@lppedd/di-wise-neo 0.21.1 → 0.22.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/cjs/index.d.ts +39 -16
- package/dist/cjs/index.js +2 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +39 -16
- package/dist/es/index.mjs +2 -6
- package/dist/es/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/cjs/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ interface RegistrationOptions {
|
|
|
29
29
|
/**
|
|
30
30
|
* The scope of the registration.
|
|
31
31
|
*/
|
|
32
|
-
readonly scope?: Scope;
|
|
32
|
+
readonly scope?: Scope | undefined;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Create a one-off type token from a factory function.
|
|
@@ -82,7 +82,7 @@ interface ProviderType<T> extends Type<T> {
|
|
|
82
82
|
/**
|
|
83
83
|
* The type's default registration options.
|
|
84
84
|
*/
|
|
85
|
-
readonly options?: RegistrationOptions;
|
|
85
|
+
readonly options?: RegistrationOptions | undefined;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Constructor type.
|
|
@@ -168,7 +168,7 @@ interface ClassProvider<Instance extends object> {
|
|
|
168
168
|
* }
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
171
|
-
readonly name?: string;
|
|
171
|
+
readonly name?: string | undefined;
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Provides a value for a token via a factory function.
|
|
@@ -196,7 +196,7 @@ interface FactoryProvider<Value> {
|
|
|
196
196
|
* }
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
|
-
readonly name?: string;
|
|
199
|
+
readonly name?: string | undefined;
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
202
|
* Provides a static - already constructed - value for a token.
|
|
@@ -221,7 +221,7 @@ interface ValueProvider<Value> {
|
|
|
221
221
|
* }
|
|
222
222
|
* ```
|
|
223
223
|
*/
|
|
224
|
-
readonly name?: string;
|
|
224
|
+
readonly name?: string | undefined;
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
227
|
* Aliases another registered token.
|
|
@@ -244,7 +244,7 @@ interface ExistingProvider<Value> {
|
|
|
244
244
|
* });
|
|
245
245
|
* ```
|
|
246
246
|
*/
|
|
247
|
-
readonly useExisting: Token<Value> | [Token<Value>, string?];
|
|
247
|
+
readonly useExisting: Token<Value> | [Token<Value>, (string | undefined)?];
|
|
248
248
|
/**
|
|
249
249
|
* An optional name to qualify this provider.
|
|
250
250
|
* If specified, the token must be resolved using the same name.
|
|
@@ -260,13 +260,19 @@ interface ExistingProvider<Value> {
|
|
|
260
260
|
* }
|
|
261
261
|
* ```
|
|
262
262
|
*/
|
|
263
|
-
readonly name?: string;
|
|
263
|
+
readonly name?: string | undefined;
|
|
264
264
|
}
|
|
265
265
|
/**
|
|
266
266
|
* A token provider.
|
|
267
267
|
*/
|
|
268
268
|
type Provider<Value> = ClassProvider<Value & object> | FactoryProvider<Value> | ValueProvider<Value> | ExistingProvider<Value>;
|
|
269
269
|
|
|
270
|
+
type RequiredNonNullable<T> = {
|
|
271
|
+
[P in keyof T]-?: NonNullable<T[P]>;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
type ProviderFor<V> = V extends object ? Provider<V> : Exclude<Provider<V>, ClassProvider<any>>;
|
|
275
|
+
type RegistrationOptionsFor<P> = P extends ValueProvider<any> ? never : RegistrationOptions;
|
|
270
276
|
/**
|
|
271
277
|
* Container creation options.
|
|
272
278
|
*/
|
|
@@ -276,20 +282,20 @@ interface ContainerOptions {
|
|
|
276
282
|
*
|
|
277
283
|
* @defaultValue Transient
|
|
278
284
|
*/
|
|
279
|
-
readonly defaultScope
|
|
285
|
+
readonly defaultScope?: Scope | undefined;
|
|
280
286
|
/**
|
|
281
287
|
* Whether to automatically register an unregistered class when resolving it as a token.
|
|
282
288
|
*
|
|
283
289
|
* @defaultValue false
|
|
284
290
|
*/
|
|
285
|
-
readonly autoRegister
|
|
291
|
+
readonly autoRegister?: boolean | undefined;
|
|
286
292
|
/**
|
|
287
293
|
* Whether to also dispose values provided via {@link ValueProvider}, which are not
|
|
288
294
|
* created or managed by the container, when the container itself is disposed.
|
|
289
295
|
*
|
|
290
296
|
* @defaultValue false
|
|
291
297
|
*/
|
|
292
|
-
readonly disposeUnmanaged
|
|
298
|
+
readonly disposeUnmanaged?: boolean | undefined;
|
|
293
299
|
}
|
|
294
300
|
/**
|
|
295
301
|
* Child container creation options.
|
|
@@ -300,7 +306,7 @@ interface ChildContainerOptions extends ContainerOptions {
|
|
|
300
306
|
*
|
|
301
307
|
* @defaultValue true
|
|
302
308
|
*/
|
|
303
|
-
readonly copyHooks
|
|
309
|
+
readonly copyHooks?: boolean | undefined;
|
|
304
310
|
}
|
|
305
311
|
/**
|
|
306
312
|
* A hook into the lifecycle of a {@link Container}.
|
|
@@ -316,14 +322,14 @@ interface ContainerHook {
|
|
|
316
322
|
* @param value - The provided value.
|
|
317
323
|
* @param scope - The {@link Scope} of the provided value.
|
|
318
324
|
*/
|
|
319
|
-
readonly onProvide?: (value: unknown, scope: Scope) => void;
|
|
325
|
+
readonly onProvide?: ((value: unknown, scope: Scope) => void) | undefined;
|
|
320
326
|
/**
|
|
321
327
|
* Called after the container has been disposed.
|
|
322
328
|
*
|
|
323
329
|
* @param values - All distinct values that were cached by the disposed container.
|
|
324
330
|
* Currently, only **Container**-scoped token values are cached.
|
|
325
331
|
*/
|
|
326
|
-
readonly onDispose?: (values: unknown[]) => void;
|
|
332
|
+
readonly onDispose?: ((values: unknown[]) => void) | undefined;
|
|
327
333
|
}
|
|
328
334
|
/**
|
|
329
335
|
* A Dependency Injection container.
|
|
@@ -332,7 +338,7 @@ interface Container {
|
|
|
332
338
|
/**
|
|
333
339
|
* The options used to create this container.
|
|
334
340
|
*/
|
|
335
|
-
readonly options: ContainerOptions
|
|
341
|
+
readonly options: RequiredNonNullable<ContainerOptions>;
|
|
336
342
|
/**
|
|
337
343
|
* The parent container, or `undefined` if this is the root container.
|
|
338
344
|
*/
|
|
@@ -346,7 +352,7 @@ interface Container {
|
|
|
346
352
|
*
|
|
347
353
|
* You can pass specific options to override the inherited ones.
|
|
348
354
|
*/
|
|
349
|
-
createChild(options?:
|
|
355
|
+
createChild(options?: ChildContainerOptions): Container;
|
|
350
356
|
/**
|
|
351
357
|
* Clears and returns all distinct values cached by this container.
|
|
352
358
|
* Values from {@link ValueProvider} registrations are not included, as they are never cached.
|
|
@@ -406,6 +412,23 @@ interface Container {
|
|
|
406
412
|
* Registers a token type with a default {@link Provider} and optional default registration options.
|
|
407
413
|
*/
|
|
408
414
|
register<Value>(token: ProviderType<Value>): Container;
|
|
415
|
+
/**
|
|
416
|
+
* Registers a {@link Provider} with a token or class.
|
|
417
|
+
*
|
|
418
|
+
* The provider must be one of:
|
|
419
|
+
* - {@link ClassProvider} via `useClass`
|
|
420
|
+
* - {@link FactoryProvider} via `useFactory`
|
|
421
|
+
* - {@link ValueProvider} via `useValue`
|
|
422
|
+
* - {@link ExistingProvider} via `useExisting`
|
|
423
|
+
*
|
|
424
|
+
* For {@link ClassProvider} registrations, the default scope is determined by the {@link Scoped}
|
|
425
|
+
* decorator applied to the provided class - if present - or by the {@link ContainerOptions.defaultScope}
|
|
426
|
+
* value, but it can be overridden by passing explicit registration options.
|
|
427
|
+
*
|
|
428
|
+
* For {@link ValueProvider} registrations, the provided value is returned as-is and never cached,
|
|
429
|
+
* and registration options do not apply.
|
|
430
|
+
*/
|
|
431
|
+
register<Value, ProviderValue extends Value, Provider extends ProviderFor<ProviderValue>>(token: Token<Value>, provider: ProviderFor<ProviderValue> & Provider, options?: RegistrationOptionsFor<Provider>): Container;
|
|
409
432
|
/**
|
|
410
433
|
* Registers a {@link ClassProvider} with a token.
|
|
411
434
|
*
|
|
@@ -638,7 +661,7 @@ interface Container {
|
|
|
638
661
|
/**
|
|
639
662
|
* Creates a new container.
|
|
640
663
|
*/
|
|
641
|
-
declare function createContainer(options?:
|
|
664
|
+
declare function createContainer(options?: ContainerOptions): Container;
|
|
642
665
|
|
|
643
666
|
/**
|
|
644
667
|
* Class decorator that enables auto-registration of an unregistered class
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
// @internal
|
|
4
3
|
function check(condition, message) {
|
|
5
4
|
if (!condition) {
|
|
6
5
|
throw new Error(tag(typeof message === "string" ? message : message()));
|
|
@@ -260,10 +259,7 @@ class Metadata {
|
|
|
260
259
|
methods: new Map()
|
|
261
260
|
};
|
|
262
261
|
this.tokenRef = {
|
|
263
|
-
|
|
264
|
-
getRefToken: ()=>{
|
|
265
|
-
check(false, "internal: unexpected getRefToken call");
|
|
266
|
-
},
|
|
262
|
+
getRefToken: ()=>check(false, "internal: unexpected getRefToken call"),
|
|
267
263
|
getRefTokens: ()=>new Set()
|
|
268
264
|
};
|
|
269
265
|
this.provider = {
|
|
@@ -645,7 +641,7 @@ function isDisposable(value) {
|
|
|
645
641
|
defaultScope: options?.defaultScope ?? this.myOptions.defaultScope,
|
|
646
642
|
autoRegister: options?.autoRegister ?? this.myOptions.autoRegister,
|
|
647
643
|
disposeUnmanaged: options?.disposeUnmanaged ?? this.myOptions.disposeUnmanaged,
|
|
648
|
-
copyHooks: options?.copyHooks
|
|
644
|
+
copyHooks: options?.copyHooks ?? true
|
|
649
645
|
});
|
|
650
646
|
this.myChildren.add(container);
|
|
651
647
|
return container;
|