phecda-server 1.2.3 → 1.3.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.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/wrong-meta.ts","../src/exception/not-found.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/context/micro.ts","../src/compiler.ts","../src/utils.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/decorators/micro.ts","../src/vite/index.ts","../src/config.ts","../src/micro-services/rabbitmq.ts","../src/client/axios.ts","../src/client/server.ts"],"sourcesContent":["export * from './context'\nexport * from './types'\nexport * from './compiler'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './vite'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './micro-services/rabbitmq'\nexport * from './client/server'\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nexport interface ValidatePipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[]): Promise<any[]>\n}\n\nexport const defaultPipe = {\n async transform(args: { arg: any; validate: boolean }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (validate && !(arg?.constructor === reflect[i])) {\n throw new ValidateException(`${arg} is not ${reflect[i].name}`)\n }\n else {\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: false })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as ValidatePipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n\n// export class BaseException extends Error {\n// constructor(public message: string, public description = 'Base exception') {\n// super(message)\n// }\n\n// get data() {\n// return { message: this.message, description: this.description, status: this.status, error: true }\n// }\n// }\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class WrongMetaException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Meta is not correct')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nexport type ErrorFilter<E extends HttpException = any> = (err: E | Error, contextData: any) => any\n\nexport const serverFilter: ErrorFilter = (e: any) => {\n if (!(e instanceof HttpException))\n e = new UndefinedException(e.message || e)\n return e.data\n}\n\nexport const rabbitMqFilter: ErrorFilter = (e: any, data) => {\n const { channel, message } = data\n channel!.reject(message!, true)\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { WrongMetaException } from '../exception/wrong-meta'\nimport { Phistroy } from '../history'\nimport { ForbiddenException } from '../exception'\n\nimport type { Pmeta } from '../meta'\n\nexport abstract class Pcontext {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Pmeta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, (req: any, isMerge: boolean) => boolean> = {}\n static interceptorsRecord: Record<string, (req: any, isMerge: boolean) => any > = {}\n // static serverRecord: Record<string, Pcontext> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n constructor(public key: string, public data: any) {\n }\n\n static registerGuard(key: string, handler: any) {\n Pcontext.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Pcontext.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Pcontext.guardsRecord))\n throw new WrongMetaException(`can't find guard named ${guard}`)\n if (!await Pcontext.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Pcontext.interceptorsRecord))\n throw new WrongMetaException(`can't find guard named ${interceptor}`)\n const post = await Pcontext.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: (contextData: any, isMerge: boolean) => boolean) {\n Pcontext.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: (contextData: any, isMerge: boolean) => any) {\n Pcontext.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Pcontext.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Pmeta) {\n const { data: { params, guards, interceptors, middlewares }, reflect } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { ValidatePipe } from '../pipe'\nimport { defaultPipe } from '../pipe'\nimport type { ErrorFilter } from '../filter'\nimport { serverFilter } from '../filter'\nimport { WrongMetaException } from '../exception/wrong-meta'\nimport { Pcontext } from './base'\n\nexport class ServerContext extends Pcontext {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new WrongMetaException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: (...params: any) => any) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: ValidatePipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ErrorFilter) {\n ServerContext.filter = filter\n}\n","import type { ValidatePipe } from '../pipe'\nimport { defaultPipe } from '../pipe'\nimport type { ErrorFilter } from '../filter'\nimport { rabbitMqFilter } from '../filter'\nimport { WrongMetaException } from '../exception/wrong-meta'\nimport { Pcontext } from './base'\n\nexport class RabbitMqContext extends Pcontext {\n static pipe = defaultPipe\n static filter = rabbitMqFilter\n static middlewareRecord: Record<string, (...params: any) => boolean> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in RabbitMqContext.middlewareRecord))\n throw new WrongMetaException(`can't find middleware named ${m}`)\n return RabbitMqContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return RabbitMqContext.pipe.transform?.(args, reflect)\n }\n\n useFilter(arg: any) {\n return RabbitMqContext.filter(arg, this.data)\n }\n}\nexport function useMqPipe(pipe: ValidatePipe) {\n RabbitMqContext.pipe = pipe\n}\nexport function useMqFilter(filter: ErrorFilter) {\n RabbitMqContext.filter = filter\n}\n","import type { RequestType } from './types'\n\nexport class Pcompiler {\n content = ''\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(className: string, methodName: string, route = '', requestType: RequestType | '' = '', params: { type: string; key: string; index: number }[] = []) {\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n if (!this.classMap[className])\n this.classMap[className] = {}\n this.classMap[className][methodName] = `\n ${methodName}(${genParams(params)}){\nconst ret={tag:\"${className}-${methodName}\",body:{},query:{},params:{},realParam:'',method:\"${requestType}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n\n addMqMethod(className: string, methodName: string, exchange = '', routeKey = '', queue = '', params: { type: string; key: string; index: number }[] = []) {\n if (!this.classMap[className])\n this.classMap[className] = {}\n this.classMap[className][methodName] = `\n ${methodName}(${genParams(params)}){\nconst ret={tag:\"${className}-${methodName}\",exchange:\"${exchange}\",routeKey:\"${routeKey}\",queue:\"${queue}\",args:{}}\n${params.reduce((p, c, i) => `${p}ret.args.${c.key}=arg${i}\\n`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n let index = 0\n return decorators.reduce((p) => {\n return `${`${p}arg${index++}`},`\n }, '')\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n\n/**\n * @experiment\n */\nexport class Wrap<F, T> {\n constructor(public v1: F,\n public V2: T) {\n\n }\n\n get value() {\n return this.V2\n }\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const REQ_SYMBOL = '__symbol_req__'\n","import type { Express } from 'express'\nimport { Pcontext, ServerContext, parseMeta } from '../context'\nimport { isObject, resolveDep } from '../utils'\nimport { REQ_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { NotFoundException } from '../exception/not-found'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n for (const i of meta) {\n const { name, method, route, header } = i.data\n const instance = moduleMap.get(name)!\n const tag = `${name}-${method}`\n\n Pcontext.metaRecord[tag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n middlewares,\n } = Pcontext.metaDataRecord[tag] ? Pcontext.metaDataRecord[tag] : (Pcontext.metaDataRecord[tag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[tag] = handler\n Pcontext.instanceRecord[name] = instance\n if (route) {\n app[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n tag,\n response: res,\n }\n const context = new ServerContext(tag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.meta = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n i.handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n\n app.post(route, (req, _res, next) => {\n (req as any)[REQ_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const contextData = {\n request: req,\n response: res,\n }\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n\n const { body: { category, data } } = req\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Pcontext.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new NotFoundException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.meta = contextData\n\n ret.push(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Pcontext.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(ret)\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Pcontext.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new NotFoundException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.meta = contextData\n resolve(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Pcontext.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.json(ret)\n })\n }\n\n res.json(await context.useFilter(new NotFoundException('category should be \\'parallel\\' or \\'series\\'')))\n })\n}\n","import 'reflect-metadata'\nimport EventEmitter from 'events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, PhecdaEmitter, ServerMeta } from './types'\nimport { Pmeta } from './meta'\n\n// TODO: support both phecda-emitter types and origin emitter type in future\nexport const emitter: PhecdaEmitter = new EventEmitter() as any\n\nexport async function Factory<T>(Modules: Construct<T>[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Pmeta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta) as InstanceType<Construct<T>>\n\n return { moduleMap, meta }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Pmeta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const name = Module.prototype._namespace?.__TAG__ || Module.name\n if (map.has(name)) {\n instance = map.get(name)\n if (!instance)\n throw new Error(`exist Circular Module dep--${Module}`)\n\n return instance\n }\n map.set(name, undefined)\n if (paramtypes) {\n for (const i in paramtypes)\n paramtypes[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypes)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name))\n await registerAsync(instance)\n map.set(name, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as ServerMeta\n initState(baseState)\n return vars.map((i) => {\n const state = (getState(instance, i) || {}) as ServerMeta\n if (baseState.route && state.route)\n state.route.route = baseState.route.route + state.route.route\n state.name = name\n state.method = i\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 state.params = params\n initState(state)\n state.header = Object.assign({}, baseState.header, state.header)\n state.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n state.guards = [...new Set([...baseState.guards, ...state.guards])]\n state.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Pmeta(state as unknown as ServerMeta, getHandler(instance, i), getParamtypes(instance, i) || [])\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.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { PHandler, ServerMeta } from './types'\n\nexport class Pmeta {\n constructor(public data: ServerMeta, public handlers: PHandler[], public reflect: any[]) {\n\n }\n}\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function Inject(_target: any) { }\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModalVar(target, k)\n mergeState(target, k, {\n header: { name, value },\n })\n }\n}\n\nexport * from './param'\nexport * from './route'\n\nexport * from './micro'\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: boolean): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModalVar(target, k)\n mergeState(target, k, {\n params: [{ type, key, index, validate }],\n })\n }\n}\n\nexport function Body(key = '', validate?: boolean) {\n return BaseParam('body', key, validate)\n}\nexport function Query(key: string, validate?: boolean) {\n return BaseParam('query', key, validate)\n}\nexport function Param(key: string, validate?: boolean) {\n return BaseParam('params', key, validate)\n}\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n route: {\n route,\n type,\n },\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n route: {\n route,\n type,\n },\n })\n }\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n guards: [...guards],\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n guards: [...guards],\n })\n }\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n middlewares: [...middlewares],\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n middlewares: [...middlewares],\n })\n }\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n interceptors: [...interceptors],\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n interceptors: [...interceptors],\n })\n }\n }\n}\n","import { mergeState, setModalVar } from 'phecda-core'\nimport type amqplib from 'amqplib'\nexport function MQ(queue: string, routeKey: string, options?: amqplib.Options.Consume) {\n return (target: any, k: PropertyKey) => {\n setModalVar(target, k)\n mergeState(target, k, {\n mq: {\n queue,\n routeKey,\n options,\n },\n })\n }\n}\n","import { resolve } from 'path'\nimport type { PluginOption } from 'vite'\nimport { normalizePath } from 'vite'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\nexport function Server(localPath = 'pmeta.js'): PluginOption {\n let root: string\n let metaPath: string\n let command: string\n return {\n name: 'phecda-server-vite:client',\n enforce: 'pre',\n configResolved(config) {\n command = config.command\n root = config.root || process.cwd()\n metaPath = normalizePath(resolve(root, localPath))\n },\n\n buildStart() {\n if (command === 'build') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n\n transform(code, id) {\n if (id === metaPath) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i.name, i.method, i.route?.route, i.route?.type, i.params)\n\n return {\n code: compiler.getContent(),\n }\n }\n },\n }\n}\n","export const Pconfig = {\n rabbitmq: {\n guard: false,\n interceptor: false,\n },\n}\n","import type amqplib from 'amqplib'\n\nimport { Pcontext, RabbitMqContext, parseMeta } from '../context'\nimport { resolveDep } from '../utils'\nimport { Pconfig } from '../config'\nimport type { Factory } from '../core'\nexport async function bindMQ(ch: amqplib.Channel, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>) {\n for (const item of meta) {\n const { route, name, method, mq: { routeKey, queue: queueName, options } = {} } = item.data\n const tag = `${name}-${method}`\n Pcontext.metaRecord[tag] = item\n\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Pcontext.metaDataRecord[tag] ? Pcontext.metaDataRecord[tag] : (Pcontext.metaDataRecord[tag] = parseMeta(item))\n const instance = moduleMap.get(name)!\n const handler = instance[method].bind(instance)\n\n Pcontext.instanceRecord[name] = instance\n\n if (route) {\n const { queue } = await ch.assertQueue(route.route)\n if (queueName && routeKey)\n await ch.bindQueue(queue, queueName, routeKey)\n\n ch.consume(route.route, async (msg) => {\n if (msg !== null) {\n const content = msg.content.toString()\n\n const data = params.length > 0 ? JSON.parse(content) : content\n const contextMeta = {\n message: msg,\n content,\n channel: ch,\n\n }\n const context = new RabbitMqContext(tag, contextMeta)\n\n try {\n if (Pconfig.rabbitmq.guard)\n await context.useGuard(guards)\n if (Pconfig.rabbitmq.interceptor)\n await context.useInterceptor(interceptors)\n\n const args = await context.usePipe(params.map(({ key, validate }) => {\n return { arg: resolveDep(data, key), validate }\n }), reflect)\n\n instance.meta = contextMeta\n\n await context.usePost(await handler(...args))\n ch.ack(msg)\n }\n catch (e) {\n item.handlers.forEach(handler => handler.error?.(e))\n context.useFilter(e)\n }\n }\n else {\n // console.log('Consumer cancelled by server')\n }\n }, options)\n }\n }\n}\n\ntype MqMethod<T> = (arg: T) => void\n\n/**\n * @experiment\n */\nexport async function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channel, method: T, type?: string): Promise<MqMethod<Parameters<T>>> {\n const { exchange, routeKey, queue } = method()\n if (exchange)\n await ch.assertExchange(exchange, type!)\n\n else\n await ch.assertQueue(queue)\n\n return async (arg: Parameters<T>) => {\n const { args } = method(arg)\n const msg = Buffer.from(JSON.stringify(args))\n if (exchange)\n await ch.publish(exchange, routeKey, msg)\n\n else\n await ch.sendToQueue(queue, msg)\n }\n}\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { PError, PRes, RequestType, ResOrErr } from '../types'\nimport { SERIES_SYMBOL } from '../common'\ninterface RequestArgs {\n body: Record<string, any>\n query: Record<string, string>\n params: Record<string, string>\n realParam: string\n method: RequestType\n url: string\n tag: string\n}\ntype MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag' >\nexport function toReq(arg: RequestArgs) {\n const { body, query, realParam, method, url } = arg\n return { method, url, body, query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')}` : '', params: realParam }\n}\n\nexport const merge = (...args: RequestArgs[]) => {\n const ret = [] as MergedReqArg[]\n for (const i of args) {\n const { body, query, params, tag } = i\n ret.push({ tag, body, query, params })\n }\n\n return ret\n}\n\nexport type RequestMethod = <F extends (...args: any[]) => any >(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>\n\nexport function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>> > {\n // @ts-expect-error methods without route decorator won't send request\n return (arg: any, config?: AxiosRequestConfig) => {\n const { url, params, query, body, method } = toReq(arg as RequestArgs)\n if (!method) {\n console.warn('methods without route decorator won\\'t send request')\n return\n }\n\n const ret = [`${url}${params}${query}`] as any[]\n body && ret.push(body)\n config && ret.push(config)\n // @ts-expect-error misdirction\n return instance[method](...ret)\n }\n}\n\nexport function createSeriesReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'series',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function createParallelReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'parallel',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function isError<T = any>(data: T | PError): data is PError {\n return typeof data === 'object' && (data as any).error\n}\n\nexport function $S(index: number, key = ''): any {\n return `${SERIES_SYMBOL}@${index}@${key}`\n}\n","import type amqplib from 'amqplib'\nexport * from './axios'\n\nexport function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void> {\n return async (arg: any) => {\n const { url, body } = arg\n await channel.assertQueue(url)\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","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","constructor","ValidateException","name","isPhecda","ret","plainToClass","err","length","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","WrongMetaException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","serverFilter","e","HttpException","UndefinedException","message","data","rabbitMqFilter","channel","reject","Phistroy","guard","interceptor","record","name","type","includes","push","Pcontext","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","WrongMetaException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","map","param","type","validate","ServerContext","Pcontext","useMiddleware","middlewares","map","m","middlewareRecord","WrongMetaException","usePipe","args","reflect","pipe","transform","useFilter","arg","filter","data","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","RabbitMqContext","Pcontext","useMiddleware","middlewares","map","m","middlewareRecord","WrongMetaException","usePipe","args","reflect","pipe","transform","useFilter","arg","filter","data","defaultPipe","rabbitMqFilter","useMqPipe","useMqFilter","Pcompiler","content","classMap","constructor","getContent","name","Object","values","reduce","p","c","addMethod","className","methodName","route","requestType","params","url","replace","genParams","filter","item","key","i","type","addMqMethod","exchange","routeKey","queue","decorators","index","isUndefined","obj","isNil","isObject","fn","resolveDep","ret","key","SERIES_SYMBOL","REQ_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","i","name","method","header","data","instance","get","tag","Pcontext","metaRecord","guards","reflect","interceptors","params","metaDataRecord","parseMeta","handler","bind","instanceRecord","type","ServerContext","useMiddleware","req","res","contextData","request","response","context","set","useGuard","useInterceptor","args","usePipe","map","key","validate","arg","resolveDep","ret","usePost","isObject","json","send","String","e","handlers","forEach","error","err","useFilter","status","post","_res","next","REQ_SYMBOL","body","category","item","split","NotFoundException","startsWith","SERIES_SYMBOL","index","argKey","Number","push","m","Promise","all","resolve","then","import_phecda_core","Pmeta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","map","paramtypes","getParamtypes","name","prototype","_namespace","__TAG__","has","get","Error","set","undefined","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","item","baseState","getState","initState","state","route","method","params","unshift","index","header","Object","assign","middlewares","Set","guards","interceptors","Pmeta","getHandler","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModalVar","mergeState","params","Body","Query","Param","import_phecda_core","Route","route","type","target","key","setModalVar","mergeState","prototype","Get","Post","Put","Delete","Controller","Guard","guards","Middle","middlewares","Interceptor","interceptors","import_phecda_core","MQ","queue","routeKey","options","target","k","setModalVar","mergeState","mq","Inject","_target","Header","name","value","target","k","setModalVar","mergeState","header","Server","localPath","root","metaPath","command","name","enforce","configResolved","config","process","cwd","normalizePath","resolve","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","method","route","params","getContent","Pconfig","rabbitmq","guard","interceptor","bindMQ","ch","meta","moduleMap","item","route","name","method","mq","routeKey","queue","queueName","options","data","tag","Pcontext","metaRecord","guards","reflect","interceptors","params","metaDataRecord","parseMeta","instance","get","handler","bind","instanceRecord","assertQueue","bindQueue","consume","msg","content","toString","length","JSON","parse","contextMeta","message","channel","context","RabbitMqContext","Pconfig","rabbitmq","guard","useGuard","interceptor","useInterceptor","args","usePipe","map","key","validate","arg","resolveDep","usePost","ack","e","handlers","forEach","error","useFilter","createPub","type","exchange","assertExchange","Buffer","from","stringify","publish","sendToQueue","toReq","arg","body","query","realParam","method","url","Object","keys","length","entries","map","k","v","join","params","merge","args","ret","i","tag","push","createReq","instance","config","console","warn","createSeriesReq","key","post","category","data","createParallelReq","isError","error","$S","index","SERIES_SYMBOL","createMqReq","channel","arg","url","body","assertQueue","sendToQueue","Buffer","from","JSON","stringify"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/wrong-meta.ts","../src/exception/not-found.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/context/micro.ts","../src/compiler.ts","../src/utils.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/decorators/micro.ts","../src/config.ts","../src/micro-services/rabbitmq.ts","../src/client/axios.ts","../src/client/server.ts"],"sourcesContent":["export * from './context'\nexport * from './types'\nexport * from './compiler'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './micro-services/rabbitmq'\nexport * from './client/server'\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nexport interface ValidatePipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[]): Promise<any[]>\n}\n\nexport const defaultPipe = {\n async transform(args: { arg: any; validate: boolean }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n args[i].arg = reflect[i](arg)\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n return args.map(item => item.arg)\n },\n} as ValidatePipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n\n// export class BaseException extends Error {\n// constructor(public message: string, public description = 'Base exception') {\n// super(message)\n// }\n\n// get data() {\n// return { message: this.message, description: this.description, status: this.status, error: true }\n// }\n// }\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class WrongMetaException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Meta is not correct')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nexport type ErrorFilter<E extends HttpException = any> = (err: E | Error, contextData: any) => any\n\nexport const serverFilter: ErrorFilter = (e: any) => {\n if (!(e instanceof HttpException))\n e = new UndefinedException(e.message || e)\n return e.data\n}\n\nexport const rabbitMqFilter: ErrorFilter = (e: any, data) => {\n const { channel, message } = data\n channel!.reject(message!, true)\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { WrongMetaException } from '../exception/wrong-meta'\nimport { Phistroy } from '../history'\nimport { ForbiddenException } from '../exception'\n\nimport type { Pmeta } from '../meta'\n\nexport abstract class Pcontext {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Pmeta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, (req: any, isMerge: boolean) => boolean> = {}\n static interceptorsRecord: Record<string, (req: any, isMerge: boolean) => any > = {}\n // static serverRecord: Record<string, Pcontext> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n constructor(public key: string, public data: any) {\n }\n\n static registerGuard(key: string, handler: any) {\n Pcontext.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Pcontext.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Pcontext.guardsRecord))\n throw new WrongMetaException(`can't find guard named ${guard}`)\n if (!await Pcontext.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Pcontext.interceptorsRecord))\n throw new WrongMetaException(`can't find guard named ${interceptor}`)\n const post = await Pcontext.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: (contextData: any, isMerge: boolean) => Promise<boolean> | boolean) {\n Pcontext.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: (contextData: any, isMerge: boolean) => any) {\n Pcontext.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Pcontext.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Pmeta) {\n const { data: { params, guards, interceptors, middlewares }, reflect } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { ValidatePipe } from '../pipe'\nimport { defaultPipe } from '../pipe'\nimport type { ErrorFilter } from '../filter'\nimport { serverFilter } from '../filter'\nimport { WrongMetaException } from '../exception/wrong-meta'\nimport { Pcontext } from './base'\n\nexport class ServerContext extends Pcontext {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new WrongMetaException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: (...params: any) => any) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: ValidatePipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ErrorFilter) {\n ServerContext.filter = filter\n}\n","import type { ValidatePipe } from '../pipe'\nimport { defaultPipe } from '../pipe'\nimport type { ErrorFilter } from '../filter'\nimport { rabbitMqFilter } from '../filter'\nimport { WrongMetaException } from '../exception/wrong-meta'\nimport { Pcontext } from './base'\n\nexport class RabbitMqContext extends Pcontext {\n static pipe = defaultPipe\n static filter = rabbitMqFilter\n static middlewareRecord: Record<string, (...params: any) => boolean> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in RabbitMqContext.middlewareRecord))\n throw new WrongMetaException(`can't find middleware named ${m}`)\n return RabbitMqContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return RabbitMqContext.pipe.transform?.(args, reflect)\n }\n\n useFilter(arg: any) {\n return RabbitMqContext.filter(arg, this.data)\n }\n}\nexport function useMqPipe(pipe: ValidatePipe) {\n RabbitMqContext.pipe = pipe\n}\nexport function useMqFilter(filter: ErrorFilter) {\n RabbitMqContext.filter = filter\n}\n","import type { ServerMeta } from './types'\n\nexport class Pcompiler {\n content = ''\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: ServerMeta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n\n// addMqMethod(className: string, methodName: string, tag: string, exchange = '', routeKey = '', queue = '', params: { type: string; key: string; index: number }[] = []) {\n// if (!this.classMap[className])\n// this.classMap[className] = {}\n// this.classMap[className][methodName] = `\n// ${methodName}(${genParams(params)}){\n// const ret={tag:\"${tag}-${methodName}\",exchange:\"${exchange}\",routeKey:\"${routeKey}\",queue:\"${queue}\",args:{}}\n// ${params.reduce((p, c, i) => `${p}ret.args.${c.key}=arg${i}\\n`, '')}\n// return ret\n// }\n// `\n// }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n\n/**\n * @experiment\n */\nexport class Wrap<F, T> {\n constructor(public v1: F,\n public V2: T) {\n\n }\n\n get value() {\n return this.V2\n }\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const REQ_SYMBOL = '__symbol_req__'\n","import type { Express } from 'express'\nimport { Pcontext, ServerContext, parseMeta } from '../context'\nimport { isObject, resolveDep } from '../utils'\nimport { REQ_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { NotFoundException } from '../exception/not-found'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n\n Pcontext.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n middlewares,\n } = Pcontext.metaDataRecord[methodTag] ? Pcontext.metaDataRecord[methodTag] : (Pcontext.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Pcontext.instanceRecord[name] = instance\n if (route) {\n app[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n methodTag,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.meta = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n i.handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n\n app.post(route, (req, _res, next) => {\n (req as any)[REQ_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const contextData = {\n request: req,\n response: res,\n }\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n\n const { body: { category, data } } = req\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Pcontext.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new NotFoundException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.meta = contextData\n\n ret.push(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Pcontext.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(ret)\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Pcontext.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new NotFoundException(`\"${tag}\" doesn't exist`)\n\n await context.useGuard(guards, true)\n await context.useInterceptor(interceptors, true)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.meta = contextData\n resolve(await context.usePost(await methodMap[tag](...args)))\n }\n catch (e: any) {\n const m = Pcontext.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.json(ret)\n })\n }\n\n res.json(await context.useFilter(new NotFoundException('category should be \\'parallel\\' or \\'series\\'')))\n })\n}\n","import 'reflect-metadata'\nimport EventEmitter from 'events'\nimport fs from 'fs'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, PhecdaEmitter, ServerMeta } from './types'\nimport { Pmeta } from './meta'\n// TODO: support both phecda-emitter types and origin emitter type in future\nexport const emitter: PhecdaEmitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Pmeta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Pmeta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular Module dep--${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as ServerMeta\n initState(baseState)\n return vars.map((i) => {\n const state = (getState(instance, i) || {}) as ServerMeta\n if (baseState.route && state.route)\n state.route.route = baseState.route.route + state.route.route\n state.name = name\n state.tag = tag\n state.method = i\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 state.params = params\n initState(state)\n state.header = Object.assign({}, baseState.header, state.header)\n state.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n state.guards = [...new Set([...baseState.guards, ...state.guards])]\n state.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Pmeta(state as unknown as ServerMeta, getHandler(instance, i), getParamtypes(instance, i) || [])\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.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { PHandler, ServerMeta } from './types'\n\nexport class Pmeta {\n constructor(public data: ServerMeta, public handlers: PHandler[], public reflect: any[]) {\n\n }\n}\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function Inject(_target: any) { }\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModalVar(target, k)\n mergeState(target, k, {\n header: { name, value },\n })\n }\n}\n\nexport * from './param'\nexport * from './route'\n\nexport * from './micro'\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: boolean): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModalVar(target, k)\n mergeState(target, k, {\n params: [{ type, key, index, validate }],\n })\n }\n}\n\nexport function Body(key = '', validate?: boolean) {\n return BaseParam('body', key, validate)\n}\nexport function Query(key: string, validate?: boolean) {\n return BaseParam('query', key, validate)\n}\nexport function Param(key: string, validate?: boolean) {\n return BaseParam('params', key, validate)\n}\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n route: {\n route,\n type,\n },\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n route: {\n route,\n type,\n },\n })\n }\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n guards: [...guards],\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n guards: [...guards],\n })\n }\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n middlewares: [...middlewares],\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n middlewares: [...middlewares],\n })\n }\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n interceptors: [...interceptors],\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n interceptors: [...interceptors],\n })\n }\n }\n}\n","import { mergeState, setModalVar } from 'phecda-core'\nimport type amqplib from 'amqplib'\nexport function MQ(queue: string, routeKey: string, options?: amqplib.Options.Consume) {\n return (target: any, k: PropertyKey) => {\n setModalVar(target, k)\n mergeState(target, k, {\n mq: {\n queue,\n routeKey,\n options,\n },\n })\n }\n}\n","export const Pconfig = {\n rabbitmq: {\n guard: false,\n interceptor: false,\n },\n}\n","import type amqplib from 'amqplib'\n\nimport { Pcontext, RabbitMqContext, parseMeta } from '../context'\nimport { resolveDep } from '../utils'\nimport { Pconfig } from '../config'\nimport type { Factory } from '../core'\nexport async function bindMQ(ch: amqplib.Channel, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>) {\n for (const item of meta) {\n const { route, name, method, mq: { routeKey, queue: queueName, options } = {} } = item.data\n const tag = `${name}-${method}`\n Pcontext.metaRecord[tag] = item\n\n const {\n guards,\n reflect,\n interceptors,\n params,\n } = Pcontext.metaDataRecord[tag] ? Pcontext.metaDataRecord[tag] : (Pcontext.metaDataRecord[tag] = parseMeta(item))\n const instance = moduleMap.get(name)!\n const handler = instance[method].bind(instance)\n\n Pcontext.instanceRecord[name] = instance\n\n if (route) {\n const { queue } = await ch.assertQueue(route.route)\n if (queueName && routeKey)\n await ch.bindQueue(queue, queueName, routeKey)\n\n ch.consume(route.route, async (msg) => {\n if (msg !== null) {\n const content = msg.content.toString()\n\n const data = params.length > 0 ? JSON.parse(content) : content\n const contextMeta = {\n message: msg,\n content,\n channel: ch,\n\n }\n const context = new RabbitMqContext(tag, contextMeta)\n\n try {\n if (Pconfig.rabbitmq.guard)\n await context.useGuard(guards)\n if (Pconfig.rabbitmq.interceptor)\n await context.useInterceptor(interceptors)\n\n const args = await context.usePipe(params.map(({ key, validate }) => {\n return { arg: resolveDep(data, key), validate }\n }), reflect)\n\n instance.meta = contextMeta\n\n await context.usePost(await handler(...args))\n ch.ack(msg)\n }\n catch (e) {\n item.handlers.forEach(handler => handler.error?.(e))\n context.useFilter(e)\n }\n }\n else {\n // console.log('Consumer cancelled by server')\n }\n }, options)\n }\n }\n}\n\ntype MqMethod<T> = (arg: T) => void\n\n/**\n * @experiment\n */\nexport async function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channel, method: T, type?: string): Promise<MqMethod<Parameters<T>>> {\n const { exchange, routeKey, queue } = method()\n if (exchange)\n await ch.assertExchange(exchange, type!)\n\n else\n await ch.assertQueue(queue)\n\n return async (arg: Parameters<T>) => {\n const { args } = method(arg)\n const msg = Buffer.from(JSON.stringify(args))\n if (exchange)\n await ch.publish(exchange, routeKey, msg)\n\n else\n await ch.sendToQueue(queue, msg)\n }\n}\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { PError, PRes, RequestType, ResOrErr } from '../types'\nimport { SERIES_SYMBOL } from '../common'\ninterface RequestArgs {\n body: Record<string, any>\n query: Record<string, string>\n params: Record<string, string>\n realParam: string\n method: RequestType\n url: string\n tag: string\n}\ntype MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag' >\nexport function toReq(arg: RequestArgs) {\n const { body, query, realParam, method, url } = arg\n return { method, url, body, query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')}` : '', params: realParam }\n}\n\nexport const merge = (...args: RequestArgs[]) => {\n const ret = [] as MergedReqArg[]\n for (const i of args) {\n const { body, query, params, tag } = i\n ret.push({ tag, body, query, params })\n }\n\n return ret\n}\n\nexport type RequestMethod = <F extends (...args: any[]) => any >(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>\n\nexport function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>> > {\n // @ts-expect-error methods without route decorator won't send request\n return (arg: any, config?: AxiosRequestConfig) => {\n const { url, params, query, body, method } = toReq(arg as RequestArgs)\n if (!method) {\n console.warn('methods without route decorator won\\'t send request')\n return\n }\n\n const ret = [`${url}${params}${query}`] as any[]\n body && ret.push(body)\n config && ret.push(config)\n // @ts-expect-error misdirction\n return instance[method](...ret)\n }\n}\n\nexport function createSeriesReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'series',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function createParallelReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'parallel',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function isError<T = any>(data: T | PError): data is PError {\n return typeof data === 'object' && (data as any).error\n}\n\nexport function $S(index: number, key = ''): any {\n return `${SERIES_SYMBOL}@${index}@${key}`\n}\n","import type amqplib from 'amqplib'\nexport * from './axios'\n\nexport function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void> {\n return async (arg: any) => {\n const { url, body } = arg\n await channel.assertQueue(url)\n await channel.sendToQueue(url, Buffer.from(JSON.stringify(body)))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,yBAAuC;;;ACAhC,IAAMA,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAA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I,SAAO,CAACtB,KAAUuB,WAAgC;AAChD,UAAM,EAAElB,KAAKS,QAAQZ,OAAOD,MAAMG,OAAM,IAAKL,MAAMC,GAAAA;AACnD,QAAI,CAACI,QAAQ;AACXoB,cAAQC,KAAK,oDAAA;AACb;IACF;AAEA,UAAMR,MAAM;MAAC,GAAGZ,MAAMS,SAASZ;;AAC/BD,YAAQgB,IAAIG,KAAKnB,IAAAA;AACjBsB,cAAUN,IAAIG,KAAKG,MAAAA;AAEnB,WAAOD,SAASlB,QAAO,GAAIa,GAAAA;EAC7B;AACF;AAfgBI;AAiBT,SAASK,gBAAgBJ,UAAyBK,MAAM,sBAAiI;AAE9L,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBG;AAUT,SAASK,kBAAkBT,UAAyBK,MAAM,sBAAiI;AAEhM,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBQ;AAUT,SAASC,QAAiBF,MAAkC;AACjE,SAAO,OAAOA,SAAS,YAAaA,KAAaG;AACnD;AAFgBD;AAIT,SAASE,GAAGC,OAAeR,MAAM,IAAS;AAC/C,SAAO,GAAGS,iBAAiBD,SAASR;AACtC;AAFgBO;;;ACpET,SAASG,YAAYC,SAAwD;AAClF,SAAO,OAAOC,QAAa;AACzB,UAAM,EAAEC,KAAKC,KAAI,IAAKF;AACtB,UAAMD,QAAQI,YAAYF,GAAAA;AAC1B,UAAMF,QAAQK,YAAYH,KAAKI,OAAOC,KAAKC,KAAKC,UAAUN,IAAAA,CAAAA,CAAAA;EAC5D;AACF;AANgBJ;","names":["HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","WrongMetaException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","serverFilter","e","HttpException","UndefinedException","message","data","rabbitMqFilter","channel","reject","Phistroy","guard","interceptor","record","name","type","includes","push","Pcontext","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","WrongMetaException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","map","param","type","validate","ServerContext","Pcontext","useMiddleware","middlewares","map","m","middlewareRecord","WrongMetaException","usePipe","args","reflect","pipe","transform","useFilter","arg","filter","data","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","RabbitMqContext","Pcontext","useMiddleware","middlewares","map","m","middlewareRecord","WrongMetaException","usePipe","args","reflect","pipe","transform","useFilter","arg","filter","data","defaultPipe","rabbitMqFilter","useMqPipe","useMqFilter","Pcompiler","content","classMap","constructor","getContent","name","Object","values","reduce","p","c","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","join","isUndefined","obj","isNil","isObject","fn","resolveDep","ret","key","SERIES_SYMBOL","REQ_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","i","name","method","header","tag","data","instance","get","methodTag","Pcontext","metaRecord","guards","reflect","interceptors","params","metaDataRecord","parseMeta","handler","bind","instanceRecord","type","ServerContext","useMiddleware","req","res","contextData","request","response","context","set","useGuard","useInterceptor","args","usePipe","map","key","validate","arg","resolveDep","ret","usePost","isObject","json","send","String","e","handlers","forEach","error","err","useFilter","status","post","_res","next","REQ_SYMBOL","body","category","item","split","NotFoundException","startsWith","SERIES_SYMBOL","index","argKey","Number","push","m","Promise","all","resolve","then","import_phecda_core","Pmeta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","method","params","unshift","index","header","Object","assign","middlewares","Set","guards","interceptors","Pmeta","getHandler","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModalVar","mergeState","params","Body","Query","Param","import_phecda_core","Route","route","type","target","key","setModalVar","mergeState","prototype","Get","Post","Put","Delete","Controller","Guard","guards","Middle","middlewares","Interceptor","interceptors","import_phecda_core","MQ","queue","routeKey","options","target","k","setModalVar","mergeState","mq","Inject","_target","Header","name","value","target","k","setModalVar","mergeState","header","Pconfig","rabbitmq","guard","interceptor","bindMQ","ch","meta","moduleMap","item","route","name","method","mq","routeKey","queue","queueName","options","data","tag","Pcontext","metaRecord","guards","reflect","interceptors","params","metaDataRecord","parseMeta","instance","get","handler","bind","instanceRecord","assertQueue","bindQueue","consume","msg","content","toString","length","JSON","parse","contextMeta","message","channel","context","RabbitMqContext","Pconfig","rabbitmq","guard","useGuard","interceptor","useInterceptor","args","usePipe","map","key","validate","arg","resolveDep","usePost","ack","e","handlers","forEach","error","useFilter","createPub","type","exchange","assertExchange","Buffer","from","stringify","publish","sendToQueue","toReq","arg","body","query","realParam","method","url","Object","keys","length","entries","map","k","v","join","params","merge","args","ret","i","tag","push","createReq","instance","config","console","warn","createSeriesReq","key","post","category","data","createParallelReq","isError","error","$S","index","SERIES_SYMBOL","createMqReq","channel","arg","url","body","assertQueue","sendToQueue","Buffer","from","JSON","stringify"]}
package/dist/index.mjs CHANGED
@@ -46,16 +46,17 @@ var defaultPipe = {
46
46
  const { validate, arg } = args[i];
47
47
  if (validate === false)
48
48
  continue;
49
- if (validate && !(arg?.constructor === reflect[i])) {
50
- throw new ValidateException(`${arg} is not ${reflect[i].name}`);
49
+ if (isPhecda(reflect[i])) {
50
+ const ret = await plainToClass(reflect[i], arg, {
51
+ transform: true
52
+ });
53
+ if (ret.err.length > 0)
54
+ throw new ValidateException(ret.err[0]);
55
+ args[i].arg = ret.data;
51
56
  } else {
52
- if (isPhecda(reflect[i])) {
53
- const ret = await plainToClass(reflect[i], arg, {
54
- transform: false
55
- });
56
- if (ret.err.length > 0)
57
- throw new ValidateException(ret.err[0]);
58
- }
57
+ args[i].arg = reflect[i](arg);
58
+ if (reflect[i] === Number && Object.is(args[i].arg, NaN))
59
+ throw new ValidateException(`parameter ${Number(i) + 1} should be a number`);
59
60
  }
60
61
  }
61
62
  return args.map((item) => item.arg);
@@ -295,28 +296,17 @@ var Pcompiler = class {
295
296
  }
296
297
  return content;
297
298
  }
298
- addMethod(className, methodName, route = "", requestType = "", params = []) {
299
+ addMethod(args) {
300
+ const { route: { route = "/", type = "get" } = {}, name, method, params, tag } = args;
299
301
  const url = route.replace(/\/\:([^\/]*)/g, "");
300
- if (!this.classMap[className])
301
- this.classMap[className] = {};
302
- this.classMap[className][methodName] = `
303
- ${methodName}(${genParams(params)}){
304
- const ret={tag:"${className}-${methodName}",body:{},query:{},params:{},realParam:'',method:"${requestType}",url:"${url}"}
302
+ if (!this.classMap[name])
303
+ this.classMap[name] = {};
304
+ this.classMap[name][method] = `
305
+ ${method}(${genParams(params)}){
306
+ const ret={tag:"${tag}-${method}",body:{},query:{},params:{},realParam:'',method:"${type}",url:"${url}"}
305
307
  ${params.filter((item) => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}
306
308
  ${c.type === "params" ? `ret.realParam+='/'+arg${i}
307
309
  ` : ""}`, "")}
308
- return ret
309
- }
310
- `;
311
- }
312
- addMqMethod(className, methodName, exchange = "", routeKey = "", queue = "", params = []) {
313
- if (!this.classMap[className])
314
- this.classMap[className] = {};
315
- this.classMap[className][methodName] = `
316
- ${methodName}(${genParams(params)}){
317
- const ret={tag:"${className}-${methodName}",exchange:"${exchange}",routeKey:"${routeKey}",queue:"${queue}",args:{}}
318
- ${params.reduce((p, c, i) => `${p}ret.args.${c.key}=arg${i}
319
- `, "")}
320
310
  return ret
321
311
  }
322
312
  `;
@@ -324,10 +314,9 @@ return ret
324
314
  };
325
315
  __name(Pcompiler, "Pcompiler");
326
316
  function genParams(decorators) {
327
- let index = 0;
328
- return decorators.reduce((p) => {
329
- return `${`${p}arg${index++}`},`;
330
- }, "");
317
+ return decorators.map((_, i) => {
318
+ return `${`arg${i}`}`;
319
+ }).join(",");
331
320
  }
332
321
  __name(genParams, "genParams");
333
322
 
@@ -357,11 +346,11 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
357
346
  };
358
347
  const methodMap = {};
359
348
  for (const i of meta) {
360
- const { name, method, route: route2, header } = i.data;
361
- const instance = moduleMap.get(name);
362
- const tag = `${name}-${method}`;
363
- Pcontext.metaRecord[tag] = i;
364
- let { guards, reflect, interceptors, params, middlewares } = Pcontext.metaDataRecord[tag] ? Pcontext.metaDataRecord[tag] : Pcontext.metaDataRecord[tag] = parseMeta(i);
349
+ const { name, method, route: route2, header, tag } = i.data;
350
+ const instance = moduleMap.get(tag);
351
+ const methodTag = `${tag}-${method}`;
352
+ Pcontext.metaRecord[methodTag] = i;
353
+ let { guards, reflect, interceptors, params, middlewares } = Pcontext.metaDataRecord[methodTag] ? Pcontext.metaDataRecord[methodTag] : Pcontext.metaDataRecord[methodTag] = parseMeta(i);
365
354
  guards = [
366
355
  ...globalGuards,
367
356
  ...guards
@@ -371,16 +360,16 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
371
360
  ...interceptors
372
361
  ];
373
362
  const handler = instance[method].bind(instance);
374
- methodMap[tag] = handler;
363
+ methodMap[methodTag] = handler;
375
364
  Pcontext.instanceRecord[name] = instance;
376
365
  if (route2) {
377
366
  app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
378
367
  const contextData = {
379
368
  request: req,
380
- tag,
369
+ methodTag,
381
370
  response: res
382
371
  };
383
- const context = new ServerContext(tag, contextData);
372
+ const context = new ServerContext(methodTag, contextData);
384
373
  try {
385
374
  for (const name2 in header)
386
375
  res.set(name2, header[name2]);
@@ -454,7 +443,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
454
443
  }
455
444
  if (category === "parallel") {
456
445
  return Promise.all(data.map((item) => {
457
- return new Promise(async (resolve2) => {
446
+ return new Promise(async (resolve) => {
458
447
  const { tag } = item;
459
448
  const [name] = tag.split("-");
460
449
  const { guards, reflect, interceptors, params } = Pcontext.metaDataRecord[tag];
@@ -472,11 +461,11 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
472
461
  };
473
462
  }), reflect);
474
463
  instance.meta = contextData;
475
- resolve2(await context.usePost(await methodMap[tag](...args)));
464
+ resolve(await context.usePost(await methodMap[tag](...args)));
476
465
  } catch (e) {
477
466
  const m = Pcontext.metaRecord[tag];
478
467
  m.handlers.forEach((handler) => handler.error?.(e));
479
- resolve2(await context.useFilter(e));
468
+ resolve(await context.useFilter(e));
480
469
  }
481
470
  });
482
471
  })).then((ret2) => {
@@ -491,6 +480,7 @@ __name(bindApp, "bindApp");
491
480
  // src/core.ts
492
481
  import "reflect-metadata";
493
482
  import EventEmitter from "events";
483
+ import fs from "fs";
494
484
  import { getExposeKey, getHandler, getState, injectProperty, registerAsync } from "phecda-core";
495
485
 
496
486
  // src/meta.ts
@@ -522,35 +512,37 @@ async function Factory(Modules) {
522
512
  await buildNestModule(Module, moduleMap, meta);
523
513
  return {
524
514
  moduleMap,
525
- meta
515
+ meta,
516
+ output: (p = "pmeta.js") => fs.writeFileSync(p, JSON.stringify(meta.map((item) => item.data)))
526
517
  };
527
518
  }
528
519
  __name(Factory, "Factory");
529
520
  async function buildNestModule(Module, map, meta) {
530
521
  const paramtypes = getParamtypes(Module);
531
522
  let instance;
532
- const name = Module.prototype._namespace?.__TAG__ || Module.name;
533
- if (map.has(name)) {
534
- instance = map.get(name);
523
+ const tag = Module.prototype?.__TAG__ || Module.name;
524
+ if (map.has(tag)) {
525
+ instance = map.get(tag);
535
526
  if (!instance)
536
527
  throw new Error(`exist Circular Module dep--${Module}`);
537
528
  return instance;
538
529
  }
539
- map.set(name, void 0);
530
+ map.set(tag, void 0);
540
531
  if (paramtypes) {
532
+ const paramtypesInstances = [];
541
533
  for (const i in paramtypes)
542
- paramtypes[i] = await buildNestModule(paramtypes[i], map, meta);
543
- instance = new Module(...paramtypes);
534
+ paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta);
535
+ instance = new Module(...paramtypesInstances);
544
536
  } else {
545
537
  instance = new Module();
546
538
  }
547
- meta.push(...getMetaFromInstance(instance, Module.name));
539
+ meta.push(...getMetaFromInstance(instance, Module.name, tag));
548
540
  await registerAsync(instance);
549
- map.set(name, instance);
541
+ map.set(tag, instance);
550
542
  return instance;
551
543
  }
552
544
  __name(buildNestModule, "buildNestModule");
553
- function getMetaFromInstance(instance, name) {
545
+ function getMetaFromInstance(instance, name, tag) {
554
546
  const vars = getExposeKey(instance).filter((item) => item !== "__CLASS");
555
547
  const baseState = getState(instance, "__CLASS") || {};
556
548
  initState(baseState);
@@ -559,6 +551,7 @@ function getMetaFromInstance(instance, name) {
559
551
  if (baseState.route && state.route)
560
552
  state.route.route = baseState.route.route + state.route.route;
561
553
  state.name = name;
554
+ state.tag = tag;
562
555
  state.method = i;
563
556
  const params = [];
564
557
  for (const i2 of state.params || []) {
@@ -779,50 +772,6 @@ function Header(name, value) {
779
772
  }
780
773
  __name(Header, "Header");
781
774
 
782
- // src/vite/index.ts
783
- import { resolve } from "path";
784
- import { normalizePath } from "vite";
785
- function Server(localPath = "pmeta.js") {
786
- let root;
787
- let metaPath;
788
- let command;
789
- return {
790
- name: "phecda-server-vite:client",
791
- enforce: "pre",
792
- configResolved(config) {
793
- command = config.command;
794
- root = config.root || process.cwd();
795
- metaPath = normalizePath(resolve(root, localPath));
796
- },
797
- buildStart() {
798
- if (command === "build") {
799
- this.emitFile({
800
- type: "chunk",
801
- id: metaPath,
802
- fileName: localPath,
803
- preserveSignature: "allow-extension"
804
- });
805
- }
806
- },
807
- resolveId(id) {
808
- if (id.endsWith(".controller"))
809
- return metaPath;
810
- },
811
- transform(code, id) {
812
- if (id === metaPath) {
813
- const meta = JSON.parse(code);
814
- const compiler = new Pcompiler();
815
- for (const i of meta)
816
- compiler.addMethod(i.name, i.method, i.route?.route, i.route?.type, i.params);
817
- return {
818
- code: compiler.getContent()
819
- };
820
- }
821
- }
822
- };
823
- }
824
- __name(Server, "Server");
825
-
826
775
  // src/index.ts
827
776
  export * from "phecda-core";
828
777
 
@@ -1004,7 +953,6 @@ export {
1004
953
  Query,
1005
954
  RabbitMqContext,
1006
955
  Route,
1007
- Server,
1008
956
  ServerContext,
1009
957
  UndefinedException,
1010
958
  ValidateException,