ts-ioc-container 72.1.0 → 72.3.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/README.md +169 -0
- package/cjm/container/Container.js +5 -2
- package/cjm/container/EmptyContainer.js +20 -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/feature/IFeatureFlags.js +6 -0
- package/cjm/index.js +14 -3
- package/cjm/provider/Provider.js +6 -6
- package/cjm/registration/Registration.js +2 -2
- package/cjm/token/BindableToken.js +63 -0
- package/cjm/token/ConstantToken.js +4 -4
- package/cjm/token/FunctionToken.js +1 -1
- package/cjm/token/GroupAliasToken.js +5 -50
- package/cjm/token/GroupInstanceToken.js +4 -4
- package/cjm/token/MultiVariantFeatureToken.js +84 -0
- package/cjm/token/SingleAliasToken.js +5 -50
- package/cjm/token/SingleToken.js +5 -50
- package/cjm/token/ToggleFeatureToken.js +10 -0
- 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 +5 -2
- package/esm/container/EmptyContainer.js +20 -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/feature/IFeatureFlags.js +3 -0
- package/esm/index.js +5 -0
- package/esm/provider/Provider.js +6 -6
- package/esm/registration/Registration.js +2 -2
- package/esm/token/BindableToken.js +59 -0
- package/esm/token/ConstantToken.js +4 -4
- package/esm/token/FunctionToken.js +1 -1
- package/esm/token/GroupAliasToken.js +5 -50
- package/esm/token/GroupInstanceToken.js +4 -4
- package/esm/token/MultiVariantFeatureToken.js +80 -0
- package/esm/token/SingleAliasToken.js +5 -50
- package/esm/token/SingleToken.js +5 -50
- package/esm/token/ToggleFeatureToken.js +6 -0
- 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 +315 -0
- package/lib/container/EmptyContainer.ts +170 -0
- package/lib/container/IContainer.ts +159 -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/feature/IFeatureFlags.ts +44 -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 +197 -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 +242 -0
- package/lib/registration/Registration.ts +122 -0
- package/lib/select.ts +33 -0
- package/lib/token/BindToken.ts +13 -0
- package/lib/token/BindableToken.ts +137 -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 +33 -0
- package/lib/token/GroupInstanceToken.ts +70 -0
- package/lib/token/InjectionToken.ts +46 -0
- package/lib/token/MultiVariantFeatureToken.ts +160 -0
- package/lib/token/SingleAliasToken.ts +28 -0
- package/lib/token/SingleToken.ts +35 -0
- package/lib/token/ToggleFeatureToken.ts +27 -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 +6 -4
- 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 +61 -0
- package/typings/container/Container.d.ts.map +1 -0
- package/typings/container/EmptyContainer.d.ts +52 -0
- package/typings/container/EmptyContainer.d.ts.map +1 -0
- package/typings/container/IContainer.d.ts +77 -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/feature/IFeatureFlags.d.ts +42 -0
- package/typings/feature/IFeatureFlags.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 +6 -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 +144 -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/BindableToken.d.ts +80 -0
- package/typings/token/BindableToken.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 +21 -22
- 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/MultiVariantFeatureToken.d.ts +79 -0
- package/typings/token/MultiVariantFeatureToken.d.ts.map +1 -0
- package/typings/token/SingleAliasToken.d.ts +16 -22
- package/typings/token/SingleAliasToken.d.ts.map +1 -0
- package/typings/token/SingleToken.d.ts +25 -21
- package/typings/token/SingleToken.d.ts.map +1 -0
- package/typings/token/ToggleFeatureToken.d.ts +25 -0
- package/typings/token/ToggleFeatureToken.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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type DependencyKey, type IContainer } from '../container/IContainer.js';
|
|
2
|
+
import { InjectionToken } from './InjectionToken.js';
|
|
3
|
+
import { type BindToken } from './BindToken.js';
|
|
4
|
+
import { type IRegistration } from '../registration/IRegistration.js';
|
|
5
|
+
import { type ArgsFn, type ResolveOptions } from '../provider/IProvider.js';
|
|
6
|
+
import { type Serializable } from '../utils/basic.js';
|
|
7
|
+
import { type MultiVariantFeatureToken } from './MultiVariantFeatureToken.js';
|
|
8
|
+
type NoInferVariant<V> = [V][V extends unknown ? 0 : never];
|
|
9
|
+
/** Internal state of a {@link BindableToken}, propagated by its modifiers. Never pass it from outside. */
|
|
10
|
+
export type BindableTokenOptions = {
|
|
11
|
+
getArgsFn?: ArgsFn;
|
|
12
|
+
isLazy?: boolean;
|
|
13
|
+
tags?: string[];
|
|
14
|
+
memberships?: DependencyKey[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Base of every token a registration can be bound to (`SingleToken`,
|
|
18
|
+
* `SingleAliasToken`, `GroupAliasToken`): a key, the args / lazy / tags state
|
|
19
|
+
* every modifier copies, and the feature memberships the token declares.
|
|
20
|
+
*
|
|
21
|
+
* `T` is the type bound to the token, `R` the type resolving it returns (an
|
|
22
|
+
* alias group resolves `T[]`). A subclass says only how it binds (`bindKey`)
|
|
23
|
+
* and how it resolves.
|
|
24
|
+
*/
|
|
25
|
+
export declare abstract class BindableToken<T = any, R = T> extends InjectionToken<R> implements BindToken<T>, Serializable {
|
|
26
|
+
readonly token: DependencyKey;
|
|
27
|
+
private readonly getArgsFn;
|
|
28
|
+
private readonly isLazyByDefault;
|
|
29
|
+
private readonly memberships;
|
|
30
|
+
constructor(token: DependencyKey, { getArgsFn, isLazy, tags, memberships }?: BindableTokenOptions);
|
|
31
|
+
/** Binds `r` under this token, and into every feature this token declared itself a variant or fallback of. */
|
|
32
|
+
bindTo(r: IRegistration<T>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Declares the dependency bound to this token the implementation of `feature`
|
|
35
|
+
* while the flag serves the variant `name`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const BlueButtonToken = new SingleToken<IButton>('BlueButton').variantOf(CheckoutButtonToken, 'blue');
|
|
39
|
+
*
|
|
40
|
+
* @register(BlueButtonToken)
|
|
41
|
+
* class BlueButton implements IButton {}
|
|
42
|
+
*/
|
|
43
|
+
variantOf<V extends string>(feature: MultiVariantFeatureToken<T, V>, name: NoInferVariant<V>): this;
|
|
44
|
+
/**
|
|
45
|
+
* Declares the dependency bound to this token the primary variant of
|
|
46
|
+
* `feature`: used while the flag is on and no named variant implementation
|
|
47
|
+
* matches. The enabled implementation of a `ToggleFeatureToken`.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const StripeGatewayToken = new SingleToken<IPaymentGateway>('StripeGateway').primaryVariantOf(PaymentGatewayToken);
|
|
51
|
+
*
|
|
52
|
+
* @register(StripeGatewayToken)
|
|
53
|
+
* class StripeGateway implements IPaymentGateway {}
|
|
54
|
+
*/
|
|
55
|
+
primaryVariantOf(feature: MultiVariantFeatureToken<T, string>): this;
|
|
56
|
+
/**
|
|
57
|
+
* Declares the dependency bound to this token the fallback of `feature`: used
|
|
58
|
+
* whenever no variant implementation applies - the flag is off, serves
|
|
59
|
+
* nothing implemented, or its client throws.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const LegacyGatewayToken = new SingleToken<IPaymentGateway>('LegacyGateway').fallbackOf(PaymentGatewayToken);
|
|
63
|
+
*
|
|
64
|
+
* @register(LegacyGatewayToken)
|
|
65
|
+
* class LegacyGateway implements IPaymentGateway {}
|
|
66
|
+
*/
|
|
67
|
+
fallbackOf(feature: MultiVariantFeatureToken<T, string>): this;
|
|
68
|
+
args(...newArgs: unknown[]): this;
|
|
69
|
+
argsFn(fn: (s: IContainer) => unknown[]): this;
|
|
70
|
+
lazy(): this;
|
|
71
|
+
addTags(...tags: string[]): this;
|
|
72
|
+
toString(): string;
|
|
73
|
+
/** Binds `r` under this token's own key or alias. */
|
|
74
|
+
protected abstract bindKey(r: IRegistration<T>): void;
|
|
75
|
+
/** The options a subclass resolves with: runtime args first, then this token's args; lazy if either asks. */
|
|
76
|
+
protected toResolveOptions(s: IContainer, { args, lazy }?: ResolveOptions): ResolveOptions;
|
|
77
|
+
private copy;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=BindableToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BindableToken.d.ts","sourceRoot":"","sources":["../../lib/token/BindableToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OA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AAE,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI;IAI9D,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IAKjC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,IAAI;IAK9C,IAAI,IAAI,IAAI;IAIZ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI;IAIhC,QAAQ,IAAI,MAAM;IAIlB,qDAAqD;IACrD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI;IAErD,6GAA6G;IAC7G,SAAS,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,cAAc;IAKnG,OAAO,CAAC,IAAI;CAUb"}
|
|
@@ -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(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OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAQ5C;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import { DependencyKey, IContainer } from '../container/IContainer.js';
|
|
2
|
-
import {
|
|
3
|
-
import { IRegistration } from '../registration/IRegistration.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { type DependencyKey, type IContainer } from '../container/IContainer.js';
|
|
2
|
+
import { BindableToken } from './BindableToken.js';
|
|
3
|
+
import { type IRegistration } from '../registration/IRegistration.js';
|
|
4
|
+
import { type ResolveOptions } from '../provider/IProvider.js';
|
|
5
|
+
/**
|
|
6
|
+
* A token for every dependency registered under an alias. As a `@register(...)`
|
|
7
|
+
* target it adds the alias; resolving returns all matches as an array.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const IMiddlewareToken = toGroupAlias<IMiddleware>('IMiddleware');
|
|
11
|
+
*
|
|
12
|
+
* @register(IMiddlewareToken)
|
|
13
|
+
* class Auth implements IMiddleware {}
|
|
14
|
+
*
|
|
15
|
+
* IMiddlewareToken.resolve(scope); // IMiddleware[]
|
|
16
|
+
*/
|
|
17
|
+
export declare class GroupAliasToken<T = any> extends BindableToken<T, T[]> {
|
|
16
18
|
select<R>(fn: (target: T[]) => R[]): (s: IContainer) => R[];
|
|
17
|
-
resolve(s: IContainer,
|
|
18
|
-
|
|
19
|
-
args(...newArgs: unknown[]): GroupAliasToken<T>;
|
|
20
|
-
argsFn(fn: (s: IContainer) => unknown[]): GroupAliasToken<T>;
|
|
21
|
-
lazy(): GroupAliasToken<T>;
|
|
22
|
-
addTags(...tags: string[]): GroupAliasToken<T>;
|
|
23
|
-
toString(): string;
|
|
19
|
+
resolve(s: IContainer, options?: ResolveOptions): T[];
|
|
20
|
+
protected bindKey(r: IRegistration<T>): void;
|
|
24
21
|
}
|
|
22
|
+
/** Creates a {@link GroupAliasToken} for `token`. */
|
|
25
23
|
export declare const toGroupAlias: <T>(token: DependencyKey) => GroupAliasToken<T>;
|
|
24
|
+
//# sourceMappingURL=GroupAliasToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroupAliasToken.d.ts","sourceRoot":"","sources":["../../lib/token/GroupAliasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,qBAAa,eAAe,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACjE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,IACxB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC,EAAE;IAIrD,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;CAGtC;AAED,qDAAqD;AACrD,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,OAAO,aAAa,uBAAkC,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { InjectionToken } from './InjectionToken.js';
|
|
2
2
|
import type { IContainer } from '../container/IContainer.js';
|
|
3
3
|
import { Instance, Serializable } from '../utils/basic.js';
|
|
4
|
+
/** Selects instances for a {@link GroupInstanceToken}. */
|
|
4
5
|
export type InstancePredicate = (dep: unknown) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the instances already created in a scope (and, by default, its
|
|
8
|
+
* child scopes) that match a predicate. Created by `select.instances(...)`.
|
|
9
|
+
*/
|
|
5
10
|
export declare class GroupInstanceToken extends InjectionToken<Instance[]> implements Serializable {
|
|
6
11
|
private predicate;
|
|
7
12
|
private isCascade;
|
|
@@ -10,11 +15,25 @@ export declare class GroupInstanceToken extends InjectionToken<Instance[]> imple
|
|
|
10
15
|
isCascade?: boolean;
|
|
11
16
|
});
|
|
12
17
|
select<R>(fn: (target: Instance) => R): (s: IContainer) => R[];
|
|
18
|
+
/**
|
|
19
|
+
* @throws {MethodNotImplementedError} always — a group instance token cannot receive static args.
|
|
20
|
+
*/
|
|
13
21
|
args(...deps: unknown[]): this;
|
|
22
|
+
/**
|
|
23
|
+
* @throws {MethodNotImplementedError} always — a group instance token cannot receive resolved args.
|
|
24
|
+
*/
|
|
14
25
|
argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<Instance[]>;
|
|
26
|
+
/**
|
|
27
|
+
* @throws {MethodNotImplementedError} always — a group instance token cannot be made lazy.
|
|
28
|
+
*/
|
|
15
29
|
lazy(): InjectionToken<Instance[]>;
|
|
30
|
+
/** Whether instances of child scopes are included (default `true`). */
|
|
16
31
|
cascade(isTrue: boolean): this;
|
|
17
32
|
resolve(c: IContainer): Instance[];
|
|
18
33
|
addTags(...tags: string[]): GroupInstanceToken;
|
|
34
|
+
/**
|
|
35
|
+
* @throws {MethodNotImplementedError} always — a group instance token has no underlying key.
|
|
36
|
+
*/
|
|
19
37
|
toString(): string;
|
|
20
38
|
}
|
|
39
|
+
//# sourceMappingURL=GroupInstanceToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroupInstanceToken.d.ts","sourceRoot":"","sources":["../../lib/token/GroupInstanceToken.ts"],"names":[],"mappings":"AA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{ ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default `getArgsFn` of every token: the runtime `args` a token is
|
|
5
|
+
* resolved with reach the provider as they are, and `token.args(...)` /
|
|
6
|
+
* `token.argsFn(...)` append after them.
|
|
7
|
+
*/
|
|
3
8
|
export declare const forwardArgs: ArgsFn;
|
|
9
|
+
/** Base class of every token: something resolvable from a scope that can be specialized with args, lazy and tags. */
|
|
4
10
|
export declare abstract class InjectionToken<T = any> {
|
|
5
11
|
private readonly tags;
|
|
6
12
|
protected constructor(tags?: Tag[]);
|
|
@@ -12,4 +18,6 @@ export declare abstract class InjectionToken<T = any> {
|
|
|
12
18
|
hasTag(tag: Tag): boolean;
|
|
13
19
|
protected getTags(): Tag[];
|
|
14
20
|
}
|
|
21
|
+
/** Narrows `target` to an {@link InjectionToken}. */
|
|
15
22
|
export declare function isInjectionToken<T = any>(target: unknown): target is InjectionToken<T>;
|
|
23
|
+
//# sourceMappingURL=InjectionToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InjectionToken.d.ts","sourceRoot":"","sources":["../../lib/token/InjectionToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,GAAG,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG/D;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,MAAgC,CAAC;AAE3D,qHAAqH;AACrH,8BAAsB,cAAc,CAAC,CAAC,GAAG,GAAG;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;IAEhC,SAAS,aAAa,IAAI,GAAE,GAAG,EAAO;IAItC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC;IAC5D,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAC3E,QAAQ,CAAC,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAEnD,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAIzB,SAAS,CAAC,OAAO,IAAI,GAAG,EAAE;CAG3B;AAED,qDAAqD;AACrD,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,CAUtF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type DependencyKey, type IContainer } from '../container/IContainer.js';
|
|
2
|
+
import { InjectionToken } from './InjectionToken.js';
|
|
3
|
+
import { type ArgsFn, type ResolveOptions } from '../provider/IProvider.js';
|
|
4
|
+
import { type Serializable } from '../utils/basic.js';
|
|
5
|
+
import { type FeatureContext, type IFeatureFlags } from '../feature/IFeatureFlags.js';
|
|
6
|
+
export type FeatureTokenOptions = {
|
|
7
|
+
getArgsFn?: ArgsFn;
|
|
8
|
+
isLazy?: boolean;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
};
|
|
11
|
+
/** What a feature token reads from its flag: whether it is on, and the named variant served, if any. */
|
|
12
|
+
export type FeatureEvaluation<V extends string = string> = {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
variant?: V;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A dependency switched by a multi-variant feature flag. The implementations
|
|
18
|
+
* decide where they belong - a bindable token declares itself
|
|
19
|
+
*
|
|
20
|
+
* - a named variant with `variantOf(feature, name)`: used while the flag serves `name`;
|
|
21
|
+
* - the primary variant with `primaryVariantOf(feature)`: used while the flag is
|
|
22
|
+
* on and no named variant implementation matches;
|
|
23
|
+
* - the fallback with `fallbackOf(feature)`: used otherwise - the flag is off,
|
|
24
|
+
* or its client throws.
|
|
25
|
+
*
|
|
26
|
+
* A flag always has a fallback: resolving a feature without one registered fails.
|
|
27
|
+
*
|
|
28
|
+
* `flag` is the flag's name on the flag service. `V` narrows the variant names
|
|
29
|
+
* implementations may claim. The flag client comes from `IFeatureFlagsToken`
|
|
30
|
+
* and the context from `IFeatureContextToken`, both resolved from the resolving
|
|
31
|
+
* scope, on every resolution.
|
|
32
|
+
*
|
|
33
|
+
* Subclasses change only how the served variant is evaluated - see
|
|
34
|
+
* `ToggleFeatureToken`, the on/off case.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const CheckoutButtonToken = new MultiVariantFeatureToken<IButton, 'blue' | 'green'>('checkout-button');
|
|
38
|
+
*
|
|
39
|
+
* @register(new SingleToken<IButton>('GreyButton').fallbackOf(CheckoutButtonToken))
|
|
40
|
+
* class GreyButton implements IButton {}
|
|
41
|
+
*
|
|
42
|
+
* @register(new SingleToken<IButton>('BlueButton').variantOf(CheckoutButtonToken, 'blue'))
|
|
43
|
+
* class BlueButton implements IButton {}
|
|
44
|
+
*
|
|
45
|
+
* @register(new SingleToken<IButton>('GreenButton').primaryVariantOf(CheckoutButtonToken))
|
|
46
|
+
* class GreenButton implements IButton {}
|
|
47
|
+
*/
|
|
48
|
+
export declare class MultiVariantFeatureToken<T = any, V extends string = string> extends InjectionToken<T> implements Serializable {
|
|
49
|
+
readonly flag: string;
|
|
50
|
+
private readonly _getArgsFn;
|
|
51
|
+
private readonly _isLazy;
|
|
52
|
+
constructor(flag: string, { getArgsFn, isLazy, tags }?: FeatureTokenOptions);
|
|
53
|
+
/** The alias an implementation of the variant `name` is bound to. Declare it with `token.variantOf(feature, name)`. */
|
|
54
|
+
variantAlias(name: V): DependencyKey;
|
|
55
|
+
/** The alias the primary variant is bound to. Declare it with `token.primaryVariantOf(feature)`. */
|
|
56
|
+
primaryAlias(): DependencyKey;
|
|
57
|
+
/** The alias the fallback is bound to. Declare it with `token.fallbackOf(feature)`. */
|
|
58
|
+
fallbackAlias(): DependencyKey;
|
|
59
|
+
/**
|
|
60
|
+
* @throws {DependencyNotFoundError} when the flag has no fallback, or the flag client, the feature context or the selected implementation cannot be resolved.
|
|
61
|
+
* @throws {ContainerDisposedError} when `s` has already been disposed.
|
|
62
|
+
*/
|
|
63
|
+
resolve(s: IContainer, { args, lazy }?: ResolveOptions): T;
|
|
64
|
+
args(...newArgs: unknown[]): this;
|
|
65
|
+
argsFn(fn: (s: IContainer) => unknown[]): this;
|
|
66
|
+
lazy(): this;
|
|
67
|
+
addTags(...tags: string[]): this;
|
|
68
|
+
toString(): string;
|
|
69
|
+
/** Whether the flag is on for `context`, and the named variant it serves, if any. */
|
|
70
|
+
protected evaluate(flags: IFeatureFlags, context: FeatureContext): FeatureEvaluation<V>;
|
|
71
|
+
private copy;
|
|
72
|
+
/**
|
|
73
|
+
* The alias of the served variant's implementation, or of the fallback.
|
|
74
|
+
*
|
|
75
|
+
* @throws {DependencyNotFoundError} when the flag has no fallback, or the flag client or the feature context cannot be resolved.
|
|
76
|
+
*/
|
|
77
|
+
private selectAlias;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=MultiVariantFeatureToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiVariantFeatureToken.d.ts","sourceRoot":"","sources":["../../lib/token/MultiVariantFeatureToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM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AAI;IAIZ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI;IAIhC,QAAQ,IAAI,MAAM;IAIlB,qFAAqF;IACrF,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,iBAAiB,CAAC,CAAC,CAAC;IAOvF,OAAO,CAAC,IAAI;IAUZ;;;;OAIG;IACH,OAAO,CAAC,WAAW;CAuBpB"}
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
import { DependencyKey, IContainer } from '../container/IContainer.js';
|
|
2
|
-
import {
|
|
3
|
-
import { IRegistration } from '../registration/IRegistration.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private readonly _isLazy;
|
|
11
|
-
constructor(token: DependencyKey, { getArgsFn, isLazy, tags, }?: {
|
|
12
|
-
getArgsFn?: ArgsFn;
|
|
13
|
-
isLazy?: boolean;
|
|
14
|
-
tags?: string[];
|
|
15
|
-
});
|
|
1
|
+
import { type DependencyKey, type IContainer } from '../container/IContainer.js';
|
|
2
|
+
import { BindableToken } from './BindableToken.js';
|
|
3
|
+
import { type IRegistration } from '../registration/IRegistration.js';
|
|
4
|
+
import { type ResolveOptions } from '../provider/IProvider.js';
|
|
5
|
+
/**
|
|
6
|
+
* Like {@link GroupAliasToken}, but resolves exactly one dependency registered
|
|
7
|
+
* under the alias, and throws `DependencyNotFoundError` when there is none.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SingleAliasToken<T = any> extends BindableToken<T> {
|
|
16
10
|
select<R>(fn: (target: T) => R): (s: IContainer) => R;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
addTags(...tags: string[]): SingleAliasToken<T>;
|
|
23
|
-
toString(): string;
|
|
11
|
+
/**
|
|
12
|
+
* @throws {DependencyNotFoundError} when no accessible registration carries the alias.
|
|
13
|
+
*/
|
|
14
|
+
resolve(s: IContainer, options?: ResolveOptions): T;
|
|
15
|
+
protected bindKey(r: IRegistration<T>): void;
|
|
24
16
|
}
|
|
17
|
+
/** Creates a {@link SingleAliasToken} for `token`. */
|
|
25
18
|
export declare const toSingleAlias: <T>(token: DependencyKey) => SingleAliasToken<T>;
|
|
19
|
+
//# sourceMappingURL=SingleAliasToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SingleAliasToken.d.ts","sourceRoot":"","sources":["../../lib/token/SingleAliasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;GAGG;AACH,qBAAa,gBAAgB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IACpB,GAAG,UAAU;IAGvB;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC;IAInD,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;CAGtC;AAED,sDAAsD;AACtD,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,aAAa,wBAAmC,CAAC"}
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { IRegistration } from '../registration/IRegistration.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { type IContainer } from '../container/IContainer.js';
|
|
2
|
+
import { BindableToken } from './BindableToken.js';
|
|
3
|
+
import { type IRegistration } from '../registration/IRegistration.js';
|
|
4
|
+
import { type ResolveOptions } from '../provider/IProvider.js';
|
|
5
|
+
/**
|
|
6
|
+
* A typed handle for one dependency key - the usual way to name a dependency.
|
|
7
|
+
* `args(...)`, `argsFn(...)` and `lazy()` return a new token and never change
|
|
8
|
+
* this one, so one token can be specialized per injection site.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const ILoggerToken = new SingleToken<ILogger>('ILogger');
|
|
12
|
+
*
|
|
13
|
+
* @register(ILoggerToken)
|
|
14
|
+
* class Logger implements ILogger {}
|
|
15
|
+
*
|
|
16
|
+
* class App {
|
|
17
|
+
* constructor(@inject(by(ILoggerToken)) logger: ILogger) {}
|
|
18
|
+
* }
|
|
19
|
+
* ILoggerToken.resolve(scope);
|
|
20
|
+
* ILoggerToken.args('prefix').lazy().resolve(scope);
|
|
21
|
+
*/
|
|
22
|
+
export declare class SingleToken<T = any> extends BindableToken<T> {
|
|
15
23
|
select<R>(fn: (target: T) => R): (s: IContainer) => R;
|
|
16
|
-
resolve(s: IContainer,
|
|
17
|
-
|
|
18
|
-
args(...newArgs: unknown[]): SingleToken<T>;
|
|
19
|
-
argsFn(fn: (s: IContainer) => unknown[]): SingleToken<T>;
|
|
20
|
-
lazy(): SingleToken<T>;
|
|
21
|
-
addTags(...tags: string[]): SingleToken<T>;
|
|
22
|
-
toString(): string;
|
|
24
|
+
resolve(s: IContainer, options?: ResolveOptions): T;
|
|
25
|
+
protected bindKey(r: IRegistration<T>): void;
|
|
23
26
|
}
|
|
27
|
+
//# sourceMappingURL=SingleToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SingleToken.d.ts","sourceRoot":"","sources":["../../lib/token/SingleToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,WAAW,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACxD,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IACpB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC;IAInD,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;CAGtC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type FeatureEvaluation, MultiVariantFeatureToken } from './MultiVariantFeatureToken.js';
|
|
2
|
+
import { type FeatureContext, type IFeatureFlags } from '../feature/IFeatureFlags.js';
|
|
3
|
+
/**
|
|
4
|
+
* The on/off case of {@link MultiVariantFeatureToken}: a flag with no named
|
|
5
|
+
* variants, only a primary one, served while `isEnabled` says so. Everything
|
|
6
|
+
* else - the fallback, the context, args and laziness - is the multi-variant
|
|
7
|
+
* token's.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const PaymentGatewayToken = new ToggleFeatureToken<IPaymentGateway>('new-checkout');
|
|
11
|
+
*
|
|
12
|
+
* @register(new SingleToken<IPaymentGateway>('LegacyGateway').fallbackOf(PaymentGatewayToken))
|
|
13
|
+
* class LegacyGateway implements IPaymentGateway {}
|
|
14
|
+
*
|
|
15
|
+
* @register(new SingleToken<IPaymentGateway>('StripeGateway').primaryVariantOf(PaymentGatewayToken))
|
|
16
|
+
* class StripeGateway implements IPaymentGateway {}
|
|
17
|
+
*
|
|
18
|
+
* class Checkout {
|
|
19
|
+
* constructor(@inject(by(PaymentGatewayToken)) gateway: IPaymentGateway) {}
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export declare class ToggleFeatureToken<T = any> extends MultiVariantFeatureToken<T, never> {
|
|
23
|
+
protected evaluate(flags: IFeatureFlags, context: FeatureContext): FeatureEvaluation<never>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ToggleFeatureToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToggleFeatureToken.d.ts","sourceRoot":"","sources":["../../lib/token/ToggleFeatureToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEnF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,wBAAwB,CAAC,CAAC,EAAE,KAAK,CAAC;cAC9D,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC;CAGrG"}
|
|
@@ -2,6 +2,18 @@ import { DependencyKey } from '../container/IContainer.js';
|
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { InjectFn } from '../hooks/hook.js';
|
|
4
4
|
import { type constructor } from '../utils/basic.js';
|
|
5
|
+
/** Anything `toToken(...)` turns into a token: a token, a key, a class or an `InjectFn`. */
|
|
5
6
|
export type Injectable<T = any> = InjectFn<T> | InjectionToken<T> | DependencyKey | constructor<T>;
|
|
7
|
+
/**
|
|
8
|
+
* @throws {UnsupportedTokenTypeError} when `token` is not an `InjectionToken`, a `DependencyKey`, a constructor, or a function.
|
|
9
|
+
*/
|
|
6
10
|
export declare const toToken: <T = any>(token: Injectable<T>) => InjectionToken<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a runtime argument so it can be resolved uniformly: an `InjectionToken`
|
|
13
|
+
* is returned as-is, anything else becomes a `ConstantToken` of itself. The
|
|
14
|
+
* library never applies it to the args list - a call site that wants
|
|
15
|
+
* "resolve tokens, pass literals through" does so explicitly, e.g.
|
|
16
|
+
* `@inject(({ scope, args = [] }) => argToToken(args[0]).resolve(scope))`.
|
|
17
|
+
*/
|
|
7
18
|
export declare const argToToken: <T = unknown>(v: T) => InjectionToken<T>;
|
|
19
|
+
//# sourceMappingURL=toToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toToken.d.ts","sourceRoot":"","sources":["../../lib/token/toToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,yBAAyB,CAAC;AAKzE,OAAO,EAAE,cAAc,EAAoB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,WAAW,EAAM,MAAM,gBAAgB,CAAC;AAGtD,4FAA4F;AAC5F,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,aAAa,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnG;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,GAAG,GAAG,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAoBvE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,KAAG,cAAc,CAAC,CAAC,CAAwD,CAAC"}
|
|
@@ -1,20 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The proxy operations the library depends on. Depend on this rather than on
|
|
3
|
+
* {@link ProxyRegistry} itself, so a caller can substitute its own
|
|
4
|
+
* implementation - the concrete registry is a singleton and cannot be
|
|
5
|
+
* constructed a second time.
|
|
6
|
+
*/
|
|
1
7
|
export interface IProxyRegistry {
|
|
8
|
+
/**
|
|
9
|
+
* Returns the real object behind `value`, unwrapping proxies stacked to any
|
|
10
|
+
* depth. A value that is not a proxy is returned as is.
|
|
11
|
+
*
|
|
12
|
+
* The library calls this itself wherever a proxy would give the wrong answer -
|
|
13
|
+
* every read of class metadata (see `resolveConstructor`, `getHooks`,
|
|
14
|
+
* `resolveArgs`) and every identity check against a tracked instance (see
|
|
15
|
+
* `IContainer.hasInstance`). Pass the container's own values to those APIs as
|
|
16
|
+
* they come; unwrapping by hand is for code that needs the real object for its
|
|
17
|
+
* own reasons.
|
|
18
|
+
*/
|
|
2
19
|
unwrap<T extends object>(value: T): T;
|
|
3
20
|
createProxy<T extends object>(target: T, handler?: ProxyHandler<T>): T;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a proxy that resolves its target on first access and caches it.
|
|
23
|
+
*/
|
|
4
24
|
createLazyProxy<T extends object>(resolveInstance: () => T): T;
|
|
25
|
+
/**
|
|
26
|
+
* Wraps `resolveInstance` in a lazy proxy when `isLazy`, otherwise calls it
|
|
27
|
+
* right away.
|
|
28
|
+
*/
|
|
5
29
|
toLazyIf<T extends object>(resolveInstance: () => T, isLazy?: boolean): T;
|
|
6
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates proxies and tracks them, so a proxy can be traced back to the real
|
|
33
|
+
* object it stands for. The library's own {@link IProxyRegistry}.
|
|
34
|
+
*
|
|
35
|
+
* Process-wide singleton: a proxy created anywhere must be unwrappable
|
|
36
|
+
* everywhere, and the registry holds no configuration that would justify a
|
|
37
|
+
* second instance. Obtain it with {@link ProxyRegistry.getInstance}.
|
|
38
|
+
*
|
|
39
|
+
* Entries are held weakly - a proxy that becomes unreachable is collected along
|
|
40
|
+
* with its state.
|
|
41
|
+
*/
|
|
7
42
|
export declare class ProxyRegistry implements IProxyRegistry {
|
|
8
43
|
private static instance?;
|
|
9
44
|
private readonly states;
|
|
10
45
|
private constructor();
|
|
11
46
|
static getInstance(): ProxyRegistry;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the real object behind `value`, unwrapping proxies stacked to any
|
|
49
|
+
* depth. A value that is not a proxy is returned as is.
|
|
50
|
+
*/
|
|
12
51
|
unwrap<T extends object>(value: T): T;
|
|
13
52
|
createProxy<T extends object>(target: T, handler?: ProxyHandler<T>): T;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a proxy that resolves its target on first access and caches it.
|
|
55
|
+
* The target is unwrapped on resolution, so wrapping a lazy proxy in another
|
|
56
|
+
* lazy proxy never stacks beyond one level.
|
|
57
|
+
*/
|
|
14
58
|
createLazyProxy<T extends object>(resolveInstance: () => T): T;
|
|
59
|
+
/**
|
|
60
|
+
* Wraps `resolveInstance` in a lazy proxy when `isLazy`, otherwise calls it
|
|
61
|
+
* right away.
|
|
62
|
+
*/
|
|
15
63
|
toLazyIf<T extends object>(resolveInstance: () => T, isLazy?: boolean): T;
|
|
16
64
|
private isProxy;
|
|
17
65
|
private getTarget;
|
|
18
66
|
private register;
|
|
19
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The real object behind `value`, unwrapping proxies stacked to any depth. A
|
|
70
|
+
* value that is not a proxy is returned as is.
|
|
71
|
+
*
|
|
72
|
+
* A shortcut for `ProxyRegistry.getInstance().unwrap(value)` - the registry is a
|
|
73
|
+
* process-wide singleton, so unwrapping never needs an instance of its own. The
|
|
74
|
+
* library already unwraps wherever a proxy would give the wrong answer (reading
|
|
75
|
+
* class metadata, and `IContainer.hasInstance`), so reach for this only when
|
|
76
|
+
* your own code needs the real object - an identity check of your own, or
|
|
77
|
+
* bypassing a lazy proxy on purpose.
|
|
78
|
+
*
|
|
79
|
+
* Note that unwrapping a lazy proxy resolves its target, which is the point:
|
|
80
|
+
* there is no real object to hand back until it does.
|
|
81
|
+
*/
|
|
20
82
|
export declare const unwrapProxy: <T extends object>(value: T) => T;
|
|
83
|
+
//# sourceMappingURL=ProxyRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyRegistry.d.ts","sourceRoot":"","sources":["../../lib/utils/ProxyRegistry.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IAEtC,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAEvE;;OAEG;IACH,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAE/D;;;OAGG;IACH,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;CAC3E;AAED;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,cAAc;IAClD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAgB;IAExC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;IAEpE,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,aAAa;IAKnC;;;OAGG;IACH,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAIrC,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,GAAE,YAAY,CAAC,CAAC,CAAM,GAAG,CAAC;IAK1E;;;;OAIG;IACH,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC;IA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