phecda-server 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -169,12 +169,16 @@ import pc from "picocolors";
169
169
  // src/filter.ts
170
170
  var defaultFilter = /* @__PURE__ */ __name((e) => {
171
171
  if (!(e instanceof Exception)) {
172
- log(e.message, "error");
173
- console.error(e.stack);
172
+ if (IS_DEV) {
173
+ log(e.message, "error");
174
+ console.error(e.stack);
175
+ }
174
176
  e = new UndefinedException(e.message || e);
175
177
  } else {
176
- log(`[${e.constructor.name}] ${e.message}`, "error");
177
- console.error(e.stack);
178
+ if (IS_DEV) {
179
+ log(`[${e.constructor.name}] ${e.message}`, "error");
180
+ console.error(e.stack);
181
+ }
178
182
  }
179
183
  return e.data;
180
184
  }, "defaultFilter");
@@ -382,4 +386,4 @@ export {
382
386
  addInterceptor,
383
387
  isAopDepInject
384
388
  };
385
- //# sourceMappingURL=chunk-Z6LSJTOF.mjs.map
389
+ //# sourceMappingURL=chunk-MIIYJMMM.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/exception/base.ts","../src/exception/validate.ts","../src/pipe.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/context.ts","../src/filter.ts","../src/history.ts"],"sourcesContent":["import { ERROR_SYMBOL } from '../common'\n\nexport class Exception 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_SYMBOL]: true }\n }\n}\n","import { Exception } from './base'\n\nexport class ValidateException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { isPhecda, plainToClass, transformClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe: P.Pipe = async ({ arg, reflect, index }: any) => {\n if (isPhecda(reflect)) {\n const instance = plainToClass(reflect, arg)\n const err = await transformClass(instance)\n if (err.length > 0)\n throw new ValidateException(err[0])\n\n arg = instance\n }\n else {\n if ([Number, Boolean].includes(reflect)) {\n arg = reflect(arg)\n\n if (reflect === Number && Object.is(arg, NaN))\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\n }\n }\n return arg\n}\n","import { Exception } from './base'\n\nexport class UndefinedException extends Exception {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { Exception } from './base'\n\nexport class ForbiddenException extends Exception {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { Exception } from './base'\n\nexport class BadRequestException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { Exception } from './base'\n\nexport class NotFoundException extends Exception {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { Exception } from './base'\n\nexport class ConflictException extends Exception {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { Exception } from './base'\n\nexport class BadGatewayException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { Exception } from './base'\n\nexport class InvalidInputException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { Exception } from './base'\n\nexport class UnsupportedMediaTypeException extends Exception {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { Exception } from './base'\n\nexport class PayloadLargeException extends Exception {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { Exception } from './base'\n\nexport class TimeoutException extends Exception {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { Exception } from './base'\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { Exception } from './base'\n\nexport class ServiceUnavailableException extends Exception {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { Exception } from './base'\n\nexport class FrameworkException extends Exception {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import pc from 'picocolors'\nimport { defaultPipe } from './pipe'\nimport { ForbiddenException, FrameworkException } from './exception'\nimport { defaultFilter } from './filter'\nimport { Histroy } from './history'\nimport type { P } from './types'\nimport { IS_DEV, IS_STRICT } from './common'\nimport type { Meta } from './meta'\nimport { log } from './utils'\nexport const guardRecord = {} as Record<string, P.Guard>\n\nexport class Context<Data extends P.BaseContext> {\n method: string\n params: string[]\n history = new Histroy()\n\n static filterRecord: Record<string, P.Filter> = {\n default: defaultFilter,\n }\n\n static pipeRecord: Record<string, P.Pipe> = {\n default: defaultPipe,\n }\n\n static guardRecord: Record<string, P.Guard> = {}\n static interceptorRecord: Record<string, P.Interceptor> = {}\n\n static pluginRecord: Record<string, any> = {}\n postInterceptors: Function[]\n\n constructor(public data: Data) {\n if (IS_DEV)\n // @ts-expect-error work for debug\n data._context = this\n }\n\n usePipe(args: { arg: any; pipe?: string; pipeOpts?: any; type: string; key: string; index: number; reflect: any }[]) {\n return Promise.all(args.map((item) => {\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\n\n else\n return Context.pipeRecord.default(item, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.data)\n }))\n }\n\n useFilter(arg: any, filter = 'default') {\n if (!Context.filterRecord[filter]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find filter named '${filter}'`)\n else\n return Context.filterRecord.default(arg, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.data)\n }\n\n async useGuard(guards: string[]) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\n if (!await Context.guardRecord[guard](this.data))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async usePostInterceptor(ret: any) {\n for (const cb of this.postInterceptors)\n ret = await cb(ret) || ret\n\n return ret\n }\n\n async useInterceptor(interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\n const postInterceptor = await Context.interceptorRecord[interceptor](this.data)\n if (postInterceptor !== undefined) {\n if (typeof postInterceptor === 'function')\n ret.push(postInterceptor)\n\n else\n return postInterceptor\n }\n }\n }\n this.postInterceptors = ret\n }\n\n static usePlugin(plugins: string[]) {\n const ret = []\n for (const m of plugins) {\n if (!(m in Context.pluginRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(Context.pluginRecord[m])\n }\n return ret as any[]\n }\n}\nexport function addPlugin<T>(key: string, handler: T) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe<C extends P.BaseContext>(key: string, pipe: P.Pipe<C>) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter<C extends P.BaseContext>(key: string, handler: P.Filter<C>) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard<C extends P.BaseContext>(key: string, handler: P.Guard<C>) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor<C extends P.BaseContext>(key: string, handler: P.Interceptor<C>) {\n Context.interceptorRecord[key] = handler\n}\n\n// detect whether plugin/filter/pipe/guard/intercept is injected\nexport function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }: {\n guards?: string[]\n interceptors?: string[]\n plugins?: string[]\n} = {}) {\n\n if (!IS_DEV) return\n const pluginSet = new Set<string>(plugins)\n\n const guardSet = new Set<string>(guards)\n const interceptorSet = new Set<string>(interceptors)\n const pipeSet = new Set<string>()\n\n const filterSet = new Set<string>()\n meta.forEach(({ data }) => {\n if (data.filter)\n filterSet.add(data.filter)\n\n data.interceptors.forEach(i => interceptorSet.add(i))\n data.guards.forEach(i => guardSet.add(i))\n data.plugins.forEach(i => pluginSet.add(i))\n data.params.forEach((i) => {\n if (i.pipe)\n pipeSet.add(i.pipe)\n })\n })\n\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\n\n if (missPlugins.length)\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\n if (missGuards.length)\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missInterceptors.length)\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missPipes.length)\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missFilters.length)\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\n}\n","import { Exception, UndefinedException } from './exception'\nimport type { P } from './types'\nimport { log } from './utils'\n\nexport const defaultFilter: P.Filter = (e) => {\n if (!(e instanceof Exception)) {\n log(e.message, 'error')\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n log(`[${e.constructor.name}] ${e.message}`, 'error')\n console.error(e.stack)\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"],"mappings":";;;;;;;;;;AAEO,IAAMA,YAAN,cAAwBC,MAAAA;EACV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message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","Exception","constructor","message","isPhecda","plainToClass","transformClass","defaultPipe","arg","reflect","index","isPhecda","instance","plainToClass","err","transformClass","length","ValidateException","Number","Boolean","includes","Object","is","NaN","UndefinedException","Exception","constructor","message","ForbiddenException","Exception","constructor","message","BadRequestException","Exception","constructor","message","NotFoundException","Exception","constructor","message","ConflictException","Exception","constructor","message","BadGatewayException","Exception","constructor","message","InvalidInputException","Exception","constructor","message","UnsupportedMediaTypeException","Exception","constructor","message","PayloadLargeException","Exception","constructor","message","TimeoutException","Exception","constructor","message","UnauthorizedException","Exception","constructor","message","ServiceUnavailableException","Exception","constructor","message","FrameworkException","Exception","constructor","message","pc","defaultFilter","e","Exception","log","message","console","error","stack","UndefinedException","constructor","name","data","Histroy","guard","interceptor","record","name","type","includes","push","guardRecord","Context","data","method","params","history","postInterceptors","constructor","Histroy","IS_DEV","_context","usePipe","args","Promise","all","map","item","pipe","pipeRecord","IS_STRICT","FrameworkException","default","useFilter","arg","filter","filterRecord","useGuard","guards","guard","record","ForbiddenException","usePostInterceptor","ret","cb","useInterceptor","interceptors","interceptor","interceptorRecord","postInterceptor","undefined","push","usePlugin","plugins","m","pluginRecord","defaultFilter","defaultPipe","addPlugin","key","handler","addPipe","addFilter","addGuard","addInterceptor","isAopDepInject","meta","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","forEach","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","length","log","pc","white","join","magenta","cyan","blue","red"]}
1
+ {"version":3,"sources":["../src/exception/base.ts","../src/exception/validate.ts","../src/pipe.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/context.ts","../src/filter.ts","../src/history.ts"],"sourcesContent":["import { ERROR_SYMBOL } from '../common'\n\nexport class Exception 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_SYMBOL]: true }\n }\n}\n","import { Exception } from './base'\n\nexport class ValidateException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { isPhecda, plainToClass, transformClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe: P.Pipe = async ({ arg, reflect, index }: any) => {\n if (isPhecda(reflect)) {\n const instance = plainToClass(reflect, arg)\n const err = await transformClass(instance)\n if (err.length > 0)\n throw new ValidateException(err[0])\n\n arg = instance\n }\n else {\n if ([Number, Boolean].includes(reflect)) {\n arg = reflect(arg)\n\n if (reflect === Number && Object.is(arg, NaN))\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\n }\n }\n return arg\n}\n","import { Exception } from './base'\n\nexport class UndefinedException extends Exception {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { Exception } from './base'\n\nexport class ForbiddenException extends Exception {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { Exception } from './base'\n\nexport class BadRequestException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { Exception } from './base'\n\nexport class NotFoundException extends Exception {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { Exception } from './base'\n\nexport class ConflictException extends Exception {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { Exception } from './base'\n\nexport class BadGatewayException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { Exception } from './base'\n\nexport class InvalidInputException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { Exception } from './base'\n\nexport class UnsupportedMediaTypeException extends Exception {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { Exception } from './base'\n\nexport class PayloadLargeException extends Exception {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { Exception } from './base'\n\nexport class TimeoutException extends Exception {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { Exception } from './base'\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { Exception } from './base'\n\nexport class ServiceUnavailableException extends Exception {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { Exception } from './base'\n\nexport class FrameworkException extends Exception {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import pc from 'picocolors'\nimport { defaultPipe } from './pipe'\nimport { ForbiddenException, FrameworkException } from './exception'\nimport { defaultFilter } from './filter'\nimport { Histroy } from './history'\nimport type { P } from './types'\nimport { IS_DEV, IS_STRICT } from './common'\nimport type { Meta } from './meta'\nimport { log } from './utils'\nexport const guardRecord = {} as Record<string, P.Guard>\n\nexport class Context<Data extends P.BaseContext> {\n method: string\n params: string[]\n history = new Histroy()\n\n static filterRecord: Record<string, P.Filter> = {\n default: defaultFilter,\n }\n\n static pipeRecord: Record<string, P.Pipe> = {\n default: defaultPipe,\n }\n\n static guardRecord: Record<string, P.Guard> = {}\n static interceptorRecord: Record<string, P.Interceptor> = {}\n\n static pluginRecord: Record<string, any> = {}\n postInterceptors: Function[]\n\n constructor(public data: Data) {\n if (IS_DEV)\n // @ts-expect-error work for debug\n data._context = this\n }\n\n usePipe(args: { arg: any; pipe?: string; pipeOpts?: any; type: string; key: string; index: number; reflect: any }[]) {\n return Promise.all(args.map((item) => {\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\n\n else\n return Context.pipeRecord.default(item, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.data)\n }))\n }\n\n useFilter(arg: any, filter = 'default') {\n if (!Context.filterRecord[filter]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find filter named '${filter}'`)\n else\n return Context.filterRecord.default(arg, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.data)\n }\n\n async useGuard(guards: string[]) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\n if (!await Context.guardRecord[guard](this.data))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async usePostInterceptor(ret: any) {\n for (const cb of this.postInterceptors)\n ret = await cb(ret) || ret\n\n return ret\n }\n\n async useInterceptor(interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\n const postInterceptor = await Context.interceptorRecord[interceptor](this.data)\n if (postInterceptor !== undefined) {\n if (typeof postInterceptor === 'function')\n ret.push(postInterceptor)\n\n else\n return postInterceptor\n }\n }\n }\n this.postInterceptors = ret\n }\n\n static usePlugin(plugins: string[]) {\n const ret = []\n for (const m of plugins) {\n if (!(m in Context.pluginRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(Context.pluginRecord[m])\n }\n return ret as any[]\n }\n}\nexport function addPlugin<T>(key: string, handler: T) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe<C extends P.BaseContext>(key: string, pipe: P.Pipe<C>) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter<C extends P.BaseContext>(key: string, handler: P.Filter<C>) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard<C extends P.BaseContext>(key: string, handler: P.Guard<C>) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor<C extends P.BaseContext>(key: string, handler: P.Interceptor<C>) {\n Context.interceptorRecord[key] = handler\n}\n\n// detect whether plugin/filter/pipe/guard/intercept is injected\nexport function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }: {\n guards?: string[]\n interceptors?: string[]\n plugins?: string[]\n} = {}) {\n\n if (!IS_DEV) return\n const pluginSet = new Set<string>(plugins)\n\n const guardSet = new Set<string>(guards)\n const interceptorSet = new Set<string>(interceptors)\n const pipeSet = new Set<string>()\n\n const filterSet = new Set<string>()\n meta.forEach(({ data }) => {\n if (data.filter)\n filterSet.add(data.filter)\n\n data.interceptors.forEach(i => interceptorSet.add(i))\n data.guards.forEach(i => guardSet.add(i))\n data.plugins.forEach(i => pluginSet.add(i))\n data.params.forEach((i) => {\n if (i.pipe)\n pipeSet.add(i.pipe)\n })\n })\n\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\n\n if (missPlugins.length)\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\n if (missGuards.length)\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missInterceptors.length)\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missPipes.length)\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missFilters.length)\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\n}\n","import { IS_DEV } from './common'\nimport { Exception, UndefinedException } from './exception'\nimport type { P } from './types'\nimport { log } from './utils'\n\nexport const defaultFilter: P.Filter = (e) => {\n if (!(e instanceof Exception)) {\n if (IS_DEV) {\n log(e.message, 'error')\n console.error(e.stack)\n }\n e = new UndefinedException(e.message || e)\n }\n else {\n if (IS_DEV) {\n log(`[${e.constructor.name}] ${e.message}`, 'error')\n console.error(e.stack)\n }\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"],"mappings":";;;;;;;;;;AAEO,IAAMA,YAAN,cAAwBC,MAAAA;EACVC;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;MAAQ,CAACI,eAAe;IAAK;EAC3G;AACF;AARaP;;;ACAN,IAAMQ,oBAAN,cAAgCC,UAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;ACFb,SAASI,UAAUC,cAAcC,sBAAsB;AAKhD,IAAMC,cAAsB,8BAAO,EAAEC,KAAKC,SAASC,MAAK,MAAY;AACzE,MAAIC,SAASF,OAAAA,GAAU;AACrB,UAAMG,WAAWC,aAAaJ,SAASD,GAAAA;AACvC,UAAMM,MAAM,MAAMC,eAAeH,QAAAA;AACjC,QAAIE,IAAIE,SAAS;AACf,YAAM,IAAIC,kBAAkBH,IAAI,EAAE;AAEpCN,UAAMI;EACR,OACK;AACH,QAAI;MAACM;MAAQC;MAASC,SAASX,OAAAA,GAAU;AACvCD,YAAMC,QAAQD,GAAAA;AAEd,UAAIC,YAAYS,UAAUG,OAAOC,GAAGd,KAAKe,GAAAA;AACvC,cAAM,IAAIN,kBAAkB,aAAaC,OAAOR,KAAAA,IAAS,sBAAsB;IACnF;EACF;AACA,SAAOF;AACT,GAlBmC;;;ACH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AK,GAAA,IAAO,mBAAmB,MAAA;AAExE,MAAIP,iBAAiBG;AACnBC,QAAI,GAAGC,GAAGI,KAAK,gBAAgBT,iBAAiBO,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEjF,MAAIN,UAAUE;AACZC,QAAI,GAAGC,GAAGK,KAAK,SAAST,UAAUM,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEnE,MAAIL,YAAYC;AACdC,QAAI,GAAGC,GAAGM,IAAI,WAAWT,YAAYK,KAAK,GAAA,IAAO,mBAAmB,MAAA;AACxE;AA9CgBpB;","names":["Exception","Error","message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","Exception","constructor","message","isPhecda","plainToClass","transformClass","defaultPipe","arg","reflect","index","isPhecda","instance","plainToClass","err","transformClass","length","ValidateException","Number","Boolean","includes","Object","is","NaN","UndefinedException","Exception","constructor","message","ForbiddenException","Exception","constructor","message","BadRequestException","Exception","constructor","message","NotFoundException","Exception","constructor","message","ConflictException","Exception","constructor","message","BadGatewayException","Exception","constructor","message","InvalidInputException","Exception","constructor","message","UnsupportedMediaTypeException","Exception","constructor","message","PayloadLargeException","Exception","constructor","message","TimeoutException","Exception","constructor","message","UnauthorizedException","Exception","constructor","message","ServiceUnavailableException","Exception","constructor","message","FrameworkException","Exception","constructor","message","pc","defaultFilter","e","Exception","IS_DEV","log","message","console","error","stack","UndefinedException","constructor","name","data","Histroy","guard","interceptor","record","name","type","includes","push","guardRecord","Context","data","method","params","history","postInterceptors","constructor","Histroy","IS_DEV","_context","usePipe","args","Promise","all","map","item","pipe","pipeRecord","IS_STRICT","FrameworkException","default","useFilter","arg","filter","filterRecord","useGuard","guards","guard","record","ForbiddenException","usePostInterceptor","ret","cb","useInterceptor","interceptors","interceptor","interceptorRecord","postInterceptor","undefined","push","usePlugin","plugins","m","pluginRecord","defaultFilter","defaultPipe","addPlugin","key","handler","addPipe","addFilter","addGuard","addInterceptor","isAopDepInject","meta","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","forEach","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","length","log","pc","white","join","magenta","cyan","blue","red"]}
@@ -169,12 +169,16 @@ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefau
169
169
  // src/filter.ts
170
170
  var defaultFilter = /* @__PURE__ */ _chunkBDIQWWHNjs.__name.call(void 0, (e) => {
171
171
  if (!(e instanceof Exception)) {
172
- _chunkBDIQWWHNjs.log.call(void 0, e.message, "error");
173
- console.error(e.stack);
172
+ if (_chunkBDIQWWHNjs.IS_DEV) {
173
+ _chunkBDIQWWHNjs.log.call(void 0, e.message, "error");
174
+ console.error(e.stack);
175
+ }
174
176
  e = new UndefinedException(e.message || e);
175
177
  } else {
176
- _chunkBDIQWWHNjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
177
- console.error(e.stack);
178
+ if (_chunkBDIQWWHNjs.IS_DEV) {
179
+ _chunkBDIQWWHNjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
180
+ console.error(e.stack);
181
+ }
178
182
  }
179
183
  return e.data;
180
184
  }, "defaultFilter");
@@ -382,4 +386,4 @@ _chunkBDIQWWHNjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
382
386
 
383
387
 
384
388
  exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.guardRecord = guardRecord; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.isAopDepInject = isAopDepInject;
385
- //# sourceMappingURL=chunk-32E425F6.js.map
389
+ //# sourceMappingURL=chunk-WBHZCJSN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/exception/base.ts","../src/exception/validate.ts","../src/pipe.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/context.ts","../src/filter.ts","../src/history.ts"],"names":["Exception","Error","message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","isPhecda","plainToClass","transformClass","defaultPipe","arg","reflect","index","instance","err","length","Number","Boolean","includes","Object","is","NaN","UndefinedException","ForbiddenException","BadRequestException","NotFoundException","ConflictException","BadGatewayException","InvalidInputException","UnsupportedMediaTypeException","PayloadLargeException","TimeoutException","UnauthorizedException","ServiceUnavailableException","FrameworkException","pc","defaultFilter","e","IS_DEV","log","console","error","stack","name","Histroy","guard","interceptor","record","type","push","guardRecord","Context","method","params","history","postInterceptors","_context","usePipe","args","Promise","all","map","item","pipe","pipeRecord","IS_STRICT","default","useFilter","filter","filterRecord","useGuard","guards","usePostInterceptor","ret","cb","useInterceptor","interceptors","interceptorRecord","postInterceptor","undefined","usePlugin","plugins","m","pluginRecord","addPlugin","key","handler","addPipe","addFilter","addGuard","addInterceptor","isAopDepInject","meta","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","forEach","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","white","join","magenta","cyan","blue","red"],"mappings":";;;;;;;;;;AAEO,IAAMA,YAAN,cAAwBC,MAAAA;EACVC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA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E;AA9CgBjB","sourcesContent":["import { ERROR_SYMBOL } from '../common'\n\nexport class Exception 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_SYMBOL]: true }\n }\n}\n","import { Exception } from './base'\n\nexport class ValidateException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { isPhecda, plainToClass, transformClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe: P.Pipe = async ({ arg, reflect, index }: any) => {\n if (isPhecda(reflect)) {\n const instance = plainToClass(reflect, arg)\n const err = await transformClass(instance)\n if (err.length > 0)\n throw new ValidateException(err[0])\n\n arg = instance\n }\n else {\n if ([Number, Boolean].includes(reflect)) {\n arg = reflect(arg)\n\n if (reflect === Number && Object.is(arg, NaN))\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\n }\n }\n return arg\n}\n","import { Exception } from './base'\n\nexport class UndefinedException extends Exception {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { Exception } from './base'\n\nexport class ForbiddenException extends Exception {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { Exception } from './base'\n\nexport class BadRequestException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { Exception } from './base'\n\nexport class NotFoundException extends Exception {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { Exception } from './base'\n\nexport class ConflictException extends Exception {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { Exception } from './base'\n\nexport class BadGatewayException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { Exception } from './base'\n\nexport class InvalidInputException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { Exception } from './base'\n\nexport class UnsupportedMediaTypeException extends Exception {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { Exception } from './base'\n\nexport class PayloadLargeException extends Exception {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { Exception } from './base'\n\nexport class TimeoutException extends Exception {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { Exception } from './base'\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { Exception } from './base'\n\nexport class ServiceUnavailableException extends Exception {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { Exception } from './base'\n\nexport class FrameworkException extends Exception {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import pc from 'picocolors'\nimport { defaultPipe } from './pipe'\nimport { ForbiddenException, FrameworkException } from './exception'\nimport { defaultFilter } from './filter'\nimport { Histroy } from './history'\nimport type { P } from './types'\nimport { IS_DEV, IS_STRICT } from './common'\nimport type { Meta } from './meta'\nimport { log } from './utils'\nexport const guardRecord = {} as Record<string, P.Guard>\n\nexport class Context<Data extends P.BaseContext> {\n method: string\n params: string[]\n history = new Histroy()\n\n static filterRecord: Record<string, P.Filter> = {\n default: defaultFilter,\n }\n\n static pipeRecord: Record<string, P.Pipe> = {\n default: defaultPipe,\n }\n\n static guardRecord: Record<string, P.Guard> = {}\n static interceptorRecord: Record<string, P.Interceptor> = {}\n\n static pluginRecord: Record<string, any> = {}\n postInterceptors: Function[]\n\n constructor(public data: Data) {\n if (IS_DEV)\n // @ts-expect-error work for debug\n data._context = this\n }\n\n usePipe(args: { arg: any; pipe?: string; pipeOpts?: any; type: string; key: string; index: number; reflect: any }[]) {\n return Promise.all(args.map((item) => {\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\n\n else\n return Context.pipeRecord.default(item, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.data)\n }))\n }\n\n useFilter(arg: any, filter = 'default') {\n if (!Context.filterRecord[filter]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find filter named '${filter}'`)\n else\n return Context.filterRecord.default(arg, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.data)\n }\n\n async useGuard(guards: string[]) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\n if (!await Context.guardRecord[guard](this.data))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async usePostInterceptor(ret: any) {\n for (const cb of this.postInterceptors)\n ret = await cb(ret) || ret\n\n return ret\n }\n\n async useInterceptor(interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\n const postInterceptor = await Context.interceptorRecord[interceptor](this.data)\n if (postInterceptor !== undefined) {\n if (typeof postInterceptor === 'function')\n ret.push(postInterceptor)\n\n else\n return postInterceptor\n }\n }\n }\n this.postInterceptors = ret\n }\n\n static usePlugin(plugins: string[]) {\n const ret = []\n for (const m of plugins) {\n if (!(m in Context.pluginRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(Context.pluginRecord[m])\n }\n return ret as any[]\n }\n}\nexport function addPlugin<T>(key: string, handler: T) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe<C extends P.BaseContext>(key: string, pipe: P.Pipe<C>) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter<C extends P.BaseContext>(key: string, handler: P.Filter<C>) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard<C extends P.BaseContext>(key: string, handler: P.Guard<C>) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor<C extends P.BaseContext>(key: string, handler: P.Interceptor<C>) {\n Context.interceptorRecord[key] = handler\n}\n\n// detect whether plugin/filter/pipe/guard/intercept is injected\nexport function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }: {\n guards?: string[]\n interceptors?: string[]\n plugins?: string[]\n} = {}) {\n\n if (!IS_DEV) return\n const pluginSet = new Set<string>(plugins)\n\n const guardSet = new Set<string>(guards)\n const interceptorSet = new Set<string>(interceptors)\n const pipeSet = new Set<string>()\n\n const filterSet = new Set<string>()\n meta.forEach(({ data }) => {\n if (data.filter)\n filterSet.add(data.filter)\n\n data.interceptors.forEach(i => interceptorSet.add(i))\n data.guards.forEach(i => guardSet.add(i))\n data.plugins.forEach(i => pluginSet.add(i))\n data.params.forEach((i) => {\n if (i.pipe)\n pipeSet.add(i.pipe)\n })\n })\n\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\n\n if (missPlugins.length)\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\n if (missGuards.length)\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missInterceptors.length)\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missPipes.length)\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missFilters.length)\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\n}\n","import { IS_DEV } from './common'\nimport { Exception, UndefinedException } from './exception'\nimport type { P } from './types'\nimport { log } from './utils'\n\nexport const defaultFilter: P.Filter = (e) => {\n if (!(e instanceof Exception)) {\n if (IS_DEV) {\n log(e.message, 'error')\n console.error(e.stack)\n }\n e = new UndefinedException(e.message || e)\n }\n else {\n if (IS_DEV) {\n log(`[${e.constructor.name}] ${e.message}`, 'error')\n console.error(e.stack)\n }\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"]}
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var _chunk63KBHOSBjs = require('./chunk-63KBHOSB.js');
34
34
 
35
35
 
36
36
 
37
- var _chunk32E425F6js = require('./chunk-32E425F6.js');
37
+ var _chunkWBHZCJSNjs = require('./chunk-WBHZCJSN.js');
38
38
 
39
39
 
40
40
 
@@ -308,9 +308,9 @@ var PFilter = class extends Dev {
308
308
  constructor(tag) {
309
309
  super();
310
310
  this.key = tag || _phecdacore.getSymbol.call(void 0, this);
311
- _chunk32E425F6js.addFilter.call(void 0, this.key, this.use.bind(this));
311
+ _chunkWBHZCJSNjs.addFilter.call(void 0, this.key, this.use.bind(this));
312
312
  this.onUnmount(() => {
313
- delete _chunk32E425F6js.Context.filterRecord[this.key];
313
+ delete _chunkWBHZCJSNjs.Context.filterRecord[this.key];
314
314
  });
315
315
  }
316
316
  };
@@ -323,9 +323,9 @@ var PGuard = class extends Dev {
323
323
  constructor(tag) {
324
324
  super();
325
325
  this.key = tag || _phecdacore.getSymbol.call(void 0, this);
326
- _chunk32E425F6js.addGuard.call(void 0, this.key, this.use.bind(this));
326
+ _chunkWBHZCJSNjs.addGuard.call(void 0, this.key, this.use.bind(this));
327
327
  this.onUnmount(() => {
328
- delete _chunk32E425F6js.Context.guardRecord[this.key];
328
+ delete _chunkWBHZCJSNjs.Context.guardRecord[this.key];
329
329
  });
330
330
  }
331
331
  };
@@ -339,9 +339,9 @@ var PInterceptor = class extends Dev {
339
339
  super();
340
340
  this.key = tag || _phecdacore.getSymbol.call(void 0, this);
341
341
  this.onUnmount(() => {
342
- delete _chunk32E425F6js.Context.interceptorRecord[this.key];
342
+ delete _chunkWBHZCJSNjs.Context.interceptorRecord[this.key];
343
343
  });
344
- _chunk32E425F6js.addInterceptor.call(void 0, this.key, this.use.bind(this));
344
+ _chunkWBHZCJSNjs.addInterceptor.call(void 0, this.key, this.use.bind(this));
345
345
  }
346
346
  };
347
347
  _chunkBDIQWWHNjs.__name.call(void 0, PInterceptor, "PInterceptor");
@@ -353,9 +353,9 @@ var PPipe = class extends Dev {
353
353
  constructor(tag) {
354
354
  super();
355
355
  this.key = tag || _phecdacore.getSymbol.call(void 0, this);
356
- _chunk32E425F6js.addPipe.call(void 0, this.key, this.use.bind(this));
356
+ _chunkWBHZCJSNjs.addPipe.call(void 0, this.key, this.use.bind(this));
357
357
  this.onUnmount(() => {
358
- delete _chunk32E425F6js.Context.pipeRecord[this.key];
358
+ delete _chunkWBHZCJSNjs.Context.pipeRecord[this.key];
359
359
  });
360
360
  }
361
361
  };
@@ -368,9 +368,9 @@ var PPlugin = class extends Dev {
368
368
  constructor(tag) {
369
369
  super();
370
370
  this.key = tag || _phecdacore.getSymbol.call(void 0, this);
371
- _chunk32E425F6js.addPlugin.call(void 0, this.key, this.use.bind(this));
371
+ _chunkWBHZCJSNjs.addPlugin.call(void 0, this.key, this.use.bind(this));
372
372
  this.onUnmount(() => {
373
- delete _chunk32E425F6js.Context.pluginRecord[this.key];
373
+ delete _chunkWBHZCJSNjs.Context.pluginRecord[this.key];
374
374
  });
375
375
  }
376
376
  };
@@ -384,33 +384,33 @@ var PModule = class extends Dev {
384
384
  super();
385
385
  const key = this.key = tag || _phecdacore.getSymbol.call(void 0, this);
386
386
  if (this.pipe) {
387
- _chunk32E425F6js.addPipe.call(void 0, key, this.pipe.bind(this));
387
+ _chunkWBHZCJSNjs.addPipe.call(void 0, key, this.pipe.bind(this));
388
388
  this.onUnmount(() => {
389
- delete _chunk32E425F6js.Context.pipeRecord[key];
389
+ delete _chunkWBHZCJSNjs.Context.pipeRecord[key];
390
390
  });
391
391
  }
392
392
  if (this.plugin) {
393
- _chunk32E425F6js.addPlugin.call(void 0, key, this.plugin.bind(this));
393
+ _chunkWBHZCJSNjs.addPlugin.call(void 0, key, this.plugin.bind(this));
394
394
  this.onUnmount(() => {
395
- delete _chunk32E425F6js.Context.pluginRecord[key];
395
+ delete _chunkWBHZCJSNjs.Context.pluginRecord[key];
396
396
  });
397
397
  }
398
398
  if (this.intercept) {
399
- _chunk32E425F6js.addInterceptor.call(void 0, key, this.intercept.bind(this));
399
+ _chunkWBHZCJSNjs.addInterceptor.call(void 0, key, this.intercept.bind(this));
400
400
  this.onUnmount(() => {
401
- delete _chunk32E425F6js.Context.interceptorRecord[key];
401
+ delete _chunkWBHZCJSNjs.Context.interceptorRecord[key];
402
402
  });
403
403
  }
404
404
  if (this.guard) {
405
- _chunk32E425F6js.addGuard.call(void 0, key, this.guard.bind(this));
405
+ _chunkWBHZCJSNjs.addGuard.call(void 0, key, this.guard.bind(this));
406
406
  this.onUnmount(() => {
407
- delete _chunk32E425F6js.Context.guardRecord[key];
407
+ delete _chunkWBHZCJSNjs.Context.guardRecord[key];
408
408
  });
409
409
  }
410
410
  if (this.filter) {
411
- _chunk32E425F6js.addFilter.call(void 0, key, this.filter.bind(this));
411
+ _chunkWBHZCJSNjs.addFilter.call(void 0, key, this.filter.bind(this));
412
412
  this.onUnmount(() => {
413
- delete _chunk32E425F6js.Context.filterRecord[key];
413
+ delete _chunkWBHZCJSNjs.Context.filterRecord[key];
414
414
  });
415
415
  }
416
416
  }
@@ -488,5 +488,5 @@ _chunkBDIQWWHNjs.__name.call(void 0, PModule, "PModule");
488
488
 
489
489
 
490
490
 
491
- exports.APP_SYMBOL = _chunkBDIQWWHNjs.APP_SYMBOL; exports.Arg = Arg; exports.BadGatewayException = _chunk32E425F6js.BadGatewayException; exports.BadRequestException = _chunk32E425F6js.BadRequestException; exports.BaseParam = BaseParam; exports.Body = Body; exports.ConflictException = _chunk32E425F6js.ConflictException; exports.Context = _chunk32E425F6js.Context; exports.Controller = Controller; exports.Define = Define; exports.Delete = Delete; exports.Dev = Dev; exports.ERROR_SYMBOL = _chunkBDIQWWHNjs.ERROR_SYMBOL; exports.Event = Event; exports.Exception = _chunk32E425F6js.Exception; exports.Factory = _chunk5L4K7XEBjs.Factory; exports.Filter = Filter; exports.ForbiddenException = _chunk32E425F6js.ForbiddenException; exports.FrameworkException = _chunk32E425F6js.FrameworkException; exports.Get = Get; exports.Guard = Guard; exports.Head = Head; exports.Header = Header; exports.IS_DEV = _chunkBDIQWWHNjs.IS_DEV; exports.IS_STRICT = _chunkBDIQWWHNjs.IS_STRICT; exports.Injectable = _chunk5L4K7XEBjs.Injectable; exports.Interceptor = Interceptor; exports.InvalidInputException = _chunk32E425F6js.InvalidInputException; exports.MERGE_SYMBOL = _chunkBDIQWWHNjs.MERGE_SYMBOL; exports.META_SYMBOL = _chunkBDIQWWHNjs.META_SYMBOL; exports.MODULE_SYMBOL = _chunkBDIQWWHNjs.MODULE_SYMBOL; exports.Meta = _chunk5L4K7XEBjs.Meta; exports.NotFoundException = _chunk32E425F6js.NotFoundException; exports.PFilter = PFilter; exports.PGuard = PGuard; exports.PInterceptor = PInterceptor; exports.PModule = PModule; exports.PPipe = PPipe; exports.PPlugin = PPlugin; exports.Param = Param; exports.Patch = Patch; exports.PayloadLargeException = _chunk32E425F6js.PayloadLargeException; exports.Pipe = Pipe; exports.Plugin = Plugin; exports.Post = Post; exports.Put = Put; exports.Query = Query; exports.Route = Route; exports.Rpc = Rpc; exports.ServiceUnavailableException = _chunk32E425F6js.ServiceUnavailableException; exports.TimeoutException = _chunk32E425F6js.TimeoutException; exports.UNMOUNT_SYMBOL = _chunkBDIQWWHNjs.UNMOUNT_SYMBOL; exports.UnauthorizedException = _chunk32E425F6js.UnauthorizedException; exports.UndefinedException = _chunk32E425F6js.UndefinedException; exports.UnsupportedMediaTypeException = _chunk32E425F6js.UnsupportedMediaTypeException; exports.ValidateException = _chunk32E425F6js.ValidateException; exports.addFilter = _chunk32E425F6js.addFilter; exports.addGuard = _chunk32E425F6js.addGuard; exports.addInterceptor = _chunk32E425F6js.addInterceptor; exports.addPipe = _chunk32E425F6js.addPipe; exports.addPlugin = _chunk32E425F6js.addPlugin; exports.defaultPipe = _chunk32E425F6js.defaultPipe; exports.emitter = _chunk5L4K7XEBjs.emitter; exports.generateHTTPCode = _chunk5L4K7XEBjs.generateHTTPCode; exports.generateRPCCode = _chunk5L4K7XEBjs.generateRPCCode; exports.getConfig = _chunkBDIQWWHNjs.getConfig; exports.guardRecord = _chunk32E425F6js.guardRecord; exports.isAopDepInject = _chunk32E425F6js.isAopDepInject; exports.log = _chunkBDIQWWHNjs.log; exports.resolveDep = _chunk63KBHOSBjs.resolveDep; exports.setConfig = _chunkBDIQWWHNjs.setConfig;
491
+ exports.APP_SYMBOL = _chunkBDIQWWHNjs.APP_SYMBOL; exports.Arg = Arg; exports.BadGatewayException = _chunkWBHZCJSNjs.BadGatewayException; exports.BadRequestException = _chunkWBHZCJSNjs.BadRequestException; exports.BaseParam = BaseParam; exports.Body = Body; exports.ConflictException = _chunkWBHZCJSNjs.ConflictException; exports.Context = _chunkWBHZCJSNjs.Context; exports.Controller = Controller; exports.Define = Define; exports.Delete = Delete; exports.Dev = Dev; exports.ERROR_SYMBOL = _chunkBDIQWWHNjs.ERROR_SYMBOL; exports.Event = Event; exports.Exception = _chunkWBHZCJSNjs.Exception; exports.Factory = _chunk5L4K7XEBjs.Factory; exports.Filter = Filter; exports.ForbiddenException = _chunkWBHZCJSNjs.ForbiddenException; exports.FrameworkException = _chunkWBHZCJSNjs.FrameworkException; exports.Get = Get; exports.Guard = Guard; exports.Head = Head; exports.Header = Header; exports.IS_DEV = _chunkBDIQWWHNjs.IS_DEV; exports.IS_STRICT = _chunkBDIQWWHNjs.IS_STRICT; exports.Injectable = _chunk5L4K7XEBjs.Injectable; exports.Interceptor = Interceptor; exports.InvalidInputException = _chunkWBHZCJSNjs.InvalidInputException; exports.MERGE_SYMBOL = _chunkBDIQWWHNjs.MERGE_SYMBOL; exports.META_SYMBOL = _chunkBDIQWWHNjs.META_SYMBOL; exports.MODULE_SYMBOL = _chunkBDIQWWHNjs.MODULE_SYMBOL; exports.Meta = _chunk5L4K7XEBjs.Meta; exports.NotFoundException = _chunkWBHZCJSNjs.NotFoundException; exports.PFilter = PFilter; exports.PGuard = PGuard; exports.PInterceptor = PInterceptor; exports.PModule = PModule; exports.PPipe = PPipe; exports.PPlugin = PPlugin; exports.Param = Param; exports.Patch = Patch; exports.PayloadLargeException = _chunkWBHZCJSNjs.PayloadLargeException; exports.Pipe = Pipe; exports.Plugin = Plugin; exports.Post = Post; exports.Put = Put; exports.Query = Query; exports.Route = Route; exports.Rpc = Rpc; exports.ServiceUnavailableException = _chunkWBHZCJSNjs.ServiceUnavailableException; exports.TimeoutException = _chunkWBHZCJSNjs.TimeoutException; exports.UNMOUNT_SYMBOL = _chunkBDIQWWHNjs.UNMOUNT_SYMBOL; exports.UnauthorizedException = _chunkWBHZCJSNjs.UnauthorizedException; exports.UndefinedException = _chunkWBHZCJSNjs.UndefinedException; exports.UnsupportedMediaTypeException = _chunkWBHZCJSNjs.UnsupportedMediaTypeException; exports.ValidateException = _chunkWBHZCJSNjs.ValidateException; exports.addFilter = _chunkWBHZCJSNjs.addFilter; exports.addGuard = _chunkWBHZCJSNjs.addGuard; exports.addInterceptor = _chunkWBHZCJSNjs.addInterceptor; exports.addPipe = _chunkWBHZCJSNjs.addPipe; exports.addPlugin = _chunkWBHZCJSNjs.addPlugin; exports.defaultPipe = _chunkWBHZCJSNjs.defaultPipe; exports.emitter = _chunk5L4K7XEBjs.emitter; exports.generateHTTPCode = _chunk5L4K7XEBjs.generateHTTPCode; exports.generateRPCCode = _chunk5L4K7XEBjs.generateRPCCode; exports.getConfig = _chunkBDIQWWHNjs.getConfig; exports.guardRecord = _chunkWBHZCJSNjs.guardRecord; exports.isAopDepInject = _chunkWBHZCJSNjs.isAopDepInject; exports.log = _chunkBDIQWWHNjs.log; exports.resolveDep = _chunk63KBHOSBjs.resolveDep; exports.setConfig = _chunkBDIQWWHNjs.setConfig;
492
492
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  defaultPipe,
35
35
  guardRecord,
36
36
  isAopDepInject
37
- } from "./chunk-Z6LSJTOF.mjs";
37
+ } from "./chunk-MIIYJMMM.mjs";
38
38
  import {
39
39
  APP_SYMBOL,
40
40
  ERROR_SYMBOL,
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk32E425F6js = require('../../chunk-32E425F6.js');
5
+ var _chunkWBHZCJSNjs = require('../../chunk-WBHZCJSN.js');
6
6
 
7
7
 
8
8
 
@@ -14,7 +14,7 @@ async function bind(ch, queue, { moduleMap, meta }, opts) {
14
14
  const existQueue = /* @__PURE__ */ new Set();
15
15
  const { globalGuards = [], globalInterceptors = [] } = opts || {};
16
16
  function handleMeta() {
17
- _chunk32E425F6js.isAopDepInject.call(void 0, meta, {
17
+ _chunkWBHZCJSNjs.isAopDepInject.call(void 0, meta, {
18
18
  guards: globalGuards,
19
19
  interceptors: globalInterceptors
20
20
  });
@@ -35,14 +35,14 @@ async function bind(ch, queue, { moduleMap, meta }, opts) {
35
35
  await ch.assertQueue(queue2);
36
36
  if (!metaMap.has(tag)) {
37
37
  queue2 && ch.sendToQueue(queue2, Buffer.from(JSON.stringify({
38
- data: new (0, _chunk32E425F6js.BadRequestException)(`service "${tag}" doesn't exist`).data,
38
+ data: new (0, _chunkWBHZCJSNjs.BadRequestException)(`service "${tag}" doesn't exist`).data,
39
39
  error: true,
40
40
  id
41
41
  })));
42
42
  return;
43
43
  }
44
44
  const meta2 = metaMap.get(tag);
45
- const context = new (0, _chunk32E425F6js.Context)({
45
+ const context = new (0, _chunkWBHZCJSNjs.Context)({
46
46
  type: "rabbitmq",
47
47
  moduleMap,
48
48
  meta: meta2,
@@ -2,7 +2,7 @@ import {
2
2
  BadRequestException,
3
3
  Context,
4
4
  isAopDepInject
5
- } from "../../chunk-Z6LSJTOF.mjs";
5
+ } from "../../chunk-MIIYJMMM.mjs";
6
6
  import {
7
7
  IS_DEV,
8
8
  __name
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk32E425F6js = require('../../chunk-32E425F6.js');
5
+ var _chunkWBHZCJSNjs = require('../../chunk-WBHZCJSN.js');
6
6
 
7
7
 
8
8
 
@@ -15,7 +15,7 @@ function bind(redis, channel, { moduleMap, meta }, opts) {
15
15
  const pub = new (0, _ioredis2.default)(redis.options);
16
16
  const { globalGuards = [], globalInterceptors = [] } = opts || {};
17
17
  function handleMeta() {
18
- _chunk32E425F6js.isAopDepInject.call(void 0, meta, {
18
+ _chunkWBHZCJSNjs.isAopDepInject.call(void 0, meta, {
19
19
  guards: globalGuards,
20
20
  interceptors: globalInterceptors
21
21
  });
@@ -34,14 +34,14 @@ function bind(redis, channel, { moduleMap, meta }, opts) {
34
34
  const { tag, args, id, queue } = data;
35
35
  if (!metaMap.has(tag)) {
36
36
  queue && pub.publish(queue, JSON.stringify({
37
- data: new (0, _chunk32E425F6js.BadRequestException)(`service "${tag}" doesn't exist`).data,
37
+ data: new (0, _chunkWBHZCJSNjs.BadRequestException)(`service "${tag}" doesn't exist`).data,
38
38
  error: true,
39
39
  id
40
40
  }));
41
41
  return;
42
42
  }
43
43
  const meta2 = metaMap.get(tag);
44
- const context = new (0, _chunk32E425F6js.Context)({
44
+ const context = new (0, _chunkWBHZCJSNjs.Context)({
45
45
  type: "redis",
46
46
  moduleMap,
47
47
  redis,
@@ -2,7 +2,7 @@ import {
2
2
  BadRequestException,
3
3
  Context,
4
4
  isAopDepInject
5
- } from "../../chunk-Z6LSJTOF.mjs";
5
+ } from "../../chunk-MIIYJMMM.mjs";
6
6
  import {
7
7
  IS_DEV,
8
8
  __name
@@ -5,7 +5,7 @@ var _chunk63KBHOSBjs = require('../../chunk-63KBHOSB.js');
5
5
 
6
6
 
7
7
 
8
- var _chunk32E425F6js = require('../../chunk-32E425F6.js');
8
+ var _chunkWBHZCJSNjs = require('../../chunk-WBHZCJSN.js');
9
9
 
10
10
 
11
11
 
@@ -24,7 +24,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
24
24
  plugins: [],
25
25
  ...options
26
26
  };
27
- _chunk32E425F6js.isAopDepInject.call(void 0, meta, {
27
+ _chunkWBHZCJSNjs.isAopDepInject.call(void 0, meta, {
28
28
  plugins,
29
29
  guards: globalGuards,
30
30
  interceptors: globalInterceptors
@@ -51,22 +51,22 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
51
51
  req[_chunkBDIQWWHNjs.MODULE_SYMBOL] = moduleMap;
52
52
  req[_chunkBDIQWWHNjs.META_SYMBOL] = meta;
53
53
  next();
54
- }, ..._chunk32E425F6js.Context.usePlugin(plugins), async (req, res) => {
54
+ }, ..._chunkWBHZCJSNjs.Context.usePlugin(plugins), async (req, res) => {
55
55
  const { body } = req;
56
56
  async function errorHandler(e) {
57
- const error = await _chunk32E425F6js.Context.filterRecord.default(e);
57
+ const error = await _chunkWBHZCJSNjs.Context.filterRecord.default(e);
58
58
  return res.status(error.status).json(error);
59
59
  }
60
60
  _chunkBDIQWWHNjs.__name.call(void 0, errorHandler, "errorHandler");
61
61
  if (!Array.isArray(body))
62
- return errorHandler(new (0, _chunk32E425F6js.BadRequestException)("data format should be an array"));
62
+ return errorHandler(new (0, _chunkWBHZCJSNjs.BadRequestException)("data format should be an array"));
63
63
  try {
64
64
  return Promise.all(body.map((item) => {
65
65
  return new Promise(async (resolve) => {
66
66
  const { tag } = item;
67
67
  const meta2 = metaMap.get(tag);
68
68
  if (!meta2)
69
- return resolve(await _chunk32E425F6js.Context.filterRecord.default(new (0, _chunk32E425F6js.BadRequestException)(`"${tag}" doesn't exist`)));
69
+ return resolve(await _chunkWBHZCJSNjs.Context.filterRecord.default(new (0, _chunkWBHZCJSNjs.BadRequestException)(`"${tag}" doesn't exist`)));
70
70
  const contextData = {
71
71
  type: "express",
72
72
  request: req,
@@ -76,7 +76,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
76
76
  parallel: true,
77
77
  tag
78
78
  };
79
- const context = new (0, _chunk32E425F6js.Context)(contextData);
79
+ const context = new (0, _chunkWBHZCJSNjs.Context)(contextData);
80
80
  const [name, method] = tag.split("-");
81
81
  const { paramsType, handlers, data: { params, guards, interceptors, filter } } = meta2;
82
82
  const instance = moduleMap.get(name);
@@ -127,7 +127,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
127
127
  req[_chunkBDIQWWHNjs.MODULE_SYMBOL] = moduleMap;
128
128
  req[_chunkBDIQWWHNjs.META_SYMBOL] = meta;
129
129
  next();
130
- }, ..._chunk32E425F6js.Context.usePlugin(plugins2), async (req, res) => {
130
+ }, ..._chunkWBHZCJSNjs.Context.usePlugin(plugins2), async (req, res) => {
131
131
  const instance = moduleMap.get(tag);
132
132
  const contextData = {
133
133
  type: "express",
@@ -138,7 +138,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
138
138
  parallel: false,
139
139
  tag: methodTag
140
140
  };
141
- const context = new (0, _chunk32E425F6js.Context)(contextData);
141
+ const context = new (0, _chunkWBHZCJSNjs.Context)(contextData);
142
142
  try {
143
143
  for (const name in header)
144
144
  res.set(name, header[name]);
@@ -192,7 +192,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
192
192
  createRoute();
193
193
  if (_chunkBDIQWWHNjs.IS_DEV) {
194
194
  _optionalChain([globalThis, 'access', _7 => _7.__PS_HMR__, 'optionalAccess', _8 => _8.push, 'call', _9 => _9(async () => {
195
- _chunk32E425F6js.isAopDepInject.call(void 0, meta, {
195
+ _chunkWBHZCJSNjs.isAopDepInject.call(void 0, meta, {
196
196
  plugins,
197
197
  guards: globalGuards,
198
198
  interceptors: globalInterceptors
@@ -5,7 +5,7 @@ import {
5
5
  BadRequestException,
6
6
  Context,
7
7
  isAopDepInject
8
- } from "../../chunk-Z6LSJTOF.mjs";
8
+ } from "../../chunk-MIIYJMMM.mjs";
9
9
  import {
10
10
  APP_SYMBOL,
11
11
  IS_DEV,
@@ -5,7 +5,7 @@ var _chunk63KBHOSBjs = require('../../chunk-63KBHOSB.js');
5
5
 
6
6
 
7
7
 
8
- var _chunk32E425F6js = require('../../chunk-32E425F6.js');
8
+ var _chunkWBHZCJSNjs = require('../../chunk-WBHZCJSN.js');
9
9
 
10
10
 
11
11
 
@@ -27,7 +27,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
27
27
  moduleMap,
28
28
  meta
29
29
  };
30
- _chunk32E425F6js.isAopDepInject.call(void 0, meta, {
30
+ _chunkWBHZCJSNjs.isAopDepInject.call(void 0, meta, {
31
31
  plugins,
32
32
  guards: globalGuards,
33
33
  interceptors: globalInterceptors
@@ -52,7 +52,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
52
52
  };
53
53
  fastify.register((fastify2, _opts, done2) => {
54
54
  plugins.forEach((p) => {
55
- const plugin = _chunk32E425F6js.Context.usePlugin([
55
+ const plugin = _chunkWBHZCJSNjs.Context.usePlugin([
56
56
  p
57
57
  ])[0];
58
58
  if (plugin) {
@@ -63,19 +63,19 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
63
63
  fastify2.post(route, async (req, res) => {
64
64
  const { body } = req;
65
65
  async function errorHandler(e) {
66
- const error = await _chunk32E425F6js.Context.filterRecord.default(e);
66
+ const error = await _chunkWBHZCJSNjs.Context.filterRecord.default(e);
67
67
  return res.status(error.status).send(error);
68
68
  }
69
69
  _chunkBDIQWWHNjs.__name.call(void 0, errorHandler, "errorHandler");
70
70
  if (!Array.isArray(body))
71
- return errorHandler(new (0, _chunk32E425F6js.BadRequestException)("data format should be an array"));
71
+ return errorHandler(new (0, _chunkWBHZCJSNjs.BadRequestException)("data format should be an array"));
72
72
  try {
73
73
  return Promise.all(body.map((item) => {
74
74
  return new Promise(async (resolve) => {
75
75
  const { tag } = item;
76
76
  const meta2 = metaMap.get(tag);
77
77
  if (!meta2)
78
- return resolve(await _chunk32E425F6js.Context.filterRecord.default(new (0, _chunk32E425F6js.BadRequestException)(`"${tag}" doesn't exist`)));
78
+ return resolve(await _chunkWBHZCJSNjs.Context.filterRecord.default(new (0, _chunkWBHZCJSNjs.BadRequestException)(`"${tag}" doesn't exist`)));
79
79
  const contextData = {
80
80
  type: "fastify",
81
81
  request: req,
@@ -85,13 +85,13 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
85
85
  parallel: true,
86
86
  tag
87
87
  };
88
- const context = new (0, _chunk32E425F6js.Context)(contextData);
88
+ const context = new (0, _chunkWBHZCJSNjs.Context)(contextData);
89
89
  const [name, method] = tag.split("-");
90
90
  const { paramsType, handlers, data: { params, guards, interceptors, filter } } = meta2;
91
91
  const instance = moduleMap.get(name);
92
92
  try {
93
93
  if (!params)
94
- throw new (0, _chunk32E425F6js.BadRequestException)(`"${tag}" doesn't exist`);
94
+ throw new (0, _chunkWBHZCJSNjs.BadRequestException)(`"${tag}" doesn't exist`);
95
95
  await context.useGuard([
96
96
  ...globalGuards,
97
97
  ...guards
@@ -137,7 +137,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
137
137
  const methodTag = `${tag}-${method}`;
138
138
  const { paramsType, handlers, data: { interceptors, guards, params, plugins: plugins2, filter } } = metaMap.get(methodTag);
139
139
  fastify.register((fastify2, _opts, done2) => {
140
- _chunk32E425F6js.Context.usePlugin(plugins2).forEach((p) => {
140
+ _chunkWBHZCJSNjs.Context.usePlugin(plugins2).forEach((p) => {
141
141
  p[Symbol.for("skip-override")] = true;
142
142
  fastify2.register(p);
143
143
  });
@@ -154,7 +154,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
154
154
  parallel: false,
155
155
  tag: methodTag
156
156
  };
157
- const context = new (0, _chunk32E425F6js.Context)(contextData);
157
+ const context = new (0, _chunkWBHZCJSNjs.Context)(contextData);
158
158
  try {
159
159
  for (const name in header)
160
160
  res.header(name, header[name]);
@@ -199,7 +199,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
199
199
  done();
200
200
  if (_chunkBDIQWWHNjs.IS_DEV) {
201
201
  _optionalChain([globalThis, 'access', _8 => _8.__PS_HMR__, 'optionalAccess', _9 => _9.push, 'call', _10 => _10(async () => {
202
- _chunk32E425F6js.isAopDepInject.call(void 0, meta, {
202
+ _chunkWBHZCJSNjs.isAopDepInject.call(void 0, meta, {
203
203
  plugins,
204
204
  guards: globalGuards,
205
205
  interceptors: globalInterceptors