@kaokei/di 3.0.9 → 4.0.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/README.md +49 -3
- package/dist/binding.d.cts +41 -17
- package/dist/binding.d.ts +41 -17
- package/dist/cachemap.d.cts +23 -8
- package/dist/cachemap.d.ts +23 -8
- package/dist/constants.d.cts +19 -6
- package/dist/constants.d.ts +19 -6
- package/dist/container.d.cts +11 -7
- package/dist/container.d.ts +11 -7
- package/dist/decorator.d.cts +30 -13
- package/dist/decorator.d.ts +30 -13
- package/dist/errors/BaseError.d.cts +1 -0
- package/dist/errors/BaseError.d.ts +1 -0
- package/dist/errors/ContainerNotFoundError.d.cts +5 -0
- package/dist/errors/ContainerNotFoundError.d.ts +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +320 -232
- package/dist/interfaces.d.cts +1 -1
- package/dist/interfaces.d.ts +1 -1
- package/dist/token.d.cts +1 -1
- package/dist/token.d.ts +1 -1
- package/package.json +7 -2
- package/dist/lazyinject.d.cts +0 -4
- package/dist/lazyinject.d.ts +0 -4
package/README.md
CHANGED
|
@@ -14,7 +14,53 @@
|
|
|
14
14
|
|
|
15
15
|
本库主要特点是参考借鉴了`InversifyJS`和`Angular`的优秀 API 设计,不依赖`reflect-metadata`,支持属性注入的循环依赖。
|
|
16
16
|
|
|
17
|
-
- [入门指南](./docs/guide/
|
|
18
|
-
- [API 文档](./docs/api/
|
|
17
|
+
- [入门指南](./docs/guide/index.md)
|
|
18
|
+
- [API 文档](./docs/api/index.md)
|
|
19
19
|
- [博客文章](./docs/note/01.什么是Token.md)
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
## CodeSandbox 在线示例
|
|
22
|
+
|
|
23
|
+
以下示例托管在 GitHub 仓库的 `examples/` 目录中,可通过 CodeSandbox 直接在线运行。
|
|
24
|
+
|
|
25
|
+
URL 格式:`https://codesandbox.io/p/github/kaokei/di/main?file=/examples/<示例目录>/src/index.ts`
|
|
26
|
+
|
|
27
|
+
| 示例 | 说明 | 在线运行 |
|
|
28
|
+
| ------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
29
|
+
| 01-basic-usage | 基础用法:创建容器、绑定服务、属性注入、单例验证 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/01-basic-usage/src/index.ts) |
|
|
30
|
+
| 02-token-usage | Token 用法:Token 实例作为标识符,三种绑定方式 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/02-token-usage/src/index.ts) |
|
|
31
|
+
| 03-optional-inject | Optional 注入:依赖不存在时返回 undefined | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/03-optional-inject/src/index.ts) |
|
|
32
|
+
| 04-hierarchical-di | 层级容器:父子容器创建与依赖查找 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/04-hierarchical-di/src/index.ts) |
|
|
33
|
+
| 05-self-skipself | Self 和 SkipSelf:控制依赖查找范围 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/05-self-skipself/src/index.ts) |
|
|
34
|
+
| 06-lifecycle-activation | 激活生命周期:onActivation 钩子与执行顺序 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/06-lifecycle-activation/src/index.ts) |
|
|
35
|
+
| 07-lifecycle-deactivation | 销毁生命周期:onDeactivation 钩子与执行顺序 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/07-lifecycle-deactivation/src/index.ts) |
|
|
36
|
+
| 08-post-construct | PostConstruct:同步/异步初始化与继承行为 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/08-post-construct/src/index.ts) |
|
|
37
|
+
| 09-pre-destroy | PreDestroy:服务销毁前的清理钩子 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/09-pre-destroy/src/index.ts) |
|
|
38
|
+
| 10-circular-dependency | 循环依赖:属性注入原生支持循环依赖 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/10-circular-dependency/src/index.ts) |
|
|
39
|
+
| 11-lazy-inject | LazyInject:延迟注入,首次访问时才从容器解析 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/11-lazy-inject/src/index.ts) |
|
|
40
|
+
| 12-inheritance | 继承:子类继承父类的属性注入与 PostConstruct 规则 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/12-inheritance/src/index.ts) |
|
|
41
|
+
| 13-to-service | toService 别名:接口 token 映射到实现类 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/13-to-service/src/index.ts) |
|
|
42
|
+
| 14-dynamic-value | 动态值:toDynamicValue 工厂函数与条件注入 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/14-dynamic-value/src/index.ts) |
|
|
43
|
+
| 15-error-handling | 错误处理:各种错误类型的触发场景与捕获方式 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/15-error-handling/src/index.ts) |
|
|
44
|
+
| 16-javascript-usage | JavaScript 用法:使用 decorate 函数手动应用装饰器 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/16-javascript-usage/src/index.js) |
|
|
45
|
+
| 17-container-destroy | 容器销毁:destroy 递归销毁子容器与 getContainerOf | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/17-container-destroy/src/index.ts) |
|
|
46
|
+
| 18-deep-circular-dependency | 深层循环依赖:属性注入支持深层循环链,以及循环依赖检测 | [打开](https://codesandbox.io/p/github/kaokei/di/main?file=/examples/18-deep-circular-dependency/src/index.ts) |
|
|
47
|
+
|
|
48
|
+
每个示例目录包含独立的 `package.json`(依赖已发布的 `@kaokei/di` 版本)和 `tsconfig.json`,与主包构建流程完全隔离,可直接在 CodeSandbox 中运行。
|
|
49
|
+
|
|
50
|
+
## 项目特点
|
|
51
|
+
|
|
52
|
+
本项目只有单例模式,没有inversify中其他模式。
|
|
53
|
+
|
|
54
|
+
本项目中@LazyInject 和 @PostConstruct 只支持class服务。
|
|
55
|
+
|
|
56
|
+
inversify中执行顺序是:
|
|
57
|
+
postConstruct --> binding handler --> container handlers
|
|
58
|
+
container handlers --> binding handler --> preDestroy
|
|
59
|
+
本项目执行顺序:
|
|
60
|
+
binding handler --> container handlers --> postConstruct
|
|
61
|
+
container handlers --> binding handler --> preDestroy
|
|
62
|
+
|
|
63
|
+
@postConstruct装饰器在inversify中,如果A类继承了B类。
|
|
64
|
+
此时如果A类和B类都有 @postConstruct,那么B类不会执行,只有A类会执行。
|
|
65
|
+
如果A类没有@postConstruct,那么会执行B类的。
|
|
66
|
+
如果A继承B继承C,并且A,B都没有@postConstruct,那么会执行C类的。
|
package/dist/binding.d.cts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import { BindingType, StatusType } from './constants';
|
|
1
2
|
import { Container } from './container';
|
|
2
|
-
import { Newable, Context, Options, CommonToken, DynamicValue, ActivationHandler, DeactivationHandler } from './interfaces';
|
|
3
|
+
import { Newable, Context, Options, CommonToken, RecordObject, DynamicValue, PostConstructParam, ActivationHandler, DeactivationHandler } from './interfaces';
|
|
4
|
+
export interface InjectPropertiesResult {
|
|
5
|
+
properties: RecordObject;
|
|
6
|
+
bindings: Binding[];
|
|
7
|
+
}
|
|
3
8
|
export declare class Binding<T = unknown> {
|
|
9
|
+
static _resolvers: Record<string, string>;
|
|
4
10
|
container: Container;
|
|
5
11
|
context: Context;
|
|
6
12
|
token: CommonToken<T>;
|
|
7
|
-
type:
|
|
8
|
-
status:
|
|
9
|
-
classValue
|
|
10
|
-
constantValue
|
|
11
|
-
dynamicValue
|
|
12
|
-
cache
|
|
13
|
-
postConstructResult
|
|
13
|
+
type: BindingType;
|
|
14
|
+
status: StatusType;
|
|
15
|
+
classValue?: Newable<T>;
|
|
16
|
+
constantValue?: T;
|
|
17
|
+
dynamicValue?: DynamicValue<T>;
|
|
18
|
+
cache?: T;
|
|
19
|
+
postConstructResult: Promise<void> | symbol | undefined;
|
|
14
20
|
onActivationHandler?: ActivationHandler<T>;
|
|
15
21
|
onDeactivationHandler?: DeactivationHandler<T>;
|
|
16
22
|
constructor(token: CommonToken<T>, container: Container);
|
|
@@ -23,14 +29,32 @@ export declare class Binding<T = unknown> {
|
|
|
23
29
|
toConstantValue(value: T): this;
|
|
24
30
|
toDynamicValue(func: DynamicValue<T>): this;
|
|
25
31
|
toService(token: CommonToken<T>): this;
|
|
26
|
-
get(options: Options<T>):
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
get(options: Options<T>): any;
|
|
33
|
+
_getAwaitBindings(bindings: Binding[], filter: PostConstructParam): Binding[];
|
|
34
|
+
/**
|
|
35
|
+
* PostConstruct 生命周期处理
|
|
36
|
+
*
|
|
37
|
+
* postConstructResult 的三种状态:
|
|
38
|
+
* - UNINITIALIZED(Symbol):PostConstruct 尚未执行,用于循环依赖检测
|
|
39
|
+
* - undefined:没有使用 @PostConstruct 装饰器,或 @PostConstruct() 无参数时同步执行完毕
|
|
40
|
+
* - Promise<void>:@PostConstruct(value) 有参数时,等待前置服务初始化后异步执行
|
|
41
|
+
*
|
|
42
|
+
* @PostConstruct() 无参数时:同步执行,不等待任何前置服务
|
|
43
|
+
* @PostConstruct(value) 有参数时:等待指定的前置服务初始化完成后再执行
|
|
44
|
+
* - 如果前置服务初始化成功,执行当前服务的 PostConstruct 方法
|
|
45
|
+
* - 如果前置服务初始化失败,rejected promise 自然传播,当前服务的 PostConstruct 不执行
|
|
46
|
+
*/
|
|
47
|
+
_postConstruct(options: Options<T>, propertyBindings: Binding[]): void;
|
|
29
48
|
preDestroy(): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
_execute(key: string): any;
|
|
50
|
+
_resolveInstanceValue(options: Options<T>): T;
|
|
51
|
+
_createInstance(): T;
|
|
52
|
+
_registerInstance(): void;
|
|
53
|
+
_injectProperties(properties: RecordObject): void;
|
|
54
|
+
_resolveConstantValue(): T;
|
|
55
|
+
_resolveDynamicValue(): T;
|
|
56
|
+
_getInjectProperties(options: Options<T>): {
|
|
57
|
+
properties: RecordObject;
|
|
58
|
+
bindings: Binding<unknown>[];
|
|
59
|
+
};
|
|
36
60
|
}
|
package/dist/binding.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import { BindingType, StatusType } from './constants';
|
|
1
2
|
import { Container } from './container';
|
|
2
|
-
import { Newable, Context, Options, CommonToken, DynamicValue, ActivationHandler, DeactivationHandler } from './interfaces';
|
|
3
|
+
import { Newable, Context, Options, CommonToken, RecordObject, DynamicValue, PostConstructParam, ActivationHandler, DeactivationHandler } from './interfaces';
|
|
4
|
+
export interface InjectPropertiesResult {
|
|
5
|
+
properties: RecordObject;
|
|
6
|
+
bindings: Binding[];
|
|
7
|
+
}
|
|
3
8
|
export declare class Binding<T = unknown> {
|
|
9
|
+
static _resolvers: Record<string, string>;
|
|
4
10
|
container: Container;
|
|
5
11
|
context: Context;
|
|
6
12
|
token: CommonToken<T>;
|
|
7
|
-
type:
|
|
8
|
-
status:
|
|
9
|
-
classValue
|
|
10
|
-
constantValue
|
|
11
|
-
dynamicValue
|
|
12
|
-
cache
|
|
13
|
-
postConstructResult
|
|
13
|
+
type: BindingType;
|
|
14
|
+
status: StatusType;
|
|
15
|
+
classValue?: Newable<T>;
|
|
16
|
+
constantValue?: T;
|
|
17
|
+
dynamicValue?: DynamicValue<T>;
|
|
18
|
+
cache?: T;
|
|
19
|
+
postConstructResult: Promise<void> | symbol | undefined;
|
|
14
20
|
onActivationHandler?: ActivationHandler<T>;
|
|
15
21
|
onDeactivationHandler?: DeactivationHandler<T>;
|
|
16
22
|
constructor(token: CommonToken<T>, container: Container);
|
|
@@ -23,14 +29,32 @@ export declare class Binding<T = unknown> {
|
|
|
23
29
|
toConstantValue(value: T): this;
|
|
24
30
|
toDynamicValue(func: DynamicValue<T>): this;
|
|
25
31
|
toService(token: CommonToken<T>): this;
|
|
26
|
-
get(options: Options<T>):
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
get(options: Options<T>): any;
|
|
33
|
+
_getAwaitBindings(bindings: Binding[], filter: PostConstructParam): Binding[];
|
|
34
|
+
/**
|
|
35
|
+
* PostConstruct 生命周期处理
|
|
36
|
+
*
|
|
37
|
+
* postConstructResult 的三种状态:
|
|
38
|
+
* - UNINITIALIZED(Symbol):PostConstruct 尚未执行,用于循环依赖检测
|
|
39
|
+
* - undefined:没有使用 @PostConstruct 装饰器,或 @PostConstruct() 无参数时同步执行完毕
|
|
40
|
+
* - Promise<void>:@PostConstruct(value) 有参数时,等待前置服务初始化后异步执行
|
|
41
|
+
*
|
|
42
|
+
* @PostConstruct() 无参数时:同步执行,不等待任何前置服务
|
|
43
|
+
* @PostConstruct(value) 有参数时:等待指定的前置服务初始化完成后再执行
|
|
44
|
+
* - 如果前置服务初始化成功,执行当前服务的 PostConstruct 方法
|
|
45
|
+
* - 如果前置服务初始化失败,rejected promise 自然传播,当前服务的 PostConstruct 不执行
|
|
46
|
+
*/
|
|
47
|
+
_postConstruct(options: Options<T>, propertyBindings: Binding[]): void;
|
|
29
48
|
preDestroy(): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
_execute(key: string): any;
|
|
50
|
+
_resolveInstanceValue(options: Options<T>): T;
|
|
51
|
+
_createInstance(): T;
|
|
52
|
+
_registerInstance(): void;
|
|
53
|
+
_injectProperties(properties: RecordObject): void;
|
|
54
|
+
_resolveConstantValue(): T;
|
|
55
|
+
_resolveDynamicValue(): T;
|
|
56
|
+
_getInjectProperties(options: Options<T>): {
|
|
57
|
+
properties: RecordObject;
|
|
58
|
+
bindings: Binding<unknown>[];
|
|
59
|
+
};
|
|
36
60
|
}
|
package/dist/cachemap.d.cts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import { CommonToken } from './interfaces';
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { CommonToken, PostConstructParam } from './interfaces';
|
|
2
|
+
import { KEYS } from './constants';
|
|
3
|
+
export interface MetadataMap {
|
|
4
|
+
[KEYS.INJECTED_PROPS]: Record<string, Record<string, unknown>>;
|
|
5
|
+
[KEYS.POST_CONSTRUCT]: {
|
|
6
|
+
key: string;
|
|
7
|
+
value?: PostConstructParam;
|
|
8
|
+
};
|
|
9
|
+
[KEYS.PRE_DESTROY]: {
|
|
10
|
+
key: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function defineMetadata<K extends keyof MetadataMap>(metadataKey: K, metadataValue: MetadataMap[K], target: CommonToken): void;
|
|
14
|
+
export declare function defineMetadata(metadataKey: string, metadataValue: unknown, target: CommonToken): void;
|
|
15
|
+
export declare function getOwnMetadata<K extends keyof MetadataMap>(metadataKey: K, target: CommonToken): MetadataMap[K] | undefined;
|
|
16
|
+
export declare function getOwnMetadata(metadataKey: string, target: CommonToken): unknown | undefined;
|
|
4
17
|
/**
|
|
5
|
-
* 使用hasParentClass判断当前target有没有父类
|
|
6
|
-
* 如果没有父类直接使用getOwnMetadata获取数据
|
|
7
|
-
* 如果有父类,那么需要合并getOwnMetadata(target)和getMetadata(target的父类)
|
|
8
|
-
*
|
|
18
|
+
* 使用 hasParentClass 判断当前 target 有没有父类
|
|
19
|
+
* 如果没有父类直接使用 getOwnMetadata 获取数据
|
|
20
|
+
* 如果有父类,那么需要合并 getOwnMetadata(target) 和 getMetadata(target 的父类)
|
|
21
|
+
* 统一使用展开运算符合并,返回外层新对象、内层原始引用
|
|
22
|
+
* 不支持 META_KEY_INJECTED_PARAMS 作为 metadataKey
|
|
9
23
|
*/
|
|
10
|
-
export declare function getMetadata(metadataKey:
|
|
24
|
+
export declare function getMetadata<K extends keyof MetadataMap>(metadataKey: K, target: CommonToken): MetadataMap[K] | undefined;
|
|
25
|
+
export declare function getMetadata(metadataKey: string, target: CommonToken): unknown | undefined;
|
package/dist/cachemap.d.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import { CommonToken } from './interfaces';
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { CommonToken, PostConstructParam } from './interfaces';
|
|
2
|
+
import { KEYS } from './constants';
|
|
3
|
+
export interface MetadataMap {
|
|
4
|
+
[KEYS.INJECTED_PROPS]: Record<string, Record<string, unknown>>;
|
|
5
|
+
[KEYS.POST_CONSTRUCT]: {
|
|
6
|
+
key: string;
|
|
7
|
+
value?: PostConstructParam;
|
|
8
|
+
};
|
|
9
|
+
[KEYS.PRE_DESTROY]: {
|
|
10
|
+
key: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function defineMetadata<K extends keyof MetadataMap>(metadataKey: K, metadataValue: MetadataMap[K], target: CommonToken): void;
|
|
14
|
+
export declare function defineMetadata(metadataKey: string, metadataValue: unknown, target: CommonToken): void;
|
|
15
|
+
export declare function getOwnMetadata<K extends keyof MetadataMap>(metadataKey: K, target: CommonToken): MetadataMap[K] | undefined;
|
|
16
|
+
export declare function getOwnMetadata(metadataKey: string, target: CommonToken): unknown | undefined;
|
|
4
17
|
/**
|
|
5
|
-
* 使用hasParentClass判断当前target有没有父类
|
|
6
|
-
* 如果没有父类直接使用getOwnMetadata获取数据
|
|
7
|
-
* 如果有父类,那么需要合并getOwnMetadata(target)和getMetadata(target的父类)
|
|
8
|
-
*
|
|
18
|
+
* 使用 hasParentClass 判断当前 target 有没有父类
|
|
19
|
+
* 如果没有父类直接使用 getOwnMetadata 获取数据
|
|
20
|
+
* 如果有父类,那么需要合并 getOwnMetadata(target) 和 getMetadata(target 的父类)
|
|
21
|
+
* 统一使用展开运算符合并,返回外层新对象、内层原始引用
|
|
22
|
+
* 不支持 META_KEY_INJECTED_PARAMS 作为 metadataKey
|
|
9
23
|
*/
|
|
10
|
-
export declare function getMetadata(metadataKey:
|
|
24
|
+
export declare function getMetadata<K extends keyof MetadataMap>(metadataKey: K, target: CommonToken): MetadataMap[K] | undefined;
|
|
25
|
+
export declare function getMetadata(metadataKey: string, target: CommonToken): unknown | undefined;
|
package/dist/constants.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const KEYS: {
|
|
2
|
-
readonly INJECTED_PARAMS: "injected:params";
|
|
3
2
|
readonly INJECTED_PROPS: "injected:props";
|
|
4
3
|
readonly INJECT: "inject";
|
|
5
4
|
readonly SELF: "self";
|
|
@@ -19,10 +18,24 @@ export declare const BINDING: {
|
|
|
19
18
|
readonly ConstantValue: "ConstantValue";
|
|
20
19
|
readonly DynamicValue: "DynamicValue";
|
|
21
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* 错误消息模板
|
|
23
|
+
*
|
|
24
|
+
* 这些消息用于装饰器和 token 模块中的运行时错误检测,
|
|
25
|
+
* 与 errors/ 目录下的错误类无关(错误类有自己的消息前缀)。
|
|
26
|
+
*/
|
|
22
27
|
export declare const ERRORS: {
|
|
23
|
-
readonly POST_CONSTRUCT: "
|
|
24
|
-
readonly PRE_DESTROY: "
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
28
|
+
readonly POST_CONSTRUCT: "Multiple @PostConstruct decorators are not allowed in a single class.";
|
|
29
|
+
readonly PRE_DESTROY: "Multiple @PreDestroy decorators are not allowed in a single class.";
|
|
30
|
+
readonly INVALID_TOKEN: "@Inject or @LazyInject requires a valid token, but received null or undefined.";
|
|
31
|
+
readonly LAZY_INJECT_INVALID_TOKEN: "@LazyInject requires a valid token, but received null or undefined.";
|
|
27
32
|
};
|
|
28
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Object.hasOwn 的兼容性替代函数
|
|
35
|
+
* Object.hasOwn 在部分旧版浏览器和运行时中不可用(ES2022+),
|
|
36
|
+
* 此函数使用 Object.prototype.hasOwnProperty.call 实现相同语义。
|
|
37
|
+
*/
|
|
38
|
+
export declare function hasOwn(obj: object, key: PropertyKey): boolean;
|
|
39
|
+
export declare const UNINITIALIZED: unique symbol;
|
|
40
|
+
export type BindingType = (typeof BINDING)[keyof typeof BINDING];
|
|
41
|
+
export type StatusType = (typeof STATUS)[keyof typeof STATUS];
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const KEYS: {
|
|
2
|
-
readonly INJECTED_PARAMS: "injected:params";
|
|
3
2
|
readonly INJECTED_PROPS: "injected:props";
|
|
4
3
|
readonly INJECT: "inject";
|
|
5
4
|
readonly SELF: "self";
|
|
@@ -19,10 +18,24 @@ export declare const BINDING: {
|
|
|
19
18
|
readonly ConstantValue: "ConstantValue";
|
|
20
19
|
readonly DynamicValue: "DynamicValue";
|
|
21
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* 错误消息模板
|
|
23
|
+
*
|
|
24
|
+
* 这些消息用于装饰器和 token 模块中的运行时错误检测,
|
|
25
|
+
* 与 errors/ 目录下的错误类无关(错误类有自己的消息前缀)。
|
|
26
|
+
*/
|
|
22
27
|
export declare const ERRORS: {
|
|
23
|
-
readonly POST_CONSTRUCT: "
|
|
24
|
-
readonly PRE_DESTROY: "
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
28
|
+
readonly POST_CONSTRUCT: "Multiple @PostConstruct decorators are not allowed in a single class.";
|
|
29
|
+
readonly PRE_DESTROY: "Multiple @PreDestroy decorators are not allowed in a single class.";
|
|
30
|
+
readonly INVALID_TOKEN: "@Inject or @LazyInject requires a valid token, but received null or undefined.";
|
|
31
|
+
readonly LAZY_INJECT_INVALID_TOKEN: "@LazyInject requires a valid token, but received null or undefined.";
|
|
27
32
|
};
|
|
28
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Object.hasOwn 的兼容性替代函数
|
|
35
|
+
* Object.hasOwn 在部分旧版浏览器和运行时中不可用(ES2022+),
|
|
36
|
+
* 此函数使用 Object.prototype.hasOwnProperty.call 实现相同语义。
|
|
37
|
+
*/
|
|
38
|
+
export declare function hasOwn(obj: object, key: PropertyKey): boolean;
|
|
39
|
+
export declare const UNINITIALIZED: unique symbol;
|
|
40
|
+
export type BindingType = (typeof BINDING)[keyof typeof BINDING];
|
|
41
|
+
export type StatusType = (typeof STATUS)[keyof typeof STATUS];
|
package/dist/container.d.cts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Binding } from './binding';
|
|
2
2
|
import { Options, CommonToken, ActivationHandler, DeactivationHandler } from './interfaces';
|
|
3
3
|
export declare class Container {
|
|
4
|
-
static
|
|
4
|
+
static _instanceContainerMap: WeakMap<object, Container>;
|
|
5
|
+
static getContainerOf(instance: object): Container | undefined;
|
|
5
6
|
parent?: Container;
|
|
6
7
|
children?: Set<Container>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
_bindings: Map<CommonToken, Binding>;
|
|
9
|
+
_onActivationHandler?: ActivationHandler;
|
|
10
|
+
_onDeactivationHandler?: DeactivationHandler;
|
|
10
11
|
bind<T>(token: CommonToken<T>): Binding<T>;
|
|
11
12
|
unbind<T>(token: CommonToken<T>): void;
|
|
12
13
|
unbindAll(): void;
|
|
@@ -21,11 +22,14 @@ export declare class Container {
|
|
|
21
22
|
optional?: false;
|
|
22
23
|
}): T;
|
|
23
24
|
get<T>(token: CommonToken<T>, options?: Options<T>): T | void;
|
|
25
|
+
_resolveSkipSelf<T>(token: CommonToken<T>, options: Options<T>): T | void;
|
|
26
|
+
_resolveSelf<T>(token: CommonToken<T>, options: Options<T>): T | void;
|
|
27
|
+
_resolveDefault<T>(token: CommonToken<T>, options: Options<T>): T | void;
|
|
24
28
|
onActivation(handler: ActivationHandler): void;
|
|
25
29
|
onDeactivation(handler: DeactivationHandler): void;
|
|
26
30
|
activate<T>(input: T, token: CommonToken<T>): T;
|
|
27
31
|
deactivate<T>(binding: Binding<T>): void;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
_buildBinding<T>(token: CommonToken<T>): Binding<T>;
|
|
33
|
+
_getBinding<T>(token: CommonToken<T>): Binding<T>;
|
|
34
|
+
_checkBindingNotFoundError<T>(token: CommonToken, options: Options<T>): void;
|
|
31
35
|
}
|
package/dist/container.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Binding } from './binding';
|
|
2
2
|
import { Options, CommonToken, ActivationHandler, DeactivationHandler } from './interfaces';
|
|
3
3
|
export declare class Container {
|
|
4
|
-
static
|
|
4
|
+
static _instanceContainerMap: WeakMap<object, Container>;
|
|
5
|
+
static getContainerOf(instance: object): Container | undefined;
|
|
5
6
|
parent?: Container;
|
|
6
7
|
children?: Set<Container>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
_bindings: Map<CommonToken, Binding>;
|
|
9
|
+
_onActivationHandler?: ActivationHandler;
|
|
10
|
+
_onDeactivationHandler?: DeactivationHandler;
|
|
10
11
|
bind<T>(token: CommonToken<T>): Binding<T>;
|
|
11
12
|
unbind<T>(token: CommonToken<T>): void;
|
|
12
13
|
unbindAll(): void;
|
|
@@ -21,11 +22,14 @@ export declare class Container {
|
|
|
21
22
|
optional?: false;
|
|
22
23
|
}): T;
|
|
23
24
|
get<T>(token: CommonToken<T>, options?: Options<T>): T | void;
|
|
25
|
+
_resolveSkipSelf<T>(token: CommonToken<T>, options: Options<T>): T | void;
|
|
26
|
+
_resolveSelf<T>(token: CommonToken<T>, options: Options<T>): T | void;
|
|
27
|
+
_resolveDefault<T>(token: CommonToken<T>, options: Options<T>): T | void;
|
|
24
28
|
onActivation(handler: ActivationHandler): void;
|
|
25
29
|
onDeactivation(handler: DeactivationHandler): void;
|
|
26
30
|
activate<T>(input: T, token: CommonToken<T>): T;
|
|
27
31
|
deactivate<T>(binding: Binding<T>): void;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
_buildBinding<T>(token: CommonToken<T>): Binding<T>;
|
|
33
|
+
_getBinding<T>(token: CommonToken<T>): Binding<T>;
|
|
34
|
+
_checkBindingNotFoundError<T>(token: CommonToken, options: Options<T>): void;
|
|
31
35
|
}
|
package/dist/decorator.d.cts
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Container } from './container';
|
|
2
|
+
import { InjectFunction, GenericToken } from './interfaces';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* 装饰器的通用逻辑就是通过cachemap记录到全局的WeakMap中
|
|
4
|
+
* 创建属性装饰器的高阶函数(Stage 3 Field Decorator)
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* 通过 context.addInitializer 在实例化时获取构造函数引用,
|
|
7
|
+
* 并将装饰器元数据存储到 CacheMap 的 INJECTED_PROPS 分区。
|
|
8
|
+
*
|
|
9
|
+
* @param decoratorKey 装饰器名称(如 'inject'、'self' 等)
|
|
10
|
+
* @param defaultValue 装饰器的默认参数值
|
|
11
|
+
* @returns 装饰器函数
|
|
9
12
|
*/
|
|
10
|
-
declare function createDecorator(decoratorKey: string, defaultValue?: any): (decoratorValue?: any) => (
|
|
13
|
+
declare function createDecorator(decoratorKey: string, defaultValue?: any): (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
11
14
|
export declare const Inject: InjectFunction<ReturnType<typeof createDecorator>>;
|
|
12
|
-
export declare const Self: (decoratorValue?: any) => (
|
|
13
|
-
export declare const SkipSelf: (decoratorValue?: any) => (
|
|
14
|
-
export declare const Optional: (decoratorValue?: any) => (
|
|
15
|
-
export declare const PostConstruct: (metaValue?: any) => (
|
|
16
|
-
export declare const PreDestroy: (metaValue?: any) => (
|
|
17
|
-
|
|
15
|
+
export declare const Self: (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
16
|
+
export declare const SkipSelf: (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
17
|
+
export declare const Optional: (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
18
|
+
export declare const PostConstruct: (metaValue?: any) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
19
|
+
export declare const PreDestroy: (metaValue?: any) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
20
|
+
/**
|
|
21
|
+
* 延迟注入装饰器,Stage 3 Field Decorator 签名。
|
|
22
|
+
* 通过 context.addInitializer 在实例上定义 getter/setter,
|
|
23
|
+
* 首次访问属性时才从容器中解析依赖。
|
|
24
|
+
*
|
|
25
|
+
* @param token 要解析的服务 Token
|
|
26
|
+
* @param container 可选,显式指定容器。未传入时通过 Container.getContainerOf 查找,
|
|
27
|
+
* 仅支持 Instance 类型绑定。toConstantValue / toDynamicValue 场景需显式传入。
|
|
28
|
+
*/
|
|
29
|
+
export declare function LazyInject<T>(token: GenericToken<T>, container?: Container): (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 创建绑定到指定容器的延迟注入装饰器工厂。
|
|
32
|
+
*/
|
|
33
|
+
export declare function createLazyInject(container: Container): <T>(token: GenericToken<T>) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
34
|
+
export declare function decorate(decorator: any, target: any, key: string): void;
|
|
18
35
|
export {};
|
package/dist/decorator.d.ts
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Container } from './container';
|
|
2
|
+
import { InjectFunction, GenericToken } from './interfaces';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* 装饰器的通用逻辑就是通过cachemap记录到全局的WeakMap中
|
|
4
|
+
* 创建属性装饰器的高阶函数(Stage 3 Field Decorator)
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* 通过 context.addInitializer 在实例化时获取构造函数引用,
|
|
7
|
+
* 并将装饰器元数据存储到 CacheMap 的 INJECTED_PROPS 分区。
|
|
8
|
+
*
|
|
9
|
+
* @param decoratorKey 装饰器名称(如 'inject'、'self' 等)
|
|
10
|
+
* @param defaultValue 装饰器的默认参数值
|
|
11
|
+
* @returns 装饰器函数
|
|
9
12
|
*/
|
|
10
|
-
declare function createDecorator(decoratorKey: string, defaultValue?: any): (decoratorValue?: any) => (
|
|
13
|
+
declare function createDecorator(decoratorKey: string, defaultValue?: any): (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
11
14
|
export declare const Inject: InjectFunction<ReturnType<typeof createDecorator>>;
|
|
12
|
-
export declare const Self: (decoratorValue?: any) => (
|
|
13
|
-
export declare const SkipSelf: (decoratorValue?: any) => (
|
|
14
|
-
export declare const Optional: (decoratorValue?: any) => (
|
|
15
|
-
export declare const PostConstruct: (metaValue?: any) => (
|
|
16
|
-
export declare const PreDestroy: (metaValue?: any) => (
|
|
17
|
-
|
|
15
|
+
export declare const Self: (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
16
|
+
export declare const SkipSelf: (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
17
|
+
export declare const Optional: (decoratorValue?: any) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
18
|
+
export declare const PostConstruct: (metaValue?: any) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
19
|
+
export declare const PreDestroy: (metaValue?: any) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
20
|
+
/**
|
|
21
|
+
* 延迟注入装饰器,Stage 3 Field Decorator 签名。
|
|
22
|
+
* 通过 context.addInitializer 在实例上定义 getter/setter,
|
|
23
|
+
* 首次访问属性时才从容器中解析依赖。
|
|
24
|
+
*
|
|
25
|
+
* @param token 要解析的服务 Token
|
|
26
|
+
* @param container 可选,显式指定容器。未传入时通过 Container.getContainerOf 查找,
|
|
27
|
+
* 仅支持 Instance 类型绑定。toConstantValue / toDynamicValue 场景需显式传入。
|
|
28
|
+
*/
|
|
29
|
+
export declare function LazyInject<T>(token: GenericToken<T>, container?: Container): (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 创建绑定到指定容器的延迟注入装饰器工厂。
|
|
32
|
+
*/
|
|
33
|
+
export declare function createLazyInject(container: Container): <T>(token: GenericToken<T>) => (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
34
|
+
export declare function decorate(decorator: any, target: any, key: string): void;
|
|
18
35
|
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var F=Object.defineProperty;var x=(n,t,e)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var r=(n,t,e)=>x(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l={INJECTED_PROPS:"injected:props",INJECT:"inject",SELF:"self",SKIP_SELF:"skipSelf",OPTIONAL:"optional",POST_CONSTRUCT:"postConstruct",PRE_DESTROY:"preDestroy"},f={DEFAULT:"default",INITING:"initing",ACTIVATED:"activated"},d={Invalid:"Invalid",Instance:"Instance",ConstantValue:"ConstantValue",DynamicValue:"DynamicValue"},T={POST_CONSTRUCT:"Multiple @PostConstruct decorators are not allowed in a single class.",PRE_DESTROY:"Multiple @PreDestroy decorators are not allowed in a single class.",INVALID_TOKEN:"@Inject or @LazyInject requires a valid token, but received null or undefined.",LAZY_INJECT_INVALID_TOKEN:"@LazyInject requires a valid token, but received null or undefined."};function O(n,t){return Object.prototype.hasOwnProperty.call(n,t)}const N=Symbol("UNINITIALIZED"),A=new WeakMap;function U(n){return typeof n=="function"&&Object.getPrototypeOf(n)!==Function.prototype}function V(n,t,e){const i=A.get(e)||{};i[n]=t,A.set(e,i)}function w(n,t){return(A.get(t)||{})[n]}function y(n,t){const e=w(n,t);if(!U(t))return e;const i=y(n,Object.getPrototypeOf(t));if(i||e)return{...i||{},...e||{}}}class J{constructor(t){r(this,"name");this.name=t}}class R{constructor(t){r(this,"_callback");this._callback=t}resolve(){return this._callback()}}function b(n){if(!n)throw new Error(T.INVALID_TOKEN);return n instanceof R?n.resolve():n}class I extends Error{constructor(e,i){const s=(i==null?void 0:i.name)||"<unknown token>";super(`${e}${s}`);r(this,"token");this.name=this.constructor.name,this.token=i}}class m extends I{constructor(t){super("");const e=[];let i=t;for(;i&&i.token;)e.push(i.token),i=i.parent;const s=e.reverse().map(o=>o.name||"<anonymous>").join(" --> ");this.message=`Circular dependency found: ${s}`}}class j extends I{constructor(t){super("Invalid binding: ",t)}}class L extends m{constructor(t){super(t),this.name="CircularDependencyError inside @PostConstruct"}}const E=class E{constructor(t,e){r(this,"container");r(this,"context");r(this,"token");r(this,"type",d.Invalid);r(this,"status",f.DEFAULT);r(this,"classValue");r(this,"constantValue");r(this,"dynamicValue");r(this,"cache");r(this,"postConstructResult",N);r(this,"onActivationHandler");r(this,"onDeactivationHandler");this.container=e,this.context={container:this.container},this.token=t}onActivation(t){this.onActivationHandler=t}onDeactivation(t){this.onDeactivationHandler=t}activate(t){const e=this.onActivationHandler?this.onActivationHandler(this.context,t):t;return this.container.activate(e,this.token)}deactivate(){this.onDeactivationHandler&&this.onDeactivationHandler(this.cache)}to(t){return this.type=d.Instance,this.classValue=t,this}toSelf(){return this.to(this.token)}toConstantValue(t){return this.type=d.ConstantValue,this.constantValue=t,this}toDynamicValue(t){return this.type=d.DynamicValue,this.dynamicValue=t,this}toService(t){return this.toDynamicValue(e=>e.container.get(t,{parent:{token:this.token}}))}get(t){if(f.INITING===this.status)throw new m(t);if(f.ACTIVATED===this.status)return this.cache;const e=E._resolvers[this.type];if(e)return this[e](t);throw new j(this.token)}_getAwaitBindings(t,e){return e===!0?t:Array.isArray(e)?t.filter(i=>e.includes(i.token)):typeof e=="function"?t.filter(e):[]}_postConstruct(t,e){if(d.Instance===this.type){const{key:i,value:s}=y(l.POST_CONSTRUCT,this.classValue)||{};if(i)if(s){const o=e.filter(c=>d.Instance===(c==null?void 0:c.type)),a=this._getAwaitBindings(o,s);for(const c of a)if(c&&c.postConstructResult===N)throw new L({token:c.token,parent:t});const u=a.map(c=>c.postConstructResult);this.postConstructResult=Promise.all(u).then(()=>this._execute(i))}else this.postConstructResult=this._execute(i);else this.postConstructResult=void 0}}preDestroy(){if(d.Instance===this.type){const{key:t}=y(l.PRE_DESTROY,this.classValue)||{};t&&this._execute(t)}_._instanceContainerMap.delete(this.cache),this.container=null,this.context=null,this.classValue=void 0,this.constantValue=void 0,this.dynamicValue=void 0,this.cache=void 0,this.postConstructResult=N,this.onActivationHandler=void 0,this.onDeactivationHandler=void 0}_execute(t){const e=this.cache[t];return e==null?void 0:e.call(this.cache)}_resolveInstanceValue(t){this.status=f.INITING;const e=this._createInstance();this.cache=this.activate(e),this.status=f.ACTIVATED,this._registerInstance();const{properties:i,bindings:s}=this._getInjectProperties(t);return this._injectProperties(i),this._postConstruct(t,s),this.cache}_createInstance(){const t=this.classValue;return new t}_registerInstance(){_._instanceContainerMap.set(this.cache,this.container)}_injectProperties(t){Object.assign(this.cache,t)}_resolveConstantValue(){return this.status=f.INITING,this.cache=this.activate(this.constantValue),this.status=f.ACTIVATED,this.cache}_resolveDynamicValue(){this.status=f.INITING;const t=this.dynamicValue(this.context);return this.cache=this.activate(t),this.status=f.ACTIVATED,this.cache}_getInjectProperties(t){const e=y(l.INJECTED_PROPS,this.classValue)||{},i=Object.keys(e),s=Object.create(null),o=[];for(let a=0;a<i.length;a++){const u=i[a],c=e[u],{inject:p,...v}=c;v.parent=t;const h=this.container.get(b(p),v);h===void 0&&c.optional||(s[u]=h),o.push(v.binding)}return{properties:s,bindings:o}}};r(E,"_resolvers",{[d.Instance]:"_resolveInstanceValue",[d.ConstantValue]:"_resolveConstantValue",[d.DynamicValue]:"_resolveDynamicValue"});let C=E;class k extends I{constructor(t){super("No matching binding found for token: ",t)}}class B extends I{constructor(t){super("Cannot bind token multiple times: ",t)}}const g=class g{constructor(){r(this,"parent");r(this,"children");r(this,"_bindings",new Map);r(this,"_onActivationHandler");r(this,"_onDeactivationHandler")}static getContainerOf(t){return g._instanceContainerMap.get(t)}bind(t){if(this._bindings.has(t))throw new B(t);const e=this._buildBinding(t);return this._bindings.set(t,e),e}unbind(t){if(this._bindings.has(t)){const e=this._getBinding(t);this.deactivate(e),e.deactivate(),e.preDestroy(),this._bindings.delete(t)}}unbindAll(){const t=Array.from(this._bindings.keys());for(const e of t)this.unbind(e)}isCurrentBound(t){return this._bindings.has(t)}isBound(t){return this.isCurrentBound(t)||!!this.parent&&this.parent.isBound(t)}createChild(){const t=new g;return t.parent=this,this.children||(this.children=new Set),this.children.add(t),t}destroy(){var t,e;if(this.children){const i=Array.from(this.children);for(const s of i)s.destroy()}this.unbindAll(),this._bindings.clear(),(e=(t=this.parent)==null?void 0:t.children)==null||e.delete(this),this.parent=void 0,this.children=void 0,this._onActivationHandler=void 0,this._onDeactivationHandler=void 0}get(t,e={}){return e.skipSelf?this._resolveSkipSelf(t,e):e.self?this._resolveSelf(t,e):this._resolveDefault(t,e)}_resolveSkipSelf(t,e){return this.parent?(e.skipSelf=!1,this.parent.get(t,e)):this._checkBindingNotFoundError(t,e)}_resolveSelf(t,e){const i=this._getBinding(t);return i?(e.token=t,e.binding=i,i.get(e)):this._checkBindingNotFoundError(t,e)}_resolveDefault(t,e){const i=this._getBinding(t);return i?(e.token=t,e.binding=i,i.get(e)):this.parent?this.parent.get(t,e):this._checkBindingNotFoundError(t,e)}onActivation(t){this._onActivationHandler=t}onDeactivation(t){this._onDeactivationHandler=t}activate(t,e){return this._onActivationHandler?this._onActivationHandler({container:this},t,e):t}deactivate(t){this._onDeactivationHandler&&this._onDeactivationHandler(t.cache,t.token)}_buildBinding(t){return new C(t,this)}_getBinding(t){return this._bindings.get(t)}_checkBindingNotFoundError(t,e){if(!e.optional)throw new k(t)}};r(g,"_instanceContainerMap",new WeakMap);let _=g;class H extends I{constructor(t,e){super(`@LazyInject(${t==null?void 0:t.name}) in class ${e.name} requires a registered container but none was found. Token: `,t)}}function D(n,t){return function(e){return function(i,s){s.addInitializer(function(){const o=this.constructor,a=s.name,u=w(l.INJECTED_PROPS,o)||{},c=u[a]||{};c[n]=e===void 0?t:e,u[a]=c,V(l.INJECTED_PROPS,u,o)})}}}function M(n,t){return e=>(i,s)=>{const o=s.name,a=s.metadata;if(O(a,n))throw new Error(t);a[n]=!0,s.addInitializer(function(){const u=this.constructor;V(n,{key:o,value:e},u)})}}const Y=D(l.INJECT),G=D(l.SELF,!0),K=D(l.SKIP_SELF,!0),$=D(l.OPTIONAL,!0),Z=M(l.POST_CONSTRUCT,T.POST_CONSTRUCT),q=M(l.PRE_DESTROY,T.PRE_DESTROY);function W(n,t,e,i){if(e==null)throw new Error(T.LAZY_INJECT_INVALID_TOKEN);const s=Symbol.for(t);Object.defineProperty(n,t,{configurable:!0,enumerable:!0,get(){if(!O(n,s)){const o=i||_.getContainerOf(n),a=n.constructor;if(!o)throw new H(b(e),a);n[s]=o.get(b(e),{parent:{token:a}})}return n[s]},set(o){n[s]=o}})}function z(n,t){return function(e,i){const s=i.name;i.addInitializer(function(){W(this,s,n,t)})}}function Q(n){return function(t){return z(t,n)}}const S=Symbol("decorate.metadata");function X(n,t,e){const i=Array.isArray(n)?n:[n],s=t.prototype,o=typeof s[e]=="function",a=[];O(t,S)||(t[S]={});const u=t[S],c={kind:o?"method":"field",name:e,static:!1,private:!1,addInitializer(h){a.push(h)},metadata:u};let p=o?s[e]:void 0;for(let h=i.length-1;h>=0;h--){const P=i[h](p,c);o&&typeof P=="function"&&(p=P)}o&&p!==s[e]&&(s[e]=p);const v=Object.create(s);for(const h of a)h.call(v)}exports.BaseError=I;exports.Binding=C;exports.BindingNotFoundError=k;exports.BindingNotValidError=j;exports.CircularDependencyError=m;exports.Container=_;exports.ContainerNotFoundError=H;exports.DuplicateBindingError=B;exports.Inject=Y;exports.LazyInject=z;exports.LazyToken=R;exports.Optional=$;exports.PostConstruct=Z;exports.PostConstructError=L;exports.PreDestroy=q;exports.Self=G;exports.SkipSelf=K;exports.Token=J;exports.createLazyInject=Q;exports.decorate=X;
|