@kaokei/di 3.0.6 → 3.0.8

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.
@@ -26,7 +26,7 @@ export declare class Binding<T = unknown> {
26
26
  get(options: Options<T>): T;
27
27
  private getAwaitBindings;
28
28
  private postConstruct;
29
- preDestroy(): any;
29
+ preDestroy(): void;
30
30
  private execute;
31
31
  private resolveInstanceValue;
32
32
  private resolveConstantValue;
package/dist/binding.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare class Binding<T = unknown> {
26
26
  get(options: Options<T>): T;
27
27
  private getAwaitBindings;
28
28
  private postConstruct;
29
- preDestroy(): any;
29
+ preDestroy(): void;
30
30
  private execute;
31
31
  private resolveInstanceValue;
32
32
  private resolveConstantValue;
@@ -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,6 +1,7 @@
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;
5
6
  children?: Set<Container>;
6
7
  private bindings;
@@ -28,4 +29,3 @@ export declare class Container {
28
29
  private getBinding;
29
30
  private checkBindingNotFoundError;
30
31
  }
31
- export declare const CONTAINER_MAP: WeakMap<any, Container>;
@@ -1,6 +1,7 @@
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;
5
6
  children?: Set<Container>;
6
7
  private bindings;
@@ -28,4 +29,3 @@ export declare class Container {
28
29
  private getBinding;
29
30
  private checkBindingNotFoundError;
30
31
  }
31
- 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 r=(n,t,e)=>_(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"},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."},P=Symbol(),v=new WeakMap;function M(n){return typeof n=="function"&&Object.getPrototypeOf(n)!==Function.prototype}function D(n,t,e){const s=v.get(e)||{};s[n]=t,v.set(e,s)}function I(n,t){return(v.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){r(this,"_","");r(this,"name");this.name=t}}class N{constructor(t){r(this,"callback");this.callback=t}resolve(){return this.callback()}}function S(n){if(!n)throw new Error(C.MISS_INJECT);return n instanceof N?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 O 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 O{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",P);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 O(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(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===P)throw new k({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}=g(l.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,A.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=I(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(S(c),h);s.push(u),i.push(h.binding)}return[s,i]}getInjectProperties(t){const e=g(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 y=this.container.get(S(u),f);y===void 0&&h.optional||(i[c]=y),o.push(f.binding)}return[i,o]}}class H extends T{constructor(t){super("No matching binding found for token: ",t)}}class x extends T{constructor(t){super("Cannot bind token multiple times: ",t)}}class m{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.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,this.children||(this.children=new Set),this.children.add(t),t}destroy(){var t,e,s;(e=(t=this.parent)==null?void 0:t.children)==null||e.delete(this),this.unbindAll(),this.bindings.clear(),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),t.deactivate()}buildBinding(t){return new L(t,this)}getBinding(t){return this.bindings.get(t)}checkBindingNotFoundError(t,e){if(!e.optional)throw new H(t)}}const A=new WeakMap;function E(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?I(u,c)||[]:g(u,c)||{},y=f[h]||{};y[n]=e===void 0?t:e,f[h]=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(l.INJECT),J=E(l.SELF,!0),U=E(l.SKIP_SELF,!0),z=E(l.OPTIONAL,!0),G=V(l.POST_CONSTRUCT,C.POST_CONSTRUCT),Y=V(l.PRE_DESTROY,C.PRE_DESTROY);function b(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"?b(n,t,void 0,e):typeof e=="string"&&b(n,t.prototype,e)}function $(n,t,e,s){function i(){const a=Symbol.for(t);if(!this.hasOwnProperty(a)){const c=s||A.get(this),h=this.constructor;if(!c)throw new Error(`${C.MISS_CONTAINER} ${h.name}`);this[a]=c.get(S(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_MAP=A;exports.Container=m;exports.Inject=F;exports.LazyInject=R;exports.LazyToken=N;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 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"},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 V 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 V{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 V(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(h.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 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}=I(h.PRE_DESTROY,this.classValue)||{};t&&this.execute(t)}y.map.delete(this.cache),this.container=null,this.context=null,this.classValue=null,this.constantValue=null,this.dynamicValue=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(h.INJECTED_PARAMS,this.classValue)||[],s=[],i=[];for(let o=0;o<e.length;o++){const a=e[o],{inject:c,...l}=a;l.parent=t;const u=this.container.get(A(c),l);s.push(u),i.push(l.binding)}return[s,i]}getInjectProperties(t){const e=I(h.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],l=e[c],{inject:u,...f}=l;f.parent=t;const g=this.container.get(A(u),f);g===void 0&&l.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,l=a?o:i,u=a?h.INJECTED_PARAMS:h.INJECTED_PROPS,f=a?T(u,c)||[]:I(u,c)||{},g=f[l]||{};g[n]=e===void 0?t:e,f[l]=g,b(u,f,c)}}}function N(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(h.INJECT),J=S(h.SELF,!0),U=S(h.SKIP_SELF,!0),z=S(h.OPTIONAL,!0),G=N(h.POST_CONSTRUCT,v.POST_CONSTRUCT),Y=N(h.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),l=this.constructor;if(!c)throw new Error(`${v.MISS_CONTAINER} ${l.name}`);this[a]=c.get(A(e),{parent:{token:l}})}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,5 +1,5 @@
1
- var V = Object.defineProperty;
2
- var R = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
1
+ var O = Object.defineProperty;
2
+ var R = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var r = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  const l = {
5
5
  // 记录构造函数参数装饰器对应的数据的key
@@ -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(
@@ -67,7 +64,7 @@ class J {
67
64
  this.name = t;
68
65
  }
69
66
  }
70
- class _ {
67
+ class B {
71
68
  constructor(t) {
72
69
  r(this, "callback");
73
70
  this.callback = t;
@@ -76,17 +73,17 @@ class _ {
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 V extends T {
90
87
  constructor(t) {
91
88
  super("");
92
89
  const n = [];
@@ -97,17 +94,17 @@ 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 V {
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
109
  r(this, "container");
113
110
  r(this, "context");
@@ -118,7 +115,7 @@ class M {
118
115
  r(this, "constantValue");
119
116
  r(this, "dynamicValue");
120
117
  r(this, "cache");
121
- r(this, "postConstructResult", S);
118
+ r(this, "postConstructResult", D);
122
119
  r(this, "onActivationHandler");
123
120
  r(this, "onDeactivationHandler");
124
121
  this.container = n, this.context = { container: this.container }, this.token = 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 V(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) : [];
@@ -178,8 +175,8 @@ class M {
178
175
  (u) => d.Instance === (u == null ? void 0 : u.type)
179
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
  });
@@ -196,10 +193,9 @@ class M {
196
193
  preDestroy() {
197
194
  if (d.Instance === this.type) {
198
195
  const { key: t } = y(l.PRE_DESTROY, this.classValue) || {};
199
- if (t)
200
- return this.execute(t);
196
+ t && this.execute(t);
201
197
  }
202
- this.container = null, this.context = null;
198
+ I.map.delete(this.cache), this.container = null, this.context = null, this.classValue = null, this.constantValue = null, this.dynamicValue = null, this.cache = null, this.postConstructResult = D, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
203
199
  }
204
200
  execute(t) {
205
201
  const n = this.cache[t];
@@ -208,7 +204,7 @@ class M {
208
204
  resolveInstanceValue(t) {
209
205
  this.status = p.INITING;
210
206
  const n = this.classValue, [s, i] = this.getConstructorParameters(t), o = new n(...s);
211
- this.cache = this.activate(o), this.status = p.ACTIVATED, N.set(this.cache, this.container);
207
+ this.cache = this.activate(o), this.status = p.ACTIVATED, I.map.set(this.cache, this.container);
212
208
  const [a, c] = this.getInjectProperties(t);
213
209
  return Object.assign(this.cache, a), this.postConstruct(t, i, c), this.cache;
214
210
  }
@@ -221,11 +217,11 @@ class M {
221
217
  return this.cache = this.activate(t), this.status = p.ACTIVATED, this.cache;
222
218
  }
223
219
  getConstructorParameters(t) {
224
- const n = I(l.INJECTED_PARAMS, this.classValue) || [], s = [], i = [];
220
+ const n = E(l.INJECTED_PARAMS, this.classValue) || [], s = [], i = [];
225
221
  for (let o = 0; o < n.length; o++) {
226
222
  const a = n[o], { inject: c, ...h } = a;
227
223
  h.parent = t;
228
- const u = this.container.get(D(c), h);
224
+ const u = this.container.get(A(c), h);
229
225
  s.push(u), i.push(h.binding);
230
226
  }
231
227
  return [s, i];
@@ -235,23 +231,23 @@ class M {
235
231
  for (let a = 0; a < s.length; a++) {
236
232
  const c = s[a], h = n[c], { inject: u, ...f } = h;
237
233
  f.parent = t;
238
- const g = this.container.get(D(u), f);
234
+ const g = this.container.get(A(u), f);
239
235
  g === void 0 && h.optional || (i[c] = g), o.push(f.binding);
240
236
  }
241
237
  return [i, o];
242
238
  }
243
239
  }
244
- class k extends E {
240
+ class k extends T {
245
241
  constructor(t) {
246
242
  super("No matching binding found for token: ", t);
247
243
  }
248
244
  }
249
- class x extends E {
245
+ class x extends T {
250
246
  constructor(t) {
251
247
  super("Cannot bind token multiple times: ", t);
252
248
  }
253
249
  }
254
- class b {
250
+ const v = class v {
255
251
  constructor() {
256
252
  r(this, "parent");
257
253
  r(this, "children");
@@ -268,7 +264,7 @@ class b {
268
264
  unbind(t) {
269
265
  if (this.bindings.has(t)) {
270
266
  const n = this.getBinding(t);
271
- this.deactivate(n), n.preDestroy(), this.bindings.delete(t);
267
+ this.deactivate(n), n.deactivate(), n.preDestroy(), this.bindings.delete(t);
272
268
  }
273
269
  }
274
270
  unbindAll() {
@@ -283,12 +279,12 @@ class b {
283
279
  return this.isCurrentBound(t) || !!this.parent && this.parent.isBound(t);
284
280
  }
285
281
  createChild() {
286
- const t = new b();
282
+ const t = new v();
287
283
  return t.parent = this, this.children || (this.children = /* @__PURE__ */ new Set()), this.children.add(t), t;
288
284
  }
289
285
  destroy() {
290
286
  var t, n, s;
291
- (n = (t = this.parent) == null ? void 0 : t.children) == null || n.delete(this), this.unbindAll(), this.bindings.clear(), this.parent = void 0, (s = this.children) == null || s.clear(), this.children = void 0, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
287
+ 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;
292
288
  }
293
289
  get(t, n = {}) {
294
290
  const s = this.getBinding(t);
@@ -312,10 +308,10 @@ class b {
312
308
  return this.onActivationHandler ? this.onActivationHandler({ container: this }, t, n) : t;
313
309
  }
314
310
  deactivate(t) {
315
- this.onDeactivationHandler && this.onDeactivationHandler(t.cache, t.token), t.deactivate();
311
+ this.onDeactivationHandler && this.onDeactivationHandler(t.cache, t.token);
316
312
  }
317
313
  buildBinding(t) {
318
- return new M(t, this);
314
+ return new j(t, this);
319
315
  }
320
316
  getBinding(t) {
321
317
  return this.bindings.get(t);
@@ -324,49 +320,50 @@ class b {
324
320
  if (!n.optional)
325
321
  throw new k(t);
326
322
  }
327
- }
328
- const N = /* @__PURE__ */ new WeakMap();
329
- function T(e, t) {
323
+ };
324
+ r(v, "map", /* @__PURE__ */ new WeakMap());
325
+ let I = v;
326
+ function m(e, t) {
330
327
  return function(n) {
331
328
  return function(s, i, o) {
332
- const a = typeof o == "number", c = a ? s : s.constructor, h = a ? o : i, u = a ? l.INJECTED_PARAMS : l.INJECTED_PROPS, f = a ? I(u, c) || [] : y(u, c) || {}, g = f[h] || {};
333
- g[e] = n === void 0 ? t : n, f[h] = g, A(u, f, c);
329
+ 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] || {};
330
+ g[e] = n === void 0 ? t : n, f[h] = g, b(u, f, c);
334
331
  };
335
332
  };
336
333
  }
337
- function O(e, t) {
334
+ function N(e, t) {
338
335
  return (n) => (s, i) => {
339
- if (I(e, s.constructor))
336
+ if (E(e, s.constructor))
340
337
  throw new Error(t);
341
- A(
338
+ b(
342
339
  e,
343
340
  { key: i, value: n },
344
341
  s.constructor
345
342
  );
346
343
  };
347
344
  }
348
- const U = T(l.INJECT), G = T(l.SELF, !0), Y = T(l.SKIP_SELF, !0), z = T(l.OPTIONAL, !0), K = O(
345
+ const U = m(l.INJECT), G = m(l.SELF, !0), Y = m(l.SKIP_SELF, !0), z = m(l.OPTIONAL, !0), K = N(
349
346
  l.POST_CONSTRUCT,
350
347
  C.POST_CONSTRUCT
351
- ), $ = O(
348
+ ), $ = N(
352
349
  l.PRE_DESTROY,
353
350
  C.PRE_DESTROY
354
351
  );
355
- function m(e, t, n, s) {
352
+ function P(e, t, n, s) {
356
353
  for (let i = e.length - 1; i >= 0; i--)
357
354
  e[i](t, n, s);
358
355
  }
359
356
  function W(e, t, n) {
360
- e = Array.isArray(e) ? e : [e], typeof n == "number" ? m(e, t, void 0, n) : typeof n == "string" && m(e, t.prototype, n);
357
+ e = Array.isArray(e) ? e : [e], typeof n == "number" ? P(e, t, void 0, n) : typeof n == "string" && P(e, t.prototype, n);
361
358
  }
362
- function H(e, t, n, s) {
359
+ function M(e, t, n, s) {
363
360
  function i() {
364
361
  const a = Symbol.for(t);
365
362
  if (!this.hasOwnProperty(a)) {
366
- const c = s || N.get(this), h = this.constructor;
363
+ const c = s || I.map.get(this), h = this.constructor;
367
364
  if (!c)
368
365
  throw new Error(`${C.MISS_CONTAINER} ${h.name}`);
369
- this[a] = c.get(D(n), {
366
+ this[a] = c.get(A(n), {
370
367
  parent: { token: h }
371
368
  });
372
369
  }
@@ -385,7 +382,7 @@ function H(e, t, n, s) {
385
382
  }
386
383
  function L(e, t) {
387
384
  return function(n, s) {
388
- H(n, s, e, t);
385
+ M(n, s, e, t);
389
386
  };
390
387
  }
391
388
  function q(e) {
@@ -394,11 +391,10 @@ function q(e) {
394
391
  };
395
392
  }
396
393
  export {
397
- N as CONTAINER_MAP,
398
- b as Container,
394
+ I as Container,
399
395
  U as Inject,
400
396
  L as LazyInject,
401
- _ as LazyToken,
397
+ B as LazyToken,
402
398
  z as Optional,
403
399
  K as PostConstruct,
404
400
  $ as PreDestroy,
@@ -406,8 +402,5 @@ export {
406
402
  Y as SkipSelf,
407
403
  J as Token,
408
404
  q as createLazyInject,
409
- W as decorate,
410
- A as defineMetadata,
411
- y as getMetadata,
412
- I as getOwnMetadata
405
+ W as decorate
413
406
  };
@@ -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.6",
3
+ "version": "3.0.8",
4
4
  "type": "module",
5
5
  "description": "Tiny di library depends on typescript decorator.",
6
6
  "main": "./dist/index.cjs",