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.
@@ -29,6 +29,9 @@ class AutoMockedContainer {
29
29
  getInstances() {
30
30
  return [];
31
31
  }
32
+ getOwnInstances() {
33
+ return [];
34
+ }
32
35
  reduceToRoot(fn, initial) {
33
36
  return initial;
34
37
  }
@@ -70,6 +70,9 @@ class Container {
70
70
  }
71
71
  return instances;
72
72
  }
73
+ getOwnInstances() {
74
+ return Array.from(this.instances);
75
+ }
73
76
  hasTag(tag) {
74
77
  return this.tags.has(tag);
75
78
  }
@@ -46,6 +46,9 @@ class EmptyContainer {
46
46
  getInstances() {
47
47
  return [];
48
48
  }
49
+ getOwnInstances() {
50
+ return [];
51
+ }
49
52
  removeScope() { }
50
53
  use(module) {
51
54
  throw new MethodNotImplementedError_1.MethodNotImplementedError();
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]) => executions.map((execute) => runExecution(execute, createContext(target, scope, methodName)))));
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);
@@ -26,6 +26,9 @@ export class AutoMockedContainer {
26
26
  getInstances() {
27
27
  return [];
28
28
  }
29
+ getOwnInstances() {
30
+ return [];
31
+ }
29
32
  reduceToRoot(fn, initial) {
30
33
  return initial;
31
34
  }
@@ -67,6 +67,9 @@ export class Container {
67
67
  }
68
68
  return instances;
69
69
  }
70
+ getOwnInstances() {
71
+ return Array.from(this.instances);
72
+ }
70
73
  hasTag(tag) {
71
74
  return this.tags.has(tag);
72
75
  }
@@ -43,6 +43,9 @@ export class EmptyContainer {
43
43
  getInstances() {
44
44
  return [];
45
45
  }
46
+ getOwnInstances() {
47
+ return [];
48
+ }
46
49
  removeScope() { }
47
50
  use(module) {
48
51
  throw new MethodNotImplementedError();
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]) => executions.map((execute) => runExecution(execute, createContext(target, scope, methodName)))));
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.2",
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": "2fc46f490e00dfdf60d77861dee309bdcf039d39"
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[];
@@ -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 {};