@moostjs/event-wf 0.2.34 → 0.2.35

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.cjs CHANGED
@@ -130,15 +130,701 @@ class MoostWf {
130
130
  }
131
131
  }
132
132
 
133
- function WfStep(path) {
134
- return getWfMate().decorate('handlers', { path, type: 'WF_STEP' }, true);
133
+ function getConstructor$1(instance) {
134
+ return isConstructor(instance) ?
135
+ instance : instance.constructor ?
136
+ instance.constructor : Object.getPrototypeOf(instance).constructor;
137
+ }
138
+ function isConstructor(v) {
139
+ return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
140
+ }
141
+
142
+ const classMetadata = {};
143
+ const paramMetadata = {};
144
+ const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
145
+ function getMetaObject(target, prop) {
146
+ const isParam = typeof prop !== 'undefined';
147
+ const metadata = isParam ? paramMetadata : classMetadata;
148
+ const targetKey = Symbol.for(getConstructor$1(target));
149
+ let meta = metadata[targetKey] = metadata[targetKey] || {};
150
+ if (isParam)
151
+ meta = (meta[prop] = meta[prop] || {});
152
+ return meta;
153
+ }
154
+ const _reflect = {
155
+ getOwnMetadata(key, target, prop) {
156
+ return getMetaObject(target, prop)[key];
157
+ },
158
+ defineMetadata(key, data, target, prop) {
159
+ const meta = getMetaObject(target, prop);
160
+ meta[key] = data;
161
+ },
162
+ metadata(key, data) {
163
+ return ((target, propKey) => {
164
+ Reflect$1.defineMetadata(key, data, target, propKey);
165
+ });
166
+ },
167
+ };
168
+ if (!root.Reflect) {
169
+ root.Reflect = _reflect;
135
170
  }
136
- function WfFlow(path) {
171
+ else {
172
+ const funcs = [
173
+ 'getOwnMetadata',
174
+ 'defineMetadata',
175
+ 'metadata',
176
+ ];
177
+ const target = root.Reflect;
178
+ for (const func of funcs) {
179
+ if (typeof target[func] !== 'function') {
180
+ Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
181
+ }
182
+ }
183
+ }
184
+ const Reflect$1 = _reflect;
185
+
186
+ const Reflect = (global === null || global === void 0 ? void 0 : global.Reflect) || (self === null || self === void 0 ? void 0 : self.Reflect) || Reflect$1;
187
+ class Mate {
188
+ constructor(workspace, options = {}) {
189
+ this.workspace = workspace;
190
+ this.options = options;
191
+ this.logger = options.logger || console;
192
+ }
193
+ set(args, key, value, isArray) {
194
+ var _a;
195
+ let level = 'CLASS';
196
+ const newArgs = args.level === 'CLASS' ? { target: args.target }
197
+ : args.level === 'PROP' ? { target: args.target, propKey: args.propKey }
198
+ : args;
199
+ let meta = (Reflect.getOwnMetadata(this.workspace, newArgs.target, newArgs.propKey) || {});
200
+ if (newArgs.propKey && this.options.readReturnType && !meta.returnType && args.descriptor) {
201
+ meta.returnType = Reflect.getOwnMetadata('design:returntype', newArgs.target, newArgs.propKey);
202
+ }
203
+ if (newArgs.propKey && this.options.readType && !meta.type) {
204
+ meta.type = Reflect.getOwnMetadata('design:type', newArgs.target, newArgs.propKey);
205
+ }
206
+ const { index } = newArgs;
207
+ const cb = typeof key === 'function' ? key : undefined;
208
+ let data = meta;
209
+ if (!data.params) {
210
+ data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
211
+ }
212
+ if (typeof index === 'number') {
213
+ level = 'PARAM';
214
+ data.params = data.params || [];
215
+ data.params[index] = data.params[index] || {
216
+ type: undefined,
217
+ };
218
+ if (cb) {
219
+ data.params[index] = cb(data.params[index], level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
220
+ }
221
+ else {
222
+ data = data.params[index];
223
+ }
224
+ }
225
+ else if (!index && !args.descriptor && args.propKey && this.options.collectPropKeys && args.level !== 'CLASS') {
226
+ this.set({ ...args, level: 'CLASS' }, (meta) => {
227
+ if (!meta.properties) {
228
+ meta.properties = [args.propKey];
229
+ }
230
+ else if (!meta.properties.includes(args.propKey)) {
231
+ meta.properties.push(args.propKey);
232
+ }
233
+ return meta;
234
+ });
235
+ }
236
+ level = typeof index === 'number' ? 'PARAM' : newArgs.propKey && newArgs.descriptor ? 'METHOD' : newArgs.propKey ? 'PROP' : 'CLASS';
237
+ if (typeof key !== 'function') {
238
+ if (isArray) {
239
+ const newArray = (data[key] || []);
240
+ if (!Array.isArray(newArray)) {
241
+ this.logger.error('Mate.add (isArray=true) called for non-array metadata');
242
+ }
243
+ newArray.unshift(value);
244
+ data[key] = newArray;
245
+ }
246
+ else {
247
+ data[key] = value;
248
+ }
249
+ }
250
+ else if (cb && typeof index !== 'number') {
251
+ meta = cb(data, level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
252
+ }
253
+ Reflect.defineMetadata(this.workspace, meta, newArgs.target, newArgs.propKey);
254
+ }
255
+ read(target, propKey) {
256
+ const isConstr = isConstructor(target);
257
+ const constructor = isConstr ? target : getConstructor$1(target);
258
+ const proto = constructor.prototype;
259
+ let ownMeta = Reflect.getOwnMetadata(this.workspace, typeof propKey === 'string' ? proto : constructor, propKey);
260
+ if (this.options.inherit) {
261
+ const inheritFn = typeof this.options.inherit === 'function' ? this.options.inherit : undefined;
262
+ let shouldInherit = this.options.inherit;
263
+ if (inheritFn) {
264
+ if (typeof propKey === 'string') {
265
+ const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
266
+ shouldInherit = inheritFn(classMeta, ownMeta, 'PROP', propKey);
267
+ }
268
+ else {
269
+ shouldInherit = inheritFn(ownMeta, ownMeta, 'CLASS');
270
+ }
271
+ }
272
+ if (shouldInherit) {
273
+ const parent = Object.getPrototypeOf(constructor);
274
+ if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
275
+ const inheritedMeta = (this.read(parent, propKey) || {});
276
+ const ownParams = ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params;
277
+ ownMeta = { ...inheritedMeta, ...ownMeta };
278
+ if (typeof propKey === 'string' && ownParams && (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params)) {
279
+ for (let i = 0; i < ownParams.length; i++) {
280
+ if (typeof (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i]) !== 'undefined') {
281
+ const ownParam = ownParams[i];
282
+ if (ownMeta.params && inheritFn && inheritFn(ownMeta, ownParam, 'PARAM', typeof propKey === 'string' ? propKey : undefined)) {
283
+ ownMeta.params[i] = {
284
+ ...inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i],
285
+ ...ownParams[i],
286
+ };
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+ }
294
+ return ownMeta;
295
+ }
296
+ apply(...decorators) {
297
+ return ((target, propKey, descriptor) => {
298
+ for (const d of decorators) {
299
+ d(target, propKey, descriptor);
300
+ }
301
+ });
302
+ }
303
+ decorate(key, value, isArray, level) {
304
+ return ((target, propKey, descriptor) => {
305
+ const args = {
306
+ target,
307
+ propKey,
308
+ descriptor: typeof descriptor === 'number' ? undefined : descriptor,
309
+ index: typeof descriptor === 'number' ? descriptor : undefined,
310
+ level,
311
+ };
312
+ this.set(args, key, value, isArray);
313
+ });
314
+ }
315
+ decorateConditional(ccb) {
316
+ return ((target, propKey, descriptor) => {
317
+ const hasIndex = typeof descriptor === 'number';
318
+ const decoratorLevel = hasIndex ? 'PARAM' : propKey && descriptor ? 'METHOD' : propKey ? 'PROP' : 'CLASS';
319
+ const d = ccb(decoratorLevel);
320
+ if (d) {
321
+ d(target, propKey, descriptor);
322
+ }
323
+ });
324
+ }
325
+ decorateClass(key, value, isArray) {
326
+ return this.decorate(key, value, isArray, 'CLASS');
327
+ }
328
+ }
329
+ const fnProto = Object.getPrototypeOf(Function);
330
+
331
+ const METADATA_WORKSPACE = 'moost';
332
+ const moostMate = new Mate(METADATA_WORKSPACE, {
333
+ readType: true,
334
+ readReturnType: true,
335
+ collectPropKeys: true,
336
+ inherit(classMeta, targetMeta, level) {
337
+ if (level === 'CLASS') {
338
+ return !!(classMeta === null || classMeta === void 0 ? void 0 : classMeta.inherit);
339
+ }
340
+ if (level === 'PROP') {
341
+ return (!!(targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.inherit) || !!((classMeta === null || classMeta === void 0 ? void 0 : classMeta.inherit) && !targetMeta));
342
+ }
343
+ return !!(targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.inherit);
344
+ },
345
+ });
346
+ function getMoostMate() {
347
+ return moostMate;
348
+ }
349
+
350
+ function getConstructor(instance) {
351
+ return Object.getPrototypeOf(instance).constructor;
352
+ }
353
+
354
+ const globalRegistry = {};
355
+ const UNDEFINED = Symbol('undefined');
356
+ class Infact {
357
+ constructor(options) {
358
+ this.options = options;
359
+ this.registry = {};
360
+ this.provideRegByInstance = new WeakMap();
361
+ this.scopes = {};
362
+ this._silent = false;
363
+ this.logger = options.logger || console;
364
+ }
365
+ setLogger(logger) {
366
+ this.logger = logger;
367
+ }
368
+ silent(value = 'logs') {
369
+ this._silent = value;
370
+ }
371
+ registerScope(scopeId) {
372
+ if (!this.scopes[scopeId]) {
373
+ this.scopes[scopeId] = {};
374
+ }
375
+ }
376
+ unregisterScope(scopeId) {
377
+ delete this.scopes[scopeId];
378
+ }
379
+ getForInstance(instance, classConstructor, opts) {
380
+ return this.get(classConstructor, { ...opts, provide: this.getProvideRegByInstnce(instance) || {} });
381
+ }
382
+ async get(classConstructor, opts, optional = false) {
383
+ const result = await this._get(classConstructor, opts, optional);
384
+ if (result) {
385
+ const { instance, mergedProvide } = result;
386
+ if (this.options.storeProvideRegByInstance) {
387
+ this.setProvideRegByInstance(instance, mergedProvide);
388
+ }
389
+ return instance;
390
+ }
391
+ return undefined;
392
+ }
393
+ setProvideRegByInstance(instance, provide) {
394
+ this.provideRegByInstance.set(instance, provide);
395
+ }
396
+ getProvideRegByInstnce(instance) {
397
+ return this.provideRegByInstance.get(instance) || {};
398
+ }
399
+ async _get(classConstructor, opts, optional) {
400
+ const hierarchy = (opts === null || opts === void 0 ? void 0 : opts.hierarchy) || [];
401
+ const provide = opts === null || opts === void 0 ? void 0 : opts.provide;
402
+ const syncContextFn = opts === null || opts === void 0 ? void 0 : opts.syncContextFn;
403
+ hierarchy.push(classConstructor.name);
404
+ let classMeta;
405
+ try {
406
+ classMeta = this.options.describeClass(classConstructor);
407
+ }
408
+ catch (e) {
409
+ throw this.panicOwnError(`Could not instantiate "${classConstructor.name}". `
410
+ + `An error occored on "describeClass" function.\n${e.message}`, hierarchy);
411
+ }
412
+ const instanceKey = Symbol.for(classConstructor);
413
+ if (!classMeta || !classMeta.injectable) {
414
+ if (provide && provide[instanceKey]) {
415
+ syncContextFn && syncContextFn(classMeta);
416
+ return { instance: await getProvidedValue(provide[instanceKey]), mergedProvide: provide };
417
+ }
418
+ if (!optional) {
419
+ throw this.panicOwnError(`Could not instantiate Injectable "${classConstructor.name}". `
420
+ + 'Please check if the class is injectable or if you properly typed arguments.', hierarchy);
421
+ }
422
+ else {
423
+ return undefined;
424
+ }
425
+ }
426
+ if (classMeta.scopeId && classMeta.global) {
427
+ throw this.panicOwnError(`Could not instantiate scoped Injectable "${classConstructor.name}" for scope "${classMeta.scopeId}". `
428
+ + 'The scoped Injectable is not supported for Global scope.', hierarchy);
429
+ }
430
+ if (classMeta.scopeId && !this.scopes[classMeta.scopeId]) {
431
+ throw this.panicOwnError(`Could not instantiate scoped Injectable "${classConstructor.name}" for scope "${classMeta.scopeId}". `
432
+ + 'The requested scope isn\'t registered.', hierarchy);
433
+ }
434
+ const scope = classMeta.scopeId ? this.scopes[classMeta.scopeId] : {};
435
+ const mergedProvide = { ...(provide || {}), ...(classMeta.provide || {}) };
436
+ if (mergedProvide[instanceKey]) {
437
+ syncContextFn && syncContextFn(classMeta);
438
+ return { instance: await getProvidedValue(mergedProvide[instanceKey]), mergedProvide };
439
+ }
440
+ if (!this.registry[instanceKey] && !globalRegistry[instanceKey] && !scope[instanceKey]) {
441
+ const registry = classMeta.scopeId ? scope : classMeta.global ? globalRegistry : this.registry;
442
+ const params = classMeta.constructorParams || [];
443
+ const isCircular = !!params.find(p => !!p.circular);
444
+ if (isCircular) {
445
+ registry[instanceKey] = Object.create(classConstructor.prototype);
446
+ }
447
+ const resolvedParams = [];
448
+ for (let i = 0; i < params.length; i++) {
449
+ const param = params[i];
450
+ if (param.inject) {
451
+ if (mergedProvide && mergedProvide[param.inject]) {
452
+ resolvedParams[i] = getProvidedValue(mergedProvide[param.inject]);
453
+ }
454
+ else if (param.nullable || param.optional) {
455
+ resolvedParams[i] = UNDEFINED;
456
+ }
457
+ else {
458
+ throw this.panicOwnError(`Could not inject ${JSON.stringify(param.inject)} to "${classConstructor.name}" to argument ${param.label ? `labeled as "${param.label}"` : `with index ${i}`}`, hierarchy);
459
+ }
460
+ }
461
+ else if (this.options.resolveParam) {
462
+ resolvedParams[i] = this.options.resolveParam({
463
+ classMeta,
464
+ classConstructor,
465
+ index: i,
466
+ paramMeta: param,
467
+ customData: opts === null || opts === void 0 ? void 0 : opts.customData,
468
+ });
469
+ }
470
+ }
471
+ for (let i = 0; i < resolvedParams.length; i++) {
472
+ const rp = resolvedParams[i];
473
+ if (rp && rp !== UNDEFINED && typeof rp.then === 'function') {
474
+ try {
475
+ syncContextFn && syncContextFn(classMeta);
476
+ resolvedParams[i] = await rp;
477
+ }
478
+ catch (e) {
479
+ const param = params[i];
480
+ throw this.panic(e, `Could not inject "${param.type.name}" to "${classConstructor.name}" `
481
+ + `constructor at index ${i}${param.label ? ` (${param.label})` : ''}. An exception occured.`, hierarchy);
482
+ }
483
+ }
484
+ }
485
+ for (let i = 0; i < params.length; i++) {
486
+ const param = params[i];
487
+ if (typeof resolvedParams[i] === 'undefined') {
488
+ if (param.type === undefined && !param.circular) {
489
+ if (this._silent === false) {
490
+ this.logger.warn(`${classConstructor.name}.constructor() expects argument ${param.label ? `labeled as "${param.label}"` : `#${i}`} that is undefined. This might happen when Circular Dependency occurs. To handle Circular Dependencies please specify circular meta for param.`);
491
+ }
492
+ }
493
+ else if (param.type === undefined && param.circular) {
494
+ param.type = param.circular();
495
+ }
496
+ if (typeof param.type === 'function') {
497
+ if ([String, Number, Date, Array].includes(param.type)) {
498
+ if (!param.nullable && !param.optional) {
499
+ throw this.panicOwnError(`Could not inject "${param.type.name}" to "${classConstructor.name}" `
500
+ + `constructor at index ${i}${param.label ? ` (${param.label})` : ''}. The param was not resolved to a value.`, hierarchy);
501
+ }
502
+ }
503
+ resolvedParams[i] = this.get(param.type, { provide: mergedProvide, hierarchy, syncContextFn, customData: opts === null || opts === void 0 ? void 0 : opts.customData }, param.optional || param.nullable);
504
+ }
505
+ }
506
+ if (resolvedParams[i] === UNDEFINED) {
507
+ resolvedParams[i] = undefined;
508
+ }
509
+ }
510
+ for (let i = 0; i < resolvedParams.length; i++) {
511
+ const rp = resolvedParams[i];
512
+ if (rp && typeof rp.then === 'function') {
513
+ try {
514
+ syncContextFn && syncContextFn(classMeta);
515
+ resolvedParams[i] = await rp;
516
+ }
517
+ catch (e) {
518
+ const param = params[i];
519
+ throw this.panic(e, `Could not inject "${param.type.name}" to "${classConstructor.name}" `
520
+ + `constructor at index ${i}${param.label ? ` (${param.label})` : ''}. An exception occured.`, hierarchy);
521
+ }
522
+ }
523
+ }
524
+ const instance = new classConstructor(...resolvedParams);
525
+ if (isCircular) {
526
+ Object.assign(registry[instanceKey], instance);
527
+ }
528
+ else {
529
+ registry[instanceKey] = instance;
530
+ }
531
+ if (this.options.describeProp && this.options.resolveProp && classMeta.properties && classMeta.properties.length) {
532
+ const resolvedProps = {};
533
+ for (const prop of classMeta.properties) {
534
+ const initialValue = instance[prop];
535
+ let propMeta;
536
+ try {
537
+ propMeta = this.options.describeProp(classConstructor, prop);
538
+ }
539
+ catch (e) {
540
+ throw this.panic(e, `Could not process prop "${prop}" of "${classConstructor.name}". `
541
+ + `An error occored on "describeProp" function.\n${e.message}`, hierarchy);
542
+ }
543
+ if (propMeta) {
544
+ try {
545
+ resolvedProps[prop] = this.options.resolveProp({
546
+ classMeta,
547
+ classConstructor,
548
+ initialValue,
549
+ key: prop,
550
+ instance,
551
+ propMeta,
552
+ customData: opts === null || opts === void 0 ? void 0 : opts.customData,
553
+ });
554
+ }
555
+ catch (e) {
556
+ throw this.panic(e, `Could not inject prop "${prop}" to "${classConstructor.name}". `
557
+ + 'An exception occured: ' + e.message, hierarchy);
558
+ }
559
+ }
560
+ }
561
+ for (const [prop, value] of Object.entries(resolvedProps)) {
562
+ try {
563
+ syncContextFn && syncContextFn(classMeta);
564
+ resolvedProps[prop] = value ? await value : value;
565
+ }
566
+ catch (e) {
567
+ throw this.panic(e, `Could not inject prop "${prop}" to "${classConstructor.name}". `
568
+ + 'An exception occured: ' + e.message, hierarchy);
569
+ }
570
+ }
571
+ Object.assign(instance, resolvedProps);
572
+ }
573
+ if (this._silent === false) {
574
+ this.logger.info(`Class "${'' + classConstructor.name + '' + ''}" instantiated with: ${''}[${resolvedParams.map(p => {
575
+ switch (typeof p) {
576
+ case 'number':
577
+ case 'boolean':
578
+ return p;
579
+ case 'string':
580
+ return `"${''}...${''}"`;
581
+ case 'object':
582
+ if (getConstructor(p))
583
+ return getConstructor(p).name;
584
+ return '{}';
585
+ default: return '*';
586
+ }
587
+ }).join(', ')}]`);
588
+ }
589
+ }
590
+ hierarchy.pop();
591
+ syncContextFn && syncContextFn(classMeta);
592
+ return { instance: await (scope[instanceKey] || this.registry[instanceKey] || globalRegistry[instanceKey]), mergedProvide };
593
+ }
594
+ panic(origError, text, hierarchy) {
595
+ if (this._silent === true) ;
596
+ else {
597
+ this.logger.error(text + (hierarchy ? ('\nHierarchy:\n' + hierarchy.join(' -> ')) : ''));
598
+ }
599
+ return origError;
600
+ }
601
+ panicOwnError(text, hierarchy) {
602
+ const e = new Error(text + (hierarchy ? ('\nHierarchy:\n' + hierarchy.join(' -> ')) : ''));
603
+ if (this._silent === true) {
604
+ return e;
605
+ }
606
+ else {
607
+ this.logger.error(e);
608
+ return e;
609
+ }
610
+ }
611
+ }
612
+ function getProvidedValue(meta) {
613
+ if (!meta.resolved) {
614
+ meta.resolved = true;
615
+ meta.value = meta.fn();
616
+ }
617
+ return meta.value;
618
+ }
619
+
620
+ function runPipes(pipes, initialValue, metas, level, restoreCtx) {
621
+ return __awaiter(this, void 0, void 0, function* () {
622
+ let v = initialValue;
623
+ for (const pipe of pipes) {
624
+ restoreCtx && restoreCtx();
625
+ v = yield pipe.handler(v, metas, level);
626
+ }
627
+ return v;
628
+ });
629
+ }
630
+
631
+ getNewMoostInfact();
632
+ function getNewMoostInfact() {
633
+ return new Infact({
634
+ describeClass(classConstructor) {
635
+ const meta = getMoostMate().read(classConstructor);
636
+ const infactMeta = {
637
+ injectable: !!(meta === null || meta === void 0 ? void 0 : meta.injectable),
638
+ global: false,
639
+ constructorParams: (meta === null || meta === void 0 ? void 0 : meta.params) || [],
640
+ provide: meta === null || meta === void 0 ? void 0 : meta.provide,
641
+ properties: (meta === null || meta === void 0 ? void 0 : meta.properties) || [],
642
+ scopeId: (meta === null || meta === void 0 ? void 0 : meta.injectable) === 'FOR_EVENT'
643
+ ? eventCore.useEventId().getId()
644
+ : undefined,
645
+ };
646
+ return infactMeta;
647
+ },
648
+ resolveParam({ paramMeta, classMeta, customData, classConstructor, index }) {
649
+ if (paramMeta && customData && customData.pipes) {
650
+ return runPipes(customData.pipes, undefined, {
651
+ paramMeta,
652
+ type: classConstructor,
653
+ key: 'constructor',
654
+ classMeta: classMeta,
655
+ index,
656
+ targetMeta: paramMeta,
657
+ }, 'PARAM');
658
+ }
659
+ },
660
+ describeProp(classConstructor, key) {
661
+ const meta = getMoostMate().read(classConstructor, key);
662
+ return meta;
663
+ },
664
+ resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
665
+ if (propMeta && customData && customData.pipes) {
666
+ return runPipes(customData.pipes, initialValue, {
667
+ instance,
668
+ type: classConstructor,
669
+ key,
670
+ propMeta,
671
+ targetMeta: propMeta,
672
+ classMeta: classMeta,
673
+ }, 'PROP');
674
+ }
675
+ },
676
+ storeProvideRegByInstance: true,
677
+ });
678
+ }
679
+
680
+ /**
681
+ * ## Label
682
+ * ### @Decorator
683
+ * _Common purpose decorator that may be used by various adapters for various purposes_
684
+ *
685
+ * Stores Label metadata
686
+ */
687
+ function Label(value) {
688
+ return getMoostMate().decorate('label', value);
689
+ }
690
+
691
+ /**
692
+ * Hook to the Response Status
693
+ * @decorator
694
+ * @param resolver - resolver function
695
+ * @param label - field label
696
+ * @paramType unknown
697
+ */
698
+ function Resolve(resolver, label) {
699
+ return (target, key, index) => {
700
+ const i = typeof index === 'number' ? index : undefined;
701
+ getMoostMate().decorate('resolver', (metas, level) => {
702
+ let newLabel = label;
703
+ if (!newLabel && level === 'PROP' && typeof metas.key === 'string') {
704
+ newLabel = metas.key;
705
+ }
706
+ fillLabel(target, key || '', i, newLabel);
707
+ return resolver(metas, level);
708
+ })(target, key, i);
709
+ };
710
+ }
711
+ function fillLabel(target, key, index, name) {
712
+ if (name) {
713
+ const meta = getMoostMate().read(target, key);
714
+ if (typeof index === 'number') {
715
+ if (!(meta === null || meta === void 0 ? void 0 : meta.params) ||
716
+ !(meta === null || meta === void 0 ? void 0 : meta.params[index]) ||
717
+ !(meta === null || meta === void 0 ? void 0 : meta.params[index].label)) {
718
+ Label(name)(target, key, index);
719
+ }
720
+ }
721
+ else {
722
+ if (!(meta === null || meta === void 0 ? void 0 : meta.label)) {
723
+ Label(name)(target, key);
724
+ }
725
+ }
726
+ }
727
+ }
728
+
729
+ getMoostMate().decorate((meta) => {
730
+ if (!meta.injectable)
731
+ meta.injectable = true;
732
+ return meta;
733
+ });
734
+
735
+ var TInterceptorPriority;
736
+ (function (TInterceptorPriority) {
737
+ TInterceptorPriority[TInterceptorPriority["BEFORE_ALL"] = 0] = "BEFORE_ALL";
738
+ TInterceptorPriority[TInterceptorPriority["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
739
+ TInterceptorPriority[TInterceptorPriority["GUARD"] = 2] = "GUARD";
740
+ TInterceptorPriority[TInterceptorPriority["AFTER_GUARD"] = 3] = "AFTER_GUARD";
741
+ TInterceptorPriority[TInterceptorPriority["INTERCEPTOR"] = 4] = "INTERCEPTOR";
742
+ TInterceptorPriority[TInterceptorPriority["CATCH_ERROR"] = 5] = "CATCH_ERROR";
743
+ TInterceptorPriority[TInterceptorPriority["AFTER_ALL"] = 6] = "AFTER_ALL";
744
+ })(TInterceptorPriority || (TInterceptorPriority = {}));
745
+
746
+ var TPipePriority;
747
+ (function (TPipePriority) {
748
+ TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
749
+ TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
750
+ TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
751
+ TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
752
+ TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
753
+ TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
754
+ TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
755
+ TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
756
+ TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
757
+ })(TPipePriority || (TPipePriority = {}));
758
+
759
+ /**
760
+ * ### Define Pipe Function
761
+ *
762
+ * ```ts
763
+ * // example of a transform pipe
764
+ * const uppercaseTransformPipe = definePipeFn((value, metas, level) => {
765
+ * return typeof value === 'string' ? value.toUpperCase() : value
766
+ * },
767
+ * TPipePriority.TRANSFORM,
768
+ * )
769
+ * ```
770
+ *
771
+ * @param fn interceptor function
772
+ * @param priority priority of the pipe where BEFORE_RESOLVE = 0, RESOLVE = 1, AFTER_RESOLVE = 2, BEFORE_TRANSFORM = 3, TRANSFORM = 4, AFTER_TRANSFORM = 5, BEFORE_VALIDATE = 6, VALIDATE = 7, AFTER_VALIDATE = 8
773
+ * @returns
774
+ */
775
+ function definePipeFn(fn, priority = TPipePriority.TRANSFORM) {
776
+ fn.priority = priority;
777
+ return fn;
778
+ }
779
+
780
+ const resolvePipe = definePipeFn((_value, metas, level) => {
781
+ var _a;
782
+ const resolver = (_a = metas.targetMeta) === null || _a === void 0 ? void 0 : _a.resolver;
783
+ if (resolver) {
784
+ return resolver(metas, level);
785
+ }
786
+ return undefined;
787
+ }, TPipePriority.RESOLVE);
788
+
789
+ [
790
+ {
791
+ handler: resolvePipe,
792
+ priority: TPipePriority.RESOLVE,
793
+ },
794
+ ];
795
+
796
+ const defaultLevels = [
797
+ 'fatal',
798
+ 'error',
799
+ 'warn',
800
+ 'log',
801
+ 'info',
802
+ 'debug',
803
+ 'trace',
804
+ ];
805
+ const defaultMappedLevels = new Map();
806
+ defaultLevels.forEach((type, level) => defaultMappedLevels.set(type, level));
807
+
808
+ function WStep(path) {
137
809
  return getWfMate().decorate('handlers', { path, type: 'WF_STEP' }, true);
138
810
  }
139
- function WfSchema(schema) {
811
+ function WFlow(path) {
812
+ return getWfMate().decorate('handlers', { path, type: 'WF_FLOW' }, true);
813
+ }
814
+ function WSchema(schema) {
140
815
  return getWfMate().decorate('wfSchema', schema);
141
- }
816
+ }
817
+ const WfCtx = (name) => Resolve(() => {
818
+ const c = eventWf.useWfState().ctx();
819
+ return name ? c[name] : c;
820
+ }, name || 'WfCtx');
821
+ const WfResume = () => Resolve(() => eventWf.useWfState().resume);
822
+ const WfIndexes = () => Resolve(() => eventWf.useWfState().indexes);
823
+ const WfSchemaId = () => Resolve(() => eventWf.useWfState().schemaId);
824
+ const WfInput = (name) => Resolve(() => {
825
+ const i = eventWf.useWfState().input();
826
+ return name ? i[name] : i;
827
+ }, name || 'WfInput');
142
828
 
143
829
  /**
144
830
  * Wrapper on top of useEventContext that provides
@@ -150,7 +836,12 @@ function useCliContext() {
150
836
  }
151
837
 
152
838
  exports.MoostWf = MoostWf;
153
- exports.WfFlow = WfFlow;
154
- exports.WfSchema = WfSchema;
155
- exports.WfStep = WfStep;
839
+ exports.WFlow = WFlow;
840
+ exports.WSchema = WSchema;
841
+ exports.WStep = WStep;
842
+ exports.WfCtx = WfCtx;
843
+ exports.WfIndexes = WfIndexes;
844
+ exports.WfInput = WfInput;
845
+ exports.WfResume = WfResume;
846
+ exports.WfSchemaId = WfSchemaId;
156
847
  exports.useCliContext = useCliContext;