ts-ioc-container 72.1.0 → 72.2.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/AGENTS.md +179 -0
- package/cjm/container/Container.js +2 -2
- package/cjm/container/EmptyContainer.js +17 -15
- package/cjm/errors/ArgumentNotFoundError.js +1 -0
- package/cjm/errors/CannonSingletonApplyTwiceError.js +2 -14
- package/cjm/errors/CannotApplySingletonTwiceError.js +18 -0
- package/cjm/errors/ContainerDisposedError.js +1 -0
- package/cjm/errors/ContainerError.js +1 -0
- package/cjm/errors/ContainerNotFoundError.js +1 -0
- package/cjm/errors/DependencyMissingKeyError.js +1 -0
- package/cjm/errors/DependencyNotFoundError.js +1 -0
- package/cjm/errors/MethodNotImplementedError.js +1 -0
- package/cjm/errors/ProviderDisposedError.js +1 -0
- package/cjm/errors/TypedEventDisposedError.js +1 -0
- package/cjm/errors/UnsupportedTokenTypeError.js +1 -0
- package/cjm/index.js +5 -3
- package/cjm/provider/Provider.js +6 -6
- package/cjm/registration/Registration.js +2 -2
- package/cjm/token/ConstantToken.js +4 -4
- package/cjm/token/FunctionToken.js +1 -1
- package/cjm/token/GroupInstanceToken.js +4 -4
- package/cjm/token/toToken.js +1 -1
- package/cjm/utils/TypedEvent.js +1 -1
- package/cjm/utils/array.js +1 -1
- package/esm/container/Container.js +2 -2
- package/esm/container/EmptyContainer.js +17 -15
- package/esm/errors/ArgumentNotFoundError.js +1 -0
- package/esm/errors/CannonSingletonApplyTwiceError.js +2 -13
- package/esm/errors/CannotApplySingletonTwiceError.js +14 -0
- package/esm/errors/ContainerDisposedError.js +1 -0
- package/esm/errors/ContainerError.js +1 -0
- package/esm/errors/ContainerNotFoundError.js +1 -0
- package/esm/errors/DependencyMissingKeyError.js +1 -0
- package/esm/errors/DependencyNotFoundError.js +1 -0
- package/esm/errors/MethodNotImplementedError.js +1 -0
- package/esm/errors/ProviderDisposedError.js +1 -0
- package/esm/errors/TypedEventDisposedError.js +1 -0
- package/esm/errors/UnsupportedTokenTypeError.js +1 -0
- package/esm/index.js +1 -0
- package/esm/provider/Provider.js +6 -6
- package/esm/registration/Registration.js +2 -2
- package/esm/token/ConstantToken.js +4 -4
- package/esm/token/FunctionToken.js +1 -1
- package/esm/token/GroupInstanceToken.js +4 -4
- package/esm/token/toToken.js +1 -1
- package/esm/utils/TypedEvent.js +1 -1
- package/esm/utils/array.js +1 -1
- package/lib/ExecutionContext.ts +6 -0
- package/lib/container/AliasMap.ts +30 -0
- package/lib/container/AutoResolveModule.ts +24 -0
- package/lib/container/Container.ts +311 -0
- package/lib/container/EmptyContainer.ts +166 -0
- package/lib/container/IContainer.ts +156 -0
- package/lib/errors/ArgumentNotFoundError.ts +13 -0
- package/lib/errors/CannonSingletonApplyTwiceError.ts +6 -0
- package/lib/errors/CannotApplySingletonTwiceError.ts +22 -0
- package/lib/errors/ContainerDisposedError.ts +13 -0
- package/lib/errors/ContainerError.ts +15 -0
- package/lib/errors/ContainerNotFoundError.ts +13 -0
- package/lib/errors/DependencyMissingKeyError.ts +13 -0
- package/lib/errors/DependencyNotFoundError.ts +13 -0
- package/lib/errors/MethodNotImplementedError.ts +13 -0
- package/lib/errors/ProviderDisposedError.ts +22 -0
- package/lib/errors/TypedEventDisposedError.ts +22 -0
- package/lib/errors/UnsupportedTokenTypeError.ts +13 -0
- package/lib/hooks/HookCollector.ts +109 -0
- package/lib/hooks/HookContext.ts +85 -0
- package/lib/hooks/combinators.ts +51 -0
- package/lib/hooks/hook.ts +89 -0
- package/lib/hooks/injectProp.ts +14 -0
- package/lib/index.ts +181 -0
- package/lib/injector/IInjector.ts +88 -0
- package/lib/injector/MetadataInjector.ts +100 -0
- package/lib/injector/ProxyInjector.ts +31 -0
- package/lib/injector/SimpleInjector.ts +20 -0
- package/lib/metadata/class.ts +50 -0
- package/lib/metadata/method.ts +47 -0
- package/lib/metadata/parameter.ts +60 -0
- package/lib/metadata/target.ts +25 -0
- package/lib/provider/IProvider.ts +65 -0
- package/lib/provider/Provider.ts +174 -0
- package/lib/registration/IRegistration.ts +235 -0
- package/lib/registration/Registration.ts +122 -0
- package/lib/select.ts +33 -0
- package/lib/token/BindToken.ts +13 -0
- package/lib/token/ClassToken.ts +72 -0
- package/lib/token/ConstantToken.ts +50 -0
- package/lib/token/FunctionToken.ts +79 -0
- package/lib/token/GroupAliasToken.ts +92 -0
- package/lib/token/GroupInstanceToken.ts +70 -0
- package/lib/token/InjectionToken.ts +46 -0
- package/lib/token/SingleAliasToken.ts +84 -0
- package/lib/token/SingleToken.ts +93 -0
- package/lib/token/toToken.ts +46 -0
- package/lib/utils/ProxyRegistry.ts +149 -0
- package/lib/utils/TypedEvent.ts +96 -0
- package/lib/utils/array.ts +28 -0
- package/lib/utils/basic.ts +34 -0
- package/lib/utils/debounce.ts +18 -0
- package/lib/utils/errorHandler.ts +34 -0
- package/lib/utils/fp.ts +86 -0
- package/lib/utils/getConstructorChain.ts +17 -0
- package/lib/utils/memoize.ts +24 -0
- package/lib/utils/once.ts +24 -0
- package/lib/utils/shallowCache.ts +22 -0
- package/lib/utils/task.ts +33 -0
- package/lib/utils/throttle.ts +17 -0
- package/package.json +5 -3
- package/typings/ExecutionContext.d.ts +2 -0
- package/typings/ExecutionContext.d.ts.map +1 -0
- package/typings/container/AliasMap.d.ts +1 -0
- package/typings/container/AliasMap.d.ts.map +1 -0
- package/typings/container/AutoResolveModule.d.ts +16 -0
- package/typings/container/AutoResolveModule.d.ts.map +1 -0
- package/typings/container/Container.d.ts +60 -0
- package/typings/container/Container.d.ts.map +1 -0
- package/typings/container/EmptyContainer.d.ts +51 -0
- package/typings/container/EmptyContainer.d.ts.map +1 -0
- package/typings/container/IContainer.d.ts +75 -0
- package/typings/container/IContainer.d.ts.map +1 -0
- package/typings/errors/ArgumentNotFoundError.d.ts +3 -0
- package/typings/errors/ArgumentNotFoundError.d.ts.map +1 -0
- package/typings/errors/CannonSingletonApplyTwiceError.d.ts +6 -6
- package/typings/errors/CannonSingletonApplyTwiceError.d.ts.map +1 -0
- package/typings/errors/CannotApplySingletonTwiceError.d.ts +12 -0
- package/typings/errors/CannotApplySingletonTwiceError.d.ts.map +1 -0
- package/typings/errors/ContainerDisposedError.d.ts +3 -0
- package/typings/errors/ContainerDisposedError.d.ts.map +1 -0
- package/typings/errors/ContainerError.d.ts +7 -0
- package/typings/errors/ContainerError.d.ts.map +1 -0
- package/typings/errors/ContainerNotFoundError.d.ts +3 -0
- package/typings/errors/ContainerNotFoundError.d.ts.map +1 -0
- package/typings/errors/DependencyMissingKeyError.d.ts +3 -0
- package/typings/errors/DependencyMissingKeyError.d.ts.map +1 -0
- package/typings/errors/DependencyNotFoundError.d.ts +3 -0
- package/typings/errors/DependencyNotFoundError.d.ts.map +1 -0
- package/typings/errors/MethodNotImplementedError.d.ts +3 -0
- package/typings/errors/MethodNotImplementedError.d.ts.map +1 -0
- package/typings/errors/ProviderDisposedError.d.ts +6 -0
- package/typings/errors/ProviderDisposedError.d.ts.map +1 -0
- package/typings/errors/TypedEventDisposedError.d.ts +6 -0
- package/typings/errors/TypedEventDisposedError.d.ts.map +1 -0
- package/typings/errors/UnsupportedTokenTypeError.d.ts +3 -0
- package/typings/errors/UnsupportedTokenTypeError.d.ts.map +1 -0
- package/typings/hooks/HookCollector.d.ts +36 -0
- package/typings/hooks/HookCollector.d.ts.map +1 -0
- package/typings/hooks/HookContext.d.ts +10 -0
- package/typings/hooks/HookContext.d.ts.map +1 -0
- package/typings/hooks/combinators.d.ts +23 -0
- package/typings/hooks/combinators.d.ts.map +1 -0
- package/typings/hooks/hook.d.ts +39 -0
- package/typings/hooks/hook.d.ts.map +1 -0
- package/typings/hooks/injectProp.d.ts +9 -0
- package/typings/hooks/injectProp.d.ts.map +1 -0
- package/typings/index.d.ts +2 -0
- package/typings/index.d.ts.map +1 -0
- package/typings/injector/IInjector.d.ts +32 -0
- package/typings/injector/IInjector.d.ts.map +1 -0
- package/typings/injector/MetadataInjector.d.ts +58 -0
- package/typings/injector/MetadataInjector.d.ts.map +1 -0
- package/typings/injector/ProxyInjector.d.ts +13 -0
- package/typings/injector/ProxyInjector.d.ts.map +1 -0
- package/typings/injector/SimpleInjector.d.ts +13 -0
- package/typings/injector/SimpleInjector.d.ts.map +1 -0
- package/typings/metadata/class.d.ts +27 -0
- package/typings/metadata/class.d.ts.map +1 -0
- package/typings/metadata/method.d.ts +24 -0
- package/typings/metadata/method.d.ts.map +1 -0
- package/typings/metadata/parameter.d.ts +21 -0
- package/typings/metadata/parameter.d.ts.map +1 -0
- package/typings/metadata/target.d.ts +19 -0
- package/typings/metadata/target.d.ts.map +1 -0
- package/typings/provider/IProvider.d.ts +25 -0
- package/typings/provider/IProvider.d.ts.map +1 -0
- package/typings/provider/Provider.d.ts +30 -0
- package/typings/provider/Provider.d.ts.map +1 -0
- package/typings/registration/IRegistration.d.ts +137 -0
- package/typings/registration/IRegistration.d.ts.map +1 -0
- package/typings/registration/Registration.d.ts +23 -0
- package/typings/registration/Registration.d.ts.map +1 -0
- package/typings/select.d.ts +15 -0
- package/typings/select.d.ts.map +1 -0
- package/typings/token/BindToken.d.ts +3 -0
- package/typings/token/BindToken.d.ts.map +1 -0
- package/typings/token/ClassToken.d.ts +2 -0
- package/typings/token/ClassToken.d.ts.map +1 -0
- package/typings/token/ConstantToken.d.ts +14 -0
- package/typings/token/ConstantToken.d.ts.map +1 -0
- package/typings/token/FunctionToken.d.ts +10 -0
- package/typings/token/FunctionToken.d.ts.map +1 -0
- package/typings/token/GroupAliasToken.d.ts +14 -0
- package/typings/token/GroupAliasToken.d.ts.map +1 -0
- package/typings/token/GroupInstanceToken.d.ts +19 -0
- package/typings/token/GroupInstanceToken.d.ts.map +1 -0
- package/typings/token/InjectionToken.d.ts +8 -0
- package/typings/token/InjectionToken.d.ts.map +1 -0
- package/typings/token/SingleAliasToken.d.ts +6 -0
- package/typings/token/SingleAliasToken.d.ts.map +1 -0
- package/typings/token/SingleToken.d.ts +18 -0
- package/typings/token/SingleToken.d.ts.map +1 -0
- package/typings/token/toToken.d.ts +12 -0
- package/typings/token/toToken.d.ts.map +1 -0
- package/typings/utils/ProxyRegistry.d.ts +63 -0
- package/typings/utils/ProxyRegistry.d.ts.map +1 -0
- package/typings/utils/TypedEvent.d.ts +42 -0
- package/typings/utils/TypedEvent.d.ts.map +1 -0
- package/typings/utils/array.d.ts +7 -0
- package/typings/utils/array.d.ts.map +1 -0
- package/typings/utils/basic.d.ts +12 -0
- package/typings/utils/basic.d.ts.map +1 -0
- package/typings/utils/debounce.d.ts +2 -0
- package/typings/utils/debounce.d.ts.map +1 -0
- package/typings/utils/errorHandler.d.ts +4 -0
- package/typings/utils/errorHandler.d.ts.map +1 -0
- package/typings/utils/fp.d.ts +8 -0
- package/typings/utils/fp.d.ts.map +1 -0
- package/typings/utils/getConstructorChain.d.ts +9 -0
- package/typings/utils/getConstructorChain.d.ts.map +1 -0
- package/typings/utils/memoize.d.ts +10 -0
- package/typings/utils/memoize.d.ts.map +1 -0
- package/typings/utils/once.d.ts +2 -0
- package/typings/utils/once.d.ts.map +1 -0
- package/typings/utils/shallowCache.d.ts +2 -0
- package/typings/utils/shallowCache.d.ts.map +1 -0
- package/typings/utils/task.d.ts +13 -0
- package/typings/utils/task.d.ts.map +1 -0
- package/typings/utils/throttle.d.ts +2 -0
- package/typings/utils/throttle.d.ts.map +1 -0
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { IInjector, InjectOptions, Injector } from './IInjector.js';
|
|
2
2
|
import { type constructor } from '../utils/basic.js';
|
|
3
|
+
/**
|
|
4
|
+
* Injector that passes the scope itself as the first constructor argument,
|
|
5
|
+
* followed by the runtime args. Needs no decorators or `reflect-metadata`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* class App {
|
|
9
|
+
* constructor(scope: IContainer) {
|
|
10
|
+
* this.logger = scope.resolve('Logger');
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* new Container({ injector: new SimpleInjector() });
|
|
14
|
+
*/
|
|
3
15
|
export declare class SimpleInjector extends Injector implements IInjector {
|
|
4
16
|
protected createInstance<T>(Target: constructor<T>, { scope, args }: InjectOptions): T;
|
|
5
17
|
}
|
|
18
|
+
//# sourceMappingURL=SimpleInjector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleInjector.d.ts","sourceRoot":"","sources":["../../lib/injector/SimpleInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,qBAAa,cAAe,SAAQ,QAAS,YAAW,SAAS;IAC/D,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAS,EAAE,EAAE,aAAa,GAAG,CAAC;CAG5F"}
|
|
@@ -1,7 +1,34 @@
|
|
|
1
|
+
/** Decorator that writes class metadata under `key`; `mapFn` receives the previous value. */
|
|
1
2
|
export declare const addClassMeta: <T>(key: string | symbol, mapFn: (prev: T | undefined) => T) => ClassDecorator;
|
|
3
|
+
/** Reads class metadata written by `addClassMeta`. */
|
|
2
4
|
export declare function getClassMeta<T>(target: object, key: string | symbol): T | undefined;
|
|
5
|
+
/** Decorator that attaches a `key` -> `label` pair to a class. */
|
|
3
6
|
export declare const addClassLabel: (key: string, label: string) => ClassDecorator;
|
|
7
|
+
/** Reads the labels written by `addClassLabel`. */
|
|
4
8
|
export declare const getClassLabels: (target: object) => Map<string, string>;
|
|
9
|
+
/** Decorator that attaches a tag to a class. */
|
|
5
10
|
export declare const addClassTag: (tag: string) => ClassDecorator;
|
|
11
|
+
/** Reads the tags written by `addClassTag`. */
|
|
6
12
|
export declare const getClassTags: (target: object) => Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Applies several class decorators as one, so a stack repeated on many classes
|
|
15
|
+
* can be given a name:
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const repository = <T>(token: SingleToken<T>, ...mappers: RegistrationMapper<T>[]) =>
|
|
19
|
+
* createComposeClassDecorator(
|
|
20
|
+
* register(IRepositoryToken, token, addMediator(token), ...mappers),
|
|
21
|
+
* addClassMeta('injection-token', () => token),
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Decorators are applied bottom-up, exactly as stacking them would be, so
|
|
26
|
+
* `@createComposeClassDecorator(a, b)` behaves like `@a @b` - moving a stack into one
|
|
27
|
+
* call never changes which decorator writes its metadata first.
|
|
28
|
+
*
|
|
29
|
+
* A decorator which returns a replacement class hands it to the next one, and
|
|
30
|
+
* the last replacement is returned - the same threading the runtime does for a
|
|
31
|
+
* stack.
|
|
32
|
+
*/
|
|
7
33
|
export declare const createComposeClassDecorator: (...decorators: ClassDecorator[]) => ClassDecorator;
|
|
34
|
+
//# sourceMappingURL=class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../lib/metadata/class.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,eAAO,MAAM,YAAY,GACtB,CAAC,EAAE,KAAK,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,KAAG,cAI7D,CAAC;AAEJ,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,SAAS,CAEnF;AAED,kEAAkE;AAClE,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,mBACgC,CAAC;AACzF,mDAAmD;AACnD,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAA+C,CAAC;AAElH,gDAAgD;AAChD,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,mBAA0E,CAAC;AAClH,+CAA+C;AAC/C,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,GAAG,CAAC,MAAM,CAA6C,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,2BAA2B,GACrC,GAAG,YAAY,cAAc,EAAE,KAAG,cAEsC,CAAC"}
|
|
@@ -1,7 +1,31 @@
|
|
|
1
|
+
/** Decorator that writes method metadata under `key`; `mapFn` receives the previous value. */
|
|
1
2
|
export declare const addMethodMeta: <T>(key: string, mapFn: (prev: T | undefined) => T) => MethodDecorator;
|
|
3
|
+
/** Reads method metadata written by `addMethodMeta`. */
|
|
2
4
|
export declare const getMethodMeta: (key: string, target: object, propertyKey: string) => unknown;
|
|
5
|
+
/** Decorator that attaches a `key` -> `label` pair to a method. */
|
|
3
6
|
export declare const addMethodLabel: (key: string, label: string) => MethodDecorator;
|
|
7
|
+
/** Reads the labels written by `addMethodLabel`. */
|
|
4
8
|
export declare const getMethodLabels: (target: object, propertyKey: string) => Map<string, string>;
|
|
9
|
+
/** Decorator that attaches a tag to a method. */
|
|
5
10
|
export declare const addMethodTag: (tag: string) => MethodDecorator;
|
|
11
|
+
/** Reads the tags written by `addMethodTag`. */
|
|
6
12
|
export declare const getMethodTags: (target: object, propertyKey: string) => Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Applies several method decorators as one, so a stack repeated on many members
|
|
15
|
+
* can be given a name:
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const handler = (event: string) =>
|
|
19
|
+
* createComposeMethodDecorator(addMethodTag('handler'), addMethodMeta('event', () => event));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Decorators are applied bottom-up, exactly as stacking them would be, so
|
|
23
|
+
* `@createComposeMethodDecorator(a, b)` behaves like `@a @b`.
|
|
24
|
+
*
|
|
25
|
+
* The property descriptor is threaded through the chain the way the runtime
|
|
26
|
+
* threads it: a decorator which returns a replacement descriptor hands it to the
|
|
27
|
+
* next one, and the last replacement is returned. That is what makes wrapping
|
|
28
|
+
* decorators such as `@once` or `@throttle` compose here.
|
|
29
|
+
*/
|
|
7
30
|
export declare const createComposeMethodDecorator: (...decorators: MethodDecorator[]) => MethodDecorator;
|
|
31
|
+
//# sourceMappingURL=method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../lib/metadata/method.ts"],"names":[],"mappings":"AAEA,8FAA8F;AAC9F,eAAO,MAAM,aAAa,GACvB,CAAC,EAAE,KAAK,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,KAAG,eAIpD,CAAC;AACJ,wDAAwD;AACxD,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,OACd,CAAC;AAEpE,mEAAmE;AACnE,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,oBACgC,CAAC;AAC1F,oDAAoD;AACpD,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CACO,CAAC;AAEhG,iDAAiD;AACjD,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,oBAA2E,CAAC;AACpH,gDAAgD;AAChD,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,GAAG,CAAC,MAAM,CACO,CAAC;AAEtF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,4BAA4B,GACtC,GAAG,YAAY,eAAe,EAAE,KAAG,eAE8D,CAAC"}
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
/** Decorator that writes parameter metadata under `key`; `mapFn` receives the previous value. */
|
|
1
2
|
export declare const addParamMeta: (key: string | symbol, mapFn: (prev: unknown) => unknown) => ParameterDecorator;
|
|
3
|
+
/** Reads parameter metadata written by `addParamMeta`. */
|
|
2
4
|
export declare const getParamMeta: (key: string | symbol, target: object) => unknown[];
|
|
5
|
+
/** Decorator that attaches a `key` -> `label` pair to a parameter. */
|
|
3
6
|
export declare const addParamLabel: (key: string, label: string) => ParameterDecorator;
|
|
7
|
+
/** Reads the labels written by `addParamLabel`. */
|
|
4
8
|
export declare const getParamLabels: (target: object, parameterIndex: number) => Map<string, string>;
|
|
9
|
+
/** Decorator that attaches a tag to a parameter. */
|
|
5
10
|
export declare const addParamTag: (tag: string) => ParameterDecorator;
|
|
11
|
+
/** Reads the tags written by `addParamTag`. */
|
|
6
12
|
export declare const getParamTags: (target: object, parameterIndex: number) => Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Applies several parameter decorators as one, so a stack repeated on many
|
|
15
|
+
* parameters can be given a name:
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const fromConfig = <T>(key: string, map: MapFn<IConfig, T>) =>
|
|
19
|
+
* createComposeParameterDecorator(inject(pipe(by(ConfigToken), map)), addParamLabel('config', key));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Decorators are applied bottom-up, exactly as stacking them would be, so
|
|
23
|
+
* `@createComposeParameterDecorator(a, b)` behaves like `@a @b`. A parameter
|
|
24
|
+
* decorator returns nothing, so there is nothing to thread - each one is called
|
|
25
|
+
* with the same target, property key and parameter index.
|
|
26
|
+
*/
|
|
7
27
|
export declare const createComposeParameterDecorator: (...decorators: ParameterDecorator[]) => ParameterDecorator;
|
|
28
|
+
//# sourceMappingURL=parameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter.d.ts","sourceRoot":"","sources":["../../lib/metadata/parameter.ts"],"names":[],"mappings":"AAEA,iGAAiG;AACjG,eAAO,MAAM,YAAY,GACtB,KAAK,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,KAAG,kBAK1D,CAAC;AACJ,0DAA0D;AAC1D,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,GAAG,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,EAE1E,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,uBAIpD,CAAC;AACL,mDAAmD;AACnD,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,gBAAgB,MAAM,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAGzF,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,uBAInC,CAAC;AACL,+CAA+C;AAC/C,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,gBAAgB,MAAM,KAAG,GAAG,CAAC,MAAM,CAG/E,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,+BAA+B,GACzC,GAAG,YAAY,kBAAkB,EAAE,KAAG,kBAKtC,CAAC"}
|
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import { type constructor, type Instance } from '../utils/basic.js';
|
|
2
|
+
/**
|
|
3
|
+
* The class behind `target`: `target` itself when it is already a constructor,
|
|
4
|
+
* otherwise the constructor of the instance.
|
|
5
|
+
*
|
|
6
|
+
* `target` may be a proxy (a `lazy()` provider hands one out), and it is
|
|
7
|
+
* unwrapped before either branch, because metadata is defined on the real class
|
|
8
|
+
* and a proxy is never that class. A proxied class misses the lookup outright,
|
|
9
|
+
* standing in for the very object metadata is keyed by; a proxied instance would
|
|
10
|
+
* only answer `constructor` correctly if its handler forwards the read, which a
|
|
11
|
+
* custom one need not do.
|
|
12
|
+
*
|
|
13
|
+
* The branch tests for a constructor rather than for an instance: `Is.instance`
|
|
14
|
+
* asks for an *own* `constructor` property, which a prototype has and an
|
|
15
|
+
* instance does not - its own `constructor` lives one level up the chain.
|
|
16
|
+
*
|
|
17
|
+
* Every metadata read goes through here, so callers pass whatever they hold - a
|
|
18
|
+
* class, an instance, or a proxy of either - and never unwrap by hand.
|
|
19
|
+
*/
|
|
2
20
|
export declare function resolveConstructor(target: constructor<unknown> | Instance): constructor<unknown>;
|
|
21
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../lib/metadata/target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAM,MAAM,gBAAgB,CAAC;AAGrE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAGhG"}
|
|
@@ -4,19 +4,43 @@ import { Serializable } from '../utils/basic.js';
|
|
|
4
4
|
export type WithLazy = {
|
|
5
5
|
lazy: boolean;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* The resolution context a provider works in: the `scope` resolving, the runtime
|
|
9
|
+
* `args`, and whether the caller asked for a `lazy` instance. One object, so a
|
|
10
|
+
* function handed it destructures what it uses (`({ scope, args }) => ...`).
|
|
11
|
+
*/
|
|
7
12
|
export type ProviderOptions = InjectOptions & Partial<WithLazy>;
|
|
13
|
+
/**
|
|
14
|
+
* `ProviderOptions` as a caller which addresses the scope directly passes them -
|
|
15
|
+
* `scope.resolve(key, options)`, `token.resolve(scope, options)` - so the scope is
|
|
16
|
+
* not repeated inside.
|
|
17
|
+
*/
|
|
8
18
|
export type ResolveOptions = Omit<ProviderOptions, keyof WithScope>;
|
|
19
|
+
/** A factory: builds the dependency from the resolution context. What `Registration.fromFn` takes. */
|
|
9
20
|
export type ResolveDependency<T = unknown> = (options: ProviderOptions) => T;
|
|
21
|
+
/** What a {@link ScopeAccessRule} sees: the scope asking, the scope holding the provider, and the runtime args. */
|
|
10
22
|
export type ScopeAccessOptions = {
|
|
11
23
|
invocationScope: Tagged;
|
|
12
24
|
providerScope: Tagged;
|
|
13
25
|
args: unknown[];
|
|
14
26
|
};
|
|
27
|
+
/** Decides whether a provider may be resolved for an invocation; `prev` is the result of earlier rules. Set with `scopeAccess(...)`. */
|
|
15
28
|
export type ScopeAccessRule = (options: ScopeAccessOptions, prev: boolean) => boolean;
|
|
29
|
+
/** Computes args from the resolution context. */
|
|
16
30
|
export type ArgsFn = (options: InjectOptions) => unknown[];
|
|
31
|
+
/** Maps runtime args to a `singleton(...)` cache key: one instance per distinct key. */
|
|
17
32
|
export type GetCacheKey = (args: unknown[]) => string | Serializable;
|
|
33
|
+
/** Wraps or replaces a resolved dependency. Used by `decorate(...)`. */
|
|
18
34
|
export type DecorateFn<Instance = any> = (dep: Instance, scope: IContainer) => Instance;
|
|
35
|
+
/**
|
|
36
|
+
* Provider hooks - the provider's own domain: a dependency was resolved.
|
|
37
|
+
*
|
|
38
|
+
* Resolution is the provider's business, so the hook list belongs to the
|
|
39
|
+
* provider. A dependency is not necessarily a constructed instance - a provider
|
|
40
|
+
* can hand out a value the container never built - so the hook takes `unknown`.
|
|
41
|
+
*/
|
|
19
42
|
export type ProviderHook = (dependency: unknown, scope: IContainer) => void;
|
|
43
|
+
/** The factory behind a registration. See {@link Provider}. */
|
|
20
44
|
export interface IProvider<T = any> {
|
|
21
45
|
resolve(options: ProviderOptions): T;
|
|
22
46
|
hasAccess(options: ScopeAccessOptions): boolean;
|
|
@@ -30,3 +54,4 @@ export interface IProvider<T = any> {
|
|
|
30
54
|
dispose(): void;
|
|
31
55
|
onResolved(...hooks: ProviderHook[]): this;
|
|
32
56
|
}
|
|
57
|
+
//# sourceMappingURL=IProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../lib/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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KAAK,IAAI,CAAC;AAE5E,+DAA+D;AAC/D,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,GAAG;IAChC,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,CAAC,CAAC;IAErC,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC;IAEhD,GAAG,CAAC,GAAG,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;IAEvC,aAAa,CAAC,GAAG,KAAK,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;IAEjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,IAAI,IAAI,IAAI,CAAC;IAEb,WAAW,IAAI,IAAI,CAAC;IAEpB,gBAAgB,IAAI,OAAO,CAAC;IAE5B,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE3C,OAAO,IAAI,IAAI,CAAC;IAEhB,UAAU,CAAC,GAAG,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;CAC5C"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type ArgsFn, type DecorateFn, type GetCacheKey, type IProvider, type ProviderOptions, type ResolveDependency, type ScopeAccessOptions, type ScopeAccessRule, type ProviderHook } from './IProvider.js';
|
|
2
2
|
import type { DependencyKey } from '../container/IContainer.js';
|
|
3
3
|
import { type constructor } from '../utils/basic.js';
|
|
4
|
+
/**
|
|
5
|
+
* The factory behind a registration: creates or returns the dependency and
|
|
6
|
+
* applies the pipes (`singleton`, `lazy`, `decorate`, args and access rules).
|
|
7
|
+
* Usually created for you by {@link Registration}; use it directly only for
|
|
8
|
+
* low-level `container.register(key, provider)` calls.
|
|
9
|
+
*/
|
|
4
10
|
export declare class Provider<T = any> implements IProvider<T> {
|
|
5
11
|
private readonly resolveDependency;
|
|
6
12
|
static fromClass<T>(Target: constructor<T>): IProvider<T>;
|
|
@@ -16,16 +22,40 @@ export declare class Provider<T = any> implements IProvider<T> {
|
|
|
16
22
|
private isDisposed;
|
|
17
23
|
private readonly onResolvedHookList;
|
|
18
24
|
constructor(resolveDependency: ResolveDependency<T>);
|
|
25
|
+
/**
|
|
26
|
+
* @throws {ProviderDisposedError} when the provider has already been disposed.
|
|
27
|
+
* @throws {unknown} rethrows whatever an `onResolved` hook threw.
|
|
28
|
+
*/
|
|
19
29
|
resolve(options: ProviderOptions): T;
|
|
30
|
+
/**
|
|
31
|
+
* @throws {unknown} rethrows whatever an `onResolved` hook threw.
|
|
32
|
+
*/
|
|
20
33
|
private resolveDep;
|
|
21
34
|
map(...mappers: DecorateFn<T>[]): this;
|
|
22
35
|
addAccessRule(...rules: ScopeAccessRule[]): this;
|
|
23
36
|
lazy(): this;
|
|
24
37
|
autoResolve(): this;
|
|
38
|
+
/**
|
|
39
|
+
* @throws {ProviderDisposedError} when the provider has already been disposed.
|
|
40
|
+
*/
|
|
25
41
|
isAutoResolvable(): boolean;
|
|
26
42
|
addArgsFn(...fns: ArgsFn[]): this;
|
|
43
|
+
/**
|
|
44
|
+
* @throws {ProviderDisposedError} when the provider has already been disposed.
|
|
45
|
+
*/
|
|
27
46
|
hasAccess(options: ScopeAccessOptions): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* @throws {CannotApplySingletonTwiceError} when the provider is already configured as a singleton.
|
|
49
|
+
*/
|
|
28
50
|
singleton(getCacheKey?: GetCacheKey): this;
|
|
51
|
+
/**
|
|
52
|
+
* Hooks run after every mapper, on each resolved dependency. A singleton provider
|
|
53
|
+
* caches the dependency, so its hooks run once — on the resolve that filled the cache.
|
|
54
|
+
*/
|
|
29
55
|
onResolved(...hooks: ProviderHook[]): this;
|
|
56
|
+
/**
|
|
57
|
+
* @throws {ProviderDisposedError} when the provider has already been disposed.
|
|
58
|
+
*/
|
|
30
59
|
dispose(): void;
|
|
31
60
|
}
|
|
61
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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AC;IAmBpC;;OAEG;IACH,OAAO,CAAC,UAAU;IAalB,GAAG,CAAC,GAAG,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAKtC,aAAa,CAAC,GAAG,KAAK,EAAE,eAAe,EAAE,GAAG,IAAI;IAKhD,IAAI,IAAI,IAAI;IAKZ,WAAW,IAAI,IAAI;IAKnB;;OAEG;IACH,gBAAgB,IAAI,OAAO;IAS3B,SAAS,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI;IAKjC;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO;IAS/C;;OAEG;IACH,SAAS,CAAC,WAAW,GAAE,WAAuB,GAAG,IAAI;IASrD;;;OAGG;IACH,UAAU,CAAC,GAAG,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI;IAK1C;;OAEG;IACH,OAAO,IAAI,IAAI;CAchB"}
|
|
@@ -3,19 +3,61 @@ import type { ArgsFn, DecorateFn, GetCacheKey, IProvider, ProviderHook, ScopeAcc
|
|
|
3
3
|
import { BindToken } from '../token/BindToken.js';
|
|
4
4
|
import { MapFn } from '../utils/fp.js';
|
|
5
5
|
import { type constructor } from '../utils/basic.js';
|
|
6
|
+
/**
|
|
7
|
+
* Decides whether a registration is copied into a scope when that scope is
|
|
8
|
+
* created (or when the registration is added). `prev` is the result of the
|
|
9
|
+
* rules before it, so rules chain. Set with {@link scope} or `registration.when(...)`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const onlyRequest: ScopeMatchRule = (s) => s.hasTag('request');
|
|
13
|
+
*/
|
|
6
14
|
export type ScopeMatchRule = (s: IContainer, prev: boolean) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* A provider transform usable in both places: `registration.pipe(...)` calls
|
|
17
|
+
* `mapProvider`, `@register(...)` calls `mapRegistration`. Build one with
|
|
18
|
+
* {@link registerPipe}; `singleton()`, `lazy()`, `scopeAccess()` etc. are all pipes.
|
|
19
|
+
*/
|
|
7
20
|
export interface ProviderPipe<T = unknown> {
|
|
8
21
|
mapProvider(p: IProvider<T>): IProvider<T>;
|
|
9
22
|
mapRegistration(r: IRegistration<T>): IRegistration<T>;
|
|
10
23
|
}
|
|
24
|
+
/** Narrows `obj` to a {@link ProviderPipe}. */
|
|
11
25
|
export declare const isProviderPipe: <T>(obj: unknown) => obj is ProviderPipe<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Turns a provider transform into a {@link ProviderPipe}, so it works both in
|
|
28
|
+
* `@register(...)` and in `registration.pipe(...)`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const cached = <T>() => registerPipe<T>((p) => p.singleton());
|
|
32
|
+
*
|
|
33
|
+
* @register(bindTo('Cache'), cached())
|
|
34
|
+
* class Cache {}
|
|
35
|
+
*/
|
|
12
36
|
export declare const registerPipe: <T>(mapProvider: (p: IProvider<T>) => IProvider<T>) => ProviderPipe<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Anything that can name a binding key: a raw key, or a token that knows how to bind itself.
|
|
39
|
+
*/
|
|
13
40
|
export type Bindable<T = any> = DependencyKey | BindToken<T>;
|
|
41
|
+
/** Normalizes a {@link Bindable}: a raw key becomes a `SingleToken`, a token is returned as is. */
|
|
14
42
|
export declare const toBindToken: <T>(target: Bindable<T>) => BindToken<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Everything accepted at provider level - by `IRegistration.pipe(...)`.
|
|
45
|
+
*/
|
|
15
46
|
export type ProviderMapper<T = any> = MapFn<IProvider<T>> | ProviderPipe<T>;
|
|
47
|
+
/** Normalizes a {@link ProviderMapper} to a plain provider transform. */
|
|
16
48
|
export declare const toProviderFn: <T>(mapper: ProviderMapper<T>) => MapFn<IProvider<T>>;
|
|
49
|
+
/**
|
|
50
|
+
* Everything accepted at registration level - by `@register(...)`.
|
|
51
|
+
*/
|
|
17
52
|
export type RegistrationMapper<T = any> = MapFn<IRegistration<T>> | ProviderPipe<T> | Bindable<T>;
|
|
53
|
+
/** Normalizes a {@link RegistrationMapper} to a plain registration transform (a `Bindable` becomes `bindTo(...)`). */
|
|
18
54
|
export declare const toRegistrationFn: <T>(mapper: RegistrationMapper<T>) => MapFn<IRegistration<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* A recipe for putting one provider into matching scopes. Created with
|
|
57
|
+
* `Registration.fromClass` / `fromValue` / `fromFn` / `fromKey` and added with
|
|
58
|
+
* `container.addRegistration(...)`; `applyTo(scope)` registers the provider
|
|
59
|
+
* when the scope rules match.
|
|
60
|
+
*/
|
|
19
61
|
export interface IRegistration<T = any> extends IContainerModule {
|
|
20
62
|
getKeyOrFail(): DependencyKey;
|
|
21
63
|
when(...predicates: ScopeMatchRule[]): this;
|
|
@@ -24,16 +66,111 @@ export interface IRegistration<T = any> extends IContainerModule {
|
|
|
24
66
|
pipe(...mappers: ProviderMapper<T>[]): this;
|
|
25
67
|
bindToAlias(alias: DependencyKey): this;
|
|
26
68
|
}
|
|
69
|
+
/** The dependency type `T` of an `IRegistration<T>`. */
|
|
27
70
|
export type ReturnTypeOfRegistration<T> = T extends IRegistration<infer R> ? R : never;
|
|
71
|
+
/** Reads the registration transforms written on a class by {@link register}. */
|
|
28
72
|
export declare const getTransformers: (Target: constructor<unknown>) => MapFn<IRegistration<any>>[];
|
|
73
|
+
/**
|
|
74
|
+
* Class decorator that configures how `Registration.fromClass(Target)` registers
|
|
75
|
+
* the class: binding keys, scope rules and provider pipes. A bare key or token
|
|
76
|
+
* is shorthand for `bindTo(...)`. Without a key the class name is used.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* @register(bindTo(ILoggerToken), scope((s) => s.hasTag('application')), singleton())
|
|
80
|
+
* class Logger implements ILogger {}
|
|
81
|
+
*
|
|
82
|
+
* container.addRegistration(Registration.fromClass(Logger));
|
|
83
|
+
*/
|
|
29
84
|
export declare const register: (...mappers: RegistrationMapper[]) => ClassDecorator;
|
|
85
|
+
/**
|
|
86
|
+
* Binds a registration to one or more keys or tokens. A `SingleToken` binds its
|
|
87
|
+
* key; an alias token (`toSingleAlias`, `toGroupAlias`) adds an alias.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* @register(bindTo(ILoggerToken))
|
|
91
|
+
* class Logger {}
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* Registration.fromValue(config).bindTo('Config');
|
|
95
|
+
*/
|
|
30
96
|
export declare const bindTo: (...tokens: Bindable[]) => MapFn<IRegistration>;
|
|
97
|
+
/**
|
|
98
|
+
* Limits which scopes a registration is copied into. Without it, a registration
|
|
99
|
+
* lands in every scope, so a `singleton()` becomes one instance per scope.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* @register(bindTo('Repo'), scope((s) => s.hasTag('request')))
|
|
103
|
+
* class Repo {}
|
|
104
|
+
*/
|
|
31
105
|
export declare const scope: (...rules: ScopeMatchRule[]) => MapFn<IRegistration>;
|
|
106
|
+
/**
|
|
107
|
+
* Appends fixed values after the runtime args handed to the provider.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* @register(bindTo('Client'), appendArgs('https://api.example.com'))
|
|
111
|
+
* class Client {
|
|
112
|
+
* constructor(@inject(arg(0)) readonly baseUrl: string) {}
|
|
113
|
+
* }
|
|
114
|
+
*/
|
|
32
115
|
export declare const appendArgs: <T>(...extraArgs: unknown[]) => ProviderPipe<T>;
|
|
116
|
+
/**
|
|
117
|
+
* Appends values computed at resolve time after the runtime args.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* @register(bindTo('Client'), appendArgsFn(({ scope }) => [scope.resolve('API_URL')]))
|
|
121
|
+
* class Client {}
|
|
122
|
+
*/
|
|
33
123
|
export declare const appendArgsFn: <T>(fn: ArgsFn) => ProviderPipe<T>;
|
|
124
|
+
/**
|
|
125
|
+
* Controls from which scopes the provider may be resolved (unlike {@link scope},
|
|
126
|
+
* which controls where it is registered). A denied lookup falls through to the parent.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* @register(bindTo('Admin'), scopeAccess(({ invocationScope }) => invocationScope.hasTag('admin')))
|
|
130
|
+
* class AdminService {}
|
|
131
|
+
*/
|
|
34
132
|
export declare const scopeAccess: <T>(rule: ScopeAccessRule) => ProviderPipe<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Resolves the dependency as a proxy that constructs the real instance on first
|
|
135
|
+
* member access.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* @register(bindTo('Heavy'), lazy())
|
|
139
|
+
* class HeavyService {}
|
|
140
|
+
*/
|
|
35
141
|
export declare const lazy: <T>() => ProviderPipe<T>;
|
|
142
|
+
/**
|
|
143
|
+
* Marks the provider for eager resolution when the scope is set up; needs
|
|
144
|
+
* `container.useModule(new AutoResolveModule())`.
|
|
145
|
+
*/
|
|
36
146
|
export declare const autoResolve: <T>() => ProviderPipe<T>;
|
|
147
|
+
/**
|
|
148
|
+
* Wraps or replaces the resolved dependency. Order relative to `lazy()` decides
|
|
149
|
+
* whether the proxy or the real instance is decorated.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* @register(bindTo('Api'), decorate((api, scope) => new LoggingApi(api)))
|
|
153
|
+
* class Api {}
|
|
154
|
+
*/
|
|
37
155
|
export declare const decorate: (...fns: DecorateFn[]) => ProviderPipe<unknown>;
|
|
156
|
+
/**
|
|
157
|
+
* Caches the dependency per provider, which means per scope the registration
|
|
158
|
+
* was copied into (combine with {@link scope}). `getCacheKey` receives the
|
|
159
|
+
* runtime args and caches one instance per distinct key.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* @register(bindTo('Db'), scope((s) => s.hasTag('application')), singleton())
|
|
163
|
+
* class Db {}
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // one instance per tenant id passed as the first runtime arg
|
|
167
|
+
* @register(bindTo('TenantDb'), singleton(([tenantId]) => String(tenantId)))
|
|
168
|
+
* class TenantDb {}
|
|
169
|
+
*/
|
|
38
170
|
export declare const singleton: <T = unknown>(getCacheKey?: GetCacheKey) => ProviderPipe<T>;
|
|
171
|
+
/**
|
|
172
|
+
* Registration-level form of `IProvider.onResolved`: attaches provider hooks to
|
|
173
|
+
* the piped registration's provider.
|
|
174
|
+
*/
|
|
39
175
|
export declare const onResolve: <T = unknown>(...hooks: ProviderHook[]) => ProviderPipe<T>;
|
|
176
|
+
//# sourceMappingURL=IRegistration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IRegistration.d.ts","sourceRoot":"","sources":["../../lib/registration/IRegistration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAmB,MAAM,yBAAyB,CAAC;AACtH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEvH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAE3C,eAAe,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;CACxD;AAED,+CAA+C;AAC/C,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,KAAK,OAAO,KAAG,GAAG,IAAI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;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,KAAK,UAAU,EAAE,0BAAuC,CAAC;AAErF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,GAAG,OAAO,EAAE,cAAc,WAAW,oBAAqD,CAAC;AAEtH;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,YAAY,EAAE,oBAAmD,CAAC"}
|
|
@@ -2,6 +2,22 @@ import { DependencyKey, IContainer } from '../container/IContainer.js';
|
|
|
2
2
|
import type { IProvider, ResolveDependency } from '../provider/IProvider.js';
|
|
3
3
|
import { type Bindable, type IRegistration, type ProviderMapper, type ScopeMatchRule } from './IRegistration.js';
|
|
4
4
|
import { type constructor } from '../utils/basic.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds registrations for `container.addRegistration(...)`. Usually imported as
|
|
7
|
+
* `Registration as R`.
|
|
8
|
+
*
|
|
9
|
+
* - `R.fromClass(Class)` - reads the class's `@register(...)` config; the key
|
|
10
|
+
* defaults to the class name.
|
|
11
|
+
* - `R.fromValue(value).bindTo('Key')` - a constant.
|
|
12
|
+
* - `R.fromFn(({ scope, args }) => ...).bindTo('Key')` - a factory.
|
|
13
|
+
* - `R.fromKey('Other').bindTo('Key')` - an alias of another key.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* container
|
|
17
|
+
* .addRegistration(R.fromClass(Logger))
|
|
18
|
+
* .addRegistration(R.fromValue('https://api.example.com').bindTo('API_URL'))
|
|
19
|
+
* .addRegistration(R.fromFn(({ scope }) => new Client(scope.resolve('API_URL'))).bindTo('Client'));
|
|
20
|
+
*/
|
|
5
21
|
export declare class Registration<T = any> implements IRegistration<T> {
|
|
6
22
|
private createProvider;
|
|
7
23
|
key?: DependencyKey | undefined;
|
|
@@ -21,6 +37,13 @@ export declare class Registration<T = any> implements IRegistration<T> {
|
|
|
21
37
|
when(...predicates: ScopeMatchRule[]): this;
|
|
22
38
|
bindTo(key: Bindable): this;
|
|
23
39
|
private matchScope;
|
|
40
|
+
/**
|
|
41
|
+
* @throws {DependencyMissingKeyError} when the registration matches the scope but has no binding key.
|
|
42
|
+
*/
|
|
24
43
|
applyTo(container: IContainer): void;
|
|
44
|
+
/**
|
|
45
|
+
* @throws {DependencyMissingKeyError} when no binding key has been set for this registration.
|
|
46
|
+
*/
|
|
25
47
|
getKeyOrFail(): DependencyKey;
|
|
26
48
|
}
|
|
49
|
+
//# sourceMappingURL=Registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Registration.d.ts","sourceRoot":"","sources":["../../lib/registration/Registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EAIpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,WAAW,EAAM,MAAM,gBAAgB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,GAAG,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IA0B1D,OAAO,CAAC,cAAc;IACf,GAAG,CAAC,EAAE,aAAa;IAC1B,OAAO,CAAC,UAAU;IA3BpB,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO;IAK5E,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;IAQ5B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAIzC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa;IAIpC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,OAAO,CAAiC;gBAGtC,cAAc,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,EACnC,GAAG,CAAC,EAAE,aAAa,YAAA,EAClB,UAAU,GAAE,cAAc,EAAO;IAG3C,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAKnC,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAKvC,IAAI,CAAC,GAAG,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAK3C,IAAI,CAAC,GAAG,UAAU,EAAE,cAAc,EAAE,GAAG,IAAI;IAK3C,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IAK3B,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;IAepC;;OAEG;IACH,YAAY,IAAI,aAAa;CAQ9B"}
|
package/typings/select.d.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { type CreateScopeOptions } from './container/IContainer.js';
|
|
2
2
|
import { FunctionToken } from './token/FunctionToken.js';
|
|
3
3
|
import { GroupInstanceToken, InstancePredicate } from './token/GroupInstanceToken.js';
|
|
4
|
+
/**
|
|
5
|
+
* Shortcuts for common tokens.
|
|
6
|
+
*
|
|
7
|
+
* - `select.token(x)` - `toToken(x)`
|
|
8
|
+
* - `select.alias('Key')` - a {@link GroupAliasToken}
|
|
9
|
+
* - `select.instances(predicate)` - instances already created in the scope
|
|
10
|
+
* - `select.scope.current` - the resolving scope itself
|
|
11
|
+
* - `select.scope.create({ tags })` - a new child scope
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* class Handler {
|
|
15
|
+
* constructor(@inject(by(select.scope.current)) private scope: IContainer) {}
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
4
18
|
export declare const select: {
|
|
5
19
|
alias: <T>(token: import("./container/IContainer.js").DependencyKey) => import("./token/GroupAliasToken.js").GroupAliasToken<T>;
|
|
6
20
|
token: <T = any>(token: import("./token/toToken.js").Injectable<T>) => import(".").InjectionToken<T>;
|
|
@@ -10,3 +24,4 @@ export declare const select: {
|
|
|
10
24
|
create: (options: CreateScopeOptions) => FunctionToken<import("./container/IContainer.js").IContainer>;
|
|
11
25
|
};
|
|
12
26
|
};
|
|
27
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../lib/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGnF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM;;;4BAKM,iBAAiB;;;0BAKpB,kBAAkB;;CAEvC,CAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IRegistration } from '../registration/IRegistration.js';
|
|
2
|
+
/** A token that can bind a registration to itself (a key or an alias). */
|
|
2
3
|
export interface BindToken<T = any> {
|
|
3
4
|
bindTo(r: IRegistration<T>): void;
|
|
4
5
|
}
|
|
6
|
+
/** Narrows `token` to a {@link BindToken}. */
|
|
5
7
|
export declare function isBindToken(token: unknown): token is BindToken;
|
|
8
|
+
//# sourceMappingURL=BindToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BindToken.d.ts","sourceRoot":"","sources":["../../lib/token/BindToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI9D,0EAA0E;AAC1E,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,GAAG;IAChC,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACnC;AAED,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D"}
|
|
@@ -2,6 +2,7 @@ import { IContainer } from '../container/IContainer.js';
|
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { type constructor, Serializable } from '../utils/basic.js';
|
|
4
4
|
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
5
|
+
/** A token for a class: resolves it through the scope's injector. `toToken(Class)` creates one. */
|
|
5
6
|
export declare class ClassToken<T = any> extends InjectionToken<T> implements Serializable {
|
|
6
7
|
private readonly target;
|
|
7
8
|
private readonly _getArgsFn;
|
|
@@ -19,3 +20,4 @@ export declare class ClassToken<T = any> extends InjectionToken<T> implements Se
|
|
|
19
20
|
addTags(...tags: string[]): ClassToken<T>;
|
|
20
21
|
toString(): string;
|
|
21
22
|
}
|
|
23
|
+
//# sourceMappingURL=ClassToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassToken.d.ts","sourceRoot":"","sources":["../../lib/token/ClassToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE/D,mGAAmG;AACnG,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,YAAY;IAK9E,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGf,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACvC,EACE,SAAuB,EACvB,MAAc,EACd,IAAS,GACV,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAOnE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IACpB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,CAAC;IAOnE,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;IAS1B,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE;IASvC,IAAI;IAQJ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;IAQzC,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import type { IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { Serializable } from '../utils/basic.js';
|
|
4
|
+
/** A token that always resolves to a fixed value. It takes no args and cannot be lazy. */
|
|
4
5
|
export declare class ConstantToken<T = any> extends InjectionToken<T> implements Serializable {
|
|
5
6
|
private readonly token;
|
|
6
7
|
constructor(token: T, { tags }?: {
|
|
7
8
|
tags?: string[];
|
|
8
9
|
});
|
|
9
10
|
resolve(s: IContainer): T;
|
|
11
|
+
/**
|
|
12
|
+
* @throws {MethodNotImplementedError} always — a constant token cannot receive static args.
|
|
13
|
+
*/
|
|
10
14
|
args(...deps: unknown[]): InjectionToken<T>;
|
|
15
|
+
/**
|
|
16
|
+
* @throws {MethodNotImplementedError} always — a constant token cannot receive resolved args.
|
|
17
|
+
*/
|
|
11
18
|
argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<T>;
|
|
19
|
+
/**
|
|
20
|
+
* @throws {MethodNotImplementedError} always — a constant token cannot be made lazy.
|
|
21
|
+
*/
|
|
12
22
|
lazy(): InjectionToken<T>;
|
|
13
23
|
addTags(...tags: string[]): ConstantToken<T>;
|
|
24
|
+
/**
|
|
25
|
+
* @throws {MethodNotImplementedError} always — a constant token has no underlying key.
|
|
26
|
+
*/
|
|
14
27
|
toString(): string;
|
|
15
28
|
}
|
|
29
|
+
//# sourceMappingURL=ConstantToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConstantToken.d.ts","sourceRoot":"","sources":["../../lib/token/ConstantToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,0FAA0F;AAC1F,qBAAa,aAAa,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,YAAY;IAEjF,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,CAAC,EACzB,EAAE,IAAS,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAKzC,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC;IAIzB;;OAEG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAI3C;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAIlE;;OAEG;IACH,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC;IAIzB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAI5C;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -3,6 +3,12 @@ import { InjectionToken } from './InjectionToken.js';
|
|
|
3
3
|
import { InjectFn } from '../hooks/hook.js';
|
|
4
4
|
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
5
5
|
import { Serializable } from '../utils/basic.js';
|
|
6
|
+
/**
|
|
7
|
+
* A token that resolves by calling an `InjectFn` with the resolution context.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const CurrentScope = new FunctionToken(({ scope }) => scope);
|
|
11
|
+
*/
|
|
6
12
|
export declare class FunctionToken<T = any> extends InjectionToken<T> implements Serializable {
|
|
7
13
|
private readonly fn;
|
|
8
14
|
private readonly _getArgsFn;
|
|
@@ -17,5 +23,9 @@ export declare class FunctionToken<T = any> extends InjectionToken<T> implements
|
|
|
17
23
|
argsFn(fn: (s: IContainer) => unknown[]): InjectionToken<T>;
|
|
18
24
|
lazy(): InjectionToken<T>;
|
|
19
25
|
addTags(...tags: string[]): FunctionToken<T>;
|
|
26
|
+
/**
|
|
27
|
+
* @throws {MethodNotImplementedError} always — a function token has no underlying key.
|
|
28
|
+
*/
|
|
20
29
|
toString(): string;
|
|
21
30
|
}
|
|
31
|
+
//# sourceMappingURL=FunctionToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FunctionToken.d.ts","sourceRoot":"","sources":["../../lib/token/FunctionToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE/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