assemblerjs 0.8.1 → 0.8.3
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/dist/index.js +1 -921
- package/dist/index.mjs +921 -0
- package/package.json +6 -9
- package/dist/index.cjs +0 -1
package/dist/index.js
CHANGED
|
@@ -1,921 +1 @@
|
|
|
1
|
-
class AbstractAssemblage {
|
|
2
|
-
static onRegister(s, t) {}
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
const ReflectParamTypes = 'design:paramtypes';
|
|
6
|
-
const ReflectPrefix = '__';
|
|
7
|
-
const ReflectSuffix = '__';
|
|
8
|
-
var ReflectFlags;
|
|
9
|
-
(function(e) {
|
|
10
|
-
e["IsAssemblage"] = "is_assemblage";
|
|
11
|
-
})(ReflectFlags || (ReflectFlags = {}));
|
|
12
|
-
var ReflectValue;
|
|
13
|
-
(function(e) {
|
|
14
|
-
e["AssemblageDefinition"] = "assemblage:definition.value";
|
|
15
|
-
})(ReflectValue || (ReflectValue = {}));
|
|
16
|
-
|
|
17
|
-
const NoOp = (...e)=>{};
|
|
18
|
-
const isOfType = (...e)=>(t)=>{
|
|
19
|
-
if (!e.includes(typeof t)) return undefined;
|
|
20
|
-
return typeof t;
|
|
21
|
-
};
|
|
22
|
-
const isUndefined = (e)=>typeof e === 'undefined';
|
|
23
|
-
const isNull = (e)=>e === null;
|
|
24
|
-
const isDefined = (e)=>!isUndefined(e) && !isNull(e);
|
|
25
|
-
const isClass = (e)=>{
|
|
26
|
-
return e && typeof e === 'function' && typeof e.constructor !== 'undefined';
|
|
27
|
-
};
|
|
28
|
-
const isObject = (e)=>typeof e === 'object' && !Array.isArray(e) && !isClass(e);
|
|
29
|
-
const isAsync = (e)=>typeof e === 'function' && e.constructor.name === 'AsyncFunction';
|
|
30
|
-
const moveArrayItem = (e, t, r)=>{
|
|
31
|
-
const o = e[t];
|
|
32
|
-
e.splice(t, 1);
|
|
33
|
-
e.splice(r, 0, o);
|
|
34
|
-
return e;
|
|
35
|
-
};
|
|
36
|
-
const dedupeArray = (e)=>Array.from(new Set(e));
|
|
37
|
-
const onlyAlphanumeric = (e, ...t)=>{
|
|
38
|
-
t.map((e, r)=>{
|
|
39
|
-
const o = /\S/.test(e);
|
|
40
|
-
if (o) t[r] = t[r].trim();
|
|
41
|
-
return !o ? r : -1;
|
|
42
|
-
}).filter((e)=>e >= 0).every((e)=>{
|
|
43
|
-
t[e] = ' ';
|
|
44
|
-
moveArrayItem(t, e, t.length - 1);
|
|
45
|
-
});
|
|
46
|
-
t = dedupeArray(t);
|
|
47
|
-
const r = new RegExp(`[^A-Za-zÀ-ÖØ-öø-ÿ0-9${t.join('')}]`, 'gi');
|
|
48
|
-
return e.replace(r, '');
|
|
49
|
-
};
|
|
50
|
-
const switchCase = (e, t)=>(r, ...o)=>e[r] ? e[r](...o) : t ? t(r, ...o) : NoOp();
|
|
51
|
-
const pipe = (...e)=>(t)=>e.reduce((e, t)=>t(e), t);
|
|
52
|
-
const conditionally = (e)=>(t)=>{
|
|
53
|
-
return e.if(t) ? e.then(t) : e.else ? e.else(t) : undefined;
|
|
54
|
-
};
|
|
55
|
-
const forOf = (e)=>(t)=>{
|
|
56
|
-
const r = Array.isArray(e) ? (e)=>parseInt(e) : NoOp;
|
|
57
|
-
for (const [o, n] of Object.entries(e)){
|
|
58
|
-
t(n, r(o));
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const forIn = (e)=>(t)=>{
|
|
62
|
-
const r = Array.isArray(e) ? (e)=>parseInt(e) : (e)=>e;
|
|
63
|
-
for(const o in e){
|
|
64
|
-
t(r(o));
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const e$2 = (e, t)=>{
|
|
68
|
-
return [
|
|
69
|
-
...Object.getOwnPropertyNames(t.prototype),
|
|
70
|
-
...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),
|
|
71
|
-
...Object.getOwnPropertyNames(e)
|
|
72
|
-
];
|
|
73
|
-
};
|
|
74
|
-
const proxifyIterable = (t, r)=>{
|
|
75
|
-
const o = new Proxy(t, {
|
|
76
|
-
get: function(o, n) {
|
|
77
|
-
if (n === Symbol.iterator) {
|
|
78
|
-
return o[Symbol.iterator].bind(o);
|
|
79
|
-
} else if (!e$2(t, r).includes(n)) {
|
|
80
|
-
return o.collection[n];
|
|
81
|
-
}
|
|
82
|
-
return o[n];
|
|
83
|
-
},
|
|
84
|
-
set: function(e, t, r) {
|
|
85
|
-
return Reflect.set(e, t, r);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return o;
|
|
89
|
-
};
|
|
90
|
-
const clearInstance = (e, t)=>{
|
|
91
|
-
const r = (e, t)=>{
|
|
92
|
-
return [
|
|
93
|
-
...Object.getOwnPropertyNames(t.prototype),
|
|
94
|
-
...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),
|
|
95
|
-
...Object.getOwnPropertyNames(e)
|
|
96
|
-
];
|
|
97
|
-
};
|
|
98
|
-
const o = e;
|
|
99
|
-
for (const n of r(e, t)){
|
|
100
|
-
delete o[n];
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const defineCustomMetadata = (t, o, n)=>{
|
|
105
|
-
Reflect.defineMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o, n);
|
|
106
|
-
};
|
|
107
|
-
const getOwnCustomMetadata = (t, o)=>{
|
|
108
|
-
return Reflect.getOwnMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o);
|
|
109
|
-
};
|
|
110
|
-
const getParamTypes = (e)=>{
|
|
111
|
-
return Reflect.getMetadata(ReflectParamTypes, e) || [];
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const isAssemblage = (m)=>{
|
|
115
|
-
return getOwnCustomMetadata(ReflectFlags.IsAssemblage, m) || false;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const n = {
|
|
119
|
-
singleton: {
|
|
120
|
-
test: (r)=>typeof r === 'boolean' || typeof r === 'undefined',
|
|
121
|
-
throw: ()=>{
|
|
122
|
-
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
123
|
-
},
|
|
124
|
-
transform: (r)=>{
|
|
125
|
-
return typeof r === 'undefined' ? true : r ? true : false;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
events: {
|
|
129
|
-
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
130
|
-
throw: ()=>{
|
|
131
|
-
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
132
|
-
},
|
|
133
|
-
transform: (r)=>r
|
|
134
|
-
},
|
|
135
|
-
inject: {
|
|
136
|
-
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
137
|
-
throw: ()=>{
|
|
138
|
-
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
139
|
-
},
|
|
140
|
-
transform: (r)=>r
|
|
141
|
-
},
|
|
142
|
-
use: {
|
|
143
|
-
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length == 2),
|
|
144
|
-
throw: ()=>{
|
|
145
|
-
throw new Error(`'use' property must be an array of tuples of length 2.`);
|
|
146
|
-
},
|
|
147
|
-
transform: (r)=>r
|
|
148
|
-
},
|
|
149
|
-
tags: {
|
|
150
|
-
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
151
|
-
throw: ()=>{
|
|
152
|
-
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
153
|
-
},
|
|
154
|
-
transform: (r)=>typeof r === 'string' ? [
|
|
155
|
-
r
|
|
156
|
-
] : r
|
|
157
|
-
},
|
|
158
|
-
metadata: {
|
|
159
|
-
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
160
|
-
throw: ()=>{
|
|
161
|
-
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
162
|
-
},
|
|
163
|
-
transform: (r)=>r
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
const validateDefinition = (r)=>{
|
|
167
|
-
const t = {
|
|
168
|
-
...r
|
|
169
|
-
};
|
|
170
|
-
for(const r in t){
|
|
171
|
-
if (!Object.keys(n).includes(r)) {
|
|
172
|
-
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
for(const r in n){
|
|
176
|
-
const e = n[r].test;
|
|
177
|
-
const o = n[r].throw;
|
|
178
|
-
const s = n[r].transform;
|
|
179
|
-
if (!e(t[r])) {
|
|
180
|
-
o();
|
|
181
|
-
}
|
|
182
|
-
t[r] = s(t[r]);
|
|
183
|
-
}
|
|
184
|
-
return t;
|
|
185
|
-
};
|
|
186
|
-
const getDefinition = (t)=>{
|
|
187
|
-
if (!isAssemblage(t)) {
|
|
188
|
-
throw new Error(`Class '${t.name}' is not an assemblage.`);
|
|
189
|
-
}
|
|
190
|
-
return getOwnCustomMetadata(ReflectValue.AssemblageDefinition, t);
|
|
191
|
-
};
|
|
192
|
-
const getDefinitionValue = (r, t)=>{
|
|
193
|
-
const e = getDefinition(t);
|
|
194
|
-
return e[r];
|
|
195
|
-
};
|
|
196
|
-
const setDefinitionValue = (e, o, n)=>{
|
|
197
|
-
const s = getDefinition(n);
|
|
198
|
-
s[e] = o;
|
|
199
|
-
const i = validateDefinition(s);
|
|
200
|
-
defineCustomMetadata(ReflectValue.AssemblageDefinition, i, n);
|
|
201
|
-
return i;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const i$1 = (n)=>{
|
|
205
|
-
return {
|
|
206
|
-
identifier: n[0],
|
|
207
|
-
concrete: n[0],
|
|
208
|
-
configuration: {}
|
|
209
|
-
};
|
|
210
|
-
};
|
|
211
|
-
const c$2 = (r)=>{
|
|
212
|
-
const i = ()=>isClass(r[0]) && isClass(r[1]);
|
|
213
|
-
const c = ()=>isClass(r[0]) && isObject(r[1]);
|
|
214
|
-
const f = ()=>pipe(conditionally({
|
|
215
|
-
if: ()=>i(),
|
|
216
|
-
then: ()=>{
|
|
217
|
-
return {
|
|
218
|
-
identifier: r[0],
|
|
219
|
-
concrete: r[1],
|
|
220
|
-
configuration: {}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
}), conditionally({
|
|
224
|
-
if: ()=>c(),
|
|
225
|
-
then: ()=>{
|
|
226
|
-
return {
|
|
227
|
-
identifier: r[0],
|
|
228
|
-
concrete: r[0],
|
|
229
|
-
configuration: r[1]
|
|
230
|
-
};
|
|
231
|
-
},
|
|
232
|
-
else: (n)=>n
|
|
233
|
-
}))();
|
|
234
|
-
return f();
|
|
235
|
-
};
|
|
236
|
-
const f = (n)=>{
|
|
237
|
-
return {
|
|
238
|
-
identifier: n[0],
|
|
239
|
-
concrete: n[1],
|
|
240
|
-
configuration: n[2]
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
const resolveInjectionTuple = (n)=>switchCase({
|
|
244
|
-
1: ()=>i$1(n),
|
|
245
|
-
2: ()=>c$2(n),
|
|
246
|
-
3: ()=>f(n)
|
|
247
|
-
}, ()=>{
|
|
248
|
-
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
249
|
-
})(n.length);
|
|
250
|
-
|
|
251
|
-
const resolveInstanceInjectionTuple = (e)=>{
|
|
252
|
-
return {
|
|
253
|
-
identifier: e[0],
|
|
254
|
-
concrete: e[0],
|
|
255
|
-
instance: e[1],
|
|
256
|
-
configuration: {}
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const Assemblage = (e)=>{
|
|
261
|
-
return (o)=>{
|
|
262
|
-
return decorateAssemblage(o, e);
|
|
263
|
-
};
|
|
264
|
-
};
|
|
265
|
-
const decorateAssemblage = (s, m)=>{
|
|
266
|
-
const n = m ? validateDefinition(m) : validateDefinition({});
|
|
267
|
-
defineCustomMetadata(ReflectFlags.IsAssemblage, true, s);
|
|
268
|
-
defineCustomMetadata(ReflectValue.AssemblageDefinition, n, s);
|
|
269
|
-
return s;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
class AbstractListenerCollection {
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
class ListenerCollection {
|
|
276
|
-
dispose() {
|
|
277
|
-
clearInstance(this, ListenerCollection);
|
|
278
|
-
}
|
|
279
|
-
add(...t) {
|
|
280
|
-
const n = (t)=>this.collection[t.channel].push(t.listener);
|
|
281
|
-
const l = conditionally({
|
|
282
|
-
if: ()=>t.length === 2,
|
|
283
|
-
then: ()=>{
|
|
284
|
-
return {
|
|
285
|
-
channel: t[0],
|
|
286
|
-
listener: t[1]
|
|
287
|
-
};
|
|
288
|
-
},
|
|
289
|
-
else: ()=>{
|
|
290
|
-
const e = t[0];
|
|
291
|
-
return {
|
|
292
|
-
channel: e[0],
|
|
293
|
-
listener: e[1]
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
const c = conditionally({
|
|
298
|
-
if: (t)=>!isDefined(this.collection[t.channel]),
|
|
299
|
-
then: (t)=>{
|
|
300
|
-
this.collection[t.channel] = [];
|
|
301
|
-
n(t);
|
|
302
|
-
},
|
|
303
|
-
else: (t)=>{
|
|
304
|
-
n(t);
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
pipe(l, c)();
|
|
308
|
-
return this;
|
|
309
|
-
}
|
|
310
|
-
remove(t, n) {
|
|
311
|
-
const l = (e)=>this.collection[t].splice(e, 1);
|
|
312
|
-
const c = conditionally({
|
|
313
|
-
if: ()=>this.collection[t] && this.collection[t].length === 0,
|
|
314
|
-
then: ()=>delete this.collection[t]
|
|
315
|
-
});
|
|
316
|
-
const s = conditionally({
|
|
317
|
-
if: ()=>isDefined(n),
|
|
318
|
-
then: ()=>l(this.collection[t].indexOf(n)),
|
|
319
|
-
else: ()=>delete this.collection[t]
|
|
320
|
-
});
|
|
321
|
-
const r = conditionally({
|
|
322
|
-
if: (t)=>this.has(t),
|
|
323
|
-
then: (t)=>this.collection[t]
|
|
324
|
-
});
|
|
325
|
-
pipe(r, s, c)();
|
|
326
|
-
return this;
|
|
327
|
-
}
|
|
328
|
-
has(...t) {
|
|
329
|
-
if (isOfType('string')(t[0])) {
|
|
330
|
-
return Object.keys(this.collection).includes(t[0]);
|
|
331
|
-
} else if (isOfType('function')(t[0])) {
|
|
332
|
-
return Object.values(this.collection).flat().includes(t[0]);
|
|
333
|
-
}
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
get(...t) {
|
|
337
|
-
if (isOfType('string')(t[0])) {
|
|
338
|
-
return this.collection[t[0]];
|
|
339
|
-
} else if (isOfType('function')(t[0])) {
|
|
340
|
-
return Object.values(this.collection).flat().filter((e)=>e === t[0]);
|
|
341
|
-
}
|
|
342
|
-
return [];
|
|
343
|
-
}
|
|
344
|
-
clear() {
|
|
345
|
-
const t = forIn(this.collection);
|
|
346
|
-
const e = (t)=>forOf(this.collection[t])((e)=>this.remove(t, e));
|
|
347
|
-
t((t)=>e(t));
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
get listeners() {
|
|
351
|
-
return Object.values(this.collection).flat();
|
|
352
|
-
}
|
|
353
|
-
get channels() {
|
|
354
|
-
return Object.keys(this.collection);
|
|
355
|
-
}
|
|
356
|
-
get length() {
|
|
357
|
-
return Object.values(this.collection).flat().length;
|
|
358
|
-
}
|
|
359
|
-
[Symbol.iterator]() {
|
|
360
|
-
let t = -1;
|
|
361
|
-
const e = this.collection ? Object.keys(this.collection) : [];
|
|
362
|
-
return {
|
|
363
|
-
next: ()=>({
|
|
364
|
-
value: e[++t],
|
|
365
|
-
done: !(t in e)
|
|
366
|
-
})
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
constructor(){
|
|
370
|
-
this.collection = {};
|
|
371
|
-
const t = proxifyIterable(this, ListenerCollection);
|
|
372
|
-
return t;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
class AbstractEventManager {
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
class EventManager {
|
|
380
|
-
dispose() {
|
|
381
|
-
this.listeners.dispose();
|
|
382
|
-
this.channels.clear();
|
|
383
|
-
clearInstance(this, EventManager);
|
|
384
|
-
}
|
|
385
|
-
addChannels(...e) {
|
|
386
|
-
const s = forOf(e);
|
|
387
|
-
s((e)=>{
|
|
388
|
-
const n = this.cleanChannel(e);
|
|
389
|
-
if (this.channels.has(n)) {
|
|
390
|
-
throw new Error(`Channel '${n}' already exists.`);
|
|
391
|
-
}
|
|
392
|
-
this.channels.add(n);
|
|
393
|
-
});
|
|
394
|
-
return this;
|
|
395
|
-
}
|
|
396
|
-
removeChannels(...e) {
|
|
397
|
-
const s = forOf(e);
|
|
398
|
-
s((e)=>{
|
|
399
|
-
const n = this.cleanChannel(e);
|
|
400
|
-
if (n !== '*' && this.channels.has(n)) {
|
|
401
|
-
this.channels.delete(n);
|
|
402
|
-
this.listeners.remove(n);
|
|
403
|
-
this.onceListeners.remove(n);
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
return this;
|
|
407
|
-
}
|
|
408
|
-
on(e, n) {
|
|
409
|
-
const s = this.cleanChannel(e);
|
|
410
|
-
if (!this.channels.has(s)) {
|
|
411
|
-
throw new Error(`Channel '${s}' was not registered.`);
|
|
412
|
-
}
|
|
413
|
-
this.listeners.add(s, n);
|
|
414
|
-
return this;
|
|
415
|
-
}
|
|
416
|
-
once(e, n) {
|
|
417
|
-
const s = this.cleanChannel(e);
|
|
418
|
-
if (!this.channels.has(s)) {
|
|
419
|
-
throw new Error(`Channel '${s}' was not registered.`);
|
|
420
|
-
}
|
|
421
|
-
this.onceListeners.add(s, n);
|
|
422
|
-
return this;
|
|
423
|
-
}
|
|
424
|
-
off(e, n) {
|
|
425
|
-
const s = this.cleanChannel(e);
|
|
426
|
-
this.listeners.remove(s, n);
|
|
427
|
-
return this;
|
|
428
|
-
}
|
|
429
|
-
emit(e, ...s) {
|
|
430
|
-
const t = this.cleanChannel(e);
|
|
431
|
-
if (this.channels.has(t)) {
|
|
432
|
-
const e = this.onceListeners.get('*') || [];
|
|
433
|
-
const i = this.listeners.get('*') || [];
|
|
434
|
-
const h = this.onceListeners.get(t) || [];
|
|
435
|
-
const r = this.listeners.get(t) || [];
|
|
436
|
-
const o = forOf(e);
|
|
437
|
-
const c = forOf(i);
|
|
438
|
-
const a = forOf(h);
|
|
439
|
-
const l = forOf(r);
|
|
440
|
-
o((e)=>{
|
|
441
|
-
this.run(e, ...s);
|
|
442
|
-
this.onceListeners.remove('*', e);
|
|
443
|
-
});
|
|
444
|
-
c((e)=>{
|
|
445
|
-
this.run(e, ...s);
|
|
446
|
-
});
|
|
447
|
-
a((e)=>{
|
|
448
|
-
this.run(e, ...s);
|
|
449
|
-
this.onceListeners.remove(t, e);
|
|
450
|
-
});
|
|
451
|
-
l((e)=>{
|
|
452
|
-
this.run(e, ...s);
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
return this;
|
|
456
|
-
}
|
|
457
|
-
run(e, ...n) {
|
|
458
|
-
if (isAsync(e)) {
|
|
459
|
-
const s = e;
|
|
460
|
-
return s(...n).then(()=>Promise.resolve());
|
|
461
|
-
}
|
|
462
|
-
e(...n);
|
|
463
|
-
}
|
|
464
|
-
cleanChannel(e) {
|
|
465
|
-
return onlyAlphanumeric(e, '*');
|
|
466
|
-
}
|
|
467
|
-
constructor(...e){
|
|
468
|
-
this.listeners = new ListenerCollection();
|
|
469
|
-
this.onceListeners = new ListenerCollection();
|
|
470
|
-
this.channels = new Set([
|
|
471
|
-
'*'
|
|
472
|
-
]);
|
|
473
|
-
this.addChannels(...e);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
const registerEvents = (t, n)=>{
|
|
478
|
-
const o = t.concrete.prototype instanceof EventManager;
|
|
479
|
-
if (o) {
|
|
480
|
-
const e = n;
|
|
481
|
-
const o = e.channels;
|
|
482
|
-
for (const n of t.events){
|
|
483
|
-
if (!o.has(n)) e.addChannels(n);
|
|
484
|
-
if (!t.privateContext.events.has(n)) t.privateContext.addChannels(n);
|
|
485
|
-
}
|
|
486
|
-
for (const e of t.events){
|
|
487
|
-
n.on(e, (...n)=>{
|
|
488
|
-
t.privateContext.emit(e, ...n);
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
const unregisterEvents = (t, n)=>{
|
|
494
|
-
const o = t.concrete.prototype instanceof EventManager;
|
|
495
|
-
if (o) {
|
|
496
|
-
const e = n;
|
|
497
|
-
for (const n of t.events){
|
|
498
|
-
e.off(n);
|
|
499
|
-
}
|
|
500
|
-
e.removeChannels(...t.events);
|
|
501
|
-
t.privateContext.removeChannels(...t.events);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
const Await = (t, e = 25)=>{
|
|
506
|
-
return (n, s, a)=>{
|
|
507
|
-
const i = a.value;
|
|
508
|
-
a.value = async function() {
|
|
509
|
-
return new Promise((n)=>{
|
|
510
|
-
if (this[t]) {
|
|
511
|
-
i.apply(this);
|
|
512
|
-
n();
|
|
513
|
-
} else {
|
|
514
|
-
const s = setInterval(()=>{
|
|
515
|
-
if (this[t]) {
|
|
516
|
-
clearInterval(s);
|
|
517
|
-
i.apply(this);
|
|
518
|
-
n();
|
|
519
|
-
}
|
|
520
|
-
}, e);
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
var ReflectParamValue;
|
|
528
|
-
(function(e) {
|
|
529
|
-
e["UseIdentifier"] = "assemblage:use.param.value";
|
|
530
|
-
})(ReflectParamValue || (ReflectParamValue = {}));
|
|
531
|
-
var ReflectParamIndex;
|
|
532
|
-
(function(e) {
|
|
533
|
-
e["Context"] = "assembler:context.param.index";
|
|
534
|
-
e["Dispose"] = "assembler:dispose.param.index";
|
|
535
|
-
e["Definition"] = "assemblage:definition.param.index";
|
|
536
|
-
e["Configuration"] = "assemblage:configuration.param.index";
|
|
537
|
-
e["Use"] = "assemblage:use.param.index";
|
|
538
|
-
})(ReflectParamIndex || (ReflectParamIndex = {}));
|
|
539
|
-
|
|
540
|
-
const i = (t)=>()=>{
|
|
541
|
-
return (i, s, r)=>{
|
|
542
|
-
const c = getOwnCustomMetadata(t, i) || [];
|
|
543
|
-
c.push(r);
|
|
544
|
-
defineCustomMetadata(t, c, i);
|
|
545
|
-
};
|
|
546
|
-
};
|
|
547
|
-
const s$1 = i(ReflectParamIndex.Context);
|
|
548
|
-
const r$1 = i(ReflectParamIndex.Configuration);
|
|
549
|
-
const c$1 = i(ReflectParamIndex.Definition);
|
|
550
|
-
const e$1 = i(ReflectParamIndex.Dispose);
|
|
551
|
-
|
|
552
|
-
const Use = (e)=>{
|
|
553
|
-
return (o, t, s)=>{
|
|
554
|
-
decorateUse(e, o, s);
|
|
555
|
-
};
|
|
556
|
-
};
|
|
557
|
-
const decorateUse = (r, n, c)=>{
|
|
558
|
-
const U = getOwnCustomMetadata(ReflectParamIndex.Use, n) || [];
|
|
559
|
-
U.push(c);
|
|
560
|
-
defineCustomMetadata(ReflectParamIndex.Use, U, n);
|
|
561
|
-
const i = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, n) || {};
|
|
562
|
-
i[c] = r;
|
|
563
|
-
defineCustomMetadata(ReflectParamValue.UseIdentifier, i, n);
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
const o = (o)=>{
|
|
567
|
-
return getOwnCustomMetadata(ReflectParamIndex.Context, o) || [];
|
|
568
|
-
};
|
|
569
|
-
const r = (o)=>{
|
|
570
|
-
return getOwnCustomMetadata(ReflectParamIndex.Configuration, o) || [];
|
|
571
|
-
};
|
|
572
|
-
const e = (o)=>{
|
|
573
|
-
return getOwnCustomMetadata(ReflectParamIndex.Definition, o) || [];
|
|
574
|
-
};
|
|
575
|
-
const s = (o)=>{
|
|
576
|
-
return getOwnCustomMetadata(ReflectParamIndex.Dispose, o) || [];
|
|
577
|
-
};
|
|
578
|
-
const c = (o)=>{
|
|
579
|
-
return getOwnCustomMetadata(ReflectParamIndex.Use, o) || [];
|
|
580
|
-
};
|
|
581
|
-
const getDecoratedParametersIndexes = (t)=>{
|
|
582
|
-
const n = o(t) || [];
|
|
583
|
-
const i = e(t) || [];
|
|
584
|
-
const m = r(t) || [];
|
|
585
|
-
const u = s(t) || [];
|
|
586
|
-
const a = c(t) || [];
|
|
587
|
-
return {
|
|
588
|
-
Context: n,
|
|
589
|
-
Definition: i,
|
|
590
|
-
Configuration: m,
|
|
591
|
-
Dispose: u,
|
|
592
|
-
Use: a
|
|
593
|
-
};
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
const createConstructorDecorator = (t)=>{
|
|
597
|
-
return (o = true)=>ConstructorDecorator(t, o);
|
|
598
|
-
};
|
|
599
|
-
const ConstructorDecorator = (f, a = true)=>(p)=>{
|
|
600
|
-
const m = class extends p {
|
|
601
|
-
constructor(...t){
|
|
602
|
-
super(...t);
|
|
603
|
-
if (f) f.call(this);
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
Object.defineProperty(m, 'name', {
|
|
607
|
-
value: p.name
|
|
608
|
-
});
|
|
609
|
-
if (!a) {
|
|
610
|
-
return m;
|
|
611
|
-
}
|
|
612
|
-
const l = Reflect.getOwnMetadata(ReflectParamTypes, p) || [];
|
|
613
|
-
const D = getDecoratedParametersIndexes(p);
|
|
614
|
-
const d = [];
|
|
615
|
-
for(let n = 0; n < l.length; n++){
|
|
616
|
-
if (D.Context.includes(n)) {
|
|
617
|
-
const e = getOwnCustomMetadata(ReflectParamIndex.Context, p) || [];
|
|
618
|
-
e.push(n);
|
|
619
|
-
defineCustomMetadata(ReflectParamIndex.Context, e, m);
|
|
620
|
-
continue;
|
|
621
|
-
}
|
|
622
|
-
if (D.Definition.includes(n)) {
|
|
623
|
-
const e = getOwnCustomMetadata(ReflectParamIndex.Definition, p) || [];
|
|
624
|
-
e.push(n);
|
|
625
|
-
defineCustomMetadata(ReflectParamIndex.Definition, e, m);
|
|
626
|
-
continue;
|
|
627
|
-
}
|
|
628
|
-
if (D.Configuration.includes(n)) {
|
|
629
|
-
const e = getOwnCustomMetadata(ReflectParamIndex.Configuration, p) || [];
|
|
630
|
-
e.push(n);
|
|
631
|
-
defineCustomMetadata(ReflectParamIndex.Configuration, e, m);
|
|
632
|
-
continue;
|
|
633
|
-
}
|
|
634
|
-
if (D.Dispose.includes(n)) {
|
|
635
|
-
const e = getOwnCustomMetadata(ReflectParamIndex.Dispose, p) || [];
|
|
636
|
-
e.push(n);
|
|
637
|
-
defineCustomMetadata(ReflectParamIndex.Dispose, e, m);
|
|
638
|
-
d.push(l[n]);
|
|
639
|
-
continue;
|
|
640
|
-
}
|
|
641
|
-
if (D.Use.includes(n)) {
|
|
642
|
-
const t = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, p);
|
|
643
|
-
decorateUse(t[n], m, n);
|
|
644
|
-
continue;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
if (!a) return m;
|
|
648
|
-
return decorateAssemblage(m, getOwnCustomMetadata(ReflectValue.AssemblageDefinition, p));
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
const resolveInjectableParameters = (i)=>{
|
|
652
|
-
const s = [];
|
|
653
|
-
const c = getParamTypes(i.concrete);
|
|
654
|
-
const r = getDecoratedParametersIndexes(i.concrete);
|
|
655
|
-
let u = 0;
|
|
656
|
-
for (const n of c){
|
|
657
|
-
if (r.Context.includes(u)) {
|
|
658
|
-
s.push(i.publicContext);
|
|
659
|
-
u++;
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
if (r.Configuration.includes(u)) {
|
|
663
|
-
s.push(i.configuration);
|
|
664
|
-
u++;
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
|
-
if (r.Definition.includes(u)) {
|
|
668
|
-
s.push(i.definition);
|
|
669
|
-
u++;
|
|
670
|
-
continue;
|
|
671
|
-
}
|
|
672
|
-
if (r.Dispose.includes(u)) {
|
|
673
|
-
s.push(i.privateContext.dispose);
|
|
674
|
-
u++;
|
|
675
|
-
continue;
|
|
676
|
-
}
|
|
677
|
-
if (r.Use.includes(u)) {
|
|
678
|
-
const n = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, i.concrete);
|
|
679
|
-
const t = n[u];
|
|
680
|
-
s.push(i.privateContext.require(t));
|
|
681
|
-
u++;
|
|
682
|
-
continue;
|
|
683
|
-
}
|
|
684
|
-
s.push(i.privateContext.require(n));
|
|
685
|
-
u++;
|
|
686
|
-
}
|
|
687
|
-
return s;
|
|
688
|
-
};
|
|
689
|
-
const resolveDependencies = (e)=>{
|
|
690
|
-
const o = [];
|
|
691
|
-
const i = getParamTypes(e);
|
|
692
|
-
const s = getDecoratedParametersIndexes(e);
|
|
693
|
-
let c = 0;
|
|
694
|
-
for (const e of i){
|
|
695
|
-
if (s.Context.includes(c) || s.Configuration.includes(c) || s.Definition.includes(c) || s.Dispose.includes(c) || s.Use.includes(c)) {
|
|
696
|
-
c++;
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
o.push(e);
|
|
700
|
-
c++;
|
|
701
|
-
}
|
|
702
|
-
return o;
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
class Injectable {
|
|
706
|
-
static of(t, e, n) {
|
|
707
|
-
return new Injectable(t, e, n);
|
|
708
|
-
}
|
|
709
|
-
dispose() {
|
|
710
|
-
if (this.singletonInstance) {
|
|
711
|
-
unregisterEvents(this, this.singletonInstance);
|
|
712
|
-
callHook(this.singletonInstance, 'onDispose', this.publicContext, this.configuration);
|
|
713
|
-
clearInstance(this.singletonInstance, this.concrete);
|
|
714
|
-
}
|
|
715
|
-
clearInstance(this, Injectable);
|
|
716
|
-
}
|
|
717
|
-
build() {
|
|
718
|
-
if (this.singletonInstance) return this.singletonInstance;
|
|
719
|
-
const t = resolveInjectableParameters(this);
|
|
720
|
-
const e = new this.concrete(...t);
|
|
721
|
-
registerEvents(this, e);
|
|
722
|
-
if (this.isSingleton) {
|
|
723
|
-
this.singletonInstance = e;
|
|
724
|
-
this.privateContext.prepareInitHook(e, this.configuration);
|
|
725
|
-
return this.singletonInstance;
|
|
726
|
-
}
|
|
727
|
-
callHook(e, 'onInit', this.publicContext);
|
|
728
|
-
return e;
|
|
729
|
-
}
|
|
730
|
-
get dependencies() {
|
|
731
|
-
return this.dependenciesIds;
|
|
732
|
-
}
|
|
733
|
-
get definition() {
|
|
734
|
-
return getDefinition(this.concrete) || {};
|
|
735
|
-
}
|
|
736
|
-
get isSingleton() {
|
|
737
|
-
return getDefinitionValue('singleton', this.concrete);
|
|
738
|
-
}
|
|
739
|
-
get singleton() {
|
|
740
|
-
return this.singletonInstance;
|
|
741
|
-
}
|
|
742
|
-
get injections() {
|
|
743
|
-
return getDefinitionValue('inject', this.concrete) || [];
|
|
744
|
-
}
|
|
745
|
-
get objects() {
|
|
746
|
-
return getDefinitionValue('use', this.concrete) || [];
|
|
747
|
-
}
|
|
748
|
-
get tags() {
|
|
749
|
-
return getDefinitionValue('tags', this.concrete) || [];
|
|
750
|
-
}
|
|
751
|
-
get events() {
|
|
752
|
-
return getDefinitionValue('events', this.concrete) || [];
|
|
753
|
-
}
|
|
754
|
-
constructor(t, i, s){
|
|
755
|
-
this.privateContext = i;
|
|
756
|
-
this.publicContext = s;
|
|
757
|
-
this.dependenciesIds = [];
|
|
758
|
-
this.identifier = t.identifier;
|
|
759
|
-
this.concrete = t.concrete;
|
|
760
|
-
this.configuration = t.configuration;
|
|
761
|
-
if (!isAssemblage(this.concrete)) {
|
|
762
|
-
throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);
|
|
763
|
-
}
|
|
764
|
-
const o = forOf(this.injections);
|
|
765
|
-
const r = forOf(this.objects);
|
|
766
|
-
o((t)=>this.privateContext.register(t));
|
|
767
|
-
r((t)=>{
|
|
768
|
-
if (typeof t[0] === 'string' || typeof t[0] === 'symbol') {
|
|
769
|
-
this.privateContext.use(t[0], t[1]);
|
|
770
|
-
} else {
|
|
771
|
-
this.privateContext.register(t, true);
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
this.dependenciesIds = resolveDependencies(this.concrete);
|
|
775
|
-
if (t.instance) {
|
|
776
|
-
this.singletonInstance = t.instance;
|
|
777
|
-
} else if (this.isSingleton) ;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
const callHook = (n, r, t, e)=>{
|
|
782
|
-
return new Promise((i)=>{
|
|
783
|
-
const m = n[r];
|
|
784
|
-
if (m) {
|
|
785
|
-
if (isAsync(m)) {
|
|
786
|
-
m.bind(n)(t, e).then(()=>{
|
|
787
|
-
i();
|
|
788
|
-
});
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
i(m.bind(n)(t, e));
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
class Assembler extends EventManager {
|
|
797
|
-
static build(e) {
|
|
798
|
-
const i = new Assembler();
|
|
799
|
-
setDefinitionValue('singleton', true, e);
|
|
800
|
-
const s = i.register([
|
|
801
|
-
e
|
|
802
|
-
]);
|
|
803
|
-
const n = i.require(s.identifier);
|
|
804
|
-
const r = i.initCache.find((e)=>e.instance === n);
|
|
805
|
-
if (!r) {
|
|
806
|
-
throw new Error('Root instance not found in assemblages cache.');
|
|
807
|
-
}
|
|
808
|
-
const h = i.initCache.indexOf(r);
|
|
809
|
-
i.initCache.splice(h, 1);
|
|
810
|
-
for (const e of i.initCache){
|
|
811
|
-
callHook(e.instance, 'onInit', i.publicContext, e.configuration);
|
|
812
|
-
}
|
|
813
|
-
callHook(n, 'onInit', i.publicContext, s.configuration);
|
|
814
|
-
i.initCache.length = 0;
|
|
815
|
-
return n;
|
|
816
|
-
}
|
|
817
|
-
dispose() {
|
|
818
|
-
for (const [e, t] of this.injectables){
|
|
819
|
-
t.dispose();
|
|
820
|
-
}
|
|
821
|
-
clearInstance(this, Assembler);
|
|
822
|
-
}
|
|
823
|
-
register(e, t = false) {
|
|
824
|
-
const r = t === true ? resolveInstanceInjectionTuple(e) : resolveInjectionTuple(e);
|
|
825
|
-
if (this.has(r.identifier)) {
|
|
826
|
-
throw new Error(`An assemblage is already registered with identifier '${r.identifier.name}'.`);
|
|
827
|
-
}
|
|
828
|
-
const h = Injectable.of(r, this.privateContext, this.publicContext);
|
|
829
|
-
this.injectables.set(h.identifier, h);
|
|
830
|
-
callHook(h.concrete, 'onRegister', this.publicContext, h.configuration);
|
|
831
|
-
return h;
|
|
832
|
-
}
|
|
833
|
-
use(e, t) {
|
|
834
|
-
if (this.has(e)) {
|
|
835
|
-
throw new Error(`A value is already registered with identifier '${String(e)}'.`);
|
|
836
|
-
}
|
|
837
|
-
this.objects.set(e, t);
|
|
838
|
-
return t;
|
|
839
|
-
}
|
|
840
|
-
prepareInitHook(e, t) {
|
|
841
|
-
this.initCache.push({
|
|
842
|
-
instance: e,
|
|
843
|
-
configuration: t
|
|
844
|
-
});
|
|
845
|
-
return this.initCache;
|
|
846
|
-
}
|
|
847
|
-
has(e) {
|
|
848
|
-
if (typeof e === 'string' || typeof e === 'symbol') {
|
|
849
|
-
return this.objects.has(e);
|
|
850
|
-
}
|
|
851
|
-
return this.injectables.has(e);
|
|
852
|
-
}
|
|
853
|
-
require(e) {
|
|
854
|
-
switch(typeof e){
|
|
855
|
-
case 'string':
|
|
856
|
-
case 'symbol':
|
|
857
|
-
{
|
|
858
|
-
if (!this.objects.has(e)) {
|
|
859
|
-
throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);
|
|
860
|
-
}
|
|
861
|
-
return this.objects.get(e);
|
|
862
|
-
}
|
|
863
|
-
default:
|
|
864
|
-
{
|
|
865
|
-
if (!this.injectables.has(e)) {
|
|
866
|
-
throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);
|
|
867
|
-
}
|
|
868
|
-
const t = this.injectables.get(e);
|
|
869
|
-
return t.build();
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
concrete(e) {
|
|
874
|
-
const t = this.injectables.get(e);
|
|
875
|
-
if (t) return t.concrete;
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
tagged(...e) {
|
|
879
|
-
const t = [];
|
|
880
|
-
for (const i of e){
|
|
881
|
-
for (const [e, s] of this.injectables){
|
|
882
|
-
if (s.tags.includes(i)) t.push(s.build());
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
return t;
|
|
886
|
-
}
|
|
887
|
-
get size() {
|
|
888
|
-
return this.injectables.size;
|
|
889
|
-
}
|
|
890
|
-
constructor(){
|
|
891
|
-
super();
|
|
892
|
-
this.injectables = new Map();
|
|
893
|
-
this.objects = new Map();
|
|
894
|
-
this.initCache = [];
|
|
895
|
-
this.publicContext = {
|
|
896
|
-
has: this.has.bind(this),
|
|
897
|
-
require: this.require.bind(this),
|
|
898
|
-
concrete: this.concrete.bind(this),
|
|
899
|
-
tagged: this.tagged.bind(this),
|
|
900
|
-
dispose: this.dispose.bind(this),
|
|
901
|
-
on: this.on.bind(this),
|
|
902
|
-
once: this.once.bind(this),
|
|
903
|
-
off: this.off.bind(this),
|
|
904
|
-
events: this.channels
|
|
905
|
-
};
|
|
906
|
-
this.privateContext = {
|
|
907
|
-
...this.publicContext,
|
|
908
|
-
register: this.register.bind(this),
|
|
909
|
-
use: this.use.bind(this),
|
|
910
|
-
prepareInitHook: this.prepareInitHook.bind(this),
|
|
911
|
-
emit: this.emit.bind(this),
|
|
912
|
-
addChannels: this.addChannels.bind(this),
|
|
913
|
-
removeChannels: this.removeChannels.bind(this)
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
class AbstractAssembler extends AbstractEventManager {
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
export { AbstractAssemblage, AbstractAssembler, AbstractEventManager, AbstractListenerCollection, Assemblage, Assembler, Await, r$1 as Configuration, ConstructorDecorator, s$1 as Context, c$1 as Definition, e$1 as Dispose, EventManager, ListenerCollection, ReflectParamIndex, ReflectParamValue, Use, createConstructorDecorator, decorateAssemblage, decorateUse, getDecoratedParametersIndexes, isAssemblage };
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="design:paramtypes";var t,n;(t||(t={})).IsAssemblage="is_assemblage",(n||(n={})).AssemblageDefinition="assemblage:definition.value";const s=(...e)=>{},i=(...e)=>t=>{if(e.includes(typeof t))return typeof t},r=e=>!(e=>void 0===e)(e)&&!(e=>null===e)(e),o=e=>e&&"function"==typeof e&&void 0!==e.constructor,a=e=>"function"==typeof e&&"AsyncFunction"===e.constructor.name,c=(e,...t)=>{t.map(((e,n)=>{const s=/\S/.test(e);return s&&(t[n]=t[n].trim()),s?-1:n})).filter((e=>e>=0)).every((e=>{t[e]=" ",((e,t,n)=>{const s=e[t];e.splice(t,1),e.splice(n,0,s)})(t,e,t.length-1)})),t=(e=>Array.from(new Set(e)))(t);const n=new RegExp(`[^A-Za-zÀ-ÖØ-öø-ÿ0-9${t.join("")}]`,"gi");return e.replace(n,"")},l=(...e)=>t=>e.reduce(((e,t)=>t(e)),t),h=e=>t=>e.if(t)?e.then(t):e.else?e.else(t):void 0,f=e=>t=>{const n=Array.isArray(e)?e=>parseInt(e):s;for(const[s,i]of Object.entries(e))t(i,n(s))},u=(e,t)=>{const n=new Proxy(e,{get:function(n,s){return s===Symbol.iterator?n[Symbol.iterator].bind(n):((e,t)=>[...Object.getOwnPropertyNames(t.prototype),...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),...Object.getOwnPropertyNames(e)])(e,t).includes(s)?n[s]:n.collection[s]},set:function(e,t,n){return Reflect.set(e,t,n)}});return n},p=(e,t)=>{const n=e;for(const s of((e,t)=>[...Object.getOwnPropertyNames(t.prototype),...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),...Object.getOwnPropertyNames(e)])(e,t))delete n[s]},d=(e,t,n)=>{Reflect.defineMetadata(`__${e}__`,t,n)},g=(e,t)=>Reflect.getOwnMetadata(`__${e}__`,t),m=t=>Reflect.getMetadata(e,t)||[],x=e=>g(t.IsAssemblage,e)||!1,b={singleton:{test:e=>"boolean"==typeof e||void 0===e,throw:()=>{throw new Error("'singleton' property must be of type 'boolean' or 'undefined'.")},transform:e=>void 0===e||!!e},events:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>"string"==typeof e)),throw:()=>{throw new Error("'events' property must be an array of strings or 'undefined'.")},transform:e=>e},inject:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>Array.isArray(e)&&e.length>=1&&e.length<=3)),throw:()=>{throw new Error("'inject' property must be an array of tuples of length 1, 2 or 3.")},transform:e=>e},use:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>Array.isArray(e)&&2==e.length)),throw:()=>{throw new Error("'use' property must be an array of tuples of length 2.")},transform:e=>e},tags:{test:e=>void 0===e||"string"==typeof e||Array.isArray(e)&&e.every((e=>"string"==typeof e)),throw:()=>{throw new Error("'tags' property must be a string or an array of strings.")},transform:e=>"string"==typeof e?[e]:e},metadata:{test:e=>("object"==typeof e||void 0===e)&&!Array.isArray(e),throw:()=>{throw new Error("'metadata' property must be of type 'object' or 'undefined'.")},transform:e=>e}},y=e=>{const t={...e};for(const n in t)if(!Object.keys(b).includes(n))throw new Error(`Property '${n}' is not a valid assemblage definition property.`);for(const n in b){const e=b[n].test,s=b[n].throw,i=b[n].transform;e(t[n])||s(),t[n]=i(t[n])}return t},C=e=>{if(!x(e))throw new Error(`Class '${e.name}' is not an assemblage.`);return g(n.AssemblageDefinition,e)},v=(e,t)=>C(t)[e],w=e=>{const t=()=>o(e[0])&&(e=>"object"==typeof e&&!Array.isArray(e)&&!o(e))(e[1]);return l(h({if:()=>o(e[0])&&o(e[1]),then:()=>({identifier:e[0],concrete:e[1],configuration:{}})}),h({if:()=>t(),then:()=>({identifier:e[0],concrete:e[0],configuration:e[1]}),else:e=>e}))()},I=(e,s)=>{const i=y(s||{});return d(t.IsAssemblage,!0,e),d(n.AssemblageDefinition,i,e),e};class j{dispose(){p(this,j)}add(...e){const t=e=>this.collection[e.channel].push(e.listener),n=h({if:()=>2===e.length,then:()=>({channel:e[0],listener:e[1]}),else:()=>{const t=e[0];return{channel:t[0],listener:t[1]}}}),s=h({if:e=>!r(this.collection[e.channel]),then:e=>{this.collection[e.channel]=[],t(e)},else:e=>{t(e)}});return l(n,s)(),this}remove(e,t){const n=t=>this.collection[e].splice(t,1),s=h({if:()=>this.collection[e]&&0===this.collection[e].length,then:()=>delete this.collection[e]}),i=h({if:()=>r(t),then:()=>n(this.collection[e].indexOf(t)),else:()=>delete this.collection[e]}),o=h({if:e=>this.has(e),then:e=>this.collection[e]});return l(o,i,s)(),this}has(...e){return i("string")(e[0])?Object.keys(this.collection).includes(e[0]):!!i("function")(e[0])&&Object.values(this.collection).flat().includes(e[0])}get(...e){return i("string")(e[0])?this.collection[e[0]]:i("function")(e[0])?Object.values(this.collection).flat().filter((t=>t===e[0])):[]}clear(){const e=(e=>t=>{const n=Array.isArray(e)?e=>parseInt(e):e=>e;for(const s in e)t(n(s))})(this.collection),t=e=>f(this.collection[e])((t=>this.remove(e,t)));return e((e=>t(e))),this}get listeners(){return Object.values(this.collection).flat()}get channels(){return Object.keys(this.collection)}get length(){return Object.values(this.collection).flat().length}[Symbol.iterator](){let e=-1;const t=this.collection?Object.keys(this.collection):[];return{next:()=>({value:t[++e],done:!(e in t)})}}constructor(){this.collection={};return u(this,j)}}class A{}class P{dispose(){this.listeners.dispose(),this.channels.clear(),p(this,P)}addChannels(...e){return f(e)((e=>{const t=this.cleanChannel(e);if(this.channels.has(t))throw new Error(`Channel '${t}' already exists.`);this.channels.add(t)})),this}removeChannels(...e){return f(e)((e=>{const t=this.cleanChannel(e);"*"!==t&&this.channels.has(t)&&(this.channels.delete(t),this.listeners.remove(t),this.onceListeners.remove(t))})),this}on(e,t){const n=this.cleanChannel(e);if(!this.channels.has(n))throw new Error(`Channel '${n}' was not registered.`);return this.listeners.add(n,t),this}once(e,t){const n=this.cleanChannel(e);if(!this.channels.has(n))throw new Error(`Channel '${n}' was not registered.`);return this.onceListeners.add(n,t),this}off(e,t){const n=this.cleanChannel(e);return this.listeners.remove(n,t),this}emit(e,...t){const n=this.cleanChannel(e);if(this.channels.has(n)){const e=this.onceListeners.get("*")||[],s=this.listeners.get("*")||[],i=this.onceListeners.get(n)||[],r=this.listeners.get(n)||[],o=f(e),a=f(s),c=f(i),l=f(r);o((e=>{this.run(e,...t),this.onceListeners.remove("*",e)})),a((e=>{this.run(e,...t)})),c((e=>{this.run(e,...t),this.onceListeners.remove(n,e)})),l((e=>{this.run(e,...t)}))}return this}run(e,...t){if(a(e)){return e(...t).then((()=>Promise.resolve()))}e(...t)}cleanChannel(e){return c(e,"*")}constructor(...e){this.listeners=new j,this.onceListeners=new j,this.channels=new Set(["*"]),this.addChannels(...e)}}exports.ReflectParamValue=void 0,(exports.ReflectParamValue||(exports.ReflectParamValue={})).UseIdentifier="assemblage:use.param.value",exports.ReflectParamIndex=void 0,function(e){e.Context="assembler:context.param.index",e.Dispose="assembler:dispose.param.index",e.Definition="assemblage:definition.param.index",e.Configuration="assemblage:configuration.param.index",e.Use="assemblage:use.param.index"}(exports.ReflectParamIndex||(exports.ReflectParamIndex={}));const R=e=>()=>(t,n,s)=>{const i=g(e,t)||[];i.push(s),d(e,i,t)},O=R(exports.ReflectParamIndex.Context),D=R(exports.ReflectParamIndex.Configuration),E=R(exports.ReflectParamIndex.Definition),U=R(exports.ReflectParamIndex.Dispose),S=(e,t,n)=>{const s=g(exports.ReflectParamIndex.Use,t)||[];s.push(n),d(exports.ReflectParamIndex.Use,s,t);const i=g(exports.ReflectParamValue.UseIdentifier,t)||{};i[n]=e,d(exports.ReflectParamValue.UseIdentifier,i,t)},$=e=>{const t=(e=>g(exports.ReflectParamIndex.Context,e)||[])(e)||[],n=(e=>g(exports.ReflectParamIndex.Definition,e)||[])(e)||[],s=(e=>g(exports.ReflectParamIndex.Configuration,e)||[])(e)||[],i=(e=>g(exports.ReflectParamIndex.Dispose,e)||[])(e)||[],r=(e=>g(exports.ReflectParamIndex.Use,e)||[])(e)||[];return{Context:t,Definition:n,Configuration:s,Dispose:i,Use:r}},L=(t,s=!0)=>i=>{const r=class extends i{constructor(...e){super(...e),t&&t.call(this)}};if(Object.defineProperty(r,"name",{value:i.name}),!s)return r;const o=Reflect.getOwnMetadata(e,i)||[],a=$(i),c=[];for(let e=0;e<o.length;e++)if(a.Context.includes(e)){const t=g(exports.ReflectParamIndex.Context,i)||[];t.push(e),d(exports.ReflectParamIndex.Context,t,r)}else if(a.Definition.includes(e)){const t=g(exports.ReflectParamIndex.Definition,i)||[];t.push(e),d(exports.ReflectParamIndex.Definition,t,r)}else if(a.Configuration.includes(e)){const t=g(exports.ReflectParamIndex.Configuration,i)||[];t.push(e),d(exports.ReflectParamIndex.Configuration,t,r)}else if(a.Dispose.includes(e)){const t=g(exports.ReflectParamIndex.Dispose,i)||[];t.push(e),d(exports.ReflectParamIndex.Dispose,t,r),c.push(o[e])}else if(a.Use.includes(e)){const t=g(exports.ReflectParamValue.UseIdentifier,i);S(t[e],r,e)}else;return s?I(r,g(n.AssemblageDefinition,i)):r};class M{static of(e,t,n){return new M(e,t,n)}dispose(){this.singletonInstance&&(((e,t)=>{if(e.concrete.prototype instanceof P){const n=t;for(const t of e.events)n.off(t);n.removeChannels(...e.events),e.privateContext.removeChannels(...e.events)}})(this,this.singletonInstance),_(this.singletonInstance,"onDispose",this.publicContext,this.configuration),p(this.singletonInstance,this.concrete)),p(this,M)}build(){if(this.singletonInstance)return this.singletonInstance;const e=(e=>{const t=[],n=m(e.concrete),s=$(e.concrete);let i=0;for(const r of n)if(s.Context.includes(i))t.push(e.publicContext),i++;else if(s.Configuration.includes(i))t.push(e.configuration),i++;else if(s.Definition.includes(i))t.push(e.definition),i++;else if(s.Dispose.includes(i))t.push(e.privateContext.dispose),i++;else if(s.Use.includes(i)){const n=g(exports.ReflectParamValue.UseIdentifier,e.concrete)[i];t.push(e.privateContext.require(n)),i++}else t.push(e.privateContext.require(r)),i++;return t})(this),t=new this.concrete(...e);return((e,t)=>{if(e.concrete.prototype instanceof P){const n=t,s=n.channels;for(const t of e.events)s.has(t)||n.addChannels(t),e.privateContext.events.has(t)||e.privateContext.addChannels(t);for(const i of e.events)t.on(i,((...t)=>{e.privateContext.emit(i,...t)}))}})(this,t),this.isSingleton?(this.singletonInstance=t,this.privateContext.prepareInitHook(t,this.configuration),this.singletonInstance):(_(t,"onInit",this.publicContext),t)}get dependencies(){return this.dependenciesIds}get definition(){return C(this.concrete)||{}}get isSingleton(){return v("singleton",this.concrete)}get singleton(){return this.singletonInstance}get injections(){return v("inject",this.concrete)||[]}get objects(){return v("use",this.concrete)||[]}get tags(){return v("tags",this.concrete)||[]}get events(){return v("events",this.concrete)||[]}constructor(e,t,n){if(this.privateContext=t,this.publicContext=n,this.dependenciesIds=[],this.identifier=e.identifier,this.concrete=e.concrete,this.configuration=e.configuration,!x(this.concrete))throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);const s=f(this.injections),i=f(this.objects);s((e=>this.privateContext.register(e))),i((e=>{"string"==typeof e[0]||"symbol"==typeof e[0]?this.privateContext.use(e[0],e[1]):this.privateContext.register(e,!0)})),this.dependenciesIds=(e=>{const t=[],n=m(e),s=$(e);let i=0;for(const r of n)s.Context.includes(i)||s.Configuration.includes(i)||s.Definition.includes(i)||s.Dispose.includes(i)||s.Use.includes(i)||t.push(r),i++;return t})(this.concrete),e.instance?this.singletonInstance=e.instance:this.isSingleton}}const _=(e,t,n,s)=>new Promise((i=>{const r=e[t];if(r){if(a(r))return void r.bind(e)(n,s).then((()=>{i()}));i(r.bind(e)(n,s))}}));class k extends P{static build(e){const t=new k;((e,t,s)=>{const i=C(s);i[e]=t;const r=y(i);d(n.AssemblageDefinition,r,s)})("singleton",!0,e);const s=t.register([e]),i=t.require(s.identifier),r=t.initCache.find((e=>e.instance===i));if(!r)throw new Error("Root instance not found in assemblages cache.");const o=t.initCache.indexOf(r);t.initCache.splice(o,1);for(const n of t.initCache)_(n.instance,"onInit",t.publicContext,n.configuration);return _(i,"onInit",t.publicContext,s.configuration),t.initCache.length=0,i}dispose(){for(const[e,t]of this.injectables)t.dispose();p(this,k)}register(e,t=!1){const n=!0===t?(e=>({identifier:e[0],concrete:e[0],instance:e[1],configuration:{}}))(e):(e=>((e,t)=>(n,...s)=>e[n]?e[n](...s):t?t(n,...s):void 0)({1:()=>(e=>({identifier:e[0],concrete:e[0],configuration:{}}))(e),2:()=>w(e),3:()=>(e=>({identifier:e[0],concrete:e[1],configuration:e[2]}))(e)},(()=>{throw new Error("Injection tuple must be of length 1, 2 or 3.")}))(e.length))(e);if(this.has(n.identifier))throw new Error(`An assemblage is already registered with identifier '${n.identifier.name}'.`);const s=M.of(n,this.privateContext,this.publicContext);return this.injectables.set(s.identifier,s),_(s.concrete,"onRegister",this.publicContext,s.configuration),s}use(e,t){if(this.has(e))throw new Error(`A value is already registered with identifier '${String(e)}'.`);return this.objects.set(e,t),t}prepareInitHook(e,t){return this.initCache.push({instance:e,configuration:t}),this.initCache}has(e){return"string"==typeof e||"symbol"==typeof e?this.objects.has(e):this.injectables.has(e)}require(e){switch(typeof e){case"string":case"symbol":if(!this.objects.has(e))throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);return this.objects.get(e);default:if(!this.injectables.has(e))throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);return this.injectables.get(e).build()}}concrete(e){const t=this.injectables.get(e);if(t)return t.concrete}tagged(...e){const t=[];for(const n of e)for(const[e,s]of this.injectables)s.tags.includes(n)&&t.push(s.build());return t}get size(){return this.injectables.size}constructor(){super(),this.injectables=new Map,this.objects=new Map,this.initCache=[],this.publicContext={has:this.has.bind(this),require:this.require.bind(this),concrete:this.concrete.bind(this),tagged:this.tagged.bind(this),dispose:this.dispose.bind(this),on:this.on.bind(this),once:this.once.bind(this),off:this.off.bind(this),events:this.channels},this.privateContext={...this.publicContext,register:this.register.bind(this),use:this.use.bind(this),prepareInitHook:this.prepareInitHook.bind(this),emit:this.emit.bind(this),addChannels:this.addChannels.bind(this),removeChannels:this.removeChannels.bind(this)}}}exports.AbstractAssemblage=class{static onRegister(e,t){}},exports.AbstractAssembler=class extends A{},exports.AbstractEventManager=A,exports.AbstractListenerCollection=class{},exports.Assemblage=e=>t=>I(t,e),exports.Assembler=k,exports.Await=(e,t=25)=>(n,s,i)=>{const r=i.value;i.value=async function(){return new Promise((n=>{if(this[e])r.apply(this),n();else{const s=setInterval((()=>{this[e]&&(clearInterval(s),r.apply(this),n())}),t)}}))}},exports.Configuration=D,exports.ConstructorDecorator=L,exports.Context=O,exports.Definition=E,exports.Dispose=U,exports.EventManager=P,exports.ListenerCollection=j,exports.Use=e=>(t,n,s)=>{S(e,t,s)},exports.createConstructorDecorator=e=>(t=!0)=>L(e,t),exports.decorateAssemblage=I,exports.decorateUse=S,exports.getDecoratedParametersIndexes=$,exports.isAssemblage=x;
|