@lppedd/di-wise-neo 0.3.0 → 0.3.2
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 +64 -8
- package/dist/cjs/index.d.ts +30 -30
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +30 -30
- package/dist/es/index.mjs +9 -9
- package/dist/es/index.mjs.map +1 -1
- package/package.json +3 -5
- package/src/container.ts +0 -292
- package/src/decorators/autoRegister.ts +0 -24
- package/src/decorators/decorators.ts +0 -47
- package/src/decorators/index.ts +0 -7
- package/src/decorators/inject.ts +0 -42
- package/src/decorators/injectAll.ts +0 -45
- package/src/decorators/injectable.ts +0 -61
- package/src/decorators/optional.ts +0 -39
- package/src/decorators/optionalAll.ts +0 -42
- package/src/decorators/scoped.ts +0 -32
- package/src/defaultContainer.ts +0 -519
- package/src/errors.ts +0 -47
- package/src/index.ts +0 -16
- package/src/inject.ts +0 -88
- package/src/injectAll.ts +0 -21
- package/src/injectionContext.ts +0 -46
- package/src/injector.ts +0 -117
- package/src/metadata.ts +0 -41
- package/src/middleware.ts +0 -85
- package/src/optional.ts +0 -65
- package/src/optionalAll.ts +0 -19
- package/src/provider.ts +0 -61
- package/src/scope.ts +0 -8
- package/src/token.ts +0 -84
- package/src/tokenRegistry.ts +0 -165
- package/src/tokensRef.ts +0 -46
- package/src/utils/context.ts +0 -19
- package/src/utils/disposable.ts +0 -10
- package/src/utils/invariant.ts +0 -6
- package/src/utils/keyedStack.ts +0 -26
- package/src/utils/typeName.ts +0 -28
- package/src/utils/weakRefMap.ts +0 -28
- package/src/valueRef.ts +0 -3
package/dist/es/index.d.mts
CHANGED
@@ -1,19 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* Constructor type.
|
3
|
-
*/
|
4
|
-
interface Constructor<Instance extends object> {
|
5
|
-
new (...args: any[]): Instance;
|
6
|
-
readonly name: string;
|
7
|
-
readonly length: number;
|
8
|
-
}
|
9
|
-
/**
|
10
|
-
* Token type.
|
11
|
-
*/
|
12
|
-
type Token<Value = any> = [Value] extends [object] ? Type<Value> | Constructor<Value> : Type<Value>;
|
13
|
-
/**
|
14
|
-
* Describes a {@link Token} array with at least one element.
|
15
|
-
*/
|
16
|
-
type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];
|
17
1
|
/**
|
18
2
|
* Type API.
|
19
3
|
*/
|
@@ -27,8 +11,8 @@ interface Type<A> {
|
|
27
11
|
*
|
28
12
|
* @example
|
29
13
|
* ```ts
|
30
|
-
* const A =
|
31
|
-
* const B =
|
14
|
+
* const A = createType<A>("A");
|
15
|
+
* const B = createType<B>("B");
|
32
16
|
*
|
33
17
|
* A.inter("I", B); // => Type<A & B>
|
34
18
|
* ```
|
@@ -39,25 +23,41 @@ interface Type<A> {
|
|
39
23
|
*
|
40
24
|
* @example
|
41
25
|
* ```ts
|
42
|
-
* const A =
|
43
|
-
* const B =
|
26
|
+
* const A = createType<A>("A");
|
27
|
+
* const B = createType<B>("B");
|
44
28
|
*
|
45
29
|
* A.union("U", B); // => Type<A | B>
|
46
30
|
* ```
|
47
31
|
*/
|
48
32
|
union<B>(typeName: string, B: Type<B>): Type<A | B>;
|
49
33
|
}
|
34
|
+
/**
|
35
|
+
* Constructor type.
|
36
|
+
*/
|
37
|
+
interface Constructor<Instance extends object> {
|
38
|
+
new (...args: any[]): Instance;
|
39
|
+
readonly name: string;
|
40
|
+
readonly length: number;
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Token type.
|
44
|
+
*/
|
45
|
+
type Token<Value = any> = [Value] extends [object] ? Type<Value> | Constructor<Value> : Type<Value>;
|
46
|
+
/**
|
47
|
+
* Describes a {@link Token} array with at least one element.
|
48
|
+
*/
|
49
|
+
type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];
|
50
50
|
/**
|
51
51
|
* Create a type token.
|
52
52
|
*
|
53
53
|
* @example
|
54
54
|
* ```ts
|
55
|
-
* const Spell =
|
55
|
+
* const Spell = createType<Spell>("Spell");
|
56
56
|
* ```
|
57
57
|
*
|
58
58
|
* @__NO_SIDE_EFFECTS__
|
59
59
|
*/
|
60
|
-
declare function
|
60
|
+
declare function createType<T>(typeName: string): Type<T>;
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Provides a class instance for a token via a class constructor.
|
@@ -115,7 +115,7 @@ interface RegistrationOptions {
|
|
115
115
|
* ```ts
|
116
116
|
* class Wizard {
|
117
117
|
* wand = inject(
|
118
|
-
*
|
118
|
+
* build(() => {
|
119
119
|
* const wand = inject(Wand);
|
120
120
|
* wand.owner = this;
|
121
121
|
* // ...
|
@@ -127,7 +127,7 @@ interface RegistrationOptions {
|
|
127
127
|
*
|
128
128
|
* @__NO_SIDE_EFFECTS__
|
129
129
|
*/
|
130
|
-
declare function
|
130
|
+
declare function build<Value>(factory: (...args: []) => Value): Type<Value>;
|
131
131
|
|
132
132
|
/**
|
133
133
|
* Container creation options.
|
@@ -277,7 +277,7 @@ interface Container {
|
|
277
277
|
*/
|
278
278
|
resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;
|
279
279
|
resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;
|
280
|
-
resolve<Instance extends object>(Class: Constructor<Instance>, optional
|
280
|
+
resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;
|
281
281
|
/**
|
282
282
|
* Resolves the given token to the value associated with it.
|
283
283
|
*
|
@@ -298,7 +298,7 @@ interface Container {
|
|
298
298
|
*/
|
299
299
|
resolve<Value>(token: Token<Value>, optional?: false): Value;
|
300
300
|
resolve<Value>(token: Token<Value>, optional: true): Value | undefined;
|
301
|
-
resolve<Value>(token: Token<Value>, optional
|
301
|
+
resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;
|
302
302
|
/**
|
303
303
|
* Resolves the given class to all instances provided by the registrations associated with it.
|
304
304
|
*
|
@@ -327,7 +327,7 @@ interface Container {
|
|
327
327
|
*/
|
328
328
|
resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];
|
329
329
|
resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];
|
330
|
-
resolveAll<Instance extends object>(Class: Constructor<Instance>, optional
|
330
|
+
resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];
|
331
331
|
/**
|
332
332
|
* Resolves the given token to all values provided by the registrations associated with it.
|
333
333
|
*
|
@@ -347,7 +347,7 @@ interface Container {
|
|
347
347
|
*/
|
348
348
|
resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];
|
349
349
|
resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];
|
350
|
-
resolveAll<Value>(token: Token<Value>, optional
|
350
|
+
resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];
|
351
351
|
/**
|
352
352
|
* Disposes this container and all its cached values.
|
353
353
|
*
|
@@ -768,5 +768,5 @@ interface Middleware {
|
|
768
768
|
*/
|
769
769
|
declare function applyMiddleware(container: Container, middlewares: Middleware[]): Container;
|
770
770
|
|
771
|
-
export { AutoRegister,
|
772
|
-
export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, ValueProvider };
|
771
|
+
export { AutoRegister, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy };
|
772
|
+
export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
|
package/dist/es/index.mjs
CHANGED
@@ -233,15 +233,15 @@ const Scope = {
|
|
233
233
|
*
|
234
234
|
* @example
|
235
235
|
* ```ts
|
236
|
-
* const Spell =
|
236
|
+
* const Spell = createType<Spell>("Spell");
|
237
237
|
* ```
|
238
238
|
*
|
239
239
|
* @__NO_SIDE_EFFECTS__
|
240
|
-
*/ function
|
240
|
+
*/ function createType(typeName) {
|
241
241
|
const type = {
|
242
242
|
name: `Type<${typeName}>`,
|
243
|
-
inter:
|
244
|
-
union:
|
243
|
+
inter: createType,
|
244
|
+
union: createType,
|
245
245
|
toString () {
|
246
246
|
return type.name;
|
247
247
|
}
|
@@ -347,7 +347,7 @@ function isBuilder(provider) {
|
|
347
347
|
* ```ts
|
348
348
|
* class Wizard {
|
349
349
|
* wand = inject(
|
350
|
-
*
|
350
|
+
* build(() => {
|
351
351
|
* const wand = inject(Wand);
|
352
352
|
* wand.owner = this;
|
353
353
|
* // ...
|
@@ -358,8 +358,8 @@ function isBuilder(provider) {
|
|
358
358
|
* ```
|
359
359
|
*
|
360
360
|
* @__NO_SIDE_EFFECTS__
|
361
|
-
*/ function
|
362
|
-
const token =
|
361
|
+
*/ function build(factory) {
|
362
|
+
const token = createType(`Build<${getTypeName(factory)}>`);
|
363
363
|
const provider = {
|
364
364
|
useFactory: factory
|
365
365
|
};
|
@@ -959,7 +959,7 @@ function OptionalAll(token) {
|
|
959
959
|
* const wizard = container.resolve(Wizard);
|
960
960
|
* wizard.getWand(); // => Wand
|
961
961
|
* ```
|
962
|
-
*/ const Injector = /*@__PURE__*/
|
962
|
+
*/ const Injector = /*@__PURE__*/ build(function Injector() {
|
963
963
|
const context = ensureInjectionContext(Injector);
|
964
964
|
const resolution = context.resolution;
|
965
965
|
const dependentFrame = resolution.stack.peek();
|
@@ -1033,5 +1033,5 @@ function OptionalAll(token) {
|
|
1033
1033
|
return container;
|
1034
1034
|
}
|
1035
1035
|
|
1036
|
-
export { AutoRegister,
|
1036
|
+
export { AutoRegister, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy };
|
1037
1037
|
//# sourceMappingURL=index.mjs.map
|