ts-ioc-container 32.6.0 → 32.6.2
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.
|
@@ -7,7 +7,12 @@ const METADATA_KEY = 'inject';
|
|
|
7
7
|
const getInjectFns = (Target, methodName) => (0, metadata_1.getParameterMetadata)(metaKey(methodName), Target);
|
|
8
8
|
exports.getInjectFns = getInjectFns;
|
|
9
9
|
const metaKey = (methodName = 'constructor') => `${METADATA_KEY}:${methodName}`;
|
|
10
|
-
|
|
10
|
+
function isInstance(target) {
|
|
11
|
+
return Object.prototype.hasOwnProperty.call(target, 'constructor');
|
|
12
|
+
}
|
|
13
|
+
const inject = (fn) => (target, propertyKey, parameterIndex) => {
|
|
14
|
+
(0, metadata_1.setParameterMetadata)(metaKey(propertyKey), fn)(isInstance(target) ? target.constructor : target, propertyKey, parameterIndex);
|
|
15
|
+
};
|
|
11
16
|
exports.inject = inject;
|
|
12
17
|
const resolveArgs = (Target, methodName) => {
|
|
13
18
|
const argsFns = (0, exports.getInjectFns)(Target, methodName);
|
|
@@ -3,7 +3,12 @@ import { setParameterMetadata, getParameterMetadata } from '../metadata';
|
|
|
3
3
|
const METADATA_KEY = 'inject';
|
|
4
4
|
export const getInjectFns = (Target, methodName) => getParameterMetadata(metaKey(methodName), Target);
|
|
5
5
|
const metaKey = (methodName = 'constructor') => `${METADATA_KEY}:${methodName}`;
|
|
6
|
-
|
|
6
|
+
function isInstance(target) {
|
|
7
|
+
return Object.prototype.hasOwnProperty.call(target, 'constructor');
|
|
8
|
+
}
|
|
9
|
+
export const inject = (fn) => (target, propertyKey, parameterIndex) => {
|
|
10
|
+
setParameterMetadata(metaKey(propertyKey), fn)(isInstance(target) ? target.constructor : target, propertyKey, parameterIndex);
|
|
11
|
+
};
|
|
7
12
|
export const resolveArgs = (Target, methodName) => {
|
|
8
13
|
const argsFns = getInjectFns(Target, methodName);
|
|
9
14
|
return (scope, ...deps) => fillEmptyIndexes(argsFns, deps.map(constant)).map((fn) => fn(scope));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "32.6.
|
|
3
|
+
"version": "32.6.2",
|
|
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": "b51eb6fbe46b4e144453a5b6a421b2ceb486d8a7"
|
|
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;
|