ts-ioc-container 72.0.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/README.md +94 -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 +8 -3
- package/cjm/metadata/class.js +3 -1
- package/cjm/metadata/method.js +3 -1
- package/cjm/metadata/parameter.js +7 -1
- 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 +4 -3
- package/esm/metadata/class.js +1 -0
- package/esm/metadata/method.js +1 -0
- package/esm/metadata/parameter.js +5 -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 +5 -3
- 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 +28 -0
- package/typings/metadata/class.d.ts.map +1 -0
- package/typings/metadata/method.d.ts +25 -0
- package/typings/metadata/method.d.ts.map +1 -0
- package/typings/metadata/parameter.d.ts +22 -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
|
@@ -4,29 +4,80 @@ import { type IRegistration } from '../registration/IRegistration.js';
|
|
|
4
4
|
import { type constructor, type Instance } from '../utils/basic.js';
|
|
5
5
|
import { type IInjector } from '../injector/IInjector.js';
|
|
6
6
|
import { type ITypedEvent } from '../utils/TypedEvent.js';
|
|
7
|
+
/**
|
|
8
|
+
* Terminates the parent chain of every root {@link Container}: `resolve` throws
|
|
9
|
+
* `DependencyNotFoundError`, alias lookups return nothing, and every other
|
|
10
|
+
* method throws `MethodNotImplementedError`. You rarely use it directly.
|
|
11
|
+
*/
|
|
7
12
|
export declare class EmptyContainer implements IContainer {
|
|
13
|
+
/**
|
|
14
|
+
* @throws {MethodNotImplementedError} always — the empty container has no disposal state.
|
|
15
|
+
*/
|
|
8
16
|
get isDisposed(): boolean;
|
|
9
17
|
addInstance(instance: Instance): void;
|
|
10
18
|
getParent(): undefined;
|
|
11
19
|
getScopes(): never[];
|
|
12
20
|
getInstances(): never[];
|
|
13
21
|
hasInstance(instance: Instance): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot create scopes.
|
|
24
|
+
*/
|
|
14
25
|
createScope(): IContainer;
|
|
26
|
+
/**
|
|
27
|
+
* @throws {MethodNotImplementedError} always — the empty container constructs nothing, so it has no injector.
|
|
28
|
+
*/
|
|
15
29
|
getInjector(): IInjector;
|
|
30
|
+
/**
|
|
31
|
+
* @throws {MethodNotImplementedError} always — the empty container holds no providers to resolve.
|
|
32
|
+
*/
|
|
16
33
|
autoResolve(options?: AutoResolveOptions): this;
|
|
34
|
+
/**
|
|
35
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot be disposed.
|
|
36
|
+
*/
|
|
17
37
|
dispose(): void;
|
|
38
|
+
/**
|
|
39
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot hold registrations.
|
|
40
|
+
*/
|
|
18
41
|
register(key: DependencyKey, value: IProvider): this;
|
|
42
|
+
/**
|
|
43
|
+
* @throws {MethodNotImplementedError} always — the empty container has no tags.
|
|
44
|
+
*/
|
|
19
45
|
hasTag(tag: Tag): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @throws {MethodNotImplementedError} always — the empty container has no tags.
|
|
48
|
+
*/
|
|
20
49
|
addTags(...tags: Tag[]): void;
|
|
21
50
|
getRegistrations(): never[];
|
|
22
51
|
hasRegistration(key: DependencyKey): boolean;
|
|
23
52
|
removeScope(): void;
|
|
53
|
+
/**
|
|
54
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot use modules.
|
|
55
|
+
*/
|
|
24
56
|
useModule(module: IContainerModule): this;
|
|
57
|
+
/**
|
|
58
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot hold registrations.
|
|
59
|
+
*/
|
|
25
60
|
addRegistration(registration: IRegistration): this;
|
|
61
|
+
/**
|
|
62
|
+
* @throws {DependencyNotFoundError} always — reaching the empty container means `key` was not found in any scope.
|
|
63
|
+
*/
|
|
26
64
|
resolve<T>(key: constructor<T> | DependencyKey, options?: ResolveOneOptions): T;
|
|
27
65
|
resolveByAlias<T>(alias: DependencyKey, options?: ResolveManyOptions): T[];
|
|
66
|
+
/**
|
|
67
|
+
* @throws {DependencyNotFoundError} always — reaching the empty container means `alias` was not found in any scope.
|
|
68
|
+
*/
|
|
28
69
|
resolveOneByAlias<T>(alias: DependencyKey, options?: ResolveOneOptions): T;
|
|
70
|
+
/**
|
|
71
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot hold hooks.
|
|
72
|
+
*/
|
|
29
73
|
get scopeCreated(): ITypedEvent<[IContainer]>;
|
|
74
|
+
/**
|
|
75
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot hold hooks.
|
|
76
|
+
*/
|
|
30
77
|
get scopeDisposed(): ITypedEvent<[IContainer]>;
|
|
78
|
+
/**
|
|
79
|
+
* @throws {MethodNotImplementedError} always — the empty container cannot hold hooks.
|
|
80
|
+
*/
|
|
31
81
|
get registered(): ITypedEvent<[IProvider, DependencyKey, IContainer]>;
|
|
32
82
|
}
|
|
83
|
+
//# sourceMappingURL=EmptyContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmptyContainer.d.ts","sourceRoot":"","sources":["../../lib/container/EmptyContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAA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AI;IAIlD;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,aAAa,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,CAAC;IAQ/E,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,CAAC,EAAE;IAI1E;;OAEG;IACH,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,CAAC;IAM1E;;OAEG;IACH,IAAI,YAAY,IAAI,WAAW,CAAC,CAAC,UAAU,CAAC,CAAC,CAE5C;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,WAAW,CAAC,CAAC,UAAU,CAAC,CAAC,CAE7C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,WAAW,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAEpE;CACF"}
|
|
@@ -3,8 +3,11 @@ import { type IRegistration } from '../registration/IRegistration.js';
|
|
|
3
3
|
import { IInjector, type WithArgs } from '../injector/IInjector.js';
|
|
4
4
|
import { type constructor, Instance } from '../utils/basic.js';
|
|
5
5
|
import { type ITypedEvent } from '../utils/TypedEvent.js';
|
|
6
|
+
/** A registration key: a string or a symbol. */
|
|
6
7
|
export type DependencyKey = string | symbol;
|
|
8
|
+
/** Narrows `target` to a {@link DependencyKey}. */
|
|
7
9
|
export declare function isDependencyKey(target: unknown): target is DependencyKey;
|
|
10
|
+
/** A scope label (`'application'`, `'request'`, ...) matched by `scope(...)` rules. */
|
|
8
11
|
export type Tag = string;
|
|
9
12
|
type WithTags = {
|
|
10
13
|
tags: Tag[];
|
|
@@ -15,47 +18,119 @@ type WithChild = {
|
|
|
15
18
|
type WithExcludedKeys = {
|
|
16
19
|
excludedKeys: DependencyKey[];
|
|
17
20
|
};
|
|
21
|
+
/** Something carrying tags: a scope or a token. */
|
|
18
22
|
export interface Tagged {
|
|
19
23
|
hasTag(tag: Tag): boolean;
|
|
20
24
|
addTags(...tags: Tag[]): void;
|
|
21
25
|
}
|
|
26
|
+
/** Options of `resolve`: runtime `args`, `lazy`, and the invoking `child` scope. */
|
|
22
27
|
export type ResolveOneOptions = ResolveOptions & Partial<WithChild>;
|
|
28
|
+
/** Options of `resolveByAlias`: like {@link ResolveOneOptions}, plus keys to exclude. */
|
|
23
29
|
export type ResolveManyOptions = ResolveOneOptions & Partial<WithExcludedKeys>;
|
|
30
|
+
/** Something that resolves a key or a class. */
|
|
24
31
|
export interface Resolvable {
|
|
25
32
|
resolve<T>(key: constructor<T> | DependencyKey, options?: ResolveOneOptions): T;
|
|
26
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* A reusable bundle of registrations or event subscriptions applied with
|
|
36
|
+
* `container.useModule(module)`. A plain object with `applyTo` is enough.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const loggingModule: IContainerModule = {
|
|
40
|
+
* applyTo: (container) => container.addRegistration(Registration.fromClass(Logger)),
|
|
41
|
+
* };
|
|
42
|
+
*/
|
|
27
43
|
export interface IContainerModule {
|
|
28
44
|
applyTo(container: IContainer): void;
|
|
29
45
|
}
|
|
46
|
+
/** Options of `createScope`: the child scope's `tags`. */
|
|
30
47
|
export type CreateScopeOptions = Partial<WithTags>;
|
|
31
48
|
export type AutoResolveOptions = Partial<WithArgs>;
|
|
32
49
|
export type RegisterOptions = {
|
|
33
50
|
aliases?: DependencyKey[];
|
|
34
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Scope event hooks - the container's own domain: a scope was created, a scope
|
|
54
|
+
* was disposed. The listener type of `IContainer.scopeCreated` / `scopeDisposed`.
|
|
55
|
+
*
|
|
56
|
+
* The other two hook domains live with the abstraction which raises them:
|
|
57
|
+
* injector hooks on `IInjector` (`InjectorHook`), provider hooks on
|
|
58
|
+
* {@link IProvider} (`ProviderHook`). An injector is configured before it is
|
|
59
|
+
* passed to a container's constructor, so a container never hands its injector
|
|
60
|
+
* out.
|
|
61
|
+
*/
|
|
35
62
|
export type ScopeHook = (scope: IContainer) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Scope event hook for a registration landing in a scope: a provider entered
|
|
65
|
+
* the provider map under `key`. Registration is always of a provider, so the
|
|
66
|
+
* name says only what varies. The listener type of `IContainer.registered`.
|
|
67
|
+
*/
|
|
36
68
|
export type RegisteredHook = (provider: IProvider, key: DependencyKey, scope: IContainer) => void;
|
|
69
|
+
/** A dependency injection scope. See {@link Container}. */
|
|
37
70
|
export interface IContainer extends Tagged {
|
|
38
71
|
readonly isDisposed: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Raised once a scope this container created is fully registered and attached.
|
|
74
|
+
* The subscriber's side only - a container raises its own scope events.
|
|
75
|
+
*/
|
|
39
76
|
readonly scopeCreated: ITypedEvent<[IContainer]>;
|
|
77
|
+
/**
|
|
78
|
+
* Raised by this container as it disposes, before its providers and instances go.
|
|
79
|
+
*/
|
|
40
80
|
readonly scopeDisposed: ITypedEvent<[IContainer]>;
|
|
81
|
+
/**
|
|
82
|
+
* Raised once a provider is registered here under a resolvable key.
|
|
83
|
+
*/
|
|
41
84
|
readonly registered: ITypedEvent<[IProvider, DependencyKey, IContainer]>;
|
|
85
|
+
/** Low-level: puts `value` under `key` in this scope only. Prefer `addRegistration`. */
|
|
42
86
|
register(key: DependencyKey, value: IProvider, options?: RegisterOptions): this;
|
|
87
|
+
/** Registers here if the registration's scope rules match, and remembers it for future child scopes. */
|
|
43
88
|
addRegistration(registration: IRegistration): this;
|
|
89
|
+
/** Registrations added to this scope and its parents - what `createScope` copies. */
|
|
44
90
|
getRegistrations(): IRegistration[];
|
|
91
|
+
/** Whether a provider is registered under `key` in this scope (parents are not checked). */
|
|
45
92
|
hasRegistration(key: DependencyKey): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Resolves a key, or constructs a class with the injector. Takes a key or a
|
|
95
|
+
* class, not a token: for a token call `token.resolve(scope)`.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* scope.resolve<ILogger>('ILogger');
|
|
99
|
+
* scope.resolve(App, { args: ['tenant-1'] });
|
|
100
|
+
*/
|
|
46
101
|
resolve<T>(target: constructor<T> | DependencyKey, options?: ResolveOneOptions): T;
|
|
102
|
+
/** Resolves every accessible dependency registered under `alias`, in this scope and its parents. */
|
|
47
103
|
resolveByAlias<T>(alias: DependencyKey, options?: ResolveManyOptions): T[];
|
|
104
|
+
/** Resolves one dependency registered under `alias`, looking here first and then in parents. */
|
|
48
105
|
resolveOneByAlias<T>(alias: DependencyKey, options?: ResolveOneOptions): T;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a child scope and copies into it the registrations whose scope
|
|
108
|
+
* rules match its tags. Registrations added later are not copied into it.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const request = app.createScope({ tags: ['request'] });
|
|
112
|
+
*/
|
|
49
113
|
createScope(options?: CreateScopeOptions): IContainer;
|
|
114
|
+
/** Resolves every provider marked with `autoResolve()`. */
|
|
50
115
|
autoResolve(options?: AutoResolveOptions): this;
|
|
116
|
+
/** Direct child scopes that are still alive. */
|
|
51
117
|
getScopes(): IContainer[];
|
|
118
|
+
/** Detaches a child scope; called by the child on dispose. */
|
|
52
119
|
removeScope(child: IContainer): void;
|
|
120
|
+
/** Applies a module to this scope. */
|
|
53
121
|
useModule(module: IContainerModule): this;
|
|
122
|
+
/** The parent scope, if any. */
|
|
54
123
|
getParent(): IContainer | undefined;
|
|
124
|
+
/** Instances constructed in this scope, and in child scopes when `cascade` is true. */
|
|
55
125
|
getInstances(cascade?: boolean): Instance[];
|
|
126
|
+
/** Whether this scope tracks `instance`. */
|
|
56
127
|
hasInstance(instance: Instance): boolean;
|
|
128
|
+
/** Raises `scopeDisposed`, drops providers and instances, and detaches from the parent. Child scopes are not disposed. */
|
|
57
129
|
dispose(): void;
|
|
130
|
+
/** Tracks an instance in this scope; called by the injector. */
|
|
58
131
|
addInstance(instance: Instance): void;
|
|
132
|
+
/** The injector shared by this scope tree, e.g. to subscribe to `onConstructed`. */
|
|
59
133
|
getInjector(): IInjector;
|
|
60
134
|
}
|
|
61
135
|
export {};
|
|
136
|
+
//# sourceMappingURL=IContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IContainer.d.ts","sourceRoot":"","sources":["../../lib/container/IContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAC5C,mDAAmD;AACnD,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,aAAa,CAExE;AAED,uFAAuF;AACvF,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AACzB,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,GAAG,EAAE,CAAA;CAAE,CAAC;AAChC,KAAK,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACnC,KAAK,gBAAgB,GAAG;IAAE,YAAY,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC;AAC1D,mDAAmD;AACnD,MAAM,WAAW,MAAM;IACrB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAC1B,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC/B;AAED,oFAAoF;AACpF,MAAM,MAAM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AC;IAE5C,4CAA4C;IAC5C,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;IAEzC,0HAA0H;IAC1H,OAAO,IAAI,IAAI,CAAC;IAEhB,gEAAgE;IAChE,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEtC,oFAAoF;IACpF,WAAW,IAAI,SAAS,CAAC;CAC1B"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown by `findOrFail` when no runtime arg matches the predicate. Code `IOC_ARGUMENT_NOT_FOUND`. */
|
|
2
3
|
export declare class ArgumentNotFoundError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_ARGUMENT_NOT_FOUND";
|
|
4
6
|
constructor(message?: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=ArgumentNotFoundError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArgumentNotFoundError.d.ts","sourceRoot":"","sources":["../../lib/errors/ArgumentNotFoundError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,uGAAuG;AACvG,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,IAAI,SAA2B;IAC/B,QAAQ,CAAC,IAAI,4BAA4B;gBAE7B,OAAO,SAAuB;CAK3C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { CannotApplySingletonTwiceError } from './CannotApplySingletonTwiceError.js';
|
|
2
|
+
/** @deprecated Misspelled name kept for compatibility. Use {@link CannotApplySingletonTwiceError}. */
|
|
3
|
+
export declare const CannonSingletonApplyTwiceError: typeof CannotApplySingletonTwiceError;
|
|
4
|
+
/** @deprecated Misspelled name kept for compatibility. Use {@link CannotApplySingletonTwiceError}. */
|
|
5
|
+
export type CannonSingletonApplyTwiceError = CannotApplySingletonTwiceError;
|
|
6
|
+
//# sourceMappingURL=CannonSingletonApplyTwiceError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CannonSingletonApplyTwiceError.d.ts","sourceRoot":"","sources":["../../lib/errors/CannonSingletonApplyTwiceError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,sGAAsG;AACtG,eAAO,MAAM,8BAA8B,uCAAiC,CAAC;AAC7E,sGAAsG;AACtG,MAAM,MAAM,8BAA8B,GAAG,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown when `singleton()` is applied twice to one provider. Code `IOC_SINGLETON_APPLIED_TWICE`. */
|
|
3
|
+
export declare class CannotApplySingletonTwiceError extends ContainerError {
|
|
4
|
+
name: string;
|
|
5
|
+
readonly code = "IOC_SINGLETON_APPLIED_TWICE";
|
|
6
|
+
constructor(message?: string);
|
|
7
|
+
/**
|
|
8
|
+
* @throws {CannotApplySingletonTwiceError} when `isTrue` is falsy.
|
|
9
|
+
*/
|
|
10
|
+
static assert(isTrue: boolean, failMessage: string): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=CannotApplySingletonTwiceError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CannotApplySingletonTwiceError.d.ts","sourceRoot":"","sources":["../../lib/errors/CannotApplySingletonTwiceError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,sGAAsG;AACtG,qBAAa,8BAA+B,SAAQ,cAAc;IAChE,IAAI,SAAoC;IACxC,QAAQ,CAAC,IAAI,iCAAiC;gBAElC,OAAO,CAAC,EAAE,MAAM;IAM5B;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM;CAKnD"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown when a disposed scope is used. Code `IOC_CONTAINER_DISPOSED`. */
|
|
2
3
|
export declare class ContainerDisposedError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_CONTAINER_DISPOSED";
|
|
4
6
|
constructor(message: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=ContainerDisposedError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContainerDisposedError.d.ts","sourceRoot":"","sources":["../../lib/errors/ContainerDisposedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,2EAA2E;AAC3E,qBAAa,sBAAuB,SAAQ,cAAc;IACxD,IAAI,SAA4B;IAChC,QAAQ,CAAC,IAAI,4BAA4B;gBAE7B,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of every error the container throws. `code` is stable across
|
|
3
|
+
* versions (unlike `message`), so match on it — or on the subclass — rather
|
|
4
|
+
* than on the text. The codes are listed in the package's AGENTS.md.
|
|
5
|
+
*/
|
|
1
6
|
export declare abstract class ContainerError extends Error {
|
|
2
7
|
name: string;
|
|
8
|
+
readonly code: string;
|
|
3
9
|
protected constructor(message?: string);
|
|
4
10
|
}
|
|
11
|
+
//# sourceMappingURL=ContainerError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContainerError.d.ts","sourceRoot":"","sources":["../../lib/errors/ContainerError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAAsB,cAAe,SAAQ,KAAK;IAChD,IAAI,SAAoB;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAyB;IAE9C,SAAS,aAAa,OAAO,CAAC,EAAE,MAAM;CAKvC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Signals that no container is associated with a target. Code `IOC_CONTAINER_NOT_FOUND`. */
|
|
2
3
|
export declare class ContainerNotFoundError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_CONTAINER_NOT_FOUND";
|
|
4
6
|
constructor(message: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=ContainerNotFoundError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContainerNotFoundError.d.ts","sourceRoot":"","sources":["../../lib/errors/ContainerNotFoundError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,6FAA6F;AAC7F,qBAAa,sBAAuB,SAAQ,cAAc;IACxD,IAAI,SAA4B;IAChC,QAAQ,CAAC,IAAI,6BAA6B;gBAE9B,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown when a registration has no binding key. Code `IOC_DEPENDENCY_MISSING_KEY`. */
|
|
2
3
|
export declare class DependencyMissingKeyError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_DEPENDENCY_MISSING_KEY";
|
|
4
6
|
constructor(message: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=DependencyMissingKeyError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependencyMissingKeyError.d.ts","sourceRoot":"","sources":["../../lib/errors/DependencyMissingKeyError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,wFAAwF;AACxF,qBAAa,yBAA0B,SAAQ,cAAc;IAC3D,IAAI,SAA+B;IACnC,QAAQ,CAAC,IAAI,gCAAgC;gBAEjC,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown when a key or alias is not found in the scope or any parent. Code `IOC_DEPENDENCY_NOT_FOUND`. */
|
|
2
3
|
export declare class DependencyNotFoundError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_DEPENDENCY_NOT_FOUND";
|
|
4
6
|
constructor(message: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=DependencyNotFoundError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependencyNotFoundError.d.ts","sourceRoot":"","sources":["../../lib/errors/DependencyNotFoundError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,2GAA2G;AAC3G,qBAAa,uBAAwB,SAAQ,cAAc;IACzD,IAAI,SAA6B;IACjC,QAAQ,CAAC,IAAI,8BAA8B;gBAE/B,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown by a method the object does not support; the message names the class and method. Code `IOC_METHOD_NOT_IMPLEMENTED`. */
|
|
2
3
|
export declare class MethodNotImplementedError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_METHOD_NOT_IMPLEMENTED";
|
|
4
6
|
constructor(message?: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=MethodNotImplementedError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MethodNotImplementedError.d.ts","sourceRoot":"","sources":["../../lib/errors/MethodNotImplementedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,iIAAiI;AACjI,qBAAa,yBAA0B,SAAQ,cAAc;IAC3D,IAAI,SAA+B;IACnC,QAAQ,CAAC,IAAI,gCAAgC;gBAEjC,OAAO,CAAC,EAAE,MAAM;CAK7B"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown when a provider of a disposed scope is used. Code `IOC_PROVIDER_DISPOSED`. */
|
|
2
3
|
export declare class ProviderDisposedError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_PROVIDER_DISPOSED";
|
|
6
|
+
/**
|
|
7
|
+
* @throws {ProviderDisposedError} when `isTrue` is falsy.
|
|
8
|
+
*/
|
|
4
9
|
static assert(isTrue: boolean, failMessage: string): void;
|
|
5
10
|
constructor(message: string);
|
|
6
11
|
}
|
|
12
|
+
//# sourceMappingURL=ProviderDisposedError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderDisposedError.d.ts","sourceRoot":"","sources":["../../lib/errors/ProviderDisposedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,wFAAwF;AACxF,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,IAAI,SAA2B;IAC/B,QAAQ,CAAC,IAAI,2BAA2B;IAExC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM;gBAMtC,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown when subscribing to an event of a disposed scope. Code `IOC_EVENT_DISPOSED`. */
|
|
2
3
|
export declare class TypedEventDisposedError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_EVENT_DISPOSED";
|
|
6
|
+
/**
|
|
7
|
+
* @throws {TypedEventDisposedError} when `isTrue` is falsy.
|
|
8
|
+
*/
|
|
4
9
|
static assert(isTrue: boolean, failMessage: string): void;
|
|
5
10
|
constructor(message: string);
|
|
6
11
|
}
|
|
12
|
+
//# sourceMappingURL=TypedEventDisposedError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedEventDisposedError.d.ts","sourceRoot":"","sources":["../../lib/errors/TypedEventDisposedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,0FAA0F;AAC1F,qBAAa,uBAAwB,SAAQ,cAAc;IACzD,IAAI,SAA6B;IACjC,QAAQ,CAAC,IAAI,wBAAwB;IAErC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM;gBAMtC,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ContainerError } from './ContainerError.js';
|
|
2
|
+
/** Thrown by `toToken` for a value that is not a token, key, class or function. Code `IOC_UNSUPPORTED_TOKEN_TYPE`. */
|
|
2
3
|
export declare class UnsupportedTokenTypeError extends ContainerError {
|
|
3
4
|
name: string;
|
|
5
|
+
readonly code = "IOC_UNSUPPORTED_TOKEN_TYPE";
|
|
4
6
|
constructor(message: string);
|
|
5
7
|
}
|
|
8
|
+
//# sourceMappingURL=UnsupportedTokenTypeError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsupportedTokenTypeError.d.ts","sourceRoot":"","sources":["../../lib/errors/UnsupportedTokenTypeError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,sHAAsH;AACtH,qBAAa,yBAA0B,SAAQ,cAAc;IAC3D,IAAI,SAA+B;IACnC,QAAQ,CAAC,IAAI,gCAAgC;gBAEjC,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -3,26 +3,62 @@ import { type Task } from '../utils/task.js';
|
|
|
3
3
|
import { type Instance } from '../utils/basic.js';
|
|
4
4
|
import { type HookFn } from './hook.js';
|
|
5
5
|
import { type CreateHookExecutionContext, type IHookContext } from './HookContext.js';
|
|
6
|
+
/** Transforms each hook context before it is handed to its hook. */
|
|
6
7
|
export type MapHookExecutionContext = (context: IHookContext) => IHookContext;
|
|
8
|
+
/**
|
|
9
|
+
* One decorated member's hook, resolved to a function and bound to the context
|
|
10
|
+
* it runs against — the model the library hands back, and the whole of what it
|
|
11
|
+
* says about a hook. The member it came from is `context.methodName`.
|
|
12
|
+
* Performing it is the caller's business (ADR 0016).
|
|
13
|
+
*/
|
|
7
14
|
export type HookAction = {
|
|
8
15
|
hook: HookFn;
|
|
9
16
|
context: IHookContext;
|
|
10
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Shapes what is collected: how each action's hook context is built, and which
|
|
20
|
+
* members take part. A collector carries defaults for all three, so a call
|
|
21
|
+
* names only what it overrides.
|
|
22
|
+
*/
|
|
11
23
|
export type HookCollectorOptions = {
|
|
12
24
|
createExecutionContext?: CreateHookExecutionContext;
|
|
13
25
|
mapExecutionContext?: MapHookExecutionContext;
|
|
14
26
|
predicate?: (methodName: string) => boolean;
|
|
15
27
|
};
|
|
28
|
+
/** What one collection runs in: the scope, plus any per-call overrides of the collector's options. */
|
|
16
29
|
export type HookCollectionContext = ExecutionContext & HookCollectorOptions;
|
|
30
|
+
/** Options of `new HookCollector(...)`. */
|
|
17
31
|
export type HookCollectorProps = HookCollectorOptions & {
|
|
32
|
+
/** The hook key this collector reads: `onConstruct`, `onScopeDisposed`, `onResolved`, or a custom one. */
|
|
18
33
|
key: string | symbol;
|
|
19
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Reads the hooks declared under one key off a target and hands them back as
|
|
37
|
+
* {@link HookAction}s, in declaration order. It runs nothing: what order the
|
|
38
|
+
* actions are performed in, what is awaited and where a failure goes are
|
|
39
|
+
* answered by the caller (ADR 0016).
|
|
40
|
+
*
|
|
41
|
+
* Wire it to whichever event should collect — the injector's `onConstructed`,
|
|
42
|
+
* the scope's `scopeDisposed`, a provider's `onResolved` — the library ships no
|
|
43
|
+
* module which does that for you (ADR 0018).
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const collector = new HookCollector({ key: 'onStart' });
|
|
47
|
+
*
|
|
48
|
+
* container.getInjector().onConstructed((instance, scope) => {
|
|
49
|
+
* runInOrder(collector.getActions(instance, { scope }).map(toTask))?.catch(report);
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
20
53
|
export declare class HookCollector {
|
|
21
54
|
private readonly key;
|
|
22
55
|
private readonly options;
|
|
23
56
|
private readonly hooksOf;
|
|
24
57
|
constructor({ key, createExecutionContext, mapExecutionContext, predicate, }: HookCollectorProps);
|
|
25
58
|
hasHooks(target: Instance): boolean;
|
|
59
|
+
/** The actions `target` declares under this collector's key — empty when it declares none. */
|
|
26
60
|
getActions(target: Instance, { scope, createExecutionContext, mapExecutionContext, predicate, }: HookCollectionContext): HookAction[];
|
|
27
61
|
}
|
|
62
|
+
/** The {@link Task} an action runs as: `runInOrder(actions.map(toTask))`, `runAtOnce(actions.map(toTask))`. */
|
|
28
63
|
export declare const toTask: ({ hook, context }: HookAction) => Task;
|
|
64
|
+
//# sourceMappingURL=HookCollector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookCollector.d.ts","sourceRoot":"","sources":["../../lib/hooks/HookCollector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAsB,KAAK,MAAM,EAAY,MAAM,QAAQ,CAAC;AACnE,OAAO,EAA8B,KAAK,0BAA0B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 -1,6 +1,11 @@
|
|
|
1
1
|
import type { IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { type Instance } from '../utils/basic.js';
|
|
3
3
|
import { type InjectFn } from './hook.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a hook receives: the `instance`, the `scope` and the decorated member's
|
|
6
|
+
* name. `invokeMethod({ args: resolveArgs() })` calls the member with its
|
|
7
|
+
* `@inject` parameters; `setProperty(fn)` assigns it (see `injectProp`).
|
|
8
|
+
*/
|
|
4
9
|
export interface IHookContext {
|
|
5
10
|
instance: Instance;
|
|
6
11
|
scope: IContainer;
|
|
@@ -14,6 +19,7 @@ export interface IHookContext {
|
|
|
14
19
|
setInitialArgs(...args: unknown[]): this;
|
|
15
20
|
getInitialArgs(): unknown[];
|
|
16
21
|
}
|
|
22
|
+
/** The default {@link IHookContext}. */
|
|
17
23
|
export declare class HookContext implements IHookContext {
|
|
18
24
|
readonly instance: Instance;
|
|
19
25
|
readonly scope: IContainer;
|
|
@@ -29,8 +35,12 @@ export declare class HookContext implements IHookContext {
|
|
|
29
35
|
setInitialArgs(...args: unknown[]): this;
|
|
30
36
|
getInitialArgs(): unknown[];
|
|
31
37
|
}
|
|
38
|
+
/** Builds the context a hook receives. */
|
|
32
39
|
export type CreateHookExecutionContext = (Target: Instance, scope: IContainer, methodName?: string) => IHookContext;
|
|
40
|
+
/** The default {@link CreateHookExecutionContext}: a {@link HookContext}. */
|
|
33
41
|
export declare const createHookExecutionContext: CreateHookExecutionContext;
|
|
42
|
+
/** A {@link CreateHookExecutionContext} whose contexts start with `args` as initial args. */
|
|
34
43
|
export declare const createHookContextFactory: ({ args }?: {
|
|
35
44
|
args?: unknown[];
|
|
36
45
|
}) => CreateHookExecutionContext;
|
|
46
|
+
//# sourceMappingURL=HookContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookContext.d.ts","sourceRoot":"","sources":["../../lib/hooks/HookContext.ts"],"names":[],"mappings":"AAAA,OAAO,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C,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAKxC,cAAc,IAAI,OAAO,EAAE;CAG5B;AAED,0CAA0C;AAC1C,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,YAAY,CAAC;AACpH,6EAA6E;AAC7E,eAAO,MAAM,0BAA0B,EAAE,0BACG,CAAC;AAE7C,6FAA6F;AAC7F,eAAO,MAAM,wBAAwB,GAClC,WAAe;IAAE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;CAAO,KAAG,0BAEmC,CAAC"}
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import type { IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { type HookFn, type HookType } from './hook.js';
|
|
3
|
+
/**
|
|
4
|
+
* A provider hook narrowed to the dependencies that can carry hook metadata.
|
|
5
|
+
*/
|
|
3
6
|
export type ResolvedObjectHook = (dependency: object, scope: IContainer) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Combines hooks into one which runs them in declaration order, staying
|
|
9
|
+
* synchronous until one returns a promise and awaiting the rest from that point.
|
|
10
|
+
*
|
|
11
|
+
* A member carries a single hook, so this is how several are declared together:
|
|
12
|
+
* `@hook('onConstruct', sequential(validate, persist))`.
|
|
13
|
+
*/
|
|
4
14
|
export declare const sequential: (...hooks: HookType[]) => HookFn;
|
|
15
|
+
/**
|
|
16
|
+
* Combines hooks into one which starts them all at once. Settles when every
|
|
17
|
+
* hook has; a fully synchronous run returns nothing, like {@link sequential}.
|
|
18
|
+
*
|
|
19
|
+
* Use it for hooks of one member which do not depend on each other:
|
|
20
|
+
* `@hook('onScopeDisposed', parallel(flush, closeSocket))`.
|
|
21
|
+
*/
|
|
5
22
|
export declare const parallel: (...hooks: HookType[]) => HookFn;
|
|
23
|
+
/**
|
|
24
|
+
* Wraps a hook so it runs a single time per instance, however often the event
|
|
25
|
+
* it is declared under fires. Composes with the combinators above —
|
|
26
|
+
* `oncePerInstance(sequential(connect, warmUp))` runs the whole sequence once.
|
|
27
|
+
*/
|
|
6
28
|
export declare const oncePerInstance: (execute: HookType) => HookFn;
|
|
29
|
+
//# sourceMappingURL=combinators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combinators.d.ts","sourceRoot":"","sources":["../../lib/hooks/combinators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAY,MAAM,QAAQ,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAEjF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,OAAO,QAAQ,EAAE,KAAG,MAGjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,QAAQ,EAAE,KAAG,MAG/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,QAAQ,KAAG,MAYnD,CAAC"}
|
package/typings/hooks/hook.d.ts
CHANGED
|
@@ -1,14 +1,53 @@
|
|
|
1
1
|
import { type IHookContext } from './HookContext.js';
|
|
2
2
|
import { type constructor, type Instance } from '../utils/basic.js';
|
|
3
3
|
import { ProviderOptions } from '../provider/IProvider.js';
|
|
4
|
+
/**
|
|
5
|
+
* What `@inject(...)` and `injectProp(...)` take: a function of the resolution
|
|
6
|
+
* context returning the value to inject. Usually built with `by(...)` or `arg(...)`.
|
|
7
|
+
*/
|
|
4
8
|
export type InjectFn<T = unknown> = (options: ProviderOptions) => T;
|
|
9
|
+
/** A hook as a function of its context. Must return `void` or `Promise<void>`. */
|
|
5
10
|
export type HookFn<T extends IHookContext = IHookContext> = (context: T) => void | Promise<void>;
|
|
11
|
+
/** A hook as a class resolved from the scope; its `execute` receives the context. */
|
|
6
12
|
export interface HookClass<T extends IHookContext = IHookContext> {
|
|
7
13
|
execute(context: Omit<T, 'scope'>): void | Promise<void>;
|
|
8
14
|
}
|
|
15
|
+
/** Anything `@hook(...)` accepts: a {@link HookFn} or a {@link HookClass} constructor. */
|
|
9
16
|
export type HookType<T extends IHookContext = IHookContext> = HookFn<T> | constructor<HookClass<T>>;
|
|
17
|
+
/** The hooks of one class under one key, by member name: one hook per member (compose with `sequential` / `parallel`). */
|
|
10
18
|
export type HooksOfClass = Map<string, HookType>;
|
|
19
|
+
/** Normalizes a {@link HookType} to a {@link HookFn}; a hook class is resolved from the context's scope. */
|
|
11
20
|
export declare const toHookFn: <C extends IHookContext>(execute: HookFn<C> | constructor<HookClass<C>>) => HookFn<C>;
|
|
21
|
+
/**
|
|
22
|
+
* Reads the hooks declared under `key`, merging hooks declared on parent classes.
|
|
23
|
+
* Hooks are collected from base to derived, so a derived class's hook for the
|
|
24
|
+
* same member replaces the parent's.
|
|
25
|
+
*
|
|
26
|
+
* `target` is an instance or its class, a proxy of either included - it is
|
|
27
|
+
* normalized by `resolveConstructor`, so callers never unwrap it themselves.
|
|
28
|
+
*
|
|
29
|
+
* The merge runs on every call and returns a fresh map. Hook metadata is fixed
|
|
30
|
+
* once a class is defined, so a caller which reads it often can wrap this in
|
|
31
|
+
* `memoize` (`HookCollector` already does).
|
|
32
|
+
*/
|
|
12
33
|
export declare function getHooks(target: Instance | constructor<unknown>, key: string | symbol): HooksOfClass;
|
|
34
|
+
/** Whether `target` (an instance or class, proxies included) declares any hook under `key`. */
|
|
13
35
|
export declare function hasHooks(target: Instance | constructor<unknown>, key: string | symbol): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Method/property decorator that declares a hook under `key`. The library only
|
|
38
|
+
* stores it: collect with `new HookCollector({ key })` and run the actions
|
|
39
|
+
* yourself. A member carries exactly one hook per key - decorating it twice
|
|
40
|
+
* replaces the earlier hook; compose several with `sequential(...)` / `parallel(...)`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const onInit = (fn: HookType) => hook('onInit', fn);
|
|
44
|
+
*
|
|
45
|
+
* class Service {
|
|
46
|
+
* @onInit((ctx) => {
|
|
47
|
+
* ctx.invokeMethod({ args: ctx.resolveArgs() });
|
|
48
|
+
* })
|
|
49
|
+
* init() {}
|
|
50
|
+
* }
|
|
51
|
+
*/
|
|
14
52
|
export declare const hook: (key: string | symbol, fn: HookType) => (target: object, propertyKey: string | symbol) => void;
|
|
53
|
+
//# sourceMappingURL=hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../lib/hooks/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAM,MAAM,gBAAgB,CAAC;AAGrE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,OAAO,EAAE,eAAe,KAAK,CAAC,CAAC;AAEpE,kFAAkF;AAClF,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjG,qFAAqF;AACrF,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY;IAC9D,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,0FAA0F;AAC1F,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpG,0HAA0H;AAC1H,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAQjD,4GAA4G;AAC5G,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,EAAE,SAAS,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CACA,CAAC;AAE3G;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,CAWpG;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAE/F;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,MAAM,GAAG,MAAM,EAAE,IAAI,QAAQ,MAAM,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,SAMxG,CAAC"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { HookFn, InjectFn } from './hook.js';
|
|
2
|
+
/**
|
|
3
|
+
* Injects a dependency into the decorated property.
|
|
4
|
+
*
|
|
5
|
+
* `fn` is an `InjectFn`, exactly as for `@inject`: it receives the resolution
|
|
6
|
+
* context and returns the value to assign, so `injectProp(({ scope }) =>
|
|
7
|
+
* scope.resolve('key'))` assigns the dependency and `injectProp(pipe(fn, sanitize()))`
|
|
8
|
+
* a mapped one.
|
|
9
|
+
*/
|
|
2
10
|
export declare const injectProp: <T>(fn: InjectFn<T>) => HookFn;
|
|
11
|
+
//# sourceMappingURL=injectProp.d.ts.map
|