phecda-server 1.2.4 → 1.4.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-95842cc3.d.ts} +31 -19
- 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 +58 -38
- package/dist/index.js +169 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -63
- 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 +4 -3
- package/template/jwt.guard.art +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import amqplib from 'amqplib';
|
|
4
|
-
import {
|
|
4
|
+
import { Events } from 'phecda-core';
|
|
5
5
|
|
|
6
|
-
declare class
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
declare class Pmeta {
|
|
7
|
+
data: ServerMeta;
|
|
8
|
+
handlers: PHandler[];
|
|
9
|
+
reflect: any[];
|
|
10
|
+
constructor(data: ServerMeta, handlers: PHandler[], reflect: any[]);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
type Construct<T = any> = new (...args: any[]) => T;
|
|
14
|
-
interface
|
|
15
|
-
on<N extends keyof
|
|
16
|
-
once<N extends keyof
|
|
17
|
-
off<N extends keyof
|
|
18
|
-
removeAllListeners<N extends keyof
|
|
19
|
-
emit<N extends keyof
|
|
14
|
+
interface Emitter {
|
|
15
|
+
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
16
|
+
once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
17
|
+
off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
18
|
+
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
19
|
+
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
20
20
|
}
|
|
21
21
|
interface PHandler {
|
|
22
22
|
error?: (arg: any) => void;
|
|
@@ -31,6 +31,7 @@ interface ServerMeta {
|
|
|
31
31
|
routeKey: string;
|
|
32
32
|
options: amqplib.Options.Consume;
|
|
33
33
|
};
|
|
34
|
+
meta?: any;
|
|
34
35
|
header: Record<string, string>;
|
|
35
36
|
params: {
|
|
36
37
|
type: string;
|
|
@@ -43,6 +44,7 @@ interface ServerMeta {
|
|
|
43
44
|
middlewares: string[];
|
|
44
45
|
method: string;
|
|
45
46
|
name: string;
|
|
47
|
+
tag: string;
|
|
46
48
|
}
|
|
47
49
|
type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
48
50
|
type MergeType = <R extends Promise<any>[]>(...args: R) => {
|
|
@@ -60,12 +62,6 @@ type ResOrErr<R> = {
|
|
|
60
62
|
[K in keyof R]: Awaited<R[K]> | PError;
|
|
61
63
|
};
|
|
62
64
|
type PRes<T> = T;
|
|
63
|
-
type UnWrap<T extends any[]> = {
|
|
64
|
-
[K in keyof T]: T[K] extends Wrap<infer F, infer _> ? F : T[K];
|
|
65
|
-
};
|
|
66
|
-
type Transform<A> = {
|
|
67
|
-
[K in keyof A]: A[K] extends (...args: infer P) => infer R ? (...args: UnWrap<P> extends unknown[] ? UnWrap<P> : unknown[]) => R : never;
|
|
68
|
-
};
|
|
69
65
|
interface ServerContextData {
|
|
70
66
|
request?: Request<any, any, any, any, Record<string, any>>;
|
|
71
67
|
response?: Response<any, Record<string, any>>;
|
|
@@ -75,6 +71,22 @@ interface MqContextData {
|
|
|
75
71
|
message?: any;
|
|
76
72
|
channel?: amqplib.Channel;
|
|
77
73
|
}
|
|
74
|
+
interface ServerMergeCtx {
|
|
75
|
+
request: Request;
|
|
76
|
+
response: Response;
|
|
77
|
+
meta: Record<string, Pmeta>;
|
|
78
|
+
tags?: string[];
|
|
79
|
+
}
|
|
80
|
+
interface ServerCtx {
|
|
81
|
+
request: Request;
|
|
82
|
+
response: Response;
|
|
83
|
+
meta: Pmeta;
|
|
84
|
+
}
|
|
85
|
+
declare class Base {
|
|
86
|
+
context: ServerMergeCtx | ServerCtx;
|
|
87
|
+
}
|
|
88
|
+
type Pguard = ((contextData: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((contextData: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean);
|
|
89
|
+
type Pinterceptor = ((contextData: ServerCtx, isMerge?: false) => any) | ((contextData: ServerMergeCtx, isMerge?: true) => any);
|
|
78
90
|
|
|
79
91
|
interface RequestArgs {
|
|
80
92
|
body: Record<string, any>;
|
|
@@ -101,4 +113,4 @@ declare function createParallelReq(instance: AxiosInstance, key?: string): <R ex
|
|
|
101
113
|
declare function isError<T = any>(data: T | PError): data is PError;
|
|
102
114
|
declare function $S(index: number, key?: string): any;
|
|
103
115
|
|
|
104
|
-
export { $S as $, BaseError as B, Construct as C, MergeType as M,
|
|
116
|
+
export { $S as $, BaseError as B, Construct as C, Emitter as E, MergeType as M, Pmeta as P, RequestType as R, ServerMergeCtx as S, ServerCtx as a, Pguard as b, Pinterceptor as c, ServerMeta as d, PHandler as e, PError as f, ResOrErr as g, PRes as h, ServerContextData as i, MqContextData as j, Base as k, RequestMethod as l, merge as m, createReq as n, createSeriesReq as o, createParallelReq as p, isError as q, toReq as t };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { $ as $S,
|
|
1
|
+
export { $ as $S, l as RequestMethod, p as createParallelReq, n as createReq, o as createSeriesReq, q as isError, m as merge, t as toReq } from '../axios-95842cc3.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
|
|
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 { 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,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S,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
|
|
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 { 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,KA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","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,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { RequestHandler, Express } from 'express';
|
|
2
|
+
import { S as ServerMergeCtx, a as ServerCtx, P as Pmeta, b as Pguard, c as Pinterceptor, d as ServerMeta, E as Emitter } from './axios-95842cc3.js';
|
|
3
|
+
export { $ as $S, k as Base, B as BaseError, C as Construct, M as MergeType, j as MqContextData, f as PError, e as PHandler, h as PRes, l as RequestMethod, R as RequestType, g as ResOrErr, i as ServerContextData, p as createParallelReq, n as createReq, o as createSeriesReq, q as isError, m as merge, t as toReq } from './axios-95842cc3.js';
|
|
4
4
|
export * from 'phecda-core';
|
|
5
5
|
import amqplib from 'amqplib';
|
|
6
6
|
import 'axios';
|
|
@@ -42,15 +42,48 @@ declare class BadRequestException extends HttpException {
|
|
|
42
42
|
constructor(message: string);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
declare class
|
|
45
|
+
declare class NotFoundException extends HttpException {
|
|
46
46
|
constructor(message: string);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
declare class
|
|
49
|
+
declare class ConflictException extends HttpException {
|
|
50
50
|
constructor(message: string);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
declare class BadGatewayException extends HttpException {
|
|
54
|
+
constructor(message: string);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare class InvalidInputException extends HttpException {
|
|
58
|
+
constructor(message: string);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare class UnsupportedMediaTypeException extends HttpException {
|
|
62
|
+
constructor(message: string);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare class PayloadLargeException extends HttpException {
|
|
66
|
+
constructor(message: string);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare class TimeoutException extends HttpException {
|
|
70
|
+
constructor(message: string);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class UnauthorizedException extends HttpException {
|
|
74
|
+
constructor(message: string);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare class ServiceUnavailableException extends HttpException {
|
|
78
|
+
constructor(message: string);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare class FrameworkException extends HttpException {
|
|
82
|
+
constructor(message: string);
|
|
83
|
+
}
|
|
84
|
+
|
|
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;
|
|
54
87
|
|
|
55
88
|
declare class Phistroy {
|
|
56
89
|
guard: string[];
|
|
@@ -58,16 +91,9 @@ declare class Phistroy {
|
|
|
58
91
|
record(name: string, type: 'guard' | 'interceptor'): boolean;
|
|
59
92
|
}
|
|
60
93
|
|
|
61
|
-
declare class
|
|
62
|
-
data: ServerMeta;
|
|
63
|
-
handlers: PHandler[];
|
|
64
|
-
reflect: any[];
|
|
65
|
-
constructor(data: ServerMeta, handlers: PHandler[], reflect: any[]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
declare abstract class Pcontext {
|
|
94
|
+
declare abstract class Pcontext<Data = any> {
|
|
69
95
|
key: string;
|
|
70
|
-
data:
|
|
96
|
+
data: Data;
|
|
71
97
|
method: string;
|
|
72
98
|
params: string[];
|
|
73
99
|
static metaRecord: Record<string, Pmeta>;
|
|
@@ -77,15 +103,15 @@ declare abstract class Pcontext {
|
|
|
77
103
|
static interceptorsRecord: Record<string, (req: any, isMerge: boolean) => any>;
|
|
78
104
|
post: ((...params: any) => any)[];
|
|
79
105
|
history: Phistroy;
|
|
80
|
-
constructor(key: string, data:
|
|
106
|
+
constructor(key: string, data: Data);
|
|
81
107
|
static registerGuard(key: string, handler: any): void;
|
|
82
108
|
static registerInterceptor(key: string, handler: any): void;
|
|
83
109
|
useGuard(guards: string[], isMerge?: boolean): Promise<void>;
|
|
84
110
|
useInterceptor(interceptors: string[], isMerge?: boolean): Promise<void>;
|
|
85
111
|
usePost(data: any): Promise<any>;
|
|
86
112
|
}
|
|
87
|
-
declare function addGuard(key: string, handler:
|
|
88
|
-
declare function addInterceptor(key: string, handler:
|
|
113
|
+
declare function addGuard(key: string, handler: Pguard): void;
|
|
114
|
+
declare function addInterceptor(key: string, handler: Pinterceptor): void;
|
|
89
115
|
declare function getInstance(tag: string): any;
|
|
90
116
|
declare function parseMeta(meta: Pmeta): {
|
|
91
117
|
guards: string[];
|
|
@@ -99,34 +125,36 @@ declare function parseMeta(meta: Pmeta): {
|
|
|
99
125
|
}[];
|
|
100
126
|
};
|
|
101
127
|
|
|
102
|
-
declare class ServerContext extends Pcontext {
|
|
128
|
+
declare class ServerContext extends Pcontext<ServerCtx | ServerMergeCtx> {
|
|
103
129
|
static pipe: ValidatePipe;
|
|
104
|
-
static filter:
|
|
130
|
+
static filter: ServerFilter<any>;
|
|
105
131
|
static middlewareRecord: Record<string, (...params: any) => any>;
|
|
106
132
|
static useMiddleware(middlewares: string[]): ((...params: any) => any)[];
|
|
107
133
|
usePipe(args: {
|
|
108
134
|
arg: any;
|
|
109
135
|
validate?: boolean;
|
|
110
136
|
}[], reflect: any[]): Promise<any[]>;
|
|
137
|
+
static useFilter(arg: any, data: ServerCtx | ServerMergeCtx): any;
|
|
111
138
|
useFilter(arg: any): any;
|
|
112
139
|
}
|
|
113
|
-
declare function addMiddleware(key: string, handler:
|
|
140
|
+
declare function addMiddleware(key: string, handler: RequestHandler): void;
|
|
114
141
|
declare function useServerPipe(pipe: ValidatePipe): void;
|
|
115
|
-
declare function useServerFilter(filter:
|
|
142
|
+
declare function useServerFilter(filter: ServerFilter): void;
|
|
116
143
|
|
|
117
144
|
declare class RabbitMqContext extends Pcontext {
|
|
118
145
|
static pipe: ValidatePipe;
|
|
119
|
-
static filter:
|
|
146
|
+
static filter: MQFilter<any>;
|
|
120
147
|
static middlewareRecord: Record<string, (...params: any) => boolean>;
|
|
121
148
|
static useMiddleware(middlewares: string[]): ((...params: any) => boolean)[];
|
|
122
149
|
usePipe(args: {
|
|
123
150
|
arg: any;
|
|
124
151
|
validate?: boolean;
|
|
125
152
|
}[], reflect: any[]): Promise<any[]>;
|
|
153
|
+
static useFilter(arg: any, data: MQFilter): any;
|
|
126
154
|
useFilter(arg: any): any;
|
|
127
155
|
}
|
|
128
156
|
declare function useMqPipe(pipe: ValidatePipe): void;
|
|
129
|
-
declare function useMqFilter(filter:
|
|
157
|
+
declare function useMqFilter(filter: MQFilter): void;
|
|
130
158
|
|
|
131
159
|
declare class Pcompiler {
|
|
132
160
|
content: string;
|
|
@@ -135,23 +163,14 @@ declare class Pcompiler {
|
|
|
135
163
|
}>;
|
|
136
164
|
constructor();
|
|
137
165
|
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;
|
|
166
|
+
addMethod(args: ServerMeta): void;
|
|
148
167
|
}
|
|
149
168
|
|
|
150
|
-
declare const emitter:
|
|
151
|
-
declare function Factory
|
|
169
|
+
declare const emitter: Emitter;
|
|
170
|
+
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
|
|
152
171
|
moduleMap: Map<string, any>;
|
|
153
172
|
meta: Pmeta[];
|
|
154
|
-
output: (p
|
|
173
|
+
output: (p?: string) => void;
|
|
155
174
|
}>;
|
|
156
175
|
|
|
157
176
|
interface Options {
|
|
@@ -181,6 +200,7 @@ declare function MQ(queue: string, routeKey: string, options?: amqplib.Options.C
|
|
|
181
200
|
|
|
182
201
|
declare function Inject(_target: any): void;
|
|
183
202
|
declare function Header(name: string, value: string): (target: any, k: PropertyKey) => void;
|
|
203
|
+
declare function Meta(key: string, value: any): (target: any, k: PropertyKey) => void;
|
|
184
204
|
|
|
185
205
|
declare function bindMQ(ch: amqplib.Channel, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>): Promise<void>;
|
|
186
206
|
type MqMethod<T> = (arg: T) => void;
|
|
@@ -188,4 +208,4 @@ declare function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channe
|
|
|
188
208
|
|
|
189
209
|
declare function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void>;
|
|
190
210
|
|
|
191
|
-
export { BadRequestException, BaseParam, Body,
|
|
211
|
+
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, Pcompiler, Pcontext, Pguard, Pinterceptor, Pmeta, Post, Put, Query, RabbitMqContext, Route, ServerContext, ServerCtx, ServerMergeCtx, ServerMeta, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, ValidatePipe, addGuard, addInterceptor, addMiddleware, bindApp, bindMQ, createMqReq, createPub, defaultPipe, emitter, getInstance, parseMeta, useMqFilter, useMqPipe, useServerFilter, useServerPipe };
|