mesh-decorators 1.1.1 → 1.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/out/main/class.d.ts +18 -0
- package/out/main/class.js +41 -0
- package/out/main/class.js.map +1 -0
- package/out/main/index.d.ts +1 -0
- package/out/main/index.js +1 -0
- package/out/main/index.js.map +1 -1
- package/out/main/member.d.ts +5 -4
- package/out/main/member.js +4 -2
- package/out/main/member.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Mesh } from 'mesh-ioc';
|
|
2
|
+
export interface ClassRef<M> {
|
|
3
|
+
target: any;
|
|
4
|
+
metadata: M;
|
|
5
|
+
}
|
|
6
|
+
export declare const globalClassRefMap: Map<string, ClassRef<any>[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a decorator that tracks references to a particular class in a global map.
|
|
9
|
+
* These class references can be subsequently accessed via `findClasses`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createClassDecorator<M = void>(decoratorName: string): (metadata: M) => (target: any) => void;
|
|
12
|
+
export declare function getClassRefs<M>(decoratorName: string): Array<ClassRef<M>>;
|
|
13
|
+
/**
|
|
14
|
+
* Obtains a list of member references decorated by specified `decoratorName`.
|
|
15
|
+
*
|
|
16
|
+
* For each reference, the `target` is the actual instance of the class created by specified `mesh`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function findClasses<T>(decoratorName: string, mesh: Mesh, recursive?: boolean): Array<ClassRef<T>>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const globalClassRefMap = new Map();
|
|
2
|
+
/**
|
|
3
|
+
* Creates a decorator that tracks references to a particular class in a global map.
|
|
4
|
+
* These class references can be subsequently accessed via `findClasses`.
|
|
5
|
+
*/
|
|
6
|
+
export function createClassDecorator(decoratorName) {
|
|
7
|
+
return function decorator(metadata) {
|
|
8
|
+
return (target) => {
|
|
9
|
+
const handlers = globalClassRefMap.get(decoratorName) || [];
|
|
10
|
+
globalClassRefMap.set(decoratorName, handlers);
|
|
11
|
+
handlers.push({ target, metadata });
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function getClassRefs(decoratorName) {
|
|
16
|
+
return globalClassRefMap.get(decoratorName) || [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Obtains a list of member references decorated by specified `decoratorName`.
|
|
20
|
+
*
|
|
21
|
+
* For each reference, the `target` is the actual instance of the class created by specified `mesh`.
|
|
22
|
+
*/
|
|
23
|
+
export function findClasses(decoratorName, mesh, recursive = true) {
|
|
24
|
+
const result = [];
|
|
25
|
+
const refs = getClassRefs(decoratorName);
|
|
26
|
+
const bindings = recursive ? mesh.allBindings() : mesh.bindings.entries();
|
|
27
|
+
for (const [key, binding] of bindings) {
|
|
28
|
+
if (binding.type === 'service') {
|
|
29
|
+
for (const { target, metadata } of refs) {
|
|
30
|
+
if (target === binding.class || Object.prototype.isPrototypeOf.call(target, binding.class)) {
|
|
31
|
+
result.push({
|
|
32
|
+
target: mesh.resolve(key),
|
|
33
|
+
metadata,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/main/class.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAgC,CAAC;AAEzE;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAW,aAAqB;IAChE,OAAO,SAAS,SAAS,CAAC,QAAW;QACjC,OAAO,CAAC,MAAW,EAAE,EAAE;YACnB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAC5D,iBAAiB,CAAC,GAAG,CAAC,aA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":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
package/out/main/member.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { Mesh } from 'mesh-ioc';
|
|
2
|
-
export interface MemberRef {
|
|
2
|
+
export interface MemberRef<M> {
|
|
3
3
|
target: any;
|
|
4
4
|
memberName: string;
|
|
5
|
+
metadata: M;
|
|
5
6
|
}
|
|
6
|
-
export declare const globalMemberRefMap: Map<string, MemberRef[]>;
|
|
7
|
+
export declare const globalMemberRefMap: Map<string, MemberRef<any>[]>;
|
|
7
8
|
/**
|
|
8
9
|
* Creates a decorator that tracks references to a particular class property or method in a global map.
|
|
9
10
|
* These member references can be subsequently accessed via `findMembers`.
|
|
10
11
|
*/
|
|
11
|
-
export declare function createMemberDecorator(decoratorName: string): () => (target: any, memberName: string) => void;
|
|
12
|
+
export declare function createMemberDecorator<M = void>(decoratorName: string): (metadata: M) => (target: any, memberName: string) => void;
|
|
12
13
|
/**
|
|
13
14
|
* Obtains a list of member references decorated by specified `decoratorName`.
|
|
14
15
|
*
|
|
15
16
|
* For each reference, the `target` is the actual instance of the class created by specified `mesh`.
|
|
16
17
|
*/
|
|
17
|
-
export declare function findMembers(decoratorName: string, mesh: Mesh, recursive?: boolean): MemberRef
|
|
18
|
+
export declare function findMembers(decoratorName: string, mesh: Mesh, recursive?: boolean): Array<MemberRef<any>>;
|
|
18
19
|
/**
|
|
19
20
|
* Convenience method to call all methods decorated with specified `decoratorName`.
|
|
20
21
|
*
|
package/out/main/member.js
CHANGED
|
@@ -4,13 +4,14 @@ export const globalMemberRefMap = new Map();
|
|
|
4
4
|
* These member references can be subsequently accessed via `findMembers`.
|
|
5
5
|
*/
|
|
6
6
|
export function createMemberDecorator(decoratorName) {
|
|
7
|
-
return function decorator() {
|
|
7
|
+
return function decorator(metadata) {
|
|
8
8
|
return (target, memberName) => {
|
|
9
9
|
const handlers = globalMemberRefMap.get(decoratorName) || [];
|
|
10
10
|
globalMemberRefMap.set(decoratorName, handlers);
|
|
11
11
|
handlers.push({
|
|
12
12
|
target: target.constructor,
|
|
13
13
|
memberName,
|
|
14
|
+
metadata,
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
};
|
|
@@ -26,11 +27,12 @@ export function findMembers(decoratorName, mesh, recursive = true) {
|
|
|
26
27
|
const bindings = recursive ? mesh.allBindings() : mesh.bindings.entries();
|
|
27
28
|
for (const [key, binding] of bindings) {
|
|
28
29
|
if (binding.type === 'service') {
|
|
29
|
-
for (const { target, memberName } of refs) {
|
|
30
|
+
for (const { target, memberName, metadata } of refs) {
|
|
30
31
|
if (target === binding.class || Object.prototype.isPrototypeOf.call(target, binding.class)) {
|
|
31
32
|
result.push({
|
|
32
33
|
target: mesh.resolve(key),
|
|
33
34
|
memberName,
|
|
35
|
+
metadata,
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
}
|
package/out/main/member.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"member.js","sourceRoot":"","sources":["../../src/main/member.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"member.js","sourceRoot":"","sources":["../../src/main/member.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAiC,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAW,aAAqB;IACjE,OAAO,SAAS,SAAS,CAAC,QAAW;QACjC,OAAO,CAAC,MAAW,EAAE,UAAkB,EAAE,EAAE;YACvC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAC7D,kBAAkB,CAAC,GAAG,CAAC,aAAa,E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,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxE,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mesh-decorators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Custom decorators for Mesh IoC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"typescript": "^5.7.2"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"mesh-ioc": "^4.0
|
|
50
|
+
"mesh-ioc": "^4.1.0"
|
|
51
51
|
}
|
|
52
52
|
}
|