ts-ioc-container 32.6.1 → 32.7.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/cjm/provider/DecoratorProvider.js +1 -1
- package/cjm/provider/IProvider.js +2 -2
- package/cjm/provider/Provider.js +6 -2
- package/cjm/provider/singleton/SingletonProvider.js +1 -1
- package/cjm/utils.js +3 -6
- package/esm/provider/DecoratorProvider.js +1 -1
- package/esm/provider/IProvider.js +3 -3
- package/esm/provider/Provider.js +7 -3
- package/esm/provider/singleton/SingletonProvider.js +1 -1
- package/esm/utils.js +1 -4
- package/package.json +2 -2
- package/typings/hooks/hook.d.ts +1 -1
- package/typings/index.d.ts +1 -1
- package/typings/provider/DecoratorProvider.d.ts +2 -2
- package/typings/provider/IProvider.d.ts +1 -3
- package/typings/provider/Provider.d.ts +1 -1
- package/typings/provider/singleton/SingletonProvider.d.ts +2 -2
- package/typings/utils.d.ts +1 -1
|
@@ -8,7 +8,7 @@ class DecoratorProvider extends IProvider_1.ProviderDecorator {
|
|
|
8
8
|
this.provider = provider;
|
|
9
9
|
this.decorateFn = decorateFn;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
resolve(scope, options) {
|
|
12
12
|
const dependency = this.provider.resolve(scope, options);
|
|
13
13
|
return this.decorateFn(dependency, scope);
|
|
14
14
|
}
|
|
@@ -31,8 +31,8 @@ class ProviderDecorator {
|
|
|
31
31
|
isVisible(parent, child) {
|
|
32
32
|
return this.decorated.isVisible(parent, child);
|
|
33
33
|
}
|
|
34
|
-
resolve(container,
|
|
35
|
-
return
|
|
34
|
+
resolve(container, options) {
|
|
35
|
+
return this.decorated.resolve(container, options);
|
|
36
36
|
}
|
|
37
37
|
pipe(...mappers) {
|
|
38
38
|
return (0, utils_1.pipe)(...mappers)(this);
|
package/cjm/provider/Provider.js
CHANGED
|
@@ -21,8 +21,12 @@ class Provider {
|
|
|
21
21
|
pipe(...mappers) {
|
|
22
22
|
return (0, utils_1.pipe)(...mappers)(this);
|
|
23
23
|
}
|
|
24
|
-
resolve(container, { args, lazy }) {
|
|
25
|
-
|
|
24
|
+
resolve(container, { args, lazy: isLazy }) {
|
|
25
|
+
const resolveDependency = () => {
|
|
26
|
+
const deps = [...this.argsFn(container, ...args), ...args];
|
|
27
|
+
return this.resolveDependency(container, { args: deps });
|
|
28
|
+
};
|
|
29
|
+
return isLazy ? (0, utils_1.lazyProxy)(resolveDependency) : resolveDependency();
|
|
26
30
|
}
|
|
27
31
|
setVisibility(predicate) {
|
|
28
32
|
this.isVisibleWhen = predicate;
|
|
@@ -13,7 +13,7 @@ class SingletonProvider extends IProvider_1.ProviderDecorator {
|
|
|
13
13
|
this.provider = provider;
|
|
14
14
|
this.cache = cache;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
resolve(container, options) {
|
|
17
17
|
const key = this.cache.getKey(...options.args);
|
|
18
18
|
if (!this.cache.hasValue(key)) {
|
|
19
19
|
this.cache.setValue(key, this.provider.resolve(container, options));
|
package/cjm/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.lazyProxy = exports.isConstructor = exports.constant = exports.fillEmptyIndexes = exports.pipe = void 0;
|
|
4
4
|
const pipe = (...mappers) => (value) => mappers.reduce((acc, current) => current(acc), value);
|
|
5
5
|
exports.pipe = pipe;
|
|
6
6
|
function fillEmptyIndexes(baseArr, insertArr) {
|
|
@@ -18,10 +18,7 @@ const constant = (value) => () => value;
|
|
|
18
18
|
exports.constant = constant;
|
|
19
19
|
const isConstructor = (T) => typeof T === 'function' && !!T.prototype;
|
|
20
20
|
exports.isConstructor = isConstructor;
|
|
21
|
-
function
|
|
22
|
-
if (!isLazy) {
|
|
23
|
-
return resolveInstance();
|
|
24
|
-
}
|
|
21
|
+
function lazyProxy(resolveInstance) {
|
|
25
22
|
let instance;
|
|
26
23
|
return new Proxy({}, {
|
|
27
24
|
get: (_, prop) => {
|
|
@@ -31,4 +28,4 @@ function lazyInstance(resolveInstance, isLazy) {
|
|
|
31
28
|
},
|
|
32
29
|
});
|
|
33
30
|
}
|
|
34
|
-
exports.
|
|
31
|
+
exports.lazyProxy = lazyProxy;
|
|
@@ -5,7 +5,7 @@ export class DecoratorProvider extends ProviderDecorator {
|
|
|
5
5
|
this.provider = provider;
|
|
6
6
|
this.decorateFn = decorateFn;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
resolve(scope, options) {
|
|
9
9
|
const dependency = this.provider.resolve(scope, options);
|
|
10
10
|
return this.decorateFn(dependency, scope);
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pipe } from '../utils';
|
|
2
2
|
import { getMetadata, setMetadata } from '../metadata';
|
|
3
3
|
export function args(...extraArgs) {
|
|
4
4
|
return (provider) => provider.setArgs(() => extraArgs);
|
|
@@ -22,8 +22,8 @@ export class ProviderDecorator {
|
|
|
22
22
|
isVisible(parent, child) {
|
|
23
23
|
return this.decorated.isVisible(parent, child);
|
|
24
24
|
}
|
|
25
|
-
resolve(container,
|
|
26
|
-
return
|
|
25
|
+
resolve(container, options) {
|
|
26
|
+
return this.decorated.resolve(container, options);
|
|
27
27
|
}
|
|
28
28
|
pipe(...mappers) {
|
|
29
29
|
return pipe(...mappers)(this);
|
package/esm/provider/Provider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getTransformers, } from './IProvider';
|
|
2
|
-
import { isConstructor,
|
|
2
|
+
import { isConstructor, lazyProxy, pipe } from '../utils';
|
|
3
3
|
export class Provider {
|
|
4
4
|
static fromClass(Target) {
|
|
5
5
|
const transformers = getTransformers(Target);
|
|
@@ -18,8 +18,12 @@ export class Provider {
|
|
|
18
18
|
pipe(...mappers) {
|
|
19
19
|
return pipe(...mappers)(this);
|
|
20
20
|
}
|
|
21
|
-
resolve(container, { args, lazy }) {
|
|
22
|
-
|
|
21
|
+
resolve(container, { args, lazy: isLazy }) {
|
|
22
|
+
const resolveDependency = () => {
|
|
23
|
+
const deps = [...this.argsFn(container, ...args), ...args];
|
|
24
|
+
return this.resolveDependency(container, { args: deps });
|
|
25
|
+
};
|
|
26
|
+
return isLazy ? lazyProxy(resolveDependency) : resolveDependency();
|
|
23
27
|
}
|
|
24
28
|
setVisibility(predicate) {
|
|
25
29
|
this.isVisibleWhen = predicate;
|
|
@@ -9,7 +9,7 @@ export class SingletonProvider extends ProviderDecorator {
|
|
|
9
9
|
this.provider = provider;
|
|
10
10
|
this.cache = cache;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
resolve(container, options) {
|
|
13
13
|
const key = this.cache.getKey(...options.args);
|
|
14
14
|
if (!this.cache.hasValue(key)) {
|
|
15
15
|
this.cache.setValue(key, this.provider.resolve(container, options));
|
package/esm/utils.js
CHANGED
|
@@ -11,10 +11,7 @@ export function fillEmptyIndexes(baseArr, insertArr) {
|
|
|
11
11
|
}
|
|
12
12
|
export const constant = (value) => () => value;
|
|
13
13
|
export const isConstructor = (T) => typeof T === 'function' && !!T.prototype;
|
|
14
|
-
export function
|
|
15
|
-
if (!isLazy) {
|
|
16
|
-
return resolveInstance();
|
|
17
|
-
}
|
|
14
|
+
export function lazyProxy(resolveInstance) {
|
|
18
15
|
let instance;
|
|
19
16
|
return new Proxy({}, {
|
|
20
17
|
get: (_, prop) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "32.
|
|
3
|
+
"version": "32.7.0",
|
|
4
4
|
"description": "Typescript IoC container",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"ts-node": "^10.9.1",
|
|
60
60
|
"typescript": "5.4.3"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "085b602ac136f4bf4209f824531709f170582a67"
|
|
63
63
|
}
|
package/typings/hooks/hook.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IContainer } from '../container/IContainer';
|
|
2
2
|
import { ExecutionContext } from './ExecutionContext';
|
|
3
|
-
export type Execution
|
|
3
|
+
export type Execution<T extends ExecutionContext = ExecutionContext> = (context: T) => void;
|
|
4
4
|
export declare const hook: (key: string | symbol, ...fns: Execution[]) => (target: object, propertyKey: string | symbol) => void;
|
|
5
5
|
export declare function getHooks(target: object, key: string | symbol): Map<string, Execution[]>;
|
|
6
6
|
export declare function hasHooks(target: object, key: string | symbol): boolean;
|
package/typings/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { IInjector } from './injector/IInjector';
|
|
|
6
6
|
export { MetadataInjector, inject, resolveArgs, getInjectFns, InjectFn } from './injector/MetadataInjector';
|
|
7
7
|
export { SimpleInjector } from './injector/SimpleInjector';
|
|
8
8
|
export { ProxyInjector } from './injector/ProxyInjector';
|
|
9
|
-
export { ResolveDependency, IProvider, provider, visible, alias, argsFn, args, ArgsFn, ProviderDecorator,
|
|
9
|
+
export { ResolveDependency, IProvider, provider, visible, alias, argsFn, args, ArgsFn, ProviderDecorator, ProviderResolveOptions, } from './provider/IProvider';
|
|
10
10
|
export { Provider } from './provider/Provider';
|
|
11
11
|
export { singleton, SingletonProvider } from './provider/singleton/SingletonProvider';
|
|
12
12
|
export { MultiCache, multiCache } from './provider/singleton/MultiCache';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IContainer } from '../container/IContainer';
|
|
2
|
-
import {
|
|
2
|
+
import { IProvider, ProviderDecorator, ProviderResolveOptions } from './IProvider';
|
|
3
3
|
export type DecorateFn<Instance> = (dep: Instance, scope: IContainer) => Instance;
|
|
4
4
|
export declare class DecoratorProvider<Instance> extends ProviderDecorator<Instance> {
|
|
5
5
|
private provider;
|
|
6
6
|
private decorateFn;
|
|
7
7
|
constructor(provider: IProvider<Instance>, decorateFn: DecorateFn<Instance>);
|
|
8
|
-
|
|
8
|
+
resolve(scope: IContainer, options: ProviderResolveOptions): Instance;
|
|
9
9
|
}
|
|
10
10
|
export declare const decorate: <Instance>(decorateFn: DecorateFn<Instance>) => (provider: IProvider<Instance>) => DecoratorProvider<Instance>;
|
|
@@ -4,7 +4,6 @@ export type ProviderResolveOptions = {
|
|
|
4
4
|
args: unknown[];
|
|
5
5
|
lazy?: boolean;
|
|
6
6
|
};
|
|
7
|
-
export type InstantDependencyOptions = Omit<ProviderResolveOptions, 'lazy'>;
|
|
8
7
|
export type ResolveDependency<T = unknown> = (container: IContainer, options: ProviderResolveOptions) => T;
|
|
9
8
|
export type ChildrenVisibilityPredicate = (options: {
|
|
10
9
|
child: Tagged;
|
|
@@ -31,8 +30,7 @@ export declare abstract class ProviderDecorator<T> implements IProvider<T> {
|
|
|
31
30
|
protected constructor(decorated: IProvider<T>);
|
|
32
31
|
setVisibility(predicate: ChildrenVisibilityPredicate): this;
|
|
33
32
|
isVisible(parent: IContainer, child: Tagged): boolean;
|
|
34
|
-
resolve(container: IContainer,
|
|
35
|
-
protected abstract resolveInstantly(container: IContainer, options: InstantDependencyOptions): T;
|
|
33
|
+
resolve(container: IContainer, options: ProviderResolveOptions): T;
|
|
36
34
|
pipe(...mappers: MapFn<IProvider<T>>[]): IProvider<T>;
|
|
37
35
|
matchAliases(predicate: AliasPredicate): boolean;
|
|
38
36
|
addAliases(...aliases: Alias[]): this;
|
|
@@ -10,7 +10,7 @@ export declare class Provider<T> implements IProvider<T> {
|
|
|
10
10
|
private isVisibleWhen;
|
|
11
11
|
constructor(resolveDependency: ResolveDependency<T>);
|
|
12
12
|
pipe(...mappers: MapFn<IProvider<T>>[]): IProvider<T>;
|
|
13
|
-
resolve(container: IContainer, { args, lazy }: ProviderResolveOptions): T;
|
|
13
|
+
resolve(container: IContainer, { args, lazy: isLazy }: ProviderResolveOptions): T;
|
|
14
14
|
setVisibility(predicate: ChildrenVisibilityPredicate): this;
|
|
15
15
|
setArgs(argsFn: ArgsFn): this;
|
|
16
16
|
isVisible(parent: Tagged, child: Tagged): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IContainer } from '../../container/IContainer';
|
|
2
|
-
import {
|
|
2
|
+
import { IProvider, ProviderDecorator, ProviderResolveOptions } from '../IProvider';
|
|
3
3
|
import { MapFn } from '../../utils';
|
|
4
4
|
import { Cache } from './Cache';
|
|
5
5
|
export declare function singleton<T = unknown>(cacheProvider?: () => Cache<unknown, T>): MapFn<IProvider<T>>;
|
|
@@ -7,5 +7,5 @@ export declare class SingletonProvider<T> extends ProviderDecorator<T> {
|
|
|
7
7
|
private readonly provider;
|
|
8
8
|
private readonly cache;
|
|
9
9
|
constructor(provider: IProvider<T>, cache: Cache<unknown, T>);
|
|
10
|
-
|
|
10
|
+
resolve(container: IContainer, options: ProviderResolveOptions): T;
|
|
11
11
|
}
|
package/typings/utils.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare const pipe: <T>(...mappers: MapFn<T>[]) => MapFn<T>;
|
|
|
4
4
|
export declare function fillEmptyIndexes<T>(baseArr: (T | undefined)[], insertArr: T[]): T[];
|
|
5
5
|
export declare const constant: <T>(value: T) => () => T;
|
|
6
6
|
export declare const isConstructor: (T: unknown) => T is constructor<unknown>;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function lazyProxy<T>(resolveInstance: () => T): T;
|