phecda-server 5.0.2 → 5.1.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/README.md +10 -108
- package/bin/cli.mjs +189 -186
- package/bin/schema.json +55 -55
- package/dist/{chunk-F5YWXY5W.js → chunk-423JPSEB.js} +18 -17
- package/dist/chunk-423JPSEB.js.map +1 -0
- package/dist/chunk-4R55T3HG.js +253 -0
- package/dist/chunk-4R55T3HG.js.map +1 -0
- package/dist/chunk-4YVAW3L4.mjs +76 -0
- package/dist/chunk-4YVAW3L4.mjs.map +1 -0
- package/dist/{chunk-W5EOVGQD.mjs → chunk-5DOVDDO7.mjs} +3 -2
- package/dist/chunk-5DOVDDO7.mjs.map +1 -0
- package/dist/{chunk-BXLBWRHS.js → chunk-5WQ2SMIK.js} +39 -38
- package/dist/chunk-5WQ2SMIK.js.map +1 -0
- package/dist/chunk-6MQP6OHU.mjs +295 -0
- package/dist/chunk-6MQP6OHU.mjs.map +1 -0
- package/dist/chunk-6Q2PCC3A.mjs +295 -0
- package/dist/chunk-6Q2PCC3A.mjs.map +1 -0
- package/dist/chunk-6UQYEBAN.js +253 -0
- package/dist/chunk-6UQYEBAN.js.map +1 -0
- package/dist/chunk-6W7CGOZC.mjs +565 -0
- package/dist/chunk-6W7CGOZC.mjs.map +1 -0
- package/dist/{chunk-YR5Q5F2K.js → chunk-7Y37NSBM.js} +1 -0
- package/dist/chunk-7Y37NSBM.js.map +1 -0
- package/dist/{chunk-RCTOVYZY.mjs → chunk-BQBSVGMG.mjs} +2 -1
- package/dist/chunk-BQBSVGMG.mjs.map +1 -0
- package/dist/chunk-BZP6GKM6.mjs +565 -0
- package/dist/chunk-BZP6GKM6.mjs.map +1 -0
- package/dist/{chunk-ITTD2GBR.mjs → chunk-C5JAHCS2.mjs} +1 -0
- package/dist/chunk-C5JAHCS2.mjs.map +1 -0
- package/dist/chunk-DTBKDALR.mjs +295 -0
- package/dist/chunk-DTBKDALR.mjs.map +1 -0
- package/dist/chunk-GHOKWS5V.js +295 -0
- package/dist/chunk-GHOKWS5V.js.map +1 -0
- package/dist/chunk-H4N6SHNG.mjs +76 -0
- package/dist/chunk-H4N6SHNG.mjs.map +1 -0
- package/dist/chunk-ICYHM4UM.js +565 -0
- package/dist/chunk-ICYHM4UM.js.map +1 -0
- package/dist/chunk-LOLXPM4J.mjs +529 -0
- package/dist/chunk-LOLXPM4J.mjs.map +1 -0
- package/dist/chunk-MSS6A2TU.js +585 -0
- package/dist/chunk-MSS6A2TU.js.map +1 -0
- package/dist/{chunk-AB4OX3WV.mjs → chunk-NEM3FY7C.mjs} +2 -1
- package/dist/chunk-NEM3FY7C.mjs.map +1 -0
- package/dist/chunk-OTHER3YM.mjs +253 -0
- package/dist/chunk-OTHER3YM.mjs.map +1 -0
- package/dist/chunk-Q2FYFIEY.js +295 -0
- package/dist/chunk-Q2FYFIEY.js.map +1 -0
- package/dist/chunk-QG4X6H5Y.js +565 -0
- package/dist/chunk-QG4X6H5Y.js.map +1 -0
- package/dist/chunk-QIEZ6YTG.mjs +295 -0
- package/dist/chunk-QIEZ6YTG.mjs.map +1 -0
- package/dist/chunk-QOAKHCM7.js +295 -0
- package/dist/chunk-QOAKHCM7.js.map +1 -0
- package/dist/chunk-QVUD6L5X.js +565 -0
- package/dist/chunk-QVUD6L5X.js.map +1 -0
- package/dist/{chunk-YERBWZCS.js → chunk-RGLTGKAU.js} +64 -63
- package/dist/chunk-RGLTGKAU.js.map +1 -0
- package/dist/chunk-SHRK3TVB.js +295 -0
- package/dist/chunk-SHRK3TVB.js.map +1 -0
- package/dist/chunk-TCH6S42Z.js +529 -0
- package/dist/chunk-TCH6S42Z.js.map +1 -0
- package/dist/chunk-UCGRFVHC.mjs +253 -0
- package/dist/chunk-UCGRFVHC.mjs.map +1 -0
- package/dist/chunk-VOISXWVF.mjs +295 -0
- package/dist/chunk-VOISXWVF.mjs.map +1 -0
- package/dist/chunk-W6BC5INO.mjs +295 -0
- package/dist/chunk-W6BC5INO.mjs.map +1 -0
- package/dist/chunk-X5WQRO4R.js +295 -0
- package/dist/chunk-X5WQRO4R.js.map +1 -0
- package/dist/chunk-XDMCVVD3.mjs +585 -0
- package/dist/chunk-XDMCVVD3.mjs.map +1 -0
- package/dist/chunk-XNTMYLK6.js +76 -0
- package/dist/chunk-XNTMYLK6.js.map +1 -0
- package/dist/chunk-Y6LI4FDO.js +537 -0
- package/dist/chunk-Y6LI4FDO.js.map +1 -0
- package/dist/chunk-YZ2AQ6IL.mjs +537 -0
- package/dist/chunk-YZ2AQ6IL.mjs.map +1 -0
- package/dist/chunk-Z4YJHEXT.js +76 -0
- package/dist/chunk-Z4YJHEXT.js.map +1 -0
- package/dist/chunk-ZE336SKZ.js +295 -0
- package/dist/chunk-ZE336SKZ.js.map +1 -0
- package/dist/chunk-ZJD235TO.mjs +565 -0
- package/dist/chunk-ZJD235TO.mjs.map +1 -0
- package/dist/core-39f27fe8.d.ts +131 -0
- package/dist/core-930ea883.d.ts +131 -0
- package/dist/core-eb646fe5.d.ts +139 -0
- package/dist/helper-06d25b37.d.ts +19 -0
- package/dist/helper-48454c0b.d.ts +20 -0
- package/dist/helper-6133f78f.d.ts +18 -0
- package/dist/helper-867a598d.d.ts +18 -0
- package/dist/helper-88b19c66.d.ts +12 -0
- package/dist/helper-9e206c66.d.ts +12 -0
- package/dist/helper-fcbf6aa8.d.ts +20 -0
- package/dist/index.d.ts +27 -32
- package/dist/index.js +45 -40
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +15 -10
- package/dist/index.mjs.map +1 -0
- package/dist/rpc/bullmq/index.d.ts +10 -6
- package/dist/rpc/bullmq/index.js +33 -53
- package/dist/rpc/bullmq/index.js.map +1 -0
- package/dist/rpc/bullmq/index.mjs +27 -47
- package/dist/rpc/bullmq/index.mjs.map +1 -0
- package/dist/rpc/kafka/index.d.ts +10 -4
- package/dist/rpc/kafka/index.js +21 -37
- package/dist/rpc/kafka/index.js.map +1 -0
- package/dist/rpc/kafka/index.mjs +16 -32
- package/dist/rpc/kafka/index.mjs.map +1 -0
- package/dist/rpc/nats/index.d.ts +2 -2
- package/dist/rpc/nats/index.js +21 -34
- package/dist/rpc/nats/index.js.map +1 -0
- package/dist/rpc/nats/index.mjs +14 -27
- package/dist/rpc/nats/index.mjs.map +1 -0
- package/dist/rpc/rabbitmq/index.d.ts +2 -2
- package/dist/rpc/rabbitmq/index.js +24 -37
- package/dist/rpc/rabbitmq/index.js.map +1 -0
- package/dist/rpc/rabbitmq/index.mjs +15 -28
- package/dist/rpc/rabbitmq/index.mjs.map +1 -0
- package/dist/rpc/redis/index.d.ts +10 -4
- package/dist/rpc/redis/index.js +24 -37
- package/dist/rpc/redis/index.js.map +1 -0
- package/dist/rpc/redis/index.mjs +17 -30
- package/dist/rpc/redis/index.mjs.map +1 -0
- package/dist/server/elysia/index.d.ts +4 -3
- package/dist/server/elysia/index.js +78 -94
- package/dist/server/elysia/index.js.map +1 -0
- package/dist/server/elysia/index.mjs +75 -91
- package/dist/server/elysia/index.mjs.map +1 -0
- package/dist/server/express/index.d.ts +5 -4
- package/dist/server/express/index.js +80 -93
- package/dist/server/express/index.js.map +1 -0
- package/dist/server/express/index.mjs +78 -91
- package/dist/server/express/index.mjs.map +1 -0
- package/dist/server/fastify/index.d.ts +8 -5
- package/dist/server/fastify/index.js +84 -102
- package/dist/server/fastify/index.js.map +1 -0
- package/dist/server/fastify/index.mjs +80 -98
- package/dist/server/fastify/index.mjs.map +1 -0
- package/dist/server/h3/index.d.ts +5 -4
- package/dist/server/h3/index.js +82 -97
- package/dist/server/h3/index.js.map +1 -0
- package/dist/server/h3/index.mjs +81 -96
- package/dist/server/h3/index.mjs.map +1 -0
- package/dist/server/hono/index.d.ts +5 -4
- package/dist/server/hono/index.js +74 -90
- package/dist/server/hono/index.js.map +1 -0
- package/dist/server/hono/index.mjs +73 -89
- package/dist/server/hono/index.mjs.map +1 -0
- package/dist/server/hyper-express/index.d.ts +6 -5
- package/dist/server/hyper-express/index.js +79 -96
- package/dist/server/hyper-express/index.js.map +1 -0
- package/dist/server/hyper-express/index.mjs +78 -95
- package/dist/server/hyper-express/index.mjs.map +1 -0
- package/dist/server/koa/index.d.ts +5 -4
- package/dist/server/koa/index.js +80 -92
- package/dist/server/koa/index.js.map +1 -0
- package/dist/server/koa/index.mjs +77 -89
- package/dist/server/koa/index.mjs.map +1 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +7 -6
- package/dist/test.js.map +1 -0
- package/dist/test.mjs +3 -2
- package/dist/test.mjs.map +1 -0
- package/package.json +8 -7
- package/register/index.mjs +40 -40
- package/register/loader.mjs +341 -340
- package/register/utils.mjs +81 -81
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk7Y37NSBMjs = require('./chunk-7Y37NSBM.js');
|
|
10
10
|
|
|
11
11
|
// src/exception/base.ts
|
|
12
12
|
var Exception = class extends Error {
|
|
@@ -24,11 +24,11 @@ var Exception = class extends Error {
|
|
|
24
24
|
message: this.message,
|
|
25
25
|
description: this.description,
|
|
26
26
|
status: this.status,
|
|
27
|
-
[
|
|
27
|
+
[_chunk7Y37NSBMjs.ERROR_SYMBOL]: true
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
_chunk7Y37NSBMjs.__name.call(void 0, Exception, "Exception");
|
|
32
32
|
|
|
33
33
|
// src/exception/validate.ts
|
|
34
34
|
var ValidateException = class extends Exception {
|
|
@@ -36,11 +36,11 @@ var ValidateException = class extends Exception {
|
|
|
36
36
|
super(message, 400, "Validate exception");
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
_chunk7Y37NSBMjs.__name.call(void 0, ValidateException, "ValidateException");
|
|
40
40
|
|
|
41
41
|
// src/pipe.ts
|
|
42
42
|
var _phecdacore = require('phecda-core');
|
|
43
|
-
var defaultPipe = /* @__PURE__ */
|
|
43
|
+
var defaultPipe = /* @__PURE__ */ _chunk7Y37NSBMjs.__name.call(void 0, ({ arg, reflect, index }) => {
|
|
44
44
|
if (_phecdacore.isPhecda.call(void 0, reflect)) {
|
|
45
45
|
const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
|
|
46
46
|
const err = _phecdacore.transformInstance.call(void 0, instance);
|
|
@@ -68,7 +68,7 @@ var UndefinedException = class extends Exception {
|
|
|
68
68
|
super(message, 500, "Undefined error");
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
|
|
71
|
+
_chunk7Y37NSBMjs.__name.call(void 0, UndefinedException, "UndefinedException");
|
|
72
72
|
|
|
73
73
|
// src/exception/forbidden.ts
|
|
74
74
|
var ForbiddenException = class extends Exception {
|
|
@@ -76,7 +76,7 @@ var ForbiddenException = class extends Exception {
|
|
|
76
76
|
super(message, 403, "Forbidden resource");
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
|
|
79
|
+
_chunk7Y37NSBMjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
|
|
80
80
|
|
|
81
81
|
// src/exception/bad-request.ts
|
|
82
82
|
var BadRequestException = class extends Exception {
|
|
@@ -84,7 +84,7 @@ var BadRequestException = class extends Exception {
|
|
|
84
84
|
super(message, 400, "Bad Request");
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
|
|
87
|
+
_chunk7Y37NSBMjs.__name.call(void 0, BadRequestException, "BadRequestException");
|
|
88
88
|
|
|
89
89
|
// src/exception/not-found.ts
|
|
90
90
|
var NotFoundException = class extends Exception {
|
|
@@ -92,7 +92,7 @@ var NotFoundException = class extends Exception {
|
|
|
92
92
|
super(message, 404, "Not Found");
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
-
|
|
95
|
+
_chunk7Y37NSBMjs.__name.call(void 0, NotFoundException, "NotFoundException");
|
|
96
96
|
|
|
97
97
|
// src/exception/conflict.ts
|
|
98
98
|
var ConflictException = class extends Exception {
|
|
@@ -100,7 +100,7 @@ var ConflictException = class extends Exception {
|
|
|
100
100
|
super(message, 409, "Conflict");
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
|
-
|
|
103
|
+
_chunk7Y37NSBMjs.__name.call(void 0, ConflictException, "ConflictException");
|
|
104
104
|
|
|
105
105
|
// src/exception/bad-gateway.ts
|
|
106
106
|
var BadGatewayException = class extends Exception {
|
|
@@ -108,7 +108,7 @@ var BadGatewayException = class extends Exception {
|
|
|
108
108
|
super(message, 502, "Bad Gatrway");
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
|
-
|
|
111
|
+
_chunk7Y37NSBMjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
|
|
112
112
|
|
|
113
113
|
// src/exception/invalid-input.ts
|
|
114
114
|
var InvalidInputException = class extends Exception {
|
|
@@ -116,7 +116,7 @@ var InvalidInputException = class extends Exception {
|
|
|
116
116
|
super(message, 502, "Invalid Input");
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
|
-
|
|
119
|
+
_chunk7Y37NSBMjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
|
|
120
120
|
|
|
121
121
|
// src/exception/media-type.ts
|
|
122
122
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
@@ -124,7 +124,7 @@ var UnsupportedMediaTypeException = class extends Exception {
|
|
|
124
124
|
super(message, 415, "Unsupported Media Type");
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
|
|
127
|
+
_chunk7Y37NSBMjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
|
|
128
128
|
|
|
129
129
|
// src/exception/payload-large.ts
|
|
130
130
|
var PayloadLargeException = class extends Exception {
|
|
@@ -132,7 +132,7 @@ var PayloadLargeException = class extends Exception {
|
|
|
132
132
|
super(message, 413, "Payload Too Large");
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
|
|
135
|
+
_chunk7Y37NSBMjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
|
|
136
136
|
|
|
137
137
|
// src/exception/timeout.ts
|
|
138
138
|
var TimeoutException = class extends Exception {
|
|
@@ -140,7 +140,7 @@ var TimeoutException = class extends Exception {
|
|
|
140
140
|
super(message, 408, "Request Timeout");
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
|
|
143
|
+
_chunk7Y37NSBMjs.__name.call(void 0, TimeoutException, "TimeoutException");
|
|
144
144
|
|
|
145
145
|
// src/exception/unauthorized.ts
|
|
146
146
|
var UnauthorizedException = class extends Exception {
|
|
@@ -148,7 +148,7 @@ var UnauthorizedException = class extends Exception {
|
|
|
148
148
|
super(message, 401, "Unauthorized");
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
|
-
|
|
151
|
+
_chunk7Y37NSBMjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
|
|
152
152
|
|
|
153
153
|
// src/exception/unavailable-service.ts
|
|
154
154
|
var ServiceUnavailableException = class extends Exception {
|
|
@@ -156,7 +156,7 @@ var ServiceUnavailableException = class extends Exception {
|
|
|
156
156
|
super(message, 503, "Service Unavailable");
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
|
-
|
|
159
|
+
_chunk7Y37NSBMjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
|
|
160
160
|
|
|
161
161
|
// src/exception/framework.ts
|
|
162
162
|
var FrameworkException = class extends Exception {
|
|
@@ -164,7 +164,7 @@ var FrameworkException = class extends Exception {
|
|
|
164
164
|
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
|
-
|
|
167
|
+
_chunk7Y37NSBMjs.__name.call(void 0, FrameworkException, "FrameworkException");
|
|
168
168
|
|
|
169
169
|
// src/exception/timer.ts
|
|
170
170
|
var TimerException = class extends Exception {
|
|
@@ -172,7 +172,7 @@ var TimerException = class extends Exception {
|
|
|
172
172
|
super(message, 0, "Timer Error");
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
|
-
|
|
175
|
+
_chunk7Y37NSBMjs.__name.call(void 0, TimerException, "TimerException");
|
|
176
176
|
|
|
177
177
|
// src/exception/worker.ts
|
|
178
178
|
var WorkerException = class extends Exception {
|
|
@@ -180,14 +180,14 @@ var WorkerException = class extends Exception {
|
|
|
180
180
|
super(message, 0, "Worker Error");
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
|
|
183
|
+
_chunk7Y37NSBMjs.__name.call(void 0, WorkerException, "WorkerException");
|
|
184
184
|
|
|
185
185
|
// src/hmr.ts
|
|
186
186
|
function HMR(cb) {
|
|
187
|
-
if (
|
|
187
|
+
if (_chunk7Y37NSBMjs.IS_HMR)
|
|
188
188
|
_optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
|
|
189
189
|
}
|
|
190
|
-
|
|
190
|
+
_chunk7Y37NSBMjs.__name.call(void 0, HMR, "HMR");
|
|
191
191
|
|
|
192
192
|
// src/server/helper.ts
|
|
193
193
|
function resolveDep(ret, key) {
|
|
@@ -195,7 +195,7 @@ function resolveDep(ret, key) {
|
|
|
195
195
|
return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
|
|
196
196
|
return ret;
|
|
197
197
|
}
|
|
198
|
-
|
|
198
|
+
_chunk7Y37NSBMjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
199
199
|
function argToReq(params, args, headers) {
|
|
200
200
|
const req = {
|
|
201
201
|
body: {},
|
|
@@ -211,14 +211,14 @@ function argToReq(params, args, headers) {
|
|
|
211
211
|
});
|
|
212
212
|
return req;
|
|
213
213
|
}
|
|
214
|
-
|
|
214
|
+
_chunk7Y37NSBMjs.__name.call(void 0, argToReq, "argToReq");
|
|
215
215
|
|
|
216
216
|
// src/rpc/helper.ts
|
|
217
217
|
var _os = require('os');
|
|
218
218
|
function genClientQueue(key) {
|
|
219
219
|
return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
|
|
220
220
|
}
|
|
221
|
-
|
|
221
|
+
_chunk7Y37NSBMjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
222
222
|
|
|
223
223
|
// src/decorators/helper.ts
|
|
224
224
|
function shallowClone(obj) {
|
|
@@ -226,30 +226,30 @@ function shallowClone(obj) {
|
|
|
226
226
|
...obj
|
|
227
227
|
};
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
_chunk7Y37NSBMjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
230
230
|
function mergeObject(...args) {
|
|
231
231
|
return Object.assign({}, ...args);
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
_chunk7Y37NSBMjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
234
234
|
function mergeArray(...args) {
|
|
235
235
|
return args.filter((item) => !!item).flat();
|
|
236
236
|
}
|
|
237
|
-
|
|
237
|
+
_chunk7Y37NSBMjs.__name.call(void 0, mergeArray, "mergeArray");
|
|
238
238
|
|
|
239
239
|
// src/context.ts
|
|
240
240
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
241
241
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
242
242
|
|
|
243
243
|
// src/filter.ts
|
|
244
|
-
var defaultFilter = /* @__PURE__ */
|
|
244
|
+
var defaultFilter = /* @__PURE__ */ _chunk7Y37NSBMjs.__name.call(void 0, (e) => {
|
|
245
245
|
if (!(e instanceof Exception)) {
|
|
246
|
-
|
|
247
|
-
if (
|
|
246
|
+
_chunk7Y37NSBMjs.log.call(void 0, e.message, "error");
|
|
247
|
+
if (_chunk7Y37NSBMjs.LOG_LEVEL <= 0)
|
|
248
248
|
console.error(e.stack);
|
|
249
249
|
e = new UndefinedException(e.message || e);
|
|
250
250
|
} else {
|
|
251
|
-
|
|
252
|
-
if (
|
|
251
|
+
_chunk7Y37NSBMjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
252
|
+
if (_chunk7Y37NSBMjs.LOG_LEVEL <= 0)
|
|
253
253
|
console.error(e.stack);
|
|
254
254
|
}
|
|
255
255
|
return e.data;
|
|
@@ -267,7 +267,7 @@ var Histroy = (_class = class {constructor() { _class.prototype.__init.call(this
|
|
|
267
267
|
return false;
|
|
268
268
|
}
|
|
269
269
|
}, _class);
|
|
270
|
-
|
|
270
|
+
_chunk7Y37NSBMjs.__name.call(void 0, Histroy, "Histroy");
|
|
271
271
|
|
|
272
272
|
// src/context.ts
|
|
273
273
|
var debug = _debug2.default.call(void 0, "phecda-server(Context)");
|
|
@@ -280,7 +280,7 @@ var _Context = class {
|
|
|
280
280
|
constructor(data) {
|
|
281
281
|
this.data = data;
|
|
282
282
|
this.history = new Histroy();
|
|
283
|
-
if (
|
|
283
|
+
if (_chunk7Y37NSBMjs.IS_HMR)
|
|
284
284
|
data._context = this;
|
|
285
285
|
}
|
|
286
286
|
async run(opts, successCb, failCb) {
|
|
@@ -322,7 +322,7 @@ var _Context = class {
|
|
|
322
322
|
usePipe(args) {
|
|
323
323
|
return Promise.all(args.map((item) => {
|
|
324
324
|
if (item.pipe && !_Context.pipeRecord[item.pipe]) {
|
|
325
|
-
if (
|
|
325
|
+
if (_chunk7Y37NSBMjs.IS_STRICT) {
|
|
326
326
|
throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
|
|
327
327
|
} else {
|
|
328
328
|
debug(`Can't find pipe named "${item.pipe}" when handling the ${item.index + 1}th argument of the func "${this.data.func}" on module "${this.data.tag}",use default pipe instead`);
|
|
@@ -334,7 +334,7 @@ var _Context = class {
|
|
|
334
334
|
}
|
|
335
335
|
useFilter(arg, filter = "default") {
|
|
336
336
|
if (!_Context.filterRecord[filter]) {
|
|
337
|
-
if (
|
|
337
|
+
if (_chunk7Y37NSBMjs.IS_STRICT) {
|
|
338
338
|
throw new FrameworkException(`can't find filter named "${filter}"`);
|
|
339
339
|
} else {
|
|
340
340
|
debug(`Can't find filter named "${filter}" when handling func "${this.data.func}" on module "${this.data.tag}",use default filter instead`);
|
|
@@ -347,7 +347,7 @@ var _Context = class {
|
|
|
347
347
|
for (const guard of guards) {
|
|
348
348
|
if (this.history.record(guard, "guard")) {
|
|
349
349
|
if (!(guard in _Context.guardRecord)) {
|
|
350
|
-
if (
|
|
350
|
+
if (_chunk7Y37NSBMjs.IS_STRICT)
|
|
351
351
|
throw new FrameworkException(`Can't find guard named "${guard}"`);
|
|
352
352
|
else
|
|
353
353
|
debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
@@ -370,7 +370,7 @@ var _Context = class {
|
|
|
370
370
|
for (const interceptor of interceptors) {
|
|
371
371
|
if (this.history.record(interceptor, "interceptor")) {
|
|
372
372
|
if (!(interceptor in _Context.interceptorRecord)) {
|
|
373
|
-
if (
|
|
373
|
+
if (_chunk7Y37NSBMjs.IS_STRICT)
|
|
374
374
|
throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
|
|
375
375
|
else
|
|
376
376
|
debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
@@ -391,7 +391,7 @@ var _Context = class {
|
|
|
391
391
|
const ret = [];
|
|
392
392
|
for (const m of plugins) {
|
|
393
393
|
if (!(m in _Context.pluginRecord)) {
|
|
394
|
-
if (
|
|
394
|
+
if (_chunk7Y37NSBMjs.IS_STRICT)
|
|
395
395
|
throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
396
396
|
continue;
|
|
397
397
|
}
|
|
@@ -401,46 +401,46 @@ var _Context = class {
|
|
|
401
401
|
}
|
|
402
402
|
};
|
|
403
403
|
var Context = _Context;
|
|
404
|
-
|
|
405
|
-
|
|
404
|
+
_chunk7Y37NSBMjs.__name.call(void 0, Context, "Context");
|
|
405
|
+
_chunk7Y37NSBMjs.__publicField.call(void 0, Context, "filterRecord", {
|
|
406
406
|
default: defaultFilter
|
|
407
407
|
});
|
|
408
|
-
|
|
408
|
+
_chunk7Y37NSBMjs.__publicField.call(void 0, Context, "pipeRecord", {
|
|
409
409
|
default: defaultPipe
|
|
410
410
|
});
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
_chunk7Y37NSBMjs.__publicField.call(void 0, Context, "guardRecord", {});
|
|
412
|
+
_chunk7Y37NSBMjs.__publicField.call(void 0, Context, "interceptorRecord", {});
|
|
413
|
+
_chunk7Y37NSBMjs.__publicField.call(void 0, Context, "pluginRecord", {});
|
|
414
414
|
function addPlugin(key, handler) {
|
|
415
415
|
if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler)
|
|
416
|
-
|
|
416
|
+
_chunk7Y37NSBMjs.log.call(void 0, `overwrite Plugin "${String(key)}"`, "warn");
|
|
417
417
|
Context.pluginRecord[key] = handler;
|
|
418
418
|
}
|
|
419
|
-
|
|
419
|
+
_chunk7Y37NSBMjs.__name.call(void 0, addPlugin, "addPlugin");
|
|
420
420
|
function addPipe(key, handler) {
|
|
421
421
|
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)
|
|
422
|
-
|
|
422
|
+
_chunk7Y37NSBMjs.log.call(void 0, `overwrite Pipe "${String(key)}"`, "warn");
|
|
423
423
|
Context.pipeRecord[key] = handler;
|
|
424
424
|
}
|
|
425
|
-
|
|
425
|
+
_chunk7Y37NSBMjs.__name.call(void 0, addPipe, "addPipe");
|
|
426
426
|
function addFilter(key, handler) {
|
|
427
427
|
if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)
|
|
428
|
-
|
|
428
|
+
_chunk7Y37NSBMjs.log.call(void 0, `overwrite Filter "${String(key)}"`, "warn");
|
|
429
429
|
Context.filterRecord[key] = handler;
|
|
430
430
|
}
|
|
431
|
-
|
|
431
|
+
_chunk7Y37NSBMjs.__name.call(void 0, addFilter, "addFilter");
|
|
432
432
|
function addGuard(key, handler) {
|
|
433
433
|
if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)
|
|
434
|
-
|
|
434
|
+
_chunk7Y37NSBMjs.log.call(void 0, `overwrite Guard "${String(key)}"`, "warn");
|
|
435
435
|
Context.guardRecord[key] = handler;
|
|
436
436
|
}
|
|
437
|
-
|
|
437
|
+
_chunk7Y37NSBMjs.__name.call(void 0, addGuard, "addGuard");
|
|
438
438
|
function addInterceptor(key, handler) {
|
|
439
439
|
if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)
|
|
440
|
-
|
|
440
|
+
_chunk7Y37NSBMjs.log.call(void 0, `overwrite Interceptor "${String(key)}"`, "warn");
|
|
441
441
|
Context.interceptorRecord[key] = handler;
|
|
442
442
|
}
|
|
443
|
-
|
|
443
|
+
_chunk7Y37NSBMjs.__name.call(void 0, addInterceptor, "addInterceptor");
|
|
444
444
|
function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller = "http") {
|
|
445
445
|
const pluginSet = new Set(plugins);
|
|
446
446
|
const guardSet = new Set(guards);
|
|
@@ -480,16 +480,16 @@ function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller =
|
|
|
480
480
|
...filterSet
|
|
481
481
|
].filter((i) => !Context.filterRecord[i]);
|
|
482
482
|
if (missPlugins.length)
|
|
483
|
-
|
|
483
|
+
_chunk7Y37NSBMjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
|
|
484
484
|
if (missGuards.length)
|
|
485
|
-
|
|
485
|
+
_chunk7Y37NSBMjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
486
486
|
if (missInterceptors.length)
|
|
487
|
-
|
|
487
|
+
_chunk7Y37NSBMjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
488
488
|
if (missPipes.length)
|
|
489
|
-
|
|
489
|
+
_chunk7Y37NSBMjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
490
490
|
if (missFilters.length)
|
|
491
|
-
|
|
492
|
-
warningSet.forEach((warn) =>
|
|
491
|
+
_chunk7Y37NSBMjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
492
|
+
warningSet.forEach((warn) => _chunk7Y37NSBMjs.log.call(void 0, warn, "warn"));
|
|
493
493
|
return {
|
|
494
494
|
missPlugins,
|
|
495
495
|
missGuards,
|
|
@@ -498,7 +498,7 @@ function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller =
|
|
|
498
498
|
missFilters
|
|
499
499
|
};
|
|
500
500
|
}
|
|
501
|
-
|
|
501
|
+
_chunk7Y37NSBMjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
502
502
|
|
|
503
503
|
|
|
504
504
|
|
|
@@ -534,3 +534,4 @@ _chunkYR5Q5F2Kjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
|
534
534
|
|
|
535
535
|
|
|
536
536
|
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.TimerException = TimerException; exports.WorkerException = WorkerException; exports.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.mergeArray = mergeArray; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.detectAopDep = detectAopDep;
|
|
537
|
+
//# sourceMappingURL=chunk-RGLTGKAU.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/exception/timer.ts","../src/exception/worker.ts","../src/hmr.ts","../src/server/helper.ts","../src/rpc/helper.ts","../src/decorators/helper.ts","../src/context.ts","../src/filter.ts","../src/history.ts"],"names":["Exception","Error","message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","isPhecda","plainToClass","transformInstance","defaultPipe","arg","reflect","index","instance","err","length","undefined","Number","Boolean","includes","Object","is","NaN","UndefinedException","ForbiddenException","BadRequestException","NotFoundException","ConflictException","BadGatewayException","InvalidInputException","UnsupportedMediaTypeException","PayloadLargeException","TimeoutException","UnauthorizedException","ServiceUnavailableException","FrameworkException","TimerException","WorkerException","HMR","cb","IS_HMR","globalThis","__PS_HMR__","push","resolveDep","ret","key","argToReq","params","args","headers","req","body","query","forEach","param","type","hostname","genClientQueue","process","pid","shallowClone","obj","mergeObject","assign","mergeArray","filter","item","flat","pc","Debug","defaultFilter","e","log","LOG_LEVEL","console","error","stack","name","Histroy","guard","interceptor","record","debug","Context","method","history","postInterceptors","_context","run","opts","successCb","failCb","meta","moduleMap","globalGuards","globalFilter","globalInterceptors","globalPipe","paramsType","guards","interceptors","tag","func","ctx","useGuard","i1","useInterceptor","usePipe","map","pipe","get","returnData","i2","usePostInterceptor","useFilter","Promise","all","pipeRecord","IS_STRICT","default","filterRecord","guardRecord","interceptorRecord","interceptRet","usePlugin","plugins","m","pluginRecord","addPlugin","handler","String","addPipe","addFilter","addGuard","addInterceptor","detectAopDep","controller","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","warningSet","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","white","join","magenta","cyan","blue","red","warn"],"mappings":";;;;;;;;;;;AAEO,IAAMA,YAAN,cAAwBC,MAAAA;EACVC;EAAwBC;EAAmBC;EAA9DC,YAAmBH,SAAwBC,SAAS,GAAUC,cAAc,aAAa;AACvF,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAmBC;EAE9D;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQ,CAACI,eAAe;IAAK;EAC3G;AACF;AARaP;;;ACAN,IAAMQ,oBAAN,cAAgCR,UAAAA;EACrCK,YAAYH,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaM;;;ACFb,SAASC,UAAUC,cAAcC,yBAAyB;AAKnD,IAAMC,cAAwB,wBAAC,EAAEC,KAAKC,SAASC,MAAK,MAAO;AAChE,MAAIN,SAASK,OAAAA,GAAU;AACrB,UAAME,WAAWN,aAAaI,SAASD,GAAAA;AACvC,UAAMI,MAAMN,kBAAkBK,QAAAA;AAC9B,QAAIC,IAAIC,SAAS;AACf,YAAM,IAAIV,kBAAkBS,IAAI,EAAE;AAEpCJ,UAAMG;EACR,OACK;AACH,QAAIH,QAAQM,UAAa,CAACL;AACxB,aAAOK;AAET,QAAI;MAACC;MAAQC;MAASC,SAASR,OAAAA,GAAU;AACvCD,YAAMC,QAAQD,GAAAA;AAEd,UAAIC,YAAYM,UAAUG,OAAOC,GAAGX,KAAKY,GAAAA;AACvC,cAAM,IAAIjB,kBAAkB,aAAaY,OAAOL,KAAAA,IAAS,sBAAsB;IACnF;EACF;AACA,SAAOF;AACT,GArBqC;;;ACH9B,IAAMa,qBAAN,cAAiC1B,UAAAA;EACtCK,YAAYH,SAAiB;AAC3B,UAAMA,SAAS,KAAK,iBAAA;EACtB;AACF;AAJawB;;;ACAN,IAAMC,qBAAN,cAAiC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,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEjF,MAAIH,UAAUvI;AACZ0D,QAAI,GAAGJ,GAAGuF,KAAK,SAASN,UAAUG,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEnE,MAAIF,YAAYxI;AACd0D,QAAI,GAAGJ,GAAGwF,IAAI,WAAWN,YAAYE,KAAK,GAAA,IAAO,mBAAmB,MAAA;AAEtET,aAAW1F,QAAQwG,CAAAA,SAAQrF,IAAIqF,MAAM,MAAA,CAAA;AAErC,SAAO;IACLX;IACAC;IACAC;IACAC;IACAC;EACF;AACF;AA7DgBf","sourcesContent":["import { ERROR_SYMBOL } from '../common'\r\n\r\nexport class Exception extends Error {\r\n constructor(public message: string, public status = 0, public description = 'Exception') {\r\n super(message)\r\n }\r\n\r\n get data() {\r\n return { message: this.message, description: this.description, status: this.status, [ERROR_SYMBOL]: true }\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class ValidateException extends Exception {\r\n constructor(message: string) {\r\n super(message, 400, 'Validate exception')\r\n }\r\n}\r\n","import { isPhecda, plainToClass, transformInstance } from 'phecda-core'\r\nimport { ValidateException } from './exception/validate'\r\n\r\nimport type { PipeType } from './context'\r\n\r\nexport const defaultPipe: PipeType = ({ arg, reflect, index }) => {\r\n if (isPhecda(reflect)) {\r\n const instance = plainToClass(reflect, arg)\r\n const err = transformInstance(instance)\r\n if (err.length > 0)\r\n throw new ValidateException(err[0])\r\n\r\n arg = instance\r\n }\r\n else {\r\n if (arg === undefined && !reflect)\r\n return undefined\r\n\r\n if ([Number, Boolean].includes(reflect)) {\r\n arg = reflect(arg)\r\n\r\n if (reflect === Number && Object.is(arg, NaN))\r\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\r\n }\r\n }\r\n return arg\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class UndefinedException extends Exception {\r\n constructor(message: string) {\r\n super(message, 500, 'Undefined error')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class ForbiddenException extends Exception {\r\n constructor(message: string) {\r\n super(message, 403, 'Forbidden resource')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class BadRequestException extends Exception {\r\n constructor(message: string) {\r\n super(message, 400, 'Bad Request')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class NotFoundException extends Exception {\r\n constructor(message: string) {\r\n super(message, 404, 'Not Found')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class ConflictException extends Exception {\r\n constructor(message: string) {\r\n super(message, 409, 'Conflict')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class BadGatewayException extends Exception {\r\n constructor(message: string) {\r\n super(message, 502, 'Bad Gatrway')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class InvalidInputException extends Exception {\r\n constructor(message: string) {\r\n super(message, 502, 'Invalid Input')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class UnsupportedMediaTypeException extends Exception {\r\n constructor(message: string) {\r\n super(message, 415, 'Unsupported Media Type')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class PayloadLargeException extends Exception {\r\n constructor(message: string) {\r\n super(message, 413, 'Payload Too Large')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class TimeoutException extends Exception {\r\n constructor(message: string) {\r\n super(message, 408, 'Request Timeout',\r\n )\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class UnauthorizedException extends Exception {\r\n constructor(message: string) {\r\n super(message, 401, 'Unauthorized')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class ServiceUnavailableException extends Exception {\r\n constructor(message: string) {\r\n super(message, 503, 'Service Unavailable')\r\n }\r\n}\r\n","import { Exception } from './base'\r\n\r\nexport class FrameworkException extends Exception {\r\n constructor(message: string) {\r\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\r\n }\r\n}\r\n","import { Exception } from './base'\r\nexport class TimerException extends Exception {\r\n constructor(message: string) {\r\n super(message, 0, 'Timer Error')\r\n }\r\n}\r\n","import { Exception } from './base'\r\nexport class WorkerException extends Exception {\r\n constructor(message: string) {\r\n super(message, 0, 'Worker Error')\r\n }\r\n}\r\n","import { IS_HMR } from './common'\r\nexport function HMR(cb: (...args: any) => any) {\r\n if (IS_HMR)\r\n globalThis.__PS_HMR__?.push(cb)\r\n}\r\n","import { IncomingHttpHeaders } from 'node:http'\r\nimport { BaseContext, DefaultOptions } from '../types'\r\nimport type { ControllerMetaData } from '../meta'\r\n\r\nexport function resolveDep(ret: any, key: string) {\r\n if (key)\r\n return ret?.[key]\r\n return ret\r\n}\r\n\r\nexport interface HttpOptions extends DefaultOptions {\r\n\r\n /**\r\n * 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求\r\n */\r\n route?: string\r\n\r\n /**\r\n * 专用路由的插件(work for merge request),\r\n */\r\n plugins?: string[]\r\n\r\n}\r\n\r\nexport interface HttpContext extends BaseContext {\r\n parallel?: true\r\n index?: number\r\n query: Record<string, any>\r\n params: Record<string, string>\r\n body: Record<string, any>\r\n headers: IncomingHttpHeaders\r\n // redirect:(url:string)=>void\r\n\r\n}\r\nexport function argToReq(params: ControllerMetaData['params'], args: any[], headers: Record<string, any>) {\r\n const req = {\r\n body: {},\r\n query: {},\r\n params: {},\r\n headers,\r\n } as any\r\n\r\n params.forEach((param) => {\r\n if (param.key)\r\n req[param.type][param.key] = args[param.index]\r\n\r\n else\r\n req[param.type] = args[param.index]\r\n })\r\n\r\n return req\r\n}\r\n","import { hostname } from 'os'\r\nimport { BaseContext, DefaultOptions } from '../types'\r\n\r\nexport function genClientQueue(key?: string) {\r\n return `PS-${key ? `${key}-` : ''}${hostname()}-${process.pid}`\r\n}\r\n\r\nexport interface RpcServerOptions extends DefaultOptions {\r\n\r\n}\r\n\r\nexport interface RpcClientOptions {\r\n // add to clientQueue\r\n key?: string\r\n timeout?: number\r\n max?: number\r\n}\r\nexport interface RpcContext extends BaseContext {\r\n args: any[]\r\n id: string\r\n queue: string\r\n isEvent?: boolean\r\n}\r\n","export function shallowClone(obj: any) {\r\n return { ...obj }\r\n}\r\nexport function mergeObject(...args: any[]) {\r\n return Object.assign({}, ...args)\r\n}\r\nexport function mergeArray(...args: any[]) {\r\n return args.filter(item => !!item).flat()\r\n}\r\n","import pc from 'picocolors'\r\nimport Debug from 'debug'\r\nimport { defaultPipe } from './pipe'\r\nimport { ForbiddenException, FrameworkException } from './exception'\r\nimport { defaultFilter } from './filter'\r\nimport { Histroy } from './history'\r\nimport type { BaseContext, DefaultOptions } from './types'\r\nimport { IS_HMR, IS_STRICT } from './common'\r\nimport type { ControllerMeta, Meta } from './meta'\r\nimport { log } from './utils'\r\nimport type { Exception } from './exception'\r\nimport { resolveDep } from './helper'\r\n\r\nconst debug = Debug('phecda-server(Context)')\r\n\r\nexport interface PipeArg { arg: any; pipe?: string; key: string; type: string; index: number; reflect: any; define: Record<string, any> }\r\nexport type GuardType<C extends BaseContext = any> = ((ctx: C) => Promise<boolean> | boolean)\r\nexport type InterceptorType<C extends BaseContext = any> = (ctx: C) => (any | ((ret: any) => any))\r\nexport type PipeType<C extends BaseContext = any> = (arg: PipeArg, ctx: C) => Promise<any>\r\nexport type FilterType<C extends BaseContext = any, E extends Exception = any> = (err: E | Error, ctx?: C) => Error | any\r\n\r\nexport class Context<Data extends BaseContext> {\r\n method: string\r\n params: string[]\r\n history = new Histroy()\r\n\r\n static filterRecord: Record<PropertyKey, FilterType> = {\r\n default: defaultFilter,\r\n }\r\n\r\n static pipeRecord: Record<PropertyKey, PipeType> = {\r\n default: defaultPipe,\r\n }\r\n\r\n static guardRecord: Record<PropertyKey, GuardType> = {}\r\n static interceptorRecord: Record<PropertyKey, InterceptorType> = {}\r\n\r\n static pluginRecord: Record<PropertyKey, any> = {}\r\n private postInterceptors: Function[]\r\n\r\n constructor(public data: Data) {\r\n if (IS_HMR)\r\n // @ts-expect-error work for debug\r\n data._context = this\r\n }\r\n\r\n public async run<ReturnData = any, ReturnErr = any>(opts: DefaultOptions, successCb: (data: any) => ReturnData, failCb: (err: any) => ReturnErr) {\r\n const { meta, moduleMap } = this.data\r\n const { globalGuards = [], globalFilter, globalInterceptors = [], globalPipe } = opts\r\n const {\r\n paramsType,\r\n data: {\r\n guards, interceptors, params,\r\n tag, func, ctx, filter,\r\n\r\n },\r\n } = meta\r\n\r\n try {\r\n await this.useGuard([...globalGuards, ...guards])\r\n const i1 = await this.useInterceptor([...globalInterceptors, ...interceptors])\r\n if (i1 !== undefined)\r\n return successCb(i1)\r\n\r\n const args = await this.usePipe(params.map((param) => {\r\n return { arg: resolveDep(this.data[param.type], param.key), reflect: paramsType[param.index], ...param, pipe: param.pipe || globalPipe }\r\n }))\r\n const instance = moduleMap.get(tag)!\r\n if (ctx)\r\n instance[ctx] = this.data\r\n const returnData = await instance[func](...args)\r\n const i2 = await this.usePostInterceptor(returnData)\r\n if (i2 !== undefined)\r\n return successCb(i2)\r\n\r\n return successCb(returnData)\r\n }\r\n catch (e) {\r\n const err = await this.useFilter(e, filter || globalFilter)\r\n return failCb(err)\r\n }\r\n }\r\n\r\n private usePipe(args: PipeArg[]) {\r\n return Promise.all(args.map((item) => {\r\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\r\n if (IS_STRICT) {\r\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\r\n }\r\n\r\n else {\r\n debug(`Can't find pipe named \"${item.pipe}\" when handling the ${item.index + 1}th argument of the func \"${this.data.func}\" on module \"${this.data.tag}\",use default pipe instead`)\r\n\r\n return Context.pipeRecord.default(item, this.data)\r\n }\r\n }\r\n\r\n return Context.pipeRecord[item.pipe || 'default'](item, this.data)\r\n }))\r\n }\r\n\r\n private useFilter(arg: any, filter = 'default') {\r\n if (!Context.filterRecord[filter]) {\r\n if (IS_STRICT) {\r\n throw new FrameworkException(`can't find filter named \"${filter}\"`)\r\n }\r\n else {\r\n debug(`Can't find filter named \"${filter}\" when handling func \"${this.data.func}\" on module \"${this.data.tag}\",use default filter instead`)\r\n\r\n return Context.filterRecord.default(arg, this.data)\r\n }\r\n }\r\n\r\n return Context.filterRecord[filter](arg, this.data)\r\n }\r\n\r\n private async useGuard(guards: string[]) {\r\n for (const guard of guards) {\r\n if (this.history.record(guard, 'guard')) {\r\n if (!(guard in Context.guardRecord)) {\r\n if (IS_STRICT)\r\n throw new FrameworkException(`Can't find guard named \"${guard}\"`)\r\n else debug(`Can't find guard named \"${guard}\" when handling func \"${this.data.func}\" on module \"${this.data.tag}\",skip it`)\r\n continue\r\n }\r\n if (!await Context.guardRecord[guard](this.data))\r\n throw new ForbiddenException(`Guard exception--[${guard}]`)\r\n }\r\n }\r\n }\r\n\r\n private async usePostInterceptor(data: any) {\r\n for (const cb of this.postInterceptors) {\r\n const ret = await cb(data)\r\n if (ret !== undefined)\r\n return ret\r\n }\r\n }\r\n\r\n private async useInterceptor(interceptors: string[]) {\r\n const cb = []\r\n for (const interceptor of interceptors) {\r\n if (this.history.record(interceptor, 'interceptor')) {\r\n if (!(interceptor in Context.interceptorRecord)) {\r\n if (IS_STRICT)\r\n throw new FrameworkException(`can't find interceptor named \"${interceptor}\"`)\r\n else debug(`Can't find interceptor named \"${interceptor}\" when handling func \"${this.data.func}\" on module \"${this.data.tag}\",skip it`)\r\n\r\n continue\r\n }\r\n const interceptRet = await Context.interceptorRecord[interceptor](this.data)\r\n if (interceptRet !== undefined) {\r\n if (typeof interceptRet === 'function')\r\n cb.push(interceptRet)\r\n\r\n else\r\n return interceptRet\r\n }\r\n }\r\n }\r\n this.postInterceptors = cb\r\n }\r\n\r\n static usePlugin(plugins: string[]) {\r\n const ret = []\r\n for (const m of plugins) {\r\n if (!(m in Context.pluginRecord)) {\r\n if (IS_STRICT)\r\n throw new FrameworkException(`can't find middleware named '${m}'`)\r\n\r\n continue\r\n }\r\n ret.push(Context.pluginRecord[m])\r\n }\r\n return ret as any[]\r\n }\r\n}\r\n\r\nexport function addPlugin<T>(key: PropertyKey, handler: T) {\r\n if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler)\r\n log(`overwrite Plugin \"${String(key)}\"`, 'warn')\r\n\r\n Context.pluginRecord[key] = handler\r\n}\r\n\r\nexport function addPipe<C extends BaseContext>(key: PropertyKey, handler: PipeType<C>) {\r\n if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)\r\n log(`overwrite Pipe \"${String(key)}\"`, 'warn')\r\n Context.pipeRecord[key] = handler\r\n}\r\n\r\nexport function addFilter<C extends BaseContext>(key: PropertyKey, handler: FilterType<C>) {\r\n if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)\r\n log(`overwrite Filter \"${String(key)}\"`, 'warn')\r\n Context.filterRecord[key] = handler\r\n}\r\n\r\nexport function addGuard<C extends BaseContext>(key: PropertyKey, handler: GuardType<C>) {\r\n if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)\r\n log(`overwrite Guard \"${String(key)}\"`, 'warn')\r\n Context.guardRecord[key] = handler\r\n}\r\n\r\nexport function addInterceptor<C extends BaseContext>(key: PropertyKey, handler: InterceptorType<C>) {\r\n if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)\r\n log(`overwrite Interceptor \"${String(key)}\"`, 'warn')\r\n Context.interceptorRecord[key] = handler\r\n}\r\n\r\n// detect whether plugin/filter/pipe/guard/intercept is injected\r\nexport function detectAopDep(meta: Meta[], { guards, interceptors, plugins }: {\r\n guards?: string[]\r\n interceptors?: string[]\r\n plugins?: string[]\r\n} = {}, controller: string = 'http') {\r\n const pluginSet = new Set<string>(plugins)\r\n\r\n const guardSet = new Set<string>(guards)\r\n const interceptorSet = new Set<string>(interceptors)\r\n const pipeSet = new Set<string>()\r\n const filterSet = new Set<string>()\r\n const warningSet = new Set<string>();\r\n\r\n (meta as ControllerMeta[]).forEach(({ data }) => {\r\n if (data.controller !== controller) {\r\n if (data[controller])\r\n 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}\"`)\r\n\r\n return\r\n }\r\n if (data.filter)\r\n filterSet.add(data.filter)\r\n\r\n data.interceptors.forEach(i => interceptorSet.add(i))\r\n data.guards.forEach(i => guardSet.add(i))\r\n data.plugins.forEach(i => pluginSet.add(i))\r\n data.params.forEach((i) => {\r\n if (i.pipe)\r\n pipeSet.add(i.pipe)\r\n })\r\n })\r\n\r\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\r\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\r\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\r\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\r\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\r\n\r\n if (missPlugins.length)\r\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\r\n if (missGuards.length)\r\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\r\n\r\n if (missInterceptors.length)\r\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\r\n\r\n if (missPipes.length)\r\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\r\n\r\n if (missFilters.length)\r\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\r\n\r\n warningSet.forEach(warn => log(warn, 'warn'))\r\n\r\n return {\r\n missPlugins,\r\n missGuards,\r\n missInterceptors,\r\n missPipes,\r\n missFilters,\r\n }\r\n}\r\n","import { LOG_LEVEL } from './common'\r\nimport { Exception, UndefinedException } from './exception'\r\nimport { log } from './utils'\r\nimport type { FilterType } from './context'\r\n\r\nexport const defaultFilter: FilterType = (e) => {\r\n if (!(e instanceof Exception)) {\r\n log(e.message, 'error')\r\n if (LOG_LEVEL <= 0)\r\n console.error(e.stack)\r\n\r\n e = new UndefinedException(e.message || e)\r\n }\r\n else {\r\n log(`[${e.constructor.name}] ${e.message}`, 'error')\r\n if (LOG_LEVEL <= 0)\r\n console.error(e.stack)\r\n }\r\n\r\n return e.data\r\n}\r\n","export class Histroy {\r\n guard: string[] = []\r\n interceptor: string[] = []\r\n record(name: string, type: 'guard' | 'interceptor') {\r\n if (!this[type].includes(name)) {\r\n this[type].push(name)\r\n return true\r\n }\r\n return false\r\n }\r\n}\r\n"]}
|