ts-ioc-container 33.0.2 → 33.2.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/container/AutoMockedContainer.js +3 -0
- package/cjm/container/Container.js +3 -0
- package/cjm/container/EmptyContainer.js +3 -0
- package/cjm/hooks/hook.js +8 -5
- package/esm/container/AutoMockedContainer.js +3 -0
- package/esm/container/Container.js +3 -0
- package/esm/container/EmptyContainer.js +3 -0
- package/esm/hooks/hook.js +8 -5
- package/package.json +2 -2
- package/typings/container/AutoMockedContainer.d.ts +1 -0
- package/typings/container/Container.d.ts +1 -0
- package/typings/container/EmptyContainer.d.ts +1 -0
- package/typings/container/IContainer.d.ts +1 -0
- package/typings/hooks/hook.d.ts +4 -2
package/cjm/hooks/hook.js
CHANGED
|
@@ -19,8 +19,8 @@ function hasHooks(target, key) {
|
|
|
19
19
|
return Reflect.hasMetadata(key, target.constructor);
|
|
20
20
|
}
|
|
21
21
|
exports.hasHooks = hasHooks;
|
|
22
|
-
const runHooks = (target, key, { scope, createContext = HookContext_1.createHookContext, }) => {
|
|
23
|
-
const hooks = Array.from(getHooks(target, key).entries());
|
|
22
|
+
const runHooks = (target, key, { scope, createContext = HookContext_1.createHookContext, predicate = () => true, }) => {
|
|
23
|
+
const hooks = Array.from(getHooks(target, key).entries()).filter(([methodName]) => predicate(methodName));
|
|
24
24
|
for (const [methodName, executions] of hooks) {
|
|
25
25
|
for (const execute of executions) {
|
|
26
26
|
execute(createContext(target, scope, methodName));
|
|
@@ -28,10 +28,13 @@ const runHooks = (target, key, { scope, createContext = HookContext_1.createHook
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
exports.runHooks = runHooks;
|
|
31
|
-
const runHooksAsync = (target, key, { scope, createContext = HookContext_1.createHookContext, }) => {
|
|
32
|
-
const hooks = Array.from(getHooks(target, key).entries());
|
|
31
|
+
const runHooksAsync = (target, key, { scope, createContext = HookContext_1.createHookContext, predicate = () => true, }) => {
|
|
32
|
+
const hooks = Array.from(getHooks(target, key).entries()).filter(([methodName]) => predicate(methodName));
|
|
33
33
|
const runExecution = (execute, context) => (0, utils_1.promisify)(execute(context));
|
|
34
|
-
return Promise.all(hooks.flatMap(([methodName, executions]) =>
|
|
34
|
+
return Promise.all(hooks.flatMap(([methodName, executions]) => {
|
|
35
|
+
const context = createContext(target, scope, methodName);
|
|
36
|
+
return executions.map((execute) => runExecution(execute, context));
|
|
37
|
+
}));
|
|
35
38
|
};
|
|
36
39
|
exports.runHooksAsync = runHooksAsync;
|
|
37
40
|
const injectProp = (fn) => (context) => context.setProperty(fn);
|
package/esm/hooks/hook.js
CHANGED
|
@@ -13,17 +13,20 @@ export function getHooks(target, key) {
|
|
|
13
13
|
export function hasHooks(target, key) {
|
|
14
14
|
return Reflect.hasMetadata(key, target.constructor);
|
|
15
15
|
}
|
|
16
|
-
export const runHooks = (target, key, { scope, createContext = createHookContext, }) => {
|
|
17
|
-
const hooks = Array.from(getHooks(target, key).entries());
|
|
16
|
+
export const runHooks = (target, key, { scope, createContext = createHookContext, predicate = () => true, }) => {
|
|
17
|
+
const hooks = Array.from(getHooks(target, key).entries()).filter(([methodName]) => predicate(methodName));
|
|
18
18
|
for (const [methodName, executions] of hooks) {
|
|
19
19
|
for (const execute of executions) {
|
|
20
20
|
execute(createContext(target, scope, methodName));
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
export const runHooksAsync = (target, key, { scope, createContext = createHookContext, }) => {
|
|
25
|
-
const hooks = Array.from(getHooks(target, key).entries());
|
|
24
|
+
export const runHooksAsync = (target, key, { scope, createContext = createHookContext, predicate = () => true, }) => {
|
|
25
|
+
const hooks = Array.from(getHooks(target, key).entries()).filter(([methodName]) => predicate(methodName));
|
|
26
26
|
const runExecution = (execute, context) => promisify(execute(context));
|
|
27
|
-
return Promise.all(hooks.flatMap(([methodName, executions]) =>
|
|
27
|
+
return Promise.all(hooks.flatMap(([methodName, executions]) => {
|
|
28
|
+
const context = createContext(target, scope, methodName);
|
|
29
|
+
return executions.map((execute) => runExecution(execute, context));
|
|
30
|
+
}));
|
|
28
31
|
};
|
|
29
32
|
export const injectProp = (fn) => (context) => context.setProperty(fn);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "33.0
|
|
3
|
+
"version": "33.2.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": "f012d80a2d1e681d4babb127e35c6584620773d3"
|
|
63
63
|
}
|
|
@@ -13,6 +13,7 @@ export declare abstract class AutoMockedContainer implements IContainer {
|
|
|
13
13
|
dispose(): void;
|
|
14
14
|
register(): this;
|
|
15
15
|
getInstances(): object[];
|
|
16
|
+
getOwnInstances(): object[];
|
|
16
17
|
reduceToRoot<TResult>(fn: ReduceScope<TResult>, initial: TResult): TResult;
|
|
17
18
|
removeScope(): void;
|
|
18
19
|
use(): this;
|
|
@@ -26,6 +26,7 @@ export declare class Container implements IContainer {
|
|
|
26
26
|
createScope(...tags: Tag[]): Container;
|
|
27
27
|
dispose(): void;
|
|
28
28
|
getInstances(direction?: 'parent' | 'child'): object[];
|
|
29
|
+
getOwnInstances(): object[];
|
|
29
30
|
hasTag(tag: Tag): boolean;
|
|
30
31
|
use(module: IContainerModule): this;
|
|
31
32
|
hasDependency(key: DependencyKey): boolean;
|
|
@@ -18,6 +18,7 @@ export declare class EmptyContainer implements IContainer {
|
|
|
18
18
|
resolve<T>(key: InjectionToken<T>, options: ResolveOptions): T;
|
|
19
19
|
getRegistrations(): never[];
|
|
20
20
|
getInstances(): object[];
|
|
21
|
+
getOwnInstances(): object[];
|
|
21
22
|
removeScope(): void;
|
|
22
23
|
use(module: IContainerModule): this;
|
|
23
24
|
add(registration: IRegistration): this;
|
|
@@ -33,6 +33,7 @@ export interface IContainer extends Resolvable, Tagged {
|
|
|
33
33
|
add(registration: IRegistration): this;
|
|
34
34
|
removeScope(child: IContainer): void;
|
|
35
35
|
getInstances(direction?: 'parent' | 'child'): object[];
|
|
36
|
+
getOwnInstances(): object[];
|
|
36
37
|
dispose(): void;
|
|
37
38
|
use(module: IContainerModule): this;
|
|
38
39
|
getRegistrations(): IRegistration[];
|
package/typings/hooks/hook.d.ts
CHANGED
|
@@ -5,13 +5,15 @@ type HooksOfClass = Map<string, Hook[]>;
|
|
|
5
5
|
export declare const hook: (key: string | symbol, ...fns: Hook[]) => (target: object, propertyKey: string | symbol) => void;
|
|
6
6
|
export declare function getHooks(target: object, key: string | symbol): HooksOfClass;
|
|
7
7
|
export declare function hasHooks(target: object, key: string | symbol): boolean;
|
|
8
|
-
export declare const runHooks: (target: object, key: string | symbol, { scope, createContext, }: {
|
|
8
|
+
export declare const runHooks: (target: object, key: string | symbol, { scope, createContext, predicate, }: {
|
|
9
9
|
scope: IContainer;
|
|
10
10
|
createContext?: ((Target: object, scope: IContainer, methodName?: string) => IHookContext) | undefined;
|
|
11
|
+
predicate?: ((methodName: string) => boolean) | undefined;
|
|
11
12
|
}) => void;
|
|
12
|
-
export declare const runHooksAsync: (target: object, key: string | symbol, { scope, createContext, }: {
|
|
13
|
+
export declare const runHooksAsync: (target: object, key: string | symbol, { scope, createContext, predicate, }: {
|
|
13
14
|
scope: IContainer;
|
|
14
15
|
createContext?: ((Target: object, scope: IContainer, methodName?: string) => IHookContext) | undefined;
|
|
16
|
+
predicate?: ((methodName: string) => boolean) | undefined;
|
|
15
17
|
}) => Promise<void[]>;
|
|
16
18
|
export declare const injectProp: (fn: InjectFn) => Hook;
|
|
17
19
|
export {};
|