@webpieces/core-context 0.3.279 → 0.3.281
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 +2 -2
- package/src/frameworkProvide.d.ts +18 -0
- package/src/frameworkProvide.js +51 -0
- package/src/frameworkProvide.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +7 -1
- package/src/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/core-context",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.281",
|
|
4
4
|
"description": "AsyncLocalStorage-based context management for request-scoped data",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@webpieces/core-util": "0.3.
|
|
25
|
+
"@webpieces/core-util": "0.3.281",
|
|
26
26
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
27
27
|
"inversify": "7.10.4",
|
|
28
28
|
"reflect-metadata": "0.2.2"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContainerModule } from 'inversify';
|
|
2
|
+
import type { ServiceIdentifier } from 'inversify';
|
|
3
|
+
/**
|
|
4
|
+
* Framework equivalent of @provideSingleton: registers the class as a singleton bound to
|
|
5
|
+
* itself, into the webpieces framework registry (NOT the binding-decorators global one).
|
|
6
|
+
*/
|
|
7
|
+
export declare function provideFrameworkSingleton(): ClassDecorator;
|
|
8
|
+
/**
|
|
9
|
+
* Framework equivalent of @provideSingletonAs: binds the impl to a token (Symbol or abstract
|
|
10
|
+
* class) as a singleton, into the webpieces framework registry.
|
|
11
|
+
*/
|
|
12
|
+
export declare function provideFrameworkSingletonAs<T>(serviceIdentifier: ServiceIdentifier<T>): ClassDecorator;
|
|
13
|
+
/**
|
|
14
|
+
* Build a ContainerModule binding every provideFrameworkSingleton(As) class. Load this into
|
|
15
|
+
* the webpieces framework + app containers (the router does this) alongside the client's own
|
|
16
|
+
* buildProviderModule().
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildFrameworkModule(): ContainerModule;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.provideFrameworkSingleton = provideFrameworkSingleton;
|
|
4
|
+
exports.provideFrameworkSingletonAs = provideFrameworkSingletonAs;
|
|
5
|
+
exports.buildFrameworkModule = buildFrameworkModule;
|
|
6
|
+
const inversify_1 = require("inversify");
|
|
7
|
+
class FrameworkBinding {
|
|
8
|
+
serviceIdentifier;
|
|
9
|
+
target;
|
|
10
|
+
constructor(serviceIdentifier, target) {
|
|
11
|
+
this.serviceIdentifier = serviceIdentifier;
|
|
12
|
+
this.target = target;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The webpieces-only binding registry (a plain module-level list, one per hosted core-context). */
|
|
16
|
+
const frameworkRegistry = [];
|
|
17
|
+
/**
|
|
18
|
+
* Framework equivalent of @provideSingleton: registers the class as a singleton bound to
|
|
19
|
+
* itself, into the webpieces framework registry (NOT the binding-decorators global one).
|
|
20
|
+
*/
|
|
21
|
+
function provideFrameworkSingleton() {
|
|
22
|
+
// webpieces-disable no-any-unknown -- decorator target is any class constructor
|
|
23
|
+
return (target) => {
|
|
24
|
+
frameworkRegistry.push(new FrameworkBinding(target, target));
|
|
25
|
+
return target;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Framework equivalent of @provideSingletonAs: binds the impl to a token (Symbol or abstract
|
|
30
|
+
* class) as a singleton, into the webpieces framework registry.
|
|
31
|
+
*/
|
|
32
|
+
function provideFrameworkSingletonAs(serviceIdentifier) {
|
|
33
|
+
// webpieces-disable no-any-unknown -- decorator target is any class constructor
|
|
34
|
+
return (target) => {
|
|
35
|
+
frameworkRegistry.push(new FrameworkBinding(serviceIdentifier, target));
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a ContainerModule binding every provideFrameworkSingleton(As) class. Load this into
|
|
41
|
+
* the webpieces framework + app containers (the router does this) alongside the client's own
|
|
42
|
+
* buildProviderModule().
|
|
43
|
+
*/
|
|
44
|
+
function buildFrameworkModule() {
|
|
45
|
+
return new inversify_1.ContainerModule((options) => {
|
|
46
|
+
for (const binding of frameworkRegistry) {
|
|
47
|
+
options.bind(binding.serviceIdentifier).to(binding.target).inSingletonScope();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=frameworkProvide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameworkProvide.js","sourceRoot":"","sources":["../../../../../packages/core/core-context/src/frameworkProvide.ts"],"names":[],"mappings":";;AAoCA,8DAMC;AAMD,kEAMC;AAOD,oDAMC;AAnED,yCAA4C;AAsB5C,MAAM,gBAAgB;IAEE;IACA;IAFpB,YACoB,iBAAoC,EACpC,MAAe;QADf,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAS;IAChC,CAAC;CACP;AAED,oGAAoG;AACpG,MAAM,iBAAiB,GAAuB,EAAE,CAAC;AAEjD;;;GAGG;AACH,SAAgB,yBAAyB;IACrC,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,iBAAiB,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7D,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAgB,2BAA2B,CAAI,iBAAuC;IAClF,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,iBAAiB,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;QACxE,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB;IAChC,OAAO,IAAI,2BAAe,CAAC,CAAC,OAAmC,EAAE,EAAE;QAC/D,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;YACtC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAClF,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { ContainerModule } from 'inversify';\nimport type { ContainerModuleLoadOptions, ServiceIdentifier } from 'inversify';\n\n/**\n * Framework-only DI provider decorators — a SEPARATE registry from the client-facing\n * @provideSingleton (which uses @inversifyjs/binding-decorators' single global registry).\n *\n * WHY: binding-decorators registers every @provideSingleton class under ONE global\n * reflect-metadata key, and buildProviderModule() scoops up that whole key. If webpieces\n * framework classes (RouteBuilderImpl, the filters, WebpiecesRouter) used @provideSingleton,\n * a CLIENT app's buildProviderModule() would drag those framework internals into its own\n * container. To keep the two worlds separate:\n * - packages/** (framework libs) MUST use provideFrameworkSingleton (this registry),\n * enforced by the no-global-providesingleton-in-packages ESLint rule.\n * - apps/** (and downstream client projects) use plain @provideSingleton (the global one).\n * The router loads BOTH buildFrameworkModule() and buildProviderModule(), so everything\n * resolves — but a client's buildProviderModule() only ever sees the client's own classes.\n */\n\n// webpieces-disable no-any-unknown -- decorator targets are arbitrary class constructors\ntype AnyCtor = new (...args: any[]) => unknown;\n\nclass FrameworkBinding {\n constructor(\n public readonly serviceIdentifier: ServiceIdentifier,\n public readonly target: AnyCtor,\n ) {}\n}\n\n/** The webpieces-only binding registry (a plain module-level list, one per hosted core-context). */\nconst frameworkRegistry: FrameworkBinding[] = [];\n\n/**\n * Framework equivalent of @provideSingleton: registers the class as a singleton bound to\n * itself, into the webpieces framework registry (NOT the binding-decorators global one).\n */\nexport function provideFrameworkSingleton(): ClassDecorator {\n // webpieces-disable no-any-unknown -- decorator target is any class constructor\n return (target: any) => {\n frameworkRegistry.push(new FrameworkBinding(target, target));\n return target;\n };\n}\n\n/**\n * Framework equivalent of @provideSingletonAs: binds the impl to a token (Symbol or abstract\n * class) as a singleton, into the webpieces framework registry.\n */\nexport function provideFrameworkSingletonAs<T>(serviceIdentifier: ServiceIdentifier<T>): ClassDecorator {\n // webpieces-disable no-any-unknown -- decorator target is any class constructor\n return (target: any) => {\n frameworkRegistry.push(new FrameworkBinding(serviceIdentifier, target));\n return target;\n };\n}\n\n/**\n * Build a ContainerModule binding every provideFrameworkSingleton(As) class. Load this into\n * the webpieces framework + app containers (the router does this) alongside the client's own\n * buildProviderModule().\n */\nexport function buildFrameworkModule(): ContainerModule {\n return new ContainerModule((options: ContainerModuleLoadOptions) => {\n for (const binding of frameworkRegistry) {\n options.bind(binding.serviceIdentifier).to(binding.target).inSingletonScope();\n }\n });\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { RequestContext } from './RequestContext';
|
|
2
2
|
export { provideSingleton, provideSingletonAs, provideTransient } from './provide';
|
|
3
|
+
export { provideFrameworkSingleton, provideFrameworkSingletonAs, buildFrameworkModule, } from './frameworkProvide';
|
|
3
4
|
export { ContextMgr, RequestIdChainProcessor } from '@webpieces/core-util';
|
|
4
5
|
export { RequestContextReader } from './RequestContextReader';
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestContextReader = exports.RequestIdChainProcessor = exports.ContextMgr = exports.provideTransient = exports.provideSingletonAs = exports.provideSingleton = exports.RequestContext = void 0;
|
|
3
|
+
exports.RequestContextReader = exports.RequestIdChainProcessor = exports.ContextMgr = exports.buildFrameworkModule = exports.provideFrameworkSingletonAs = exports.provideFrameworkSingleton = exports.provideTransient = exports.provideSingletonAs = exports.provideSingleton = exports.RequestContext = void 0;
|
|
4
4
|
// Context management with AsyncLocalStorage
|
|
5
5
|
var RequestContext_1 = require("./RequestContext");
|
|
6
6
|
Object.defineProperty(exports, "RequestContext", { enumerable: true, get: function () { return RequestContext_1.RequestContext; } });
|
|
@@ -9,6 +9,12 @@ var provide_1 = require("./provide");
|
|
|
9
9
|
Object.defineProperty(exports, "provideSingleton", { enumerable: true, get: function () { return provide_1.provideSingleton; } });
|
|
10
10
|
Object.defineProperty(exports, "provideSingletonAs", { enumerable: true, get: function () { return provide_1.provideSingletonAs; } });
|
|
11
11
|
Object.defineProperty(exports, "provideTransient", { enumerable: true, get: function () { return provide_1.provideTransient; } });
|
|
12
|
+
// Framework-only DI registry (packages/** use these; keeps framework classes out of a
|
|
13
|
+
// client's buildProviderModule() global scan). See frameworkProvide.ts.
|
|
14
|
+
var frameworkProvide_1 = require("./frameworkProvide");
|
|
15
|
+
Object.defineProperty(exports, "provideFrameworkSingleton", { enumerable: true, get: function () { return frameworkProvide_1.provideFrameworkSingleton; } });
|
|
16
|
+
Object.defineProperty(exports, "provideFrameworkSingletonAs", { enumerable: true, get: function () { return frameworkProvide_1.provideFrameworkSingletonAs; } });
|
|
17
|
+
Object.defineProperty(exports, "buildFrameworkModule", { enumerable: true, get: function () { return frameworkProvide_1.buildFrameworkModule; } });
|
|
12
18
|
// Outbound-header machinery — MOVED to browser+node @webpieces/core-util so the
|
|
13
19
|
// isomorphic http-client can use ContextMgr without pulling in this Node-only
|
|
14
20
|
// (AsyncLocalStorage) package. Re-exported here for back-compat.
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-context/src/index.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,mFAAmF;AACnF,qCAAmF;AAA1E,2GAAA,gBAAgB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,2GAAA,gBAAgB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-context/src/index.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,mFAAmF;AACnF,qCAAmF;AAA1E,2GAAA,gBAAgB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAC/D,sFAAsF;AACtF,wEAAwE;AACxE,uDAI4B;AAHxB,6HAAA,yBAAyB,OAAA;AACzB,+HAAA,2BAA2B,OAAA;AAC3B,wHAAA,oBAAoB,OAAA;AAGxB,gFAAgF;AAChF,8EAA8E;AAC9E,iEAAiE;AACjE,kDAA2E;AAAlE,uGAAA,UAAU,OAAA;AAAE,oHAAA,uBAAuB,OAAA;AAC5C,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA","sourcesContent":["// Context management with AsyncLocalStorage\nexport { RequestContext } from './RequestContext';\n\n// DI provider decorators (shared DI seam; http-routing re-exports for back-compat)\nexport { provideSingleton, provideSingletonAs, provideTransient } from './provide';\n// Framework-only DI registry (packages/** use these; keeps framework classes out of a\n// client's buildProviderModule() global scan). See frameworkProvide.ts.\nexport {\n provideFrameworkSingleton,\n provideFrameworkSingletonAs,\n buildFrameworkModule,\n} from './frameworkProvide';\n\n// Outbound-header machinery — MOVED to browser+node @webpieces/core-util so the\n// isomorphic http-client can use ContextMgr without pulling in this Node-only\n// (AsyncLocalStorage) package. Re-exported here for back-compat.\nexport { ContextMgr, RequestIdChainProcessor } from '@webpieces/core-util';\nexport { RequestContextReader } from './RequestContextReader';\n"]}
|