New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@inversifyjs/container

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inversifyjs/container - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

lib/cjs/binding/calculations/isResolvedValueMetadataInjectOptions.d.ts

11

CHANGELOG.md
# @inversifyjs/container
## 1.5.0
### Minor Changes
- 9ba2c64: Updated `BindToFluentSyntax` with `.toResolvedValue`
### Patch Changes
- Updated dependencies
- @inversifyjs/core@3.5.0
## 1.4.2

@@ -4,0 +15,0 @@

2

lib/cjs/binding/models/BindingFluentSyntax.d.ts
import { Newable, ServiceIdentifier } from '@inversifyjs/common';
import { BindingActivation, BindingDeactivation, BindingMetadata, DynamicValueBuilder, Factory, MetadataName, MetadataTag, Provider, ResolutionContext } from '@inversifyjs/core';
import { ResolvedValueInjectOptions } from './ResolvedValueInjectOptions';
export interface BindToFluentSyntax<T> {

@@ -10,2 +11,3 @@ to(type: Newable<T>): BindInWhenOnFluentSyntax<T>;

toProvider(provider: T extends Provider<unknown, any> ? (context: ResolutionContext) => T : never): BindWhenOnFluentSyntax<T>;
toResolvedValue(factory: (...args: any[]) => T, injectOptions?: ResolvedValueInjectOptions<T>[]): BindInWhenOnFluentSyntax<T>;
toService(service: ServiceIdentifier<T>): void;

@@ -12,0 +14,0 @@ }

@@ -5,2 +5,3 @@ import { Newable, ServiceIdentifier } from '@inversifyjs/common';

import { BindInFluentSyntax, BindInWhenOnFluentSyntax, BindOnFluentSyntax, BindToFluentSyntax, BindWhenFluentSyntax, BindWhenOnFluentSyntax } from './BindingFluentSyntax';
import { ResolvedValueInjectOptions } from './ResolvedValueInjectOptions';
export declare class BindInFluentSyntaxImplementation<T> implements BindInFluentSyntax<T> {

@@ -20,2 +21,3 @@ #private;

toDynamicValue(builder: DynamicValueBuilder<T>): BindInWhenOnFluentSyntax<T>;
toResolvedValue(factory: (...args: any[]) => T, injectOptions?: ResolvedValueInjectOptions<T>[]): BindInWhenOnFluentSyntax<T>;
toFactory(builder: T extends Factory<unknown, any> ? (context: ResolutionContext) => T : never): BindWhenOnFluentSyntax<T>;

@@ -22,0 +24,0 @@ toProvider(provider: T extends Provider<unknown, any> ? (context: ResolutionContext) => T : never): BindWhenOnFluentSyntax<T>;

@@ -26,2 +26,3 @@ "use strict";

const isParentBindingMetadataWithTag_1 = require("../calculations/isParentBindingMetadataWithTag");
const isResolvedValueMetadataInjectOptions_1 = require("../calculations/isResolvedValueMetadataInjectOptions");
class BindInFluentSyntaxImplementation {

@@ -121,2 +122,24 @@ #binding;

}
toResolvedValue(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
factory, injectOptions) {
const binding = {
cache: {
isRight: false,
value: undefined,
},
factory,
id: (0, getBindingId_1.getBindingId)(),
isSatisfiedBy: BindingConstraintUtils_1.BindingConstraintUtils.always,
metadata: this.#buildResolvedValueMetadata(injectOptions),
moduleId: this.#containerModuleId,
onActivation: undefined,
onDeactivation: undefined,
scope: this.#defaultScope,
serviceIdentifier: this.#serviceIdentifier,
type: core_1.bindingTypeValues.ResolvedValue,
};
this.#callback(binding);
return new BindInWhenOnFluentSyntaxImplementation(binding);
}
toFactory(

@@ -175,2 +198,32 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

}
#buildResolvedValueMetadata(options) {
const resolvedValueMetadata = {
arguments: (options ?? []).map((injectOption) => {
if ((0, isResolvedValueMetadataInjectOptions_1.isResolvedValueMetadataInjectOptions)(injectOption)) {
return {
kind: injectOption.isMultiple === true
? core_1.ResolvedValueElementMetadataKind.multipleInjection
: core_1.ResolvedValueElementMetadataKind.singleInjection,
name: injectOption.name,
optional: injectOption.optional ?? false,
tags: new Map((injectOption.tags ?? []).map((tag) => [
tag.key,
tag.value,
])),
value: injectOption.serviceIdentifier,
};
}
else {
return {
kind: core_1.ResolvedValueElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: injectOption,
};
}
}),
};
return resolvedValueMetadata;
}
}

@@ -177,0 +230,0 @@ exports.BindToFluentSyntaxImplementation = BindToFluentSyntaxImplementation;

3

lib/cjs/index.d.ts
import 'reflect-metadata';
import { BindInFluentSyntax, BindInWhenOnFluentSyntax, BindOnFluentSyntax, BindToFluentSyntax, BindWhenFluentSyntax, BindWhenOnFluentSyntax } from './binding/models/BindingFluentSyntax';
import { ResolvedValueInjectOptions, ResolvedValueMetadataInjectOptions, ResolvedValueMetadataInjectTagOptions } from './binding/models/ResolvedValueInjectOptions';
import { ContainerModule, ContainerModuleLoadOptions } from './container/models/ContainerModule';

@@ -8,4 +9,4 @@ import { IsBoundOptions } from './container/models/isBoundOptions';

import { InversifyContainerErrorKind } from './error/models/InversifyContainerErrorKind';
export type { BindInFluentSyntax, BindInWhenOnFluentSyntax, BindOnFluentSyntax, BindToFluentSyntax, BindWhenFluentSyntax, BindWhenOnFluentSyntax, ContainerModuleLoadOptions, ContainerOptions, IsBoundOptions, };
export type { BindInFluentSyntax, BindInWhenOnFluentSyntax, BindOnFluentSyntax, BindToFluentSyntax, BindWhenFluentSyntax, BindWhenOnFluentSyntax, ContainerModuleLoadOptions, ContainerOptions, IsBoundOptions, ResolvedValueInjectOptions, ResolvedValueMetadataInjectOptions, ResolvedValueMetadataInjectTagOptions, };
export { Container, ContainerModule, InversifyContainerError, InversifyContainerErrorKind, };
//# sourceMappingURL=index.d.ts.map

@@ -1,4 +0,17 @@

import { Newable, ServiceIdentifier } from '@inversifyjs/common';
import { DynamicValueBuilder, Factory, ResolutionContext, Provider, BindingActivation, BindingDeactivation, BindingMetadata, MetadataName, MetadataTag, GetOptionsTagConstraint, BindingScope, OptionalGetOptions, GetOptions } from '@inversifyjs/core';
import { LazyServiceIdentifier, ServiceIdentifier, Newable } from '@inversifyjs/common';
import { MetadataName, MetadataTag, BindingMetadata, BindingActivation, BindingDeactivation, DynamicValueBuilder, Factory, ResolutionContext, Provider, GetOptionsTagConstraint, BindingScope, OptionalGetOptions, GetOptions } from '@inversifyjs/core';
type ResolvedValueInjectOptions<T> = LazyServiceIdentifier<T> | ResolvedValueMetadataInjectOptions<T> | ServiceIdentifier<T>;
interface ResolvedValueMetadataInjectOptions<T> {
isMultiple?: true;
name?: MetadataName;
optional?: true;
serviceIdentifier: ServiceIdentifier<T> | LazyServiceIdentifier<T>;
tags?: ResolvedValueMetadataInjectTagOptions[];
}
interface ResolvedValueMetadataInjectTagOptions {
key: MetadataTag;
value: unknown;
}
interface BindToFluentSyntax<T> {

@@ -11,2 +24,3 @@ to(type: Newable<T>): BindInWhenOnFluentSyntax<T>;

toProvider(provider: T extends Provider<unknown, any> ? (context: ResolutionContext) => T : never): BindWhenOnFluentSyntax<T>;
toResolvedValue(factory: (...args: any[]) => T, injectOptions?: ResolvedValueInjectOptions<T>[]): BindInWhenOnFluentSyntax<T>;
toService(service: ServiceIdentifier<T>): void;

@@ -109,2 +123,2 @@ }

export { type BindInFluentSyntax, type BindInWhenOnFluentSyntax, type BindOnFluentSyntax, type BindToFluentSyntax, type BindWhenFluentSyntax, type BindWhenOnFluentSyntax, Container, ContainerModule, type ContainerModuleLoadOptions, type ContainerOptions, InversifyContainerError, InversifyContainerErrorKind, type IsBoundOptions };
export { type BindInFluentSyntax, type BindInWhenOnFluentSyntax, type BindOnFluentSyntax, type BindToFluentSyntax, type BindWhenFluentSyntax, type BindWhenOnFluentSyntax, Container, ContainerModule, type ContainerModuleLoadOptions, type ContainerOptions, InversifyContainerError, InversifyContainerErrorKind, type IsBoundOptions, type ResolvedValueInjectOptions, type ResolvedValueMetadataInjectOptions, type ResolvedValueMetadataInjectTagOptions };

@@ -1,2 +0,2 @@

import"reflect-metadata";import{getOwnReflectMetadata as i,setReflectMetadata as e,updateOwnReflectMetadata as t}from"@inversifyjs/reflect-metadata-utils";import{isPromise as n,stringifyServiceIdentifier as s}from"@inversifyjs/common";import{getClassMetadata as r,bindingTypeValues as a,bindingScopeValues as o,PlanResultCacheService as c,ActivationsService as d,BindingService as l,DeactivationsService as u,resolveServiceDeactivations as h,resolveModuleDeactivations as v,plan as g,resolve as S}from"@inversifyjs/core";const b="@inversifyjs/container/bindingId";class p{#i;#e;constructor(n){this.#i=function(){const n=i(Object,b)??0;return n===Number.MAX_SAFE_INTEGER?e(Object,b,Number.MIN_SAFE_INTEGER):t(Object,b,(()=>n),(i=>i+1)),n}(),this.#e=n}get id(){return this.#i}async load(i){await this.#e(i)}}class f{static always=i=>!0}const y="@inversifyjs/container/bindingId";function w(){const n=i(Object,y)??0;return n===Number.MAX_SAFE_INTEGER?e(Object,y,Number.MIN_SAFE_INTEGER):t(Object,y,(()=>n),(i=>i+1)),n}function m(i){return e=>{for(let t=e.getAncestor();void 0!==t;t=t.getAncestor())if(i(t))return!0;return!1}}function I(i){return e=>e.name===i}function A(i){return e=>e.serviceIdentifier===i}function P(i,e){return t=>t.tags.has(i)&&t.tags.get(i)===e}function R(i){return void 0===i.name&&0===i.tags.size}function B(i){const e=m(i);return i=>!e(i)}function C(i){return e=>{const t=e.getAncestor();return void 0===t||!i(t)}}function N(i){return e=>{const t=e.getAncestor();return void 0!==t&&i(t)}}class M{#t;constructor(i){this.#t=i}inRequestScope(){return this.#t.scope=o.Request,new x(this.#t)}inSingletonScope(){return this.#t.scope=o.Singleton,new x(this.#t)}inTransientScope(){return this.#t.scope=o.Transient,new x(this.#t)}}class O{#n;#s;#r;#a;constructor(i,e,t,n){this.#n=i,this.#s=e,this.#r=t,this.#a=n}to(i){const e=r(i),t={cache:{isRight:!1,value:void 0},id:w(),implementationType:i,isSatisfiedBy:f.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:e.scope??this.#r,serviceIdentifier:this.#a,type:a.Instance};return this.#n(t),new E(t)}toSelf(){if("function"!=typeof this.#a)throw new Error('"toSelf" function can only be applied when a newable function is used as service identifier');return this.to(this.#a)}toConstantValue(i){const e={cache:{isRight:!1,value:void 0},id:w(),isSatisfiedBy:f.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:o.Singleton,serviceIdentifier:this.#a,type:a.ConstantValue,value:i};return this.#n(e),new x(e)}toDynamicValue(i){const e={cache:{isRight:!1,value:void 0},id:w(),isSatisfiedBy:f.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:this.#r,serviceIdentifier:this.#a,type:a.DynamicValue,value:i};return this.#n(e),new E(e)}toFactory(i){const e={cache:{isRight:!1,value:void 0},factory:i,id:w(),isSatisfiedBy:f.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:o.Singleton,serviceIdentifier:this.#a,type:a.Factory};return this.#n(e),new x(e)}toProvider(i){const e={cache:{isRight:!1,value:void 0},id:w(),isSatisfiedBy:f.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,provider:i,scope:o.Singleton,serviceIdentifier:this.#a,type:a.Provider};return this.#n(e),new x(e)}toService(i){const e={id:w(),isSatisfiedBy:f.always,moduleId:this.#s,serviceIdentifier:this.#a,targetServiceIdentifier:i,type:a.ServiceRedirection};this.#n(e)}}class F{#t;constructor(i){this.#t=i}onActivation(i){return this.#t.onActivation=i,new D(this.#t)}onDeactivation(i){return this.#t.onDeactivation=i,new D(this.#t)}}class D{#t;constructor(i){this.#t=i}when(i){return this.#t.isSatisfiedBy=i,new F(this.#t)}whenAnyAncestor(i){return this.when(m(i))}whenAnyAncestorIs(i){return this.when(m(A(i)))}whenAnyAncestorNamed(i){return this.when(function(i){return m(I(i))}(i))}whenAnyAncestorTagged(i,e){return this.when(function(i,e){return m(P(i,e))}(i,e))}whenDefault(){return this.when(R)}whenNamed(i){return this.when(I(i))}whenNoParent(i){return this.when(C(i))}whenNoParentIs(i){return this.when(C(A(i)))}whenNoParentNamed(i){return this.when(function(i){return C(I(i))}(i))}whenNoParentTagged(i,e){return this.when(function(i,e){return C(P(i,e))}(i,e))}whenParent(i){return this.when(N(i))}whenParentIs(i){return this.when(N(A(i)))}whenParentNamed(i){return this.when(function(i){return N(I(i))}(i))}whenParentTagged(i,e){return this.when(function(i,e){return N(P(i,e))}(i,e))}whenTagged(i,e){return this.when(P(i,e))}whenNoAncestor(i){return this.when(B(i))}whenNoAncestorIs(i){return this.when(B(A(i)))}whenNoAncestorNamed(i){return this.when(function(i){return B(I(i))}(i))}whenNoAncestorTagged(i,e){return this.when(function(i,e){return B(P(i,e))}(i,e))}}class x extends D{#o;constructor(i){super(i),this.#o=new F(i)}onActivation(i){return this.#o.onActivation(i)}onDeactivation(i){return this.#o.onDeactivation(i)}}class E extends x{#c;constructor(i){super(i),this.#c=new M(i)}inRequestScope(){return this.#c.inRequestScope()}inSingletonScope(){return this.#c.inSingletonScope()}inTransientScope(){return this.#c.inTransientScope()}}const T=Symbol.for("@inversifyjs/container/InversifyContainerError");class k extends Error{[T];kind;constructor(i,e,t){super(e,t),this[T]=!0,this.kind=i}static is(i){return"object"==typeof i&&null!==i&&!0===i[T]}static isErrorOfKind(i,e){return k.is(i)&&i.kind===e}}var j;!function(i){i[i.invalidOperation=0]="invalidOperation"}(j||(j={}));const _=o.Transient;class V{#d;#l;#u;#h;#v;#g;constructor(i){this.#v=new c,void 0===i?.parent?(this.#d=d.build(void 0),this.#l=l.build(void 0),this.#u=u.build(void 0)):(this.#d=d.build(i.parent.#d),this.#l=l.build(i.parent.#l),this.#u=u.build(i.parent.#u),i.parent.#v.subscribe(this.#v)),this.#h={autobind:i?.autobind??!1,defaultScope:i?.defaultScope??_},this.#g=[]}bind(i){return new O((i=>{this.#S(i)}),void 0,this.#h.defaultScope,i)}get(i,e){const t=this.#b(!1,i,e),r=this.#p(t);if(n(r))throw new k(j.invalidOperation,`Unexpected asyncronous service when resolving service "${s(i)}"`);return r}getAll(i,e){const t=this.#b(!0,i,e),r=this.#p(t);if(n(r))throw new k(j.invalidOperation,`Unexpected asyncronous service when resolving service "${s(i)}"`);return r}async getAllAsync(i,e){const t=this.#b(!0,i,e);return this.#p(t)}async getAsync(i,e){const t=this.#b(!1,i,e);return this.#p(t)}isBound(i,e){const t=this.#l.get(i);return this.#f(i,t,e)}isCurrentBound(i,e){const t=this.#l.getNonParentBindings(i);return this.#f(i,t,e)}async load(...i){await Promise.all(i.map((async i=>i.load(this.#y(i.id)))))}onActivation(i,e){this.#d.add(e,{serviceId:i})}onDeactivation(i,e){this.#u.add(e,{serviceId:i})}restore(){const i=this.#g.pop();if(void 0===i)throw new k(j.invalidOperation,"No snapshot available to restore");this.#d=i.activationService,this.#l=i.bindingService,this.#u=i.deactivationService,this.#v.clearCache()}snapshot(){this.#g.push({activationService:this.#d.clone(),bindingService:this.#l.clone(),deactivationService:this.#u.clone()})}async unbind(i){await h(this.#w(),i),this.#d.removeAllByServiceId(i),this.#l.removeAllByServiceId(i),this.#u.removeAllByServiceId(i),this.#v.clearCache()}async unbindAll(){const i=this.#w(),e=[...this.#l.getNonParentBoundServices()];await Promise.all(e.map((async e=>h(i,e))));for(const i of e)this.#d.removeAllByServiceId(i),this.#l.removeAllByServiceId(i),this.#u.removeAllByServiceId(i);this.#v.clearCache()}async unload(...i){const e=this.#w();await Promise.all(i.map((i=>v(e,i.id))));for(const e of i)this.#d.removeAllByModuleId(e.id),this.#l.removeAllByModuleId(e.id),this.#u.removeAllByModuleId(e.id);this.#v.clearCache()}#y(i){return{bind:e=>new O((i=>{this.#S(i)}),i,this.#h.defaultScope,e),isBound:this.isBound.bind(this),onActivation:(e,t)=>{this.#d.add(t,{moduleId:i,serviceId:e})},onDeactivation:(e,t)=>{this.#u.add(t,{moduleId:i,serviceId:e})},unbind:this.unbind.bind(this)}}#w(){return{getBindings:i=>this.#l.get(i),getBindingsFromModule:i=>this.#l.getByModuleId(i),getClassMetadata:r,getDeactivations:i=>this.#u.get(i)}}#m(i,e,t){return{isMultiple:i,name:t?.name,optional:t?.optional,serviceIdentifier:e,tag:t?.tag}}#I(i,e,t){const n={autobindOptions:t?.autobind??this.#h.autobind?{scope:this.#h.defaultScope}:void 0,getBindings:this.#l.get.bind(this.#l),getClassMetadata:r,rootConstraints:{isMultiple:i,serviceIdentifier:e},servicesBranch:new Set,setBinding:this.#S.bind(this)};return this.#A(n,t),n}#b(i,e,t){const n=this.#m(i,e,t),s=this.#v.get(n);if(void 0!==s)return s;const r=g(this.#I(i,e,t));return this.#v.set(n,r),r}#p(i){return S({context:{get:this.get.bind(this),getAll:this.getAll.bind(this),getAllAsync:this.getAllAsync.bind(this),getAsync:this.getAsync.bind(this)},getActivations:i=>this.#d.get(i),planResult:i,requestScopeCache:new Map})}#A(i,e){void 0!==e&&(void 0!==e.name&&(i.rootConstraints.name=e.name),!0===e.optional&&(i.rootConstraints.isOptional=!0),void 0!==e.tag&&(i.rootConstraints.tag={key:e.tag.key,value:e.tag.value}))}#f(i,e,t){if(void 0===e)return!1;const n={getAncestor:()=>{},name:t?.name,serviceIdentifier:i,tags:new Map};void 0!==t?.tag&&n.tags.set(t.tag.key,t.tag.value);for(const i of e)if(i.isSatisfiedBy(n))return!0;return!1}#S(i){this.#l.set(i),this.#v.clearCache()}}export{V as Container,p as ContainerModule,k as InversifyContainerError,j as InversifyContainerErrorKind};
import"reflect-metadata";import{getOwnReflectMetadata as e,setReflectMetadata as i,updateOwnReflectMetadata as t}from"@inversifyjs/reflect-metadata-utils";import{LazyServiceIdentifier as n,isPromise as s,stringifyServiceIdentifier as a}from"@inversifyjs/common";import{getClassMetadata as r,bindingTypeValues as o,bindingScopeValues as c,ResolvedValueElementMetadataKind as d,PlanResultCacheService as l,ActivationsService as u,BindingService as h,DeactivationsService as v,resolveServiceDeactivations as g,resolveModuleDeactivations as S,plan as p,resolve as b}from"@inversifyjs/core";const f="@inversifyjs/container/bindingId";class y{#e;#i;constructor(n){this.#e=function(){const n=e(Object,f)??0;return n===Number.MAX_SAFE_INTEGER?i(Object,f,Number.MIN_SAFE_INTEGER):t(Object,f,(()=>n),(e=>e+1)),n}(),this.#i=n}get id(){return this.#e}async load(e){await this.#i(e)}}class w{static always=e=>!0}const m="@inversifyjs/container/bindingId";function I(){const n=e(Object,m)??0;return n===Number.MAX_SAFE_INTEGER?i(Object,m,Number.MIN_SAFE_INTEGER):t(Object,m,(()=>n),(e=>e+1)),n}function A(e){return i=>{for(let t=i.getAncestor();void 0!==t;t=t.getAncestor())if(e(t))return!0;return!1}}function R(e){return i=>i.name===e}function P(e){return i=>i.serviceIdentifier===e}function B(e,i){return t=>t.tags.has(e)&&t.tags.get(e)===i}function C(e){return void 0===e.name&&0===e.tags.size}function M(e){const i=A(e);return e=>!i(e)}function N(e){return i=>{const t=i.getAncestor();return void 0===t||!e(t)}}function O(e){return i=>{const t=i.getAncestor();return void 0!==t&&e(t)}}class F{#t;constructor(e){this.#t=e}inRequestScope(){return this.#t.scope=c.Request,new x(this.#t)}inSingletonScope(){return this.#t.scope=c.Singleton,new x(this.#t)}inTransientScope(){return this.#t.scope=c.Transient,new x(this.#t)}}class D{#n;#s;#a;#r;constructor(e,i,t,n){this.#n=e,this.#s=i,this.#a=t,this.#r=n}to(e){const i=r(e),t={cache:{isRight:!1,value:void 0},id:I(),implementationType:e,isSatisfiedBy:w.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:i.scope??this.#a,serviceIdentifier:this.#r,type:o.Instance};return this.#n(t),new E(t)}toSelf(){if("function"!=typeof this.#r)throw new Error('"toSelf" function can only be applied when a newable function is used as service identifier');return this.to(this.#r)}toConstantValue(e){const i={cache:{isRight:!1,value:void 0},id:I(),isSatisfiedBy:w.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:c.Singleton,serviceIdentifier:this.#r,type:o.ConstantValue,value:e};return this.#n(i),new x(i)}toDynamicValue(e){const i={cache:{isRight:!1,value:void 0},id:I(),isSatisfiedBy:w.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:this.#a,serviceIdentifier:this.#r,type:o.DynamicValue,value:e};return this.#n(i),new E(i)}toResolvedValue(e,i){const t={cache:{isRight:!1,value:void 0},factory:e,id:I(),isSatisfiedBy:w.always,metadata:this.#o(i),moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:this.#a,serviceIdentifier:this.#r,type:o.ResolvedValue};return this.#n(t),new E(t)}toFactory(e){const i={cache:{isRight:!1,value:void 0},factory:e,id:I(),isSatisfiedBy:w.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,scope:c.Singleton,serviceIdentifier:this.#r,type:o.Factory};return this.#n(i),new x(i)}toProvider(e){const i={cache:{isRight:!1,value:void 0},id:I(),isSatisfiedBy:w.always,moduleId:this.#s,onActivation:void 0,onDeactivation:void 0,provider:e,scope:c.Singleton,serviceIdentifier:this.#r,type:o.Provider};return this.#n(i),new x(i)}toService(e){const i={id:I(),isSatisfiedBy:w.always,moduleId:this.#s,serviceIdentifier:this.#r,targetServiceIdentifier:e,type:o.ServiceRedirection};this.#n(i)}#o(e){return{arguments:(e??[]).map((e=>function(e){return"object"==typeof e&&!n.is(e)}(e)?{kind:!0===e.isMultiple?d.multipleInjection:d.singleInjection,name:e.name,optional:e.optional??!1,tags:new Map((e.tags??[]).map((e=>[e.key,e.value]))),value:e.serviceIdentifier}:{kind:d.singleInjection,name:void 0,optional:!1,tags:new Map,value:e}))}}}class k{#t;constructor(e){this.#t=e}onActivation(e){return this.#t.onActivation=e,new j(this.#t)}onDeactivation(e){return this.#t.onDeactivation=e,new j(this.#t)}}class j{#t;constructor(e){this.#t=e}when(e){return this.#t.isSatisfiedBy=e,new k(this.#t)}whenAnyAncestor(e){return this.when(A(e))}whenAnyAncestorIs(e){return this.when(A(P(e)))}whenAnyAncestorNamed(e){return this.when(function(e){return A(R(e))}(e))}whenAnyAncestorTagged(e,i){return this.when(function(e,i){return A(B(e,i))}(e,i))}whenDefault(){return this.when(C)}whenNamed(e){return this.when(R(e))}whenNoParent(e){return this.when(N(e))}whenNoParentIs(e){return this.when(N(P(e)))}whenNoParentNamed(e){return this.when(function(e){return N(R(e))}(e))}whenNoParentTagged(e,i){return this.when(function(e,i){return N(B(e,i))}(e,i))}whenParent(e){return this.when(O(e))}whenParentIs(e){return this.when(O(P(e)))}whenParentNamed(e){return this.when(function(e){return O(R(e))}(e))}whenParentTagged(e,i){return this.when(function(e,i){return O(B(e,i))}(e,i))}whenTagged(e,i){return this.when(B(e,i))}whenNoAncestor(e){return this.when(M(e))}whenNoAncestorIs(e){return this.when(M(P(e)))}whenNoAncestorNamed(e){return this.when(function(e){return M(R(e))}(e))}whenNoAncestorTagged(e,i){return this.when(function(e,i){return M(B(e,i))}(e,i))}}class x extends j{#c;constructor(e){super(e),this.#c=new k(e)}onActivation(e){return this.#c.onActivation(e)}onDeactivation(e){return this.#c.onDeactivation(e)}}class E extends x{#d;constructor(e){super(e),this.#d=new F(e)}inRequestScope(){return this.#d.inRequestScope()}inSingletonScope(){return this.#d.inSingletonScope()}inTransientScope(){return this.#d.inTransientScope()}}const T=Symbol.for("@inversifyjs/container/InversifyContainerError");class V extends Error{[T];kind;constructor(e,i,t){super(i,t),this[T]=!0,this.kind=e}static is(e){return"object"==typeof e&&null!==e&&!0===e[T]}static isErrorOfKind(e,i){return V.is(e)&&e.kind===i}}var _;!function(e){e[e.invalidOperation=0]="invalidOperation"}(_||(_={}));const G=c.Transient;class q{#l;#u;#h;#v;#g;#S;constructor(e){this.#g=new l,void 0===e?.parent?(this.#l=u.build(void 0),this.#u=h.build(void 0),this.#h=v.build(void 0)):(this.#l=u.build(e.parent.#l),this.#u=h.build(e.parent.#u),this.#h=v.build(e.parent.#h),e.parent.#g.subscribe(this.#g)),this.#v={autobind:e?.autobind??!1,defaultScope:e?.defaultScope??G},this.#S=[]}bind(e){return new D((e=>{this.#p(e)}),void 0,this.#v.defaultScope,e)}get(e,i){const t=this.#b(!1,e,i),n=this.#f(t);if(s(n))throw new V(_.invalidOperation,`Unexpected asyncronous service when resolving service "${a(e)}"`);return n}getAll(e,i){const t=this.#b(!0,e,i),n=this.#f(t);if(s(n))throw new V(_.invalidOperation,`Unexpected asyncronous service when resolving service "${a(e)}"`);return n}async getAllAsync(e,i){const t=this.#b(!0,e,i);return this.#f(t)}async getAsync(e,i){const t=this.#b(!1,e,i);return this.#f(t)}isBound(e,i){const t=this.#u.get(e);return this.#y(e,t,i)}isCurrentBound(e,i){const t=this.#u.getNonParentBindings(e);return this.#y(e,t,i)}async load(...e){await Promise.all(e.map((async e=>e.load(this.#w(e.id)))))}onActivation(e,i){this.#l.add(i,{serviceId:e})}onDeactivation(e,i){this.#h.add(i,{serviceId:e})}restore(){const e=this.#S.pop();if(void 0===e)throw new V(_.invalidOperation,"No snapshot available to restore");this.#l=e.activationService,this.#u=e.bindingService,this.#h=e.deactivationService,this.#g.clearCache()}snapshot(){this.#S.push({activationService:this.#l.clone(),bindingService:this.#u.clone(),deactivationService:this.#h.clone()})}async unbind(e){await g(this.#m(),e),this.#l.removeAllByServiceId(e),this.#u.removeAllByServiceId(e),this.#h.removeAllByServiceId(e),this.#g.clearCache()}async unbindAll(){const e=this.#m(),i=[...this.#u.getNonParentBoundServices()];await Promise.all(i.map((async i=>g(e,i))));for(const e of i)this.#l.removeAllByServiceId(e),this.#u.removeAllByServiceId(e),this.#h.removeAllByServiceId(e);this.#g.clearCache()}async unload(...e){const i=this.#m();await Promise.all(e.map((e=>S(i,e.id))));for(const i of e)this.#l.removeAllByModuleId(i.id),this.#u.removeAllByModuleId(i.id),this.#h.removeAllByModuleId(i.id);this.#g.clearCache()}#w(e){return{bind:i=>new D((e=>{this.#p(e)}),e,this.#v.defaultScope,i),isBound:this.isBound.bind(this),onActivation:(i,t)=>{this.#l.add(t,{moduleId:e,serviceId:i})},onDeactivation:(i,t)=>{this.#h.add(t,{moduleId:e,serviceId:i})},unbind:this.unbind.bind(this)}}#m(){return{getBindings:e=>this.#u.get(e),getBindingsFromModule:e=>this.#u.getByModuleId(e),getClassMetadata:r,getDeactivations:e=>this.#h.get(e)}}#I(e,i,t){return{isMultiple:e,name:t?.name,optional:t?.optional,serviceIdentifier:i,tag:t?.tag}}#A(e,i,t){const n={autobindOptions:t?.autobind??this.#v.autobind?{scope:this.#v.defaultScope}:void 0,getBindings:this.#u.get.bind(this.#u),getClassMetadata:r,rootConstraints:{isMultiple:e,serviceIdentifier:i},servicesBranch:new Set,setBinding:this.#p.bind(this)};return this.#R(n,t),n}#b(e,i,t){const n=this.#I(e,i,t),s=this.#g.get(n);if(void 0!==s)return s;const a=p(this.#A(e,i,t));return this.#g.set(n,a),a}#f(e){return b({context:{get:this.get.bind(this),getAll:this.getAll.bind(this),getAllAsync:this.getAllAsync.bind(this),getAsync:this.getAsync.bind(this)},getActivations:e=>this.#l.get(e),planResult:e,requestScopeCache:new Map})}#R(e,i){void 0!==i&&(void 0!==i.name&&(e.rootConstraints.name=i.name),!0===i.optional&&(e.rootConstraints.isOptional=!0),void 0!==i.tag&&(e.rootConstraints.tag={key:i.tag.key,value:i.tag.value}))}#y(e,i,t){if(void 0===i)return!1;const n={getAncestor:()=>{},name:t?.name,serviceIdentifier:e,tags:new Map};void 0!==t?.tag&&n.tags.set(t.tag.key,t.tag.value);for(const e of i)if(e.isSatisfiedBy(n))return!0;return!1}#p(e){this.#u.set(e),this.#g.clearCache()}}export{q as Container,y as ContainerModule,V as InversifyContainerError,_ as InversifyContainerErrorKind};
//# sourceMappingURL=index.js.map

@@ -9,4 +9,4 @@ {

"@inversifyjs/common": "1.5.0",
"@inversifyjs/reflect-metadata-utils": "1.1.0",
"@inversifyjs/core": "3.4.0"
"@inversifyjs/core": "3.5.0",
"@inversifyjs/reflect-metadata-utils": "1.1.0"
},

@@ -18,3 +18,3 @@ "devDependencies": {

"@stryker-mutator/typescript-checker": "8.7.1",
"@types/node": "22.10.10",
"@types/node": "22.13.0",
"eslint": "9.19.0",

@@ -24,3 +24,3 @@ "jest": "29.7.0",

"rimraf": "6.0.1",
"rollup": "4.32.0",
"rollup": "4.34.0",
"ts-loader": "9.5.2",

@@ -66,3 +66,3 @@ "ts-jest": "29.2.5",

},
"version": "1.4.2",
"version": "1.5.0",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc