phecda-server 1.4.1 → 1.5.1
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-646333e3.d.ts +136 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.ts +22 -44
- package/dist/index.js +70 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -48
- package/dist/index.mjs.map +1 -1
- package/dist/unplugin/esbuild.js +11 -9
- package/dist/unplugin/esbuild.js.map +1 -1
- package/dist/unplugin/esbuild.mjs +11 -9
- package/dist/unplugin/esbuild.mjs.map +1 -1
- package/dist/unplugin/unplugin.js +11 -9
- package/dist/unplugin/unplugin.js.map +1 -1
- package/dist/unplugin/unplugin.mjs +11 -9
- package/dist/unplugin/unplugin.mjs.map +1 -1
- package/dist/unplugin/vite.js +11 -9
- package/dist/unplugin/vite.js.map +1 -1
- package/dist/unplugin/vite.mjs +11 -9
- package/dist/unplugin/vite.mjs.map +1 -1
- package/dist/unplugin/webpack.js +11 -9
- package/dist/unplugin/webpack.js.map +1 -1
- package/dist/unplugin/webpack.mjs +11 -9
- package/dist/unplugin/webpack.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/axios-95842cc3.d.ts +0 -116
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { Request, Response } from 'express';
|
|
3
|
+
import amqplib from 'amqplib';
|
|
4
|
+
import { Events } from 'phecda-core';
|
|
5
|
+
|
|
6
|
+
declare class Meta {
|
|
7
|
+
data: P.Meta;
|
|
8
|
+
handlers: P.Handler[];
|
|
9
|
+
reflect: any[];
|
|
10
|
+
constructor(data: P.Meta, handlers: P.Handler[], reflect: any[]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class HttpException extends Error {
|
|
14
|
+
message: string;
|
|
15
|
+
status: number;
|
|
16
|
+
description: string;
|
|
17
|
+
constructor(message: string, status: number, description?: string);
|
|
18
|
+
get data(): {
|
|
19
|
+
message: string;
|
|
20
|
+
description: string;
|
|
21
|
+
status: number;
|
|
22
|
+
error: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Construct<T = any> = new (...args: any[]) => T;
|
|
27
|
+
interface Emitter {
|
|
28
|
+
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
29
|
+
once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
30
|
+
off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
31
|
+
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
32
|
+
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
33
|
+
}
|
|
34
|
+
type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
35
|
+
type MergeType = <R extends Promise<any>[]>(...args: R) => {
|
|
36
|
+
[K in keyof R]: Awaited<R[K]>;
|
|
37
|
+
};
|
|
38
|
+
interface MqCtx {
|
|
39
|
+
content?: string;
|
|
40
|
+
message?: any;
|
|
41
|
+
channel?: amqplib.Channel;
|
|
42
|
+
}
|
|
43
|
+
interface ServerMergeCtx {
|
|
44
|
+
request: Request;
|
|
45
|
+
response: Response;
|
|
46
|
+
meta: Record<string, Meta>;
|
|
47
|
+
isMerge: true;
|
|
48
|
+
tags?: string[];
|
|
49
|
+
}
|
|
50
|
+
interface ServerCtx {
|
|
51
|
+
request: Request;
|
|
52
|
+
response: Response;
|
|
53
|
+
meta: Meta;
|
|
54
|
+
}
|
|
55
|
+
interface BaseError {
|
|
56
|
+
error: true;
|
|
57
|
+
status: number;
|
|
58
|
+
}
|
|
59
|
+
type ServerFilter<E extends HttpException = any> = (err: E | Error, contextData: ServerMergeCtx | ServerCtx) => any;
|
|
60
|
+
type MQFilter<E extends HttpException = any> = (err: E | Error, contextData: any) => any;
|
|
61
|
+
declare class Base {
|
|
62
|
+
context: ServerMergeCtx | ServerCtx;
|
|
63
|
+
}
|
|
64
|
+
declare namespace P {
|
|
65
|
+
interface Error extends BaseError {
|
|
66
|
+
message: string;
|
|
67
|
+
description: string;
|
|
68
|
+
}
|
|
69
|
+
type ResOrErr<R> = {
|
|
70
|
+
[K in keyof R]: Awaited<R[K]> | Error;
|
|
71
|
+
};
|
|
72
|
+
type Res<T> = T;
|
|
73
|
+
type Guard = ((contextData: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((contextData: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean);
|
|
74
|
+
type Interceptor = ((contextData: ServerCtx, isMerge?: false) => any) | ((contextData: ServerMergeCtx, isMerge?: true) => any);
|
|
75
|
+
interface Handler {
|
|
76
|
+
error?: (arg: any) => void;
|
|
77
|
+
}
|
|
78
|
+
interface Meta {
|
|
79
|
+
route?: {
|
|
80
|
+
type: RequestType;
|
|
81
|
+
route: string;
|
|
82
|
+
};
|
|
83
|
+
mq?: {
|
|
84
|
+
queue: string;
|
|
85
|
+
routeKey: string;
|
|
86
|
+
options: amqplib.Options.Consume;
|
|
87
|
+
};
|
|
88
|
+
define?: any;
|
|
89
|
+
header: Record<string, string>;
|
|
90
|
+
params: {
|
|
91
|
+
type: string;
|
|
92
|
+
index: number;
|
|
93
|
+
key: string;
|
|
94
|
+
validate?: boolean;
|
|
95
|
+
}[];
|
|
96
|
+
guards: string[];
|
|
97
|
+
interceptors: string[];
|
|
98
|
+
middlewares: string[];
|
|
99
|
+
method: string;
|
|
100
|
+
name: string;
|
|
101
|
+
tag: string;
|
|
102
|
+
}
|
|
103
|
+
interface Pipe {
|
|
104
|
+
transform(args: {
|
|
105
|
+
arg: any;
|
|
106
|
+
validate?: boolean;
|
|
107
|
+
}[], reflect: any[]): Promise<any[]>;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface RequestArgs {
|
|
112
|
+
body: Record<string, any>;
|
|
113
|
+
query: Record<string, string>;
|
|
114
|
+
params: Record<string, string>;
|
|
115
|
+
realParam: string;
|
|
116
|
+
method: RequestType;
|
|
117
|
+
url: string;
|
|
118
|
+
tag: string;
|
|
119
|
+
}
|
|
120
|
+
type MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag'>;
|
|
121
|
+
declare function toReq(arg: RequestArgs): {
|
|
122
|
+
method: RequestType;
|
|
123
|
+
url: string;
|
|
124
|
+
body: Record<string, any>;
|
|
125
|
+
query: string;
|
|
126
|
+
params: string;
|
|
127
|
+
};
|
|
128
|
+
declare const merge: (...args: RequestArgs[]) => MergedReqArg[];
|
|
129
|
+
type RequestMethod = <F extends (...args: any[]) => any>(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>;
|
|
130
|
+
declare function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<P.Res<Awaited<R>>>>;
|
|
131
|
+
declare function createSeriesReq(instance: AxiosInstance, key?: string): <R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<P.ResOrErr<P.Res<R>>>>;
|
|
132
|
+
declare function createParallelReq(instance: AxiosInstance, key?: string): <R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<P.ResOrErr<P.Res<R>>>>;
|
|
133
|
+
declare function isError<T = any>(data: T | P.Error): data is P.Error;
|
|
134
|
+
declare function $S(index: number, key?: string): any;
|
|
135
|
+
|
|
136
|
+
export { $S as $, BaseError as B, Construct as C, Emitter as E, HttpException as H, Meta as M, P, RequestType as R, ServerCtx as S, ServerMergeCtx as a, ServerFilter as b, MQFilter as c, MergeType as d, MqCtx as e, Base as f, RequestMethod as g, createReq as h, createSeriesReq as i, createParallelReq as j, isError as k, merge as m, toReq as t };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $ as $S,
|
|
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-646333e3.js';
|
|
2
2
|
import 'axios';
|
|
3
3
|
import 'express';
|
|
4
4
|
import 'amqplib';
|
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\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 MERGE_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type {
|
|
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 MERGE_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { P, RequestType } 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<P.Res<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<P.ResOrErr<P.Res<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<P.ResOrErr<P.Res<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 | P.Error): data is P.Error {\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,UAAiH;AAEzI,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,sBAAoI;AAEjM,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,sBAAoI;AAEnM,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,MAAoC;AACnE,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"]}
|
|
@@ -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 MERGE_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/common.ts","../../src/client/axios.ts","../../src/client/index.ts"],"sourcesContent":["export const SERIES_SYMBOL = '__symbol_series__'\nexport const MERGE_SYMBOL = '__symbol_req__'\n","import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport type { P, RequestType } 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<P.Res<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<P.ResOrErr<P.Res<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<P.ResOrErr<P.Res<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 | P.Error): data is P.Error {\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,UAAiH;AAEzI,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,sBAAoI;AAEjM,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,sBAAoI;AAEnM,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,MAAoC;AACnE,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,31 +1,10 @@
|
|
|
1
1
|
import { RequestHandler, Express } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
export { $ as $S,
|
|
2
|
+
import { H as HttpException, M as Meta, P, S as ServerCtx, a as ServerMergeCtx, b as ServerFilter, c as MQFilter, E as Emitter } from './axios-646333e3.js';
|
|
3
|
+
export { $ as $S, f as Base, B as BaseError, C as Construct, d as MergeType, e as MqCtx, g as RequestMethod, R as RequestType, j as createParallelReq, h as createReq, i as createSeriesReq, k as isError, m as merge, t as toReq } from './axios-646333e3.js';
|
|
4
4
|
export * from 'phecda-core';
|
|
5
5
|
import amqplib from 'amqplib';
|
|
6
6
|
import 'axios';
|
|
7
7
|
|
|
8
|
-
interface ValidatePipe {
|
|
9
|
-
transform(args: {
|
|
10
|
-
arg: any;
|
|
11
|
-
validate?: boolean;
|
|
12
|
-
}[], reflect: any[]): Promise<any[]>;
|
|
13
|
-
}
|
|
14
|
-
declare const defaultPipe: ValidatePipe;
|
|
15
|
-
|
|
16
|
-
declare class HttpException extends Error {
|
|
17
|
-
message: string;
|
|
18
|
-
status: number;
|
|
19
|
-
description: string;
|
|
20
|
-
constructor(message: string, status: number, description?: string);
|
|
21
|
-
get data(): {
|
|
22
|
-
message: string;
|
|
23
|
-
description: string;
|
|
24
|
-
status: number;
|
|
25
|
-
error: boolean;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
8
|
declare class UndefinedException extends HttpException {
|
|
30
9
|
constructor(message: string);
|
|
31
10
|
}
|
|
@@ -82,25 +61,22 @@ declare class FrameworkException extends HttpException {
|
|
|
82
61
|
constructor(message: string);
|
|
83
62
|
}
|
|
84
63
|
|
|
85
|
-
type ServerFilter<E extends HttpException = any> = (err: E | Error, contextData: ServerMergeCtx | ServerCtx) => any;
|
|
86
|
-
type MQFilter<E extends HttpException = any> = (err: E | Error, contextData: any) => any;
|
|
87
|
-
|
|
88
64
|
declare class Phistroy {
|
|
89
65
|
guard: string[];
|
|
90
66
|
interceptor: string[];
|
|
91
67
|
record(name: string, type: 'guard' | 'interceptor'): boolean;
|
|
92
68
|
}
|
|
93
69
|
|
|
94
|
-
declare abstract class
|
|
70
|
+
declare abstract class Context<Data = any> {
|
|
95
71
|
key: string;
|
|
96
72
|
data: Data;
|
|
97
73
|
method: string;
|
|
98
74
|
params: string[];
|
|
99
|
-
static metaRecord: Record<string,
|
|
75
|
+
static metaRecord: Record<string, Meta>;
|
|
100
76
|
static metaDataRecord: Record<string, ReturnType<typeof parseMeta>>;
|
|
101
77
|
static instanceRecord: Record<string, any>;
|
|
102
|
-
static guardsRecord: Record<string,
|
|
103
|
-
static interceptorsRecord: Record<string,
|
|
78
|
+
static guardsRecord: Record<string, any>;
|
|
79
|
+
static interceptorsRecord: Record<string, any>;
|
|
104
80
|
post: ((...params: any) => any)[];
|
|
105
81
|
history: Phistroy;
|
|
106
82
|
constructor(key: string, data: Data);
|
|
@@ -110,10 +86,10 @@ declare abstract class Pcontext<Data = any> {
|
|
|
110
86
|
useInterceptor(interceptors: string[], isMerge?: boolean): Promise<void>;
|
|
111
87
|
usePost(data: any): Promise<any>;
|
|
112
88
|
}
|
|
113
|
-
declare function addGuard(key: string, handler:
|
|
114
|
-
declare function addInterceptor(key: string, handler:
|
|
89
|
+
declare function addGuard(key: string, handler: P.Guard): void;
|
|
90
|
+
declare function addInterceptor(key: string, handler: P.Interceptor): void;
|
|
115
91
|
declare function getInstance(tag: string): any;
|
|
116
|
-
declare function parseMeta(meta:
|
|
92
|
+
declare function parseMeta(meta: Meta): {
|
|
117
93
|
guards: string[];
|
|
118
94
|
reflect: any[];
|
|
119
95
|
interceptors: string[];
|
|
@@ -125,8 +101,8 @@ declare function parseMeta(meta: Pmeta): {
|
|
|
125
101
|
}[];
|
|
126
102
|
};
|
|
127
103
|
|
|
128
|
-
declare class ServerContext extends
|
|
129
|
-
static pipe:
|
|
104
|
+
declare class ServerContext extends Context<ServerCtx | ServerMergeCtx> {
|
|
105
|
+
static pipe: P.Pipe;
|
|
130
106
|
static filter: ServerFilter<any>;
|
|
131
107
|
static middlewareRecord: Record<string, (...params: any) => any>;
|
|
132
108
|
static useMiddleware(middlewares: string[]): ((...params: any) => any)[];
|
|
@@ -138,11 +114,11 @@ declare class ServerContext extends Pcontext<ServerCtx | ServerMergeCtx> {
|
|
|
138
114
|
useFilter(arg: any): any;
|
|
139
115
|
}
|
|
140
116
|
declare function addMiddleware(key: string, handler: RequestHandler): void;
|
|
141
|
-
declare function useServerPipe(pipe:
|
|
117
|
+
declare function useServerPipe(pipe: P.Pipe): void;
|
|
142
118
|
declare function useServerFilter(filter: ServerFilter): void;
|
|
143
119
|
|
|
144
|
-
declare class RabbitMqContext extends
|
|
145
|
-
static pipe:
|
|
120
|
+
declare class RabbitMqContext extends Context {
|
|
121
|
+
static pipe: P.Pipe;
|
|
146
122
|
static filter: MQFilter<any>;
|
|
147
123
|
static middlewareRecord: Record<string, (...params: any) => boolean>;
|
|
148
124
|
static useMiddleware(middlewares: string[]): ((...params: any) => boolean)[];
|
|
@@ -153,10 +129,10 @@ declare class RabbitMqContext extends Pcontext {
|
|
|
153
129
|
static useFilter(arg: any, data: MQFilter): any;
|
|
154
130
|
useFilter(arg: any): any;
|
|
155
131
|
}
|
|
156
|
-
declare function useMqPipe(pipe:
|
|
132
|
+
declare function useMqPipe(pipe: P.Pipe): void;
|
|
157
133
|
declare function useMqFilter(filter: MQFilter): void;
|
|
158
134
|
|
|
159
|
-
declare class
|
|
135
|
+
declare class Compiler {
|
|
160
136
|
classMap: Record<string, {
|
|
161
137
|
[key: string]: string;
|
|
162
138
|
}>;
|
|
@@ -164,13 +140,13 @@ declare class Pcompiler {
|
|
|
164
140
|
constructor();
|
|
165
141
|
getContent(): string;
|
|
166
142
|
createRequest(): string;
|
|
167
|
-
addMethod(args:
|
|
143
|
+
addMethod(args: P.Meta): void;
|
|
168
144
|
}
|
|
169
145
|
|
|
170
146
|
declare const emitter: Emitter;
|
|
171
147
|
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
|
|
172
148
|
moduleMap: Map<string, any>;
|
|
173
|
-
meta:
|
|
149
|
+
meta: Meta[];
|
|
174
150
|
output: (p?: string) => void;
|
|
175
151
|
}>;
|
|
176
152
|
|
|
@@ -201,7 +177,9 @@ declare function MQ(queue: string, routeKey: string, options?: amqplib.Options.C
|
|
|
201
177
|
|
|
202
178
|
declare function Inject(_target: any): void;
|
|
203
179
|
declare function Header(name: string, value: string): (target: any, k: PropertyKey) => void;
|
|
204
|
-
declare function
|
|
180
|
+
declare function Define(key: string, value: any): (target: any, k?: PropertyKey) => void;
|
|
181
|
+
|
|
182
|
+
declare const defaultPipe: P.Pipe;
|
|
205
183
|
|
|
206
184
|
declare function bindMQ(ch: amqplib.Channel, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>): Promise<void>;
|
|
207
185
|
type MqMethod<T> = (arg: T) => void;
|
|
@@ -209,4 +187,4 @@ declare function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channe
|
|
|
209
187
|
|
|
210
188
|
declare function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void>;
|
|
211
189
|
|
|
212
|
-
export { BadGatewayException, BadRequestException, BaseParam, Body, ConflictException, Controller, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Inject, Interceptor, InvalidInputException, MQ, Meta, Middle, NotFoundException, Options, Param, PayloadLargeException,
|
|
190
|
+
export { BadGatewayException, BadRequestException, BaseParam, Body, Compiler, ConflictException, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Inject, Interceptor, InvalidInputException, MQ, MQFilter, Meta, Middle, NotFoundException, Options, P, Param, PayloadLargeException, Post, Put, Query, RabbitMqContext, Route, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, bindMQ, createMqReq, createPub, defaultPipe, emitter, getInstance, parseMeta, useMqFilter, useMqPipe, useServerFilter, useServerPipe };
|