phecda-server 4.0.5 → 4.0.6
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-YU7ROHTO.js → chunk-7OB6K45T.js} +78 -66
- package/dist/chunk-7OB6K45T.js.map +1 -0
- package/dist/{chunk-LZAU5FUS.js → chunk-AAF47ZC6.js} +9 -3
- package/dist/chunk-AAF47ZC6.js.map +1 -0
- package/dist/{chunk-AJ2HYENF.mjs → chunk-AYJWOIAW.mjs} +10 -4
- package/dist/chunk-AYJWOIAW.mjs.map +1 -0
- package/dist/{chunk-Q6T7HNEO.mjs → chunk-GSJ5A2MA.mjs} +43 -31
- package/dist/chunk-GSJ5A2MA.mjs.map +1 -0
- package/dist/{chunk-NFAA3WFR.mjs → chunk-K32VRTXB.mjs} +18 -11
- package/dist/chunk-K32VRTXB.mjs.map +1 -0
- package/dist/{chunk-R3N4HR7U.js → chunk-TZ27DHWL.js} +39 -32
- package/dist/chunk-TZ27DHWL.js.map +1 -0
- package/dist/{chunk-JQPX546Z.mjs → chunk-V7SC5EVJ.mjs} +2 -2
- package/dist/{chunk-FAHHXHL5.js → chunk-ZPMAM4LQ.js} +3 -3
- package/dist/{core-ba036c2b.d.ts → core-c27b4cf4.d.ts} +1 -1
- package/dist/index.d.ts +45 -26
- package/dist/index.js +119 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -33
- package/dist/index.mjs.map +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +2 -2
- 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 -2
- 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 +4 -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 +3 -2
- package/dist/server/fastify/index.js +33 -25
- package/dist/server/fastify/index.js.map +1 -1
- package/dist/server/fastify/index.mjs +18 -10
- package/dist/server/fastify/index.mjs.map +1 -1
- package/dist/server/h3/index.d.ts +6 -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 +3 -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 +1 -1
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-ead02c5d.d.ts → types-8415bd5d.d.ts} +16 -17
- package/package.json +1 -1
- 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/{chunk-JQPX546Z.mjs.map → chunk-V7SC5EVJ.mjs.map} +0 -0
- /package/dist/{chunk-FAHHXHL5.js.map → chunk-ZPMAM4LQ.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/exception/base.ts","../src/exception/validate.ts","../src/pipe.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/context.ts","../src/filter.ts","../src/history.ts"],"sourcesContent":["import { ERROR_SYMBOL } from '../common'\n\nexport class Exception extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, [ERROR_SYMBOL]: true }\n }\n}\n","import { Exception } from './base'\n\nexport class ValidateException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { isPhecda, plainToClass, transformClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe: P.Pipe = async ({ arg, reflect, index }: any) => {\n if (isPhecda(reflect)) {\n const instance = plainToClass(reflect, arg)\n const err = await transformClass(instance)\n if (err.length > 0)\n throw new ValidateException(err[0])\n\n arg = instance\n }\n else {\n if ([Number, Boolean].includes(reflect)) {\n arg = reflect(arg)\n\n if (reflect === Number && Object.is(arg, NaN))\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\n }\n }\n return arg\n}\n","import { Exception } from './base'\n\nexport class UndefinedException extends Exception {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { Exception } from './base'\n\nexport class ForbiddenException extends Exception {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { Exception } from './base'\n\nexport class BadRequestException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { Exception } from './base'\n\nexport class NotFoundException extends Exception {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { Exception } from './base'\n\nexport class ConflictException extends Exception {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { Exception } from './base'\n\nexport class BadGatewayException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { Exception } from './base'\n\nexport class InvalidInputException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { Exception } from './base'\n\nexport class UnsupportedMediaTypeException extends Exception {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { Exception } from './base'\n\nexport class PayloadLargeException extends Exception {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { Exception } from './base'\n\nexport class TimeoutException extends Exception {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { Exception } from './base'\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { Exception } from './base'\n\nexport class ServiceUnavailableException extends Exception {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { Exception } from './base'\n\nexport class FrameworkException extends Exception {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import pc from 'picocolors'\nimport { defaultPipe } from './pipe'\nimport { ForbiddenException, FrameworkException } from './exception'\nimport { defaultFilter } from './filter'\nimport { Histroy } from './history'\nimport type { P } from './types'\nimport { IS_DEV, IS_STRICT } from './common'\nimport type { Meta } from './meta'\nimport { log } from './utils'\nexport const guardRecord = {} as Record<string, P.Guard>\n\nexport class Context<Data = any> {\n method: string\n params: string[]\n history = new Histroy()\n\n static filterRecord: Record<string, P.Filter> = {\n default: defaultFilter,\n }\n\n static pipeRecord: Record<string, P.Pipe> = {\n default: defaultPipe,\n }\n\n static guardRecord: Record<string, P.Guard> = {}\n static interceptorRecord: Record<string, P.Interceptor> = {}\n\n static pluginRecord: Record<string, any> = {}\n postInterceptors: Function[]\n\n constructor(public tag: string, public data: Data) {\n if (IS_DEV)\n // @ts-expect-error work for debug\n data._context = this\n }\n\n usePipe(args: { arg: any; pipe?: string; pipeOpts?: any; type: string; key: string; index: number; reflect: any }[]) {\n return Promise.all(args.map((item) => {\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\n\n else\n return Context.pipeRecord.default(item, this.tag, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.tag, this.data)\n }))\n }\n\n useFilter(arg: any, filter = 'default') {\n if (!Context.filterRecord[filter]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find filter named '${filter}'`)\n else\n return Context.filterRecord.default(arg, this.tag, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.tag, this.data)\n }\n\n async useGuard(guards: string[]) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\n if (!await Context.guardRecord[guard](this.tag, this.data))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async usePostInterceptor(ret: any) {\n for (const cb of this.postInterceptors)\n ret = await cb(ret) || ret\n\n return ret\n }\n\n async useInterceptor(interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\n const postInterceptor = await Context.interceptorRecord[interceptor](this.tag, this.data)\n if (postInterceptor !== undefined) {\n if (typeof postInterceptor === 'function')\n ret.push(postInterceptor)\n\n else\n return postInterceptor\n }\n }\n }\n this.postInterceptors = ret\n }\n\n static usePlugin(plugins: string[]) {\n const ret = []\n for (const m of plugins) {\n if (!(m in Context.pluginRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(Context.pluginRecord[m])\n }\n return ret as any[]\n }\n}\nexport function addPlugin<C>(key: string, handler: C) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe(key: string, pipe: P.Pipe) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter(key: string, handler: P.Filter) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.interceptorRecord[key] = handler\n}\n\n// detect whether plugin/filter/pipe/guard/intercept is injected\nexport function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }: {\n guards?: string[]\n interceptors?: string[]\n plugins?: string[]\n} = {}) {\n const pluginSet = new Set<string>(plugins)\n\n const guardSet = new Set<string>(guards)\n const interceptorSet = new Set<string>(interceptors)\n const pipeSet = new Set<string>()\n\n const filterSet = new Set<string>()\n meta.forEach(({ data }) => {\n if (data.filter)\n filterSet.add(data.filter)\n\n data.interceptors.forEach(i => interceptorSet.add(i))\n data.guards.forEach(i => guardSet.add(i))\n data.plugins.forEach(i => pluginSet.add(i))\n data.params.forEach((i) => {\n if (i.pipe)\n pipeSet.add(i.pipe)\n })\n })\n\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\n\n if (missPlugins.length)\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\n if (missGuards.length)\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missInterceptors.length)\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missPipes.length)\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missFilters.length)\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\n}\n","import { Exception, UndefinedException } from './exception'\nimport type { P } from './types'\nimport { log } from './utils'\n\nexport const defaultFilter: P.Filter = (e) => {\n if (!(e instanceof Exception)) {\n log(e.message, 'error')\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n log(`[${e.constructor.name}] ${e.message}`, 'error')\n console.error(e.stack)\n }\n\n return e.data\n}\n","export class Histroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n"],"mappings":";;;;;;;;;;AAEO,IAAMA,YAAN,cAAwBC,MAAAA;EACVC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQ,CAACI,eAAe;IAAK;EAC3G;AACF;AARaP;;;ACAN,IAAMQ,oBAAN,cAAgCC,UAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;ACFb,SAASI,UAAUC,cAAcC,sBAAsB;AAKhD,IAAMC,cAAsB,8BAAO,EAAEC,KAAKC,SAASC,MAAK,MAAY;AACzE,MAAIC,SAASF,OAAAA,GAAU;AACrB,UAAMG,WAAWC,aAAaJ,SAASD,GAAAA;AACvC,UAAMM,MAAM,MAAMC,eAAeH,QAAAA;AACjC,QAAIE,IAAIE,SAAS;AACf,YAAM,IAAIC,kBAAkBH,IAAI,EAAE;AAEpCN,UAAMI;EACR,OACK;AACH,QAAI;MAACM;MAAQC;MAASC,SAASX,OAAAA,GAAU;AACvCD,YAAMC,QAAQD,GAAAA;AAEd,UAAIC,YAAYS,UAAUG,OAAOC,GAAGd,KAAKe,GAAAA;AACvC,cAAM,IAAIN,kBAAkB,aAAaC,OAAOR,KAAAA,IAAS,sBAAsB;IACnF;EACF;AACA,SAAOF;AACT,GAlBmC;;;ACH5B,IAAMgB,qBAAN,cAAiCC,UAAAA;EACt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AA;AAExE,MAAIP,iBAAiBG;AACnBC,QAAI,GAAGC,GAAGI,KAAK,gBAAgBT,iBAAiBO,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEjF,MAAIN,UAAUE;AACZC,QAAI,GAAGC,GAAGK,KAAK,SAAST,UAAUM,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEnE,MAAIL,YAAYC;AACdC,QAAI,GAAGC,GAAGM,IAAI,WAAWT,YAAYK,KAAK,GAAA,IAAO,mBAAmB,MAAA;AACxE;AA5CgBpB;","names":["Exception","Error","message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","Exception","constructor","message","isPhecda","plainToClass","transformClass","defaultPipe","arg","reflect","index","isPhecda","instance","plainToClass","err","transformClass","length","ValidateException","Number","Boolean","includes","Object","is","NaN","UndefinedException","Exception","constructor","message","ForbiddenException","Exception","constructor","message","BadRequestException","Exception","constructor","message","NotFoundException","Exception","constructor","message","ConflictException","Exception","constructor","message","BadGatewayException","Exception","constructor","message","InvalidInputException","Exception","constructor","message","UnsupportedMediaTypeException","Exception","constructor","message","PayloadLargeException","Exception","constructor","message","TimeoutException","Exception","constructor","message","UnauthorizedException","Exception","constructor","message","ServiceUnavailableException","Exception","constructor","message","FrameworkException","Exception","constructor","message","pc","defaultFilter","e","Exception","log","message","console","error","stack","UndefinedException","constructor","name","data","Histroy","guard","interceptor","record","name","type","includes","push","guardRecord","Context","tag","data","method","params","history","postInterceptors","constructor","Histroy","IS_DEV","_context","usePipe","args","Promise","all","map","item","pipe","pipeRecord","IS_STRICT","FrameworkException","default","useFilter","arg","filter","filterRecord","useGuard","guards","guard","record","ForbiddenException","usePostInterceptor","ret","cb","useInterceptor","interceptors","interceptor","interceptorRecord","postInterceptor","undefined","push","usePlugin","plugins","m","pluginRecord","defaultFilter","defaultPipe","addPlugin","key","handler","addPipe","addFilter","addGuard","addInterceptor","isAopDepInject","meta","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","forEach","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","length","log","pc","white","join","magenta","cyan","blue","red"]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
UNMOUNT_SYMBOL,
|
|
4
4
|
__name,
|
|
5
5
|
log
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AYJWOIAW.mjs";
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -105,7 +105,6 @@ import fs from "fs";
|
|
|
105
105
|
import EventEmitter from "node:events";
|
|
106
106
|
import { Empty, getExposeKey, getHandler, getState, injectProperty, isPhecda, registerAsync } from "phecda-core";
|
|
107
107
|
import Debug from "debug";
|
|
108
|
-
import pc from "picocolors";
|
|
109
108
|
function Injectable() {
|
|
110
109
|
return (target) => Empty(target);
|
|
111
110
|
}
|
|
@@ -135,12 +134,12 @@ async function Factory(Modules, opts = {}) {
|
|
|
135
134
|
if (!moduleMap.has(tag))
|
|
136
135
|
return;
|
|
137
136
|
const instance = moduleMap.get(tag);
|
|
137
|
+
debug(`unmount module "${tag}"`);
|
|
138
138
|
if (instance?.[UNMOUNT_SYMBOL]) {
|
|
139
139
|
for (const cb of instance[UNMOUNT_SYMBOL])
|
|
140
140
|
await cb();
|
|
141
141
|
}
|
|
142
142
|
debug(`del module "${tag}"`);
|
|
143
|
-
log(`Module ${pc.yellow(`[${tag}]`)} unmount`);
|
|
144
143
|
moduleMap.delete(tag);
|
|
145
144
|
constructorMap.delete(tag);
|
|
146
145
|
for (let i = meta.length - 1; i >= 0; i--) {
|
|
@@ -154,8 +153,8 @@ async function Factory(Modules, opts = {}) {
|
|
|
154
153
|
const tag = Module.prototype?.__TAG__ || Module.name;
|
|
155
154
|
const oldInstance = await del(tag);
|
|
156
155
|
const { instance: newModule } = await buildNestModule(Module);
|
|
157
|
-
debug(`add module "${tag}"`);
|
|
158
156
|
if (oldInstance && moduleGraph.has(tag)) {
|
|
157
|
+
debug(`replace module "${tag}"`);
|
|
159
158
|
[
|
|
160
159
|
...moduleGraph.get(tag)
|
|
161
160
|
].forEach((tag2) => {
|
|
@@ -166,7 +165,6 @@ async function Factory(Modules, opts = {}) {
|
|
|
166
165
|
}
|
|
167
166
|
});
|
|
168
167
|
}
|
|
169
|
-
moduleMap.set(tag, newModule);
|
|
170
168
|
}
|
|
171
169
|
__name(add, "add");
|
|
172
170
|
async function buildNestModule(Module) {
|
|
@@ -196,14 +194,17 @@ async function Factory(Modules, opts = {}) {
|
|
|
196
194
|
moduleGraph.set(subTag, /* @__PURE__ */ new Set());
|
|
197
195
|
moduleGraph.get(subTag).add(tag);
|
|
198
196
|
}
|
|
197
|
+
debug(`instantiate module "${tag}"`);
|
|
199
198
|
instance = new Module(...paramtypesInstances);
|
|
200
199
|
} else {
|
|
200
|
+
debug(`instantiate module "${tag}"`);
|
|
201
201
|
instance = new Module();
|
|
202
202
|
}
|
|
203
203
|
meta.push(...getMetaFromInstance(instance, tag, Module.name));
|
|
204
|
+
debug(`init module "${tag}"`);
|
|
204
205
|
await registerAsync(instance);
|
|
206
|
+
debug(`add module "${tag}"`);
|
|
205
207
|
moduleMap.set(tag, instance);
|
|
206
|
-
log(`Module ${pc.yellow(`[${tag}]`)} mount"`);
|
|
207
208
|
constructorMap.set(tag, Module);
|
|
208
209
|
return {
|
|
209
210
|
instance,
|
|
@@ -214,9 +215,14 @@ async function Factory(Modules, opts = {}) {
|
|
|
214
215
|
for (const Module of Modules)
|
|
215
216
|
await buildNestModule(Module);
|
|
216
217
|
function writeCode() {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
if (http) {
|
|
219
|
+
debug(`write http code to ${http}`);
|
|
220
|
+
fs.promises.writeFile(http, generateHTTPCode(meta.map((item) => item.data)));
|
|
221
|
+
}
|
|
222
|
+
if (rpc) {
|
|
223
|
+
debug(`write rpc code to ${rpc}`);
|
|
224
|
+
fs.promises.writeFile(rpc, generateRPCCode(meta.map((item) => item.data)));
|
|
225
|
+
}
|
|
220
226
|
}
|
|
221
227
|
__name(writeCode, "writeCode");
|
|
222
228
|
writeCode();
|
|
@@ -224,8 +230,8 @@ async function Factory(Modules, opts = {}) {
|
|
|
224
230
|
if (!globalThis.__PS_HMR__)
|
|
225
231
|
globalThis.__PS_HMR__ = [];
|
|
226
232
|
globalThis.__PS_HMR__?.push(async (files) => {
|
|
233
|
+
debug("reload files ");
|
|
227
234
|
for (const file of files) {
|
|
228
|
-
debug(`reload file ${file}`);
|
|
229
235
|
const module = await import(file);
|
|
230
236
|
for (const i in module) {
|
|
231
237
|
if (isPhecda(module[i]))
|
|
@@ -276,6 +282,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
276
282
|
break;
|
|
277
283
|
}
|
|
278
284
|
meta.params = params;
|
|
285
|
+
meta.filter = state.filter || baseState.filter;
|
|
279
286
|
meta.define = {
|
|
280
287
|
...baseState.define,
|
|
281
288
|
...state.define
|
|
@@ -332,4 +339,4 @@ export {
|
|
|
332
339
|
emitter,
|
|
333
340
|
Factory
|
|
334
341
|
};
|
|
335
|
-
//# sourceMappingURL=chunk-
|
|
342
|
+
//# sourceMappingURL=chunk-K32VRTXB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/meta.ts","../src/compiler/rpc.ts","../src/compiler/http.ts","../src/core.ts"],"sourcesContent":["import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public paramsType: any[]) {\n\n }\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n rpc, name, method, tag,\n } = args\n if (!rpc || !rpc.type)\n return\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(){\n return {tag:'${tag}-${method}',isEvent:${!!rpc.isEvent},rpc:[${rpc.type.reduce((p, c) => {\n return `${p}\"${c}\",`\n }, '')}]}\n\n }\n `\n }\n}\n\nexport function generateRPCCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n // createRequest() {\n // let content = 'import {useC} from \\'phecda-server\\'\\n'\n // for (const name in this.classMap)\n // content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n // return content\n // }\n\n addMethod(args: P.Meta) {\n const {\n http, name, method, params, tag,\n } = args\n if (!http)\n return\n const url = http.route.replace(/\\/\\:([^\\/]*)/g, (_, js) => `/{{${js}}}`)\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(...args){\nconst ret={tag:\"${tag}-${method}\",body:{},headers:{},query:{},params:{},method:\"${http.type}\",url:\"${url}\",args}\n\n${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ''}=args[${i}]\\n${c.type === 'params' ? `ret.url=ret.url.replace('{{${c.key}}}',args[${i}])` : ''}\\n`, '')}\nreturn ret\n }\n `\n }\n}\n\nexport function generateHTTPCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { Empty, getExposeKey, getHandler, getState, injectProperty, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { log } from './utils'\nimport { IS_DEV, UNMOUNT_SYMBOL } from './common'\nimport { generateHTTPCode, generateRPCCode } from './compiler'\nexport function Injectable() {\n return (target: any) => Empty(target)\n}\nconst debug = Debug('phecda-server')\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[], opts: {\n\n // HTTP generate code path\n http?: string\n // rpc generate code path\n rpc?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n\n // only work for warn\n const constructorSet = new WeakSet()\n const moduleGraph = new Map<string, Set<string>>()\n const { http, rpc } = opts\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n // work for hmr\n if (!instance[UNMOUNT_SYMBOL])\n instance[UNMOUNT_SYMBOL] = []\n\n instance[UNMOUNT_SYMBOL].push(() => {\n (emitter as any).off(eventName, fn)\n })\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n // only remove module in moduleMap(won't remove indiect module)\n async function del(tag: string) {\n if (!moduleMap.has(tag))\n return\n\n const instance = moduleMap.get(tag)\n\n debug(`unmount module \"${tag}\"`)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n\n debug(`del module \"${tag}\"`)\n\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n return instance\n }\n\n async function add(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n const oldInstance = await del(tag)\n\n const { instance: newModule } = await buildNestModule(Module)\n\n if (oldInstance && moduleGraph.has(tag)) {\n debug(`replace module \"${tag}\"`);\n\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === oldInstance)\n module[key] = newModule\n }\n })\n }\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamTypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {\n constructorSet.add(Module)// a module will only warn once\n log(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`, 'warn')\n }\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n\n debug(`init module \"${tag}\"`)\n\n await registerAsync(instance)\n\n debug(`add module \"${tag}\"`)\n\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeCode() {\n if (http) {\n debug(`write http code to ${http}`)\n fs.promises.writeFile(http, generateHTTPCode(meta.map(item => item.data)))\n }\n if (rpc) {\n debug(`write rpc code to ${rpc}`)\n\n fs.promises.writeFile(rpc, generateRPCCode(meta.map(item => item.data)))\n }\n }\n\n writeCode()\n if (IS_DEV) {\n if (!globalThis.__PS_HMR__)\n globalThis.__PS_HMR__ = []\n\n globalThis.__PS_HMR__?.push(async (files: string[]) => {\n debug('reload files ')\n\n for (const file of files) {\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await add(module[i])\n }\n }\n writeCode()\n })\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n add,\n del,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.http) {\n meta.http = {\n route: (baseState.http?.route || '') + (state.http.route),\n type: state.http.type,\n }\n }\n if (baseState.rpc)\n meta.rpc = baseState.rpc\n if (state.rpc) {\n meta.rpc = {\n ...meta.rpc,\n ...state.rpc,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n\n meta.params = params\n meta.filter = state.filter || baseState.filter\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.plugins = [...new Set([...baseState.plugins, ...state.plugins])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamTypes(instance, i as string) || [])\n })\n}\n\nfunction getParamTypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.plugins)\n state.plugins = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n"],"mappings":";;;;;;;;AAEO,IAAMA,OAAN,MAAMA;EACQC;EAAqBC;EAA8BC;EAAtEC,YAAmBH,MAAqBC,UAA8BC,YAAmB;gBAAtEF;oBAAqBC;sBAA8BC;EAEtE;AACF;AA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;EAChH,CAAA;AACF;AA5CSwB;AA8CT,SAAST,cAAcV,QAAarB,KAAuB;AACzD,SAAO4E,QAAQC,YAAY,qBAAqBxD,QAAQrB,GAAAA;AAC1D;AAFS+B;AAIT,SAAS8B,UAAUC,OAAY;AAC7B,MAAI,CAACA,MAAMO;AACTP,UAAMO,SAAS,CAAC;AAClB,MAAI,CAACP,MAAMQ;AACTR,UAAMQ,SAAS,CAAC;AAClB,MAAI,CAACR,MAAMS;AACTT,UAAMS,UAAU,CAAA;AAClB,MAAI,CAACT,MAAMU;AACTV,UAAMU,SAAS,CAAA;AACjB,MAAI,CAACV,MAAMW;AACTX,UAAMW,eAAe,CAAA;AACzB;AAXSZ;","names":["Meta","data","handlers","paramsType","constructor","Compiler","classMap","constructor","getContent","content","name","Object","values","reduce","p","c","addMethod","args","rpc","method","tag","type","isEvent","generateRPCCode","meta","compiler","i","Compiler","classMap","constructor","getContent","content","name","Object","values","reduce","p","c","addMethod","args","http","method","params","tag","url","route","replace","_","js","type","i","key","generateHTTPCode","meta","compiler","fs","EventEmitter","Empty","getExposeKey","getHandler","getState","injectProperty","isPhecda","registerAsync","Debug","Injectable","target","Empty","debug","Debug","emitter","EventEmitter","Factory","Modules","opts","moduleMap","Map","meta","constructorMap","constructorSet","WeakSet","moduleGraph","http","rpc","injectProperty","eventName","instance","key","options","fn","bind","v","UNMOUNT_SYMBOL","push","off","once","on","del","tag","has","get","cb","delete","i","length","data","splice","add","Module","prototype","__TAG__","name","oldInstance","newModule","buildNestModule","forEach","module","paramtypes","getParamTypes","Error","log","set","undefined","paramtypesInstances","sub","subTag","Set","getMetaFromInstance","registerAsync","writeCode","fs","promises","writeFile","generateHTTPCode","map","item","generateRPCCode","IS_DEV","globalThis","__PS_HMR__","files","file","isPhecda","vars","getExposeKey","filter","baseState","getState","initState","state","route","type","method","params","unshift","index","define","header","plugins","guards","interceptors","Meta","getHandler","Reflect","getMetadata"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkAAF47ZC6js = require('./chunk-AAF47ZC6.js');
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -16,10 +16,10 @@ var Meta = class {
|
|
|
16
16
|
this.paramsType = paramsType;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
_chunkAAF47ZC6js.__name.call(void 0, Meta, "Meta");
|
|
20
20
|
|
|
21
21
|
// src/compiler/rpc.ts
|
|
22
|
-
var Compiler = /* @__PURE__ */
|
|
22
|
+
var Compiler = /* @__PURE__ */ _chunkAAF47ZC6js.__name.call(void 0, (_class =class Compiler2 {
|
|
23
23
|
__init() {this.classMap = {}}
|
|
24
24
|
constructor() {;_class.prototype.__init.call(this);
|
|
25
25
|
}
|
|
@@ -55,10 +55,10 @@ function generateRPCCode(meta) {
|
|
|
55
55
|
compiler.addMethod(i);
|
|
56
56
|
return compiler.getContent();
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
_chunkAAF47ZC6js.__name.call(void 0, generateRPCCode, "generateRPCCode");
|
|
59
59
|
|
|
60
60
|
// src/compiler/http.ts
|
|
61
|
-
var Compiler3 = /* @__PURE__ */
|
|
61
|
+
var Compiler3 = /* @__PURE__ */ _chunkAAF47ZC6js.__name.call(void 0, (_class2 =class Compiler4 {
|
|
62
62
|
__init2() {this.classMap = {}}
|
|
63
63
|
constructor() {;_class2.prototype.__init2.call(this);
|
|
64
64
|
}
|
|
@@ -97,7 +97,7 @@ function generateHTTPCode(meta) {
|
|
|
97
97
|
compiler.addMethod(i);
|
|
98
98
|
return compiler.getContent();
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
_chunkAAF47ZC6js.__name.call(void 0, generateHTTPCode, "generateHTTPCode");
|
|
101
101
|
|
|
102
102
|
// src/core.ts
|
|
103
103
|
require('reflect-metadata');
|
|
@@ -105,11 +105,10 @@ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
|
105
105
|
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
106
106
|
var _phecdacore = require('phecda-core');
|
|
107
107
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
108
|
-
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
109
108
|
function Injectable() {
|
|
110
109
|
return (target) => _phecdacore.Empty.call(void 0, target);
|
|
111
110
|
}
|
|
112
|
-
|
|
111
|
+
_chunkAAF47ZC6js.__name.call(void 0, Injectable, "Injectable");
|
|
113
112
|
var debug = _debug2.default.call(void 0, "phecda-server");
|
|
114
113
|
var emitter = new (0, _events2.default)();
|
|
115
114
|
async function Factory(Modules, opts = {}) {
|
|
@@ -121,9 +120,9 @@ async function Factory(Modules, opts = {}) {
|
|
|
121
120
|
const { http, rpc } = opts;
|
|
122
121
|
_phecdacore.injectProperty.call(void 0, "watcher", ({ eventName, instance, key, options }) => {
|
|
123
122
|
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
124
|
-
if (!instance[
|
|
125
|
-
instance[
|
|
126
|
-
instance[
|
|
123
|
+
if (!instance[_chunkAAF47ZC6js.UNMOUNT_SYMBOL])
|
|
124
|
+
instance[_chunkAAF47ZC6js.UNMOUNT_SYMBOL] = [];
|
|
125
|
+
instance[_chunkAAF47ZC6js.UNMOUNT_SYMBOL].push(() => {
|
|
127
126
|
emitter.off(eventName, fn);
|
|
128
127
|
});
|
|
129
128
|
if (_optionalChain([options, 'optionalAccess', _2 => _2.once]))
|
|
@@ -135,12 +134,12 @@ async function Factory(Modules, opts = {}) {
|
|
|
135
134
|
if (!moduleMap.has(tag))
|
|
136
135
|
return;
|
|
137
136
|
const instance = moduleMap.get(tag);
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
debug(`unmount module "${tag}"`);
|
|
138
|
+
if (_optionalChain([instance, 'optionalAccess', _3 => _3[_chunkAAF47ZC6js.UNMOUNT_SYMBOL]])) {
|
|
139
|
+
for (const cb of instance[_chunkAAF47ZC6js.UNMOUNT_SYMBOL])
|
|
140
140
|
await cb();
|
|
141
141
|
}
|
|
142
142
|
debug(`del module "${tag}"`);
|
|
143
|
-
_chunkLZAU5FUSjs.log.call(void 0, `Module ${_picocolors2.default.yellow(`[${tag}]`)} unmount`);
|
|
144
143
|
moduleMap.delete(tag);
|
|
145
144
|
constructorMap.delete(tag);
|
|
146
145
|
for (let i = meta.length - 1; i >= 0; i--) {
|
|
@@ -149,13 +148,13 @@ async function Factory(Modules, opts = {}) {
|
|
|
149
148
|
}
|
|
150
149
|
return instance;
|
|
151
150
|
}
|
|
152
|
-
|
|
151
|
+
_chunkAAF47ZC6js.__name.call(void 0, del, "del");
|
|
153
152
|
async function add(Module) {
|
|
154
153
|
const tag = _optionalChain([Module, 'access', _4 => _4.prototype, 'optionalAccess', _5 => _5.__TAG__]) || Module.name;
|
|
155
154
|
const oldInstance = await del(tag);
|
|
156
155
|
const { instance: newModule } = await buildNestModule(Module);
|
|
157
|
-
debug(`add module "${tag}"`);
|
|
158
156
|
if (oldInstance && moduleGraph.has(tag)) {
|
|
157
|
+
debug(`replace module "${tag}"`);
|
|
159
158
|
[
|
|
160
159
|
...moduleGraph.get(tag)
|
|
161
160
|
].forEach((tag2) => {
|
|
@@ -166,9 +165,8 @@ async function Factory(Modules, opts = {}) {
|
|
|
166
165
|
}
|
|
167
166
|
});
|
|
168
167
|
}
|
|
169
|
-
moduleMap.set(tag, newModule);
|
|
170
168
|
}
|
|
171
|
-
|
|
169
|
+
_chunkAAF47ZC6js.__name.call(void 0, add, "add");
|
|
172
170
|
async function buildNestModule(Module) {
|
|
173
171
|
const paramtypes = getParamTypes(Module);
|
|
174
172
|
let instance;
|
|
@@ -179,7 +177,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
179
177
|
throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`);
|
|
180
178
|
if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {
|
|
181
179
|
constructorSet.add(Module);
|
|
182
|
-
|
|
180
|
+
_chunkAAF47ZC6js.log.call(void 0, `Synonym module: Module taged "${tag}" has been loaded before, so phecda-server won't load Module "${Module.name}"`, "warn");
|
|
183
181
|
}
|
|
184
182
|
return {
|
|
185
183
|
instance,
|
|
@@ -196,36 +194,44 @@ async function Factory(Modules, opts = {}) {
|
|
|
196
194
|
moduleGraph.set(subTag, /* @__PURE__ */ new Set());
|
|
197
195
|
moduleGraph.get(subTag).add(tag);
|
|
198
196
|
}
|
|
197
|
+
debug(`instantiate module "${tag}"`);
|
|
199
198
|
instance = new Module(...paramtypesInstances);
|
|
200
199
|
} else {
|
|
200
|
+
debug(`instantiate module "${tag}"`);
|
|
201
201
|
instance = new Module();
|
|
202
202
|
}
|
|
203
203
|
meta.push(...getMetaFromInstance(instance, tag, Module.name));
|
|
204
|
+
debug(`init module "${tag}"`);
|
|
204
205
|
await _phecdacore.registerAsync.call(void 0, instance);
|
|
206
|
+
debug(`add module "${tag}"`);
|
|
205
207
|
moduleMap.set(tag, instance);
|
|
206
|
-
_chunkLZAU5FUSjs.log.call(void 0, `Module ${_picocolors2.default.yellow(`[${tag}]`)} mount"`);
|
|
207
208
|
constructorMap.set(tag, Module);
|
|
208
209
|
return {
|
|
209
210
|
instance,
|
|
210
211
|
tag
|
|
211
212
|
};
|
|
212
213
|
}
|
|
213
|
-
|
|
214
|
+
_chunkAAF47ZC6js.__name.call(void 0, buildNestModule, "buildNestModule");
|
|
214
215
|
for (const Module of Modules)
|
|
215
216
|
await buildNestModule(Module);
|
|
216
217
|
function writeCode() {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
if (http) {
|
|
219
|
+
debug(`write http code to ${http}`);
|
|
220
|
+
_fs2.default.promises.writeFile(http, generateHTTPCode(meta.map((item) => item.data)));
|
|
221
|
+
}
|
|
222
|
+
if (rpc) {
|
|
223
|
+
debug(`write rpc code to ${rpc}`);
|
|
224
|
+
_fs2.default.promises.writeFile(rpc, generateRPCCode(meta.map((item) => item.data)));
|
|
225
|
+
}
|
|
220
226
|
}
|
|
221
|
-
|
|
227
|
+
_chunkAAF47ZC6js.__name.call(void 0, writeCode, "writeCode");
|
|
222
228
|
writeCode();
|
|
223
|
-
if (
|
|
229
|
+
if (_chunkAAF47ZC6js.IS_DEV) {
|
|
224
230
|
if (!globalThis.__PS_HMR__)
|
|
225
231
|
globalThis.__PS_HMR__ = [];
|
|
226
232
|
_optionalChain([globalThis, 'access', _8 => _8.__PS_HMR__, 'optionalAccess', _9 => _9.push, 'call', _10 => _10(async (files) => {
|
|
233
|
+
debug("reload files ");
|
|
227
234
|
for (const file of files) {
|
|
228
|
-
debug(`reload file ${file}`);
|
|
229
235
|
const module = await Promise.resolve().then(() => require(file));
|
|
230
236
|
for (const i in module) {
|
|
231
237
|
if (_phecdacore.isPhecda.call(void 0, module[i]))
|
|
@@ -243,7 +249,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
243
249
|
del
|
|
244
250
|
};
|
|
245
251
|
}
|
|
246
|
-
|
|
252
|
+
_chunkAAF47ZC6js.__name.call(void 0, Factory, "Factory");
|
|
247
253
|
function getMetaFromInstance(instance, tag, name) {
|
|
248
254
|
const vars = _phecdacore.getExposeKey.call(void 0, instance).filter((item) => item !== "__CLASS");
|
|
249
255
|
const baseState = _phecdacore.getState.call(void 0, instance, "__CLASS") || {};
|
|
@@ -276,6 +282,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
276
282
|
break;
|
|
277
283
|
}
|
|
278
284
|
meta.params = params;
|
|
285
|
+
meta.filter = state.filter || baseState.filter;
|
|
279
286
|
meta.define = {
|
|
280
287
|
...baseState.define,
|
|
281
288
|
...state.define
|
|
@@ -305,11 +312,11 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
305
312
|
return new Meta(meta, _phecdacore.getHandler.call(void 0, instance, i), getParamTypes(instance, i) || []);
|
|
306
313
|
});
|
|
307
314
|
}
|
|
308
|
-
|
|
315
|
+
_chunkAAF47ZC6js.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
|
|
309
316
|
function getParamTypes(Module, key) {
|
|
310
317
|
return Reflect.getMetadata("design:paramtypes", Module, key);
|
|
311
318
|
}
|
|
312
|
-
|
|
319
|
+
_chunkAAF47ZC6js.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
313
320
|
function initState(state) {
|
|
314
321
|
if (!state.define)
|
|
315
322
|
state.define = {};
|
|
@@ -322,7 +329,7 @@ function initState(state) {
|
|
|
322
329
|
if (!state.interceptors)
|
|
323
330
|
state.interceptors = [];
|
|
324
331
|
}
|
|
325
|
-
|
|
332
|
+
_chunkAAF47ZC6js.__name.call(void 0, initState, "initState");
|
|
326
333
|
|
|
327
334
|
|
|
328
335
|
|
|
@@ -332,4 +339,4 @@ _chunkLZAU5FUSjs.__name.call(void 0, initState, "initState");
|
|
|
332
339
|
|
|
333
340
|
|
|
334
341
|
exports.Meta = Meta; exports.generateRPCCode = generateRPCCode; exports.generateHTTPCode = generateHTTPCode; exports.Injectable = Injectable; exports.emitter = emitter; exports.Factory = Factory;
|
|
335
|
-
//# sourceMappingURL=chunk-
|
|
342
|
+
//# sourceMappingURL=chunk-TZ27DHWL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/meta.ts","../src/compiler/rpc.ts","../src/compiler/http.ts","../src/core.ts"],"names":["Meta","data","handlers","paramsType","constructor","Compiler","classMap","getContent","content","name","Object","values","reduce","p","c","addMethod","args","rpc","method","tag","type","isEvent","generateRPCCode","meta","compiler","i","http","params","url","route","replace","_","js","key","generateHTTPCode","fs","EventEmitter","Empty","getExposeKey","getHandler","getState","injectProperty","isPhecda","registerAsync","Debug","Injectable","target","debug","emitter","Factory","Modules","opts","moduleMap","Map","constructorMap","constructorSet","WeakSet","moduleGraph","eventName","instance","options","fn","bind","v","UNMOUNT_SYMBOL","push","off","once","on","del","has","get","cb","delete","length","splice","add","Module","prototype","__TAG__","oldInstance","newModule","buildNestModule","forEach","module","paramtypes","getParamTypes","Error","log","set","undefined","paramtypesInstances","sub","subTag","Set","getMetaFromInstance","writeCode","promises","writeFile","map","item","IS_DEV","globalThis","__PS_HMR__","files","file","vars","filter","baseState","initState","state","unshift","index","define","header","plugins","guards","interceptors","Reflect","getMetadata"],"mappings":";;;;;;;;AAEO,IAAMA,OAAN,MAAMA;EACQC;EAAqBC;EAA8BC;EAAtEC,YAAmBH,MAAqBC,UAA8BC,YAAmB;gBAAtEF;oBAAqBC;sBAA8BC;EAEtE;AACF;AAJaH;;;ACAb,IAAMK,WAAN,6BAAMA,UAAAA;EACJC,WAAsD,CAAC;EACvDF,cAAc;EAAE;EAEhBG,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWC,QAAQ,KAAKH,UAAU;AAChCE,iBAAW;uBACMC;cACTC,OAAOC,OAAO,KAAKL,SAASG,KAAK,EAAEG,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAON;EACT;EAEAO,UAAUC,MAAc;AACtB,UAAM,EACJC,KAAKR,MAAMS,QAAQC,IAAG,IACpBH;AACJ,QAAI,CAACC,OAAO,CAACA,IAAIG;AACf;AACF,QAAI,CAAC,KAAKd,SAASG;AACjB,WAAKH,SAASG,QAAQ,CAAC;AACzB,SAAKH,SAASG,MAAMS,UAAU;MAC5BA;qBACeC,OAAOD,mBAAmB,CAAC,CAACD,IAAII,gBAAgBJ,IAAIG,KAAKR,OAAO,CAACC,GAAGC,MAAM;AACvF,aAAO,GAAGD,KAAKC;IACjB,GAAG,EAAA;;;;EAIP;AACF,GAjCA;AAmCO,SAASQ,gBAAgBC,MAAgB;AAC9C,QAAMC,WAAW,IAAInB,SAAAA;AAErB,aAAWoB,KAAKF;AACdC,aAAST,UAAUU,CAAAA;AACrB,SAAOD,SAASjB,WAAU;AAC5B;AANgBe;;;ACnChB,IAAMjB,YAAN,6BAAMA,UAAAA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;AACrD1F,SAAK2F,SAAS;MAAE,GAAGN,UAAUM;MAAQ,GAAGJ,MAAMI;IAAO;AACrD3F,SAAK4F,UAAU;SAAI,oBAAIrB,IAAI;WAAIc,UAAUO;WAAYL,MAAMK;OAAQ;;AACnE5F,SAAK6F,SAAS;SAAI,oBAAItB,IAAI;WAAIc,UAAUQ;WAAWN,MAAMM;OAAO;;AAChE7F,SAAK8F,eAAe;SAAI,oBAAIvB,IAAI;WAAIc,UAAUS;WAAiBP,MAAMO;OAAa;;AAElF,WAAO,IAAIrH,KAAKuB,MAA2BgB,WAAWoB,UAAUlC,CAAAA,GAAI6D,cAAc3B,UAAUlC,CAAAA,KAAgB,CAAA,CAAE;EAChH,CAAA;AACF;AA5CSsE;AA8CT,SAAST,cAAcT,QAAa5C,KAAuB;AACzD,SAAOqF,QAAQC,YAAY,qBAAqB1C,QAAQ5C,GAAAA;AAC1D;AAFSqD;AAIT,SAASuB,UAAUC,OAAY;AAC7B,MAAI,CAACA,MAAMG;AACTH,UAAMG,SAAS,CAAC;AAClB,MAAI,CAACH,MAAMI;AACTJ,UAAMI,SAAS,CAAC;AAClB,MAAI,CAACJ,MAAMK;AACTL,UAAMK,UAAU,CAAA;AAClB,MAAI,CAACL,MAAMM;AACTN,UAAMM,SAAS,CAAA;AACjB,MAAI,CAACN,MAAMO;AACTP,UAAMO,eAAe,CAAA;AACzB;AAXSR","sourcesContent":["import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.Meta, public handlers: P.Handler[], public paramsType: any[]) {\n\n }\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n rpc, name, method, tag,\n } = args\n if (!rpc || !rpc.type)\n return\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(){\n return {tag:'${tag}-${method}',isEvent:${!!rpc.isEvent},rpc:[${rpc.type.reduce((p, c) => {\n return `${p}\"${c}\",`\n }, '')}]}\n\n }\n `\n }\n}\n\nexport function generateRPCCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n // createRequest() {\n // let content = 'import {useC} from \\'phecda-server\\'\\n'\n // for (const name in this.classMap)\n // content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n // return content\n // }\n\n addMethod(args: P.Meta) {\n const {\n http, name, method, params, tag,\n } = args\n if (!http)\n return\n const url = http.route.replace(/\\/\\:([^\\/]*)/g, (_, js) => `/{{${js}}}`)\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(...args){\nconst ret={tag:\"${tag}-${method}\",body:{},headers:{},query:{},params:{},method:\"${http.type}\",url:\"${url}\",args}\n\n${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ''}=args[${i}]\\n${c.type === 'params' ? `ret.url=ret.url.replace('{{${c.key}}}',args[${i}])` : ''}\\n`, '')}\nreturn ret\n }\n `\n }\n}\n\nexport function generateHTTPCode(meta: P.Meta[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { Empty, getExposeKey, getHandler, getState, injectProperty, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { log } from './utils'\nimport { IS_DEV, UNMOUNT_SYMBOL } from './common'\nimport { generateHTTPCode, generateRPCCode } from './compiler'\nexport function Injectable() {\n return (target: any) => Empty(target)\n}\nconst debug = Debug('phecda-server')\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[], opts: {\n\n // HTTP generate code path\n http?: string\n // rpc generate code path\n rpc?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n\n // only work for warn\n const constructorSet = new WeakSet()\n const moduleGraph = new Map<string, Set<string>>()\n const { http, rpc } = opts\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n // work for hmr\n if (!instance[UNMOUNT_SYMBOL])\n instance[UNMOUNT_SYMBOL] = []\n\n instance[UNMOUNT_SYMBOL].push(() => {\n (emitter as any).off(eventName, fn)\n })\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n\n // only remove module in moduleMap(won't remove indiect module)\n async function del(tag: string) {\n if (!moduleMap.has(tag))\n return\n\n const instance = moduleMap.get(tag)\n\n debug(`unmount module \"${tag}\"`)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n\n debug(`del module \"${tag}\"`)\n\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n return instance\n }\n\n async function add(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n const oldInstance = await del(tag)\n\n const { instance: newModule } = await buildNestModule(Module)\n\n if (oldInstance && moduleGraph.has(tag)) {\n debug(`replace module \"${tag}\"`);\n\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === oldInstance)\n module[key] = newModule\n }\n })\n }\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamTypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {\n constructorSet.add(Module)// a module will only warn once\n log(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`, 'warn')\n }\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n\n debug(`init module \"${tag}\"`)\n\n await registerAsync(instance)\n\n debug(`add module \"${tag}\"`)\n\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeCode() {\n if (http) {\n debug(`write http code to ${http}`)\n fs.promises.writeFile(http, generateHTTPCode(meta.map(item => item.data)))\n }\n if (rpc) {\n debug(`write rpc code to ${rpc}`)\n\n fs.promises.writeFile(rpc, generateRPCCode(meta.map(item => item.data)))\n }\n }\n\n writeCode()\n if (IS_DEV) {\n if (!globalThis.__PS_HMR__)\n globalThis.__PS_HMR__ = []\n\n globalThis.__PS_HMR__?.push(async (files: string[]) => {\n debug('reload files ')\n\n for (const file of files) {\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await add(module[i])\n }\n }\n writeCode()\n })\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n add,\n del,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.Meta\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.Meta\n const state = (getState(instance, i) || {}) as P.Meta\n initState(state)\n if (state.http) {\n meta.http = {\n route: (baseState.http?.route || '') + (state.http.route),\n type: state.http.type,\n }\n }\n if (baseState.rpc)\n meta.rpc = baseState.rpc\n if (state.rpc) {\n meta.rpc = {\n ...meta.rpc,\n ...state.rpc,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n\n meta.params = params\n meta.filter = state.filter || baseState.filter\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.plugins = [...new Set([...baseState.plugins, ...state.plugins])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.Meta, getHandler(instance, i), getParamTypes(instance, i as string) || [])\n })\n}\n\nfunction getParamTypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.plugins)\n state.plugins = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__name
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AYJWOIAW.mjs";
|
|
4
4
|
|
|
5
5
|
// src/helper.ts
|
|
6
6
|
function resolveDep(ret, key) {
|
|
@@ -13,4 +13,4 @@ __name(resolveDep, "resolveDep");
|
|
|
13
13
|
export {
|
|
14
14
|
resolveDep
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=chunk-
|
|
16
|
+
//# sourceMappingURL=chunk-V7SC5EVJ.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
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 _chunkAAF47ZC6js = require('./chunk-AAF47ZC6.js');
|
|
4
4
|
|
|
5
5
|
// src/helper.ts
|
|
6
6
|
function resolveDep(ret, key) {
|
|
@@ -8,9 +8,9 @@ function resolveDep(ret, key) {
|
|
|
8
8
|
return _optionalChain([ret, 'optionalAccess', _ => _[key]]);
|
|
9
9
|
return ret;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
_chunkAAF47ZC6js.__name.call(void 0, resolveDep, "resolveDep");
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
exports.resolveDep = resolveDep;
|
|
16
|
-
//# sourceMappingURL=chunk-
|
|
16
|
+
//# sourceMappingURL=chunk-ZPMAM4LQ.js.map
|