@nzyme/ioc 0.13.0 → 0.15.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/dist/Caller.d.ts +8 -0
- package/dist/Caller.js +8 -0
- package/dist/Caller.js.map +1 -1
- package/dist/Command.d.ts +44 -11
- package/dist/Command.js +29 -9
- package/dist/Command.js.map +1 -1
- package/dist/Command.test.d.ts +1 -0
- package/dist/Command.test.js +136 -0
- package/dist/Command.test.js.map +1 -0
- package/dist/Container.d.ts +119 -14
- package/dist/Container.js +28 -4
- package/dist/Container.js.map +1 -1
- package/dist/ContainerScope.d.ts +18 -0
- package/dist/ContainerScope.js +7 -1
- package/dist/ContainerScope.js.map +1 -1
- package/dist/Factory.d.ts +84 -0
- package/dist/Factory.js +42 -0
- package/dist/Factory.js.map +1 -0
- package/dist/Fetch.d.ts +3 -0
- package/dist/Fetch.js +4 -0
- package/dist/Fetch.js.map +1 -0
- package/dist/Injectable.d.ts +63 -28
- package/dist/Injectable.js +16 -8
- package/dist/Injectable.js.map +1 -1
- package/dist/Interface.d.ts +51 -34
- package/dist/Interface.js +39 -14
- package/dist/Interface.js.map +1 -1
- package/dist/Interface.test.d.ts +1 -0
- package/dist/Interface.test.js +37 -0
- package/dist/Interface.test.js.map +1 -0
- package/dist/Module.d.ts +26 -0
- package/dist/Module.js +10 -1
- package/dist/Module.js.map +1 -1
- package/dist/Service.d.ts +102 -30
- package/dist/Service.js +24 -19
- package/dist/Service.js.map +1 -1
- package/dist/Service.test.d.ts +1 -0
- package/dist/Service.test.js +378 -0
- package/dist/Service.test.js.map +1 -0
- package/dist/defineEnvVariable.d.ts +82 -0
- package/dist/defineEnvVariable.js +54 -0
- package/dist/defineEnvVariable.js.map +1 -0
- package/dist/helpers/EnvVariables.d.ts +10 -0
- package/dist/helpers/EnvVariables.js +9 -0
- package/dist/helpers/EnvVariables.js.map +1 -0
- package/dist/helpers/fallback.d.ts +1 -1
- package/dist/helpers/injectLazy.d.ts +7 -0
- package/dist/helpers/injectLazy.js +20 -0
- package/dist/helpers/injectLazy.js.map +1 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/serviceResolve.d.ts +60 -13
- package/dist/serviceResolve.js +64 -22
- package/dist/serviceResolve.js.map +1 -1
- package/dist/services/ContextProvider.d.ts +8 -0
- package/dist/services/ContextProvider.js +37 -0
- package/dist/services/ContextProvider.js.map +1 -0
- package/dist/utils/getAllDeps.d.ts +5 -0
- package/dist/utils/getAllDeps.js +25 -0
- package/dist/utils/getAllDeps.js.map +1 -0
- package/dist/utils/isDependentOn.d.ts +6 -0
- package/dist/utils/isDependentOn.js +9 -0
- package/dist/utils/isDependentOn.js.map +1 -0
- package/dist/utils/resolveDeps.d.ts +2 -2
- package/dist/utils/resolveDeps.js.map +1 -1
- package/dist/utils/sortByDependency.d.ts +7 -0
- package/dist/utils/sortByDependency.js +46 -0
- package/dist/utils/sortByDependency.js.map +1 -0
- package/dist/utils/sortByDependency.test.d.ts +1 -0
- package/dist/utils/sortByDependency.test.js +100 -0
- package/dist/utils/sortByDependency.test.js.map +1 -0
- package/package.json +31 -38
- package/dist/Caller.cjs +0 -9
- package/dist/Caller.cjs.map +0 -1
- package/dist/Command.cjs +0 -20
- package/dist/Command.cjs.map +0 -1
- package/dist/Container.cjs +0 -69
- package/dist/Container.cjs.map +0 -1
- package/dist/ContainerScope.cjs +0 -10
- package/dist/ContainerScope.cjs.map +0 -1
- package/dist/Injectable.cjs +0 -29
- package/dist/Injectable.cjs.map +0 -1
- package/dist/Interface.cjs +0 -73
- package/dist/Interface.cjs.map +0 -1
- package/dist/Module.cjs +0 -8
- package/dist/Module.cjs.map +0 -1
- package/dist/Service.cjs +0 -39
- package/dist/Service.cjs.map +0 -1
- package/dist/helpers/callerName.cjs +0 -15
- package/dist/helpers/callerName.cjs.map +0 -1
- package/dist/helpers/constValue.cjs +0 -15
- package/dist/helpers/constValue.cjs.map +0 -1
- package/dist/helpers/envVariable.cjs +0 -23
- package/dist/helpers/envVariable.cjs.map +0 -1
- package/dist/helpers/envVariable.d.ts +0 -16
- package/dist/helpers/envVariable.js +0 -20
- package/dist/helpers/envVariable.js.map +0 -1
- package/dist/helpers/fallback.cjs +0 -23
- package/dist/helpers/fallback.cjs.map +0 -1
- package/dist/index.cjs +0 -17
- package/dist/index.cjs.map +0 -1
- package/dist/serviceResolve.cjs +0 -83
- package/dist/serviceResolve.cjs.map +0 -1
- package/dist/utils/resolveDeps.cjs +0 -18
- package/dist/utils/resolveDeps.cjs.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Injectable } from './Injectable.js';
|
|
2
|
+
/** Resolves to TValue when required, or TValue | undefined when optional. */
|
|
3
|
+
export type EnvVariableValue<TRequired extends boolean = false, TValue = string> = TRequired extends true ? TValue : TValue | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Options for the env variable.
|
|
6
|
+
*/
|
|
7
|
+
export interface EnvVariableOptionsRequired<TRequired extends boolean> {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the environment variable is required.
|
|
10
|
+
*/
|
|
11
|
+
required?: TRequired;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for the env variable.
|
|
15
|
+
*/
|
|
16
|
+
export interface EnvVariableOptionsParse<TRequired extends boolean, TValue = string> extends EnvVariableOptionsRequired<TRequired> {
|
|
17
|
+
/**
|
|
18
|
+
* Function to parse the environment variable value.
|
|
19
|
+
*/
|
|
20
|
+
parse?: (value: EnvVariableValue<TRequired>) => TValue;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for the env variable.
|
|
24
|
+
*/
|
|
25
|
+
export interface EnvVariableOptionsDefault<TValue = string> extends EnvVariableOptionsParse<false, TValue> {
|
|
26
|
+
/**
|
|
27
|
+
* Default value of the environment variable.
|
|
28
|
+
*/
|
|
29
|
+
default: (() => TValue) | TValue;
|
|
30
|
+
}
|
|
31
|
+
/** An injectable environment variable with typed access and optional parsing. */
|
|
32
|
+
export interface EnvVariable<TName extends string = string, TRequired extends boolean = boolean, TValue = unknown> extends EnvVariableOptionsParse<TRequired, TValue>, Injectable<TValue> {
|
|
33
|
+
/**
|
|
34
|
+
* Whether the environment variable is required.
|
|
35
|
+
*/
|
|
36
|
+
required: TRequired;
|
|
37
|
+
/**
|
|
38
|
+
* Name of the environment variable.
|
|
39
|
+
*/
|
|
40
|
+
name: TName;
|
|
41
|
+
/**
|
|
42
|
+
* Default value of the environment variable.
|
|
43
|
+
*/
|
|
44
|
+
default?: () => TValue;
|
|
45
|
+
/**
|
|
46
|
+
* Get the value of the environment variable.
|
|
47
|
+
*/
|
|
48
|
+
get(): TValue | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Assert that the environment variable is set.
|
|
51
|
+
*/
|
|
52
|
+
assert(): TValue;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Define an environment variable injectable.
|
|
56
|
+
* @param name - Name of the environment variable.
|
|
57
|
+
* @param options - Options for the environment variable.
|
|
58
|
+
* @returns Environment variable injectable.
|
|
59
|
+
* @__NO_SIDE_EFFECTS__
|
|
60
|
+
*/
|
|
61
|
+
export declare function defineEnvVariable<TName extends string = string, TRequired extends boolean = true>(name: TName, options?: EnvVariableOptionsRequired<TRequired> & {
|
|
62
|
+
default?: never;
|
|
63
|
+
parse?: never;
|
|
64
|
+
}): EnvVariable<TName, TRequired, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Define an environment variable injectable.
|
|
67
|
+
* @param name - Name of the environment variable.
|
|
68
|
+
* @param options - Options for the environment variable.
|
|
69
|
+
* @returns Environment variable injectable.
|
|
70
|
+
* @__NO_SIDE_EFFECTS__
|
|
71
|
+
*/
|
|
72
|
+
export declare function defineEnvVariable<TName extends string = string, TRequired extends boolean = true, TValue = string>(name: TName, options?: EnvVariableOptionsParse<TRequired, TValue> & {
|
|
73
|
+
default?: never;
|
|
74
|
+
}): EnvVariable<TName, TRequired, TValue>;
|
|
75
|
+
/**
|
|
76
|
+
* Define an environment variable injectable.
|
|
77
|
+
* @param name - Name of the environment variable.
|
|
78
|
+
* @param options - Options for the environment variable.
|
|
79
|
+
* @returns Environment variable injectable.
|
|
80
|
+
* @__NO_SIDE_EFFECTS__
|
|
81
|
+
*/
|
|
82
|
+
export declare function defineEnvVariable<TName extends string = string, TValue = string>(name: TName, options?: EnvVariableOptionsDefault<TValue>): EnvVariable<TName, false, TValue>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EnvVariables } from './helpers/EnvVariables.js';
|
|
2
|
+
import { defineInjectable } from './Injectable.js';
|
|
3
|
+
const DEPS = {
|
|
4
|
+
env: EnvVariables,
|
|
5
|
+
};
|
|
6
|
+
/** Implementation overload for defineEnvVariable. */
|
|
7
|
+
export function defineEnvVariable(name, options) {
|
|
8
|
+
const defaultValue = options?.default;
|
|
9
|
+
return defineInjectable({
|
|
10
|
+
name,
|
|
11
|
+
deps: DEPS,
|
|
12
|
+
required: options?.required ?? !defaultValue,
|
|
13
|
+
parse: options?.parse,
|
|
14
|
+
resolve,
|
|
15
|
+
default: defaultValue ? (typeof defaultValue === 'function' ? defaultValue : () => defaultValue) : undefined,
|
|
16
|
+
get: getValue,
|
|
17
|
+
assert: assertValue,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function getValue() {
|
|
21
|
+
const value = process.env[this.name];
|
|
22
|
+
if (value == null) {
|
|
23
|
+
return this.default?.();
|
|
24
|
+
}
|
|
25
|
+
if (this.parse) {
|
|
26
|
+
return this.parse(value);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function assertValue() {
|
|
31
|
+
const value = getValue.call(this);
|
|
32
|
+
if (value == null) {
|
|
33
|
+
throw new Error(`Environment variable ${this.name} is not set.`);
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
function resolve(container, caller) {
|
|
38
|
+
const name = this.name;
|
|
39
|
+
const env = container.resolve(EnvVariables);
|
|
40
|
+
const value = env[name];
|
|
41
|
+
if (!value) {
|
|
42
|
+
if (this.default) {
|
|
43
|
+
return this.default();
|
|
44
|
+
}
|
|
45
|
+
if (this.required) {
|
|
46
|
+
throw new Error(`Environment variable ${name} is not set. Caller: ${caller?.name}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (this.parse) {
|
|
50
|
+
return this.parse(value);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=defineEnvVariable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineEnvVariable.js","sourceRoot":"","sources":["../src/defineEnvVariable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,MAAM,IAAI,GAAG;IACT,GAAG,EAAE,YAAY;CACpB,CAAC;AAsGF,qDAAqD;AACrD,MAAM,UAAU,iBAAiB,CAC7B,IAAY,EACZ,OAAgH;IAEhH,MAAM,YAAY,GAAG,OAAO,EAAE,OAA+C,CAAC;IAE9E,OAAO,gBAAgB,CAAc;QACjC,IAAI;QACJ,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAC,YAAY;QAC5C,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,OAAO;QACP,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;QAC5G,GAAG,EAAE,QAAQ;QACb,MAAM,EAAE,WAAW;KACtB,CAAC,CAAC;AACP,CAAC;AAED,SAAS,QAAQ;IACb,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAA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variables.
|
|
3
|
+
*/
|
|
4
|
+
export type EnvVariables = {
|
|
5
|
+
[key: string]: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The environment variables interface.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EnvVariables: import("../Interface.js").Interface<EnvVariables>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvVariables.js","sourceRoot":"","sources":["../../src/helpers/EnvVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AASlD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAe;IACtD,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG;CAC7B,CAAC,CAAC"}
|
|
@@ -4,4 +4,4 @@ import type { Injectable } from '../Injectable.js';
|
|
|
4
4
|
* @param value - Value to define.
|
|
5
5
|
* @returns Fallback injectable.
|
|
6
6
|
*/
|
|
7
|
-
export declare function fallback<T>(...injectables: Injectable<T |
|
|
7
|
+
export declare function fallback<T>(...injectables: Injectable<T | null | undefined>[]): Injectable<NonNullable<T> | undefined>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineInjectable } from '../Injectable.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define a lazy injectable.
|
|
4
|
+
* @param injectable - Injectable to define.
|
|
5
|
+
* @returns Lazy injectable.
|
|
6
|
+
*/
|
|
7
|
+
export function injectLazy(injectable) {
|
|
8
|
+
let value;
|
|
9
|
+
return defineInjectable({
|
|
10
|
+
resolve: container => {
|
|
11
|
+
return () => {
|
|
12
|
+
if (!value) {
|
|
13
|
+
value = container.resolve(injectable);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=injectLazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectLazy.js","sourceRoot":"","sources":["../../src/helpers/injectLazy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAI,UAAyB;IACnD,IAAI,KAAoB,CAAC;IAEzB,OAAO,gBAAgB,CAAC;QACpB,OAAO,EAAE,SAAS,CAAC,EAAE;YACjB,OAAO,GAAG,EAAE;gBACR,IAAI,CAAC,KAAK,EAAE,CAAC;oBACT,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC1C,CAAC;gBAED,OAAO,KAAK,CAAC;YACjB,CAAC,CAAC;QACN,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
export * from './Caller.js';
|
|
1
2
|
export * from './Command.js';
|
|
2
3
|
export * from './Container.js';
|
|
3
4
|
export * from './ContainerScope.js';
|
|
5
|
+
export * from './defineEnvVariable.js';
|
|
6
|
+
export * from './Factory.js';
|
|
7
|
+
export * from './Fetch.js';
|
|
8
|
+
export * from './helpers/callerName.js';
|
|
9
|
+
export * from './helpers/constValue.js';
|
|
10
|
+
export * from './helpers/EnvVariables.js';
|
|
11
|
+
export * from './helpers/fallback.js';
|
|
12
|
+
export * from './helpers/injectLazy.js';
|
|
4
13
|
export * from './Injectable.js';
|
|
5
14
|
export * from './Interface.js';
|
|
6
15
|
export * from './Module.js';
|
|
7
16
|
export * from './Service.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './helpers/fallback.js';
|
|
12
|
-
export * from './helpers/callerName.js';
|
|
17
|
+
export * from './services/ContextProvider.js';
|
|
18
|
+
export * from './utils/getAllDeps.js';
|
|
19
|
+
export * from './utils/isDependentOn.js';
|
|
13
20
|
export * from './utils/resolveDeps.js';
|
|
21
|
+
export * from './utils/sortByDependency.js';
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
export * from './Caller.js';
|
|
1
2
|
export * from './Command.js';
|
|
2
3
|
export * from './Container.js';
|
|
3
4
|
export * from './ContainerScope.js';
|
|
5
|
+
export * from './defineEnvVariable.js';
|
|
6
|
+
export * from './Factory.js';
|
|
7
|
+
export * from './Fetch.js';
|
|
8
|
+
export * from './helpers/callerName.js';
|
|
9
|
+
export * from './helpers/constValue.js';
|
|
10
|
+
export * from './helpers/EnvVariables.js';
|
|
11
|
+
export * from './helpers/fallback.js';
|
|
12
|
+
export * from './helpers/injectLazy.js';
|
|
4
13
|
export * from './Injectable.js';
|
|
5
14
|
export * from './Interface.js';
|
|
6
15
|
export * from './Module.js';
|
|
7
16
|
export * from './Service.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './helpers/fallback.js';
|
|
12
|
-
export * from './helpers/callerName.js';
|
|
17
|
+
export * from './services/ContextProvider.js';
|
|
18
|
+
export * from './utils/getAllDeps.js';
|
|
19
|
+
export * from './utils/isDependentOn.js';
|
|
13
20
|
export * from './utils/resolveDeps.js';
|
|
21
|
+
export * from './utils/sortByDependency.js';
|
|
14
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC"}
|
package/dist/serviceResolve.d.ts
CHANGED
|
@@ -1,15 +1,62 @@
|
|
|
1
1
|
import type { Container } from './Container.js';
|
|
2
2
|
import type { Injectable } from './Injectable.js';
|
|
3
|
-
import type { Service
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
import type { Service } from './Service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Function that determines how a service instance is created and cached.
|
|
6
|
+
*
|
|
7
|
+
* @param service - The service to resolve
|
|
8
|
+
* @param container - The container used for dependency resolution
|
|
9
|
+
* @param caller - Optional injectable that requested this resolution
|
|
10
|
+
* @returns The resolved service instance
|
|
11
|
+
*/
|
|
12
|
+
export type ServiceResolutionStrategy = (service: Service, container: Container, caller?: Injectable) => unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Built-in service resolution strategies:
|
|
15
|
+
* - 'transient': Creates a new instance on each resolution
|
|
16
|
+
* - 'singleton': Creates and caches a single instance
|
|
17
|
+
* - 'lazy': Creates a proxy that resolves to a singleton on first use
|
|
18
|
+
*/
|
|
19
|
+
export type ServiceResolutionType = 'lazy' | 'singleton' | 'transient';
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new service resolution strategy.
|
|
22
|
+
* This is a type-safe wrapper that ensures the function matches the ServiceResolutionStrategy interface.
|
|
23
|
+
*
|
|
24
|
+
* @param strategy - The function that implements the resolution strategy
|
|
25
|
+
* @returns The same function, properly typed as a ServiceResolutionStrategy
|
|
26
|
+
* @__NO_SIDE_EFFECTS__
|
|
27
|
+
*/
|
|
28
|
+
export declare function defineResolutionStrategy(strategy: ServiceResolutionStrategy): ServiceResolutionStrategy;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the resolution strategy function for a given strategy type or function.
|
|
31
|
+
*
|
|
32
|
+
* @param strategy - The strategy type or function
|
|
33
|
+
* @returns The resolution strategy function
|
|
34
|
+
* @throws Error if the strategy type is invalid
|
|
35
|
+
*/
|
|
36
|
+
export declare function getResolutionStrategy(strategy: ServiceResolutionStrategy | ServiceResolutionType): ServiceResolutionStrategy;
|
|
37
|
+
/**
|
|
38
|
+
* Resolution strategy that creates and caches a single instance of the service.
|
|
39
|
+
* The instance is:
|
|
40
|
+
* - Created on first resolution
|
|
41
|
+
* - Cached in the container
|
|
42
|
+
* - Reused for subsequent resolutions
|
|
43
|
+
* - Scoped to the container's scope
|
|
44
|
+
*/
|
|
45
|
+
export declare const singletonStrategy: ServiceResolutionStrategy;
|
|
46
|
+
/**
|
|
47
|
+
* Resolution strategy that creates a new instance of the service on each resolution.
|
|
48
|
+
* The instance is:
|
|
49
|
+
* - Created on each resolution
|
|
50
|
+
* - Not cached in the container
|
|
51
|
+
* - Scoped to the container's scope
|
|
52
|
+
*/
|
|
53
|
+
export declare const transientStrategy: ServiceResolutionStrategy;
|
|
54
|
+
/**
|
|
55
|
+
* Resolution strategy that creates a proxy that resolves to a singleton on first use.
|
|
56
|
+
* The proxy:
|
|
57
|
+
* - Is created immediately
|
|
58
|
+
* - Defers instance creation until first use
|
|
59
|
+
* - Caches the instance after creation
|
|
60
|
+
* - Forwards all operations to the cached instance
|
|
61
|
+
*/
|
|
62
|
+
export declare const lazyStrategy: ServiceResolutionStrategy;
|
package/dist/serviceResolve.js
CHANGED
|
@@ -1,21 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMemo } from '@nzyme/utils/createMemo.js';
|
|
2
|
+
import { noop } from '@nzyme/utils/functions/noop.js';
|
|
2
3
|
import { resolveDeps } from './utils/resolveDeps.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new service resolution strategy.
|
|
6
|
+
* This is a type-safe wrapper that ensures the function matches the ServiceResolutionStrategy interface.
|
|
7
|
+
*
|
|
8
|
+
* @param strategy - The function that implements the resolution strategy
|
|
9
|
+
* @returns The same function, properly typed as a ServiceResolutionStrategy
|
|
10
|
+
* @__NO_SIDE_EFFECTS__
|
|
11
|
+
*/
|
|
12
|
+
export function defineResolutionStrategy(strategy) {
|
|
13
|
+
return strategy;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the resolution strategy function for a given strategy type or function.
|
|
17
|
+
*
|
|
18
|
+
* @param strategy - The strategy type or function
|
|
19
|
+
* @returns The resolution strategy function
|
|
20
|
+
* @throws Error if the strategy type is invalid
|
|
21
|
+
*/
|
|
3
22
|
export function getResolutionStrategy(strategy) {
|
|
4
23
|
if (typeof strategy === 'function') {
|
|
5
24
|
return strategy;
|
|
6
25
|
}
|
|
7
26
|
switch (strategy) {
|
|
8
|
-
case 'transient':
|
|
9
|
-
return transientStrategy;
|
|
10
|
-
case 'singleton':
|
|
11
|
-
return singletonStrategy;
|
|
12
27
|
case 'lazy':
|
|
13
28
|
return lazyStrategy;
|
|
29
|
+
case 'singleton':
|
|
30
|
+
return singletonStrategy;
|
|
31
|
+
case 'transient':
|
|
32
|
+
return transientStrategy;
|
|
14
33
|
default:
|
|
15
34
|
throw new Error(`Invalid service resolution strategy: ${strategy}`);
|
|
16
35
|
}
|
|
17
36
|
}
|
|
18
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Resolution strategy that creates and caches a single instance of the service.
|
|
39
|
+
* The instance is:
|
|
40
|
+
* - Created on first resolution
|
|
41
|
+
* - Cached in the container
|
|
42
|
+
* - Reused for subsequent resolutions
|
|
43
|
+
* - Scoped to the container's scope
|
|
44
|
+
*/
|
|
45
|
+
export const singletonStrategy = defineResolutionStrategy((service, container) => {
|
|
19
46
|
let instance = container.get(service);
|
|
20
47
|
if (instance) {
|
|
21
48
|
return instance;
|
|
@@ -30,15 +57,22 @@ export function singletonStrategy({ service, options, container, caller, }) {
|
|
|
30
57
|
return instance;
|
|
31
58
|
}
|
|
32
59
|
}
|
|
33
|
-
const deps = resolveDeps(service.deps, container,
|
|
34
|
-
instance =
|
|
60
|
+
const deps = resolveDeps(service.deps, container, service);
|
|
61
|
+
instance = service.create(deps);
|
|
35
62
|
container.set(service, instance);
|
|
36
|
-
if (
|
|
37
|
-
container.set(
|
|
63
|
+
if (service.implements && !container.get(service.implements)) {
|
|
64
|
+
container.set(service.implements, instance);
|
|
38
65
|
}
|
|
39
66
|
return instance;
|
|
40
|
-
}
|
|
41
|
-
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Resolution strategy that creates a new instance of the service on each resolution.
|
|
70
|
+
* The instance is:
|
|
71
|
+
* - Created on each resolution
|
|
72
|
+
* - Not cached in the container
|
|
73
|
+
* - Scoped to the container's scope
|
|
74
|
+
*/
|
|
75
|
+
export const transientStrategy = defineResolutionStrategy((service, container, caller) => {
|
|
42
76
|
if (service.scope) {
|
|
43
77
|
while (container.scope !== service.scope) {
|
|
44
78
|
if (!container.parent) {
|
|
@@ -48,30 +82,38 @@ export function transientStrategy({ service, options, container, caller, }) {
|
|
|
48
82
|
}
|
|
49
83
|
}
|
|
50
84
|
const deps = resolveDeps(service.deps, container, caller);
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
85
|
+
return service.create(deps);
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Resolution strategy that creates a proxy that resolves to a singleton on first use.
|
|
89
|
+
* The proxy:
|
|
90
|
+
* - Is created immediately
|
|
91
|
+
* - Defers instance creation until first use
|
|
92
|
+
* - Caches the instance after creation
|
|
93
|
+
* - Forwards all operations to the cached instance
|
|
94
|
+
*/
|
|
95
|
+
export const lazyStrategy = defineResolutionStrategy((service, container, caller) => {
|
|
54
96
|
// Short-circuit if already resolved
|
|
55
|
-
const existing =
|
|
97
|
+
const existing = container.get(service);
|
|
56
98
|
if (existing) {
|
|
57
99
|
return existing;
|
|
58
100
|
}
|
|
59
|
-
const memo = createMemo(() => singletonStrategy(
|
|
101
|
+
const memo = createMemo(() => singletonStrategy(service, container, caller));
|
|
60
102
|
const proxy = new Proxy(noop, {
|
|
61
|
-
get: (
|
|
103
|
+
get: (_target, prop) => {
|
|
62
104
|
return memo()[prop];
|
|
63
105
|
},
|
|
64
|
-
set: (
|
|
106
|
+
set: (_target, prop, value) => {
|
|
65
107
|
memo()[prop] = value;
|
|
66
108
|
return true;
|
|
67
109
|
},
|
|
68
|
-
has: (
|
|
110
|
+
has: (_target, prop) => {
|
|
69
111
|
return prop in memo();
|
|
70
112
|
},
|
|
71
|
-
apply: (
|
|
113
|
+
apply: (_target, _thisArg, args) => {
|
|
72
114
|
return memo()(...args);
|
|
73
115
|
},
|
|
74
116
|
});
|
|
75
117
|
return proxy;
|
|
76
|
-
}
|
|
118
|
+
});
|
|
77
119
|
//# sourceMappingURL=serviceResolve.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceResolve.js","sourceRoot":"","sources":["../src/serviceResolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"serviceResolve.js","sourceRoot":"","sources":["../src/serviceResolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAKtD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAoBrD;;;;;;;GAOG;AACH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;IACpB,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE;QAC1B,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACnB,OAAQ,IAAI,EAAuC,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC;QACD,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;YACzB,IAAI,EAAuC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAC3D,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACnB,OAAO,IAAI,IAAK,IAAI,EAAuC,CAAC;QAChE,CAAC;QACD,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAe,EAAE,EAAE;YAC1C,OAAQ,IAAI,EAAsC,CAAC,GAAG,IAAI,CAAC,CAAC;QAChE,CAAC;KACJ,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Service that provides a request-scoped key-value store for sharing data within a context. */
|
|
2
|
+
export declare const ContextProvider: import("../Service.js").Service<{
|
|
3
|
+
get: <T>(key: symbol) => T | undefined;
|
|
4
|
+
getOrCreate: <T>(key: symbol, factory: () => T) => T;
|
|
5
|
+
newContext: () => void;
|
|
6
|
+
remove: (key: symbol) => void;
|
|
7
|
+
set: <T>(key: symbol, value: T) => T;
|
|
8
|
+
}, import("@nzyme/types/Object.js").SomeObject>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineService } from '../Service.js';
|
|
2
|
+
/** Service that provides a request-scoped key-value store for sharing data within a context. */
|
|
3
|
+
export const ContextProvider = defineService({
|
|
4
|
+
name: 'ContextProvider',
|
|
5
|
+
setup() {
|
|
6
|
+
let ctx = new Map();
|
|
7
|
+
return {
|
|
8
|
+
get,
|
|
9
|
+
getOrCreate,
|
|
10
|
+
newContext,
|
|
11
|
+
remove,
|
|
12
|
+
set,
|
|
13
|
+
};
|
|
14
|
+
function get(key) {
|
|
15
|
+
return ctx.get(key);
|
|
16
|
+
}
|
|
17
|
+
function getOrCreate(key, factory) {
|
|
18
|
+
let value = ctx.get(key);
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
value = factory();
|
|
21
|
+
ctx.set(key, value);
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function set(key, value) {
|
|
26
|
+
ctx.set(key, value);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function remove(key) {
|
|
30
|
+
ctx.delete(key);
|
|
31
|
+
}
|
|
32
|
+
function newContext() {
|
|
33
|
+
ctx = new Map();
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=ContextProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextProvider.js","sourceRoot":"","sources":["../../src/services/ContextProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,gGAAgG;AAChG,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;IACzC,IAAI,EAAE,iBAAiB;IACvB,KAAK;QACD,IAAI,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;QAErC,OAAO;YACH,GAAG;YACH,WAAW;YACX,UAAU;YACV,MAAM;YACN,GAAG;SACN,CAAC;QAEF,SAAS,GAAG,CAAI,GAAW;YACvB,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAkB,CAAC;QACzC,CAAC;QAED,SAAS,WAAW,CAAI,GAAW,EAAE,OAAgB;YACjD,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACtB,KAAK,GAAG,OAAO,EAAE,CAAC;gBAClB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,CAAC;YAED,OAAO,KAAU,CAAC;QACtB,CAAC;QAED,SAAS,GAAG,CAAI,GAAW,EAAE,KAAQ;YACjC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACpB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,SAAS,MAAM,CAAC,GAAW;YACvB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;QAED,SAAS,UAAU;YACf,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QACpB,CAAC;IACL,CAAC;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const depsCacheSymbol = Symbol('ioc:deps');
|
|
2
|
+
/**
|
|
3
|
+
* Returns a set of all direct and nested dependencies of a service.
|
|
4
|
+
*/
|
|
5
|
+
export function getAllDeps(injectable) {
|
|
6
|
+
let deps = injectable[depsCacheSymbol];
|
|
7
|
+
if (deps) {
|
|
8
|
+
return deps;
|
|
9
|
+
}
|
|
10
|
+
deps = new Set();
|
|
11
|
+
injectable[depsCacheSymbol] = deps;
|
|
12
|
+
if (!injectable.deps) {
|
|
13
|
+
return deps;
|
|
14
|
+
}
|
|
15
|
+
for (const dep of Object.values(injectable.deps)) {
|
|
16
|
+
deps.add(dep);
|
|
17
|
+
const nestedDeps = getAllDeps(dep);
|
|
18
|
+
for (const nestedDep of nestedDeps) {
|
|
19
|
+
deps.add(nestedDep);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
deps = Object.freeze(deps);
|
|
23
|
+
return deps;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=getAllDeps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllDeps.js","sourceRoot":"","sources":["../../src/utils/getAllDeps.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAM3C;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,UAAsB;IAC7C,IAAI,IAAI,GAAI,UAAiC,CAAC,eAAe,CAAC,CAAC;IAE/D,IAAI,IAAI,EAAE,CAAC;QACP,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,GAAG,IAAI,GAAG,EAAc,CAAC;IAC5B,UAAiC,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;IAE3D,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;IACL,CAAC;IAED,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getAllDeps } from './getAllDeps.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a service is dependent on an injectable.
|
|
4
|
+
*/
|
|
5
|
+
export function isDependentOn(service, injectable) {
|
|
6
|
+
const deps = getAllDeps(service);
|
|
7
|
+
return deps.has(injectable);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=isDependentOn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isDependentOn.js","sourceRoot":"","sources":["../../src/utils/isDependentOn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,UAAsB;IAClE,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Container } from '../Container.js';
|
|
2
2
|
import type { Injectable } from '../Injectable.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Dependencies, ResolveDeps } from '../Service.js';
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the dependencies of a service.
|
|
6
6
|
* @param deps - The dependencies to resolve.
|
|
@@ -8,4 +8,4 @@ import type { ServiceDependencies } from '../Service.js';
|
|
|
8
8
|
* @param caller - The caller of the service.
|
|
9
9
|
* @returns The resolved dependencies.
|
|
10
10
|
*/
|
|
11
|
-
export declare function resolveDeps(deps:
|
|
11
|
+
export declare function resolveDeps<TDeps extends Dependencies>(deps: TDeps, container: Container, caller?: Injectable): ResolveDeps<TDeps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveDeps.js","sourceRoot":"","sources":["../../src/utils/resolveDeps.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"resolveDeps.js","sourceRoot":"","sources":["../../src/utils/resolveDeps.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACvB,IAAW,EACX,SAAoB,EACpB,MAAmB;IAEnB,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,QAA8B,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Service } from '../Service.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sorts an array of services by dependency using topological sort.
|
|
4
|
+
* Services with no dependencies come first, followed by their dependents.
|
|
5
|
+
* @__NO_SIDE_EFFECTS__
|
|
6
|
+
*/
|
|
7
|
+
export declare function sortByDependency<S extends Service>(services: S[]): S[];
|