@webpieces/http-routing 0.3.303 → 0.3.305

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/http-routing",
3
- "version": "0.3.303",
3
+ "version": "0.3.305",
4
4
  "description": "Decorator-based routing with auto-wiring for WebPieces",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@inversifyjs/binding-decorators": "1.1.5",
25
- "@webpieces/core-context": "0.3.303",
26
- "@webpieces/core-util": "0.3.303",
25
+ "@webpieces/core-context": "0.3.305",
26
+ "@webpieces/core-util": "0.3.305",
27
27
  "inversify": "7.10.4",
28
28
  "minimatch": "10.0.1"
29
29
  }
@@ -7,17 +7,18 @@ import { ApiClientFactory } from './ApiClientFactory';
7
7
  import { ApiFactory } from './ApiFactory';
8
8
  import { ApiClient } from './ApiClient';
9
9
  /**
10
- * Options for {@link WebpiecesRouterFactory.create}.
10
+ * Options for {@link WebpiecesRouterFactory.create} — one object (config lives inside it).
11
11
  *
12
- * appBindings - REQUIRED DI ContainerModules to load (framework + app), e.g.
13
- * [WebpiecesModule, CompanyHeadersModule, AppModule]. Loaded after the
12
+ * appBindings - DI ContainerModules to load (framework + app). Loaded after the
14
13
  * @provideSingleton auto-scan so they can add/override bindings.
15
14
  * appOverrides - A single ContainerModule loaded LAST so tests can rebind real
16
15
  * controllers/clients to mocks (see @webpieces/core-mock createMock()).
16
+ * config - Optional {@link WebpiecesConfig} (recording flags, etc.); defaults to a fresh one.
17
17
  */
18
18
  export interface WebpiecesRouterOptions {
19
19
  appBindings: ContainerModule[];
20
20
  appOverrides?: ContainerModule;
21
+ config?: WebpiecesConfig;
21
22
  }
22
23
  /**
23
24
  * WebpiecesRouter - the node-only heart of a webpieces app: a DI container + a filter
@@ -34,9 +35,7 @@ export interface WebpiecesRouterOptions {
34
35
  *
35
36
  * Usage:
36
37
  * ```typescript
37
- * const router = await WebpiecesRouterFactory.create(new WebpiecesConfig(), {
38
- * appBindings: [WebpiecesModule, CompanyHeadersModule],
39
- * });
38
+ * const router = await WebpiecesRouterFactory.create({ appBindings: [AppModule] });
40
39
  * router.addRoutes(SaveApi, SaveController);
41
40
  * router.addFilter(new FilterDefinition(1800, LogApiFilter, '*')); // your own filters
42
41
  * // (ErrorLogFilter + AuthFilter are auto-installed above yours; auth is AuthMode-driven)
@@ -101,5 +100,5 @@ export declare class WebpiecesRouter implements ApiFactory {
101
100
  * container with the @provideSingleton auto-scan + appBindings + optional test overrides.
102
101
  */
103
102
  export declare class WebpiecesRouterFactory {
104
- static create(config: WebpiecesConfig, options: WebpiecesRouterOptions): Promise<WebpiecesRouter>;
103
+ static create(options: WebpiecesRouterOptions): Promise<WebpiecesRouter>;
105
104
  }
@@ -28,9 +28,7 @@ const AuthFilter_1 = require("./filters/AuthFilter");
28
28
  *
29
29
  * Usage:
30
30
  * ```typescript
31
- * const router = await WebpiecesRouterFactory.create(new WebpiecesConfig(), {
32
- * appBindings: [WebpiecesModule, CompanyHeadersModule],
33
- * });
31
+ * const router = await WebpiecesRouterFactory.create({ appBindings: [AppModule] });
34
32
  * router.addRoutes(SaveApi, SaveController);
35
33
  * router.addFilter(new FilterDefinition(1800, LogApiFilter, '*')); // your own filters
36
34
  * // (ErrorLogFilter + AuthFilter are auto-installed above yours; auth is AuthMode-driven)
@@ -83,7 +81,7 @@ let WebpiecesRouter = class WebpiecesRouter {
83
81
  // buildProviderModule() only ever contains the client's classes — never framework internals.
84
82
  await this.appContainer.load((0, core_context_1.buildFrameworkModule)());
85
83
  await this.appContainer.load((0, binding_decorators_1.buildProviderModule)());
86
- // Load all modules into application container
84
+ // Load all app modules into application container
87
85
  // (webpiecesContainer is currently empty, reserved for future framework bindings)
88
86
  for (const module of options.appBindings) {
89
87
  await this.appContainer.load(module);
@@ -145,12 +143,12 @@ exports.WebpiecesRouter = WebpiecesRouter = tslib_1.__decorate([
145
143
  * container with the @provideSingleton auto-scan + appBindings + optional test overrides.
146
144
  */
147
145
  class WebpiecesRouterFactory {
148
- static async create(config, options) {
146
+ static async create(options) {
149
147
  // Platform (framework) container — build via buildFrameworkModule so framework
150
148
  // singletons (WebpiecesRouter, RouteBuilderImpl) come from the webpieces registry,
151
149
  // NOT the client's global one.
152
150
  const webpiecesContainer = new inversify_1.Container();
153
- webpiecesContainer.bind(WebpiecesConfig_1.WEBPIECES_CONFIG_TOKEN).toConstantValue(config);
151
+ webpiecesContainer.bind(WebpiecesConfig_1.WEBPIECES_CONFIG_TOKEN).toConstantValue(options.config ?? new WebpiecesConfig_1.WebpiecesConfig());
154
152
  await webpiecesContainer.load((0, core_context_1.buildFrameworkModule)());
155
153
  // Resolve the router from the container (NOT new'd) so @DocumentDesign + DI hold.
156
154
  const router = webpiecesContainer.get(WebpiecesRouter);
@@ -1 +1 @@
1
- {"version":3,"file":"WebpiecesRouter.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/WebpiecesRouter.ts"],"names":[],"mappings":";;;;AAAA,yCAA+D;AAC/D,wEAAsE;AACtE,oDAAsD;AACtD,0DAA0F;AAC1F,yDAAsD;AACtD,2DAAmE;AACnE,6CAAgD;AAChD,uDAA4E;AAC5E,yDAAsD;AAGtD,6DAA0D;AAC1D,qDAAkD;AAgBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAe;IAKuB;IACA;IALvC,kBAAkB,CAAa;IAC/B,YAAY,CAAa;IAEjC,YAC+C,YAA8B,EAC9B,gBAAkC;QADlC,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;IAC9E,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,kBAA6B,EAAE,OAA+B;QAC3E,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAE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AAC;QACrD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAjBD,wDAiBC","sourcesContent":["import { Container, ContainerModule, inject } from 'inversify';\nimport { buildProviderModule } from '@inversifyjs/binding-decorators';\nimport { DocumentDesign } from '@webpieces/core-util';\nimport { provideFrameworkSingleton, buildFrameworkModule } from '@webpieces/core-context';\nimport { RouteBuilderImpl } from './RouteBuilderImpl';\nimport { ApiRoutingFactory, ClassType } from './ApiRoutingFactory';\nimport { FilterDefinition } from './WebAppMeta';\nimport { WebpiecesConfig, WEBPIECES_CONFIG_TOKEN } from './WebpiecesConfig';\nimport { ApiClientFactory } from './ApiClientFactory';\nimport { ApiFactory } from './ApiFactory';\nimport { ApiClient } from './ApiClient';\nimport { ErrorLogFilter } from './filters/ErrorLogFilter';\nimport { AuthFilter } from './filters/AuthFilter';\n\n/**\n * Options for {@link WebpiecesRouterFactory.create}.\n *\n * appBindings - REQUIRED DI ContainerModules to load (framework + app), e.g.\n * [WebpiecesModule, CompanyHeadersModule, AppModule]. Loaded after the\n * @provideSingleton auto-scan so they can add/override bindings.\n * appOverrides - A single ContainerModule loaded LAST so tests can rebind real\n * controllers/clients to mocks (see @webpieces/core-mock createMock()).\n */\nexport interface WebpiecesRouterOptions {\n appBindings: ContainerModule[];\n appOverrides?: ContainerModule;\n}\n\n/**\n * WebpiecesRouter - the node-only heart of a webpieces app: a DI container + a filter\n * chain + an in-process API client. It has NO express dependency, so it runs anywhere\n * node runs and is fully testable with zero HTTP.\n *\n * DI-resolved from the platform container (like the old WebpiecesServerImpl):\n * `@provideSingleton @injectable`, RouteBuilderImpl injected, and the two containers set in\n * initialize(). Built by {@link WebpiecesRouterFactory.create} — never `new`ed by callers.\n *\n * Two-container pattern (mirrors Java WebPieces):\n * - webpiecesContainer : framework bindings (config token, @DocumentDesign design roots)\n * - appContainer : your controllers/filters/modules (a child of the framework one)\n *\n * Usage:\n * ```typescript\n * const router = await WebpiecesRouterFactory.create(new WebpiecesConfig(), {\n * appBindings: [WebpiecesModule, CompanyHeadersModule],\n * });\n * router.addRoutes(SaveApi, SaveController);\n * router.addFilter(new FilterDefinition(1800, LogApiFilter, '*')); // your own filters\n * // (ErrorLogFilter + AuthFilter are auto-installed above yours; auth is AuthMode-driven)\n *\n * // test (no express): runs the SAME filter chain (incl. auth) -> controller\n * const api = router.createApiClient(SaveApi);\n * await api.save(new SaveRequest(...));\n * ```\n *\n * To serve real HTTP, hand this router to the express adapter in @webpieces/http-server\n * (bindExpress / bindAndStartExpress) — express lifecycle lives THERE, never here.\n *\n * @DocumentDesign marks it a design root so it appears in http-routing's designed-lib graph.\n */\n@DocumentDesign()\n@provideFrameworkSingleton()\nexport class WebpiecesRouter implements ApiFactory {\n private webpiecesContainer!: Container;\n private appContainer!: Container;\n\n constructor(\n @inject(RouteBuilderImpl) private readonly routeBuilder: RouteBuilderImpl,\n @inject(ApiClientFactory) private readonly apiClientFactory: ApiClientFactory,\n ) {}\n\n /**\n * Build the app container (child of the framework container), load the @provideSingleton\n * auto-scan + appBindings + appOverrides, and point the RouteBuilder at it. Called once by\n * the factory after this router is resolved from the framework container.\n */\n async initialize(webpiecesContainer: Container, options: WebpiecesRouterOptions): Promise<void> {\n this.webpiecesContainer = webpiecesContainer;\n\n // App container is a child so app bindings see framework bindings while staying separate.\n this.appContainer = new Container({ parent: webpiecesContainer });\n this.routeBuilder.setContainer(this.appContainer);\n\n await this.loadDIModules(options);\n this.installFixedFilters();\n }\n\n /**\n * Auto-install the two fixed framework filters on every route (apps add only their own\n * filters below these): ErrorLogFilter outermost (log + let the transport translate), then\n * AuthFilter (enforces the endpoint's AuthMode off the HttpRequest). Both run over HTTP AND\n * in-process — there is no transport tier.\n */\n private installFixedFilters(): void {\n this.addFilter(new FilterDefinition(1_000_000, ErrorLogFilter, '*'));\n this.addFilter(new FilterDefinition(900_000, AuthFilter, '*'));\n }\n\n private async loadDIModules(options: WebpiecesRouterOptions): Promise<void> {\n // Load BOTH registries: framework classes (provideFrameworkSingleton) + the client's\n // own @provideSingleton classes (binding-decorators global). A client's\n // buildProviderModule() only ever contains the client's classes — never framework internals.\n await this.appContainer.load(buildFrameworkModule());\n await this.appContainer.load(buildProviderModule());\n\n // Load all modules into application container\n // (webpiecesContainer is currently empty, reserved for future framework bindings)\n for (const module of options.appBindings) {\n await this.appContainer.load(module);\n }\n\n // Load appOverrides LAST so they can override existing bindings\n if (options.appOverrides) {\n await this.appContainer.load(options.appOverrides);\n }\n }\n\n /**\n * Wire an API prototype (with @ApiPath/@Endpoint decorators) to its controller.\n * The controller is resolved from the container at request time.\n */\n addRoutes<TApi, TController extends TApi>(\n api: ClassType<TApi>,\n controller: ClassType<TController>,\n ): this {\n new ApiRoutingFactory(api, controller).configure(this.routeBuilder);\n return this;\n }\n\n /**\n * Register a user filter (runs in-process AND over HTTP, below the auto-installed fixed\n * ErrorLogFilter + AuthFilter).\n */\n addFilter(filter: FilterDefinition): this {\n this.routeBuilder.addFilter(filter);\n return this;\n }\n\n /**\n * Create an in-process API client that runs the api-tier filter chain + controller\n * with NO express/HTTP. The primary path for tests and node-only callers.\n */\n // webpieces-disable no-any-unknown -- abstract constructor signature requires any[] args\n createApiClient<T>(apiPrototype: abstract new (...args: any[]) => T): T {\n return this.apiClientFactory.createApiClient(apiPrototype);\n }\n\n /**\n * Reify the registered APIs as {@link ApiClient}s (contract + the createApiClient proxy) via\n * the shared {@link ApiClientFactory}. This is the ONLY handoff to the express layer — the\n * internal RouteBuilder never leaves.\n */\n apiClients(): ApiClient[] {\n return this.apiClientFactory.apiClients();\n }\n\n /** The application DI container (child of the framework container). */\n getContainer(): Container {\n return this.appContainer;\n }\n}\n\n/**\n * Builds a {@link WebpiecesRouter}: constructs the platform container (mirrors\n * WebpiecesServerFactory.create), RESOLVES the router from DI, then initializes its app child\n * container with the @provideSingleton auto-scan + appBindings + optional test overrides.\n */\nexport class WebpiecesRouterFactory {\n static async create(\n config: WebpiecesConfig,\n options: WebpiecesRouterOptions,\n ): Promise<WebpiecesRouter> {\n // Platform (framework) container — build via buildFrameworkModule so framework\n // singletons (WebpiecesRouter, RouteBuilderImpl) come from the webpieces registry,\n // NOT the client's global one.\n const webpiecesContainer = new Container();\n webpiecesContainer.bind(WEBPIECES_CONFIG_TOKEN).toConstantValue(config);\n await webpiecesContainer.load(buildFrameworkModule());\n\n // Resolve the router from the container (NOT new'd) so @DocumentDesign + DI hold.\n const router = webpiecesContainer.get(WebpiecesRouter);\n await router.initialize(webpiecesContainer, options);\n return router;\n }\n}\n"]}
1
+ {"version":3,"file":"WebpiecesRouter.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/WebpiecesRouter.ts"],"names":[],"mappings":";;;;AAAA,yCAA+D;AAC/D,wEAAsE;AACtE,oDAAsD;AACtD,0DAA0F;AAC1F,yDAAsD;AACtD,2DAAmE;AACnE,6CAAgD;AAChD,uDAA4E;AAC5E,yDAAsD;AAGtD,6DAA0D;AAC1D,qDAAkD;AAiBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAe;IAKuB;IACA;IALvC,kBAAkB,CAAa;IAC/B,YAAY,CAAa;IAEjC,YAC+C,YAA8B,EAC9B,gBAAkC;QADlC,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;IAC9E,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,kBAA6B,EAAE,OAA+B;QAC3E,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAE7C,0FAA0F;QAC1F,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAS,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAElD,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC/B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CAAC,YAAY,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACH,UAAU;QACN,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC;IAC9C,CAAC;IAED,uEAAuE;IACvE,YAAY;QACR,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ,CAAA;AAlGY,0CAAe;0BAAf,eAAe;IAF3B,IAAA,0BAAc,GAAE;IAChB,IAAA,wCAAyB,GAAE;IAMnB,mBAAA,IAAA,kBAAM,EAAC,mCAAgB,CAAC,CAAA;IACxB,mBAAA,IAAA,kBAAM,EAAC,mCAAgB,CAAC,CAAA;6CADgC,mCAAgB;QACZ,mCAAgB;GANxE,eAAe,CAkG3B;AAED;;;;GAIG;AACH,MAAa,sBAAsB;IAC/B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAA+B;QAC/C,+EAA+E;QAC/E,mFAAmF;QACnF,+BAA+B;QAC/B,MAAM,kBAAkB,GAAG,IAAI,qBAAS,EAAE,CAAC;QAC3C,kBAAkB,CAAC,IAAI,CAAC,wCAAsB,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,iCAAe,EAAE,CAAC,CAAC;QACzG,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAA,mCAAoB,GAAE,CAAC,CAAC;QAEtD,kFAAkF;QAClF,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACvD,MAAM,MAAM,CAAC,UAAU,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAdD,wDAcC","sourcesContent":["import { Container, ContainerModule, inject } from 'inversify';\nimport { buildProviderModule } from '@inversifyjs/binding-decorators';\nimport { DocumentDesign } from '@webpieces/core-util';\nimport { provideFrameworkSingleton, buildFrameworkModule } from '@webpieces/core-context';\nimport { RouteBuilderImpl } from './RouteBuilderImpl';\nimport { ApiRoutingFactory, ClassType } from './ApiRoutingFactory';\nimport { FilterDefinition } from './WebAppMeta';\nimport { WebpiecesConfig, WEBPIECES_CONFIG_TOKEN } from './WebpiecesConfig';\nimport { ApiClientFactory } from './ApiClientFactory';\nimport { ApiFactory } from './ApiFactory';\nimport { ApiClient } from './ApiClient';\nimport { ErrorLogFilter } from './filters/ErrorLogFilter';\nimport { AuthFilter } from './filters/AuthFilter';\n\n/**\n * Options for {@link WebpiecesRouterFactory.create} — one object (config lives inside it).\n *\n * appBindings - DI ContainerModules to load (framework + app). Loaded after the\n * @provideSingleton auto-scan so they can add/override bindings.\n * appOverrides - A single ContainerModule loaded LAST so tests can rebind real\n * controllers/clients to mocks (see @webpieces/core-mock createMock()).\n * config - Optional {@link WebpiecesConfig} (recording flags, etc.); defaults to a fresh one.\n */\nexport interface WebpiecesRouterOptions {\n appBindings: ContainerModule[];\n appOverrides?: ContainerModule;\n config?: WebpiecesConfig;\n}\n\n/**\n * WebpiecesRouter - the node-only heart of a webpieces app: a DI container + a filter\n * chain + an in-process API client. It has NO express dependency, so it runs anywhere\n * node runs and is fully testable with zero HTTP.\n *\n * DI-resolved from the platform container (like the old WebpiecesServerImpl):\n * `@provideSingleton @injectable`, RouteBuilderImpl injected, and the two containers set in\n * initialize(). Built by {@link WebpiecesRouterFactory.create} — never `new`ed by callers.\n *\n * Two-container pattern (mirrors Java WebPieces):\n * - webpiecesContainer : framework bindings (config token, @DocumentDesign design roots)\n * - appContainer : your controllers/filters/modules (a child of the framework one)\n *\n * Usage:\n * ```typescript\n * const router = await WebpiecesRouterFactory.create({ appBindings: [AppModule] });\n * router.addRoutes(SaveApi, SaveController);\n * router.addFilter(new FilterDefinition(1800, LogApiFilter, '*')); // your own filters\n * // (ErrorLogFilter + AuthFilter are auto-installed above yours; auth is AuthMode-driven)\n *\n * // test (no express): runs the SAME filter chain (incl. auth) -> controller\n * const api = router.createApiClient(SaveApi);\n * await api.save(new SaveRequest(...));\n * ```\n *\n * To serve real HTTP, hand this router to the express adapter in @webpieces/http-server\n * (bindExpress / bindAndStartExpress) — express lifecycle lives THERE, never here.\n *\n * @DocumentDesign marks it a design root so it appears in http-routing's designed-lib graph.\n */\n@DocumentDesign()\n@provideFrameworkSingleton()\nexport class WebpiecesRouter implements ApiFactory {\n private webpiecesContainer!: Container;\n private appContainer!: Container;\n\n constructor(\n @inject(RouteBuilderImpl) private readonly routeBuilder: RouteBuilderImpl,\n @inject(ApiClientFactory) private readonly apiClientFactory: ApiClientFactory,\n ) {}\n\n /**\n * Build the app container (child of the framework container), load the @provideSingleton\n * auto-scan + appBindings + appOverrides, and point the RouteBuilder at it. Called once by\n * the factory after this router is resolved from the framework container.\n */\n async initialize(webpiecesContainer: Container, options: WebpiecesRouterOptions): Promise<void> {\n this.webpiecesContainer = webpiecesContainer;\n\n // App container is a child so app bindings see framework bindings while staying separate.\n this.appContainer = new Container({ parent: webpiecesContainer });\n this.routeBuilder.setContainer(this.appContainer);\n\n await this.loadDIModules(options);\n this.installFixedFilters();\n }\n\n /**\n * Auto-install the two fixed framework filters on every route (apps add only their own\n * filters below these): ErrorLogFilter outermost (log + let the transport translate), then\n * AuthFilter (enforces the endpoint's AuthMode off the HttpRequest). Both run over HTTP AND\n * in-process — there is no transport tier.\n */\n private installFixedFilters(): void {\n this.addFilter(new FilterDefinition(1_000_000, ErrorLogFilter, '*'));\n this.addFilter(new FilterDefinition(900_000, AuthFilter, '*'));\n }\n\n private async loadDIModules(options: WebpiecesRouterOptions): Promise<void> {\n // Load BOTH registries: framework classes (provideFrameworkSingleton) + the client's\n // own @provideSingleton classes (binding-decorators global). A client's\n // buildProviderModule() only ever contains the client's classes — never framework internals.\n await this.appContainer.load(buildFrameworkModule());\n await this.appContainer.load(buildProviderModule());\n\n // Load all app modules into application container\n // (webpiecesContainer is currently empty, reserved for future framework bindings)\n for (const module of options.appBindings) {\n await this.appContainer.load(module);\n }\n\n // Load appOverrides LAST so they can override existing bindings\n if (options.appOverrides) {\n await this.appContainer.load(options.appOverrides);\n }\n }\n\n /**\n * Wire an API prototype (with @ApiPath/@Endpoint decorators) to its controller.\n * The controller is resolved from the container at request time.\n */\n addRoutes<TApi, TController extends TApi>(\n api: ClassType<TApi>,\n controller: ClassType<TController>,\n ): this {\n new ApiRoutingFactory(api, controller).configure(this.routeBuilder);\n return this;\n }\n\n /**\n * Register a user filter (runs in-process AND over HTTP, below the auto-installed fixed\n * ErrorLogFilter + AuthFilter).\n */\n addFilter(filter: FilterDefinition): this {\n this.routeBuilder.addFilter(filter);\n return this;\n }\n\n /**\n * Create an in-process API client that runs the api-tier filter chain + controller\n * with NO express/HTTP. The primary path for tests and node-only callers.\n */\n // webpieces-disable no-any-unknown -- abstract constructor signature requires any[] args\n createApiClient<T>(apiPrototype: abstract new (...args: any[]) => T): T {\n return this.apiClientFactory.createApiClient(apiPrototype);\n }\n\n /**\n * Reify the registered APIs as {@link ApiClient}s (contract + the createApiClient proxy) via\n * the shared {@link ApiClientFactory}. This is the ONLY handoff to the express layer — the\n * internal RouteBuilder never leaves.\n */\n apiClients(): ApiClient[] {\n return this.apiClientFactory.apiClients();\n }\n\n /** The application DI container (child of the framework container). */\n getContainer(): Container {\n return this.appContainer;\n }\n}\n\n/**\n * Builds a {@link WebpiecesRouter}: constructs the platform container (mirrors\n * WebpiecesServerFactory.create), RESOLVES the router from DI, then initializes its app child\n * container with the @provideSingleton auto-scan + appBindings + optional test overrides.\n */\nexport class WebpiecesRouterFactory {\n static async create(options: WebpiecesRouterOptions): Promise<WebpiecesRouter> {\n // Platform (framework) container — build via buildFrameworkModule so framework\n // singletons (WebpiecesRouter, RouteBuilderImpl) come from the webpieces registry,\n // NOT the client's global one.\n const webpiecesContainer = new Container();\n webpiecesContainer.bind(WEBPIECES_CONFIG_TOKEN).toConstantValue(options.config ?? new WebpiecesConfig());\n await webpiecesContainer.load(buildFrameworkModule());\n\n // Resolve the router from the container (NOT new'd) so @DocumentDesign + DI hold.\n const router = webpiecesContainer.get(WebpiecesRouter);\n await router.initialize(webpiecesContainer, options);\n return router;\n }\n}\n"]}
package/src/index.d.ts CHANGED
@@ -16,5 +16,6 @@ export { ApiClient, ApiClientProxy } from './ApiClient';
16
16
  export { AuthConfig, Principal } from './AuthConfig';
17
17
  export { fillContext } from './fillContext';
18
18
  export { WebpiecesRouter, WebpiecesRouterFactory, WebpiecesRouterOptions } from './WebpiecesRouter';
19
+ export { setupRuntime, RuntimeSetupOptions } from './setupRuntime';
19
20
  export { RequestContextReader } from '@webpieces/core-context';
20
21
  export { WebpiecesConfig, WEBPIECES_CONFIG_TOKEN } from './WebpiecesConfig';
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebpiecesRouterFactory = exports.WebpiecesRouter = exports.fillContext = exports.Principal = exports.AuthConfig = exports.ApiClient = exports.FilterMatcher = exports.RouteHandler = exports.MethodMeta = exports.FilterChain = exports.WpResponse = exports.Filter = exports.HttpRequest = exports.FilterDefinition = exports.RouteDefinition = exports.ApiRoutingFactory = exports.buildFrameworkModule = exports.provideFrameworkSingletonAs = exports.provideFrameworkSingleton = exports.provideTransient = exports.provideSingletonAs = exports.provideSingleton = exports.ROUTING_METADATA_KEYS = exports.SourceFile = exports.isDocumentDesign = exports.DocumentDesign = exports.METADATA_KEYS = exports.RouteMetadata = exports.AuthMeta = exports.getQueueName = exports.assertPubSubConventions = exports.assertApiKind = exports.getApiKind = exports.assertEveryEndpointHasAuthMode = exports.getAuthMode = exports.getAuthMeta = exports.isApiPath = exports.getEndpoints = exports.getApiPath = exports.Queue = exports.PubSub = exports.Rpc = exports.AuthSharedSecret = exports.AuthOidc = exports.AuthJwt = exports.Public = exports.AuthenticationConfig = exports.Authentication = exports.Endpoint = exports.ApiPath = void 0;
4
- exports.WEBPIECES_CONFIG_TOKEN = exports.WebpiecesConfig = exports.RequestContextReader = void 0;
4
+ exports.WEBPIECES_CONFIG_TOKEN = exports.WebpiecesConfig = exports.RequestContextReader = exports.RuntimeSetupOptions = exports.setupRuntime = void 0;
5
5
  // Re-export API decorators from core-util for convenience
6
6
  var core_util_1 = require("@webpieces/core-util");
7
7
  Object.defineProperty(exports, "ApiPath", { enumerable: true, get: function () { return core_util_1.ApiPath; } });
@@ -84,6 +84,11 @@ Object.defineProperty(exports, "fillContext", { enumerable: true, get: function
84
84
  var WebpiecesRouter_1 = require("./WebpiecesRouter");
85
85
  Object.defineProperty(exports, "WebpiecesRouter", { enumerable: true, get: function () { return WebpiecesRouter_1.WebpiecesRouter; } });
86
86
  Object.defineProperty(exports, "WebpiecesRouterFactory", { enumerable: true, get: function () { return WebpiecesRouter_1.WebpiecesRouterFactory; } });
87
+ // The ONE transport-free startup sequence (headers → logging → router → routes) → ApiFactory.
88
+ // Reusable by any company/app and any framework adapter; a company wraps it with its own headers.
89
+ var setupRuntime_1 = require("./setupRuntime");
90
+ Object.defineProperty(exports, "setupRuntime", { enumerable: true, get: function () { return setupRuntime_1.setupRuntime; } });
91
+ Object.defineProperty(exports, "RuntimeSetupOptions", { enumerable: true, get: function () { return setupRuntime_1.RuntimeSetupOptions; } });
87
92
  // Context readers (Node.js only) moved to core-context; re-exported for back-compat
88
93
  var core_context_4 = require("@webpieces/core-context");
89
94
  Object.defineProperty(exports, "RequestContextReader", { enumerable: true, get: function () { return core_context_4.RequestContextReader; } });
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/index.ts"],"names":[],"mappings":";;;;AAAA,0DAA0D;AAC1D,kDA8B8B;AA7B1B,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,mGAAA,MAAM,OAAA;AACN,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,6GAAA,gBAAgB,OAAA;AAChB,gGAAA,GAAG,OAAA;AACH,mGAAA,MAAM,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a,OAAA;AAItB,yCAAwD;AAA/C,sGAAA,SAAS,OAAA;AAElB,sFAAsF;AACtF,2CAAqD;AAA5C,wGAAA,UAAU,OAAA;AAAE,uGAAA,SAAS,OAAA;AAE9B,kEAAkE;AAClE,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AAEpB,0FAA0F;AAC1F,qDAAoG;AAA3F,kHAAA,eAAe,OAAA;AAAE,yHAAA,sBAAsB,OAAA;AAEhD,oFAAoF;AACpF,wDAA+D;AAAtD,oHAAA,oBAAoB,OAAA;AAE7B,uBAAuB;AACvB,qDAA4E;AAAnE,kHAAA,eAAe,OAAA;AAAE,yHAAA,sBAAsB,OAAA","sourcesContent":["// Re-export API decorators from core-util for convenience\nexport {\n ApiPath,\n Endpoint,\n Authentication,\n AuthenticationConfig,\n Public,\n AuthJwt,\n AuthOidc,\n AuthSharedSecret,\n Rpc,\n PubSub,\n Queue,\n getApiPath,\n getEndpoints,\n isApiPath,\n getAuthMeta,\n getAuthMode,\n assertEveryEndpointHasAuthMode,\n getApiKind,\n assertApiKind,\n assertPubSubConventions,\n getQueueName,\n AuthMeta,\n RouteMetadata,\n METADATA_KEYS,\n ValidateImplementation,\n // @DocumentDesign moved to core-util (design-root marker, browser + Node);\n // re-exported here for back-compat.\n DocumentDesign,\n isDocumentDesign,\n} from '@webpieces/core-util';\nexport type { AuthMode, ApiKind } from '@webpieces/core-util';\n\n// Server-side routing decorators and utilities\nexport {\n SourceFile,\n ROUTING_METADATA_KEYS,\n} from './decorators';\n\n// DI provider decorators moved to core-context; re-exported here for back-compat\nexport { provideSingleton, provideSingletonAs, provideTransient } from '@webpieces/core-context';\n// Framework-only DI registry (packages/** framework classes use these; see frameworkProvide.ts)\nexport {\n provideFrameworkSingleton,\n provideFrameworkSingletonAs,\n buildFrameworkModule,\n} from '@webpieces/core-context';\n\nexport { ApiRoutingFactory, ClassType } from './ApiRoutingFactory';\n\n// Core routing types\nexport {\n Routes,\n RouteBuilder,\n RouteDefinition,\n FilterDefinition,\n} from './WebAppMeta';\n\n// The transport-neutral request type (defined in core-context; this is http-routing's\n// public request — a transport adapter builds one and the chain reads it from RequestContext).\nexport { HttpRequest } from '@webpieces/core-context';\n\n// Filter-chain primitives (absorbed from the former @webpieces/http-filters package)\nexport { Filter, WpResponse, Service } from './Filter';\nexport { FilterChain } from './FilterChain';\nexport { MethodMeta } from './MethodMeta';\nexport { RouteHandler } from './RouteHandler';\n\n// RouteBuilderImpl (the route table + chain composer) is now INTERNAL — it is never\n// handed to upper layers. The express layer consumes ApiFactory.apiClients() instead.\n\n// Filter matching\nexport { FilterMatcher, HttpFilter } from './FilterMatcher';\n\n// The public API-surface abstraction: declare routes/filters, get them back as ApiClient[].\nexport { ApiFactory } from './ApiFactory';\nexport { ApiClient, ApiClientProxy } from './ApiClient';\n\n// Auth: the app-provided, container-bound verifiers the framework AuthFilter injects.\nexport { AuthConfig, Principal } from './AuthConfig';\n\n// Above-boundary context setup shared by every transport adapter.\nexport { fillContext } from './fillContext';\n\n// Node-only router (the express-free heart: container + filter chain + in-process client)\nexport { WebpiecesRouter, WebpiecesRouterFactory, WebpiecesRouterOptions } from './WebpiecesRouter';\n\n// Context readers (Node.js only) moved to core-context; re-exported for back-compat\nexport { RequestContextReader } from '@webpieces/core-context';\n\n// Server configuration\nexport { WebpiecesConfig, WEBPIECES_CONFIG_TOKEN } from './WebpiecesConfig';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/index.ts"],"names":[],"mappings":";;;;AAAA,0DAA0D;AAC1D,kDA8B8B;AA7B1B,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,mGAAA,MAAM,OAAA;AACN,oGAAA,OAAO,OAAA;AACP,qGAAA,QAAQ,OAAA;AACR,6GAAA,gBAAgB,OAAA;AAChB,gGAAA,GAAG,OAAA;AACH,mGAAA,MAAM,OAAA;AACN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AItB,yCAAwD;AAA/C,sGAAA,SAAS,OAAA;AAElB,sFAAsF;AACtF,2CAAqD;AAA5C,wGAAA,UAAU,OAAA;AAAE,uGAAA,SAAS,OAAA;AAE9B,kEAAkE;AAClE,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AAEpB,0FAA0F;AAC1F,qDAAoG;AAA3F,kHAAA,eAAe,OAAA;AAAE,yHAAA,sBAAsB,OAAA;AAEhD,8FAA8F;AAC9F,kGAAkG;AAClG,+CAAmE;AAA1D,4GAAA,YAAY,OAAA;AAAE,mHAAA,mBAAmB,OAAA;AAE1C,oFAAoF;AACpF,wDAA+D;AAAtD,oHAAA,oBAAoB,OAAA;AAE7B,uBAAuB;AACvB,qDAA4E;AAAnE,kHAAA,eAAe,OAAA;AAAE,yHAAA,sBAAsB,OAAA","sourcesContent":["// Re-export API decorators from core-util for convenience\nexport {\n ApiPath,\n Endpoint,\n Authentication,\n AuthenticationConfig,\n Public,\n AuthJwt,\n AuthOidc,\n AuthSharedSecret,\n Rpc,\n PubSub,\n Queue,\n getApiPath,\n getEndpoints,\n isApiPath,\n getAuthMeta,\n getAuthMode,\n assertEveryEndpointHasAuthMode,\n getApiKind,\n assertApiKind,\n assertPubSubConventions,\n getQueueName,\n AuthMeta,\n RouteMetadata,\n METADATA_KEYS,\n ValidateImplementation,\n // @DocumentDesign moved to core-util (design-root marker, browser + Node);\n // re-exported here for back-compat.\n DocumentDesign,\n isDocumentDesign,\n} from '@webpieces/core-util';\nexport type { AuthMode, ApiKind } from '@webpieces/core-util';\n\n// Server-side routing decorators and utilities\nexport {\n SourceFile,\n ROUTING_METADATA_KEYS,\n} from './decorators';\n\n// DI provider decorators moved to core-context; re-exported here for back-compat\nexport { provideSingleton, provideSingletonAs, provideTransient } from '@webpieces/core-context';\n// Framework-only DI registry (packages/** framework classes use these; see frameworkProvide.ts)\nexport {\n provideFrameworkSingleton,\n provideFrameworkSingletonAs,\n buildFrameworkModule,\n} from '@webpieces/core-context';\n\nexport { ApiRoutingFactory, ClassType } from './ApiRoutingFactory';\n\n// Core routing types\nexport {\n Routes,\n RouteBuilder,\n RouteDefinition,\n FilterDefinition,\n} from './WebAppMeta';\n\n// The transport-neutral request type (defined in core-context; this is http-routing's\n// public request — a transport adapter builds one and the chain reads it from RequestContext).\nexport { HttpRequest } from '@webpieces/core-context';\n\n// Filter-chain primitives (absorbed from the former @webpieces/http-filters package)\nexport { Filter, WpResponse, Service } from './Filter';\nexport { FilterChain } from './FilterChain';\nexport { MethodMeta } from './MethodMeta';\nexport { RouteHandler } from './RouteHandler';\n\n// RouteBuilderImpl (the route table + chain composer) is now INTERNAL — it is never\n// handed to upper layers. The express layer consumes ApiFactory.apiClients() instead.\n\n// Filter matching\nexport { FilterMatcher, HttpFilter } from './FilterMatcher';\n\n// The public API-surface abstraction: declare routes/filters, get them back as ApiClient[].\nexport { ApiFactory } from './ApiFactory';\nexport { ApiClient, ApiClientProxy } from './ApiClient';\n\n// Auth: the app-provided, container-bound verifiers the framework AuthFilter injects.\nexport { AuthConfig, Principal } from './AuthConfig';\n\n// Above-boundary context setup shared by every transport adapter.\nexport { fillContext } from './fillContext';\n\n// Node-only router (the express-free heart: container + filter chain + in-process client)\nexport { WebpiecesRouter, WebpiecesRouterFactory, WebpiecesRouterOptions } from './WebpiecesRouter';\n\n// The ONE transport-free startup sequence (headers → logging → router → routes) → ApiFactory.\n// Reusable by any company/app and any framework adapter; a company wraps it with its own headers.\nexport { setupRuntime, RuntimeSetupOptions } from './setupRuntime';\n\n// Context readers (Node.js only) moved to core-context; re-exported for back-compat\nexport { RequestContextReader } from '@webpieces/core-context';\n\n// Server configuration\nexport { WebpiecesConfig, WEBPIECES_CONFIG_TOKEN } from './WebpiecesConfig';\n"]}
@@ -0,0 +1,59 @@
1
+ import { ContainerModule } from 'inversify';
2
+ import { ContextKey, LoggerFactory } from '@webpieces/core-util';
3
+ import { WebpiecesConfig } from './WebpiecesConfig';
4
+ import { WebpiecesRouter } from './WebpiecesRouter';
5
+ import { ApiFactory } from './ApiFactory';
6
+ /**
7
+ * RuntimeSetupOptions - inputs to {@link setupRuntime}. Data-only structure (a class, per the
8
+ * webpieces guidelines). A company/app layer supplies its own header tiers + logger + modules;
9
+ * the framework runs the canonical startup sequence and hands back a transport-free ApiFactory.
10
+ *
11
+ * Header tiers mirror {@link HeaderRegistry.configure}: platform defaults + org/company keys +
12
+ * this-service keys.
13
+ */
14
+ export declare class RuntimeSetupOptions {
15
+ /** Logging backend to install (LogManager.setFactory). */
16
+ readonly loggerFactory: LoggerFactory;
17
+ /** This service's own context keys. */
18
+ readonly svrHeaders: ContextKey[];
19
+ /** Org/company-wide shared context keys (the company layer passes these in). */
20
+ readonly companyHeaders: ContextKey[];
21
+ /** Include the webpieces platform default headers. */
22
+ readonly platformHeaders: boolean;
23
+ /** App DI ContainerModules to load. */
24
+ readonly modules: ContainerModule[];
25
+ /** A single DI module loaded LAST so tests can rebind bindings to mocks. */
26
+ readonly appOverrides?: ContainerModule | undefined;
27
+ /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
28
+ readonly config?: WebpiecesConfig | undefined;
29
+ constructor(
30
+ /** Logging backend to install (LogManager.setFactory). */
31
+ loggerFactory: LoggerFactory,
32
+ /** This service's own context keys. */
33
+ svrHeaders?: ContextKey[],
34
+ /** Org/company-wide shared context keys (the company layer passes these in). */
35
+ companyHeaders?: ContextKey[],
36
+ /** Include the webpieces platform default headers. */
37
+ platformHeaders?: boolean,
38
+ /** App DI ContainerModules to load. */
39
+ modules?: ContainerModule[],
40
+ /** A single DI module loaded LAST so tests can rebind bindings to mocks. */
41
+ appOverrides?: ContainerModule | undefined,
42
+ /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
43
+ config?: WebpiecesConfig | undefined);
44
+ }
45
+ /**
46
+ * setupRuntime - the ONE canonical, TRANSPORT-FREE startup sequence, reusable by any company/app
47
+ * AND any framework adapter (express, fastify, a serverless handler, ...). It runs, in the correct
48
+ * fail-fast order:
49
+ *
50
+ * 1. HeaderRegistry.configure (filters read it at construction; logging masks off it)
51
+ * 2. LogManager.setFactory (fails fast unless the registry is configured first)
52
+ * 3. build the router + DI container
53
+ * 4. run the caller's `configureRoutes(router)` block (addRoutes/addFilter)
54
+ *
55
+ * and returns the built {@link ApiFactory} — `apiClients()` for a transport to bind, or
56
+ * `createApiClient()` for in-process tests. There is NO express (or any transport) here; a
57
+ * transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.
58
+ */
59
+ export declare function setupRuntime(options: RuntimeSetupOptions, configureRoutes: (router: WebpiecesRouter) => void): Promise<ApiFactory>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimeSetupOptions = void 0;
4
+ exports.setupRuntime = setupRuntime;
5
+ const core_util_1 = require("@webpieces/core-util");
6
+ const WebpiecesConfig_1 = require("./WebpiecesConfig");
7
+ const WebpiecesRouter_1 = require("./WebpiecesRouter");
8
+ /**
9
+ * RuntimeSetupOptions - inputs to {@link setupRuntime}. Data-only structure (a class, per the
10
+ * webpieces guidelines). A company/app layer supplies its own header tiers + logger + modules;
11
+ * the framework runs the canonical startup sequence and hands back a transport-free ApiFactory.
12
+ *
13
+ * Header tiers mirror {@link HeaderRegistry.configure}: platform defaults + org/company keys +
14
+ * this-service keys.
15
+ */
16
+ class RuntimeSetupOptions {
17
+ loggerFactory;
18
+ svrHeaders;
19
+ companyHeaders;
20
+ platformHeaders;
21
+ modules;
22
+ appOverrides;
23
+ config;
24
+ constructor(
25
+ /** Logging backend to install (LogManager.setFactory). */
26
+ loggerFactory,
27
+ /** This service's own context keys. */
28
+ svrHeaders = [],
29
+ /** Org/company-wide shared context keys (the company layer passes these in). */
30
+ companyHeaders = [],
31
+ /** Include the webpieces platform default headers. */
32
+ platformHeaders = true,
33
+ /** App DI ContainerModules to load. */
34
+ modules = [],
35
+ /** A single DI module loaded LAST so tests can rebind bindings to mocks. */
36
+ appOverrides,
37
+ /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
38
+ config) {
39
+ this.loggerFactory = loggerFactory;
40
+ this.svrHeaders = svrHeaders;
41
+ this.companyHeaders = companyHeaders;
42
+ this.platformHeaders = platformHeaders;
43
+ this.modules = modules;
44
+ this.appOverrides = appOverrides;
45
+ this.config = config;
46
+ }
47
+ }
48
+ exports.RuntimeSetupOptions = RuntimeSetupOptions;
49
+ /**
50
+ * setupRuntime - the ONE canonical, TRANSPORT-FREE startup sequence, reusable by any company/app
51
+ * AND any framework adapter (express, fastify, a serverless handler, ...). It runs, in the correct
52
+ * fail-fast order:
53
+ *
54
+ * 1. HeaderRegistry.configure (filters read it at construction; logging masks off it)
55
+ * 2. LogManager.setFactory (fails fast unless the registry is configured first)
56
+ * 3. build the router + DI container
57
+ * 4. run the caller's `configureRoutes(router)` block (addRoutes/addFilter)
58
+ *
59
+ * and returns the built {@link ApiFactory} — `apiClients()` for a transport to bind, or
60
+ * `createApiClient()` for in-process tests. There is NO express (or any transport) here; a
61
+ * transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.
62
+ */
63
+ async function setupRuntime(options, configureRoutes) {
64
+ // 1. Register the global HeaderRegistry FIRST.
65
+ core_util_1.HeaderRegistry.configure(options.svrHeaders, options.companyHeaders, options.platformHeaders);
66
+ // 2. Install the logging backend ONCE, before anything else logs.
67
+ core_util_1.LogManager.setFactory(options.loggerFactory);
68
+ // 3. Build the node-only router + DI container.
69
+ const router = await WebpiecesRouter_1.WebpiecesRouterFactory.create({
70
+ appBindings: [...options.modules],
71
+ appOverrides: options.appOverrides,
72
+ config: options.config ?? new WebpiecesConfig_1.WebpiecesConfig(),
73
+ });
74
+ // 4. Let the caller declare its routes + filters, then hand back the consumer surface.
75
+ configureRoutes(router);
76
+ return router;
77
+ }
78
+ //# sourceMappingURL=setupRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupRuntime.js","sourceRoot":"","sources":["../../../../../packages/http/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,MAAM,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { ContainerModule } from 'inversify';\nimport { ContextKey, HeaderRegistry, LoggerFactory, LogManager } from '@webpieces/core-util';\nimport { WebpiecesConfig } from './WebpiecesConfig';\nimport { WebpiecesRouter, WebpiecesRouterFactory } from './WebpiecesRouter';\nimport { ApiFactory } from './ApiFactory';\n\n/**\n * RuntimeSetupOptions - inputs to {@link setupRuntime}. Data-only structure (a class, per the\n * webpieces guidelines). A company/app layer supplies its own header tiers + logger + modules;\n * the framework runs the canonical startup sequence and hands back a transport-free ApiFactory.\n *\n * Header tiers mirror {@link HeaderRegistry.configure}: platform defaults + org/company keys +\n * this-service keys.\n */\nexport class RuntimeSetupOptions {\n constructor(\n /** Logging backend to install (LogManager.setFactory). */\n public readonly loggerFactory: LoggerFactory,\n /** This service's own context keys. */\n public readonly svrHeaders: ContextKey[] = [],\n /** Org/company-wide shared context keys (the company layer passes these in). */\n public readonly companyHeaders: ContextKey[] = [],\n /** Include the webpieces platform default headers. */\n public readonly platformHeaders: boolean = true,\n /** App DI ContainerModules to load. */\n public readonly modules: ContainerModule[] = [],\n /** A single DI module loaded LAST so tests can rebind bindings to mocks. */\n public readonly appOverrides?: ContainerModule,\n /** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */\n public readonly config?: WebpiecesConfig,\n ) {}\n}\n\n/**\n * setupRuntime - the ONE canonical, TRANSPORT-FREE startup sequence, reusable by any company/app\n * AND any framework adapter (express, fastify, a serverless handler, ...). It runs, in the correct\n * fail-fast order:\n *\n * 1. HeaderRegistry.configure (filters read it at construction; logging masks off it)\n * 2. LogManager.setFactory (fails fast unless the registry is configured first)\n * 3. build the router + DI container\n * 4. run the caller's `configureRoutes(router)` block (addRoutes/addFilter)\n *\n * and returns the built {@link ApiFactory} — `apiClients()` for a transport to bind, or\n * `createApiClient()` for in-process tests. There is NO express (or any transport) here; a\n * transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.\n */\nexport async function setupRuntime(\n options: RuntimeSetupOptions,\n configureRoutes: (router: WebpiecesRouter) => void,\n): Promise<ApiFactory> {\n // 1. Register the global HeaderRegistry FIRST.\n HeaderRegistry.configure(options.svrHeaders, options.companyHeaders, options.platformHeaders);\n\n // 2. Install the logging backend ONCE, before anything else logs.\n LogManager.setFactory(options.loggerFactory);\n\n // 3. Build the node-only router + DI container.\n const router = await WebpiecesRouterFactory.create({\n appBindings: [...options.modules],\n appOverrides: options.appOverrides,\n config: options.config ?? new WebpiecesConfig(),\n });\n\n // 4. Let the caller declare its routes + filters, then hand back the consumer surface.\n configureRoutes(router);\n return router;\n}\n"]}