moost 0.5.28 → 0.5.30
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 +360 -116
- package/dist/index.d.ts +363 -13
- package/dist/index.mjs +342 -100
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//#region rolldown:runtime
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
@@ -37,10 +36,18 @@ function setDefaultLogger(logger) {
|
|
|
37
36
|
function getDefaultLogger(topic) {
|
|
38
37
|
if (!defaultLogger) defaultLogger = new __prostojs_logger.ProstoLogger({
|
|
39
38
|
level: 4,
|
|
40
|
-
transports: [
|
|
39
|
+
transports: [loggerConsoleTransport]
|
|
41
40
|
});
|
|
42
41
|
return topic && defaultLogger instanceof __prostojs_logger.ProstoLogger ? defaultLogger.createTopic(topic) : defaultLogger;
|
|
43
42
|
}
|
|
43
|
+
function createLogger(opts) {
|
|
44
|
+
return new __prostojs_logger.ProstoLogger({
|
|
45
|
+
...opts,
|
|
46
|
+
level: opts?.level ?? 4,
|
|
47
|
+
transports: opts?.transports ?? [loggerConsoleTransport]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const loggerConsoleTransport = (0, __prostojs_logger.createConsoleTransort)({ format: __prostojs_logger.coloredConsole });
|
|
44
51
|
|
|
45
52
|
//#endregion
|
|
46
53
|
//#region packages/moost/src/pipes/run-pipes.ts
|
|
@@ -70,7 +77,7 @@ function getMoostMate() {
|
|
|
70
77
|
//#endregion
|
|
71
78
|
//#region packages/moost/src/metadata/infact.ts
|
|
72
79
|
const sharedMoostInfact = getNewMoostInfact();
|
|
73
|
-
const INFACT_BANNER =
|
|
80
|
+
const INFACT_BANNER = `[2m[35minfact`;
|
|
74
81
|
let loggingOptions = {
|
|
75
82
|
newInstance: "SINGLETON",
|
|
76
83
|
warn: true,
|
|
@@ -85,15 +92,27 @@ function setInfactLoggingOptions(options) {
|
|
|
85
92
|
function getMoostInfact() {
|
|
86
93
|
return sharedMoostInfact;
|
|
87
94
|
}
|
|
88
|
-
const scopeVarsMap = new Map();
|
|
89
|
-
|
|
95
|
+
const scopeVarsMap = /* @__PURE__ */ new Map();
|
|
96
|
+
/**
|
|
97
|
+
* Define global scope name to be used with `@InjectFromScope` and `@InjectScopeVars` decorators
|
|
98
|
+
*
|
|
99
|
+
* You can read scoped vars with `getInfactScopeVars`
|
|
100
|
+
* @param name scope name
|
|
101
|
+
* @param scopeVars key-value object as scoped vars
|
|
102
|
+
*/ function defineInfactScope(name, scopeVars) {
|
|
90
103
|
scopeVarsMap.set(name, scopeVars);
|
|
91
104
|
getMoostInfact().registerScope(name);
|
|
92
105
|
}
|
|
93
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Read scoped vars defined with `defineInfactScope`
|
|
108
|
+
* @param name scope name
|
|
109
|
+
* @returns key-value object as scoped vars
|
|
110
|
+
*/ function getInfactScopeVars(name) {
|
|
94
111
|
return scopeVarsMap.get(name);
|
|
95
112
|
}
|
|
96
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Get Infact instance (used for Dependency Injections)
|
|
115
|
+
*/ function getNewMoostInfact() {
|
|
97
116
|
return new __prostojs_infact.Infact({
|
|
98
117
|
describeClass(classConstructor) {
|
|
99
118
|
const meta = getMoostMate().read(classConstructor);
|
|
@@ -103,11 +122,11 @@ function getNewMoostInfact() {
|
|
|
103
122
|
constructorParams: meta?.params || [],
|
|
104
123
|
provide: meta?.provide,
|
|
105
124
|
properties: meta?.properties || [],
|
|
106
|
-
scopeId: meta?.injectable === "FOR_EVENT" ? (0, __wooksjs_event_core.useEventId)().getId() :
|
|
125
|
+
scopeId: meta?.injectable === "FOR_EVENT" ? (0, __wooksjs_event_core.useEventId)().getId() : void 0
|
|
107
126
|
};
|
|
108
127
|
},
|
|
109
128
|
resolveParam({ paramMeta, customData, classConstructor, index, scopeId }) {
|
|
110
|
-
if (paramMeta && customData?.pipes) return runPipes(customData.pipes,
|
|
129
|
+
if (paramMeta && customData?.pipes) return runPipes(customData.pipes, void 0, {
|
|
111
130
|
paramMeta,
|
|
112
131
|
type: classConstructor,
|
|
113
132
|
key: "constructor",
|
|
@@ -155,14 +174,14 @@ function getNewMoostInfact() {
|
|
|
155
174
|
} catch (error) {
|
|
156
175
|
logger = getDefaultLogger(INFACT_BANNER);
|
|
157
176
|
}
|
|
158
|
-
const instance =
|
|
177
|
+
const instance = `[4m${targetClass.name}[24m`;
|
|
159
178
|
switch (event) {
|
|
160
179
|
case "new-instance": {
|
|
161
180
|
const params = args?.map((a) => {
|
|
162
181
|
switch (typeof a) {
|
|
163
182
|
case "number":
|
|
164
|
-
case "boolean": return
|
|
165
|
-
case "string": return
|
|
183
|
+
case "boolean": return `[33m${a}[2m[34m`;
|
|
184
|
+
case "string": return `[92m"${a.slice(0, 1)}..."[2m[34m`;
|
|
166
185
|
case "object": {
|
|
167
186
|
if (Array.isArray(a)) return `[${a.length}]`;
|
|
168
187
|
if ((0, __prostojs_mate.getConstructor)(a)) return (0, __prostojs_mate.getConstructor)(a).name;
|
|
@@ -170,17 +189,17 @@ function getNewMoostInfact() {
|
|
|
170
189
|
}
|
|
171
190
|
default: return "*";
|
|
172
191
|
}
|
|
173
|
-
}).map((a) =>
|
|
174
|
-
logger.info(`new ${instance}
|
|
192
|
+
}).map((a) => `[2m[1m${a}[22m[2m`).join(", ") || "";
|
|
193
|
+
logger.info(`new ${instance}[2m[34m(${params})`);
|
|
175
194
|
break;
|
|
176
195
|
}
|
|
177
196
|
case "warn": {
|
|
178
|
-
const hier =
|
|
197
|
+
const hier = `[2m[34m⋱ ${args?.map(String).join(" → ") || ""}`;
|
|
179
198
|
logger.warn(`${instance} - ${message} ${hier}`);
|
|
180
199
|
break;
|
|
181
200
|
}
|
|
182
201
|
case "error": {
|
|
183
|
-
const hier =
|
|
202
|
+
const hier = `[2m[34m⋱ ${args?.map(String).join(" → ") || ""}`;
|
|
184
203
|
logger.error(`Failed to instantiate ${instance}. ${message} ${hier}`);
|
|
185
204
|
break;
|
|
186
205
|
}
|
|
@@ -257,7 +276,7 @@ function defineMoostEventHandler(options) {
|
|
|
257
276
|
const interceptorHandler = await options.getIterceptorHandler();
|
|
258
277
|
if (interceptorHandler?.count) try {
|
|
259
278
|
response = await ci.with("Interceptors:init", () => interceptorHandler.init());
|
|
260
|
-
if (response !==
|
|
279
|
+
if (response !== void 0) return await endWithResponse();
|
|
261
280
|
} catch (error) {
|
|
262
281
|
options.logErrors && logger.error(error);
|
|
263
282
|
response = error;
|
|
@@ -273,7 +292,7 @@ function defineMoostEventHandler(options) {
|
|
|
273
292
|
}
|
|
274
293
|
if (interceptorHandler?.countBefore) {
|
|
275
294
|
response = await ci.with("Interceptors:before", () => interceptorHandler.fireBefore(response));
|
|
276
|
-
if (response !==
|
|
295
|
+
if (response !== void 0) return endWithResponse();
|
|
277
296
|
}
|
|
278
297
|
const callControllerMethod = () => {
|
|
279
298
|
if (options.callControllerMethod) return options.callControllerMethod(args);
|
|
@@ -342,7 +361,7 @@ async function getCallableFn(targetInstance, fn, pipes, logger) {
|
|
|
342
361
|
return (...args) => instance.handler(...args);
|
|
343
362
|
}
|
|
344
363
|
if (typeof fn === "function") return fn;
|
|
345
|
-
const e = new Error(`getCallableFn failed for "${(0, __prostojs_mate.getConstructor)(targetInstance).name}" because the passed arg is not a Function nor TClassFunction`);
|
|
364
|
+
const e = /* @__PURE__ */ new Error(`getCallableFn failed for "${(0, __prostojs_mate.getConstructor)(targetInstance).name}" because the passed arg is not a Function nor TClassFunction`);
|
|
346
365
|
logger.error(e);
|
|
347
366
|
throw e;
|
|
348
367
|
}
|
|
@@ -395,7 +414,7 @@ var InterceptorHandler = class {
|
|
|
395
414
|
fn
|
|
396
415
|
});
|
|
397
416
|
}));
|
|
398
|
-
if (response !==
|
|
417
|
+
if (response !== void 0) return response;
|
|
399
418
|
}
|
|
400
419
|
}
|
|
401
420
|
async fireBefore(response) {
|
|
@@ -491,7 +510,7 @@ async function bindControllerMethods(options) {
|
|
|
491
510
|
});
|
|
492
511
|
const resolveArgs = async () => {
|
|
493
512
|
const args = [];
|
|
494
|
-
for (const [i, { pipes: pipes$1, meta: paramMeta }] of argsPipes.entries()) args[i] = await runPipes(pipes$1,
|
|
513
|
+
for (const [i, { pipes: pipes$1, meta: paramMeta }] of argsPipes.entries()) args[i] = await runPipes(pipes$1, void 0, {
|
|
495
514
|
classMeta: meta,
|
|
496
515
|
methodMeta,
|
|
497
516
|
paramMeta,
|
|
@@ -502,7 +521,7 @@ async function bindControllerMethods(options) {
|
|
|
502
521
|
}, "PARAM");
|
|
503
522
|
return args;
|
|
504
523
|
};
|
|
505
|
-
const wm = new WeakMap();
|
|
524
|
+
const wm = /* @__PURE__ */ new WeakMap();
|
|
506
525
|
controllerOverview.handlers.push(...methodMeta.handlers.map((h) => {
|
|
507
526
|
const data = {
|
|
508
527
|
meta: methodMeta,
|
|
@@ -546,22 +565,67 @@ function Circular(resolver) {
|
|
|
546
565
|
|
|
547
566
|
//#endregion
|
|
548
567
|
//#region packages/moost/src/decorators/common.decorator.ts
|
|
549
|
-
|
|
568
|
+
/**
|
|
569
|
+
* Apply Multiple Decorators
|
|
570
|
+
*
|
|
571
|
+
* @param decorators - array of decorators
|
|
572
|
+
* @returns
|
|
573
|
+
*/ function ApplyDecorators(...decorators) {
|
|
574
|
+
const mate$1 = getMoostMate();
|
|
575
|
+
return mate$1.apply(...decorators);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* ## Label
|
|
579
|
+
* ### @Decorator
|
|
580
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
581
|
+
*
|
|
582
|
+
* Stores Label metadata
|
|
583
|
+
*/ function Label(value) {
|
|
550
584
|
return getMoostMate().decorate("label", value);
|
|
551
585
|
}
|
|
552
|
-
|
|
586
|
+
/**
|
|
587
|
+
* ## Description
|
|
588
|
+
* ### @Decorator
|
|
589
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
590
|
+
*
|
|
591
|
+
* Stores Description metadata
|
|
592
|
+
*/ function Description(value) {
|
|
553
593
|
return getMoostMate().decorate("description", value);
|
|
554
594
|
}
|
|
555
|
-
|
|
595
|
+
/**
|
|
596
|
+
* ## Value
|
|
597
|
+
* ### @Decorator
|
|
598
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
599
|
+
*
|
|
600
|
+
* Stores Value metadata
|
|
601
|
+
*/ function Value(value) {
|
|
556
602
|
return getMoostMate().decorate("value", value);
|
|
557
603
|
}
|
|
558
|
-
|
|
604
|
+
/**
|
|
605
|
+
* ## Id
|
|
606
|
+
* ### @Decorator
|
|
607
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
608
|
+
*
|
|
609
|
+
* Stores Id metadata
|
|
610
|
+
*/ function Id(value) {
|
|
559
611
|
return getMoostMate().decorate("id", value);
|
|
560
612
|
}
|
|
561
|
-
|
|
613
|
+
/**
|
|
614
|
+
* ## Optional
|
|
615
|
+
* ### @Decorator
|
|
616
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
617
|
+
*
|
|
618
|
+
* Stores Optional metadata
|
|
619
|
+
*/ function Optional() {
|
|
562
620
|
return getMoostMate().decorate("optional", true);
|
|
563
621
|
}
|
|
564
|
-
|
|
622
|
+
/**
|
|
623
|
+
* ## Required
|
|
624
|
+
* ### @Decorator
|
|
625
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
626
|
+
*
|
|
627
|
+
* Stores Required metadata
|
|
628
|
+
*/ function Required() {
|
|
565
629
|
const mate$1 = getMoostMate();
|
|
566
630
|
return mate$1.apply(mate$1.decorate("required", true), mate$1.decorateClass((meta, level, key, index) => {
|
|
567
631
|
if (typeof index !== "number" && meta && ["string", "symbol"].includes(typeof key)) {
|
|
@@ -574,7 +638,15 @@ function Required() {
|
|
|
574
638
|
|
|
575
639
|
//#endregion
|
|
576
640
|
//#region packages/moost/src/decorators/injectable.decorator.ts
|
|
577
|
-
|
|
641
|
+
/**
|
|
642
|
+
* ## Injectable
|
|
643
|
+
* ### @Decorator
|
|
644
|
+
* Mark the Class as Injectable to enable it to be used in dependency injection
|
|
645
|
+
* @param scope - Scope for injection ("FOR_EVENT" | "SINGLETON" | true)
|
|
646
|
+
* FOR_EVENT - will create a new instance for each incoming request
|
|
647
|
+
* SINGLETON | true - will create a new instance only once
|
|
648
|
+
* @param label - field label
|
|
649
|
+
*/ function Injectable(scope = true) {
|
|
578
650
|
return getMoostMate().decorate("injectable", scope);
|
|
579
651
|
}
|
|
580
652
|
const insureInjectable = getMoostMate().decorate((meta) => {
|
|
@@ -584,25 +656,35 @@ const insureInjectable = getMoostMate().decorate((meta) => {
|
|
|
584
656
|
|
|
585
657
|
//#endregion
|
|
586
658
|
//#region packages/moost/src/decorators/controller.decorator.ts
|
|
587
|
-
|
|
659
|
+
/**
|
|
660
|
+
* ## Controller
|
|
661
|
+
* ### @Decorator
|
|
662
|
+
* Set Class as a Controller
|
|
663
|
+
* @param prefix - define the prefix for all the paths of this controller
|
|
664
|
+
*/ function Controller(prefix) {
|
|
588
665
|
const mate$1 = getMoostMate();
|
|
589
666
|
return mate$1.apply(insureInjectable, mate$1.decorate("controller", { prefix: prefix || "" }));
|
|
590
667
|
}
|
|
591
668
|
function ImportController(prefix, controller, provide) {
|
|
592
669
|
return getMoostMate().decorate("importController", {
|
|
593
|
-
prefix: typeof prefix === "string" ? prefix :
|
|
670
|
+
prefix: typeof prefix === "string" ? prefix : void 0,
|
|
594
671
|
typeResolver: typeof prefix === "string" ? controller : prefix,
|
|
595
|
-
provide: typeof prefix === "string" ? provide ||
|
|
672
|
+
provide: typeof prefix === "string" ? provide || void 0 : controller || void 0
|
|
596
673
|
}, true);
|
|
597
674
|
}
|
|
598
675
|
|
|
599
676
|
//#endregion
|
|
600
677
|
//#region packages/moost/src/decorators/inherit.decorator.ts
|
|
601
|
-
|
|
678
|
+
/**
|
|
679
|
+
* ## Inherit
|
|
680
|
+
* ### @Decorator
|
|
681
|
+
* Inherit metadata from super class
|
|
682
|
+
* @returns
|
|
683
|
+
*/ const Inherit = () => getMoostMate().decorate("inherit", true);
|
|
602
684
|
|
|
603
685
|
//#endregion
|
|
604
686
|
//#region packages/moost/src/decorators/intercept.decorator.ts
|
|
605
|
-
var TInterceptorPriority =
|
|
687
|
+
var TInterceptorPriority = /* @__PURE__ */ function(TInterceptorPriority$1) {
|
|
606
688
|
TInterceptorPriority$1[TInterceptorPriority$1["BEFORE_ALL"] = 0] = "BEFORE_ALL";
|
|
607
689
|
TInterceptorPriority$1[TInterceptorPriority$1["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
|
|
608
690
|
TInterceptorPriority$1[TInterceptorPriority$1["GUARD"] = 2] = "GUARD";
|
|
@@ -612,7 +694,14 @@ var TInterceptorPriority = /*#__PURE__*/ function(TInterceptorPriority$1) {
|
|
|
612
694
|
TInterceptorPriority$1[TInterceptorPriority$1["AFTER_ALL"] = 6] = "AFTER_ALL";
|
|
613
695
|
return TInterceptorPriority$1;
|
|
614
696
|
}({});
|
|
615
|
-
|
|
697
|
+
/**
|
|
698
|
+
* ## Intercept
|
|
699
|
+
* ### @Decorator
|
|
700
|
+
* Set interceptor
|
|
701
|
+
* @param handler interceptor fn (use defineInterceptorFn)
|
|
702
|
+
* @param priority interceptor priority
|
|
703
|
+
* @returns
|
|
704
|
+
*/ function Intercept(handler, priority, name) {
|
|
616
705
|
return getMoostMate().decorate("interceptors", {
|
|
617
706
|
handler,
|
|
618
707
|
priority: priority || handler.priority || 4,
|
|
@@ -622,9 +711,15 @@ function Intercept(handler, priority, name) {
|
|
|
622
711
|
|
|
623
712
|
//#endregion
|
|
624
713
|
//#region packages/moost/src/decorators/resolve.decorator.ts
|
|
625
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Hook to the Response Status
|
|
716
|
+
* @decorator
|
|
717
|
+
* @param resolver - resolver function
|
|
718
|
+
* @param label - field label
|
|
719
|
+
* @paramType unknown
|
|
720
|
+
*/ function Resolve(resolver, label) {
|
|
626
721
|
return (target, key, index) => {
|
|
627
|
-
const i = typeof index === "number" ? index :
|
|
722
|
+
const i = typeof index === "number" ? index : void 0;
|
|
628
723
|
getMoostMate().decorate("resolver", (metas, level) => {
|
|
629
724
|
let newLabel = label;
|
|
630
725
|
if (!newLabel && level === "PROP" && typeof metas.key === "string") newLabel = metas.key;
|
|
@@ -633,16 +728,37 @@ function Resolve(resolver, label) {
|
|
|
633
728
|
})(target, key, i);
|
|
634
729
|
};
|
|
635
730
|
}
|
|
636
|
-
|
|
731
|
+
/**
|
|
732
|
+
* Get Param Value from url parh
|
|
733
|
+
* @decorator
|
|
734
|
+
* @param name - param name
|
|
735
|
+
* @paramType string
|
|
736
|
+
*/ function Param(name) {
|
|
637
737
|
return getMoostMate().apply(getMoostMate().decorate("paramSource", "ROUTE"), getMoostMate().decorate("paramName", name), Resolve(() => (0, __wooksjs_event_core.useRouteParams)().get(name), name));
|
|
638
738
|
}
|
|
639
|
-
|
|
739
|
+
/**
|
|
740
|
+
* Get Parsed Params from url parh
|
|
741
|
+
* @decorator
|
|
742
|
+
* @paramType object
|
|
743
|
+
*/ function Params() {
|
|
640
744
|
return Resolve(() => (0, __wooksjs_event_core.useRouteParams)().params, "params");
|
|
641
745
|
}
|
|
642
|
-
|
|
746
|
+
/**
|
|
747
|
+
* Provide Const Value
|
|
748
|
+
* @decorator
|
|
749
|
+
* @param value - provided value
|
|
750
|
+
* @param label - label of the field
|
|
751
|
+
* @paramType unknown
|
|
752
|
+
*/ function Const(value, label) {
|
|
643
753
|
return Resolve(() => value, label);
|
|
644
754
|
}
|
|
645
|
-
|
|
755
|
+
/**
|
|
756
|
+
* Provide Const Value from Factory fn
|
|
757
|
+
* @decorator
|
|
758
|
+
* @param factory - value Factory fn
|
|
759
|
+
* @param label - label of the field
|
|
760
|
+
* @paramType unknown
|
|
761
|
+
*/ function ConstFactory(factory, label) {
|
|
646
762
|
return Resolve(async () => factory(), label);
|
|
647
763
|
}
|
|
648
764
|
function fillLabel(target, key, index, name) {
|
|
@@ -656,10 +772,18 @@ function fillLabel(target, key, index, name) {
|
|
|
656
772
|
|
|
657
773
|
//#endregion
|
|
658
774
|
//#region packages/moost/src/decorators/logger.decorator.ts
|
|
659
|
-
|
|
775
|
+
/**
|
|
776
|
+
* Resolves event logger from event context
|
|
777
|
+
* @param topic
|
|
778
|
+
* @returns Resolver to '@wooksjs/event-core' (EventLogger)
|
|
779
|
+
*/ function InjectEventLogger(topic) {
|
|
660
780
|
return Resolve(() => (0, __wooksjs_event_core.useEventLogger)(topic));
|
|
661
781
|
}
|
|
662
|
-
|
|
782
|
+
/**
|
|
783
|
+
* Resolves app-level logger
|
|
784
|
+
* @param topic - logger topic (can be overrided by @LoggerTopic)
|
|
785
|
+
* @returns
|
|
786
|
+
*/ function InjectMoostLogger(topic) {
|
|
663
787
|
return Resolve(async (metas) => {
|
|
664
788
|
const { instantiate, getController } = useControllerContext();
|
|
665
789
|
const controller = getController();
|
|
@@ -668,13 +792,17 @@ function InjectMoostLogger(topic) {
|
|
|
668
792
|
return moostApp.getLogger(meta?.loggerTopic || topic || meta?.id);
|
|
669
793
|
});
|
|
670
794
|
}
|
|
671
|
-
|
|
795
|
+
/**
|
|
796
|
+
* Sets logger topic (used in @InjectMoostLogger)
|
|
797
|
+
* @param topic - logger topic (banner)
|
|
798
|
+
* @returns
|
|
799
|
+
*/ function LoggerTopic(topic) {
|
|
672
800
|
return getMoostMate().decorate("loggerTopic", topic);
|
|
673
801
|
}
|
|
674
802
|
|
|
675
803
|
//#endregion
|
|
676
804
|
//#region packages/moost/src/pipes/types.ts
|
|
677
|
-
var TPipePriority =
|
|
805
|
+
var TPipePriority = /* @__PURE__ */ function(TPipePriority$1) {
|
|
678
806
|
TPipePriority$1[TPipePriority$1["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
|
|
679
807
|
TPipePriority$1[TPipePriority$1["RESOLVE"] = 1] = "RESOLVE";
|
|
680
808
|
TPipePriority$1[TPipePriority$1["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
|
|
@@ -689,7 +817,14 @@ var TPipePriority = /*#__PURE__*/ function(TPipePriority$1) {
|
|
|
689
817
|
|
|
690
818
|
//#endregion
|
|
691
819
|
//#region packages/moost/src/decorators/pipe.decorator.ts
|
|
692
|
-
|
|
820
|
+
/**
|
|
821
|
+
* ## Pipe
|
|
822
|
+
* ### @Decorator
|
|
823
|
+
* Attach pipe
|
|
824
|
+
* @param handler pipe handler
|
|
825
|
+
* @param priority pipe priority
|
|
826
|
+
* @returns
|
|
827
|
+
*/ function Pipe(handler, priority) {
|
|
693
828
|
if (typeof priority !== "number") priority = typeof handler.priority === "number" ? handler.priority : TPipePriority.TRANSFORM;
|
|
694
829
|
return getMoostMate().decorate("pipes", {
|
|
695
830
|
handler,
|
|
@@ -699,40 +834,104 @@ function Pipe(handler, priority) {
|
|
|
699
834
|
|
|
700
835
|
//#endregion
|
|
701
836
|
//#region packages/moost/src/decorators/provide.decorator.ts
|
|
702
|
-
|
|
837
|
+
/**
|
|
838
|
+
* ## Provide
|
|
839
|
+
* ### @Decorator
|
|
840
|
+
* Defines provide registry for class (and all the children)
|
|
841
|
+
* @param type - string or class constructor
|
|
842
|
+
* @param fn - factory function for provided value
|
|
843
|
+
*/ function Provide(type, fn) {
|
|
703
844
|
return getMoostMate().decorate((meta) => {
|
|
704
845
|
meta.provide = meta.provide || {};
|
|
705
846
|
Object.assign(meta.provide, (0, __prostojs_infact.createProvideRegistry)([type, fn]));
|
|
706
847
|
return meta;
|
|
707
848
|
});
|
|
708
849
|
}
|
|
709
|
-
|
|
850
|
+
/**
|
|
851
|
+
* ## Replace
|
|
852
|
+
* ### @Decorator
|
|
853
|
+
* Defines class to replace in DI
|
|
854
|
+
* @param type - class to replace
|
|
855
|
+
* @param newType - new class
|
|
856
|
+
*/ function Replace(type, newType) {
|
|
710
857
|
return getMoostMate().decorate((meta) => {
|
|
711
858
|
meta.replace = meta.replace || {};
|
|
712
859
|
Object.assign(meta.replace, (0, __prostojs_infact.createReplaceRegistry)([type, newType]));
|
|
713
860
|
return meta;
|
|
714
861
|
});
|
|
715
862
|
}
|
|
716
|
-
|
|
863
|
+
/**
|
|
864
|
+
* ## Inject
|
|
865
|
+
* ### @Decorator
|
|
866
|
+
* Defines a key from provide registry to inject value
|
|
867
|
+
* (For optional values use with @Optional())
|
|
868
|
+
* @param type - string or class constructor
|
|
869
|
+
*/ function Inject(type) {
|
|
717
870
|
return getMoostMate().decorate("inject", type);
|
|
718
871
|
}
|
|
719
|
-
|
|
872
|
+
/**
|
|
873
|
+
* Injects instance from scope
|
|
874
|
+
*
|
|
875
|
+
* (scope must be defined by `defineInfactScope` fn)
|
|
876
|
+
* @param name scope name
|
|
877
|
+
*/ function InjectFromScope(name) {
|
|
720
878
|
return getMoostMate().decorate("fromScope", name);
|
|
721
879
|
}
|
|
722
|
-
|
|
880
|
+
/**
|
|
881
|
+
* Inject vars from scope for instances
|
|
882
|
+
* instantiated with `@InjectFromScope` decorator
|
|
883
|
+
*/ function InjectScopeVars(name) {
|
|
723
884
|
return Resolve(({ scopeId }) => {
|
|
724
885
|
if (scopeId) return name ? getInfactScopeVars(scopeId)?.[name] : getInfactScopeVars(scopeId);
|
|
725
|
-
return
|
|
886
|
+
return void 0;
|
|
726
887
|
});
|
|
727
888
|
}
|
|
728
889
|
|
|
729
890
|
//#endregion
|
|
730
891
|
//#region packages/moost/src/define.ts
|
|
731
|
-
|
|
892
|
+
/**
|
|
893
|
+
* ### Define Interceptor Function
|
|
894
|
+
*
|
|
895
|
+
* ```ts
|
|
896
|
+
* defineInterceptorFn((before, after, onError) => {
|
|
897
|
+
* //init
|
|
898
|
+
* before(() => {
|
|
899
|
+
* // before handler
|
|
900
|
+
* })
|
|
901
|
+
* after((response, reply) => {
|
|
902
|
+
* // after handler
|
|
903
|
+
* })
|
|
904
|
+
* onError((error, reply) => {
|
|
905
|
+
* // when error occured
|
|
906
|
+
* })
|
|
907
|
+
* },
|
|
908
|
+
* TInterceptorPriority.INTERCEPTOR,
|
|
909
|
+
* )
|
|
910
|
+
* ```
|
|
911
|
+
*
|
|
912
|
+
* @param fn interceptor function
|
|
913
|
+
* @param priority priority of the interceptor where BEFORE_ALL = 0, BEFORE_GUARD = 1, GUARD = 2, AFTER_GUARD = 3, INTERCEPTOR = 4, CATCH_ERROR = 5, AFTER_ALL = 6
|
|
914
|
+
* @returns
|
|
915
|
+
*/ function defineInterceptorFn(fn, priority = TInterceptorPriority.INTERCEPTOR) {
|
|
732
916
|
fn.priority = priority;
|
|
733
917
|
return fn;
|
|
734
918
|
}
|
|
735
|
-
|
|
919
|
+
/**
|
|
920
|
+
* ### Define Pipe Function
|
|
921
|
+
*
|
|
922
|
+
* ```ts
|
|
923
|
+
* // example of a transform pipe
|
|
924
|
+
* const uppercaseTransformPipe = definePipeFn((value, metas, level) => {
|
|
925
|
+
* return typeof value === 'string' ? value.toUpperCase() : value
|
|
926
|
+
* },
|
|
927
|
+
* TPipePriority.TRANSFORM,
|
|
928
|
+
* )
|
|
929
|
+
* ```
|
|
930
|
+
*
|
|
931
|
+
* @param fn interceptor function
|
|
932
|
+
* @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
|
|
933
|
+
* @returns
|
|
934
|
+
*/ function definePipeFn(fn, priority = TPipePriority.TRANSFORM) {
|
|
736
935
|
fn.priority = priority;
|
|
737
936
|
return fn;
|
|
738
937
|
}
|
|
@@ -742,7 +941,7 @@ function definePipeFn(fn, priority = TPipePriority.TRANSFORM) {
|
|
|
742
941
|
const resolvePipe = definePipeFn((_value, metas, level) => {
|
|
743
942
|
const resolver = metas.targetMeta?.resolver;
|
|
744
943
|
if (resolver) return resolver(metas, level);
|
|
745
|
-
return
|
|
944
|
+
return void 0;
|
|
746
945
|
}, TPipePriority.RESOLVE);
|
|
747
946
|
|
|
748
947
|
//#endregion
|
|
@@ -764,7 +963,56 @@ function _define_property(obj, key, value) {
|
|
|
764
963
|
else obj[key] = value;
|
|
765
964
|
return obj;
|
|
766
965
|
}
|
|
767
|
-
|
|
966
|
+
/**
|
|
967
|
+
* ## Moost
|
|
968
|
+
* Main moostjs class that serves as a shell for Moost Adapters
|
|
969
|
+
*
|
|
970
|
+
* ### Usage with HTTP Adapter
|
|
971
|
+
* ```ts
|
|
972
|
+
* │ // HTTP server example
|
|
973
|
+
* │ import { MoostHttp, Get } from '@moostjs/event-http'
|
|
974
|
+
* │ import { Moost, Param } from 'moost'
|
|
975
|
+
* │
|
|
976
|
+
* │ class MyServer extends Moost {
|
|
977
|
+
* │ @Get('test/:name')
|
|
978
|
+
* │ test(@Param('name') name: string) {
|
|
979
|
+
* │ return { message: `Hello ${name}!` }
|
|
980
|
+
* │ }
|
|
981
|
+
* │ }
|
|
982
|
+
* │
|
|
983
|
+
* │ const app = new MyServer()
|
|
984
|
+
* │ const http = new MoostHttp()
|
|
985
|
+
* │ app.adapter(http).listen(3000, () => {
|
|
986
|
+
* │ app.getLogger('MyApp').log('Up on port 3000')
|
|
987
|
+
* │ })
|
|
988
|
+
* │ app.init()
|
|
989
|
+
* ```
|
|
990
|
+
* ### Usage with CLI Adapter
|
|
991
|
+
* ```ts
|
|
992
|
+
* │ // CLI example
|
|
993
|
+
* │ import { MoostCli, Cli, CliOption, cliHelpInterceptor } from '@moostjs/event-cli'
|
|
994
|
+
* │ import { Moost, Param } from 'moost'
|
|
995
|
+
* │
|
|
996
|
+
* │ class MyApp extends Moost {
|
|
997
|
+
* │ @Cli('command/:arg')
|
|
998
|
+
* │ command(
|
|
999
|
+
* │ @Param('arg')
|
|
1000
|
+
* │ arg: string,
|
|
1001
|
+
* │ @CliOption('test', 't')
|
|
1002
|
+
* │ test: boolean,
|
|
1003
|
+
* │ ) {
|
|
1004
|
+
* │ return `command run with flag arg=${ arg }, test=${ test }`
|
|
1005
|
+
* │ }
|
|
1006
|
+
* │ }
|
|
1007
|
+
* │
|
|
1008
|
+
* │ const app = new MyApp()
|
|
1009
|
+
* │ app.applyGlobalInterceptors(cliHelpInterceptor())
|
|
1010
|
+
* │
|
|
1011
|
+
* │ const cli = new MoostCli()
|
|
1012
|
+
* │ app.adapter(cli)
|
|
1013
|
+
* │ app.init()
|
|
1014
|
+
* ```
|
|
1015
|
+
*/ var Moost = class Moost extends hookable.Hookable {
|
|
768
1016
|
_fireEventStart(source) {
|
|
769
1017
|
this.callHook("event-start", source);
|
|
770
1018
|
}
|
|
@@ -879,17 +1127,10 @@ var Moost = class Moost extends hookable.Hookable {
|
|
|
879
1127
|
for (const ic of classMeta.importController) if (ic.typeResolver) {
|
|
880
1128
|
const isConstr = (0, __prostojs_mate.isConstructor)(ic.typeResolver);
|
|
881
1129
|
const isFunc = typeof ic.typeResolver === "function";
|
|
882
|
-
await this.bindController(
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
...mergedProvide,
|
|
887
|
-
...ic.provide
|
|
888
|
-
} : mergedProvide,
|
|
889
|
-
mergedReplace,
|
|
890
|
-
`${globalPrefix}/${prefix || ""}`,
|
|
891
|
-
ic.prefix
|
|
892
|
-
);
|
|
1130
|
+
await this.bindController(isConstr ? ic.typeResolver : isFunc ? await ic.typeResolver() : ic.typeResolver, ic.provide ? {
|
|
1131
|
+
...mergedProvide,
|
|
1132
|
+
...ic.provide
|
|
1133
|
+
} : mergedProvide, mergedReplace, `${globalPrefix}/${prefix || ""}`, ic.prefix);
|
|
893
1134
|
}
|
|
894
1135
|
}
|
|
895
1136
|
}
|
|
@@ -902,7 +1143,7 @@ var Moost = class Moost extends hookable.Hookable {
|
|
|
902
1143
|
handler: item.handler,
|
|
903
1144
|
priority: item.priority
|
|
904
1145
|
});
|
|
905
|
-
this.globalInterceptorHandler =
|
|
1146
|
+
this.globalInterceptorHandler = void 0;
|
|
906
1147
|
return this;
|
|
907
1148
|
}
|
|
908
1149
|
/**
|
|
@@ -931,7 +1172,7 @@ var Moost = class Moost extends hookable.Hookable {
|
|
|
931
1172
|
priority: item.priority,
|
|
932
1173
|
name: item.name || item.handler._name || item.handler.name || "<anonymous>"
|
|
933
1174
|
});
|
|
934
|
-
this.globalInterceptorHandler =
|
|
1175
|
+
this.globalInterceptorHandler = void 0;
|
|
935
1176
|
return this;
|
|
936
1177
|
}
|
|
937
1178
|
/**
|
|
@@ -967,11 +1208,11 @@ var Moost = class Moost extends hookable.Hookable {
|
|
|
967
1208
|
logMappedHandler(eventName, classConstructor, method, stroke, prefix) {
|
|
968
1209
|
const c = stroke ? "\x1B[9m" : "";
|
|
969
1210
|
const coff = stroke ? "\x1B[29m" : "";
|
|
970
|
-
this.logger.info(`${prefix || ""}${c}${eventName} ${"\x1B[0m\x1B[2m\x1B[32m" + c}→ ${classConstructor.name}.${"\x1B[36m" + c}${method}
|
|
1211
|
+
this.logger.info(`${prefix || ""}${c}${eventName} ${"\x1B[0m\x1B[2m\x1B[32m" + c}→ ${classConstructor.name}.${"\x1B[36m" + c}${method}[32m()${coff}`);
|
|
971
1212
|
}
|
|
972
1213
|
constructor(options) {
|
|
973
1214
|
super(), _define_property(this, "options", void 0), _define_property(this, "logger", void 0), _define_property(this, "pipes", void 0), _define_property(this, "interceptors", void 0), _define_property(this, "adapters", void 0), _define_property(this, "controllersOverview", void 0), _define_property(this, "provide", void 0), _define_property(this, "replace", void 0), _define_property(this, "unregisteredControllers", void 0), _define_property(this, "globalInterceptorHandler", void 0), this.options = options, this.pipes = Array.from(sharedPipes), this.interceptors = [], this.adapters = [], this.controllersOverview = [], this.provide = (0, __prostojs_infact.createProvideRegistry)([__prostojs_infact.Infact, getMoostInfact], [__prostojs_mate.Mate, getMoostMate]), this.replace = {}, this.unregisteredControllers = [];
|
|
974
|
-
this.logger = options?.logger || getDefaultLogger(
|
|
1215
|
+
this.logger = options?.logger || getDefaultLogger(`[2m[35mmoost`);
|
|
975
1216
|
setDefaultLogger(this.logger);
|
|
976
1217
|
const mate$1 = getMoostMate();
|
|
977
1218
|
Object.assign(mate$1, { logger: this.getLogger("mate") });
|
|
@@ -979,60 +1220,62 @@ var Moost = class Moost extends hookable.Hookable {
|
|
|
979
1220
|
};
|
|
980
1221
|
|
|
981
1222
|
//#endregion
|
|
982
|
-
exports.
|
|
983
|
-
exports.
|
|
984
|
-
exports.
|
|
1223
|
+
exports.ApplyDecorators = ApplyDecorators;
|
|
1224
|
+
exports.Circular = Circular;
|
|
1225
|
+
exports.Const = Const;
|
|
1226
|
+
exports.ConstFactory = ConstFactory;
|
|
985
1227
|
Object.defineProperty(exports, 'ContextInjector', {
|
|
986
1228
|
enumerable: true,
|
|
987
1229
|
get: function () {
|
|
988
1230
|
return __wooksjs_event_core.ContextInjector;
|
|
989
1231
|
}
|
|
990
1232
|
});
|
|
991
|
-
exports.Controller = Controller
|
|
992
|
-
exports.Description = Description
|
|
1233
|
+
exports.Controller = Controller;
|
|
1234
|
+
exports.Description = Description;
|
|
993
1235
|
Object.defineProperty(exports, 'EventLogger', {
|
|
994
1236
|
enumerable: true,
|
|
995
1237
|
get: function () {
|
|
996
1238
|
return __wooksjs_event_core.EventLogger;
|
|
997
1239
|
}
|
|
998
1240
|
});
|
|
999
|
-
exports.Id = Id
|
|
1000
|
-
exports.ImportController = ImportController
|
|
1001
|
-
exports.Inherit = Inherit
|
|
1002
|
-
exports.Inject = Inject
|
|
1003
|
-
exports.InjectEventLogger = InjectEventLogger
|
|
1004
|
-
exports.InjectFromScope = InjectFromScope
|
|
1005
|
-
exports.InjectMoostLogger = InjectMoostLogger
|
|
1006
|
-
exports.InjectScopeVars = InjectScopeVars
|
|
1007
|
-
exports.Injectable = Injectable
|
|
1008
|
-
exports.Intercept = Intercept
|
|
1009
|
-
exports.InterceptorHandler = InterceptorHandler
|
|
1010
|
-
exports.Label = Label
|
|
1011
|
-
exports.LoggerTopic = LoggerTopic
|
|
1012
|
-
exports.Moost = Moost
|
|
1013
|
-
exports.Optional = Optional
|
|
1014
|
-
exports.Param = Param
|
|
1015
|
-
exports.Params = Params
|
|
1016
|
-
exports.Pipe = Pipe
|
|
1241
|
+
exports.Id = Id;
|
|
1242
|
+
exports.ImportController = ImportController;
|
|
1243
|
+
exports.Inherit = Inherit;
|
|
1244
|
+
exports.Inject = Inject;
|
|
1245
|
+
exports.InjectEventLogger = InjectEventLogger;
|
|
1246
|
+
exports.InjectFromScope = InjectFromScope;
|
|
1247
|
+
exports.InjectMoostLogger = InjectMoostLogger;
|
|
1248
|
+
exports.InjectScopeVars = InjectScopeVars;
|
|
1249
|
+
exports.Injectable = Injectable;
|
|
1250
|
+
exports.Intercept = Intercept;
|
|
1251
|
+
exports.InterceptorHandler = InterceptorHandler;
|
|
1252
|
+
exports.Label = Label;
|
|
1253
|
+
exports.LoggerTopic = LoggerTopic;
|
|
1254
|
+
exports.Moost = Moost;
|
|
1255
|
+
exports.Optional = Optional;
|
|
1256
|
+
exports.Param = Param;
|
|
1257
|
+
exports.Params = Params;
|
|
1258
|
+
exports.Pipe = Pipe;
|
|
1017
1259
|
Object.defineProperty(exports, 'ProstoLogger', {
|
|
1018
1260
|
enumerable: true,
|
|
1019
1261
|
get: function () {
|
|
1020
1262
|
return __prostojs_logger.ProstoLogger;
|
|
1021
1263
|
}
|
|
1022
1264
|
});
|
|
1023
|
-
exports.Provide = Provide
|
|
1024
|
-
exports.Replace = Replace
|
|
1025
|
-
exports.Required = Required
|
|
1026
|
-
exports.Resolve = Resolve
|
|
1027
|
-
exports.TInterceptorPriority = TInterceptorPriority
|
|
1028
|
-
exports.TPipePriority = TPipePriority
|
|
1029
|
-
exports.Value = Value
|
|
1265
|
+
exports.Provide = Provide;
|
|
1266
|
+
exports.Replace = Replace;
|
|
1267
|
+
exports.Required = Required;
|
|
1268
|
+
exports.Resolve = Resolve;
|
|
1269
|
+
exports.TInterceptorPriority = TInterceptorPriority;
|
|
1270
|
+
exports.TPipePriority = TPipePriority;
|
|
1271
|
+
exports.Value = Value;
|
|
1030
1272
|
Object.defineProperty(exports, 'clearGlobalWooks', {
|
|
1031
1273
|
enumerable: true,
|
|
1032
1274
|
get: function () {
|
|
1033
1275
|
return wooks.clearGlobalWooks;
|
|
1034
1276
|
}
|
|
1035
1277
|
});
|
|
1278
|
+
exports.createLogger = createLogger;
|
|
1036
1279
|
Object.defineProperty(exports, 'createProvideRegistry', {
|
|
1037
1280
|
enumerable: true,
|
|
1038
1281
|
get: function () {
|
|
@@ -1045,10 +1288,10 @@ Object.defineProperty(exports, 'createReplaceRegistry', {
|
|
|
1045
1288
|
return __prostojs_infact.createReplaceRegistry;
|
|
1046
1289
|
}
|
|
1047
1290
|
});
|
|
1048
|
-
exports.defineInfactScope = defineInfactScope
|
|
1049
|
-
exports.defineInterceptorFn = defineInterceptorFn
|
|
1050
|
-
exports.defineMoostEventHandler = defineMoostEventHandler
|
|
1051
|
-
exports.definePipeFn = definePipeFn
|
|
1291
|
+
exports.defineInfactScope = defineInfactScope;
|
|
1292
|
+
exports.defineInterceptorFn = defineInterceptorFn;
|
|
1293
|
+
exports.defineMoostEventHandler = defineMoostEventHandler;
|
|
1294
|
+
exports.definePipeFn = definePipeFn;
|
|
1052
1295
|
Object.defineProperty(exports, 'getConstructor', {
|
|
1053
1296
|
enumerable: true,
|
|
1054
1297
|
get: function () {
|
|
@@ -1067,35 +1310,36 @@ Object.defineProperty(exports, 'getGlobalWooks', {
|
|
|
1067
1310
|
return wooks.getGlobalWooks;
|
|
1068
1311
|
}
|
|
1069
1312
|
});
|
|
1070
|
-
exports.getInfactScopeVars = getInfactScopeVars
|
|
1071
|
-
exports.getInstanceOwnMethods = getInstanceOwnMethods
|
|
1072
|
-
exports.getInstanceOwnProps = getInstanceOwnProps
|
|
1073
|
-
exports.getMoostInfact = getMoostInfact
|
|
1074
|
-
exports.getMoostMate = getMoostMate
|
|
1075
|
-
exports.getNewMoostInfact = getNewMoostInfact
|
|
1313
|
+
exports.getInfactScopeVars = getInfactScopeVars;
|
|
1314
|
+
exports.getInstanceOwnMethods = getInstanceOwnMethods;
|
|
1315
|
+
exports.getInstanceOwnProps = getInstanceOwnProps;
|
|
1316
|
+
exports.getMoostInfact = getMoostInfact;
|
|
1317
|
+
exports.getMoostMate = getMoostMate;
|
|
1318
|
+
exports.getNewMoostInfact = getNewMoostInfact;
|
|
1076
1319
|
Object.defineProperty(exports, 'isConstructor', {
|
|
1077
1320
|
enumerable: true,
|
|
1078
1321
|
get: function () {
|
|
1079
1322
|
return __prostojs_mate.isConstructor;
|
|
1080
1323
|
}
|
|
1081
1324
|
});
|
|
1082
|
-
exports.
|
|
1325
|
+
exports.loggerConsoleTransport = loggerConsoleTransport;
|
|
1326
|
+
exports.registerEventScope = registerEventScope;
|
|
1083
1327
|
Object.defineProperty(exports, 'replaceContextInjector', {
|
|
1084
1328
|
enumerable: true,
|
|
1085
1329
|
get: function () {
|
|
1086
1330
|
return __wooksjs_event_core.replaceContextInjector;
|
|
1087
1331
|
}
|
|
1088
1332
|
});
|
|
1089
|
-
exports.resolvePipe = resolvePipe
|
|
1090
|
-
exports.setControllerContext = setControllerContext
|
|
1091
|
-
exports.setInfactLoggingOptions = setInfactLoggingOptions
|
|
1333
|
+
exports.resolvePipe = resolvePipe;
|
|
1334
|
+
exports.setControllerContext = setControllerContext;
|
|
1335
|
+
exports.setInfactLoggingOptions = setInfactLoggingOptions;
|
|
1092
1336
|
Object.defineProperty(exports, 'useAsyncEventContext', {
|
|
1093
1337
|
enumerable: true,
|
|
1094
1338
|
get: function () {
|
|
1095
1339
|
return __wooksjs_event_core.useAsyncEventContext;
|
|
1096
1340
|
}
|
|
1097
1341
|
});
|
|
1098
|
-
exports.useControllerContext = useControllerContext
|
|
1342
|
+
exports.useControllerContext = useControllerContext;
|
|
1099
1343
|
Object.defineProperty(exports, 'useEventLogger', {
|
|
1100
1344
|
enumerable: true,
|
|
1101
1345
|
get: function () {
|