@webpieces/http-routing 0.3.368 → 0.3.370
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 +4 -4
- package/src/AppModules.d.ts +2 -1
- package/src/AppModules.js.map +1 -1
- package/src/setupRuntime.d.ts +11 -16
- package/src/setupRuntime.js +12 -17
- package/src/setupRuntime.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/http-routing",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.370",
|
|
4
4
|
"description": "Decorator-based routing with auto-wiring for WebPieces",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
25
|
-
"@webpieces/core-context": "0.3.
|
|
26
|
-
"@webpieces/core-util": "0.3.
|
|
27
|
-
"@webpieces/gcp-identity": "0.3.
|
|
25
|
+
"@webpieces/core-context": "0.3.370",
|
|
26
|
+
"@webpieces/core-util": "0.3.370",
|
|
27
|
+
"@webpieces/gcp-identity": "0.3.370",
|
|
28
28
|
"inversify": "7.10.4",
|
|
29
29
|
"jsonwebtoken": "9.0.2",
|
|
30
30
|
"minimatch": "10.0.1"
|
package/src/AppModules.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface AppModules {
|
|
|
53
53
|
getBindingModules(): ContainerModule[];
|
|
54
54
|
/** The route groups to configure onto the router, in order. */
|
|
55
55
|
getRoutingModules(): RouteModule[];
|
|
56
|
-
/** This
|
|
56
|
+
/** This company's own context keys(usually all keys across all servers),
|
|
57
|
+
* registered into the global HeaderRegistry at startup. */
|
|
57
58
|
getHeaders(): ContextKey[];
|
|
58
59
|
}
|
package/src/AppModules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppModules.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/AppModules.ts"],"names":[],"mappings":"","sourcesContent":["import { ContainerModule } from 'inversify';\nimport { ContextKey } from '@webpieces/core-util';\nimport { WebpiecesRouter } from './WebpiecesRouter';\n\n/**\n * RouteModule - a reusable, named group of routes + filters, configured onto the\n * {@link WebpiecesRouter}. This is the TypeScript analog of a Java WebPieces \"RouteModule\":\n * instead of one anonymous `(router) => { ... }` block, each cohesive group of routes/filters\n * lives in its own named class, and an app composes several of them.\n *\n * A RouteModule holds business logic (it configures the router), so it is an interface — the\n * same category as {@link Routes} / {@link Filter}, NOT a data-only class (per the webpieces\n * guidelines).\n *\n * ```ts\n * export class AuthRoutes implements RouteModule {\n * configure(router: WebpiecesRouter): void {\n * router.addFilter(new FilterDefinition(1800, LogApiFilter, '*'));\n * router.addRoutes(AuthApi, AuthController);\n * }\n * }\n * ```\n */\nexport interface RouteModule {\n /** Declare this group's routes + filters via {@link WebpiecesRouter.addRoutes} / addFilter. */\n configure(router: WebpiecesRouter): void;\n}\n\n/**\n * AppModules - an app's COMPLETE server-surface declaration in one object: its DI binding modules,\n * its route groups, and its own context-key headers. It replaces the old split of a\n * `ContainerModule[]` + a `ContextKey[]` + an inline `(router) => void` callback threaded through\n * the bootstrap in separate arguments.\n *\n * Apps implement this on a class with a static `create()` factory, so the real server AND its\n * tests build the SAME object (tests then tweak it / pass a test override module):\n *\n * ```ts\n * export class MyAppModules implements AppModules {\n * static create(): MyAppModules { return new MyAppModules(); }\n * getBindingModules(): ContainerModule[] { return [InversifyModule]; }\n * getRoutingModules(): RouteModule[] { return [new AppRoutes()]; }\n * getHeaders(): ContextKey[] { return AppHeaders.getAllHeaders(); }\n * }\n *\n * // server.ts\n * await bootstrapServer(new BootstrapOptions(8200, 'my-svr'), MyAppModules.create());\n * ```\n *\n * AppModules is a provider interface (it hands back the app's pieces), the same category as the\n * former WebAppMeta — hence an interface, not a data-only class.\n */\nexport interface AppModules {\n /** App-specific DI ContainerModules (beyond the standard company/framework set). */\n getBindingModules(): ContainerModule[];\n /** The route groups to configure onto the router, in order. */\n getRoutingModules(): RouteModule[];\n /** This
|
|
1
|
+
{"version":3,"file":"AppModules.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/AppModules.ts"],"names":[],"mappings":"","sourcesContent":["import { ContainerModule } from 'inversify';\nimport { ContextKey } from '@webpieces/core-util';\nimport { WebpiecesRouter } from './WebpiecesRouter';\n\n/**\n * RouteModule - a reusable, named group of routes + filters, configured onto the\n * {@link WebpiecesRouter}. This is the TypeScript analog of a Java WebPieces \"RouteModule\":\n * instead of one anonymous `(router) => { ... }` block, each cohesive group of routes/filters\n * lives in its own named class, and an app composes several of them.\n *\n * A RouteModule holds business logic (it configures the router), so it is an interface — the\n * same category as {@link Routes} / {@link Filter}, NOT a data-only class (per the webpieces\n * guidelines).\n *\n * ```ts\n * export class AuthRoutes implements RouteModule {\n * configure(router: WebpiecesRouter): void {\n * router.addFilter(new FilterDefinition(1800, LogApiFilter, '*'));\n * router.addRoutes(AuthApi, AuthController);\n * }\n * }\n * ```\n */\nexport interface RouteModule {\n /** Declare this group's routes + filters via {@link WebpiecesRouter.addRoutes} / addFilter. */\n configure(router: WebpiecesRouter): void;\n}\n\n/**\n * AppModules - an app's COMPLETE server-surface declaration in one object: its DI binding modules,\n * its route groups, and its own context-key headers. It replaces the old split of a\n * `ContainerModule[]` + a `ContextKey[]` + an inline `(router) => void` callback threaded through\n * the bootstrap in separate arguments.\n *\n * Apps implement this on a class with a static `create()` factory, so the real server AND its\n * tests build the SAME object (tests then tweak it / pass a test override module):\n *\n * ```ts\n * export class MyAppModules implements AppModules {\n * static create(): MyAppModules { return new MyAppModules(); }\n * getBindingModules(): ContainerModule[] { return [InversifyModule]; }\n * getRoutingModules(): RouteModule[] { return [new AppRoutes()]; }\n * getHeaders(): ContextKey[] { return AppHeaders.getAllHeaders(); }\n * }\n *\n * // server.ts\n * await bootstrapServer(new BootstrapOptions(8200, 'my-svr'), MyAppModules.create());\n * ```\n *\n * AppModules is a provider interface (it hands back the app's pieces), the same category as the\n * former WebAppMeta — hence an interface, not a data-only class.\n */\nexport interface AppModules {\n /** App-specific DI ContainerModules (beyond the standard company/framework set). */\n getBindingModules(): ContainerModule[];\n /** The route groups to configure onto the router, in order. */\n getRoutingModules(): RouteModule[];\n /** This company's own context keys(usually all keys across all servers),\n * registered into the global HeaderRegistry at startup. */\n getHeaders(): ContextKey[];\n}\n"]}
|
package/src/setupRuntime.d.ts
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
import { ContainerModule } from 'inversify';
|
|
2
|
-
import {
|
|
2
|
+
import { LoggerFactory } from '@webpieces/core-util';
|
|
3
3
|
import { WebpiecesConfig } from './WebpiecesConfig';
|
|
4
4
|
import { AppModules } from './AppModules';
|
|
5
5
|
import { ApiFactory } from './ApiFactory';
|
|
6
6
|
/**
|
|
7
7
|
* RuntimeSetupOptions - the environment/wiring inputs to {@link setupRuntime} (everything NOT
|
|
8
|
-
* declared by the app's {@link AppModules}): the logging backend, the
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* declared by the app's {@link AppModules}): the logging backend, whether to include the platform
|
|
9
|
+
* default headers, and config. Data-only structure (a class, per the webpieces guidelines). The
|
|
10
|
+
* app's own binding modules + route groups + headers come from the AppModules passed alongside;
|
|
11
|
+
* the test-override module is the separate `appOverrides` param of {@link setupRuntime}.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Headers: {@link HeaderRegistry.configure} registers the platform defaults (when
|
|
14
|
+
* `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).
|
|
15
15
|
*/
|
|
16
16
|
export declare class RuntimeSetupOptions {
|
|
17
17
|
/** Logging backend to install (LogManager.setFactory). */
|
|
18
18
|
readonly loggerFactory: LoggerFactory;
|
|
19
|
-
/** Org/company-wide shared context keys (the company layer passes these in). */
|
|
20
|
-
readonly companyHeaders: ContextKey[];
|
|
21
19
|
/** Include the webpieces platform default headers. */
|
|
22
20
|
readonly platformHeaders: boolean;
|
|
23
|
-
/** A single DI module loaded LAST so tests can rebind bindings to mocks. */
|
|
24
|
-
readonly appOverrides?: ContainerModule | undefined;
|
|
25
21
|
/** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
|
|
26
22
|
readonly config?: WebpiecesConfig | undefined;
|
|
27
23
|
constructor(
|
|
28
24
|
/** Logging backend to install (LogManager.setFactory). */
|
|
29
25
|
loggerFactory: LoggerFactory,
|
|
30
|
-
/** Org/company-wide shared context keys (the company layer passes these in). */
|
|
31
|
-
companyHeaders?: ContextKey[],
|
|
32
26
|
/** Include the webpieces platform default headers. */
|
|
33
27
|
platformHeaders?: boolean,
|
|
34
|
-
/** A single DI module loaded LAST so tests can rebind bindings to mocks. */
|
|
35
|
-
appOverrides?: ContainerModule | undefined,
|
|
36
28
|
/** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
|
|
37
29
|
config?: WebpiecesConfig | undefined);
|
|
38
30
|
}
|
|
@@ -50,4 +42,7 @@ export declare class RuntimeSetupOptions {
|
|
|
50
42
|
* `createApiClient()` for in-process tests. There is NO express (or any transport) here; a
|
|
51
43
|
* transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.
|
|
52
44
|
*/
|
|
53
|
-
export declare function setupRuntime(options: RuntimeSetupOptions, appModules: AppModules
|
|
45
|
+
export declare function setupRuntime(options: RuntimeSetupOptions, appModules: AppModules,
|
|
46
|
+
/** A single DI module loaded LAST so tests can rebind bindings to mocks.
|
|
47
|
+
* Or special case servers that want to override specific things */
|
|
48
|
+
appOverrides?: ContainerModule): Promise<ApiFactory>;
|
package/src/setupRuntime.js
CHANGED
|
@@ -7,35 +7,27 @@ const WebpiecesConfig_1 = require("./WebpiecesConfig");
|
|
|
7
7
|
const WebpiecesRouter_1 = require("./WebpiecesRouter");
|
|
8
8
|
/**
|
|
9
9
|
* RuntimeSetupOptions - the environment/wiring inputs to {@link setupRuntime} (everything NOT
|
|
10
|
-
* declared by the app's {@link AppModules}): the logging backend, the
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* declared by the app's {@link AppModules}): the logging backend, whether to include the platform
|
|
11
|
+
* default headers, and config. Data-only structure (a class, per the webpieces guidelines). The
|
|
12
|
+
* app's own binding modules + route groups + headers come from the AppModules passed alongside;
|
|
13
|
+
* the test-override module is the separate `appOverrides` param of {@link setupRuntime}.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Headers: {@link HeaderRegistry.configure} registers the platform defaults (when
|
|
16
|
+
* `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).
|
|
17
17
|
*/
|
|
18
18
|
class RuntimeSetupOptions {
|
|
19
19
|
loggerFactory;
|
|
20
|
-
companyHeaders;
|
|
21
20
|
platformHeaders;
|
|
22
|
-
appOverrides;
|
|
23
21
|
config;
|
|
24
22
|
constructor(
|
|
25
23
|
/** Logging backend to install (LogManager.setFactory). */
|
|
26
24
|
loggerFactory,
|
|
27
|
-
/** Org/company-wide shared context keys (the company layer passes these in). */
|
|
28
|
-
companyHeaders = [],
|
|
29
25
|
/** Include the webpieces platform default headers. */
|
|
30
26
|
platformHeaders = true,
|
|
31
|
-
/** A single DI module loaded LAST so tests can rebind bindings to mocks. */
|
|
32
|
-
appOverrides,
|
|
33
27
|
/** Optional WebpiecesConfig (e.g. recording flags); defaults to a fresh one. */
|
|
34
28
|
config) {
|
|
35
29
|
this.loggerFactory = loggerFactory;
|
|
36
|
-
this.companyHeaders = companyHeaders;
|
|
37
30
|
this.platformHeaders = platformHeaders;
|
|
38
|
-
this.appOverrides = appOverrides;
|
|
39
31
|
this.config = config;
|
|
40
32
|
}
|
|
41
33
|
}
|
|
@@ -54,15 +46,18 @@ exports.RuntimeSetupOptions = RuntimeSetupOptions;
|
|
|
54
46
|
* `createApiClient()` for in-process tests. There is NO express (or any transport) here; a
|
|
55
47
|
* transport adapter (e.g. WebpiecesExpressRouter in @webpieces/http-server) serves the result.
|
|
56
48
|
*/
|
|
57
|
-
async function setupRuntime(options, appModules
|
|
49
|
+
async function setupRuntime(options, appModules,
|
|
50
|
+
/** A single DI module loaded LAST so tests can rebind bindings to mocks.
|
|
51
|
+
* Or special case servers that want to override specific things */
|
|
52
|
+
appOverrides) {
|
|
58
53
|
// 1. Register the global HeaderRegistry FIRST (this service's own keys come from AppModules).
|
|
59
|
-
core_util_1.HeaderRegistry.configure(appModules.getHeaders(), options.
|
|
54
|
+
core_util_1.HeaderRegistry.configure(appModules.getHeaders(), options.platformHeaders);
|
|
60
55
|
// 2. Install the logging backend ONCE, before anything else logs.
|
|
61
56
|
core_util_1.LogManager.setFactory(options.loggerFactory);
|
|
62
57
|
// 3. Build the node-only router + DI container.
|
|
63
58
|
const router = await WebpiecesRouter_1.WebpiecesRouterFactory.create({
|
|
64
59
|
appBindings: [...appModules.getBindingModules()],
|
|
65
|
-
appOverrides:
|
|
60
|
+
appOverrides: appOverrides,
|
|
66
61
|
config: options.config ?? new WebpiecesConfig_1.WebpiecesConfig(),
|
|
67
62
|
});
|
|
68
63
|
// 4. Let each route group declare its routes + filters, then hand back the consumer surface.
|
package/src/setupRuntime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupRuntime.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/setupRuntime.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"setupRuntime.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/setupRuntime.ts"],"names":[],"mappings":";;;AA0CA,oCAyBC;AAlED,oDAAiF;AACjF,uDAAoD;AACpD,uDAA2D;AAI3D;;;;;;;;;GASG;AACH,MAAa,mBAAmB;IAGR;IAEA;IAEA;IANpB;IACI,0DAA0D;IAC1C,aAA4B;IAC5C,sDAAsD;IACtC,kBAA2B,IAAI;IAC/C,gFAAgF;IAChE,MAAwB;QAJxB,kBAAa,GAAb,aAAa,CAAe;QAE5B,oBAAe,GAAf,eAAe,CAAgB;QAE/B,WAAM,GAAN,MAAM,CAAkB;IACzC,CAAC;CACP;AATD,kDASC;AAED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,YAAY,CAC9B,OAA4B,EAC5B,UAAsB;AACtB;mEACmE;AACnE,YAA8B;IAE9B,8FAA8F;IAC9F,0BAAc,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAE3E,kEAAkE;IAClE,sBAAU,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAE7C,gDAAgD;IAChD,MAAM,MAAM,GAAG,MAAM,wCAAsB,CAAC,MAAM,CAAC;QAC/C,WAAW,EAAE,CAAC,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;QAChD,YAAY,EAAE,YAAY;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,iCAAe,EAAE;KAClD,CAAC,CAAC;IAEH,6FAA6F;IAC7F,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,iBAAiB,EAAE,EAAE,CAAC;QACvD,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { ContainerModule } from 'inversify';\nimport { HeaderRegistry, LoggerFactory, LogManager } from '@webpieces/core-util';\nimport { WebpiecesConfig } from './WebpiecesConfig';\nimport { WebpiecesRouterFactory } from './WebpiecesRouter';\nimport { AppModules } from './AppModules';\nimport { ApiFactory } from './ApiFactory';\n\n/**\n * RuntimeSetupOptions - the environment/wiring inputs to {@link setupRuntime} (everything NOT\n * declared by the app's {@link AppModules}): the logging backend, whether to include the platform\n * default headers, and config. Data-only structure (a class, per the webpieces guidelines). The\n * app's own binding modules + route groups + headers come from the AppModules passed alongside;\n * the test-override module is the separate `appOverrides` param of {@link setupRuntime}.\n *\n * Headers: {@link HeaderRegistry.configure} registers the platform defaults (when\n * `platformHeaders` is true) plus AppModules.getHeaders() (by convention the company-wide set).\n */\nexport class RuntimeSetupOptions {\n constructor(\n /** Logging backend to install (LogManager.setFactory). */\n public readonly loggerFactory: LoggerFactory,\n /** Include the webpieces platform default headers. */\n public readonly platformHeaders: boolean = true,\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 (from appModules.getBindingModules())\n * 4. configure each appModules.getRoutingModules() onto the router (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 appModules: AppModules,\n /** A single DI module loaded LAST so tests can rebind bindings to mocks.\n * Or special case servers that want to override specific things */\n appOverrides?: ContainerModule,\n): Promise<ApiFactory> {\n // 1. Register the global HeaderRegistry FIRST (this service's own keys come from AppModules).\n HeaderRegistry.configure(appModules.getHeaders(), 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: [...appModules.getBindingModules()],\n appOverrides: appOverrides,\n config: options.config ?? new WebpiecesConfig(),\n });\n\n // 4. Let each route group declare its routes + filters, then hand back the consumer surface.\n for (const routeModule of appModules.getRoutingModules()) {\n routeModule.configure(router);\n }\n return router;\n}\n"]}
|