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