phecda-server 5.2.4 → 5.2.5
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/{chunk-VYDBNZJ2.mjs → chunk-2NTXVYQC.mjs} +1 -8
- package/dist/{chunk-Q4AGVGVA.mjs → chunk-2O6X54P5.mjs} +103 -105
- package/dist/{chunk-AWY6FTH4.js → chunk-6QLTBEXP.js} +70 -86
- package/dist/{chunk-H6NYBVBV.js → chunk-6T4UZ4LV.js} +130 -132
- package/dist/{chunk-FNJWO324.js → chunk-H2FWLKXN.js} +2 -9
- package/dist/{chunk-IJNA24EZ.mjs → chunk-JJJ7AUEF.mjs} +39 -55
- package/dist/{chunk-LGP5AT6W.mjs → chunk-MGADYFW4.mjs} +28 -49
- package/dist/{chunk-UJAI73O6.js → chunk-MKZOLLJS.js} +39 -60
- package/dist/core-BIm7dkko.d.mts +27 -0
- package/dist/{core-7f6d2be6.d.ts → core-C3cON4Um.d.ts} +1 -1
- package/dist/helper.d.mts +27 -0
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/index.d.mts +246 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +73 -64
- package/dist/index.mjs +48 -39
- package/dist/rpc/bullmq/index.d.mts +21 -0
- package/dist/rpc/bullmq/index.d.ts +4 -4
- package/dist/rpc/bullmq/index.js +30 -43
- package/dist/rpc/bullmq/index.mjs +20 -33
- package/dist/rpc/kafka/index.d.mts +24 -0
- package/dist/rpc/kafka/index.d.ts +4 -4
- package/dist/rpc/kafka/index.js +25 -34
- package/dist/rpc/kafka/index.mjs +17 -26
- package/dist/rpc/nats/index.d.mts +15 -0
- package/dist/rpc/nats/index.d.ts +4 -4
- package/dist/rpc/nats/index.js +33 -46
- package/dist/rpc/nats/index.mjs +24 -37
- package/dist/rpc/rabbitmq/index.d.mts +16 -0
- package/dist/rpc/rabbitmq/index.d.ts +4 -4
- package/dist/rpc/rabbitmq/index.js +34 -46
- package/dist/rpc/rabbitmq/index.mjs +23 -35
- package/dist/rpc/redis/index.d.mts +23 -0
- package/dist/rpc/redis/index.d.ts +4 -4
- package/dist/rpc/redis/index.js +27 -38
- package/dist/rpc/redis/index.mjs +18 -29
- package/dist/server/elysia/index.d.mts +18 -0
- package/dist/server/elysia/index.d.ts +4 -4
- package/dist/server/elysia/index.js +22 -27
- package/dist/server/elysia/index.mjs +8 -13
- package/dist/server/express/index.d.mts +18 -0
- package/dist/server/express/index.d.ts +4 -4
- package/dist/server/express/index.js +24 -33
- package/dist/server/express/index.mjs +11 -20
- package/dist/server/fastify/index.d.mts +20 -0
- package/dist/server/fastify/index.d.ts +4 -4
- package/dist/server/fastify/index.js +23 -30
- package/dist/server/fastify/index.mjs +10 -17
- package/dist/server/h3/index.d.mts +16 -0
- package/dist/server/h3/index.d.ts +4 -4
- package/dist/server/h3/index.js +21 -25
- package/dist/server/h3/index.mjs +10 -14
- package/dist/server/hono/index.d.mts +16 -0
- package/dist/server/hono/index.d.ts +4 -4
- package/dist/server/hono/index.js +22 -30
- package/dist/server/hono/index.mjs +10 -18
- package/dist/server/hyper-express/index.d.mts +18 -0
- package/dist/server/hyper-express/index.d.ts +4 -4
- package/dist/server/hyper-express/index.js +23 -32
- package/dist/server/hyper-express/index.mjs +11 -20
- package/dist/server/koa/index.d.mts +18 -0
- package/dist/server/koa/index.d.ts +4 -4
- package/dist/server/koa/index.js +22 -29
- package/dist/server/koa/index.mjs +9 -16
- package/dist/test.d.mts +18 -0
- package/dist/test.d.ts +3 -3
- package/dist/test.js +14 -22
- package/dist/test.mjs +10 -18
- package/dist/types-B-y2TwhC.d.mts +17 -0
- package/dist/types-ByP1fKMe.d.mts +27 -0
- package/dist/{types-0a76c4bc.d.ts → types-C5sdDiDQ.d.ts} +2 -2
- package/dist/{types-f3b79218.d.ts → types-CIZbw8S2.d.ts} +2 -2
- package/dist/{types-81be0ba3.d.ts → types-CdQey96H.d.mts} +1 -1
- package/dist/types-CdQey96H.d.ts +108 -0
- package/package.json +3 -3
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
-
var __publicField = (obj, key, value) => {
|
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
8
3
|
|
|
9
4
|
// src/common.ts
|
|
10
5
|
var UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
|
|
@@ -34,8 +29,7 @@ function log(msg, level = "log") {
|
|
|
34
29
|
warn: 2,
|
|
35
30
|
error: 3
|
|
36
31
|
}[level];
|
|
37
|
-
if (logLevel < LOG_LEVEL)
|
|
38
|
-
return;
|
|
32
|
+
if (logLevel < LOG_LEVEL) return;
|
|
39
33
|
const color = {
|
|
40
34
|
error: "red",
|
|
41
35
|
info: "gray",
|
|
@@ -61,7 +55,6 @@ __name(Mix, "Mix");
|
|
|
61
55
|
|
|
62
56
|
export {
|
|
63
57
|
__name,
|
|
64
|
-
__publicField,
|
|
65
58
|
UNMOUNT_SYMBOL,
|
|
66
59
|
ERROR_SYMBOL,
|
|
67
60
|
IS_HMR,
|
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
IS_STRICT,
|
|
5
5
|
LOG_LEVEL,
|
|
6
6
|
__name,
|
|
7
|
-
__publicField,
|
|
8
7
|
log
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2NTXVYQC.mjs";
|
|
10
9
|
|
|
11
10
|
// src/helper.ts
|
|
12
11
|
import pc from "picocolors";
|
|
@@ -19,6 +18,9 @@ import { isPhecda, plainToClass, transformInstance } from "phecda-core";
|
|
|
19
18
|
|
|
20
19
|
// src/exception/base.ts
|
|
21
20
|
var Exception = class extends Error {
|
|
21
|
+
static {
|
|
22
|
+
__name(this, "Exception");
|
|
23
|
+
}
|
|
22
24
|
message;
|
|
23
25
|
status;
|
|
24
26
|
description;
|
|
@@ -37,34 +39,32 @@ var Exception = class extends Error {
|
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
|
-
__name(Exception, "Exception");
|
|
41
42
|
|
|
42
43
|
// src/exception/validate.ts
|
|
43
44
|
var ValidateException = class extends Exception {
|
|
45
|
+
static {
|
|
46
|
+
__name(this, "ValidateException");
|
|
47
|
+
}
|
|
44
48
|
constructor(message) {
|
|
45
49
|
super(message, 400, "Validate exception");
|
|
46
50
|
}
|
|
47
51
|
};
|
|
48
|
-
__name(ValidateException, "ValidateException");
|
|
49
52
|
|
|
50
53
|
// src/pipe.ts
|
|
51
54
|
var defaultPipe = /* @__PURE__ */ __name(({ arg, reflect, index }) => {
|
|
52
55
|
if (isPhecda(reflect)) {
|
|
53
56
|
const instance = plainToClass(reflect, arg);
|
|
54
57
|
const err = transformInstance(instance);
|
|
55
|
-
if (err.length > 0)
|
|
56
|
-
throw new ValidateException(err[0]);
|
|
58
|
+
if (err.length > 0) throw new ValidateException(err[0]);
|
|
57
59
|
arg = instance;
|
|
58
60
|
} else {
|
|
59
|
-
if (arg === void 0 && !reflect)
|
|
60
|
-
return void 0;
|
|
61
|
+
if (arg === void 0 && !reflect) return void 0;
|
|
61
62
|
if ([
|
|
62
63
|
Number,
|
|
63
64
|
Boolean
|
|
64
65
|
].includes(reflect)) {
|
|
65
66
|
arg = reflect(arg);
|
|
66
|
-
if (reflect === Number && Object.is(arg, NaN))
|
|
67
|
-
throw new ValidateException(`parameter ${Number(index) + 1} should be a number`);
|
|
67
|
+
if (reflect === Number && Object.is(arg, NaN)) throw new ValidateException(`parameter ${Number(index) + 1} should be a number`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return arg;
|
|
@@ -72,145 +72,185 @@ var defaultPipe = /* @__PURE__ */ __name(({ arg, reflect, index }) => {
|
|
|
72
72
|
|
|
73
73
|
// src/exception/undefine.ts
|
|
74
74
|
var UndefinedException = class extends Exception {
|
|
75
|
+
static {
|
|
76
|
+
__name(this, "UndefinedException");
|
|
77
|
+
}
|
|
75
78
|
constructor(message) {
|
|
76
79
|
super(message, 500, "Undefined error");
|
|
77
80
|
}
|
|
78
81
|
};
|
|
79
|
-
__name(UndefinedException, "UndefinedException");
|
|
80
82
|
|
|
81
83
|
// src/exception/forbidden.ts
|
|
82
84
|
var ForbiddenException = class extends Exception {
|
|
85
|
+
static {
|
|
86
|
+
__name(this, "ForbiddenException");
|
|
87
|
+
}
|
|
83
88
|
constructor(message) {
|
|
84
89
|
super(message, 403, "Forbidden resource");
|
|
85
90
|
}
|
|
86
91
|
};
|
|
87
|
-
__name(ForbiddenException, "ForbiddenException");
|
|
88
92
|
|
|
89
93
|
// src/exception/bad-request.ts
|
|
90
94
|
var BadRequestException = class extends Exception {
|
|
95
|
+
static {
|
|
96
|
+
__name(this, "BadRequestException");
|
|
97
|
+
}
|
|
91
98
|
constructor(message) {
|
|
92
99
|
super(message, 400, "Bad Request");
|
|
93
100
|
}
|
|
94
101
|
};
|
|
95
|
-
__name(BadRequestException, "BadRequestException");
|
|
96
102
|
|
|
97
103
|
// src/exception/not-found.ts
|
|
98
104
|
var NotFoundException = class extends Exception {
|
|
105
|
+
static {
|
|
106
|
+
__name(this, "NotFoundException");
|
|
107
|
+
}
|
|
99
108
|
constructor(message) {
|
|
100
109
|
super(message, 404, "Not Found");
|
|
101
110
|
}
|
|
102
111
|
};
|
|
103
|
-
__name(NotFoundException, "NotFoundException");
|
|
104
112
|
|
|
105
113
|
// src/exception/conflict.ts
|
|
106
114
|
var ConflictException = class extends Exception {
|
|
115
|
+
static {
|
|
116
|
+
__name(this, "ConflictException");
|
|
117
|
+
}
|
|
107
118
|
constructor(message) {
|
|
108
119
|
super(message, 409, "Conflict");
|
|
109
120
|
}
|
|
110
121
|
};
|
|
111
|
-
__name(ConflictException, "ConflictException");
|
|
112
122
|
|
|
113
123
|
// src/exception/bad-gateway.ts
|
|
114
124
|
var BadGatewayException = class extends Exception {
|
|
125
|
+
static {
|
|
126
|
+
__name(this, "BadGatewayException");
|
|
127
|
+
}
|
|
115
128
|
constructor(message) {
|
|
116
129
|
super(message, 502, "Bad Gatrway");
|
|
117
130
|
}
|
|
118
131
|
};
|
|
119
|
-
__name(BadGatewayException, "BadGatewayException");
|
|
120
132
|
|
|
121
133
|
// src/exception/invalid-input.ts
|
|
122
134
|
var InvalidInputException = class extends Exception {
|
|
135
|
+
static {
|
|
136
|
+
__name(this, "InvalidInputException");
|
|
137
|
+
}
|
|
123
138
|
constructor(message) {
|
|
124
139
|
super(message, 502, "Invalid Input");
|
|
125
140
|
}
|
|
126
141
|
};
|
|
127
|
-
__name(InvalidInputException, "InvalidInputException");
|
|
128
142
|
|
|
129
143
|
// src/exception/media-type.ts
|
|
130
144
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
145
|
+
static {
|
|
146
|
+
__name(this, "UnsupportedMediaTypeException");
|
|
147
|
+
}
|
|
131
148
|
constructor(message) {
|
|
132
149
|
super(message, 415, "Unsupported Media Type");
|
|
133
150
|
}
|
|
134
151
|
};
|
|
135
|
-
__name(UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
|
|
136
152
|
|
|
137
153
|
// src/exception/payload-large.ts
|
|
138
154
|
var PayloadLargeException = class extends Exception {
|
|
155
|
+
static {
|
|
156
|
+
__name(this, "PayloadLargeException");
|
|
157
|
+
}
|
|
139
158
|
constructor(message) {
|
|
140
159
|
super(message, 413, "Payload Too Large");
|
|
141
160
|
}
|
|
142
161
|
};
|
|
143
|
-
__name(PayloadLargeException, "PayloadLargeException");
|
|
144
162
|
|
|
145
163
|
// src/exception/timeout.ts
|
|
146
164
|
var TimeoutException = class extends Exception {
|
|
165
|
+
static {
|
|
166
|
+
__name(this, "TimeoutException");
|
|
167
|
+
}
|
|
147
168
|
constructor(message) {
|
|
148
169
|
super(message, 408, "Request Timeout");
|
|
149
170
|
}
|
|
150
171
|
};
|
|
151
|
-
__name(TimeoutException, "TimeoutException");
|
|
152
172
|
|
|
153
173
|
// src/exception/unauthorized.ts
|
|
154
174
|
var UnauthorizedException = class extends Exception {
|
|
175
|
+
static {
|
|
176
|
+
__name(this, "UnauthorizedException");
|
|
177
|
+
}
|
|
155
178
|
constructor(message) {
|
|
156
179
|
super(message, 401, "Unauthorized");
|
|
157
180
|
}
|
|
158
181
|
};
|
|
159
|
-
__name(UnauthorizedException, "UnauthorizedException");
|
|
160
182
|
|
|
161
183
|
// src/exception/unavailable-service.ts
|
|
162
184
|
var ServiceUnavailableException = class extends Exception {
|
|
185
|
+
static {
|
|
186
|
+
__name(this, "ServiceUnavailableException");
|
|
187
|
+
}
|
|
163
188
|
constructor(message) {
|
|
164
189
|
super(message, 503, "Service Unavailable");
|
|
165
190
|
}
|
|
166
191
|
};
|
|
167
|
-
__name(ServiceUnavailableException, "ServiceUnavailableException");
|
|
168
192
|
|
|
169
193
|
// src/exception/framework.ts
|
|
170
194
|
var FrameworkException = class extends Exception {
|
|
195
|
+
static {
|
|
196
|
+
__name(this, "FrameworkException");
|
|
197
|
+
}
|
|
171
198
|
constructor(message) {
|
|
172
199
|
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
173
200
|
}
|
|
174
201
|
};
|
|
175
|
-
__name(FrameworkException, "FrameworkException");
|
|
176
202
|
|
|
177
203
|
// src/exception/timer.ts
|
|
178
204
|
var TimerException = class extends Exception {
|
|
205
|
+
static {
|
|
206
|
+
__name(this, "TimerException");
|
|
207
|
+
}
|
|
179
208
|
constructor(message) {
|
|
180
209
|
super(message, 0, "Timer Error");
|
|
181
210
|
}
|
|
182
211
|
};
|
|
183
|
-
__name(TimerException, "TimerException");
|
|
184
212
|
|
|
185
213
|
// src/exception/worker.ts
|
|
186
214
|
var WorkerException = class extends Exception {
|
|
215
|
+
static {
|
|
216
|
+
__name(this, "WorkerException");
|
|
217
|
+
}
|
|
187
218
|
constructor(message) {
|
|
188
219
|
super(message, 0, "Worker Error");
|
|
189
220
|
}
|
|
190
221
|
};
|
|
191
|
-
__name(WorkerException, "WorkerException");
|
|
192
222
|
|
|
193
223
|
// src/filter.ts
|
|
194
224
|
var defaultFilter = /* @__PURE__ */ __name((e) => {
|
|
195
225
|
if (!(e instanceof Exception)) {
|
|
196
226
|
log(e.message, "error");
|
|
197
|
-
if (LOG_LEVEL <= 0)
|
|
198
|
-
console.error(e.stack);
|
|
227
|
+
if (LOG_LEVEL <= 0) console.error(e.stack);
|
|
199
228
|
e = new UndefinedException(e.message || e);
|
|
200
229
|
} else {
|
|
201
230
|
log(`[${e.constructor.name}] ${e.message}`, "error");
|
|
202
|
-
if (LOG_LEVEL <= 0)
|
|
203
|
-
console.error(e.stack);
|
|
231
|
+
if (LOG_LEVEL <= 0) console.error(e.stack);
|
|
204
232
|
}
|
|
205
233
|
return e.data;
|
|
206
234
|
}, "defaultFilter");
|
|
207
235
|
|
|
208
236
|
// src/context.ts
|
|
209
237
|
var debug = Debug("phecda-server(Context)");
|
|
210
|
-
var
|
|
238
|
+
var Context = class _Context {
|
|
239
|
+
static {
|
|
240
|
+
__name(this, "Context");
|
|
241
|
+
}
|
|
211
242
|
data;
|
|
212
243
|
method;
|
|
213
244
|
params;
|
|
245
|
+
static filterRecord = {
|
|
246
|
+
default: defaultFilter
|
|
247
|
+
};
|
|
248
|
+
static pipeRecord = {
|
|
249
|
+
default: defaultPipe
|
|
250
|
+
};
|
|
251
|
+
static guardRecord = {};
|
|
252
|
+
static interceptorRecord = {};
|
|
253
|
+
static pluginRecord = {};
|
|
214
254
|
postInterceptors;
|
|
215
255
|
constructor(data) {
|
|
216
256
|
this.data = data;
|
|
@@ -230,8 +270,7 @@ var _Context = class {
|
|
|
230
270
|
...globalInterceptors,
|
|
231
271
|
...interceptors
|
|
232
272
|
]);
|
|
233
|
-
if (i1 !== void 0)
|
|
234
|
-
return successCb(i1);
|
|
273
|
+
if (i1 !== void 0) return successCb(i1);
|
|
235
274
|
const args = await this.usePipe(params.map((param) => {
|
|
236
275
|
return {
|
|
237
276
|
arg: resolveDep(this.data[param.type], param.key),
|
|
@@ -246,8 +285,7 @@ var _Context = class {
|
|
|
246
285
|
}
|
|
247
286
|
const returnData = await instance[func](...args);
|
|
248
287
|
const i2 = await this.usePostInterceptor(returnData);
|
|
249
|
-
if (i2 !== void 0)
|
|
250
|
-
return successCb(i2);
|
|
288
|
+
if (i2 !== void 0) return successCb(i2);
|
|
251
289
|
return successCb(returnData);
|
|
252
290
|
} catch (e) {
|
|
253
291
|
const err = await this.useFilter(e, filter || globalFilter);
|
|
@@ -281,39 +319,31 @@ var _Context = class {
|
|
|
281
319
|
async useGuard(guards) {
|
|
282
320
|
for (const guard of new Set(guards)) {
|
|
283
321
|
if (!(guard in _Context.guardRecord)) {
|
|
284
|
-
if (IS_STRICT)
|
|
285
|
-
|
|
286
|
-
else
|
|
287
|
-
debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
322
|
+
if (IS_STRICT) throw new FrameworkException(`Can't find guard named "${guard}"`);
|
|
323
|
+
else debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
288
324
|
continue;
|
|
289
325
|
}
|
|
290
|
-
if (!await _Context.guardRecord[guard](this.data))
|
|
291
|
-
throw new ForbiddenException(`Guard exception--[${guard}]`);
|
|
326
|
+
if (!await _Context.guardRecord[guard](this.data)) throw new ForbiddenException(`Guard exception--[${guard}]`);
|
|
292
327
|
}
|
|
293
328
|
}
|
|
294
329
|
async usePostInterceptor(data) {
|
|
295
330
|
for (const cb of this.postInterceptors) {
|
|
296
331
|
const ret = await cb(data);
|
|
297
|
-
if (ret !== void 0)
|
|
298
|
-
return ret;
|
|
332
|
+
if (ret !== void 0) return ret;
|
|
299
333
|
}
|
|
300
334
|
}
|
|
301
335
|
async useInterceptor(interceptors) {
|
|
302
336
|
const cb = [];
|
|
303
337
|
for (const interceptor of new Set(interceptors)) {
|
|
304
338
|
if (!(interceptor in _Context.interceptorRecord)) {
|
|
305
|
-
if (IS_STRICT)
|
|
306
|
-
|
|
307
|
-
else
|
|
308
|
-
debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
339
|
+
if (IS_STRICT) throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
|
|
340
|
+
else debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
309
341
|
continue;
|
|
310
342
|
}
|
|
311
343
|
const interceptRet = await _Context.interceptorRecord[interceptor](this.data);
|
|
312
344
|
if (interceptRet !== void 0) {
|
|
313
|
-
if (typeof interceptRet === "function")
|
|
314
|
-
|
|
315
|
-
else
|
|
316
|
-
return interceptRet;
|
|
345
|
+
if (typeof interceptRet === "function") cb.push(interceptRet);
|
|
346
|
+
else return interceptRet;
|
|
317
347
|
}
|
|
318
348
|
}
|
|
319
349
|
this.postInterceptors = cb;
|
|
@@ -322,8 +352,7 @@ var _Context = class {
|
|
|
322
352
|
const ret = [];
|
|
323
353
|
for (const m of new Set(plugins)) {
|
|
324
354
|
if (!(m in _Context.pluginRecord)) {
|
|
325
|
-
if (IS_STRICT)
|
|
326
|
-
throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
355
|
+
if (IS_STRICT) throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
327
356
|
continue;
|
|
328
357
|
}
|
|
329
358
|
const plugin = _Context.pluginRecord[m](framework);
|
|
@@ -332,59 +361,41 @@ var _Context = class {
|
|
|
332
361
|
return ret;
|
|
333
362
|
}
|
|
334
363
|
};
|
|
335
|
-
var Context = _Context;
|
|
336
|
-
__name(Context, "Context");
|
|
337
|
-
__publicField(Context, "filterRecord", {
|
|
338
|
-
default: defaultFilter
|
|
339
|
-
});
|
|
340
|
-
__publicField(Context, "pipeRecord", {
|
|
341
|
-
default: defaultPipe
|
|
342
|
-
});
|
|
343
|
-
__publicField(Context, "guardRecord", {});
|
|
344
|
-
__publicField(Context, "interceptorRecord", {});
|
|
345
|
-
__publicField(Context, "pluginRecord", {});
|
|
346
364
|
function addPlugin(key, handler) {
|
|
347
|
-
if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler)
|
|
348
|
-
log(`overwrite Plugin "${String(key)}"`, "warn");
|
|
365
|
+
if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler) log(`overwrite Plugin "${String(key)}"`, "warn");
|
|
349
366
|
Context.pluginRecord[key] = handler;
|
|
350
367
|
}
|
|
351
368
|
__name(addPlugin, "addPlugin");
|
|
352
369
|
function addPipe(key, handler) {
|
|
353
|
-
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)
|
|
354
|
-
log(`overwrite Pipe "${String(key)}"`, "warn");
|
|
370
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler) log(`overwrite Pipe "${String(key)}"`, "warn");
|
|
355
371
|
Context.pipeRecord[key] = handler;
|
|
356
372
|
}
|
|
357
373
|
__name(addPipe, "addPipe");
|
|
358
374
|
function addFilter(key, handler) {
|
|
359
|
-
if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)
|
|
360
|
-
log(`overwrite Filter "${String(key)}"`, "warn");
|
|
375
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== handler) log(`overwrite Filter "${String(key)}"`, "warn");
|
|
361
376
|
Context.filterRecord[key] = handler;
|
|
362
377
|
}
|
|
363
378
|
__name(addFilter, "addFilter");
|
|
364
379
|
function addGuard(key, handler) {
|
|
365
|
-
if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)
|
|
366
|
-
log(`overwrite Guard "${String(key)}"`, "warn");
|
|
380
|
+
if (Context.guardRecord[key] && Context.guardRecord[key] !== handler) log(`overwrite Guard "${String(key)}"`, "warn");
|
|
367
381
|
Context.guardRecord[key] = handler;
|
|
368
382
|
}
|
|
369
383
|
__name(addGuard, "addGuard");
|
|
370
384
|
function addInterceptor(key, handler) {
|
|
371
|
-
if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)
|
|
372
|
-
log(`overwrite Interceptor "${String(key)}"`, "warn");
|
|
385
|
+
if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler) log(`overwrite Interceptor "${String(key)}"`, "warn");
|
|
373
386
|
Context.interceptorRecord[key] = handler;
|
|
374
387
|
}
|
|
375
388
|
__name(addInterceptor, "addInterceptor");
|
|
376
389
|
|
|
377
390
|
// src/hmr.ts
|
|
378
391
|
function HMR(cb) {
|
|
379
|
-
if (IS_HMR)
|
|
380
|
-
globalThis.__PS_HMR__?.push(cb);
|
|
392
|
+
if (IS_HMR) globalThis.__PS_HMR__?.push(cb);
|
|
381
393
|
}
|
|
382
394
|
__name(HMR, "HMR");
|
|
383
395
|
|
|
384
396
|
// src/server/helper.ts
|
|
385
397
|
function resolveDep(ret, key) {
|
|
386
|
-
if (key)
|
|
387
|
-
return ret?.[key];
|
|
398
|
+
if (key) return ret?.[key];
|
|
388
399
|
return ret;
|
|
389
400
|
}
|
|
390
401
|
__name(resolveDep, "resolveDep");
|
|
@@ -396,10 +407,8 @@ function argToReq(params, args, headers) {
|
|
|
396
407
|
headers
|
|
397
408
|
};
|
|
398
409
|
params.forEach((param) => {
|
|
399
|
-
if (param.key)
|
|
400
|
-
|
|
401
|
-
else
|
|
402
|
-
req[param.type] = args[param.index];
|
|
410
|
+
if (param.key) req[param.type][param.key] = args[param.index];
|
|
411
|
+
else req[param.type] = args[param.index];
|
|
403
412
|
});
|
|
404
413
|
return req;
|
|
405
414
|
}
|
|
@@ -431,14 +440,11 @@ function createControllerMetaMap(meta, filter) {
|
|
|
431
440
|
metaMap.clear();
|
|
432
441
|
for (const item of meta) {
|
|
433
442
|
const { tag, func } = item.data;
|
|
434
|
-
if (!filter(item))
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
metaMap.set(tag, {
|
|
440
|
-
[func]: item
|
|
441
|
-
});
|
|
443
|
+
if (!filter(item)) continue;
|
|
444
|
+
if (metaMap.has(tag)) metaMap.get(tag)[func] = item;
|
|
445
|
+
else metaMap.set(tag, {
|
|
446
|
+
[func]: item
|
|
447
|
+
});
|
|
442
448
|
}
|
|
443
449
|
}
|
|
444
450
|
__name(handleMeta, "handleMeta");
|
|
@@ -472,18 +478,15 @@ function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller =
|
|
|
472
478
|
});
|
|
473
479
|
meta.forEach(({ data }) => {
|
|
474
480
|
if (data.controller !== controller) {
|
|
475
|
-
if (data[controller])
|
|
476
|
-
warningSet.add(`Module "${data.tag === data.name ? data.name : `${data.name}(${data.tag})`}" should use ${controller} controller to decorate class or remove ${controller} decorator on method "${data.func}"`);
|
|
481
|
+
if (data[controller]) warningSet.add(`Module "${data.tag === data.name ? data.name : `${data.name}(${data.tag})`}" should use ${controller} controller to decorate class or remove ${controller} decorator on method "${data.func}"`);
|
|
477
482
|
return;
|
|
478
483
|
}
|
|
479
|
-
if (data.filter)
|
|
480
|
-
filterSet.add(data.filter);
|
|
484
|
+
if (data.filter) filterSet.add(data.filter);
|
|
481
485
|
data.interceptors.forEach((i) => interceptorSet.add(i));
|
|
482
486
|
data.guards.forEach((i) => guardSet.add(i));
|
|
483
487
|
data.plugins.forEach((i) => pluginSet.add(i));
|
|
484
488
|
data.params.forEach((i) => {
|
|
485
|
-
if (i.pipe)
|
|
486
|
-
pipeSet.add(i.pipe);
|
|
489
|
+
if (i.pipe) pipeSet.add(i.pipe);
|
|
487
490
|
});
|
|
488
491
|
});
|
|
489
492
|
const missPlugins = [
|
|
@@ -501,16 +504,11 @@ function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller =
|
|
|
501
504
|
const missFilters = [
|
|
502
505
|
...filterSet
|
|
503
506
|
].filter((i) => !Context.filterRecord[i]);
|
|
504
|
-
if (missPlugins.length)
|
|
505
|
-
|
|
506
|
-
if (
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
log(`${pc.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
510
|
-
if (missPipes.length)
|
|
511
|
-
log(`${pc.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
512
|
-
if (missFilters.length)
|
|
513
|
-
log(`${pc.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
507
|
+
if (missPlugins.length) log(`${pc.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
|
|
508
|
+
if (missGuards.length) log(`${pc.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
509
|
+
if (missInterceptors.length) log(`${pc.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
510
|
+
if (missPipes.length) log(`${pc.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
511
|
+
if (missFilters.length) log(`${pc.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
514
512
|
warningSet.forEach((warn) => log(warn, "warn"));
|
|
515
513
|
}
|
|
516
514
|
__name(handleMeta, "handleMeta");
|