phecda-server 1.3.0 → 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-d8ab1187.d.ts → axios-95842cc3.d.ts} +30 -19
- 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 +55 -26
- package/dist/index.js +138 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -24
- package/dist/index.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;
|
|
@@ -61,12 +62,6 @@ type ResOrErr<R> = {
|
|
|
61
62
|
[K in keyof R]: Awaited<R[K]> | PError;
|
|
62
63
|
};
|
|
63
64
|
type PRes<T> = T;
|
|
64
|
-
type UnWrap<T extends any[]> = {
|
|
65
|
-
[K in keyof T]: T[K] extends Wrap<infer F, infer _> ? F : T[K];
|
|
66
|
-
};
|
|
67
|
-
type Transform<A> = {
|
|
68
|
-
[K in keyof A]: A[K] extends (...args: infer P) => infer R ? (...args: UnWrap<P> extends unknown[] ? UnWrap<P> : unknown[]) => R : never;
|
|
69
|
-
};
|
|
70
65
|
interface ServerContextData {
|
|
71
66
|
request?: Request<any, any, any, any, Record<string, any>>;
|
|
72
67
|
response?: Response<any, Record<string, any>>;
|
|
@@ -76,6 +71,22 @@ interface MqContextData {
|
|
|
76
71
|
message?: any;
|
|
77
72
|
channel?: amqplib.Channel;
|
|
78
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);
|
|
79
90
|
|
|
80
91
|
interface RequestArgs {
|
|
81
92
|
body: Record<string, any>;
|
|
@@ -102,4 +113,4 @@ declare function createParallelReq(instance: AxiosInstance, key?: string): <R ex
|
|
|
102
113
|
declare function isError<T = any>(data: T | PError): data is PError;
|
|
103
114
|
declare function $S(index: number, key?: string): any;
|
|
104
115
|
|
|
105
|
-
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,4 +1,4 @@
|
|
|
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';
|
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
|
|
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,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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;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
|
|
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,GA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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,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
|
+
constructor(message: string);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare class BadGatewayException extends HttpException {
|
|
50
54
|
constructor(message: string);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
|
|
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;
|
|
@@ -138,7 +166,7 @@ declare class Pcompiler {
|
|
|
138
166
|
addMethod(args: ServerMeta): void;
|
|
139
167
|
}
|
|
140
168
|
|
|
141
|
-
declare const emitter:
|
|
169
|
+
declare const emitter: Emitter;
|
|
142
170
|
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
|
|
143
171
|
moduleMap: Map<string, any>;
|
|
144
172
|
meta: Pmeta[];
|
|
@@ -172,6 +200,7 @@ declare function MQ(queue: string, routeKey: string, options?: amqplib.Options.C
|
|
|
172
200
|
|
|
173
201
|
declare function Inject(_target: any): void;
|
|
174
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;
|
|
175
204
|
|
|
176
205
|
declare function bindMQ(ch: amqplib.Channel, { meta, moduleMap }: Awaited<ReturnType<typeof Factory>>): Promise<void>;
|
|
177
206
|
type MqMethod<T> = (arg: T) => void;
|
|
@@ -179,4 +208,4 @@ declare function createPub<T extends (...args: any[]) => any>(ch: amqplib.Channe
|
|
|
179
208
|
|
|
180
209
|
declare function createMqReq(channel: amqplib.Channel): <R>(arg: R) => Promise<void>;
|
|
181
210
|
|
|
182
|
-
export { BadRequestException, BaseParam, Body, Controller, Delete, Factory, ForbiddenException, Get, Guard, Header, HttpException, Inject, Interceptor, MQ, Middle, NotFoundException, Options,
|
|
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 };
|