phecda-server 4.0.6 → 4.1.0

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.
Files changed (65) hide show
  1. package/dist/{chunk-7OB6K45T.js → chunk-32E425F6.js} +55 -55
  2. package/dist/chunk-32E425F6.js.map +1 -0
  3. package/dist/{chunk-AYJWOIAW.mjs → chunk-5KOB2WHH.mjs} +20 -2
  4. package/dist/chunk-5KOB2WHH.mjs.map +1 -0
  5. package/dist/{chunk-TZ27DHWL.js → chunk-5L4K7XEB.js} +33 -31
  6. package/dist/chunk-5L4K7XEB.js.map +1 -0
  7. package/dist/{chunk-ZPMAM4LQ.js → chunk-63KBHOSB.js} +3 -3
  8. package/dist/{chunk-AAF47ZC6.js → chunk-BDIQWWHN.js} +20 -2
  9. package/dist/chunk-BDIQWWHN.js.map +1 -0
  10. package/dist/{chunk-V7SC5EVJ.mjs → chunk-Q3V3ERU3.mjs} +2 -2
  11. package/dist/{chunk-K32VRTXB.mjs → chunk-WQBXOVND.mjs} +16 -14
  12. package/dist/chunk-WQBXOVND.mjs.map +1 -0
  13. package/dist/{chunk-GSJ5A2MA.mjs → chunk-Z6LSJTOF.mjs} +11 -11
  14. package/dist/chunk-Z6LSJTOF.mjs.map +1 -0
  15. package/dist/{types-8415bd5d.d.ts → core-d080d872.d.ts} +41 -9
  16. package/dist/index.d.ts +28 -29
  17. package/dist/index.js +61 -57
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +10 -6
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/rpc/rabbitmq/index.d.ts +3 -7
  22. package/dist/rpc/rabbitmq/index.js +22 -20
  23. package/dist/rpc/rabbitmq/index.js.map +1 -1
  24. package/dist/rpc/rabbitmq/index.mjs +17 -15
  25. package/dist/rpc/rabbitmq/index.mjs.map +1 -1
  26. package/dist/rpc/redis/index.d.ts +3 -7
  27. package/dist/rpc/redis/index.js +23 -21
  28. package/dist/rpc/redis/index.js.map +1 -1
  29. package/dist/rpc/redis/index.mjs +18 -16
  30. package/dist/rpc/redis/index.mjs.map +1 -1
  31. package/dist/server/express/index.d.ts +2 -6
  32. package/dist/server/express/index.js +28 -26
  33. package/dist/server/express/index.js.map +1 -1
  34. package/dist/server/express/index.mjs +9 -7
  35. package/dist/server/express/index.mjs.map +1 -1
  36. package/dist/server/fastify/index.d.ts +4 -8
  37. package/dist/server/fastify/index.js +30 -24
  38. package/dist/server/fastify/index.js.map +1 -1
  39. package/dist/server/fastify/index.mjs +14 -8
  40. package/dist/server/fastify/index.mjs.map +1 -1
  41. package/dist/server/h3/index.d.ts +2 -6
  42. package/dist/server/h3/index.js +28 -26
  43. package/dist/server/h3/index.js.map +1 -1
  44. package/dist/server/h3/index.mjs +9 -7
  45. package/dist/server/h3/index.mjs.map +1 -1
  46. package/dist/server/koa/index.d.ts +2 -6
  47. package/dist/server/koa/index.js +28 -26
  48. package/dist/server/koa/index.js.map +1 -1
  49. package/dist/server/koa/index.mjs +9 -7
  50. package/dist/server/koa/index.mjs.map +1 -1
  51. package/dist/test.d.ts +9 -5
  52. package/dist/test.js +10 -21
  53. package/dist/test.js.map +1 -1
  54. package/dist/test.mjs +7 -18
  55. package/dist/test.mjs.map +1 -1
  56. package/package.json +2 -2
  57. package/dist/chunk-7OB6K45T.js.map +0 -1
  58. package/dist/chunk-AAF47ZC6.js.map +0 -1
  59. package/dist/chunk-AYJWOIAW.mjs.map +0 -1
  60. package/dist/chunk-GSJ5A2MA.mjs.map +0 -1
  61. package/dist/chunk-K32VRTXB.mjs.map +0 -1
  62. package/dist/chunk-TZ27DHWL.js.map +0 -1
  63. package/dist/core-c27b4cf4.d.ts +0 -23
  64. /package/dist/{chunk-ZPMAM4LQ.js.map → chunk-63KBHOSB.js.map} +0 -0
  65. /package/dist/{chunk-V7SC5EVJ.mjs.map → chunk-Q3V3ERU3.mjs.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/common.ts","../src/utils.ts"],"names":["MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","APP_SYMBOL","IS_DEV","process","env","NODE_ENV","IS_STRICT","PS_STRICT","ERROR_SYMBOL","pc","time","log","msg","level","color","error","info","warn","date","Date","current","now","interval","console","magenta","gray","getHours","getMinutes","getSeconds"],"mappings":";;;;;;;;;AAAO,IAAMA,eAAe;AACrB,IAAMC,iBAAiB;AACvB,IAAMC,gBAAgB;AACtB,IAAMC,cAAc;AACpB,IAAMC,aAAa;AACnB,IAAMC,SAASC,QAAQC,IAAIC,aAAa;AACxC,IAAMC,YAAY,CAAC,CAACH,QAAQC,IAAIG;AAChC,IAAMC,eAAe;;;ACP5B,OAAOC,QAAQ;AAEf,IAAIC;AAEG,SAASC,IAAIC,KAAaC,QAAmC,QAAQ;AAC1E,QAAMC,QAAS;IAAEC,OAAO;IAAOC,MAAM;IAASC,MAAM;EAAS,EAAYJ;AACzE,QAAMK,OAAO,IAAIC,KAAAA;AACjB,QAAMC,UAAUD,KAAKE,IAAG;AACxB,QAAMC,WAAYZ,QAAQU,UAAUV,OAAQ,IAAIU,UAAUV,SAAS;AACnEA,SAAOU;AAEPG,UAAQZ,IAAI,GAAGF,GAAGe,QAAQ,iBAAA,KAAsBf,GAAGgB,KAAK,GAAGP,KAAKQ,SAAQ,KAAMR,KAAKS,WAAU,KAAMT,KAAKU,WAAU,GAAI,KAAKnB,GAAGK,OAAOF,GAAAA,KAAQH,GAAGgB,KAAKH,QAAAA,GAAW;AAClK;AARgBX","sourcesContent":["export const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\nexport const APP_SYMBOL = '__PS__'\nexport const IS_DEV = process.env.NODE_ENV === 'development'\nexport const IS_STRICT = !!process.env.PS_STRICT\nexport const ERROR_SYMBOL = '__PS_ERROR__'\n","import pc from 'picocolors'\n\nlet time: number\n\nexport function log(msg: string, level: 'error' | 'info' | 'warn' = 'info') {\n const color = ({ error: 'red', info: 'green', warn: 'yellow' } as const)[level]\n const date = new Date()\n const current = Date.now()\n const interval = (time && current - time) ? `+${current - time}` : ''\n time = current\n // eslint-disable-next-line no-console\n console.log(`${pc.magenta('[phecda-server]')} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`)\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/common.ts","../src/utils.ts"],"sourcesContent":["export const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\nexport const APP_SYMBOL = '__PS__'\nexport const IS_DEV = process.env.NODE_ENV === 'development'\nexport const IS_STRICT = !!process.env.PS_STRICT\nexport const ERROR_SYMBOL = '__PS_ERROR__'\n","import pc from 'picocolors'\n\nlet time: number\n\nexport function log(msg: string, level: 'error' | 'info' | 'warn' = 'info') {\n const color = ({ error: 'red', info: 'green', warn: 'yellow' } as const)[level]\n const date = new Date()\n const current = Date.now()\n const interval = (time && current - time) ? `+${current - time}` : ''\n time = current\n // eslint-disable-next-line no-console\n console.log(`${pc.magenta('[phecda-server]')} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`)\n}\n"],"mappings":";;;;;;;;;AAAO,IAAMA,eAAe;AACrB,IAAMC,iBAAiB;AACvB,IAAMC,gBAAgB;AACtB,IAAMC,cAAc;AACpB,IAAMC,aAAa;AACnB,IAAMC,SAASC,QAAQC,IAAIC,aAAa;AACxC,IAAMC,YAAY,CAAC,CAACH,QAAQC,IAAIG;AAChC,IAAMC,eAAe;;;ACP5B,OAAOC,QAAQ;AAEf,IAAIC;AAEG,SAASC,IAAIC,KAAaC,QAAmC,QAAQ;AAC1E,QAAMC,QAAS;IAAEC,OAAO;IAAOC,MAAM;IAASC,MAAM;EAAS,EAAYJ;AACzE,QAAMK,OAAO,IAAIC,KAAAA;AACjB,QAAMC,UAAUD,KAAKE,IAAG;AACxB,QAAMC,WAAYZ,QAAQU,UAAUV,OAAQ,IAAIU,UAAUV,SAAS;AACnEA,SAAOU;AAEPG,UAAQZ,IAAI,GAAGa,GAAGC,QAAQ,iBAAA,KAAsBD,GAAGE,KAAK,GAAGR,KAAKS,SAAQ,KAAMT,KAAKU,WAAU,KAAMV,KAAKW,WAAU,GAAI,KAAKL,GAAGV,OAAOF,GAAAA,KAAQY,GAAGE,KAAKJ,QAAAA,GAAW;AAClK;AARgBX;","names":["MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","APP_SYMBOL","IS_DEV","process","env","NODE_ENV","IS_STRICT","PS_STRICT","ERROR_SYMBOL","pc","time","log","msg","level","color","error","info","warn","date","Date","current","now","interval","console","pc","magenta","gray","getHours","getMinutes","getSeconds"]}
@@ -1 +0,0 @@
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 = any> {\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 tag: string, 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.tag, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.tag, 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.tag, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.tag, 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.tag, 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.tag, 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<C>(key: string, handler: C) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe(key: string, pipe: P.Pipe) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter(key: string, handler: P.Filter) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\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 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;EACVC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA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YMBOL","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","tag","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 +0,0 @@
1
- {"version":3,"sources":["../src/meta.ts","../src/compiler/rpc.ts","../src/compiler/http.ts","../src/core.ts"],"sourcesContent":["import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public paramsType: any[]) {\n\n }\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n rpc, name, method, tag,\n } = args\n if (!rpc || !rpc.type)\n return\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(){\n return {tag:'${tag}-${method}',isEvent:${!!rpc.isEvent},rpc:[${rpc.type.reduce((p, c) => {\n return `${p}\"${c}\",`\n }, '')}]}\n\n }\n `\n }\n}\n\nexport function generateRPCCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n // createRequest() {\n // let content = 'import {useC} from \\'phecda-server\\'\\n'\n // for (const name in this.classMap)\n // content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n // return content\n // }\n\n addMethod(args: P.Meta) {\n const {\n http, name, method, params, tag,\n } = args\n if (!http)\n return\n const url = http.route.replace(/\\/\\:([^\\/]*)/g, (_, js) => `/{{${js}}}`)\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(...args){\nconst ret={tag:\"${tag}-${method}\",body:{},headers:{},query:{},params:{},method:\"${http.type}\",url:\"${url}\",args}\n\n${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ''}=args[${i}]\\n${c.type === 'params' ? `ret.url=ret.url.replace('{{${c.key}}}',args[${i}])` : ''}\\n`, '')}\nreturn ret\n }\n `\n }\n}\n\nexport function generateHTTPCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { Empty, 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 { log } from './utils'\nimport { IS_DEV, UNMOUNT_SYMBOL } from './common'\nimport { generateHTTPCode, generateRPCCode } from './compiler'\nexport function Injectable() {\n return (target: any) => Empty(target)\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\n // HTTP generate code path\n http?: string\n // rpc generate code path\n rpc?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n\n // only work for warn\n const constructorSet = new WeakSet()\n const moduleGraph = new Map<string, Set<string>>()\n const { http, rpc } = 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 // work for hmr\n if (!instance[UNMOUNT_SYMBOL])\n instance[UNMOUNT_SYMBOL] = []\n\n instance[UNMOUNT_SYMBOL].push(() => {\n (emitter as any).off(eventName, fn)\n })\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 // only remove module in moduleMap(won't remove indiect module)\n async function del(tag: string) {\n if (!moduleMap.has(tag))\n return\n\n const instance = moduleMap.get(tag)\n\n debug(`unmount module \"${tag}\"`)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n\n debug(`del module \"${tag}\"`)\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 return instance\n }\n\n async function add(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n const oldInstance = await del(tag)\n\n const { instance: newModule } = await buildNestModule(Module)\n\n if (oldInstance && moduleGraph.has(tag)) {\n debug(`replace module \"${tag}\"`);\n\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === oldInstance)\n module[key] = newModule\n }\n })\n }\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 && !constructorSet.has(Module)) {\n constructorSet.add(Module)// a module will only warn once\n log(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`, 'warn')\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 debug(`instantiate module \"${tag}\"`)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n\n debug(`init module \"${tag}\"`)\n\n await registerAsync(instance)\n\n debug(`add module \"${tag}\"`)\n\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 writeCode() {\n if (http) {\n debug(`write http code to ${http}`)\n fs.promises.writeFile(http, generateHTTPCode(meta.map(item => item.data)))\n }\n if (rpc) {\n debug(`write rpc code to ${rpc}`)\n\n fs.promises.writeFile(rpc, generateRPCCode(meta.map(item => item.data)))\n }\n }\n\n writeCode()\n if (IS_DEV) {\n if (!globalThis.__PS_HMR__)\n globalThis.__PS_HMR__ = []\n\n globalThis.__PS_HMR__?.push(async (files: string[]) => {\n debug('reload files ')\n\n for (const file of files) {\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await add(module[i])\n }\n }\n writeCode()\n })\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n add,\n del,\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.http) {\n meta.http = {\n route: (baseState.http?.route || '') + (state.http.route),\n type: state.http.type,\n }\n }\n if (baseState.rpc)\n meta.rpc = baseState.rpc\n if (state.rpc) {\n meta.rpc = {\n ...meta.rpc,\n ...state.rpc,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n\n meta.params = params\n meta.filter = state.filter || baseState.filter\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.plugins = [...new Set([...baseState.plugins, ...state.plugins])]\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.plugins)\n state.plugins = []\n if (!state.guards)\n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AAChElF,SAAKmF,eAAe;SAAI,oBAAIlC,IAAI;WAAIoB,UAAUc;WAAiBX,MAAMW;OAAa;;AAElF,WAAO,IAAIC,KAAKpF,MAA2BqF,WAAW5E,UAAUiB,CAAAA,GAAIe,cAAchC,UAAUiB,CAAAA,KAAgB,CAAA,CAAE;EAChH,CAAA;AACF;AA5CSwB;AA8CT,SAAST,cAAcV,QAAarB,KAAuB;AACzD,SAAO4E,QAAQC,YAAY,qBAAqBxD,QAAQrB,GAAAA;AAC1D;AAFS+B;AAIT,SAAS8B,UAAUC,OAAY;AAC7B,MAAI,CAACA,MAAMO;AACTP,UAAMO,SAAS,CAAC;AAClB,MAAI,CAACP,MAAMQ;AACTR,UAAMQ,SAAS,CAAC;AAClB,MAAI,CAACR,MAAMS;AACTT,UAAMS,UAAU,CAAA;AAClB,MAAI,CAACT,MAAMU;AACTV,UAAMU,SAAS,CAAA;AACjB,MAAI,CAACV,MAAMW;AACTX,UAAMW,eAAe,CAAA;AACzB;AAXSZ;","names":["Meta","data","handlers","paramsType","constructor","Compiler","classMap","constructor","getContent","content","name","Object","values","reduce","p","c","addMethod","args","rpc","method","tag","type","isEvent","generateRPCCode","meta","compiler","i","Compiler","classMap","constructor","getContent","content","name","Object","values","reduce","p","c","addMethod","args","http","method","params","tag","url","route","replace","_","js","type","i","key","generateHTTPCode","meta","compiler","fs","EventEmitter","Empty","getExposeKey","getHandler","getState","injectProperty","isPhecda","registerAsync","Debug","Injectable","target","Empty","debug","Debug","emitter","EventEmitter","Factory","Modules","opts","moduleMap","Map","meta","constructorMap","constructorSet","WeakSet","moduleGraph","http","rpc","injectProperty","eventName","instance","key","options","fn","bind","v","UNMOUNT_SYMBOL","push","off","once","on","del","tag","has","get","cb","delete","i","length","data","splice","add","Module","prototype","__TAG__","name","oldInstance","newModule","buildNestModule","forEach","module","paramtypes","getParamTypes","Error","log","set","undefined","paramtypesInstances","sub","subTag","Set","getMetaFromInstance","registerAsync","writeCode","fs","promises","writeFile","generateHTTPCode","map","item","generateRPCCode","IS_DEV","globalThis","__PS_HMR__","files","file","isPhecda","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","plugins","guards","interceptors","Meta","getHandler","Reflect","getMetadata"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/meta.ts","../src/compiler/rpc.ts","../src/compiler/http.ts","../src/core.ts"],"names":["Meta","data","handlers","paramsType","constructor","Compiler","classMap","getContent","content","name","Object","values","reduce","p","c","addMethod","args","rpc","method","tag","type","isEvent","generateRPCCode","meta","compiler","i","http","params","url","route","replace","_","js","key","generateHTTPCode","fs","EventEmitter","Empty","getExposeKey","getHandler","getState","injectProperty","isPhecda","registerAsync","Debug","Injectable","target","debug","emitter","Factory","Modules","opts","moduleMap","Map","constructorMap","constructorSet","WeakSet","moduleGraph","eventName","instance","options","fn","bind","v","UNMOUNT_SYMBOL","push","off","once","on","del","has","get","cb","delete","length","splice","add","Module","prototype","__TAG__","oldInstance","newModule","buildNestModule","forEach","module","paramtypes","getParamTypes","Error","log","set","undefined","paramtypesInstances","sub","subTag","Set","getMetaFromInstance","writeCode","promises","writeFile","map","item","IS_DEV","globalThis","__PS_HMR__","files","file","vars","filter","baseState","initState","state","unshift","index","define","header","plugins","guards","interceptors","Reflect","getMetadata"],"mappings":";;;;;;;;AAEO,IAAMA,OAAN,MAAMA;EACQC;EAAqBC;EAA8BC;EAAtEC,YAAmBH,MAAqBC,UAA8BC,YAAmB;gBAAtEF;oBAAqBC;sBAA8BC;EAEtE;AACF;AAJaH;;;ACAb,IAAMK,WAAN,6BAAMA,UAAAA;EACJC,WAAsD,CAAC;EACvDF,cAAc;EAAE;EAEhBG,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWC,QAAQ,KAAKH,UAAU;AAChCE,iBAAW;uBACMC;cACTC,OAAOC,OAAO,KAAKL,SAASG,KAAK,EAAEG,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAON;EACT;EAEAO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;AACTJ,UAAMI,SAAS,CAAC;AAClB,MAAI,CAACJ,MAAMK;AACTL,UAAMK,UAAU,CAAA;AAClB,MAAI,CAACL,MAAMM;AACTN,UAAMM,SAAS,CAAA;AACjB,MAAI,CAACN,MAAMO;AACTP,UAAMO,eAAe,CAAA;AACzB;AAXSR","sourcesContent":["import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public paramsType: any[]) {\n\n }\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n rpc, name, method, tag,\n } = args\n if (!rpc || !rpc.type)\n return\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(){\n return {tag:'${tag}-${method}',isEvent:${!!rpc.isEvent},rpc:[${rpc.type.reduce((p, c) => {\n return `${p}\"${c}\",`\n }, '')}]}\n\n }\n `\n }\n}\n\nexport function generateRPCCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n // createRequest() {\n // let content = 'import {useC} from \\'phecda-server\\'\\n'\n // for (const name in this.classMap)\n // content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n // return content\n // }\n\n addMethod(args: P.Meta) {\n const {\n http, name, method, params, tag,\n } = args\n if (!http)\n return\n const url = http.route.replace(/\\/\\:([^\\/]*)/g, (_, js) => `/{{${js}}}`)\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(...args){\nconst ret={tag:\"${tag}-${method}\",body:{},headers:{},query:{},params:{},method:\"${http.type}\",url:\"${url}\",args}\n\n${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ''}=args[${i}]\\n${c.type === 'params' ? `ret.url=ret.url.replace('{{${c.key}}}',args[${i}])` : ''}\\n`, '')}\nreturn ret\n }\n `\n }\n}\n\nexport function generateHTTPCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { Empty, 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 { log } from './utils'\nimport { IS_DEV, UNMOUNT_SYMBOL } from './common'\nimport { generateHTTPCode, generateRPCCode } from './compiler'\nexport function Injectable() {\n return (target: any) => Empty(target)\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\n // HTTP generate code path\n http?: string\n // rpc generate code path\n rpc?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n\n // only work for warn\n const constructorSet = new WeakSet()\n const moduleGraph = new Map<string, Set<string>>()\n const { http, rpc } = 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 // work for hmr\n if (!instance[UNMOUNT_SYMBOL])\n instance[UNMOUNT_SYMBOL] = []\n\n instance[UNMOUNT_SYMBOL].push(() => {\n (emitter as any).off(eventName, fn)\n })\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 // only remove module in moduleMap(won't remove indiect module)\n async function del(tag: string) {\n if (!moduleMap.has(tag))\n return\n\n const instance = moduleMap.get(tag)\n\n debug(`unmount module \"${tag}\"`)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n\n debug(`del module \"${tag}\"`)\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 return instance\n }\n\n async function add(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n const oldInstance = await del(tag)\n\n const { instance: newModule } = await buildNestModule(Module)\n\n if (oldInstance && moduleGraph.has(tag)) {\n debug(`replace module \"${tag}\"`);\n\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === oldInstance)\n module[key] = newModule\n }\n })\n }\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 && !constructorSet.has(Module)) {\n constructorSet.add(Module)// a module will only warn once\n log(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`, 'warn')\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 debug(`instantiate module \"${tag}\"`)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n\n debug(`init module \"${tag}\"`)\n\n await registerAsync(instance)\n\n debug(`add module \"${tag}\"`)\n\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 writeCode() {\n if (http) {\n debug(`write http code to ${http}`)\n fs.promises.writeFile(http, generateHTTPCode(meta.map(item => item.data)))\n }\n if (rpc) {\n debug(`write rpc code to ${rpc}`)\n\n fs.promises.writeFile(rpc, generateRPCCode(meta.map(item => item.data)))\n }\n }\n\n writeCode()\n if (IS_DEV) {\n if (!globalThis.__PS_HMR__)\n globalThis.__PS_HMR__ = []\n\n globalThis.__PS_HMR__?.push(async (files: string[]) => {\n debug('reload files ')\n\n for (const file of files) {\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await add(module[i])\n }\n }\n writeCode()\n })\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n add,\n del,\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.http) {\n meta.http = {\n route: (baseState.http?.route || '') + (state.http.route),\n type: state.http.type,\n }\n }\n if (baseState.rpc)\n meta.rpc = baseState.rpc\n if (state.rpc) {\n meta.rpc = {\n ...meta.rpc,\n ...state.rpc,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n\n meta.params = params\n meta.filter = state.filter || baseState.filter\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.plugins = [...new Set([...baseState.plugins, ...state.plugins])]\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.plugins)\n state.plugins = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n"]}
@@ -1,23 +0,0 @@
1
- import { P, a as Emitter, C as Construct } from './types-8415bd5d.js';
2
-
3
- declare class Meta {
4
- data: P.Meta;
5
- handlers: P.Handler[];
6
- paramsType: any[];
7
- constructor(data: P.Meta, handlers: P.Handler[], paramsType: any[]);
8
- }
9
-
10
- declare function Injectable(): (target: any) => void;
11
- declare const emitter: Emitter;
12
- declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
13
- http?: string;
14
- rpc?: string;
15
- }): Promise<{
16
- moduleMap: Map<string, any>;
17
- meta: Meta[];
18
- constructorMap: Map<any, any>;
19
- add: (Module: Construct) => Promise<void>;
20
- del: (tag: string) => Promise<any>;
21
- }>;
22
-
23
- export { Factory as F, Injectable as I, Meta as M, emitter as e };