phecda-server 3.2.0-alpha.1 → 3.2.0-alpha.3

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  const { exec } = require('child_process')
2
2
  const pc = require('picocolors')
3
+ const kill = require('tree-kill')
3
4
  const cmd = process.argv.slice(2)[0]
5
+
4
6
  let child
5
7
  function startChild() {
6
8
  child = exec(`node --import phecda-server/register ${cmd}`, {
@@ -11,23 +13,47 @@ function startChild() {
11
13
  child.stdin.pipe(process.stdin)
12
14
  child.stdout.pipe(process.stdout)
13
15
 
14
- child.on('exit', (code) => {
15
- if (code === 3) {
16
+ child.once('exit', (code) => {
17
+ if (code >= 2) {
16
18
  log('relunch...')
17
- return startChild()
19
+ startChild()
18
20
  }
19
-
20
- process.exit(0)
21
+ child = undefined
21
22
  })
22
23
  }
23
24
 
24
25
  process.on('SIGINT', () => {
25
- child.kill('SIGINT')
26
+ process.exit()
26
27
  })
27
28
 
29
+ function exit() {
30
+ if (child) {
31
+ kill(child.pid, () => {
32
+ process.exit(0)
33
+ })
34
+ }
35
+ else {
36
+ process.exit(0)
37
+ }
38
+ }
39
+
28
40
  function log(msg, color = 'green') {
29
41
  const date = new Date()
30
- console.log(`${pc.gray(`${date.getHours()} ${date.getMinutes()} ${date.getSeconds()}`)} ${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)
42
+ console.log(`${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)
31
43
  }
32
44
 
33
45
  startChild()
46
+
47
+ process.stdin.on('data', (data) => {
48
+ const input = data.toString().trim().toLocaleLowerCase()
49
+ if (input === 'r') {
50
+ if (child) {
51
+ kill(child.pid, () => {
52
+ log('relunch...')
53
+ startChild()
54
+ })
55
+ }
56
+ }
57
+ if (input === 'e')
58
+ exit()
59
+ })
package/dist/index.d.ts CHANGED
@@ -218,9 +218,11 @@ declare function addMiddleware(key: string, handler: RequestHandler): void;
218
218
  declare function useServerPipe(pipe: P.Pipe): void;
219
219
  declare function useServerFilter(filter: ServerFilter): void;
220
220
 
221
- declare const SERIES_SYMBOL = "__symbol_series__";
222
- declare const MERGE_SYMBOL = "__symbol_req__";
223
- declare const UNMOUNT_SYMBOL = "__symbol_unmount__";
221
+ declare const SERIES_SYMBOL = "__PS_SERIES__";
222
+ declare const MERGE_SYMBOL = "__PS_MERGE__";
223
+ declare const UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
224
+ declare const MODULE_SYMBOL = "__PS_MODULE__";
225
+ declare const META_SYMBOL = "__PS_META__";
224
226
 
225
227
  declare const emitter: Emitter;
226
228
  declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
@@ -248,6 +250,7 @@ declare function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<Ret
248
250
 
249
251
  declare function BaseParam(type: string, key: string, option?: any): any;
250
252
  declare function Body(key?: string, pipeOpts?: any): any;
253
+ declare function Head(key: string, pipeOpts?: any): any;
251
254
  declare function Query(key?: string, pipeOpts?: any): any;
252
255
  declare function Param(key: string, pipeOpts?: any): any;
253
256
 
@@ -270,4 +273,4 @@ declare const defaultPipe: P.Pipe;
270
273
  declare function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx;
271
274
  declare function resolveDep(ret: any, key: string): any;
272
275
 
273
- export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Dev, 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, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
276
+ export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Dev, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Head, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, META_SYMBOL, MODULE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
package/dist/index.js CHANGED
@@ -49,11 +49,14 @@ __export(src_exports, {
49
49
  FrameworkException: () => FrameworkException,
50
50
  Get: () => Get,
51
51
  Guard: () => Guard,
52
+ Head: () => Head,
52
53
  Header: () => Header,
53
54
  HttpException: () => HttpException,
54
55
  Interceptor: () => Interceptor,
55
56
  InvalidInputException: () => InvalidInputException,
56
57
  MERGE_SYMBOL: () => MERGE_SYMBOL,
58
+ META_SYMBOL: () => META_SYMBOL,
59
+ MODULE_SYMBOL: () => MODULE_SYMBOL,
57
60
  Meta: () => Meta,
58
61
  Middle: () => Middle,
59
62
  NotFoundException: () => NotFoundException,
@@ -87,9 +90,6 @@ __export(src_exports, {
87
90
  });
88
91
  module.exports = __toCommonJS(src_exports);
89
92
 
90
- // src/pipe.ts
91
- var import_phecda_core = require("phecda-core");
92
-
93
93
  // src/exception/base.ts
94
94
  var HttpException = class extends Error {
95
95
  message;
@@ -112,48 +112,6 @@ var HttpException = class extends Error {
112
112
  };
113
113
  __name(HttpException, "HttpException");
114
114
 
115
- // src/exception/validate.ts
116
- var ValidateException = class extends HttpException {
117
- constructor(message) {
118
- super(message, 400, "Validate exception");
119
- }
120
- };
121
- __name(ValidateException, "ValidateException");
122
-
123
- // src/pipe.ts
124
- var defaultPipe = {
125
- async transform(args) {
126
- for (const i in args) {
127
- const { option, arg, reflect } = args[i];
128
- if (option === false)
129
- continue;
130
- if (!reflect) {
131
- if (option && arg)
132
- args[i].arg = option(arg);
133
- continue;
134
- }
135
- if ((0, import_phecda_core.isPhecda)(reflect)) {
136
- const ret = await (0, import_phecda_core.plainToClass)(reflect, arg, {
137
- transform: true
138
- });
139
- if (ret.err.length > 0)
140
- throw new ValidateException(ret.err[0]);
141
- args[i].arg = ret.data;
142
- } else {
143
- if ([
144
- Number,
145
- Boolean
146
- ].includes(reflect)) {
147
- args[i].arg = reflect(arg);
148
- if (reflect === Number && Object.is(args[i].arg, NaN))
149
- throw new ValidateException(`parameter ${Number(i) + 1} should be a number`);
150
- }
151
- }
152
- }
153
- return args.map((item) => item.arg);
154
- }
155
- };
156
-
157
115
  // src/exception/undefine.ts
158
116
  var UndefinedException = class extends HttpException {
159
117
  constructor(message) {
@@ -162,6 +120,14 @@ var UndefinedException = class extends HttpException {
162
120
  };
163
121
  __name(UndefinedException, "UndefinedException");
164
122
 
123
+ // src/exception/validate.ts
124
+ var ValidateException = class extends HttpException {
125
+ constructor(message) {
126
+ super(message, 400, "Validate exception");
127
+ }
128
+ };
129
+ __name(ValidateException, "ValidateException");
130
+
165
131
  // src/exception/forbidden.ts
166
132
  var ForbiddenException = class extends HttpException {
167
133
  constructor(message) {
@@ -258,6 +224,41 @@ var FrameworkException = class extends HttpException {
258
224
  };
259
225
  __name(FrameworkException, "FrameworkException");
260
226
 
227
+ // src/pipe.ts
228
+ var import_phecda_core = require("phecda-core");
229
+ var defaultPipe = {
230
+ async transform(args) {
231
+ for (const i in args) {
232
+ const { option, arg, reflect } = args[i];
233
+ if (option === false)
234
+ continue;
235
+ if (!reflect) {
236
+ if (option && arg)
237
+ args[i].arg = option(arg);
238
+ continue;
239
+ }
240
+ if ((0, import_phecda_core.isPhecda)(reflect)) {
241
+ const ret = await (0, import_phecda_core.plainToClass)(reflect, arg, {
242
+ transform: true
243
+ });
244
+ if (ret.err.length > 0)
245
+ throw new ValidateException(ret.err[0]);
246
+ args[i].arg = ret.data;
247
+ } else {
248
+ if ([
249
+ Number,
250
+ Boolean
251
+ ].includes(reflect)) {
252
+ args[i].arg = reflect(arg);
253
+ if (reflect === Number && Object.is(args[i].arg, NaN))
254
+ throw new ValidateException(`parameter ${Number(i) + 1} should be a number`);
255
+ }
256
+ }
257
+ }
258
+ return args.map((item) => item.arg);
259
+ }
260
+ };
261
+
261
262
  // src/filter.ts
262
263
  var serverFilter = /* @__PURE__ */ __name((e) => {
263
264
  if (!(e instanceof HttpException)) {
@@ -315,8 +316,11 @@ var _Context = class {
315
316
  async useGuard(guards, isMerge2 = false) {
316
317
  for (const guard of guards) {
317
318
  if (this.history.record(guard, "guard")) {
318
- if (!(guard in _Context.guardsRecord))
319
- throw new FrameworkException(`can't find guard named ${guard}`);
319
+ if (!(guard in _Context.guardsRecord)) {
320
+ if (process.env.PS_STRICT)
321
+ throw new FrameworkException(`can't find guard named '${guard}'`);
322
+ continue;
323
+ }
320
324
  if (!await _Context.guardsRecord[guard](this.data, isMerge2))
321
325
  throw new ForbiddenException(`Guard exception--${guard}`);
322
326
  }
@@ -326,8 +330,11 @@ var _Context = class {
326
330
  const ret = [];
327
331
  for (const interceptor of interceptors) {
328
332
  if (this.history.record(interceptor, "interceptor")) {
329
- if (!(interceptor in _Context.interceptorsRecord))
330
- throw new FrameworkException(`can't find interceptor named ${interceptor}`);
333
+ if (!(interceptor in _Context.interceptorsRecord)) {
334
+ if (process.env.PS_STRICT)
335
+ throw new FrameworkException(`can't find interceptor named '${interceptor}'`);
336
+ continue;
337
+ }
331
338
  const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge2);
332
339
  if (post)
333
340
  ret.push(post);
@@ -377,11 +384,16 @@ __name(parseMeta, "parseMeta");
377
384
  // src/context/server.ts
378
385
  var _ServerContext = class extends Context {
379
386
  static useMiddleware(middlewares) {
380
- return middlewares.map((m) => {
381
- if (!(m in _ServerContext.middlewareRecord))
382
- throw new FrameworkException(`can't find middleware named ${m}`);
383
- return _ServerContext.middlewareRecord[m];
384
- });
387
+ const ret = [];
388
+ for (const m of middlewares) {
389
+ if (!(m in _ServerContext.middlewareRecord)) {
390
+ if (process.env.PS_STRICT)
391
+ throw new FrameworkException(`can't find middleware named '${m}'`);
392
+ continue;
393
+ }
394
+ ret.push(_ServerContext.middlewareRecord[m]);
395
+ }
396
+ return ret;
385
397
  }
386
398
  async usePipe(args, tag) {
387
399
  return _ServerContext.pipe.transform?.(args, tag, this.data);
@@ -430,9 +442,11 @@ function resolveDep(ret, key) {
430
442
  __name(resolveDep, "resolveDep");
431
443
 
432
444
  // src/common.ts
433
- var SERIES_SYMBOL = "__symbol_series__";
434
- var MERGE_SYMBOL = "__symbol_req__";
435
- var UNMOUNT_SYMBOL = "__symbol_unmount__";
445
+ var SERIES_SYMBOL = "__PS_SERIES__";
446
+ var MERGE_SYMBOL = "__PS_MERGE__";
447
+ var UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
448
+ var MODULE_SYMBOL = "__PS_MODULE__";
449
+ var META_SYMBOL = "__PS_META__";
436
450
 
437
451
  // src/server/express.ts
438
452
  function bindApp(app, { moduleMap, meta }, options = {}) {
@@ -446,6 +460,8 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
446
460
  const contextMeta = {};
447
461
  app.post(route, (req, _res, next) => {
448
462
  req[MERGE_SYMBOL] = true;
463
+ req[MODULE_SYMBOL] = moduleMap;
464
+ req[META_SYMBOL] = meta;
449
465
  next();
450
466
  }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {
451
467
  const { body: { category, data } } = req;
@@ -575,7 +591,11 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
575
591
  ...interceptors
576
592
  ];
577
593
  if (route2) {
578
- app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
594
+ app[route2.type](route2.route, (req, _res, next) => {
595
+ req[MODULE_SYMBOL] = moduleMap;
596
+ req[META_SYMBOL] = meta;
597
+ next();
598
+ }, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
579
599
  const instance = moduleMap.get(tag);
580
600
  const contextData = {
581
601
  request: req,
@@ -617,8 +637,8 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
617
637
  __name(createRoute, "createRoute");
618
638
  createRoute();
619
639
  if (dev) {
620
- const rawMetaHmr = globalThis.__PHECDA_SERVER_META__;
621
- globalThis.__PHECDA_SERVER_META__ = () => {
640
+ const rawMetaHmr = globalThis.__PS_WRITEMETA__;
641
+ globalThis.__PS_WRITEMETA__ = () => {
622
642
  app.stack = app.stack.slice(0, 1);
623
643
  Context.metaDataRecord = {};
624
644
  createRoute();
@@ -743,7 +763,7 @@ async function Factory(Modules, opts = {}) {
743
763
  __name(writeMeta, "writeMeta");
744
764
  writeMeta();
745
765
  if (dev) {
746
- globalThis.__PHECDA_SERVER_HMR__ = async (file2) => {
766
+ globalThis.__PS_HMR__ = async (file2) => {
747
767
  debug(`reload file ${file2}`);
748
768
  const module2 = await import(file2);
749
769
  for (const i in module2) {
@@ -751,7 +771,7 @@ async function Factory(Modules, opts = {}) {
751
771
  await update(module2[i]);
752
772
  }
753
773
  };
754
- globalThis.__PHECDA_SERVER_META__ = writeMeta;
774
+ globalThis.__PS_WRITEMETA__ = writeMeta;
755
775
  }
756
776
  return {
757
777
  moduleMap,
@@ -865,6 +885,10 @@ function Body(key = "", pipeOpts) {
865
885
  return BaseParam("body", key, pipeOpts);
866
886
  }
867
887
  __name(Body, "Body");
888
+ function Head(key, pipeOpts) {
889
+ return BaseParam("headers", key.toLowerCase(), pipeOpts);
890
+ }
891
+ __name(Head, "Head");
868
892
  function Query(key = "", pipeOpts) {
869
893
  return BaseParam("query", key, pipeOpts);
870
894
  }
@@ -1006,11 +1030,14 @@ __reExport(src_exports, require("phecda-core"), module.exports);
1006
1030
  FrameworkException,
1007
1031
  Get,
1008
1032
  Guard,
1033
+ Head,
1009
1034
  Header,
1010
1035
  HttpException,
1011
1036
  Interceptor,
1012
1037
  InvalidInputException,
1013
1038
  MERGE_SYMBOL,
1039
+ META_SYMBOL,
1040
+ MODULE_SYMBOL,
1014
1041
  Meta,
1015
1042
  Middle,
1016
1043
  NotFoundException,
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/utils.ts","../src/context/base.ts","../src/context/server.ts","../src/types.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: any[]) {\n for (const i in args) {\n const { option, arg, reflect } = args[i]\n if (option === false)\n continue\n if (!reflect) {\n if (option && arg)\n args[i].arg = option(arg)\n\n continue\n }\n\n if (isPhecda(reflect)) {\n const ret = await plainToClass(reflect, 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)) {\n args[i].arg = reflect(arg)\n\n if (reflect === 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 Histroy {\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 pc from 'picocolors'\nexport 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\nexport function warn(msg: string, color = 'yellow') {\n // @ts-expect-error pc\n console.warn(`${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Histroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\nimport { warn } from '../utils'\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 guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Histroy()\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 interceptor 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}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n\n params.forEach(({ index, key }, i) => {\n if (index !== i)\n warn(`the ${i + 1}th argument on the method '${key}' require decorator`)\n })\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params,\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; option?: any; type: string;key: string;index: number; reflect: any }[], tag: string) {\n return ServerContext.pipe.transform?.(args, tag, 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 moduleMap: Record<string, any>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\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\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; option?: any }[]\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; option?: any; key: string; type: string; index: number; reflect: any }[], tag: string, ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\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__'\nexport const UNMOUNT_SYMBOL = '__symbol_unmount__'\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 dev?: boolean\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件(work for merge request),全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { dev = process.env.NODE_ENV !== 'production', globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n\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 moduleMap,\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, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, argIndex, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(argIndex)], argKey || key), option, index, type, key, reflect: reflect[index] }\n }\n\n return { arg, option, index, type, key, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n\n ret.push(await moduleMap.get(name)[method](...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, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n return { arg, type, key, option, index, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n resolve(await moduleMap.get(name)[method](...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\n async function createRoute() {\n for (const i of meta) {\n const { method, route, header, tag } = i.data\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n\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 if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const instance = moduleMap.get(tag)!\n const contextData = {\n request: req,\n meta: i,\n response: res,\n moduleMap,\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, option, index }) => {\n return { arg: resolveDep((req as any)[type], key), option, key, type, index, reflect: reflect[index] }\n }), methodTag)\n instance.context = contextData\n\n const ret = await context.usePost(await instance[method](...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\n createRoute()\n if (dev) {\n // @ts-expect-error globalThis\n const rawMetaHmr = globalThis.__PHECDA_SERVER_META__\n // @ts-expect-error globalThis\n\n globalThis.__PHECDA_SERVER_META__ = () => {\n app.stack = app.stack.slice(0, 1)\n Context.metaDataRecord = {}\n\n createRoute()\n rawMetaHmr?.()\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, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { warn } from './utils'\nimport { UNMOUNT_SYMBOL } from './common'\n\nconst debug = Debug('phecda-server')\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)[], opts: {\n dev?: boolean\n file?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n const moduleGraph = new Map<string, Set<string>>()\n const { dev = process.env.NODE_ENV !== 'production', file = 'pmeta.js' } = opts\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 async function update(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n if (!moduleMap.has(tag))\n return\n debug(`update module \"${tag}\"`)\n\n const instance = moduleMap.get(tag)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n const { instance: newModule } = await buildNestModule(Module)\n if (moduleGraph.has(tag)) {\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === instance)\n module[key] = newModule\n }\n })\n }\n\n moduleMap.set(tag, newModule)\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.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 if (constructorMap.get(tag) !== Module)\n warn(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`)\n\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n await registerAsync(instance)\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeMeta() {\n debug('write metadata')\n fs.promises.writeFile(file, JSON.stringify(meta.map(item => item.data)))\n }\n\n writeMeta()\n if (dev) {\n // @ts-expect-error globalThis\n globalThis.__PHECDA_SERVER_HMR__ = async (file: string) => {\n debug(`reload file ${file}`)\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await update(module[i])\n }\n }\n // @ts-expect-error globalThis\n globalThis.__PHECDA_SERVER_META__ = writeMeta\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n update,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: 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 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\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\nexport class Dev {\n [UNMOUNT_SYMBOL]: (() => void)[] = []\n onUnmount(cb: () => void) {\n this[UNMOUNT_SYMBOL].push(cb)\n }\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, option?: 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, option })\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;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,MAAa;AAC3B,eAAWC,KAAKD,MAAM;AACpB,YAAM,EAAEE,QAAQC,KAAKC,Q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E,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","i","option","arg","reflect","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","Histroy","guard","interceptor","record","name","type","includes","push","isUndefined","obj","isNil","isObject","fn","warn","msg","color","console","pc","magenta","Context","key","data","method","params","post","history","constructor","Histroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","addGuard","addInterceptor","parseMeta","meta","middlewares","reflect","handlers","forEach","index","i","warn","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","tag","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","UNMOUNT_SYMBOL","bindApp","app","moduleMap","meta","options","dev","process","env","NODE_ENV","globalGuards","globalInterceptors","route","middlewares","proMiddle","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","method","split","reflect","params","instance","get","args","usePipe","type","key","option","index","arg","resolveDep","startsWith","SERIES_SYMBOL","argIndex","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","createRoute","i","header","methodTag","parseMeta","set","isObject","send","String","rawMetaHmr","globalThis","__PHECDA_SERVER_META__","stack","slice","import_phecda_core","Meta","data","handlers","reflect","constructor","debug","Debug","emitter","EventEmitter","Factory","Modules","opts","moduleMap","Map","meta","constructorMap","moduleGraph","dev","process","env","NODE_ENV","file","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","update","Module","tag","prototype","__TAG__","name","has","get","UNMOUNT_SYMBOL","cb","delete","i","length","data","splice","newModule","buildNestModule","forEach","module","set","paramtypes","getParamtypes","Error","warn","undefined","paramtypesInstances","sub","subTag","Set","add","push","getMetaFromInstance","registerAsync","writeMeta","fs","promises","writeFile","JSON","stringify","map","item","globalThis","__PHECDA_SERVER_HMR__","isPhecda","__PHECDA_SERVER_META__","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","guards","interceptors","Meta","getHandler","Reflect","getMetadata","Dev","onUnmount","import_phecda_core","import_phecda_core","BaseParam","type","key","option","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"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/exception/base.ts","../src/exception/undefine.ts","../src/exception/validate.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/pipe.ts","../src/filter.ts","../src/history.ts","../src/utils.ts","../src/context/base.ts","../src/context/server.ts","../src/types.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","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 UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\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 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 { 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: any[]) {\n for (const i in args) {\n const { option, arg, reflect } = args[i]\n if (option === false)\n continue\n if (!reflect) {\n if (option && arg)\n args[i].arg = option(arg)\n\n continue\n }\n\n if (isPhecda(reflect)) {\n const ret = await plainToClass(reflect, 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)) {\n args[i].arg = reflect(arg)\n\n if (reflect === 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","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 Histroy {\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 pc from 'picocolors'\nexport 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\nexport function warn(msg: string, color = 'yellow') {\n // @ts-expect-error pc\n console.warn(`${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Histroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\nimport { warn } from '../utils'\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 guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Histroy()\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 if (process.env.PS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\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 if (process.env.PS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\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}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n\n params.forEach(({ index, key }, i) => {\n if (index !== i)\n warn(`the ${i + 1}th argument on the method '${key}' require decorator`)\n })\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params,\n }\n}\n","import type { RequestHandler } from 'express'\nimport { FrameworkException } from '../exception'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\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 const ret = []\n for (const m of middlewares) {\n if (!(m in ServerContext.middlewareRecord)) {\n if (process.env.PS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(ServerContext.middlewareRecord[m])\n }\n return ret\n }\n\n async usePipe(args: { arg: any; option?: any; type: string;key: string;index: number; reflect: any }[], tag: string) {\n return ServerContext.pipe.transform?.(args, tag, 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 moduleMap: Record<string, any>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\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\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; option?: any }[]\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; option?: any; key: string; type: string; index: number; reflect: any }[], tag: string, ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\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 = '__PS_SERIES__'\nexport const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, META_SYMBOL, MODULE_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 dev?: boolean\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件(work for merge request),全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { dev = process.env.NODE_ENV !== 'production', globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true;\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n\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 moduleMap,\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\n const [name, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, argIndex, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(argIndex)], argKey || key), option, index, type, key, reflect: reflect[index] }\n }\n\n return { arg, option, index, type, key, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n\n ret.push(await moduleMap.get(name)[method](...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, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n return { arg, type, key, option, index, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n resolve(await moduleMap.get(name)[method](...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\n async function createRoute() {\n for (const i of meta) {\n const { method, route, header, tag } = i.data\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n\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 if (route) {\n (app as Express)[route.type](route.route, (req, _res, next) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n next()\n }, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const instance = moduleMap.get(tag)!\n const contextData = {\n request: req,\n meta: i,\n response: res,\n moduleMap,\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, option, index }) => {\n return { arg: resolveDep((req as any)[type], key), option, key, type, index, reflect: reflect[index] }\n }), methodTag)\n instance.context = contextData\n\n const ret = await context.usePost(await instance[method](...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\n createRoute()\n if (dev) {\n // @ts-expect-error globalThis\n const rawMetaHmr = globalThis.__PS_WRITEMETA__\n // @ts-expect-error globalThis\n\n globalThis.__PS_WRITEMETA__ = () => {\n app.stack = app.stack.slice(0, 1)\n Context.metaDataRecord = {}\n\n createRoute()\n rawMetaHmr?.()\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, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { warn } from './utils'\nimport { UNMOUNT_SYMBOL } from './common'\n\nconst debug = Debug('phecda-server')\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)[], opts: {\n dev?: boolean\n file?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n const moduleGraph = new Map<string, Set<string>>()\n const { dev = process.env.NODE_ENV !== 'production', file = 'pmeta.js' } = opts\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 async function update(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n if (!moduleMap.has(tag))\n return\n debug(`update module \"${tag}\"`)\n\n const instance = moduleMap.get(tag)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n const { instance: newModule } = await buildNestModule(Module)\n if (moduleGraph.has(tag)) {\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === instance)\n module[key] = newModule\n }\n })\n }\n\n moduleMap.set(tag, newModule)\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.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 if (constructorMap.get(tag) !== Module)\n warn(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`)\n\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n await registerAsync(instance)\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeMeta() {\n debug('write metadata')\n fs.promises.writeFile(file, JSON.stringify(meta.map(item => item.data)))\n }\n\n writeMeta()\n if (dev) {\n // @ts-expect-error globalThis\n globalThis.__PS_HMR__ = async (file: string) => {\n debug(`reload file ${file}`)\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await update(module[i])\n }\n }\n // @ts-expect-error globalThis\n globalThis.__PS_WRITEMETA__ = writeMeta\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n update,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: 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 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\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\nexport class Dev {\n [UNMOUNT_SYMBOL]: (() => void)[] = []\n onUnmount(cb: () => void) {\n this[UNMOUNT_SYMBOL].push(cb)\n }\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, option?: 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, option })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\n// req.headers\nexport function Head(key: string, pipeOpts?: any) {\n return BaseParam('headers', key.toLowerCase(), pipeOpts)\n}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;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L,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","UndefinedException","HttpException","constructor","message","ValidateException","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","defaultPipe","transform","args","i","option","arg","reflect","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Histroy","guard","interceptor","record","name","type","includes","push","isUndefined","obj","isNil","isObject","fn","warn","msg","color","console","pc","magenta","Context","key","data","method","params","post","history","constructor","Histroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","process","env","PS_STRICT","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","addGuard","addInterceptor","parseMeta","meta","middlewares","reflect","handlers","forEach","index","i","warn","ServerContext","Context","useMiddleware","middlewares","ret","m","middlewareRecord","process","env","PS_STRICT","FrameworkException","push","usePipe","args","tag","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","bindApp","app","moduleMap","meta","options","dev","process","env","NODE_ENV","globalGuards","globalInterceptors","route","middlewares","proMiddle","contextMeta","post","req","_res","next","MERGE_SYMBOL","MODULE_SYMBOL","META_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","method","split","reflect","params","instance","get","args","usePipe","type","key","option","index","arg","resolveDep","startsWith","SERIES_SYMBOL","argIndex","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","createRoute","i","header","methodTag","parseMeta","set","isObject","send","String","rawMetaHmr","globalThis","__PS_WRITEMETA__","stack","slice","import_phecda_core","Meta","data","handlers","reflect","constructor","debug","Debug","emitter","EventEmitter","Factory","Modules","opts","moduleMap","Map","meta","constructorMap","moduleGraph","dev","process","env","NODE_ENV","file","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","update","Module","tag","prototype","__TAG__","name","has","get","UNMOUNT_SYMBOL","cb","delete","i","length","data","splice","newModule","buildNestModule","forEach","module","set","paramtypes","getParamtypes","Error","warn","undefined","paramtypesInstances","sub","subTag","Set","add","push","getMetaFromInstance","registerAsync","writeMeta","fs","promises","writeFile","JSON","stringify","map","item","globalThis","__PS_HMR__","isPhecda","__PS_WRITEMETA__","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","guards","interceptors","Meta","getHandler","Reflect","getMetadata","Dev","onUnmount","import_phecda_core","import_phecda_core","BaseParam","type","key","option","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Head","toLowerCase","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
@@ -6,9 +6,6 @@ var __publicField = (obj, key, value) => {
6
6
  return value;
7
7
  };
8
8
 
9
- // src/pipe.ts
10
- import { isPhecda, plainToClass } from "phecda-core";
11
-
12
9
  // src/exception/base.ts
13
10
  var HttpException = class extends Error {
14
11
  message;
@@ -31,48 +28,6 @@ var HttpException = class extends Error {
31
28
  };
32
29
  __name(HttpException, "HttpException");
33
30
 
34
- // src/exception/validate.ts
35
- var ValidateException = class extends HttpException {
36
- constructor(message) {
37
- super(message, 400, "Validate exception");
38
- }
39
- };
40
- __name(ValidateException, "ValidateException");
41
-
42
- // src/pipe.ts
43
- var defaultPipe = {
44
- async transform(args) {
45
- for (const i in args) {
46
- const { option, arg, reflect } = args[i];
47
- if (option === false)
48
- continue;
49
- if (!reflect) {
50
- if (option && arg)
51
- args[i].arg = option(arg);
52
- continue;
53
- }
54
- if (isPhecda(reflect)) {
55
- const ret = await plainToClass(reflect, arg, {
56
- transform: true
57
- });
58
- if (ret.err.length > 0)
59
- throw new ValidateException(ret.err[0]);
60
- args[i].arg = ret.data;
61
- } else {
62
- if ([
63
- Number,
64
- Boolean
65
- ].includes(reflect)) {
66
- args[i].arg = reflect(arg);
67
- if (reflect === Number && Object.is(args[i].arg, NaN))
68
- throw new ValidateException(`parameter ${Number(i) + 1} should be a number`);
69
- }
70
- }
71
- }
72
- return args.map((item) => item.arg);
73
- }
74
- };
75
-
76
31
  // src/exception/undefine.ts
77
32
  var UndefinedException = class extends HttpException {
78
33
  constructor(message) {
@@ -81,6 +36,14 @@ var UndefinedException = class extends HttpException {
81
36
  };
82
37
  __name(UndefinedException, "UndefinedException");
83
38
 
39
+ // src/exception/validate.ts
40
+ var ValidateException = class extends HttpException {
41
+ constructor(message) {
42
+ super(message, 400, "Validate exception");
43
+ }
44
+ };
45
+ __name(ValidateException, "ValidateException");
46
+
84
47
  // src/exception/forbidden.ts
85
48
  var ForbiddenException = class extends HttpException {
86
49
  constructor(message) {
@@ -177,6 +140,41 @@ var FrameworkException = class extends HttpException {
177
140
  };
178
141
  __name(FrameworkException, "FrameworkException");
179
142
 
143
+ // src/pipe.ts
144
+ import { isPhecda, plainToClass } from "phecda-core";
145
+ var defaultPipe = {
146
+ async transform(args) {
147
+ for (const i in args) {
148
+ const { option, arg, reflect } = args[i];
149
+ if (option === false)
150
+ continue;
151
+ if (!reflect) {
152
+ if (option && arg)
153
+ args[i].arg = option(arg);
154
+ continue;
155
+ }
156
+ if (isPhecda(reflect)) {
157
+ const ret = await plainToClass(reflect, arg, {
158
+ transform: true
159
+ });
160
+ if (ret.err.length > 0)
161
+ throw new ValidateException(ret.err[0]);
162
+ args[i].arg = ret.data;
163
+ } else {
164
+ if ([
165
+ Number,
166
+ Boolean
167
+ ].includes(reflect)) {
168
+ args[i].arg = reflect(arg);
169
+ if (reflect === Number && Object.is(args[i].arg, NaN))
170
+ throw new ValidateException(`parameter ${Number(i) + 1} should be a number`);
171
+ }
172
+ }
173
+ }
174
+ return args.map((item) => item.arg);
175
+ }
176
+ };
177
+
180
178
  // src/filter.ts
181
179
  var serverFilter = /* @__PURE__ */ __name((e) => {
182
180
  if (!(e instanceof HttpException)) {
@@ -234,8 +232,11 @@ var _Context = class {
234
232
  async useGuard(guards, isMerge2 = false) {
235
233
  for (const guard of guards) {
236
234
  if (this.history.record(guard, "guard")) {
237
- if (!(guard in _Context.guardsRecord))
238
- throw new FrameworkException(`can't find guard named ${guard}`);
235
+ if (!(guard in _Context.guardsRecord)) {
236
+ if (process.env.PS_STRICT)
237
+ throw new FrameworkException(`can't find guard named '${guard}'`);
238
+ continue;
239
+ }
239
240
  if (!await _Context.guardsRecord[guard](this.data, isMerge2))
240
241
  throw new ForbiddenException(`Guard exception--${guard}`);
241
242
  }
@@ -245,8 +246,11 @@ var _Context = class {
245
246
  const ret = [];
246
247
  for (const interceptor of interceptors) {
247
248
  if (this.history.record(interceptor, "interceptor")) {
248
- if (!(interceptor in _Context.interceptorsRecord))
249
- throw new FrameworkException(`can't find interceptor named ${interceptor}`);
249
+ if (!(interceptor in _Context.interceptorsRecord)) {
250
+ if (process.env.PS_STRICT)
251
+ throw new FrameworkException(`can't find interceptor named '${interceptor}'`);
252
+ continue;
253
+ }
250
254
  const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge2);
251
255
  if (post)
252
256
  ret.push(post);
@@ -296,11 +300,16 @@ __name(parseMeta, "parseMeta");
296
300
  // src/context/server.ts
297
301
  var _ServerContext = class extends Context {
298
302
  static useMiddleware(middlewares) {
299
- return middlewares.map((m) => {
300
- if (!(m in _ServerContext.middlewareRecord))
301
- throw new FrameworkException(`can't find middleware named ${m}`);
302
- return _ServerContext.middlewareRecord[m];
303
- });
303
+ const ret = [];
304
+ for (const m of middlewares) {
305
+ if (!(m in _ServerContext.middlewareRecord)) {
306
+ if (process.env.PS_STRICT)
307
+ throw new FrameworkException(`can't find middleware named '${m}'`);
308
+ continue;
309
+ }
310
+ ret.push(_ServerContext.middlewareRecord[m]);
311
+ }
312
+ return ret;
304
313
  }
305
314
  async usePipe(args, tag) {
306
315
  return _ServerContext.pipe.transform?.(args, tag, this.data);
@@ -349,9 +358,11 @@ function resolveDep(ret, key) {
349
358
  __name(resolveDep, "resolveDep");
350
359
 
351
360
  // src/common.ts
352
- var SERIES_SYMBOL = "__symbol_series__";
353
- var MERGE_SYMBOL = "__symbol_req__";
354
- var UNMOUNT_SYMBOL = "__symbol_unmount__";
361
+ var SERIES_SYMBOL = "__PS_SERIES__";
362
+ var MERGE_SYMBOL = "__PS_MERGE__";
363
+ var UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
364
+ var MODULE_SYMBOL = "__PS_MODULE__";
365
+ var META_SYMBOL = "__PS_META__";
355
366
 
356
367
  // src/server/express.ts
357
368
  function bindApp(app, { moduleMap, meta }, options = {}) {
@@ -365,6 +376,8 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
365
376
  const contextMeta = {};
366
377
  app.post(route, (req, _res, next) => {
367
378
  req[MERGE_SYMBOL] = true;
379
+ req[MODULE_SYMBOL] = moduleMap;
380
+ req[META_SYMBOL] = meta;
368
381
  next();
369
382
  }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {
370
383
  const { body: { category, data } } = req;
@@ -494,7 +507,11 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
494
507
  ...interceptors
495
508
  ];
496
509
  if (route2) {
497
- app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
510
+ app[route2.type](route2.route, (req, _res, next) => {
511
+ req[MODULE_SYMBOL] = moduleMap;
512
+ req[META_SYMBOL] = meta;
513
+ next();
514
+ }, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
498
515
  const instance = moduleMap.get(tag);
499
516
  const contextData = {
500
517
  request: req,
@@ -536,8 +553,8 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
536
553
  __name(createRoute, "createRoute");
537
554
  createRoute();
538
555
  if (dev) {
539
- const rawMetaHmr = globalThis.__PHECDA_SERVER_META__;
540
- globalThis.__PHECDA_SERVER_META__ = () => {
556
+ const rawMetaHmr = globalThis.__PS_WRITEMETA__;
557
+ globalThis.__PS_WRITEMETA__ = () => {
541
558
  app.stack = app.stack.slice(0, 1);
542
559
  Context.metaDataRecord = {};
543
560
  createRoute();
@@ -662,7 +679,7 @@ async function Factory(Modules, opts = {}) {
662
679
  __name(writeMeta, "writeMeta");
663
680
  writeMeta();
664
681
  if (dev) {
665
- globalThis.__PHECDA_SERVER_HMR__ = async (file2) => {
682
+ globalThis.__PS_HMR__ = async (file2) => {
666
683
  debug(`reload file ${file2}`);
667
684
  const module = await import(file2);
668
685
  for (const i in module) {
@@ -670,7 +687,7 @@ async function Factory(Modules, opts = {}) {
670
687
  await update(module[i]);
671
688
  }
672
689
  };
673
- globalThis.__PHECDA_SERVER_META__ = writeMeta;
690
+ globalThis.__PS_WRITEMETA__ = writeMeta;
674
691
  }
675
692
  return {
676
693
  moduleMap,
@@ -784,6 +801,10 @@ function Body(key = "", pipeOpts) {
784
801
  return BaseParam("body", key, pipeOpts);
785
802
  }
786
803
  __name(Body, "Body");
804
+ function Head(key, pipeOpts) {
805
+ return BaseParam("headers", key.toLowerCase(), pipeOpts);
806
+ }
807
+ __name(Head, "Head");
787
808
  function Query(key = "", pipeOpts) {
788
809
  return BaseParam("query", key, pipeOpts);
789
810
  }
@@ -924,11 +945,14 @@ export {
924
945
  FrameworkException,
925
946
  Get,
926
947
  Guard,
948
+ Head,
927
949
  Header,
928
950
  HttpException,
929
951
  Interceptor,
930
952
  InvalidInputException,
931
953
  MERGE_SYMBOL,
954
+ META_SYMBOL,
955
+ MODULE_SYMBOL,
932
956
  Meta,
933
957
  Middle,
934
958
  NotFoundException,
@@ -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/utils.ts","../src/context/base.ts","../src/context/server.ts","../src/types.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: any[]) {\n for (const i in args) {\n const { option, arg, reflect } = args[i]\n if (option === false)\n continue\n if (!reflect) {\n if (option && arg)\n args[i].arg = option(arg)\n\n continue\n }\n\n if (isPhecda(reflect)) {\n const ret = await plainToClass(reflect, 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)) {\n args[i].arg = reflect(arg)\n\n if (reflect === 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 Histroy {\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 pc from 'picocolors'\nexport 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\nexport function warn(msg: string, color = 'yellow') {\n // @ts-expect-error pc\n console.warn(`${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Histroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\nimport { warn } from '../utils'\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 guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Histroy()\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 interceptor 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}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n\n params.forEach(({ index, key }, i) => {\n if (index !== i)\n warn(`the ${i + 1}th argument on the method '${key}' require decorator`)\n })\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params,\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; option?: any; type: string;key: string;index: number; reflect: any }[], tag: string) {\n return ServerContext.pipe.transform?.(args, tag, 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 moduleMap: Record<string, any>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\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\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; option?: any }[]\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; option?: any; key: string; type: string; index: number; reflect: any }[], tag: string, ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\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__'\nexport const UNMOUNT_SYMBOL = '__symbol_unmount__'\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 dev?: boolean\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件(work for merge request),全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { dev = process.env.NODE_ENV !== 'production', globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n\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 moduleMap,\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, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, argIndex, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(argIndex)], argKey || key), option, index, type, key, reflect: reflect[index] }\n }\n\n return { arg, option, index, type, key, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n\n ret.push(await moduleMap.get(name)[method](...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, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n return { arg, type, key, option, index, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n resolve(await moduleMap.get(name)[method](...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\n async function createRoute() {\n for (const i of meta) {\n const { method, route, header, tag } = i.data\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n\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 if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const instance = moduleMap.get(tag)!\n const contextData = {\n request: req,\n meta: i,\n response: res,\n moduleMap,\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, option, index }) => {\n return { arg: resolveDep((req as any)[type], key), option, key, type, index, reflect: reflect[index] }\n }), methodTag)\n instance.context = contextData\n\n const ret = await context.usePost(await instance[method](...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\n createRoute()\n if (dev) {\n // @ts-expect-error globalThis\n const rawMetaHmr = globalThis.__PHECDA_SERVER_META__\n // @ts-expect-error globalThis\n\n globalThis.__PHECDA_SERVER_META__ = () => {\n app.stack = app.stack.slice(0, 1)\n Context.metaDataRecord = {}\n\n createRoute()\n rawMetaHmr?.()\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, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { warn } from './utils'\nimport { UNMOUNT_SYMBOL } from './common'\n\nconst debug = Debug('phecda-server')\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)[], opts: {\n dev?: boolean\n file?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n const moduleGraph = new Map<string, Set<string>>()\n const { dev = process.env.NODE_ENV !== 'production', file = 'pmeta.js' } = opts\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 async function update(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n if (!moduleMap.has(tag))\n return\n debug(`update module \"${tag}\"`)\n\n const instance = moduleMap.get(tag)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n const { instance: newModule } = await buildNestModule(Module)\n if (moduleGraph.has(tag)) {\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === instance)\n module[key] = newModule\n }\n })\n }\n\n moduleMap.set(tag, newModule)\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.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 if (constructorMap.get(tag) !== Module)\n warn(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`)\n\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n await registerAsync(instance)\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeMeta() {\n debug('write metadata')\n fs.promises.writeFile(file, JSON.stringify(meta.map(item => item.data)))\n }\n\n writeMeta()\n if (dev) {\n // @ts-expect-error globalThis\n globalThis.__PHECDA_SERVER_HMR__ = async (file: string) => {\n debug(`reload file ${file}`)\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await update(module[i])\n }\n }\n // @ts-expect-error globalThis\n globalThis.__PHECDA_SERVER_META__ = writeMeta\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n update,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: 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 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\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\nexport class Dev {\n [UNMOUNT_SYMBOL]: (() => void)[] = []\n onUnmount(cb: () => void) {\n this[UNMOUNT_SYMBOL].push(cb)\n }\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, option?: 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, option })\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,IAAM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BS,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","i","option","arg","reflect","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","Histroy","guard","interceptor","record","name","type","includes","push","pc","isUndefined","obj","isNil","isObject","fn","warn","msg","color","console","pc","magenta","Context","key","data","method","params","post","history","constructor","Histroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","addGuard","addInterceptor","parseMeta","meta","middlewares","reflect","handlers","forEach","index","i","warn","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","tag","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","UNMOUNT_SYMBOL","bindApp","app","moduleMap","meta","options","dev","process","env","NODE_ENV","globalGuards","globalInterceptors","route","middlewares","proMiddle","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","method","split","reflect","params","instance","get","args","usePipe","type","key","option","index","arg","resolveDep","startsWith","SERIES_SYMBOL","argIndex","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","createRoute","i","header","methodTag","parseMeta","set","isObject","send","String","rawMetaHmr","globalThis","__PHECDA_SERVER_META__","stack","slice","fs","EventEmitter","getExposeKey","getHandler","getState","injectProperty","isPhecda","registerAsync","Debug","Meta","data","handlers","reflect","constructor","debug","Debug","emitter","EventEmitter","Factory","Modules","opts","moduleMap","Map","meta","constructorMap","moduleGraph","dev","process","env","NODE_ENV","file","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","update","Module","tag","prototype","__TAG__","name","has","get","UNMOUNT_SYMBOL","cb","delete","i","length","data","splice","newModule","buildNestModule","forEach","module","set","paramtypes","getParamtypes","Error","warn","undefined","paramtypesInstances","sub","subTag","Set","add","push","getMetaFromInstance","registerAsync","writeMeta","fs","promises","writeFile","JSON","stringify","map","item","globalThis","__PHECDA_SERVER_HMR__","isPhecda","__PHECDA_SERVER_META__","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","guards","interceptors","Meta","getHandler","Reflect","getMetadata","Dev","onUnmount","setModelVar","setState","setModelVar","setState","BaseParam","type","key","option","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"]}
1
+ {"version":3,"sources":["../src/exception/base.ts","../src/exception/undefine.ts","../src/exception/validate.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/pipe.ts","../src/filter.ts","../src/history.ts","../src/utils.ts","../src/context/base.ts","../src/context/server.ts","../src/types.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":["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 UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\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 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 { 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: any[]) {\n for (const i in args) {\n const { option, arg, reflect } = args[i]\n if (option === false)\n continue\n if (!reflect) {\n if (option && arg)\n args[i].arg = option(arg)\n\n continue\n }\n\n if (isPhecda(reflect)) {\n const ret = await plainToClass(reflect, 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)) {\n args[i].arg = reflect(arg)\n\n if (reflect === 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","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 Histroy {\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 pc from 'picocolors'\nexport 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\nexport function warn(msg: string, color = 'yellow') {\n // @ts-expect-error pc\n console.warn(`${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Histroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\nimport { warn } from '../utils'\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 guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Histroy()\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 if (process.env.PS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\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 if (process.env.PS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\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}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n\n params.forEach(({ index, key }, i) => {\n if (index !== i)\n warn(`the ${i + 1}th argument on the method '${key}' require decorator`)\n })\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params,\n }\n}\n","import type { RequestHandler } from 'express'\nimport { FrameworkException } from '../exception'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\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 const ret = []\n for (const m of middlewares) {\n if (!(m in ServerContext.middlewareRecord)) {\n if (process.env.PS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(ServerContext.middlewareRecord[m])\n }\n return ret\n }\n\n async usePipe(args: { arg: any; option?: any; type: string;key: string;index: number; reflect: any }[], tag: string) {\n return ServerContext.pipe.transform?.(args, tag, 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 moduleMap: Record<string, any>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\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\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; option?: any }[]\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; option?: any; key: string; type: string; index: number; reflect: any }[], tag: string, ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\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 = '__PS_SERIES__'\nexport const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, META_SYMBOL, MODULE_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 dev?: boolean\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件(work for merge request),全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { dev = process.env.NODE_ENV !== 'production', globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true;\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n\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 moduleMap,\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\n const [name, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, argIndex, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(argIndex)], argKey || key), option, index, type, key, reflect: reflect[index] }\n }\n\n return { arg, option, index, type, key, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n\n ret.push(await moduleMap.get(name)[method](...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, method] = 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, option, index }) => {\n const arg = resolveDep(item[type], key)\n return { arg, type, key, option, index, reflect: reflect[index] }\n }), tag) as any\n instance.context = contextData\n resolve(await moduleMap.get(name)[method](...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\n async function createRoute() {\n for (const i of meta) {\n const { method, route, header, tag } = i.data\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n\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 if (route) {\n (app as Express)[route.type](route.route, (req, _res, next) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n next()\n }, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const instance = moduleMap.get(tag)!\n const contextData = {\n request: req,\n meta: i,\n response: res,\n moduleMap,\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, option, index }) => {\n return { arg: resolveDep((req as any)[type], key), option, key, type, index, reflect: reflect[index] }\n }), methodTag)\n instance.context = contextData\n\n const ret = await context.usePost(await instance[method](...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\n createRoute()\n if (dev) {\n // @ts-expect-error globalThis\n const rawMetaHmr = globalThis.__PS_WRITEMETA__\n // @ts-expect-error globalThis\n\n globalThis.__PS_WRITEMETA__ = () => {\n app.stack = app.stack.slice(0, 1)\n Context.metaDataRecord = {}\n\n createRoute()\n rawMetaHmr?.()\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, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { warn } from './utils'\nimport { UNMOUNT_SYMBOL } from './common'\n\nconst debug = Debug('phecda-server')\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)[], opts: {\n dev?: boolean\n file?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n const moduleGraph = new Map<string, Set<string>>()\n const { dev = process.env.NODE_ENV !== 'production', file = 'pmeta.js' } = opts\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 async function update(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n if (!moduleMap.has(tag))\n return\n debug(`update module \"${tag}\"`)\n\n const instance = moduleMap.get(tag)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n const { instance: newModule } = await buildNestModule(Module)\n if (moduleGraph.has(tag)) {\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === instance)\n module[key] = newModule\n }\n })\n }\n\n moduleMap.set(tag, newModule)\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.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 if (constructorMap.get(tag) !== Module)\n warn(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`)\n\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n await registerAsync(instance)\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeMeta() {\n debug('write metadata')\n fs.promises.writeFile(file, JSON.stringify(meta.map(item => item.data)))\n }\n\n writeMeta()\n if (dev) {\n // @ts-expect-error globalThis\n globalThis.__PS_HMR__ = async (file: string) => {\n debug(`reload file ${file}`)\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await update(module[i])\n }\n }\n // @ts-expect-error globalThis\n globalThis.__PS_WRITEMETA__ = writeMeta\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n update,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: 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 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\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\nexport class Dev {\n [UNMOUNT_SYMBOL]: (() => void)[] = []\n onUnmount(cb: () => void) {\n this[UNMOUNT_SYMBOL].push(cb)\n }\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, option?: 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, option })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\n// req.headers\nexport function Head(key: string, pipeOpts?: any) {\n return BaseParam('headers', key.toLowerCase(), pipeOpts)\n}\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":";;;;;;;;;AAAO,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,KAAKA;MAAQI,OAAO;IAAK;EAClG;AACF;AARaP;;;ACEN,IAAMQ,qBAAN,cAAiCC,cAAAA;EACtCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,iBAAA;EACtB;AACF;AAJaH;;;ACAN,IAAMI,oBAAN,cAAgCC,cAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;ACAN,IAAMI,qBAAN,cAAiCC,cAAAA;EACtCC,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A;EACtB;AACF;AAfgBM;;;AGNhB,cAAc;","names":["HttpException","Error","message","status","description","constructor","data","error","UndefinedException","HttpException","constructor","message","ValidateException","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","isPhecda","plainToClass","defaultPipe","transform","args","i","option","arg","reflect","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Histroy","guard","interceptor","record","name","type","includes","push","pc","isUndefined","obj","isNil","isObject","fn","warn","msg","color","console","pc","magenta","Context","key","data","method","params","post","history","constructor","Histroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","process","env","PS_STRICT","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","addGuard","addInterceptor","parseMeta","meta","middlewares","reflect","handlers","forEach","index","i","warn","ServerContext","Context","useMiddleware","middlewares","ret","m","middlewareRecord","process","env","PS_STRICT","FrameworkException","push","usePipe","args","tag","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","bindApp","app","moduleMap","meta","options","dev","process","env","NODE_ENV","globalGuards","globalInterceptors","route","middlewares","proMiddle","contextMeta","post","req","_res","next","MERGE_SYMBOL","MODULE_SYMBOL","META_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","method","split","reflect","params","instance","get","args","usePipe","type","key","option","index","arg","resolveDep","startsWith","SERIES_SYMBOL","argIndex","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","createRoute","i","header","methodTag","parseMeta","set","isObject","send","String","rawMetaHmr","globalThis","__PS_WRITEMETA__","stack","slice","fs","EventEmitter","getExposeKey","getHandler","getState","injectProperty","isPhecda","registerAsync","Debug","Meta","data","handlers","reflect","constructor","debug","Debug","emitter","EventEmitter","Factory","Modules","opts","moduleMap","Map","meta","constructorMap","moduleGraph","dev","process","env","NODE_ENV","file","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","update","Module","tag","prototype","__TAG__","name","has","get","UNMOUNT_SYMBOL","cb","delete","i","length","data","splice","newModule","buildNestModule","forEach","module","set","paramtypes","getParamtypes","Error","warn","undefined","paramtypesInstances","sub","subTag","Set","add","push","getMetaFromInstance","registerAsync","writeMeta","fs","promises","writeFile","JSON","stringify","map","item","globalThis","__PS_HMR__","isPhecda","__PS_WRITEMETA__","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","guards","interceptors","Meta","getHandler","Reflect","getMetadata","Dev","onUnmount","setModelVar","setState","setModelVar","setState","BaseParam","type","key","option","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Head","toLowerCase","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,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "3.2.0-alpha.1",
3
+ "version": "3.2.0-alpha.3",
4
4
  "description": "provide express middlewares, `nestjs` format",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -44,6 +44,7 @@
44
44
  "debug": "^4.3.4",
45
45
  "picocolors": "^1.0.0",
46
46
  "reflect-metadata": "^0.1.13",
47
+ "tree-kill": "^1.2.2",
47
48
  "phecda-core": "2.0.1-alpha.0"
48
49
  },
49
50
  "scripts": {
@@ -11,7 +11,7 @@ register('./loader.mjs', {
11
11
  })
12
12
 
13
13
  port1.on('message', async (data) => {
14
- if (!globalThis.__PHECDA_SERVER_HMR__)
14
+ if (!globalThis.__PS_HMR__)
15
15
  return
16
16
 
17
17
  const { type, files } = JSON.parse(data)
@@ -19,11 +19,11 @@ port1.on('message', async (data) => {
19
19
  log('reload module...')
20
20
 
21
21
  for (const file of files.reverse())
22
- await globalThis.__PHECDA_SERVER_HMR__?.(file)
22
+ await globalThis.__PS_HMR__?.(file)
23
23
 
24
24
  log('reload done')
25
25
 
26
- await globalThis.__PHECDA_SERVER_META__?.()
26
+ await globalThis.__PS_WRITEMETA__?.()
27
27
  }
28
28
  })
29
29