ts-ioc-container 32.3.0 → 32.4.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/hooks/hook.js CHANGED
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeHooks = exports.hasHooks = exports.getHooks = exports.hook = void 0;
4
4
  const ExecutionContext_1 = require("./ExecutionContext");
5
5
  const createStore = () => new Map();
6
- const hook = (key, fn) => (target, propertyKey) => {
6
+ const hook = (key, ...fns) => (target, propertyKey) => {
7
7
  const hooks = Reflect.hasMetadata(key, target.constructor)
8
8
  ? Reflect.getMetadata(key, target.constructor)
9
9
  : createStore();
10
- hooks.set(propertyKey, fn);
10
+ hooks.set(propertyKey, (hooks.get(propertyKey) ?? []).concat(fns));
11
11
  Reflect.defineMetadata(key, hooks, target.constructor); // eslint-disable-line @typescript-eslint/ban-types
12
12
  };
13
13
  exports.hook = hook;
@@ -20,8 +20,10 @@ function hasHooks(target, key) {
20
20
  }
21
21
  exports.hasHooks = hasHooks;
22
22
  const executeHooks = (target, key, { scope, createContext = (c) => c, }) => {
23
- for (const [methodName, execute] of getHooks(target, key)) {
24
- execute(createContext(new ExecutionContext_1.ExecutionContext(target, methodName, scope)));
23
+ for (const [methodName, executions] of getHooks(target, key)) {
24
+ for (const execute of executions) {
25
+ execute(createContext(new ExecutionContext_1.ExecutionContext(target, methodName, scope)));
26
+ }
25
27
  }
26
28
  };
27
29
  exports.executeHooks = executeHooks;
package/esm/hooks/hook.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { ExecutionContext } from './ExecutionContext';
2
2
  const createStore = () => new Map();
3
- export const hook = (key, fn) => (target, propertyKey) => {
3
+ export const hook = (key, ...fns) => (target, propertyKey) => {
4
4
  const hooks = Reflect.hasMetadata(key, target.constructor)
5
5
  ? Reflect.getMetadata(key, target.constructor)
6
6
  : createStore();
7
- hooks.set(propertyKey, fn);
7
+ hooks.set(propertyKey, (hooks.get(propertyKey) ?? []).concat(fns));
8
8
  Reflect.defineMetadata(key, hooks, target.constructor); // eslint-disable-line @typescript-eslint/ban-types
9
9
  };
10
10
  export function getHooks(target, key) {
@@ -14,7 +14,9 @@ export function hasHooks(target, key) {
14
14
  return Reflect.hasMetadata(key, target.constructor);
15
15
  }
16
16
  export const executeHooks = (target, key, { scope, createContext = (c) => c, }) => {
17
- for (const [methodName, execute] of getHooks(target, key)) {
18
- execute(createContext(new ExecutionContext(target, methodName, scope)));
17
+ for (const [methodName, executions] of getHooks(target, key)) {
18
+ for (const execute of executions) {
19
+ execute(createContext(new ExecutionContext(target, methodName, scope)));
20
+ }
19
21
  }
20
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-ioc-container",
3
- "version": "32.3.0",
3
+ "version": "32.4.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": "9785342f77f8a8548837f5fe45f587adc6394797"
62
+ "gitHead": "590a34c13ebc93437a8a368f6e1e39db25600126"
63
63
  }
@@ -1,8 +1,8 @@
1
1
  import { IContainer } from '../container/IContainer';
2
2
  import { ExecutionContext } from './ExecutionContext';
3
3
  export type Execution = <T extends ExecutionContext>(context: T) => void;
4
- export declare const hook: (key: string | symbol, fn: Execution) => MethodDecorator;
5
- export declare function getHooks(target: object, key: string | symbol): Map<string, Execution>;
4
+ export declare const hook: (key: string | symbol, ...fns: Execution[]) => MethodDecorator;
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;
7
7
  export declare const executeHooks: <Context extends ExecutionContext>(target: object, key: string | symbol, { scope, createContext, }: {
8
8
  scope: IContainer;