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