ditox 3.2.0 → 3.3.1
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/README.md +76 -27
- package/dist/index.cjs +531 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{umd/index.d.ts → index.d.cts} +191 -196
- package/dist/{browser/index.d.ts → index.d.ts} +191 -196
- package/dist/index.js +514 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +537 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +22 -20
- package/src/container.test.ts +77 -33
- package/src/container.ts +26 -11
- package/src/index.ts +22 -24
- package/src/modules.test.ts +190 -37
- package/src/modules.ts +22 -5
- package/src/removal-compatibility.test.ts +259 -0
- package/src/removal.test.ts +190 -0
- package/src/tokens.test.ts +9 -8
- package/src/tokens.ts +2 -2
- package/src/utils.test.ts +18 -17
- package/src/utils.ts +21 -21
- package/dist/browser/index.js +0 -2
- package/dist/browser/index.js.map +0 -1
- package/dist/cjs/container.d.ts +0 -93
- package/dist/cjs/container.js +0 -216
- package/dist/cjs/container.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/modules.d.ts +0 -121
- package/dist/cjs/modules.js +0 -143
- package/dist/cjs/modules.js.map +0 -1
- package/dist/cjs/tokens.d.ts +0 -56
- package/dist/cjs/tokens.js +0 -20
- package/dist/cjs/tokens.js.map +0 -1
- package/dist/cjs/utils.d.ts +0 -137
- package/dist/cjs/utils.js +0 -156
- package/dist/cjs/utils.js.map +0 -1
- package/dist/esm/container.d.ts +0 -93
- package/dist/esm/container.js +0 -211
- package/dist/esm/container.js.map +0 -1
- package/dist/esm/index.d.ts +0 -7
- package/dist/esm/index.js +0 -5
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/modules.d.ts +0 -121
- package/dist/esm/modules.js +0 -136
- package/dist/esm/modules.js.map +0 -1
- package/dist/esm/tokens.d.ts +0 -56
- package/dist/esm/tokens.js +0 -15
- package/dist/esm/tokens.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -137
- package/dist/esm/utils.js +0 -145
- package/dist/esm/utils.js.map +0 -1
- package/dist/umd/index.js +0 -2
- package/dist/umd/index.js.map +0 -1
package/dist/cjs/modules.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.declareModuleBindings = exports.declareModule = exports.bindModules = exports.bindModule = void 0;
|
|
4
|
-
const tokens_1 = require("./tokens");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
/**
|
|
7
|
-
* Binds the dependency module to the container
|
|
8
|
-
* @param container - Dependency container.
|
|
9
|
-
* @param moduleDeclaration - Declaration of the dependency module.
|
|
10
|
-
* @param options - Options for module binding.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* bindModule(container, LOGGER_MODULE);
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
function bindModule(container, moduleDeclaration, options) {
|
|
18
|
-
var _a, _b, _c;
|
|
19
|
-
const rootEntry = {
|
|
20
|
-
module: moduleDeclaration,
|
|
21
|
-
options: options !== null && options !== void 0 ? options : {},
|
|
22
|
-
};
|
|
23
|
-
const bfsVisits = new Set([rootEntry]);
|
|
24
|
-
const bfsQueue = [rootEntry];
|
|
25
|
-
let bfsIndex = 0;
|
|
26
|
-
while (bfsIndex < bfsQueue.length) {
|
|
27
|
-
const entry = bfsQueue[bfsIndex];
|
|
28
|
-
const m = 'module' in entry ? entry.module : entry;
|
|
29
|
-
(_a = m.imports) === null || _a === void 0 ? void 0 : _a.forEach((depEntry) => {
|
|
30
|
-
if (!bfsVisits.has(depEntry)) {
|
|
31
|
-
bfsVisits.add(depEntry);
|
|
32
|
-
bfsQueue.push(depEntry);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
bfsIndex++;
|
|
36
|
-
}
|
|
37
|
-
for (let i = 0; i < bfsQueue.length; i++) {
|
|
38
|
-
const entry = bfsQueue[i];
|
|
39
|
-
const m = 'module' in entry ? entry.module : entry;
|
|
40
|
-
(_b = m.beforeBinding) === null || _b === void 0 ? void 0 : _b.call(m, container);
|
|
41
|
-
}
|
|
42
|
-
for (let i = 0; i < bfsQueue.length; i++) {
|
|
43
|
-
const entry = bfsQueue[i];
|
|
44
|
-
bindModuleEntry(container, entry);
|
|
45
|
-
}
|
|
46
|
-
for (let i = bfsQueue.length - 1; i >= 0; i--) {
|
|
47
|
-
const entry = bfsQueue[i];
|
|
48
|
-
const m = 'module' in entry ? entry.module : entry;
|
|
49
|
-
(_c = m.afterBinding) === null || _c === void 0 ? void 0 : _c.call(m, container);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.bindModule = bindModule;
|
|
53
|
-
function bindModuleEntry(container, entry) {
|
|
54
|
-
let module;
|
|
55
|
-
let options;
|
|
56
|
-
if ('module' in entry) {
|
|
57
|
-
module = entry.module;
|
|
58
|
-
options = entry.options;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
module = entry;
|
|
62
|
-
}
|
|
63
|
-
const scope = options === null || options === void 0 ? void 0 : options.scope;
|
|
64
|
-
const exportedValueTokens = new Set();
|
|
65
|
-
const moduleExports = module.exports;
|
|
66
|
-
if (moduleExports) {
|
|
67
|
-
const keys = Object.keys(moduleExports);
|
|
68
|
-
keys.forEach((valueKey) => {
|
|
69
|
-
const valueToken = moduleExports[valueKey];
|
|
70
|
-
if (valueToken) {
|
|
71
|
-
exportedValueTokens.add(valueToken);
|
|
72
|
-
container.bindFactory(valueToken, (0, utils_1.injectable)((module) => module[valueKey], module.token), { scope });
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
container.bindFactory(module.token, module.factory, {
|
|
77
|
-
scope,
|
|
78
|
-
onRemoved: (moduleInstance) => {
|
|
79
|
-
if (moduleInstance.destroy) {
|
|
80
|
-
moduleInstance.destroy();
|
|
81
|
-
}
|
|
82
|
-
exportedValueTokens.forEach((valueToken) => container.remove(valueToken));
|
|
83
|
-
exportedValueTokens.clear();
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Binds dependency modules to the container
|
|
89
|
-
*
|
|
90
|
-
* @param container - Dependency container for binding
|
|
91
|
-
* @param modules - Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects.
|
|
92
|
-
*/
|
|
93
|
-
function bindModules(container, modules) {
|
|
94
|
-
modules.forEach((entry) => {
|
|
95
|
-
if ('module' in entry) {
|
|
96
|
-
bindModule(container, entry.module, entry.options);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
bindModule(container, entry);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.bindModules = bindModules;
|
|
104
|
-
/**
|
|
105
|
-
* Declares a module binding
|
|
106
|
-
*
|
|
107
|
-
* @param declaration - a module declaration
|
|
108
|
-
* @param declaration.token - optional field
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
113
|
-
* factory: (container) => {
|
|
114
|
-
* const transport = container.resolve(TRANSPORT_TOKEN).open();
|
|
115
|
-
* return {
|
|
116
|
-
* logger: { log: (message) => transport.write(message) },
|
|
117
|
-
* destroy: () => transport.close(),
|
|
118
|
-
* }
|
|
119
|
-
* },
|
|
120
|
-
* exports: {
|
|
121
|
-
* logger: LOGGER_TOKEN,
|
|
122
|
-
* },
|
|
123
|
-
* });
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
function declareModule(declaration) {
|
|
127
|
-
var _a;
|
|
128
|
-
return { ...declaration, token: (_a = declaration.token) !== null && _a !== void 0 ? _a : (0, tokens_1.token)() };
|
|
129
|
-
}
|
|
130
|
-
exports.declareModule = declareModule;
|
|
131
|
-
/**
|
|
132
|
-
* Declares bindings of several modules
|
|
133
|
-
*
|
|
134
|
-
* @param modules - module declaration entries
|
|
135
|
-
*/
|
|
136
|
-
function declareModuleBindings(modules) {
|
|
137
|
-
return declareModule({
|
|
138
|
-
factory: () => ({}),
|
|
139
|
-
imports: modules,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
exports.declareModuleBindings = declareModuleBindings;
|
|
143
|
-
//# sourceMappingURL=modules.js.map
|
package/dist/cjs/modules.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../../src/modules.ts"],"names":[],"mappings":";;;AACA,qCAAsC;AACtC,mCAAmC;AAyFnC;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,SAAoB,EACpB,iBAAuC,EACvC,OAA2B;;IAE3B,MAAM,SAAS,GAAuB;QACpC,MAAM,EAAE,iBAAiB;QACzB,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE;KACvB,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAyB,CAAC,SAAS,CAAC,CAAC;IAEnD,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,OAAO,QAAQ,GAAG,QAAQ,CAAC,MAAM,EAAE;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEjC,MAAM,CAAC,GAAG,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;QAEnD,MAAA,CAAC,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBAC5B,SAAS,CAAC,GAAG,CAA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AK,EAAE,EAAE;QACxB,IAAI,QAAQ,IAAI,KAAK,EAAE;YACrB,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;SACpD;aAAM;YACL,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SAC9B;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAXD,kCAWC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,aAAa,CAC3B,WAC8C;;IAE9C,OAAO,EAAC,GAAG,WAAW,EAAE,KAAK,EAAE,MAAA,WAAW,CAAC,KAAK,mCAAI,IAAA,cAAK,GAAE,EAAC,CAAC;AAC/D,CAAC;AALD,sCAKC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CACnC,OAA0C;IAE1C,OAAO,aAAa,CAAC;QACnB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;QACnB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;AACL,CAAC;AAPD,sDAOC"}
|
package/dist/cjs/tokens.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @ignore
|
|
3
|
-
* Binding token for mandatory value
|
|
4
|
-
*/
|
|
5
|
-
export type RequiredToken<T> = {
|
|
6
|
-
symbol: symbol;
|
|
7
|
-
type?: T;
|
|
8
|
-
isOptional?: false;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @ignore
|
|
12
|
-
* Binding token for optional value
|
|
13
|
-
*/
|
|
14
|
-
export type OptionalToken<T> = {
|
|
15
|
-
symbol: symbol;
|
|
16
|
-
type?: T;
|
|
17
|
-
isOptional: true;
|
|
18
|
-
optionalValue: T;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Binding token
|
|
22
|
-
*/
|
|
23
|
-
export type Token<T> = RequiredToken<T> | OptionalToken<T>;
|
|
24
|
-
/**
|
|
25
|
-
* Token options
|
|
26
|
-
*/
|
|
27
|
-
export type TokenOptions = {
|
|
28
|
-
/**
|
|
29
|
-
* Key for token's symbol. It allows to create shareable tokens.
|
|
30
|
-
*/
|
|
31
|
-
key: string;
|
|
32
|
-
/** @ignore */
|
|
33
|
-
description?: undefined;
|
|
34
|
-
} | {
|
|
35
|
-
/** Description for better error messages */
|
|
36
|
-
description?: string;
|
|
37
|
-
/** @ignore */
|
|
38
|
-
key?: undefined;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Creates a new binding token.
|
|
42
|
-
* @param description - Token description for better error messages.
|
|
43
|
-
*/
|
|
44
|
-
export declare function token<T>(description?: string): Token<T>;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a new binding token.
|
|
47
|
-
* @param options - Token description for better error messages.
|
|
48
|
-
*/ export declare function token<T>(options?: TokenOptions): Token<T>;
|
|
49
|
-
/**
|
|
50
|
-
* Decorate a token with an optional value.
|
|
51
|
-
* This value is be used as default value in case a container does not have registered token.
|
|
52
|
-
* @param token - Existed token.
|
|
53
|
-
* @param optionalValue - Default value for the resolver.
|
|
54
|
-
*/
|
|
55
|
-
export declare function optional<T>(token: Token<T>, optionalValue: T): OptionalToken<T>;
|
|
56
|
-
export declare function optional<T>(token: Token<T>): OptionalToken<T | undefined>;
|
package/dist/cjs/tokens.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.optional = exports.token = void 0;
|
|
4
|
-
function token(options) {
|
|
5
|
-
const normalized = typeof options === 'string' ? { description: options } : options;
|
|
6
|
-
const symbol = (normalized === null || normalized === void 0 ? void 0 : normalized.key)
|
|
7
|
-
? Symbol.for(normalized.key)
|
|
8
|
-
: Symbol(normalized === null || normalized === void 0 ? void 0 : normalized.description);
|
|
9
|
-
return { symbol };
|
|
10
|
-
}
|
|
11
|
-
exports.token = token;
|
|
12
|
-
function optional(token, optionalValue) {
|
|
13
|
-
return {
|
|
14
|
-
symbol: token.symbol,
|
|
15
|
-
isOptional: true,
|
|
16
|
-
optionalValue,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
exports.optional = optional;
|
|
20
|
-
//# sourceMappingURL=tokens.js.map
|
package/dist/cjs/tokens.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/tokens.ts"],"names":[],"mappings":";;;AAwDA,SAAgB,KAAK,CAAI,OAA+B;IACtD,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAC,WAAW,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAEjE,MAAM,MAAM,GAAW,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG;QACpC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QAC5B,CAAC,CAAC,MAAM,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,CAAC,CAAC;IAEpC,OAAO,EAAC,MAAM,EAAC,CAAC;AAClB,CAAC;AATD,sBASC;AAaD,SAAgB,QAAQ,CACtB,KAAe,EACf,aAAiB;IAEjB,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,UAAU,EAAE,IAAI;QAChB,aAAa;KACd,CAAC;AACJ,CAAC;AATD,4BASC"}
|
package/dist/cjs/utils.d.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import type { Container } from './container';
|
|
2
|
-
import { Token } from './tokens';
|
|
3
|
-
type ValuesProps = {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
};
|
|
6
|
-
type TokenProps<Props extends ValuesProps> = {
|
|
7
|
-
[K in keyof Props]: Token<Props[K]>;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Checks if a value is the token
|
|
11
|
-
*/
|
|
12
|
-
export declare function isToken<T>(value: unknown): value is Token<T>;
|
|
13
|
-
/**
|
|
14
|
-
* Rebinds the array by the token with added new value.
|
|
15
|
-
* @param container - Dependency container.
|
|
16
|
-
* @param token - Token for an array of values.
|
|
17
|
-
* @param value - New value which is added to the end of the array.
|
|
18
|
-
*/
|
|
19
|
-
export declare function bindMultiValue<T>(container: Container, token: Token<ReadonlyArray<T>>, value: T): void;
|
|
20
|
-
/**
|
|
21
|
-
* Tries to resolve a value by the provided token.
|
|
22
|
-
*
|
|
23
|
-
* If an argument is an object which has tokens as its properties,
|
|
24
|
-
* then returns an object containing resolved values as properties.
|
|
25
|
-
|
|
26
|
-
* If a token is not found, then `undefined` value is used.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const value = tryResolveValue(container, tokenA);
|
|
31
|
-
* console.log(value); // 1
|
|
32
|
-
*
|
|
33
|
-
* const props = tryResolveValue(container, {a: tokenA, b: tokenB});
|
|
34
|
-
* console.log(props); // {a: 1, b: 2}
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare function tryResolveValue<Tokens extends Token<unknown> | {
|
|
38
|
-
[key: string]: Token<unknown>;
|
|
39
|
-
}, Values extends Tokens extends Token<infer V> ? V | undefined : Tokens extends TokenProps<infer Props> ? Partial<Props> : never>(container: Container, token: Tokens): Values;
|
|
40
|
-
/**
|
|
41
|
-
* Returns an array of resolved values or objects with resolved values.
|
|
42
|
-
*
|
|
43
|
-
* If an item of the array is an object which has tokens as its properties,
|
|
44
|
-
* then returns an object containing resolved values as properties.
|
|
45
|
-
|
|
46
|
-
* If a token is not found, then `undefined` value is used.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const items1 = tryResolveValues(container, tokenA);
|
|
51
|
-
* console.log(items1); // [1]
|
|
52
|
-
*
|
|
53
|
-
* const items2 = tryResolveValues(container, tokenA, {a: tokenA, b: tokenB});
|
|
54
|
-
* console.log(items2); // [1, {a: 1, b: 2}]
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare function tryResolveValues<Tokens extends (Token<unknown> | {
|
|
58
|
-
[key: string]: Token<unknown>;
|
|
59
|
-
})[], Values extends {
|
|
60
|
-
[K in keyof Tokens]: Tokens[K] extends Token<infer V> ? V | undefined : Tokens[K] extends TokenProps<infer Props> ? Partial<Props> : never;
|
|
61
|
-
}>(container: Container, ...tokens: Tokens): Values;
|
|
62
|
-
/**
|
|
63
|
-
* Resolves a value by the provided token.
|
|
64
|
-
*
|
|
65
|
-
* If an argument is an object which has tokens as its properties,
|
|
66
|
-
* then returns an object containing resolved values as properties.
|
|
67
|
-
|
|
68
|
-
* If a value is not found by the token, then `ResolverError` is thrown.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* const value = resolveValue(container, tokenA);
|
|
73
|
-
* console.log(value); // 1
|
|
74
|
-
*
|
|
75
|
-
* const props = resolveValue(container, {a: tokenA, b: tokenB});
|
|
76
|
-
* console.log(props); // {a: 1, b: 2}
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export declare function resolveValue<Tokens extends Token<unknown> | {
|
|
80
|
-
[key: string]: Token<unknown>;
|
|
81
|
-
}, Values extends Tokens extends Token<infer V> ? V : Tokens extends TokenProps<infer Props> ? Props : never>(container: Container, token: Tokens): Values;
|
|
82
|
-
/**
|
|
83
|
-
* Returns an array of resolved values or objects with resolved values.
|
|
84
|
-
*
|
|
85
|
-
* If an item of the array is an object which has tokens as its properties,
|
|
86
|
-
* then returns an object containing resolved values as properties.
|
|
87
|
-
|
|
88
|
-
* If a token is not found, then `ResolverError` is thrown.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* const items1 = resolveValues(container, tokenA);
|
|
93
|
-
* console.log(items1); // [1]
|
|
94
|
-
*
|
|
95
|
-
* const items2 = resolveValues(container, tokenA, {a: tokenA, b: tokenB});
|
|
96
|
-
* console.log(items2); // [1, {a: 1, b: 2}]
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export declare function resolveValues<Tokens extends (Token<unknown> | {
|
|
100
|
-
[key: string]: Token<unknown>;
|
|
101
|
-
})[], Values extends {
|
|
102
|
-
[K in keyof Tokens]: Tokens[K] extends Token<infer V> ? V : Tokens[K] extends TokenProps<infer Props> ? Props : never;
|
|
103
|
-
}>(container: Container, ...tokens: Tokens): Values;
|
|
104
|
-
/**
|
|
105
|
-
* Decorates a factory by passing resolved values as factory arguments.
|
|
106
|
-
*
|
|
107
|
-
* If an argument is an object which has tokens as its properties,
|
|
108
|
-
* then returns an object containing resolved values as properties.
|
|
109
|
-
*
|
|
110
|
-
* @param factory - A factory.
|
|
111
|
-
* @param tokens - Tokens which correspond to factory arguments.
|
|
112
|
-
*
|
|
113
|
-
* @return Decorated factory which takes a dependency container as a single argument.
|
|
114
|
-
*/
|
|
115
|
-
export declare function injectable<Tokens extends (Token<unknown> | {
|
|
116
|
-
[key: string]: Token<unknown>;
|
|
117
|
-
})[], Values extends {
|
|
118
|
-
[K in keyof Tokens]: Tokens[K] extends Token<infer V> ? V : Tokens[K] extends TokenProps<infer Props> ? Props : never;
|
|
119
|
-
}, Result>(this: unknown, factory: (...params: Values) => Result, ...tokens: Tokens): (container: Container) => Result;
|
|
120
|
-
/**
|
|
121
|
-
* Decorates a class by passing resolved values as arguments to its constructor.
|
|
122
|
-
*
|
|
123
|
-
* If an argument is an object which has tokens as its properties,
|
|
124
|
-
* then returns an object containing resolved values as properties.
|
|
125
|
-
*
|
|
126
|
-
* @param constructor - Constructor of a class
|
|
127
|
-
* @param tokens - Tokens which correspond to constructor arguments
|
|
128
|
-
*
|
|
129
|
-
* @return A factory function which takes a dependency container as a single argument
|
|
130
|
-
* and returns a new created class.
|
|
131
|
-
*/
|
|
132
|
-
export declare function injectableClass<Tokens extends (Token<unknown> | {
|
|
133
|
-
[key: string]: Token<unknown>;
|
|
134
|
-
})[], Values extends {
|
|
135
|
-
[K in keyof Tokens]: Tokens[K] extends Token<infer V> ? V : Tokens[K] extends TokenProps<infer Props> ? Props : never;
|
|
136
|
-
}, Result>(this: unknown, constructor: new (...params: Values) => Result, ...tokens: Tokens): (container: Container) => Result;
|
|
137
|
-
export {};
|
package/dist/cjs/utils.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.injectableClass = exports.injectable = exports.resolveValues = exports.resolveValue = exports.tryResolveValues = exports.tryResolveValue = exports.bindMultiValue = exports.isToken = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Checks if a value is the token
|
|
6
|
-
*/
|
|
7
|
-
function isToken(value) {
|
|
8
|
-
return (value !== undefined &&
|
|
9
|
-
value !== null &&
|
|
10
|
-
typeof value === 'object' &&
|
|
11
|
-
'symbol' in value &&
|
|
12
|
-
typeof value.symbol === 'symbol');
|
|
13
|
-
}
|
|
14
|
-
exports.isToken = isToken;
|
|
15
|
-
/**
|
|
16
|
-
* Rebinds the array by the token with added new value.
|
|
17
|
-
* @param container - Dependency container.
|
|
18
|
-
* @param token - Token for an array of values.
|
|
19
|
-
* @param value - New value which is added to the end of the array.
|
|
20
|
-
*/
|
|
21
|
-
function bindMultiValue(container, token, value) {
|
|
22
|
-
var _a;
|
|
23
|
-
const prevValues = (_a = container.get(token)) !== null && _a !== void 0 ? _a : [];
|
|
24
|
-
const nextValues = [...prevValues, value];
|
|
25
|
-
container.bindValue(token, nextValues);
|
|
26
|
-
}
|
|
27
|
-
exports.bindMultiValue = bindMultiValue;
|
|
28
|
-
/**
|
|
29
|
-
* Tries to resolve a value by the provided token.
|
|
30
|
-
*
|
|
31
|
-
* If an argument is an object which has tokens as its properties,
|
|
32
|
-
* then returns an object containing resolved values as properties.
|
|
33
|
-
|
|
34
|
-
* If a token is not found, then `undefined` value is used.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const value = tryResolveValue(container, tokenA);
|
|
39
|
-
* console.log(value); // 1
|
|
40
|
-
*
|
|
41
|
-
* const props = tryResolveValue(container, {a: tokenA, b: tokenB});
|
|
42
|
-
* console.log(props); // {a: 1, b: 2}
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
function tryResolveValue(container, token) {
|
|
46
|
-
if (isToken(token)) {
|
|
47
|
-
return container.get(token);
|
|
48
|
-
}
|
|
49
|
-
const obj = {};
|
|
50
|
-
Object.keys(token).forEach((key) => (obj[key] = container.get(token[key])));
|
|
51
|
-
return obj;
|
|
52
|
-
}
|
|
53
|
-
exports.tryResolveValue = tryResolveValue;
|
|
54
|
-
/**
|
|
55
|
-
* Returns an array of resolved values or objects with resolved values.
|
|
56
|
-
*
|
|
57
|
-
* If an item of the array is an object which has tokens as its properties,
|
|
58
|
-
* then returns an object containing resolved values as properties.
|
|
59
|
-
|
|
60
|
-
* If a token is not found, then `undefined` value is used.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const items1 = tryResolveValues(container, tokenA);
|
|
65
|
-
* console.log(items1); // [1]
|
|
66
|
-
*
|
|
67
|
-
* const items2 = tryResolveValues(container, tokenA, {a: tokenA, b: tokenB});
|
|
68
|
-
* console.log(items2); // [1, {a: 1, b: 2}]
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
function tryResolveValues(container, ...tokens) {
|
|
72
|
-
return tokens.map((item) => tryResolveValue(container, item));
|
|
73
|
-
}
|
|
74
|
-
exports.tryResolveValues = tryResolveValues;
|
|
75
|
-
/**
|
|
76
|
-
* Resolves a value by the provided token.
|
|
77
|
-
*
|
|
78
|
-
* If an argument is an object which has tokens as its properties,
|
|
79
|
-
* then returns an object containing resolved values as properties.
|
|
80
|
-
|
|
81
|
-
* If a value is not found by the token, then `ResolverError` is thrown.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const value = resolveValue(container, tokenA);
|
|
86
|
-
* console.log(value); // 1
|
|
87
|
-
*
|
|
88
|
-
* const props = resolveValue(container, {a: tokenA, b: tokenB});
|
|
89
|
-
* console.log(props); // {a: 1, b: 2}
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
function resolveValue(container, token) {
|
|
93
|
-
if (isToken(token)) {
|
|
94
|
-
return container.resolve(token);
|
|
95
|
-
}
|
|
96
|
-
const obj = {};
|
|
97
|
-
Object.keys(token).forEach((key) => (obj[key] = container.resolve(token[key])));
|
|
98
|
-
return obj;
|
|
99
|
-
}
|
|
100
|
-
exports.resolveValue = resolveValue;
|
|
101
|
-
/**
|
|
102
|
-
* Returns an array of resolved values or objects with resolved values.
|
|
103
|
-
*
|
|
104
|
-
* If an item of the array is an object which has tokens as its properties,
|
|
105
|
-
* then returns an object containing resolved values as properties.
|
|
106
|
-
|
|
107
|
-
* If a token is not found, then `ResolverError` is thrown.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const items1 = resolveValues(container, tokenA);
|
|
112
|
-
* console.log(items1); // [1]
|
|
113
|
-
*
|
|
114
|
-
* const items2 = resolveValues(container, tokenA, {a: tokenA, b: tokenB});
|
|
115
|
-
* console.log(items2); // [1, {a: 1, b: 2}]
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
function resolveValues(container, ...tokens) {
|
|
119
|
-
return tokens.map((item) => resolveValue(container, item));
|
|
120
|
-
}
|
|
121
|
-
exports.resolveValues = resolveValues;
|
|
122
|
-
/**
|
|
123
|
-
* Decorates a factory by passing resolved values as factory arguments.
|
|
124
|
-
*
|
|
125
|
-
* If an argument is an object which has tokens as its properties,
|
|
126
|
-
* then returns an object containing resolved values as properties.
|
|
127
|
-
*
|
|
128
|
-
* @param factory - A factory.
|
|
129
|
-
* @param tokens - Tokens which correspond to factory arguments.
|
|
130
|
-
*
|
|
131
|
-
* @return Decorated factory which takes a dependency container as a single argument.
|
|
132
|
-
*/
|
|
133
|
-
function injectable(factory, ...tokens) {
|
|
134
|
-
return (container) => {
|
|
135
|
-
const values = resolveValues(container, ...tokens);
|
|
136
|
-
return factory.apply(this, values);
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
exports.injectable = injectable;
|
|
140
|
-
/**
|
|
141
|
-
* Decorates a class by passing resolved values as arguments to its constructor.
|
|
142
|
-
*
|
|
143
|
-
* If an argument is an object which has tokens as its properties,
|
|
144
|
-
* then returns an object containing resolved values as properties.
|
|
145
|
-
*
|
|
146
|
-
* @param constructor - Constructor of a class
|
|
147
|
-
* @param tokens - Tokens which correspond to constructor arguments
|
|
148
|
-
*
|
|
149
|
-
* @return A factory function which takes a dependency container as a single argument
|
|
150
|
-
* and returns a new created class.
|
|
151
|
-
*/
|
|
152
|
-
function injectableClass(constructor, ...tokens) {
|
|
153
|
-
return injectable((...values) => new constructor(...values), ...tokens);
|
|
154
|
-
}
|
|
155
|
-
exports.injectableClass = injectableClass;
|
|
156
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAQA;;GAEG;AACH,SAAgB,OAAO,CAAI,KAAc;IACvC,OAAO,CACL,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,QAAQ,IAAI,KAAK;QACjB,OAAQ,KAAa,CAAC,MAAM,KAAK,QAAQ,CAC1C,CAAC;AACJ,CAAC;AARD,0BAQC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAC5B,SAAoB,EACpB,KAA8B,EAC9B,KAAQ;;IAER,MAAM,UAAU,GAAG,MAAA,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC;IAC9C,MAAM,UAA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;IACF,OAAO,GAAG,CAAC;AACb,CAAC;AAjBD,oCAiBC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,aAAa,CAS3B,SAAoB,EAAE,GAAG,MAAc;IACvC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAW,CAAC;AACvE,CAAC;AAXD,sCAWC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CAYxB,OAAsC,EACtC,GAAG,MAAc;IAEjB,OAAO,CAAC,SAAS,EAAE,EAAE;QACnB,MAAM,MAAM,GAAW,aAAa,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,CAAC;QAC3D,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC;AACJ,CAAC;AAnBD,gCAmBC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAY7B,WAA8C,EAC9C,GAAG,MAAc;IAEjB,OAAO,UAAU,CACf,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,GAAG,MAAM,CAAC,EACzC,GAAG,MAAM,CACV,CAAC;AACJ,CAAC;AAnBD,0CAmBC"}
|
package/dist/esm/container.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Token } from './tokens';
|
|
2
|
-
/**
|
|
3
|
-
* ResolverError is thrown by the resolver when a token is not found in a container.
|
|
4
|
-
*/
|
|
5
|
-
export declare class ResolverError extends Error {
|
|
6
|
-
constructor(message: string);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @see https://github.com/mnasyrov/ditox#factory-lifetimes
|
|
10
|
-
*/
|
|
11
|
-
export type FactoryScope = 'scoped' | 'singleton' | 'transient';
|
|
12
|
-
/**
|
|
13
|
-
* Options for factory binding.
|
|
14
|
-
*
|
|
15
|
-
* `scope` types:
|
|
16
|
-
* - `singleton` - **This is the default**. The value is created and cached by the most distant parent container which owns the factory function.
|
|
17
|
-
* - `scoped` - The value is created and cached by the nearest container which owns the factory function.
|
|
18
|
-
* - `transient` - The value is created every time it is resolved.
|
|
19
|
-
*
|
|
20
|
-
* `scoped` and `singleton` scopes can have `onRemoved` callback. It is called when a token is removed from the container.
|
|
21
|
-
*/
|
|
22
|
-
export type FactoryOptions<T> = {
|
|
23
|
-
scope?: 'scoped' | 'singleton';
|
|
24
|
-
onRemoved?: (value: T) => void;
|
|
25
|
-
} | {
|
|
26
|
-
scope: 'transient';
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Dependency container.
|
|
30
|
-
*/
|
|
31
|
-
export type Container = {
|
|
32
|
-
/**
|
|
33
|
-
* Binds a value for the token
|
|
34
|
-
*/
|
|
35
|
-
bindValue<T>(token: Token<T>, value: T): void;
|
|
36
|
-
/**
|
|
37
|
-
* Binds a factory for the token.
|
|
38
|
-
*/
|
|
39
|
-
bindFactory<T>(token: Token<T>, factory: (container: Container) => T, options?: FactoryOptions<T>): void;
|
|
40
|
-
/**
|
|
41
|
-
* Checks if the token is registered in the container hierarchy.
|
|
42
|
-
*/
|
|
43
|
-
hasToken(token: Token<unknown>): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Returns a resolved value by the token, or returns `undefined` in case the token is not found.
|
|
46
|
-
*/
|
|
47
|
-
get<T>(token: Token<T>): T | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Returns a resolved value by the token or throws `ResolverError` in case the token is not found.
|
|
50
|
-
*/
|
|
51
|
-
resolve<T>(token: Token<T>): T;
|
|
52
|
-
/**
|
|
53
|
-
* Removes a binding for the token.
|
|
54
|
-
*/
|
|
55
|
-
remove<T>(token: Token<T>): void;
|
|
56
|
-
/**
|
|
57
|
-
* Removes all bindings in the container.
|
|
58
|
-
*/
|
|
59
|
-
removeAll(): void;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* A subset of Container interface that provides read-only access to dependency resolution.
|
|
63
|
-
* This type is used for parent containers to allow token resolution without exposing mutation methods.
|
|
64
|
-
*/
|
|
65
|
-
export type ContainerResolver = Pick<Container, 'hasToken' | 'get' | 'resolve'>;
|
|
66
|
-
/** @internal */
|
|
67
|
-
export declare const CONTAINER: Token<Container>;
|
|
68
|
-
/** @internal */
|
|
69
|
-
export declare const PARENT_CONTAINERS: Token<ReadonlyArray<Container>>;
|
|
70
|
-
/** @internal */
|
|
71
|
-
export declare const RESOLVER: Token<Resolver>;
|
|
72
|
-
/** @internal */
|
|
73
|
-
declare const NOT_FOUND: unique symbol;
|
|
74
|
-
/** @internal */
|
|
75
|
-
type FactoryContext<T> = {
|
|
76
|
-
factory: (container: Container) => T;
|
|
77
|
-
options?: FactoryOptions<T>;
|
|
78
|
-
};
|
|
79
|
-
/** @internal */
|
|
80
|
-
export type FactoriesMap = Map<symbol, FactoryContext<any>>;
|
|
81
|
-
/** @internal */
|
|
82
|
-
export declare const FACTORIES_MAP: Token<FactoriesMap>;
|
|
83
|
-
/** @internal */
|
|
84
|
-
type Resolver = <T>(token: Token<T>, origin: Container) => T | typeof NOT_FOUND;
|
|
85
|
-
/**
|
|
86
|
-
* Creates a new dependency container.
|
|
87
|
-
*
|
|
88
|
-
* Container can have an optional parent to chain token resolution. The parent is used in case the current container does not have a registered token.
|
|
89
|
-
*
|
|
90
|
-
* @param parentArg - Optional parent container or an array of containers.
|
|
91
|
-
*/
|
|
92
|
-
export declare function createContainer(parentArg?: ContainerResolver | ReadonlyArray<ContainerResolver>): Container;
|
|
93
|
-
export {};
|