phecda-server 1.2.4 → 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 -16
- package/dist/index.js +32 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -40
- package/dist/index.mjs.map +1 -1
- package/dist/unplugin/esbuild.js +11 -23
- package/dist/unplugin/esbuild.js.map +1 -1
- package/dist/unplugin/esbuild.mjs +11 -23
- package/dist/unplugin/esbuild.mjs.map +1 -1
- package/dist/unplugin/unplugin.js +11 -23
- package/dist/unplugin/unplugin.js.map +1 -1
- package/dist/unplugin/unplugin.mjs +11 -23
- package/dist/unplugin/unplugin.mjs.map +1 -1
- package/dist/unplugin/vite.js +11 -23
- package/dist/unplugin/vite.js.map +1 -1
- package/dist/unplugin/vite.mjs +11 -23
- package/dist/unplugin/vite.mjs.map +1 -1
- package/dist/unplugin/webpack.js +11 -23
- package/dist/unplugin/webpack.js.map +1 -1
- package/dist/unplugin/webpack.mjs +11 -23
- package/dist/unplugin/webpack.mjs.map +1 -1
- package/package.json +2 -2
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,5 +1,5 @@
|
|
|
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
4
|
export * from 'phecda-core';
|
|
5
5
|
import amqplib from 'amqplib';
|
|
@@ -84,7 +84,7 @@ declare abstract class Pcontext {
|
|
|
84
84
|
useInterceptor(interceptors: string[], isMerge?: boolean): Promise<void>;
|
|
85
85
|
usePost(data: any): Promise<any>;
|
|
86
86
|
}
|
|
87
|
-
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;
|
|
88
88
|
declare function addInterceptor(key: string, handler: (contextData: any, isMerge: boolean) => any): void;
|
|
89
89
|
declare function getInstance(tag: string): any;
|
|
90
90
|
declare function parseMeta(meta: Pmeta): {
|
|
@@ -135,23 +135,14 @@ declare class Pcompiler {
|
|
|
135
135
|
}>;
|
|
136
136
|
constructor();
|
|
137
137
|
getContent(): string;
|
|
138
|
-
addMethod(
|
|
139
|
-
type: string;
|
|
140
|
-
key: string;
|
|
141
|
-
index: number;
|
|
142
|
-
}[]): void;
|
|
143
|
-
addMqMethod(className: string, methodName: string, exchange?: string, routeKey?: string, queue?: string, params?: {
|
|
144
|
-
type: string;
|
|
145
|
-
key: string;
|
|
146
|
-
index: number;
|
|
147
|
-
}[]): void;
|
|
138
|
+
addMethod(args: ServerMeta): void;
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
declare const emitter: PhecdaEmitter;
|
|
151
|
-
declare function Factory
|
|
142
|
+
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
|
|
152
143
|
moduleMap: Map<string, any>;
|
|
153
144
|
meta: Pmeta[];
|
|
154
|
-
output: (p
|
|
145
|
+
output: (p?: string) => void;
|
|
155
146
|
}>;
|
|
156
147
|
|
|
157
148
|
interface Options {
|
|
@@ -188,4 +179,4 @@ declare function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channe
|
|
|
188
179
|
|
|
189
180
|
declare function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void>;
|
|
190
181
|
|
|
191
|
-
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
|
@@ -136,6 +136,8 @@ var defaultPipe = {
|
|
|
136
136
|
args[i].arg = ret.data;
|
|
137
137
|
} else {
|
|
138
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`);
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
143
|
return args.map((item) => item.arg);
|
|
@@ -375,28 +377,17 @@ var Pcompiler = class {
|
|
|
375
377
|
}
|
|
376
378
|
return content;
|
|
377
379
|
}
|
|
378
|
-
addMethod(
|
|
380
|
+
addMethod(args) {
|
|
381
|
+
const { route: { route = "/", type = "get" } = {}, name, method, params, tag } = args;
|
|
379
382
|
const url = route.replace(/\/\:([^\/]*)/g, "");
|
|
380
|
-
if (!this.classMap[
|
|
381
|
-
this.classMap[
|
|
382
|
-
this.classMap[
|
|
383
|
-
${
|
|
384
|
-
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}"}
|
|
385
388
|
${params.filter((item) => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}
|
|
386
389
|
${c.type === "params" ? `ret.realParam+='/'+arg${i}
|
|
387
390
|
` : ""}`, "")}
|
|
388
|
-
return ret
|
|
389
|
-
}
|
|
390
|
-
`;
|
|
391
|
-
}
|
|
392
|
-
addMqMethod(className, methodName, exchange = "", routeKey = "", queue = "", params = []) {
|
|
393
|
-
if (!this.classMap[className])
|
|
394
|
-
this.classMap[className] = {};
|
|
395
|
-
this.classMap[className][methodName] = `
|
|
396
|
-
${methodName}(${genParams(params)}){
|
|
397
|
-
const ret={tag:"${className}-${methodName}",exchange:"${exchange}",routeKey:"${routeKey}",queue:"${queue}",args:{}}
|
|
398
|
-
${params.reduce((p, c, i) => `${p}ret.args.${c.key}=arg${i}
|
|
399
|
-
`, "")}
|
|
400
391
|
return ret
|
|
401
392
|
}
|
|
402
393
|
`;
|
|
@@ -404,10 +395,9 @@ return ret
|
|
|
404
395
|
};
|
|
405
396
|
__name(Pcompiler, "Pcompiler");
|
|
406
397
|
function genParams(decorators) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}, "");
|
|
398
|
+
return decorators.map((_, i) => {
|
|
399
|
+
return `${`arg${i}`}`;
|
|
400
|
+
}).join(",");
|
|
411
401
|
}
|
|
412
402
|
__name(genParams, "genParams");
|
|
413
403
|
|
|
@@ -437,11 +427,11 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
437
427
|
};
|
|
438
428
|
const methodMap = {};
|
|
439
429
|
for (const i of meta) {
|
|
440
|
-
const { name, method, route: route2, header } = i.data;
|
|
441
|
-
const instance = moduleMap.get(
|
|
442
|
-
const
|
|
443
|
-
Pcontext.metaRecord[
|
|
444
|
-
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);
|
|
445
435
|
guards = [
|
|
446
436
|
...globalGuards,
|
|
447
437
|
...guards
|
|
@@ -451,16 +441,16 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
451
441
|
...interceptors
|
|
452
442
|
];
|
|
453
443
|
const handler = instance[method].bind(instance);
|
|
454
|
-
methodMap[
|
|
444
|
+
methodMap[methodTag] = handler;
|
|
455
445
|
Pcontext.instanceRecord[name] = instance;
|
|
456
446
|
if (route2) {
|
|
457
447
|
app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
|
|
458
448
|
const contextData = {
|
|
459
449
|
request: req,
|
|
460
|
-
|
|
450
|
+
methodTag,
|
|
461
451
|
response: res
|
|
462
452
|
};
|
|
463
|
-
const context = new ServerContext(
|
|
453
|
+
const context = new ServerContext(methodTag, contextData);
|
|
464
454
|
try {
|
|
465
455
|
for (const name2 in header)
|
|
466
456
|
res.set(name2, header[name2]);
|
|
@@ -604,35 +594,36 @@ async function Factory(Modules) {
|
|
|
604
594
|
return {
|
|
605
595
|
moduleMap,
|
|
606
596
|
meta,
|
|
607
|
-
output: (p) => import_fs.default.writeFileSync(p, JSON.stringify(meta.map((item) => item.data)))
|
|
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 || []) {
|