phecda-server 4.0.5 → 4.0.7
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/{chunk-JQPX546Z.mjs → chunk-43ZXHSVH.mjs} +2 -2
- package/dist/{chunk-Q6T7HNEO.mjs → chunk-ATMZNJSE.mjs} +43 -31
- package/dist/chunk-ATMZNJSE.mjs.map +1 -0
- package/dist/{chunk-AJ2HYENF.mjs → chunk-DQUH5BP6.mjs} +28 -4
- package/dist/chunk-DQUH5BP6.mjs.map +1 -0
- package/dist/{chunk-NFAA3WFR.mjs → chunk-F5PQVQTY.mjs} +18 -11
- package/dist/chunk-F5PQVQTY.mjs.map +1 -0
- package/dist/{chunk-FAHHXHL5.js → chunk-FCLWCFQS.js} +3 -3
- package/dist/{chunk-YU7ROHTO.js → chunk-JZGLQ4FQ.js} +78 -66
- package/dist/chunk-JZGLQ4FQ.js.map +1 -0
- package/dist/{chunk-R3N4HR7U.js → chunk-WWYSLFOI.js} +39 -32
- package/dist/chunk-WWYSLFOI.js.map +1 -0
- package/dist/{chunk-LZAU5FUS.js → chunk-ZZ2QKZ46.js} +27 -3
- package/dist/chunk-ZZ2QKZ46.js.map +1 -0
- package/dist/{types-ead02c5d.d.ts → core-72951cf9.d.ts} +42 -19
- package/dist/index.d.ts +45 -26
- package/dist/index.js +123 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -32
- package/dist/index.mjs.map +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +2 -3
- package/dist/rpc/rabbitmq/index.js +19 -13
- package/dist/rpc/rabbitmq/index.js.map +1 -1
- package/dist/rpc/rabbitmq/index.mjs +13 -7
- package/dist/rpc/rabbitmq/index.mjs.map +1 -1
- package/dist/rpc/redis/index.d.ts +2 -3
- package/dist/rpc/redis/index.js +19 -13
- package/dist/rpc/redis/index.js.map +1 -1
- package/dist/rpc/redis/index.mjs +13 -7
- package/dist/rpc/redis/index.mjs.map +1 -1
- package/dist/server/express/index.d.ts +3 -3
- package/dist/server/express/index.js +37 -29
- package/dist/server/express/index.js.map +1 -1
- package/dist/server/express/index.mjs +19 -11
- package/dist/server/express/index.mjs.map +1 -1
- package/dist/server/fastify/index.d.ts +4 -4
- package/dist/server/fastify/index.js +38 -26
- package/dist/server/fastify/index.js.map +1 -1
- package/dist/server/fastify/index.mjs +23 -11
- package/dist/server/fastify/index.mjs.map +1 -1
- package/dist/server/h3/index.d.ts +5 -5
- package/dist/server/h3/index.js +34 -28
- package/dist/server/h3/index.js.map +1 -1
- package/dist/server/h3/index.mjs +16 -10
- package/dist/server/h3/index.mjs.map +1 -1
- package/dist/server/koa/index.d.ts +2 -2
- package/dist/server/koa/index.js +36 -28
- package/dist/server/koa/index.js.map +1 -1
- package/dist/server/koa/index.mjs +18 -10
- package/dist/server/koa/index.mjs.map +1 -1
- package/dist/test.d.ts +9 -5
- package/dist/test.js +10 -21
- package/dist/test.js.map +1 -1
- package/dist/test.mjs +7 -18
- package/dist/test.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-AJ2HYENF.mjs.map +0 -1
- package/dist/chunk-LZAU5FUS.js.map +0 -1
- package/dist/chunk-NFAA3WFR.mjs.map +0 -1
- package/dist/chunk-Q6T7HNEO.mjs.map +0 -1
- package/dist/chunk-R3N4HR7U.js.map +0 -1
- package/dist/chunk-YU7ROHTO.js.map +0 -1
- package/dist/core-ba036c2b.d.ts +0 -23
- /package/dist/{chunk-JQPX546Z.mjs.map → chunk-43ZXHSVH.mjs.map} +0 -0
- /package/dist/{chunk-FAHHXHL5.js.map → chunk-FCLWCFQS.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/express/bind.ts"],"sourcesContent":["import type { Express, Router } from 'express'\nimport { resolveDep } from '../../helper'\nimport { APP_SYMBOL, IS_DEV, MERGE_SYMBOL, META_SYMBOL, MODULE_SYMBOL } from '../../common'\nimport type { Factory } from '../../core'\nimport { BadRequestException } from '../../exception'\nimport type { Meta } from '../../meta'\nimport { Context, isAopDepInject } from '../../context'\n\nexport interface ExpressCtx {\n type: 'express'\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\n [key: string]: any\n}\nexport interface Options {\n\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),\n */\n plugins?: string[]\n\n}\n\nexport function bindApp(app: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, plugins } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], plugins: [], ...options } as Required<Options>\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n });\n\n (app as any)[APP_SYMBOL] = { moduleMap, meta }\n\n const metaMap = new Map<string, Meta>()\n function handleMeta() {\n metaMap.clear()\n for (const item of meta) {\n const { tag, method, http } = item.data\n if (!http?.type)\n continue\n const methodTag = `${tag}-${method}`\n metaMap.set(methodTag, item)\n }\n }\n\n async function createRoute() {\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true;\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n\n next()\n }, ...Context.usePlugin(plugins), async (req, res) => {\n const { body } = req\n\n async function errorHandler(e: any) {\n const error = await Context.filter(e)\n return res.status(error.status).json(error)\n }\n\n if (!Array.isArray(body))\n return errorHandler(new BadRequestException('data format should be an array'))\n\n try {\n return Promise.all(body.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const meta = metaMap.get(tag)\n if (!meta)\n return resolve(await Context.filter(new BadRequestException(`\"${tag}\" doesn't exist`)))\n\n const contextData = {\n type: 'express' as const,\n request: req,\n meta,\n response: res,\n moduleMap,\n parallel: true,\n }\n const context = new Context(tag, contextData)\n const [name, method] = tag.split('-')\n const {\n paramsType,\n handlers,\n data: {\n params,\n guards, interceptors,\n },\n } = meta\n\n const instance = moduleMap.get(name)\n\n try {\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n return resolve(cache)\n const args = await context.usePipe(params.map(({ type, key, pipeOpts, pipe, index }) => {\n return { arg: item.args[index], type, key, pipeOpts, pipe, index, reflect: paramsType[index] }\n })) as any\n instance.context = contextData\n const funcData = await moduleMap.get(name)[method](...args)\n resolve(await context.usePostInterceptor(funcData))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.json(ret)\n })\n }\n catch (e) {\n return errorHandler(e)\n }\n })\n for (const i of meta) {\n const { method, http, header, tag } = i.data\n\n if (!http?.type)\n continue\n\n const methodTag = `${tag}-${method}`\n\n const {\n paramsType,\n handlers,\n data: {\n interceptors,\n guards,\n params,\n plugins,\n },\n } = metaMap.get(methodTag)!;\n\n (app as Express)[http.type](http.route, (req, _res, next) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n next()\n }, ...Context.usePlugin(plugins), async (req, res) => {\n const instance = moduleMap.get(tag)!\n const contextData = {\n type: 'express' as const,\n request: req,\n meta: i,\n response: res,\n moduleMap,\n }\n const context = new Context(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined) {\n if (typeof cache === 'string')\n res.send(cache)\n\n else\n res.json(cache)\n\n return\n }\n const args = await context.usePipe(params.map(({ type, key, pipeOpts, index, pipe }) => {\n return { arg: resolveDep((req as any)[type], key), pipeOpts, pipe, key, type, index, reflect: paramsType[index] }\n }))\n\n instance.context = contextData\n const funcData = await instance[method](...args)\n const ret = await context.usePostInterceptor(funcData)\n\n if (res.writableEnded)\n return true\n\n if (typeof ret === 'string')\n res.send(ret)\n\n else\n res.json(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 handleMeta()\n createRoute()\n if (IS_DEV) {\n globalThis.__PS_HMR__?.push(async () => {\n app.stack = []// app.stack.slice(0, 1)\n handleMeta()\n createRoute()\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCO,SAASA,QAAQC,KAAa,EAAEC,WAAWC,KAAI,GAAyCC,UAAmB,CAAC,GAAG;AACpH,QAAM,EAAEC,cAAcC,oBAAoBC,OAAOC,QAAO,IAAK;IAAED,OAAO;IAAsBF,cAAc,CAAA;IAAIC,oBAAoB,CAAA;IAAIE,SAAS,CAAA;IAAI,GAAGJ;EAAQ;AAC9JK,iBAAeN,MAAM;IACnBK;IACAE,QAAQL;IACRM,cAAcL;EAChB,CAAA;AAECL,MAAYW,cAAc;IAAEV;IAAWC;EAAK;AAE7C,QAAMU,UAAU,oBAAIC,IAAAA;AACpB,WAASC,aAAa;AACpBF,YAAQG,MAAK;AACb,eAAWC,QAAQd,MAAM;AACvB,YAAM,EAAEe,KAAKC,QAAQC,KAAI,IAAKH,KAAKI;AACnC,UAAI,CAACD,MAAME;AACT;AACF,YAAMC,YAAY,GAAGL,OAAOC;AAC5BN,cAAQW,IAAID,WAAWN,IAAAA;IACzB;EACF;AATSF;AAWT,iBAAeU,cAAc;AAC1BxB,QAAgByB,KAAKnB,OAAO,CAACoB,KAAKC,MAAMC,SAAS;AAC/CF,UAAYG,gBAAgB;AAC5BH,UAAYI,iBAAiB7B;AAC7ByB,UAAYK,eAAe7B;AAE5B0B,WAAAA;IACF,GAAA,GAAMI,QAAQC,UAAU1B,OAAAA,GAAU,OAAOmB,KAAKQ,QAAQ;AACpD,YAAM,EAAEC,KAAI,IAAKT;AAEjB,qBA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,CAAA;EACF;AACF;AAlLgBzB;","names":["bindApp","app","moduleMap","meta","options","globalGuards","globalInterceptors","route","plugins","isAopDepInject","guards","interceptors","APP_SYMBOL","metaMap","Map","handleMeta","clear","item","tag","method","http","data","type","methodTag","set","createRoute","post","req","_res","next","MERGE_SYMBOL","MODULE_SYMBOL","META_SYMBOL","Context","usePlugin","res","body","errorHandler","e","error","filter","status","json","Array","isArray","BadRequestException","Promise","all","map","resolve","get","contextData","request","response","parallel","context","name","split","paramsType","handlers","params","instance","useGuard","cache","useInterceptor","undefined","args","usePipe","key","pipeOpts","pipe","index","arg","reflect","funcData","usePostInterceptor","forEach","handler","useFilter","then","ret","i","header","send","resolveDep","writableEnded","err","IS_DEV","globalThis","__PS_HMR__","push","stack"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/express/bind.ts"],"sourcesContent":["import type { Express, Request, Response, Router } from 'express'\nimport { resolveDep } from '../../helper'\nimport { APP_SYMBOL, IS_DEV, MERGE_SYMBOL, META_SYMBOL, MODULE_SYMBOL } from '../../common'\nimport type { Factory } from '../../core'\nimport { BadRequestException } from '../../exception'\nimport type { Meta } from '../../meta'\nimport { Context, isAopDepInject } from '../../context'\n\nexport interface ExpressCtx {\n type: 'express'\n request: Request\n response: Response\n meta: Meta\n moduleMap: Record<string, any>\n parallel: boolean\n [key: string]: any\n}\nexport interface Options {\n\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),\n */\n plugins?: string[]\n\n}\n\nexport function bindApp(app: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}) {\n const { globalGuards, globalInterceptors, route, plugins } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], plugins: [], ...options } as Required<Options>\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n });\n\n (app as any)[APP_SYMBOL] = { moduleMap, meta }\n\n const metaMap = new Map<string, Meta>()\n function handleMeta() {\n metaMap.clear()\n for (const item of meta) {\n const { tag, method, http } = item.data\n if (!http?.type)\n continue\n const methodTag = `${tag}-${method}`\n metaMap.set(methodTag, item)\n }\n }\n\n async function createRoute() {\n (app as Express).post(route, (req, _res, next) => {\n (req as any)[MERGE_SYMBOL] = true;\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n\n next()\n }, ...Context.usePlugin(plugins), async (req, res) => {\n const { body } = req\n\n async function errorHandler(e: any) {\n const error = await Context.filterRecord.default(e)\n return res.status(error.status).json(error)\n }\n\n if (!Array.isArray(body))\n return errorHandler(new BadRequestException('data format should be an array'))\n\n try {\n return Promise.all(body.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const meta = metaMap.get(tag)\n if (!meta)\n return resolve(await Context.filterRecord.default(new BadRequestException(`\"${tag}\" doesn't exist`)))\n\n const contextData = {\n type: 'express' as const,\n request: req,\n meta,\n response: res,\n moduleMap,\n parallel: true,\n }\n const context = new Context<ExpressCtx>(tag, contextData)\n const [name, method] = tag.split('-')\n const {\n paramsType,\n handlers,\n data: {\n params,\n guards, interceptors,\n filter,\n },\n } = meta\n\n const instance = moduleMap.get(name)\n\n try {\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n return resolve(cache)\n const args = await context.usePipe(params.map(({ type, key, pipeOpts, pipe, index }) => {\n return { arg: item.args[index], type, key, pipeOpts, pipe, index, reflect: paramsType[index] }\n })) as any\n instance.context = contextData\n const funcData = await moduleMap.get(name)[method](...args)\n resolve(await context.usePostInterceptor(funcData))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e, filter))\n }\n })\n })).then((ret) => {\n res.json(ret)\n })\n }\n catch (e) {\n return errorHandler(e)\n }\n })\n for (const i of meta) {\n const { method, http, header, tag } = i.data\n\n if (!http?.type)\n continue\n\n const methodTag = `${tag}-${method}`\n\n const {\n paramsType,\n handlers,\n data: {\n interceptors,\n guards,\n params,\n plugins,\n filter,\n },\n } = metaMap.get(methodTag)!;\n\n (app as Express)[http.type](http.route, (req, _res, next) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n next()\n }, ...Context.usePlugin(plugins), async (req, res) => {\n const instance = moduleMap.get(tag)!\n const contextData = {\n type: 'express' as const,\n request: req,\n meta: i,\n response: res,\n moduleMap,\n parallel: false,\n }\n const context = new Context<ExpressCtx>(methodTag, contextData)\n\n try {\n for (const name in header)\n res.set(name, header[name])\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined) {\n if (typeof cache === 'string')\n res.send(cache)\n\n else\n res.json(cache)\n\n return\n }\n const args = await context.usePipe(params.map(({ type, key, pipeOpts, index, pipe }) => {\n return { arg: resolveDep((req as any)[type], key), pipeOpts, pipe, key, type, index, reflect: paramsType[index] }\n }))\n\n instance.context = contextData\n const funcData = await instance[method](...args)\n const ret = await context.usePostInterceptor(funcData)\n\n if (res.writableEnded)\n return\n\n if (typeof ret === 'string')\n res.send(ret)\n\n else\n res.json(ret)\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e, filter)\n if (res.writableEnded)\n return\n res.status(err.status).json(err)\n }\n })\n }\n }\n\n handleMeta()\n createRoute()\n if (IS_DEV) {\n globalThis.__PS_HMR__?.push(async () => {\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n app.stack = []// app.stack.slice(0, 1)\n handleMeta()\n createRoute()\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsCO,SAASA,QAAQC,KAAa,EAAEC,WAAWC,KAAI,GAAyCC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AACA,gBAAMG,OAAO,MAAMZ,QAAQa,QAAQR,OAAOZ,IAAI,CAAC,EAAE3B,MAAMgD,KAAKC,UAAUE,OAAOD,KAAI,MAAO;AACtF,mBAAO;cAAEE,KAAKY,WAAY3D,IAAYL,OAAOgD,GAAAA;cAAMC;cAAUC;cAAMF;cAAKhD;cAAMmD;cAAOE,SAAShB,WAAWc;YAAO;UAClH,CAAA,CAAA;AAEAV,mBAASP,UAAUJ;AACnB,gBAAMwB,WAAW,MAAMb,SAAS5C,QAAO,GAAIiD,IAAAA;AAC3C,gBAAMc,MAAM,MAAM1B,QAAQqB,mBAAmBD,QAAAA;AAE7C,cAAIzC,IAAIoD;AACN;AAEF,cAAI,OAAOL,QAAQ;AACjB/C,gBAAIkD,KAAKH,GAAAA;;AAGT/C,gBAAIQ,KAAKuC,GAAAA;QACb,SACO5C,GAAP;AACEsB,mBAASkB,QAAQC,CAAAA,YAAWA,QAAQxC,QAAQD,CAAAA,CAAAA;AAC5C,gBAAMkD,MAAM,MAAMhC,QAAQwB,UAAU1C,GAAGwB,MAAAA;AACvC,cAAI3B,IAAIoD;AACN;AACFpD,cAAIO,OAAO8C,IAAI9C,MAAM,EAAEC,KAAK6C,GAAAA;QAC9B;MACF,CAAA;IACF;EACF;AAtJe/D;AAwJfV,aAAAA;AACAU,cAAAA;AACA,MAAIgE,QAAQ;AACVC,eAAWC,YAAYC,KAAK,YAAY;AACtCnF,qBAAeN,MAAM;QACnBK;QACAE,QAAQL;QACRM,cAAcL;MAChB,CAAA;AACAL,UAAI4F,QAAQ,CAAA;AACZ9E,iBAAAA;AACAU,kBAAAA;IACF,CAAA;EACF;AACF;AA5LgBzB;","names":["bindApp","app","moduleMap","meta","options","globalGuards","globalInterceptors","route","plugins","isAopDepInject","guards","interceptors","APP_SYMBOL","metaMap","Map","handleMeta","clear","item","tag","method","http","data","type","methodTag","set","createRoute","post","req","_res","next","MERGE_SYMBOL","MODULE_SYMBOL","META_SYMBOL","Context","usePlugin","res","body","errorHandler","e","error","filterRecord","default","status","json","Array","isArray","BadRequestException","Promise","all","map","resolve","get","contextData","request","response","parallel","context","name","split","paramsType","handlers","params","filter","instance","useGuard","cache","useInterceptor","undefined","args","usePipe","key","pipeOpts","pipe","index","arg","reflect","funcData","usePostInterceptor","forEach","handler","useFilter","then","ret","i","header","send","resolveDep","writableEnded","err","IS_DEV","globalThis","__PS_HMR__","push","stack"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { FastifyRequest, FastifyReply, FastifyPluginCallback } from 'fastify';
|
|
2
|
-
import { M as Meta, F as Factory } from '../../core-
|
|
3
|
-
import '../../types-ead02c5d.js';
|
|
1
|
+
import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback } from 'fastify';
|
|
2
|
+
import { M as Meta, F as Factory } from '../../core-72951cf9.js';
|
|
4
3
|
import 'phecda-core';
|
|
5
4
|
|
|
6
5
|
interface FastifyCtx {
|
|
@@ -9,6 +8,7 @@ interface FastifyCtx {
|
|
|
9
8
|
response: FastifyReply;
|
|
10
9
|
meta: Meta;
|
|
11
10
|
moduleMap: Record<string, any>;
|
|
11
|
+
parallel: boolean;
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}
|
|
14
14
|
interface Options {
|
|
@@ -17,6 +17,6 @@ interface Options {
|
|
|
17
17
|
globalInterceptors?: string[];
|
|
18
18
|
plugins?: string[];
|
|
19
19
|
}
|
|
20
|
-
declare function bindApp({ moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options?: Options): FastifyPluginCallback;
|
|
20
|
+
declare function bindApp(app: FastifyInstance, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options?: Options): FastifyPluginCallback;
|
|
21
21
|
|
|
22
22
|
export { FastifyCtx, Options, bindApp };
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFCLWCFQSjs = require('../../chunk-FCLWCFQS.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkJZGLQ4FQjs = require('../../chunk-JZGLQ4FQ.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkZZ2QKZ46js = require('../../chunk-ZZ2QKZ46.js');
|
|
16
16
|
|
|
17
17
|
// src/server/fastify/bind.ts
|
|
18
|
-
function bindApp({ moduleMap, meta }, options = {}) {
|
|
18
|
+
function bindApp(app, { moduleMap, meta }, options = {}) {
|
|
19
19
|
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
20
20
|
route: "/__PHECDA_SERVER__",
|
|
21
21
|
globalGuards: [],
|
|
@@ -23,7 +23,11 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
23
23
|
plugins: [],
|
|
24
24
|
...options
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
app.server[_chunkZZ2QKZ46js.APP_SYMBOL] = {
|
|
27
|
+
moduleMap,
|
|
28
|
+
meta
|
|
29
|
+
};
|
|
30
|
+
_chunkJZGLQ4FQjs.isAopDepInject.call(void 0, meta, {
|
|
27
31
|
plugins,
|
|
28
32
|
guards: globalGuards,
|
|
29
33
|
interceptors: globalInterceptors
|
|
@@ -39,16 +43,16 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
39
43
|
metaMap.set(methodTag, item);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
|
-
|
|
46
|
+
_chunkZZ2QKZ46js.__name.call(void 0, handleMeta, "handleMeta");
|
|
43
47
|
handleMeta();
|
|
44
48
|
return (fastify, _, done) => {
|
|
45
|
-
fastify[
|
|
49
|
+
fastify[_chunkZZ2QKZ46js.APP_SYMBOL] = {
|
|
46
50
|
moduleMap,
|
|
47
51
|
meta
|
|
48
52
|
};
|
|
49
53
|
fastify.register((fastify2, _opts, done2) => {
|
|
50
54
|
plugins.forEach((p) => {
|
|
51
|
-
const plugin =
|
|
55
|
+
const plugin = _chunkJZGLQ4FQjs.Context.usePlugin([
|
|
52
56
|
p
|
|
53
57
|
])[0];
|
|
54
58
|
if (plugin) {
|
|
@@ -59,19 +63,19 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
59
63
|
fastify2.post(route, async (req, res) => {
|
|
60
64
|
const { body } = req;
|
|
61
65
|
async function errorHandler(e) {
|
|
62
|
-
const error = await
|
|
66
|
+
const error = await _chunkJZGLQ4FQjs.Context.filterRecord.default(e);
|
|
63
67
|
return res.status(error.status).send(error);
|
|
64
68
|
}
|
|
65
|
-
|
|
69
|
+
_chunkZZ2QKZ46js.__name.call(void 0, errorHandler, "errorHandler");
|
|
66
70
|
if (!Array.isArray(body))
|
|
67
|
-
return errorHandler(new (0,
|
|
71
|
+
return errorHandler(new (0, _chunkJZGLQ4FQjs.BadRequestException)("data format should be an array"));
|
|
68
72
|
try {
|
|
69
73
|
return Promise.all(body.map((item) => {
|
|
70
74
|
return new Promise(async (resolve) => {
|
|
71
75
|
const { tag } = item;
|
|
72
76
|
const meta2 = metaMap.get(tag);
|
|
73
77
|
if (!meta2)
|
|
74
|
-
return resolve(await
|
|
78
|
+
return resolve(await _chunkJZGLQ4FQjs.Context.filterRecord.default(new (0, _chunkJZGLQ4FQjs.BadRequestException)(`"${tag}" doesn't exist`)));
|
|
75
79
|
const contextData = {
|
|
76
80
|
type: "fastify",
|
|
77
81
|
request: req,
|
|
@@ -80,13 +84,13 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
80
84
|
moduleMap,
|
|
81
85
|
parallel: true
|
|
82
86
|
};
|
|
83
|
-
const context = new (0,
|
|
87
|
+
const context = new (0, _chunkJZGLQ4FQjs.Context)(tag, contextData);
|
|
84
88
|
const [name, method] = tag.split("-");
|
|
85
|
-
const { paramsType, handlers, data: { params, guards, interceptors } } = meta2;
|
|
89
|
+
const { paramsType, handlers, data: { params, guards, interceptors, filter } } = meta2;
|
|
86
90
|
const instance = moduleMap.get(name);
|
|
87
91
|
try {
|
|
88
92
|
if (!params)
|
|
89
|
-
throw new (0,
|
|
93
|
+
throw new (0, _chunkJZGLQ4FQjs.BadRequestException)(`"${tag}" doesn't exist`);
|
|
90
94
|
await context.useGuard([
|
|
91
95
|
...globalGuards,
|
|
92
96
|
...guards
|
|
@@ -113,7 +117,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
113
117
|
resolve(await context.usePostInterceptor(funcData));
|
|
114
118
|
} catch (e) {
|
|
115
119
|
handlers.forEach((handler) => _optionalChain([handler, 'access', _3 => _3.error, 'optionalCall', _4 => _4(e)]));
|
|
116
|
-
resolve(await context.useFilter(e));
|
|
120
|
+
resolve(await context.useFilter(e, filter));
|
|
117
121
|
}
|
|
118
122
|
});
|
|
119
123
|
})).then((ret) => {
|
|
@@ -130,24 +134,25 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
130
134
|
if (!_optionalChain([http, 'optionalAccess', _5 => _5.type]))
|
|
131
135
|
continue;
|
|
132
136
|
const methodTag = `${tag}-${method}`;
|
|
133
|
-
const { paramsType, handlers, data: { interceptors, guards, params, plugins: plugins2 } } = metaMap.get(methodTag);
|
|
137
|
+
const { paramsType, handlers, data: { interceptors, guards, params, plugins: plugins2, filter } } = metaMap.get(methodTag);
|
|
134
138
|
fastify.register((fastify2, _opts, done2) => {
|
|
135
|
-
|
|
139
|
+
_chunkJZGLQ4FQjs.Context.usePlugin(plugins2).forEach((p) => {
|
|
136
140
|
p[Symbol.for("skip-override")] = true;
|
|
137
141
|
fastify2.register(p);
|
|
138
142
|
});
|
|
139
143
|
fastify2[http.type](http.route, async (req, res) => {
|
|
140
|
-
req[
|
|
141
|
-
req[
|
|
144
|
+
req[_chunkZZ2QKZ46js.MODULE_SYMBOL] = moduleMap;
|
|
145
|
+
req[_chunkZZ2QKZ46js.META_SYMBOL] = meta;
|
|
142
146
|
const instance = moduleMap.get(tag);
|
|
143
147
|
const contextData = {
|
|
144
148
|
type: "fastify",
|
|
145
149
|
request: req,
|
|
146
150
|
meta: i,
|
|
147
151
|
response: res,
|
|
148
|
-
moduleMap
|
|
152
|
+
moduleMap,
|
|
153
|
+
parallel: false
|
|
149
154
|
};
|
|
150
|
-
const context = new (0,
|
|
155
|
+
const context = new (0, _chunkJZGLQ4FQjs.Context)(methodTag, contextData);
|
|
151
156
|
try {
|
|
152
157
|
for (const name in header)
|
|
153
158
|
res.header(name, header[name]);
|
|
@@ -163,7 +168,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
163
168
|
return cache;
|
|
164
169
|
const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {
|
|
165
170
|
return {
|
|
166
|
-
arg:
|
|
171
|
+
arg: _chunkFCLWCFQSjs.resolveDep.call(void 0, req[type], key),
|
|
167
172
|
pipe,
|
|
168
173
|
pipeOpts,
|
|
169
174
|
key,
|
|
@@ -180,7 +185,9 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
180
185
|
return ret;
|
|
181
186
|
} catch (e) {
|
|
182
187
|
handlers.forEach((handler) => _optionalChain([handler, 'access', _6 => _6.error, 'optionalCall', _7 => _7(e)]));
|
|
183
|
-
const err = await context.useFilter(e);
|
|
188
|
+
const err = await context.useFilter(e, filter);
|
|
189
|
+
if (res.sent)
|
|
190
|
+
return;
|
|
184
191
|
res.status(err.status).send(err);
|
|
185
192
|
}
|
|
186
193
|
});
|
|
@@ -188,14 +195,19 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
188
195
|
});
|
|
189
196
|
}
|
|
190
197
|
done();
|
|
191
|
-
if (
|
|
198
|
+
if (_chunkZZ2QKZ46js.IS_DEV) {
|
|
192
199
|
_optionalChain([globalThis, 'access', _8 => _8.__PS_HMR__, 'optionalAccess', _9 => _9.push, 'call', _10 => _10(async () => {
|
|
200
|
+
_chunkJZGLQ4FQjs.isAopDepInject.call(void 0, meta, {
|
|
201
|
+
plugins,
|
|
202
|
+
guards: globalGuards,
|
|
203
|
+
interceptors: globalInterceptors
|
|
204
|
+
});
|
|
193
205
|
handleMeta();
|
|
194
206
|
})]);
|
|
195
207
|
}
|
|
196
208
|
};
|
|
197
209
|
}
|
|
198
|
-
|
|
210
|
+
_chunkZZ2QKZ46js.__name.call(void 0, bindApp, "bindApp");
|
|
199
211
|
|
|
200
212
|
|
|
201
213
|
exports.bindApp = bindApp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/fastify/bind.ts"],"names":["bindApp","moduleMap","meta","options","globalGuards","globalInterceptors","route","plugins","isAopDepInject","guards","interceptors","metaMap","Map","handleMeta","clear","item","tag","method","http","data","type","methodTag","set","fastify","_","done","APP_SYMBOL","register","_opts","forEach","p","plugin","Context","usePlugin","Symbol","for","post","req","res","body","errorHandler","e","error","filter","status","send","Array","isArray","BadRequestException","Promise","all","map","resolve","get","contextData","request","response","parallel","context","name","split","paramsType","handlers","params","instance","useGuard","cache","useInterceptor","undefined","args","usePipe","key","pipe","pipeOpts","index","arg","reflect","funcData","usePostInterceptor","handler","useFilter","then","ret","i","header","MODULE_SYMBOL","META_SYMBOL","resolveDep","sent","err","IS_DEV","globalThis","__PS_HMR__","push"],"mappings":";;;;;;;;;;;;;;;;;AAsCO,SAASA,QAAQ,EAAEC,WAAWC,KAAI,GAAyCC,UAAmB,CAAC,GAA0B;AAC9H,QAAM,EAAEC,cAAcC,oBAAoBC,OAAOC,QAAO,IAAK;IAAED,OAAO;IAAsBF,cAAc,CAAA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BAAMyD,QAAQ,MAAMR,QAAQS,eAAe;iBAAI9D;iBAAuBK;aAAa;AACnF,gBAAIwD,UAAUE;AAEZ,qBAAOF;AAET,kBAAMG,OAAO,MAAMX,QAAQY,QAAQP,OAAOZ,IAAI,CAAC,EAAE/B,MAAMmD,KAAKC,MAAMC,UAAUC,MAAK,MAAO;AACtF,qBAAO;gBAAEC,KAAKY,WAAYlD,IAAYjB,OAAOmD,GAAAA;gBAAMC;gBAAMC;gBAAUF;gBAAKnD;gBAAMsD;gBAAOE,SAASf,WAAWa;cAAO;YAClH,CAAA,CAAA;AAEAV,qBAASN,UAAUJ;AACnB,kBAAMuB,WAAW,MAAMb,SAAS/C,QAAO,GAAIoD,IAAAA;AAC3C,kBAAMa,MAAM,MAAMxB,QAAQoB,mBAAmBD,QAAAA;AAC7C,gBAAIvC,IAAIkD;AACN;AAEF,mBAAON;UACT,SACOzC,GAAP;AACEqB,qBAASjC,QAAQkD,CAAAA,YAAWA,QAAQrC,QAAQD,CAAAA,CAAAA;AAC5C,kBAAMgD,MAAM,MAAM/B,QAAQsB,UAAUvC,CAAAA;AACpCH,gBAAIM,OAAO6C,IAAI7C,MAAM,EAAEC,KAAK4C,GAAAA;UAC9B;QACF,CAAA;AACAhE,QAAAA,MAAAA;MACF,CAAA;IACF;AAEAA,SAAAA;AAEA,QAAIiE,QAAQ;AACVC,iBAAWC,YAAYC,KAAK,YAAY;AACtChF,mBAAAA;MACF,CAAA;IACF;EACF;AACF;AApMgBb","sourcesContent":["import type { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'\nimport { resolveDep } from '../../helper'\nimport { APP_SYMBOL, IS_DEV, META_SYMBOL, MODULE_SYMBOL } from '../../common'\nimport type { Factory } from '../../core'\nimport { BadRequestException } from '../../exception'\nimport type { Meta } from '../../meta'\nimport { Context, isAopDepInject } from '../../context'\n\nexport interface FastifyCtx {\n type: 'fastify'\n request: FastifyRequest\n response: FastifyReply\n meta: Meta\n moduleMap: Record<string, any>\n [key: string]: any\n}\nexport interface Options {\n\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n\n /**\n * 专用路由的插件(work for merge request),\n */\n plugins?: string[]\n\n}\n\nexport function bindApp({ moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}): FastifyPluginCallback {\n const { globalGuards, globalInterceptors, route, plugins } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], plugins: [], ...options } as Required<Options>\n // (app as any)[APP_SYMBOL] = { moduleMap, meta }\n\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n\n const metaMap = new Map<string, Meta>()\n function handleMeta() {\n metaMap.clear()\n for (const item of meta) {\n const { tag, method, http } = item.data\n if (!http?.type)\n continue\n const methodTag = `${tag}-${method}`\n metaMap.set(methodTag, item)\n }\n }\n\n handleMeta()\n\n return (fastify, _, done) => {\n (fastify as any)[APP_SYMBOL] = {\n moduleMap, meta,\n }\n // fastify.decorateRequest(MODULE_SYMBOL, null)\n // fastify.decorateRequest(META_SYMBOL, null)\n // fastify.decorateRequest(MERGE_SYMBOL, false)\n\n fastify.register((fastify, _opts, done) => {\n plugins.forEach((p) => {\n const plugin = Context.usePlugin([p])[0]\n if (plugin) {\n plugin[Symbol.for('skip-override')] = true\n\n fastify.register(plugin)\n }\n })\n fastify.post(route, async (req, res) => {\n const { body } = req as any\n\n async function errorHandler(e: any) {\n const error = await Context.filter(e)\n return res.status(error.status).send(error)\n }\n\n if (!Array.isArray(body))\n return errorHandler(new BadRequestException('data format should be an array'))\n\n try {\n return Promise.all(body.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const meta = metaMap.get(tag)\n\n if (!meta)\n return resolve(await Context.filter(new BadRequestException(`\"${tag}\" doesn't exist`)))\n\n const contextData = {\n type: 'fastify',\n request: req,\n meta,\n response: res,\n moduleMap,\n parallel: true,\n\n }\n const context = new Context(tag, contextData)\n const [name, method] = tag.split('-')\n const {\n paramsType,\n\n handlers,\n\n data: {\n params,\n guards, interceptors,\n },\n } = meta\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return resolve(cache)\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: item.args[index], type, key, pipe, pipeOpts, index, reflect: paramsType[index] }\n })) as any\n instance.context = contextData\n const funcData = await moduleMap.get(name)[method](...args)\n resolve(await context.usePostInterceptor(funcData))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.send(ret)\n })\n }\n catch (e) {\n return errorHandler(e)\n }\n })\n\n done()\n })\n\n for (const i of meta) {\n const { method, http, header, tag } = i.data\n\n if (!http?.type)\n continue\n\n const methodTag = `${tag}-${method}`\n\n const {\n paramsType,\n handlers,\n data: {\n interceptors,\n guards,\n params,\n plugins,\n },\n } = metaMap.get(methodTag)!\n\n fastify.register((fastify, _opts, done) => {\n Context.usePlugin(plugins).forEach((p) => {\n p[Symbol.for('skip-override')] = true\n\n fastify.register(p)\n })\n fastify[http.type](http.route, async (req, res) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n const instance = moduleMap.get(tag)!\n const contextData = {\n type: 'fastify',\n request: req,\n meta: i,\n response: res,\n moduleMap,\n }\n const context = new Context(methodTag, contextData)\n\n try {\n for (const name in header)\n res.header(name, header[name])\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return cache\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: resolveDep((req as any)[type], key), pipe, pipeOpts, key, type, index, reflect: paramsType[index] }\n }))\n\n instance.context = contextData\n const funcData = await instance[method](...args)\n const ret = await context.usePostInterceptor(funcData)\n if (res.sent)\n return\n\n return 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).send(err)\n }\n })\n done()\n })\n }\n\n done()\n\n if (IS_DEV) {\n globalThis.__PS_HMR__?.push(async () => {\n handleMeta()\n })\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/fastify/bind.ts"],"names":["bindApp","app","moduleMap","meta","options","globalGuards","globalInterceptors","route","plugins","server","APP_SYMBOL","isAopDepInject","guards","interceptors","metaMap","Map","handleMeta","clear","item","tag","method","http","data","type","methodTag","set","fastify","_","done","register","_opts","forEach","p","plugin","Context","usePlugin","Symbol","for","post","req","res","body","errorHandler","e","error","filterRecord","default","status","send","Array","isArray","BadRequestException","Promise","all","map","resolve","get","contextData","request","response","parallel","context","name","split","paramsType","handlers","params","filter","instance","useGuard","cache","useInterceptor","undefined","args","usePipe","key","pipe","pipeOpts","index","arg","reflect","funcData","usePostInterceptor","handler","useFilter","then","ret","i","header","MODULE_SYMBOL","META_SYMBOL","resolveDep","sent","err","IS_DEV","globalThis","__PS_HMR__","push"],"mappings":";;;;;;;;;;;;;;;;;AAuCO,SAASA,QAAQC,KAAsB,EAAEC,WAAWC,KAAI,GAAyCC,UAAmB,CAAC,GAA0B;AACpJ,QAAM,EAAEC,cAAcC,oBAAoBC,OAAOC,QAAO,IAAK;IAAED,OAAO;IAAsBF,cAAc,CAAA;IAAIC,oBAAoB,CAAA;IAAIE,SAAS,CAAA;IAAI,GAAGJ;EAAQ;AAC7JH,MAAYQ,OAAOC,cAAc;IAAER;IAAWC;EAAK;AAEpDQ,iBAAeR,MAAM;IACnBK;IACAI,QAAQP;IACRQ,cAAcP;EAChB,CAAA;AAEA,Q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AAUE;AAEZ,qBAAOF;AAET,kBAAMG,OAAO,MAAMZ,QAAQa,QAAQR,OAAOZ,IAAI,CAAC,EAAE/B,MAAMoD,KAAKC,MAAMC,UAAUC,MAAK,MAAO;AACtF,qBAAO;gBAAEC,KAAKY,WAAYpD,IAAYhB,OAAOoD,GAAAA;gBAAMC;gBAAMC;gBAAUF;gBAAKpD;gBAAMuD;gBAAOE,SAAShB,WAAWc;cAAO;YAClH,CAAA,CAAA;AAEAV,qBAASP,UAAUJ;AACnB,kBAAMwB,WAAW,MAAMb,SAAShD,QAAO,GAAIqD,IAAAA;AAC3C,kBAAMa,MAAM,MAAMzB,QAAQqB,mBAAmBD,QAAAA;AAC7C,gBAAIzC,IAAIoD;AACN;AAEF,mBAAON;UACT,SACO3C,GAAP;AACEsB,qBAASlC,QAAQoD,CAAAA,YAAWA,QAAQvC,QAAQD,CAAAA,CAAAA;AAC5C,kBAAMkD,MAAM,MAAMhC,QAAQuB,UAAUzC,GAAGwB,MAAAA;AAEvC,gBAAI3B,IAAIoD;AACN;AACFpD,gBAAIO,OAAO8C,IAAI9C,MAAM,EAAEC,KAAK6C,GAAAA;UAC9B;QACF,CAAA;AACAjE,QAAAA,MAAAA;MACF,CAAA;IACF;AAEAA,SAAAA;AAEA,QAAIkE,QAAQ;AACVC,iBAAWC,YAAYC,KAAK,YAAY;AACtCtF,uBAAeR,MAAM;UACnBK;UACAI,QAAQP;UACRQ,cAAcP;QAChB,CAAA;AACAU,mBAAAA;MACF,CAAA;IACF;EACF;AACF;AAhNgBhB","sourcesContent":["import type { FastifyInstance, FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'\nimport { resolveDep } from '../../helper'\nimport { APP_SYMBOL, IS_DEV, META_SYMBOL, MODULE_SYMBOL } from '../../common'\nimport type { Factory } from '../../core'\nimport { BadRequestException } from '../../exception'\nimport type { Meta } from '../../meta'\nimport { Context, isAopDepInject } from '../../context'\n\nexport interface FastifyCtx {\n type: 'fastify'\n request: FastifyRequest\n response: FastifyReply\n meta: Meta\n moduleMap: Record<string, any>\n parallel: boolean\n [key: string]: any\n}\nexport interface Options {\n\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n\n /**\n * 专用路由的插件(work for merge request),\n */\n plugins?: string[]\n\n}\n\nexport function bindApp(app: FastifyInstance, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}): FastifyPluginCallback {\n const { globalGuards, globalInterceptors, route, plugins } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], plugins: [], ...options } as Required<Options>\n (app as any).server[APP_SYMBOL] = { moduleMap, meta }\n\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n\n const metaMap = new Map<string, Meta>()\n function handleMeta() {\n metaMap.clear()\n for (const item of meta) {\n const { tag, method, http } = item.data\n if (!http?.type)\n continue\n const methodTag = `${tag}-${method}`\n metaMap.set(methodTag, item)\n }\n }\n\n handleMeta()\n\n return (fastify, _, done) => {\n (fastify as any)[APP_SYMBOL] = {\n moduleMap, meta,\n }\n // fastify.decorateRequest(MODULE_SYMBOL, null)\n // fastify.decorateRequest(META_SYMBOL, null)\n // fastify.decorateRequest(MERGE_SYMBOL, false)\n\n fastify.register((fastify, _opts, done) => {\n plugins.forEach((p) => {\n const plugin = Context.usePlugin([p])[0]\n if (plugin) {\n plugin[Symbol.for('skip-override')] = true\n\n fastify.register(plugin)\n }\n })\n fastify.post(route, async (req, res) => {\n const { body } = req as any\n\n async function errorHandler(e: any) {\n const error = await Context.filterRecord.default(e)\n return res.status(error.status).send(error)\n }\n\n if (!Array.isArray(body))\n return errorHandler(new BadRequestException('data format should be an array'))\n\n try {\n return Promise.all(body.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const meta = metaMap.get(tag)\n\n if (!meta)\n return resolve(await Context.filterRecord.default(new BadRequestException(`\"${tag}\" doesn't exist`)))\n\n const contextData = {\n type: 'fastify' as const,\n request: req,\n meta,\n response: res,\n moduleMap,\n parallel: true,\n\n }\n const context = new Context<FastifyCtx>(tag, contextData)\n const [name, method] = tag.split('-')\n const {\n paramsType,\n\n handlers,\n\n data: {\n params,\n guards,\n interceptors,\n filter,\n },\n } = meta\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return resolve(cache)\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: item.args[index], type, key, pipe, pipeOpts, index, reflect: paramsType[index] }\n })) as any\n instance.context = contextData\n const funcData = await moduleMap.get(name)[method](...args)\n resolve(await context.usePostInterceptor(funcData))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e, filter))\n }\n })\n })).then((ret) => {\n res.send(ret)\n })\n }\n catch (e) {\n return errorHandler(e)\n }\n })\n\n done()\n })\n\n for (const i of meta) {\n const { method, http, header, tag } = i.data\n\n if (!http?.type)\n continue\n\n const methodTag = `${tag}-${method}`\n\n const {\n paramsType,\n handlers,\n data: {\n interceptors,\n guards,\n params,\n plugins,\n filter,\n },\n } = metaMap.get(methodTag)!\n\n fastify.register((fastify, _opts, done) => {\n Context.usePlugin(plugins).forEach((p) => {\n p[Symbol.for('skip-override')] = true\n\n fastify.register(p)\n })\n fastify[http.type](http.route, async (req, res) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n const instance = moduleMap.get(tag)!\n const contextData = {\n type: 'fastify' as const,\n request: req,\n meta: i,\n response: res,\n moduleMap,\n parallel: false,\n }\n const context = new Context<FastifyCtx>(methodTag, contextData)\n\n try {\n for (const name in header)\n res.header(name, header[name])\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return cache\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: resolveDep((req as any)[type], key), pipe, pipeOpts, key, type, index, reflect: paramsType[index] }\n }))\n\n instance.context = contextData\n const funcData = await instance[method](...args)\n const ret = await context.usePostInterceptor(funcData)\n if (res.sent)\n return\n\n return ret\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e, filter)\n\n if (res.sent)\n return\n res.status(err.status).send(err)\n }\n })\n done()\n })\n }\n\n done()\n\n if (IS_DEV) {\n globalThis.__PS_HMR__?.push(async () => {\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n handleMeta()\n })\n }\n }\n}\n"]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveDep
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-43ZXHSVH.mjs";
|
|
4
4
|
import {
|
|
5
5
|
BadRequestException,
|
|
6
6
|
Context,
|
|
7
7
|
isAopDepInject
|
|
8
|
-
} from "../../chunk-
|
|
8
|
+
} from "../../chunk-ATMZNJSE.mjs";
|
|
9
9
|
import {
|
|
10
10
|
APP_SYMBOL,
|
|
11
11
|
IS_DEV,
|
|
12
12
|
META_SYMBOL,
|
|
13
13
|
MODULE_SYMBOL,
|
|
14
14
|
__name
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-DQUH5BP6.mjs";
|
|
16
16
|
|
|
17
17
|
// src/server/fastify/bind.ts
|
|
18
|
-
function bindApp({ moduleMap, meta }, options = {}) {
|
|
18
|
+
function bindApp(app, { moduleMap, meta }, options = {}) {
|
|
19
19
|
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
20
20
|
route: "/__PHECDA_SERVER__",
|
|
21
21
|
globalGuards: [],
|
|
@@ -23,6 +23,10 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
23
23
|
plugins: [],
|
|
24
24
|
...options
|
|
25
25
|
};
|
|
26
|
+
app.server[APP_SYMBOL] = {
|
|
27
|
+
moduleMap,
|
|
28
|
+
meta
|
|
29
|
+
};
|
|
26
30
|
isAopDepInject(meta, {
|
|
27
31
|
plugins,
|
|
28
32
|
guards: globalGuards,
|
|
@@ -59,7 +63,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
59
63
|
fastify2.post(route, async (req, res) => {
|
|
60
64
|
const { body } = req;
|
|
61
65
|
async function errorHandler(e) {
|
|
62
|
-
const error = await Context.
|
|
66
|
+
const error = await Context.filterRecord.default(e);
|
|
63
67
|
return res.status(error.status).send(error);
|
|
64
68
|
}
|
|
65
69
|
__name(errorHandler, "errorHandler");
|
|
@@ -71,7 +75,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
71
75
|
const { tag } = item;
|
|
72
76
|
const meta2 = metaMap.get(tag);
|
|
73
77
|
if (!meta2)
|
|
74
|
-
return resolve(await Context.
|
|
78
|
+
return resolve(await Context.filterRecord.default(new BadRequestException(`"${tag}" doesn't exist`)));
|
|
75
79
|
const contextData = {
|
|
76
80
|
type: "fastify",
|
|
77
81
|
request: req,
|
|
@@ -82,7 +86,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
82
86
|
};
|
|
83
87
|
const context = new Context(tag, contextData);
|
|
84
88
|
const [name, method] = tag.split("-");
|
|
85
|
-
const { paramsType, handlers, data: { params, guards, interceptors } } = meta2;
|
|
89
|
+
const { paramsType, handlers, data: { params, guards, interceptors, filter } } = meta2;
|
|
86
90
|
const instance = moduleMap.get(name);
|
|
87
91
|
try {
|
|
88
92
|
if (!params)
|
|
@@ -113,7 +117,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
113
117
|
resolve(await context.usePostInterceptor(funcData));
|
|
114
118
|
} catch (e) {
|
|
115
119
|
handlers.forEach((handler) => handler.error?.(e));
|
|
116
|
-
resolve(await context.useFilter(e));
|
|
120
|
+
resolve(await context.useFilter(e, filter));
|
|
117
121
|
}
|
|
118
122
|
});
|
|
119
123
|
})).then((ret) => {
|
|
@@ -130,7 +134,7 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
130
134
|
if (!http?.type)
|
|
131
135
|
continue;
|
|
132
136
|
const methodTag = `${tag}-${method}`;
|
|
133
|
-
const { paramsType, handlers, data: { interceptors, guards, params, plugins: plugins2 } } = metaMap.get(methodTag);
|
|
137
|
+
const { paramsType, handlers, data: { interceptors, guards, params, plugins: plugins2, filter } } = metaMap.get(methodTag);
|
|
134
138
|
fastify.register((fastify2, _opts, done2) => {
|
|
135
139
|
Context.usePlugin(plugins2).forEach((p) => {
|
|
136
140
|
p[Symbol.for("skip-override")] = true;
|
|
@@ -145,7 +149,8 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
145
149
|
request: req,
|
|
146
150
|
meta: i,
|
|
147
151
|
response: res,
|
|
148
|
-
moduleMap
|
|
152
|
+
moduleMap,
|
|
153
|
+
parallel: false
|
|
149
154
|
};
|
|
150
155
|
const context = new Context(methodTag, contextData);
|
|
151
156
|
try {
|
|
@@ -180,7 +185,9 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
180
185
|
return ret;
|
|
181
186
|
} catch (e) {
|
|
182
187
|
handlers.forEach((handler) => handler.error?.(e));
|
|
183
|
-
const err = await context.useFilter(e);
|
|
188
|
+
const err = await context.useFilter(e, filter);
|
|
189
|
+
if (res.sent)
|
|
190
|
+
return;
|
|
184
191
|
res.status(err.status).send(err);
|
|
185
192
|
}
|
|
186
193
|
});
|
|
@@ -190,6 +197,11 @@ function bindApp({ moduleMap, meta }, options = {}) {
|
|
|
190
197
|
done();
|
|
191
198
|
if (IS_DEV) {
|
|
192
199
|
globalThis.__PS_HMR__?.push(async () => {
|
|
200
|
+
isAopDepInject(meta, {
|
|
201
|
+
plugins,
|
|
202
|
+
guards: globalGuards,
|
|
203
|
+
interceptors: globalInterceptors
|
|
204
|
+
});
|
|
193
205
|
handleMeta();
|
|
194
206
|
});
|
|
195
207
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/fastify/bind.ts"],"sourcesContent":["import type { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'\nimport { resolveDep } from '../../helper'\nimport { APP_SYMBOL, IS_DEV, META_SYMBOL, MODULE_SYMBOL } from '../../common'\nimport type { Factory } from '../../core'\nimport { BadRequestException } from '../../exception'\nimport type { Meta } from '../../meta'\nimport { Context, isAopDepInject } from '../../context'\n\nexport interface FastifyCtx {\n type: 'fastify'\n request: FastifyRequest\n response: FastifyReply\n meta: Meta\n moduleMap: Record<string, any>\n [key: string]: any\n}\nexport interface Options {\n\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n\n /**\n * 专用路由的插件(work for merge request),\n */\n plugins?: string[]\n\n}\n\nexport function bindApp({ moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}): FastifyPluginCallback {\n const { globalGuards, globalInterceptors, route, plugins } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], plugins: [], ...options } as Required<Options>\n // (app as any)[APP_SYMBOL] = { moduleMap, meta }\n\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n\n const metaMap = new Map<string, Meta>()\n function handleMeta() {\n metaMap.clear()\n for (const item of meta) {\n const { tag, method, http } = item.data\n if (!http?.type)\n continue\n const methodTag = `${tag}-${method}`\n metaMap.set(methodTag, item)\n }\n }\n\n handleMeta()\n\n return (fastify, _, done) => {\n (fastify as any)[APP_SYMBOL] = {\n moduleMap, meta,\n }\n // fastify.decorateRequest(MODULE_SYMBOL, null)\n // fastify.decorateRequest(META_SYMBOL, null)\n // fastify.decorateRequest(MERGE_SYMBOL, false)\n\n fastify.register((fastify, _opts, done) => {\n plugins.forEach((p) => {\n const plugin = Context.usePlugin([p])[0]\n if (plugin) {\n plugin[Symbol.for('skip-override')] = true\n\n fastify.register(plugin)\n }\n })\n fastify.post(route, async (req, res) => {\n const { body } = req as any\n\n async function errorHandler(e: any) {\n const error = await Context.filter(e)\n return res.status(error.status).send(error)\n }\n\n if (!Array.isArray(body))\n return errorHandler(new BadRequestException('data format should be an array'))\n\n try {\n return Promise.all(body.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const meta = metaMap.get(tag)\n\n if (!meta)\n return resolve(await Context.filter(new BadRequestException(`\"${tag}\" doesn't exist`)))\n\n const contextData = {\n type: 'fastify',\n request: req,\n meta,\n response: res,\n moduleMap,\n parallel: true,\n\n }\n const context = new Context(tag, contextData)\n const [name, method] = tag.split('-')\n const {\n paramsType,\n\n handlers,\n\n data: {\n params,\n guards, interceptors,\n },\n } = meta\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return resolve(cache)\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: item.args[index], type, key, pipe, pipeOpts, index, reflect: paramsType[index] }\n })) as any\n instance.context = contextData\n const funcData = await moduleMap.get(name)[method](...args)\n resolve(await context.usePostInterceptor(funcData))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e))\n }\n })\n })).then((ret) => {\n res.send(ret)\n })\n }\n catch (e) {\n return errorHandler(e)\n }\n })\n\n done()\n })\n\n for (const i of meta) {\n const { method, http, header, tag } = i.data\n\n if (!http?.type)\n continue\n\n const methodTag = `${tag}-${method}`\n\n const {\n paramsType,\n handlers,\n data: {\n interceptors,\n guards,\n params,\n plugins,\n },\n } = metaMap.get(methodTag)!\n\n fastify.register((fastify, _opts, done) => {\n Context.usePlugin(plugins).forEach((p) => {\n p[Symbol.for('skip-override')] = true\n\n fastify.register(p)\n })\n fastify[http.type](http.route, async (req, res) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n const instance = moduleMap.get(tag)!\n const contextData = {\n type: 'fastify',\n request: req,\n meta: i,\n response: res,\n moduleMap,\n }\n const context = new Context(methodTag, contextData)\n\n try {\n for (const name in header)\n res.header(name, header[name])\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return cache\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: resolveDep((req as any)[type], key), pipe, pipeOpts, key, type, index, reflect: paramsType[index] }\n }))\n\n instance.context = contextData\n const funcData = await instance[method](...args)\n const ret = await context.usePostInterceptor(funcData)\n if (res.sent)\n return\n\n return 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).send(err)\n }\n })\n done()\n })\n }\n\n done()\n\n if (IS_DEV) {\n globalThis.__PS_HMR__?.push(async () => {\n handleMeta()\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsCO,SAASA,QAAQ,EAAEC,WAAWC,KAAI,GAAyCC,UAAmB,CAAC,GAA0B;AAC9H,QAAM,EAAEC,cAAcC,oBAAoBC,OAAOC,QAAO,IAAK;IAAED,OAAO;IAAsBF,cAAc,CAAA;IAAIC,oBAAoB,CAAA;IAAIE,SAAS,CAAA;IAAI,GAAGJ;EAAQ;AAG9JK,iBAAeN,MAAM;IACnBK;IACAE,QAAQL;IACRM,cAAcL;EAChB,CAAA;AAEA,QAAMM,UAAU,oBAAIC,IAAAA;AACpB,WAASC,aAAa;AACpB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C,UAAUC,MAAK,MAAO;AACtF,qBAAO;gBAAEC,KAAKY,WAAYlD,IAAYjB,OAAOmD,GAAAA;gBAAMC;gBAAMC;gBAAUF;gBAAKnD;gBAAMsD;gBAAOE,SAASf,WAAWa;cAAO;YAClH,CAAA,CAAA;AAEAV,qBAASN,UAAUJ;AACnB,kBAAMuB,WAAW,MAAMb,SAAS/C,QAAO,GAAIoD,IAAAA;AAC3C,kBAAMa,MAAM,MAAMxB,QAAQoB,mBAAmBD,QAAAA;AAC7C,gBAAIvC,IAAIkD;AACN;AAEF,mBAAON;UACT,SACOzC,GAAP;AACEqB,qBAASjC,QAAQkD,CAAAA,YAAWA,QAAQrC,QAAQD,CAAAA,CAAAA;AAC5C,kBAAMgD,MAAM,MAAM/B,QAAQsB,UAAUvC,CAAAA;AACpCH,gBAAIM,OAAO6C,IAAI7C,MAAM,EAAEC,KAAK4C,GAAAA;UAC9B;QACF,CAAA;AACAhE,QAAAA,MAAAA;MACF,CAAA;IACF;AAEAA,SAAAA;AAEA,QAAIiE,QAAQ;AACVC,iBAAWC,YAAYC,KAAK,YAAY;AACtChF,mBAAAA;MACF,CAAA;IACF;EACF;AACF;AApMgBb;","names":["bindApp","moduleMap","meta","options","globalGuards","globalInterceptors","route","plugins","isAopDepInject","guards","interceptors","metaMap","Map","handleMeta","clear","item","tag","method","http","data","type","methodTag","set","fastify","_","done","APP_SYMBOL","register","_opts","forEach","p","plugin","Context","usePlugin","Symbol","for","post","req","res","body","errorHandler","e","error","filter","status","send","Array","isArray","BadRequestException","Promise","all","map","resolve","get","contextData","request","response","parallel","context","name","split","paramsType","handlers","params","instance","useGuard","cache","useInterceptor","undefined","args","usePipe","key","pipe","pipeOpts","index","arg","reflect","funcData","usePostInterceptor","handler","useFilter","then","ret","i","header","MODULE_SYMBOL","META_SYMBOL","resolveDep","sent","err","IS_DEV","globalThis","__PS_HMR__","push"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/fastify/bind.ts"],"sourcesContent":["import type { FastifyInstance, FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'\nimport { resolveDep } from '../../helper'\nimport { APP_SYMBOL, IS_DEV, META_SYMBOL, MODULE_SYMBOL } from '../../common'\nimport type { Factory } from '../../core'\nimport { BadRequestException } from '../../exception'\nimport type { Meta } from '../../meta'\nimport { Context, isAopDepInject } from '../../context'\n\nexport interface FastifyCtx {\n type: 'fastify'\n request: FastifyRequest\n response: FastifyReply\n meta: Meta\n moduleMap: Record<string, any>\n parallel: boolean\n [key: string]: any\n}\nexport interface Options {\n\n /**\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\n */\n route?: string\n /**\n * 全局守卫\n */\n globalGuards?: string[]\n /**\n * 全局拦截器\n */\n globalInterceptors?: string[]\n\n /**\n * 专用路由的插件(work for merge request),\n */\n plugins?: string[]\n\n}\n\nexport function bindApp(app: FastifyInstance, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options: Options = {}): FastifyPluginCallback {\n const { globalGuards, globalInterceptors, route, plugins } = { route: '/__PHECDA_SERVER__', globalGuards: [], globalInterceptors: [], plugins: [], ...options } as Required<Options>\n (app as any).server[APP_SYMBOL] = { moduleMap, meta }\n\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n\n const metaMap = new Map<string, Meta>()\n function handleMeta() {\n metaMap.clear()\n for (const item of meta) {\n const { tag, method, http } = item.data\n if (!http?.type)\n continue\n const methodTag = `${tag}-${method}`\n metaMap.set(methodTag, item)\n }\n }\n\n handleMeta()\n\n return (fastify, _, done) => {\n (fastify as any)[APP_SYMBOL] = {\n moduleMap, meta,\n }\n // fastify.decorateRequest(MODULE_SYMBOL, null)\n // fastify.decorateRequest(META_SYMBOL, null)\n // fastify.decorateRequest(MERGE_SYMBOL, false)\n\n fastify.register((fastify, _opts, done) => {\n plugins.forEach((p) => {\n const plugin = Context.usePlugin([p])[0]\n if (plugin) {\n plugin[Symbol.for('skip-override')] = true\n\n fastify.register(plugin)\n }\n })\n fastify.post(route, async (req, res) => {\n const { body } = req as any\n\n async function errorHandler(e: any) {\n const error = await Context.filterRecord.default(e)\n return res.status(error.status).send(error)\n }\n\n if (!Array.isArray(body))\n return errorHandler(new BadRequestException('data format should be an array'))\n\n try {\n return Promise.all(body.map((item: any) => {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n const { tag } = item\n const meta = metaMap.get(tag)\n\n if (!meta)\n return resolve(await Context.filterRecord.default(new BadRequestException(`\"${tag}\" doesn't exist`)))\n\n const contextData = {\n type: 'fastify' as const,\n request: req,\n meta,\n response: res,\n moduleMap,\n parallel: true,\n\n }\n const context = new Context<FastifyCtx>(tag, contextData)\n const [name, method] = tag.split('-')\n const {\n paramsType,\n\n handlers,\n\n data: {\n params,\n guards,\n interceptors,\n filter,\n },\n } = meta\n\n const instance = moduleMap.get(name)\n\n try {\n if (!params)\n throw new BadRequestException(`\"${tag}\" doesn't exist`)\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return resolve(cache)\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: item.args[index], type, key, pipe, pipeOpts, index, reflect: paramsType[index] }\n })) as any\n instance.context = contextData\n const funcData = await moduleMap.get(name)[method](...args)\n resolve(await context.usePostInterceptor(funcData))\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n resolve(await context.useFilter(e, filter))\n }\n })\n })).then((ret) => {\n res.send(ret)\n })\n }\n catch (e) {\n return errorHandler(e)\n }\n })\n\n done()\n })\n\n for (const i of meta) {\n const { method, http, header, tag } = i.data\n\n if (!http?.type)\n continue\n\n const methodTag = `${tag}-${method}`\n\n const {\n paramsType,\n handlers,\n data: {\n interceptors,\n guards,\n params,\n plugins,\n filter,\n },\n } = metaMap.get(methodTag)!\n\n fastify.register((fastify, _opts, done) => {\n Context.usePlugin(plugins).forEach((p) => {\n p[Symbol.for('skip-override')] = true\n\n fastify.register(p)\n })\n fastify[http.type](http.route, async (req, res) => {\n (req as any)[MODULE_SYMBOL] = moduleMap;\n (req as any)[META_SYMBOL] = meta\n const instance = moduleMap.get(tag)!\n const contextData = {\n type: 'fastify' as const,\n request: req,\n meta: i,\n response: res,\n moduleMap,\n parallel: false,\n }\n const context = new Context<FastifyCtx>(methodTag, contextData)\n\n try {\n for (const name in header)\n res.header(name, header[name])\n await context.useGuard([...globalGuards, ...guards])\n const cache = await context.useInterceptor([...globalInterceptors, ...interceptors])\n if (cache !== undefined)\n\n return cache\n\n const args = await context.usePipe(params.map(({ type, key, pipe, pipeOpts, index }) => {\n return { arg: resolveDep((req as any)[type], key), pipe, pipeOpts, key, type, index, reflect: paramsType[index] }\n }))\n\n instance.context = contextData\n const funcData = await instance[method](...args)\n const ret = await context.usePostInterceptor(funcData)\n if (res.sent)\n return\n\n return ret\n }\n catch (e: any) {\n handlers.forEach(handler => handler.error?.(e))\n const err = await context.useFilter(e, filter)\n\n if (res.sent)\n return\n res.status(err.status).send(err)\n }\n })\n done()\n })\n }\n\n done()\n\n if (IS_DEV) {\n globalThis.__PS_HMR__?.push(async () => {\n isAopDepInject(meta, {\n plugins,\n guards: globalGuards,\n interceptors: globalInterceptors,\n })\n handleMeta()\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCO,SAASA,QAAQC,KAAsB,EAAEC,WAAWC,KAAI,GAAyCC,UAAmB,CAAC,GAA0B;AACpJ,QAAM,EAAEC,cAAcC,oBAAoBC,OAAOC,QAAO,IAAK;IAAED,OAAO;IAAsBF,cAAc,CAAA;IAAIC,oBAAoB,CAAA;IAAIE,SAAS,CAAA;IAAI,GAAGJ;EAAQ;AAC7JH,MAAYQ,OAAOC,cAAc;IAAER;IAAWC;EAAK;AAEpDQ,iBAAeR,MAAM;IACnBK;IACAI,QAAQP;IACRQ,cAAcP;EAChB,CAAA;AAEA,QAAMQ,UAAU,oBAAIC,I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AET,kBAAMG,OAAO,MAAMZ,QAAQa,QAAQR,OAAOZ,IAAI,CAAC,EAAE/B,MAAMoD,KAAKC,MAAMC,UAAUC,MAAK,MAAO;AACtF,qBAAO;gBAAEC,KAAKY,WAAYpD,IAAYhB,OAAOoD,GAAAA;gBAAMC;gBAAMC;gBAAUF;gBAAKpD;gBAAMuD;gBAAOE,SAAShB,WAAWc;cAAO;YAClH,CAAA,CAAA;AAEAV,qBAASP,UAAUJ;AACnB,kBAAMwB,WAAW,MAAMb,SAAShD,QAAO,GAAIqD,IAAAA;AAC3C,kBAAMa,MAAM,MAAMzB,QAAQqB,mBAAmBD,QAAAA;AAC7C,gBAAIzC,IAAIoD;AACN;AAEF,mBAAON;UACT,SACO3C,GAAP;AACEsB,qBAASlC,QAAQoD,CAAAA,YAAWA,QAAQvC,QAAQD,CAAAA,CAAAA;AAC5C,kBAAMkD,MAAM,MAAMhC,QAAQuB,UAAUzC,GAAGwB,MAAAA;AAEvC,gBAAI3B,IAAIoD;AACN;AACFpD,gBAAIO,OAAO8C,IAAI9C,MAAM,EAAEC,KAAK6C,GAAAA;UAC9B;QACF,CAAA;AACAjE,QAAAA,MAAAA;MACF,CAAA;IACF;AAEAA,SAAAA;AAEA,QAAIkE,QAAQ;AACVC,iBAAWC,YAAYC,KAAK,YAAY;AACtCtF,uBAAeR,MAAM;UACnBK;UACAI,QAAQP;UACRQ,cAAcP;QAChB,CAAA;AACAU,mBAAAA;MACF,CAAA;IACF;EACF;AACF;AAhNgBhB;","names":["bindApp","app","moduleMap","meta","options","globalGuards","globalInterceptors","route","plugins","server","APP_SYMBOL","isAopDepInject","guards","interceptors","metaMap","Map","handleMeta","clear","item","tag","method","http","data","type","methodTag","set","fastify","_","done","register","_opts","forEach","p","plugin","Context","usePlugin","Symbol","for","post","req","res","body","errorHandler","e","error","filterRecord","default","status","send","Array","isArray","BadRequestException","Promise","all","map","resolve","get","contextData","request","response","parallel","context","name","split","paramsType","handlers","params","filter","instance","useGuard","cache","useInterceptor","undefined","args","usePipe","key","pipe","pipeOpts","index","arg","reflect","funcData","usePostInterceptor","handler","useFilter","then","ret","i","header","MODULE_SYMBOL","META_SYMBOL","resolveDep","sent","err","IS_DEV","globalThis","__PS_HMR__","push"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Router } from 'h3';
|
|
2
|
-
import { M as Meta, F as Factory } from '../../core-
|
|
3
|
-
import '../../types-ead02c5d.js';
|
|
1
|
+
import { H3Event, Router } from 'h3';
|
|
2
|
+
import { M as Meta, F as Factory } from '../../core-72951cf9.js';
|
|
4
3
|
import 'phecda-core';
|
|
5
4
|
|
|
6
5
|
interface H3Ctx {
|
|
7
6
|
type: 'h3';
|
|
8
|
-
|
|
9
|
-
response: Response;
|
|
7
|
+
event: H3Event;
|
|
10
8
|
meta: Meta;
|
|
11
9
|
moduleMap: Record<string, any>;
|
|
10
|
+
parallel: boolean;
|
|
11
|
+
[key: string]: any;
|
|
12
12
|
}
|
|
13
13
|
interface Options {
|
|
14
14
|
route?: string;
|