moost 0.5.21 → 0.5.22
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/LICENSE +21 -0
- package/dist/index.cjs +946 -928
- package/dist/index.d.ts +12 -350
- package/dist/index.mjs +824 -860
- package/package.json +19 -8
package/dist/index.mjs
CHANGED
|
@@ -1,994 +1,958 @@
|
|
|
1
|
-
import { Mate, getConstructor, isConstructor } from
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { ProstoLogger, createConsoleTransort, coloredConsole } from '@prostojs/logger';
|
|
8
|
-
export { ProstoLogger } from '@prostojs/logger';
|
|
9
|
-
import { Hookable } from 'hookable';
|
|
10
|
-
export { clearGlobalWooks, getGlobalWooks } from 'wooks';
|
|
1
|
+
import { Mate, getConstructor, isConstructor } from "@prostojs/mate";
|
|
2
|
+
import { ContextInjector, EventLogger, createAsyncEventContext, getContextInjector, replaceContextInjector, useAsyncEventContext, useEventId, useEventLogger, useRouteParams } from "@wooksjs/event-core";
|
|
3
|
+
import { Infact, createProvideRegistry, createReplaceRegistry } from "@prostojs/infact";
|
|
4
|
+
import { ProstoLogger, coloredConsole, createConsoleTransort } from "@prostojs/logger";
|
|
5
|
+
import { Hookable } from "hookable";
|
|
6
|
+
import { clearGlobalWooks, getGlobalWooks } from "wooks";
|
|
11
7
|
|
|
8
|
+
//#region packages/moost/src/logger.ts
|
|
12
9
|
let defaultLogger;
|
|
13
10
|
function setDefaultLogger(logger) {
|
|
14
|
-
|
|
11
|
+
defaultLogger = logger;
|
|
15
12
|
}
|
|
16
13
|
function getDefaultLogger(topic) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
format: coloredConsole,
|
|
23
|
-
}),
|
|
24
|
-
],
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return topic && defaultLogger instanceof ProstoLogger
|
|
28
|
-
? defaultLogger.createTopic(topic)
|
|
29
|
-
: defaultLogger;
|
|
14
|
+
if (!defaultLogger) defaultLogger = new ProstoLogger({
|
|
15
|
+
level: 4,
|
|
16
|
+
transports: [createConsoleTransort({ format: coloredConsole })]
|
|
17
|
+
});
|
|
18
|
+
return topic && defaultLogger instanceof ProstoLogger ? defaultLogger.createTopic(topic) : defaultLogger;
|
|
30
19
|
}
|
|
31
20
|
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region packages/moost/src/pipes/run-pipes.ts
|
|
32
23
|
async function runPipes(pipes, initialValue, metas, level) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return v;
|
|
24
|
+
let v = initialValue;
|
|
25
|
+
for (const pipe of pipes) v = await pipe.handler(v, metas, level);
|
|
26
|
+
return v;
|
|
38
27
|
}
|
|
39
28
|
|
|
40
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region packages/moost/src/metadata/moost-metadata.ts
|
|
31
|
+
const METADATA_WORKSPACE = "moost";
|
|
41
32
|
const moostMate = new Mate(METADATA_WORKSPACE, {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return !!targetMeta?.inherit || !!(classMeta?.inherit && !targetMeta);
|
|
51
|
-
}
|
|
52
|
-
return !!targetMeta?.inherit;
|
|
53
|
-
},
|
|
33
|
+
readType: true,
|
|
34
|
+
readReturnType: true,
|
|
35
|
+
collectPropKeys: true,
|
|
36
|
+
inherit(classMeta, targetMeta, level) {
|
|
37
|
+
if (level === "CLASS") return !!classMeta?.inherit;
|
|
38
|
+
if (level === "PROP") return !!targetMeta?.inherit || !!(classMeta?.inherit && !targetMeta);
|
|
39
|
+
return !!targetMeta?.inherit;
|
|
40
|
+
}
|
|
54
41
|
});
|
|
55
42
|
function getMoostMate() {
|
|
56
|
-
|
|
43
|
+
return moostMate;
|
|
57
44
|
}
|
|
58
45
|
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region packages/moost/src/metadata/infact.ts
|
|
59
48
|
const sharedMoostInfact = getNewMoostInfact();
|
|
60
|
-
const INFACT_BANNER = `${
|
|
49
|
+
const INFACT_BANNER = `${"\x1B[2m\x1B[35m"}infact`;
|
|
61
50
|
let loggingOptions = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
newInstance: "SINGLETON",
|
|
52
|
+
warn: true,
|
|
53
|
+
error: true
|
|
65
54
|
};
|
|
66
55
|
function setInfactLoggingOptions(options) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
loggingOptions = {
|
|
57
|
+
...loggingOptions,
|
|
58
|
+
...options
|
|
59
|
+
};
|
|
71
60
|
}
|
|
72
61
|
function getMoostInfact() {
|
|
73
|
-
|
|
62
|
+
return sharedMoostInfact;
|
|
74
63
|
}
|
|
75
64
|
const scopeVarsMap = new Map();
|
|
76
65
|
function defineInfactScope(name, scopeVars) {
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
scopeVarsMap.set(name, scopeVars);
|
|
67
|
+
getMoostInfact().registerScope(name);
|
|
79
68
|
}
|
|
80
69
|
function getInfactScopeVars(name) {
|
|
81
|
-
|
|
70
|
+
return scopeVarsMap.get(name);
|
|
82
71
|
}
|
|
83
72
|
function getNewMoostInfact() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return '{}';
|
|
179
|
-
}
|
|
180
|
-
default: {
|
|
181
|
-
return '*';
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
.map(a => `${'[2m' + '[1m'}${a}${'[22m' + '[2m'}`)
|
|
186
|
-
.join(', ') || '';
|
|
187
|
-
logger.info(`new ${instance}${'[2m' + '[34m'}(${params})`);
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
case 'warn': {
|
|
191
|
-
const hier = `${'[2m' + '[34m'}⋱ ${args?.map(String).join(' → ') || ''}`;
|
|
192
|
-
logger.warn(`${instance} - ${message} ${hier}`);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
case 'error': {
|
|
196
|
-
const hier = `${'[2m' + '[34m'}⋱ ${args?.map(String).join(' → ') || ''}`;
|
|
197
|
-
logger.error(`Failed to instantiate ${instance}. ${message} ${hier}`);
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
});
|
|
73
|
+
return new Infact({
|
|
74
|
+
describeClass(classConstructor) {
|
|
75
|
+
const meta = getMoostMate().read(classConstructor);
|
|
76
|
+
return {
|
|
77
|
+
injectable: !!meta?.injectable,
|
|
78
|
+
global: false,
|
|
79
|
+
constructorParams: meta?.params || [],
|
|
80
|
+
provide: meta?.provide,
|
|
81
|
+
properties: meta?.properties || [],
|
|
82
|
+
scopeId: meta?.injectable === "FOR_EVENT" ? useEventId().getId() : undefined
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
resolveParam({ paramMeta, customData, classConstructor, index, scopeId }) {
|
|
86
|
+
if (paramMeta && customData?.pipes) return runPipes(customData.pipes, undefined, {
|
|
87
|
+
paramMeta,
|
|
88
|
+
type: classConstructor,
|
|
89
|
+
key: "constructor",
|
|
90
|
+
scopeId,
|
|
91
|
+
classMeta: getMoostMate().read(classConstructor),
|
|
92
|
+
index,
|
|
93
|
+
targetMeta: paramMeta
|
|
94
|
+
}, "PARAM");
|
|
95
|
+
},
|
|
96
|
+
describeProp(classConstructor, key) {
|
|
97
|
+
const meta = getMoostMate().read(classConstructor, key);
|
|
98
|
+
return meta;
|
|
99
|
+
},
|
|
100
|
+
resolveProp({ instance, key, initialValue, propMeta, scopeId, classMeta, customData, classConstructor }) {
|
|
101
|
+
if (propMeta && customData?.pipes) return runPipes(customData.pipes, initialValue, {
|
|
102
|
+
instance,
|
|
103
|
+
type: classConstructor,
|
|
104
|
+
key,
|
|
105
|
+
scopeId,
|
|
106
|
+
propMeta,
|
|
107
|
+
targetMeta: propMeta,
|
|
108
|
+
classMeta
|
|
109
|
+
}, "PROP");
|
|
110
|
+
},
|
|
111
|
+
storeProvideRegByInstance: true,
|
|
112
|
+
on: (event, targetClass, message, args) => {
|
|
113
|
+
switch (event) {
|
|
114
|
+
case "new-instance": {
|
|
115
|
+
const scope = getMoostMate().read(targetClass)?.injectable || "SINGLETON";
|
|
116
|
+
if (loggingOptions.newInstance === false || !(loggingOptions.newInstance === scope || loggingOptions.newInstance === "SINGLETON" && scope === true)) return;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case "warn": {
|
|
120
|
+
if (!loggingOptions.warn) return;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case "error": {
|
|
124
|
+
if (!loggingOptions.error) return;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
let logger;
|
|
129
|
+
try {
|
|
130
|
+
logger = event === "error" ? getDefaultLogger(INFACT_BANNER) : useEventLogger(INFACT_BANNER);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
logger = getDefaultLogger(INFACT_BANNER);
|
|
133
|
+
}
|
|
134
|
+
const instance = `${"\x1B[4m"}${targetClass.name}${"\x1B[24m"}`;
|
|
135
|
+
switch (event) {
|
|
136
|
+
case "new-instance": {
|
|
137
|
+
const params = args?.map((a) => {
|
|
138
|
+
switch (typeof a) {
|
|
139
|
+
case "number":
|
|
140
|
+
case "boolean": return `${"\x1B[33m"}${a}${"\x1B[2m\x1B[34m"}`;
|
|
141
|
+
case "string": return `${"\x1B[92m"}"${a.slice(0, 1)}..."${"\x1B[2m\x1B[34m"}`;
|
|
142
|
+
case "object": {
|
|
143
|
+
if (Array.isArray(a)) return `[${a.length}]`;
|
|
144
|
+
if (getConstructor(a)) return getConstructor(a).name;
|
|
145
|
+
return "{}";
|
|
146
|
+
}
|
|
147
|
+
default: return "*";
|
|
148
|
+
}
|
|
149
|
+
}).map((a) => `${"\x1B[2m\x1B[1m"}${a}${"\x1B[22m\x1B[2m"}`).join(", ") || "";
|
|
150
|
+
logger.info(`new ${instance}${"\x1B[2m\x1B[34m"}(${params})`);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "warn": {
|
|
154
|
+
const hier = `${"\x1B[2m\x1B[34m"}⋱ ${args?.map(String).join(" → ") || ""}`;
|
|
155
|
+
logger.warn(`${instance} - ${message} ${hier}`);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case "error": {
|
|
159
|
+
const hier = `${"\x1B[2m\x1B[34m"}⋱ ${args?.map(String).join(" → ") || ""}`;
|
|
160
|
+
logger.error(`Failed to instantiate ${instance}. ${message} ${hier}`);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
default: break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
203
167
|
}
|
|
204
168
|
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region packages/moost/src/composables/controller.composable.ts
|
|
205
171
|
function setControllerContext(controller, method, route) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
172
|
+
const { store } = useAsyncEventContext();
|
|
173
|
+
const { set } = store("controller");
|
|
174
|
+
set("instance", controller);
|
|
175
|
+
set("method", method);
|
|
176
|
+
set("route", route);
|
|
211
177
|
}
|
|
212
178
|
function useControllerContext() {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
179
|
+
const { store } = useAsyncEventContext();
|
|
180
|
+
const { get } = store("controller");
|
|
181
|
+
const getController = () => get("instance");
|
|
182
|
+
const getMethod = () => get("method");
|
|
183
|
+
const getRoute = () => get("route");
|
|
184
|
+
const getControllerMeta = () => getMoostMate().read(getController());
|
|
185
|
+
const getMethodMeta = (name) => getMoostMate().read(getController(), name || getMethod());
|
|
186
|
+
function instantiate(c) {
|
|
187
|
+
return getMoostInfact().getForInstance(getController(), c);
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
instantiate,
|
|
191
|
+
getRoute,
|
|
192
|
+
getController,
|
|
193
|
+
getMethod,
|
|
194
|
+
getControllerMeta,
|
|
195
|
+
getMethodMeta,
|
|
196
|
+
getPropertiesList: () => getControllerMeta()?.properties || [],
|
|
197
|
+
getScope: () => getControllerMeta()?.injectable || "SINGLETON",
|
|
198
|
+
getParamsMeta: () => getMethodMeta()?.params || [],
|
|
199
|
+
getPropMeta: (name) => getMethodMeta(name)
|
|
200
|
+
};
|
|
235
201
|
}
|
|
236
202
|
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region packages/moost/src/adapter-utils.ts
|
|
237
205
|
const infact = getMoostInfact();
|
|
238
206
|
function registerEventScope(scopeId) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
207
|
+
infact.registerScope(scopeId);
|
|
208
|
+
return () => {
|
|
209
|
+
infact.unregisterScope(scopeId);
|
|
210
|
+
};
|
|
243
211
|
}
|
|
244
212
|
function defineMoostEventHandler(options) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
options.logErrors && logger.error(error);
|
|
316
|
-
response = error;
|
|
317
|
-
return endWithResponse(true);
|
|
318
|
-
}
|
|
319
|
-
async function endWithResponse(raise = false) {
|
|
320
|
-
if (interceptorHandler?.countAfter || interceptorHandler?.countOnError) {
|
|
321
|
-
try {
|
|
322
|
-
response = await ci.with('Interceptors:after', () => interceptorHandler.fireAfter(response));
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
options.logErrors && logger.error(error);
|
|
326
|
-
if (!options.manualUnscope) {
|
|
327
|
-
unscope();
|
|
328
|
-
}
|
|
329
|
-
throw error;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (!options.manualUnscope) {
|
|
333
|
-
unscope();
|
|
334
|
-
}
|
|
335
|
-
if (options.hooks?.end) {
|
|
336
|
-
await options.hooks.end(hookOptions);
|
|
337
|
-
}
|
|
338
|
-
if (raise) {
|
|
339
|
-
throw response;
|
|
340
|
-
}
|
|
341
|
-
return response;
|
|
342
|
-
}
|
|
343
|
-
return endWithResponse();
|
|
344
|
-
};
|
|
213
|
+
const ci = getContextInjector();
|
|
214
|
+
return async () => {
|
|
215
|
+
const scopeId = useEventId().getId();
|
|
216
|
+
const logger = useEventLogger(options.loggerTitle);
|
|
217
|
+
const unscope = registerEventScope(scopeId);
|
|
218
|
+
let response;
|
|
219
|
+
const hookOptions = {
|
|
220
|
+
scopeId,
|
|
221
|
+
logger,
|
|
222
|
+
unscope,
|
|
223
|
+
method: options.controllerMethod,
|
|
224
|
+
getResponse: () => response,
|
|
225
|
+
reply: (r) => response = r
|
|
226
|
+
};
|
|
227
|
+
if (options.hooks?.init) await options.hooks.init(hookOptions);
|
|
228
|
+
const instance = await options.getControllerInstance();
|
|
229
|
+
if (instance) {
|
|
230
|
+
setControllerContext(instance, options.controllerMethod || "", options.targetPath);
|
|
231
|
+
ci.hook(options.handlerType, "Controller:registered");
|
|
232
|
+
}
|
|
233
|
+
const interceptorHandler = await options.getIterceptorHandler();
|
|
234
|
+
if (interceptorHandler?.count) try {
|
|
235
|
+
response = await ci.with("Interceptors:init", () => interceptorHandler.init());
|
|
236
|
+
if (response !== undefined) return await endWithResponse();
|
|
237
|
+
} catch (error) {
|
|
238
|
+
options.logErrors && logger.error(error);
|
|
239
|
+
response = error;
|
|
240
|
+
return endWithResponse(true);
|
|
241
|
+
}
|
|
242
|
+
let args = [];
|
|
243
|
+
if (options.resolveArgs) try {
|
|
244
|
+
args = await ci.with("Arguments:resolve", () => options.resolveArgs());
|
|
245
|
+
} catch (error) {
|
|
246
|
+
options.logErrors && logger.error(error);
|
|
247
|
+
response = error;
|
|
248
|
+
return endWithResponse(true);
|
|
249
|
+
}
|
|
250
|
+
if (interceptorHandler?.countBefore) {
|
|
251
|
+
response = await ci.with("Interceptors:before", () => interceptorHandler.fireBefore(response));
|
|
252
|
+
if (response !== undefined) return endWithResponse();
|
|
253
|
+
}
|
|
254
|
+
const callControllerMethod = () => {
|
|
255
|
+
if (options.callControllerMethod) return options.callControllerMethod(args);
|
|
256
|
+
else if (instance && options.controllerMethod && typeof instance[options.controllerMethod] === "function") return instance[options.controllerMethod](...args);
|
|
257
|
+
};
|
|
258
|
+
try {
|
|
259
|
+
response = await ci.with(`Handler:${options.targetPath}`, {
|
|
260
|
+
"moost.handler": options.controllerMethod || "",
|
|
261
|
+
"moost.controller": getConstructor(instance).name
|
|
262
|
+
}, () => callControllerMethod());
|
|
263
|
+
} catch (error) {
|
|
264
|
+
options.logErrors && logger.error(error);
|
|
265
|
+
response = error;
|
|
266
|
+
return endWithResponse(true);
|
|
267
|
+
}
|
|
268
|
+
async function endWithResponse(raise = false) {
|
|
269
|
+
if (interceptorHandler?.countAfter || interceptorHandler?.countOnError) try {
|
|
270
|
+
response = await ci.with("Interceptors:after", () => interceptorHandler.fireAfter(response));
|
|
271
|
+
} catch (error) {
|
|
272
|
+
options.logErrors && logger.error(error);
|
|
273
|
+
if (!options.manualUnscope) unscope();
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
if (!options.manualUnscope) unscope();
|
|
277
|
+
if (options.hooks?.end) await options.hooks.end(hookOptions);
|
|
278
|
+
if (raise) throw response;
|
|
279
|
+
return response;
|
|
280
|
+
}
|
|
281
|
+
return endWithResponse();
|
|
282
|
+
};
|
|
345
283
|
}
|
|
346
284
|
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region packages/moost/src/binding/utils.ts
|
|
347
287
|
function getInstanceOwnMethods(instance) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
288
|
+
const proto = Object.getPrototypeOf(instance);
|
|
289
|
+
return [
|
|
290
|
+
...getParentProps(getConstructor(instance)),
|
|
291
|
+
...Object.getOwnPropertyNames(proto),
|
|
292
|
+
...Object.getOwnPropertyNames(instance)
|
|
293
|
+
].filter((m) => typeof instance[m] === "function");
|
|
354
294
|
}
|
|
355
295
|
function getInstanceOwnProps(instance) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
296
|
+
const proto = Object.getPrototypeOf(instance);
|
|
297
|
+
return [
|
|
298
|
+
...getParentProps(getConstructor(instance)),
|
|
299
|
+
...Object.getOwnPropertyNames(proto),
|
|
300
|
+
...Object.getOwnPropertyNames(instance)
|
|
301
|
+
].filter((m) => typeof instance[m] !== "function");
|
|
362
302
|
}
|
|
363
303
|
const fnProto = Object.getPrototypeOf(Function);
|
|
364
304
|
function getParentProps(constructor) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
parent !== constructor &&
|
|
369
|
-
parent.prototype) {
|
|
370
|
-
return [...getParentProps(parent), ...Object.getOwnPropertyNames(parent.prototype)];
|
|
371
|
-
}
|
|
372
|
-
return [];
|
|
305
|
+
const parent = Object.getPrototypeOf(constructor);
|
|
306
|
+
if (typeof parent === "function" && parent !== fnProto && parent !== constructor && parent.prototype) return [...getParentProps(parent), ...Object.getOwnPropertyNames(parent.prototype)];
|
|
307
|
+
return [];
|
|
373
308
|
}
|
|
374
309
|
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region packages/moost/src/class-function/class-function.ts
|
|
375
312
|
async function getCallableFn(targetInstance, fn, pipes, logger) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (typeof fn === 'function') {
|
|
388
|
-
return fn;
|
|
389
|
-
}
|
|
390
|
-
const e = new Error(`getCallableFn failed for "${getConstructor(targetInstance).name}" because the passed arg is not a Function nor TClassFunction`);
|
|
391
|
-
logger.error(e);
|
|
392
|
-
throw e;
|
|
313
|
+
const mate$1 = getMoostMate();
|
|
314
|
+
const meta = mate$1.read(fn);
|
|
315
|
+
if (meta?.injectable) {
|
|
316
|
+
const infact$1 = getMoostInfact();
|
|
317
|
+
const instance = await infact$1.getForInstance(targetInstance, fn, { customData: { pipes: [...pipes || [], ...meta.pipes || []].sort((a, b) => a.priority - b.priority) } });
|
|
318
|
+
return (...args) => instance.handler(...args);
|
|
319
|
+
}
|
|
320
|
+
if (typeof fn === "function") return fn;
|
|
321
|
+
const e = new Error(`getCallableFn failed for "${getConstructor(targetInstance).name}" because the passed arg is not a Function nor TClassFunction`);
|
|
322
|
+
logger.error(e);
|
|
323
|
+
throw e;
|
|
393
324
|
}
|
|
394
325
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region packages/moost/src/interceptor-handler.ts
|
|
328
|
+
function _define_property$1(obj, key, value) {
|
|
329
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
330
|
+
value,
|
|
331
|
+
enumerable: true,
|
|
332
|
+
configurable: true,
|
|
333
|
+
writable: true
|
|
334
|
+
});
|
|
335
|
+
else obj[key] = value;
|
|
336
|
+
return obj;
|
|
337
|
+
}
|
|
338
|
+
var InterceptorHandler = class {
|
|
339
|
+
get count() {
|
|
340
|
+
return this.handlers.length;
|
|
341
|
+
}
|
|
342
|
+
get countBefore() {
|
|
343
|
+
return this.before.length;
|
|
344
|
+
}
|
|
345
|
+
get countAfter() {
|
|
346
|
+
return this.after.length;
|
|
347
|
+
}
|
|
348
|
+
get countOnError() {
|
|
349
|
+
return this.onError.length;
|
|
350
|
+
}
|
|
351
|
+
replyFn(reply) {
|
|
352
|
+
this.response = reply;
|
|
353
|
+
this.responseOverwritten = true;
|
|
354
|
+
}
|
|
355
|
+
async init() {
|
|
356
|
+
const ci = getContextInjector();
|
|
357
|
+
for (const { handler, name } of this.handlers) {
|
|
358
|
+
const response = await ci.with(`Interceptor:${name}`, { "moost.interceptor.stage": "init" }, () => handler((fn) => {
|
|
359
|
+
this.before.push({
|
|
360
|
+
name,
|
|
361
|
+
fn
|
|
362
|
+
});
|
|
363
|
+
}, (fn) => {
|
|
364
|
+
this.after.unshift({
|
|
365
|
+
name,
|
|
366
|
+
fn
|
|
367
|
+
});
|
|
368
|
+
}, (fn) => {
|
|
369
|
+
this.onError.unshift({
|
|
370
|
+
name,
|
|
371
|
+
fn
|
|
372
|
+
});
|
|
373
|
+
}));
|
|
374
|
+
if (response !== undefined) return response;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async fireBefore(response) {
|
|
378
|
+
const ci = getContextInjector();
|
|
379
|
+
this.response = response;
|
|
380
|
+
for (const { name, fn } of this.before) {
|
|
381
|
+
await ci.with(`Interceptor:${name}`, { "moost.interceptor.stage": "before" }, () => fn(this.replyFn.bind(this)));
|
|
382
|
+
if (this.responseOverwritten) break;
|
|
383
|
+
}
|
|
384
|
+
return this.response;
|
|
385
|
+
}
|
|
386
|
+
async fireAfter(response) {
|
|
387
|
+
const ci = getContextInjector();
|
|
388
|
+
this.response = response;
|
|
389
|
+
if (response instanceof Error) for (const { name, fn } of this.onError) await ci.with(`Interceptor:${name}`, { "moost.interceptor.stage": "after" }, () => fn(response, this.replyFn.bind(this)));
|
|
390
|
+
else for (const { name, fn } of this.after) await ci.with(`Interceptor:${name}`, { "moost.interceptor.stage": "onError" }, () => fn(response, this.replyFn.bind(this)));
|
|
391
|
+
return this.response;
|
|
392
|
+
}
|
|
393
|
+
constructor(handlers) {
|
|
394
|
+
_define_property$1(this, "handlers", void 0);
|
|
395
|
+
_define_property$1(this, "before", void 0);
|
|
396
|
+
_define_property$1(this, "after", void 0);
|
|
397
|
+
_define_property$1(this, "onError", void 0);
|
|
398
|
+
_define_property$1(this, "response", void 0);
|
|
399
|
+
_define_property$1(this, "responseOverwritten", void 0);
|
|
400
|
+
this.handlers = handlers;
|
|
401
|
+
this.before = [];
|
|
402
|
+
this.after = [];
|
|
403
|
+
this.onError = [];
|
|
404
|
+
this.responseOverwritten = false;
|
|
405
|
+
}
|
|
406
|
+
};
|
|
469
407
|
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region packages/moost/src/utils.ts
|
|
470
410
|
const mate = getMoostMate();
|
|
471
411
|
function getIterceptorHandlerFactory(interceptors, getTargetInstance, pipes, logger) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
};
|
|
412
|
+
return () => {
|
|
413
|
+
const interceptorHandlers = [];
|
|
414
|
+
for (const { handler, name } of interceptors) {
|
|
415
|
+
const interceptorMeta = mate.read(handler);
|
|
416
|
+
if (interceptorMeta?.injectable) interceptorHandlers.push({
|
|
417
|
+
handler: async (...args) => {
|
|
418
|
+
const targetInstance = await getTargetInstance();
|
|
419
|
+
return (await getCallableFn(targetInstance, handler, pipes, logger))(...args);
|
|
420
|
+
},
|
|
421
|
+
name
|
|
422
|
+
});
|
|
423
|
+
else interceptorHandlers.push({
|
|
424
|
+
handler,
|
|
425
|
+
name
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return Promise.resolve(new InterceptorHandler(interceptorHandlers));
|
|
429
|
+
};
|
|
491
430
|
}
|
|
492
431
|
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region packages/moost/src/binding/bind-controller.ts
|
|
493
434
|
async function bindControllerMethods(options) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const data = wm.get(h);
|
|
575
|
-
if (data) {
|
|
576
|
-
data.registeredAs.push({
|
|
577
|
-
path,
|
|
578
|
-
args,
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
return controllerOverview;
|
|
435
|
+
const opts = options || {};
|
|
436
|
+
const { getInstance } = opts;
|
|
437
|
+
const { classConstructor } = opts;
|
|
438
|
+
const { adapters } = opts;
|
|
439
|
+
opts.globalPrefix = opts.globalPrefix || "";
|
|
440
|
+
opts.provide = opts.provide || {};
|
|
441
|
+
const fakeInstance = Object.create(classConstructor.prototype);
|
|
442
|
+
const methods = getInstanceOwnMethods(fakeInstance);
|
|
443
|
+
const mate$1 = getMoostMate();
|
|
444
|
+
const meta = mate$1.read(classConstructor) || {};
|
|
445
|
+
const ownPrefix = typeof opts.replaceOwnPrefix === "string" ? opts.replaceOwnPrefix : meta.controller?.prefix || "";
|
|
446
|
+
const prefix = `${opts.globalPrefix}/${ownPrefix}`;
|
|
447
|
+
const controllerOverview = {
|
|
448
|
+
meta,
|
|
449
|
+
computedPrefix: prefix,
|
|
450
|
+
type: classConstructor,
|
|
451
|
+
handlers: []
|
|
452
|
+
};
|
|
453
|
+
for (const method of methods) {
|
|
454
|
+
const methodMeta = getMoostMate().read(fakeInstance, method) || {};
|
|
455
|
+
if (!methodMeta.handlers?.length) continue;
|
|
456
|
+
const pipes = [...opts.pipes || [], ...methodMeta.pipes || []].sort((a, b) => a.priority - b.priority);
|
|
457
|
+
const interceptors = [
|
|
458
|
+
...opts.interceptors || [],
|
|
459
|
+
...meta.interceptors || [],
|
|
460
|
+
...methodMeta.interceptors || []
|
|
461
|
+
].sort((a, b) => a.priority - b.priority);
|
|
462
|
+
const getIterceptorHandler = getIterceptorHandlerFactory(interceptors, getInstance, pipes, options.logger);
|
|
463
|
+
const argsPipes = [];
|
|
464
|
+
for (const p of methodMeta.params || []) argsPipes.push({
|
|
465
|
+
meta: p,
|
|
466
|
+
pipes: [...pipes, ...p.pipes || []].sort((a, b) => a.priority - b.priority)
|
|
467
|
+
});
|
|
468
|
+
const resolveArgs = async () => {
|
|
469
|
+
const args = [];
|
|
470
|
+
for (const [i, { pipes: pipes$1, meta: paramMeta }] of argsPipes.entries()) args[i] = await runPipes(pipes$1, undefined, {
|
|
471
|
+
classMeta: meta,
|
|
472
|
+
methodMeta,
|
|
473
|
+
paramMeta,
|
|
474
|
+
type: classConstructor,
|
|
475
|
+
key: method,
|
|
476
|
+
index: i,
|
|
477
|
+
targetMeta: paramMeta
|
|
478
|
+
}, "PARAM");
|
|
479
|
+
return args;
|
|
480
|
+
};
|
|
481
|
+
const wm = new WeakMap();
|
|
482
|
+
controllerOverview.handlers.push(...methodMeta.handlers.map((h) => {
|
|
483
|
+
const data = {
|
|
484
|
+
meta: methodMeta,
|
|
485
|
+
path: h.path,
|
|
486
|
+
type: h.type,
|
|
487
|
+
method,
|
|
488
|
+
handler: h,
|
|
489
|
+
registeredAs: []
|
|
490
|
+
};
|
|
491
|
+
wm.set(h, data);
|
|
492
|
+
return data;
|
|
493
|
+
}));
|
|
494
|
+
for (const adapter of adapters) await adapter.bindHandler({
|
|
495
|
+
prefix,
|
|
496
|
+
fakeInstance,
|
|
497
|
+
getInstance,
|
|
498
|
+
method,
|
|
499
|
+
handlers: methodMeta.handlers,
|
|
500
|
+
getIterceptorHandler,
|
|
501
|
+
resolveArgs,
|
|
502
|
+
logHandler: (eventName) => {
|
|
503
|
+
options.moostInstance.logMappedHandler(eventName, classConstructor, method);
|
|
504
|
+
},
|
|
505
|
+
register(h, path, args) {
|
|
506
|
+
const data = wm.get(h);
|
|
507
|
+
if (data) data.registeredAs.push({
|
|
508
|
+
path,
|
|
509
|
+
args
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return controllerOverview;
|
|
586
515
|
}
|
|
587
516
|
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region packages/moost/src/decorators/circular.decorator.ts
|
|
588
519
|
function Circular(resolver) {
|
|
589
|
-
|
|
520
|
+
return getMoostMate().decorate("circular", resolver);
|
|
590
521
|
}
|
|
591
522
|
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region packages/moost/src/decorators/common.decorator.ts
|
|
592
525
|
function Label(value) {
|
|
593
|
-
|
|
526
|
+
return getMoostMate().decorate("label", value);
|
|
594
527
|
}
|
|
595
528
|
function Description(value) {
|
|
596
|
-
|
|
529
|
+
return getMoostMate().decorate("description", value);
|
|
597
530
|
}
|
|
598
531
|
function Value(value) {
|
|
599
|
-
|
|
532
|
+
return getMoostMate().decorate("value", value);
|
|
600
533
|
}
|
|
601
534
|
function Id(value) {
|
|
602
|
-
|
|
535
|
+
return getMoostMate().decorate("id", value);
|
|
603
536
|
}
|
|
604
537
|
function Optional() {
|
|
605
|
-
|
|
538
|
+
return getMoostMate().decorate("optional", true);
|
|
606
539
|
}
|
|
607
540
|
function Required() {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
541
|
+
const mate$1 = getMoostMate();
|
|
542
|
+
return mate$1.apply(mate$1.decorate("required", true), mate$1.decorateClass((meta, level, key, index) => {
|
|
543
|
+
if (typeof index !== "number" && meta && ["string", "symbol"].includes(typeof key)) {
|
|
544
|
+
meta.requiredProps = meta.requiredProps || [];
|
|
545
|
+
meta.requiredProps.push(key);
|
|
546
|
+
}
|
|
547
|
+
return meta;
|
|
548
|
+
}));
|
|
616
549
|
}
|
|
617
550
|
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region packages/moost/src/decorators/injectable.decorator.ts
|
|
618
553
|
function Injectable(scope = true) {
|
|
619
|
-
|
|
554
|
+
return getMoostMate().decorate("injectable", scope);
|
|
620
555
|
}
|
|
621
|
-
const insureInjectable = getMoostMate().decorate(meta => {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
return meta;
|
|
556
|
+
const insureInjectable = getMoostMate().decorate((meta) => {
|
|
557
|
+
if (!meta.injectable) meta.injectable = true;
|
|
558
|
+
return meta;
|
|
626
559
|
});
|
|
627
560
|
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region packages/moost/src/decorators/controller.decorator.ts
|
|
628
563
|
function Controller(prefix) {
|
|
629
|
-
|
|
630
|
-
|
|
564
|
+
const mate$1 = getMoostMate();
|
|
565
|
+
return mate$1.apply(insureInjectable, mate$1.decorate("controller", { prefix: prefix || "" }));
|
|
631
566
|
}
|
|
632
567
|
function ImportController(prefix, controller, provide) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
provide: typeof prefix === 'string'
|
|
639
|
-
? provide || undefined
|
|
640
|
-
: controller || undefined,
|
|
641
|
-
}, true);
|
|
568
|
+
return getMoostMate().decorate("importController", {
|
|
569
|
+
prefix: typeof prefix === "string" ? prefix : undefined,
|
|
570
|
+
typeResolver: typeof prefix === "string" ? controller : prefix,
|
|
571
|
+
provide: typeof prefix === "string" ? provide || undefined : controller || undefined
|
|
572
|
+
}, true);
|
|
642
573
|
}
|
|
643
574
|
|
|
644
|
-
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region packages/moost/src/decorators/inherit.decorator.ts
|
|
577
|
+
const Inherit = () => getMoostMate().decorate("inherit", true);
|
|
645
578
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region packages/moost/src/decorators/intercept.decorator.ts
|
|
581
|
+
var TInterceptorPriority = /*#__PURE__*/ function(TInterceptorPriority$1) {
|
|
582
|
+
TInterceptorPriority$1[TInterceptorPriority$1["BEFORE_ALL"] = 0] = "BEFORE_ALL";
|
|
583
|
+
TInterceptorPriority$1[TInterceptorPriority$1["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
|
|
584
|
+
TInterceptorPriority$1[TInterceptorPriority$1["GUARD"] = 2] = "GUARD";
|
|
585
|
+
TInterceptorPriority$1[TInterceptorPriority$1["AFTER_GUARD"] = 3] = "AFTER_GUARD";
|
|
586
|
+
TInterceptorPriority$1[TInterceptorPriority$1["INTERCEPTOR"] = 4] = "INTERCEPTOR";
|
|
587
|
+
TInterceptorPriority$1[TInterceptorPriority$1["CATCH_ERROR"] = 5] = "CATCH_ERROR";
|
|
588
|
+
TInterceptorPriority$1[TInterceptorPriority$1["AFTER_ALL"] = 6] = "AFTER_ALL";
|
|
589
|
+
return TInterceptorPriority$1;
|
|
590
|
+
}({});
|
|
656
591
|
function Intercept(handler, priority, name) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
592
|
+
return getMoostMate().decorate("interceptors", {
|
|
593
|
+
handler,
|
|
594
|
+
priority: priority || handler.priority || 4,
|
|
595
|
+
name: name || handler._name || handler.name
|
|
596
|
+
}, true);
|
|
662
597
|
}
|
|
663
598
|
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region packages/moost/src/decorators/resolve.decorator.ts
|
|
664
601
|
function Resolve(resolver, label) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
})(target, key, i);
|
|
675
|
-
};
|
|
602
|
+
return (target, key, index) => {
|
|
603
|
+
const i = typeof index === "number" ? index : undefined;
|
|
604
|
+
getMoostMate().decorate("resolver", (metas, level) => {
|
|
605
|
+
let newLabel = label;
|
|
606
|
+
if (!newLabel && level === "PROP" && typeof metas.key === "string") newLabel = metas.key;
|
|
607
|
+
fillLabel(target, key || "", i, newLabel);
|
|
608
|
+
return resolver(metas, level);
|
|
609
|
+
})(target, key, i);
|
|
610
|
+
};
|
|
676
611
|
}
|
|
677
612
|
function Param(name) {
|
|
678
|
-
|
|
613
|
+
return getMoostMate().apply(getMoostMate().decorate("paramSource", "ROUTE"), getMoostMate().decorate("paramName", name), Resolve(() => useRouteParams().get(name), name));
|
|
679
614
|
}
|
|
680
615
|
function Params() {
|
|
681
|
-
|
|
616
|
+
return Resolve(() => useRouteParams().params, "params");
|
|
682
617
|
}
|
|
683
618
|
function Const(value, label) {
|
|
684
|
-
|
|
619
|
+
return Resolve(() => value, label);
|
|
685
620
|
}
|
|
686
621
|
function ConstFactory(factory, label) {
|
|
687
|
-
|
|
622
|
+
return Resolve(async () => factory(), label);
|
|
688
623
|
}
|
|
689
624
|
function fillLabel(target, key, index, name) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
else if (!meta?.label) {
|
|
698
|
-
Label(name)(target, key);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
625
|
+
if (name) {
|
|
626
|
+
const meta = getMoostMate().read(target, key);
|
|
627
|
+
if (typeof index === "number") {
|
|
628
|
+
if (!meta?.params?.[index]?.label) Label(name)(target, key, index);
|
|
629
|
+
} else if (!meta?.label) Label(name)(target, key);
|
|
630
|
+
}
|
|
701
631
|
}
|
|
702
632
|
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region packages/moost/src/decorators/logger.decorator.ts
|
|
703
635
|
function InjectEventLogger(topic) {
|
|
704
|
-
|
|
636
|
+
return Resolve(() => useEventLogger(topic));
|
|
705
637
|
}
|
|
706
638
|
function InjectMoostLogger(topic) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
639
|
+
return Resolve(async (metas) => {
|
|
640
|
+
const { instantiate, getController } = useControllerContext();
|
|
641
|
+
const controller = getController();
|
|
642
|
+
const moostApp = controller instanceof Moost ? controller : await instantiate(Moost);
|
|
643
|
+
const meta = metas.classMeta;
|
|
644
|
+
return moostApp.getLogger(meta?.loggerTopic || topic || meta?.id);
|
|
645
|
+
});
|
|
714
646
|
}
|
|
715
647
|
function LoggerTopic(topic) {
|
|
716
|
-
|
|
648
|
+
return getMoostMate().decorate("loggerTopic", topic);
|
|
717
649
|
}
|
|
718
650
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
651
|
+
//#endregion
|
|
652
|
+
//#region packages/moost/src/pipes/types.ts
|
|
653
|
+
var TPipePriority = /*#__PURE__*/ function(TPipePriority$1) {
|
|
654
|
+
TPipePriority$1[TPipePriority$1["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
|
|
655
|
+
TPipePriority$1[TPipePriority$1["RESOLVE"] = 1] = "RESOLVE";
|
|
656
|
+
TPipePriority$1[TPipePriority$1["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
|
|
657
|
+
TPipePriority$1[TPipePriority$1["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
|
|
658
|
+
TPipePriority$1[TPipePriority$1["TRANSFORM"] = 4] = "TRANSFORM";
|
|
659
|
+
TPipePriority$1[TPipePriority$1["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
|
|
660
|
+
TPipePriority$1[TPipePriority$1["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
|
|
661
|
+
TPipePriority$1[TPipePriority$1["VALIDATE"] = 7] = "VALIDATE";
|
|
662
|
+
TPipePriority$1[TPipePriority$1["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
663
|
+
return TPipePriority$1;
|
|
664
|
+
}({});
|
|
731
665
|
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region packages/moost/src/decorators/pipe.decorator.ts
|
|
732
668
|
function Pipe(handler, priority) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
669
|
+
if (typeof priority !== "number") priority = typeof handler.priority === "number" ? handler.priority : TPipePriority.TRANSFORM;
|
|
670
|
+
return getMoostMate().decorate("pipes", {
|
|
671
|
+
handler,
|
|
672
|
+
priority
|
|
673
|
+
}, true);
|
|
737
674
|
}
|
|
738
675
|
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region packages/moost/src/decorators/provide.decorator.ts
|
|
739
678
|
function Provide(type, fn) {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
679
|
+
return getMoostMate().decorate((meta) => {
|
|
680
|
+
meta.provide = meta.provide || {};
|
|
681
|
+
Object.assign(meta.provide, createProvideRegistry([type, fn]));
|
|
682
|
+
return meta;
|
|
683
|
+
});
|
|
745
684
|
}
|
|
746
685
|
function Replace(type, newType) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
686
|
+
return getMoostMate().decorate((meta) => {
|
|
687
|
+
meta.replace = meta.replace || {};
|
|
688
|
+
Object.assign(meta.replace, createReplaceRegistry([type, newType]));
|
|
689
|
+
return meta;
|
|
690
|
+
});
|
|
752
691
|
}
|
|
753
692
|
function Inject(type) {
|
|
754
|
-
|
|
693
|
+
return getMoostMate().decorate("inject", type);
|
|
755
694
|
}
|
|
756
695
|
function InjectFromScope(name) {
|
|
757
|
-
|
|
696
|
+
return getMoostMate().decorate("fromScope", name);
|
|
758
697
|
}
|
|
759
698
|
function InjectScopeVars(name) {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
: getInfactScopeVars(scopeId);
|
|
765
|
-
}
|
|
766
|
-
return undefined;
|
|
767
|
-
});
|
|
699
|
+
return Resolve(({ scopeId }) => {
|
|
700
|
+
if (scopeId) return name ? getInfactScopeVars(scopeId)?.[name] : getInfactScopeVars(scopeId);
|
|
701
|
+
return undefined;
|
|
702
|
+
});
|
|
768
703
|
}
|
|
769
704
|
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region packages/moost/src/define.ts
|
|
770
707
|
function defineInterceptorFn(fn, priority = TInterceptorPriority.INTERCEPTOR) {
|
|
771
|
-
|
|
772
|
-
|
|
708
|
+
fn.priority = priority;
|
|
709
|
+
return fn;
|
|
773
710
|
}
|
|
774
711
|
function definePipeFn(fn, priority = TPipePriority.TRANSFORM) {
|
|
775
|
-
|
|
776
|
-
|
|
712
|
+
fn.priority = priority;
|
|
713
|
+
return fn;
|
|
777
714
|
}
|
|
778
715
|
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region packages/moost/src/pipes/resolve.pipe.ts
|
|
779
718
|
const resolvePipe = definePipeFn((_value, metas, level) => {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
}
|
|
784
|
-
return undefined;
|
|
719
|
+
const resolver = metas.targetMeta?.resolver;
|
|
720
|
+
if (resolver) return resolver(metas, level);
|
|
721
|
+
return undefined;
|
|
785
722
|
}, TPipePriority.RESOLVE);
|
|
786
723
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
];
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region packages/moost/src/pipes/shared-pipes.ts
|
|
726
|
+
const sharedPipes = [{
|
|
727
|
+
handler: resolvePipe,
|
|
728
|
+
priority: TPipePriority.RESOLVE
|
|
729
|
+
}];
|
|
793
730
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region packages/moost/src/moost.ts
|
|
733
|
+
function _define_property(obj, key, value) {
|
|
734
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
735
|
+
value,
|
|
736
|
+
enumerable: true,
|
|
737
|
+
configurable: true,
|
|
738
|
+
writable: true
|
|
739
|
+
});
|
|
740
|
+
else obj[key] = value;
|
|
741
|
+
return obj;
|
|
742
|
+
}
|
|
743
|
+
var Moost = class Moost extends Hookable {
|
|
744
|
+
_fireEventStart(source) {
|
|
745
|
+
this.callHook("event-start", source);
|
|
746
|
+
}
|
|
747
|
+
_fireEventEnd(source) {
|
|
748
|
+
this.callHook("event-end", source);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* ### getLogger
|
|
752
|
+
* Provides application logger
|
|
753
|
+
* ```js
|
|
754
|
+
* // get logger with topic = "App"
|
|
755
|
+
* const logger = app.getLogger('App')
|
|
756
|
+
* logger.log('...')
|
|
757
|
+
* ```
|
|
758
|
+
* @param topic
|
|
759
|
+
* @returns
|
|
760
|
+
*/ getLogger(topic) {
|
|
761
|
+
if (topic && this.logger instanceof ProstoLogger) return this.logger.createTopic(topic);
|
|
762
|
+
return this.logger;
|
|
763
|
+
}
|
|
764
|
+
adapter(a) {
|
|
765
|
+
this.adapters.push(a);
|
|
766
|
+
return a;
|
|
767
|
+
}
|
|
768
|
+
getControllersOverview() {
|
|
769
|
+
return this.controllersOverview;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* ### init
|
|
773
|
+
* Ititializes adapter. Must be called after adapters are attached.
|
|
774
|
+
*/ async init() {
|
|
775
|
+
this.setProvideRegistry(createProvideRegistry([Moost, () => this], [ProstoLogger, () => this.logger], ["MOOST_LOGGER", () => this.logger]));
|
|
776
|
+
for (const a of this.adapters) {
|
|
777
|
+
const constructor = getConstructor(a);
|
|
778
|
+
if (constructor) this.setProvideRegistry(createProvideRegistry([constructor, () => a]));
|
|
779
|
+
if (typeof a.getProvideRegistry === "function") this.setProvideRegistry(a.getProvideRegistry());
|
|
780
|
+
}
|
|
781
|
+
this.unregisteredControllers.unshift(this);
|
|
782
|
+
await this.bindControllers();
|
|
783
|
+
for (const a of this.adapters) await (a.onInit && a.onInit(this));
|
|
784
|
+
}
|
|
785
|
+
async bindControllers() {
|
|
786
|
+
const meta = getMoostMate();
|
|
787
|
+
const thisMeta = meta.read(this);
|
|
788
|
+
const provide = {
|
|
789
|
+
...thisMeta?.provide,
|
|
790
|
+
...this.provide
|
|
791
|
+
};
|
|
792
|
+
const replace = {
|
|
793
|
+
...thisMeta?.replace,
|
|
794
|
+
...this.replace
|
|
795
|
+
};
|
|
796
|
+
for (const _controller of this.unregisteredControllers) {
|
|
797
|
+
let newPrefix;
|
|
798
|
+
let controller = _controller;
|
|
799
|
+
if (Array.isArray(_controller) && typeof _controller[0] === "string") {
|
|
800
|
+
newPrefix = _controller[0];
|
|
801
|
+
controller = _controller[1];
|
|
802
|
+
}
|
|
803
|
+
await this.bindController(controller, provide, replace, this.options?.globalPrefix || "", newPrefix);
|
|
804
|
+
}
|
|
805
|
+
this.unregisteredControllers = [];
|
|
806
|
+
}
|
|
807
|
+
async bindController(controller, provide, replace, globalPrefix, replaceOwnPrefix) {
|
|
808
|
+
const mate$1 = getMoostMate();
|
|
809
|
+
const classMeta = mate$1.read(controller);
|
|
810
|
+
const infact$1 = getMoostInfact();
|
|
811
|
+
const isControllerConsructor = isConstructor(controller);
|
|
812
|
+
const pipes = [...this.pipes, ...classMeta?.pipes || []].sort((a, b) => a.priority - b.priority);
|
|
813
|
+
let instance;
|
|
814
|
+
const infactOpts = {
|
|
815
|
+
provide,
|
|
816
|
+
replace,
|
|
817
|
+
customData: { pipes }
|
|
818
|
+
};
|
|
819
|
+
if (isControllerConsructor && (classMeta?.injectable === "SINGLETON" || classMeta?.injectable === true)) await createAsyncEventContext({
|
|
820
|
+
event: { type: "init" },
|
|
821
|
+
options: {}
|
|
822
|
+
})(async () => {
|
|
823
|
+
setControllerContext(this, "bindController", "");
|
|
824
|
+
instance = await infact$1.get(controller, infactOpts);
|
|
825
|
+
});
|
|
826
|
+
else if (!isControllerConsructor) {
|
|
827
|
+
instance = controller;
|
|
828
|
+
infact$1.setInstanceRegistries(instance, provide, replace, { pipes });
|
|
829
|
+
}
|
|
830
|
+
const getInstance = instance ? () => Promise.resolve(instance) : async () => await infact$1.get(controller, { ...infactOpts });
|
|
831
|
+
const classConstructor = isConstructor(controller) ? controller : getConstructor(controller);
|
|
832
|
+
this.controllersOverview.push(await bindControllerMethods({
|
|
833
|
+
getInstance,
|
|
834
|
+
classConstructor,
|
|
835
|
+
adapters: this.adapters,
|
|
836
|
+
globalPrefix,
|
|
837
|
+
replaceOwnPrefix,
|
|
838
|
+
interceptors: Array.from(this.interceptors),
|
|
839
|
+
pipes,
|
|
840
|
+
provide: classMeta?.provide,
|
|
841
|
+
replace: classMeta?.replace,
|
|
842
|
+
logger: this.logger,
|
|
843
|
+
moostInstance: this
|
|
844
|
+
}));
|
|
845
|
+
if (classMeta?.importController) {
|
|
846
|
+
const prefix = typeof replaceOwnPrefix === "string" ? replaceOwnPrefix : classMeta.controller?.prefix;
|
|
847
|
+
const mergedProvide = {
|
|
848
|
+
...provide,
|
|
849
|
+
...classMeta.provide
|
|
850
|
+
};
|
|
851
|
+
const mergedReplace = {
|
|
852
|
+
...this.replace,
|
|
853
|
+
...classMeta.replace
|
|
854
|
+
};
|
|
855
|
+
for (const ic of classMeta.importController) if (ic.typeResolver) {
|
|
856
|
+
const isConstr = isConstructor(ic.typeResolver);
|
|
857
|
+
const isFunc = typeof ic.typeResolver === "function";
|
|
858
|
+
await this.bindController(
|
|
859
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
860
|
+
isConstr ? ic.typeResolver : isFunc ? await ic.typeResolver() : ic.typeResolver,
|
|
861
|
+
ic.provide ? {
|
|
862
|
+
...mergedProvide,
|
|
863
|
+
...ic.provide
|
|
864
|
+
} : mergedProvide,
|
|
865
|
+
mergedReplace,
|
|
866
|
+
`${globalPrefix}/${prefix || ""}`,
|
|
867
|
+
ic.prefix
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
applyGlobalPipes(...items) {
|
|
873
|
+
for (const item of items) if (typeof item === "function") this.pipes.push({
|
|
874
|
+
handler: item,
|
|
875
|
+
priority: typeof item.priority === "number" ? item.priority : TPipePriority.TRANSFORM
|
|
876
|
+
});
|
|
877
|
+
else this.pipes.push({
|
|
878
|
+
handler: item.handler,
|
|
879
|
+
priority: item.priority
|
|
880
|
+
});
|
|
881
|
+
this.globalInterceptorHandler = undefined;
|
|
882
|
+
return this;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Provides InterceptorHandler with global interceptors and pipes.
|
|
886
|
+
* Used to process interceptors when event handler was not found.
|
|
887
|
+
*
|
|
888
|
+
* @returns IterceptorHandler
|
|
889
|
+
*/ getGlobalInterceptorHandler() {
|
|
890
|
+
if (!this.globalInterceptorHandler) {
|
|
891
|
+
const mate$1 = getMoostMate();
|
|
892
|
+
const thisMeta = mate$1.read(this);
|
|
893
|
+
const pipes = [...this.pipes || [], ...thisMeta?.pipes || []].sort((a, b) => a.priority - b.priority);
|
|
894
|
+
const interceptors = [...this.interceptors, ...thisMeta?.interceptors || []].sort((a, b) => a.priority - b.priority);
|
|
895
|
+
this.globalInterceptorHandler = getIterceptorHandlerFactory(interceptors, () => Promise.resolve(this), pipes, this.logger);
|
|
896
|
+
}
|
|
897
|
+
return this.globalInterceptorHandler();
|
|
898
|
+
}
|
|
899
|
+
applyGlobalInterceptors(...items) {
|
|
900
|
+
for (const item of items) if (typeof item === "function") this.interceptors.push({
|
|
901
|
+
handler: item,
|
|
902
|
+
priority: typeof item.priority === "number" ? item.priority : TInterceptorPriority.INTERCEPTOR,
|
|
903
|
+
name: item._name || item.name || "<anonymous>"
|
|
904
|
+
});
|
|
905
|
+
else this.interceptors.push({
|
|
906
|
+
handler: item.handler,
|
|
907
|
+
priority: item.priority,
|
|
908
|
+
name: item.name || item.handler._name || item.handler.name || "<anonymous>"
|
|
909
|
+
});
|
|
910
|
+
this.globalInterceptorHandler = undefined;
|
|
911
|
+
return this;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Register new entries to provide as dependency injections
|
|
915
|
+
* @param provide - Provide Registry (use createProvideRegistry from '\@prostojs/infact')
|
|
916
|
+
* @returns
|
|
917
|
+
*/ setProvideRegistry(provide) {
|
|
918
|
+
this.provide = {
|
|
919
|
+
...this.provide,
|
|
920
|
+
...provide
|
|
921
|
+
};
|
|
922
|
+
return this;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Register replace classes to provide as dependency injections
|
|
926
|
+
* @param replace - Replace Registry (use createReplaceRegistry from '\@prostojs/infact')
|
|
927
|
+
* @returns
|
|
928
|
+
*/ setReplaceRegistry(replace) {
|
|
929
|
+
this.replace = {
|
|
930
|
+
...this.replace,
|
|
931
|
+
...replace
|
|
932
|
+
};
|
|
933
|
+
return this;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Register controllers (similar to @ImportController decorator)
|
|
937
|
+
* @param controllers - list of target controllers (instances)
|
|
938
|
+
* @returns
|
|
939
|
+
*/ registerControllers(...controllers) {
|
|
940
|
+
this.unregisteredControllers.push(...controllers);
|
|
941
|
+
return this;
|
|
942
|
+
}
|
|
943
|
+
logMappedHandler(eventName, classConstructor, method, stroke, prefix) {
|
|
944
|
+
const c = stroke ? "\x1B[9m" : "";
|
|
945
|
+
const coff = stroke ? "\x1B[29m" : "";
|
|
946
|
+
this.logger.info(`${prefix || ""}${c}${eventName} ${"\x1B[0m\x1B[2m\x1B[32m" + c}→ ${classConstructor.name}.${"\x1B[36m" + c}${method}${"\x1B[32m"}()${coff}`);
|
|
947
|
+
}
|
|
948
|
+
constructor(options) {
|
|
949
|
+
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 = createProvideRegistry([Infact, getMoostInfact], [Mate, getMoostMate]), this.replace = {}, this.unregisteredControllers = [];
|
|
950
|
+
this.logger = options?.logger || getDefaultLogger(`${"\x1B[2m\x1B[35m"}moost`);
|
|
951
|
+
setDefaultLogger(this.logger);
|
|
952
|
+
const mate$1 = getMoostMate();
|
|
953
|
+
Object.assign(mate$1, { logger: this.getLogger("mate") });
|
|
954
|
+
}
|
|
955
|
+
};
|
|
993
956
|
|
|
994
|
-
|
|
957
|
+
//#endregion
|
|
958
|
+
export { Circular, Const, ConstFactory, ContextInjector, Controller, Description, EventLogger, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectFromScope, InjectMoostLogger, InjectScopeVars, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, ProstoLogger, Provide, Replace, Required, Resolve, TInterceptorPriority, TPipePriority, Value, clearGlobalWooks, createProvideRegistry, createReplaceRegistry, defineInfactScope, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getConstructor, getContextInjector, getGlobalWooks, getInfactScopeVars, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, isConstructor, registerEventScope, replaceContextInjector, resolvePipe, setControllerContext, setInfactLoggingOptions, useAsyncEventContext, useControllerContext, useEventLogger };
|