phecda-server 3.0.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -94,6 +94,7 @@ interface ServerMergeCtx {
94
94
  request: Request;
95
95
  response: Response;
96
96
  meta: Record<string, Meta>;
97
+ moduleMap: Record<string, any>;
97
98
  isMerge: true;
98
99
  tags?: string[];
99
100
  }
@@ -101,6 +102,7 @@ interface ServerCtx {
101
102
  request: Request;
102
103
  response: Response;
103
104
  meta: Meta;
105
+ moduleMap: Record<string, any>;
104
106
  }
105
107
  interface BaseError {
106
108
  error: true;
@@ -210,6 +212,7 @@ declare function useServerPipe(pipe: P.Pipe): void;
210
212
  declare function useServerFilter(filter: ServerFilter): void;
211
213
 
212
214
  declare const emitter: Emitter;
215
+ declare const constructorMap: Map<any, any>;
213
216
  declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
214
217
  moduleMap: Map<string, any>;
215
218
  meta: Meta[];
@@ -251,4 +254,4 @@ declare function resolveDep(ret: any, key: string): any;
251
254
  declare const SERIES_SYMBOL = "__symbol_series__";
252
255
  declare const MERGE_SYMBOL = "__symbol_req__";
253
256
 
254
- export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, getInstance, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
257
+ export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, constructorMap, defaultPipe, emitter, getInstance, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
package/dist/index.js CHANGED
@@ -75,6 +75,7 @@ __export(src_exports, {
75
75
  addInterceptor: () => addInterceptor,
76
76
  addMiddleware: () => addMiddleware,
77
77
  bindApp: () => bindApp,
78
+ constructorMap: () => constructorMap,
78
79
  defaultPipe: () => defaultPipe,
79
80
  emitter: () => emitter,
80
81
  getInstance: () => getInstance,
@@ -316,7 +317,7 @@ var _Context = class {
316
317
  for (const interceptor of interceptors) {
317
318
  if (this.history.record(interceptor, "interceptor")) {
318
319
  if (!(interceptor in _Context.interceptorsRecord))
319
- throw new FrameworkException(`can't find guard named ${interceptor}`);
320
+ throw new FrameworkException(`can't find interceptor named ${interceptor}`);
320
321
  const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge2);
321
322
  if (post)
322
323
  ret.push(post);
@@ -415,9 +416,14 @@ var Base = class {
415
416
  __name(Base, "Base");
416
417
 
417
418
  // src/utils.ts
419
+ var import_picocolors = __toESM(require("picocolors"));
418
420
  var isUndefined = /* @__PURE__ */ __name((obj) => typeof obj === "undefined", "isUndefined");
419
421
  var isNil = /* @__PURE__ */ __name((obj) => isUndefined(obj) || obj === null, "isNil");
420
422
  var isObject = /* @__PURE__ */ __name((fn) => !isNil(fn) && typeof fn === "object", "isObject");
423
+ function warn(msg) {
424
+ console.warn(`${import_picocolors.default.magenta("[phecda-server]")} ${import_picocolors.default.yellow(msg)}`);
425
+ }
426
+ __name(warn, "warn");
421
427
 
422
428
  // src/helper.ts
423
429
  function isMerge(data) {
@@ -455,6 +461,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
455
461
  request: req,
456
462
  response: res,
457
463
  meta: contextMeta,
464
+ moduleMap,
458
465
  isMerge: true
459
466
  };
460
467
  if (!Array.isArray(data))
@@ -571,7 +578,8 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
571
578
  const contextData = {
572
579
  request: req,
573
580
  meta: i,
574
- response: res
581
+ response: res,
582
+ moduleMap
575
583
  };
576
584
  const context = new ServerContext(methodTag, contextData);
577
585
  try {
@@ -623,6 +631,7 @@ __name(Meta, "Meta");
623
631
 
624
632
  // src/core.ts
625
633
  var emitter = new import_node_events.default();
634
+ var constructorMap = /* @__PURE__ */ new Map();
626
635
  async function Factory(Modules) {
627
636
  const moduleMap = /* @__PURE__ */ new Map();
628
637
  const meta = [];
@@ -635,6 +644,7 @@ async function Factory(Modules) {
635
644
  });
636
645
  for (const Module of Modules)
637
646
  await buildNestModule(Module, moduleMap, meta);
647
+ constructorMap.clear();
638
648
  return {
639
649
  moduleMap,
640
650
  meta,
@@ -650,6 +660,8 @@ async function buildNestModule(Module, map, meta) {
650
660
  instance = map.get(tag);
651
661
  if (!instance)
652
662
  throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`);
663
+ if (constructorMap.get(tag) !== Module)
664
+ warn(`Synonym module: Module taged "${tag}" has been loaded before, so phecda-server won't load Module "${Module.name}"`);
653
665
  return instance;
654
666
  }
655
667
  map.set(tag, void 0);
@@ -664,6 +676,7 @@ async function buildNestModule(Module, map, meta) {
664
676
  meta.push(...getMetaFromInstance(instance, Module.name, tag));
665
677
  await (0, import_phecda_core2.registerAsync)(instance);
666
678
  map.set(tag, instance);
679
+ constructorMap.set(tag, Module);
667
680
  return instance;
668
681
  }
669
682
  __name(buildNestModule, "buildNestModule");
@@ -931,6 +944,7 @@ __reExport(src_exports, require("phecda-core"), module.exports);
931
944
  addInterceptor,
932
945
  addMiddleware,
933
946
  bindApp,
947
+ constructorMap,
934
948
  defaultPipe,
935
949
  emitter,
936
950
  getInstance,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts"],"sourcesContent":["export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: any }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (!reflect[i]) {\n if (validate && arg)\n args[i].arg = validate(arg)\n\n continue\n }\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException)) {\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n console.error(e.message)\n }\n\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find guard named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n if (category !== 'series' && category !== 'parallel')\n return res.json(await ServerContext.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\''), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n try {\n const mergeGuards = new Set([...globalGuards])\n const mergeInterceptors = new Set([...globalInterceptors])\n\n data.forEach(({ tag }) => {\n const {\n guards,\n interceptors,\n } = Context.metaDataRecord[tag]\n guards.forEach(guard => mergeGuards.add(guard))\n interceptors.forEach(intercept => mergeInterceptors.add(intercept))\n })\n await context.useGuard([...mergeGuards], true)\n await context.useInterceptor([...mergeInterceptors], true)\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await methodMap[tag](...args))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(await context.usePost(ret))\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n handlers,\n } = Context.metaDataRecord[tag]\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await methodMap[tag](...args))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then(async (ret) => {\n res.json(await context.usePost(ret))\n })\n }\n }\n catch (e) {\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n handlers,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Patch(route: string) {\n return Route(route, 'patch')\n}\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.intercept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AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,sCAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;A5BNhB,wBAAc,wBARd;","names":["HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","handlers","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","post","req","_res","next","MERGE_SYMBOL","ServerContext","useMiddleware","res","body","category","data","contextData","request","response","isMerge","Array","isArray","json","useFilter","BadRequestException","tags","map","item","tag","context","ret","mergeGuards","Set","mergeInterceptors","forEach","guards","interceptors","Context","metaDataRecord","guard","add","intercept","useGuard","useInterceptor","name","split","reflect","params","instance","get","args","usePipe","type","key","validate","arg","resolveDep","startsWith","SERIES_SYMBOL","index","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","i","method","header","methodTag","parseMeta","bind","instanceRecord","set","isObject","send","String","import_phecda_core","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","import_phecda_core","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Patch","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts"],"sourcesContent":["export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: any }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (!reflect[i]) {\n if (validate && arg)\n args[i].arg = validate(arg)\n\n continue\n }\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException)) {\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n console.error(e.message)\n }\n\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find interceptor named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n moduleMap: Record<string, any>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","import pc from 'picocolors'\nexport const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n\nexport function warn(msg: string) {\n console.warn(`${pc.magenta('[phecda-server]')} ${pc.yellow(msg)}`)\n}\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件(work for merge request),全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n moduleMap,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n if (category !== 'series' && category !== 'parallel')\n return res.json(await ServerContext.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\''), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n try {\n const mergeGuards = new Set([...globalGuards])\n const mergeInterceptors = new Set([...globalInterceptors])\n\n data.forEach(({ tag }) => {\n const {\n guards,\n interceptors,\n } = Context.metaDataRecord[tag]\n guards.forEach(guard => mergeGuards.add(guard))\n interceptors.forEach(intercept => mergeInterceptors.add(intercept))\n })\n await context.useGuard([...mergeGuards], true)\n await context.useInterceptor([...mergeInterceptors], true)\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await methodMap[tag](...args))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(await context.usePost(ret))\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n handlers,\n } = Context.metaDataRecord[tag]\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await methodMap[tag](...args))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then(async (ret) => {\n res.json(await context.usePost(ret))\n })\n }\n }\n catch (e) {\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n handlers,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n moduleMap,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { warn } from './utils'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\nexport const constructorMap = new Map() // just for warn\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n constructorMap.clear()\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n if (constructorMap.get(tag) !== Module)\n warn(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`)\n\n return instance\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 constructorMap.set(tag, Module)\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Patch(route: string) {\n return Route(route, 'patch')\n}\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;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ACF;AAVgBN;AAYT,SAASY,OAAOC,KAAaX,OAAY;AAC9C,SAAO,CAACC,QAAaC,MAAoB;AACvC,QAAI,CAACA,GAAG;AACNA,UAAI;AACJD,eAASA,OAAOW;IAClB;AAEAT,yCAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,sCAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;A5BNhB,wBAAc,wBARd;","names":["HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","handlers","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","warn","msg","console","pc","magenta","yellow","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","post","req","_res","next","MERGE_SYMBOL","ServerContext","useMiddleware","res","body","category","data","contextData","request","response","isMerge","Array","isArray","json","useFilter","BadRequestException","tags","map","item","tag","context","ret","mergeGuards","Set","mergeInterceptors","forEach","guards","interceptors","Context","metaDataRecord","guard","add","intercept","useGuard","useInterceptor","name","split","reflect","params","instance","get","args","usePipe","type","key","validate","arg","resolveDep","startsWith","SERIES_SYMBOL","index","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","i","method","header","methodTag","parseMeta","bind","instanceRecord","set","isObject","send","String","import_phecda_core","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","constructorMap","Map","Factory","Modules","moduleMap","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","clear","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","warn","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","import_phecda_core","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Patch","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
package/dist/index.mjs CHANGED
@@ -236,7 +236,7 @@ var _Context = class {
236
236
  for (const interceptor of interceptors) {
237
237
  if (this.history.record(interceptor, "interceptor")) {
238
238
  if (!(interceptor in _Context.interceptorsRecord))
239
- throw new FrameworkException(`can't find guard named ${interceptor}`);
239
+ throw new FrameworkException(`can't find interceptor named ${interceptor}`);
240
240
  const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge2);
241
241
  if (post)
242
242
  ret.push(post);
@@ -335,9 +335,14 @@ var Base = class {
335
335
  __name(Base, "Base");
336
336
 
337
337
  // src/utils.ts
338
+ import pc from "picocolors";
338
339
  var isUndefined = /* @__PURE__ */ __name((obj) => typeof obj === "undefined", "isUndefined");
339
340
  var isNil = /* @__PURE__ */ __name((obj) => isUndefined(obj) || obj === null, "isNil");
340
341
  var isObject = /* @__PURE__ */ __name((fn) => !isNil(fn) && typeof fn === "object", "isObject");
342
+ function warn(msg) {
343
+ console.warn(`${pc.magenta("[phecda-server]")} ${pc.yellow(msg)}`);
344
+ }
345
+ __name(warn, "warn");
341
346
 
342
347
  // src/helper.ts
343
348
  function isMerge(data) {
@@ -375,6 +380,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
375
380
  request: req,
376
381
  response: res,
377
382
  meta: contextMeta,
383
+ moduleMap,
378
384
  isMerge: true
379
385
  };
380
386
  if (!Array.isArray(data))
@@ -491,7 +497,8 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
491
497
  const contextData = {
492
498
  request: req,
493
499
  meta: i,
494
- response: res
500
+ response: res,
501
+ moduleMap
495
502
  };
496
503
  const context = new ServerContext(methodTag, contextData);
497
504
  try {
@@ -543,6 +550,7 @@ __name(Meta, "Meta");
543
550
 
544
551
  // src/core.ts
545
552
  var emitter = new EventEmitter();
553
+ var constructorMap = /* @__PURE__ */ new Map();
546
554
  async function Factory(Modules) {
547
555
  const moduleMap = /* @__PURE__ */ new Map();
548
556
  const meta = [];
@@ -555,6 +563,7 @@ async function Factory(Modules) {
555
563
  });
556
564
  for (const Module of Modules)
557
565
  await buildNestModule(Module, moduleMap, meta);
566
+ constructorMap.clear();
558
567
  return {
559
568
  moduleMap,
560
569
  meta,
@@ -570,6 +579,8 @@ async function buildNestModule(Module, map, meta) {
570
579
  instance = map.get(tag);
571
580
  if (!instance)
572
581
  throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`);
582
+ if (constructorMap.get(tag) !== Module)
583
+ warn(`Synonym module: Module taged "${tag}" has been loaded before, so phecda-server won't load Module "${Module.name}"`);
573
584
  return instance;
574
585
  }
575
586
  map.set(tag, void 0);
@@ -584,6 +595,7 @@ async function buildNestModule(Module, map, meta) {
584
595
  meta.push(...getMetaFromInstance(instance, Module.name, tag));
585
596
  await registerAsync(instance);
586
597
  map.set(tag, instance);
598
+ constructorMap.set(tag, Module);
587
599
  return instance;
588
600
  }
589
601
  __name(buildNestModule, "buildNestModule");
@@ -850,6 +862,7 @@ export {
850
862
  addInterceptor,
851
863
  addMiddleware,
852
864
  bindApp,
865
+ constructorMap,
853
866
  defaultPipe,
854
867
  emitter,
855
868
  getInstance,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/index.ts"],"sourcesContent":["import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: any }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (!reflect[i]) {\n if (validate && arg)\n args[i].arg = validate(arg)\n\n continue\n }\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException)) {\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n console.error(e.message)\n }\n\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find guard named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件,全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n if (category !== 'series' && category !== 'parallel')\n return res.json(await ServerContext.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\''), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n try {\n const mergeGuards = new Set([...globalGuards])\n const mergeInterceptors = new Set([...globalInterceptors])\n\n data.forEach(({ tag }) => {\n const {\n guards,\n interceptors,\n } = Context.metaDataRecord[tag]\n guards.forEach(guard => mergeGuards.add(guard))\n interceptors.forEach(intercept => mergeInterceptors.add(intercept))\n })\n await context.useGuard([...mergeGuards], true)\n await context.useInterceptor([...mergeInterceptors], true)\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await methodMap[tag](...args))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(await context.usePost(ret))\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n handlers,\n } = Context.metaDataRecord[tag]\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await methodMap[tag](...args))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then(async (ret) => {\n res.json(await context.usePost(ret))\n })\n }\n }\n catch (e) {\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n handlers,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n return instance\n }\n map.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes)\n paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, Module.name, tag))\n await registerAsync(instance)\n map.set(tag, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Patch(route: string) {\n return Route(route, 'patch')\n}\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n","export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n"],"mappings":";;;;;;;;;AAAA,SAASA,UAAUC,oBAAoB;;;ACAhC,IAAMC,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQI,OAAO;IAAK;EAClG;AACF;AARaP;;;ACEN,IAAMQ,oBAAN,cAAgCC,cAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;AFGN,IAAMI,cAAc;EAEzB,MAAMC,UAAUC,MAAqCC,SAAgB;AACnE,eAAWC,KAAKF,MAAM;AACpB,YAAM,EAAEG,UAAUC,IAAG,IAAKJ,KAAKE;AAC/B,UAAIC,aAAa;AACf;AACF,UAA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ASR,QAAQC,KAAKG,KAAAA;EACxB;AACF;AAdgBgB;;;AFvET,SAASE,OAAOC,MAAcC,OAAe;AAClD,SAAO,CAACC,QAAaC,MAAmB;AACtCC,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMI;AACTJ,YAAMI,SAAS,CAAC;AAElBJ,UAAMI,OAAOT,QAAQC;AACrBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAVgBN;AAYT,SAASY,OAAOC,KAAaX,OAAY;AAC9C,SAAO,CAACC,QAAaC,MAAoB;AACvC,QAAI,CAACA,GAAG;AACNA,UAAI;AACJD,eAASA,OAAOW;IAClB;AAEAT,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;AGNhB,cAAc;","names":["isPhecda","plainToClass","HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","handlers","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","isUndefined","obj","isNil","isObject","fn","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","post","req","_res","next","MERGE_SYMBOL","ServerContext","useMiddleware","res","body","category","data","contextData","request","response","isMerge","Array","isArray","json","useFilter","BadRequestException","tags","map","item","tag","context","ret","mergeGuards","Set","mergeInterceptors","forEach","guards","interceptors","Context","metaDataRecord","guard","add","intercept","useGuard","useInterceptor","name","split","reflect","params","instance","get","args","usePipe","type","key","validate","arg","resolveDep","startsWith","SERIES_SYMBOL","index","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","i","method","header","methodTag","parseMeta","bind","instanceRecord","set","isObject","send","String","fs","EventEmitter","getExposeKey","getHandler","getState","injectProperty","registerAsync","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","Factory","Modules","moduleMap","Map","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","setModelVar","setState","setModelVar","setState","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","setModelVar","setState","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Patch","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
1
+ {"version":3,"sources":["../src/pipe.ts","../src/exception/base.ts","../src/exception/validate.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/filter.ts","../src/history.ts","../src/context/base.ts","../src/context/server.ts","../src/types.ts","../src/utils.ts","../src/helper.ts","../src/common.ts","../src/server/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/index.ts"],"sourcesContent":["import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe = {\n // todo: add more params\n async transform(args: { arg: any; validate: any }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (!reflect[i]) {\n if (validate && arg)\n args[i].arg = validate(arg)\n\n continue\n }\n\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: true })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n args[i].arg = ret.data\n }\n else {\n if ([Number, Boolean].includes(reflect[i])) {\n args[i].arg = reflect[i](arg)\n\n if (reflect[i] === Number && Object.is(args[i].arg, NaN))\n throw new ValidateException(`parameter ${Number(i) + 1} should be a number`)\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as P.Pipe\n","export class HttpException extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, error: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { HttpException } from './base'\n\nexport class NotFoundException extends HttpException {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { HttpException } from './base'\n\nexport class ConflictException extends HttpException {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadGatewayException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { HttpException } from './base'\n\nexport class InvalidInputException extends HttpException {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { HttpException } from './base'\n\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { HttpException } from './base'\n\nexport class PayloadLargeException extends HttpException {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { HttpException } from './base'\n\nexport class TimeoutException extends HttpException {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { HttpException } from './base'\n\nexport class UnauthorizedException extends HttpException {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { HttpException } from './base'\n\nexport class ServiceUnavailableException extends HttpException {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { HttpException } from './base'\n\nexport class FrameworkException extends HttpException {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import { HttpException, UndefinedException } from './exception'\nimport type { ServerFilter } from './types'\n\nexport const serverFilter: ServerFilter = (e: any) => {\n if (!(e instanceof HttpException)) {\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n console.error(e.message)\n }\n\n return e.data\n}\n","export class Phistroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n","import { ForbiddenException, FrameworkException } from '../exception'\nimport { Phistroy } from '../history'\n\nimport type { Meta } from '../meta'\nimport type { P } from '../types'\n\nexport abstract class Context<Data = any> {\n method: string\n params: string[]\n\n static metaRecord: Record<string, Meta> = {}\n static metaDataRecord: Record<string, ReturnType<typeof parseMeta>> = {}\n static instanceRecord: Record<string, any> = {}\n static guardsRecord: Record<string, any> = {}\n static interceptorsRecord: Record<string, any > = {}\n // static serverRecord: Record<string, Context> = {}\n post: ((...params: any) => any)[]\n history = new Phistroy()\n\n constructor(public key: string, public data: Data) {\n }\n\n static registerGuard(key: string, handler: any) {\n Context.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Context.interceptorsRecord[key] = handler\n }\n\n async useGuard(guards: string[], isMerge = false) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardsRecord))\n throw new FrameworkException(`can't find guard named ${guard}`)\n if (!await Context.guardsRecord[guard](this.data, isMerge))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async useInterceptor(interceptors: string[], isMerge = false) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorsRecord))\n throw new FrameworkException(`can't find interceptor named ${interceptor}`)\n const post = await Context.interceptorsRecord[interceptor](this.data, isMerge)\n if (post)\n ret.push(post)\n }\n }\n this.post = ret\n }\n\n async usePost(data: any) {\n if (!this.post)\n return data\n for (const cb of this.post)\n data = (await cb(data)) | data\n\n return data\n }\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.registerInterceptor(key, handler)\n}\nexport function getInstance(tag: string) {\n return Context.instanceRecord[tag]\n}\n\nexport function parseMeta(meta: Meta) {\n const { data: { params, guards, interceptors, middlewares }, reflect, handlers } = meta\n return {\n guards,\n reflect,\n interceptors,\n middlewares,\n handlers,\n params: params.map((param) => {\n const { type, key, validate } = param\n return { type, key, validate }\n }),\n }\n}\n","import type { RequestHandler } from 'express'\nimport { defaultPipe } from '../pipe'\nimport { serverFilter } from '../filter'\nimport { FrameworkException } from '../exception'\nimport type { P, ServerCtx, ServerFilter, ServerMergeCtx } from '../types'\nimport { Context } from './base'\n\nexport class ServerContext extends Context<ServerCtx | ServerMergeCtx > {\n static pipe = defaultPipe\n static filter = serverFilter\n static middlewareRecord: Record<string, (...params: any) => any> = {}\n static useMiddleware(middlewares: string[]) {\n return middlewares.map((m) => {\n if (!(m in ServerContext.middlewareRecord))\n throw new FrameworkException(`can't find middleware named ${m}`)\n return ServerContext.middlewareRecord[m]\n })\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return ServerContext.pipe.transform?.(args, reflect, this.data)\n }\n\n static useFilter(arg: any, data: ServerCtx | ServerMergeCtx) {\n return ServerContext.filter(arg, data)\n }\n\n useFilter(arg: any) {\n return ServerContext.filter(arg, this.data)\n }\n}\n\nexport function addMiddleware(key: string, handler: RequestHandler) {\n ServerContext.middlewareRecord[key] = handler\n}\n\nexport function useServerPipe(pipe: P.Pipe) {\n ServerContext.pipe = pipe\n}\nexport function useServerFilter(filter: ServerFilter) {\n ServerContext.filter = filter\n}\n","import type { Request, Response } from 'express'\nimport type { Events } from 'phecda-core'\nimport type { Meta } from './meta'\nimport type { HttpException } from './exception'\nexport type Construct<T = any> = new (...args: any[]) => T\n\nexport interface Emitter {\n on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void\n removeAllListeners<N extends keyof Events>(eventName: N): void\n emit<N extends keyof Events>(eventName: N, param: Events[N]): void\n}\n\nexport type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'\n\nexport type MergeType = <R extends Promise<any>[]> (...args: R) => { [K in keyof R]: Awaited<R[K]> }\n\nexport interface ServerMergeCtx {\n request: Request\n response: Response\n meta: Record<string, Meta>\n moduleMap: Record<string, any>\n isMerge: true\n tags?: string[]\n}\n\nexport interface ServerCtx {\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\n}\nexport interface BaseError {\n error: true\n status: number\n}\nexport type ServerFilter<E extends HttpException = any> = (err: E | Error, ctx: ServerMergeCtx | ServerCtx) => any\n\nexport class Base {\n context: ServerMergeCtx | ServerCtx\n}\n\nexport namespace P{\n export interface Error extends BaseError { message: string; description: string}\n\n export type ResOrErr<R > = { [K in keyof R]: Awaited<R[K]> | Error }\n\n export type Res<T> = T\n export type Guard = ((ctx: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((ctx: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean)\n export type Interceptor = ((ctx: ServerCtx, isMerge?: false) => any) | ((ctx: ServerMergeCtx, isMerge?: true) => any)\n export interface Handler {\n error?: (arg: any) => void\n }\n export interface Meta {\n route?: {\n type: RequestType\n route: string\n }\n // mq?: {\n // queue: string\n // routeKey: string\n // options: amqplib.Options.Consume\n\n // }\n define?: any\n header: Record<string, string>\n params: { type: string; index: number; key: string; validate?: boolean }[]\n guards: string[]\n interceptors: string[]\n middlewares: string[]\n method: string\n name: string\n tag: string\n }\n export interface Pipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[], ctx: ServerCtx | ServerMergeCtx): Promise<any[]>\n }\n\n}\n","import pc from 'picocolors'\nexport const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n\nexport function warn(msg: string) {\n console.warn(`${pc.magenta('[phecda-server]')} ${pc.yellow(msg)}`)\n}\n","import type { ServerCtx, ServerMergeCtx } from './types'\n\nexport function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx {\n return !!(data as ServerMergeCtx).isMerge\n}\n\nexport function resolveDep(ret: any, key: string) {\n if (key)\n return ret?.[key]\n return ret\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { Express, Router } from 'express'\nimport { Context, ServerContext, parseMeta } from '../context'\nimport { isObject } from '../utils'\nimport { resolveDep } from '../helper'\nimport { MERGE_SYMBOL, SERIES_SYMBOL } from '../common'\nimport type { Factory } from '../core'\nimport { BadRequestException } from '../exception'\nimport type { Meta } from '../meta'\nimport type { ServerMergeCtx } from '../types'\n\nexport interface Options {\n/**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n /**\n * 专用路由的中间件(work for merge request),全局中间件请在bindApp以外设置\n */\n middlewares?: string[]\n}\n\nexport function bindApp(app: Express | Router, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, middlewares: proMiddle } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], middlewares: [], ...options } as Required<Options>\n const methodMap = {} as Record<string, (...args: any[]) => any>\n const contextMeta = {} as Record<string, Meta>\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true\n next()\n }, ...ServerContext.useMiddleware(proMiddle), async (req, res) => {\n const { body: { category, data } } = req\n\n const contextData = {\n request: req,\n response: res,\n meta: contextMeta,\n moduleMap,\n isMerge: true,\n } as unknown as ServerMergeCtx\n\n if (!Array.isArray(data))\n return res.json(await ServerContext.useFilter(new BadRequestException('data format should be an array'), contextData))\n\n if (category !== 'series' && category !== 'parallel')\n return res.json(await ServerContext.useFilter(new BadRequestException('category should be \\'parallel\\' or \\'series\\''), contextData))\n\n contextData.tags = data.map((item: any) => item.tag)\n\n const context = new ServerContext(route, contextData)\n const ret = [] as any[]\n try {\n const mergeGuards = new Set([...globalGuards])\n const mergeInterceptors = new Set([...globalInterceptors])\n\n data.forEach(({ tag }) => {\n const {\n guards,\n interceptors,\n } = Context.metaDataRecord[tag]\n guards.forEach(guard => mergeGuards.add(guard))\n interceptors.forEach(intercept => mergeInterceptors.add(intercept))\n })\n await context.useGuard([...mergeGuards], true)\n await context.useInterceptor([...mergeInterceptors], true)\n\n if (category === 'series') {\n for (const item of data) {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n } = Context.metaDataRecord[tag]\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n if (typeof arg === 'string' && arg.startsWith(SERIES_SYMBOL)) {\n const [, index, argKey] = arg.split('@')\n return { arg: resolveDep(ret[Number(index)], argKey || key), validate }\n }\n\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n\n ret.push(await methodMap[tag](...args))\n }\n catch (e: any) {\n const m = Context.metaRecord[tag]\n m.handlers.forEach(handler => handler.error?.(e))\n ret.push(await context.useFilter(e))\n }\n }\n return res.json(await context.usePost(ret))\n }\n if (category === 'parallel') {\n return Promise.all(data.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const [name] = tag.split('-')\n const {\n reflect,\n params,\n handlers,\n } = Context.metaDataRecord[tag]\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n const arg = resolveDep(item[type], key)\n return { arg, validate }\n }), reflect) as any\n instance.context = contextData\n resolve(await methodMap[tag](...args))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then(async (ret) => {\n res.json(await context.usePost(ret))\n })\n }\n }\n catch (e) {\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n for (const i of meta) {\n const { name, method, route, header, tag } = i.data\n const instance = moduleMap.get(tag)!\n const methodTag = `${tag}-${method}`\n contextMeta[methodTag] = i\n Context.metaRecord[methodTag] = i\n let {\n guards,\n reflect,\n interceptors,\n params,\n handlers,\n middlewares,\n } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : (Context.metaDataRecord[methodTag] = parseMeta(i))\n\n guards = [...globalGuards!, ...guards]\n interceptors = [...globalInterceptors!, ...interceptors]\n\n const handler = instance[method].bind(instance)\n methodMap[methodTag] = handler\n Context.instanceRecord[name] = instance\n if (route) {\n (app as Express)[route.type](route.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {\n const contextData = {\n request: req,\n meta: i,\n response: res,\n moduleMap,\n }\n const context = new ServerContext(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard(guards)\n await context.useInterceptor(interceptors)\n const args = await context.usePipe(params.map(({ type, key, validate }) => {\n return { arg: resolveDep((req as any)[type], key), validate }\n }), reflect)\n instance.context = contextData\n\n const ret = await context.usePost(await handler(...args))\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e)\n res.status(err.status).json(err)\n }\n })\n }\n }\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { getExposeKey, getHandler, getState, injectProperty, registerAsync } from 'phecda-core'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { warn } from './utils'\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\nexport const constructorMap = new Map() // just for warn\n\nexport async function Factory(Modules: (new (...args: any) => any)[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n for (const Module of Modules)\n await buildNestModule(Module, moduleMap, meta)\n\n constructorMap.clear()\n return { moduleMap, meta, output: (p = 'pmeta.js') => fs.writeFileSync(p, JSON.stringify(meta.map(item => item.data))) }\n}\n\nasync function buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Meta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n\n if (map.has(tag)) {\n instance = map.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n if (constructorMap.get(tag) !== Module)\n warn(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`)\n\n return instance\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 constructorMap.set(tag, Module)\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string, tag: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.route) {\n meta.route = {\n route: (baseState.route?.route || '') + (state.route.route),\n type: state.route.type,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n meta.params = params\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamtypes(instance, i as string) || [])\n })\n}\n\nfunction getParamtypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public reflect: any[]) {\n\n }\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.header)\n state.header = {}\n\n state.header[name] = value\n setState(target, k, state)\n }\n}\n\nexport function Define(key: string, value: any) {\n return (target: any, k?: PropertyKey) => {\n if (!k) {\n k = '__CLASS'\n target = target.prototype\n }\n\n setModelVar(target, k)\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.define)\n state.define = {}\n\n state.define[key] = value\n setState(target, k, state)\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: any): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModelVar(target, k)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(k) || {}\n if (!state.params)\n state.params = []\n\n state.params.push({ type, key, index, validate })\n setState(target, k, state)\n }\n}\n\nexport function Body(key = '', pipeOpts?: any) {\n return BaseParam('body', key, pipeOpts)\n}\nexport function Query(key = '', pipeOpts?: any) {\n return BaseParam('query', key, pipeOpts)\n}\nexport function Param(key: string, pipeOpts?: any) {\n return BaseParam('params', key, pipeOpts)\n}\n","import { setModelVar, setState } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n state.route = {\n route,\n type,\n }\n setState(target, key, state)\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Patch(route: string) {\n return Route(route, 'patch')\n}\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n\nexport function Guard(...guards: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.guards)\n state.guards = []\n state.guards.push(...guards)\n setState(target, key, state)\n }\n}\n\nexport function Middle(...middlewares: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.middlewares)\n state.middlewares = []\n state.middlewares.push(...middlewares)\n setState(target, key, state)\n }\n}\n\nexport function Interceptor(...interceptors: string[]): any {\n return (target: any, key?: PropertyKey) => {\n if (!key)\n key = '__CLASS'\n target = key === '__CLASS' ? target.prototype : target\n\n setModelVar(target, key)\n\n const state = target._namespace.__STATE_NAMESPACE__.get(key) || {}\n if (!state.interceptors)\n state.interceptors = []\n state.interceptors.push(...interceptors)\n setState(target, key, state)\n }\n}\n","export * from './context'\nexport * from './types'\nexport * from './server/express'\nexport * from './core'\nexport * from './decorators'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\nexport * from 'phecda-core'\nexport * from './helper'\nexport * from './common'\n"],"mappings":";;;;;;;;;AAAA,SAASA,UAAUC,oBAAoB;;;ACAhC,IAAMC,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQI,OAAO;IAAK;EAClG;AACF;AARaP;;;ACEN,IAAMQ,oBAAN,cAAgCC,cAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;AFGN,IAAMI,cAAc;EAEzB,MAAMC,UAAUC,MAAqCC,SAAgB;AACnE,eAAWC,KAAKF,MAAM;AACpB,YAAM,EAAEG,UAAUC,IAAG,IAAKJ,KAAKE;AAC/B,UAAIC,aAAa;AACf;AACF,UAAI,CAACF,QAAQC,IAAI;AACf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CAACrB,QAAaC,QAAsB;AACzC,QAAI,CAACA;AACHA,YAAM;AACRD,aAASC,QAAQ,YAAYD,OAAOE,YAAYF;AAEhDG,IAAAA,aAAYH,QAAQC,GAAAA;AAEpB,UAAMG,QAAQJ,OAAOK,WAAWC,oBAAoBC,IAAIN,GAAAA,KAAQ,CAAC;AACjE,QAAI,CAACG,MAAMiB;AACTjB,YAAMiB,eAAe,CAAA;AACvBjB,UAAMiB,aAAaJ,KAAI,GAAII,YAAAA;AAC3Bb,IAAAA,UAASR,QAAQC,KAAKG,KAAAA;EACxB;AACF;AAdgBgB;;;AFvET,SAASE,OAAOC,MAAcC,OAAe;AAClD,SAAO,CAACC,QAAaC,MAAmB;AACtCC,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMI;AACTJ,YAAMI,SAAS,CAAC;AAElBJ,UAAMI,OAAOT,QAAQC;AACrBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAVgBN;AAYT,SAASY,OAAOC,KAAaX,OAAY;AAC9C,SAAO,CAACC,QAAaC,MAAoB;AACvC,QAAI,CAACA,GAAG;AACNA,UAAI;AACJD,eAASA,OAAOW;IAClB;AAEAT,IAAAA,aAAYF,QAAQC,CAAAA;AACpB,UAAME,QAAQH,OAAOI,WAAWC,oBAAoBC,IAAIL,CAAAA,KAAM,CAAC;AAC/D,QAAI,CAACE,MAAMS;AACTT,YAAMS,SAAS,CAAC;AAElBT,UAAMS,OAAOF,OAAOX;AACpBS,IAAAA,UAASR,QAAQC,GAAGE,KAAAA;EACtB;AACF;AAfgBM;;;AGNhB,cAAc;","names":["isPhecda","plainToClass","HttpException","Error","message","status","description","constructor","data","error","ValidateException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","isPhecda","ret","plainToClass","err","length","ValidateException","data","Number","Boolean","includes","Object","is","NaN","map","item","UndefinedException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","NotFoundException","HttpException","constructor","message","ConflictException","HttpException","constructor","message","BadGatewayException","HttpException","constructor","message","InvalidInputException","HttpException","constructor","message","UnsupportedMediaTypeException","HttpException","constructor","message","PayloadLargeException","HttpException","constructor","message","TimeoutException","HttpException","constructor","message","UnauthorizedException","HttpException","constructor","message","ServiceUnavailableException","HttpException","constructor","message","FrameworkException","HttpException","constructor","message","serverFilter","e","HttpException","console","error","stack","UndefinedException","message","data","Phistroy","guard","interceptor","record","name","type","includes","push","Context","key","data","method","params","post","history","constructor","Phistroy","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","guards","isMerge","guard","record","FrameworkException","ForbiddenException","useInterceptor","interceptors","ret","interceptor","push","usePost","cb","metaRecord","metaDataRecord","instanceRecord","addGuard","addInterceptor","getInstance","tag","parseMeta","meta","middlewares","reflect","handlers","map","param","type","validate","ServerContext","Context","useMiddleware","middlewares","map","m","middlewareRecord","FrameworkException","usePipe","args","reflect","pipe","transform","data","useFilter","arg","filter","defaultPipe","serverFilter","addMiddleware","key","handler","useServerPipe","useServerFilter","Base","context","pc","isUndefined","obj","isNil","isObject","fn","warn","msg","console","pc","magenta","yellow","isMerge","data","resolveDep","ret","key","SERIES_SYMBOL","MERGE_SYMBOL","bindApp","app","meta","moduleMap","options","globalGuards","globalInterceptors","route","middlewares","proMiddle","methodMap","contextMeta","post","req","_res","next","MERGE_SYMBOL","ServerContext","useMiddleware","res","body","category","data","contextData","request","response","isMerge","Array","isArray","json","useFilter","BadRequestException","tags","map","item","tag","context","ret","mergeGuards","Set","mergeInterceptors","forEach","guards","interceptors","Context","metaDataRecord","guard","add","intercept","useGuard","useInterceptor","name","split","reflect","params","instance","get","args","usePipe","type","key","validate","arg","resolveDep","startsWith","SERIES_SYMBOL","index","argKey","Number","push","e","m","metaRecord","handlers","handler","error","usePost","Promise","all","resolve","then","err","status","i","method","header","methodTag","parseMeta","bind","instanceRecord","set","isObject","send","String","fs","EventEmitter","getExposeKey","getHandler","getState","injectProperty","registerAsync","Meta","data","handlers","reflect","constructor","emitter","EventEmitter","constructorMap","Map","Factory","Modules","moduleMap","meta","injectProperty","eventName","instance","key","options","fn","bind","v","once","on","Module","buildNestModule","clear","output","p","fs","writeFileSync","JSON","stringify","map","item","data","paramtypes","getParamtypes","tag","prototype","__TAG__","name","has","get","Error","warn","set","undefined","paramtypesInstances","i","push","getMetaFromInstance","registerAsync","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","middlewares","Set","guards","interceptors","Meta","getHandler","Reflect","getMetadata","setModelVar","setState","setModelVar","setState","BaseParam","type","key","validate","target","k","index","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","params","push","setState","Body","pipeOpts","Query","Param","setModelVar","setState","Route","route","type","target","key","prototype","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","setState","Get","Post","Put","Patch","Delete","Controller","Guard","guards","push","Middle","middlewares","Interceptor","interceptors","Header","name","value","target","k","setModelVar","state","_namespace","__STATE_NAMESPACE__","get","header","setState","Define","key","prototype","define"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "provide express middlewares, `nestjs` format",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,7 +29,7 @@
29
29
  "vite": "^4.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "eventemitter3": "^5.0.0",
32
+ "picocolors": "^1.0.0",
33
33
  "reflect-metadata": "^0.1.13",
34
34
  "phecda-core": "2.0.0"
35
35
  },