@kaokei/di 3.0.5 → 3.0.7

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.
@@ -1,13 +1,5 @@
1
- import { CommonToken, META_KEY_INJECTED_PARAMS, META_KEY_INJECTED_PROPS, META_KEY_POST_CONSTRUCT, META_KEY_PRE_DESTROY, META_VALUE_INJECTED_PARAMS, META_VALUE_INJECTED_PROPS, META_VALUE_POST_CONSTRUCT, META_VALUE_PRE_DESTROY } from './interfaces';
2
- export declare function defineMetadata(metadataKey: META_KEY_INJECTED_PARAMS, metadataValue: META_VALUE_INJECTED_PARAMS, target: CommonToken): void;
3
- export declare function defineMetadata(metadataKey: META_KEY_INJECTED_PROPS, metadataValue: META_VALUE_INJECTED_PROPS, target: CommonToken): void;
4
- export declare function defineMetadata(metadataKey: META_KEY_POST_CONSTRUCT, metadataValue: META_VALUE_POST_CONSTRUCT, target: CommonToken): void;
5
- export declare function defineMetadata(metadataKey: META_KEY_PRE_DESTROY, metadataValue: META_VALUE_PRE_DESTROY, target: CommonToken): void;
1
+ import { CommonToken } from './interfaces';
6
2
  export declare function defineMetadata(metadataKey: string, metadataValue: any, target: CommonToken): void;
7
- export declare function getOwnMetadata(metadataKey: META_KEY_INJECTED_PARAMS, target: CommonToken): META_VALUE_INJECTED_PARAMS | undefined;
8
- export declare function getOwnMetadata(metadataKey: META_KEY_INJECTED_PROPS, target: CommonToken): META_VALUE_INJECTED_PROPS | undefined;
9
- export declare function getOwnMetadata(metadataKey: META_KEY_POST_CONSTRUCT, target: CommonToken): META_VALUE_POST_CONSTRUCT | undefined;
10
- export declare function getOwnMetadata(metadataKey: META_KEY_PRE_DESTROY, target: CommonToken): META_VALUE_PRE_DESTROY | undefined;
11
3
  export declare function getOwnMetadata(metadataKey: string, target: CommonToken): any | undefined;
12
4
  /**
13
5
  * 使用hasParentClass判断当前target有没有父类
@@ -15,7 +7,4 @@ export declare function getOwnMetadata(metadataKey: string, target: CommonToken)
15
7
  * 如果有父类,那么需要合并getOwnMetadata(target)和getMetadata(target的父类)
16
8
  * 不支持META_KEY_INJECTED_PARAMS作为metadataKey
17
9
  */
18
- export declare function getMetadata(metadataKey: META_KEY_INJECTED_PROPS, target: CommonToken): META_VALUE_INJECTED_PROPS | undefined;
19
- export declare function getMetadata(metadataKey: META_KEY_POST_CONSTRUCT, target: CommonToken): META_VALUE_POST_CONSTRUCT | undefined;
20
- export declare function getMetadata(metadataKey: META_KEY_PRE_DESTROY, target: CommonToken): META_VALUE_PRE_DESTROY | undefined;
21
10
  export declare function getMetadata(metadataKey: string, target: CommonToken): any | undefined;
@@ -1,13 +1,5 @@
1
- import { CommonToken, META_KEY_INJECTED_PARAMS, META_KEY_INJECTED_PROPS, META_KEY_POST_CONSTRUCT, META_KEY_PRE_DESTROY, META_VALUE_INJECTED_PARAMS, META_VALUE_INJECTED_PROPS, META_VALUE_POST_CONSTRUCT, META_VALUE_PRE_DESTROY } from './interfaces';
2
- export declare function defineMetadata(metadataKey: META_KEY_INJECTED_PARAMS, metadataValue: META_VALUE_INJECTED_PARAMS, target: CommonToken): void;
3
- export declare function defineMetadata(metadataKey: META_KEY_INJECTED_PROPS, metadataValue: META_VALUE_INJECTED_PROPS, target: CommonToken): void;
4
- export declare function defineMetadata(metadataKey: META_KEY_POST_CONSTRUCT, metadataValue: META_VALUE_POST_CONSTRUCT, target: CommonToken): void;
5
- export declare function defineMetadata(metadataKey: META_KEY_PRE_DESTROY, metadataValue: META_VALUE_PRE_DESTROY, target: CommonToken): void;
1
+ import { CommonToken } from './interfaces';
6
2
  export declare function defineMetadata(metadataKey: string, metadataValue: any, target: CommonToken): void;
7
- export declare function getOwnMetadata(metadataKey: META_KEY_INJECTED_PARAMS, target: CommonToken): META_VALUE_INJECTED_PARAMS | undefined;
8
- export declare function getOwnMetadata(metadataKey: META_KEY_INJECTED_PROPS, target: CommonToken): META_VALUE_INJECTED_PROPS | undefined;
9
- export declare function getOwnMetadata(metadataKey: META_KEY_POST_CONSTRUCT, target: CommonToken): META_VALUE_POST_CONSTRUCT | undefined;
10
- export declare function getOwnMetadata(metadataKey: META_KEY_PRE_DESTROY, target: CommonToken): META_VALUE_PRE_DESTROY | undefined;
11
3
  export declare function getOwnMetadata(metadataKey: string, target: CommonToken): any | undefined;
12
4
  /**
13
5
  * 使用hasParentClass判断当前target有没有父类
@@ -15,7 +7,4 @@ export declare function getOwnMetadata(metadataKey: string, target: CommonToken)
15
7
  * 如果有父类,那么需要合并getOwnMetadata(target)和getMetadata(target的父类)
16
8
  * 不支持META_KEY_INJECTED_PARAMS作为metadataKey
17
9
  */
18
- export declare function getMetadata(metadataKey: META_KEY_INJECTED_PROPS, target: CommonToken): META_VALUE_INJECTED_PROPS | undefined;
19
- export declare function getMetadata(metadataKey: META_KEY_POST_CONSTRUCT, target: CommonToken): META_VALUE_POST_CONSTRUCT | undefined;
20
- export declare function getMetadata(metadataKey: META_KEY_PRE_DESTROY, target: CommonToken): META_VALUE_PRE_DESTROY | undefined;
21
10
  export declare function getMetadata(metadataKey: string, target: CommonToken): any | undefined;
@@ -1,7 +1,9 @@
1
1
  import { Binding } from './binding';
2
2
  import { Options, CommonToken, ActivationHandler, DeactivationHandler } from './interfaces';
3
3
  export declare class Container {
4
+ static map: WeakMap<any, Container>;
4
5
  parent?: Container;
6
+ children?: Set<Container>;
5
7
  private bindings;
6
8
  private onActivationHandler?;
7
9
  private onDeactivationHandler?;
@@ -11,6 +13,7 @@ export declare class Container {
11
13
  isCurrentBound<T>(token: CommonToken<T>): boolean;
12
14
  isBound<T>(token: CommonToken<T>): boolean;
13
15
  createChild(): Container;
16
+ destroy(): void;
14
17
  get<T>(token: CommonToken<T>, options: Options<T> & {
15
18
  optional: true;
16
19
  }): T | void;
@@ -26,4 +29,3 @@ export declare class Container {
26
29
  private getBinding;
27
30
  private checkBindingNotFoundError;
28
31
  }
29
- export declare const CONTAINER_MAP: WeakMap<any, Container>;
@@ -1,7 +1,9 @@
1
1
  import { Binding } from './binding';
2
2
  import { Options, CommonToken, ActivationHandler, DeactivationHandler } from './interfaces';
3
3
  export declare class Container {
4
+ static map: WeakMap<any, Container>;
4
5
  parent?: Container;
6
+ children?: Set<Container>;
5
7
  private bindings;
6
8
  private onActivationHandler?;
7
9
  private onDeactivationHandler?;
@@ -11,6 +13,7 @@ export declare class Container {
11
13
  isCurrentBound<T>(token: CommonToken<T>): boolean;
12
14
  isBound<T>(token: CommonToken<T>): boolean;
13
15
  createChild(): Container;
16
+ destroy(): void;
14
17
  get<T>(token: CommonToken<T>, options: Options<T> & {
15
18
  optional: true;
16
19
  }): T | void;
@@ -26,4 +29,3 @@ export declare class Container {
26
29
  private getBinding;
27
30
  private checkBindingNotFoundError;
28
31
  }
29
- export declare const CONTAINER_MAP: WeakMap<any, Container>;
@@ -12,7 +12,7 @@ export declare const Inject: InjectFunction<ReturnType<typeof createDecorator>>;
12
12
  export declare const Self: (decoratorValue?: any) => (target: any, targetKey?: string, index?: number) => void;
13
13
  export declare const SkipSelf: (decoratorValue?: any) => (target: any, targetKey?: string, index?: number) => void;
14
14
  export declare const Optional: (decoratorValue?: any) => (target: any, targetKey?: string, index?: number) => void;
15
- export declare const PostConstruct: (metaValue: import('./interfaces').PostConstructParam) => (target: any, propertyKey: string) => void;
16
- export declare const PreDestroy: (metaValue: void) => (target: any, propertyKey: string) => void;
15
+ export declare const PostConstruct: (metaValue: any) => (target: any, propertyKey: string) => void;
16
+ export declare const PreDestroy: (metaValue: any) => (target: any, propertyKey: string) => void;
17
17
  export declare function decorate(decorator: any, target: any, key: number | string): void;
18
18
  export {};
@@ -12,7 +12,7 @@ export declare const Inject: InjectFunction<ReturnType<typeof createDecorator>>;
12
12
  export declare const Self: (decoratorValue?: any) => (target: any, targetKey?: string, index?: number) => void;
13
13
  export declare const SkipSelf: (decoratorValue?: any) => (target: any, targetKey?: string, index?: number) => void;
14
14
  export declare const Optional: (decoratorValue?: any) => (target: any, targetKey?: string, index?: number) => void;
15
- export declare const PostConstruct: (metaValue: import('./interfaces').PostConstructParam) => (target: any, propertyKey: string) => void;
16
- export declare const PreDestroy: (metaValue: void) => (target: any, propertyKey: string) => void;
15
+ export declare const PostConstruct: (metaValue: any) => (target: any, propertyKey: string) => void;
16
+ export declare const PreDestroy: (metaValue: any) => (target: any, propertyKey: string) => void;
17
17
  export declare function decorate(decorator: any, target: any, key: number | string): void;
18
18
  export {};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var _=(n,t,e)=>t in n?w(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var a=(n,t,e)=>_(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h={INJECTED_PARAMS:"injected:params",INJECTED_PROPS:"injected:props",INJECT:"inject",SELF:"self",SKIP_SELF:"skipSelf",OPTIONAL:"optional",POST_CONSTRUCT:"postConstruct",PRE_DESTROY:"preDestroy"},p={DEFAULT:"default",INITING:"initing",ACTIVATED:"activated"},d={Invalid:"Invalid",Instance:"Instance",ConstantValue:"ConstantValue",DynamicValue:"DynamicValue"},C={POST_CONSTRUCT:"Cannot apply @PostConstruct decorator multiple times in the same class.",PRE_DESTROY:"Cannot apply @PreDestroy decorator multiple times in the same class.",MISS_INJECT:"Expected a @Inject decorator to explicitly specify the token.",MISS_CONTAINER:"@LazyInject decorator cannot find the corresponding container."},A=Symbol(),S=new WeakMap;function M(n){return typeof n=="function"&&Object.getPrototypeOf(n)!==Function.prototype}function D(n,t,e){const s=S.get(e)||{};s[n]=t,S.set(e,s)}function I(n,t){return(S.get(t)||{})[n]}function g(n,t){const e=I(n,t);if(!M(t))return e;const s=g(n,Object.getPrototypeOf(t));if(s||e)return{...s||{},...e||{}}}class j{constructor(t){a(this,"_","");a(this,"name");this.name=t}}class O{constructor(t){a(this,"callback");this.callback=t}resolve(){return this.callback()}}function v(n){if(!n)throw new Error(C.MISS_INJECT);return n instanceof O?n.resolve():n}class T extends Error{constructor(t,e){super(),this.name=this.constructor.name,this.message=`${t}${e==null?void 0:e.name}`}}class b extends T{constructor(t){super("");const e=[];let s=t;for(;s&&s.token;)e.push(s.token),s=s.parent;const i=e.reverse().map(o=>o.name).join(" --> ");this.message=`Circular dependency found: ${i}`}}class B extends T{constructor(t){super("Invalid binding: ",t)}}class k extends b{constructor(t){super(t),this.name="CircularDependencyError inside @PostConstruct"}}class L{constructor(t,e){a(this,"container");a(this,"context");a(this,"token");a(this,"type",d.Invalid);a(this,"status",p.DEFAULT);a(this,"classValue");a(this,"constantValue");a(this,"dynamicValue");a(this,"cache");a(this,"postConstructResult",A);a(this,"onActivationHandler");a(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(p.INITING===this.status)throw new b(t);if(p.ACTIVATED===this.status)return this.cache;if(d.Instance===this.type)return this.resolveInstanceValue(t);if(d.ConstantValue===this.type)return this.resolveConstantValue();if(d.DynamicValue===this.type)return this.resolveDynamicValue();throw new B(this.token)}getAwaitBindings(t,e){return e===!0?t:Array.isArray(e)?t.filter(s=>e.includes(s.token)):typeof e=="function"?t.filter(e):[]}postConstruct(t,e,s){if(d.Instance===this.type){const{key:i,value:o}=g(h.POST_CONSTRUCT,this.classValue)||{};if(i)if(o){const r=[...e,...s].filter(u=>d.Instance===(u==null?void 0:u.type)),c=this.getAwaitBindings(r,o);for(const u of c)if(u&&u.postConstructResult===A)throw new k({token:u.token,parent:t});const l=c.map(u=>u.postConstructResult);this.postConstructResult=Promise.all(l).then(()=>this.execute(i))}else this.postConstructResult=this.execute(i);else this.postConstructResult=void 0}}preDestroy(){if(d.Instance===this.type){const{key:t}=g(h.PRE_DESTROY,this.classValue)||{};if(t)return this.execute(t)}this.container=null,this.context=null}execute(t){const e=this.cache[t];return e==null?void 0:e.call(this.cache)}resolveInstanceValue(t){this.status=p.INITING;const e=this.classValue,[s,i]=this.getConstructorParameters(t),o=new e(...s);this.cache=this.activate(o),this.status=p.ACTIVATED,P.set(this.cache,this.container);const[r,c]=this.getInjectProperties(t);return Object.assign(this.cache,r),this.postConstruct(t,i,c),this.cache}resolveConstantValue(){return this.status=p.INITING,this.cache=this.activate(this.constantValue),this.status=p.ACTIVATED,this.cache}resolveDynamicValue(){this.status=p.INITING;const t=this.dynamicValue.call(this,this.context);return this.cache=this.activate(t),this.status=p.ACTIVATED,this.cache}getConstructorParameters(t){const e=I(h.INJECTED_PARAMS,this.classValue)||[],s=[],i=[];for(let o=0;o<e.length;o++){const r=e[o],{inject:c,...l}=r;l.parent=t;const u=this.container.get(v(c),l);s.push(u),i.push(l.binding)}return[s,i]}getInjectProperties(t){const e=g(h.INJECTED_PROPS,this.classValue)||{},s=Object.keys(e),i=Object.create(null),o=[];for(let r=0;r<s.length;r++){const c=s[r],l=e[c],{inject:u,...f}=l;f.parent=t;const y=this.container.get(v(u),f);y===void 0&&l.optional||(i[c]=y),o.push(f.binding)}return[i,o]}}class x extends T{constructor(t){super("No matching binding found for token: ",t)}}class H extends T{constructor(t){super("Cannot bind token multiple times: ",t)}}class m{constructor(){a(this,"parent");a(this,"bindings",new Map);a(this,"onActivationHandler");a(this,"onDeactivationHandler")}bind(t){if(this.bindings.has(t))throw new H(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.preDestroy(),this.bindings.delete(t)}}unbindAll(){this.bindings.forEach(t=>{this.unbind(t.token)})}isCurrentBound(t){return this.bindings.has(t)}isBound(t){return this.isCurrentBound(t)||!!this.parent&&this.parent.isBound(t)}createChild(){const t=new m;return t.parent=this,t}get(t,e={}){const s=this.getBinding(t);if(e.skipSelf){if(this.parent)return e.skipSelf=!1,this.parent.get(t,e)}else if(e.self||s){if(s)return e.token=t,e.binding=s,s.get(e)}else if(this.parent)return this.parent.get(t,e);return 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),t.deactivate()}buildBinding(t){return new L(t,this)}getBinding(t){return this.bindings.get(t)}checkBindingNotFoundError(t,e){if(!e.optional)throw new x(t)}}const P=new WeakMap;function E(n,t){return function(e){return function(s,i,o){const r=typeof o=="number",c=r?s:s.constructor,l=r?o:i,u=r?h.INJECTED_PARAMS:h.INJECTED_PROPS,f=r?I(u,c)||[]:g(u,c)||{},y=f[l]||{};y[n]=e===void 0?t:e,f[l]=y,D(u,f,c)}}}function V(n,t){return e=>(s,i)=>{if(I(n,s.constructor))throw new Error(t);D(n,{key:i,value:e},s.constructor)}}const F=E(h.INJECT),J=E(h.SELF,!0),U=E(h.SKIP_SELF,!0),z=E(h.OPTIONAL,!0),G=V(h.POST_CONSTRUCT,C.POST_CONSTRUCT),Y=V(h.PRE_DESTROY,C.PRE_DESTROY);function N(n,t,e,s){for(let i=n.length-1;i>=0;i--)n[i](t,e,s)}function K(n,t,e){n=Array.isArray(n)?n:[n],typeof e=="number"?N(n,t,void 0,e):typeof e=="string"&&N(n,t.prototype,e)}function $(n,t,e,s){function i(){const r=Symbol.for(t);if(!this.hasOwnProperty(r)){const c=s||P.get(this),l=this.constructor;if(!c)throw new Error(`${C.MISS_CONTAINER} ${l.name}`);this[r]=c.get(v(e),{parent:{token:l}})}return this[r]}function o(r){const c=Symbol.for(t);this[c]=r}Object.defineProperty(n,t,{configurable:!0,enumerable:!0,get:i,set:o})}function R(n,t){return function(e,s){$(e,s,n,t)}}function W(n){return function(t){return R(t,n)}}exports.CONTAINER_MAP=P;exports.Container=m;exports.Inject=F;exports.LazyInject=R;exports.LazyToken=O;exports.Optional=z;exports.PostConstruct=G;exports.PreDestroy=Y;exports.Self=J;exports.SkipSelf=U;exports.Token=j;exports.createLazyInject=W;exports.decorate=K;exports.defineMetadata=D;exports.getMetadata=g;exports.getOwnMetadata=I;
1
+ "use strict";var w=Object.defineProperty;var j=(n,t,e)=>t in n?w(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var r=(n,t,e)=>j(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l={INJECTED_PARAMS:"injected:params",INJECTED_PROPS:"injected:props",INJECT:"inject",SELF:"self",SKIP_SELF:"skipSelf",OPTIONAL:"optional",POST_CONSTRUCT:"postConstruct",PRE_DESTROY:"preDestroy"},p={DEFAULT:"default",INITING:"initing",ACTIVATED:"activated"},d={Invalid:"Invalid",Instance:"Instance",ConstantValue:"ConstantValue",DynamicValue:"DynamicValue"},v={POST_CONSTRUCT:"Cannot apply @PostConstruct decorator multiple times in the same class.",PRE_DESTROY:"Cannot apply @PreDestroy decorator multiple times in the same class.",MISS_INJECT:"Expected a @Inject decorator to explicitly specify the token.",MISS_CONTAINER:"@LazyInject decorator cannot find the corresponding container."},m=Symbol(),D=new WeakMap;function B(n){return typeof n=="function"&&Object.getPrototypeOf(n)!==Function.prototype}function b(n,t,e){const s=D.get(e)||{};s[n]=t,D.set(e,s)}function T(n,t){return(D.get(t)||{})[n]}function I(n,t){const e=T(n,t);if(!B(t))return e;const s=I(n,Object.getPrototypeOf(t));if(s||e)return{...s||{},...e||{}}}class _{constructor(t){r(this,"_","");r(this,"name");this.name=t}}class O{constructor(t){r(this,"callback");this.callback=t}resolve(){return this.callback()}}function A(n){if(!n)throw new Error(v.MISS_INJECT);return n instanceof O?n.resolve():n}class E extends Error{constructor(t,e){super(),this.name=this.constructor.name,this.message=`${t}${e==null?void 0:e.name}`}}class N extends E{constructor(t){super("");const e=[];let s=t;for(;s&&s.token;)e.push(s.token),s=s.parent;const i=e.reverse().map(o=>o.name).join(" --> ");this.message=`Circular dependency found: ${i}`}}class k extends E{constructor(t){super("Invalid binding: ",t)}}class H extends N{constructor(t){super(t),this.name="CircularDependencyError inside @PostConstruct"}}class L{constructor(t,e){r(this,"container");r(this,"context");r(this,"token");r(this,"type",d.Invalid);r(this,"status",p.DEFAULT);r(this,"classValue");r(this,"constantValue");r(this,"dynamicValue");r(this,"cache");r(this,"postConstructResult",m);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(p.INITING===this.status)throw new N(t);if(p.ACTIVATED===this.status)return this.cache;if(d.Instance===this.type)return this.resolveInstanceValue(t);if(d.ConstantValue===this.type)return this.resolveConstantValue();if(d.DynamicValue===this.type)return this.resolveDynamicValue();throw new k(this.token)}getAwaitBindings(t,e){return e===!0?t:Array.isArray(e)?t.filter(s=>e.includes(s.token)):typeof e=="function"?t.filter(e):[]}postConstruct(t,e,s){if(d.Instance===this.type){const{key:i,value:o}=I(l.POST_CONSTRUCT,this.classValue)||{};if(i)if(o){const a=[...e,...s].filter(u=>d.Instance===(u==null?void 0:u.type)),c=this.getAwaitBindings(a,o);for(const u of c)if(u&&u.postConstructResult===m)throw new H({token:u.token,parent:t});const h=c.map(u=>u.postConstructResult);this.postConstructResult=Promise.all(h).then(()=>this.execute(i))}else this.postConstructResult=this.execute(i);else this.postConstructResult=void 0}}preDestroy(){if(d.Instance===this.type){const{key:t}=I(l.PRE_DESTROY,this.classValue)||{};if(t)return this.execute(t)}y.map.delete(this.cache),this.container=null,this.context=null,this.cache=null,this.postConstructResult=m,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=p.INITING;const e=this.classValue,[s,i]=this.getConstructorParameters(t),o=new e(...s);this.cache=this.activate(o),this.status=p.ACTIVATED,y.map.set(this.cache,this.container);const[a,c]=this.getInjectProperties(t);return Object.assign(this.cache,a),this.postConstruct(t,i,c),this.cache}resolveConstantValue(){return this.status=p.INITING,this.cache=this.activate(this.constantValue),this.status=p.ACTIVATED,this.cache}resolveDynamicValue(){this.status=p.INITING;const t=this.dynamicValue.call(this,this.context);return this.cache=this.activate(t),this.status=p.ACTIVATED,this.cache}getConstructorParameters(t){const e=T(l.INJECTED_PARAMS,this.classValue)||[],s=[],i=[];for(let o=0;o<e.length;o++){const a=e[o],{inject:c,...h}=a;h.parent=t;const u=this.container.get(A(c),h);s.push(u),i.push(h.binding)}return[s,i]}getInjectProperties(t){const e=I(l.INJECTED_PROPS,this.classValue)||{},s=Object.keys(e),i=Object.create(null),o=[];for(let a=0;a<s.length;a++){const c=s[a],h=e[c],{inject:u,...f}=h;f.parent=t;const g=this.container.get(A(u),f);g===void 0&&h.optional||(i[c]=g),o.push(f.binding)}return[i,o]}}class M extends E{constructor(t){super("No matching binding found for token: ",t)}}class x extends E{constructor(t){super("Cannot bind token multiple times: ",t)}}const C=class C{constructor(){r(this,"parent");r(this,"children");r(this,"bindings",new Map);r(this,"onActivationHandler");r(this,"onDeactivationHandler")}bind(t){if(this.bindings.has(t))throw new x(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(){this.bindings.forEach(t=>{this.unbind(t.token)})}isCurrentBound(t){return this.bindings.has(t)}isBound(t){return this.isCurrentBound(t)||!!this.parent&&this.parent.isBound(t)}createChild(){const t=new C;return t.parent=this,this.children||(this.children=new Set),this.children.add(t),t}destroy(){var t,e,s;this.unbindAll(),this.bindings.clear(),(e=(t=this.parent)==null?void 0:t.children)==null||e.delete(this),this.parent=void 0,(s=this.children)==null||s.clear(),this.children=void 0,this.onActivationHandler=void 0,this.onDeactivationHandler=void 0}get(t,e={}){const s=this.getBinding(t);if(e.skipSelf){if(this.parent)return e.skipSelf=!1,this.parent.get(t,e)}else if(e.self||s){if(s)return e.token=t,e.binding=s,s.get(e)}else if(this.parent)return this.parent.get(t,e);return 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 L(t,this)}getBinding(t){return this.bindings.get(t)}checkBindingNotFoundError(t,e){if(!e.optional)throw new M(t)}};r(C,"map",new WeakMap);let y=C;function S(n,t){return function(e){return function(s,i,o){const a=typeof o=="number",c=a?s:s.constructor,h=a?o:i,u=a?l.INJECTED_PARAMS:l.INJECTED_PROPS,f=a?T(u,c)||[]:I(u,c)||{},g=f[h]||{};g[n]=e===void 0?t:e,f[h]=g,b(u,f,c)}}}function V(n,t){return e=>(s,i)=>{if(T(n,s.constructor))throw new Error(t);b(n,{key:i,value:e},s.constructor)}}const F=S(l.INJECT),J=S(l.SELF,!0),U=S(l.SKIP_SELF,!0),z=S(l.OPTIONAL,!0),G=V(l.POST_CONSTRUCT,v.POST_CONSTRUCT),Y=V(l.PRE_DESTROY,v.PRE_DESTROY);function P(n,t,e,s){for(let i=n.length-1;i>=0;i--)n[i](t,e,s)}function K(n,t,e){n=Array.isArray(n)?n:[n],typeof e=="number"?P(n,t,void 0,e):typeof e=="string"&&P(n,t.prototype,e)}function $(n,t,e,s){function i(){const a=Symbol.for(t);if(!this.hasOwnProperty(a)){const c=s||y.map.get(this),h=this.constructor;if(!c)throw new Error(`${v.MISS_CONTAINER} ${h.name}`);this[a]=c.get(A(e),{parent:{token:h}})}return this[a]}function o(a){const c=Symbol.for(t);this[c]=a}Object.defineProperty(n,t,{configurable:!0,enumerable:!0,get:i,set:o})}function R(n,t){return function(e,s){$(e,s,n,t)}}function W(n){return function(t){return R(t,n)}}exports.Container=y;exports.Inject=F;exports.LazyInject=R;exports.LazyToken=O;exports.Optional=z;exports.PostConstruct=G;exports.PreDestroy=Y;exports.Self=J;exports.SkipSelf=U;exports.Token=_;exports.createLazyInject=W;exports.decorate=K;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './interfaces';
2
- export { Container, CONTAINER_MAP } from './container';
2
+ export { Container } from './container';
3
3
  export { Token, LazyToken } from './token';
4
4
  export { Inject, Self, SkipSelf, Optional, PostConstruct, PreDestroy, decorate, } from './decorator';
5
5
  export { LazyInject, createLazyInject } from './lazyinject';
6
- export { defineMetadata, getOwnMetadata, getMetadata } from './cachemap';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './interfaces';
2
- export { Container, CONTAINER_MAP } from './container';
2
+ export { Container } from './container';
3
3
  export { Token, LazyToken } from './token';
4
4
  export { Inject, Self, SkipSelf, Optional, PostConstruct, PreDestroy, decorate, } from './decorator';
5
5
  export { LazyInject, createLazyInject } from './lazyinject';
6
- export { defineMetadata, getOwnMetadata, getMetadata } from './cachemap';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var V = Object.defineProperty;
2
2
  var R = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var a = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
3
+ var r = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  const l = {
5
5
  // 记录构造函数参数装饰器对应的数据的key
6
6
  INJECTED_PARAMS: "injected:params",
@@ -32,22 +32,19 @@ const l = {
32
32
  PRE_DESTROY: "Cannot apply @PreDestroy decorator multiple times in the same class.",
33
33
  MISS_INJECT: "Expected a @Inject decorator to explicitly specify the token.",
34
34
  MISS_CONTAINER: "@LazyInject decorator cannot find the corresponding container."
35
- }, S = Symbol(), v = /* @__PURE__ */ new WeakMap();
35
+ }, D = Symbol(), S = /* @__PURE__ */ new WeakMap();
36
36
  function w(e) {
37
37
  return typeof e == "function" && Object.getPrototypeOf(e) !== Function.prototype;
38
38
  }
39
- function A(e, t, n) {
40
- const s = v.get(n) || {};
41
- s[e] = t, v.set(n, s);
39
+ function b(e, t, n) {
40
+ const s = S.get(n) || {};
41
+ s[e] = t, S.set(n, s);
42
42
  }
43
- function I(e, t) {
44
- return (v.get(t) || {})[e];
43
+ function E(e, t) {
44
+ return (S.get(t) || {})[e];
45
45
  }
46
46
  function y(e, t) {
47
- const n = I(
48
- e,
49
- t
50
- );
47
+ const n = E(e, t);
51
48
  if (!w(t))
52
49
  return n;
53
50
  const s = y(
@@ -62,31 +59,31 @@ function y(e, t) {
62
59
  }
63
60
  class J {
64
61
  constructor(t) {
65
- a(this, "_", "");
66
- a(this, "name");
62
+ r(this, "_", "");
63
+ r(this, "name");
67
64
  this.name = t;
68
65
  }
69
66
  }
70
- class _ {
67
+ class B {
71
68
  constructor(t) {
72
- a(this, "callback");
69
+ r(this, "callback");
73
70
  this.callback = t;
74
71
  }
75
72
  resolve() {
76
73
  return this.callback();
77
74
  }
78
75
  }
79
- function D(e) {
76
+ function A(e) {
80
77
  if (!e)
81
78
  throw new Error(C.MISS_INJECT);
82
- return e instanceof _ ? e.resolve() : e;
79
+ return e instanceof B ? e.resolve() : e;
83
80
  }
84
- class E extends Error {
81
+ class T extends Error {
85
82
  constructor(t, n) {
86
83
  super(), this.name = this.constructor.name, this.message = `${t}${n == null ? void 0 : n.name}`;
87
84
  }
88
85
  }
89
- class P extends E {
86
+ class N extends T {
90
87
  constructor(t) {
91
88
  super("");
92
89
  const n = [];
@@ -97,30 +94,30 @@ class P extends E {
97
94
  this.message = `Circular dependency found: ${i}`;
98
95
  }
99
96
  }
100
- class B extends E {
97
+ class _ extends T {
101
98
  constructor(t) {
102
99
  super("Invalid binding: ", t);
103
100
  }
104
101
  }
105
- class j extends P {
102
+ class H extends N {
106
103
  constructor(t) {
107
104
  super(t), this.name = "CircularDependencyError inside @PostConstruct";
108
105
  }
109
106
  }
110
- class M {
107
+ class j {
111
108
  constructor(t, n) {
112
- a(this, "container");
113
- a(this, "context");
114
- a(this, "token");
115
- a(this, "type", d.Invalid);
116
- a(this, "status", p.DEFAULT);
117
- a(this, "classValue");
118
- a(this, "constantValue");
119
- a(this, "dynamicValue");
120
- a(this, "cache");
121
- a(this, "postConstructResult", S);
122
- a(this, "onActivationHandler");
123
- a(this, "onDeactivationHandler");
109
+ r(this, "container");
110
+ r(this, "context");
111
+ r(this, "token");
112
+ r(this, "type", d.Invalid);
113
+ r(this, "status", p.DEFAULT);
114
+ r(this, "classValue");
115
+ r(this, "constantValue");
116
+ r(this, "dynamicValue");
117
+ r(this, "cache");
118
+ r(this, "postConstructResult", D);
119
+ r(this, "onActivationHandler");
120
+ r(this, "onDeactivationHandler");
124
121
  this.container = n, this.context = { container: this.container }, this.token = t;
125
122
  }
126
123
  onActivation(t) {
@@ -155,7 +152,7 @@ class M {
155
152
  }
156
153
  get(t) {
157
154
  if (p.INITING === this.status)
158
- throw new P(t);
155
+ throw new N(t);
159
156
  if (p.ACTIVATED === this.status)
160
157
  return this.cache;
161
158
  if (d.Instance === this.type)
@@ -164,7 +161,7 @@ class M {
164
161
  return this.resolveConstantValue();
165
162
  if (d.DynamicValue === this.type)
166
163
  return this.resolveDynamicValue();
167
- throw new B(this.token);
164
+ throw new _(this.token);
168
165
  }
169
166
  getAwaitBindings(t, n) {
170
167
  return n === !0 ? t : Array.isArray(n) ? t.filter((s) => n.includes(s.token)) : typeof n == "function" ? t.filter(n) : [];
@@ -174,12 +171,12 @@ class M {
174
171
  const { key: i, value: o } = y(l.POST_CONSTRUCT, this.classValue) || {};
175
172
  if (i)
176
173
  if (o) {
177
- const r = [...n, ...s].filter(
174
+ const a = [...n, ...s].filter(
178
175
  (u) => d.Instance === (u == null ? void 0 : u.type)
179
- ), c = this.getAwaitBindings(r, o);
176
+ ), c = this.getAwaitBindings(a, o);
180
177
  for (const u of c)
181
- if (u && u.postConstructResult === S)
182
- throw new j({
178
+ if (u && u.postConstructResult === D)
179
+ throw new H({
183
180
  token: u.token,
184
181
  parent: t
185
182
  });
@@ -199,7 +196,7 @@ class M {
199
196
  if (t)
200
197
  return this.execute(t);
201
198
  }
202
- this.container = null, this.context = null;
199
+ I.map.delete(this.cache), this.container = null, this.context = null, this.cache = null, this.postConstructResult = D, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
203
200
  }
204
201
  execute(t) {
205
202
  const n = this.cache[t];
@@ -208,9 +205,9 @@ class M {
208
205
  resolveInstanceValue(t) {
209
206
  this.status = p.INITING;
210
207
  const n = this.classValue, [s, i] = this.getConstructorParameters(t), o = new n(...s);
211
- this.cache = this.activate(o), this.status = p.ACTIVATED, b.set(this.cache, this.container);
212
- const [r, c] = this.getInjectProperties(t);
213
- return Object.assign(this.cache, r), this.postConstruct(t, i, c), this.cache;
208
+ this.cache = this.activate(o), this.status = p.ACTIVATED, I.map.set(this.cache, this.container);
209
+ const [a, c] = this.getInjectProperties(t);
210
+ return Object.assign(this.cache, a), this.postConstruct(t, i, c), this.cache;
214
211
  }
215
212
  resolveConstantValue() {
216
213
  return this.status = p.INITING, this.cache = this.activate(this.constantValue), this.status = p.ACTIVATED, this.cache;
@@ -221,42 +218,43 @@ class M {
221
218
  return this.cache = this.activate(t), this.status = p.ACTIVATED, this.cache;
222
219
  }
223
220
  getConstructorParameters(t) {
224
- const n = I(l.INJECTED_PARAMS, this.classValue) || [], s = [], i = [];
221
+ const n = E(l.INJECTED_PARAMS, this.classValue) || [], s = [], i = [];
225
222
  for (let o = 0; o < n.length; o++) {
226
- const r = n[o], { inject: c, ...h } = r;
223
+ const a = n[o], { inject: c, ...h } = a;
227
224
  h.parent = t;
228
- const u = this.container.get(D(c), h);
225
+ const u = this.container.get(A(c), h);
229
226
  s.push(u), i.push(h.binding);
230
227
  }
231
228
  return [s, i];
232
229
  }
233
230
  getInjectProperties(t) {
234
231
  const n = y(l.INJECTED_PROPS, this.classValue) || {}, s = Object.keys(n), i = /* @__PURE__ */ Object.create(null), o = [];
235
- for (let r = 0; r < s.length; r++) {
236
- const c = s[r], h = n[c], { inject: u, ...f } = h;
232
+ for (let a = 0; a < s.length; a++) {
233
+ const c = s[a], h = n[c], { inject: u, ...f } = h;
237
234
  f.parent = t;
238
- const g = this.container.get(D(u), f);
235
+ const g = this.container.get(A(u), f);
239
236
  g === void 0 && h.optional || (i[c] = g), o.push(f.binding);
240
237
  }
241
238
  return [i, o];
242
239
  }
243
240
  }
244
- class k extends E {
241
+ class k extends T {
245
242
  constructor(t) {
246
243
  super("No matching binding found for token: ", t);
247
244
  }
248
245
  }
249
- class x extends E {
246
+ class x extends T {
250
247
  constructor(t) {
251
248
  super("Cannot bind token multiple times: ", t);
252
249
  }
253
250
  }
254
- class N {
251
+ const v = class v {
255
252
  constructor() {
256
- a(this, "parent");
257
- a(this, "bindings", /* @__PURE__ */ new Map());
258
- a(this, "onActivationHandler");
259
- a(this, "onDeactivationHandler");
253
+ r(this, "parent");
254
+ r(this, "children");
255
+ r(this, "bindings", /* @__PURE__ */ new Map());
256
+ r(this, "onActivationHandler");
257
+ r(this, "onDeactivationHandler");
260
258
  }
261
259
  bind(t) {
262
260
  if (this.bindings.has(t))
@@ -267,7 +265,7 @@ class N {
267
265
  unbind(t) {
268
266
  if (this.bindings.has(t)) {
269
267
  const n = this.getBinding(t);
270
- this.deactivate(n), n.preDestroy(), this.bindings.delete(t);
268
+ this.deactivate(n), n.deactivate(), n.preDestroy(), this.bindings.delete(t);
271
269
  }
272
270
  }
273
271
  unbindAll() {
@@ -282,8 +280,12 @@ class N {
282
280
  return this.isCurrentBound(t) || !!this.parent && this.parent.isBound(t);
283
281
  }
284
282
  createChild() {
285
- const t = new N();
286
- return t.parent = this, t;
283
+ const t = new v();
284
+ return t.parent = this, this.children || (this.children = /* @__PURE__ */ new Set()), this.children.add(t), t;
285
+ }
286
+ destroy() {
287
+ var t, n, s;
288
+ this.unbindAll(), this.bindings.clear(), (n = (t = this.parent) == null ? void 0 : t.children) == null || n.delete(this), this.parent = void 0, (s = this.children) == null || s.clear(), this.children = void 0, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
287
289
  }
288
290
  get(t, n = {}) {
289
291
  const s = this.getBinding(t);
@@ -307,10 +309,10 @@ class N {
307
309
  return this.onActivationHandler ? this.onActivationHandler({ container: this }, t, n) : t;
308
310
  }
309
311
  deactivate(t) {
310
- this.onDeactivationHandler && this.onDeactivationHandler(t.cache, t.token), t.deactivate();
312
+ this.onDeactivationHandler && this.onDeactivationHandler(t.cache, t.token);
311
313
  }
312
314
  buildBinding(t) {
313
- return new M(t, this);
315
+ return new j(t, this);
314
316
  }
315
317
  getBinding(t) {
316
318
  return this.bindings.get(t);
@@ -319,57 +321,58 @@ class N {
319
321
  if (!n.optional)
320
322
  throw new k(t);
321
323
  }
322
- }
323
- const b = /* @__PURE__ */ new WeakMap();
324
- function T(e, t) {
324
+ };
325
+ r(v, "map", /* @__PURE__ */ new WeakMap());
326
+ let I = v;
327
+ function m(e, t) {
325
328
  return function(n) {
326
329
  return function(s, i, o) {
327
- const r = typeof o == "number", c = r ? s : s.constructor, h = r ? o : i, u = r ? l.INJECTED_PARAMS : l.INJECTED_PROPS, f = r ? I(u, c) || [] : y(u, c) || {}, g = f[h] || {};
328
- g[e] = n === void 0 ? t : n, f[h] = g, A(u, f, c);
330
+ const a = typeof o == "number", c = a ? s : s.constructor, h = a ? o : i, u = a ? l.INJECTED_PARAMS : l.INJECTED_PROPS, f = a ? E(u, c) || [] : y(u, c) || {}, g = f[h] || {};
331
+ g[e] = n === void 0 ? t : n, f[h] = g, b(u, f, c);
329
332
  };
330
333
  };
331
334
  }
332
335
  function O(e, t) {
333
336
  return (n) => (s, i) => {
334
- if (I(e, s.constructor))
337
+ if (E(e, s.constructor))
335
338
  throw new Error(t);
336
- A(
339
+ b(
337
340
  e,
338
341
  { key: i, value: n },
339
342
  s.constructor
340
343
  );
341
344
  };
342
345
  }
343
- const U = T(l.INJECT), G = T(l.SELF, !0), Y = T(l.SKIP_SELF, !0), z = T(l.OPTIONAL, !0), K = O(
346
+ const U = m(l.INJECT), G = m(l.SELF, !0), Y = m(l.SKIP_SELF, !0), z = m(l.OPTIONAL, !0), K = O(
344
347
  l.POST_CONSTRUCT,
345
348
  C.POST_CONSTRUCT
346
349
  ), $ = O(
347
350
  l.PRE_DESTROY,
348
351
  C.PRE_DESTROY
349
352
  );
350
- function m(e, t, n, s) {
353
+ function P(e, t, n, s) {
351
354
  for (let i = e.length - 1; i >= 0; i--)
352
355
  e[i](t, n, s);
353
356
  }
354
357
  function W(e, t, n) {
355
- e = Array.isArray(e) ? e : [e], typeof n == "number" ? m(e, t, void 0, n) : typeof n == "string" && m(e, t.prototype, n);
358
+ e = Array.isArray(e) ? e : [e], typeof n == "number" ? P(e, t, void 0, n) : typeof n == "string" && P(e, t.prototype, n);
356
359
  }
357
- function H(e, t, n, s) {
360
+ function M(e, t, n, s) {
358
361
  function i() {
359
- const r = Symbol.for(t);
360
- if (!this.hasOwnProperty(r)) {
361
- const c = s || b.get(this), h = this.constructor;
362
+ const a = Symbol.for(t);
363
+ if (!this.hasOwnProperty(a)) {
364
+ const c = s || I.map.get(this), h = this.constructor;
362
365
  if (!c)
363
366
  throw new Error(`${C.MISS_CONTAINER} ${h.name}`);
364
- this[r] = c.get(D(n), {
367
+ this[a] = c.get(A(n), {
365
368
  parent: { token: h }
366
369
  });
367
370
  }
368
- return this[r];
371
+ return this[a];
369
372
  }
370
- function o(r) {
373
+ function o(a) {
371
374
  const c = Symbol.for(t);
372
- this[c] = r;
375
+ this[c] = a;
373
376
  }
374
377
  Object.defineProperty(e, t, {
375
378
  configurable: !0,
@@ -380,7 +383,7 @@ function H(e, t, n, s) {
380
383
  }
381
384
  function L(e, t) {
382
385
  return function(n, s) {
383
- H(n, s, e, t);
386
+ M(n, s, e, t);
384
387
  };
385
388
  }
386
389
  function q(e) {
@@ -389,11 +392,10 @@ function q(e) {
389
392
  };
390
393
  }
391
394
  export {
392
- b as CONTAINER_MAP,
393
- N as Container,
395
+ I as Container,
394
396
  U as Inject,
395
397
  L as LazyInject,
396
- _ as LazyToken,
398
+ B as LazyToken,
397
399
  z as Optional,
398
400
  K as PostConstruct,
399
401
  $ as PreDestroy,
@@ -401,8 +403,5 @@ export {
401
403
  Y as SkipSelf,
402
404
  J as Token,
403
405
  q as createLazyInject,
404
- W as decorate,
405
- A as defineMetadata,
406
- y as getMetadata,
407
- I as getOwnMetadata
406
+ W as decorate
408
407
  };
@@ -1,7 +1,6 @@
1
1
  import { Token, LazyToken } from './token';
2
2
  import { Container } from './container';
3
3
  import { Binding } from './binding';
4
- import { KEYS } from './constants';
5
4
  export type Newable<TInstance = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => TInstance;
6
5
  export type InjectFunction<R extends (...args: any) => any> = (token: GenericToken) => ReturnType<R>;
7
6
  export type CommonToken<T = unknown> = Token<T> | Newable<T>;
@@ -25,25 +24,3 @@ export interface Options<T = unknown> {
25
24
  export type ActivationHandler<T = unknown> = (ctx: Context, input: T, token?: CommonToken<T>) => T;
26
25
  export type DeactivationHandler<T = unknown> = (input: T, token?: CommonToken<T>) => void;
27
26
  export type PostConstructParam = void | true | CommonToken[] | ((item: Binding, index: number, arr: Binding[]) => boolean);
28
- export type META_KEY_INJECTED_PARAMS = typeof KEYS.INJECTED_PARAMS;
29
- export type META_KEY_INJECTED_PROPS = typeof KEYS.INJECTED_PROPS;
30
- export type META_KEY_POST_CONSTRUCT = typeof KEYS.POST_CONSTRUCT;
31
- export type META_KEY_PRE_DESTROY = typeof KEYS.PRE_DESTROY;
32
- export type META_KEYS = META_KEY_INJECTED_PARAMS | META_KEY_INJECTED_PROPS | META_KEY_POST_CONSTRUCT | META_KEY_PRE_DESTROY;
33
- export type META_VALUE_INJECTED_PARAMS = Options[];
34
- export type META_VALUE_INJECTED_PROPS = Record<string, Options>;
35
- export type META_VALUE_POST_CONSTRUCT = KV<PostConstructParam>;
36
- export type META_VALUE_PRE_DESTROY = KV<void>;
37
- export type META_VALUES = META_VALUE_INJECTED_PARAMS | META_VALUE_INJECTED_PROPS | META_VALUE_POST_CONSTRUCT | META_VALUE_PRE_DESTROY;
38
- export interface KV<T> {
39
- key: string;
40
- value: T;
41
- }
42
- export type ExtractKV<T> = T extends META_KEY_POST_CONSTRUCT ? PostConstructParam : T extends META_KEY_PRE_DESTROY ? void : never;
43
- export interface CacheMapValue {
44
- [KEYS.INJECTED_PARAMS]: Options[];
45
- [KEYS.INJECTED_PROPS]: Record<string, Options>;
46
- [KEYS.POST_CONSTRUCT]: KV<PostConstructParam>;
47
- [KEYS.PRE_DESTROY]: KV<void>;
48
- [key: string]: any;
49
- }
@@ -1,7 +1,6 @@
1
1
  import { Token, LazyToken } from './token';
2
2
  import { Container } from './container';
3
3
  import { Binding } from './binding';
4
- import { KEYS } from './constants';
5
4
  export type Newable<TInstance = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => TInstance;
6
5
  export type InjectFunction<R extends (...args: any) => any> = (token: GenericToken) => ReturnType<R>;
7
6
  export type CommonToken<T = unknown> = Token<T> | Newable<T>;
@@ -25,25 +24,3 @@ export interface Options<T = unknown> {
25
24
  export type ActivationHandler<T = unknown> = (ctx: Context, input: T, token?: CommonToken<T>) => T;
26
25
  export type DeactivationHandler<T = unknown> = (input: T, token?: CommonToken<T>) => void;
27
26
  export type PostConstructParam = void | true | CommonToken[] | ((item: Binding, index: number, arr: Binding[]) => boolean);
28
- export type META_KEY_INJECTED_PARAMS = typeof KEYS.INJECTED_PARAMS;
29
- export type META_KEY_INJECTED_PROPS = typeof KEYS.INJECTED_PROPS;
30
- export type META_KEY_POST_CONSTRUCT = typeof KEYS.POST_CONSTRUCT;
31
- export type META_KEY_PRE_DESTROY = typeof KEYS.PRE_DESTROY;
32
- export type META_KEYS = META_KEY_INJECTED_PARAMS | META_KEY_INJECTED_PROPS | META_KEY_POST_CONSTRUCT | META_KEY_PRE_DESTROY;
33
- export type META_VALUE_INJECTED_PARAMS = Options[];
34
- export type META_VALUE_INJECTED_PROPS = Record<string, Options>;
35
- export type META_VALUE_POST_CONSTRUCT = KV<PostConstructParam>;
36
- export type META_VALUE_PRE_DESTROY = KV<void>;
37
- export type META_VALUES = META_VALUE_INJECTED_PARAMS | META_VALUE_INJECTED_PROPS | META_VALUE_POST_CONSTRUCT | META_VALUE_PRE_DESTROY;
38
- export interface KV<T> {
39
- key: string;
40
- value: T;
41
- }
42
- export type ExtractKV<T> = T extends META_KEY_POST_CONSTRUCT ? PostConstructParam : T extends META_KEY_PRE_DESTROY ? void : never;
43
- export interface CacheMapValue {
44
- [KEYS.INJECTED_PARAMS]: Options[];
45
- [KEYS.INJECTED_PROPS]: Record<string, Options>;
46
- [KEYS.POST_CONSTRUCT]: KV<PostConstructParam>;
47
- [KEYS.PRE_DESTROY]: KV<void>;
48
- [key: string]: any;
49
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaokei/di",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "type": "module",
5
5
  "description": "Tiny di library depends on typescript decorator.",
6
6
  "main": "./dist/index.cjs",