phecda-server 7.0.0-alpha.0 → 7.0.0-alpha.10
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/assets/ps.json +24 -24
- package/assets/schema.json +55 -55
- package/bin/cli.mjs +31 -18
- package/dist/chunk-4LLLQOMF.js +152 -0
- package/dist/{chunk-BGXSMOLX.js → chunk-6OQ2SB5W.js} +138 -70
- package/dist/{chunk-SW5IKE5H.js → chunk-G7JFKM2M.js} +136 -89
- package/dist/{chunk-MBCHNDAY.js → chunk-KCPBITYZ.js} +24 -24
- package/dist/{chunk-HMVLXNV3.mjs → chunk-MUI6MTUO.mjs} +1 -1
- package/dist/chunk-NQ55PA2X.mjs +152 -0
- package/dist/{chunk-5622RBNB.mjs → chunk-YCES6ABN.mjs} +125 -57
- package/dist/{chunk-P75VKZJY.mjs → chunk-Z7NAAE4M.mjs} +94 -47
- package/dist/{core-BIcUwV18.d.mts → core-CUTbX_IS.d.ts} +5 -3
- package/dist/{core-CYwEPfN4.d.ts → core-DIfgUKIU.d.mts} +5 -3
- package/dist/helper.d.mts +8 -6
- package/dist/helper.d.ts +8 -6
- package/dist/helper.js +8 -3
- package/dist/helper.mjs +10 -5
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +43 -44
- package/dist/http/elysia/index.mjs +9 -10
- package/dist/http/express/index.d.mts +4 -4
- package/dist/http/express/index.d.ts +4 -4
- package/dist/http/express/index.js +40 -41
- package/dist/http/express/index.mjs +9 -10
- package/dist/http/fastify/index.d.mts +4 -4
- package/dist/http/fastify/index.d.ts +4 -4
- package/dist/http/fastify/index.js +41 -42
- package/dist/http/fastify/index.mjs +9 -10
- package/dist/http/h3/index.d.mts +4 -4
- package/dist/http/h3/index.d.ts +4 -4
- package/dist/http/h3/index.js +41 -42
- package/dist/http/h3/index.mjs +9 -10
- package/dist/http/hono/index.d.mts +4 -4
- package/dist/http/hono/index.d.ts +4 -4
- package/dist/http/hono/index.js +37 -39
- package/dist/http/hono/index.mjs +5 -7
- package/dist/http/hyper-express/index.d.mts +4 -4
- package/dist/http/hyper-express/index.d.ts +4 -4
- package/dist/http/hyper-express/index.js +38 -39
- package/dist/http/hyper-express/index.mjs +8 -9
- package/dist/http/koa/index.d.mts +4 -4
- package/dist/http/koa/index.d.ts +4 -4
- package/dist/http/koa/index.js +40 -41
- package/dist/http/koa/index.mjs +9 -10
- package/dist/index.d.mts +46 -40
- package/dist/index.d.ts +46 -40
- package/dist/index.js +48 -42
- package/dist/index.mjs +21 -15
- package/dist/{meta-BXKLFTgG.d.mts → meta-CR-D39hQ.d.mts} +7 -5
- package/dist/{meta-BXKLFTgG.d.ts → meta-CR-D39hQ.d.ts} +7 -5
- package/dist/rpc/bullmq/index.d.mts +5 -5
- package/dist/rpc/bullmq/index.d.ts +5 -5
- package/dist/rpc/bullmq/index.js +15 -14
- package/dist/rpc/bullmq/index.mjs +4 -3
- package/dist/rpc/kafka/index.d.mts +4 -4
- package/dist/rpc/kafka/index.d.ts +4 -4
- package/dist/rpc/kafka/index.js +15 -14
- package/dist/rpc/kafka/index.mjs +3 -2
- package/dist/rpc/nats/index.d.mts +4 -4
- package/dist/rpc/nats/index.d.ts +4 -4
- package/dist/rpc/nats/index.js +14 -13
- package/dist/rpc/nats/index.mjs +4 -3
- package/dist/rpc/rabbitmq/index.d.mts +4 -4
- package/dist/rpc/rabbitmq/index.d.ts +4 -4
- package/dist/rpc/rabbitmq/index.js +16 -15
- package/dist/rpc/rabbitmq/index.mjs +4 -3
- package/dist/rpc/redis/index.d.mts +4 -4
- package/dist/rpc/redis/index.d.ts +4 -4
- package/dist/rpc/redis/index.js +14 -13
- package/dist/rpc/redis/index.mjs +4 -3
- package/dist/test.d.mts +3 -3
- package/dist/test.d.ts +3 -3
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-h40T3cRG.d.mts → types-BF1TDbFV.d.ts} +4 -3
- package/dist/{types-BtbL49Zs.d.mts → types-DYRu0vic.d.ts} +4 -3
- package/dist/{types-VFzEM7LL.d.ts → types-DYviSl5B.d.mts} +4 -3
- package/dist/{types-m3IEDKjP.d.ts → types-DqH1qA-q.d.mts} +4 -3
- package/package.json +8 -5
- package/register/export.mjs +30 -0
- package/register/index.mjs +50 -40
- package/register/loader.mjs +384 -367
- package/register/utils.mjs +60 -56
- package/dist/chunk-J5CFUN4V.js +0 -73
- package/dist/chunk-WHJ5FALK.mjs +0 -73
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunk4LLLQOMFjs = require('./chunk-4LLLQOMF.js');
|
|
8
11
|
|
|
9
12
|
// src/helper.ts
|
|
10
13
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
@@ -12,15 +15,16 @@ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefau
|
|
|
12
15
|
// src/context.ts
|
|
13
16
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
17
|
|
|
18
|
+
|
|
15
19
|
// src/pipe.ts
|
|
16
|
-
var defaultPipe = /* @__PURE__ */
|
|
20
|
+
var defaultPipe = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, ({ arg }) => {
|
|
17
21
|
return arg;
|
|
18
22
|
}, "defaultPipe");
|
|
19
23
|
|
|
20
24
|
// src/exception/base.ts
|
|
21
25
|
var Exception = class extends Error {
|
|
22
26
|
static {
|
|
23
|
-
|
|
27
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "Exception");
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
|
|
@@ -33,7 +37,7 @@ var Exception = class extends Error {
|
|
|
33
37
|
message: this.message,
|
|
34
38
|
description: this.description,
|
|
35
39
|
status: this.status,
|
|
36
|
-
[
|
|
40
|
+
[_chunk4LLLQOMFjs.ERROR_SYMBOL]: true
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
43
|
};
|
|
@@ -41,7 +45,7 @@ var Exception = class extends Error {
|
|
|
41
45
|
// src/exception/undefine.ts
|
|
42
46
|
var UndefinedException = class extends Exception {
|
|
43
47
|
static {
|
|
44
|
-
|
|
48
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "UndefinedException");
|
|
45
49
|
}
|
|
46
50
|
constructor(message) {
|
|
47
51
|
super(message, 500, "Undefined error");
|
|
@@ -51,7 +55,7 @@ var UndefinedException = class extends Exception {
|
|
|
51
55
|
// src/exception/validate.ts
|
|
52
56
|
var ValidateException = class extends Exception {
|
|
53
57
|
static {
|
|
54
|
-
|
|
58
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "ValidateException");
|
|
55
59
|
}
|
|
56
60
|
constructor(message) {
|
|
57
61
|
super(message, 400, "Validate exception");
|
|
@@ -61,7 +65,7 @@ var ValidateException = class extends Exception {
|
|
|
61
65
|
// src/exception/forbidden.ts
|
|
62
66
|
var ForbiddenException = class extends Exception {
|
|
63
67
|
static {
|
|
64
|
-
|
|
68
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "ForbiddenException");
|
|
65
69
|
}
|
|
66
70
|
constructor(message) {
|
|
67
71
|
super(message, 403, "Forbidden resource");
|
|
@@ -71,7 +75,7 @@ var ForbiddenException = class extends Exception {
|
|
|
71
75
|
// src/exception/bad-request.ts
|
|
72
76
|
var BadRequestException = class extends Exception {
|
|
73
77
|
static {
|
|
74
|
-
|
|
78
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "BadRequestException");
|
|
75
79
|
}
|
|
76
80
|
constructor(message) {
|
|
77
81
|
super(message, 400, "Bad Request");
|
|
@@ -81,7 +85,7 @@ var BadRequestException = class extends Exception {
|
|
|
81
85
|
// src/exception/not-found.ts
|
|
82
86
|
var NotFoundException = class extends Exception {
|
|
83
87
|
static {
|
|
84
|
-
|
|
88
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "NotFoundException");
|
|
85
89
|
}
|
|
86
90
|
constructor(message) {
|
|
87
91
|
super(message, 404, "Not Found");
|
|
@@ -91,7 +95,7 @@ var NotFoundException = class extends Exception {
|
|
|
91
95
|
// src/exception/conflict.ts
|
|
92
96
|
var ConflictException = class extends Exception {
|
|
93
97
|
static {
|
|
94
|
-
|
|
98
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "ConflictException");
|
|
95
99
|
}
|
|
96
100
|
constructor(message) {
|
|
97
101
|
super(message, 409, "Conflict");
|
|
@@ -101,7 +105,7 @@ var ConflictException = class extends Exception {
|
|
|
101
105
|
// src/exception/bad-gateway.ts
|
|
102
106
|
var BadGatewayException = class extends Exception {
|
|
103
107
|
static {
|
|
104
|
-
|
|
108
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "BadGatewayException");
|
|
105
109
|
}
|
|
106
110
|
constructor(message) {
|
|
107
111
|
super(message, 502, "Bad Gatrway");
|
|
@@ -111,7 +115,7 @@ var BadGatewayException = class extends Exception {
|
|
|
111
115
|
// src/exception/invalid-input.ts
|
|
112
116
|
var InvalidInputException = class extends Exception {
|
|
113
117
|
static {
|
|
114
|
-
|
|
118
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "InvalidInputException");
|
|
115
119
|
}
|
|
116
120
|
constructor(message) {
|
|
117
121
|
super(message, 502, "Invalid Input");
|
|
@@ -121,7 +125,7 @@ var InvalidInputException = class extends Exception {
|
|
|
121
125
|
// src/exception/media-type.ts
|
|
122
126
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
123
127
|
static {
|
|
124
|
-
|
|
128
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "UnsupportedMediaTypeException");
|
|
125
129
|
}
|
|
126
130
|
constructor(message) {
|
|
127
131
|
super(message, 415, "Unsupported Media Type");
|
|
@@ -131,7 +135,7 @@ var UnsupportedMediaTypeException = class extends Exception {
|
|
|
131
135
|
// src/exception/payload-large.ts
|
|
132
136
|
var PayloadLargeException = class extends Exception {
|
|
133
137
|
static {
|
|
134
|
-
|
|
138
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "PayloadLargeException");
|
|
135
139
|
}
|
|
136
140
|
constructor(message) {
|
|
137
141
|
super(message, 413, "Payload Too Large");
|
|
@@ -141,7 +145,7 @@ var PayloadLargeException = class extends Exception {
|
|
|
141
145
|
// src/exception/timeout.ts
|
|
142
146
|
var TimeoutException = class extends Exception {
|
|
143
147
|
static {
|
|
144
|
-
|
|
148
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "TimeoutException");
|
|
145
149
|
}
|
|
146
150
|
constructor(message) {
|
|
147
151
|
super(message, 408, "Request Timeout");
|
|
@@ -151,7 +155,7 @@ var TimeoutException = class extends Exception {
|
|
|
151
155
|
// src/exception/unauthorized.ts
|
|
152
156
|
var UnauthorizedException = class extends Exception {
|
|
153
157
|
static {
|
|
154
|
-
|
|
158
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "UnauthorizedException");
|
|
155
159
|
}
|
|
156
160
|
constructor(message) {
|
|
157
161
|
super(message, 401, "Unauthorized");
|
|
@@ -161,7 +165,7 @@ var UnauthorizedException = class extends Exception {
|
|
|
161
165
|
// src/exception/unavailable-service.ts
|
|
162
166
|
var ServiceUnavailableException = class extends Exception {
|
|
163
167
|
static {
|
|
164
|
-
|
|
168
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "ServiceUnavailableException");
|
|
165
169
|
}
|
|
166
170
|
constructor(message) {
|
|
167
171
|
super(message, 503, "Service Unavailable");
|
|
@@ -171,7 +175,7 @@ var ServiceUnavailableException = class extends Exception {
|
|
|
171
175
|
// src/exception/framework.ts
|
|
172
176
|
var FrameworkException = class extends Exception {
|
|
173
177
|
static {
|
|
174
|
-
|
|
178
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "FrameworkException");
|
|
175
179
|
}
|
|
176
180
|
constructor(message) {
|
|
177
181
|
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
@@ -181,7 +185,7 @@ var FrameworkException = class extends Exception {
|
|
|
181
185
|
// src/exception/timer.ts
|
|
182
186
|
var TimerException = class extends Exception {
|
|
183
187
|
static {
|
|
184
|
-
|
|
188
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "TimerException");
|
|
185
189
|
}
|
|
186
190
|
constructor(message) {
|
|
187
191
|
super(message, 0, "Timer Error");
|
|
@@ -191,7 +195,7 @@ var TimerException = class extends Exception {
|
|
|
191
195
|
// src/exception/worker.ts
|
|
192
196
|
var WorkerException = class extends Exception {
|
|
193
197
|
static {
|
|
194
|
-
|
|
198
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "WorkerException");
|
|
195
199
|
}
|
|
196
200
|
constructor(message) {
|
|
197
201
|
super(message, 0, "Worker Error");
|
|
@@ -199,14 +203,14 @@ var WorkerException = class extends Exception {
|
|
|
199
203
|
};
|
|
200
204
|
|
|
201
205
|
// src/filter.ts
|
|
202
|
-
var defaultFilter = /* @__PURE__ */
|
|
206
|
+
var defaultFilter = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (e) => {
|
|
203
207
|
if (!(e instanceof Exception)) {
|
|
204
|
-
|
|
205
|
-
if (
|
|
208
|
+
_chunk4LLLQOMFjs.log.call(void 0, e.message, "error");
|
|
209
|
+
if (_chunk4LLLQOMFjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
206
210
|
e = new UndefinedException(e.message || e);
|
|
207
211
|
} else {
|
|
208
|
-
|
|
209
|
-
if (
|
|
212
|
+
_chunk4LLLQOMFjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
213
|
+
if (_chunk4LLLQOMFjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
210
214
|
}
|
|
211
215
|
return e.data;
|
|
212
216
|
}, "defaultFilter");
|
|
@@ -215,7 +219,7 @@ var defaultFilter = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (e) =>
|
|
|
215
219
|
var debug = _debug2.default.call(void 0, "phecda-server(Context)");
|
|
216
220
|
var Context = (_class = class _Context {
|
|
217
221
|
static {
|
|
218
|
-
|
|
222
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "Context");
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
|
|
@@ -228,21 +232,48 @@ var Context = (_class = class _Context {
|
|
|
228
232
|
}}
|
|
229
233
|
static __initStatic3() {this.guardRecord = {}}
|
|
230
234
|
static __initStatic4() {this.addonRecord = {}}
|
|
235
|
+
|
|
236
|
+
|
|
231
237
|
constructor(data) {
|
|
232
238
|
this.data = data;
|
|
233
|
-
|
|
239
|
+
this.canGetCtx = true;
|
|
240
|
+
if (_chunk4LLLQOMFjs.IS_DEV)
|
|
234
241
|
data._context = this;
|
|
242
|
+
const that = this;
|
|
243
|
+
this.ctx = new Proxy(data, {
|
|
244
|
+
get(target, p) {
|
|
245
|
+
if (_chunk4LLLQOMFjs.IS_DEV && !that.canGetCtx) throw new FrameworkException("ctx must be obtained within the same request cycle in controller");
|
|
246
|
+
if (!(p in target)) _chunk4LLLQOMFjs.log.call(void 0, `attribute "${p}" does not exist on ctx, which might be due to a missing AOP role (such as a guard).`, "warn", data.tag);
|
|
247
|
+
return target[p];
|
|
248
|
+
},
|
|
249
|
+
set(target, p, newValue) {
|
|
250
|
+
target[p] = newValue;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
235
254
|
}
|
|
236
255
|
static getAop(meta, opts) {
|
|
237
256
|
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
238
|
-
const { data: { guards, filter, params } } = meta;
|
|
239
|
-
|
|
240
|
-
guards:
|
|
257
|
+
const { data: { guards, filter, params, tag, func } } = meta;
|
|
258
|
+
const resolved = {
|
|
259
|
+
guards: [
|
|
241
260
|
...globalGuards,
|
|
242
261
|
...guards
|
|
243
|
-
]
|
|
244
|
-
pipe:
|
|
245
|
-
filter:
|
|
262
|
+
],
|
|
263
|
+
pipe: params.map((item) => item.pipe || globalPipe),
|
|
264
|
+
filter: filter || globalFilter
|
|
265
|
+
};
|
|
266
|
+
if (process.env.DEBUG) {
|
|
267
|
+
const { guards: guards2, pipe, filter: filter2 } = resolved;
|
|
268
|
+
debug(`func "${tag}-${func}" aop:
|
|
269
|
+
${_picocolors2.default.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
|
|
270
|
+
${_picocolors2.default.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
|
|
271
|
+
${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
guards: this.getGuards(resolved.guards),
|
|
275
|
+
pipe: this.getPipe(resolved.pipe),
|
|
276
|
+
filter: this.getFilter(resolved.filter)
|
|
246
277
|
};
|
|
247
278
|
}
|
|
248
279
|
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
@@ -250,32 +281,38 @@ var Context = (_class = class _Context {
|
|
|
250
281
|
const { paramsType, data: { ctxs, tag, params, func } } = meta;
|
|
251
282
|
try {
|
|
252
283
|
let res;
|
|
253
|
-
const nextHandler = /* @__PURE__ */
|
|
284
|
+
const nextHandler = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (index) => {
|
|
254
285
|
return async () => {
|
|
255
286
|
if (index === guards.length) {
|
|
256
287
|
const instance = moduleMap.get(tag);
|
|
257
288
|
if (ctxs) {
|
|
258
|
-
ctxs.forEach((ctx) => instance[ctx] = this.
|
|
289
|
+
ctxs.forEach((ctx) => instance[ctx] = this.ctx);
|
|
259
290
|
}
|
|
260
291
|
const args = await Promise.all(params.map((item, i) => pipe[i]({
|
|
261
292
|
arg: resolveDep(this.data[item.type], item.key),
|
|
262
293
|
reflect: paramsType[item.index],
|
|
263
294
|
...item
|
|
264
|
-
}, this.
|
|
295
|
+
}, this.ctx)));
|
|
296
|
+
if (_chunk4LLLQOMFjs.IS_DEV) {
|
|
297
|
+
Promise.resolve().then(() => {
|
|
298
|
+
this.canGetCtx = false;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
265
301
|
res = await instance[func](...args);
|
|
302
|
+
this.canGetCtx = true;
|
|
266
303
|
} else {
|
|
267
304
|
let nextPromise;
|
|
268
305
|
async function next() {
|
|
269
306
|
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
270
307
|
if (ret2 !== void 0) {
|
|
271
|
-
debug(`The ${index + 1}th guard rewrite the response value.`);
|
|
308
|
+
debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
|
|
272
309
|
res = ret2;
|
|
273
310
|
}
|
|
274
311
|
return res;
|
|
275
312
|
});
|
|
276
313
|
}
|
|
277
|
-
|
|
278
|
-
const ret = await guards[index](this.
|
|
314
|
+
_chunk4LLLQOMFjs.__name.call(void 0, next, "next");
|
|
315
|
+
const ret = await guards[index](this.ctx, next);
|
|
279
316
|
if (ret !== void 0) {
|
|
280
317
|
res = ret;
|
|
281
318
|
} else {
|
|
@@ -288,7 +325,7 @@ var Context = (_class = class _Context {
|
|
|
288
325
|
await nextHandler(0)();
|
|
289
326
|
return successCb(res);
|
|
290
327
|
} catch (e) {
|
|
291
|
-
const err = await filter(e, this.
|
|
328
|
+
const err = await filter(e, this.ctx);
|
|
292
329
|
return failCb(err);
|
|
293
330
|
}
|
|
294
331
|
}
|
|
@@ -316,65 +353,45 @@ var Context = (_class = class _Context {
|
|
|
316
353
|
}
|
|
317
354
|
}, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class.__initStatic4(), _class);
|
|
318
355
|
function addPipe(key, pipe) {
|
|
319
|
-
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe)
|
|
356
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
|
|
320
357
|
Context.pipeRecord[key] = pipe;
|
|
321
358
|
}
|
|
322
|
-
|
|
359
|
+
_chunk4LLLQOMFjs.__name.call(void 0, addPipe, "addPipe");
|
|
323
360
|
function addFilter(key, filter) {
|
|
324
|
-
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter)
|
|
361
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
|
|
325
362
|
Context.filterRecord[key] = filter;
|
|
326
363
|
}
|
|
327
|
-
|
|
364
|
+
_chunk4LLLQOMFjs.__name.call(void 0, addFilter, "addFilter");
|
|
328
365
|
function addGuard(key, guard, priority = 0) {
|
|
329
|
-
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard)
|
|
366
|
+
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
|
|
330
367
|
Context.guardRecord[key] = {
|
|
331
368
|
value: guard,
|
|
332
369
|
priority
|
|
333
370
|
};
|
|
334
371
|
}
|
|
335
|
-
|
|
372
|
+
_chunk4LLLQOMFjs.__name.call(void 0, addGuard, "addGuard");
|
|
336
373
|
function addAddon(key, addon, priority = 0) {
|
|
337
|
-
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon)
|
|
374
|
+
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
|
|
338
375
|
Context.addonRecord[key] = {
|
|
339
376
|
value: addon,
|
|
340
377
|
priority
|
|
341
378
|
};
|
|
342
379
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
// src/hmr.ts
|
|
346
|
-
function HMR(cb) {
|
|
347
|
-
if (_chunkJ5CFUN4Vjs.IS_HMR) _optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
|
|
348
|
-
}
|
|
349
|
-
_chunkJ5CFUN4Vjs.__name.call(void 0, HMR, "HMR");
|
|
380
|
+
_chunk4LLLQOMFjs.__name.call(void 0, addAddon, "addAddon");
|
|
350
381
|
|
|
351
382
|
// src/http/helper.ts
|
|
352
383
|
function resolveDep(ret, key) {
|
|
353
|
-
if (key) return _optionalChain([ret, 'optionalAccess',
|
|
384
|
+
if (key) return _optionalChain([ret, 'optionalAccess', _ => _[key]]);
|
|
354
385
|
return ret;
|
|
355
386
|
}
|
|
356
|
-
|
|
357
|
-
function argToReq(params, args, headers) {
|
|
358
|
-
const req = {
|
|
359
|
-
body: {},
|
|
360
|
-
query: {},
|
|
361
|
-
params: {},
|
|
362
|
-
headers
|
|
363
|
-
};
|
|
364
|
-
params.forEach((param) => {
|
|
365
|
-
if (param.key) req[param.type][param.key] = args[param.index];
|
|
366
|
-
else req[param.type] = args[param.index];
|
|
367
|
-
});
|
|
368
|
-
return req;
|
|
369
|
-
}
|
|
370
|
-
_chunkJ5CFUN4Vjs.__name.call(void 0, argToReq, "argToReq");
|
|
387
|
+
_chunk4LLLQOMFjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
371
388
|
|
|
372
389
|
// src/rpc/helper.ts
|
|
373
390
|
var _os = require('os');
|
|
374
391
|
function genClientQueue(key) {
|
|
375
392
|
return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
|
|
376
393
|
}
|
|
377
|
-
|
|
394
|
+
_chunk4LLLQOMFjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
378
395
|
|
|
379
396
|
// src/decorators/helper.ts
|
|
380
397
|
function shallowClone(obj) {
|
|
@@ -382,11 +399,11 @@ function shallowClone(obj) {
|
|
|
382
399
|
...obj
|
|
383
400
|
};
|
|
384
401
|
}
|
|
385
|
-
|
|
402
|
+
_chunk4LLLQOMFjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
386
403
|
function mergeObject(...args) {
|
|
387
404
|
return Object.assign({}, ...args);
|
|
388
405
|
}
|
|
389
|
-
|
|
406
|
+
_chunk4LLLQOMFjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
390
407
|
|
|
391
408
|
// src/helper.ts
|
|
392
409
|
function createControllerMetaMap(meta, filter) {
|
|
@@ -402,13 +419,14 @@ function createControllerMetaMap(meta, filter) {
|
|
|
402
419
|
});
|
|
403
420
|
}
|
|
404
421
|
}
|
|
405
|
-
|
|
422
|
+
_chunk4LLLQOMFjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
406
423
|
handleMeta();
|
|
407
|
-
HMR(handleMeta);
|
|
424
|
+
_chunk4LLLQOMFjs.HMR.call(void 0, handleMeta);
|
|
408
425
|
return metaMap;
|
|
409
426
|
}
|
|
410
|
-
|
|
427
|
+
_chunk4LLLQOMFjs.__name.call(void 0, createControllerMetaMap, "createControllerMetaMap");
|
|
411
428
|
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
429
|
+
if (_chunk4LLLQOMFjs.IS_PURE) return;
|
|
412
430
|
const addonSet = /* @__PURE__ */ new Set();
|
|
413
431
|
const guardSet = /* @__PURE__ */ new Set();
|
|
414
432
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
@@ -420,15 +438,17 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
420
438
|
pipeSet.clear();
|
|
421
439
|
filterSet.clear();
|
|
422
440
|
warningSet.clear();
|
|
423
|
-
_optionalChain([addons, 'optionalAccess',
|
|
441
|
+
_optionalChain([addons, 'optionalAccess', _2 => _2.forEach, 'call', _3 => _3((item) => {
|
|
424
442
|
addonSet.add(item);
|
|
425
443
|
})]);
|
|
426
|
-
_optionalChain([guards, 'optionalAccess',
|
|
444
|
+
_optionalChain([guards, 'optionalAccess', _4 => _4.forEach, 'call', _5 => _5((item) => {
|
|
427
445
|
guardSet.add(item);
|
|
428
446
|
})]);
|
|
429
447
|
meta.forEach(({ data }) => {
|
|
448
|
+
if (!data.controller) return;
|
|
449
|
+
if (typeof data.tag !== "string") warningSet.add(`Tag of controller "${data.name}" should be a string`);
|
|
430
450
|
if (data.controller !== controller) {
|
|
431
|
-
if (data[controller]) warningSet.add(`
|
|
451
|
+
if (data[controller]) warningSet.add(`Should use ${controller} controller to decorate class "${data.name}"`);
|
|
432
452
|
return;
|
|
433
453
|
}
|
|
434
454
|
if (data.filter) filterSet.add(data.filter);
|
|
@@ -450,15 +470,35 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
450
470
|
const missFilters = [
|
|
451
471
|
...filterSet
|
|
452
472
|
].filter((i) => !Context.filterRecord[i]);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
473
|
+
function exit() {
|
|
474
|
+
if (_chunk4LLLQOMFjs.IS_STRICT) {
|
|
475
|
+
_chunk4LLLQOMFjs.log.call(void 0, "Does not meet strict mode requirements", "error");
|
|
476
|
+
process.exit(1);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
_chunk4LLLQOMFjs.__name.call(void 0, exit, "exit");
|
|
480
|
+
if (missAddons.length) {
|
|
481
|
+
_chunk4LLLQOMFjs.log.call(void 0, `${_picocolors2.default.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
482
|
+
exit();
|
|
483
|
+
}
|
|
484
|
+
if (missGuards.length) {
|
|
485
|
+
_chunk4LLLQOMFjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
486
|
+
exit();
|
|
487
|
+
}
|
|
488
|
+
if (missPipes.length) {
|
|
489
|
+
_chunk4LLLQOMFjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
490
|
+
exit();
|
|
491
|
+
}
|
|
492
|
+
if (missFilters.length) {
|
|
493
|
+
_chunk4LLLQOMFjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
494
|
+
exit();
|
|
495
|
+
}
|
|
496
|
+
warningSet.forEach((warn) => _chunk4LLLQOMFjs.log.call(void 0, warn, "warn"));
|
|
497
|
+
if (warningSet.size) exit();
|
|
458
498
|
}
|
|
459
|
-
|
|
499
|
+
_chunk4LLLQOMFjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
460
500
|
handleMeta();
|
|
461
|
-
HMR(handleMeta);
|
|
501
|
+
_chunk4LLLQOMFjs.HMR.call(void 0, handleMeta);
|
|
462
502
|
return {
|
|
463
503
|
addonSet,
|
|
464
504
|
guardSet,
|
|
@@ -466,8 +506,15 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
466
506
|
filterSet
|
|
467
507
|
};
|
|
468
508
|
}
|
|
469
|
-
|
|
470
|
-
|
|
509
|
+
_chunk4LLLQOMFjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
510
|
+
function joinUrl(base, ...paths) {
|
|
511
|
+
const joinedPath = [
|
|
512
|
+
base,
|
|
513
|
+
...paths
|
|
514
|
+
].filter((p) => p).map((path) => path.replace(/(^\/)/g, "")).join("/");
|
|
515
|
+
return `/${joinedPath}`;
|
|
516
|
+
}
|
|
517
|
+
_chunk4LLLQOMFjs.__name.call(void 0, joinUrl, "joinUrl");
|
|
471
518
|
|
|
472
519
|
|
|
473
520
|
|
|
@@ -500,4 +547,4 @@ _chunkJ5CFUN4Vjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
|
500
547
|
|
|
501
548
|
|
|
502
549
|
|
|
503
|
-
exports.defaultPipe = defaultPipe; exports.Exception = Exception; exports.UndefinedException = UndefinedException; exports.ValidateException = ValidateException; 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.Context = Context; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addAddon = addAddon; exports.
|
|
550
|
+
exports.defaultPipe = defaultPipe; exports.Exception = Exception; exports.UndefinedException = UndefinedException; exports.ValidateException = ValidateException; 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.Context = Context; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addAddon = addAddon; exports.resolveDep = resolveDep; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.createControllerMetaMap = createControllerMetaMap; exports.detectAopDep = detectAopDep; exports.joinUrl = joinUrl;
|