@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.
@@ -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 = Type<A>("A");
31
- * const B = Type<B>("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 = Type<A>("A");
43
- * const B = Type<B>("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 = Type<Spell>("Spell");
55
+ * const Spell = createType<Spell>("Spell");
56
56
  * ```
57
57
  *
58
58
  * @__NO_SIDE_EFFECTS__
59
59
  */
60
- declare function Type<T>(typeName: string): Type<T>;
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
- * Build(() => {
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 Build<Value>(factory: (...args: []) => Value): Type<Value>;
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: boolean): Instance | undefined;
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: boolean): Value | undefined;
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: boolean): Instance[];
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: boolean): NonNullable<Value>[];
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, Build, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, Type, applyMiddleware, createContainer, forwardRef, inject, injectAll, injectBy };
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 = Type<Spell>("Spell");
236
+ * const Spell = createType<Spell>("Spell");
237
237
  * ```
238
238
  *
239
239
  * @__NO_SIDE_EFFECTS__
240
- */ function Type(typeName) {
240
+ */ function createType(typeName) {
241
241
  const type = {
242
242
  name: `Type<${typeName}>`,
243
- inter: Type,
244
- union: Type,
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
- * Build(() => {
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 Build(factory) {
362
- const token = Type(`Build<${getTypeName(factory)}>`);
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__*/ Build(function Injector() {
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, Build, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, Type, applyMiddleware, createContainer, forwardRef, inject, injectAll, injectBy };
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