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