ts-ioc-container 55.3.0 → 55.4.1
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.
|
@@ -6,7 +6,6 @@ const ContainerDisposedError_1 = require("../errors/ContainerDisposedError");
|
|
|
6
6
|
const MetadataInjector_1 = require("../injector/MetadataInjector");
|
|
7
7
|
const AliasMap_1 = require("./AliasMap");
|
|
8
8
|
const DependencyNotFoundError_1 = require("../errors/DependencyNotFoundError");
|
|
9
|
-
const ContainerNotFoundError_1 = require("../errors/ContainerNotFoundError");
|
|
10
9
|
const basic_1 = require("../utils/basic");
|
|
11
10
|
const array_1 = require("../utils/array");
|
|
12
11
|
class Container {
|
|
@@ -137,15 +136,10 @@ class Container {
|
|
|
137
136
|
}
|
|
138
137
|
getScopeByInstanceOrFail(instance) {
|
|
139
138
|
this.validateContainer();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const scope = queue.shift();
|
|
143
|
-
if (scope.hasInstance(instance)) {
|
|
144
|
-
return scope;
|
|
145
|
-
}
|
|
146
|
-
queue.push(...scope.getScopes());
|
|
139
|
+
if (this.hasInstance(instance)) {
|
|
140
|
+
return this;
|
|
147
141
|
}
|
|
148
|
-
|
|
142
|
+
return this.parent.getScopeByInstanceOrFail(instance);
|
|
149
143
|
}
|
|
150
144
|
removeScope(child) {
|
|
151
145
|
this.scopes = this.scopes.filter((s) => s !== child);
|
package/cjm/hooks/HooksRunner.js
CHANGED
|
@@ -10,6 +10,9 @@ class HooksRunner {
|
|
|
10
10
|
constructor(key) {
|
|
11
11
|
this.key = key;
|
|
12
12
|
}
|
|
13
|
+
hasHooks(target) {
|
|
14
|
+
return (0, hook_1.hasHooks)(target, this.key);
|
|
15
|
+
}
|
|
13
16
|
execute(target, { scope, createContext = HookContext_1.createHookContext, mapContext = (context) => context, predicate = () => true, }) {
|
|
14
17
|
const hooks = Array.from((0, hook_1.getHooks)(target, this.key).entries()).filter(([methodName]) => predicate(methodName));
|
|
15
18
|
const runMethodHooks = (methodName, executions) => {
|
|
@@ -3,7 +3,6 @@ import { ContainerDisposedError } from '../errors/ContainerDisposedError';
|
|
|
3
3
|
import { MetadataInjector } from '../injector/MetadataInjector';
|
|
4
4
|
import { AliasMap } from './AliasMap';
|
|
5
5
|
import { DependencyNotFoundError } from '../errors/DependencyNotFoundError';
|
|
6
|
-
import { ContainerNotFoundError } from '../errors/ContainerNotFoundError';
|
|
7
6
|
import { Is } from '../utils/basic';
|
|
8
7
|
import { Filter as F } from '../utils/array';
|
|
9
8
|
export class Container {
|
|
@@ -134,15 +133,10 @@ export class Container {
|
|
|
134
133
|
}
|
|
135
134
|
getScopeByInstanceOrFail(instance) {
|
|
136
135
|
this.validateContainer();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const scope = queue.shift();
|
|
140
|
-
if (scope.hasInstance(instance)) {
|
|
141
|
-
return scope;
|
|
142
|
-
}
|
|
143
|
-
queue.push(...scope.getScopes());
|
|
136
|
+
if (this.hasInstance(instance)) {
|
|
137
|
+
return this;
|
|
144
138
|
}
|
|
145
|
-
|
|
139
|
+
return this.parent.getScopeByInstanceOrFail(instance);
|
|
146
140
|
}
|
|
147
141
|
removeScope(child) {
|
|
148
142
|
this.scopes = this.scopes.filter((s) => s !== child);
|
package/esm/hooks/HooksRunner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHookContext } from './HookContext';
|
|
2
|
-
import { getHooks, toHookFn } from './hook';
|
|
2
|
+
import { getHooks, hasHooks, toHookFn } from './hook';
|
|
3
3
|
import { UnexpectedHookResultError } from '../errors/UnexpectedHookResultError';
|
|
4
4
|
import { promisify } from '../utils/promise';
|
|
5
5
|
export class HooksRunner {
|
|
@@ -7,6 +7,9 @@ export class HooksRunner {
|
|
|
7
7
|
constructor(key) {
|
|
8
8
|
this.key = key;
|
|
9
9
|
}
|
|
10
|
+
hasHooks(target) {
|
|
11
|
+
return hasHooks(target, this.key);
|
|
12
|
+
}
|
|
10
13
|
execute(target, { scope, createContext = createHookContext, mapContext = (context) => context, predicate = () => true, }) {
|
|
11
14
|
const hooks = Array.from(getHooks(target, this.key).entries()).filter(([methodName]) => predicate(methodName));
|
|
12
15
|
const runMethodHooks = (methodName, executions) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "55.
|
|
3
|
+
"version": "55.4.1",
|
|
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
|
"workspaces": [
|
|
6
6
|
"docs"
|
|
@@ -10,6 +10,7 @@ export type HooksRunnerContext = {
|
|
|
10
10
|
export declare class HooksRunner {
|
|
11
11
|
private readonly key;
|
|
12
12
|
constructor(key: string | symbol);
|
|
13
|
+
hasHooks(target: object): boolean;
|
|
13
14
|
execute(target: object, { scope, createContext, mapContext, predicate, }: HooksRunnerContext): void;
|
|
14
15
|
executeAsync(target: object, { scope, createContext, mapContext, predicate, }: HooksRunnerContext): Promise<void[]>;
|
|
15
16
|
}
|