phecda-server 1.4.1 → 1.5.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-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 +46 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -42
- 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 };
|
package/dist/index.js
CHANGED
|
@@ -39,8 +39,11 @@ __export(src_exports, {
|
|
|
39
39
|
Base: () => Base,
|
|
40
40
|
BaseParam: () => BaseParam,
|
|
41
41
|
Body: () => Body,
|
|
42
|
+
Compiler: () => Compiler,
|
|
42
43
|
ConflictException: () => ConflictException,
|
|
44
|
+
Context: () => Context,
|
|
43
45
|
Controller: () => Controller,
|
|
46
|
+
Define: () => Define,
|
|
44
47
|
Delete: () => Delete,
|
|
45
48
|
Factory: () => Factory,
|
|
46
49
|
ForbiddenException: () => ForbiddenException,
|
|
@@ -58,9 +61,6 @@ __export(src_exports, {
|
|
|
58
61
|
NotFoundException: () => NotFoundException,
|
|
59
62
|
Param: () => Param,
|
|
60
63
|
PayloadLargeException: () => PayloadLargeException,
|
|
61
|
-
Pcompiler: () => Pcompiler,
|
|
62
|
-
Pcontext: () => Pcontext,
|
|
63
|
-
Pmeta: () => Pmeta,
|
|
64
64
|
Post: () => Post,
|
|
65
65
|
Put: () => Put,
|
|
66
66
|
Query: () => Query,
|
|
@@ -197,7 +197,7 @@ __name(ConflictException, "ConflictException");
|
|
|
197
197
|
// src/exception/bad-gateway.ts
|
|
198
198
|
var BadGatewayException = class extends HttpException {
|
|
199
199
|
constructor(message) {
|
|
200
|
-
super(message,
|
|
200
|
+
super(message, 502, "Bad Gatrway");
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
__name(BadGatewayException, "BadGatewayException");
|
|
@@ -284,7 +284,7 @@ var Phistroy = class {
|
|
|
284
284
|
__name(Phistroy, "Phistroy");
|
|
285
285
|
|
|
286
286
|
// src/context/base.ts
|
|
287
|
-
var
|
|
287
|
+
var _Context = class {
|
|
288
288
|
key;
|
|
289
289
|
data;
|
|
290
290
|
method;
|
|
@@ -297,17 +297,17 @@ var _Pcontext = class {
|
|
|
297
297
|
this.history = new Phistroy();
|
|
298
298
|
}
|
|
299
299
|
static registerGuard(key, handler) {
|
|
300
|
-
|
|
300
|
+
_Context.guardsRecord[key] = handler;
|
|
301
301
|
}
|
|
302
302
|
static registerInterceptor(key, handler) {
|
|
303
|
-
|
|
303
|
+
_Context.interceptorsRecord[key] = handler;
|
|
304
304
|
}
|
|
305
305
|
async useGuard(guards, isMerge = false) {
|
|
306
306
|
for (const guard of guards) {
|
|
307
307
|
if (this.history.record(guard, "guard")) {
|
|
308
|
-
if (!(guard in
|
|
308
|
+
if (!(guard in _Context.guardsRecord))
|
|
309
309
|
throw new FrameworkException(`can't find guard named ${guard}`);
|
|
310
|
-
if (!await
|
|
310
|
+
if (!await _Context.guardsRecord[guard](this.data, isMerge))
|
|
311
311
|
throw new ForbiddenException(`Guard exception--${guard}`);
|
|
312
312
|
}
|
|
313
313
|
}
|
|
@@ -316,9 +316,9 @@ var _Pcontext = class {
|
|
|
316
316
|
const ret = [];
|
|
317
317
|
for (const interceptor of interceptors) {
|
|
318
318
|
if (this.history.record(interceptor, "interceptor")) {
|
|
319
|
-
if (!(interceptor in
|
|
319
|
+
if (!(interceptor in _Context.interceptorsRecord))
|
|
320
320
|
throw new FrameworkException(`can't find guard named ${interceptor}`);
|
|
321
|
-
const post = await
|
|
321
|
+
const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge);
|
|
322
322
|
if (post)
|
|
323
323
|
ret.push(post);
|
|
324
324
|
}
|
|
@@ -333,23 +333,23 @@ var _Pcontext = class {
|
|
|
333
333
|
return data;
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
|
-
var
|
|
337
|
-
__name(
|
|
338
|
-
__publicField(
|
|
339
|
-
__publicField(
|
|
340
|
-
__publicField(
|
|
341
|
-
__publicField(
|
|
342
|
-
__publicField(
|
|
336
|
+
var Context = _Context;
|
|
337
|
+
__name(Context, "Context");
|
|
338
|
+
__publicField(Context, "metaRecord", {});
|
|
339
|
+
__publicField(Context, "metaDataRecord", {});
|
|
340
|
+
__publicField(Context, "instanceRecord", {});
|
|
341
|
+
__publicField(Context, "guardsRecord", {});
|
|
342
|
+
__publicField(Context, "interceptorsRecord", {});
|
|
343
343
|
function addGuard(key, handler) {
|
|
344
|
-
|
|
344
|
+
Context.registerGuard(key, handler);
|
|
345
345
|
}
|
|
346
346
|
__name(addGuard, "addGuard");
|
|
347
347
|
function addInterceptor(key, handler) {
|
|
348
|
-
|
|
348
|
+
Context.registerInterceptor(key, handler);
|
|
349
349
|
}
|
|
350
350
|
__name(addInterceptor, "addInterceptor");
|
|
351
351
|
function getInstance(tag) {
|
|
352
|
-
return
|
|
352
|
+
return Context.instanceRecord[tag];
|
|
353
353
|
}
|
|
354
354
|
__name(getInstance, "getInstance");
|
|
355
355
|
function parseMeta(meta) {
|
|
@@ -372,7 +372,7 @@ function parseMeta(meta) {
|
|
|
372
372
|
__name(parseMeta, "parseMeta");
|
|
373
373
|
|
|
374
374
|
// src/context/server.ts
|
|
375
|
-
var _ServerContext = class extends
|
|
375
|
+
var _ServerContext = class extends Context {
|
|
376
376
|
static useMiddleware(middlewares) {
|
|
377
377
|
return middlewares.map((m) => {
|
|
378
378
|
if (!(m in _ServerContext.middlewareRecord))
|
|
@@ -409,7 +409,7 @@ function useServerFilter(filter) {
|
|
|
409
409
|
__name(useServerFilter, "useServerFilter");
|
|
410
410
|
|
|
411
411
|
// src/context/micro.ts
|
|
412
|
-
var _RabbitMqContext = class extends
|
|
412
|
+
var _RabbitMqContext = class extends Context {
|
|
413
413
|
static useMiddleware(middlewares) {
|
|
414
414
|
return middlewares.map((m) => {
|
|
415
415
|
if (!(m in _RabbitMqContext.middlewareRecord))
|
|
@@ -448,7 +448,7 @@ var Base = class {
|
|
|
448
448
|
__name(Base, "Base");
|
|
449
449
|
|
|
450
450
|
// src/compiler.ts
|
|
451
|
-
var
|
|
451
|
+
var Compiler = class {
|
|
452
452
|
classMap = {};
|
|
453
453
|
name;
|
|
454
454
|
constructor() {
|
|
@@ -487,7 +487,7 @@ return ret
|
|
|
487
487
|
`;
|
|
488
488
|
}
|
|
489
489
|
};
|
|
490
|
-
__name(
|
|
490
|
+
__name(Compiler, "Compiler");
|
|
491
491
|
function genParams(decorators) {
|
|
492
492
|
return decorators.map((_, i) => {
|
|
493
493
|
return `${`arg${i}`}`;
|
|
@@ -526,8 +526,8 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
526
526
|
const instance = moduleMap.get(tag);
|
|
527
527
|
const methodTag = `${tag}-${method}`;
|
|
528
528
|
contextMeta[methodTag] = i;
|
|
529
|
-
|
|
530
|
-
let { guards, reflect, interceptors, params, middlewares } =
|
|
529
|
+
Context.metaRecord[methodTag] = i;
|
|
530
|
+
let { guards, reflect, interceptors, params, middlewares } = Context.metaDataRecord[methodTag] ? Context.metaDataRecord[methodTag] : Context.metaDataRecord[methodTag] = parseMeta(i);
|
|
531
531
|
guards = [
|
|
532
532
|
...globalGuards,
|
|
533
533
|
...guards
|
|
@@ -538,7 +538,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
538
538
|
];
|
|
539
539
|
const handler = instance[method].bind(instance);
|
|
540
540
|
methodMap[methodTag] = handler;
|
|
541
|
-
|
|
541
|
+
Context.instanceRecord[name] = instance;
|
|
542
542
|
if (route2) {
|
|
543
543
|
app[route2.type](route2.route, ...ServerContext.useMiddleware(middlewares), async (req, res) => {
|
|
544
544
|
const contextData = {
|
|
@@ -580,7 +580,8 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
580
580
|
const contextData = {
|
|
581
581
|
request: req,
|
|
582
582
|
response: res,
|
|
583
|
-
meta: contextMeta
|
|
583
|
+
meta: contextMeta,
|
|
584
|
+
isMerge: true
|
|
584
585
|
};
|
|
585
586
|
if (!Array.isArray(data))
|
|
586
587
|
return res.json(await ServerContext.useFilter(new BadRequestException("data format should be an array"), contextData));
|
|
@@ -591,7 +592,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
591
592
|
for (const item of data) {
|
|
592
593
|
const { tag } = item;
|
|
593
594
|
const [name] = tag.split("-");
|
|
594
|
-
const { guards, reflect, interceptors, params } =
|
|
595
|
+
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
595
596
|
const instance = moduleMap.get(name);
|
|
596
597
|
try {
|
|
597
598
|
if (!params)
|
|
@@ -615,7 +616,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
615
616
|
instance.context = contextData;
|
|
616
617
|
ret.push(await context.usePost(await methodMap[tag](...args)));
|
|
617
618
|
} catch (e) {
|
|
618
|
-
const m =
|
|
619
|
+
const m = Context.metaRecord[tag];
|
|
619
620
|
m.handlers.forEach((handler) => handler.error?.(e));
|
|
620
621
|
ret.push(await context.useFilter(e));
|
|
621
622
|
}
|
|
@@ -627,7 +628,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
627
628
|
return new Promise(async (resolve) => {
|
|
628
629
|
const { tag } = item;
|
|
629
630
|
const [name] = tag.split("-");
|
|
630
|
-
const { guards, reflect, interceptors, params } =
|
|
631
|
+
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag];
|
|
631
632
|
const instance = moduleMap.get(name);
|
|
632
633
|
try {
|
|
633
634
|
if (!params)
|
|
@@ -644,7 +645,7 @@ function bindApp(app, { meta, moduleMap }, options = {}) {
|
|
|
644
645
|
instance.context = contextData;
|
|
645
646
|
resolve(await context.usePost(await methodMap[tag](...args)));
|
|
646
647
|
} catch (e) {
|
|
647
|
-
const m =
|
|
648
|
+
const m = Context.metaRecord[tag];
|
|
648
649
|
m.handlers.forEach((handler) => handler.error?.(e));
|
|
649
650
|
resolve(await context.useFilter(e));
|
|
650
651
|
}
|
|
@@ -665,7 +666,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
665
666
|
var import_phecda_core2 = require("phecda-core");
|
|
666
667
|
|
|
667
668
|
// src/meta.ts
|
|
668
|
-
var
|
|
669
|
+
var Meta = class {
|
|
669
670
|
data;
|
|
670
671
|
handlers;
|
|
671
672
|
reflect;
|
|
@@ -675,7 +676,7 @@ var Pmeta = class {
|
|
|
675
676
|
this.reflect = reflect;
|
|
676
677
|
}
|
|
677
678
|
};
|
|
678
|
-
__name(
|
|
679
|
+
__name(Meta, "Meta");
|
|
679
680
|
|
|
680
681
|
// src/core.ts
|
|
681
682
|
var emitter = new import_events.default();
|
|
@@ -761,7 +762,7 @@ function getMetaFromInstance(instance, name, tag) {
|
|
|
761
762
|
...state.interceptors
|
|
762
763
|
])
|
|
763
764
|
];
|
|
764
|
-
return new
|
|
765
|
+
return new Meta(state, (0, import_phecda_core2.getHandler)(instance, i), getParamtypes(instance, i) || []);
|
|
765
766
|
});
|
|
766
767
|
}
|
|
767
768
|
__name(getMetaFromInstance, "getMetaFromInstance");
|
|
@@ -952,17 +953,17 @@ function Header(name, value) {
|
|
|
952
953
|
};
|
|
953
954
|
}
|
|
954
955
|
__name(Header, "Header");
|
|
955
|
-
function
|
|
956
|
+
function Define(key, value) {
|
|
956
957
|
return (target, k) => {
|
|
957
958
|
(0, import_phecda_core6.setModalVar)(target, k);
|
|
958
959
|
(0, import_phecda_core6.mergeState)(target, k, {
|
|
959
|
-
|
|
960
|
+
define: {
|
|
960
961
|
[key]: value
|
|
961
962
|
}
|
|
962
963
|
});
|
|
963
964
|
};
|
|
964
965
|
}
|
|
965
|
-
__name(
|
|
966
|
+
__name(Define, "Define");
|
|
966
967
|
|
|
967
968
|
// src/index.ts
|
|
968
969
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
@@ -980,11 +981,11 @@ async function bindMQ(ch, { meta, moduleMap }) {
|
|
|
980
981
|
for (const item of meta) {
|
|
981
982
|
const { route, name, method, mq: { routeKey, queue: queueName, options } = {} } = item.data;
|
|
982
983
|
const tag = `${name}-${method}`;
|
|
983
|
-
|
|
984
|
-
const { guards, reflect, interceptors, params } =
|
|
984
|
+
Context.metaRecord[tag] = item;
|
|
985
|
+
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag] ? Context.metaDataRecord[tag] : Context.metaDataRecord[tag] = parseMeta(item);
|
|
985
986
|
const instance = moduleMap.get(name);
|
|
986
987
|
const handler = instance[method].bind(instance);
|
|
987
|
-
|
|
988
|
+
Context.instanceRecord[name] = instance;
|
|
988
989
|
if (route) {
|
|
989
990
|
const { queue } = await ch.assertQueue(route.route);
|
|
990
991
|
if (queueName && routeKey)
|
|
@@ -1126,8 +1127,11 @@ __name(createMqReq, "createMqReq");
|
|
|
1126
1127
|
Base,
|
|
1127
1128
|
BaseParam,
|
|
1128
1129
|
Body,
|
|
1130
|
+
Compiler,
|
|
1129
1131
|
ConflictException,
|
|
1132
|
+
Context,
|
|
1130
1133
|
Controller,
|
|
1134
|
+
Define,
|
|
1131
1135
|
Delete,
|
|
1132
1136
|
Factory,
|
|
1133
1137
|
ForbiddenException,
|
|
@@ -1145,9 +1149,6 @@ __name(createMqReq, "createMqReq");
|
|
|
1145
1149
|
NotFoundException,
|
|
1146
1150
|
Param,
|
|
1147
1151
|
PayloadLargeException,
|
|
1148
|
-
Pcompiler,
|
|
1149
|
-
Pcontext,
|
|
1150
|
-
Pmeta,
|
|
1151
1152
|
Post,
|
|
1152
1153
|
Put,
|
|
1153
1154
|
Query,
|