phecda-server 1.4.1 → 1.5.1
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/axios-646333e3.d.ts +136 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.ts +22 -44
- package/dist/index.js +70 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -48
- package/dist/index.mjs.map +1 -1
- package/dist/unplugin/esbuild.js +11 -9
- package/dist/unplugin/esbuild.js.map +1 -1
- package/dist/unplugin/esbuild.mjs +11 -9
- package/dist/unplugin/esbuild.mjs.map +1 -1
- package/dist/unplugin/unplugin.js +11 -9
- package/dist/unplugin/unplugin.js.map +1 -1
- package/dist/unplugin/unplugin.mjs +11 -9
- package/dist/unplugin/unplugin.mjs.map +1 -1
- package/dist/unplugin/vite.js +11 -9
- package/dist/unplugin/vite.js.map +1 -1
- package/dist/unplugin/vite.mjs +11 -9
- package/dist/unplugin/vite.mjs.map +1 -1
- package/dist/unplugin/webpack.js +11 -9
- package/dist/unplugin/webpack.js.map +1 -1
- package/dist/unplugin/webpack.mjs +11 -9
- package/dist/unplugin/webpack.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/axios-95842cc3.d.ts +0 -116
package/dist/index.js
CHANGED
|
@@ -39,8 +39,11 @@ __export(src_exports, {
|
|
|
39
39
|
Base: () => Base,
|
|
40
40
|
BaseParam: () => BaseParam,
|
|
41
41
|
Body: () => Body,
|
|
42
|
+
Compiler: () => Compiler,
|
|
42
43
|
ConflictException: () => ConflictException,
|
|
44
|
+
Context: () => Context,
|
|
43
45
|
Controller: () => Controller,
|
|
46
|
+
Define: () => Define,
|
|
44
47
|
Delete: () => Delete,
|
|
45
48
|
Factory: () => Factory,
|
|
46
49
|
ForbiddenException: () => ForbiddenException,
|
|
@@ -58,9 +61,6 @@ __export(src_exports, {
|
|
|
58
61
|
NotFoundException: () => NotFoundException,
|
|
59
62
|
Param: () => Param,
|
|
60
63
|
PayloadLargeException: () => PayloadLargeException,
|
|
61
|
-
Pcompiler: () => Pcompiler,
|
|
62
|
-
Pcontext: () => Pcontext,
|
|
63
|
-
Pmeta: () => Pmeta,
|
|
64
64
|
Post: () => Post,
|
|
65
65
|
Put: () => Put,
|
|
66
66
|
Query: () => Query,
|
|
@@ -197,7 +197,7 @@ __name(ConflictException, "ConflictException");
|
|
|
197
197
|
// src/exception/bad-gateway.ts
|
|
198
198
|
var BadGatewayException = class extends HttpException {
|
|
199
199
|
constructor(message) {
|
|
200
|
-
super(message,
|
|
200
|
+
super(message, 502, "Bad Gatrway");
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
__name(BadGatewayException, "BadGatewayException");
|
|
@@ -284,7 +284,7 @@ var Phistroy = class {
|
|
|
284
284
|
__name(Phistroy, "Phistroy");
|
|
285
285
|
|
|
286
286
|
// src/context/base.ts
|
|
287
|
-
var
|
|
287
|
+
var _Context = class {
|
|
288
288
|
key;
|
|
289
289
|
data;
|
|
290
290
|
method;
|
|
@@ -297,17 +297,17 @@ var _Pcontext = class {
|
|
|
297
297
|
this.history = new Phistroy();
|
|
298
298
|
}
|
|
299
299
|
static registerGuard(key, handler) {
|
|
300
|
-
|
|
300
|
+
_Context.guardsRecord[key] = handler;
|
|
301
301
|
}
|
|
302
302
|
static registerInterceptor(key, handler) {
|
|
303
|
-
|
|
303
|
+
_Context.interceptorsRecord[key] = handler;
|
|
304
304
|
}
|
|
305
305
|
async useGuard(guards, isMerge = false) {
|
|
306
306
|
for (const guard of guards) {
|
|
307
307
|
if (this.history.record(guard, "guard")) {
|
|
308
|
-
if (!(guard in
|
|
308
|
+
if (!(guard in _Context.guardsRecord))
|
|
309
309
|
throw new FrameworkException(`can't find guard named ${guard}`);
|
|
310
|
-
if (!await
|
|
310
|
+
if (!await _Context.guardsRecord[guard](this.data, isMerge))
|
|
311
311
|
throw new ForbiddenException(`Guard exception--${guard}`);
|
|
312
312
|
}
|
|
313
313
|
}
|
|
@@ -316,9 +316,9 @@ var _Pcontext = class {
|
|
|
316
316
|
const ret = [];
|
|
317
317
|
for (const interceptor of interceptors) {
|
|
318
318
|
if (this.history.record(interceptor, "interceptor")) {
|
|
319
|
-
if (!(interceptor in
|
|
319
|
+
if (!(interceptor in _Context.interceptorsRecord))
|
|
320
320
|
throw new FrameworkException(`can't find guard named ${interceptor}`);
|
|
321
|
-
const post = await
|
|
321
|
+
const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge);
|
|
322
322
|
if (post)
|
|
323
323
|
ret.push(post);
|
|
324
324
|
}
|
|
@@ -333,23 +333,23 @@ var _Pcontext = class {
|
|
|
333
333
|
return data;
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
|
-
var
|
|
337
|
-
__name(
|
|
338
|
-
__publicField(
|
|
339
|
-
__publicField(
|
|
340
|
-
__publicField(
|
|
341
|
-
__publicField(
|
|
342
|
-
__publicField(
|
|
336
|
+
var Context = _Context;
|
|
337
|
+
__name(Context, "Context");
|
|
338
|
+
__publicField(Context, "metaRecord", {});
|
|
339
|
+
__publicField(Context, "metaDataRecord", {});
|
|
340
|
+
__publicField(Context, "instanceRecord", {});
|
|
341
|
+
__publicField(Context, "guardsRecord", {});
|
|
342
|
+
__publicField(Context, "interceptorsRecord", {});
|
|
343
343
|
function addGuard(key, handler) {
|
|
344
|
-
|
|
344
|
+
Context.registerGuard(key, handler);
|
|
345
345
|
}
|
|
346
346
|
__name(addGuard, "addGuard");
|
|
347
347
|
function addInterceptor(key, handler) {
|
|
348
|
-
|
|
348
|
+
Context.registerInterceptor(key, handler);
|
|
349
349
|
}
|
|
350
350
|
__name(addInterceptor, "addInterceptor");
|
|
351
351
|
function getInstance(tag) {
|
|
352
|
-
return
|
|
352
|
+
return Context.instanceRecord[tag];
|
|
353
353
|
}
|
|
354
354
|
__name(getInstance, "getInstance");
|
|
355
355
|
function parseMeta(meta) {
|
|
@@ -372,7 +372,7 @@ function parseMeta(meta) {
|
|
|
372
372
|
__name(parseMeta, "parseMeta");
|
|
373
373
|
|
|
374
374
|
// src/context/server.ts
|
|
375
|
-
var _ServerContext = class extends
|
|
375
|
+
var _ServerContext = class extends Context {
|
|
376
376
|
static useMiddleware(middlewares) {
|
|
377
377
|
return middlewares.map((m) => {
|
|
378
378
|
if (!(m in _ServerContext.middlewareRecord))
|
|
@@ -409,7 +409,7 @@ function useServerFilter(filter) {
|
|
|
409
409
|
__name(useServerFilter, "useServerFilter");
|
|
410
410
|
|
|
411
411
|
// src/context/micro.ts
|
|
412
|
-
var _RabbitMqContext = class extends
|
|
412
|
+
var _RabbitMqContext = class extends Context {
|
|
413
413
|
static useMiddleware(middlewares) {
|
|
414
414
|
return middlewares.map((m) => {
|
|
415
415
|
if (!(m in _RabbitMqContext.middlewareRecord))
|
|
@@ -448,7 +448,7 @@ var Base = class {
|
|
|
448
448
|
__name(Base, "Base");
|
|
449
449
|
|
|
450
450
|
// src/compiler.ts
|
|
451
|
-
var
|
|
451
|
+
var Compiler = class {
|
|
452
452
|
classMap = {};
|
|
453
453
|
name;
|
|
454
454
|
constructor() {
|
|
@@ -487,7 +487,7 @@ return ret
|
|
|
487
487
|
`;
|
|
488
488
|
}
|
|
489
489
|
};
|
|
490
|
-
__name(
|
|
490
|
+
__name(Compiler, "Compiler");
|
|
491
491
|
function genParams(decorators) {
|
|
492
492
|
return decorators.map((_, i) => {
|
|
493
493
|
return `${`arg${i}`}`;
|
|
@@ -526,8 +526,8 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
526
526
|
const instance = moduleMap.get(tag);
|
|
527
527
|
const methodTag = `${tag}-${method}`;
|
|
528
528
|
contextMeta[methodTag] = i;
|
|
529
|
-
|
|
530
|
-
let { guards, reflect, interceptors, params, middlewares } =
|
|
529
|
+
Context.metaRecord[methodTag] = i;
|
|
530
|
+
let { guards, reflect, interceptors, params, middlewares } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : Context.metaDataRecord[methodTag] = parseMeta(i);
|
|
531
531
|
guards = [
|
|
532
532
|
...globalGuards,
|
|
533
533
|
...guards
|
|
@@ -538,7 +538,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
538
538
|
];
|
|
539
539
|
const handler = instance[method].bind(instance);
|
|
540
540
|
methodMap[methodTag] = handler;
|
|
541
|
-
|
|
541
|
+
Context.instanceRecord[name] = instance;
|
|
542
542
|
if (route2) {
|
|
543
543
|
app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
|
|
544
544
|
const contextData = {
|
|
@@ -580,7 +580,8 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
580
580
|
const contextData = {
|
|
581
581
|
request: req,
|
|
582
582
|
response: res,
|
|
583
|
-
meta: contextMeta
|
|
583
|
+
meta: contextMeta,
|
|
584
|
+
isMerge: true
|
|
584
585
|
};
|
|
585
586
|
if (!Array.isArray(data))
|
|
586
587
|
return res.json(await ServerContext.useFilter(new BadRequestException("data format should be an array"), contextData));
|
|
@@ -591,7 +592,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
591
592
|
for (const item of data) {
|
|
592
593
|
const { tag } = item;
|
|
593
594
|
const [name] = tag.split("-");
|
|
594
|
-
const { guards, reflect, interceptors, params } =
|
|
595
|
+
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
595
596
|
const instance = moduleMap.get(name);
|
|
596
597
|
try {
|
|
597
598
|
if (!params)
|
|
@@ -615,7 +616,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
615
616
|
instance.context = contextData;
|
|
616
617
|
ret.push(await context.usePost(await methodMap[tag](...args)));
|
|
617
618
|
} catch (e) {
|
|
618
|
-
const m =
|
|
619
|
+
const m = Context.metaRecord[tag];
|
|
619
620
|
m.handlers.forEach((handler) => handler.error?.(e));
|
|
620
621
|
ret.push(await context.useFilter(e));
|
|
621
622
|
}
|
|
@@ -627,7 +628,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
627
628
|
return new Promise(async (resolve) => {
|
|
628
629
|
const { tag } = item;
|
|
629
630
|
const [name] = tag.split("-");
|
|
630
|
-
const { guards, reflect, interceptors, params } =
|
|
631
|
+
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
631
632
|
const instance = moduleMap.get(name);
|
|
632
633
|
try {
|
|
633
634
|
if (!params)
|
|
@@ -644,7 +645,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
644
645
|
instance.context = contextData;
|
|
645
646
|
resolve(await context.usePost(await methodMap[tag](...args)));
|
|
646
647
|
} catch (e) {
|
|
647
|
-
const m =
|
|
648
|
+
const m = Context.metaRecord[tag];
|
|
648
649
|
m.handlers.forEach((handler) => handler.error?.(e));
|
|
649
650
|
resolve(await context.useFilter(e));
|
|
650
651
|
}
|
|
@@ -665,7 +666,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
665
666
|
var import_phecda_core2 = require("phecda-core");
|
|
666
667
|
|
|
667
668
|
// src/meta.ts
|
|
668
|
-
var
|
|
669
|
+
var Meta = class {
|
|
669
670
|
data;
|
|
670
671
|
handlers;
|
|
671
672
|
reflect;
|
|
@@ -675,7 +676,7 @@ var Pmeta = class {
|
|
|
675
676
|
this.reflect = reflect;
|
|
676
677
|
}
|
|
677
678
|
};
|
|
678
|
-
__name(
|
|
679
|
+
__name(Meta, "Meta");
|
|
679
680
|
|
|
680
681
|
// src/core.ts
|
|
681
682
|
var emitter = new import_events.default();
|
|
@@ -742,7 +743,14 @@ function getMetaFromInstance(instance, name, tag) {
|
|
|
742
743
|
}
|
|
743
744
|
state.params = params;
|
|
744
745
|
initState(state);
|
|
745
|
-
state.
|
|
746
|
+
state.define = {
|
|
747
|
+
...baseState.define,
|
|
748
|
+
...state.define
|
|
749
|
+
};
|
|
750
|
+
state.header = {
|
|
751
|
+
...baseState.header,
|
|
752
|
+
...state.header
|
|
753
|
+
};
|
|
746
754
|
state.middlewares = [
|
|
747
755
|
.../* @__PURE__ */ new Set([
|
|
748
756
|
...baseState.middlewares,
|
|
@@ -761,7 +769,7 @@ function getMetaFromInstance(instance, name, tag) {
|
|
|
761
769
|
...state.interceptors
|
|
762
770
|
])
|
|
763
771
|
];
|
|
764
|
-
return new
|
|
772
|
+
return new Meta(state, (0, import_phecda_core2.getHandler)(instance, i), getParamtypes(instance, i) || []);
|
|
765
773
|
});
|
|
766
774
|
}
|
|
767
775
|
__name(getMetaFromInstance, "getMetaFromInstance");
|
|
@@ -770,6 +778,8 @@ function getParamtypes(Module, key) {
|
|
|
770
778
|
}
|
|
771
779
|
__name(getParamtypes, "getParamtypes");
|
|
772
780
|
function initState(state) {
|
|
781
|
+
if (!state.define)
|
|
782
|
+
state.define = {};
|
|
773
783
|
if (!state.header)
|
|
774
784
|
state.header = {};
|
|
775
785
|
if (!state.middlewares)
|
|
@@ -952,17 +962,26 @@ function Header(name, value) {
|
|
|
952
962
|
};
|
|
953
963
|
}
|
|
954
964
|
__name(Header, "Header");
|
|
955
|
-
function
|
|
965
|
+
function Define(key, value) {
|
|
956
966
|
return (target, k) => {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
967
|
+
if (k) {
|
|
968
|
+
(0, import_phecda_core6.setModalVar)(target, k);
|
|
969
|
+
(0, import_phecda_core6.mergeState)(target, k, {
|
|
970
|
+
define: {
|
|
971
|
+
[key]: value
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
} else {
|
|
975
|
+
(0, import_phecda_core6.setModalVar)(target.prototype, "__CLASS");
|
|
976
|
+
(0, import_phecda_core6.mergeState)(target.prototype, "__CLASS", {
|
|
977
|
+
define: {
|
|
978
|
+
[key]: value
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
}
|
|
963
982
|
};
|
|
964
983
|
}
|
|
965
|
-
__name(
|
|
984
|
+
__name(Define, "Define");
|
|
966
985
|
|
|
967
986
|
// src/index.ts
|
|
968
987
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
@@ -980,11 +999,11 @@ async function bindMQ(ch, { meta, moduleMap }) {
|
|
|
980
999
|
for (const item of meta) {
|
|
981
1000
|
const { route, name, method, mq: { routeKey, queue: queueName, options } = {} } = item.data;
|
|
982
1001
|
const tag = `${name}-${method}`;
|
|
983
|
-
|
|
984
|
-
const { guards, reflect, interceptors, params } =
|
|
1002
|
+
Context.metaRecord[tag] = item;
|
|
1003
|
+
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag] ? Context.metaDataRecord[tag] : Context.metaDataRecord[tag] = parseMeta(item);
|
|
985
1004
|
const instance = moduleMap.get(name);
|
|
986
1005
|
const handler = instance[method].bind(instance);
|
|
987
|
-
|
|
1006
|
+
Context.instanceRecord[name] = instance;
|
|
988
1007
|
if (route) {
|
|
989
1008
|
const { queue } = await ch.assertQueue(route.route);
|
|
990
1009
|
if (queueName && routeKey)
|
|
@@ -1126,8 +1145,11 @@ __name(createMqReq, "createMqReq");
|
|
|
1126
1145
|
Base,
|
|
1127
1146
|
BaseParam,
|
|
1128
1147
|
Body,
|
|
1148
|
+
Compiler,
|
|
1129
1149
|
ConflictException,
|
|
1150
|
+
Context,
|
|
1130
1151
|
Controller,
|
|
1152
|
+
Define,
|
|
1131
1153
|
Delete,
|
|
1132
1154
|
Factory,
|
|
1133
1155
|
ForbiddenException,
|
|
@@ -1145,9 +1167,6 @@ __name(createMqReq, "createMqReq");
|
|
|
1145
1167
|
NotFoundException,
|
|
1146
1168
|
Param,
|
|
1147
1169
|
PayloadLargeException,
|
|
1148
|
-
Pcompiler,
|
|
1149
|
-
Pcontext,
|
|
1150
|
-
Pmeta,
|
|
1151
1170
|
Post,
|
|
1152
1171
|
Put,
|
|
1153
1172
|
Query,
|