+4
-1
@@ -222,2 +222,3 @@ import { AsyncLocalStorage } from 'async_hooks'; | ||
| set<T>(token: Constructor, value?: T | Scope | Options): this; | ||
| alias(token: Token, target: Constructor): this; | ||
| use(injector: any): this; | ||
@@ -392,2 +393,3 @@ get<T>(token: AlsToken<T>): T | any; | ||
| declare function has(token: Token): boolean; | ||
| declare function alias(token: Token, target: Constructor): Container; | ||
| declare function boot(services?: Constructor[]): Promise<any[]>; | ||
@@ -510,2 +512,3 @@ declare function reset(): Promise<Container>; | ||
| private cleanOptions; | ||
| alias(token: Token, target: Constructor): this; | ||
| getByName(name: string): Token | undefined; | ||
@@ -847,2 +850,2 @@ } | ||
| export { AlsStore, AlsToken, type AsyncFactory, BaseError, CLASS_TYPE, CONTROLLER, CONTROLLER_PATH, type Constructor, Container, Controller, type ControllerOptions, type CreateInjectOptions, DATABASE, DESIGN_PARAMTYPES, DESIGN_RETURNTYPE, DESIGN_TYPE, DI, DIError, DI_CODES, type DecoratorMetadata, Deleter, type Factory, FactoryWrapper, INJECTABLE, INJECTIONS, INJECT_PARAMS, INJECT_PROPS, Inject, Injectable, type InjectableOptions, type InjectableType, type InjectionDefinition, Instantiator, METADATA, Meta, MetaHelper, type Metadata, MetadataManager, type MetadataQuery, type NextFunction, type OnBootComplete, type OnDestroy, type OnInit, type Options, type PropertyInjection, type PropsInject, REPOSITORY, type RegEntryOpts, Register, type Registration, type RegistryEntry, Repository, type RepositoryOptions, Resolver, SCAN_PROPS, SCOPE, SERVICE, Scope, Service, type ServiceOptions, Store, type TStore, type Token, Value, boot, container, createAlsToken, createInject, findAll, get, getAll, getClassType, getClasses, getDatabase, getDecoratorMetadata, getDecoratorMetadataValue, getParamTypes, getParameterInjections, getPath, getPropertyInjections, getPropertyType, getReflectType, getReturnType, getScope, has, hasDecoratorMetadata, hasOnBootComplete, hasOnDestroy, hasOnInit, hasSingletonInstance, hasSingletonPending, isAlsToken, isArrayToken, isConstructor, isController, isInjectable, isNamedToken, isRegistryEntry, isRepository, isReqScope, isService, mergeMetadata, reset, resolve, set, setClassType, setInjectable, setScope }; | ||
| export { AlsStore, AlsToken, type AsyncFactory, BaseError, CLASS_TYPE, CONTROLLER, CONTROLLER_PATH, type Constructor, Container, Controller, type ControllerOptions, type CreateInjectOptions, DATABASE, DESIGN_PARAMTYPES, DESIGN_RETURNTYPE, DESIGN_TYPE, DI, DIError, DI_CODES, type DecoratorMetadata, Deleter, type Factory, FactoryWrapper, INJECTABLE, INJECTIONS, INJECT_PARAMS, INJECT_PROPS, Inject, Injectable, type InjectableOptions, type InjectableType, type InjectionDefinition, Instantiator, METADATA, Meta, MetaHelper, type Metadata, MetadataManager, type MetadataQuery, type NextFunction, type OnBootComplete, type OnDestroy, type OnInit, type Options, type PropertyInjection, type PropsInject, REPOSITORY, type RegEntryOpts, Register, type Registration, type RegistryEntry, Repository, type RepositoryOptions, Resolver, SCAN_PROPS, SCOPE, SERVICE, Scope, Service, type ServiceOptions, Store, type TStore, type Token, Value, alias, boot, container, createAlsToken, createInject, findAll, get, getAll, getClassType, getClasses, getDatabase, getDecoratorMetadata, getDecoratorMetadataValue, getParamTypes, getParameterInjections, getPath, getPropertyInjections, getPropertyType, getReflectType, getReturnType, getScope, has, hasDecoratorMetadata, hasOnBootComplete, hasOnDestroy, hasOnInit, hasSingletonInstance, hasSingletonPending, isAlsToken, isArrayToken, isConstructor, isController, isInjectable, isNamedToken, isRegistryEntry, isRepository, isReqScope, isService, mergeMetadata, reset, resolve, set, setClassType, setInjectable, setScope }; |
+31
-0
@@ -981,2 +981,9 @@ var __defProp = Object.defineProperty; | ||
| } | ||
| alias(token, target) { | ||
| this.registry.set(token, { | ||
| scope: Scope.SINGLETON, | ||
| factory: /* @__PURE__ */ __name((requestId) => this.container.resolver.resolve(target, requestId), "factory") | ||
| }); | ||
| return this; | ||
| } | ||
| getByName(name) { | ||
@@ -1081,2 +1088,8 @@ return this.nameToToken.get(name); | ||
| } | ||
| if (isRegistryEntry(value)) { | ||
| if (!hasSingletonInstance(value)) { | ||
| throw DIError.singletonNotInitialized(token); | ||
| } | ||
| return value.instance; | ||
| } | ||
| return value; | ||
@@ -1141,2 +1154,11 @@ } | ||
| } | ||
| if (isRegistryEntry(value)) { | ||
| if (hasSingletonInstance(value)) | ||
| return value.instance; | ||
| if (hasSingletonPending(value)) | ||
| return value.pending; | ||
| const pending = this.createInstance(token, value); | ||
| value.pending = pending; | ||
| return pending; | ||
| } | ||
| return value; | ||
@@ -1667,2 +1689,6 @@ } | ||
| } | ||
| alias(token, target) { | ||
| this.register.alias(token, target); | ||
| return this; | ||
| } | ||
| use(injector) { | ||
@@ -1987,2 +2013,6 @@ this.instantiator.use(injector); | ||
| __name(has, "has"); | ||
| function alias(token, target) { | ||
| return container.alias(token, target); | ||
| } | ||
| __name(alias, "alias"); | ||
| async function boot(services) { | ||
@@ -2048,2 +2078,3 @@ return await container.boot(services); | ||
| Value, | ||
| alias, | ||
| boot, | ||
@@ -2050,0 +2081,0 @@ container, |
+1
-1
| { | ||
| "name": "diject", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "description": "Lightweight TypeScript DI container with decorators, scopes, metadata queries, and AsyncLocalStorage support.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
108843
0.99%2919
1.18%