ts-ioc-container 71.0.0 → 72.0.0
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.
- package/README.md +109 -65
- package/cjm/container/Container.js +5 -5
- package/cjm/hooks/HookContext.js +3 -2
- package/cjm/hooks/injectProp.js +2 -4
- package/cjm/index.js +3 -3
- package/cjm/injector/IInjector.js +2 -2
- package/cjm/injector/MetadataInjector.js +14 -9
- package/cjm/injector/ProxyInjector.js +1 -1
- package/cjm/injector/SimpleInjector.js +2 -2
- package/cjm/provider/Provider.js +9 -8
- package/cjm/registration/IRegistration.js +2 -2
- package/cjm/select.js +2 -2
- package/cjm/token/ClassToken.js +3 -3
- package/cjm/token/FunctionToken.js +5 -4
- package/cjm/token/GroupAliasToken.js +3 -3
- package/cjm/token/InjectionToken.js +1 -1
- package/cjm/token/SingleAliasToken.js +3 -3
- package/cjm/token/SingleToken.js +3 -3
- package/cjm/token/toToken.js +1 -8
- package/esm/container/Container.js +5 -5
- package/esm/hooks/HookContext.js +3 -2
- package/esm/hooks/injectProp.js +1 -4
- package/esm/index.js +2 -2
- package/esm/injector/IInjector.js +2 -2
- package/esm/injector/MetadataInjector.js +13 -9
- package/esm/injector/ProxyInjector.js +1 -1
- package/esm/injector/SimpleInjector.js +2 -2
- package/esm/provider/Provider.js +9 -8
- package/esm/registration/IRegistration.js +2 -2
- package/esm/select.js +2 -2
- package/esm/token/ClassToken.js +3 -3
- package/esm/token/FunctionToken.js +5 -4
- package/esm/token/GroupAliasToken.js +3 -3
- package/esm/token/InjectionToken.js +1 -1
- package/esm/token/SingleAliasToken.js +3 -3
- package/esm/token/SingleToken.js +3 -3
- package/esm/token/toToken.js +0 -6
- package/package.json +1 -1
- package/typings/container/IContainer.d.ts +2 -2
- package/typings/hooks/HookContext.d.ts +3 -3
- package/typings/hooks/hook.d.ts +1 -2
- package/typings/hooks/injectProp.d.ts +2 -14
- package/typings/index.d.ts +4 -4
- package/typings/injector/IInjector.d.ts +7 -4
- package/typings/injector/MetadataInjector.d.ts +6 -16
- package/typings/injector/ProxyInjector.d.ts +1 -2
- package/typings/injector/SimpleInjector.d.ts +1 -2
- package/typings/provider/IProvider.d.ts +5 -4
- package/typings/provider/Provider.d.ts +2 -2
- package/typings/select.d.ts +3 -3
- package/typings/token/ClassToken.d.ts +2 -2
- package/typings/token/FunctionToken.d.ts +2 -2
- package/typings/token/GroupAliasToken.d.ts +2 -2
- package/typings/token/InjectionToken.d.ts +2 -2
- package/typings/token/SingleAliasToken.d.ts +3 -3
- package/typings/token/SingleToken.d.ts +2 -2
- package/typings/token/toToken.d.ts +0 -2
|
@@ -11,15 +11,16 @@ export class FunctionToken extends InjectionToken {
|
|
|
11
11
|
this._isLazy = isLazy;
|
|
12
12
|
}
|
|
13
13
|
resolve(s, { args = [], lazy } = {}) {
|
|
14
|
-
return this.fn(
|
|
15
|
-
|
|
14
|
+
return this.fn({
|
|
15
|
+
scope: s,
|
|
16
|
+
args: this._getArgsFn({ scope: s, args }),
|
|
16
17
|
lazy: this._isLazy || lazy,
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
args(...newArgs) {
|
|
20
21
|
const parentFn = this._getArgsFn;
|
|
21
22
|
return new FunctionToken(this.fn, {
|
|
22
|
-
getArgsFn: (
|
|
23
|
+
getArgsFn: (options) => [...parentFn(options), ...newArgs],
|
|
23
24
|
isLazy: this._isLazy,
|
|
24
25
|
tags: this.getTags(),
|
|
25
26
|
});
|
|
@@ -27,7 +28,7 @@ export class FunctionToken extends InjectionToken {
|
|
|
27
28
|
argsFn(fn) {
|
|
28
29
|
const parentFn = this._getArgsFn;
|
|
29
30
|
return new FunctionToken(this.fn, {
|
|
30
|
-
getArgsFn: (
|
|
31
|
+
getArgsFn: (options) => [...parentFn(options), ...fn(options.scope)],
|
|
31
32
|
isLazy: this._isLazy,
|
|
32
33
|
tags: this.getTags(),
|
|
33
34
|
});
|
|
@@ -14,7 +14,7 @@ export class GroupAliasToken extends InjectionToken {
|
|
|
14
14
|
}
|
|
15
15
|
resolve(s, { args = [], lazy } = {}) {
|
|
16
16
|
return s.resolveByAlias(this.token, {
|
|
17
|
-
args: this._getArgsFn(s,
|
|
17
|
+
args: this._getArgsFn({ scope: s, args }),
|
|
18
18
|
lazy: this._isLazy || lazy,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -24,7 +24,7 @@ export class GroupAliasToken extends InjectionToken {
|
|
|
24
24
|
args(...newArgs) {
|
|
25
25
|
const parentFn = this._getArgsFn;
|
|
26
26
|
return new GroupAliasToken(this.token, {
|
|
27
|
-
getArgsFn: (
|
|
27
|
+
getArgsFn: (options) => [...parentFn(options), ...newArgs],
|
|
28
28
|
isLazy: this._isLazy,
|
|
29
29
|
tags: this.getTags(),
|
|
30
30
|
});
|
|
@@ -32,7 +32,7 @@ export class GroupAliasToken extends InjectionToken {
|
|
|
32
32
|
argsFn(fn) {
|
|
33
33
|
const parentFn = this._getArgsFn;
|
|
34
34
|
return new GroupAliasToken(this.token, {
|
|
35
|
-
getArgsFn: (
|
|
35
|
+
getArgsFn: (options) => [...parentFn(options), ...fn(options.scope)],
|
|
36
36
|
isLazy: this._isLazy,
|
|
37
37
|
tags: this.getTags(),
|
|
38
38
|
});
|
|
@@ -14,7 +14,7 @@ export class SingleAliasToken extends InjectionToken {
|
|
|
14
14
|
}
|
|
15
15
|
resolve(s, { args = [], lazy } = {}) {
|
|
16
16
|
return s.resolveOneByAlias(this.token, {
|
|
17
|
-
args: this._getArgsFn(s,
|
|
17
|
+
args: this._getArgsFn({ scope: s, args }),
|
|
18
18
|
lazy: this._isLazy || lazy,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -24,7 +24,7 @@ export class SingleAliasToken extends InjectionToken {
|
|
|
24
24
|
args(...newArgs) {
|
|
25
25
|
const parentFn = this._getArgsFn;
|
|
26
26
|
return new SingleAliasToken(this.token, {
|
|
27
|
-
getArgsFn: (
|
|
27
|
+
getArgsFn: (options) => [...parentFn(options), ...newArgs],
|
|
28
28
|
isLazy: this._isLazy,
|
|
29
29
|
tags: this.getTags(),
|
|
30
30
|
});
|
|
@@ -32,7 +32,7 @@ export class SingleAliasToken extends InjectionToken {
|
|
|
32
32
|
argsFn(fn) {
|
|
33
33
|
const parentFn = this._getArgsFn;
|
|
34
34
|
return new SingleAliasToken(this.token, {
|
|
35
|
-
getArgsFn: (
|
|
35
|
+
getArgsFn: (options) => [...parentFn(options), ...fn(options.scope)],
|
|
36
36
|
isLazy: this._isLazy,
|
|
37
37
|
tags: this.getTags(),
|
|
38
38
|
});
|
package/esm/token/SingleToken.js
CHANGED
|
@@ -14,7 +14,7 @@ export class SingleToken extends InjectionToken {
|
|
|
14
14
|
}
|
|
15
15
|
resolve(s, { args = [], lazy } = {}) {
|
|
16
16
|
return s.resolve(this.token, {
|
|
17
|
-
args: this._getArgsFn(s,
|
|
17
|
+
args: this._getArgsFn({ scope: s, args }),
|
|
18
18
|
lazy: this._isLazy || lazy,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -24,7 +24,7 @@ export class SingleToken extends InjectionToken {
|
|
|
24
24
|
args(...newArgs) {
|
|
25
25
|
const parentFn = this._getArgsFn;
|
|
26
26
|
return new SingleToken(this.token, {
|
|
27
|
-
getArgsFn: (
|
|
27
|
+
getArgsFn: (options) => [...parentFn(options), ...newArgs],
|
|
28
28
|
isLazy: this._isLazy,
|
|
29
29
|
tags: this.getTags(),
|
|
30
30
|
});
|
|
@@ -32,7 +32,7 @@ export class SingleToken extends InjectionToken {
|
|
|
32
32
|
argsFn(fn) {
|
|
33
33
|
const parentFn = this._getArgsFn;
|
|
34
34
|
return new SingleToken(this.token, {
|
|
35
|
-
getArgsFn: (
|
|
35
|
+
getArgsFn: (options) => [...parentFn(options), ...fn(options.scope)],
|
|
36
36
|
isLazy: this._isLazy,
|
|
37
37
|
tags: this.getTags(),
|
|
38
38
|
});
|
package/esm/token/toToken.js
CHANGED
|
@@ -6,7 +6,6 @@ import { UnsupportedTokenTypeError } from '../errors/UnsupportedTokenTypeError.j
|
|
|
6
6
|
import { InjectionToken, isInjectionToken } from './InjectionToken.js';
|
|
7
7
|
import { Is } from '../utils/basic.js';
|
|
8
8
|
import { ConstantToken } from './ConstantToken.js';
|
|
9
|
-
import { pipe } from '../utils/fp.js';
|
|
10
9
|
export const toToken = (token) => {
|
|
11
10
|
if (token instanceof InjectionToken) {
|
|
12
11
|
return token;
|
|
@@ -23,8 +22,3 @@ export const toToken = (token) => {
|
|
|
23
22
|
throw new UnsupportedTokenTypeError(`Unknown token ${token}`);
|
|
24
23
|
};
|
|
25
24
|
export const argToToken = (v) => (isInjectionToken(v) ? v : new ConstantToken(v));
|
|
26
|
-
export const toMappedToken = (token, mappers) => {
|
|
27
|
-
const source = toToken(token);
|
|
28
|
-
const mapInstance = pipe(...mappers);
|
|
29
|
-
return new FunctionToken((scope, options) => mapInstance(source.resolve(scope, options)));
|
|
30
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "72.0.0",
|
|
4
4
|
"description": "Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IProvider,
|
|
1
|
+
import { type IProvider, ResolveOptions } from '../provider/IProvider.js';
|
|
2
2
|
import { type IRegistration } from '../registration/IRegistration.js';
|
|
3
3
|
import { IInjector, type WithArgs } from '../injector/IInjector.js';
|
|
4
4
|
import { type constructor, Instance } from '../utils/basic.js';
|
|
@@ -19,7 +19,7 @@ export interface Tagged {
|
|
|
19
19
|
hasTag(tag: Tag): boolean;
|
|
20
20
|
addTags(...tags: Tag[]): void;
|
|
21
21
|
}
|
|
22
|
-
export type ResolveOneOptions =
|
|
22
|
+
export type ResolveOneOptions = ResolveOptions & Partial<WithChild>;
|
|
23
23
|
export type ResolveManyOptions = ResolveOneOptions & Partial<WithExcludedKeys>;
|
|
24
24
|
export interface Resolvable {
|
|
25
25
|
resolve<T>(key: constructor<T> | DependencyKey, options?: ResolveOneOptions): T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IContainer } from '../container/IContainer.js';
|
|
2
|
-
import { InjectionToken } from '../token/InjectionToken.js';
|
|
3
2
|
import { type Instance } from '../utils/basic.js';
|
|
3
|
+
import { type InjectFn } from './hook.js';
|
|
4
4
|
export interface IHookContext {
|
|
5
5
|
instance: Instance;
|
|
6
6
|
scope: IContainer;
|
|
@@ -9,7 +9,7 @@ export interface IHookContext {
|
|
|
9
9
|
invokeMethod(options?: {
|
|
10
10
|
args?: unknown[];
|
|
11
11
|
}): unknown;
|
|
12
|
-
setProperty(fn:
|
|
12
|
+
setProperty(fn: InjectFn): void;
|
|
13
13
|
getProperty(): unknown;
|
|
14
14
|
setInitialArgs(...args: unknown[]): this;
|
|
15
15
|
getInitialArgs(): unknown[];
|
|
@@ -24,7 +24,7 @@ export declare class HookContext implements IHookContext {
|
|
|
24
24
|
invokeMethod({ args }?: {
|
|
25
25
|
args?: unknown[];
|
|
26
26
|
}): unknown;
|
|
27
|
-
setProperty(fn:
|
|
27
|
+
setProperty(fn: InjectFn): void;
|
|
28
28
|
getProperty(): unknown;
|
|
29
29
|
setInitialArgs(...args: unknown[]): this;
|
|
30
30
|
getInitialArgs(): unknown[];
|
package/typings/hooks/hook.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type IHookContext } from './HookContext.js';
|
|
2
|
-
import type { IContainer } from '../container/IContainer.js';
|
|
3
2
|
import { type constructor, type Instance } from '../utils/basic.js';
|
|
4
3
|
import { ProviderOptions } from '../provider/IProvider.js';
|
|
5
|
-
export type InjectFn<T = unknown> = (
|
|
4
|
+
export type InjectFn<T = unknown> = (options: ProviderOptions) => T;
|
|
6
5
|
export type HookFn<T extends IHookContext = IHookContext> = (context: T) => void | Promise<void>;
|
|
7
6
|
export interface HookClass<T extends IHookContext = IHookContext> {
|
|
8
7
|
execute(context: Omit<T, 'scope'>): void | Promise<void>;
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
import { HookFn } from './hook.js';
|
|
2
|
-
|
|
3
|
-
import { type MapFn } from '../utils/fp.js';
|
|
4
|
-
export declare function injectProp<T, B>(fn: Injectable<T>, fn1: MapFn<T, B>): HookFn;
|
|
5
|
-
export declare function injectProp<T, B, C>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>): HookFn;
|
|
6
|
-
export declare function injectProp<T, B, C, D>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>): HookFn;
|
|
7
|
-
export declare function injectProp<T, B, C, D, E>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>): HookFn;
|
|
8
|
-
export declare function injectProp<T, B, C, D, E, F>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>): HookFn;
|
|
9
|
-
export declare function injectProp<T, B, C, D, E, F, G>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>): HookFn;
|
|
10
|
-
export declare function injectProp<T, B, C, D, E, F, G, H>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>): HookFn;
|
|
11
|
-
export declare function injectProp<T, B, C, D, E, F, G, H, I>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>, fn8: MapFn<H, I>): HookFn;
|
|
12
|
-
export declare function injectProp<T, B, C, D, E, F, G, H, I, J>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>, fn8: MapFn<H, I>, fn9: MapFn<I, J>): HookFn;
|
|
13
|
-
export declare function injectProp<T, B, C, D, E, F, G, H, I, J, K>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>, fn8: MapFn<H, I>, fn9: MapFn<I, J>, fn10: MapFn<J, K>): HookFn;
|
|
14
|
-
export declare function injectProp<T>(fn: Injectable<T>, ...mappers: MapFn<T>[]): HookFn;
|
|
1
|
+
import { HookFn, InjectFn } from './hook.js';
|
|
2
|
+
export declare const injectProp: <T>(fn: InjectFn<T>) => HookFn;
|
package/typings/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export { type IContainer, type Resolvable, type IContainerModule, type Dependenc
|
|
|
2
2
|
export { Container } from './container/Container.js';
|
|
3
3
|
export { AutoResolveModule } from './container/AutoResolveModule.js';
|
|
4
4
|
export { EmptyContainer } from './container/EmptyContainer.js';
|
|
5
|
-
export { type IInjector, type InjectOptions, type IInjectFnResolver, type IInjectorModule, type InjectorHook, Injector, } from './injector/IInjector.js';
|
|
6
|
-
export { MetadataInjector, inject, arg, args, argsFn, resolveArgs } from './injector/MetadataInjector.js';
|
|
5
|
+
export { type IInjector, type InjectOptions, type WithScope, type WithArgs, type IInjectFnResolver, type IInjectorModule, type InjectorHook, Injector, } from './injector/IInjector.js';
|
|
6
|
+
export { MetadataInjector, inject, arg, args, argsFn, by, resolveArgs } from './injector/MetadataInjector.js';
|
|
7
7
|
export { SimpleInjector } from './injector/SimpleInjector.js';
|
|
8
8
|
export { ProxyInjector } from './injector/ProxyInjector.js';
|
|
9
|
-
export { type ResolveDependency, type IProvider, type DecorateFn, type ArgsFn, type ProviderOptions, type GetCacheKey, type ScopeAccessOptions, type ScopeAccessRule, type ProviderHook, } from './provider/IProvider.js';
|
|
9
|
+
export { type ResolveDependency, type IProvider, type DecorateFn, type ArgsFn, type ProviderOptions, type ResolveOptions, type GetCacheKey, type ScopeAccessOptions, type ScopeAccessRule, type ProviderHook, } from './provider/IProvider.js';
|
|
10
10
|
export { Provider } from './provider/Provider.js';
|
|
11
11
|
export { type IRegistration, type ReturnTypeOfRegistration, type ScopeMatchRule, type ProviderPipe, type Bindable, type ProviderMapper, type RegistrationMapper, isProviderPipe, registerPipe, toBindToken, toProviderFn, toRegistrationFn, register, bindTo, scope, scopeAccess, lazy, autoResolve, singleton, decorate, appendArgs, appendArgsFn, onResolve, } from './registration/IRegistration.js';
|
|
12
12
|
export { Registration } from './registration/Registration.js';
|
|
@@ -27,7 +27,7 @@ export { injectProp } from './hooks/injectProp.js';
|
|
|
27
27
|
export { sequential, parallel, oncePerInstance, type ResolvedObjectHook } from './hooks/combinators.js';
|
|
28
28
|
export { HookCollector, toTask, type HookAction, type HookCollectionContext, type HookCollectorOptions, type HookCollectorProps, type MapHookExecutionContext, } from './hooks/HookCollector.js';
|
|
29
29
|
export { InjectionToken, isInjectionToken, forwardArgs } from './token/InjectionToken.js';
|
|
30
|
-
export { type Injectable, toToken,
|
|
30
|
+
export { type Injectable, toToken, argToToken } from './token/toToken.js';
|
|
31
31
|
export { GroupAliasToken, toGroupAlias } from './token/GroupAliasToken.js';
|
|
32
32
|
export { SingleAliasToken, toSingleAlias } from './token/SingleAliasToken.js';
|
|
33
33
|
export { ClassToken } from './token/ClassToken.js';
|
|
@@ -2,13 +2,16 @@ import { type IContainer, ResolveOneOptions } from '../container/IContainer.js';
|
|
|
2
2
|
import { ProviderOptions } from '../provider/IProvider.js';
|
|
3
3
|
import { type IProxyRegistry } from '../utils/ProxyRegistry.js';
|
|
4
4
|
import { type constructor, Instance } from '../utils/basic.js';
|
|
5
|
+
export type WithScope = {
|
|
6
|
+
scope: IContainer;
|
|
7
|
+
};
|
|
5
8
|
export type WithArgs = {
|
|
6
9
|
args: unknown[];
|
|
7
10
|
};
|
|
8
|
-
export type InjectOptions = Partial<WithArgs>;
|
|
11
|
+
export type InjectOptions = WithScope & Partial<WithArgs>;
|
|
9
12
|
export type InjectorHook = (instance: Instance, scope: IContainer) => void;
|
|
10
13
|
export interface IInjector {
|
|
11
|
-
resolve<T>(
|
|
14
|
+
resolve<T>(Target: constructor<T>, options: ProviderOptions): T;
|
|
12
15
|
onConstructed(...hooks: InjectorHook[]): this;
|
|
13
16
|
}
|
|
14
17
|
export interface IInjectorModule {
|
|
@@ -21,8 +24,8 @@ export declare abstract class Injector {
|
|
|
21
24
|
private readonly proxyRegistry;
|
|
22
25
|
private readonly onConstructedHookList;
|
|
23
26
|
constructor(proxyRegistry?: IProxyRegistry);
|
|
24
|
-
resolve<T>(
|
|
27
|
+
resolve<T>(Target: constructor<T>, { scope, args, lazy }: ProviderOptions): T;
|
|
25
28
|
onConstructed(...hooks: InjectorHook[]): this;
|
|
26
29
|
useModule(module: IInjectorModule): this;
|
|
27
|
-
protected abstract createInstance<T>(
|
|
30
|
+
protected abstract createInstance<T>(Target: constructor<T>, options: InjectOptions): T;
|
|
28
31
|
}
|
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
import { IInjector, InjectOptions, Injector } from './IInjector.js';
|
|
2
|
-
import type { IContainer } from '../container/IContainer.js';
|
|
3
2
|
import { type constructor, type Instance } from '../utils/basic.js';
|
|
4
3
|
import { ProviderOptions } from '../provider/IProvider.js';
|
|
5
|
-
import { type Injectable } from '../token/toToken.js';
|
|
6
4
|
import { InjectFn } from '../hooks/hook.js';
|
|
7
|
-
import { type
|
|
5
|
+
import { type DependencyKey } from '../container/IContainer.js';
|
|
6
|
+
import { type InjectionToken } from '../token/InjectionToken.js';
|
|
8
7
|
export declare class MetadataInjector extends Injector implements IInjector {
|
|
9
|
-
protected createInstance<T>(
|
|
8
|
+
protected createInstance<T>(Target: constructor<T>, { scope, args: deps }: InjectOptions): T;
|
|
10
9
|
}
|
|
11
|
-
export declare function inject<T
|
|
12
|
-
export declare
|
|
13
|
-
export declare function inject<T, B, C, D>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>): ParameterDecorator;
|
|
14
|
-
export declare function inject<T, B, C, D, E>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>): ParameterDecorator;
|
|
15
|
-
export declare function inject<T, B, C, D, E, F>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>): ParameterDecorator;
|
|
16
|
-
export declare function inject<T, B, C, D, E, F, G>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>): ParameterDecorator;
|
|
17
|
-
export declare function inject<T, B, C, D, E, F, G, H>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>): ParameterDecorator;
|
|
18
|
-
export declare function inject<T, B, C, D, E, F, G, H, I>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>, fn8: MapFn<H, I>): ParameterDecorator;
|
|
19
|
-
export declare function inject<T, B, C, D, E, F, G, H, I, J>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>, fn8: MapFn<H, I>, fn9: MapFn<I, J>): ParameterDecorator;
|
|
20
|
-
export declare function inject<T, B, C, D, E, F, G, H, I, J, K>(fn: Injectable<T>, fn1: MapFn<T, B>, fn2: MapFn<B, C>, fn3: MapFn<C, D>, fn4: MapFn<D, E>, fn5: MapFn<E, F>, fn6: MapFn<F, G>, fn7: MapFn<G, H>, fn8: MapFn<H, I>, fn9: MapFn<I, J>, fn10: MapFn<J, K>): ParameterDecorator;
|
|
21
|
-
export declare function inject<T>(fn: Injectable<T>, ...mappers: MapFn<T>[]): ParameterDecorator;
|
|
10
|
+
export declare function inject<T>(fn: InjectFn<T>): ParameterDecorator;
|
|
11
|
+
export declare const by: <T>(target: InjectionToken<T> | DependencyKey | constructor<T>) => InjectFn<T>;
|
|
22
12
|
export declare const argsFn: <T = unknown>(predicate: (value: unknown, index: number) => boolean) => InjectFn<T>;
|
|
23
13
|
export declare const arg: <T = unknown>(index: number) => InjectFn<T>;
|
|
24
14
|
export declare const args: InjectFn<unknown[]>;
|
|
25
|
-
export declare const resolveArgs: (target: constructor<unknown> | Instance, methodName?: string) => (
|
|
15
|
+
export declare const resolveArgs: (target: constructor<unknown> | Instance, methodName?: string) => (options: ProviderOptions) => unknown[];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IInjector, InjectOptions, Injector } from './IInjector.js';
|
|
2
|
-
import type { IContainer } from '../container/IContainer.js';
|
|
3
2
|
import { type constructor } from '../utils/basic.js';
|
|
4
3
|
export declare class ProxyInjector extends Injector implements IInjector {
|
|
5
|
-
protected createInstance<T>(
|
|
4
|
+
protected createInstance<T>(Target: constructor<T>, { scope, args }: InjectOptions): T;
|
|
6
5
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IInjector, InjectOptions, Injector } from './IInjector.js';
|
|
2
|
-
import type { IContainer } from '../container/IContainer.js';
|
|
3
2
|
import { type constructor } from '../utils/basic.js';
|
|
4
3
|
export declare class SimpleInjector extends Injector implements IInjector {
|
|
5
|
-
protected createInstance<T>(
|
|
4
|
+
protected createInstance<T>(Target: constructor<T>, { scope, args }: InjectOptions): T;
|
|
6
5
|
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { IContainer, Tagged } from '../container/IContainer.js';
|
|
2
|
-
import { InjectOptions } from '../injector/IInjector.js';
|
|
2
|
+
import { InjectOptions, WithScope } from '../injector/IInjector.js';
|
|
3
3
|
import { Serializable } from '../utils/basic.js';
|
|
4
4
|
export type WithLazy = {
|
|
5
5
|
lazy: boolean;
|
|
6
6
|
};
|
|
7
7
|
export type ProviderOptions = InjectOptions & Partial<WithLazy>;
|
|
8
|
-
export type
|
|
8
|
+
export type ResolveOptions = Omit<ProviderOptions, keyof WithScope>;
|
|
9
|
+
export type ResolveDependency<T = unknown> = (options: ProviderOptions) => T;
|
|
9
10
|
export type ScopeAccessOptions = {
|
|
10
11
|
invocationScope: Tagged;
|
|
11
12
|
providerScope: Tagged;
|
|
12
13
|
args: unknown[];
|
|
13
14
|
};
|
|
14
15
|
export type ScopeAccessRule = (options: ScopeAccessOptions, prev: boolean) => boolean;
|
|
15
|
-
export type ArgsFn = (
|
|
16
|
+
export type ArgsFn = (options: InjectOptions) => unknown[];
|
|
16
17
|
export type GetCacheKey = (args: unknown[]) => string | Serializable;
|
|
17
18
|
export type DecorateFn<Instance = any> = (dep: Instance, scope: IContainer) => Instance;
|
|
18
19
|
export type ProviderHook = (dependency: unknown, scope: IContainer) => void;
|
|
19
20
|
export interface IProvider<T = any> {
|
|
20
|
-
resolve(
|
|
21
|
+
resolve(options: ProviderOptions): T;
|
|
21
22
|
hasAccess(options: ScopeAccessOptions): boolean;
|
|
22
23
|
map(...mappers: DecorateFn<T>[]): this;
|
|
23
24
|
addAccessRule(...rules: ScopeAccessRule[]): this;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ArgsFn, type DecorateFn, type GetCacheKey, type IProvider, type ProviderOptions, type ResolveDependency, type ScopeAccessOptions, type ScopeAccessRule, type ProviderHook } from './IProvider.js';
|
|
2
|
-
import type { DependencyKey
|
|
2
|
+
import type { DependencyKey } from '../container/IContainer.js';
|
|
3
3
|
import { type constructor } from '../utils/basic.js';
|
|
4
4
|
export declare class Provider<T = any> implements IProvider<T> {
|
|
5
5
|
private readonly resolveDependency;
|
|
@@ -16,7 +16,7 @@ export declare class Provider<T = any> implements IProvider<T> {
|
|
|
16
16
|
private isDisposed;
|
|
17
17
|
private readonly onResolvedHookList;
|
|
18
18
|
constructor(resolveDependency: ResolveDependency<T>);
|
|
19
|
-
resolve(
|
|
19
|
+
resolve(options: ProviderOptions): T;
|
|
20
20
|
private resolveDep;
|
|
21
21
|
map(...mappers: DecorateFn<T>[]): this;
|
|
22
22
|
addAccessRule(...rules: ScopeAccessRule[]): this;
|
package/typings/select.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CreateScopeOptions
|
|
1
|
+
import { type CreateScopeOptions } from './container/IContainer.js';
|
|
2
2
|
import { FunctionToken } from './token/FunctionToken.js';
|
|
3
3
|
import { GroupInstanceToken, InstancePredicate } from './token/GroupInstanceToken.js';
|
|
4
4
|
export declare const select: {
|
|
@@ -6,7 +6,7 @@ export declare const select: {
|
|
|
6
6
|
token: <T = any>(token: import("./token/toToken.js").Injectable<T>) => import(".").InjectionToken<T>;
|
|
7
7
|
instances: (predicate?: InstancePredicate) => GroupInstanceToken;
|
|
8
8
|
scope: {
|
|
9
|
-
current: FunctionToken<IContainer>;
|
|
10
|
-
create: (options: CreateScopeOptions) => FunctionToken<IContainer>;
|
|
9
|
+
current: FunctionToken<import("./container/IContainer.js").IContainer>;
|
|
10
|
+
create: (options: CreateScopeOptions) => FunctionToken<import("./container/IContainer.js").IContainer>;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { type constructor, Serializable } from '../utils/basic.js';
|
|
4
|
-
import { ArgsFn,
|
|
4
|
+
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
5
5
|
export declare class ClassToken<T = any> extends InjectionToken<T> implements Serializable {
|
|
6
6
|
private readonly target;
|
|
7
7
|
private readonly _getArgsFn;
|
|
@@ -12,7 +12,7 @@ export declare class ClassToken<T = any> extends InjectionToken<T> implements Se
|
|
|
12
12
|
tags?: string[];
|
|
13
13
|
});
|
|
14
14
|
select<R>(fn: (target: T) => R): (s: IContainer) => R;
|
|
15
|
-
resolve(s: IContainer, { args, lazy }?:
|
|
15
|
+
resolve(s: IContainer, { args, lazy }?: ResolveOptions): T;
|
|
16
16
|
args(...newArgs: unknown[]): ClassToken<T>;
|
|
17
17
|
argsFn(fn: (s: IContainer) => unknown[]): ClassToken<T>;
|
|
18
18
|
lazy(): ClassToken<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { InjectFn } from '../hooks/hook.js';
|
|
4
|
-
import { ArgsFn,
|
|
4
|
+
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
5
5
|
import { Serializable } from '../utils/basic.js';
|
|
6
6
|
export declare class FunctionToken<T = any> extends InjectionToken<T> implements Serializable {
|
|
7
7
|
private readonly fn;
|
|
@@ -12,7 +12,7 @@ export declare class FunctionToken<T = any> extends InjectionToken<T> implements
|
|
|
12
12
|
isLazy?: boolean;
|
|
13
13
|
tags?: string[];
|
|
14
14
|
});
|
|
15
|
-
resolve(s: IContainer, { args, lazy }?:
|
|
15
|
+
resolve(s: IContainer, { args, lazy }?: ResolveOptions): T;
|
|
16
16
|
args(...newArgs: unknown[]): InjectionToken<T>;
|
|
17
17
|
argsFn(fn: (s: IContainer) => unknown[]): InjectionToken<T>;
|
|
18
18
|
lazy(): InjectionToken<T>;
|
|
@@ -2,7 +2,7 @@ import { DependencyKey, IContainer } from '../container/IContainer.js';
|
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { IRegistration } from '../registration/IRegistration.js';
|
|
4
4
|
import { BindToken } from './BindToken.js';
|
|
5
|
-
import { ArgsFn,
|
|
5
|
+
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
6
6
|
import { Serializable } from '../utils/basic.js';
|
|
7
7
|
export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implements BindToken<T>, Serializable {
|
|
8
8
|
readonly token: DependencyKey;
|
|
@@ -14,7 +14,7 @@ export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implem
|
|
|
14
14
|
tags?: string[];
|
|
15
15
|
});
|
|
16
16
|
select<R>(fn: (target: T[]) => R[]): (s: IContainer) => R[];
|
|
17
|
-
resolve(s: IContainer, { args, lazy }?:
|
|
17
|
+
resolve(s: IContainer, { args, lazy }?: ResolveOptions): T[];
|
|
18
18
|
bindTo(r: IRegistration<T>): void;
|
|
19
19
|
args(...newArgs: unknown[]): GroupAliasToken<T>;
|
|
20
20
|
argsFn(fn: (s: IContainer) => unknown[]): GroupAliasToken<T>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type IContainer, type Tag } from '../container/IContainer.js';
|
|
2
|
-
import { ArgsFn,
|
|
2
|
+
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
3
3
|
export declare const forwardArgs: ArgsFn;
|
|
4
4
|
export declare abstract class InjectionToken<T = any> {
|
|
5
5
|
private readonly tags;
|
|
6
6
|
protected constructor(tags?: Tag[]);
|
|
7
|
-
abstract resolve(s: IContainer, options?:
|
|
7
|
+
abstract resolve(s: IContainer, options?: ResolveOptions): T;
|
|
8
8
|
abstract args(...deps: unknown[]): InjectionToken<T>;
|
|
9
9
|
abstract argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<T>;
|
|
10
10
|
abstract lazy(): InjectionToken<T>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DependencyKey, IContainer
|
|
1
|
+
import { DependencyKey, IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { IRegistration } from '../registration/IRegistration.js';
|
|
4
4
|
import { BindToken } from './BindToken.js';
|
|
5
|
-
import { ArgsFn } from '../provider/IProvider.js';
|
|
5
|
+
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
6
6
|
import { Serializable } from '../utils/basic.js';
|
|
7
7
|
export declare class SingleAliasToken<T = any> extends InjectionToken<T> implements BindToken<T>, Serializable {
|
|
8
8
|
readonly token: DependencyKey;
|
|
@@ -14,7 +14,7 @@ export declare class SingleAliasToken<T = any> extends InjectionToken<T> impleme
|
|
|
14
14
|
tags?: string[];
|
|
15
15
|
});
|
|
16
16
|
select<R>(fn: (target: T) => R): (s: IContainer) => R;
|
|
17
|
-
resolve(s: IContainer, { args, lazy }?:
|
|
17
|
+
resolve(s: IContainer, { args, lazy }?: ResolveOptions): T;
|
|
18
18
|
bindTo(r: IRegistration<T>): void;
|
|
19
19
|
args(...newArgs: unknown[]): SingleAliasToken<T>;
|
|
20
20
|
argsFn(fn: (s: IContainer) => unknown[]): SingleAliasToken<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DependencyKey, IContainer } from '../container/IContainer.js';
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { IRegistration } from '../registration/IRegistration.js';
|
|
4
|
-
import { ArgsFn,
|
|
4
|
+
import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
|
|
5
5
|
import { Serializable } from '../utils/basic.js';
|
|
6
6
|
export declare class SingleToken<T = any> extends InjectionToken<T> implements Serializable {
|
|
7
7
|
token: DependencyKey;
|
|
@@ -13,7 +13,7 @@ export declare class SingleToken<T = any> extends InjectionToken<T> implements S
|
|
|
13
13
|
tags?: string[];
|
|
14
14
|
});
|
|
15
15
|
select<R>(fn: (target: T) => R): (s: IContainer) => R;
|
|
16
|
-
resolve(s: IContainer, { args, lazy }?:
|
|
16
|
+
resolve(s: IContainer, { args, lazy }?: ResolveOptions): T;
|
|
17
17
|
bindTo(r: IRegistration<T>): void;
|
|
18
18
|
args(...newArgs: unknown[]): SingleToken<T>;
|
|
19
19
|
argsFn(fn: (s: IContainer) => unknown[]): SingleToken<T>;
|
|
@@ -2,8 +2,6 @@ import { DependencyKey } from '../container/IContainer.js';
|
|
|
2
2
|
import { InjectionToken } from './InjectionToken.js';
|
|
3
3
|
import { InjectFn } from '../hooks/hook.js';
|
|
4
4
|
import { type constructor } from '../utils/basic.js';
|
|
5
|
-
import { type MapFn } from '../utils/fp.js';
|
|
6
5
|
export type Injectable<T = any> = InjectFn<T> | InjectionToken<T> | DependencyKey | constructor<T>;
|
|
7
6
|
export declare const toToken: <T = any>(token: Injectable<T>) => InjectionToken<T>;
|
|
8
7
|
export declare const argToToken: <T = unknown>(v: T) => InjectionToken<T>;
|
|
9
|
-
export declare const toMappedToken: <T = any, R = T>(token: Injectable<T>, mappers: MapFn<any, any>[]) => InjectionToken<R>;
|