async-injection 1.2.7 → 1.5.0
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/Changelog.md +11 -2
- package/License.txt +1 -1
- package/ReadMe.md +9 -5
- package/lib/cjs/async-factory-provider.js.map +1 -1
- package/lib/cjs/bindable-provider.js +6 -6
- package/lib/cjs/bindable-provider.js.map +1 -1
- package/lib/cjs/binder.d.ts +1 -1
- package/lib/cjs/binder.js.map +1 -1
- package/lib/cjs/class-provider.d.ts +5 -3
- package/lib/cjs/class-provider.js +6 -7
- package/lib/cjs/class-provider.js.map +1 -1
- package/lib/cjs/constant-provider.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/container.d.ts +30 -2
- package/lib/cjs/container.js +59 -9
- package/lib/cjs/container.js.map +1 -1
- package/lib/cjs/decorators.d.ts +13 -0
- package/lib/cjs/decorators.js +33 -1
- package/lib/cjs/decorators.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/injector.d.ts +10 -1
- package/lib/cjs/injector.js +15 -0
- package/lib/cjs/injector.js.map +1 -1
- package/lib/cjs/provider.d.ts +8 -0
- package/lib/cjs/provider.js +26 -0
- package/lib/cjs/provider.js.map +1 -1
- package/lib/cjs/state.js +1 -1
- package/lib/cjs/state.js.map +1 -1
- package/lib/cjs/sync-factory-provider.js.map +1 -1
- package/lib/cjs/utils.d.ts +12 -0
- package/lib/cjs/utils.js +29 -2
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/async-factory-provider.js.map +1 -1
- package/lib/esm/bindable-provider.js +4 -4
- package/lib/esm/bindable-provider.js.map +1 -1
- package/lib/esm/binder.d.ts +1 -1
- package/lib/esm/binder.js.map +1 -1
- package/lib/esm/class-provider.d.ts +5 -3
- package/lib/esm/class-provider.js +3 -4
- package/lib/esm/class-provider.js.map +1 -1
- package/lib/esm/constant-provider.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/container.d.ts +30 -2
- package/lib/esm/container.js +58 -8
- package/lib/esm/container.js.map +1 -1
- package/lib/esm/decorators.d.ts +13 -0
- package/lib/esm/decorators.js +32 -1
- package/lib/esm/decorators.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/injector.d.ts +10 -1
- package/lib/esm/injector.js +13 -1
- package/lib/esm/injector.js.map +1 -1
- package/lib/esm/provider.d.ts +8 -0
- package/lib/esm/provider.js +26 -0
- package/lib/esm/provider.js.map +1 -1
- package/lib/esm/state.js +1 -1
- package/lib/esm/state.js.map +1 -1
- package/lib/esm/sync-factory-provider.js.map +1 -1
- package/lib/esm/utils.d.ts +12 -0
- package/lib/esm/utils.js +26 -0
- package/lib/esm/utils.js.map +1 -1
- package/package.json +13 -13
package/lib/esm/injector.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Allow for implicit typing of constants and interfaces.
|
|
3
|
+
* Inspired by Angular and some colleges at work.
|
|
4
|
+
*/
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
export class InjectionToken {
|
|
7
|
+
constructor(id) {
|
|
8
|
+
this.id = id;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return this.id.toString();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
2
14
|
//# sourceMappingURL=injector.js.map
|
package/lib/esm/injector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../../src/injector.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * This is about as close as we can get in Typescript\n */\nexport type AbstractConstructor<T> = Function & { prototype: T }; // eslint-disable-line @typescript-eslint/ban-types\n/**\n * Standard definition of a constructor.\n */\nexport type ClassConstructor<T> = new (...args: any[]) => T;\n\n/**\n * Universal id that can be bound to a constant, class, or factories.\n */\nexport type InjectableId<T> = string | symbol | AbstractConstructor<T> | ClassConstructor<T>;\n\n/**\n * Retrieve instances previously bound to the specified InjectableId.\n */\nexport interface Injector {\n\t/**\n\t * Check to see if the existing InjectableId is known (aka has been bound).\n\t * Error callbacks may wish to know if a particular InjectableId is available.\n\t * Also the Binder's bindXXX calls always overwrite any previous bindings, so you may want to use this as a gate.\n\t *\n\t * @param id The id to check for.\n\t * @param ascending If true, this will search up the chain of parent containers (if they exist). Default is false (only checks if the id is bound within this container).\n\t */\n\tisIdKnown<T>(id: InjectableId<T> | AbstractConstructor<T>, ascending?: boolean): boolean;\n\n\t/**\n\t * Return an instance of <T> previously bound to 'id'.\n\t *\n\t * @throws Error if the InjectableId was never registered, OR if there are unresolved asynchronous dependencies in the dependency tree for 'id'.\n\t */\n\tget<T>(id: InjectableId<T> | AbstractConstructor<T>): T;\n\n\t/**\n\t * awaits the asynchronous resolution of all dependencies in the tree for 'id'.\n\t */\n\tresolve<T>(id?: InjectableId<T> | AbstractConstructor<T>): Promise<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../../src/injector.ts"],"names":[],"mappings":"AASA;;;GAGG;AACF,6DAA6D;AAC9D,MAAM,OAAO,cAAc;IAC1B,YAAoB,EAAmB;QAAnB,OAAE,GAAF,EAAE,CAAiB;IACvC,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;CACD","sourcesContent":["/**\n * This is about as close as we can get in Typescript\n */\nexport type AbstractConstructor<T> = Function & { prototype: T }; // eslint-disable-line @typescript-eslint/ban-types\n/**\n * Standard definition of a constructor.\n */\nexport type ClassConstructor<T> = new (...args: any[]) => T;\n\n/**\n * Allow for implicit typing of constants and interfaces.\n * Inspired by Angular and some colleges at work.\n */\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport class InjectionToken<T> {\n\tconstructor(private id: string | symbol) {\n\t}\n\n\ttoString(): string {\n\t\treturn this.id.toString();\n\t}\n}\n\n/**\n * Universal id that can be bound to a constant, class, or factories.\n */\nexport type InjectableId<T> = string | symbol | AbstractConstructor<T> | ClassConstructor<T> | InjectionToken<T>;\n\n/**\n * Retrieve instances previously bound to the specified InjectableId.\n */\nexport interface Injector {\n\t/**\n\t * Check to see if the existing InjectableId is known (aka has been bound).\n\t * Error callbacks may wish to know if a particular InjectableId is available.\n\t * Also the Binder's bindXXX calls always overwrite any previous bindings, so you may want to use this as a gate.\n\t *\n\t * @param id The id to check for.\n\t * @param ascending If true, this will search up the chain of parent containers (if they exist). Default is false (only checks if the id is bound within this container).\n\t */\n\tisIdKnown<T>(id: InjectableId<T> | AbstractConstructor<T>, ascending?: boolean): boolean;\n\n\t/**\n\t * Return an instance of <T> previously bound to 'id'.\n\t *\n\t * @throws Error if the InjectableId was never registered, OR if there are unresolved asynchronous dependencies in the dependency tree for 'id'.\n\t */\n\tget<T>(id: InjectableId<T> | AbstractConstructor<T>): T;\n\n\t/**\n\t * awaits the asynchronous resolution of all dependencies in the tree for 'id'.\n\t */\n\tresolve<T>(id?: InjectableId<T> | AbstractConstructor<T>): Promise<T>;\n}\n"]}
|
package/lib/esm/provider.d.ts
CHANGED
|
@@ -26,4 +26,12 @@ export declare abstract class Provider<T = any> {
|
|
|
26
26
|
* @returns A completion Promise if initialization requires asynchronicity, otherwise the return value is undefined.
|
|
27
27
|
*/
|
|
28
28
|
resolveIfSingleton(asyncOnly: boolean): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* If (and only if) this Provider has been configured as a Singleton, and if it has been (or is being resolved), find and invoke the @Release decorated method (if there is one).
|
|
31
|
+
* NOTE that if the singleton is actively being resolved when this method is called, this method waits for the resolution to complete and then invokes the @Release decorated method; But in any case this is a synchronous method and returns immediately to it's caller.
|
|
32
|
+
* Also note that invoking this method does not release or invalidate the Provider;
|
|
33
|
+
* Rather, it resets a Singleton Provider to a fresh (unresolved/unqueried) state (aka sets this.singleton to null).
|
|
34
|
+
* It is assumed that the Singleton itself will no longer be used after this method returns.
|
|
35
|
+
*/
|
|
36
|
+
releaseIfSingleton(): void;
|
|
29
37
|
}
|
package/lib/esm/provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InvokeReleaseMethod } from './utils';
|
|
1
2
|
/**
|
|
2
3
|
* Internally all InjectableIds are mapped to an abstract Provider<T>.
|
|
3
4
|
* A Provider may choose to return a singleton or a new value each time it is queried.
|
|
@@ -22,5 +23,30 @@ export class Provider {
|
|
|
22
23
|
}
|
|
23
24
|
return undefined;
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* If (and only if) this Provider has been configured as a Singleton, and if it has been (or is being resolved), find and invoke the @Release decorated method (if there is one).
|
|
28
|
+
* NOTE that if the singleton is actively being resolved when this method is called, this method waits for the resolution to complete and then invokes the @Release decorated method; But in any case this is a synchronous method and returns immediately to it's caller.
|
|
29
|
+
* Also note that invoking this method does not release or invalidate the Provider;
|
|
30
|
+
* Rather, it resets a Singleton Provider to a fresh (unresolved/unqueried) state (aka sets this.singleton to null).
|
|
31
|
+
* It is assumed that the Singleton itself will no longer be used after this method returns.
|
|
32
|
+
*/
|
|
33
|
+
releaseIfSingleton() {
|
|
34
|
+
if (this.singleton) {
|
|
35
|
+
const s = this.provideAsState();
|
|
36
|
+
if (s.pending) {
|
|
37
|
+
s.promise.then((v) => {
|
|
38
|
+
this.singleton = null;
|
|
39
|
+
InvokeReleaseMethod(v);
|
|
40
|
+
}).catch(() => {
|
|
41
|
+
this.singleton = null;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.singleton = null;
|
|
46
|
+
if ((!s.rejected) && s.fulfilled)
|
|
47
|
+
InvokeReleaseMethod(s.fulfilled);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
25
51
|
}
|
|
26
52
|
//# sourceMappingURL=provider.js.map
|
package/lib/esm/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAG5C;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IAC7B;IACA,CAAC;IAiBD;;;;;;OAMG;IACH,kBAAkB,CAAC,SAAkB;QACpC,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE;YAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAChC,IAAI,CAAC,CAAC,OAAO;gBACZ,OAAO,CAAC,CAAC,OAAO,CAAC;iBACb,IAAI,CAAC,CAAC,QAAQ;gBAClB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;SACnC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,kBAAkB;QACjB,IAAI,IAAI,CAAC,SAAS,EAAE;YACnB,MAAM,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAChC,IAAI,CAAC,CAAC,OAAO,EAAE;gBACd,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;oBACpB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;oBACtB,mBAAmB,CAAC,CAAC,CAAC,CAAC;gBACxB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;oBACb,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACvB,CAAC,CAAC,CAAC;aACH;iBACI;gBACJ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACtB,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS;oBAC/B,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aAClC;SACD;IACF,CAAC;CACD","sourcesContent":["import {State} from './state';\nimport {InvokeReleaseMethod} from './utils';\n\n\n/**\n * Internally all InjectableIds are mapped to an abstract Provider<T>.\n * A Provider may choose to return a singleton or a new value each time it is queried.\n */\nexport abstract class Provider<T = any> {\n\tprotected constructor() {\n\t}\n\n\t/**\n\t * If the provider is configured as a singleton, this property will be the state of that singleton.\n\t * This value will be defined for resolved/resolving Singletons, null for Singletons that have not yet been queried, and will remain undefined for non-Singleton Providers.\n\t * Default value is undefined (e.g. not a Singleton).\n\t */\n\tprotected singleton?: State<T>;\n\n\t/**\n\t * This is the workhorse method of the Provider, and is invoked directly or indirectly by both Injector.get and Injector.resolve.\n\t * This method returns the current State<T> if it is already known (which it might be for Singleton scenarios).\n\t * Otherwise it resolves the State<T>.\n\t * IF the Provider<T> is a Singleton, it's State<T> is updated before returning.\n\t */\n\tabstract provideAsState(): State<T>;\n\n\t/**\n\t * Base method to initialize the state of this Provider *if* (and only if) it has been configured as a Singleton.\n\t * If this Provider has not been configured as a singleton, this method is essentially a noop that returns undefined.\n\t *\n\t * @param asyncOnly This default implementation ignores this parameter.\n\t * @returns A completion Promise if initialization requires asynchronicity, otherwise the return value is undefined.\n\t */\n\tresolveIfSingleton(asyncOnly: boolean): Promise<T> { // eslint-disable-line @typescript-eslint/no-unused-vars\n\t\tif (this.singleton === null) {\n\t\t\tconst s = this.provideAsState();\n\t\t\tif (s.pending)\n\t\t\t\treturn s.promise;\n\t\t\telse if (s.rejected)\n\t\t\t\treturn Promise.reject(s.rejected);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * If (and only if) this Provider has been configured as a Singleton, and if it has been (or is being resolved), find and invoke the @Release decorated method (if there is one).\n\t * NOTE that if the singleton is actively being resolved when this method is called, this method waits for the resolution to complete and then invokes the @Release decorated method; But in any case this is a synchronous method and returns immediately to it's caller.\n\t * Also note that invoking this method does not release or invalidate the Provider;\n\t * Rather, it resets a Singleton Provider to a fresh (unresolved/unqueried) state (aka sets this.singleton to null).\n\t * It is assumed that the Singleton itself will no longer be used after this method returns.\n\t */\n\treleaseIfSingleton(): void {\n\t\tif (this.singleton) {\n\t\t\tconst s = this.provideAsState();\n\t\t\tif (s.pending) {\n\t\t\t\ts.promise.then((v) => {\n\t\t\t\t\tthis.singleton = null;\n\t\t\t\t\tInvokeReleaseMethod(v);\n\t\t\t\t}).catch(() => {\n\t\t\t\t\tthis.singleton = null;\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.singleton = null;\n\t\t\t\tif ((!s.rejected) && s.fulfilled)\n\t\t\t\t\tInvokeReleaseMethod(s.fulfilled);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/lib/esm/state.js
CHANGED
package/lib/esm/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,KAAK;IA+BjB;IACA,CAAC;IA/BD,MAAM,CAAC,SAAS,CAAe,OAAwB,EAAE,QAAkB,EAAE,SAAkB;QAC9F,MAAM,MAAM,GAAG,IAAI,KAAK,EAAU,CAAC;QACnC,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE;YACvB,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;YACvB,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAC7B,CAAC,CAAC,EAAE,EAAE;gBACL,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC;gBACtB,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC;gBACxB,OAAO,CAAC,CAAC;YACV,CAAC,EACD,CAAC,CAAM,EAAE,EAAE;gBACV,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;gBACrB,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC;gBACxB,MAAM,CAAC,CAAC;YACT,CAAC,CACD,CAAC;SACF;aACI;YACJ,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC;YACxB,IAAI,QAAQ,EAAE;gBACb,MAAM,CAAC,SAAS,GAAG,QAAQ,CAAC;aAC5B;iBACI;gBACJ,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;aAC9B;YACD,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;SACvB;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAOD,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAID,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAID,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAID,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;CACD","sourcesContent":["import {isPromise} from './utils';\n\n/**\n * Internal class that allows us to track the state of a promise (chain).\n */\nexport class State<T = any> {\n\tstatic MakeState<TState = any>(promise: Promise<TState>, rejected?: unknown, fulfilled?: TState): State<TState> {\n\t\tconst retVal = new State<TState>();\n\t\tif (isPromise(promise)) {\n\t\t\tretVal._pending = true;\n\t\t\tretVal._promise = promise.then(\n\t\t\t\t(v) => {\n\t\t\t\t\tretVal._fulfilled = v;\n\t\t\t\t\tretVal._pending = false;\n\t\t\t\t\treturn v;\n\t\t\t\t},\n\t\t\t\t(e: any) => {\n\t\t\t\t\tretVal._rejected = e;\n\t\t\t\t\tretVal._pending = false;\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\telse {\n\t\t\tretVal._pending = false;\n\t\t\tif (rejected) {\n\t\t\t\tretVal._rejected = rejected;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tretVal._fulfilled = fulfilled;\n\t\t\t}\n\t\t\tretVal._promise = null;\n\t\t}\n\t\treturn retVal;\n\t}\n\n\tprotected constructor() {\n\t}\n\n\tprotected _promise: Promise<T>;\n\n\tget promise(): Promise<T> {\n\t\treturn this._promise;\n\t}\n\n\tprotected _pending: boolean;\n\n\tget pending(): boolean {\n\t\treturn this._pending;\n\t}\n\n\tprotected _fulfilled: T;\n\n\tget fulfilled(): T {\n\t\treturn this._fulfilled;\n\t}\n\n\tprotected _rejected: unknown;\n\n\tget rejected(): unknown {\n\t\treturn this._rejected;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-factory-provider.js","sourceRoot":"","sources":["../../src/sync-factory-provider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"sync-factory-provider.js","sourceRoot":"","sources":["../../src/sync-factory-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;;GAGG;AACH,MAAM,OAAO,oBAAwB,SAAQ,gBAAmC;IAC/E,YAAY,QAAkB,EAAE,EAAmB,EAAE,KAAqB;QACzE,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,cAAc;QACb,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,EAAE;YACZ,IAAI;gBACH,MAAM,GAAG,KAAK,CAAC,SAAS,CAAI,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;aACxE;YACD,OAAO,GAAG,EAAE;gBACX,0EAA0E;gBAC1E,IAAI;oBACH,2EAA2E;oBAC3E,MAAM,GAAG,KAAK,CAAC,SAAS,CAAI,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;iBAC1E;gBACD,OAAO,CAAC,EAAE;oBACT,0CAA0C;oBAC1C,MAAM,GAAG,KAAK,CAAC,SAAS,CAAI,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;iBAChD;aACD;SACD;QACD,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YAC1B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,kBAAkB,CAAC,SAAkB;QACpC,IAAI,SAAS;YACZ,OAAO,SAAS,CAAC;QAClB,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACD","sourcesContent":["import {BindableProvider} from './bindable-provider';\nimport {SyncFactory} from './binder';\nimport {InjectableId, Injector} from './injector';\nimport {State} from './state';\n\n/**\n * @inheritDoc\n * This specialization simply invokes it's configured Factory and provides the result.\n */\nexport class FactoryBasedProvider<T> extends BindableProvider<T, SyncFactory<T>> {\n\tconstructor(injector: Injector, id: InjectableId<T>, maker: SyncFactory<T>) {\n\t\tsuper(injector, id, maker);\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * This specialization invokes it's configured Factory and provides the result (or invokes the error handler if necessary).\n\t */\n\tprovideAsState(): State<T> {\n\t\tlet retVal = this.singleton;\n\t\tif (!retVal) {\n\t\t\ttry {\n\t\t\t\tretVal = State.MakeState<T>(null, undefined, this.maker(this.injector));\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\t// There was an error, give the errorHandler (if any) a crack at recovery.\n\t\t\t\ttry {\n\t\t\t\t\t// queryErrorHandler will throw if it could not obtain a substitute object.\n\t\t\t\t\tretVal = State.MakeState<T>(null, undefined, this.queryErrorHandler(err));\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\t// could not recover, propagate the error.\n\t\t\t\t\tretVal = State.MakeState<T>(null, e, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (this.singleton === null)\n\t\t\tthis.singleton = retVal;\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * This specialization returns undefined anytime 'asyncOnly' is true (since this Provider is by definition synchronous).\n\t */\n\tresolveIfSingleton(asyncOnly: boolean): Promise<T> {\n\t\tif (asyncOnly)\n\t\t\treturn undefined;\n\t\treturn super.resolveIfSingleton(false);\n\t}\n}\n"]}
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if the specified object looks like a JavaScript Error object.
|
|
3
|
+
*/
|
|
1
4
|
export declare function isErrorObj(err: any): err is Error;
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the specified value is "thenable" (aka a Promise).
|
|
7
|
+
*/
|
|
2
8
|
export declare function isPromise<T>(value: any): value is Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Simple helper function to find the @Release decorated method of an object (if any), and invoke it.
|
|
11
|
+
* This is primarily an internal method as you probably know the exact method, and should invoke it yourself.
|
|
12
|
+
* async-injection uses this helper to allow Singletons to clean up any non-garbage-collectable resources they may have allocated.
|
|
13
|
+
*/
|
|
14
|
+
export declare function InvokeReleaseMethod<T = unknown>(obj: T): boolean;
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
import { RELEASE_METADATA_KEY } from './constants';
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the specified object looks like a JavaScript Error object.
|
|
5
|
+
*/
|
|
2
6
|
export function isErrorObj(err) {
|
|
3
7
|
if (!err)
|
|
4
8
|
return false;
|
|
@@ -6,6 +10,9 @@ export function isErrorObj(err) {
|
|
|
6
10
|
return true;
|
|
7
11
|
return err && typeof err.message === 'string' && typeof err.stack === 'string';
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the specified value is "thenable" (aka a Promise).
|
|
15
|
+
*/
|
|
9
16
|
export function isPromise(value) {
|
|
10
17
|
if (!value)
|
|
11
18
|
return false;
|
|
@@ -13,4 +20,23 @@ export function isPromise(value) {
|
|
|
13
20
|
return true;
|
|
14
21
|
return value && typeof value.then === 'function';
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Simple helper function to find the @Release decorated method of an object (if any), and invoke it.
|
|
25
|
+
* This is primarily an internal method as you probably know the exact method, and should invoke it yourself.
|
|
26
|
+
* async-injection uses this helper to allow Singletons to clean up any non-garbage-collectable resources they may have allocated.
|
|
27
|
+
*/
|
|
28
|
+
export function InvokeReleaseMethod(obj) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const releaseMethod = Reflect.getMetadata(RELEASE_METADATA_KEY, obj.constructor);
|
|
31
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
|
|
32
|
+
if (releaseMethod && obj.constructor.prototype[releaseMethod] && typeof obj.constructor.prototype[releaseMethod] === 'function') {
|
|
33
|
+
const releaseFn = (_b = (_a = obj[releaseMethod]).bind) === null || _b === void 0 ? void 0 : _b.call(_a, obj);
|
|
34
|
+
if (releaseFn) {
|
|
35
|
+
releaseFn();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/* eslint-enable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
16
42
|
//# sourceMappingURL=utils.js.map
|
package/lib/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,kHAAkH;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IAClC,IAAI,CAAC,GAAG;QACP,OAAO,KAAK,CAAC;IAEd,IAAI,GAAG,YAAY,KAAK;QACvB,OAAO,IAAI,CAAC;IAEb,OAAO,GAAG,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC;AAChF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAI,KAAU;IACtC,IAAI,CAAC,KAAK;QACT,OAAO,KAAK,CAAC;IAEd,IAAI,KAAK,YAAY,OAAO;QAC3B,OAAO,IAAI,CAAC;IAEb,OAAO,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAc,GAAM;;IACtD,MAAM,aAAa,GAAW,OAAO,CAAC,WAAW,CAAC,oBAAoB,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACzF,kGAAkG;IAClG,IAAI,aAAa,IAAI,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,OAAO,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,UAAU,EAAE;QAChI,MAAM,SAAS,GAAG,MAAA,MAAA,GAAG,CAAC,aAAa,CAAC,EAAC,IAAI,mDAAG,GAAG,CAAC,CAAC;QACjD,IAAI,SAAS,EAAE;YACd,SAAS,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;SACZ;KACD;IACD,iGAAiG;IACjG,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/explicit-module-boundary-types */\nimport {RELEASE_METADATA_KEY} from './constants';\n\n/**\n * Returns true if the specified object looks like a JavaScript Error object.\n */\nexport function isErrorObj(err: any): err is Error {\n\tif (!err)\n\t\treturn false;\n\n\tif (err instanceof Error)\n\t\treturn true;\n\n\treturn err && typeof err.message === 'string' && typeof err.stack === 'string';\n}\n\n/**\n * Returns true if the specified value is \"thenable\" (aka a Promise).\n */\nexport function isPromise<T>(value: any): value is Promise<T> {\n\tif (!value)\n\t\treturn false;\n\n\tif (value instanceof Promise)\n\t\treturn true;\n\n\treturn value && typeof value.then === 'function';\n}\n\n/**\n * Simple helper function to find the @Release decorated method of an object (if any), and invoke it.\n * This is primarily an internal method as you probably know the exact method, and should invoke it yourself.\n * async-injection uses this helper to allow Singletons to clean up any non-garbage-collectable resources they may have allocated.\n */\nexport function InvokeReleaseMethod<T = unknown>(obj: T): boolean {\n\tconst releaseMethod: string = Reflect.getMetadata(RELEASE_METADATA_KEY, obj.constructor);\n\t/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */\n\tif (releaseMethod && obj.constructor.prototype[releaseMethod] && typeof obj.constructor.prototype[releaseMethod] === 'function') {\n\t\tconst releaseFn = obj[releaseMethod].bind?.(obj);\n\t\tif (releaseFn) {\n\t\t\treleaseFn();\n\t\t\treturn true;\n\t\t}\n\t}\n\t/* eslint-enable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */\n\treturn false;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "async-injection",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A robust lightweight dependency injection library for TypeScript.",
|
|
5
5
|
"author": "Frank Stock",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,24 +50,24 @@
|
|
|
50
50
|
"url": "https://github.com/pcafstockf/async-injection/issues"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@istanbuljs/nyc-config-typescript": "~1.0.
|
|
54
|
-
"@types/jasmine": "~3.
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "~4.
|
|
56
|
-
"@typescript-eslint/parser": "~4.
|
|
53
|
+
"@istanbuljs/nyc-config-typescript": "~1.0.2",
|
|
54
|
+
"@types/jasmine": "~3.10.6",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "~4.33.0",
|
|
56
|
+
"@typescript-eslint/parser": "~4.33.0",
|
|
57
57
|
"eslint": "~7.32.0",
|
|
58
|
-
"eslint-plugin-import": "~2.
|
|
59
|
-
"eslint-plugin-jsdoc": "~36.
|
|
58
|
+
"eslint-plugin-import": "~2.26.0",
|
|
59
|
+
"eslint-plugin-jsdoc": "~36.1.1",
|
|
60
60
|
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
61
|
-
"jasmine": "~3.
|
|
61
|
+
"jasmine": "~3.99.0",
|
|
62
62
|
"jasmine-console-reporter": "~3.1.0",
|
|
63
63
|
"nyc": "~15.1.0",
|
|
64
64
|
"reflect-metadata": "~0.1.13",
|
|
65
65
|
"rimraf": "~3.0.2",
|
|
66
|
-
"source-map-support": "~0.5.
|
|
67
|
-
"ts-node": "~10.
|
|
68
|
-
"tsconfig-paths": "~3.
|
|
69
|
-
"tslib": "~2.3.
|
|
70
|
-
"typescript": "~4.
|
|
66
|
+
"source-map-support": "~0.5.21",
|
|
67
|
+
"ts-node": "~10.7.0",
|
|
68
|
+
"tsconfig-paths": "~3.14.1",
|
|
69
|
+
"tslib": "~2.3.1",
|
|
70
|
+
"typescript": "~4.4.4"
|
|
71
71
|
},
|
|
72
72
|
"nyc": {
|
|
73
73
|
"extends": "@istanbuljs/nyc-config-typescript",
|