assemblerjs 0.3.25 → 0.4.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 +1 -1
- package/dist/index.d.ts +302 -196
- package/dist/index.js +1 -1
- package/dist/index.mjs +403 -394
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
class AbstractAssemblage {
|
|
2
|
+
static onRegister(s) {}
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
const ReflectParamTypes = 'design:paramtypes';
|
|
6
|
+
const ReflectPrefix = '__';
|
|
7
|
+
const ReflectSuffix = '__';
|
|
8
|
+
var ReflectFlags = /*#__PURE__*/ function(e) {
|
|
9
|
+
e["IsAssemblage"] = "is_assemblage";
|
|
10
|
+
return e;
|
|
11
|
+
}({});
|
|
12
|
+
var ReflectValue = /*#__PURE__*/ function(e) {
|
|
13
|
+
e["AssemblageDefinition"] = "assemblage:definition.value";
|
|
14
|
+
return e;
|
|
15
|
+
}({});
|
|
16
|
+
|
|
1
17
|
const NoOp = (...e)=>{};
|
|
2
18
|
const isOfType = (...e)=>(t)=>{
|
|
3
19
|
if (!e.includes(typeof t)) return undefined;
|
|
@@ -48,7 +64,7 @@ const forIn = (e)=>(t)=>{
|
|
|
48
64
|
t(r(o));
|
|
49
65
|
}
|
|
50
66
|
};
|
|
51
|
-
const e$
|
|
67
|
+
const e$5 = (e, t)=>{
|
|
52
68
|
return [
|
|
53
69
|
...Object.getOwnPropertyNames(t.prototype),
|
|
54
70
|
...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),
|
|
@@ -60,7 +76,7 @@ const proxifyIterable = (t, r)=>{
|
|
|
60
76
|
get: function(o, n) {
|
|
61
77
|
if (n === Symbol.iterator) {
|
|
62
78
|
return o[Symbol.iterator].bind(o);
|
|
63
|
-
} else if (!e$
|
|
79
|
+
} else if (!e$5(t, r).includes(n)) {
|
|
64
80
|
return o.collection[n];
|
|
65
81
|
}
|
|
66
82
|
return o[n];
|
|
@@ -85,7 +101,310 @@ const clearInstance = (e, t)=>{
|
|
|
85
101
|
}
|
|
86
102
|
};
|
|
87
103
|
|
|
88
|
-
|
|
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)=>typeof r === 'undefined' ? true : false
|
|
125
|
+
},
|
|
126
|
+
events: {
|
|
127
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
128
|
+
throw: ()=>{
|
|
129
|
+
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
130
|
+
},
|
|
131
|
+
transform: (r)=>r
|
|
132
|
+
},
|
|
133
|
+
inject: {
|
|
134
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
135
|
+
throw: ()=>{
|
|
136
|
+
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
137
|
+
},
|
|
138
|
+
transform: (r)=>r
|
|
139
|
+
},
|
|
140
|
+
use: {
|
|
141
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length == 2),
|
|
142
|
+
throw: ()=>{
|
|
143
|
+
throw new Error(`'use' property must be an array of tuples of length 2.`);
|
|
144
|
+
},
|
|
145
|
+
transform: (r)=>r
|
|
146
|
+
},
|
|
147
|
+
tags: {
|
|
148
|
+
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
149
|
+
throw: ()=>{
|
|
150
|
+
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
151
|
+
},
|
|
152
|
+
transform: (r)=>typeof r === 'string' ? [
|
|
153
|
+
r
|
|
154
|
+
] : r
|
|
155
|
+
},
|
|
156
|
+
metadata: {
|
|
157
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
158
|
+
throw: ()=>{
|
|
159
|
+
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
160
|
+
},
|
|
161
|
+
transform: (r)=>r
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const validateDefinition = (r)=>{
|
|
165
|
+
const t = {
|
|
166
|
+
...r
|
|
167
|
+
};
|
|
168
|
+
for(const r in t){
|
|
169
|
+
if (!Object.keys(n).includes(r)) {
|
|
170
|
+
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
171
|
+
}
|
|
172
|
+
const e = n[r].test;
|
|
173
|
+
const o = n[r].throw;
|
|
174
|
+
const s = n[r].transform;
|
|
175
|
+
if (!e(t[r])) {
|
|
176
|
+
o();
|
|
177
|
+
}
|
|
178
|
+
t[r] = s(t[r]);
|
|
179
|
+
}
|
|
180
|
+
return t;
|
|
181
|
+
};
|
|
182
|
+
const getDefinition = (t)=>{
|
|
183
|
+
if (!isAssemblage(t)) {
|
|
184
|
+
throw new Error(`Class '${t.name}' is not an assemblage.`);
|
|
185
|
+
}
|
|
186
|
+
return getOwnCustomMetadata(ReflectValue.AssemblageDefinition, t);
|
|
187
|
+
};
|
|
188
|
+
const getDefinitionValue = (r, t)=>{
|
|
189
|
+
const e = getDefinition(t);
|
|
190
|
+
return e[r];
|
|
191
|
+
};
|
|
192
|
+
const setDefinitionValue = (e, o, n)=>{
|
|
193
|
+
const s = getDefinition(n);
|
|
194
|
+
s[e] = o;
|
|
195
|
+
const i = validateDefinition(s);
|
|
196
|
+
defineCustomMetadata(ReflectValue.AssemblageDefinition, i, n);
|
|
197
|
+
return i;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const i$1 = (n)=>{
|
|
201
|
+
return {
|
|
202
|
+
identifier: n[0],
|
|
203
|
+
concrete: n[0],
|
|
204
|
+
configuration: {}
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const c$2 = (r)=>{
|
|
208
|
+
const i = ()=>isClass(r[0]) && isClass(r[1]);
|
|
209
|
+
const c = ()=>isClass(r[0]) && isObject(r[1]);
|
|
210
|
+
const f = ()=>pipe(conditionally({
|
|
211
|
+
if: ()=>i(),
|
|
212
|
+
then: ()=>{
|
|
213
|
+
return {
|
|
214
|
+
identifier: r[0],
|
|
215
|
+
concrete: r[1],
|
|
216
|
+
configuration: {}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}), conditionally({
|
|
220
|
+
if: ()=>c(),
|
|
221
|
+
then: ()=>{
|
|
222
|
+
return {
|
|
223
|
+
identifier: r[0],
|
|
224
|
+
concrete: r[0],
|
|
225
|
+
configuration: r[1]
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
else: (n)=>n
|
|
229
|
+
}))();
|
|
230
|
+
return f();
|
|
231
|
+
};
|
|
232
|
+
const f = (n)=>{
|
|
233
|
+
return {
|
|
234
|
+
identifier: n[0],
|
|
235
|
+
concrete: n[1],
|
|
236
|
+
configuration: n[2]
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
const resolveInjectionTuple = (n)=>switchCase({
|
|
240
|
+
1: ()=>i$1(n),
|
|
241
|
+
2: ()=>c$2(n),
|
|
242
|
+
3: ()=>f(n)
|
|
243
|
+
}, ()=>{
|
|
244
|
+
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
245
|
+
})(n.length);
|
|
246
|
+
|
|
247
|
+
const resolveInstanceInjectionTuple = (e)=>{
|
|
248
|
+
return {
|
|
249
|
+
identifier: e[0],
|
|
250
|
+
concrete: e[0],
|
|
251
|
+
instance: e[1],
|
|
252
|
+
configuration: {}
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const Assemblage = (m)=>{
|
|
257
|
+
const n = m ? validateDefinition(m) : {};
|
|
258
|
+
return (t)=>{
|
|
259
|
+
defineCustomMetadata(ReflectFlags.IsAssemblage, true, t);
|
|
260
|
+
defineCustomMetadata(ReflectValue.AssemblageDefinition, n, t);
|
|
261
|
+
return t;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const Await = (t, e = 25)=>{
|
|
266
|
+
return (n, s, a)=>{
|
|
267
|
+
const i = a.value;
|
|
268
|
+
a.value = async function() {
|
|
269
|
+
return new Promise((n)=>{
|
|
270
|
+
if (this[t]) {
|
|
271
|
+
i.apply(this);
|
|
272
|
+
n();
|
|
273
|
+
} else {
|
|
274
|
+
const s = setInterval(()=>{
|
|
275
|
+
if (this[t]) {
|
|
276
|
+
clearInterval(s);
|
|
277
|
+
i.apply(this);
|
|
278
|
+
n();
|
|
279
|
+
}
|
|
280
|
+
}, e);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
var ReflectParamValue = /*#__PURE__*/ function(e) {
|
|
288
|
+
e["UseIdentifier"] = "assemblage:use.param.value";
|
|
289
|
+
return e;
|
|
290
|
+
}({});
|
|
291
|
+
var ReflectParamIndex = /*#__PURE__*/ function(e) {
|
|
292
|
+
e["Context"] = "assembler:context.param.index";
|
|
293
|
+
e["Dispose"] = "assembler:dispose.param.index";
|
|
294
|
+
e["Definition"] = "assemblage:definition.param.index";
|
|
295
|
+
e["Configuration"] = "assemblage:configuration.param.index";
|
|
296
|
+
e["Use"] = "assemblage:use.param.index";
|
|
297
|
+
return e;
|
|
298
|
+
}({});
|
|
299
|
+
|
|
300
|
+
const i = (t)=>()=>{
|
|
301
|
+
return (i, s, r)=>{
|
|
302
|
+
const c = getOwnCustomMetadata(t, i) || [];
|
|
303
|
+
c.push(r);
|
|
304
|
+
defineCustomMetadata(t, c, i);
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
const s$1 = i(ReflectParamIndex.Context);
|
|
308
|
+
const r$1 = i(ReflectParamIndex.Configuration);
|
|
309
|
+
const c$1 = i(ReflectParamIndex.Definition);
|
|
310
|
+
const e$4 = i(ReflectParamIndex.Dispose);
|
|
311
|
+
|
|
312
|
+
const Use = (n)=>{
|
|
313
|
+
return (r, i, m)=>{
|
|
314
|
+
const c = getOwnCustomMetadata(ReflectParamIndex.Use, r) || [];
|
|
315
|
+
c.push(m);
|
|
316
|
+
defineCustomMetadata(ReflectParamIndex.Use, c, r);
|
|
317
|
+
const U = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, r) || {};
|
|
318
|
+
U[m] = n;
|
|
319
|
+
defineCustomMetadata(ReflectParamValue.UseIdentifier, U, r);
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const o = (o)=>{
|
|
324
|
+
return getOwnCustomMetadata(ReflectParamIndex.Context, o) || [];
|
|
325
|
+
};
|
|
326
|
+
const r = (o)=>{
|
|
327
|
+
return getOwnCustomMetadata(ReflectParamIndex.Configuration, o) || [];
|
|
328
|
+
};
|
|
329
|
+
const e$3 = (o)=>{
|
|
330
|
+
return getOwnCustomMetadata(ReflectParamIndex.Definition, o) || [];
|
|
331
|
+
};
|
|
332
|
+
const s = (o)=>{
|
|
333
|
+
return getOwnCustomMetadata(ReflectParamIndex.Dispose, o) || [];
|
|
334
|
+
};
|
|
335
|
+
const c = (o)=>{
|
|
336
|
+
return getOwnCustomMetadata(ReflectParamIndex.Use, o) || [];
|
|
337
|
+
};
|
|
338
|
+
const getDecoratedParametersIndexes = (t)=>{
|
|
339
|
+
const n = o(t);
|
|
340
|
+
const i = e$3(t);
|
|
341
|
+
const a = r(t);
|
|
342
|
+
const u = s(t);
|
|
343
|
+
const m = c(t);
|
|
344
|
+
return {
|
|
345
|
+
context: n,
|
|
346
|
+
definition: i,
|
|
347
|
+
configuration: a,
|
|
348
|
+
dispose: u,
|
|
349
|
+
use: m
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const resolveParameters = (i)=>{
|
|
354
|
+
const c = [];
|
|
355
|
+
const s = getParamTypes(i.concrete);
|
|
356
|
+
const u = getDecoratedParametersIndexes(i.concrete);
|
|
357
|
+
let r = 0;
|
|
358
|
+
for (const n of s){
|
|
359
|
+
if (u.context.includes(r)) {
|
|
360
|
+
c.push(i.publicContext);
|
|
361
|
+
r++;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (u.configuration.includes(r)) {
|
|
365
|
+
c.push(i.configuration);
|
|
366
|
+
r++;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (u.definition.includes(r)) {
|
|
370
|
+
c.push(i.definition);
|
|
371
|
+
r++;
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (u.dispose.includes(r)) {
|
|
375
|
+
c.push(i.privateContext.dispose);
|
|
376
|
+
r++;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (u.use.includes(r)) {
|
|
380
|
+
const n = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, i.concrete);
|
|
381
|
+
const t = n[r];
|
|
382
|
+
c.push(i.privateContext.require(t));
|
|
383
|
+
r++;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
c.push(i.privateContext.require(n));
|
|
387
|
+
r++;
|
|
388
|
+
}
|
|
389
|
+
return c;
|
|
390
|
+
};
|
|
391
|
+
const resolveDependencies = (e)=>{
|
|
392
|
+
const o = [];
|
|
393
|
+
const i = getParamTypes(e);
|
|
394
|
+
const c = getDecoratedParametersIndexes(e);
|
|
395
|
+
let s = 0;
|
|
396
|
+
for (const e of i){
|
|
397
|
+
if (c.context.includes(s) || c.configuration.includes(s) || c.definition.includes(s) || c.dispose.includes(s) || c.use.includes(s)) {
|
|
398
|
+
s++;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
o.push(e);
|
|
402
|
+
s++;
|
|
403
|
+
}
|
|
404
|
+
return o;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
function e$2(e, t, n) {
|
|
89
408
|
if (t in e) {
|
|
90
409
|
Object.defineProperty(e, t, {
|
|
91
410
|
value: n,
|
|
@@ -98,14 +417,14 @@ function e$5(e, t, n) {
|
|
|
98
417
|
}
|
|
99
418
|
return e;
|
|
100
419
|
}
|
|
101
|
-
let h
|
|
420
|
+
let h = Symbol.iterator;
|
|
102
421
|
class ListenerCollection {
|
|
103
422
|
dispose() {
|
|
104
423
|
clearInstance(this, ListenerCollection);
|
|
105
424
|
}
|
|
106
425
|
add(...e) {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
426
|
+
const t = (e)=>this.collection[e.channel].push(e.listener);
|
|
427
|
+
const l = conditionally({
|
|
109
428
|
if: ()=>e.length === 2,
|
|
110
429
|
then: ()=>{
|
|
111
430
|
return {
|
|
@@ -121,35 +440,35 @@ class ListenerCollection {
|
|
|
121
440
|
};
|
|
122
441
|
}
|
|
123
442
|
});
|
|
124
|
-
const
|
|
443
|
+
const i = conditionally({
|
|
125
444
|
if: (e)=>!isDefined(this.collection[e.channel]),
|
|
126
445
|
then: (e)=>{
|
|
127
446
|
this.collection[e.channel] = [];
|
|
128
|
-
|
|
447
|
+
t(e);
|
|
129
448
|
},
|
|
130
449
|
else: (e)=>{
|
|
131
|
-
|
|
450
|
+
t(e);
|
|
132
451
|
}
|
|
133
452
|
});
|
|
134
|
-
pipe(
|
|
453
|
+
pipe(l, i)();
|
|
135
454
|
return this;
|
|
136
455
|
}
|
|
137
|
-
remove(e,
|
|
138
|
-
const
|
|
139
|
-
const
|
|
456
|
+
remove(e, t) {
|
|
457
|
+
const l = (t)=>this.collection[e].splice(t, 1);
|
|
458
|
+
const i = conditionally({
|
|
140
459
|
if: ()=>this.collection[e] && this.collection[e].length === 0,
|
|
141
460
|
then: ()=>delete this.collection[e]
|
|
142
461
|
});
|
|
143
|
-
const
|
|
144
|
-
if: ()=>isDefined(
|
|
145
|
-
then: ()=>
|
|
462
|
+
const o = conditionally({
|
|
463
|
+
if: ()=>isDefined(t),
|
|
464
|
+
then: ()=>l(this.collection[e].indexOf(t)),
|
|
146
465
|
else: ()=>delete this.collection[e]
|
|
147
466
|
});
|
|
148
467
|
const r = conditionally({
|
|
149
468
|
if: (e)=>this.has(e),
|
|
150
469
|
then: (e)=>this.collection[e]
|
|
151
470
|
});
|
|
152
|
-
pipe(r,
|
|
471
|
+
pipe(r, o, i)();
|
|
153
472
|
return this;
|
|
154
473
|
}
|
|
155
474
|
has(...e) {
|
|
@@ -183,7 +502,7 @@ class ListenerCollection {
|
|
|
183
502
|
get length() {
|
|
184
503
|
return Object.values(this.collection).flat().length;
|
|
185
504
|
}
|
|
186
|
-
[h
|
|
505
|
+
[h]() {
|
|
187
506
|
let e = -1;
|
|
188
507
|
const t = this.collection ? Object.keys(this.collection) : [];
|
|
189
508
|
return {
|
|
@@ -194,13 +513,16 @@ class ListenerCollection {
|
|
|
194
513
|
};
|
|
195
514
|
}
|
|
196
515
|
constructor(){
|
|
197
|
-
e$
|
|
516
|
+
e$2(this, "collection", {});
|
|
198
517
|
const t = proxifyIterable(this, ListenerCollection);
|
|
199
518
|
return t;
|
|
200
519
|
}
|
|
201
520
|
}
|
|
202
521
|
|
|
203
|
-
|
|
522
|
+
class AbstractEventManager {
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function e$1(e, n, s) {
|
|
204
526
|
if (n in e) {
|
|
205
527
|
Object.defineProperty(e, n, {
|
|
206
528
|
value: s,
|
|
@@ -302,237 +624,15 @@ class EventManager {
|
|
|
302
624
|
return onlyAlphanumeric(e, '*');
|
|
303
625
|
}
|
|
304
626
|
constructor(...n){
|
|
305
|
-
e$
|
|
306
|
-
e$
|
|
307
|
-
e$
|
|
627
|
+
e$1(this, "listeners", new ListenerCollection());
|
|
628
|
+
e$1(this, "onceListeners", new ListenerCollection());
|
|
629
|
+
e$1(this, "channels", new Set([
|
|
308
630
|
'*'
|
|
309
631
|
]));
|
|
310
632
|
this.addChannels(...n);
|
|
311
633
|
}
|
|
312
634
|
}
|
|
313
635
|
|
|
314
|
-
const ReflectParamTypes = 'design:paramtypes';
|
|
315
|
-
const ReflectPrefix = '__';
|
|
316
|
-
const ReflectSuffix = '__';
|
|
317
|
-
const ReflectIsAssemblageFlag = `is_assemblage`;
|
|
318
|
-
const ReflectDefinition = 'assemblage_definition';
|
|
319
|
-
const ReflectContextParamIndex = `context_param_index`;
|
|
320
|
-
const ReflectConfigurationParamIndex = `config_param_index`;
|
|
321
|
-
const ReflectDefinitionParamIndex = `definition_param_index`;
|
|
322
|
-
const ReflectDisposeParamIndex = `dispose_param_index`;
|
|
323
|
-
const ReflectUseParamIndex = `use_param_index`;
|
|
324
|
-
const ReflectUseToken = 'use_token';
|
|
325
|
-
|
|
326
|
-
const defineCustomMetadata = (t, o, n)=>{
|
|
327
|
-
Reflect.defineMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o, n);
|
|
328
|
-
};
|
|
329
|
-
const getOwnCustomMetadata = (t, o)=>{
|
|
330
|
-
return Reflect.getOwnMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o);
|
|
331
|
-
};
|
|
332
|
-
const getParamTypes = (e)=>{
|
|
333
|
-
return Reflect.getMetadata(ReflectParamTypes, e) || [];
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
const e$3 = {
|
|
337
|
-
singleton: {
|
|
338
|
-
test: (r)=>typeof r === 'boolean' || typeof r === 'undefined',
|
|
339
|
-
throw: ()=>{
|
|
340
|
-
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
341
|
-
},
|
|
342
|
-
transform: (r)=>typeof r === 'undefined' ? true : false
|
|
343
|
-
},
|
|
344
|
-
events: {
|
|
345
|
-
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
346
|
-
throw: ()=>{
|
|
347
|
-
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
348
|
-
},
|
|
349
|
-
transform: (r)=>r
|
|
350
|
-
},
|
|
351
|
-
inject: {
|
|
352
|
-
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
353
|
-
throw: ()=>{
|
|
354
|
-
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
355
|
-
},
|
|
356
|
-
transform: (r)=>r
|
|
357
|
-
},
|
|
358
|
-
use: {
|
|
359
|
-
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length == 2),
|
|
360
|
-
throw: ()=>{
|
|
361
|
-
throw new Error(`'use' property must be an array of tuples of length 2.`);
|
|
362
|
-
},
|
|
363
|
-
transform: (r)=>r
|
|
364
|
-
},
|
|
365
|
-
tags: {
|
|
366
|
-
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
367
|
-
throw: ()=>{
|
|
368
|
-
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
369
|
-
},
|
|
370
|
-
transform: (r)=>typeof r === 'string' ? [
|
|
371
|
-
r
|
|
372
|
-
] : r
|
|
373
|
-
},
|
|
374
|
-
metadata: {
|
|
375
|
-
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
376
|
-
throw: ()=>{
|
|
377
|
-
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
378
|
-
},
|
|
379
|
-
transform: (r)=>r
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
const validateDefinition = (r)=>{
|
|
383
|
-
const t = {
|
|
384
|
-
...r
|
|
385
|
-
};
|
|
386
|
-
for(const r in t){
|
|
387
|
-
if (!Object.keys(e$3).includes(r)) {
|
|
388
|
-
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
389
|
-
}
|
|
390
|
-
const o = e$3[r].test;
|
|
391
|
-
const n = e$3[r].throw;
|
|
392
|
-
const s = e$3[r].transform;
|
|
393
|
-
if (!o(t[r])) {
|
|
394
|
-
n();
|
|
395
|
-
}
|
|
396
|
-
t[r] = s(t[r]);
|
|
397
|
-
}
|
|
398
|
-
return t;
|
|
399
|
-
};
|
|
400
|
-
const getDefinition = (e)=>{
|
|
401
|
-
return getOwnCustomMetadata(ReflectDefinition, e);
|
|
402
|
-
};
|
|
403
|
-
const getDefinitionValue = (r, t)=>{
|
|
404
|
-
const e = getDefinition(t);
|
|
405
|
-
return e[r];
|
|
406
|
-
};
|
|
407
|
-
const setDefinitionValue = (r, t, e)=>{
|
|
408
|
-
const o = getDefinition(e);
|
|
409
|
-
o[r] = t;
|
|
410
|
-
const n = validateDefinition(o);
|
|
411
|
-
return n;
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
function e$2(e, t, r, o) {
|
|
415
|
-
var s = arguments.length, n = s < 3 ? t : o === null ? o = Object.getOwnPropertyDescriptor(t, r) : o, l;
|
|
416
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") n = Reflect.decorate(e, t, r, o);
|
|
417
|
-
else for(var c = e.length - 1; c >= 0; c--)if (l = e[c]) n = (s < 3 ? l(n) : s > 3 ? l(t, r, n) : l(t, r)) || n;
|
|
418
|
-
return s > 3 && n && Object.defineProperty(t, r, n), n;
|
|
419
|
-
}
|
|
420
|
-
const Assemblage = (e)=>{
|
|
421
|
-
const r = e ? validateDefinition(e) : {};
|
|
422
|
-
return (e)=>{
|
|
423
|
-
defineCustomMetadata(ReflectIsAssemblageFlag, true, e);
|
|
424
|
-
defineCustomMetadata(ReflectDefinition, r, e);
|
|
425
|
-
return e;
|
|
426
|
-
};
|
|
427
|
-
};
|
|
428
|
-
const isAssemblage = (e)=>{
|
|
429
|
-
return getOwnCustomMetadata(ReflectIsAssemblageFlag, e) || false;
|
|
430
|
-
};
|
|
431
|
-
class NoOpAssemblage {
|
|
432
|
-
}
|
|
433
|
-
NoOpAssemblage = e$2([
|
|
434
|
-
Assemblage()
|
|
435
|
-
], NoOpAssemblage);
|
|
436
|
-
|
|
437
|
-
const callHook = (o, r, t)=>{
|
|
438
|
-
return new Promise((i)=>{
|
|
439
|
-
const e = o[r];
|
|
440
|
-
if (e) {
|
|
441
|
-
if (isAsync(e)) {
|
|
442
|
-
e.bind(o)(t).then(()=>{
|
|
443
|
-
i();
|
|
444
|
-
});
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
i(e.bind(o)(t));
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
const getContextIndex = (e)=>{
|
|
453
|
-
return getOwnCustomMetadata(ReflectContextParamIndex, e) || [];
|
|
454
|
-
};
|
|
455
|
-
const getConfigurationIndex = (t)=>{
|
|
456
|
-
return getOwnCustomMetadata(ReflectConfigurationParamIndex, t) || [];
|
|
457
|
-
};
|
|
458
|
-
const getDefinitionIndex = (e)=>{
|
|
459
|
-
return getOwnCustomMetadata(ReflectDefinitionParamIndex, e) || [];
|
|
460
|
-
};
|
|
461
|
-
const getDisposeIndex = (e)=>{
|
|
462
|
-
return getOwnCustomMetadata(ReflectDisposeParamIndex, e) || [];
|
|
463
|
-
};
|
|
464
|
-
const getUseIndex = (e)=>{
|
|
465
|
-
return getOwnCustomMetadata(ReflectUseParamIndex, e) || [];
|
|
466
|
-
};
|
|
467
|
-
const getDecoratedParametersIndexes = (e)=>{
|
|
468
|
-
const t = getContextIndex(e);
|
|
469
|
-
const n = getDefinitionIndex(e);
|
|
470
|
-
const o = getConfigurationIndex(e);
|
|
471
|
-
const r = getDisposeIndex(e);
|
|
472
|
-
const s = getUseIndex(e);
|
|
473
|
-
return {
|
|
474
|
-
context: t,
|
|
475
|
-
definition: n,
|
|
476
|
-
configuration: o,
|
|
477
|
-
dispose: r,
|
|
478
|
-
use: s
|
|
479
|
-
};
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
const resolveParameters = (i)=>{
|
|
483
|
-
const s = [];
|
|
484
|
-
const c = getParamTypes(i.concrete);
|
|
485
|
-
const r = getDecoratedParametersIndexes(i.concrete);
|
|
486
|
-
let u = 0;
|
|
487
|
-
for (const e of c){
|
|
488
|
-
if (r.context.includes(u)) {
|
|
489
|
-
s.push(i.publicContext);
|
|
490
|
-
u++;
|
|
491
|
-
continue;
|
|
492
|
-
}
|
|
493
|
-
if (r.configuration.includes(u)) {
|
|
494
|
-
s.push(i.configuration);
|
|
495
|
-
u++;
|
|
496
|
-
continue;
|
|
497
|
-
}
|
|
498
|
-
if (r.definition.includes(u)) {
|
|
499
|
-
s.push(i.definition);
|
|
500
|
-
u++;
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
if (r.dispose.includes(u)) {
|
|
504
|
-
s.push(i.privateContext.dispose);
|
|
505
|
-
u++;
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
if (r.use.includes(u)) {
|
|
509
|
-
const e = getOwnCustomMetadata(ReflectUseToken, i.concrete);
|
|
510
|
-
const o = e[u];
|
|
511
|
-
s.push(i.privateContext.require(o));
|
|
512
|
-
u++;
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
s.push(i.privateContext.require(e));
|
|
516
|
-
u++;
|
|
517
|
-
}
|
|
518
|
-
return s;
|
|
519
|
-
};
|
|
520
|
-
const resolveDependencies = (n)=>{
|
|
521
|
-
const t = [];
|
|
522
|
-
const i = getParamTypes(n);
|
|
523
|
-
const s = getDecoratedParametersIndexes(n);
|
|
524
|
-
let c = 0;
|
|
525
|
-
for (const e of i){
|
|
526
|
-
if (s.context.includes(c) || s.configuration.includes(c) || s.definition.includes(c) || s.dispose.includes(c) || s.use.includes(c)) {
|
|
527
|
-
c++;
|
|
528
|
-
continue;
|
|
529
|
-
}
|
|
530
|
-
t.push(e);
|
|
531
|
-
c++;
|
|
532
|
-
}
|
|
533
|
-
return t;
|
|
534
|
-
};
|
|
535
|
-
|
|
536
636
|
const registerEvents = (t, n)=>{
|
|
537
637
|
const o = t.concrete.prototype instanceof EventManager;
|
|
538
638
|
if (o) {
|
|
@@ -561,22 +661,22 @@ const unregisterEvents = (t, n)=>{
|
|
|
561
661
|
}
|
|
562
662
|
};
|
|
563
663
|
|
|
564
|
-
function
|
|
565
|
-
if (
|
|
566
|
-
Object.defineProperty(
|
|
664
|
+
function t(t, e, n) {
|
|
665
|
+
if (e in t) {
|
|
666
|
+
Object.defineProperty(t, e, {
|
|
567
667
|
value: n,
|
|
568
668
|
enumerable: true,
|
|
569
669
|
configurable: true,
|
|
570
670
|
writable: true
|
|
571
671
|
});
|
|
572
672
|
} else {
|
|
573
|
-
e
|
|
673
|
+
t[e] = n;
|
|
574
674
|
}
|
|
575
|
-
return
|
|
675
|
+
return t;
|
|
576
676
|
}
|
|
577
677
|
class Injectable {
|
|
578
|
-
static of(
|
|
579
|
-
return new Injectable(
|
|
678
|
+
static of(t, e, n) {
|
|
679
|
+
return new Injectable(t, e, n);
|
|
580
680
|
}
|
|
581
681
|
dispose() {
|
|
582
682
|
if (this.singletonInstance) {
|
|
@@ -588,16 +688,16 @@ class Injectable {
|
|
|
588
688
|
}
|
|
589
689
|
build() {
|
|
590
690
|
if (this.singletonInstance) return this.singletonInstance;
|
|
591
|
-
const
|
|
592
|
-
const
|
|
593
|
-
registerEvents(this,
|
|
691
|
+
const t = resolveParameters(this);
|
|
692
|
+
const e = new this.concrete(...t);
|
|
693
|
+
registerEvents(this, e);
|
|
594
694
|
if (this.isSingleton) {
|
|
595
|
-
this.singletonInstance =
|
|
596
|
-
this.privateContext.
|
|
695
|
+
this.singletonInstance = e;
|
|
696
|
+
this.privateContext.prepareInitHook(e);
|
|
597
697
|
return this.singletonInstance;
|
|
598
698
|
}
|
|
599
|
-
callHook(
|
|
600
|
-
return
|
|
699
|
+
callHook(e, 'onInit', this.publicContext);
|
|
700
|
+
return e;
|
|
601
701
|
}
|
|
602
702
|
get dependencies() {
|
|
603
703
|
return this.dependenciesIds;
|
|
@@ -623,93 +723,53 @@ class Injectable {
|
|
|
623
723
|
get events() {
|
|
624
724
|
return getDefinitionValue('events', this.concrete) || [];
|
|
625
725
|
}
|
|
626
|
-
constructor(
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
726
|
+
constructor(e, s, o){
|
|
727
|
+
t(this, "privateContext", undefined);
|
|
728
|
+
t(this, "publicContext", undefined);
|
|
729
|
+
t(this, "identifier", undefined);
|
|
730
|
+
t(this, "concrete", undefined);
|
|
731
|
+
t(this, "configuration", undefined);
|
|
732
|
+
t(this, "dependenciesIds", undefined);
|
|
733
|
+
t(this, "singletonInstance", undefined);
|
|
634
734
|
this.privateContext = s;
|
|
635
735
|
this.publicContext = o;
|
|
636
736
|
this.dependenciesIds = [];
|
|
637
|
-
this.identifier =
|
|
638
|
-
this.concrete =
|
|
639
|
-
this.configuration =
|
|
737
|
+
this.identifier = e.identifier;
|
|
738
|
+
this.concrete = e.concrete;
|
|
739
|
+
this.configuration = e.configuration;
|
|
640
740
|
if (!isAssemblage(this.concrete)) {
|
|
641
741
|
throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);
|
|
642
742
|
}
|
|
643
743
|
const r = forOf(this.injections);
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
if (typeof
|
|
648
|
-
this.privateContext.use(
|
|
744
|
+
const c = forOf(this.objects);
|
|
745
|
+
r((t)=>this.privateContext.register(t));
|
|
746
|
+
c((t)=>{
|
|
747
|
+
if (typeof t[0] === 'string' || typeof t[0] === 'symbol') {
|
|
748
|
+
this.privateContext.use(t[0], t[1]);
|
|
649
749
|
} else {
|
|
650
|
-
this.privateContext.register(
|
|
750
|
+
this.privateContext.register(t, true);
|
|
651
751
|
}
|
|
652
752
|
});
|
|
653
753
|
this.dependenciesIds = resolveDependencies(this.concrete);
|
|
654
|
-
if (
|
|
655
|
-
this.singletonInstance =
|
|
754
|
+
if (e.instance) {
|
|
755
|
+
this.singletonInstance = e.instance;
|
|
656
756
|
}
|
|
657
757
|
}
|
|
658
758
|
}
|
|
659
759
|
|
|
660
|
-
const
|
|
661
|
-
return {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
const c = ()=>isClass(o[0]) && isObject(o[1]);
|
|
670
|
-
const u = ()=>pipe(conditionally({
|
|
671
|
-
if: ()=>i(),
|
|
672
|
-
then: ()=>{
|
|
673
|
-
return {
|
|
674
|
-
identifier: o[0],
|
|
675
|
-
concrete: o[1],
|
|
676
|
-
configuration: {}
|
|
677
|
-
};
|
|
760
|
+
const callHook = (n, r, t)=>{
|
|
761
|
+
return new Promise((e)=>{
|
|
762
|
+
const i = n[r];
|
|
763
|
+
if (i) {
|
|
764
|
+
if (isAsync(i)) {
|
|
765
|
+
i.bind(n)(t).then(()=>{
|
|
766
|
+
e();
|
|
767
|
+
});
|
|
768
|
+
return;
|
|
678
769
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return {
|
|
683
|
-
identifier: o[0],
|
|
684
|
-
concrete: o[0],
|
|
685
|
-
configuration: o[1]
|
|
686
|
-
};
|
|
687
|
-
},
|
|
688
|
-
else: (n)=>n
|
|
689
|
-
}))();
|
|
690
|
-
return u();
|
|
691
|
-
};
|
|
692
|
-
const u$1 = (n)=>{
|
|
693
|
-
return {
|
|
694
|
-
identifier: n[0],
|
|
695
|
-
concrete: n[1],
|
|
696
|
-
configuration: n[2]
|
|
697
|
-
};
|
|
698
|
-
};
|
|
699
|
-
const resolveInjectionTuple = (n)=>switchCase({
|
|
700
|
-
1: ()=>i(n),
|
|
701
|
-
2: ()=>c(n),
|
|
702
|
-
3: ()=>u$1(n)
|
|
703
|
-
}, ()=>{
|
|
704
|
-
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
705
|
-
})(n.length);
|
|
706
|
-
const resolveInstanceInjectionTuple = (n)=>{
|
|
707
|
-
return {
|
|
708
|
-
identifier: n[0],
|
|
709
|
-
concrete: n[0],
|
|
710
|
-
instance: n[1],
|
|
711
|
-
configuration: {}
|
|
712
|
-
};
|
|
770
|
+
e(i.bind(n)(t));
|
|
771
|
+
}
|
|
772
|
+
});
|
|
713
773
|
};
|
|
714
774
|
|
|
715
775
|
function e(e, t, i) {
|
|
@@ -729,18 +789,18 @@ class Assembler extends EventManager {
|
|
|
729
789
|
static build(e) {
|
|
730
790
|
const t = new Assembler();
|
|
731
791
|
setDefinitionValue('singleton', true, e);
|
|
732
|
-
const
|
|
792
|
+
const s = t.register([
|
|
733
793
|
e
|
|
734
794
|
]);
|
|
735
|
-
const
|
|
736
|
-
const
|
|
737
|
-
t.initCache.splice(
|
|
795
|
+
const n = t.require(s.identifier);
|
|
796
|
+
const r = t.initCache.indexOf(n);
|
|
797
|
+
t.initCache.splice(r, 1);
|
|
738
798
|
for (const e of t.initCache){
|
|
739
799
|
callHook(e, 'onInit', t.publicContext);
|
|
740
800
|
}
|
|
741
|
-
callHook(
|
|
801
|
+
callHook(n, 'onInit', t.publicContext);
|
|
742
802
|
t.initCache.length = 0;
|
|
743
|
-
return
|
|
803
|
+
return n;
|
|
744
804
|
}
|
|
745
805
|
dispose() {
|
|
746
806
|
for (const [e, t] of this.injectables){
|
|
@@ -753,10 +813,10 @@ class Assembler extends EventManager {
|
|
|
753
813
|
if (this.has(i.identifier)) {
|
|
754
814
|
throw new Error(`An assemblage is already registered with identifier '${i.identifier.name}'.`);
|
|
755
815
|
}
|
|
756
|
-
const
|
|
757
|
-
this.injectables.set(
|
|
758
|
-
callHook(
|
|
759
|
-
return
|
|
816
|
+
const o = Injectable.of(i, this.privateContext, this.publicContext);
|
|
817
|
+
this.injectables.set(o.identifier, o);
|
|
818
|
+
callHook(o.concrete, 'onRegister', this.publicContext);
|
|
819
|
+
return o;
|
|
760
820
|
}
|
|
761
821
|
use(e, t) {
|
|
762
822
|
if (this.has(e)) {
|
|
@@ -765,7 +825,7 @@ class Assembler extends EventManager {
|
|
|
765
825
|
this.objects.set(e, t);
|
|
766
826
|
return t;
|
|
767
827
|
}
|
|
768
|
-
|
|
828
|
+
prepareInitHook(e) {
|
|
769
829
|
this.initCache.push(e);
|
|
770
830
|
return this.initCache;
|
|
771
831
|
}
|
|
@@ -822,7 +882,7 @@ class Assembler extends EventManager {
|
|
|
822
882
|
...this.publicContext,
|
|
823
883
|
register: this.register.bind(this),
|
|
824
884
|
use: this.use.bind(this),
|
|
825
|
-
|
|
885
|
+
prepareInitHook: this.prepareInitHook.bind(this),
|
|
826
886
|
emit: this.emit.bind(this),
|
|
827
887
|
addChannels: this.addChannels.bind(this),
|
|
828
888
|
removeChannels: this.removeChannels.bind(this),
|
|
@@ -831,58 +891,7 @@ class Assembler extends EventManager {
|
|
|
831
891
|
}
|
|
832
892
|
}
|
|
833
893
|
|
|
834
|
-
const p = (o)=>()=>{
|
|
835
|
-
return (t, n, s)=>{
|
|
836
|
-
const e = getOwnCustomMetadata(o, t) || [];
|
|
837
|
-
e.push(s);
|
|
838
|
-
defineCustomMetadata(o, e, t);
|
|
839
|
-
};
|
|
840
|
-
};
|
|
841
|
-
const f = p(ReflectContextParamIndex);
|
|
842
|
-
const u = p(ReflectConfigurationParamIndex);
|
|
843
|
-
const m = p(ReflectDefinitionParamIndex);
|
|
844
|
-
const h = p(ReflectDisposeParamIndex);
|
|
845
|
-
const l = (o)=>{
|
|
846
|
-
return (t, n, s)=>{
|
|
847
|
-
const p = getOwnCustomMetadata(ReflectUseParamIndex, t) || [];
|
|
848
|
-
p.push(s);
|
|
849
|
-
defineCustomMetadata(ReflectUseParamIndex, p, t);
|
|
850
|
-
const f = getOwnCustomMetadata(ReflectUseToken, t) || {};
|
|
851
|
-
f[s] = o;
|
|
852
|
-
defineCustomMetadata(ReflectUseToken, f, t);
|
|
853
|
-
};
|
|
854
|
-
};
|
|
855
|
-
|
|
856
|
-
const Await = (t, e = 25)=>{
|
|
857
|
-
return (n, s, a)=>{
|
|
858
|
-
const i = a.value;
|
|
859
|
-
a.value = async function() {
|
|
860
|
-
return new Promise((n)=>{
|
|
861
|
-
if (this[t]) {
|
|
862
|
-
i.apply(this);
|
|
863
|
-
n();
|
|
864
|
-
} else {
|
|
865
|
-
const s = setInterval(()=>{
|
|
866
|
-
if (this[t]) {
|
|
867
|
-
clearInterval(s);
|
|
868
|
-
i.apply(this);
|
|
869
|
-
n();
|
|
870
|
-
}
|
|
871
|
-
}, e);
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
};
|
|
875
|
-
};
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
class AbstractAssemblage {
|
|
879
|
-
static onRegister(s) {}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
class AbstractEventManager {
|
|
883
|
-
}
|
|
884
|
-
|
|
885
894
|
class AbstractAssembler extends AbstractEventManager {
|
|
886
895
|
}
|
|
887
896
|
|
|
888
|
-
export { AbstractAssemblage, AbstractAssembler, AbstractEventManager, Assemblage, Assembler, Await,
|
|
897
|
+
export { AbstractAssemblage, AbstractAssembler, AbstractEventManager, Assemblage, Assembler, Await, r$1 as Configuration, s$1 as Context, c$1 as Definition, e$4 as Dispose, EventManager, ReflectParamIndex, ReflectParamValue, Use, getDecoratedParametersIndexes };
|