assemblerjs 1.0.0 → 1.1.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/README.md +29 -53
- package/dist/index.d.ts +430 -9
- package/dist/index.js +24 -12
- package/dist/index.mjs +16 -12
- package/dist/index11.js +82 -20
- package/dist/index11.mjs +78 -20
- package/dist/index12.js +17 -8
- package/dist/index12.mjs +16 -8
- package/dist/index13.js +148 -73
- package/dist/index13.mjs +148 -73
- package/dist/index14.js +4 -17
- package/dist/index14.mjs +4 -17
- package/dist/index15.js +21 -16
- package/dist/index15.mjs +21 -16
- package/dist/index16.js +10 -16
- package/dist/index16.mjs +10 -16
- package/dist/index17.js +88 -16
- package/dist/index17.mjs +88 -16
- package/dist/index18.js +11 -20
- package/dist/index18.mjs +11 -19
- package/dist/index19.js +11 -20
- package/dist/index19.mjs +11 -19
- package/dist/index2.js +3 -3
- package/dist/index2.mjs +3 -3
- package/dist/index20.js +11 -20
- package/dist/index20.mjs +11 -20
- package/dist/index21.js +14 -25
- package/dist/index21.mjs +14 -21
- package/dist/index22.js +24 -46
- package/dist/index22.mjs +23 -45
- package/dist/index23.js +25 -63
- package/dist/index23.mjs +24 -63
- package/dist/index24.js +24 -30
- package/dist/index24.mjs +24 -30
- package/dist/index25.js +24 -62
- package/dist/index25.mjs +20 -62
- package/dist/index26.js +46 -30
- package/dist/index26.mjs +45 -30
- package/dist/index27.js +2 -34
- package/dist/index27.mjs +2 -32
- package/dist/index28.js +17 -41
- package/dist/index28.mjs +15 -40
- package/dist/index29.js +64 -15
- package/dist/index29.mjs +64 -13
- package/dist/index3.js +2 -2
- package/dist/index3.mjs +2 -2
- package/dist/index30.js +32 -14
- package/dist/index30.mjs +32 -12
- package/dist/index31.js +57 -86
- package/dist/index31.mjs +57 -84
- package/dist/index32.js +28 -19
- package/dist/index32.mjs +28 -19
- package/dist/index33.js +28 -25
- package/dist/index33.mjs +28 -24
- package/dist/index34.js +17 -8
- package/dist/index34.mjs +14 -8
- package/dist/index35.js +23 -49
- package/dist/index35.mjs +23 -49
- package/dist/index36.js +37 -108
- package/dist/index36.mjs +36 -108
- package/dist/index37.js +98 -10
- package/dist/index37.mjs +96 -10
- package/dist/index38.js +95 -20
- package/dist/index38.mjs +95 -20
- package/dist/index39.js +23 -44
- package/dist/index39.mjs +23 -43
- package/dist/index4.js +5 -5
- package/dist/index4.mjs +5 -5
- package/dist/index40.js +34 -0
- package/dist/index40.mjs +29 -0
- package/dist/index41.js +14 -0
- package/dist/index41.mjs +10 -0
- package/dist/index42.js +54 -0
- package/dist/index42.mjs +50 -0
- package/dist/index43.js +177 -0
- package/dist/index43.mjs +173 -0
- package/dist/index44.js +947 -0
- package/dist/index44.mjs +943 -0
- package/dist/index45.js +7 -0
- package/dist/index45.mjs +3 -0
- package/dist/index46.js +7 -0
- package/dist/index46.mjs +3 -0
- package/dist/index47.js +19 -0
- package/dist/index47.mjs +15 -0
- package/dist/index48.js +33 -0
- package/dist/index48.mjs +29 -0
- package/dist/index49.js +67 -0
- package/dist/index49.mjs +62 -0
- package/package.json +2 -2
package/dist/index13.mjs
CHANGED
|
@@ -1,90 +1,165 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isClass } from '@assemblerjs/core';
|
|
2
|
+
import { PointcutMatcher } from './index39.mjs';
|
|
3
|
+
import { getAffectedMethods } from './index12.mjs';
|
|
4
|
+
import { getDefinition } from './index37.mjs';
|
|
2
5
|
|
|
3
|
-
class
|
|
4
|
-
static
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
6
|
+
class TransversalManager {
|
|
7
|
+
static getInstance(e) {
|
|
8
|
+
let t = this.instances.get(e);
|
|
9
|
+
if (!t) {
|
|
10
|
+
t = new TransversalManager(e);
|
|
11
|
+
this.instances.set(e, t);
|
|
8
12
|
}
|
|
9
|
-
|
|
10
|
-
const o = `assemblage:${r.toLowerCase()}.param.value`;
|
|
11
|
-
const c = this.createDecoratorFunction(s, o, t);
|
|
12
|
-
this.registeredDecorators.set(r, {
|
|
13
|
-
name: r,
|
|
14
|
-
valueType: t,
|
|
15
|
-
handler: a
|
|
16
|
-
});
|
|
17
|
-
return c;
|
|
13
|
+
return t;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
getTransversalInstance(e) {
|
|
16
|
+
return TransversalManager.transversalInstances.get(e);
|
|
17
|
+
}
|
|
18
|
+
static resetGlobalState() {
|
|
19
|
+
TransversalManager.transversalInstances.clear();
|
|
20
|
+
TransversalManager.transversalMetadata.clear();
|
|
21
|
+
TransversalManager.instances = new WeakMap();
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
registerTransversal(t, n) {
|
|
24
|
+
let s;
|
|
25
|
+
let r;
|
|
26
|
+
let o;
|
|
27
|
+
if (t.length === 1) {
|
|
28
|
+
s = t[0];
|
|
29
|
+
r = t[0];
|
|
30
|
+
o = undefined;
|
|
31
|
+
} else if (t.length === 2) {
|
|
32
|
+
const a = t[1];
|
|
33
|
+
if (isClass(a)) {
|
|
34
|
+
s = t[0];
|
|
35
|
+
r = a;
|
|
36
|
+
o = undefined;
|
|
37
|
+
} else {
|
|
38
|
+
s = t[0];
|
|
39
|
+
r = t[0];
|
|
40
|
+
o = a;
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
} else {
|
|
43
|
+
s = t[0];
|
|
44
|
+
r = t[1];
|
|
45
|
+
o = t[2];
|
|
46
|
+
}
|
|
47
|
+
const c = r.name;
|
|
48
|
+
if (!TransversalManager.transversalInstances.has(c)) {
|
|
49
|
+
const e = n || this.context;
|
|
50
|
+
const t = e.require(s, o);
|
|
51
|
+
const i = getDefinition(r);
|
|
52
|
+
if (!i) {
|
|
53
|
+
throw new Error(`Transversal ${c} must be decorated with @Transversal`);
|
|
35
54
|
}
|
|
55
|
+
TransversalManager.transversalInstances.set(c, t);
|
|
56
|
+
const l = {
|
|
57
|
+
definition: i,
|
|
58
|
+
advices: this.extractAdvices(r, t),
|
|
59
|
+
instance: t
|
|
60
|
+
};
|
|
61
|
+
TransversalManager.transversalMetadata.set(c, l);
|
|
36
62
|
}
|
|
37
63
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
n
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
const o = getOwnCustomMetadata(c, a) || {};
|
|
59
|
-
o[s] = t;
|
|
60
|
-
defineCustomMetadata(c, o, a);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
64
|
+
extractAdvices(e, t) {
|
|
65
|
+
const n = getDefinition(e);
|
|
66
|
+
const s = [];
|
|
67
|
+
const r = n?.metadata?.advices || [];
|
|
68
|
+
for (const a of r){
|
|
69
|
+
const n = t[a.methodName];
|
|
70
|
+
if (typeof n !== 'function') {
|
|
71
|
+
throw new Error(`Advice method ${a.methodName} not found in ${e.name}`);
|
|
72
|
+
}
|
|
73
|
+
const r = a.pointcut.startsWith('execution(') ? undefined : a.pointcut;
|
|
74
|
+
s.push({
|
|
75
|
+
type: a.type,
|
|
76
|
+
pointcut: a.pointcut,
|
|
77
|
+
method: n,
|
|
78
|
+
transversalInstance: t,
|
|
79
|
+
priority: a.priority || 0,
|
|
80
|
+
enabled: a.enabled ?? true,
|
|
81
|
+
role: r
|
|
82
|
+
});
|
|
63
83
|
}
|
|
84
|
+
return s;
|
|
64
85
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
86
|
+
getAspectsForTarget(e) {
|
|
87
|
+
const t = [];
|
|
88
|
+
for (const a of TransversalManager.transversalMetadata.values()){
|
|
89
|
+
if (this.hasMatchingAdviceForClass(a, e)) {
|
|
90
|
+
t.push(a);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return t;
|
|
74
94
|
}
|
|
75
|
-
|
|
76
|
-
return
|
|
95
|
+
hasMatchingAdviceForClass(e, t) {
|
|
96
|
+
return e.advices.some((e)=>{
|
|
97
|
+
if (!e.enabled) return false;
|
|
98
|
+
const a = e.pointcut.match(/execution\(([^.]+)\.[^)]+\)/);
|
|
99
|
+
if (a) {
|
|
100
|
+
const e = a[1];
|
|
101
|
+
const n = this.patternToRegex(e);
|
|
102
|
+
return n.test(t.name);
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
});
|
|
77
106
|
}
|
|
78
|
-
|
|
79
|
-
|
|
107
|
+
patternToRegex(e) {
|
|
108
|
+
if (e === '*') {
|
|
109
|
+
return /.*/;
|
|
110
|
+
}
|
|
111
|
+
const t = e.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
|
|
112
|
+
const a = t.replace(/\*/g, '.*');
|
|
113
|
+
return new RegExp(`^${a}$`);
|
|
80
114
|
}
|
|
81
|
-
|
|
82
|
-
|
|
115
|
+
getAdvicesForJoinPoint(e, a, s, r) {
|
|
116
|
+
const o = [];
|
|
117
|
+
for (const n of a){
|
|
118
|
+
for (const a of n.advices){
|
|
119
|
+
if (!a.enabled) continue;
|
|
120
|
+
const n = PointcutMatcher.parse(a.pointcut);
|
|
121
|
+
if (n.matches(e)) {
|
|
122
|
+
o.push(a);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (s && r) {
|
|
127
|
+
const e = s.constructor.prototype;
|
|
128
|
+
const t = getAffectedMethods(e, r);
|
|
129
|
+
for (const e of t){
|
|
130
|
+
const t = e.transversal;
|
|
131
|
+
const a = typeof t === 'function' ? t.name : String(t);
|
|
132
|
+
let n = TransversalManager.transversalMetadata.get(a);
|
|
133
|
+
if (!n && typeof t === 'function') {
|
|
134
|
+
const e = Object.getPrototypeOf(t);
|
|
135
|
+
if (e && e.name) {
|
|
136
|
+
n = TransversalManager.transversalMetadata.get(e.name);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!n) {
|
|
140
|
+
console.warn(`@Affect: Transversal ${a} not found. Make sure it's registered in transversals[].`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
for (const t of n.advices){
|
|
144
|
+
if (!t.enabled) continue;
|
|
145
|
+
if (e.role && t.role !== e.role) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
o.push({
|
|
149
|
+
...t,
|
|
150
|
+
config: e.config
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return o.sort((e, t)=>t.priority - e.priority);
|
|
83
156
|
}
|
|
84
|
-
|
|
85
|
-
|
|
157
|
+
constructor(e){
|
|
158
|
+
this.context = e;
|
|
86
159
|
}
|
|
87
160
|
}
|
|
88
|
-
|
|
161
|
+
TransversalManager.instances = new WeakMap();
|
|
162
|
+
TransversalManager.transversalInstances = new Map();
|
|
163
|
+
TransversalManager.transversalMetadata = new Map();
|
|
89
164
|
|
|
90
|
-
export {
|
|
165
|
+
export { TransversalManager };
|
package/dist/index14.js
CHANGED
|
@@ -2,21 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
class AbstractTransversal {
|
|
6
|
+
static onRegister(s, t) {}
|
|
7
|
+
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
resolve(e, r, t) {
|
|
10
|
-
return r.publicContext;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const Context = (()=>{
|
|
14
|
-
resolverStore.ResolverStore.register('Context', ContextResolver);
|
|
15
|
-
return parameterDecoratorFactory.ParameterDecoratorFactory.create({
|
|
16
|
-
name: 'Context',
|
|
17
|
-
valueType: 'array',
|
|
18
|
-
resolver: ContextResolver
|
|
19
|
-
});
|
|
20
|
-
})();
|
|
21
|
-
|
|
22
|
-
exports.Context = Context;
|
|
9
|
+
exports.AbstractTransversal = AbstractTransversal;
|
package/dist/index14.mjs
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
class AbstractTransversal {
|
|
2
|
+
static onRegister(s, t) {}
|
|
3
|
+
}
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
resolve(e, r, t) {
|
|
6
|
-
return r.publicContext;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
const Context = (()=>{
|
|
10
|
-
ResolverStore.register('Context', ContextResolver);
|
|
11
|
-
return ParameterDecoratorFactory.create({
|
|
12
|
-
name: 'Context',
|
|
13
|
-
valueType: 'array',
|
|
14
|
-
resolver: ContextResolver
|
|
15
|
-
});
|
|
16
|
-
})();
|
|
17
|
-
|
|
18
|
-
export { Context };
|
|
5
|
+
export { AbstractTransversal };
|
package/dist/index15.js
CHANGED
|
@@ -2,21 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const Await = (t, e = 25)=>{
|
|
6
|
+
return (n, s, a)=>{
|
|
7
|
+
const i = a.value;
|
|
8
|
+
a.value = async function() {
|
|
9
|
+
return new Promise((n)=>{
|
|
10
|
+
if (this[t]) {
|
|
11
|
+
i.apply(this);
|
|
12
|
+
n();
|
|
13
|
+
} else {
|
|
14
|
+
const s = setInterval(()=>{
|
|
15
|
+
if (this[t]) {
|
|
16
|
+
clearInterval(s);
|
|
17
|
+
i.apply(this);
|
|
18
|
+
n();
|
|
19
|
+
}
|
|
20
|
+
}, e);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
};
|
|
12
25
|
};
|
|
13
|
-
const Configuration = (()=>{
|
|
14
|
-
resolverStore.ResolverStore.register('Configuration', ConfigurationResolver);
|
|
15
|
-
return parameterDecoratorFactory.ParameterDecoratorFactory.create({
|
|
16
|
-
name: 'Configuration',
|
|
17
|
-
valueType: 'array',
|
|
18
|
-
resolver: ConfigurationResolver
|
|
19
|
-
});
|
|
20
|
-
})();
|
|
21
26
|
|
|
22
|
-
exports.
|
|
27
|
+
exports.Await = Await;
|
package/dist/index15.mjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
const Await = (t, e = 25)=>{
|
|
2
|
+
return (n, s, a)=>{
|
|
3
|
+
const i = a.value;
|
|
4
|
+
a.value = async function() {
|
|
5
|
+
return new Promise((n)=>{
|
|
6
|
+
if (this[t]) {
|
|
7
|
+
i.apply(this);
|
|
8
|
+
n();
|
|
9
|
+
} else {
|
|
10
|
+
const s = setInterval(()=>{
|
|
11
|
+
if (this[t]) {
|
|
12
|
+
clearInterval(s);
|
|
13
|
+
i.apply(this);
|
|
14
|
+
n();
|
|
15
|
+
}
|
|
16
|
+
}, e);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
};
|
|
8
21
|
};
|
|
9
|
-
const Configuration = (()=>{
|
|
10
|
-
ResolverStore.register('Configuration', ConfigurationResolver);
|
|
11
|
-
return ParameterDecoratorFactory.create({
|
|
12
|
-
name: 'Configuration',
|
|
13
|
-
valueType: 'array',
|
|
14
|
-
resolver: ConfigurationResolver
|
|
15
|
-
});
|
|
16
|
-
})();
|
|
17
22
|
|
|
18
|
-
export {
|
|
23
|
+
export { Await };
|
package/dist/index16.js
CHANGED
|
@@ -2,21 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const resolverStore = require('./index32.js');
|
|
5
|
+
const reflection = require('./index34.js');
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name: 'Definition',
|
|
17
|
-
valueType: 'array',
|
|
18
|
-
resolver: DefinitionResolver
|
|
19
|
-
});
|
|
20
|
-
})();
|
|
7
|
+
const t = (t)=>()=>{
|
|
8
|
+
return (e, c, n)=>{
|
|
9
|
+
const a = reflection.getOwnCustomMetadata(t, e) || [];
|
|
10
|
+
a.push(n);
|
|
11
|
+
reflection.defineCustomMetadata(t, a, e);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const createParamIndexDecorator = t;
|
|
21
15
|
|
|
22
|
-
exports.
|
|
16
|
+
exports.createParamIndexDecorator = createParamIndexDecorator;
|
package/dist/index16.mjs
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ResolverStore } from './index32.mjs';
|
|
1
|
+
import { getOwnCustomMetadata, defineCustomMetadata } from './index34.mjs';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
name: 'Definition',
|
|
13
|
-
valueType: 'array',
|
|
14
|
-
resolver: DefinitionResolver
|
|
15
|
-
});
|
|
16
|
-
})();
|
|
3
|
+
const t = (t)=>()=>{
|
|
4
|
+
return (e, c, n)=>{
|
|
5
|
+
const a = getOwnCustomMetadata(t, e) || [];
|
|
6
|
+
a.push(n);
|
|
7
|
+
defineCustomMetadata(t, a, e);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const createParamIndexDecorator = t;
|
|
17
11
|
|
|
18
|
-
export {
|
|
12
|
+
export { createParamIndexDecorator };
|
package/dist/index17.js
CHANGED
|
@@ -2,21 +2,93 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const resolverStore = require('./index32.js');
|
|
5
|
+
const reflection = require('./index34.js');
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
class ParameterDecoratorFactory {
|
|
8
|
+
static create(e) {
|
|
9
|
+
const { name: r, valueType: t = 'single', handler: a } = e;
|
|
10
|
+
if (this.registeredDecorators.has(r)) {
|
|
11
|
+
throw new Error(`Decorator ${r} already exists`);
|
|
12
|
+
}
|
|
13
|
+
const s = `assemblage:${r.toLowerCase()}.param.index`;
|
|
14
|
+
const o = `assemblage:${r.toLowerCase()}.param.value`;
|
|
15
|
+
const c = this.createDecoratorFunction(s, o, t);
|
|
16
|
+
this.registeredDecorators.set(r, {
|
|
17
|
+
name: r,
|
|
18
|
+
valueType: t,
|
|
19
|
+
handler: a
|
|
20
|
+
});
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
static createDecoratorFunction(e, r, t) {
|
|
24
|
+
return (a)=>{
|
|
25
|
+
return (s, o, c)=>{
|
|
26
|
+
this.storeParameterData(a, s, c, e, r, t);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
static validateSingleDecoratorPerParameter(r, t, a) {
|
|
31
|
+
for (const s of this.registeredDecorators.keys()){
|
|
32
|
+
const o = `assemblage:${s.toLowerCase()}.param.index`;
|
|
33
|
+
if (o === a) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const c = reflection.getOwnCustomMetadata(o, r) || [];
|
|
37
|
+
if (c.includes(t)) {
|
|
38
|
+
throw new Error(`Parameter at index ${t} already has decorator @${s}. ` + `Multiple decorators per parameter are not allowed.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static storeParameterData(t, a, s, o, c, i) {
|
|
43
|
+
this.validateSingleDecoratorPerParameter(a, s, o);
|
|
44
|
+
const n = reflection.getOwnCustomMetadata(o, a) || [];
|
|
45
|
+
n.push(s);
|
|
46
|
+
reflection.defineCustomMetadata(o, n, a);
|
|
47
|
+
switch(i){
|
|
48
|
+
case 'single':
|
|
49
|
+
{
|
|
50
|
+
reflection.defineCustomMetadata(c, t, a);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'array':
|
|
54
|
+
{
|
|
55
|
+
const o = reflection.getOwnCustomMetadata(c, a) || [];
|
|
56
|
+
o[s] = t;
|
|
57
|
+
reflection.defineCustomMetadata(c, o, a);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'map':
|
|
61
|
+
{
|
|
62
|
+
const o = reflection.getOwnCustomMetadata(c, a) || {};
|
|
63
|
+
o[s] = t;
|
|
64
|
+
reflection.defineCustomMetadata(c, o, a);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static createParameterIndexGetter(r) {
|
|
70
|
+
return (t)=>{
|
|
71
|
+
return reflection.getOwnCustomMetadata(r, t) || [];
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
static createParameterValueGetter(r, t) {
|
|
75
|
+
return (t)=>{
|
|
76
|
+
return reflection.getOwnCustomMetadata(r, t);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
static getRegisteredDecorators() {
|
|
80
|
+
return Array.from(this.registeredDecorators.keys());
|
|
81
|
+
}
|
|
82
|
+
static isRegistered(e) {
|
|
83
|
+
return this.registeredDecorators.has(e);
|
|
84
|
+
}
|
|
85
|
+
static getDecoratorMetadata(e) {
|
|
86
|
+
return this.registeredDecorators.get(e);
|
|
87
|
+
}
|
|
88
|
+
static getDecoratorHandler(e) {
|
|
89
|
+
return this.registeredDecorators.get(e)?.handler;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
ParameterDecoratorFactory.registeredDecorators = new Map();
|
|
21
93
|
|
|
22
|
-
exports.
|
|
94
|
+
exports.ParameterDecoratorFactory = ParameterDecoratorFactory;
|
package/dist/index17.mjs
CHANGED
|
@@ -1,18 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ResolverStore } from './index32.mjs';
|
|
1
|
+
import { getOwnCustomMetadata, defineCustomMetadata } from './index34.mjs';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
class ParameterDecoratorFactory {
|
|
4
|
+
static create(e) {
|
|
5
|
+
const { name: r, valueType: t = 'single', handler: a } = e;
|
|
6
|
+
if (this.registeredDecorators.has(r)) {
|
|
7
|
+
throw new Error(`Decorator ${r} already exists`);
|
|
8
|
+
}
|
|
9
|
+
const s = `assemblage:${r.toLowerCase()}.param.index`;
|
|
10
|
+
const o = `assemblage:${r.toLowerCase()}.param.value`;
|
|
11
|
+
const c = this.createDecoratorFunction(s, o, t);
|
|
12
|
+
this.registeredDecorators.set(r, {
|
|
13
|
+
name: r,
|
|
14
|
+
valueType: t,
|
|
15
|
+
handler: a
|
|
16
|
+
});
|
|
17
|
+
return c;
|
|
18
|
+
}
|
|
19
|
+
static createDecoratorFunction(e, r, t) {
|
|
20
|
+
return (a)=>{
|
|
21
|
+
return (s, o, c)=>{
|
|
22
|
+
this.storeParameterData(a, s, c, e, r, t);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static validateSingleDecoratorPerParameter(r, t, a) {
|
|
27
|
+
for (const s of this.registeredDecorators.keys()){
|
|
28
|
+
const o = `assemblage:${s.toLowerCase()}.param.index`;
|
|
29
|
+
if (o === a) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const c = getOwnCustomMetadata(o, r) || [];
|
|
33
|
+
if (c.includes(t)) {
|
|
34
|
+
throw new Error(`Parameter at index ${t} already has decorator @${s}. ` + `Multiple decorators per parameter are not allowed.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static storeParameterData(t, a, s, o, c, i) {
|
|
39
|
+
this.validateSingleDecoratorPerParameter(a, s, o);
|
|
40
|
+
const n = getOwnCustomMetadata(o, a) || [];
|
|
41
|
+
n.push(s);
|
|
42
|
+
defineCustomMetadata(o, n, a);
|
|
43
|
+
switch(i){
|
|
44
|
+
case 'single':
|
|
45
|
+
{
|
|
46
|
+
defineCustomMetadata(c, t, a);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'array':
|
|
50
|
+
{
|
|
51
|
+
const o = getOwnCustomMetadata(c, a) || [];
|
|
52
|
+
o[s] = t;
|
|
53
|
+
defineCustomMetadata(c, o, a);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'map':
|
|
57
|
+
{
|
|
58
|
+
const o = getOwnCustomMetadata(c, a) || {};
|
|
59
|
+
o[s] = t;
|
|
60
|
+
defineCustomMetadata(c, o, a);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
static createParameterIndexGetter(r) {
|
|
66
|
+
return (t)=>{
|
|
67
|
+
return getOwnCustomMetadata(r, t) || [];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
static createParameterValueGetter(r, t) {
|
|
71
|
+
return (t)=>{
|
|
72
|
+
return getOwnCustomMetadata(r, t);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
static getRegisteredDecorators() {
|
|
76
|
+
return Array.from(this.registeredDecorators.keys());
|
|
77
|
+
}
|
|
78
|
+
static isRegistered(e) {
|
|
79
|
+
return this.registeredDecorators.has(e);
|
|
80
|
+
}
|
|
81
|
+
static getDecoratorMetadata(e) {
|
|
82
|
+
return this.registeredDecorators.get(e);
|
|
83
|
+
}
|
|
84
|
+
static getDecoratorHandler(e) {
|
|
85
|
+
return this.registeredDecorators.get(e)?.handler;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
ParameterDecoratorFactory.registeredDecorators = new Map();
|
|
17
89
|
|
|
18
|
-
export {
|
|
90
|
+
export { ParameterDecoratorFactory };
|