@webpieces/core-context 0.3.334 → 0.3.336
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/provide.d.ts +1 -1
- package/src/provide.js +1 -1
- package/src/provide.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.336",
|
|
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.336",
|
|
26
26
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
27
27
|
"inversify": "7.10.4",
|
|
28
28
|
"reflect-metadata": "0.2.2"
|
package/src/provide.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare function provideTransient(): ClassDecorator;
|
|
|
71
71
|
* would hand back the first instance.
|
|
72
72
|
*
|
|
73
73
|
* `get()` is SYNCHRONOUS, like Guice's. An async `get()` would force every consumer (e.g.
|
|
74
|
-
* `ClientHttpFactory.
|
|
74
|
+
* `ClientHttpFactory.createRpcClient`) to become async, and neither Angular's `useFactory` nor
|
|
75
75
|
* inversify's `toDynamicValue` can await.
|
|
76
76
|
*
|
|
77
77
|
* TypeScript erases generics, so `Provider<T>` has NO runtime identity and cannot itself be a DI
|
package/src/provide.js
CHANGED
|
@@ -94,7 +94,7 @@ function provideTransient() {
|
|
|
94
94
|
* would hand back the first instance.
|
|
95
95
|
*
|
|
96
96
|
* `get()` is SYNCHRONOUS, like Guice's. An async `get()` would force every consumer (e.g.
|
|
97
|
-
* `ClientHttpFactory.
|
|
97
|
+
* `ClientHttpFactory.createRpcClient`) to become async, and neither Angular's `useFactory` nor
|
|
98
98
|
* inversify's `toDynamicValue` can await.
|
|
99
99
|
*
|
|
100
100
|
* TypeScript erases generics, so `Provider<T>` has NO runtime identity and cannot itself be a DI
|
package/src/provide.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provide.js","sourceRoot":"","sources":["../../../../../packages/core/core-context/src/provide.ts"],"names":[],"mappings":";;;AAyBA,4CAKC;AAsBD,sEAEC;AAcD,4CASC;AA7ED,4BAA0B;AAC1B,wEAA0D;AAG1D;;;;;;;GAOG;AAEH;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB;IAC5B,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,OAAO,IAAA,4BAAO,EAAC,MAAM,EAAE,CAAC,IAAuC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACzG,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,8FAA8F;AAC9F,SAAgB,6BAA6B,CAAI,iBAAuC;IACpF,OAAO,IAAA,4BAAO,EAAC,iBAAiB,EAAE,CAAC,IAAiC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;AACtG,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB;IAC5B,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,uFAAuF;QACvF,qFAAqF;QACrF,wEAAwE;QACxE,+FAA+F;QAC/F,OAAO,IAAA,4BAAO,EAAC,MAAM,EAAE,CAAC,IAAuC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACzG,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,QAAQ;IACY;IAA7B,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,GAAG;QACC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACJ;AAND,4BAMC","sourcesContent":["import 'reflect-metadata';\nimport { provide } from '@inversifyjs/binding-decorators';\nimport type { BindInWhenOnFluentSyntax, ServiceIdentifier } from 'inversify';\n\n/**\n * DI provider decorators (the lightweight DI seam shared across webpieces).\n *\n * These live in @webpieces/core-context — the lowest package that already owns\n * request-scoped context — so libraries (cloudtasks-client, http-client, …) can\n * register singletons WITHOUT depending on the server-side @webpieces/http-routing\n * package. http-routing re-exports them for back-compat.\n */\n\n/**\n * Provides a singleton-scoped dependency.\n * When called without arguments, the decorated class binds to itself.\n *\n * Usage:\n * ```typescript\n * @provideSingleton()\n * export class SaveController {\n * // ...\n * }\n * ```\n */\nexport function provideSingleton(): ClassDecorator {\n // webpieces-disable no-any-unknown -- decorator target is any class constructor\n return (target: any) => {\n return provide(target, (bind: BindInWhenOnFluentSyntax<unknown>) => bind.inSingletonScope())(target);\n };\n}\n\n/**\n * Marks this class as the DEFAULT (overridable) singleton implementation OF a contract token\n * (a Symbol or an abstract class). Binds `token -> thisClass` as a singleton. Guice's\n * `@ImplementedBy`, done impl-side so the api never imports the impl (no cycle).\n *\n * An app overrides the default via appOverrides, same idiom as AuthConfig:\n * `(await options.rebind(TOKEN)).to(OtherImpl)`.\n *\n * The DI-graph designer reads this in pass 1, so `@inject(TOKEN)` renders as `TOKEN (thisClass)`\n * and expands this class's own dependencies instead of dead-ending as unresolved.\n *\n * Usage:\n * ```typescript\n * import { SOME_API_TOKEN } from '@myorg/some-api';\n *\n * @provideSingletonDefaultForApi(SOME_API_TOKEN)\n * export class SomeApiImpl { ... }\n * ```\n */\n// webpieces-disable no-function-outside-class -- a decorator factory cannot be a class method\nexport function provideSingletonDefaultForApi<T>(serviceIdentifier: ServiceIdentifier<T>): ClassDecorator {\n return provide(serviceIdentifier, (bind: BindInWhenOnFluentSyntax<T>) => bind.inSingletonScope());\n}\n\n/**\n * Provides a transient-scoped dependency (new instance every time).\n * When called without arguments, the decorated class binds to itself.\n *\n * Usage:\n * ```typescript\n * @provideTransient()\n * export class TransientController {\n * // ...\n * }\n * ```\n */\nexport function provideTransient(): ClassDecorator {\n // webpieces-disable no-any-unknown -- decorator target is any class constructor\n return (target: any) => {\n // Call inTransientScope() EXPLICITLY. Omitting the scope call inherits the container's\n // defaultScope which, while Transient by default in inversify 7, would silently flip\n // meaning if anyone ever passed `new Container({ defaultScope: ... })`.\n // webpieces-disable no-any-unknown -- inversify's own fluent-syntax generic for a self-binding\n return provide(target, (bind: BindInWhenOnFluentSyntax<unknown>) => bind.inTransientScope())(target);\n };\n}\n\n/**\n * Provider<T> — Guice's object-oriented `Provider<T>`, which inversify does not have.\n *\n * Inversify's own `Provider<T>` is a FUNCTION type `(...args) => Promise<T>` and its\n * `toProvider()` binding is deprecated (\"Providers will be removed in v8\"), so we model\n * Guice's seam ourselves.\n *\n * It caches NOTHING, because `ResolutionContext.get()` already applies the BOUND SCOPE of `T`:\n *\n * T bound @provideFrameworkSingleton -> every get() returns the SAME instance, built on the\n * first call. That is a LAZY SINGLETON.\n * T bound @provideFrameworkTransient -> every get() builds a NEW instance. That is 1-to-many.\n *\n * A provider that cached internally would break the transient case outright: the second get()\n * would hand back the first instance.\n *\n * `get()` is SYNCHRONOUS, like Guice's. An async `get()` would force every consumer (e.g.\n * `ClientHttpFactory.
|
|
1
|
+
{"version":3,"file":"provide.js","sourceRoot":"","sources":["../../../../../packages/core/core-context/src/provide.ts"],"names":[],"mappings":";;;AAyBA,4CAKC;AAsBD,sEAEC;AAcD,4CASC;AA7ED,4BAA0B;AAC1B,wEAA0D;AAG1D;;;;;;;GAOG;AAEH;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB;IAC5B,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,OAAO,IAAA,4BAAO,EAAC,MAAM,EAAE,CAAC,IAAuC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACzG,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,8FAA8F;AAC9F,SAAgB,6BAA6B,CAAI,iBAAuC;IACpF,OAAO,IAAA,4BAAO,EAAC,iBAAiB,EAAE,CAAC,IAAiC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;AACtG,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB;IAC5B,gFAAgF;IAChF,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,uFAAuF;QACvF,qFAAqF;QACrF,wEAAwE;QACxE,+FAA+F;QAC/F,OAAO,IAAA,4BAAO,EAAC,MAAM,EAAE,CAAC,IAAuC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACzG,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,QAAQ;IACY;IAA7B,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,GAAG;QACC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACJ;AAND,4BAMC","sourcesContent":["import 'reflect-metadata';\nimport { provide } from '@inversifyjs/binding-decorators';\nimport type { BindInWhenOnFluentSyntax, ServiceIdentifier } from 'inversify';\n\n/**\n * DI provider decorators (the lightweight DI seam shared across webpieces).\n *\n * These live in @webpieces/core-context — the lowest package that already owns\n * request-scoped context — so libraries (cloudtasks-client, http-client, …) can\n * register singletons WITHOUT depending on the server-side @webpieces/http-routing\n * package. http-routing re-exports them for back-compat.\n */\n\n/**\n * Provides a singleton-scoped dependency.\n * When called without arguments, the decorated class binds to itself.\n *\n * Usage:\n * ```typescript\n * @provideSingleton()\n * export class SaveController {\n * // ...\n * }\n * ```\n */\nexport function provideSingleton(): ClassDecorator {\n // webpieces-disable no-any-unknown -- decorator target is any class constructor\n return (target: any) => {\n return provide(target, (bind: BindInWhenOnFluentSyntax<unknown>) => bind.inSingletonScope())(target);\n };\n}\n\n/**\n * Marks this class as the DEFAULT (overridable) singleton implementation OF a contract token\n * (a Symbol or an abstract class). Binds `token -> thisClass` as a singleton. Guice's\n * `@ImplementedBy`, done impl-side so the api never imports the impl (no cycle).\n *\n * An app overrides the default via appOverrides, same idiom as AuthConfig:\n * `(await options.rebind(TOKEN)).to(OtherImpl)`.\n *\n * The DI-graph designer reads this in pass 1, so `@inject(TOKEN)` renders as `TOKEN (thisClass)`\n * and expands this class's own dependencies instead of dead-ending as unresolved.\n *\n * Usage:\n * ```typescript\n * import { SOME_API_TOKEN } from '@myorg/some-api';\n *\n * @provideSingletonDefaultForApi(SOME_API_TOKEN)\n * export class SomeApiImpl { ... }\n * ```\n */\n// webpieces-disable no-function-outside-class -- a decorator factory cannot be a class method\nexport function provideSingletonDefaultForApi<T>(serviceIdentifier: ServiceIdentifier<T>): ClassDecorator {\n return provide(serviceIdentifier, (bind: BindInWhenOnFluentSyntax<T>) => bind.inSingletonScope());\n}\n\n/**\n * Provides a transient-scoped dependency (new instance every time).\n * When called without arguments, the decorated class binds to itself.\n *\n * Usage:\n * ```typescript\n * @provideTransient()\n * export class TransientController {\n * // ...\n * }\n * ```\n */\nexport function provideTransient(): ClassDecorator {\n // webpieces-disable no-any-unknown -- decorator target is any class constructor\n return (target: any) => {\n // Call inTransientScope() EXPLICITLY. Omitting the scope call inherits the container's\n // defaultScope which, while Transient by default in inversify 7, would silently flip\n // meaning if anyone ever passed `new Container({ defaultScope: ... })`.\n // webpieces-disable no-any-unknown -- inversify's own fluent-syntax generic for a self-binding\n return provide(target, (bind: BindInWhenOnFluentSyntax<unknown>) => bind.inTransientScope())(target);\n };\n}\n\n/**\n * Provider<T> — Guice's object-oriented `Provider<T>`, which inversify does not have.\n *\n * Inversify's own `Provider<T>` is a FUNCTION type `(...args) => Promise<T>` and its\n * `toProvider()` binding is deprecated (\"Providers will be removed in v8\"), so we model\n * Guice's seam ourselves.\n *\n * It caches NOTHING, because `ResolutionContext.get()` already applies the BOUND SCOPE of `T`:\n *\n * T bound @provideFrameworkSingleton -> every get() returns the SAME instance, built on the\n * first call. That is a LAZY SINGLETON.\n * T bound @provideFrameworkTransient -> every get() builds a NEW instance. That is 1-to-many.\n *\n * A provider that cached internally would break the transient case outright: the second get()\n * would hand back the first instance.\n *\n * `get()` is SYNCHRONOUS, like Guice's. An async `get()` would force every consumer (e.g.\n * `ClientHttpFactory.createRpcClient`) to become async, and neither Angular's `useFactory` nor\n * inversify's `toDynamicValue` can await.\n *\n * TypeScript erases generics, so `Provider<T>` has NO runtime identity and cannot itself be a DI\n * token. Register it against a Symbol naming T, with {@link bindFrameworkProvider}, and inject it\n * by that token — the declared type is what a reader needs, the Symbol is what inversify needs:\n *\n * ```typescript\n * // webpieces-disable no-symbol-di-tokens -- Provider<T> is erased at runtime; T names the token\n * export const TASK_PROXY_PROVIDER = Symbol.for('TaskProxyClientProvider');\n * bindFrameworkProvider(TASK_PROXY_PROVIDER, TaskProxyClient);\n *\n * constructor(@inject(TASK_PROXY_PROVIDER) private readonly provider: Provider<TaskProxyClient>) {}\n * ```\n *\n * Inject a Provider when you need a dependency LATER or REPEATEDLY rather than at construction\n * time — a lazily-created singleton, or a fresh instance per call.\n */\nexport class Provider<T> {\n constructor(private readonly resolve: () => T) {}\n\n get(): T {\n return this.resolve();\n }\n}\n"]}
|