phecda-server 1.5.0 → 2.0.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/index.d.ts +105 -39
- package/dist/index.js +52 -299
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -283
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -54
- package/dist/axios-646333e3.d.ts +0 -136
- package/dist/client/index.d.ts +0 -10
- package/dist/client/index.js +0 -131
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs +0 -98
- package/dist/client/index.mjs.map +0 -1
- package/dist/unplugin/esbuild.d.ts +0 -7
- package/dist/unplugin/esbuild.js +0 -136
- package/dist/unplugin/esbuild.js.map +0 -1
- package/dist/unplugin/esbuild.mjs +0 -111
- package/dist/unplugin/esbuild.mjs.map +0 -1
- package/dist/unplugin/unplugin.d.ts +0 -7
- package/dist/unplugin/unplugin.js +0 -131
- package/dist/unplugin/unplugin.js.map +0 -1
- package/dist/unplugin/unplugin.mjs +0 -108
- package/dist/unplugin/unplugin.mjs.map +0 -1
- package/dist/unplugin/vite.d.ts +0 -7
- package/dist/unplugin/vite.js +0 -134
- package/dist/unplugin/vite.js.map +0 -1
- package/dist/unplugin/vite.mjs +0 -111
- package/dist/unplugin/vite.mjs.map +0 -1
- package/dist/unplugin/webpack.d.ts +0 -5
- package/dist/unplugin/webpack.js +0 -136
- package/dist/unplugin/webpack.js.map +0 -1
- package/dist/unplugin/webpack.mjs +0 -111
- package/dist/unplugin/webpack.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import { RequestHandler, Express } from 'express';
|
|
2
|
-
import {
|
|
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';
|
|
1
|
+
import { Request, Response, RequestHandler, Express } from 'express';
|
|
2
|
+
import { Events } from 'phecda-core';
|
|
4
3
|
export * from 'phecda-core';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
declare class Meta {
|
|
6
|
+
data: P.Meta;
|
|
7
|
+
handlers: P.Handler[];
|
|
8
|
+
reflect: any[];
|
|
9
|
+
constructor(data: P.Meta, handlers: P.Handler[], reflect: any[]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class HttpException extends Error {
|
|
13
|
+
message: string;
|
|
14
|
+
status: number;
|
|
15
|
+
description: string;
|
|
16
|
+
constructor(message: string, status: number, description?: string);
|
|
17
|
+
get data(): {
|
|
18
|
+
message: string;
|
|
19
|
+
description: string;
|
|
20
|
+
status: number;
|
|
21
|
+
error: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
7
24
|
|
|
8
25
|
declare class UndefinedException extends HttpException {
|
|
9
26
|
constructor(message: string);
|
|
@@ -61,6 +78,80 @@ declare class FrameworkException extends HttpException {
|
|
|
61
78
|
constructor(message: string);
|
|
62
79
|
}
|
|
63
80
|
|
|
81
|
+
type Construct<T = any> = new (...args: any[]) => T;
|
|
82
|
+
interface Emitter {
|
|
83
|
+
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
84
|
+
once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
85
|
+
off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
86
|
+
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
87
|
+
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
88
|
+
}
|
|
89
|
+
type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
90
|
+
type MergeType = <R extends Promise<any>[]>(...args: R) => {
|
|
91
|
+
[K in keyof R]: Awaited<R[K]>;
|
|
92
|
+
};
|
|
93
|
+
interface ServerMergeCtx {
|
|
94
|
+
request: Request;
|
|
95
|
+
response: Response;
|
|
96
|
+
meta: Record<string, Meta>;
|
|
97
|
+
isMerge: true;
|
|
98
|
+
tags?: string[];
|
|
99
|
+
}
|
|
100
|
+
interface ServerCtx {
|
|
101
|
+
request: Request;
|
|
102
|
+
response: Response;
|
|
103
|
+
meta: Meta;
|
|
104
|
+
}
|
|
105
|
+
interface BaseError {
|
|
106
|
+
error: true;
|
|
107
|
+
status: number;
|
|
108
|
+
}
|
|
109
|
+
type ServerFilter<E extends HttpException = any> = (err: E | Error, contextData: ServerMergeCtx | ServerCtx) => any;
|
|
110
|
+
declare class Base {
|
|
111
|
+
context: ServerMergeCtx | ServerCtx;
|
|
112
|
+
}
|
|
113
|
+
declare namespace P {
|
|
114
|
+
interface Error extends BaseError {
|
|
115
|
+
message: string;
|
|
116
|
+
description: string;
|
|
117
|
+
}
|
|
118
|
+
type ResOrErr<R> = {
|
|
119
|
+
[K in keyof R]: Awaited<R[K]> | Error;
|
|
120
|
+
};
|
|
121
|
+
type Res<T> = T;
|
|
122
|
+
type Guard = ((contextData: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((contextData: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean);
|
|
123
|
+
type Interceptor = ((contextData: ServerCtx, isMerge?: false) => any) | ((contextData: ServerMergeCtx, isMerge?: true) => any);
|
|
124
|
+
interface Handler {
|
|
125
|
+
error?: (arg: any) => void;
|
|
126
|
+
}
|
|
127
|
+
interface Meta {
|
|
128
|
+
route?: {
|
|
129
|
+
type: RequestType;
|
|
130
|
+
route: string;
|
|
131
|
+
};
|
|
132
|
+
define?: any;
|
|
133
|
+
header: Record<string, string>;
|
|
134
|
+
params: {
|
|
135
|
+
type: string;
|
|
136
|
+
index: number;
|
|
137
|
+
key: string;
|
|
138
|
+
validate?: boolean;
|
|
139
|
+
}[];
|
|
140
|
+
guards: string[];
|
|
141
|
+
interceptors: string[];
|
|
142
|
+
middlewares: string[];
|
|
143
|
+
method: string;
|
|
144
|
+
name: string;
|
|
145
|
+
tag: string;
|
|
146
|
+
}
|
|
147
|
+
interface Pipe {
|
|
148
|
+
transform(args: {
|
|
149
|
+
arg: any;
|
|
150
|
+
validate?: boolean;
|
|
151
|
+
}[], reflect: any[]): Promise<any[]>;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
64
155
|
declare class Phistroy {
|
|
65
156
|
guard: string[];
|
|
66
157
|
interceptor: string[];
|
|
@@ -117,32 +208,6 @@ declare function addMiddleware(key: string, handler: RequestHandler): void;
|
|
|
117
208
|
declare function useServerPipe(pipe: P.Pipe): void;
|
|
118
209
|
declare function useServerFilter(filter: ServerFilter): void;
|
|
119
210
|
|
|
120
|
-
declare class RabbitMqContext extends Context {
|
|
121
|
-
static pipe: P.Pipe;
|
|
122
|
-
static filter: MQFilter<any>;
|
|
123
|
-
static middlewareRecord: Record<string, (...params: any) => boolean>;
|
|
124
|
-
static useMiddleware(middlewares: string[]): ((...params: any) => boolean)[];
|
|
125
|
-
usePipe(args: {
|
|
126
|
-
arg: any;
|
|
127
|
-
validate?: boolean;
|
|
128
|
-
}[], reflect: any[]): Promise<any[]>;
|
|
129
|
-
static useFilter(arg: any, data: MQFilter): any;
|
|
130
|
-
useFilter(arg: any): any;
|
|
131
|
-
}
|
|
132
|
-
declare function useMqPipe(pipe: P.Pipe): void;
|
|
133
|
-
declare function useMqFilter(filter: MQFilter): void;
|
|
134
|
-
|
|
135
|
-
declare class Compiler {
|
|
136
|
-
classMap: Record<string, {
|
|
137
|
-
[key: string]: string;
|
|
138
|
-
}>;
|
|
139
|
-
name: string;
|
|
140
|
-
constructor();
|
|
141
|
-
getContent(): string;
|
|
142
|
-
createRequest(): string;
|
|
143
|
-
addMethod(args: P.Meta): void;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
211
|
declare const emitter: Emitter;
|
|
147
212
|
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<{
|
|
148
213
|
moduleMap: Map<string, any>;
|
|
@@ -173,18 +238,19 @@ declare function Guard(...guards: string[]): any;
|
|
|
173
238
|
declare function Middle(...middlewares: string[]): any;
|
|
174
239
|
declare function Interceptor(...interceptors: string[]): any;
|
|
175
240
|
|
|
176
|
-
declare function MQ(queue: string, routeKey: string, options?: amqplib.Options.Consume): (target: any, k: PropertyKey) => void;
|
|
177
|
-
|
|
178
241
|
declare function Inject(_target: any): void;
|
|
179
242
|
declare function Header(name: string, value: string): (target: any, k: PropertyKey) => void;
|
|
180
|
-
declare function Define(key: string, value: any): (target: any, k
|
|
243
|
+
declare function Define(key: string, value: any): (target: any, k?: PropertyKey) => void;
|
|
181
244
|
|
|
182
245
|
declare const defaultPipe: P.Pipe;
|
|
183
246
|
|
|
184
|
-
declare
|
|
185
|
-
|
|
186
|
-
declare
|
|
247
|
+
declare const isUndefined: (obj: any) => obj is undefined;
|
|
248
|
+
declare const isNil: (obj: any) => obj is null | undefined;
|
|
249
|
+
declare const isObject: (fn: any) => fn is object;
|
|
250
|
+
declare function resolveDep(ret: any, key: string): any;
|
|
251
|
+
declare function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx;
|
|
187
252
|
|
|
188
|
-
declare
|
|
253
|
+
declare const SERIES_SYMBOL = "__symbol_series__";
|
|
254
|
+
declare const MERGE_SYMBOL = "__symbol_req__";
|
|
189
255
|
|
|
190
|
-
export { BadGatewayException, BadRequestException, BaseParam, Body,
|
|
256
|
+
export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Inject, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, getInstance, isMerge, isNil, isObject, isUndefined, parseMeta, resolveDep, useServerFilter, useServerPipe };
|
package/dist/index.js
CHANGED
|
@@ -33,13 +33,11 @@ var __publicField = (obj, key, value) => {
|
|
|
33
33
|
// src/index.ts
|
|
34
34
|
var src_exports = {};
|
|
35
35
|
__export(src_exports, {
|
|
36
|
-
$S: () => $S,
|
|
37
36
|
BadGatewayException: () => BadGatewayException,
|
|
38
37
|
BadRequestException: () => BadRequestException,
|
|
39
38
|
Base: () => Base,
|
|
40
39
|
BaseParam: () => BaseParam,
|
|
41
40
|
Body: () => Body,
|
|
42
|
-
Compiler: () => Compiler,
|
|
43
41
|
ConflictException: () => ConflictException,
|
|
44
42
|
Context: () => Context,
|
|
45
43
|
Controller: () => Controller,
|
|
@@ -55,7 +53,7 @@ __export(src_exports, {
|
|
|
55
53
|
Inject: () => Inject,
|
|
56
54
|
Interceptor: () => Interceptor,
|
|
57
55
|
InvalidInputException: () => InvalidInputException,
|
|
58
|
-
|
|
56
|
+
MERGE_SYMBOL: () => MERGE_SYMBOL,
|
|
59
57
|
Meta: () => Meta,
|
|
60
58
|
Middle: () => Middle,
|
|
61
59
|
NotFoundException: () => NotFoundException,
|
|
@@ -64,8 +62,8 @@ __export(src_exports, {
|
|
|
64
62
|
Post: () => Post,
|
|
65
63
|
Put: () => Put,
|
|
66
64
|
Query: () => Query,
|
|
67
|
-
RabbitMqContext: () => RabbitMqContext,
|
|
68
65
|
Route: () => Route,
|
|
66
|
+
SERIES_SYMBOL: () => SERIES_SYMBOL,
|
|
69
67
|
ServerContext: () => ServerContext,
|
|
70
68
|
ServiceUnavailableException: () => ServiceUnavailableException,
|
|
71
69
|
TimeoutException: () => TimeoutException,
|
|
@@ -77,21 +75,15 @@ __export(src_exports, {
|
|
|
77
75
|
addInterceptor: () => addInterceptor,
|
|
78
76
|
addMiddleware: () => addMiddleware,
|
|
79
77
|
bindApp: () => bindApp,
|
|
80
|
-
bindMQ: () => bindMQ,
|
|
81
|
-
createMqReq: () => createMqReq,
|
|
82
|
-
createParallelReq: () => createParallelReq,
|
|
83
|
-
createPub: () => createPub,
|
|
84
|
-
createReq: () => createReq,
|
|
85
|
-
createSeriesReq: () => createSeriesReq,
|
|
86
78
|
defaultPipe: () => defaultPipe,
|
|
87
79
|
emitter: () => emitter,
|
|
88
80
|
getInstance: () => getInstance,
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
isMerge: () => isMerge,
|
|
82
|
+
isNil: () => isNil,
|
|
83
|
+
isObject: () => isObject,
|
|
84
|
+
isUndefined: () => isUndefined,
|
|
91
85
|
parseMeta: () => parseMeta,
|
|
92
|
-
|
|
93
|
-
useMqFilter: () => useMqFilter,
|
|
94
|
-
useMqPipe: () => useMqPipe,
|
|
86
|
+
resolveDep: () => resolveDep,
|
|
95
87
|
useServerFilter: () => useServerFilter,
|
|
96
88
|
useServerPipe: () => useServerPipe
|
|
97
89
|
});
|
|
@@ -264,10 +256,6 @@ var serverFilter = /* @__PURE__ */ __name((e) => {
|
|
|
264
256
|
e = new UndefinedException(e.message || e);
|
|
265
257
|
return e.data;
|
|
266
258
|
}, "serverFilter");
|
|
267
|
-
var rabbitMqFilter = /* @__PURE__ */ __name((e, data) => {
|
|
268
|
-
const { channel, message } = data;
|
|
269
|
-
channel.reject(message, true);
|
|
270
|
-
}, "rabbitMqFilter");
|
|
271
259
|
|
|
272
260
|
// src/history.ts
|
|
273
261
|
var Phistroy = class {
|
|
@@ -302,23 +290,23 @@ var _Context = class {
|
|
|
302
290
|
static registerInterceptor(key, handler) {
|
|
303
291
|
_Context.interceptorsRecord[key] = handler;
|
|
304
292
|
}
|
|
305
|
-
async useGuard(guards,
|
|
293
|
+
async useGuard(guards, isMerge2 = false) {
|
|
306
294
|
for (const guard of guards) {
|
|
307
295
|
if (this.history.record(guard, "guard")) {
|
|
308
296
|
if (!(guard in _Context.guardsRecord))
|
|
309
297
|
throw new FrameworkException(`can't find guard named ${guard}`);
|
|
310
|
-
if (!await _Context.guardsRecord[guard](this.data,
|
|
298
|
+
if (!await _Context.guardsRecord[guard](this.data, isMerge2))
|
|
311
299
|
throw new ForbiddenException(`Guard exception--${guard}`);
|
|
312
300
|
}
|
|
313
301
|
}
|
|
314
302
|
}
|
|
315
|
-
async useInterceptor(interceptors,
|
|
303
|
+
async useInterceptor(interceptors, isMerge2 = false) {
|
|
316
304
|
const ret = [];
|
|
317
305
|
for (const interceptor of interceptors) {
|
|
318
306
|
if (this.history.record(interceptor, "interceptor")) {
|
|
319
307
|
if (!(interceptor in _Context.interceptorsRecord))
|
|
320
308
|
throw new FrameworkException(`can't find guard named ${interceptor}`);
|
|
321
|
-
const post = await _Context.interceptorsRecord[interceptor](this.data,
|
|
309
|
+
const post = await _Context.interceptorsRecord[interceptor](this.data, isMerge2);
|
|
322
310
|
if (post)
|
|
323
311
|
ret.push(post);
|
|
324
312
|
}
|
|
@@ -408,93 +396,12 @@ function useServerFilter(filter) {
|
|
|
408
396
|
}
|
|
409
397
|
__name(useServerFilter, "useServerFilter");
|
|
410
398
|
|
|
411
|
-
// src/context/micro.ts
|
|
412
|
-
var _RabbitMqContext = class extends Context {
|
|
413
|
-
static useMiddleware(middlewares) {
|
|
414
|
-
return middlewares.map((m) => {
|
|
415
|
-
if (!(m in _RabbitMqContext.middlewareRecord))
|
|
416
|
-
throw new FrameworkException(`can't find middleware named ${m}`);
|
|
417
|
-
return _RabbitMqContext.middlewareRecord[m];
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
async usePipe(args, reflect) {
|
|
421
|
-
return _RabbitMqContext.pipe.transform?.(args, reflect);
|
|
422
|
-
}
|
|
423
|
-
static useFilter(arg, data) {
|
|
424
|
-
return _RabbitMqContext.filter(arg, data);
|
|
425
|
-
}
|
|
426
|
-
useFilter(arg) {
|
|
427
|
-
return _RabbitMqContext.filter(arg, this.data);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
var RabbitMqContext = _RabbitMqContext;
|
|
431
|
-
__name(RabbitMqContext, "RabbitMqContext");
|
|
432
|
-
__publicField(RabbitMqContext, "pipe", defaultPipe);
|
|
433
|
-
__publicField(RabbitMqContext, "filter", rabbitMqFilter);
|
|
434
|
-
__publicField(RabbitMqContext, "middlewareRecord", {});
|
|
435
|
-
function useMqPipe(pipe) {
|
|
436
|
-
RabbitMqContext.pipe = pipe;
|
|
437
|
-
}
|
|
438
|
-
__name(useMqPipe, "useMqPipe");
|
|
439
|
-
function useMqFilter(filter) {
|
|
440
|
-
RabbitMqContext.filter = filter;
|
|
441
|
-
}
|
|
442
|
-
__name(useMqFilter, "useMqFilter");
|
|
443
|
-
|
|
444
399
|
// src/types.ts
|
|
445
400
|
var Base = class {
|
|
446
401
|
context;
|
|
447
402
|
};
|
|
448
403
|
__name(Base, "Base");
|
|
449
404
|
|
|
450
|
-
// src/compiler.ts
|
|
451
|
-
var Compiler = class {
|
|
452
|
-
classMap = {};
|
|
453
|
-
name;
|
|
454
|
-
constructor() {
|
|
455
|
-
}
|
|
456
|
-
getContent() {
|
|
457
|
-
let content = "";
|
|
458
|
-
for (const name in this.classMap) {
|
|
459
|
-
content += `
|
|
460
|
-
export class ${name}{
|
|
461
|
-
${Object.values(this.classMap[name]).reduce((p, c) => p + c)}
|
|
462
|
-
}`;
|
|
463
|
-
}
|
|
464
|
-
return content;
|
|
465
|
-
}
|
|
466
|
-
createRequest() {
|
|
467
|
-
let content = "import {useC} from 'phecda-server'\n";
|
|
468
|
-
for (const name in this.classMap)
|
|
469
|
-
content += `export const {${Object.keys(this.classMap[name]).join(",")}}=useC(${name})
|
|
470
|
-
`;
|
|
471
|
-
return content;
|
|
472
|
-
}
|
|
473
|
-
addMethod(args) {
|
|
474
|
-
const { route: { route = "/", type = "get" } = {}, name, method, params, tag } = args;
|
|
475
|
-
const url = route.replace(/\/\:([^\/]*)/g, "");
|
|
476
|
-
this.name = name;
|
|
477
|
-
if (!this.classMap[name])
|
|
478
|
-
this.classMap[name] = {};
|
|
479
|
-
this.classMap[name][method] = `
|
|
480
|
-
${method}(${genParams(params)}){
|
|
481
|
-
const ret={tag:"${tag}-${method}",body:{},query:{},params:{},realParam:'',method:"${type}",url:"${url}"}
|
|
482
|
-
${params.filter((item) => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}
|
|
483
|
-
${c.type === "params" ? `ret.realParam+='/'+arg${i}
|
|
484
|
-
` : ""}`, "")}
|
|
485
|
-
return ret
|
|
486
|
-
}
|
|
487
|
-
`;
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
__name(Compiler, "Compiler");
|
|
491
|
-
function genParams(decorators) {
|
|
492
|
-
return decorators.map((_, i) => {
|
|
493
|
-
return `${`arg${i}`}`;
|
|
494
|
-
}).join(",");
|
|
495
|
-
}
|
|
496
|
-
__name(genParams, "genParams");
|
|
497
|
-
|
|
498
405
|
// src/utils.ts
|
|
499
406
|
var isUndefined = /* @__PURE__ */ __name((obj) => typeof obj === "undefined", "isUndefined");
|
|
500
407
|
var isNil = /* @__PURE__ */ __name((obj) => isUndefined(obj) || obj === null, "isNil");
|
|
@@ -505,6 +412,10 @@ function resolveDep(ret, key) {
|
|
|
505
412
|
return ret;
|
|
506
413
|
}
|
|
507
414
|
__name(resolveDep, "resolveDep");
|
|
415
|
+
function isMerge(data) {
|
|
416
|
+
return !!data.isMerge;
|
|
417
|
+
}
|
|
418
|
+
__name(isMerge, "isMerge");
|
|
508
419
|
|
|
509
420
|
// src/common.ts
|
|
510
421
|
var SERIES_SYMBOL = "__symbol_series__";
|
|
@@ -661,8 +572,8 @@ __name(bindApp, "bindApp");
|
|
|
661
572
|
|
|
662
573
|
// src/core.ts
|
|
663
574
|
var import_reflect_metadata = require("reflect-metadata");
|
|
664
|
-
var import_events = __toESM(require("events"));
|
|
665
575
|
var import_fs = __toESM(require("fs"));
|
|
576
|
+
var import_node_events = __toESM(require("events"));
|
|
666
577
|
var import_phecda_core2 = require("phecda-core");
|
|
667
578
|
|
|
668
579
|
// src/meta.ts
|
|
@@ -679,7 +590,7 @@ var Meta = class {
|
|
|
679
590
|
__name(Meta, "Meta");
|
|
680
591
|
|
|
681
592
|
// src/core.ts
|
|
682
|
-
var emitter = new
|
|
593
|
+
var emitter = new import_node_events.default();
|
|
683
594
|
async function Factory(Modules) {
|
|
684
595
|
const moduleMap = /* @__PURE__ */ new Map();
|
|
685
596
|
const meta = [];
|
|
@@ -743,7 +654,14 @@ function getMetaFromInstance(instance, name, tag) {
|
|
|
743
654
|
}
|
|
744
655
|
state.params = params;
|
|
745
656
|
initState(state);
|
|
746
|
-
state.
|
|
657
|
+
state.define = {
|
|
658
|
+
...baseState.define,
|
|
659
|
+
...state.define
|
|
660
|
+
};
|
|
661
|
+
state.header = {
|
|
662
|
+
...baseState.header,
|
|
663
|
+
...state.header
|
|
664
|
+
};
|
|
747
665
|
state.middlewares = [
|
|
748
666
|
.../* @__PURE__ */ new Set([
|
|
749
667
|
...baseState.middlewares,
|
|
@@ -771,6 +689,8 @@ function getParamtypes(Module, key) {
|
|
|
771
689
|
}
|
|
772
690
|
__name(getParamtypes, "getParamtypes");
|
|
773
691
|
function initState(state) {
|
|
692
|
+
if (!state.define)
|
|
693
|
+
state.define = {};
|
|
774
694
|
if (!state.header)
|
|
775
695
|
state.header = {};
|
|
776
696
|
if (!state.middlewares)
|
|
@@ -783,7 +703,7 @@ function initState(state) {
|
|
|
783
703
|
__name(initState, "initState");
|
|
784
704
|
|
|
785
705
|
// src/decorators/index.ts
|
|
786
|
-
var
|
|
706
|
+
var import_phecda_core5 = require("phecda-core");
|
|
787
707
|
|
|
788
708
|
// src/decorators/param.ts
|
|
789
709
|
var import_phecda_core3 = require("phecda-core");
|
|
@@ -921,30 +841,14 @@ function Interceptor(...interceptors) {
|
|
|
921
841
|
}
|
|
922
842
|
__name(Interceptor, "Interceptor");
|
|
923
843
|
|
|
924
|
-
// src/decorators/micro.ts
|
|
925
|
-
var import_phecda_core5 = require("phecda-core");
|
|
926
|
-
function MQ(queue, routeKey, options) {
|
|
927
|
-
return (target, k) => {
|
|
928
|
-
(0, import_phecda_core5.setModalVar)(target, k);
|
|
929
|
-
(0, import_phecda_core5.mergeState)(target, k, {
|
|
930
|
-
mq: {
|
|
931
|
-
queue,
|
|
932
|
-
routeKey,
|
|
933
|
-
options
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
__name(MQ, "MQ");
|
|
939
|
-
|
|
940
844
|
// src/decorators/index.ts
|
|
941
845
|
function Inject(_target) {
|
|
942
846
|
}
|
|
943
847
|
__name(Inject, "Inject");
|
|
944
848
|
function Header(name, value) {
|
|
945
849
|
return (target, k) => {
|
|
946
|
-
(0,
|
|
947
|
-
(0,
|
|
850
|
+
(0, import_phecda_core5.setModalVar)(target, k);
|
|
851
|
+
(0, import_phecda_core5.mergeState)(target, k, {
|
|
948
852
|
header: {
|
|
949
853
|
name,
|
|
950
854
|
value
|
|
@@ -955,179 +859,34 @@ function Header(name, value) {
|
|
|
955
859
|
__name(Header, "Header");
|
|
956
860
|
function Define(key, value) {
|
|
957
861
|
return (target, k) => {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
862
|
+
if (k) {
|
|
863
|
+
(0, import_phecda_core5.setModalVar)(target, k);
|
|
864
|
+
(0, import_phecda_core5.mergeState)(target, k, {
|
|
865
|
+
define: {
|
|
866
|
+
[key]: value
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
} else {
|
|
870
|
+
(0, import_phecda_core5.setModalVar)(target.prototype, "__CLASS");
|
|
871
|
+
(0, import_phecda_core5.mergeState)(target.prototype, "__CLASS", {
|
|
872
|
+
define: {
|
|
873
|
+
[key]: value
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
}
|
|
964
877
|
};
|
|
965
878
|
}
|
|
966
879
|
__name(Define, "Define");
|
|
967
880
|
|
|
968
881
|
// src/index.ts
|
|
969
882
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
970
|
-
|
|
971
|
-
// src/config.ts
|
|
972
|
-
var Pconfig = {
|
|
973
|
-
rabbitmq: {
|
|
974
|
-
guard: false,
|
|
975
|
-
interceptor: false
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
|
|
979
|
-
// src/micro-services/rabbitmq.ts
|
|
980
|
-
async function bindMQ(ch, { meta, moduleMap }) {
|
|
981
|
-
for (const item of meta) {
|
|
982
|
-
const { route, name, method, mq: { routeKey, queue: queueName, options } = {} } = item.data;
|
|
983
|
-
const tag = `${name}-${method}`;
|
|
984
|
-
Context.metaRecord[tag] = item;
|
|
985
|
-
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag] ? Context.metaDataRecord[tag] : Context.metaDataRecord[tag] = parseMeta(item);
|
|
986
|
-
const instance = moduleMap.get(name);
|
|
987
|
-
const handler = instance[method].bind(instance);
|
|
988
|
-
Context.instanceRecord[name] = instance;
|
|
989
|
-
if (route) {
|
|
990
|
-
const { queue } = await ch.assertQueue(route.route);
|
|
991
|
-
if (queueName && routeKey)
|
|
992
|
-
await ch.bindQueue(queue, queueName, routeKey);
|
|
993
|
-
ch.consume(route.route, async (msg) => {
|
|
994
|
-
if (msg !== null) {
|
|
995
|
-
const content = msg.content.toString();
|
|
996
|
-
const data = params.length > 0 ? JSON.parse(content) : content;
|
|
997
|
-
const contextMeta = {
|
|
998
|
-
message: msg,
|
|
999
|
-
content,
|
|
1000
|
-
channel: ch
|
|
1001
|
-
};
|
|
1002
|
-
const context = new RabbitMqContext(tag, contextMeta);
|
|
1003
|
-
try {
|
|
1004
|
-
if (Pconfig.rabbitmq.guard)
|
|
1005
|
-
await context.useGuard(guards);
|
|
1006
|
-
if (Pconfig.rabbitmq.interceptor)
|
|
1007
|
-
await context.useInterceptor(interceptors);
|
|
1008
|
-
const args = await context.usePipe(params.map(({ key, validate }) => {
|
|
1009
|
-
return {
|
|
1010
|
-
arg: resolveDep(data, key),
|
|
1011
|
-
validate
|
|
1012
|
-
};
|
|
1013
|
-
}), reflect);
|
|
1014
|
-
instance.meta = contextMeta;
|
|
1015
|
-
await context.usePost(await handler(...args));
|
|
1016
|
-
ch.ack(msg);
|
|
1017
|
-
} catch (e) {
|
|
1018
|
-
item.handlers.forEach((handler2) => handler2.error?.(e));
|
|
1019
|
-
context.useFilter(e);
|
|
1020
|
-
}
|
|
1021
|
-
} else {
|
|
1022
|
-
}
|
|
1023
|
-
}, options);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
__name(bindMQ, "bindMQ");
|
|
1028
|
-
async function createPub(ch, method, type) {
|
|
1029
|
-
const { exchange, routeKey, queue } = method();
|
|
1030
|
-
if (exchange)
|
|
1031
|
-
await ch.assertExchange(exchange, type);
|
|
1032
|
-
else
|
|
1033
|
-
await ch.assertQueue(queue);
|
|
1034
|
-
return async (arg) => {
|
|
1035
|
-
const { args } = method(arg);
|
|
1036
|
-
const msg = Buffer.from(JSON.stringify(args));
|
|
1037
|
-
if (exchange)
|
|
1038
|
-
await ch.publish(exchange, routeKey, msg);
|
|
1039
|
-
else
|
|
1040
|
-
await ch.sendToQueue(queue, msg);
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
__name(createPub, "createPub");
|
|
1044
|
-
|
|
1045
|
-
// src/client/axios.ts
|
|
1046
|
-
function toReq(arg) {
|
|
1047
|
-
const { body, query, realParam, method, url } = arg;
|
|
1048
|
-
return {
|
|
1049
|
-
method,
|
|
1050
|
-
url,
|
|
1051
|
-
body,
|
|
1052
|
-
query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join("&")}` : "",
|
|
1053
|
-
params: realParam
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
__name(toReq, "toReq");
|
|
1057
|
-
var merge = /* @__PURE__ */ __name((...args) => {
|
|
1058
|
-
const ret = [];
|
|
1059
|
-
for (const i of args) {
|
|
1060
|
-
const { body, query, params, tag } = i;
|
|
1061
|
-
ret.push({
|
|
1062
|
-
tag,
|
|
1063
|
-
body,
|
|
1064
|
-
query,
|
|
1065
|
-
params
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
return ret;
|
|
1069
|
-
}, "merge");
|
|
1070
|
-
function createReq(instance) {
|
|
1071
|
-
return (arg, config) => {
|
|
1072
|
-
const { url, params, query, body, method } = toReq(arg);
|
|
1073
|
-
if (!method) {
|
|
1074
|
-
console.warn("methods without route decorator won't send request");
|
|
1075
|
-
return;
|
|
1076
|
-
}
|
|
1077
|
-
const ret = [
|
|
1078
|
-
`${url}${params}${query}`
|
|
1079
|
-
];
|
|
1080
|
-
body && ret.push(body);
|
|
1081
|
-
config && ret.push(config);
|
|
1082
|
-
return instance[method](...ret);
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
__name(createReq, "createReq");
|
|
1086
|
-
function createSeriesReq(instance, key = "/__PHECDA_SERVER__") {
|
|
1087
|
-
return (args, config) => {
|
|
1088
|
-
return instance.post(key, {
|
|
1089
|
-
category: "series",
|
|
1090
|
-
data: merge(...args)
|
|
1091
|
-
}, config);
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
__name(createSeriesReq, "createSeriesReq");
|
|
1095
|
-
function createParallelReq(instance, key = "/__PHECDA_SERVER__") {
|
|
1096
|
-
return (args, config) => {
|
|
1097
|
-
return instance.post(key, {
|
|
1098
|
-
category: "parallel",
|
|
1099
|
-
data: merge(...args)
|
|
1100
|
-
}, config);
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
__name(createParallelReq, "createParallelReq");
|
|
1104
|
-
function isError(data) {
|
|
1105
|
-
return typeof data === "object" && data.error;
|
|
1106
|
-
}
|
|
1107
|
-
__name(isError, "isError");
|
|
1108
|
-
function $S(index, key = "") {
|
|
1109
|
-
return `${SERIES_SYMBOL}@${index}@${key}`;
|
|
1110
|
-
}
|
|
1111
|
-
__name($S, "$S");
|
|
1112
|
-
|
|
1113
|
-
// src/client/server.ts
|
|
1114
|
-
function createMqReq(channel) {
|
|
1115
|
-
return async (arg) => {
|
|
1116
|
-
const { url, body } = arg;
|
|
1117
|
-
await channel.assertQueue(url);
|
|
1118
|
-
await channel.sendToQueue(url, Buffer.from(JSON.stringify(body)));
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
__name(createMqReq, "createMqReq");
|
|
1122
883
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1123
884
|
0 && (module.exports = {
|
|
1124
|
-
$S,
|
|
1125
885
|
BadGatewayException,
|
|
1126
886
|
BadRequestException,
|
|
1127
887
|
Base,
|
|
1128
888
|
BaseParam,
|
|
1129
889
|
Body,
|
|
1130
|
-
Compiler,
|
|
1131
890
|
ConflictException,
|
|
1132
891
|
Context,
|
|
1133
892
|
Controller,
|
|
@@ -1143,7 +902,7 @@ __name(createMqReq, "createMqReq");
|
|
|
1143
902
|
Inject,
|
|
1144
903
|
Interceptor,
|
|
1145
904
|
InvalidInputException,
|
|
1146
|
-
|
|
905
|
+
MERGE_SYMBOL,
|
|
1147
906
|
Meta,
|
|
1148
907
|
Middle,
|
|
1149
908
|
NotFoundException,
|
|
@@ -1152,8 +911,8 @@ __name(createMqReq, "createMqReq");
|
|
|
1152
911
|
Post,
|
|
1153
912
|
Put,
|
|
1154
913
|
Query,
|
|
1155
|
-
RabbitMqContext,
|
|
1156
914
|
Route,
|
|
915
|
+
SERIES_SYMBOL,
|
|
1157
916
|
ServerContext,
|
|
1158
917
|
ServiceUnavailableException,
|
|
1159
918
|
TimeoutException,
|
|
@@ -1165,21 +924,15 @@ __name(createMqReq, "createMqReq");
|
|
|
1165
924
|
addInterceptor,
|
|
1166
925
|
addMiddleware,
|
|
1167
926
|
bindApp,
|
|
1168
|
-
bindMQ,
|
|
1169
|
-
createMqReq,
|
|
1170
|
-
createParallelReq,
|
|
1171
|
-
createPub,
|
|
1172
|
-
createReq,
|
|
1173
|
-
createSeriesReq,
|
|
1174
927
|
defaultPipe,
|
|
1175
928
|
emitter,
|
|
1176
929
|
getInstance,
|
|
1177
|
-
|
|
1178
|
-
|
|
930
|
+
isMerge,
|
|
931
|
+
isNil,
|
|
932
|
+
isObject,
|
|
933
|
+
isUndefined,
|
|
1179
934
|
parseMeta,
|
|
1180
|
-
|
|
1181
|
-
useMqFilter,
|
|
1182
|
-
useMqPipe,
|
|
935
|
+
resolveDep,
|
|
1183
936
|
useServerFilter,
|
|
1184
937
|
useServerPipe
|
|
1185
938
|
});
|