@appneurox/service-composition

中文文档
0.1.0发布于 2026/10/27Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 2613

Importable service modules and a single-process NestJS composition foundation.

原始使用文档

Shared service composition foundation

This package composes the same importable NestJS service modules into either a standalone application or one process with one public HTTP listener. It uses the canonical @appneurox/service-runtime package for bootstrap, authentication, tenant context, correlation, errors and shutdown. It creates no second AsyncLocalStorage, authentication decorators or runtime copies. Build that runtime first on the remote Node24 runner; the workspace root owns dependency installation and the lockfile.

ServiceDefinition contains a safe lowercase service slug and a public label. composeServiceModule(ModuleType, definition, ApplicationClass, options) accepts a unique module class and an application class extending BaseServiceApplication; its dynamic module exports the application class and the stable serviceApplicationToken(slug) symbol. Application classes can use normal Nest DI. Domain modules do not bootstrap applications, register global guards, install process handlers, read process configuration or open sockets. Optional provider/import options support explicit infrastructure injection; they do not provision or verify infrastructure.

@Injectable()
class VendorApplication extends BaseServiceApplication {
  constructor() { super({ slug: 'vendor-service', label: 'Vendor' }); }
}
@Module({})
class VendorModule {}
const definition = { slug: 'vendor-service', label: 'Vendor' };
const service = {
  definition,
  module: composeServiceModule(VendorModule, definition, VendorApplication),
  applicationToken: serviceApplicationToken(definition.slug),
};

Standalone hosts import service.module through the canonical runtime bootstrap. createMonolithApplication({ services, config, authVerifier, logger }) initializes without listening; bootstrapMonolith opens the one host listener and owns graceful shutdown. Both accept the canonical runtime options. Each service's controllers are mounted under its slug, for example /vendor-service/v1/module and /vendor-service/v1/execute. One host runtime serves health/discovery, and public /modules lists metadata. Duplicate slugs, shared module classes, unsafe definitions and mismatched application tokens fail before bootstrap.

BaseServiceApplication.metadata() reports BOILERPLATE, businessReady: false and businessImplementation: not_implemented. Its execute boundary accepts exactly { operation, payload }. Operation names use lowercase letters/numbers with optional dot, underscore or hyphen separators, at most 63 characters. Payloads must be plain JSON objects; accessors, symbols, prototype keys, cycles, sparse arrays and non-JSON values are rejected. Input is limited to 64KiB, 16 nesting levels and 4096 JSON nodes. The shared ExecuteOperationDto adds HTTP validation, while the application validates again for direct calls.

authorizeOperation(scope, requireTenant = true) reads only the canonical runtime's verified request context. It rechecks the principal, selected tenant membership and exact scope; request headers alone never grant authority. It does not verify bearer tokens or mint principals: the host's real AuthVerifier must establish that context first. Direct trusted callers must enter through the same verified authority boundary. execute requires ${slug}:${operation} and then returns501 because no business implementation exists. HTTP adapters may additionally require a fixed ingress scope such as ${slug}:invoke.

Application services call exported application providers directly through DI in monolith mode. Standalone dependency adapters can implement the same explicit ports. Redis pools, persistence, provider clients and background jobs remain opt-in owner implementations. This foundation includes no Redis driver, WS/gRPC listener or readiness claim; those transports require explicit adapters, authentication and lifecycle tests. It neither converts the existing 82 implementations or native 54 modules nor cuts over their APIs, data or deployments.

版本与发布记录

@appneurox/service-composition 共发布 2 个版本,首次发布于 2026/10/27;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.0latest2026/10/2712 天前
0.0.0-stage2026/10/2712 天前

关于 @appneurox/service-composition 的常见问题

@appneurox/service-composition 是什么?

Importable service modules and a single-process NestJS composition foundation.

如何安装 @appneurox/service-composition?

在项目目录运行 npm install @appneurox/service-composition,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@nestjs/core(^12.2.0)、@nestjs/common(^12.2.0)、class-validator(^0.15.1)、@appneurox/service-runtime(^0.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@appneurox/service-composition 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@appneurox/service-composition 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@appneurox/service-composition 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24 <25。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@appneurox/service-composition 可以商用吗?

@appneurox/service-composition 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@appneurox/service-composition 的下载量有多少?

根据 npm 官方下载统计,@appneurox/service-composition 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,613 次,日均约 87 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@appneurox/service-composition 还在维护吗?

最新版本 0.1.0 发布于 2026/10/27(12 天前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。