phecda-server 4.0.4 → 4.0.6
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-YU7ROHTO.js → chunk-7OB6K45T.js} +78 -66
- package/dist/chunk-7OB6K45T.js.map +1 -0
- package/dist/{chunk-LZAU5FUS.js → chunk-AAF47ZC6.js} +9 -3
- package/dist/chunk-AAF47ZC6.js.map +1 -0
- package/dist/{chunk-AJ2HYENF.mjs → chunk-AYJWOIAW.mjs} +10 -4
- package/dist/chunk-AYJWOIAW.mjs.map +1 -0
- package/dist/{chunk-Q6T7HNEO.mjs → chunk-GSJ5A2MA.mjs} +43 -31
- package/dist/chunk-GSJ5A2MA.mjs.map +1 -0
- package/dist/{chunk-JUXEUWOU.mjs → chunk-K32VRTXB.mjs} +32 -18
- package/dist/chunk-K32VRTXB.mjs.map +1 -0
- package/dist/{chunk-W64EUEDU.js → chunk-TZ27DHWL.js} +51 -37
- package/dist/chunk-TZ27DHWL.js.map +1 -0
- package/dist/{chunk-JQPX546Z.mjs → chunk-V7SC5EVJ.mjs} +2 -2
- package/dist/{chunk-FAHHXHL5.js → chunk-ZPMAM4LQ.js} +3 -3
- package/dist/{core-7c2dd0c7.d.ts → core-c27b4cf4.d.ts} +3 -2
- package/dist/index.d.ts +45 -26
- package/dist/index.js +119 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -33
- package/dist/index.mjs.map +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +2 -2
- package/dist/rpc/rabbitmq/index.js +19 -13
- package/dist/rpc/rabbitmq/index.js.map +1 -1
- package/dist/rpc/rabbitmq/index.mjs +13 -7
- package/dist/rpc/rabbitmq/index.mjs.map +1 -1
- package/dist/rpc/redis/index.d.ts +2 -2
- package/dist/rpc/redis/index.js +19 -13
- package/dist/rpc/redis/index.js.map +1 -1
- package/dist/rpc/redis/index.mjs +13 -7
- package/dist/rpc/redis/index.mjs.map +1 -1
- package/dist/server/express/index.d.ts +4 -3
- package/dist/server/express/index.js +37 -29
- package/dist/server/express/index.js.map +1 -1
- package/dist/server/express/index.mjs +19 -11
- package/dist/server/express/index.mjs.map +1 -1
- package/dist/server/fastify/index.d.ts +3 -2
- package/dist/server/fastify/index.js +33 -25
- package/dist/server/fastify/index.js.map +1 -1
- package/dist/server/fastify/index.mjs +18 -10
- package/dist/server/fastify/index.mjs.map +1 -1
- package/dist/server/h3/index.d.ts +6 -5
- package/dist/server/h3/index.js +34 -28
- package/dist/server/h3/index.js.map +1 -1
- package/dist/server/h3/index.mjs +16 -10
- package/dist/server/h3/index.mjs.map +1 -1
- package/dist/server/koa/index.d.ts +3 -2
- package/dist/server/koa/index.js +36 -28
- package/dist/server/koa/index.js.map +1 -1
- package/dist/server/koa/index.mjs +18 -10
- package/dist/server/koa/index.mjs.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-ead02c5d.d.ts → types-8415bd5d.d.ts} +16 -17
- package/package.json +1 -1
- package/register/compile.mjs +3 -7
- package/register/loader.mjs +0 -1
- package/dist/chunk-AJ2HYENF.mjs.map +0 -1
- package/dist/chunk-JUXEUWOU.mjs.map +0 -1
- package/dist/chunk-LZAU5FUS.js.map +0 -1
- package/dist/chunk-Q6T7HNEO.mjs.map +0 -1
- package/dist/chunk-W64EUEDU.js.map +0 -1
- package/dist/chunk-YU7ROHTO.js.map +0 -1
- /package/dist/{chunk-JQPX546Z.mjs.map → chunk-V7SC5EVJ.mjs.map} +0 -0
- /package/dist/{chunk-FAHHXHL5.js.map → chunk-ZPMAM4LQ.js.map} +0 -0
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
var _chunkAAF47ZC6js = require('./chunk-AAF47ZC6.js');
|
|
8
9
|
|
|
9
10
|
// src/exception/base.ts
|
|
10
11
|
var Exception = class extends Error {
|
|
@@ -22,11 +23,11 @@ var Exception = class extends Error {
|
|
|
22
23
|
message: this.message,
|
|
23
24
|
description: this.description,
|
|
24
25
|
status: this.status,
|
|
25
|
-
|
|
26
|
+
[_chunkAAF47ZC6js.ERROR_SYMBOL]: true
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
+
_chunkAAF47ZC6js.__name.call(void 0, Exception, "Exception");
|
|
30
31
|
|
|
31
32
|
// src/exception/validate.ts
|
|
32
33
|
var ValidateException = class extends Exception {
|
|
@@ -34,11 +35,11 @@ var ValidateException = class extends Exception {
|
|
|
34
35
|
super(message, 400, "Validate exception");
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
+
_chunkAAF47ZC6js.__name.call(void 0, ValidateException, "ValidateException");
|
|
38
39
|
|
|
39
40
|
// src/pipe.ts
|
|
40
41
|
var _phecdacore = require('phecda-core');
|
|
41
|
-
var defaultPipe = /* @__PURE__ */
|
|
42
|
+
var defaultPipe = /* @__PURE__ */ _chunkAAF47ZC6js.__name.call(void 0, async ({ arg, reflect, index }) => {
|
|
42
43
|
if (_phecdacore.isPhecda.call(void 0, reflect)) {
|
|
43
44
|
const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
|
|
44
45
|
const err = await _phecdacore.transformClass.call(void 0, instance);
|
|
@@ -64,7 +65,7 @@ var UndefinedException = class extends Exception {
|
|
|
64
65
|
super(message, 500, "Undefined error");
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
|
-
|
|
68
|
+
_chunkAAF47ZC6js.__name.call(void 0, UndefinedException, "UndefinedException");
|
|
68
69
|
|
|
69
70
|
// src/exception/forbidden.ts
|
|
70
71
|
var ForbiddenException = class extends Exception {
|
|
@@ -72,7 +73,7 @@ var ForbiddenException = class extends Exception {
|
|
|
72
73
|
super(message, 403, "Forbidden resource");
|
|
73
74
|
}
|
|
74
75
|
};
|
|
75
|
-
|
|
76
|
+
_chunkAAF47ZC6js.__name.call(void 0, ForbiddenException, "ForbiddenException");
|
|
76
77
|
|
|
77
78
|
// src/exception/bad-request.ts
|
|
78
79
|
var BadRequestException = class extends Exception {
|
|
@@ -80,7 +81,7 @@ var BadRequestException = class extends Exception {
|
|
|
80
81
|
super(message, 400, "Bad Request");
|
|
81
82
|
}
|
|
82
83
|
};
|
|
83
|
-
|
|
84
|
+
_chunkAAF47ZC6js.__name.call(void 0, BadRequestException, "BadRequestException");
|
|
84
85
|
|
|
85
86
|
// src/exception/not-found.ts
|
|
86
87
|
var NotFoundException = class extends Exception {
|
|
@@ -88,7 +89,7 @@ var NotFoundException = class extends Exception {
|
|
|
88
89
|
super(message, 404, "Not Found");
|
|
89
90
|
}
|
|
90
91
|
};
|
|
91
|
-
|
|
92
|
+
_chunkAAF47ZC6js.__name.call(void 0, NotFoundException, "NotFoundException");
|
|
92
93
|
|
|
93
94
|
// src/exception/conflict.ts
|
|
94
95
|
var ConflictException = class extends Exception {
|
|
@@ -96,7 +97,7 @@ var ConflictException = class extends Exception {
|
|
|
96
97
|
super(message, 409, "Conflict");
|
|
97
98
|
}
|
|
98
99
|
};
|
|
99
|
-
|
|
100
|
+
_chunkAAF47ZC6js.__name.call(void 0, ConflictException, "ConflictException");
|
|
100
101
|
|
|
101
102
|
// src/exception/bad-gateway.ts
|
|
102
103
|
var BadGatewayException = class extends Exception {
|
|
@@ -104,7 +105,7 @@ var BadGatewayException = class extends Exception {
|
|
|
104
105
|
super(message, 502, "Bad Gatrway");
|
|
105
106
|
}
|
|
106
107
|
};
|
|
107
|
-
|
|
108
|
+
_chunkAAF47ZC6js.__name.call(void 0, BadGatewayException, "BadGatewayException");
|
|
108
109
|
|
|
109
110
|
// src/exception/invalid-input.ts
|
|
110
111
|
var InvalidInputException = class extends Exception {
|
|
@@ -112,7 +113,7 @@ var InvalidInputException = class extends Exception {
|
|
|
112
113
|
super(message, 502, "Invalid Input");
|
|
113
114
|
}
|
|
114
115
|
};
|
|
115
|
-
|
|
116
|
+
_chunkAAF47ZC6js.__name.call(void 0, InvalidInputException, "InvalidInputException");
|
|
116
117
|
|
|
117
118
|
// src/exception/media-type.ts
|
|
118
119
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
@@ -120,7 +121,7 @@ var UnsupportedMediaTypeException = class extends Exception {
|
|
|
120
121
|
super(message, 415, "Unsupported Media Type");
|
|
121
122
|
}
|
|
122
123
|
};
|
|
123
|
-
|
|
124
|
+
_chunkAAF47ZC6js.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
|
|
124
125
|
|
|
125
126
|
// src/exception/payload-large.ts
|
|
126
127
|
var PayloadLargeException = class extends Exception {
|
|
@@ -128,7 +129,7 @@ var PayloadLargeException = class extends Exception {
|
|
|
128
129
|
super(message, 413, "Payload Too Large");
|
|
129
130
|
}
|
|
130
131
|
};
|
|
131
|
-
|
|
132
|
+
_chunkAAF47ZC6js.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
|
|
132
133
|
|
|
133
134
|
// src/exception/timeout.ts
|
|
134
135
|
var TimeoutException = class extends Exception {
|
|
@@ -136,7 +137,7 @@ var TimeoutException = class extends Exception {
|
|
|
136
137
|
super(message, 408, "Request Timeout");
|
|
137
138
|
}
|
|
138
139
|
};
|
|
139
|
-
|
|
140
|
+
_chunkAAF47ZC6js.__name.call(void 0, TimeoutException, "TimeoutException");
|
|
140
141
|
|
|
141
142
|
// src/exception/unauthorized.ts
|
|
142
143
|
var UnauthorizedException = class extends Exception {
|
|
@@ -144,7 +145,7 @@ var UnauthorizedException = class extends Exception {
|
|
|
144
145
|
super(message, 401, "Unauthorized");
|
|
145
146
|
}
|
|
146
147
|
};
|
|
147
|
-
|
|
148
|
+
_chunkAAF47ZC6js.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
|
|
148
149
|
|
|
149
150
|
// src/exception/unavailable-service.ts
|
|
150
151
|
var ServiceUnavailableException = class extends Exception {
|
|
@@ -152,7 +153,7 @@ var ServiceUnavailableException = class extends Exception {
|
|
|
152
153
|
super(message, 503, "Service Unavailable");
|
|
153
154
|
}
|
|
154
155
|
};
|
|
155
|
-
|
|
156
|
+
_chunkAAF47ZC6js.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
|
|
156
157
|
|
|
157
158
|
// src/exception/framework.ts
|
|
158
159
|
var FrameworkException = class extends Exception {
|
|
@@ -160,19 +161,19 @@ var FrameworkException = class extends Exception {
|
|
|
160
161
|
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
161
162
|
}
|
|
162
163
|
};
|
|
163
|
-
|
|
164
|
+
_chunkAAF47ZC6js.__name.call(void 0, FrameworkException, "FrameworkException");
|
|
164
165
|
|
|
165
166
|
// src/context.ts
|
|
166
167
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
167
168
|
|
|
168
169
|
// src/filter.ts
|
|
169
|
-
var defaultFilter = /* @__PURE__ */
|
|
170
|
+
var defaultFilter = /* @__PURE__ */ _chunkAAF47ZC6js.__name.call(void 0, (e) => {
|
|
170
171
|
if (!(e instanceof Exception)) {
|
|
171
|
-
|
|
172
|
+
_chunkAAF47ZC6js.log.call(void 0, e.message, "error");
|
|
172
173
|
console.error(e.stack);
|
|
173
174
|
e = new UndefinedException(e.message || e);
|
|
174
175
|
} else {
|
|
175
|
-
|
|
176
|
+
_chunkAAF47ZC6js.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
176
177
|
console.error(e.stack);
|
|
177
178
|
}
|
|
178
179
|
return e.data;
|
|
@@ -190,7 +191,7 @@ var Histroy = (_class = class {constructor() { _class.prototype.__init.call(this
|
|
|
190
191
|
return false;
|
|
191
192
|
}
|
|
192
193
|
}, _class);
|
|
193
|
-
|
|
194
|
+
_chunkAAF47ZC6js.__name.call(void 0, Histroy, "Histroy");
|
|
194
195
|
|
|
195
196
|
// src/context.ts
|
|
196
197
|
var guardRecord = {};
|
|
@@ -205,13 +206,13 @@ var _Context = class {
|
|
|
205
206
|
this.tag = tag;
|
|
206
207
|
this.data = data;
|
|
207
208
|
this.history = new Histroy();
|
|
208
|
-
if (
|
|
209
|
+
if (_chunkAAF47ZC6js.IS_DEV)
|
|
209
210
|
data._context = this;
|
|
210
211
|
}
|
|
211
212
|
usePipe(args) {
|
|
212
213
|
return Promise.all(args.map((item) => {
|
|
213
214
|
if (item.pipe && !_Context.pipeRecord[item.pipe]) {
|
|
214
|
-
if (
|
|
215
|
+
if (_chunkAAF47ZC6js.IS_STRICT)
|
|
215
216
|
throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
|
|
216
217
|
else
|
|
217
218
|
return _Context.pipeRecord.default(item, this.tag, this.data);
|
|
@@ -219,14 +220,20 @@ var _Context = class {
|
|
|
219
220
|
return _Context.pipeRecord[item.pipe || "default"](item, this.tag, this.data);
|
|
220
221
|
}));
|
|
221
222
|
}
|
|
222
|
-
useFilter(arg) {
|
|
223
|
-
|
|
223
|
+
useFilter(arg, filter = "default") {
|
|
224
|
+
if (!_Context.filterRecord[filter]) {
|
|
225
|
+
if (_chunkAAF47ZC6js.IS_STRICT)
|
|
226
|
+
throw new FrameworkException(`can't find filter named '${filter}'`);
|
|
227
|
+
else
|
|
228
|
+
return _Context.filterRecord.default(arg, this.tag, this.data);
|
|
229
|
+
}
|
|
230
|
+
return _Context.filterRecord[filter](arg, this.tag, this.data);
|
|
224
231
|
}
|
|
225
232
|
async useGuard(guards) {
|
|
226
233
|
for (const guard of guards) {
|
|
227
234
|
if (this.history.record(guard, "guard")) {
|
|
228
235
|
if (!(guard in _Context.guardRecord)) {
|
|
229
|
-
if (
|
|
236
|
+
if (_chunkAAF47ZC6js.IS_STRICT)
|
|
230
237
|
throw new FrameworkException(`can't find guard named '${guard}'`);
|
|
231
238
|
continue;
|
|
232
239
|
}
|
|
@@ -245,7 +252,7 @@ var _Context = class {
|
|
|
245
252
|
for (const interceptor of interceptors) {
|
|
246
253
|
if (this.history.record(interceptor, "interceptor")) {
|
|
247
254
|
if (!(interceptor in _Context.interceptorRecord)) {
|
|
248
|
-
if (
|
|
255
|
+
if (_chunkAAF47ZC6js.IS_STRICT)
|
|
249
256
|
throw new FrameworkException(`can't find interceptor named '${interceptor}'`);
|
|
250
257
|
continue;
|
|
251
258
|
}
|
|
@@ -264,7 +271,7 @@ var _Context = class {
|
|
|
264
271
|
const ret = [];
|
|
265
272
|
for (const m of plugins) {
|
|
266
273
|
if (!(m in _Context.pluginRecord)) {
|
|
267
|
-
if (
|
|
274
|
+
if (_chunkAAF47ZC6js.IS_STRICT)
|
|
268
275
|
throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
269
276
|
continue;
|
|
270
277
|
}
|
|
@@ -274,40 +281,45 @@ var _Context = class {
|
|
|
274
281
|
}
|
|
275
282
|
};
|
|
276
283
|
var Context = _Context;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
_chunkAAF47ZC6js.__name.call(void 0, Context, "Context");
|
|
285
|
+
_chunkAAF47ZC6js.__publicField.call(void 0, Context, "filterRecord", {
|
|
286
|
+
default: defaultFilter
|
|
287
|
+
});
|
|
288
|
+
_chunkAAF47ZC6js.__publicField.call(void 0, Context, "pipeRecord", {
|
|
280
289
|
default: defaultPipe
|
|
281
290
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
291
|
+
_chunkAAF47ZC6js.__publicField.call(void 0, Context, "guardRecord", {});
|
|
292
|
+
_chunkAAF47ZC6js.__publicField.call(void 0, Context, "interceptorRecord", {});
|
|
293
|
+
_chunkAAF47ZC6js.__publicField.call(void 0, Context, "pluginRecord", {});
|
|
285
294
|
function addPlugin(key, handler) {
|
|
286
295
|
Context.pluginRecord[key] = handler;
|
|
287
296
|
}
|
|
288
|
-
|
|
297
|
+
_chunkAAF47ZC6js.__name.call(void 0, addPlugin, "addPlugin");
|
|
289
298
|
function addPipe(key, pipe) {
|
|
290
299
|
Context.pipeRecord[key] = pipe;
|
|
291
300
|
}
|
|
292
|
-
|
|
293
|
-
function
|
|
294
|
-
Context.
|
|
301
|
+
_chunkAAF47ZC6js.__name.call(void 0, addPipe, "addPipe");
|
|
302
|
+
function addFilter(key, handler) {
|
|
303
|
+
Context.filterRecord[key] = handler;
|
|
295
304
|
}
|
|
296
|
-
|
|
305
|
+
_chunkAAF47ZC6js.__name.call(void 0, addFilter, "addFilter");
|
|
297
306
|
function addGuard(key, handler) {
|
|
298
307
|
Context.guardRecord[key] = handler;
|
|
299
308
|
}
|
|
300
|
-
|
|
309
|
+
_chunkAAF47ZC6js.__name.call(void 0, addGuard, "addGuard");
|
|
301
310
|
function addInterceptor(key, handler) {
|
|
302
311
|
Context.interceptorRecord[key] = handler;
|
|
303
312
|
}
|
|
304
|
-
|
|
313
|
+
_chunkAAF47ZC6js.__name.call(void 0, addInterceptor, "addInterceptor");
|
|
305
314
|
function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
|
|
306
315
|
const pluginSet = new Set(plugins);
|
|
307
316
|
const guardSet = new Set(guards);
|
|
308
317
|
const interceptorSet = new Set(interceptors);
|
|
309
318
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
319
|
+
const filterSet = /* @__PURE__ */ new Set();
|
|
310
320
|
meta.forEach(({ data }) => {
|
|
321
|
+
if (data.filter)
|
|
322
|
+
filterSet.add(data.filter);
|
|
311
323
|
data.interceptors.forEach((i) => interceptorSet.add(i));
|
|
312
324
|
data.guards.forEach((i) => guardSet.add(i));
|
|
313
325
|
data.plugins.forEach((i) => pluginSet.add(i));
|
|
@@ -316,33 +328,33 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
|
|
|
316
328
|
pipeSet.add(i.pipe);
|
|
317
329
|
});
|
|
318
330
|
});
|
|
319
|
-
[
|
|
331
|
+
const missPlugins = [
|
|
320
332
|
...pluginSet
|
|
321
|
-
].
|
|
322
|
-
|
|
323
|
-
_chunkLZAU5FUSjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${i}]`)} doesn't exist`, "warn");
|
|
324
|
-
});
|
|
325
|
-
[
|
|
333
|
+
].filter((i) => !Context.pluginRecord[i]);
|
|
334
|
+
const missGuards = [
|
|
326
335
|
...guardSet
|
|
327
|
-
].
|
|
328
|
-
|
|
329
|
-
_chunkLZAU5FUSjs.log.call(void 0, `${_picocolors2.default.red(`Guard [${i}]`)} doesn't exist`, "warn");
|
|
330
|
-
});
|
|
331
|
-
[
|
|
336
|
+
].filter((i) => !Context.guardRecord[i]);
|
|
337
|
+
const missInterceptors = [
|
|
332
338
|
...interceptorSet
|
|
333
|
-
].
|
|
334
|
-
|
|
335
|
-
_chunkLZAU5FUSjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${i}]`)} doesn't exist`, "warn");
|
|
336
|
-
});
|
|
337
|
-
[
|
|
339
|
+
].filter((i) => !Context.interceptorRecord[i]);
|
|
340
|
+
const missPipes = [
|
|
338
341
|
...pipeSet
|
|
339
|
-
].
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
].filter((i) => !Context.pipeRecord[i]);
|
|
343
|
+
const missFilters = [
|
|
344
|
+
...filterSet
|
|
345
|
+
].filter((i) => !Context.filterRecord[i]);
|
|
346
|
+
if (missPlugins.length)
|
|
347
|
+
_chunkAAF47ZC6js.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
|
|
348
|
+
if (missGuards.length)
|
|
349
|
+
_chunkAAF47ZC6js.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
350
|
+
if (missInterceptors.length)
|
|
351
|
+
_chunkAAF47ZC6js.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
352
|
+
if (missPipes.length)
|
|
353
|
+
_chunkAAF47ZC6js.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
354
|
+
if (missFilters.length)
|
|
355
|
+
_chunkAAF47ZC6js.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
343
356
|
}
|
|
344
|
-
|
|
345
|
-
|
|
357
|
+
_chunkAAF47ZC6js.__name.call(void 0, isAopDepInject, "isAopDepInject");
|
|
346
358
|
|
|
347
359
|
|
|
348
360
|
|
|
@@ -369,5 +381,5 @@ _chunkLZAU5FUSjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
|
|
|
369
381
|
|
|
370
382
|
|
|
371
383
|
|
|
372
|
-
exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.
|
|
373
|
-
//# sourceMappingURL=chunk-
|
|
384
|
+
exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.guardRecord = guardRecord; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.isAopDepInject = isAopDepInject;
|
|
385
|
+
//# sourceMappingURL=chunk-7OB6K45T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/exception/base.ts","../src/exception/validate.ts","../src/pipe.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/context.ts","../src/filter.ts","../src/history.ts"],"names":["Exception","Error","message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","isPhecda","plainToClass","transformClass","defaultPipe","arg","reflect","index","instance","err","length","Number","Boolean","includes","Object","is","NaN","UndefinedException","ForbiddenException","BadRequestException","NotFoundException","ConflictException","BadGatewayException","InvalidInputException","UnsupportedMediaTypeException","PayloadLargeException","TimeoutException","UnauthorizedException","ServiceUnavailableException","FrameworkException","pc","defaultFilter","e","log","console","error","stack","name","Histroy","guard","interceptor","record","type","push","guardRecord","Context","tag","method","params","history","postInterceptors","IS_DEV","_context","usePipe","args","Promise","all","map","item","pipe","pipeRecord","IS_STRICT","default","useFilter","filter","filterRecord","useGuard","guards","usePostInterceptor","ret","cb","useInterceptor","interceptors","interceptorRecord","postInterceptor","undefined","usePlugin","plugins","m","pluginRecord","addPlugin","key","handler","addPipe","addFilter","addGuard","addInterceptor","isAopDepInject","meta","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","forEach","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","white","join","magenta","cyan","blue","red"],"mappings":";;;;;;;;;;AAEO,IAAMA,YAAN,cAAwBC,MAAAA;EACVC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,W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YMBOL } from '../common'\n\nexport class Exception extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, [ERROR_SYMBOL]: true }\n }\n}\n","import { Exception } from './base'\n\nexport class ValidateException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { isPhecda, plainToClass, transformClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe: P.Pipe = async ({ arg, reflect, index }: any) => {\n if (isPhecda(reflect)) {\n const instance = plainToClass(reflect, arg)\n const err = await transformClass(instance)\n if (err.length > 0)\n throw new ValidateException(err[0])\n\n arg = instance\n }\n else {\n if ([Number, Boolean].includes(reflect)) {\n arg = reflect(arg)\n\n if (reflect === Number && Object.is(arg, NaN))\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\n }\n }\n return arg\n}\n","import { Exception } from './base'\n\nexport class UndefinedException extends Exception {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { Exception } from './base'\n\nexport class ForbiddenException extends Exception {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { Exception } from './base'\n\nexport class BadRequestException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { Exception } from './base'\n\nexport class NotFoundException extends Exception {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { Exception } from './base'\n\nexport class ConflictException extends Exception {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { Exception } from './base'\n\nexport class BadGatewayException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { Exception } from './base'\n\nexport class InvalidInputException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { Exception } from './base'\n\nexport class UnsupportedMediaTypeException extends Exception {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { Exception } from './base'\n\nexport class PayloadLargeException extends Exception {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { Exception } from './base'\n\nexport class TimeoutException extends Exception {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { Exception } from './base'\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { Exception } from './base'\n\nexport class ServiceUnavailableException extends Exception {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { Exception } from './base'\n\nexport class FrameworkException extends Exception {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import pc from 'picocolors'\nimport { defaultPipe } from './pipe'\nimport { ForbiddenException, FrameworkException } from './exception'\nimport { defaultFilter } from './filter'\nimport { Histroy } from './history'\nimport type { P } from './types'\nimport { IS_DEV, IS_STRICT } from './common'\nimport type { Meta } from './meta'\nimport { log } from './utils'\nexport const guardRecord = {} as Record<string, P.Guard>\n\nexport class Context<Data = any> {\n method: string\n params: string[]\n history = new Histroy()\n\n static filterRecord: Record<string, P.Filter> = {\n default: defaultFilter,\n }\n\n static pipeRecord: Record<string, P.Pipe> = {\n default: defaultPipe,\n }\n\n static guardRecord: Record<string, P.Guard> = {}\n static interceptorRecord: Record<string, P.Interceptor> = {}\n\n static pluginRecord: Record<string, any> = {}\n postInterceptors: Function[]\n\n constructor(public tag: string, public data: Data) {\n if (IS_DEV)\n // @ts-expect-error work for debug\n data._context = this\n }\n\n usePipe(args: { arg: any; pipe?: string; pipeOpts?: any; type: string; key: string; index: number; reflect: any }[]) {\n return Promise.all(args.map((item) => {\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\n\n else\n return Context.pipeRecord.default(item, this.tag, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.tag, this.data)\n }))\n }\n\n useFilter(arg: any, filter = 'default') {\n if (!Context.filterRecord[filter]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find filter named '${filter}'`)\n else\n return Context.filterRecord.default(arg, this.tag, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.tag, this.data)\n }\n\n async useGuard(guards: string[]) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\n if (!await Context.guardRecord[guard](this.tag, this.data))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async usePostInterceptor(ret: any) {\n for (const cb of this.postInterceptors)\n ret = await cb(ret) || ret\n\n return ret\n }\n\n async useInterceptor(interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\n const postInterceptor = await Context.interceptorRecord[interceptor](this.tag, this.data)\n if (postInterceptor !== undefined) {\n if (typeof postInterceptor === 'function')\n ret.push(postInterceptor)\n\n else\n return postInterceptor\n }\n }\n }\n this.postInterceptors = ret\n }\n\n static usePlugin(plugins: string[]) {\n const ret = []\n for (const m of plugins) {\n if (!(m in Context.pluginRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(Context.pluginRecord[m])\n }\n return ret as any[]\n }\n}\nexport function addPlugin<C>(key: string, handler: C) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe(key: string, pipe: P.Pipe) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter(key: string, handler: P.Filter) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard(key: string, handler: P.Guard) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor(key: string, handler: P.Interceptor) {\n Context.interceptorRecord[key] = handler\n}\n\n// detect whether plugin/filter/pipe/guard/intercept is injected\nexport function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }: {\n guards?: string[]\n interceptors?: string[]\n plugins?: string[]\n} = {}) {\n const pluginSet = new Set<string>(plugins)\n\n const guardSet = new Set<string>(guards)\n const interceptorSet = new Set<string>(interceptors)\n const pipeSet = new Set<string>()\n\n const filterSet = new Set<string>()\n meta.forEach(({ data }) => {\n if (data.filter)\n filterSet.add(data.filter)\n\n data.interceptors.forEach(i => interceptorSet.add(i))\n data.guards.forEach(i => guardSet.add(i))\n data.plugins.forEach(i => pluginSet.add(i))\n data.params.forEach((i) => {\n if (i.pipe)\n pipeSet.add(i.pipe)\n })\n })\n\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\n\n if (missPlugins.length)\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\n if (missGuards.length)\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missInterceptors.length)\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missPipes.length)\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missFilters.length)\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\n}\n","import { Exception, UndefinedException } from './exception'\nimport type { P } from './types'\nimport { log } from './utils'\n\nexport const defaultFilter: P.Filter = (e) => {\n if (!(e instanceof Exception)) {\n log(e.message, 'error')\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n log(`[${e.constructor.name}] ${e.message}`, 'error')\n console.error(e.stack)\n }\n\n return e.data\n}\n","export class Histroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n"]}
|
|
@@ -14,9 +14,11 @@ var META_SYMBOL = "__PS_META__";
|
|
|
14
14
|
var APP_SYMBOL = "__PS__";
|
|
15
15
|
var IS_DEV = process.env.NODE_ENV === "development";
|
|
16
16
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
17
|
+
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
17
18
|
|
|
18
19
|
// src/utils.ts
|
|
19
20
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
21
|
+
var time;
|
|
20
22
|
function log(msg, level = "info") {
|
|
21
23
|
const color = {
|
|
22
24
|
error: "red",
|
|
@@ -24,7 +26,10 @@ function log(msg, level = "info") {
|
|
|
24
26
|
warn: "yellow"
|
|
25
27
|
}[level];
|
|
26
28
|
const date = new Date();
|
|
27
|
-
|
|
29
|
+
const current = Date.now();
|
|
30
|
+
const interval = time && current - time ? `+${current - time}` : "";
|
|
31
|
+
time = current;
|
|
32
|
+
console.log(`${_picocolors2.default.magenta("[phecda-server]")} ${_picocolors2.default.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${_picocolors2.default[color](msg)} ${_picocolors2.default.gray(interval)}`);
|
|
28
33
|
}
|
|
29
34
|
__name(log, "log");
|
|
30
35
|
|
|
@@ -39,5 +44,6 @@ __name(log, "log");
|
|
|
39
44
|
|
|
40
45
|
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
|
|
48
|
+
exports.__name = __name; exports.__publicField = __publicField; exports.MERGE_SYMBOL = MERGE_SYMBOL; exports.UNMOUNT_SYMBOL = UNMOUNT_SYMBOL; exports.MODULE_SYMBOL = MODULE_SYMBOL; exports.META_SYMBOL = META_SYMBOL; exports.APP_SYMBOL = APP_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_STRICT = IS_STRICT; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.log = log;
|
|
49
|
+
//# sourceMappingURL=chunk-AAF47ZC6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common.ts","../src/utils.ts"],"names":["MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","APP_SYMBOL","IS_DEV","process","env","NODE_ENV","IS_STRICT","PS_STRICT","ERROR_SYMBOL","pc","time","log","msg","level","color","error","info","warn","date","Date","current","now","interval","console","magenta","gray","getHours","getMinutes","getSeconds"],"mappings":";;;;;;;;;AAAO,IAAMA,eAAe;AACrB,IAAMC,iBAAiB;AACvB,IAAMC,gBAAgB;AACtB,IAAMC,cAAc;AACpB,IAAMC,aAAa;AACnB,IAAMC,SAASC,QAAQC,IAAIC,aAAa;AACxC,IAAMC,YAAY,CAAC,CAACH,QAAQC,IAAIG;AAChC,IAAMC,eAAe;;;ACP5B,OAAOC,QAAQ;AAEf,IAAIC;AAEG,SAASC,IAAIC,KAAaC,QAAmC,QAAQ;AAC1E,QAAMC,QAAS;IAAEC,OAAO;IAAOC,MAAM;IAASC,MAAM;EAAS,EAAYJ;AACzE,QAAMK,OAAO,IAAIC,KAAAA;AACjB,QAAMC,UAAUD,KAAKE,IAAG;AACxB,QAAMC,WAAYZ,QAAQU,UAAUV,OAAQ,IAAIU,UAAUV,SAAS;AACnEA,SAAOU;AAEPG,UAAQZ,IAAI,GAAGF,GAAGe,QAAQ,iBAAA,KAAsBf,GAAGgB,KAAK,GAAGP,KAAKQ,SAAQ,KAAMR,KAAKS,WAAU,KAAMT,KAAKU,WAAU,GAAI,KAAKnB,GAAGK,OAAOF,GAAAA,KAAQH,GAAGgB,KAAKH,QAAAA,GAAW;AAClK;AARgBX","sourcesContent":["export const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\nexport const APP_SYMBOL = '__PS__'\nexport const IS_DEV = process.env.NODE_ENV === 'development'\nexport const IS_STRICT = !!process.env.PS_STRICT\nexport const ERROR_SYMBOL = '__PS_ERROR__'\n","import pc from 'picocolors'\n\nlet time: number\n\nexport function log(msg: string, level: 'error' | 'info' | 'warn' = 'info') {\n const color = ({ error: 'red', info: 'green', warn: 'yellow' } as const)[level]\n const date = new Date()\n const current = Date.now()\n const interval = (time && current - time) ? `+${current - time}` : ''\n time = current\n // eslint-disable-next-line no-console\n console.log(`${pc.magenta('[phecda-server]')} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`)\n}\n"]}
|
|
@@ -14,9 +14,11 @@ var META_SYMBOL = "__PS_META__";
|
|
|
14
14
|
var APP_SYMBOL = "__PS__";
|
|
15
15
|
var IS_DEV = process.env.NODE_ENV === "development";
|
|
16
16
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
17
|
+
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
17
18
|
|
|
18
19
|
// src/utils.ts
|
|
19
20
|
import pc from "picocolors";
|
|
21
|
+
var time;
|
|
20
22
|
function log(msg, level = "info") {
|
|
21
23
|
const color = {
|
|
22
24
|
error: "red",
|
|
@@ -24,20 +26,24 @@ function log(msg, level = "info") {
|
|
|
24
26
|
warn: "yellow"
|
|
25
27
|
}[level];
|
|
26
28
|
const date = new Date();
|
|
27
|
-
|
|
29
|
+
const current = Date.now();
|
|
30
|
+
const interval = time && current - time ? `+${current - time}` : "";
|
|
31
|
+
time = current;
|
|
32
|
+
console.log(`${pc.magenta("[phecda-server]")} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`);
|
|
28
33
|
}
|
|
29
34
|
__name(log, "log");
|
|
30
35
|
|
|
31
36
|
export {
|
|
32
37
|
__name,
|
|
33
38
|
__publicField,
|
|
34
|
-
log,
|
|
35
39
|
MERGE_SYMBOL,
|
|
36
40
|
UNMOUNT_SYMBOL,
|
|
37
41
|
MODULE_SYMBOL,
|
|
38
42
|
META_SYMBOL,
|
|
39
43
|
APP_SYMBOL,
|
|
40
44
|
IS_DEV,
|
|
41
|
-
IS_STRICT
|
|
45
|
+
IS_STRICT,
|
|
46
|
+
ERROR_SYMBOL,
|
|
47
|
+
log
|
|
42
48
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-AYJWOIAW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common.ts","../src/utils.ts"],"sourcesContent":["export const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\nexport const APP_SYMBOL = '__PS__'\nexport const IS_DEV = process.env.NODE_ENV === 'development'\nexport const IS_STRICT = !!process.env.PS_STRICT\nexport const ERROR_SYMBOL = '__PS_ERROR__'\n","import pc from 'picocolors'\n\nlet time: number\n\nexport function log(msg: string, level: 'error' | 'info' | 'warn' = 'info') {\n const color = ({ error: 'red', info: 'green', warn: 'yellow' } as const)[level]\n const date = new Date()\n const current = Date.now()\n const interval = (time && current - time) ? `+${current - time}` : ''\n time = current\n // eslint-disable-next-line no-console\n console.log(`${pc.magenta('[phecda-server]')} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`)\n}\n"],"mappings":";;;;;;;;;AAAO,IAAMA,eAAe;AACrB,IAAMC,iBAAiB;AACvB,IAAMC,gBAAgB;AACtB,IAAMC,cAAc;AACpB,IAAMC,aAAa;AACnB,IAAMC,SAASC,QAAQC,IAAIC,aAAa;AACxC,IAAMC,YAAY,CAAC,CAACH,QAAQC,IAAIG;AAChC,IAAMC,eAAe;;;ACP5B,OAAOC,QAAQ;AAEf,IAAIC;AAEG,SAASC,IAAIC,KAAaC,QAAmC,QAAQ;AAC1E,QAAMC,QAAS;IAAEC,OAAO;IAAOC,MAAM;IAASC,MAAM;EAAS,EAAYJ;AACzE,QAAMK,OAAO,IAAIC,KAAAA;AACjB,QAAMC,UAAUD,KAAKE,IAAG;AACxB,QAAMC,WAAYZ,QAAQU,UAAUV,OAAQ,IAAIU,UAAUV,SAAS;AACnEA,SAAOU;AAEPG,UAAQZ,IAAI,GAAGa,GAAGC,QAAQ,iBAAA,KAAsBD,GAAGE,KAAK,GAAGR,KAAKS,SAAQ,KAAMT,KAAKU,WAAU,KAAMV,KAAKW,WAAU,GAAI,KAAKL,GAAGV,OAAOF,GAAAA,KAAQY,GAAGE,KAAKJ,QAAAA,GAAW;AAClK;AARgBX;","names":["MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","APP_SYMBOL","IS_DEV","process","env","NODE_ENV","IS_STRICT","PS_STRICT","ERROR_SYMBOL","pc","time","log","msg","level","color","error","info","warn","date","Date","current","now","interval","console","pc","magenta","gray","getHours","getMinutes","getSeconds"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ERROR_SYMBOL,
|
|
2
3
|
IS_DEV,
|
|
3
4
|
IS_STRICT,
|
|
4
5
|
__name,
|
|
5
6
|
__publicField,
|
|
6
7
|
log
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-AYJWOIAW.mjs";
|
|
8
9
|
|
|
9
10
|
// src/exception/base.ts
|
|
10
11
|
var Exception = class extends Error {
|
|
@@ -22,7 +23,7 @@ var Exception = class extends Error {
|
|
|
22
23
|
message: this.message,
|
|
23
24
|
description: this.description,
|
|
24
25
|
status: this.status,
|
|
25
|
-
|
|
26
|
+
[ERROR_SYMBOL]: true
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
};
|
|
@@ -219,8 +220,14 @@ var _Context = class {
|
|
|
219
220
|
return _Context.pipeRecord[item.pipe || "default"](item, this.tag, this.data);
|
|
220
221
|
}));
|
|
221
222
|
}
|
|
222
|
-
useFilter(arg) {
|
|
223
|
-
|
|
223
|
+
useFilter(arg, filter = "default") {
|
|
224
|
+
if (!_Context.filterRecord[filter]) {
|
|
225
|
+
if (IS_STRICT)
|
|
226
|
+
throw new FrameworkException(`can't find filter named '${filter}'`);
|
|
227
|
+
else
|
|
228
|
+
return _Context.filterRecord.default(arg, this.tag, this.data);
|
|
229
|
+
}
|
|
230
|
+
return _Context.filterRecord[filter](arg, this.tag, this.data);
|
|
224
231
|
}
|
|
225
232
|
async useGuard(guards) {
|
|
226
233
|
for (const guard of guards) {
|
|
@@ -275,7 +282,9 @@ var _Context = class {
|
|
|
275
282
|
};
|
|
276
283
|
var Context = _Context;
|
|
277
284
|
__name(Context, "Context");
|
|
278
|
-
__publicField(Context, "
|
|
285
|
+
__publicField(Context, "filterRecord", {
|
|
286
|
+
default: defaultFilter
|
|
287
|
+
});
|
|
279
288
|
__publicField(Context, "pipeRecord", {
|
|
280
289
|
default: defaultPipe
|
|
281
290
|
});
|
|
@@ -290,10 +299,10 @@ function addPipe(key, pipe) {
|
|
|
290
299
|
Context.pipeRecord[key] = pipe;
|
|
291
300
|
}
|
|
292
301
|
__name(addPipe, "addPipe");
|
|
293
|
-
function
|
|
294
|
-
Context.
|
|
302
|
+
function addFilter(key, handler) {
|
|
303
|
+
Context.filterRecord[key] = handler;
|
|
295
304
|
}
|
|
296
|
-
__name(
|
|
305
|
+
__name(addFilter, "addFilter");
|
|
297
306
|
function addGuard(key, handler) {
|
|
298
307
|
Context.guardRecord[key] = handler;
|
|
299
308
|
}
|
|
@@ -307,7 +316,10 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
|
|
|
307
316
|
const guardSet = new Set(guards);
|
|
308
317
|
const interceptorSet = new Set(interceptors);
|
|
309
318
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
319
|
+
const filterSet = /* @__PURE__ */ new Set();
|
|
310
320
|
meta.forEach(({ data }) => {
|
|
321
|
+
if (data.filter)
|
|
322
|
+
filterSet.add(data.filter);
|
|
311
323
|
data.interceptors.forEach((i) => interceptorSet.add(i));
|
|
312
324
|
data.guards.forEach((i) => guardSet.add(i));
|
|
313
325
|
data.plugins.forEach((i) => pluginSet.add(i));
|
|
@@ -316,30 +328,31 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
|
|
|
316
328
|
pipeSet.add(i.pipe);
|
|
317
329
|
});
|
|
318
330
|
});
|
|
319
|
-
[
|
|
331
|
+
const missPlugins = [
|
|
320
332
|
...pluginSet
|
|
321
|
-
].
|
|
322
|
-
|
|
323
|
-
log(`${pc.white(`Plugin [${i}]`)} doesn't exist`, "warn");
|
|
324
|
-
});
|
|
325
|
-
[
|
|
333
|
+
].filter((i) => !Context.pluginRecord[i]);
|
|
334
|
+
const missGuards = [
|
|
326
335
|
...guardSet
|
|
327
|
-
].
|
|
328
|
-
|
|
329
|
-
log(`${pc.red(`Guard [${i}]`)} doesn't exist`, "warn");
|
|
330
|
-
});
|
|
331
|
-
[
|
|
336
|
+
].filter((i) => !Context.guardRecord[i]);
|
|
337
|
+
const missInterceptors = [
|
|
332
338
|
...interceptorSet
|
|
333
|
-
].
|
|
334
|
-
|
|
335
|
-
log(`${pc.cyan(`Interceptor [${i}]`)} doesn't exist`, "warn");
|
|
336
|
-
});
|
|
337
|
-
[
|
|
339
|
+
].filter((i) => !Context.interceptorRecord[i]);
|
|
340
|
+
const missPipes = [
|
|
338
341
|
...pipeSet
|
|
339
|
-
].
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
].filter((i) => !Context.pipeRecord[i]);
|
|
343
|
+
const missFilters = [
|
|
344
|
+
...filterSet
|
|
345
|
+
].filter((i) => !Context.filterRecord[i]);
|
|
346
|
+
if (missPlugins.length)
|
|
347
|
+
log(`${pc.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
|
|
348
|
+
if (missGuards.length)
|
|
349
|
+
log(`${pc.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
350
|
+
if (missInterceptors.length)
|
|
351
|
+
log(`${pc.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
352
|
+
if (missPipes.length)
|
|
353
|
+
log(`${pc.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
354
|
+
if (missFilters.length)
|
|
355
|
+
log(`${pc.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
343
356
|
}
|
|
344
357
|
__name(isAopDepInject, "isAopDepInject");
|
|
345
358
|
|
|
@@ -360,14 +373,13 @@ export {
|
|
|
360
373
|
UnauthorizedException,
|
|
361
374
|
ServiceUnavailableException,
|
|
362
375
|
FrameworkException,
|
|
363
|
-
defaultFilter,
|
|
364
376
|
guardRecord,
|
|
365
377
|
Context,
|
|
366
378
|
addPlugin,
|
|
367
379
|
addPipe,
|
|
368
|
-
|
|
380
|
+
addFilter,
|
|
369
381
|
addGuard,
|
|
370
382
|
addInterceptor,
|
|
371
383
|
isAopDepInject
|
|
372
384
|
};
|
|
373
|
-
//# sourceMappingURL=chunk-
|
|
385
|
+
//# sourceMappingURL=chunk-GSJ5A2MA.mjs.map
|