phecda-server 3.0.0 → 3.0.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/bin/cli.js +12 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +123 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/bin/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const [module, dir = ''] = process.argv.slice(2)
|
|
4
|
+
|
|
5
|
+
const dirPath = path.resolve(process.cwd(), dir, module)
|
|
6
|
+
fs.mkdirSync(dirPath)
|
|
7
|
+
|
|
8
|
+
fs.writeFileSync(path.resolve(dirPath, `${module}.controller.ts`), `
|
|
9
|
+
export class ${module.slice(0).toUpperCase()}${module.slice(1)}Controller{
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
`)
|
package/dist/index.d.ts
CHANGED
|
@@ -185,6 +185,7 @@ declare function parseMeta(meta: Meta): {
|
|
|
185
185
|
reflect: any[];
|
|
186
186
|
interceptors: string[];
|
|
187
187
|
middlewares: string[];
|
|
188
|
+
handlers: P.Handler[];
|
|
188
189
|
params: {
|
|
189
190
|
type: string;
|
|
190
191
|
key: string;
|
|
@@ -232,6 +233,7 @@ declare function Route(route: string, type?: string): any;
|
|
|
232
233
|
declare function Get(route: string): any;
|
|
233
234
|
declare function Post(route: string): any;
|
|
234
235
|
declare function Put(route: string): any;
|
|
236
|
+
declare function Patch(route: string): any;
|
|
235
237
|
declare function Delete(route: string): any;
|
|
236
238
|
declare function Controller(route: string): any;
|
|
237
239
|
declare function Guard(...guards: string[]): any;
|
|
@@ -249,4 +251,4 @@ declare function resolveDep(ret: any, key: string): any;
|
|
|
249
251
|
declare const SERIES_SYMBOL = "__symbol_series__";
|
|
250
252
|
declare const MERGE_SYMBOL = "__symbol_req__";
|
|
251
253
|
|
|
252
|
-
export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, getInstance, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
|
|
254
|
+
export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, getInstance, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
|
package/dist/index.js
CHANGED
|
@@ -57,6 +57,7 @@ __export(src_exports, {
|
|
|
57
57
|
Middle: () => Middle,
|
|
58
58
|
NotFoundException: () => NotFoundException,
|
|
59
59
|
Param: () => Param,
|
|
60
|
+
Patch: () => Patch,
|
|
60
61
|
PayloadLargeException: () => PayloadLargeException,
|
|
61
62
|
Post: () => Post,
|
|
62
63
|
Put: () => Put,
|
|
@@ -123,8 +124,13 @@ var defaultPipe = {
|
|
|
123
124
|
async transform(args, reflect) {
|
|
124
125
|
for (const i in args) {
|
|
125
126
|
const { validate, arg } = args[i];
|
|
126
|
-
if (validate === false
|
|
127
|
+
if (validate === false)
|
|
127
128
|
continue;
|
|
129
|
+
if (!reflect[i]) {
|
|
130
|
+
if (validate && arg)
|
|
131
|
+
args[i].arg = validate(arg);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
128
134
|
if ((0, import_phecda_core.isPhecda)(reflect[i])) {
|
|
129
135
|
const ret = await (0, import_phecda_core.plainToClass)(reflect[i], arg, {
|
|
130
136
|
transform: true
|
|
@@ -253,8 +259,12 @@ __name(FrameworkException, "FrameworkException");
|
|
|
253
259
|
|
|
254
260
|
// src/filter.ts
|
|
255
261
|
var serverFilter = /* @__PURE__ */ __name((e) => {
|
|
256
|
-
if (!(e instanceof HttpException))
|
|
262
|
+
if (!(e instanceof HttpException)) {
|
|
263
|
+
console.error(e.stack);
|
|
257
264
|
e = new UndefinedException(e.message || e);
|
|
265
|
+
} else {
|
|
266
|
+
console.error(e.message);
|
|
267
|
+
}
|
|
258
268
|
return e.data;
|
|
259
269
|
}, "serverFilter");
|
|
260
270
|
|
|
@@ -342,12 +352,13 @@ function getInstance(tag) {
|
|
|
342
352
|
}
|
|
343
353
|
__name(getInstance, "getInstance");
|
|
344
354
|
function parseMeta(meta) {
|
|
345
|
-
const { data: { params, guards, interceptors, middlewares }, reflect } = meta;
|
|
355
|
+
const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta;
|
|
346
356
|
return {
|
|
347
357
|
guards,
|
|
348
358
|
reflect,
|
|
349
359
|
interceptors,
|
|
350
360
|
middlewares,
|
|
361
|
+
handlers,
|
|
351
362
|
params: params.map((param) => {
|
|
352
363
|
const { type, key, validate } = param;
|
|
353
364
|
return {
|
|
@@ -435,13 +446,115 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
435
446
|
};
|
|
436
447
|
const methodMap = {};
|
|
437
448
|
const contextMeta = {};
|
|
449
|
+
app.post(route, (req, _res, next) => {
|
|
450
|
+
req[MERGE_SYMBOL] = true;
|
|
451
|
+
next();
|
|
452
|
+
}, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {
|
|
453
|
+
const { body: { category, data } } = req;
|
|
454
|
+
const contextData = {
|
|
455
|
+
request: req,
|
|
456
|
+
response: res,
|
|
457
|
+
meta: contextMeta,
|
|
458
|
+
isMerge: true
|
|
459
|
+
};
|
|
460
|
+
if (!Array.isArray(data))
|
|
461
|
+
return res.json(await ServerContext.useFilter(new BadRequestException("data format should be an array"), contextData));
|
|
462
|
+
if (category !== "series" && category !== "parallel")
|
|
463
|
+
return res.json(await ServerContext.useFilter(new BadRequestException("category should be 'parallel' or 'series'"), contextData));
|
|
464
|
+
contextData.tags = data.map((item) => item.tag);
|
|
465
|
+
const context = new ServerContext(route, contextData);
|
|
466
|
+
const ret = [];
|
|
467
|
+
try {
|
|
468
|
+
const mergeGuards = /* @__PURE__ */ new Set([
|
|
469
|
+
...globalGuards
|
|
470
|
+
]);
|
|
471
|
+
const mergeInterceptors = /* @__PURE__ */ new Set([
|
|
472
|
+
...globalInterceptors
|
|
473
|
+
]);
|
|
474
|
+
data.forEach(({ tag }) => {
|
|
475
|
+
const { guards, interceptors } = Context.metaDataRecord[tag];
|
|
476
|
+
guards.forEach((guard) => mergeGuards.add(guard));
|
|
477
|
+
interceptors.forEach((intercept) => mergeInterceptors.add(intercept));
|
|
478
|
+
});
|
|
479
|
+
await context.useGuard([
|
|
480
|
+
...mergeGuards
|
|
481
|
+
], true);
|
|
482
|
+
await context.useInterceptor([
|
|
483
|
+
...mergeInterceptors
|
|
484
|
+
], true);
|
|
485
|
+
if (category === "series") {
|
|
486
|
+
for (const item of data) {
|
|
487
|
+
const { tag } = item;
|
|
488
|
+
const [name] = tag.split("-");
|
|
489
|
+
const { reflect, params } = Context.metaDataRecord[tag];
|
|
490
|
+
const instance = moduleMap.get(name);
|
|
491
|
+
try {
|
|
492
|
+
if (!params)
|
|
493
|
+
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
494
|
+
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
495
|
+
const arg = resolveDep(item[type], key);
|
|
496
|
+
if (typeof arg === "string" && arg.startsWith(SERIES_SYMBOL)) {
|
|
497
|
+
const [, index, argKey] = arg.split("@");
|
|
498
|
+
return {
|
|
499
|
+
arg: resolveDep(ret[Number(index)], argKey || key),
|
|
500
|
+
validate
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
arg,
|
|
505
|
+
validate
|
|
506
|
+
};
|
|
507
|
+
}), reflect);
|
|
508
|
+
instance.context = contextData;
|
|
509
|
+
ret.push(await methodMap[tag](...args));
|
|
510
|
+
} catch (e) {
|
|
511
|
+
const m = Context.metaRecord[tag];
|
|
512
|
+
m.handlers.forEach((handler) => handler.error?.(e));
|
|
513
|
+
ret.push(await context.useFilter(e));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return res.json(await context.usePost(ret));
|
|
517
|
+
}
|
|
518
|
+
if (category === "parallel") {
|
|
519
|
+
return Promise.all(data.map((item) => {
|
|
520
|
+
return new Promise(async (resolve) => {
|
|
521
|
+
const { tag } = item;
|
|
522
|
+
const [name] = tag.split("-");
|
|
523
|
+
const { reflect, params, handlers } = Context.metaDataRecord[tag];
|
|
524
|
+
const instance = moduleMap.get(name);
|
|
525
|
+
try {
|
|
526
|
+
if (!params)
|
|
527
|
+
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
528
|
+
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
529
|
+
const arg = resolveDep(item[type], key);
|
|
530
|
+
return {
|
|
531
|
+
arg,
|
|
532
|
+
validate
|
|
533
|
+
};
|
|
534
|
+
}), reflect);
|
|
535
|
+
instance.context = contextData;
|
|
536
|
+
resolve(await methodMap[tag](...args));
|
|
537
|
+
} catch (e) {
|
|
538
|
+
handlers.forEach((handler) => handler.error?.(e));
|
|
539
|
+
resolve(await context.useFilter(e));
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
})).then(async (ret2) => {
|
|
543
|
+
res.json(await context.usePost(ret2));
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
} catch (e) {
|
|
547
|
+
const err = await context.useFilter(e);
|
|
548
|
+
res.status(err.status).json(err);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
438
551
|
for (const i of meta) {
|
|
439
552
|
const { name, method, route: route2, header, tag } = i.data;
|
|
440
553
|
const instance = moduleMap.get(tag);
|
|
441
554
|
const methodTag = `${tag}-${method}`;
|
|
442
555
|
contextMeta[methodTag] = i;
|
|
443
556
|
Context.metaRecord[methodTag] = i;
|
|
444
|
-
let { guards, reflect, interceptors, params, middlewares } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : Context.metaDataRecord[methodTag] = parseMeta(i);
|
|
557
|
+
let { guards, reflect, interceptors, params, handlers, middlewares } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : Context.metaDataRecord[methodTag] = parseMeta(i);
|
|
445
558
|
guards = [
|
|
446
559
|
...globalGuards,
|
|
447
560
|
...guards
|
|
@@ -479,97 +592,13 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
479
592
|
else
|
|
480
593
|
res.send(String(ret));
|
|
481
594
|
} catch (e) {
|
|
482
|
-
|
|
595
|
+
handlers.forEach((handler2) => handler2.error?.(e));
|
|
483
596
|
const err = await context.useFilter(e);
|
|
484
597
|
res.status(err.status).json(err);
|
|
485
598
|
}
|
|
486
599
|
});
|
|
487
600
|
}
|
|
488
601
|
}
|
|
489
|
-
app.post(route, (req, _res, next) => {
|
|
490
|
-
req[MERGE_SYMBOL] = true;
|
|
491
|
-
next();
|
|
492
|
-
}, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {
|
|
493
|
-
const { body: { category, data } } = req;
|
|
494
|
-
const contextData = {
|
|
495
|
-
request: req,
|
|
496
|
-
response: res,
|
|
497
|
-
meta: contextMeta,
|
|
498
|
-
isMerge: true
|
|
499
|
-
};
|
|
500
|
-
if (!Array.isArray(data))
|
|
501
|
-
return res.json(await ServerContext.useFilter(new BadRequestException("data format should be an array"), contextData));
|
|
502
|
-
contextData.tags = data.map((item) => item.tag);
|
|
503
|
-
const context = new ServerContext(route, contextData);
|
|
504
|
-
const ret = [];
|
|
505
|
-
if (category === "series") {
|
|
506
|
-
for (const item of data) {
|
|
507
|
-
const { tag } = item;
|
|
508
|
-
const [name] = tag.split("-");
|
|
509
|
-
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
510
|
-
const instance = moduleMap.get(name);
|
|
511
|
-
try {
|
|
512
|
-
if (!params)
|
|
513
|
-
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
514
|
-
await context.useGuard(guards, true);
|
|
515
|
-
await context.useInterceptor(interceptors, true);
|
|
516
|
-
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
517
|
-
const arg = resolveDep(item[type], key);
|
|
518
|
-
if (typeof arg === "string" && arg.startsWith(SERIES_SYMBOL)) {
|
|
519
|
-
const [, index, argKey] = arg.split("@");
|
|
520
|
-
return {
|
|
521
|
-
arg: resolveDep(ret[Number(index)], argKey || key),
|
|
522
|
-
validate
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
return {
|
|
526
|
-
arg,
|
|
527
|
-
validate
|
|
528
|
-
};
|
|
529
|
-
}), reflect);
|
|
530
|
-
instance.context = contextData;
|
|
531
|
-
ret.push(await context.usePost(await methodMap[tag](...args)));
|
|
532
|
-
} catch (e) {
|
|
533
|
-
const m = Context.metaRecord[tag];
|
|
534
|
-
m.handlers.forEach((handler) => handler.error?.(e));
|
|
535
|
-
ret.push(await context.useFilter(e));
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
return res.json(ret);
|
|
539
|
-
}
|
|
540
|
-
if (category === "parallel") {
|
|
541
|
-
return Promise.all(data.map((item) => {
|
|
542
|
-
return new Promise(async (resolve) => {
|
|
543
|
-
const { tag } = item;
|
|
544
|
-
const [name] = tag.split("-");
|
|
545
|
-
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
546
|
-
const instance = moduleMap.get(name);
|
|
547
|
-
try {
|
|
548
|
-
if (!params)
|
|
549
|
-
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
550
|
-
await context.useGuard(guards, true);
|
|
551
|
-
await context.useInterceptor(interceptors, true);
|
|
552
|
-
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
553
|
-
const arg = resolveDep(item[type], key);
|
|
554
|
-
return {
|
|
555
|
-
arg,
|
|
556
|
-
validate
|
|
557
|
-
};
|
|
558
|
-
}), reflect);
|
|
559
|
-
instance.context = contextData;
|
|
560
|
-
resolve(await context.usePost(await methodMap[tag](...args)));
|
|
561
|
-
} catch (e) {
|
|
562
|
-
const m = Context.metaRecord[tag];
|
|
563
|
-
m.handlers.forEach((handler) => handler.error?.(e));
|
|
564
|
-
resolve(await context.useFilter(e));
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
})).then((ret2) => {
|
|
568
|
-
res.json(ret2);
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
res.json(await context.useFilter(new BadRequestException("category should be 'parallel' or 'series'")));
|
|
572
|
-
});
|
|
573
602
|
}
|
|
574
603
|
__name(bindApp, "bindApp");
|
|
575
604
|
|
|
@@ -773,6 +802,10 @@ function Put(route) {
|
|
|
773
802
|
return Route(route, "put");
|
|
774
803
|
}
|
|
775
804
|
__name(Put, "Put");
|
|
805
|
+
function Patch(route) {
|
|
806
|
+
return Route(route, "patch");
|
|
807
|
+
}
|
|
808
|
+
__name(Patch, "Patch");
|
|
776
809
|
function Delete(route) {
|
|
777
810
|
return Route(route, "delete");
|
|
778
811
|
}
|
|
@@ -880,6 +913,7 @@ __reExport(src_exports, require("phecda-core"), module.exports);
|
|
|
880
913
|
Middle,
|
|
881
914
|
NotFoundException,
|
|
882
915
|
Param,
|
|
916
|
+
Patch,
|
|
883
917
|
PayloadLargeException,
|
|
884
918
|
Post,
|
|
885
919
|
Put,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts"],"sourcesContent":["export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: boolean }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false || !reflect[i]/** work for undefined */)\n continue\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException))\n e = new UndefinedException(e.message || e)\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find guard named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n i.handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(ret)\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.json(ret)\n })\n }\n\n res.json(await context.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\'')))\n })\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,yBAAuC;;;ACAhC,IAAMA,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,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;AAEAT,yCAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,sCAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;A5BNhB,wBAAc,wBARd;","names":["HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","i","name","method","header","tag","data","instance","get","methodTag","Context","metaRecord","guards","reflect","interceptors","params","metaDataRecord","parseMeta","handler","bind","instanceRecord","type","ServerContext","useMiddleware","req","res","contextData","request","response","context","set","useGuard","useInterceptor","args","usePipe","map","key","validate","arg","resolveDep","ret","usePost","isObject","json","send","String","e","handlers","forEach","error","err","useFilter","status","post","_res","next","MERGE_SYMBOL","body","category","isMerge","Array","isArray","BadRequestException","tags","item","split","startsWith","SERIES_SYMBOL","index","argKey","Number","push","m","Promise","all","resolve","then","import_phecda_core","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","import_phecda_core","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts"],"sourcesContent":["export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: any }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (!reflect[i]) {\n if (validate && arg)\n args[i].arg = validate(arg)\n\n continue\n }\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException)) {\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n console.error(e.message)\n }\n\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find guard named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n if (category !== 'series' && category !== 'parallel')\n return res.json(await ServerContext.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\''), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n try {\n const mergeGuards = new Set([...globalGuards])\n const mergeInterceptors = new Set([...globalInterceptors])\n\n data.forEach(({ tag }) => {\n const {\n guards,\n interceptors,\n } = Context.metaDataRecord[tag]\n guards.forEach(guard => mergeGuards.add(guard))\n interceptors.forEach(intercept => mergeInterceptors.add(intercept))\n })\n await context.useGuard([...mergeGuards], true)\n await context.useInterceptor([...mergeInterceptors], true)\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await methodMap[tag](...args))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(await context.usePost(ret))\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n handlers,\n } = Context.metaDataRecord[tag]\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await methodMap[tag](...args))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then(async (ret) => {\n res.json(await context.usePost(ret))\n })\n }\n }\n catch (e) {\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n handlers,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Patch(route: string) {\n return Route(route, 'patch')\n}\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,yBAAuC;;;ACAhC,IAAMA,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;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,CAACA;AACHA,YAAM;AACRD,aAASC,QAAQ,YAAYD,OAAOE,YAAYF;AAEhDG,yCAAYH,QAAQC,GAAAA;AAEpB,UAAMG,QAAQJ,OAAOK,WAAWC,oBAAoBC,IAAIN,GAAAA,KAAQ,CAAC;AACjE,QAAI,CAACG,MAAMiB;AACTjB,YAAMiB,eAAe,CAAA;AACvBjB,UAAMiB,aAAaJ,KAAI,GAAII,YAAAA;AAC3Bb,sCAASR,QAAQC,KAAKG,KAAAA;EACxB;AACF;AAdgBgB;;;AFvET,SAASE,OAAOC,MAAcC,OAAe;AAClD,SAAO,CAACC,QAAaC,MAAmB;AACtCC,yCAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMI;AACTJ,YAAMI,SAAS,CAAC;AAElBJ,UAAMI,OAAOT,QAAQC;AACrBS,sCAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAVgBN;AAYT,SAASY,OAAOC,KAAaX,OAAY;AAC9C,SAAO,CAACC,QAAaC,MAAoB;AACvC,QAAI,CAACA,GAAG;AACNA,UAAI;AACJD,eAASA,OAAOW;IAClB;AAEAT,yCAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,sCAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;A5BNhB,wBAAc,wBARd;","names":["HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","handlers","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","post","req","_res","next","MERGE_SYMBOL","ServerContext","useMiddleware","res","body","category","data","contextData","request","response","isMerge","Array","isArray","json","useFilter","BadRequestException","tags","map","item","tag","context","ret","mergeGuards","Set","mergeInterceptors","forEach","guards","interceptors","Context","metaDataRecord","guard","add","intercept","useGuard","useInterceptor","name","split","reflect","params","instance","get","args","usePipe","type","key","validate","arg","resolveDep","startsWith","SERIES_SYMBOL","index","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","i","method","header","methodTag","parseMeta","bind","instanceRecord","set","isObject","send","String","import_phecda_core","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","import_phecda_core","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Patch","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
|
package/dist/index.mjs
CHANGED
|
@@ -44,8 +44,13 @@ var defaultPipe = {
|
|
|
44
44
|
async transform(args, reflect) {
|
|
45
45
|
for (const i in args) {
|
|
46
46
|
const { validate, arg } = args[i];
|
|
47
|
-
if (validate === false
|
|
47
|
+
if (validate === false)
|
|
48
48
|
continue;
|
|
49
|
+
if (!reflect[i]) {
|
|
50
|
+
if (validate && arg)
|
|
51
|
+
args[i].arg = validate(arg);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
49
54
|
if (isPhecda(reflect[i])) {
|
|
50
55
|
const ret = await plainToClass(reflect[i], arg, {
|
|
51
56
|
transform: true
|
|
@@ -174,8 +179,12 @@ __name(FrameworkException, "FrameworkException");
|
|
|
174
179
|
|
|
175
180
|
// src/filter.ts
|
|
176
181
|
var serverFilter = /* @__PURE__ */ __name((e) => {
|
|
177
|
-
if (!(e instanceof HttpException))
|
|
182
|
+
if (!(e instanceof HttpException)) {
|
|
183
|
+
console.error(e.stack);
|
|
178
184
|
e = new UndefinedException(e.message || e);
|
|
185
|
+
} else {
|
|
186
|
+
console.error(e.message);
|
|
187
|
+
}
|
|
179
188
|
return e.data;
|
|
180
189
|
}, "serverFilter");
|
|
181
190
|
|
|
@@ -263,12 +272,13 @@ function getInstance(tag) {
|
|
|
263
272
|
}
|
|
264
273
|
__name(getInstance, "getInstance");
|
|
265
274
|
function parseMeta(meta) {
|
|
266
|
-
const { data: { params, guards, interceptors, middlewares }, reflect } = meta;
|
|
275
|
+
const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta;
|
|
267
276
|
return {
|
|
268
277
|
guards,
|
|
269
278
|
reflect,
|
|
270
279
|
interceptors,
|
|
271
280
|
middlewares,
|
|
281
|
+
handlers,
|
|
272
282
|
params: params.map((param) => {
|
|
273
283
|
const { type, key, validate } = param;
|
|
274
284
|
return {
|
|
@@ -356,13 +366,115 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
356
366
|
};
|
|
357
367
|
const methodMap = {};
|
|
358
368
|
const contextMeta = {};
|
|
369
|
+
app.post(route, (req, _res, next) => {
|
|
370
|
+
req[MERGE_SYMBOL] = true;
|
|
371
|
+
next();
|
|
372
|
+
}, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {
|
|
373
|
+
const { body: { category, data } } = req;
|
|
374
|
+
const contextData = {
|
|
375
|
+
request: req,
|
|
376
|
+
response: res,
|
|
377
|
+
meta: contextMeta,
|
|
378
|
+
isMerge: true
|
|
379
|
+
};
|
|
380
|
+
if (!Array.isArray(data))
|
|
381
|
+
return res.json(await ServerContext.useFilter(new BadRequestException("data format should be an array"), contextData));
|
|
382
|
+
if (category !== "series" && category !== "parallel")
|
|
383
|
+
return res.json(await ServerContext.useFilter(new BadRequestException("category should be 'parallel' or 'series'"), contextData));
|
|
384
|
+
contextData.tags = data.map((item) => item.tag);
|
|
385
|
+
const context = new ServerContext(route, contextData);
|
|
386
|
+
const ret = [];
|
|
387
|
+
try {
|
|
388
|
+
const mergeGuards = /* @__PURE__ */ new Set([
|
|
389
|
+
...globalGuards
|
|
390
|
+
]);
|
|
391
|
+
const mergeInterceptors = /* @__PURE__ */ new Set([
|
|
392
|
+
...globalInterceptors
|
|
393
|
+
]);
|
|
394
|
+
data.forEach(({ tag }) => {
|
|
395
|
+
const { guards, interceptors } = Context.metaDataRecord[tag];
|
|
396
|
+
guards.forEach((guard) => mergeGuards.add(guard));
|
|
397
|
+
interceptors.forEach((intercept) => mergeInterceptors.add(intercept));
|
|
398
|
+
});
|
|
399
|
+
await context.useGuard([
|
|
400
|
+
...mergeGuards
|
|
401
|
+
], true);
|
|
402
|
+
await context.useInterceptor([
|
|
403
|
+
...mergeInterceptors
|
|
404
|
+
], true);
|
|
405
|
+
if (category === "series") {
|
|
406
|
+
for (const item of data) {
|
|
407
|
+
const { tag } = item;
|
|
408
|
+
const [name] = tag.split("-");
|
|
409
|
+
const { reflect, params } = Context.metaDataRecord[tag];
|
|
410
|
+
const instance = moduleMap.get(name);
|
|
411
|
+
try {
|
|
412
|
+
if (!params)
|
|
413
|
+
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
414
|
+
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
415
|
+
const arg = resolveDep(item[type], key);
|
|
416
|
+
if (typeof arg === "string" && arg.startsWith(SERIES_SYMBOL)) {
|
|
417
|
+
const [, index, argKey] = arg.split("@");
|
|
418
|
+
return {
|
|
419
|
+
arg: resolveDep(ret[Number(index)], argKey || key),
|
|
420
|
+
validate
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
arg,
|
|
425
|
+
validate
|
|
426
|
+
};
|
|
427
|
+
}), reflect);
|
|
428
|
+
instance.context = contextData;
|
|
429
|
+
ret.push(await methodMap[tag](...args));
|
|
430
|
+
} catch (e) {
|
|
431
|
+
const m = Context.metaRecord[tag];
|
|
432
|
+
m.handlers.forEach((handler) => handler.error?.(e));
|
|
433
|
+
ret.push(await context.useFilter(e));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return res.json(await context.usePost(ret));
|
|
437
|
+
}
|
|
438
|
+
if (category === "parallel") {
|
|
439
|
+
return Promise.all(data.map((item) => {
|
|
440
|
+
return new Promise(async (resolve) => {
|
|
441
|
+
const { tag } = item;
|
|
442
|
+
const [name] = tag.split("-");
|
|
443
|
+
const { reflect, params, handlers } = Context.metaDataRecord[tag];
|
|
444
|
+
const instance = moduleMap.get(name);
|
|
445
|
+
try {
|
|
446
|
+
if (!params)
|
|
447
|
+
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
448
|
+
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
449
|
+
const arg = resolveDep(item[type], key);
|
|
450
|
+
return {
|
|
451
|
+
arg,
|
|
452
|
+
validate
|
|
453
|
+
};
|
|
454
|
+
}), reflect);
|
|
455
|
+
instance.context = contextData;
|
|
456
|
+
resolve(await methodMap[tag](...args));
|
|
457
|
+
} catch (e) {
|
|
458
|
+
handlers.forEach((handler) => handler.error?.(e));
|
|
459
|
+
resolve(await context.useFilter(e));
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
})).then(async (ret2) => {
|
|
463
|
+
res.json(await context.usePost(ret2));
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
} catch (e) {
|
|
467
|
+
const err = await context.useFilter(e);
|
|
468
|
+
res.status(err.status).json(err);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
359
471
|
for (const i of meta) {
|
|
360
472
|
const { name, method, route: route2, header, tag } = i.data;
|
|
361
473
|
const instance = moduleMap.get(tag);
|
|
362
474
|
const methodTag = `${tag}-${method}`;
|
|
363
475
|
contextMeta[methodTag] = i;
|
|
364
476
|
Context.metaRecord[methodTag] = i;
|
|
365
|
-
let { guards, reflect, interceptors, params, middlewares } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : Context.metaDataRecord[methodTag] = parseMeta(i);
|
|
477
|
+
let { guards, reflect, interceptors, params, handlers, middlewares } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : Context.metaDataRecord[methodTag] = parseMeta(i);
|
|
366
478
|
guards = [
|
|
367
479
|
...globalGuards,
|
|
368
480
|
...guards
|
|
@@ -400,97 +512,13 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
400
512
|
else
|
|
401
513
|
res.send(String(ret));
|
|
402
514
|
} catch (e) {
|
|
403
|
-
|
|
515
|
+
handlers.forEach((handler2) => handler2.error?.(e));
|
|
404
516
|
const err = await context.useFilter(e);
|
|
405
517
|
res.status(err.status).json(err);
|
|
406
518
|
}
|
|
407
519
|
});
|
|
408
520
|
}
|
|
409
521
|
}
|
|
410
|
-
app.post(route, (req, _res, next) => {
|
|
411
|
-
req[MERGE_SYMBOL] = true;
|
|
412
|
-
next();
|
|
413
|
-
}, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {
|
|
414
|
-
const { body: { category, data } } = req;
|
|
415
|
-
const contextData = {
|
|
416
|
-
request: req,
|
|
417
|
-
response: res,
|
|
418
|
-
meta: contextMeta,
|
|
419
|
-
isMerge: true
|
|
420
|
-
};
|
|
421
|
-
if (!Array.isArray(data))
|
|
422
|
-
return res.json(await ServerContext.useFilter(new BadRequestException("data format should be an array"), contextData));
|
|
423
|
-
contextData.tags = data.map((item) => item.tag);
|
|
424
|
-
const context = new ServerContext(route, contextData);
|
|
425
|
-
const ret = [];
|
|
426
|
-
if (category === "series") {
|
|
427
|
-
for (const item of data) {
|
|
428
|
-
const { tag } = item;
|
|
429
|
-
const [name] = tag.split("-");
|
|
430
|
-
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
431
|
-
const instance = moduleMap.get(name);
|
|
432
|
-
try {
|
|
433
|
-
if (!params)
|
|
434
|
-
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
435
|
-
await context.useGuard(guards, true);
|
|
436
|
-
await context.useInterceptor(interceptors, true);
|
|
437
|
-
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
438
|
-
const arg = resolveDep(item[type], key);
|
|
439
|
-
if (typeof arg === "string" && arg.startsWith(SERIES_SYMBOL)) {
|
|
440
|
-
const [, index, argKey] = arg.split("@");
|
|
441
|
-
return {
|
|
442
|
-
arg: resolveDep(ret[Number(index)], argKey || key),
|
|
443
|
-
validate
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
arg,
|
|
448
|
-
validate
|
|
449
|
-
};
|
|
450
|
-
}), reflect);
|
|
451
|
-
instance.context = contextData;
|
|
452
|
-
ret.push(await context.usePost(await methodMap[tag](...args)));
|
|
453
|
-
} catch (e) {
|
|
454
|
-
const m = Context.metaRecord[tag];
|
|
455
|
-
m.handlers.forEach((handler) => handler.error?.(e));
|
|
456
|
-
ret.push(await context.useFilter(e));
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
return res.json(ret);
|
|
460
|
-
}
|
|
461
|
-
if (category === "parallel") {
|
|
462
|
-
return Promise.all(data.map((item) => {
|
|
463
|
-
return new Promise(async (resolve) => {
|
|
464
|
-
const { tag } = item;
|
|
465
|
-
const [name] = tag.split("-");
|
|
466
|
-
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
467
|
-
const instance = moduleMap.get(name);
|
|
468
|
-
try {
|
|
469
|
-
if (!params)
|
|
470
|
-
throw new BadRequestException(`"${tag}" doesn't exist`);
|
|
471
|
-
await context.useGuard(guards, true);
|
|
472
|
-
await context.useInterceptor(interceptors, true);
|
|
473
|
-
const args = await context.usePipe(params.map(({ type, key, validate }) => {
|
|
474
|
-
const arg = resolveDep(item[type], key);
|
|
475
|
-
return {
|
|
476
|
-
arg,
|
|
477
|
-
validate
|
|
478
|
-
};
|
|
479
|
-
}), reflect);
|
|
480
|
-
instance.context = contextData;
|
|
481
|
-
resolve(await context.usePost(await methodMap[tag](...args)));
|
|
482
|
-
} catch (e) {
|
|
483
|
-
const m = Context.metaRecord[tag];
|
|
484
|
-
m.handlers.forEach((handler) => handler.error?.(e));
|
|
485
|
-
resolve(await context.useFilter(e));
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
})).then((ret2) => {
|
|
489
|
-
res.json(ret2);
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
res.json(await context.useFilter(new BadRequestException("category should be 'parallel' or 'series'")));
|
|
493
|
-
});
|
|
494
522
|
}
|
|
495
523
|
__name(bindApp, "bindApp");
|
|
496
524
|
|
|
@@ -694,6 +722,10 @@ function Put(route) {
|
|
|
694
722
|
return Route(route, "put");
|
|
695
723
|
}
|
|
696
724
|
__name(Put, "Put");
|
|
725
|
+
function Patch(route) {
|
|
726
|
+
return Route(route, "patch");
|
|
727
|
+
}
|
|
728
|
+
__name(Patch, "Patch");
|
|
697
729
|
function Delete(route) {
|
|
698
730
|
return Route(route, "delete");
|
|
699
731
|
}
|
|
@@ -800,6 +832,7 @@ export {
|
|
|
800
832
|
Middle,
|
|
801
833
|
NotFoundException,
|
|
802
834
|
Param,
|
|
835
|
+
Patch,
|
|
803
836
|
PayloadLargeException,
|
|
804
837
|
Post,
|
|
805
838
|
Put,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/index.ts"],"sourcesContent":["import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: boolean }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false || !reflect[i]/** work for undefined */)\n continue\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException))\n e = new UndefinedException(e.message || e)\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find guard named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n i.handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(ret)\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.json(ret)\n })\n }\n\n res.json(await context.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\'')))\n })\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n","export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n"],"mappings":";;;;;;;;;AAAA,SAASA,UAAUC,oBAAoB;;;ACAhC,IAAMC,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQI,OAAO;IAAK;EAClG;AACF;AARaP;;;ACEN,IAAMQ,oBAAN,cAAgCC,cAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;AFGN,IAAMI,cAAc;EAEzB,MAAMC,UAAUC,MAAyCC,SAAgB;AACvE,eAAWC,KAAKF,MAAM;AACpB,YAAM,EAAEG,UAAUC,IAAG,IAAKJ,KAAKE;AAC/B,UAAIC,aAAa,SAAS,CAACF,QAAQC;AACjC;AAEF,UAAIG,SAASJ,QAAQC,EAAE,GAAG;AACxB,cAAMI,MAAM,MAAMC,aAAaN,QAAQC,IAAIE,KAAK;UAAEL,WAAW;QAAK,CAAA;AAClE,YAAIO,IAAIE,IAAIC,SAAS;AACnB,gBAAM,IAAIC,kBAAkBJ,IAAIE,IAAI,EAAE;AACxCR,aAAKE,GAAGE,MAAME,IAAIK;MACpB,OACK;AACH,YAAI;UAACC;UAAQC;UAASC,SAASb,QAAQC,EAAE,GAAG;AAC1CF,eAAKE,GAAGE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QAAQC,GAAAA;AAEpB,UAAMG,QAAQJ,OAAOK,WAAWC,oBAAoBC,IAAIN,GAAAA,KAAQ,CAAC;AACjE,QAAI,CAACG,MAAMgB;AACThB,YAAMgB,eAAe,CAAA;AACvBhB,UAAMgB,aAAaJ,KAAI,GAAII,YAAAA;AAC3BZ,IAAAA,UAASR,QAAQC,KAAKG,KAAAA;EACxB;AACF;AAdgBe;;;AFpET,SAASE,OAAOC,MAAcC,OAAe;AAClD,SAAO,CAACC,QAAaC,MAAmB;AACtCC,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMI;AACTJ,YAAMI,SAAS,CAAC;AAElBJ,UAAMI,OAAOT,QAAQC;AACrBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAVgBN;AAYT,SAASY,OAAOC,KAAaX,OAAY;AAC9C,SAAO,CAACC,QAAaC,MAAoB;AACvC,QAAI,CAACA,GAAG;AACNA,UAAI;AACJD,eAASA,OAAOW;IAClB;AAEAT,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;AGNhB,cAAc;","names":["isPhecda","plainToClass","HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","i","name","method","header","tag","data","instance","get","methodTag","Context","metaRecord","guards","reflect","interceptors","params","metaDataRecord","parseMeta","handler","bind","instanceRecord","type","ServerContext","useMiddleware","req","res","contextData","request","response","context","set","useGuard","useInterceptor","args","usePipe","map","key","validate","arg","resolveDep","ret","usePost","isObject","json","send","String","e","handlers","forEach","error","err","useFilter","status","post","_res","next","MERGE_SYMBOL","body","category","isMerge","Array","isArray","BadRequestException","tags","item","split","startsWith","SERIES_SYMBOL","index","argKey","Number","push","m","Promise","all","resolve","then","fs","EventEmitter","getExposeKey","getHandler","getState","injectProperty","registerAsync","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","setModelVar","setState","setModelVar","setState","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","setModelVar","setState","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
|
|
1
|
+
{"version":3,"sources":["../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/index.ts"],"sourcesContent":["import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: any }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (!reflect[i]) {\n if (validate && arg)\n args[i].arg = validate(arg)\n\n continue\n }\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException)) {\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n console.error(e.message)\n }\n\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find guard named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n if (category !== 'series' && category !== 'parallel')\n return res.json(await ServerContext.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\''), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n try {\n const mergeGuards = new Set([...globalGuards])\n const mergeInterceptors = new Set([...globalInterceptors])\n\n data.forEach(({ tag }) => {\n const {\n guards,\n interceptors,\n } = Context.metaDataRecord[tag]\n guards.forEach(guard => mergeGuards.add(guard))\n interceptors.forEach(intercept => mergeInterceptors.add(intercept))\n })\n await context.useGuard([...mergeGuards], true)\n await context.useInterceptor([...mergeInterceptors], true)\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await methodMap[tag](...args))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(await context.usePost(ret))\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n handlers,\n } = Context.metaDataRecord[tag]\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await methodMap[tag](...args))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then(async (ret) => {\n res.json(await context.usePost(ret))\n })\n }\n }\n catch (e) {\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n handlers,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Patch(route: string) {\n return Route(route, 'patch')\n}\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n","export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n"],"mappings":";;;;;;;;;AAAA,SAASA,UAAUC,oBAAoB;;;ACAhC,IAAMC,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQI,OAAO;IAAK;EAClG;AACF;AARaP;;;ACEN,IAAMQ,oBAAN,cAAgCC,cAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;AFGN,IAAMI,cAAc;EAEzB,MAAMC,UAAUC,MAAqCC,SAAgB;AACnE,eAAWC,KAAKF,MAAM;AACpB,YAAM,EAAEG,UAAUC,IAAG,IAAKJ,KAAKE;AAC/B,UAAIC,aAAa;AACf;AACF,UAAI,CAACF,QAAQC,IAAI;AACf,YAAIC,YAAYC;AACdJ,eAAKE,GAAGE,MAAMD,SAASC,GAAAA;AAEzB;MACF;AAEA,UAAIC,SAASJ,QAAQC,EAAE,GAAG;AACxB,cAAMI,MAAM,MAAMC,aAAaN,QAAQC,IAA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WC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMI;AACTJ,YAAMI,SAAS,CAAC;AAElBJ,UAAMI,OAAOT,QAAQC;AACrBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAVgBN;AAYT,SAASY,OAAOC,KAAaX,OAAY;AAC9C,SAAO,CAACC,QAAaC,MAAoB;AACvC,QAAI,CAACA,GAAG;AACNA,UAAI;AACJD,eAASA,OAAOW;IAClB;AAEAT,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;AGNhB,cAAc;","names":["isPhecda","plainToClass","HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","handlers","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","post","req","_res","next","MERGE_SYMBOL","ServerContext","useMiddleware","res","body","category","data","contextData","request","response","isMerge","Array","isArray","json","useFilter","BadRequestException","tags","map","item","tag","context","ret","mergeGuards","Set","mergeInterceptors","forEach","guards","interceptors","Context","metaDataRecord","guard","add","intercept","useGuard","useInterceptor","name","split","reflect","params","instance","get","args","usePipe","type","key","validate","arg","resolveDep","startsWith","SERIES_SYMBOL","index","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","i","method","header","methodTag","parseMeta","bind","instanceRecord","set","isObject","send","String","fs","EventEmitter","getExposeKey","getHandler","getState","injectProperty","registerAsync","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","setModelVar","setState","setModelVar","setState","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","setModelVar","setState","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Patch","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-server",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "provide express middlewares, `nestjs` format",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"ps": "bin/cli.js"
|
|
10
|
+
},
|
|
8
11
|
"keywords": [
|
|
9
12
|
"server",
|
|
10
13
|
"express",
|
|
@@ -13,7 +16,8 @@
|
|
|
13
16
|
],
|
|
14
17
|
"author": "",
|
|
15
18
|
"files": [
|
|
16
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"bin"
|
|
17
21
|
],
|
|
18
22
|
"license": "MIT",
|
|
19
23
|
"devDependencies": {
|