phecda-server 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{axios-13a49ed4.d.ts → axios-d8ab1187.d.ts} +1 -0
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +8 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +6 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.ts +7 -18
- package/dist/index.js +45 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -97
- package/dist/index.mjs.map +1 -1
- package/dist/unplugin/esbuild.d.ts +7 -0
- package/dist/unplugin/esbuild.js +120 -0
- package/dist/unplugin/esbuild.js.map +1 -0
- package/dist/unplugin/esbuild.mjs +95 -0
- package/dist/unplugin/esbuild.mjs.map +1 -0
- package/dist/unplugin/unplugin.d.ts +7 -0
- package/dist/unplugin/unplugin.js +115 -0
- package/dist/unplugin/unplugin.js.map +1 -0
- package/dist/unplugin/unplugin.mjs +92 -0
- package/dist/unplugin/unplugin.mjs.map +1 -0
- package/dist/unplugin/vite.d.ts +7 -0
- package/dist/unplugin/vite.js +118 -0
- package/dist/unplugin/vite.js.map +1 -0
- package/dist/unplugin/vite.mjs +95 -0
- package/dist/unplugin/vite.mjs.map +1 -0
- package/dist/unplugin/webpack.d.ts +5 -0
- package/dist/unplugin/webpack.js +120 -0
- package/dist/unplugin/webpack.js.map +1 -0
- package/dist/unplugin/webpack.mjs +95 -0
- package/dist/unplugin/webpack.mjs.map +1 -0
- package/package.json +33 -4
package/dist/client/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { $ as $S, g as RequestMethod, j as createParallelReq, h as createReq, i as createSeriesReq, k as isError, m as merge, t as toReq } from '../axios-
|
|
1
|
+
export { $ as $S, g as RequestMethod, j as createParallelReq, h as createReq, i as createSeriesReq, k as isError, m as merge, t as toReq } from '../axios-d8ab1187.js';
|
|
2
2
|
import 'axios';
|
|
3
3
|
import 'express';
|
|
4
4
|
import 'amqplib';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
declare function createBeacon(baseUrl: string): (arg: any) => void;
|
|
8
|
+
declare function useC<T extends new (...args: any) => any>(Module: T): InstanceType<T>;
|
|
8
9
|
|
|
9
|
-
export { createBeacon };
|
|
10
|
+
export { createBeacon, useC };
|
package/dist/client/index.js
CHANGED
|
@@ -28,7 +28,8 @@ __export(client_exports, {
|
|
|
28
28
|
createSeriesReq: () => createSeriesReq,
|
|
29
29
|
isError: () => isError,
|
|
30
30
|
merge: () => merge,
|
|
31
|
-
toReq: () => toReq
|
|
31
|
+
toReq: () => toReq,
|
|
32
|
+
useC: () => useC
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(client_exports);
|
|
34
35
|
|
|
@@ -111,6 +112,10 @@ function createBeacon(baseUrl) {
|
|
|
111
112
|
};
|
|
112
113
|
}
|
|
113
114
|
__name(createBeacon, "createBeacon");
|
|
115
|
+
function useC(Module) {
|
|
116
|
+
return new Module();
|
|
117
|
+
}
|
|
118
|
+
__name(useC, "useC");
|
|
114
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
115
120
|
0 && (module.exports = {
|
|
116
121
|
$S,
|
|
@@ -120,6 +125,7 @@ __name(createBeacon, "createBeacon");
|
|
|
120
125
|
createSeriesReq,
|
|
121
126
|
isError,
|
|
122
127
|
merge,
|
|
123
|
-
toReq
|
|
128
|
+
toReq,
|
|
129
|
+
useC
|
|
124
130
|
});
|
|
125
131
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/index.ts","../../src/common.ts","../../src/client/axios.ts"],"sourcesContent":["import { toReq } from './axios'\nexport * from './axios'\n\nexport function createBeacon(baseUrl: string) {\n return (arg: any) => {\n const { url, params, query, body } = toReq(arg as any)\n\n navigator.sendBeacon(`${baseUrl}${url}${params}${query}`, JSON.stringify(body))\n }\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const REQ_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { PError, PRes, RequestType, ResOrErr } from '../types'\nimport { SERIES_SYMBOL } from '../common'\ninterface RequestArgs {\n body: Record<string, any>\n query: Record<string, string>\n params: Record<string, string>\n realParam: string\n method: RequestType\n url: string\n tag: string\n}\ntype MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag' >\nexport function toReq(arg: RequestArgs) {\n const { body, query, realParam, method, url } = arg\n return { method, url, body, query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')}` : '', params: realParam }\n}\n\nexport const merge = (...args: RequestArgs[]) => {\n const ret = [] as MergedReqArg[]\n for (const i of args) {\n const { body, query, params, tag } = i\n ret.push({ tag, body, query, params })\n }\n\n return ret\n}\n\nexport type RequestMethod = <F extends (...args: any[]) => any >(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>\n\nexport function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>> > {\n // @ts-expect-error methods without route decorator won't send request\n return (arg: any, config?: AxiosRequestConfig) => {\n const { url, params, query, body, method } = toReq(arg as RequestArgs)\n if (!method) {\n console.warn('methods without route decorator won\\'t send request')\n return\n }\n\n const ret = [`${url}${params}${query}`] as any[]\n body && ret.push(body)\n config && ret.push(config)\n // @ts-expect-error misdirction\n return instance[method](...ret)\n }\n}\n\nexport function createSeriesReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'series',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function createParallelReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'parallel',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function isError<T = any>(data: T | PError): data is PError {\n return typeof data === 'object' && (data as any).error\n}\n\nexport function $S(index: number, key = ''): any {\n return `${SERIES_SYMBOL}@${index}@${key}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"sources":["../../src/client/index.ts","../../src/common.ts","../../src/client/axios.ts"],"sourcesContent":["import { toReq } from './axios'\nexport * from './axios'\n\nexport function createBeacon(baseUrl: string) {\n return (arg: any) => {\n const { url, params, query, body } = toReq(arg as any)\n\n navigator.sendBeacon(`${baseUrl}${url}${params}${query}`, JSON.stringify(body))\n }\n}\n\nexport function useC<T extends new (...args: any) => any>(Module: T): InstanceType<T> {\n return new Module()\n}\n","export const SERIES_SYMBOL = '__symbol_series__'\nexport const REQ_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { PError, PRes, RequestType, ResOrErr } from '../types'\nimport { SERIES_SYMBOL } from '../common'\ninterface RequestArgs {\n body: Record<string, any>\n query: Record<string, string>\n params: Record<string, string>\n realParam: string\n method: RequestType\n url: string\n tag: string\n}\ntype MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag' >\nexport function toReq(arg: RequestArgs) {\n const { body, query, realParam, method, url } = arg\n return { method, url, body, query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')}` : '', params: realParam }\n}\n\nexport const merge = (...args: RequestArgs[]) => {\n const ret = [] as MergedReqArg[]\n for (const i of args) {\n const { body, query, params, tag } = i\n ret.push({ tag, body, query, params })\n }\n\n return ret\n}\n\nexport type RequestMethod = <F extends (...args: any[]) => any >(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>\n\nexport function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>> > {\n // @ts-expect-error methods without route decorator won't send request\n return (arg: any, config?: AxiosRequestConfig) => {\n const { url, params, query, body, method } = toReq(arg as RequestArgs)\n if (!method) {\n console.warn('methods without route decorator won\\'t send request')\n return\n }\n\n const ret = [`${url}${params}${query}`] as any[]\n body && ret.push(body)\n config && ret.push(config)\n // @ts-expect-error misdirction\n return instance[method](...ret)\n }\n}\n\nexport function createSeriesReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'series',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function createParallelReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'parallel',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function isError<T = any>(data: T | PError): data is PError {\n return typeof data === 'object' && (data as any).error\n}\n\nexport function $S(index: number, key = ''): any {\n return `${SERIES_SYMBOL}@${index}@${key}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACAO,IAAMA,gBAAgB;;;ACatB,SAASC,MAAMC,KAAkB;AACtC,QAAM,EAAEC,MAAMC,OAAOC,WAAWC,QAAQC,IAAG,IAAKL;AAChD,SAAO;IAAEI;IAAQC;IAAKJ;IAAMC,OAAOI,OAAOC,KAAKL,KAAAA,EAAOM,SAAS,IAAI,IAAIF,OAAOG,QAAQP,KAAAA,EAAOQ,IAAI,CAAC,CAACC,GAAGC,CAAAA,MAAO,GAAGD,KAAKC,GAAG,EAAEC,KAAK,GAAA,MAAS;IAAIC,QAAQX;EAAU;AAChK;AAHgBJ;AAKT,IAAMgB,QAAQ,2BAAIC,SAAwB;AAC/C,QAAMC,MAAM,CAAA;AACZ,aAAWC,KAAKF,MAAM;AACpB,UAAM,EAAEf,MAAMC,OAAOY,QAAQK,IAAG,IAAKD;AACrCD,QAAIG,KAAK;MAAED;MAAKlB;MAAMC;MAAOY;IAAO,CAAA;EACtC;AAEA,SAAOG;AACT,GARqB;AAYd,SAASI,UAAUC,UAAgH;AAExI,SAAO,CAACtB,KAAUuB,WAAgC;AAChD,UAAM,EAAElB,KAAKS,QAAQZ,OAAOD,MAAMG,OAAM,IAAKL,MAAMC,GAAAA;AACnD,QAAI,CAACI,QAAQ;AACXoB,cAAQC,KAAK,oDAAA;AACb;IACF;AAEA,UAAMR,MAAM;MAAC,GAAGZ,MAAMS,SAASZ;;AAC/BD,YAAQgB,IAAIG,KAAKnB,IAAAA;AACjBsB,cAAUN,IAAIG,KAAKG,MAAAA;AAEnB,WAAOD,SAASlB,QAAO,GAAIa,GAAAA;EAC7B;AACF;AAfgBI;AAiBT,SAASK,gBAAgBJ,UAAyBK,MAAM,sBAAiI;AAE9L,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBG;AAUT,SAASK,kBAAkBT,UAAyBK,MAAM,sBAAiI;AAEhM,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBQ;AAUT,SAASC,QAAiBF,MAAkC;AACjE,SAAO,OAAOA,SAAS,YAAaA,KAAaG;AACnD;AAFgBD;AAIT,SAASE,GAAGC,OAAeR,MAAM,IAAS;AAC/C,SAAO,GAAGS,iBAAiBD,SAASR;AACtC;AAFgBO;;;AFpET,SAASG,aAAaC,SAAiB;AAC5C,SAAO,CAACC,QAAa;AACnB,UAAM,EAAEC,KAAKC,QAAQC,OAAOC,KAAI,IAAKC,MAAML,GAAAA;AAE3CM,cAAUC,WAAW,GAAGR,UAAUE,MAAMC,SAASC,SAASK,KAAKC,UAAUL,IAAAA,CAAAA;EAC3E;AACF;AANgBN;AAQT,SAASY,KAA0CC,QAA4B;AACpF,SAAO,IAAIA,OAAAA;AACb;AAFgBD;","names":["SERIES_SYMBOL","toReq","arg","body","query","realParam","method","url","Object","keys","length","entries","map","k","v","join","params","merge","args","ret","i","tag","push","createReq","instance","config","console","warn","createSeriesReq","key","post","category","data","createParallelReq","isError","error","$S","index","SERIES_SYMBOL","createBeacon","baseUrl","arg","url","params","query","body","toReq","navigator","sendBeacon","JSON","stringify","useC","Module"]}
|
package/dist/client/index.mjs
CHANGED
|
@@ -80,6 +80,10 @@ function createBeacon(baseUrl) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
__name(createBeacon, "createBeacon");
|
|
83
|
+
function useC(Module) {
|
|
84
|
+
return new Module();
|
|
85
|
+
}
|
|
86
|
+
__name(useC, "useC");
|
|
83
87
|
export {
|
|
84
88
|
$S,
|
|
85
89
|
createBeacon,
|
|
@@ -88,6 +92,7 @@ export {
|
|
|
88
92
|
createSeriesReq,
|
|
89
93
|
isError,
|
|
90
94
|
merge,
|
|
91
|
-
toReq
|
|
95
|
+
toReq,
|
|
96
|
+
useC
|
|
92
97
|
};
|
|
93
98
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/common.ts","../../src/client/axios.ts","../../src/client/index.ts"],"sourcesContent":["export const SERIES_SYMBOL = '__symbol_series__'\nexport const REQ_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { PError, PRes, RequestType, ResOrErr } from '../types'\nimport { SERIES_SYMBOL } from '../common'\ninterface RequestArgs {\n body: Record<string, any>\n query: Record<string, string>\n params: Record<string, string>\n realParam: string\n method: RequestType\n url: string\n tag: string\n}\ntype MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag' >\nexport function toReq(arg: RequestArgs) {\n const { body, query, realParam, method, url } = arg\n return { method, url, body, query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')}` : '', params: realParam }\n}\n\nexport const merge = (...args: RequestArgs[]) => {\n const ret = [] as MergedReqArg[]\n for (const i of args) {\n const { body, query, params, tag } = i\n ret.push({ tag, body, query, params })\n }\n\n return ret\n}\n\nexport type RequestMethod = <F extends (...args: any[]) => any >(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>\n\nexport function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>> > {\n // @ts-expect-error methods without route decorator won't send request\n return (arg: any, config?: AxiosRequestConfig) => {\n const { url, params, query, body, method } = toReq(arg as RequestArgs)\n if (!method) {\n console.warn('methods without route decorator won\\'t send request')\n return\n }\n\n const ret = [`${url}${params}${query}`] as any[]\n body && ret.push(body)\n config && ret.push(config)\n // @ts-expect-error misdirction\n return instance[method](...ret)\n }\n}\n\nexport function createSeriesReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'series',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function createParallelReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'parallel',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function isError<T = any>(data: T | PError): data is PError {\n return typeof data === 'object' && (data as any).error\n}\n\nexport function $S(index: number, key = ''): any {\n return `${SERIES_SYMBOL}@${index}@${key}`\n}\n","import { toReq } from './axios'\nexport * from './axios'\n\nexport function createBeacon(baseUrl: string) {\n return (arg: any) => {\n const { url, params, query, body } = toReq(arg as any)\n\n navigator.sendBeacon(`${baseUrl}${url}${params}${query}`, JSON.stringify(body))\n }\n}\n"],"mappings":";;;;AAAO,IAAMA,gBAAgB;;;ACatB,SAASC,MAAMC,KAAkB;AACtC,QAAM,EAAEC,MAAMC,OAAOC,WAAWC,QAAQC,IAAG,IAAKL;AAChD,SAAO;IAAEI;IAAQC;IAAKJ;IAAMC,OAAOI,OAAOC,KAAKL,KAAAA,EAAOM,SAAS,IAAI,IAAIF,OAAOG,QAAQP,KAAAA,EAAOQ,IAAI,CAAC,CAACC,GAAGC,CAAAA,MAAO,GAAGD,KAAKC,GAAG,EAAEC,KAAK,GAAA,MAAS;IAAIC,QAAQX;EAAU;AAChK;AAHgBJ;AAKT,IAAMgB,QAAQ,2BAAIC,SAAwB;AAC/C,QAAMC,MAAM,CAAA;AACZ,aAAWC,KAAKF,MAAM;AACpB,UAAM,EAAEf,MAAMC,OAAOY,QAAQK,IAAG,IAAKD;AACrCD,QAAIG,KAAK;MAAED;MAAKlB;MAAMC;MAAOY;IAAO,CAAA;EACtC;AAEA,SAAOG;AACT,GARqB;AAYd,SAASI,UAAUC,UAAgH;AAExI,SAAO,CAACtB,KAAUuB,WAAgC;AAChD,UAAM,EAAElB,KAAKS,QAAQZ,OAAOD,MAAMG,OAAM,IAAKL,MAAMC,GAAAA;AACnD,QAAI,CAACI,QAAQ;AACXoB,cAAQC,KAAK,oDAAA;AACb;IACF;AAEA,UAAMR,MAAM;MAAC,GAAGZ,MAAMS,SAASZ;;AAC/BD,YAAQgB,IAAIG,KAAKnB,IAAAA;AACjBsB,cAAUN,IAAIG,KAAKG,MAAAA;AAEnB,WAAOD,SAASlB,QAAO,GAAIa,GAAAA;EAC7B;AACF;AAfgBI;AAiBT,SAASK,gBAAgBJ,UAAyBK,MAAM,sBAAiI;AAE9L,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBG;AAUT,SAASK,kBAAkBT,UAAyBK,MAAM,sBAAiI;AAEhM,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBQ;AAUT,SAASC,QAAiBF,MAAkC;AACjE,SAAO,OAAOA,SAAS,YAAaA,KAAaG;AACnD;AAFgBD;AAIT,SAASE,GAAGC,OAAeR,MAAM,IAAS;AAC/C,SAAO,GAAGS,iBAAiBD,SAASR;AACtC;AAFgBO;;;ACpET,SAASG,aAAaC,SAAiB;AAC5C,SAAO,CAACC,QAAa;AACnB,UAAM,EAAEC,KAAKC,QAAQC,OAAOC,KAAI,IAAKC,MAAML,GAAAA;AAE3CM,cAAUC,WAAW,GAAGR,UAAUE,MAAMC,SAASC,SAASK,KAAKC,UAAUL,IAAAA,CAAAA;EAC3E;AACF;AANgBN;","names":["SERIES_SYMBOL","toReq","arg","body","query","realParam","method","url","Object","keys","length","entries","map","k","v","join","params","merge","args","ret","i","tag","push","createReq","instance","config","console","warn","createSeriesReq","key","post","category","data","createParallelReq","isError","error","$S","index","SERIES_SYMBOL","createBeacon","baseUrl","arg","url","params","query","body","toReq","navigator","sendBeacon","JSON","stringify"]}
|
|
1
|
+
{"version":3,"sources":["../../src/common.ts","../../src/client/axios.ts","../../src/client/index.ts"],"sourcesContent":["export const SERIES_SYMBOL = '__symbol_series__'\nexport const REQ_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { PError, PRes, RequestType, ResOrErr } from '../types'\nimport { SERIES_SYMBOL } from '../common'\ninterface RequestArgs {\n body: Record<string, any>\n query: Record<string, string>\n params: Record<string, string>\n realParam: string\n method: RequestType\n url: string\n tag: string\n}\ntype MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag' >\nexport function toReq(arg: RequestArgs) {\n const { body, query, realParam, method, url } = arg\n return { method, url, body, query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')}` : '', params: realParam }\n}\n\nexport const merge = (...args: RequestArgs[]) => {\n const ret = [] as MergedReqArg[]\n for (const i of args) {\n const { body, query, params, tag } = i\n ret.push({ tag, body, query, params })\n }\n\n return ret\n}\n\nexport type RequestMethod = <F extends (...args: any[]) => any >(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>\n\nexport function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>> > {\n // @ts-expect-error methods without route decorator won't send request\n return (arg: any, config?: AxiosRequestConfig) => {\n const { url, params, query, body, method } = toReq(arg as RequestArgs)\n if (!method) {\n console.warn('methods without route decorator won\\'t send request')\n return\n }\n\n const ret = [`${url}${params}${query}`] as any[]\n body && ret.push(body)\n config && ret.push(config)\n // @ts-expect-error misdirction\n return instance[method](...ret)\n }\n}\n\nexport function createSeriesReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'series',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function createParallelReq(instance: AxiosInstance, key = '/__PHECDA_SERVER__'): < R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>> {\n // @ts-expect-error misdirction\n return (args: RequestArgs[], config?: AxiosRequestConfig) => {\n return instance.post(key, {\n category: 'parallel',\n data: merge(...args),\n }, config)\n }\n}\n\nexport function isError<T = any>(data: T | PError): data is PError {\n return typeof data === 'object' && (data as any).error\n}\n\nexport function $S(index: number, key = ''): any {\n return `${SERIES_SYMBOL}@${index}@${key}`\n}\n","import { toReq } from './axios'\nexport * from './axios'\n\nexport function createBeacon(baseUrl: string) {\n return (arg: any) => {\n const { url, params, query, body } = toReq(arg as any)\n\n navigator.sendBeacon(`${baseUrl}${url}${params}${query}`, JSON.stringify(body))\n }\n}\n\nexport function useC<T extends new (...args: any) => any>(Module: T): InstanceType<T> {\n return new Module()\n}\n"],"mappings":";;;;AAAO,IAAMA,gBAAgB;;;ACatB,SAASC,MAAMC,KAAkB;AACtC,QAAM,EAAEC,MAAMC,OAAOC,WAAWC,QAAQC,IAAG,IAAKL;AAChD,SAAO;IAAEI;IAAQC;IAAKJ;IAAMC,OAAOI,OAAOC,KAAKL,KAAAA,EAAOM,SAAS,IAAI,IAAIF,OAAOG,QAAQP,KAAAA,EAAOQ,IAAI,CAAC,CAACC,GAAGC,CAAAA,MAAO,GAAGD,KAAKC,GAAG,EAAEC,KAAK,GAAA,MAAS;IAAIC,QAAQX;EAAU;AAChK;AAHgBJ;AAKT,IAAMgB,QAAQ,2BAAIC,SAAwB;AAC/C,QAAMC,MAAM,CAAA;AACZ,aAAWC,KAAKF,MAAM;AACpB,UAAM,EAAEf,MAAMC,OAAOY,QAAQK,IAAG,IAAKD;AACrCD,QAAIG,KAAK;MAAED;MAAKlB;MAAMC;MAAOY;IAAO,CAAA;EACtC;AAEA,SAAOG;AACT,GARqB;AAYd,SAASI,UAAUC,UAAgH;AAExI,SAAO,CAACtB,KAAUuB,WAAgC;AAChD,UAAM,EAAElB,KAAKS,QAAQZ,OAAOD,MAAMG,OAAM,IAAKL,MAAMC,GAAAA;AACnD,QAAI,CAACI,QAAQ;AACXoB,cAAQC,KAAK,oDAAA;AACb;IACF;AAEA,UAAMR,MAAM;MAAC,GAAGZ,MAAMS,SAASZ;;AAC/BD,YAAQgB,IAAIG,KAAKnB,IAAAA;AACjBsB,cAAUN,IAAIG,KAAKG,MAAAA;AAEnB,WAAOD,SAASlB,QAAO,GAAIa,GAAAA;EAC7B;AACF;AAfgBI;AAiBT,SAASK,gBAAgBJ,UAAyBK,MAAM,sBAAiI;AAE9L,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBG;AAUT,SAASK,kBAAkBT,UAAyBK,MAAM,sBAAiI;AAEhM,SAAO,CAACX,MAAqBO,WAAgC;AAC3D,WAAOD,SAASM,KAAKD,KAAK;MACxBE,UAAU;MACVC,MAAMf,MAAAA,GAASC,IAAAA;IACjB,GAAGO,MAAAA;EACL;AACF;AARgBQ;AAUT,SAASC,QAAiBF,MAAkC;AACjE,SAAO,OAAOA,SAAS,YAAaA,KAAaG;AACnD;AAFgBD;AAIT,SAASE,GAAGC,OAAeR,MAAM,IAAS;AAC/C,SAAO,GAAGS,iBAAiBD,SAASR;AACtC;AAFgBO;;;ACpET,SAASG,aAAaC,SAAiB;AAC5C,SAAO,CAACC,QAAa;AACnB,UAAM,EAAEC,KAAKC,QAAQC,OAAOC,KAAI,IAAKC,MAAML,GAAAA;AAE3CM,cAAUC,WAAW,GAAGR,UAAUE,MAAMC,SAASC,SAASK,KAAKC,UAAUL,IAAAA,CAAAA;EAC3E;AACF;AANgBN;AAQT,SAASY,KAA0CC,QAA4B;AACpF,SAAO,IAAIA,OAAAA;AACb;AAFgBD;","names":["SERIES_SYMBOL","toReq","arg","body","query","realParam","method","url","Object","keys","length","entries","map","k","v","join","params","merge","args","ret","i","tag","push","createReq","instance","config","console","warn","createSeriesReq","key","post","category","data","createParallelReq","isError","error","$S","index","SERIES_SYMBOL","createBeacon","baseUrl","arg","url","params","query","body","toReq","navigator","sendBeacon","JSON","stringify","useC","Module"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { S as ServerMeta, P as PHandler,
|
|
2
|
-
export { $ as $S, B as BaseError, M as MergeType, f as MqContextData, b as PError, d as PRes, g as RequestMethod, c as ResOrErr, e as ServerContextData, T as Transform, U as UnWrap, j as createParallelReq, h as createReq, i as createSeriesReq, k as isError, m as merge, t as toReq } from './axios-
|
|
1
|
+
import { S as ServerMeta, P as PHandler, a as PhecdaEmitter } from './axios-d8ab1187.js';
|
|
2
|
+
export { $ as $S, B as BaseError, C as Construct, M as MergeType, f as MqContextData, b as PError, d as PRes, g as RequestMethod, R as RequestType, c as ResOrErr, e as ServerContextData, T as Transform, U as UnWrap, j as createParallelReq, h as createReq, i as createSeriesReq, k as isError, m as merge, t as toReq } from './axios-d8ab1187.js';
|
|
3
3
|
import { Express } from 'express';
|
|
4
|
-
import { PluginOption } from 'vite';
|
|
5
4
|
export * from 'phecda-core';
|
|
6
5
|
import amqplib from 'amqplib';
|
|
7
6
|
import 'axios';
|
|
@@ -85,7 +84,7 @@ declare abstract class Pcontext {
|
|
|
85
84
|
useInterceptor(interceptors: string[], isMerge?: boolean): Promise<void>;
|
|
86
85
|
usePost(data: any): Promise<any>;
|
|
87
86
|
}
|
|
88
|
-
declare function addGuard(key: string, handler: (contextData: any, isMerge: boolean) => boolean): void;
|
|
87
|
+
declare function addGuard(key: string, handler: (contextData: any, isMerge: boolean) => Promise<boolean> | boolean): void;
|
|
89
88
|
declare function addInterceptor(key: string, handler: (contextData: any, isMerge: boolean) => any): void;
|
|
90
89
|
declare function getInstance(tag: string): any;
|
|
91
90
|
declare function parseMeta(meta: Pmeta): {
|
|
@@ -136,22 +135,14 @@ declare class Pcompiler {
|
|
|
136
135
|
}>;
|
|
137
136
|
constructor();
|
|
138
137
|
getContent(): string;
|
|
139
|
-
addMethod(
|
|
140
|
-
type: string;
|
|
141
|
-
key: string;
|
|
142
|
-
index: number;
|
|
143
|
-
}[]): void;
|
|
144
|
-
addMqMethod(className: string, methodName: string, exchange?: string, routeKey?: string, queue?: string, params?: {
|
|
145
|
-
type: string;
|
|
146
|
-
key: string;
|
|
147
|
-
index: number;
|
|
148
|
-
}[]): void;
|
|
138
|
+
addMethod(args: ServerMeta): void;
|
|
149
139
|
}
|
|
150
140
|
|
|
151
141
|
declare const emitter: PhecdaEmitter;
|
|
152
|
-
declare function Factory
|
|
142
|
+
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
|
|
153
143
|
moduleMap: Map<string, any>;
|
|
154
144
|
meta: Pmeta[];
|
|
145
|
+
output: (p?: string) => void;
|
|
155
146
|
}>;
|
|
156
147
|
|
|
157
148
|
interface Options {
|
|
@@ -182,12 +173,10 @@ declare function MQ(queue: string, routeKey: string, options?: amqplib.Options.C
|
|
|
182
173
|
declare function Inject(_target: any): void;
|
|
183
174
|
declare function Header(name: string, value: string): (target: any, k: PropertyKey) => void;
|
|
184
175
|
|
|
185
|
-
declare function Server(localPath?: string): PluginOption;
|
|
186
|
-
|
|
187
176
|
declare function bindMQ(ch: amqplib.Channel, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>): Promise<void>;
|
|
188
177
|
type MqMethod<T> = (arg: T) => void;
|
|
189
178
|
declare function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channel, method: T, type?: string): Promise<MqMethod<Parameters<T>>>;
|
|
190
179
|
|
|
191
180
|
declare function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void>;
|
|
192
181
|
|
|
193
|
-
export { BadRequestException, BaseParam, Body,
|
|
182
|
+
export { BadRequestException, BaseParam, Body, Controller, Delete, Factory, ForbiddenException, Get, Guard, Header, HttpException, Inject, Interceptor, MQ, Middle, NotFoundException, Options, PHandler, Param, Pcompiler, Pcontext, PhecdaEmitter, Pmeta, Post, Put, Query, RabbitMqContext, Route, ServerContext, ServerMeta, UndefinedException, ValidateException, ValidatePipe, WrongMetaException, addGuard, addInterceptor, addMiddleware, bindApp, bindMQ, createMqReq, createPub, defaultPipe, emitter, getInstance, parseMeta, useMqFilter, useMqPipe, useServerFilter, useServerPipe };
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,6 @@ __export(src_exports, {
|
|
|
59
59
|
Query: () => Query,
|
|
60
60
|
RabbitMqContext: () => RabbitMqContext,
|
|
61
61
|
Route: () => Route,
|
|
62
|
-
Server: () => Server,
|
|
63
62
|
ServerContext: () => ServerContext,
|
|
64
63
|
UndefinedException: () => UndefinedException,
|
|
65
64
|
ValidateException: () => ValidateException,
|
|
@@ -128,16 +127,17 @@ var defaultPipe = {
|
|
|
128
127
|
const { validate, arg } = args[i];
|
|
129
128
|
if (validate === false)
|
|
130
129
|
continue;
|
|
131
|
-
if (
|
|
132
|
-
|
|
130
|
+
if ((0, import_phecda_core.isPhecda)(reflect[i])) {
|
|
131
|
+
const ret = await (0, import_phecda_core.plainToClass)(reflect[i], arg, {
|
|
132
|
+
transform: true
|
|
133
|
+
});
|
|
134
|
+
if (ret.err.length > 0)
|
|
135
|
+
throw new ValidateException(ret.err[0]);
|
|
136
|
+
args[i].arg = ret.data;
|
|
133
137
|
} else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
if (ret.err.length > 0)
|
|
139
|
-
throw new ValidateException(ret.err[0]);
|
|
140
|
-
}
|
|
138
|
+
args[i].arg = reflect[i](arg);
|
|
139
|
+
if (reflect[i] === Number && Object.is(args[i].arg, NaN))
|
|
140
|
+
throw new ValidateException(`parameter ${Number(i) + 1} should be a number`);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
return args.map((item) => item.arg);
|
|
@@ -377,28 +377,17 @@ var Pcompiler = class {
|
|
|
377
377
|
}
|
|
378
378
|
return content;
|
|
379
379
|
}
|
|
380
|
-
addMethod(
|
|
380
|
+
addMethod(args) {
|
|
381
|
+
const { route: { route = "/", type = "get" } = {}, name, method, params, tag } = args;
|
|
381
382
|
const url = route.replace(/\/\:([^\/]*)/g, "");
|
|
382
|
-
if (!this.classMap[
|
|
383
|
-
this.classMap[
|
|
384
|
-
this.classMap[
|
|
385
|
-
${
|
|
386
|
-
const ret={tag:"${
|
|
383
|
+
if (!this.classMap[name])
|
|
384
|
+
this.classMap[name] = {};
|
|
385
|
+
this.classMap[name][method] = `
|
|
386
|
+
${method}(${genParams(params)}){
|
|
387
|
+
const ret={tag:"${tag}-${method}",body:{},query:{},params:{},realParam:'',method:"${type}",url:"${url}"}
|
|
387
388
|
${params.filter((item) => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}
|
|
388
389
|
${c.type === "params" ? `ret.realParam+='/'+arg${i}
|
|
389
390
|
` : ""}`, "")}
|
|
390
|
-
return ret
|
|
391
|
-
}
|
|
392
|
-
`;
|
|
393
|
-
}
|
|
394
|
-
addMqMethod(className, methodName, exchange = "", routeKey = "", queue = "", params = []) {
|
|
395
|
-
if (!this.classMap[className])
|
|
396
|
-
this.classMap[className] = {};
|
|
397
|
-
this.classMap[className][methodName] = `
|
|
398
|
-
${methodName}(${genParams(params)}){
|
|
399
|
-
const ret={tag:"${className}-${methodName}",exchange:"${exchange}",routeKey:"${routeKey}",queue:"${queue}",args:{}}
|
|
400
|
-
${params.reduce((p, c, i) => `${p}ret.args.${c.key}=arg${i}
|
|
401
|
-
`, "")}
|
|
402
391
|
return ret
|
|
403
392
|
}
|
|
404
393
|
`;
|
|
@@ -406,10 +395,9 @@ return ret
|
|
|
406
395
|
};
|
|
407
396
|
__name(Pcompiler, "Pcompiler");
|
|
408
397
|
function genParams(decorators) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}, "");
|
|
398
|
+
return decorators.map((_, i) => {
|
|
399
|
+
return `${`arg${i}`}`;
|
|
400
|
+
}).join(",");
|
|
413
401
|
}
|
|
414
402
|
__name(genParams, "genParams");
|
|
415
403
|
|
|
@@ -439,11 +427,11 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
439
427
|
};
|
|
440
428
|
const methodMap = {};
|
|
441
429
|
for (const i of meta) {
|
|
442
|
-
const { name, method, route: route2, header } = i.data;
|
|
443
|
-
const instance = moduleMap.get(
|
|
444
|
-
const
|
|
445
|
-
Pcontext.metaRecord[
|
|
446
|
-
let { guards, reflect, interceptors, params, middlewares } = Pcontext.metaDataRecord[
|
|
430
|
+
const { name, method, route: route2, header, tag } = i.data;
|
|
431
|
+
const instance = moduleMap.get(tag);
|
|
432
|
+
const methodTag = `${tag}-${method}`;
|
|
433
|
+
Pcontext.metaRecord[methodTag] = i;
|
|
434
|
+
let { guards, reflect, interceptors, params, middlewares } = Pcontext.metaDataRecord[methodTag] ? Pcontext.metaDataRecord[methodTag] : Pcontext.metaDataRecord[methodTag] = parseMeta(i);
|
|
447
435
|
guards = [
|
|
448
436
|
...globalGuards,
|
|
449
437
|
...guards
|
|
@@ -453,16 +441,16 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
453
441
|
...interceptors
|
|
454
442
|
];
|
|
455
443
|
const handler = instance[method].bind(instance);
|
|
456
|
-
methodMap[
|
|
444
|
+
methodMap[methodTag] = handler;
|
|
457
445
|
Pcontext.instanceRecord[name] = instance;
|
|
458
446
|
if (route2) {
|
|
459
447
|
app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
|
|
460
448
|
const contextData = {
|
|
461
449
|
request: req,
|
|
462
|
-
|
|
450
|
+
methodTag,
|
|
463
451
|
response: res
|
|
464
452
|
};
|
|
465
|
-
const context = new ServerContext(
|
|
453
|
+
const context = new ServerContext(methodTag, contextData);
|
|
466
454
|
try {
|
|
467
455
|
for (const name2 in header)
|
|
468
456
|
res.set(name2, header[name2]);
|
|
@@ -536,7 +524,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
536
524
|
}
|
|
537
525
|
if (category === "parallel") {
|
|
538
526
|
return Promise.all(data.map((item) => {
|
|
539
|
-
return new Promise(async (
|
|
527
|
+
return new Promise(async (resolve) => {
|
|
540
528
|
const { tag } = item;
|
|
541
529
|
const [name] = tag.split("-");
|
|
542
530
|
const { guards, reflect, interceptors, params } = Pcontext.metaDataRecord[tag];
|
|
@@ -554,11 +542,11 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
554
542
|
};
|
|
555
543
|
}), reflect);
|
|
556
544
|
instance.meta = contextData;
|
|
557
|
-
|
|
545
|
+
resolve(await context.usePost(await methodMap[tag](...args)));
|
|
558
546
|
} catch (e) {
|
|
559
547
|
const m = Pcontext.metaRecord[tag];
|
|
560
548
|
m.handlers.forEach((handler) => handler.error?.(e));
|
|
561
|
-
|
|
549
|
+
resolve(await context.useFilter(e));
|
|
562
550
|
}
|
|
563
551
|
});
|
|
564
552
|
})).then((ret2) => {
|
|
@@ -573,6 +561,7 @@ __name(bindApp, "bindApp");
|
|
|
573
561
|
// src/core.ts
|
|
574
562
|
var import_reflect_metadata = require("reflect-metadata");
|
|
575
563
|
var import_events = __toESM(require("events"));
|
|
564
|
+
var import_fs = __toESM(require("fs"));
|
|
576
565
|
var import_phecda_core2 = require("phecda-core");
|
|
577
566
|
|
|
578
567
|
// src/meta.ts
|
|
@@ -604,35 +593,37 @@ async function Factory(Modules) {
|
|
|
604
593
|
await buildNestModule(Module, moduleMap, meta);
|
|
605
594
|
return {
|
|
606
595
|
moduleMap,
|
|
607
|
-
meta
|
|
596
|
+
meta,
|
|
597
|
+
output: (p = "pmeta.js") => import_fs.default.writeFileSync(p, JSON.stringify(meta.map((item) => item.data)))
|
|
608
598
|
};
|
|
609
599
|
}
|
|
610
600
|
__name(Factory, "Factory");
|
|
611
601
|
async function buildNestModule(Module, map, meta) {
|
|
612
602
|
const paramtypes = getParamtypes(Module);
|
|
613
603
|
let instance;
|
|
614
|
-
const
|
|
615
|
-
if (map.has(
|
|
616
|
-
instance = map.get(
|
|
604
|
+
const tag = Module.prototype?.__TAG__ || Module.name;
|
|
605
|
+
if (map.has(tag)) {
|
|
606
|
+
instance = map.get(tag);
|
|
617
607
|
if (!instance)
|
|
618
608
|
throw new Error(`exist Circular Module dep--${Module}`);
|
|
619
609
|
return instance;
|
|
620
610
|
}
|
|
621
|
-
map.set(
|
|
611
|
+
map.set(tag, void 0);
|
|
622
612
|
if (paramtypes) {
|
|
613
|
+
const paramtypesInstances = [];
|
|
623
614
|
for (const i in paramtypes)
|
|
624
|
-
|
|
625
|
-
instance = new Module(...
|
|
615
|
+
paramtypesInstances[i] = await buildNestModule(paramtypes[i], map, meta);
|
|
616
|
+
instance = new Module(...paramtypesInstances);
|
|
626
617
|
} else {
|
|
627
618
|
instance = new Module();
|
|
628
619
|
}
|
|
629
|
-
meta.push(...getMetaFromInstance(instance, Module.name));
|
|
620
|
+
meta.push(...getMetaFromInstance(instance, Module.name, tag));
|
|
630
621
|
await (0, import_phecda_core2.registerAsync)(instance);
|
|
631
|
-
map.set(
|
|
622
|
+
map.set(tag, instance);
|
|
632
623
|
return instance;
|
|
633
624
|
}
|
|
634
625
|
__name(buildNestModule, "buildNestModule");
|
|
635
|
-
function getMetaFromInstance(instance, name) {
|
|
626
|
+
function getMetaFromInstance(instance, name, tag) {
|
|
636
627
|
const vars = (0, import_phecda_core2.getExposeKey)(instance).filter((item) => item !== "__CLASS");
|
|
637
628
|
const baseState = (0, import_phecda_core2.getState)(instance, "__CLASS") || {};
|
|
638
629
|
initState(baseState);
|
|
@@ -641,6 +632,7 @@ function getMetaFromInstance(instance, name) {
|
|
|
641
632
|
if (baseState.route && state.route)
|
|
642
633
|
state.route.route = baseState.route.route + state.route.route;
|
|
643
634
|
state.name = name;
|
|
635
|
+
state.tag = tag;
|
|
644
636
|
state.method = i;
|
|
645
637
|
const params = [];
|
|
646
638
|
for (const i2 of state.params || []) {
|
|
@@ -861,50 +853,6 @@ function Header(name, value) {
|
|
|
861
853
|
}
|
|
862
854
|
__name(Header, "Header");
|
|
863
855
|
|
|
864
|
-
// src/vite/index.ts
|
|
865
|
-
var import_path = require("path");
|
|
866
|
-
var import_vite = require("vite");
|
|
867
|
-
function Server(localPath = "pmeta.js") {
|
|
868
|
-
let root;
|
|
869
|
-
let metaPath;
|
|
870
|
-
let command;
|
|
871
|
-
return {
|
|
872
|
-
name: "phecda-server-vite:client",
|
|
873
|
-
enforce: "pre",
|
|
874
|
-
configResolved(config) {
|
|
875
|
-
command = config.command;
|
|
876
|
-
root = config.root || process.cwd();
|
|
877
|
-
metaPath = (0, import_vite.normalizePath)((0, import_path.resolve)(root, localPath));
|
|
878
|
-
},
|
|
879
|
-
buildStart() {
|
|
880
|
-
if (command === "build") {
|
|
881
|
-
this.emitFile({
|
|
882
|
-
type: "chunk",
|
|
883
|
-
id: metaPath,
|
|
884
|
-
fileName: localPath,
|
|
885
|
-
preserveSignature: "allow-extension"
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
},
|
|
889
|
-
resolveId(id) {
|
|
890
|
-
if (id.endsWith(".controller"))
|
|
891
|
-
return metaPath;
|
|
892
|
-
},
|
|
893
|
-
transform(code, id) {
|
|
894
|
-
if (id === metaPath) {
|
|
895
|
-
const meta = JSON.parse(code);
|
|
896
|
-
const compiler = new Pcompiler();
|
|
897
|
-
for (const i of meta)
|
|
898
|
-
compiler.addMethod(i.name, i.method, i.route?.route, i.route?.type, i.params);
|
|
899
|
-
return {
|
|
900
|
-
code: compiler.getContent()
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
__name(Server, "Server");
|
|
907
|
-
|
|
908
856
|
// src/index.ts
|
|
909
857
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
910
858
|
|
|
@@ -1087,7 +1035,6 @@ __name(createMqReq, "createMqReq");
|
|
|
1087
1035
|
Query,
|
|
1088
1036
|
RabbitMqContext,
|
|
1089
1037
|
Route,
|
|
1090
|
-
Server,
|
|
1091
1038
|
ServerContext,
|
|
1092
1039
|
UndefinedException,
|
|
1093
1040
|
ValidateException,
|