phecda-server 1.5.1 → 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 +104 -38
- package/dist/index.js +31 -296
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -280
- 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
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 = [];
|
|
@@ -792,7 +703,7 @@ function initState(state) {
|
|
|
792
703
|
__name(initState, "initState");
|
|
793
704
|
|
|
794
705
|
// src/decorators/index.ts
|
|
795
|
-
var
|
|
706
|
+
var import_phecda_core5 = require("phecda-core");
|
|
796
707
|
|
|
797
708
|
// src/decorators/param.ts
|
|
798
709
|
var import_phecda_core3 = require("phecda-core");
|
|
@@ -930,30 +841,14 @@ function Interceptor(...interceptors) {
|
|
|
930
841
|
}
|
|
931
842
|
__name(Interceptor, "Interceptor");
|
|
932
843
|
|
|
933
|
-
// src/decorators/micro.ts
|
|
934
|
-
var import_phecda_core5 = require("phecda-core");
|
|
935
|
-
function MQ(queue, routeKey, options) {
|
|
936
|
-
return (target, k) => {
|
|
937
|
-
(0, import_phecda_core5.setModalVar)(target, k);
|
|
938
|
-
(0, import_phecda_core5.mergeState)(target, k, {
|
|
939
|
-
mq: {
|
|
940
|
-
queue,
|
|
941
|
-
routeKey,
|
|
942
|
-
options
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
__name(MQ, "MQ");
|
|
948
|
-
|
|
949
844
|
// src/decorators/index.ts
|
|
950
845
|
function Inject(_target) {
|
|
951
846
|
}
|
|
952
847
|
__name(Inject, "Inject");
|
|
953
848
|
function Header(name, value) {
|
|
954
849
|
return (target, k) => {
|
|
955
|
-
(0,
|
|
956
|
-
(0,
|
|
850
|
+
(0, import_phecda_core5.setModalVar)(target, k);
|
|
851
|
+
(0, import_phecda_core5.mergeState)(target, k, {
|
|
957
852
|
header: {
|
|
958
853
|
name,
|
|
959
854
|
value
|
|
@@ -965,15 +860,15 @@ __name(Header, "Header");
|
|
|
965
860
|
function Define(key, value) {
|
|
966
861
|
return (target, k) => {
|
|
967
862
|
if (k) {
|
|
968
|
-
(0,
|
|
969
|
-
(0,
|
|
863
|
+
(0, import_phecda_core5.setModalVar)(target, k);
|
|
864
|
+
(0, import_phecda_core5.mergeState)(target, k, {
|
|
970
865
|
define: {
|
|
971
866
|
[key]: value
|
|
972
867
|
}
|
|
973
868
|
});
|
|
974
869
|
} else {
|
|
975
|
-
(0,
|
|
976
|
-
(0,
|
|
870
|
+
(0, import_phecda_core5.setModalVar)(target.prototype, "__CLASS");
|
|
871
|
+
(0, import_phecda_core5.mergeState)(target.prototype, "__CLASS", {
|
|
977
872
|
define: {
|
|
978
873
|
[key]: value
|
|
979
874
|
}
|
|
@@ -985,167 +880,13 @@ __name(Define, "Define");
|
|
|
985
880
|
|
|
986
881
|
// src/index.ts
|
|
987
882
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
988
|
-
|
|
989
|
-
// src/config.ts
|
|
990
|
-
var Pconfig = {
|
|
991
|
-
rabbitmq: {
|
|
992
|
-
guard: false,
|
|
993
|
-
interceptor: false
|
|
994
|
-
}
|
|
995
|
-
};
|
|
996
|
-
|
|
997
|
-
// src/micro-services/rabbitmq.ts
|
|
998
|
-
async function bindMQ(ch, { meta, moduleMap }) {
|
|
999
|
-
for (const item of meta) {
|
|
1000
|
-
const { route, name, method, mq: { routeKey, queue: queueName, options } = {} } = item.data;
|
|
1001
|
-
const tag = `${name}-${method}`;
|
|
1002
|
-
Context.metaRecord[tag] = item;
|
|
1003
|
-
const { guards, reflect, interceptors, params } = Context.metaDataRecord[tag] ? Context.metaDataRecord[tag] : Context.metaDataRecord[tag] = parseMeta(item);
|
|
1004
|
-
const instance = moduleMap.get(name);
|
|
1005
|
-
const handler = instance[method].bind(instance);
|
|
1006
|
-
Context.instanceRecord[name] = instance;
|
|
1007
|
-
if (route) {
|
|
1008
|
-
const { queue } = await ch.assertQueue(route.route);
|
|
1009
|
-
if (queueName && routeKey)
|
|
1010
|
-
await ch.bindQueue(queue, queueName, routeKey);
|
|
1011
|
-
ch.consume(route.route, async (msg) => {
|
|
1012
|
-
if (msg !== null) {
|
|
1013
|
-
const content = msg.content.toString();
|
|
1014
|
-
const data = params.length > 0 ? JSON.parse(content) : content;
|
|
1015
|
-
const contextMeta = {
|
|
1016
|
-
message: msg,
|
|
1017
|
-
content,
|
|
1018
|
-
channel: ch
|
|
1019
|
-
};
|
|
1020
|
-
const context = new RabbitMqContext(tag, contextMeta);
|
|
1021
|
-
try {
|
|
1022
|
-
if (Pconfig.rabbitmq.guard)
|
|
1023
|
-
await context.useGuard(guards);
|
|
1024
|
-
if (Pconfig.rabbitmq.interceptor)
|
|
1025
|
-
await context.useInterceptor(interceptors);
|
|
1026
|
-
const args = await context.usePipe(params.map(({ key, validate }) => {
|
|
1027
|
-
return {
|
|
1028
|
-
arg: resolveDep(data, key),
|
|
1029
|
-
validate
|
|
1030
|
-
};
|
|
1031
|
-
}), reflect);
|
|
1032
|
-
instance.meta = contextMeta;
|
|
1033
|
-
await context.usePost(await handler(...args));
|
|
1034
|
-
ch.ack(msg);
|
|
1035
|
-
} catch (e) {
|
|
1036
|
-
item.handlers.forEach((handler2) => handler2.error?.(e));
|
|
1037
|
-
context.useFilter(e);
|
|
1038
|
-
}
|
|
1039
|
-
} else {
|
|
1040
|
-
}
|
|
1041
|
-
}, options);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
__name(bindMQ, "bindMQ");
|
|
1046
|
-
async function createPub(ch, method, type) {
|
|
1047
|
-
const { exchange, routeKey, queue } = method();
|
|
1048
|
-
if (exchange)
|
|
1049
|
-
await ch.assertExchange(exchange, type);
|
|
1050
|
-
else
|
|
1051
|
-
await ch.assertQueue(queue);
|
|
1052
|
-
return async (arg) => {
|
|
1053
|
-
const { args } = method(arg);
|
|
1054
|
-
const msg = Buffer.from(JSON.stringify(args));
|
|
1055
|
-
if (exchange)
|
|
1056
|
-
await ch.publish(exchange, routeKey, msg);
|
|
1057
|
-
else
|
|
1058
|
-
await ch.sendToQueue(queue, msg);
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
__name(createPub, "createPub");
|
|
1062
|
-
|
|
1063
|
-
// src/client/axios.ts
|
|
1064
|
-
function toReq(arg) {
|
|
1065
|
-
const { body, query, realParam, method, url } = arg;
|
|
1066
|
-
return {
|
|
1067
|
-
method,
|
|
1068
|
-
url,
|
|
1069
|
-
body,
|
|
1070
|
-
query: Object.keys(query).length > 0 ? `?${Object.entries(query).map(([k, v]) => `${k}=${v}`).join("&")}` : "",
|
|
1071
|
-
params: realParam
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
__name(toReq, "toReq");
|
|
1075
|
-
var merge = /* @__PURE__ */ __name((...args) => {
|
|
1076
|
-
const ret = [];
|
|
1077
|
-
for (const i of args) {
|
|
1078
|
-
const { body, query, params, tag } = i;
|
|
1079
|
-
ret.push({
|
|
1080
|
-
tag,
|
|
1081
|
-
body,
|
|
1082
|
-
query,
|
|
1083
|
-
params
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
return ret;
|
|
1087
|
-
}, "merge");
|
|
1088
|
-
function createReq(instance) {
|
|
1089
|
-
return (arg, config) => {
|
|
1090
|
-
const { url, params, query, body, method } = toReq(arg);
|
|
1091
|
-
if (!method) {
|
|
1092
|
-
console.warn("methods without route decorator won't send request");
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
const ret = [
|
|
1096
|
-
`${url}${params}${query}`
|
|
1097
|
-
];
|
|
1098
|
-
body && ret.push(body);
|
|
1099
|
-
config && ret.push(config);
|
|
1100
|
-
return instance[method](...ret);
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
__name(createReq, "createReq");
|
|
1104
|
-
function createSeriesReq(instance, key = "/__PHECDA_SERVER__") {
|
|
1105
|
-
return (args, config) => {
|
|
1106
|
-
return instance.post(key, {
|
|
1107
|
-
category: "series",
|
|
1108
|
-
data: merge(...args)
|
|
1109
|
-
}, config);
|
|
1110
|
-
};
|
|
1111
|
-
}
|
|
1112
|
-
__name(createSeriesReq, "createSeriesReq");
|
|
1113
|
-
function createParallelReq(instance, key = "/__PHECDA_SERVER__") {
|
|
1114
|
-
return (args, config) => {
|
|
1115
|
-
return instance.post(key, {
|
|
1116
|
-
category: "parallel",
|
|
1117
|
-
data: merge(...args)
|
|
1118
|
-
}, config);
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
__name(createParallelReq, "createParallelReq");
|
|
1122
|
-
function isError(data) {
|
|
1123
|
-
return typeof data === "object" && data.error;
|
|
1124
|
-
}
|
|
1125
|
-
__name(isError, "isError");
|
|
1126
|
-
function $S(index, key = "") {
|
|
1127
|
-
return `${SERIES_SYMBOL}@${index}@${key}`;
|
|
1128
|
-
}
|
|
1129
|
-
__name($S, "$S");
|
|
1130
|
-
|
|
1131
|
-
// src/client/server.ts
|
|
1132
|
-
function createMqReq(channel) {
|
|
1133
|
-
return async (arg) => {
|
|
1134
|
-
const { url, body } = arg;
|
|
1135
|
-
await channel.assertQueue(url);
|
|
1136
|
-
await channel.sendToQueue(url, Buffer.from(JSON.stringify(body)));
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
__name(createMqReq, "createMqReq");
|
|
1140
883
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1141
884
|
0 && (module.exports = {
|
|
1142
|
-
$S,
|
|
1143
885
|
BadGatewayException,
|
|
1144
886
|
BadRequestException,
|
|
1145
887
|
Base,
|
|
1146
888
|
BaseParam,
|
|
1147
889
|
Body,
|
|
1148
|
-
Compiler,
|
|
1149
890
|
ConflictException,
|
|
1150
891
|
Context,
|
|
1151
892
|
Controller,
|
|
@@ -1161,7 +902,7 @@ __name(createMqReq, "createMqReq");
|
|
|
1161
902
|
Inject,
|
|
1162
903
|
Interceptor,
|
|
1163
904
|
InvalidInputException,
|
|
1164
|
-
|
|
905
|
+
MERGE_SYMBOL,
|
|
1165
906
|
Meta,
|
|
1166
907
|
Middle,
|
|
1167
908
|
NotFoundException,
|
|
@@ -1170,8 +911,8 @@ __name(createMqReq, "createMqReq");
|
|
|
1170
911
|
Post,
|
|
1171
912
|
Put,
|
|
1172
913
|
Query,
|
|
1173
|
-
RabbitMqContext,
|
|
1174
914
|
Route,
|
|
915
|
+
SERIES_SYMBOL,
|
|
1175
916
|
ServerContext,
|
|
1176
917
|
ServiceUnavailableException,
|
|
1177
918
|
TimeoutException,
|
|
@@ -1183,21 +924,15 @@ __name(createMqReq, "createMqReq");
|
|
|
1183
924
|
addInterceptor,
|
|
1184
925
|
addMiddleware,
|
|
1185
926
|
bindApp,
|
|
1186
|
-
bindMQ,
|
|
1187
|
-
createMqReq,
|
|
1188
|
-
createParallelReq,
|
|
1189
|
-
createPub,
|
|
1190
|
-
createReq,
|
|
1191
|
-
createSeriesReq,
|
|
1192
927
|
defaultPipe,
|
|
1193
928
|
emitter,
|
|
1194
929
|
getInstance,
|
|
1195
|
-
|
|
1196
|
-
|
|
930
|
+
isMerge,
|
|
931
|
+
isNil,
|
|
932
|
+
isObject,
|
|
933
|
+
isUndefined,
|
|
1197
934
|
parseMeta,
|
|
1198
|
-
|
|
1199
|
-
useMqFilter,
|
|
1200
|
-
useMqPipe,
|
|
935
|
+
resolveDep,
|
|
1201
936
|
useServerFilter,
|
|
1202
937
|
useServerPipe
|
|
1203
938
|
});
|