@moostjs/otel 0.4.6 → 0.4.7
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 +920 -1
- package/dist/index.d.ts +146 -1
- package/dist/index.mjs +922 -8
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var api = require('@opentelemetry/api');
|
|
4
4
|
var moost = require('moost');
|
|
5
|
+
var crypto = require('crypto');
|
|
6
|
+
var node_async_hooks = require('node:async_hooks');
|
|
7
|
+
var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
5
8
|
|
|
6
9
|
function useOtelContext() {
|
|
7
10
|
const store = moost.useAsyncEventContext().store('otel');
|
|
@@ -80,14 +83,16 @@ function enableOtelForMoost() {
|
|
|
80
83
|
const { getSpan } = useOtelContext();
|
|
81
84
|
const span = getSpan();
|
|
82
85
|
if (span) {
|
|
83
|
-
const { getMethod, getMethodMeta, getController } = moost.useControllerContext();
|
|
86
|
+
const { getMethod, getMethodMeta, getController, getControllerMeta } = moost.useControllerContext();
|
|
84
87
|
const methodName = getMethod();
|
|
85
88
|
const methodMeta = getMethodMeta();
|
|
89
|
+
const cMeta = getControllerMeta();
|
|
86
90
|
span.setAttributes({
|
|
87
91
|
'custom.event_type': eventType,
|
|
88
92
|
'custom.event_description': methodMeta?.description || methodMeta?.label || methodName,
|
|
89
93
|
'moost.controller': moost.getConstructor(getController()).name,
|
|
90
94
|
'moost.handler': methodName,
|
|
95
|
+
'moost.ignore': cMeta?.otelIgnoreSpan || methodMeta?.otelIgnoreSpan,
|
|
91
96
|
});
|
|
92
97
|
if (abortReason) {
|
|
93
98
|
span.recordException(new Error(abortReason));
|
|
@@ -107,7 +112,921 @@ function enableOtelForMoost() {
|
|
|
107
112
|
});
|
|
108
113
|
}
|
|
109
114
|
|
|
115
|
+
const defaultLevels = [
|
|
116
|
+
'fatal',
|
|
117
|
+
'error',
|
|
118
|
+
'warn',
|
|
119
|
+
'log',
|
|
120
|
+
'info',
|
|
121
|
+
'debug',
|
|
122
|
+
'trace',
|
|
123
|
+
];
|
|
124
|
+
const defaultMappedLevels = new Map();
|
|
125
|
+
defaultLevels.forEach((type, level) => defaultMappedLevels.set(type, level));
|
|
126
|
+
|
|
127
|
+
class Hookable {
|
|
128
|
+
constructor() {
|
|
129
|
+
this.hooks = {};
|
|
130
|
+
}
|
|
131
|
+
hook(name, cb) {
|
|
132
|
+
if (!this.hooks[name]) {
|
|
133
|
+
this.hooks[name] = [];
|
|
134
|
+
}
|
|
135
|
+
this.hooks[name].push(cb);
|
|
136
|
+
return () => {
|
|
137
|
+
this.unhook(name, cb);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
callHook(name, ...args) {
|
|
141
|
+
if (this.hooks[name]) {
|
|
142
|
+
for (const cb of this.hooks[name]) {
|
|
143
|
+
try {
|
|
144
|
+
cb(...args);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error(`Error in hook ${name}:`, error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
unhook(name, cb) {
|
|
153
|
+
if (this.hooks[name]) {
|
|
154
|
+
this.hooks[name] = this.hooks[name].filter(hookCb => hookCb !== cb);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
class EventContextHooks extends Hookable {
|
|
160
|
+
fireStartEvent(eventType) {
|
|
161
|
+
this.callHook('start-event', eventType);
|
|
162
|
+
}
|
|
163
|
+
fireEndEvent(eventType, abortReason) {
|
|
164
|
+
this.callHook('end-event', eventType, abortReason);
|
|
165
|
+
}
|
|
166
|
+
onStartEvent(cb) {
|
|
167
|
+
return this.hook('start-event', cb);
|
|
168
|
+
}
|
|
169
|
+
onEndEvent(cb) {
|
|
170
|
+
return this.hook('end-event', cb);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const eventContextHooks = new EventContextHooks();
|
|
174
|
+
|
|
175
|
+
function attachHook(target, opts, name) {
|
|
176
|
+
Object.defineProperty(target, name || 'value', {
|
|
177
|
+
get: opts.get,
|
|
178
|
+
set: opts.set,
|
|
179
|
+
});
|
|
180
|
+
return target;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const asyncStorage = new node_async_hooks.AsyncLocalStorage();
|
|
184
|
+
function useAsyncEventContext(expectedTypes) {
|
|
185
|
+
let cc = asyncStorage.getStore();
|
|
186
|
+
if (!cc) {
|
|
187
|
+
throw new Error('Event context does not exist at this point.');
|
|
188
|
+
}
|
|
189
|
+
if (expectedTypes || typeof expectedTypes === 'string') {
|
|
190
|
+
const type = cc.event.type;
|
|
191
|
+
const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
|
|
192
|
+
if (!types.includes(type)) {
|
|
193
|
+
if (cc.parentCtx?.event.type && types.includes(cc.parentCtx.event.type)) {
|
|
194
|
+
cc = cc.parentCtx;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
throw new Error(`Event context type mismatch: expected ${types
|
|
198
|
+
.map(t => `"${t}"`)
|
|
199
|
+
.join(', ')}, received "${type}"`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return _getCtxHelpers(cc);
|
|
204
|
+
}
|
|
205
|
+
function _getCtxHelpers(cc) {
|
|
206
|
+
function store(key) {
|
|
207
|
+
const obj = {
|
|
208
|
+
value: null,
|
|
209
|
+
hook,
|
|
210
|
+
init,
|
|
211
|
+
set: setNested,
|
|
212
|
+
get: getNested,
|
|
213
|
+
has: hasNested,
|
|
214
|
+
del: delNested,
|
|
215
|
+
entries,
|
|
216
|
+
clear,
|
|
217
|
+
};
|
|
218
|
+
attachHook(obj, {
|
|
219
|
+
set: v => {
|
|
220
|
+
set(key, v);
|
|
221
|
+
},
|
|
222
|
+
get: () => get(key),
|
|
223
|
+
});
|
|
224
|
+
function init(key2, getter) {
|
|
225
|
+
if (hasNested(key2)) {
|
|
226
|
+
return getNested(key2);
|
|
227
|
+
}
|
|
228
|
+
return setNested(key2, getter());
|
|
229
|
+
}
|
|
230
|
+
function hook(key2) {
|
|
231
|
+
const obj = {
|
|
232
|
+
value: null,
|
|
233
|
+
isDefined: null,
|
|
234
|
+
};
|
|
235
|
+
attachHook(obj, {
|
|
236
|
+
set: v => setNested(key2, v),
|
|
237
|
+
get: () => getNested(key2),
|
|
238
|
+
});
|
|
239
|
+
attachHook(obj, {
|
|
240
|
+
get: () => hasNested(key2),
|
|
241
|
+
}, 'isDefined');
|
|
242
|
+
return obj;
|
|
243
|
+
}
|
|
244
|
+
function setNested(key2, v) {
|
|
245
|
+
if (obj.value === undefined) {
|
|
246
|
+
obj.value = {};
|
|
247
|
+
}
|
|
248
|
+
obj.value[key2] = v;
|
|
249
|
+
return v;
|
|
250
|
+
}
|
|
251
|
+
function delNested(key2) {
|
|
252
|
+
setNested(key2, undefined);
|
|
253
|
+
}
|
|
254
|
+
function getNested(key2) {
|
|
255
|
+
return (obj.value || {})[key2];
|
|
256
|
+
}
|
|
257
|
+
function hasNested(key2) {
|
|
258
|
+
return (obj.value || {})[key2] !== undefined;
|
|
259
|
+
}
|
|
260
|
+
function entries() {
|
|
261
|
+
return Object.entries(obj.value || {});
|
|
262
|
+
}
|
|
263
|
+
function clear() {
|
|
264
|
+
obj.value = {};
|
|
265
|
+
}
|
|
266
|
+
return obj;
|
|
267
|
+
}
|
|
268
|
+
function getCtx() {
|
|
269
|
+
return cc;
|
|
270
|
+
}
|
|
271
|
+
function get(key) {
|
|
272
|
+
return getCtx()[key];
|
|
273
|
+
}
|
|
274
|
+
function set(key, v) {
|
|
275
|
+
getCtx()[key] = v;
|
|
276
|
+
}
|
|
277
|
+
const hasParentCtx = () => !!cc.parentCtx;
|
|
278
|
+
return {
|
|
279
|
+
getCtx,
|
|
280
|
+
endEvent: (abortReason) => {
|
|
281
|
+
if (cc && !cc._ended) {
|
|
282
|
+
cc._ended = true;
|
|
283
|
+
eventContextHooks.fireEndEvent(cc.event.type, abortReason);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
store,
|
|
287
|
+
getStore: get,
|
|
288
|
+
setStore: set,
|
|
289
|
+
setParentCtx: (parentCtx) => {
|
|
290
|
+
cc.parentCtx = parentCtx;
|
|
291
|
+
},
|
|
292
|
+
hasParentCtx,
|
|
293
|
+
getParentCtx: () => {
|
|
294
|
+
if (!hasParentCtx()) {
|
|
295
|
+
throw new Error('Parent context is not available');
|
|
296
|
+
}
|
|
297
|
+
return _getCtxHelpers(cc.parentCtx);
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function useEventId() {
|
|
303
|
+
const { store } = useAsyncEventContext();
|
|
304
|
+
const { init } = store('event');
|
|
305
|
+
const getId = () => init('id', () => crypto.randomUUID());
|
|
306
|
+
return { getId };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function getConstructor$1(instance) {
|
|
310
|
+
return Object.getPrototypeOf(instance).constructor;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const globalRegistry = {};
|
|
314
|
+
const UNDEFINED = Symbol('undefined');
|
|
315
|
+
class Infact {
|
|
316
|
+
constructor(options) {
|
|
317
|
+
this.options = options;
|
|
318
|
+
this.registry = {};
|
|
319
|
+
this.instanceRegistries = new WeakMap();
|
|
320
|
+
this.scopes = {};
|
|
321
|
+
this._silent = false;
|
|
322
|
+
this.logger = options.logger || console;
|
|
323
|
+
}
|
|
324
|
+
setLogger(logger) {
|
|
325
|
+
this.logger = logger;
|
|
326
|
+
}
|
|
327
|
+
silent(value = 'logs') {
|
|
328
|
+
this._silent = value;
|
|
329
|
+
}
|
|
330
|
+
registerScope(scopeId) {
|
|
331
|
+
if (!this.scopes[scopeId]) {
|
|
332
|
+
this.scopes[scopeId] = {};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
unregisterScope(scopeId) {
|
|
336
|
+
delete this.scopes[scopeId];
|
|
337
|
+
}
|
|
338
|
+
getForInstance(instance, classConstructor, opts) {
|
|
339
|
+
const registries = this.getInstanceRegistries(instance);
|
|
340
|
+
return this.get(classConstructor, {
|
|
341
|
+
...opts,
|
|
342
|
+
provide: registries.provide || {},
|
|
343
|
+
replace: registries.replace,
|
|
344
|
+
customData: registries.customData,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
async get(classConstructor, opts, optional = false) {
|
|
348
|
+
const result = await this._get(classConstructor, opts, optional);
|
|
349
|
+
if (result) {
|
|
350
|
+
const { instance, mergedProvide, replace } = result;
|
|
351
|
+
if (this.options.storeProvideRegByInstance) {
|
|
352
|
+
this.setInstanceRegistries(instance, mergedProvide, replace, opts === null || opts === void 0 ? void 0 : opts.customData);
|
|
353
|
+
}
|
|
354
|
+
return instance;
|
|
355
|
+
}
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
setInstanceRegistries(instance, provide, replace, customData) {
|
|
359
|
+
this.instanceRegistries.set(instance, { provide, replace, customData });
|
|
360
|
+
}
|
|
361
|
+
getInstanceRegistries(instance) {
|
|
362
|
+
return this.instanceRegistries.get(instance) || {};
|
|
363
|
+
}
|
|
364
|
+
async _get(classConstructor, opts, optional) {
|
|
365
|
+
const hierarchy = (opts === null || opts === void 0 ? void 0 : opts.hierarchy) || [];
|
|
366
|
+
const provide = opts === null || opts === void 0 ? void 0 : opts.provide;
|
|
367
|
+
const replace = opts === null || opts === void 0 ? void 0 : opts.replace;
|
|
368
|
+
const syncContextFn = opts === null || opts === void 0 ? void 0 : opts.syncContextFn;
|
|
369
|
+
hierarchy.push(classConstructor.name);
|
|
370
|
+
let classMeta;
|
|
371
|
+
let instanceKey = Symbol.for(classConstructor);
|
|
372
|
+
if (replace && replace[instanceKey]) {
|
|
373
|
+
classConstructor = replace === null || replace === void 0 ? void 0 : replace[instanceKey];
|
|
374
|
+
instanceKey = Symbol.for(classConstructor);
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
classMeta = this.options.describeClass(classConstructor);
|
|
378
|
+
}
|
|
379
|
+
catch (e) {
|
|
380
|
+
throw this.panicOwnError(`Could not instantiate "${classConstructor.name}". ` +
|
|
381
|
+
`An error occored on "describeClass" function.\n${e.message}`, hierarchy);
|
|
382
|
+
}
|
|
383
|
+
if (!classMeta || !classMeta.injectable) {
|
|
384
|
+
if (provide && provide[instanceKey]) {
|
|
385
|
+
syncContextFn && syncContextFn(classMeta);
|
|
386
|
+
return {
|
|
387
|
+
instance: await getProvidedValue(provide[instanceKey]),
|
|
388
|
+
mergedProvide: provide,
|
|
389
|
+
replace,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
if (!optional) {
|
|
393
|
+
throw this.panicOwnError(`Could not instantiate Injectable "${classConstructor.name}". ` +
|
|
394
|
+
'Please check if the class is injectable or if you properly typed arguments.', hierarchy);
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (classMeta.scopeId && classMeta.global) {
|
|
401
|
+
throw this.panicOwnError(`Could not instantiate scoped Injectable "${classConstructor.name}" for scope "${classMeta.scopeId}". ` +
|
|
402
|
+
'The scoped Injectable is not supported for Global scope.', hierarchy);
|
|
403
|
+
}
|
|
404
|
+
if (classMeta.scopeId && !this.scopes[classMeta.scopeId]) {
|
|
405
|
+
throw this.panicOwnError(`Could not instantiate scoped Injectable "${classConstructor.name}" for scope "${classMeta.scopeId}". ` +
|
|
406
|
+
'The requested scope isn\'t registered.', hierarchy);
|
|
407
|
+
}
|
|
408
|
+
const scope = classMeta.scopeId
|
|
409
|
+
? this.scopes[classMeta.scopeId]
|
|
410
|
+
: {};
|
|
411
|
+
const mergedProvide = {
|
|
412
|
+
...(provide || {}),
|
|
413
|
+
...(classMeta.provide || {}),
|
|
414
|
+
};
|
|
415
|
+
if (mergedProvide[instanceKey]) {
|
|
416
|
+
syncContextFn && syncContextFn(classMeta);
|
|
417
|
+
return {
|
|
418
|
+
instance: await getProvidedValue(mergedProvide[instanceKey]),
|
|
419
|
+
mergedProvide,
|
|
420
|
+
replace,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if (!this.registry[instanceKey] &&
|
|
424
|
+
!globalRegistry[instanceKey] &&
|
|
425
|
+
!scope[instanceKey]) {
|
|
426
|
+
const registry = classMeta.scopeId
|
|
427
|
+
? scope
|
|
428
|
+
: classMeta.global
|
|
429
|
+
? globalRegistry
|
|
430
|
+
: this.registry;
|
|
431
|
+
const params = classMeta.constructorParams || [];
|
|
432
|
+
const isCircular = !!params.find((p) => !!p.circular);
|
|
433
|
+
if (isCircular) {
|
|
434
|
+
registry[instanceKey] = Object.create(classConstructor.prototype);
|
|
435
|
+
}
|
|
436
|
+
const resolvedParams = [];
|
|
437
|
+
for (let i = 0; i < params.length; i++) {
|
|
438
|
+
const param = params[i];
|
|
439
|
+
if (param.inject) {
|
|
440
|
+
if (mergedProvide && mergedProvide[param.inject]) {
|
|
441
|
+
resolvedParams[i] = getProvidedValue(mergedProvide[param.inject]);
|
|
442
|
+
}
|
|
443
|
+
else if (param.nullable || param.optional) {
|
|
444
|
+
resolvedParams[i] = UNDEFINED;
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
throw this.panicOwnError(`Could not inject ${JSON.stringify(param.inject)} to "${classConstructor.name}" to argument ${param.label
|
|
448
|
+
? `labeled as "${param.label}"`
|
|
449
|
+
: `with index ${i}`}`, hierarchy);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
else if (this.options.resolveParam) {
|
|
453
|
+
resolvedParams[i] = this.options.resolveParam({
|
|
454
|
+
classMeta,
|
|
455
|
+
classConstructor,
|
|
456
|
+
index: i,
|
|
457
|
+
paramMeta: param,
|
|
458
|
+
customData: opts === null || opts === void 0 ? void 0 : opts.customData,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
for (let i = 0; i < resolvedParams.length; i++) {
|
|
463
|
+
const rp = resolvedParams[i];
|
|
464
|
+
if (rp &&
|
|
465
|
+
rp !== UNDEFINED &&
|
|
466
|
+
typeof rp.then === 'function') {
|
|
467
|
+
try {
|
|
468
|
+
syncContextFn && syncContextFn(classMeta);
|
|
469
|
+
resolvedParams[i] = await rp;
|
|
470
|
+
}
|
|
471
|
+
catch (e) {
|
|
472
|
+
const param = params[i];
|
|
473
|
+
throw this.panic(e, `Could not inject "${param.type.name}" to "${classConstructor.name}" ` +
|
|
474
|
+
`constructor at index ${i}${param.label ? ` (${param.label})` : ''}. An exception occured.`, hierarchy);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
for (let i = 0; i < params.length; i++) {
|
|
479
|
+
const param = params[i];
|
|
480
|
+
if (typeof resolvedParams[i] === 'undefined') {
|
|
481
|
+
if (param.type === undefined && !param.circular) {
|
|
482
|
+
if (this._silent === false) {
|
|
483
|
+
this.logger.warn(`${classConstructor.name}.constructor() expects argument ${param.label
|
|
484
|
+
? `labeled as "${param.label}"`
|
|
485
|
+
: `#${i}`} that is undefined. This might happen when Circular Dependency occurs. To handle Circular Dependencies please specify circular meta for param.`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
else if (param.type === undefined && param.circular) {
|
|
489
|
+
param.type = param.circular();
|
|
490
|
+
}
|
|
491
|
+
if (typeof param.type === 'function') {
|
|
492
|
+
if ([String, Number, Date, Array].includes(param.type)) {
|
|
493
|
+
if (!param.nullable && !param.optional) {
|
|
494
|
+
throw this.panicOwnError(`Could not inject "${param.type
|
|
495
|
+
.name}" to "${classConstructor.name}" ` +
|
|
496
|
+
`constructor at index ${i}${param.label
|
|
497
|
+
? ` (${param.label})`
|
|
498
|
+
: ''}. The param was not resolved to a value.`, hierarchy);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
resolvedParams[i] = this.get(param.type, {
|
|
502
|
+
provide: mergedProvide,
|
|
503
|
+
replace,
|
|
504
|
+
hierarchy,
|
|
505
|
+
syncContextFn,
|
|
506
|
+
customData: opts === null || opts === void 0 ? void 0 : opts.customData,
|
|
507
|
+
}, param.optional || param.nullable);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (resolvedParams[i] === UNDEFINED) {
|
|
511
|
+
resolvedParams[i] = undefined;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
for (let i = 0; i < resolvedParams.length; i++) {
|
|
515
|
+
const rp = resolvedParams[i];
|
|
516
|
+
if (rp && typeof rp.then === 'function') {
|
|
517
|
+
try {
|
|
518
|
+
syncContextFn && syncContextFn(classMeta);
|
|
519
|
+
resolvedParams[i] = await rp;
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
const param = params[i];
|
|
523
|
+
throw this.panic(e, `Could not inject "${param.type.name}" to "${classConstructor.name}" ` +
|
|
524
|
+
`constructor at index ${i}${param.label ? ` (${param.label})` : ''}. An exception occured.`, hierarchy);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const instance = new classConstructor(...resolvedParams);
|
|
529
|
+
if (isCircular) {
|
|
530
|
+
Object.assign(registry[instanceKey], instance);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
registry[instanceKey] = instance;
|
|
534
|
+
}
|
|
535
|
+
if (this.options.describeProp &&
|
|
536
|
+
this.options.resolveProp &&
|
|
537
|
+
classMeta.properties &&
|
|
538
|
+
classMeta.properties.length) {
|
|
539
|
+
const resolvedProps = {};
|
|
540
|
+
for (const prop of classMeta.properties) {
|
|
541
|
+
const initialValue = instance[prop];
|
|
542
|
+
let propMeta;
|
|
543
|
+
try {
|
|
544
|
+
propMeta = this.options.describeProp(classConstructor, prop);
|
|
545
|
+
}
|
|
546
|
+
catch (e) {
|
|
547
|
+
throw this.panic(e, `Could not process prop "${prop}" of "${classConstructor.name}". ` +
|
|
548
|
+
`An error occored on "describeProp" function.\n${e.message}`, hierarchy);
|
|
549
|
+
}
|
|
550
|
+
if (propMeta) {
|
|
551
|
+
try {
|
|
552
|
+
resolvedProps[prop] = this.options.resolveProp({
|
|
553
|
+
classMeta,
|
|
554
|
+
classConstructor,
|
|
555
|
+
initialValue,
|
|
556
|
+
key: prop,
|
|
557
|
+
instance,
|
|
558
|
+
propMeta,
|
|
559
|
+
customData: opts === null || opts === void 0 ? void 0 : opts.customData,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
catch (e) {
|
|
563
|
+
throw this.panic(e, `Could not inject prop "${prop}" to "${classConstructor.name}". ` +
|
|
564
|
+
'An exception occured: ' +
|
|
565
|
+
e.message, hierarchy);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
for (const [prop, value] of Object.entries(resolvedProps)) {
|
|
570
|
+
try {
|
|
571
|
+
syncContextFn && syncContextFn(classMeta);
|
|
572
|
+
resolvedProps[prop] = value
|
|
573
|
+
? await value
|
|
574
|
+
: value;
|
|
575
|
+
}
|
|
576
|
+
catch (e) {
|
|
577
|
+
throw this.panic(e, `Could not inject prop "${prop}" to "${classConstructor.name}". ` +
|
|
578
|
+
'An exception occured: ' +
|
|
579
|
+
e.message, hierarchy);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
Object.assign(instance, resolvedProps);
|
|
583
|
+
}
|
|
584
|
+
if (this._silent === false) {
|
|
585
|
+
this.logger.info(`Class "${'[1m' +
|
|
586
|
+
classConstructor.name +
|
|
587
|
+
'[22m' +
|
|
588
|
+
'[2m'}" instantiated with: ${'[34m'}[${resolvedParams
|
|
589
|
+
.map((p) => {
|
|
590
|
+
switch (typeof p) {
|
|
591
|
+
case 'number':
|
|
592
|
+
case 'boolean':
|
|
593
|
+
return p;
|
|
594
|
+
case 'string':
|
|
595
|
+
return `"${'[92m'}...${'[34m'}"`;
|
|
596
|
+
case 'object':
|
|
597
|
+
if (getConstructor$1(p))
|
|
598
|
+
return getConstructor$1(p).name;
|
|
599
|
+
return '{}';
|
|
600
|
+
default:
|
|
601
|
+
return '*';
|
|
602
|
+
}
|
|
603
|
+
})
|
|
604
|
+
.join(', ')}]`);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
hierarchy.pop();
|
|
608
|
+
syncContextFn && syncContextFn(classMeta);
|
|
609
|
+
return {
|
|
610
|
+
instance: await (scope[instanceKey] ||
|
|
611
|
+
this.registry[instanceKey] ||
|
|
612
|
+
globalRegistry[instanceKey]),
|
|
613
|
+
mergedProvide,
|
|
614
|
+
replace,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
panic(origError, text, hierarchy) {
|
|
618
|
+
if (this._silent === true) ;
|
|
619
|
+
else {
|
|
620
|
+
this.logger.error(text +
|
|
621
|
+
(hierarchy
|
|
622
|
+
? '\nHierarchy:\n' + hierarchy.join(' -> ')
|
|
623
|
+
: ''));
|
|
624
|
+
}
|
|
625
|
+
return origError;
|
|
626
|
+
}
|
|
627
|
+
panicOwnError(text, hierarchy) {
|
|
628
|
+
const e = new Error(text + (hierarchy ? '\nHierarchy:\n' + hierarchy.join(' -> ') : ''));
|
|
629
|
+
if (this._silent === true) {
|
|
630
|
+
return e;
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
this.logger.error(e);
|
|
634
|
+
return e;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function getProvidedValue(meta) {
|
|
639
|
+
if (!meta.resolved) {
|
|
640
|
+
meta.resolved = true;
|
|
641
|
+
meta.value = meta.fn();
|
|
642
|
+
}
|
|
643
|
+
return meta.value;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
async function runPipes(pipes, initialValue, metas, level) {
|
|
647
|
+
let v = initialValue;
|
|
648
|
+
for (const pipe of pipes) {
|
|
649
|
+
v = await pipe.handler(v, metas, level);
|
|
650
|
+
}
|
|
651
|
+
return v;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function getConstructor(instance) {
|
|
655
|
+
return isConstructor(instance) ?
|
|
656
|
+
instance : instance.constructor ?
|
|
657
|
+
instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
658
|
+
}
|
|
659
|
+
function isConstructor(v) {
|
|
660
|
+
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const classMetadata = new WeakMap();
|
|
664
|
+
const paramMetadata = new WeakMap();
|
|
665
|
+
const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
|
|
666
|
+
function getMetaObject(target, prop) {
|
|
667
|
+
const isParam = typeof prop !== 'undefined';
|
|
668
|
+
const metadata = isParam ? paramMetadata : classMetadata;
|
|
669
|
+
const targetKey = getConstructor(target);
|
|
670
|
+
let meta = metadata.get(targetKey);
|
|
671
|
+
if (!meta) {
|
|
672
|
+
meta = {};
|
|
673
|
+
metadata.set(targetKey, meta);
|
|
674
|
+
}
|
|
675
|
+
if (isParam) {
|
|
676
|
+
meta = (meta[prop] =
|
|
677
|
+
meta[prop] || {});
|
|
678
|
+
}
|
|
679
|
+
return meta;
|
|
680
|
+
}
|
|
681
|
+
const _reflect = {
|
|
682
|
+
getOwnMetadata(key, target, prop) {
|
|
683
|
+
return getMetaObject(target, prop)[key];
|
|
684
|
+
},
|
|
685
|
+
defineMetadata(key, data, target, prop) {
|
|
686
|
+
const meta = getMetaObject(target, prop);
|
|
687
|
+
meta[key] = data;
|
|
688
|
+
},
|
|
689
|
+
metadata(key, data) {
|
|
690
|
+
return ((target, propKey) => {
|
|
691
|
+
Reflect$1.defineMetadata(key, data, target, propKey);
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
};
|
|
695
|
+
if (!root.Reflect) {
|
|
696
|
+
root.Reflect = _reflect;
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
const funcs = [
|
|
700
|
+
'getOwnMetadata',
|
|
701
|
+
'defineMetadata',
|
|
702
|
+
'metadata',
|
|
703
|
+
];
|
|
704
|
+
const target = root.Reflect;
|
|
705
|
+
for (const func of funcs) {
|
|
706
|
+
if (typeof target[func] !== 'function') {
|
|
707
|
+
Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const Reflect$1 = _reflect;
|
|
712
|
+
|
|
713
|
+
const Reflect = (global === null || global === void 0 ? void 0 : global.Reflect) || (self === null || self === void 0 ? void 0 : self.Reflect) || Reflect$1;
|
|
714
|
+
class Mate {
|
|
715
|
+
constructor(workspace, options = {}) {
|
|
716
|
+
this.workspace = workspace;
|
|
717
|
+
this.options = options;
|
|
718
|
+
this.logger = options.logger || console;
|
|
719
|
+
}
|
|
720
|
+
set(args, key, value, isArray) {
|
|
721
|
+
var _a;
|
|
722
|
+
let level = 'CLASS';
|
|
723
|
+
const newArgs = args.level === 'CLASS' ? { target: args.target }
|
|
724
|
+
: args.level === 'PROP' ? { target: args.target, propKey: args.propKey }
|
|
725
|
+
: args;
|
|
726
|
+
let meta = (Reflect.getOwnMetadata(this.workspace, newArgs.target, newArgs.propKey) || {});
|
|
727
|
+
if (newArgs.propKey && this.options.readReturnType && !meta.returnType && args.descriptor) {
|
|
728
|
+
meta.returnType = Reflect.getOwnMetadata('design:returntype', newArgs.target, newArgs.propKey);
|
|
729
|
+
}
|
|
730
|
+
if (newArgs.propKey && this.options.readType && !meta.type) {
|
|
731
|
+
meta.type = Reflect.getOwnMetadata('design:type', newArgs.target, newArgs.propKey);
|
|
732
|
+
}
|
|
733
|
+
const { index } = newArgs;
|
|
734
|
+
const cb = typeof key === 'function' ? key : undefined;
|
|
735
|
+
let data = meta;
|
|
736
|
+
if (!data.params) {
|
|
737
|
+
data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
|
|
738
|
+
}
|
|
739
|
+
if (typeof index === 'number') {
|
|
740
|
+
level = 'PARAM';
|
|
741
|
+
data.params = data.params || [];
|
|
742
|
+
data.params[index] = data.params[index] || {
|
|
743
|
+
type: undefined,
|
|
744
|
+
};
|
|
745
|
+
if (cb) {
|
|
746
|
+
data.params[index] = cb(data.params[index], level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
data = data.params[index];
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
else if (!index && !args.descriptor && args.propKey && this.options.collectPropKeys && args.level !== 'CLASS') {
|
|
753
|
+
this.set({ ...args, level: 'CLASS' }, (meta) => {
|
|
754
|
+
if (!meta.properties) {
|
|
755
|
+
meta.properties = [args.propKey];
|
|
756
|
+
}
|
|
757
|
+
else if (!meta.properties.includes(args.propKey)) {
|
|
758
|
+
meta.properties.push(args.propKey);
|
|
759
|
+
}
|
|
760
|
+
return meta;
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
level = typeof index === 'number' ? 'PARAM' : newArgs.propKey && newArgs.descriptor ? 'METHOD' : newArgs.propKey ? 'PROP' : 'CLASS';
|
|
764
|
+
if (typeof key !== 'function') {
|
|
765
|
+
if (isArray) {
|
|
766
|
+
const newArray = (data[key] || []);
|
|
767
|
+
if (!Array.isArray(newArray)) {
|
|
768
|
+
this.logger.error('Mate.add (isArray=true) called for non-array metadata');
|
|
769
|
+
}
|
|
770
|
+
newArray.unshift(value);
|
|
771
|
+
data[key] = newArray;
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
data[key] = value;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
else if (cb && typeof index !== 'number') {
|
|
778
|
+
meta = cb(data, level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
|
|
779
|
+
}
|
|
780
|
+
Reflect.defineMetadata(this.workspace, meta, newArgs.target, newArgs.propKey);
|
|
781
|
+
}
|
|
782
|
+
read(target, propKey) {
|
|
783
|
+
var _a;
|
|
784
|
+
const isConstr = isConstructor(target);
|
|
785
|
+
const constructor = isConstr ? target : getConstructor(target);
|
|
786
|
+
const proto = constructor.prototype;
|
|
787
|
+
let ownMeta = Reflect.getOwnMetadata(this.workspace, typeof propKey === 'string' ? proto : constructor, propKey);
|
|
788
|
+
if (ownMeta && propKey === undefined && ownMeta.params === undefined) {
|
|
789
|
+
const parent = Object.getPrototypeOf(constructor);
|
|
790
|
+
if (typeof parent === 'function' &&
|
|
791
|
+
parent !== fnProto &&
|
|
792
|
+
parent !== constructor) {
|
|
793
|
+
ownMeta.params = (_a = this.read(parent)) === null || _a === void 0 ? void 0 : _a.params;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (this.options.inherit) {
|
|
797
|
+
const inheritFn = typeof this.options.inherit === 'function'
|
|
798
|
+
? this.options.inherit
|
|
799
|
+
: undefined;
|
|
800
|
+
let shouldInherit = this.options.inherit;
|
|
801
|
+
if (inheritFn) {
|
|
802
|
+
if (typeof propKey === 'string') {
|
|
803
|
+
const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
|
|
804
|
+
shouldInherit = inheritFn(classMeta, ownMeta, 'PROP', propKey);
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
shouldInherit = inheritFn(ownMeta, ownMeta, 'CLASS');
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (shouldInherit) {
|
|
811
|
+
const parent = Object.getPrototypeOf(constructor);
|
|
812
|
+
if (typeof parent === 'function' &&
|
|
813
|
+
parent !== fnProto &&
|
|
814
|
+
parent !== constructor) {
|
|
815
|
+
const inheritedMeta = (this.read(parent, propKey) ||
|
|
816
|
+
{});
|
|
817
|
+
const ownParams = ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params;
|
|
818
|
+
ownMeta = { ...inheritedMeta, ...ownMeta };
|
|
819
|
+
if (typeof propKey === 'string' &&
|
|
820
|
+
ownParams &&
|
|
821
|
+
(inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params)) {
|
|
822
|
+
for (let i = 0; i < ownParams.length; i++) {
|
|
823
|
+
if (typeof (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i]) !==
|
|
824
|
+
'undefined') {
|
|
825
|
+
const ownParam = ownParams[i];
|
|
826
|
+
if (ownMeta.params &&
|
|
827
|
+
inheritFn &&
|
|
828
|
+
inheritFn(ownMeta, ownParam, 'PARAM', typeof propKey === 'string'
|
|
829
|
+
? propKey
|
|
830
|
+
: undefined)) {
|
|
831
|
+
ownMeta.params[i] = {
|
|
832
|
+
...inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i],
|
|
833
|
+
...ownParams[i],
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return ownMeta;
|
|
843
|
+
}
|
|
844
|
+
apply(...decorators) {
|
|
845
|
+
return ((target, propKey, descriptor) => {
|
|
846
|
+
for (const d of decorators) {
|
|
847
|
+
d(target, propKey, descriptor);
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
decorate(key, value, isArray, level) {
|
|
852
|
+
return ((target, propKey, descriptor) => {
|
|
853
|
+
const args = {
|
|
854
|
+
target,
|
|
855
|
+
propKey,
|
|
856
|
+
descriptor: typeof descriptor === 'number' ? undefined : descriptor,
|
|
857
|
+
index: typeof descriptor === 'number' ? descriptor : undefined,
|
|
858
|
+
level,
|
|
859
|
+
};
|
|
860
|
+
this.set(args, key, value, isArray);
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
decorateConditional(ccb) {
|
|
864
|
+
return ((target, propKey, descriptor) => {
|
|
865
|
+
const hasIndex = typeof descriptor === 'number';
|
|
866
|
+
const decoratorLevel = hasIndex ? 'PARAM' : propKey && descriptor ? 'METHOD' : propKey ? 'PROP' : 'CLASS';
|
|
867
|
+
const d = ccb(decoratorLevel);
|
|
868
|
+
if (d) {
|
|
869
|
+
d(target, propKey, descriptor);
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
decorateClass(key, value, isArray) {
|
|
874
|
+
return this.decorate(key, value, isArray, 'CLASS');
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const fnProto = Object.getPrototypeOf(Function);
|
|
878
|
+
|
|
879
|
+
const METADATA_WORKSPACE = 'moost';
|
|
880
|
+
const moostMate = new Mate(METADATA_WORKSPACE, {
|
|
881
|
+
readType: true,
|
|
882
|
+
readReturnType: true,
|
|
883
|
+
collectPropKeys: true,
|
|
884
|
+
inherit(classMeta, targetMeta, level) {
|
|
885
|
+
if (level === 'CLASS') {
|
|
886
|
+
return !!classMeta?.inherit;
|
|
887
|
+
}
|
|
888
|
+
if (level === 'PROP') {
|
|
889
|
+
return !!targetMeta?.inherit || !!(classMeta?.inherit && !targetMeta);
|
|
890
|
+
}
|
|
891
|
+
return !!targetMeta?.inherit;
|
|
892
|
+
},
|
|
893
|
+
});
|
|
894
|
+
function getMoostMate() {
|
|
895
|
+
return moostMate;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
getNewMoostInfact();
|
|
899
|
+
function getNewMoostInfact() {
|
|
900
|
+
return new Infact({
|
|
901
|
+
describeClass(classConstructor) {
|
|
902
|
+
const meta = getMoostMate().read(classConstructor);
|
|
903
|
+
return {
|
|
904
|
+
injectable: !!meta?.injectable,
|
|
905
|
+
global: false,
|
|
906
|
+
constructorParams: meta?.params || [],
|
|
907
|
+
provide: meta?.provide,
|
|
908
|
+
properties: meta?.properties || [],
|
|
909
|
+
scopeId: meta?.injectable === 'FOR_EVENT' ? useEventId().getId() : undefined,
|
|
910
|
+
};
|
|
911
|
+
},
|
|
912
|
+
resolveParam({ paramMeta, classMeta, customData, classConstructor, index }) {
|
|
913
|
+
if (paramMeta && customData?.pipes) {
|
|
914
|
+
return runPipes(customData.pipes, undefined, {
|
|
915
|
+
paramMeta,
|
|
916
|
+
type: classConstructor,
|
|
917
|
+
key: 'constructor',
|
|
918
|
+
classMeta: classMeta,
|
|
919
|
+
index,
|
|
920
|
+
targetMeta: paramMeta,
|
|
921
|
+
}, 'PARAM');
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
describeProp(classConstructor, key) {
|
|
925
|
+
const meta = getMoostMate().read(classConstructor, key);
|
|
926
|
+
return meta;
|
|
927
|
+
},
|
|
928
|
+
resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
|
|
929
|
+
if (propMeta && customData?.pipes) {
|
|
930
|
+
return runPipes(customData.pipes, initialValue, {
|
|
931
|
+
instance,
|
|
932
|
+
type: classConstructor,
|
|
933
|
+
key,
|
|
934
|
+
propMeta,
|
|
935
|
+
targetMeta: propMeta,
|
|
936
|
+
classMeta: classMeta,
|
|
937
|
+
}, 'PROP');
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
storeProvideRegByInstance: true,
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
getMoostMate().decorate(meta => {
|
|
945
|
+
if (!meta.injectable) {
|
|
946
|
+
meta.injectable = true;
|
|
947
|
+
}
|
|
948
|
+
return meta;
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
var TInterceptorPriority;
|
|
952
|
+
(function (TInterceptorPriority) {
|
|
953
|
+
TInterceptorPriority[TInterceptorPriority["BEFORE_ALL"] = 0] = "BEFORE_ALL";
|
|
954
|
+
TInterceptorPriority[TInterceptorPriority["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
|
|
955
|
+
TInterceptorPriority[TInterceptorPriority["GUARD"] = 2] = "GUARD";
|
|
956
|
+
TInterceptorPriority[TInterceptorPriority["AFTER_GUARD"] = 3] = "AFTER_GUARD";
|
|
957
|
+
TInterceptorPriority[TInterceptorPriority["INTERCEPTOR"] = 4] = "INTERCEPTOR";
|
|
958
|
+
TInterceptorPriority[TInterceptorPriority["CATCH_ERROR"] = 5] = "CATCH_ERROR";
|
|
959
|
+
TInterceptorPriority[TInterceptorPriority["AFTER_ALL"] = 6] = "AFTER_ALL";
|
|
960
|
+
})(TInterceptorPriority || (TInterceptorPriority = {}));
|
|
961
|
+
|
|
962
|
+
var TPipePriority;
|
|
963
|
+
(function (TPipePriority) {
|
|
964
|
+
TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
|
|
965
|
+
TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
|
|
966
|
+
TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
|
|
967
|
+
TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
|
|
968
|
+
TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
|
|
969
|
+
TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
|
|
970
|
+
TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
|
|
971
|
+
TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
|
|
972
|
+
TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
973
|
+
})(TPipePriority || (TPipePriority = {}));
|
|
974
|
+
|
|
975
|
+
function definePipeFn(fn, priority = TPipePriority.TRANSFORM) {
|
|
976
|
+
fn.priority = priority;
|
|
977
|
+
return fn;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
const resolvePipe = definePipeFn((_value, metas, level) => {
|
|
981
|
+
const resolver = metas.targetMeta?.resolver;
|
|
982
|
+
if (resolver) {
|
|
983
|
+
return resolver(metas, level);
|
|
984
|
+
}
|
|
985
|
+
return undefined;
|
|
986
|
+
}, TPipePriority.RESOLVE);
|
|
987
|
+
|
|
988
|
+
[
|
|
989
|
+
{
|
|
990
|
+
handler: resolvePipe,
|
|
991
|
+
priority: TPipePriority.RESOLVE,
|
|
992
|
+
},
|
|
993
|
+
];
|
|
994
|
+
|
|
995
|
+
function getOtelMate() {
|
|
996
|
+
return getMoostMate();
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
const mate = getOtelMate();
|
|
1000
|
+
const OtelIgnoreSpan = () => mate.decorate('otelIgnoreSpan', true);
|
|
1001
|
+
|
|
1002
|
+
function shouldSpanBeIgnored(span) {
|
|
1003
|
+
return span.attributes['moost.ignore'] === true;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
class MoostBatchSpanProcessor extends sdkTraceBase.BatchSpanProcessor {
|
|
1007
|
+
onEnd(span) {
|
|
1008
|
+
if (shouldSpanBeIgnored(span)) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
super.onEnd(span);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
class MoostSimpleSpanProcessor extends sdkTraceBase.SimpleSpanProcessor {
|
|
1016
|
+
onEnd(span) {
|
|
1017
|
+
if (shouldSpanBeIgnored(span)) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
super.onEnd(span);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
exports.MoostBatchSpanProcessor = MoostBatchSpanProcessor;
|
|
1025
|
+
exports.MoostSimpleSpanProcessor = MoostSimpleSpanProcessor;
|
|
1026
|
+
exports.OtelIgnoreSpan = OtelIgnoreSpan;
|
|
110
1027
|
exports.enableOtelForMoost = enableOtelForMoost;
|
|
1028
|
+
exports.getOtelMate = getOtelMate;
|
|
1029
|
+
exports.shouldSpanBeIgnored = shouldSpanBeIgnored;
|
|
111
1030
|
exports.useOtelContext = useOtelContext;
|
|
112
1031
|
exports.useOtelPropagation = useOtelPropagation;
|
|
113
1032
|
exports.useSpan = useSpan;
|