@inversifyjs/core
Advanced tools
Comparing version 3.0.0 to 3.0.1
# @inversifyjs/core | ||
## 3.0.1 | ||
### Patch Changes | ||
- 0dadb6a: Updated `MaybeClassElementMetadataKind` values to avoid collisions | ||
- 7e751e2: Updated resolve flow to keep default values on optional property injection | ||
- 5c9ebca: Updated decorator metadata access to avoid conflicts with base type metadata | ||
- Updated dependencies | ||
- @inversifyjs/reflect-metadata-utils@1.1.0 | ||
## 3.0.0 | ||
@@ -4,0 +14,0 @@ |
@@ -12,3 +12,3 @@ "use strict"; | ||
metadata.kind === MaybeClassElementMetadataKind_1.MaybeClassElementMetadataKind.unknown) { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(type, pendingClassMetadataCountReflectKey_1.pendingClassMetadataCountReflectKey, getDefaultPendingClassMetadataCount_1.getDefaultPendingClassMetadataCount, (count) => count - 1); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(type, pendingClassMetadataCountReflectKey_1.pendingClassMetadataCountReflectKey, getDefaultPendingClassMetadataCount_1.getDefaultPendingClassMetadataCount, (count) => count - 1); | ||
} | ||
@@ -15,0 +15,0 @@ }; |
@@ -10,3 +10,3 @@ "use strict"; | ||
if (metadata === undefined) { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(type, pendingClassMetadataCountReflectKey_1.pendingClassMetadataCountReflectKey, getDefaultPendingClassMetadataCount_1.getDefaultPendingClassMetadataCount, (count) => count + 1); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(type, pendingClassMetadataCountReflectKey_1.pendingClassMetadataCountReflectKey, getDefaultPendingClassMetadataCount_1.getDefaultPendingClassMetadataCount, (count) => count + 1); | ||
} | ||
@@ -13,0 +13,0 @@ }; |
@@ -10,5 +10,5 @@ "use strict"; | ||
function setIsInjectableFlag(target) { | ||
const isInjectableFlag = (0, reflect_metadata_utils_1.getReflectMetadata)(target, classIsInjectableFlagReflectKey_1.classIsInjectableFlagReflectKey); | ||
const isInjectableFlag = (0, reflect_metadata_utils_1.getOwnReflectMetadata)(target, classIsInjectableFlagReflectKey_1.classIsInjectableFlagReflectKey); | ||
if (isInjectableFlag !== undefined) { | ||
throw new InversifyCoreError_1.InversifyCoreError(InversifyCoreErrorKind_1.InversifyCoreErrorKind.injectionDecoratorConflict, 'Cannot apply @injectable decorator multiple times'); | ||
throw new InversifyCoreError_1.InversifyCoreError(InversifyCoreErrorKind_1.InversifyCoreErrorKind.injectionDecoratorConflict, `Cannot apply @injectable decorator multiple times at class "${target.name}"`); | ||
} | ||
@@ -15,0 +15,0 @@ (0, reflect_metadata_utils_1.setReflectMetadata)(target, classIsInjectableFlagReflectKey_1.classIsInjectableFlagReflectKey, true); |
@@ -11,5 +11,5 @@ "use strict"; | ||
function updateClassMetadataWithTypescriptParameterTypes(target) { | ||
const typescriptConstructorArguments = (0, reflect_metadata_utils_1.getReflectMetadata)(target, typescriptDesignParameterTypesReflectKey_1.typescriptParameterTypesReflectKey); | ||
const typescriptConstructorArguments = (0, reflect_metadata_utils_1.getOwnReflectMetadata)(target, typescriptDesignParameterTypesReflectKey_1.typescriptParameterTypesReflectKey); | ||
if (typescriptConstructorArguments !== undefined) { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, updateMaybeClassMetadataWithTypescriptClassMetadata(typescriptConstructorArguments)); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, updateMaybeClassMetadataWithTypescriptClassMetadata(typescriptConstructorArguments)); | ||
} | ||
@@ -16,0 +16,0 @@ } |
@@ -11,3 +11,3 @@ "use strict"; | ||
function getClassMetadata(type) { | ||
const classMetadata = (0, reflect_metadata_utils_1.getReflectMetadata)(type, classMetadataReflectKey_1.classMetadataReflectKey) ?? | ||
const classMetadata = (0, reflect_metadata_utils_1.getOwnReflectMetadata)(type, classMetadataReflectKey_1.classMetadataReflectKey) ?? | ||
(0, getDefaultClassMetadata_1.getDefaultClassMetadata)(); | ||
@@ -14,0 +14,0 @@ if ((0, isPendingClassMetadata_1.isPendingClassMetadata)(type)) { |
@@ -7,5 +7,5 @@ "use strict"; | ||
function isPendingClassMetadata(type) { | ||
const pendingClassMetadataCount = (0, reflect_metadata_utils_1.getReflectMetadata)(type, pendingClassMetadataCountReflectKey_1.pendingClassMetadataCountReflectKey); | ||
const pendingClassMetadataCount = (0, reflect_metadata_utils_1.getOwnReflectMetadata)(type, pendingClassMetadataCountReflectKey_1.pendingClassMetadataCountReflectKey); | ||
return (pendingClassMetadataCount !== undefined && pendingClassMetadataCount !== 0); | ||
} | ||
//# sourceMappingURL=isPendingClassMetadata.js.map |
@@ -15,3 +15,3 @@ "use strict"; | ||
if (scope !== undefined) { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (metadata) => ({ | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (metadata) => ({ | ||
...metadata, | ||
@@ -18,0 +18,0 @@ scope, |
@@ -33,3 +33,3 @@ "use strict"; | ||
if (isConstructorParameter(target, propertyKey)) { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataConstructorArgument_1.updateMaybeClassMetadataConstructorArgument)(buildComposedUpdateMetadataFromTarget(target), parameterIndex)); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataConstructorArgument_1.updateMaybeClassMetadataConstructorArgument)(buildComposedUpdateMetadataFromTarget(target), parameterIndex)); | ||
} | ||
@@ -45,3 +45,3 @@ else { | ||
return (target, propertyKey) => { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target.constructor, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataProperty_1.updateMaybeClassMetadataProperty)(buildComposedUpdateMetadataFromTarget(target), propertyKey)); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target.constructor, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataProperty_1.updateMaybeClassMetadataProperty)(buildComposedUpdateMetadataFromTarget(target), propertyKey)); | ||
}; | ||
@@ -48,0 +48,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
const baseTypeClassMetadata = (0, getClassMetadata_1.getClassMetadata)(options.type); | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, composeUpdateReflectMetadataCallback(options, baseTypeClassMetadata)); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, composeUpdateReflectMetadataCallback(options, baseTypeClassMetadata)); | ||
}; | ||
@@ -17,0 +17,0 @@ return decorator; |
@@ -12,3 +12,3 @@ "use strict"; | ||
try { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target.constructor, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataPostConstructor_1.updateMaybeClassMetadataPostConstructor)(propertyKey)); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target.constructor, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataPostConstructor_1.updateMaybeClassMetadataPostConstructor)(propertyKey)); | ||
} | ||
@@ -15,0 +15,0 @@ catch (error) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
try { | ||
(0, reflect_metadata_utils_1.updateReflectMetadata)(target.constructor, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataPreDestroy_1.updateMaybeClassMetadataPreDestroy)(propertyKey)); | ||
(0, reflect_metadata_utils_1.updateOwnReflectMetadata)(target.constructor, classMetadataReflectKey_1.classMetadataReflectKey, getDefaultClassMetadata_1.getDefaultClassMetadata, (0, updateMaybeClassMetadataPreDestroy_1.updateMaybeClassMetadataPreDestroy)(propertyKey)); | ||
} | ||
@@ -15,0 +15,0 @@ catch (error) { |
export declare enum MaybeClassElementMetadataKind { | ||
unknown = 0 | ||
unknown = 32 | ||
} | ||
//# sourceMappingURL=MaybeClassElementMetadataKind.d.ts.map |
@@ -6,4 +6,4 @@ "use strict"; | ||
(function (MaybeClassElementMetadataKind) { | ||
MaybeClassElementMetadataKind[MaybeClassElementMetadataKind["unknown"] = 0] = "unknown"; | ||
MaybeClassElementMetadataKind[MaybeClassElementMetadataKind["unknown"] = 32] = "unknown"; | ||
})(MaybeClassElementMetadataKind || (exports.MaybeClassElementMetadataKind = MaybeClassElementMetadataKind = {})); | ||
//# sourceMappingURL=MaybeClassElementMetadataKind.js.map |
@@ -16,3 +16,4 @@ "use strict"; | ||
} | ||
if (metadata.kind !== ClassElementMetadataKind_1.ClassElementMetadataKind.unmanaged) { | ||
if (metadata.kind !== ClassElementMetadataKind_1.ClassElementMetadataKind.unmanaged && | ||
propertyNode.bindings !== undefined) { | ||
instance[propertyKey] = resolveServiceNode(params, propertyNode); | ||
@@ -19,0 +20,0 @@ if ((0, common_1.isPromise)(instance[propertyKey])) { |
@@ -1,2 +0,2 @@ | ||
import{getReflectMetadata as e,updateReflectMetadata as n,setReflectMetadata as t}from"@inversifyjs/reflect-metadata-utils";import{getBaseType as o}from"@inversifyjs/prototype-utils";import{stringifyServiceIdentifier as i,LazyServiceIdentifier as r,isPromise as s}from"@inversifyjs/common";const c={Request:"Request",Singleton:"Singleton",Transient:"Transient"},a={ConstantValue:"ConstantValue",DynamicValue:"DynamicValue",Factory:"Factory",Instance:"Instance",Provider:"Provider",ServiceRedirection:"ServiceRedirection"};function*u(...e){for(const n of e)yield*n}class d{#e;#n;#t;constructor(e){this.#e=new Map,this.#n={};for(const n of Reflect.ownKeys(e))this.#n[n]=new Map;this.#t=e}clone(){const e=Reflect.ownKeys(this.#t),n=new d(this.#t);this.#o(this.#e,n.#e);for(const t of e)this.#o(this.#n[t],n.#n[t]);return n}get(e,n){return this.#n[e].get(n)?.values()}getAllKeys(e){return this.#n[e].keys()}removeByRelation(e,n){const t=this.get(e,n);if(void 0!==t)for(const e of t){const n=this.#e.get(e);if(void 0===n)throw new Error("Expecting model relation, none found");this.#i(e,n),this.#e.delete(e)}}set(e,n){this.#e.set(e,n);for(const t of Reflect.ownKeys(n))this.#r(t,n[t]).add(e)}#r(e,n){let t=this.#n[e].get(n);return void 0===t&&(t=new Set,this.#n[e].set(n,t)),t}#o(e,n){for(const[t,o]of e)n.set(t,o)}#i(e,n){for(const t of Reflect.ownKeys(n))this.#s(e,t,n[t])}#s(e,n,t){const o=this.#n[n].get(t);void 0!==o&&(o.delete(e),0===o.size&&this.#n[n].delete(t))}}var l,f,p;!function(e){e.moduleId="moduleId",e.serviceId="serviceId"}(l||(l={}));class g{#c;#a;constructor(e,n){this.#c=n??new d({moduleId:{isOptional:!0},serviceId:{isOptional:!1}}),this.#a=e}static build(e){return new g(e)}add(e,n){this.#c.set(e,n)}clone(){return new g(this.#a,this.#c.clone())}get(e){const n=[],t=this.#c.get(l.serviceId,e);void 0!==t&&n.push(t);const o=this.#a?.get(e);if(void 0!==o&&n.push(o),0!==n.length)return u(...n)}removeAllByModuleId(e){this.#c.removeByRelation(l.moduleId,e)}removeAllByServiceId(e){this.#c.removeByRelation(l.serviceId,e)}}!function(e){e.moduleId="moduleId",e.serviceId="serviceId"}(f||(f={}));class m{#u;#a;constructor(e,n){this.#u=n??new d({moduleId:{isOptional:!0},serviceId:{isOptional:!1}}),this.#a=e}static build(e){return new m(e)}clone(){return new m(this.#a,this.#u.clone())}get(e){return this.getNonParentBindings(e)??this.#a?.get(e)}getNonParentBindings(e){return this.#u.get(f.serviceId,e)}getNonParentBoundServices(){return this.#u.getAllKeys(f.serviceId)}getByModuleId(e){return this.#u.get(f.moduleId,e)??this.#a?.getByModuleId(e)}removeAllByModuleId(e){this.#u.removeByRelation(f.moduleId,e)}removeAllByServiceId(e){this.#u.removeByRelation(f.serviceId,e)}set(e){const n={[f.serviceId]:e.serviceIdentifier};void 0!==e.moduleId&&(n[f.moduleId]=e.moduleId),this.#u.set(e,n)}}!function(e){e.moduleId="moduleId",e.serviceId="serviceId"}(p||(p={}));class v{#d;#a;constructor(e,n){this.#d=n??new d({moduleId:{isOptional:!0},serviceId:{isOptional:!1}}),this.#a=e}static build(e){return new v(e)}add(e,n){this.#d.set(e,n)}clone(){return new v(this.#a,this.#d.clone())}get(e){const n=[],t=this.#d.get(p.serviceId,e);void 0!==t&&n.push(t);const o=this.#a?.get(e);if(void 0!==o&&n.push(o),0!==n.length)return u(...n)}removeAllByModuleId(e){this.#d.removeByRelation(p.moduleId,e)}removeAllByServiceId(e){this.#d.removeByRelation(p.serviceId,e)}}function h(e,n,t){const o=Array.isArray(e)?e:[e];if(void 0!==t)if("number"!=typeof t)Reflect.decorate(o,n.prototype,t);else for(const e of o)e(n,void 0,t);else Reflect.decorate(o,n)}const y="@inversifyjs/core/classMetadataReflectKey";function w(){return{constructorArguments:[],lifecycle:{postConstructMethodName:void 0,preDestroyMethodName:void 0},properties:new Map,scope:void 0}}const M="@inversifyjs/core/pendingClassMetadataCountReflectKey";const I=Symbol.for("@inversifyjs/core/InversifyCoreError");class b extends Error{[I];kind;constructor(e,n,t){super(n,t),this[I]=!0,this.kind=e}static is(e){return"object"==typeof e&&null!==e&&!0===e[I]}static isErrorOfKind(e,n){return b.is(e)&&e.kind===n}}var j,C,x;function $(n){const t=e(n,y)??w();if(!function(n){const t=e(n,M);return void 0!==t&&0!==t}(n))return function(e,n){const t=[];if(n.length<e.length)throw new b(j.missingInjectionDecorator,`Found unexpected missing metadata on type "${e.name}". "${e.name}" constructor requires at least ${e.length.toString()} arguments, found ${n.length.toString()} instead.\nAre you using @inject, @multiInject or @unmanaged decorators in every non optional constructor argument?\n\nIf you're using typescript and want to rely on auto injection, set "emitDecoratorMetadata" compiler option to true`);for(let e=0;e<n.length;++e)void 0===n[e]&&t.push(e);if(t.length>0)throw new b(j.missingInjectionDecorator,`Found unexpected missing metadata on type "${e.name}" at constructor indexes "${t.join('", "')}".\n\nAre you using @inject, @multiInject or @unmanaged decorators at those indexes?\n\nIf you're using typescript and want to rely on auto injection, set "emitDecoratorMetadata" compiler option to true`)}(n,t.constructorArguments),t;!function(e,n){const t=[];for(let o=0;o<n.constructorArguments.length;++o){const i=n.constructorArguments[o];void 0!==i&&i.kind!==C.unknown||t.push(` - Missing or incomplete metadata for type "${e.name}" at constructor argument with index ${o.toString()}.\nEvery constructor parameter must be decorated either with @inject, @multiInject or @unmanaged decorator.`)}for(const[o,i]of n.properties)i.kind===C.unknown&&t.push(` - Missing or incomplete metadata for type "${e.name}" at property "${o.toString()}".\nThis property must be decorated either with @inject or @multiInject decorator.`);if(0===t.length)throw new b(j.unknown,`Unexpected class metadata for type "${e.name}" with uncompletion traces.\nThis might be caused by one of the following reasons:\n\n1. A third party library is targeting inversify reflection metadata.\n2. A bug is causing the issue. Consider submiting an issue to fix it.`);throw new b(j.missingInjectionDecorator,`Invalid class metadata at type ${e.name}:\n\n${t.join("\n\n")}`)}(n,t)}function R(){return 0}function S(e){return t=>{void 0!==t&&t.kind===C.unknown&&n(e,M,R,(e=>e-1))}}function A(e,n){return(...t)=>o=>{if(void 0===o)return e(...t);if(o.kind===x.unmanaged)throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Multiple @inject, @multiInject or @unmanaged decorators found");return n(o,...t)}}function T(e){if(e.kind!==C.unknown&&!0!==e.isFromTypescriptParamType)throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Multiple @inject, @multiInject or @unmanaged decorators found")}!function(e){e[e.injectionDecoratorConflict=0]="injectionDecoratorConflict",e[e.missingInjectionDecorator=1]="missingInjectionDecorator",e[e.planning=2]="planning",e[e.resolution=3]="resolution",e[e.unknown=4]="unknown"}(j||(j={})),function(e){e[e.unknown=0]="unknown"}(C||(C={})),function(e){e[e.multipleInjection=0]="multipleInjection",e[e.singleInjection=1]="singleInjection",e[e.unmanaged=2]="unmanaged"}(x||(x={}));const D=A((function(e,n){return{kind:e,name:void 0,optional:!1,tags:new Map,value:n}}),(function(e,n,t){return T(e),{...e,kind:n,value:t}}));var k;function B(e,n,t,o){if(b.isErrorOfKind(o,j.injectionDecoratorConflict)){const i=function(e,n,t){if(void 0===t){if(void 0===n)throw new b(j.unknown,"Unexpected undefined property and index values");return{kind:k.property,property:n,targetClass:e.constructor}}return{index:t,kind:k.parameter,targetClass:e}}(e,n,t);throw new b(j.injectionDecoratorConflict,`Unexpected injection error.\n\nCause:\n\n${o.message}\n\nDetails\n\n${function(e){switch(e.kind){case k.parameter:return`[class: "${e.targetClass.name}", index: "${e.index.toString()}"]`;case k.property:return`[class: "${e.targetClass.name}", property: "${e.property.toString()}"]`}}(i)}`,{cause:o})}throw o}function P(e,t){return(o,i,r)=>{void 0===r?function(e,t){const o=F(e,t);return(e,t)=>{n(e.constructor,y,w,function(e,n){return t=>{const o=t.properties.get(n);return t.properties.set(n,e(o)),t}}(o(e),t))}}(e,t)(o,i):function(e,t){const o=F(e,t);return(e,t,i)=>{if(!function(e,n){return"function"==typeof e&&void 0===n}(e,t))throw new Error(`Found an @inject decorator in a non constructor parameter.\nFound @inject decorator at method "${t?.toString()??""}" at class "${e.constructor.name}"`);n(e,y,w,function(e,n){return t=>{const o=t.constructorArguments[n];return t.constructorArguments[n]=e(o),t}}(o(e),i))}}(e,t)(o,i,r)}}function F(e,n){return t=>{const o=n(t);return n=>(o(n),e(n))}}function N(e){const n=D(x.singleInjection,e);return(e,t,o)=>{try{void 0===o?P(n,S)(e,t):P(n,S)(e,t,o)}catch(n){B(e,t,o,n)}}}!function(e){e[e.parameter=0]="parameter",e[e.property=1]="property"}(k||(k={}));const E="@inversifyjs/core/classIsInjectableFlagReflectKey";const U=[Array,BigInt,Boolean,Function,Number,Object,String];function O(t){const o=e(t,"design:paramtypes");void 0!==o&&n(t,y,w,function(e){return n=>(e.forEach(((e,t)=>{var o;void 0!==n.constructorArguments[t]||(o=e,U.includes(o))||(n.constructorArguments[t]=function(e){return{isFromTypescriptParamType:!0,kind:x.singleInjection,name:void 0,optional:!1,tags:new Map,value:e}}(e))})),n)}(o))}function K(o){return i=>{!function(n){if(void 0!==e(n,E))throw new b(j.injectionDecoratorConflict,"Cannot apply @injectable decorator multiple times");t(n,E,!0)}(i),O(i),void 0!==o&&n(i,y,w,(e=>({...e,scope:o})))}}function q(e,n,t){let o;return e.extendConstructorArguments??!1?(o=[...n.constructorArguments],t.constructorArguments.map(((e,n)=>{o[n]=e}))):o=t.constructorArguments,o}function V(e,n,t){let o;return o=e.extendProperties??!1?new Map(u(n.properties,t.properties)):t.properties,o}function z(e){return t=>{const o=$(e.type);n(t,y,w,function(e,n){const t=t=>({constructorArguments:q(e,n,t),lifecycle:t.lifecycle,properties:V(e,n,t),scope:t.scope});return t}(e,o))}}function G(e){return n=>{const t=o(n);if(void 0===t)throw new b(j.injectionDecoratorConflict,`Expected base type for type "${n.name}", none found.`);z({...e,type:t})(n)}}function H(e){const n=D(x.multipleInjection,e);return(e,t,o)=>{try{void 0===o?P(n,S)(e,t):P(n,S)(e,t,o)}catch(n){B(e,t,o,n)}}}function J(e){return t=>{void 0===t&&n(e,M,R,(e=>e+1))}}function L(e){return n=>{const t=n??{kind:C.unknown,name:void 0,optional:!1,tags:new Map};if(t.kind===x.unmanaged)throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Found @unmanaged injection with additional @named, @optional, @tagged or @targetName injections");return e(t)}}function Q(e){const n=L(function(e){return n=>{if(void 0!==n.name)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated named decorator");return n.name=e,n}}(e));return(e,t,o)=>{try{void 0===o?P(n,J)(e,t):P(n,J)(e,t,o)}catch(n){B(e,t,o,n)}}}function W(e){if(e.optional)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated optional decorator");return e.optional=!0,e}function X(){const e=L(W);return(n,t,o)=>{try{void 0===o?P(e,J)(n,t):P(e,J)(n,t,o)}catch(e){B(n,t,o,e)}}}function Y(){return(e,t,o)=>{try{n(e.constructor,y,w,(i=t,e=>{if(void 0!==e.lifecycle.postConstructMethodName)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated postConstruct decorator");return e.lifecycle.postConstructMethodName=i,e}))}catch(n){B(e,t,void 0,n)}var i}}function Z(){return(e,t,o)=>{try{n(e.constructor,y,w,(i=t,e=>{if(void 0!==e.lifecycle.preDestroyMethodName)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated preDestroy decorator");return e.lifecycle.preDestroyMethodName=i,e}))}catch(n){B(e,t,void 0,n)}var i}}function _(e,n){const t=L(function(e,n){return t=>{if(t.tags.has(e))throw new b(j.injectionDecoratorConflict,"Unexpected duplicated tag decorator with existing tag");return t.tags.set(e,n),t}}(e,n));return(e,n,o)=>{try{void 0===o?P(t,J)(e,n):P(t,J)(e,n,o)}catch(t){B(e,n,o,t)}}}function ee(){return{kind:x.unmanaged}}const ne=A(ee,(function(e){if(T(e),function(e){return void 0!==e.name||e.optional||e.tags.size>0}(e))throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Found @unmanaged injection with additional @named, @optional, @tagged or @targetName injections");return ee()}));function te(){const e=ne();return(n,t,o)=>{try{void 0===o?P(e,S)(n,t):P(e,S)(n,t,o)}catch(e){B(n,t,o,e)}}}class oe{last;constructor(e){this.last=e}concat(e){return new oe({elem:e,previous:this.last})}[Symbol.iterator](){let e=this.last;return{next:()=>{if(void 0===e)return{done:!0,value:void 0};const n=e.elem;return e=e.previous,{done:!1,value:n}}}}}function ie(e,n){e.servicesBranch.has(n)&&function(e,n){const t=(o=[...e.servicesBranch,n],[...o].map(i).join(" -> "));var o;throw new b(j.planning,`Circular dependency found: ${t}`)}(e,n),e.servicesBranch.add(n)}class re{#l;constructor(e){this.#l=e}get name(){return this.#l.elem.name}get tags(){return this.#l.elem.tags}get serviceIdentifier(){return this.#l.elem.serviceIdentifier}getAncestor(){if(void 0!==this.#l.previous)return new re(this.#l.previous)}}function se(e,n,t){const o=new re(n.last),i=t?.customServiceIdentifier??o.serviceIdentifier;return[...e.getBindings(i)??[]].filter((e=>e.isSatisfiedBy(o)))}function ce(e){return void 0!==e.redirections}function ae(e,n,t){let o,r;ce(t)?(o=t.binding.targetServiceIdentifier,r=t.binding.serviceIdentifier):(o=t.serviceIdentifier,r=t.parent?.binding.serviceIdentifier),Array.isArray(e)?function(e,n,t,o){if(0!==e.length){const n=`Ambiguous bindings found for service: "${i(t)}".\n\nRegistered bindings:\n\n${e.map((e=>function(e){switch(e.type){case a.Instance:return`[ type: "${e.type}", serviceIdentifier: "${i(e.serviceIdentifier)}", scope: "${e.scope}", implementationType: "${e.implementationType.name}" ]`;case a.ServiceRedirection:return`[ type: "${e.type}", serviceIdentifier: "${i(e.serviceIdentifier)}", redirection: "${i(e.targetServiceIdentifier)}" ]`;default:return`[ type: "${e.type}", serviceIdentifier: "${i(e.serviceIdentifier)}", scope: "${e.scope}" ]`}}(e.binding))).join("\n")}\n\nTrying to resolve bindings for "${de(t,o)}".`;throw new b(j.planning,n)}n||ue(t,o)}(e,n,o,r):function(e,n,t,o){if(void 0!==e||n)return;ue(t,o)}(e,n,o,r)}function ue(e,n){const t=`No bindings found for service: "${i(e)}".\n\nTrying to resolve bindings for "${de(e,n)}".`;throw new b(j.planning,t)}function de(e,n){return void 0===n?`${i(e)} (Root service)`:i(n)}function le(e,n){if(1!==e.redirections.length)ae(e.redirections,n,e);else{const[t]=e.redirections;ce(t)&&le(t,n)}}function fe(e,n){if(Array.isArray(e.bindings)&&1===e.bindings.length){const[t]=e.bindings;ce(t)&&le(t,n)}else ae(e.bindings,n,e)}function pe(e){const n=new Map;void 0!==e.rootConstraints.tag&&n.set(e.rootConstraints.tag.key,e.rootConstraints.tag.value);const t=new oe({elem:{name:e.rootConstraints.name,serviceIdentifier:e.rootConstraints.serviceIdentifier,tags:n},previous:void 0}),o=se(e,t),i=[],r={bindings:i,parent:void 0,serviceIdentifier:e.rootConstraints.serviceIdentifier};if(i.push(...ve(e,t,o,r)),!e.rootConstraints.isMultiple){fe(r,e.rootConstraints.isOptional??!1);const[n]=i;r.bindings=n}return{tree:{root:r}}}function ge(e,n,t,o){const i={binding:n,classMetadata:e.getClassMetadata(n.implementationType),constructorParams:[],parent:o,propertyParams:new Map};return function(e,n){const t=e.node.classMetadata;for(const[o,i]of t.constructorArguments.entries())e.node.constructorParams[o]=me(e,n,i);for(const[o,i]of t.properties){const t=me(e,n,i);void 0!==t&&e.node.propertyParams.set(o,t)}return e.node}({getBindings:e.getBindings,getClassMetadata:e.getClassMetadata,node:i,servicesBranch:e.servicesBranch},t)}function me(e,n,t){if(t.kind===x.unmanaged)return;const o=r.is(t.value)?t.value.unwrap():t.value,i=n.concat({name:t.name,serviceIdentifier:o,tags:t.tags}),s=se(e,i),c=[],a={bindings:c,parent:e.node,serviceIdentifier:o};if(c.push(...ve(e,i,s,a)),t.kind===x.singleInjection){fe(a,t.optional);const[e]=c;a.bindings=e}return a}function ve(e,n,t,o){const i=ce(o)?o.binding.targetServiceIdentifier:o.serviceIdentifier;ie(e,i);const r=[];for(const i of t)switch(i.type){case a.Instance:r.push(ge(e,i,n,o));break;case a.ServiceRedirection:{const t=he(e,n,i,o);r.push(t);break}default:r.push({binding:i,parent:o})}return e.servicesBranch.delete(i),r}function he(e,n,t,o){const i={binding:t,parent:o,redirections:[]},r=se(e,n,{customServiceIdentifier:t.targetServiceIdentifier});return i.redirections.push(...ve(e,n,r,i)),i}function ye(e,n,t){const o=e.getActivations(n);return void 0===o?t:s(t)?we(e,t,o[Symbol.iterator]()):function(e,n,t){let o=n,i=t.next();for(;!0!==i.done;){const n=i.value(e.context,o);if(s(n))return we(e,n,t);o=n,i=t.next()}return o}(e,t,o[Symbol.iterator]())}async function we(e,n,t){let o=await n,i=t.next();for(;!0!==i.done;)o=await i.value(e.context,o),i=t.next();return o}function Me(e,n,t){let o=t;if(void 0!==n.onActivation){const t=n.onActivation;o=s(o)?o.then((n=>t(e.context,n))):t(e.context,o)}return ye(e,n.serviceIdentifier,o)}function Ie(e){return(n,t)=>{if(t.cache.isRight)return t.cache.value;const o=Me(n,t,e(n,t));return t.cache={isRight:!0,value:o},o}}const be=Ie((function(e,n){return n.value}));function je(e){return e}function Ce(e,n){return(t,o)=>{const i=e(o);switch(i.scope){case c.Singleton:{if(i.cache.isRight)return i.cache.value;const e=xe(t,o,i,n);return i.cache={isRight:!0,value:e},e}case c.Request:{if(t.requestScopeCache.has(i.id))return t.requestScopeCache.get(i.id);const e=xe(t,o,i,n);return t.requestScopeCache.set(i.id,e),e}case c.Transient:return xe(t,o,i,n)}}}function xe(e,n,t,o){return Me(e,t,o(e,n))}const $e=(e=>Ce(je,e))((function(e,n){return n.value(e.context)}));const Re=Ie((function(e,n){return n.factory(e.context)}));function Se(e,n,t){const o=function(e,n,t){if(void 0===t)return;if(!(t in e))throw new b(j.resolution,`Expecting a "${t.toString()}" property when resolving "${n.implementationType.name}" class @postConstruct decorated method, none found.`);if("function"!=typeof e[t])throw new b(j.resolution,`Expecting a "${t.toString()}" method when resolving "${n.implementationType.name}" class @postConstruct decorated method, a non function property was found instead.`);{let o;try{o=e[t]()}catch(e){throw new b(j.resolution,`Unexpected error found when calling "${t.toString()}" @postConstruct decorated method on class "${n.implementationType.name}"`,{cause:e})}if(s(o))return async function(e,n,t){try{await t}catch(t){throw new b(j.resolution,`Unexpected error found when calling "${n.toString()}" @postConstruct decorated method on class "${e.implementationType.name}"`,{cause:t})}}(n,t,o)}}(e,n,t);return s(o)?o.then((()=>e)):e}function Ae(e){return(n,t,o)=>{const i=new o.binding.implementationType(...n),r=e(t,i,o);return s(r)?r.then((()=>Se(i,o.binding,o.classMetadata.lifecycle.postConstructMethodName))):Se(i,o.binding,o.classMetadata.lifecycle.postConstructMethodName)}}const Te=Ie((function(e,n){return n.provider(e.context)}));function De(e){return e.binding}const ke=function(e){return(n,t,o)=>{const i=[];for(const[r,c]of o.propertyParams){const a=o.classMetadata.properties.get(r);if(void 0===a)throw new b(j.resolution,`Expecting metadata at property "${r.toString()}", none found`);a.kind!==x.unmanaged&&(t[r]=e(n,c),s(t[r])&&i.push((async()=>{t[r]=await t[r]})()))}if(i.length>0)return Promise.all(i).then((()=>{}))}}(Ue),Be=function(e){return function n(t,o){const i=[];for(const r of o.redirections)ce(r)?i.push(...n(t,r)):i.push(e(t,r));return i}}(Ee),Pe=function(e,n,t){return(o,i)=>{const r=e(o,i);return s(r)?n(r,o,i):t(r,o,i)}}(function(e){return(n,t)=>{const o=[];for(const i of t.constructorParams)void 0===i?o.push(void 0):o.push(e(n,i));return o.some(s)?Promise.all(o):o}}(Ue),function(e){return async(n,t,o)=>{const i=await n;return e(i,t,o)}}(Ae(ke)),Ae(ke)),Fe=(e=>Ce(De,e))(Pe);function Ne(e){return Ue(e,e.planResult.tree.root)}function Ee(e,n){switch(n.binding.type){case a.ConstantValue:return be(e,n.binding);case a.DynamicValue:return $e(e,n.binding);case a.Factory:return Re(e,n.binding);case a.Instance:return Fe(e,n);case a.Provider:return Te(e,n.binding)}}function Ue(e,n){if(void 0!==n.bindings)return Array.isArray(n.bindings)?function(e,n){const t=[];for(const o of n)ce(o)?t.push(...Be(e,o)):t.push(Ee(e,o));if(t.some(s))return Promise.all(t);return t}(e,n.bindings):function(e,n){if(ce(n)){const t=Be(e,n);if(1===t.length)return t[0];throw new b(j.resolution,"Unexpected multiple resolved values on single injection")}return Ee(e,n)}(e,n.bindings)}function Oe(e){return void 0!==e.scope}function Ke(e,n){if(void 0!==e.lifecycle.preDestroyMethodName&&"function"==typeof n[e.lifecycle.preDestroyMethodName])return n[e.lifecycle.preDestroyMethodName]()}function qe(e,n,t){const o=e.getDeactivations(n);if(void 0!==o)return s(t)?Ve(t,o[Symbol.iterator]()):function(e,n){let t=n.next();for(;!0!==t.done;){const o=t.value(e);if(s(o))return Ve(e,n);t=n.next()}}(t,o[Symbol.iterator]())}async function Ve(e,n){const t=await e;let o=n.next();for(;!0!==o.done;)await o.value(t),o=n.next()}function ze(e,n){const t=function(e,n){if(n.type===a.Instance){const t=e.getClassMetadata(n.implementationType),o=n.cache.value;return s(o)?o.then((e=>Ke(t,e))):Ke(t,o)}}(e,n);return void 0===t?Ge(e,n):t.then((()=>Ge(e,n)))}function Ge(e,n){const t=n.cache;return s(t.value)?t.value.then((t=>He(e,n,t))):He(e,n,t.value)}function He(e,n,t){let o;if(void 0!==n.onDeactivation){o=(0,n.onDeactivation)(t)}return void 0===o?qe(e,n.serviceIdentifier,t):o.then((()=>qe(e,n.serviceIdentifier,t)))}function Je(e,n){if(void 0===n)return;const t=function(e){const n=[];for(const t of e)Oe(t)&&t.scope===c.Singleton&&t.cache.isRight&&n.push(t);return n}(n),o=[];for(const n of t){const t=ze(e,n);void 0!==t&&o.push(t)}return o.length>0?Promise.all(o).then((()=>{})):void 0}function Le(e,n){const t=e.getBindingsFromModule(n);return Je(e,t)}function Qe(e,n){const t=e.getBindings(n);return Je(e,t)}export{g as ActivationsService,m as BindingService,x as ClassElementMetadataKind,v as DeactivationsService,c as bindingScopeValues,a as bindingTypeValues,h as decorate,$ as getClassMetadata,N as inject,G as injectFromBase,K as injectable,H as multiInject,Q as named,X as optional,pe as plan,Y as postConstruct,Z as preDestroy,Ne as resolve,Le as resolveModuleDeactivations,Qe as resolveServiceDeactivations,_ as tagged,te as unmanaged}; | ||
import{getOwnReflectMetadata as e,updateOwnReflectMetadata as n,setReflectMetadata as t}from"@inversifyjs/reflect-metadata-utils";import{getBaseType as o}from"@inversifyjs/prototype-utils";import{stringifyServiceIdentifier as i,LazyServiceIdentifier as r,isPromise as s}from"@inversifyjs/common";const c={Request:"Request",Singleton:"Singleton",Transient:"Transient"},a={ConstantValue:"ConstantValue",DynamicValue:"DynamicValue",Factory:"Factory",Instance:"Instance",Provider:"Provider",ServiceRedirection:"ServiceRedirection"};function*u(...e){for(const n of e)yield*n}class d{#e;#n;#t;constructor(e){this.#e=new Map,this.#n={};for(const n of Reflect.ownKeys(e))this.#n[n]=new Map;this.#t=e}clone(){const e=Reflect.ownKeys(this.#t),n=new d(this.#t);this.#o(this.#e,n.#e);for(const t of e)this.#o(this.#n[t],n.#n[t]);return n}get(e,n){return this.#n[e].get(n)?.values()}getAllKeys(e){return this.#n[e].keys()}removeByRelation(e,n){const t=this.get(e,n);if(void 0!==t)for(const e of t){const n=this.#e.get(e);if(void 0===n)throw new Error("Expecting model relation, none found");this.#i(e,n),this.#e.delete(e)}}set(e,n){this.#e.set(e,n);for(const t of Reflect.ownKeys(n))this.#r(t,n[t]).add(e)}#r(e,n){let t=this.#n[e].get(n);return void 0===t&&(t=new Set,this.#n[e].set(n,t)),t}#o(e,n){for(const[t,o]of e)n.set(t,o)}#i(e,n){for(const t of Reflect.ownKeys(n))this.#s(e,t,n[t])}#s(e,n,t){const o=this.#n[n].get(t);void 0!==o&&(o.delete(e),0===o.size&&this.#n[n].delete(t))}}var l,f,p;!function(e){e.moduleId="moduleId",e.serviceId="serviceId"}(l||(l={}));class g{#c;#a;constructor(e,n){this.#c=n??new d({moduleId:{isOptional:!0},serviceId:{isOptional:!1}}),this.#a=e}static build(e){return new g(e)}add(e,n){this.#c.set(e,n)}clone(){return new g(this.#a,this.#c.clone())}get(e){const n=[],t=this.#c.get(l.serviceId,e);void 0!==t&&n.push(t);const o=this.#a?.get(e);if(void 0!==o&&n.push(o),0!==n.length)return u(...n)}removeAllByModuleId(e){this.#c.removeByRelation(l.moduleId,e)}removeAllByServiceId(e){this.#c.removeByRelation(l.serviceId,e)}}!function(e){e.moduleId="moduleId",e.serviceId="serviceId"}(f||(f={}));class m{#u;#a;constructor(e,n){this.#u=n??new d({moduleId:{isOptional:!0},serviceId:{isOptional:!1}}),this.#a=e}static build(e){return new m(e)}clone(){return new m(this.#a,this.#u.clone())}get(e){return this.getNonParentBindings(e)??this.#a?.get(e)}getNonParentBindings(e){return this.#u.get(f.serviceId,e)}getNonParentBoundServices(){return this.#u.getAllKeys(f.serviceId)}getByModuleId(e){return this.#u.get(f.moduleId,e)??this.#a?.getByModuleId(e)}removeAllByModuleId(e){this.#u.removeByRelation(f.moduleId,e)}removeAllByServiceId(e){this.#u.removeByRelation(f.serviceId,e)}set(e){const n={[f.serviceId]:e.serviceIdentifier};void 0!==e.moduleId&&(n[f.moduleId]=e.moduleId),this.#u.set(e,n)}}!function(e){e.moduleId="moduleId",e.serviceId="serviceId"}(p||(p={}));class v{#d;#a;constructor(e,n){this.#d=n??new d({moduleId:{isOptional:!0},serviceId:{isOptional:!1}}),this.#a=e}static build(e){return new v(e)}add(e,n){this.#d.set(e,n)}clone(){return new v(this.#a,this.#d.clone())}get(e){const n=[],t=this.#d.get(p.serviceId,e);void 0!==t&&n.push(t);const o=this.#a?.get(e);if(void 0!==o&&n.push(o),0!==n.length)return u(...n)}removeAllByModuleId(e){this.#d.removeByRelation(p.moduleId,e)}removeAllByServiceId(e){this.#d.removeByRelation(p.serviceId,e)}}function h(e,n,t){const o=Array.isArray(e)?e:[e];if(void 0!==t)if("number"!=typeof t)Reflect.decorate(o,n.prototype,t);else for(const e of o)e(n,void 0,t);else Reflect.decorate(o,n)}const y="@inversifyjs/core/classMetadataReflectKey";function w(){return{constructorArguments:[],lifecycle:{postConstructMethodName:void 0,preDestroyMethodName:void 0},properties:new Map,scope:void 0}}const M="@inversifyjs/core/pendingClassMetadataCountReflectKey";const I=Symbol.for("@inversifyjs/core/InversifyCoreError");class b extends Error{[I];kind;constructor(e,n,t){super(n,t),this[I]=!0,this.kind=e}static is(e){return"object"==typeof e&&null!==e&&!0===e[I]}static isErrorOfKind(e,n){return b.is(e)&&e.kind===n}}var j,C,x;function $(n){const t=e(n,y)??w();if(!function(n){const t=e(n,M);return void 0!==t&&0!==t}(n))return function(e,n){const t=[];if(n.length<e.length)throw new b(j.missingInjectionDecorator,`Found unexpected missing metadata on type "${e.name}". "${e.name}" constructor requires at least ${e.length.toString()} arguments, found ${n.length.toString()} instead.\nAre you using @inject, @multiInject or @unmanaged decorators in every non optional constructor argument?\n\nIf you're using typescript and want to rely on auto injection, set "emitDecoratorMetadata" compiler option to true`);for(let e=0;e<n.length;++e)void 0===n[e]&&t.push(e);if(t.length>0)throw new b(j.missingInjectionDecorator,`Found unexpected missing metadata on type "${e.name}" at constructor indexes "${t.join('", "')}".\n\nAre you using @inject, @multiInject or @unmanaged decorators at those indexes?\n\nIf you're using typescript and want to rely on auto injection, set "emitDecoratorMetadata" compiler option to true`)}(n,t.constructorArguments),t;!function(e,n){const t=[];for(let o=0;o<n.constructorArguments.length;++o){const i=n.constructorArguments[o];void 0!==i&&i.kind!==C.unknown||t.push(` - Missing or incomplete metadata for type "${e.name}" at constructor argument with index ${o.toString()}.\nEvery constructor parameter must be decorated either with @inject, @multiInject or @unmanaged decorator.`)}for(const[o,i]of n.properties)i.kind===C.unknown&&t.push(` - Missing or incomplete metadata for type "${e.name}" at property "${o.toString()}".\nThis property must be decorated either with @inject or @multiInject decorator.`);if(0===t.length)throw new b(j.unknown,`Unexpected class metadata for type "${e.name}" with uncompletion traces.\nThis might be caused by one of the following reasons:\n\n1. A third party library is targeting inversify reflection metadata.\n2. A bug is causing the issue. Consider submiting an issue to fix it.`);throw new b(j.missingInjectionDecorator,`Invalid class metadata at type ${e.name}:\n\n${t.join("\n\n")}`)}(n,t)}function R(){return 0}function S(e){return t=>{void 0!==t&&t.kind===C.unknown&&n(e,M,R,(e=>e-1))}}function A(e,n){return(...t)=>o=>{if(void 0===o)return e(...t);if(o.kind===x.unmanaged)throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Multiple @inject, @multiInject or @unmanaged decorators found");return n(o,...t)}}function T(e){if(e.kind!==C.unknown&&!0!==e.isFromTypescriptParamType)throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Multiple @inject, @multiInject or @unmanaged decorators found")}!function(e){e[e.injectionDecoratorConflict=0]="injectionDecoratorConflict",e[e.missingInjectionDecorator=1]="missingInjectionDecorator",e[e.planning=2]="planning",e[e.resolution=3]="resolution",e[e.unknown=4]="unknown"}(j||(j={})),function(e){e[e.unknown=32]="unknown"}(C||(C={})),function(e){e[e.multipleInjection=0]="multipleInjection",e[e.singleInjection=1]="singleInjection",e[e.unmanaged=2]="unmanaged"}(x||(x={}));const D=A((function(e,n){return{kind:e,name:void 0,optional:!1,tags:new Map,value:n}}),(function(e,n,t){return T(e),{...e,kind:n,value:t}}));var k;function B(e,n,t,o){if(b.isErrorOfKind(o,j.injectionDecoratorConflict)){const i=function(e,n,t){if(void 0===t){if(void 0===n)throw new b(j.unknown,"Unexpected undefined property and index values");return{kind:k.property,property:n,targetClass:e.constructor}}return{index:t,kind:k.parameter,targetClass:e}}(e,n,t);throw new b(j.injectionDecoratorConflict,`Unexpected injection error.\n\nCause:\n\n${o.message}\n\nDetails\n\n${function(e){switch(e.kind){case k.parameter:return`[class: "${e.targetClass.name}", index: "${e.index.toString()}"]`;case k.property:return`[class: "${e.targetClass.name}", property: "${e.property.toString()}"]`}}(i)}`,{cause:o})}throw o}function P(e,t){return(o,i,r)=>{void 0===r?function(e,t){const o=F(e,t);return(e,t)=>{n(e.constructor,y,w,function(e,n){return t=>{const o=t.properties.get(n);return t.properties.set(n,e(o)),t}}(o(e),t))}}(e,t)(o,i):function(e,t){const o=F(e,t);return(e,t,i)=>{if(!function(e,n){return"function"==typeof e&&void 0===n}(e,t))throw new Error(`Found an @inject decorator in a non constructor parameter.\nFound @inject decorator at method "${t?.toString()??""}" at class "${e.constructor.name}"`);n(e,y,w,function(e,n){return t=>{const o=t.constructorArguments[n];return t.constructorArguments[n]=e(o),t}}(o(e),i))}}(e,t)(o,i,r)}}function F(e,n){return t=>{const o=n(t);return n=>(o(n),e(n))}}function N(e){const n=D(x.singleInjection,e);return(e,t,o)=>{try{void 0===o?P(n,S)(e,t):P(n,S)(e,t,o)}catch(n){B(e,t,o,n)}}}!function(e){e[e.parameter=0]="parameter",e[e.property=1]="property"}(k||(k={}));const E="@inversifyjs/core/classIsInjectableFlagReflectKey";const U=[Array,BigInt,Boolean,Function,Number,Object,String];function O(t){const o=e(t,"design:paramtypes");void 0!==o&&n(t,y,w,function(e){return n=>(e.forEach(((e,t)=>{var o;void 0!==n.constructorArguments[t]||(o=e,U.includes(o))||(n.constructorArguments[t]=function(e){return{isFromTypescriptParamType:!0,kind:x.singleInjection,name:void 0,optional:!1,tags:new Map,value:e}}(e))})),n)}(o))}function K(o){return i=>{!function(n){if(void 0!==e(n,E))throw new b(j.injectionDecoratorConflict,`Cannot apply @injectable decorator multiple times at class "${n.name}"`);t(n,E,!0)}(i),O(i),void 0!==o&&n(i,y,w,(e=>({...e,scope:o})))}}function q(e,n,t){let o;return e.extendConstructorArguments??!1?(o=[...n.constructorArguments],t.constructorArguments.map(((e,n)=>{o[n]=e}))):o=t.constructorArguments,o}function V(e,n,t){let o;return o=e.extendProperties??!1?new Map(u(n.properties,t.properties)):t.properties,o}function z(e){return t=>{const o=$(e.type);n(t,y,w,function(e,n){const t=t=>({constructorArguments:q(e,n,t),lifecycle:t.lifecycle,properties:V(e,n,t),scope:t.scope});return t}(e,o))}}function G(e){return n=>{const t=o(n);if(void 0===t)throw new b(j.injectionDecoratorConflict,`Expected base type for type "${n.name}", none found.`);z({...e,type:t})(n)}}function H(e){const n=D(x.multipleInjection,e);return(e,t,o)=>{try{void 0===o?P(n,S)(e,t):P(n,S)(e,t,o)}catch(n){B(e,t,o,n)}}}function J(e){return t=>{void 0===t&&n(e,M,R,(e=>e+1))}}function L(e){return n=>{const t=n??{kind:C.unknown,name:void 0,optional:!1,tags:new Map};if(t.kind===x.unmanaged)throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Found @unmanaged injection with additional @named, @optional, @tagged or @targetName injections");return e(t)}}function Q(e){const n=L(function(e){return n=>{if(void 0!==n.name)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated named decorator");return n.name=e,n}}(e));return(e,t,o)=>{try{void 0===o?P(n,J)(e,t):P(n,J)(e,t,o)}catch(n){B(e,t,o,n)}}}function W(e){if(e.optional)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated optional decorator");return e.optional=!0,e}function X(){const e=L(W);return(n,t,o)=>{try{void 0===o?P(e,J)(n,t):P(e,J)(n,t,o)}catch(e){B(n,t,o,e)}}}function Y(){return(e,t,o)=>{try{n(e.constructor,y,w,(i=t,e=>{if(void 0!==e.lifecycle.postConstructMethodName)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated postConstruct decorator");return e.lifecycle.postConstructMethodName=i,e}))}catch(n){B(e,t,void 0,n)}var i}}function Z(){return(e,t,o)=>{try{n(e.constructor,y,w,(i=t,e=>{if(void 0!==e.lifecycle.preDestroyMethodName)throw new b(j.injectionDecoratorConflict,"Unexpected duplicated preDestroy decorator");return e.lifecycle.preDestroyMethodName=i,e}))}catch(n){B(e,t,void 0,n)}var i}}function _(e,n){const t=L(function(e,n){return t=>{if(t.tags.has(e))throw new b(j.injectionDecoratorConflict,"Unexpected duplicated tag decorator with existing tag");return t.tags.set(e,n),t}}(e,n));return(e,n,o)=>{try{void 0===o?P(t,J)(e,n):P(t,J)(e,n,o)}catch(t){B(e,n,o,t)}}}function ee(){return{kind:x.unmanaged}}const ne=A(ee,(function(e){if(T(e),function(e){return void 0!==e.name||e.optional||e.tags.size>0}(e))throw new b(j.injectionDecoratorConflict,"Unexpected injection found. Found @unmanaged injection with additional @named, @optional, @tagged or @targetName injections");return ee()}));function te(){const e=ne();return(n,t,o)=>{try{void 0===o?P(e,S)(n,t):P(e,S)(n,t,o)}catch(e){B(n,t,o,e)}}}class oe{last;constructor(e){this.last=e}concat(e){return new oe({elem:e,previous:this.last})}[Symbol.iterator](){let e=this.last;return{next:()=>{if(void 0===e)return{done:!0,value:void 0};const n=e.elem;return e=e.previous,{done:!1,value:n}}}}}function ie(e,n){e.servicesBranch.has(n)&&function(e,n){const t=(o=[...e.servicesBranch,n],[...o].map(i).join(" -> "));var o;throw new b(j.planning,`Circular dependency found: ${t}`)}(e,n),e.servicesBranch.add(n)}class re{#l;constructor(e){this.#l=e}get name(){return this.#l.elem.name}get tags(){return this.#l.elem.tags}get serviceIdentifier(){return this.#l.elem.serviceIdentifier}getAncestor(){if(void 0!==this.#l.previous)return new re(this.#l.previous)}}function se(e,n,t){const o=new re(n.last),i=t?.customServiceIdentifier??o.serviceIdentifier;return[...e.getBindings(i)??[]].filter((e=>e.isSatisfiedBy(o)))}function ce(e){return void 0!==e.redirections}function ae(e,n,t){let o,r;ce(t)?(o=t.binding.targetServiceIdentifier,r=t.binding.serviceIdentifier):(o=t.serviceIdentifier,r=t.parent?.binding.serviceIdentifier),Array.isArray(e)?function(e,n,t,o){if(0!==e.length){const n=`Ambiguous bindings found for service: "${i(t)}".\n\nRegistered bindings:\n\n${e.map((e=>function(e){switch(e.type){case a.Instance:return`[ type: "${e.type}", serviceIdentifier: "${i(e.serviceIdentifier)}", scope: "${e.scope}", implementationType: "${e.implementationType.name}" ]`;case a.ServiceRedirection:return`[ type: "${e.type}", serviceIdentifier: "${i(e.serviceIdentifier)}", redirection: "${i(e.targetServiceIdentifier)}" ]`;default:return`[ type: "${e.type}", serviceIdentifier: "${i(e.serviceIdentifier)}", scope: "${e.scope}" ]`}}(e.binding))).join("\n")}\n\nTrying to resolve bindings for "${de(t,o)}".`;throw new b(j.planning,n)}n||ue(t,o)}(e,n,o,r):function(e,n,t,o){if(void 0!==e||n)return;ue(t,o)}(e,n,o,r)}function ue(e,n){const t=`No bindings found for service: "${i(e)}".\n\nTrying to resolve bindings for "${de(e,n)}".`;throw new b(j.planning,t)}function de(e,n){return void 0===n?`${i(e)} (Root service)`:i(n)}function le(e,n){if(1!==e.redirections.length)ae(e.redirections,n,e);else{const[t]=e.redirections;ce(t)&&le(t,n)}}function fe(e,n){if(Array.isArray(e.bindings)&&1===e.bindings.length){const[t]=e.bindings;ce(t)&&le(t,n)}else ae(e.bindings,n,e)}function pe(e){const n=new Map;void 0!==e.rootConstraints.tag&&n.set(e.rootConstraints.tag.key,e.rootConstraints.tag.value);const t=new oe({elem:{name:e.rootConstraints.name,serviceIdentifier:e.rootConstraints.serviceIdentifier,tags:n},previous:void 0}),o=se(e,t),i=[],r={bindings:i,parent:void 0,serviceIdentifier:e.rootConstraints.serviceIdentifier};if(i.push(...ve(e,t,o,r)),!e.rootConstraints.isMultiple){fe(r,e.rootConstraints.isOptional??!1);const[n]=i;r.bindings=n}return{tree:{root:r}}}function ge(e,n,t,o){const i={binding:n,classMetadata:e.getClassMetadata(n.implementationType),constructorParams:[],parent:o,propertyParams:new Map};return function(e,n){const t=e.node.classMetadata;for(const[o,i]of t.constructorArguments.entries())e.node.constructorParams[o]=me(e,n,i);for(const[o,i]of t.properties){const t=me(e,n,i);void 0!==t&&e.node.propertyParams.set(o,t)}return e.node}({getBindings:e.getBindings,getClassMetadata:e.getClassMetadata,node:i,servicesBranch:e.servicesBranch},t)}function me(e,n,t){if(t.kind===x.unmanaged)return;const o=r.is(t.value)?t.value.unwrap():t.value,i=n.concat({name:t.name,serviceIdentifier:o,tags:t.tags}),s=se(e,i),c=[],a={bindings:c,parent:e.node,serviceIdentifier:o};if(c.push(...ve(e,i,s,a)),t.kind===x.singleInjection){fe(a,t.optional);const[e]=c;a.bindings=e}return a}function ve(e,n,t,o){const i=ce(o)?o.binding.targetServiceIdentifier:o.serviceIdentifier;ie(e,i);const r=[];for(const i of t)switch(i.type){case a.Instance:r.push(ge(e,i,n,o));break;case a.ServiceRedirection:{const t=he(e,n,i,o);r.push(t);break}default:r.push({binding:i,parent:o})}return e.servicesBranch.delete(i),r}function he(e,n,t,o){const i={binding:t,parent:o,redirections:[]},r=se(e,n,{customServiceIdentifier:t.targetServiceIdentifier});return i.redirections.push(...ve(e,n,r,i)),i}function ye(e,n,t){const o=e.getActivations(n);return void 0===o?t:s(t)?we(e,t,o[Symbol.iterator]()):function(e,n,t){let o=n,i=t.next();for(;!0!==i.done;){const n=i.value(e.context,o);if(s(n))return we(e,n,t);o=n,i=t.next()}return o}(e,t,o[Symbol.iterator]())}async function we(e,n,t){let o=await n,i=t.next();for(;!0!==i.done;)o=await i.value(e.context,o),i=t.next();return o}function Me(e,n,t){let o=t;if(void 0!==n.onActivation){const t=n.onActivation;o=s(o)?o.then((n=>t(e.context,n))):t(e.context,o)}return ye(e,n.serviceIdentifier,o)}function Ie(e){return(n,t)=>{if(t.cache.isRight)return t.cache.value;const o=Me(n,t,e(n,t));return t.cache={isRight:!0,value:o},o}}const be=Ie((function(e,n){return n.value}));function je(e){return e}function Ce(e,n){return(t,o)=>{const i=e(o);switch(i.scope){case c.Singleton:{if(i.cache.isRight)return i.cache.value;const e=xe(t,o,i,n);return i.cache={isRight:!0,value:e},e}case c.Request:{if(t.requestScopeCache.has(i.id))return t.requestScopeCache.get(i.id);const e=xe(t,o,i,n);return t.requestScopeCache.set(i.id,e),e}case c.Transient:return xe(t,o,i,n)}}}function xe(e,n,t,o){return Me(e,t,o(e,n))}const $e=(e=>Ce(je,e))((function(e,n){return n.value(e.context)}));const Re=Ie((function(e,n){return n.factory(e.context)}));function Se(e,n,t){const o=function(e,n,t){if(void 0===t)return;if(!(t in e))throw new b(j.resolution,`Expecting a "${t.toString()}" property when resolving "${n.implementationType.name}" class @postConstruct decorated method, none found.`);if("function"!=typeof e[t])throw new b(j.resolution,`Expecting a "${t.toString()}" method when resolving "${n.implementationType.name}" class @postConstruct decorated method, a non function property was found instead.`);{let o;try{o=e[t]()}catch(e){throw new b(j.resolution,`Unexpected error found when calling "${t.toString()}" @postConstruct decorated method on class "${n.implementationType.name}"`,{cause:e})}if(s(o))return async function(e,n,t){try{await t}catch(t){throw new b(j.resolution,`Unexpected error found when calling "${n.toString()}" @postConstruct decorated method on class "${e.implementationType.name}"`,{cause:t})}}(n,t,o)}}(e,n,t);return s(o)?o.then((()=>e)):e}function Ae(e){return(n,t,o)=>{const i=new o.binding.implementationType(...n),r=e(t,i,o);return s(r)?r.then((()=>Se(i,o.binding,o.classMetadata.lifecycle.postConstructMethodName))):Se(i,o.binding,o.classMetadata.lifecycle.postConstructMethodName)}}const Te=Ie((function(e,n){return n.provider(e.context)}));function De(e){return e.binding}const ke=function(e){return(n,t,o)=>{const i=[];for(const[r,c]of o.propertyParams){const a=o.classMetadata.properties.get(r);if(void 0===a)throw new b(j.resolution,`Expecting metadata at property "${r.toString()}", none found`);a.kind!==x.unmanaged&&void 0!==c.bindings&&(t[r]=e(n,c),s(t[r])&&i.push((async()=>{t[r]=await t[r]})()))}if(i.length>0)return Promise.all(i).then((()=>{}))}}(Ue),Be=function(e){return function n(t,o){const i=[];for(const r of o.redirections)ce(r)?i.push(...n(t,r)):i.push(e(t,r));return i}}(Ee),Pe=function(e,n,t){return(o,i)=>{const r=e(o,i);return s(r)?n(r,o,i):t(r,o,i)}}(function(e){return(n,t)=>{const o=[];for(const i of t.constructorParams)void 0===i?o.push(void 0):o.push(e(n,i));return o.some(s)?Promise.all(o):o}}(Ue),function(e){return async(n,t,o)=>{const i=await n;return e(i,t,o)}}(Ae(ke)),Ae(ke)),Fe=(e=>Ce(De,e))(Pe);function Ne(e){return Ue(e,e.planResult.tree.root)}function Ee(e,n){switch(n.binding.type){case a.ConstantValue:return be(e,n.binding);case a.DynamicValue:return $e(e,n.binding);case a.Factory:return Re(e,n.binding);case a.Instance:return Fe(e,n);case a.Provider:return Te(e,n.binding)}}function Ue(e,n){if(void 0!==n.bindings)return Array.isArray(n.bindings)?function(e,n){const t=[];for(const o of n)ce(o)?t.push(...Be(e,o)):t.push(Ee(e,o));if(t.some(s))return Promise.all(t);return t}(e,n.bindings):function(e,n){if(ce(n)){const t=Be(e,n);if(1===t.length)return t[0];throw new b(j.resolution,"Unexpected multiple resolved values on single injection")}return Ee(e,n)}(e,n.bindings)}function Oe(e){return void 0!==e.scope}function Ke(e,n){if(void 0!==e.lifecycle.preDestroyMethodName&&"function"==typeof n[e.lifecycle.preDestroyMethodName])return n[e.lifecycle.preDestroyMethodName]()}function qe(e,n,t){const o=e.getDeactivations(n);if(void 0!==o)return s(t)?Ve(t,o[Symbol.iterator]()):function(e,n){let t=n.next();for(;!0!==t.done;){const o=t.value(e);if(s(o))return Ve(e,n);t=n.next()}}(t,o[Symbol.iterator]())}async function Ve(e,n){const t=await e;let o=n.next();for(;!0!==o.done;)await o.value(t),o=n.next()}function ze(e,n){const t=function(e,n){if(n.type===a.Instance){const t=e.getClassMetadata(n.implementationType),o=n.cache.value;return s(o)?o.then((e=>Ke(t,e))):Ke(t,o)}}(e,n);return void 0===t?Ge(e,n):t.then((()=>Ge(e,n)))}function Ge(e,n){const t=n.cache;return s(t.value)?t.value.then((t=>He(e,n,t))):He(e,n,t.value)}function He(e,n,t){let o;if(void 0!==n.onDeactivation){o=(0,n.onDeactivation)(t)}return void 0===o?qe(e,n.serviceIdentifier,t):o.then((()=>qe(e,n.serviceIdentifier,t)))}function Je(e,n){if(void 0===n)return;const t=function(e){const n=[];for(const t of e)Oe(t)&&t.scope===c.Singleton&&t.cache.isRight&&n.push(t);return n}(n),o=[];for(const n of t){const t=ze(e,n);void 0!==t&&o.push(t)}return o.length>0?Promise.all(o).then((()=>{})):void 0}function Le(e,n){const t=e.getBindingsFromModule(n);return Je(e,t)}function Qe(e,n){const t=e.getBindings(n);return Je(e,t)}export{g as ActivationsService,m as BindingService,x as ClassElementMetadataKind,v as DeactivationsService,c as bindingScopeValues,a as bindingTypeValues,h as decorate,$ as getClassMetadata,N as inject,G as injectFromBase,K as injectable,H as multiInject,Q as named,X as optional,pe as plan,Y as postConstruct,Z as preDestroy,Ne as resolve,Le as resolveModuleDeactivations,Qe as resolveServiceDeactivations,_ as tagged,te as unmanaged}; | ||
//# sourceMappingURL=index.js.map |
@@ -10,3 +10,3 @@ { | ||
"@inversifyjs/prototype-utils": "0.1.0", | ||
"@inversifyjs/reflect-metadata-utils": "1.0.0" | ||
"@inversifyjs/reflect-metadata-utils": "1.1.0" | ||
}, | ||
@@ -66,3 +66,3 @@ "devDependencies": { | ||
}, | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"scripts": { | ||
@@ -69,0 +69,0 @@ "build": "pnpm run build:cjs && pnpm run build:esm", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
469090
862
3601
+ Added@inversifyjs/reflect-metadata-utils@1.1.0(transitive)
- Removed@inversifyjs/reflect-metadata-utils@1.0.0(transitive)