phecda-server 8.5.4 → 8.7.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/bin/cli.mjs +1 -9
- package/dist/{chunk-76UDKZOJ.js → chunk-CCK6KDM3.js} +120 -76
- package/dist/{chunk-LLF55NZP.js → chunk-IBVPZSZJ.js} +6 -6
- package/dist/{chunk-URKOYTBU.mjs → chunk-ITDH2YDL.mjs} +6 -6
- package/dist/{chunk-5ZZAOOKE.js → chunk-KVWT2QTL.js} +26 -26
- package/dist/{chunk-WST6E6MQ.mjs → chunk-LNL3MVTR.mjs} +71 -27
- package/dist/{chunk-ZHNYWZRL.mjs → chunk-T5F6Q2CZ.mjs} +1 -1
- package/dist/{chunk-MUUKKO67.mjs → chunk-UK3RDUEP.mjs} +1 -1
- package/dist/{chunk-SKGOTR4T.js → chunk-UP64TNWR.js} +20 -20
- package/dist/{core-BiS3xJKx.d.ts → core-Bd2ynlyb.d.ts} +1 -1
- package/dist/{core-BYxcQ8kf.d.mts → core-nqk9d66O.d.mts} +1 -1
- package/dist/helper.d.mts +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +40 -40
- package/dist/http/elysia/index.mjs +3 -3
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +37 -37
- package/dist/http/express/index.mjs +2 -2
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +38 -38
- package/dist/http/fastify/index.mjs +3 -3
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +38 -38
- package/dist/http/h3/index.mjs +2 -2
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +34 -34
- package/dist/http/hono/index.mjs +2 -2
- package/dist/http/hyper-express/index.d.mts +3 -3
- package/dist/http/hyper-express/index.d.ts +3 -3
- package/dist/http/hyper-express/index.js +35 -35
- package/dist/http/hyper-express/index.mjs +2 -2
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +37 -37
- package/dist/http/koa/index.mjs +2 -2
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +54 -54
- package/dist/index.mjs +19 -19
- package/dist/{meta-Csp1xcSR.d.mts → meta-ZbvaS7xK.d.mts} +2 -2
- package/dist/{meta-Csp1xcSR.d.ts → meta-ZbvaS7xK.d.ts} +2 -2
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +11 -11
- package/dist/rpc/bullmq/index.mjs +2 -2
- package/dist/rpc/electron/index.d.mts +3 -3
- package/dist/rpc/electron/index.d.ts +3 -3
- package/dist/rpc/electron/index.js +8 -8
- package/dist/rpc/electron/index.mjs +2 -2
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +10 -10
- package/dist/rpc/kafka/index.mjs +2 -2
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +11 -11
- package/dist/rpc/nats/index.mjs +2 -2
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +12 -12
- package/dist/rpc/rabbitmq/index.mjs +2 -2
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +10 -10
- package/dist/rpc/redis/index.mjs +2 -2
- package/dist/rpc/web-ext/index.d.mts +3 -3
- package/dist/rpc/web-ext/index.d.ts +3 -3
- package/dist/rpc/web-ext/index.js +8 -8
- package/dist/rpc/web-ext/index.mjs +2 -2
- package/dist/rpc/ws/index.d.mts +3 -3
- package/dist/rpc/ws/index.d.ts +3 -3
- package/dist/rpc/ws/index.js +7 -7
- package/dist/rpc/ws/index.mjs +2 -2
- package/dist/test.d.mts +2 -2
- package/dist/test.d.ts +2 -2
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-Bs64nYvd.d.ts → types-B4zY7i87.d.ts} +1 -1
- package/dist/{types-CjVwVyJT.d.mts → types-BfcBZVua.d.mts} +1 -1
- package/dist/{types-DExQe0qk.d.ts → types-CHWgzilt.d.ts} +1 -1
- package/dist/{types-DSlyrmns.d.mts → types-f_hV_rCD.d.mts} +1 -1
- package/package.json +2 -2
- package/register/index.mjs +2 -0
- package/register/loader.mjs +3 -3
package/bin/cli.mjs
CHANGED
|
@@ -39,7 +39,7 @@ if (nodeVersion < 18.19) {
|
|
|
39
39
|
|
|
40
40
|
function startChild(file, args) {
|
|
41
41
|
child = fork(file, {
|
|
42
|
-
env: { ...process.env },
|
|
42
|
+
env: { ...process.env, PS_RUNTIME: 'true' },
|
|
43
43
|
stdio: 'inherit',
|
|
44
44
|
execArgv: [
|
|
45
45
|
...args,
|
|
@@ -188,20 +188,12 @@ cli
|
|
|
188
188
|
.command('<file> [root]', 'run file')
|
|
189
189
|
.alias('run')
|
|
190
190
|
// .allowUnknownOptions()
|
|
191
|
-
.option('-p,--prod', 'prod mode', {
|
|
192
|
-
default: false,
|
|
193
|
-
})
|
|
194
191
|
.action((file, root, options) => {
|
|
195
192
|
const nodeArgs = options.nodeArgs.split(' ').filter(Boolean)
|
|
196
193
|
|
|
197
194
|
if (root)
|
|
198
195
|
process.chdir(root)
|
|
199
196
|
|
|
200
|
-
if (options.prod)
|
|
201
|
-
process.env.NODE_ENV = 'production'
|
|
202
|
-
else
|
|
203
|
-
process.env.NODE_ENV = 'development'
|
|
204
|
-
|
|
205
197
|
process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
|
|
206
198
|
|
|
207
199
|
log('process start!')
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
var _chunkLLF55NZPjs = require('./chunk-LLF55NZP.js');
|
|
9
|
+
var _chunkIBVPZSZJjs = require('./chunk-IBVPZSZJ.js');
|
|
11
10
|
|
|
12
11
|
// src/helper.ts
|
|
13
12
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
@@ -22,7 +21,7 @@ var _phecdacore = require('phecda-core');
|
|
|
22
21
|
// src/exception/base.ts
|
|
23
22
|
var Exception = class extends Error {
|
|
24
23
|
static {
|
|
25
|
-
|
|
24
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "Exception");
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
|
|
@@ -36,7 +35,7 @@ var Exception = class extends Error {
|
|
|
36
35
|
message: this.message,
|
|
37
36
|
description: this.description,
|
|
38
37
|
status: this.status,
|
|
39
|
-
[
|
|
38
|
+
[_chunkIBVPZSZJjs.ERROR_SYMBOL]: true
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
};
|
|
@@ -44,7 +43,7 @@ var Exception = class extends Error {
|
|
|
44
43
|
// src/exception/undefine.ts
|
|
45
44
|
var UndefinedException = class extends Exception {
|
|
46
45
|
static {
|
|
47
|
-
|
|
46
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "UndefinedException");
|
|
48
47
|
}
|
|
49
48
|
constructor(message, metadata) {
|
|
50
49
|
super(message, metadata, 500, "Undefined error");
|
|
@@ -54,7 +53,7 @@ var UndefinedException = class extends Exception {
|
|
|
54
53
|
// src/exception/validate.ts
|
|
55
54
|
var ValidateException = class extends Exception {
|
|
56
55
|
static {
|
|
57
|
-
|
|
56
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "ValidateException");
|
|
58
57
|
}
|
|
59
58
|
constructor(message, metadata) {
|
|
60
59
|
super(message, metadata, 400, "Validate exception");
|
|
@@ -64,7 +63,7 @@ var ValidateException = class extends Exception {
|
|
|
64
63
|
// src/exception/forbidden.ts
|
|
65
64
|
var ForbiddenException = class extends Exception {
|
|
66
65
|
static {
|
|
67
|
-
|
|
66
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "ForbiddenException");
|
|
68
67
|
}
|
|
69
68
|
constructor(message, metadata) {
|
|
70
69
|
super(message, metadata, 403, "Forbidden resource");
|
|
@@ -74,7 +73,7 @@ var ForbiddenException = class extends Exception {
|
|
|
74
73
|
// src/exception/bad-request.ts
|
|
75
74
|
var BadRequestException = class extends Exception {
|
|
76
75
|
static {
|
|
77
|
-
|
|
76
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "BadRequestException");
|
|
78
77
|
}
|
|
79
78
|
constructor(message, metadata) {
|
|
80
79
|
super(message, metadata, 400, "Bad Request");
|
|
@@ -84,7 +83,7 @@ var BadRequestException = class extends Exception {
|
|
|
84
83
|
// src/exception/not-found.ts
|
|
85
84
|
var NotFoundException = class extends Exception {
|
|
86
85
|
static {
|
|
87
|
-
|
|
86
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "NotFoundException");
|
|
88
87
|
}
|
|
89
88
|
constructor(message, metadata) {
|
|
90
89
|
super(message, metadata, 404, "Not Found");
|
|
@@ -94,7 +93,7 @@ var NotFoundException = class extends Exception {
|
|
|
94
93
|
// src/exception/conflict.ts
|
|
95
94
|
var ConflictException = class extends Exception {
|
|
96
95
|
static {
|
|
97
|
-
|
|
96
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "ConflictException");
|
|
98
97
|
}
|
|
99
98
|
constructor(message, metadata) {
|
|
100
99
|
super(message, metadata, 409, "Conflict");
|
|
@@ -104,7 +103,7 @@ var ConflictException = class extends Exception {
|
|
|
104
103
|
// src/exception/bad-gateway.ts
|
|
105
104
|
var BadGatewayException = class extends Exception {
|
|
106
105
|
static {
|
|
107
|
-
|
|
106
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "BadGatewayException");
|
|
108
107
|
}
|
|
109
108
|
constructor(message, metadata) {
|
|
110
109
|
super(message, metadata, 502, "Bad Gatrway");
|
|
@@ -114,7 +113,7 @@ var BadGatewayException = class extends Exception {
|
|
|
114
113
|
// src/exception/invalid-input.ts
|
|
115
114
|
var InvalidInputException = class extends Exception {
|
|
116
115
|
static {
|
|
117
|
-
|
|
116
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "InvalidInputException");
|
|
118
117
|
}
|
|
119
118
|
constructor(message, metadata) {
|
|
120
119
|
super(message, metadata, 502, "Invalid Input");
|
|
@@ -124,7 +123,7 @@ var InvalidInputException = class extends Exception {
|
|
|
124
123
|
// src/exception/media-type.ts
|
|
125
124
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
126
125
|
static {
|
|
127
|
-
|
|
126
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "UnsupportedMediaTypeException");
|
|
128
127
|
}
|
|
129
128
|
constructor(message, metadata) {
|
|
130
129
|
super(message, metadata, 415, "Unsupported Media Type");
|
|
@@ -134,7 +133,7 @@ var UnsupportedMediaTypeException = class extends Exception {
|
|
|
134
133
|
// src/exception/payload-large.ts
|
|
135
134
|
var PayloadLargeException = class extends Exception {
|
|
136
135
|
static {
|
|
137
|
-
|
|
136
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "PayloadLargeException");
|
|
138
137
|
}
|
|
139
138
|
constructor(message, metadata) {
|
|
140
139
|
super(message, metadata, 413, "Payload Too Large");
|
|
@@ -144,7 +143,7 @@ var PayloadLargeException = class extends Exception {
|
|
|
144
143
|
// src/exception/timeout.ts
|
|
145
144
|
var TimeoutException = class extends Exception {
|
|
146
145
|
static {
|
|
147
|
-
|
|
146
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "TimeoutException");
|
|
148
147
|
}
|
|
149
148
|
constructor(message, metadata) {
|
|
150
149
|
super(message, metadata, 408, "Request Timeout");
|
|
@@ -154,7 +153,7 @@ var TimeoutException = class extends Exception {
|
|
|
154
153
|
// src/exception/unauthorized.ts
|
|
155
154
|
var UnauthorizedException = class extends Exception {
|
|
156
155
|
static {
|
|
157
|
-
|
|
156
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "UnauthorizedException");
|
|
158
157
|
}
|
|
159
158
|
constructor(message, metadata) {
|
|
160
159
|
super(message, metadata, 401, "Unauthorized");
|
|
@@ -164,7 +163,7 @@ var UnauthorizedException = class extends Exception {
|
|
|
164
163
|
// src/exception/unavailable-service.ts
|
|
165
164
|
var ServiceUnavailableException = class extends Exception {
|
|
166
165
|
static {
|
|
167
|
-
|
|
166
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "ServiceUnavailableException");
|
|
168
167
|
}
|
|
169
168
|
constructor(message, metadata) {
|
|
170
169
|
super(message, metadata, 503, "Service Unavailable");
|
|
@@ -174,7 +173,7 @@ var ServiceUnavailableException = class extends Exception {
|
|
|
174
173
|
// src/exception/framework.ts
|
|
175
174
|
var FrameworkException = class extends Exception {
|
|
176
175
|
static {
|
|
177
|
-
|
|
176
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "FrameworkException");
|
|
178
177
|
}
|
|
179
178
|
constructor(message, metadata) {
|
|
180
179
|
super(`[phecda-server] ${message}`, metadata, 500, "Framework Error");
|
|
@@ -184,7 +183,7 @@ var FrameworkException = class extends Exception {
|
|
|
184
183
|
// src/exception/timer.ts
|
|
185
184
|
var TimerException = class extends Exception {
|
|
186
185
|
static {
|
|
187
|
-
|
|
186
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "TimerException");
|
|
188
187
|
}
|
|
189
188
|
constructor(message, metadata) {
|
|
190
189
|
super(message, metadata, 0, "Timer Error");
|
|
@@ -194,7 +193,7 @@ var TimerException = class extends Exception {
|
|
|
194
193
|
// src/exception/worker.ts
|
|
195
194
|
var WorkerException = class extends Exception {
|
|
196
195
|
static {
|
|
197
|
-
|
|
196
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "WorkerException");
|
|
198
197
|
}
|
|
199
198
|
constructor(message, metadata) {
|
|
200
199
|
super(message, metadata, 0, "Worker Error");
|
|
@@ -202,7 +201,63 @@ var WorkerException = class extends Exception {
|
|
|
202
201
|
};
|
|
203
202
|
|
|
204
203
|
// src/pipe.ts
|
|
205
|
-
var
|
|
204
|
+
var modelRulesCache = /* @__PURE__ */ new WeakMap();
|
|
205
|
+
function isPlainObject(value) {
|
|
206
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
207
|
+
}
|
|
208
|
+
_chunkIBVPZSZJjs.__name.call(void 0, isPlainObject, "isPlainObject");
|
|
209
|
+
function convertForRequestInput(value, type, index) {
|
|
210
|
+
if (value === void 0) return value;
|
|
211
|
+
if (type === Number && typeof value === "string") {
|
|
212
|
+
const num = Number(value);
|
|
213
|
+
if (Number.isNaN(num)) throw new ValidateException(`param ${index + 1} is not a number`);
|
|
214
|
+
return num;
|
|
215
|
+
}
|
|
216
|
+
if (type === Boolean && typeof value === "string") {
|
|
217
|
+
if (value === "true") return true;
|
|
218
|
+
if (value === "false") return false;
|
|
219
|
+
throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
223
|
+
_chunkIBVPZSZJjs.__name.call(void 0, convertForRequestInput, "convertForRequestInput");
|
|
224
|
+
function isStrTypeParam(type) {
|
|
225
|
+
return [
|
|
226
|
+
"params",
|
|
227
|
+
"query",
|
|
228
|
+
"headers"
|
|
229
|
+
].includes(type);
|
|
230
|
+
}
|
|
231
|
+
_chunkIBVPZSZJjs.__name.call(void 0, isStrTypeParam, "isStrTypeParam");
|
|
232
|
+
function convertExtractedDataByRules(data, rules, index) {
|
|
233
|
+
if (!data || typeof data !== "object") return data;
|
|
234
|
+
for (const rule of rules) {
|
|
235
|
+
if (!rule.property) continue;
|
|
236
|
+
if (rule.property.includes(".") || rule.property.includes("[]")) throw new ValidateException("default pipe only supports simple shallow phecda class for query/params/headers; please use custom pipe for nested data");
|
|
237
|
+
data[rule.property] = convertForRequestInput(data[rule.property], rule.designType, index);
|
|
238
|
+
}
|
|
239
|
+
return data;
|
|
240
|
+
}
|
|
241
|
+
_chunkIBVPZSZJjs.__name.call(void 0, convertExtractedDataByRules, "convertExtractedDataByRules");
|
|
242
|
+
function getModelRules(model) {
|
|
243
|
+
const cached = modelRulesCache.get(model);
|
|
244
|
+
if (cached) return cached;
|
|
245
|
+
const rules = _phecdacore.extractRules.call(void 0, model);
|
|
246
|
+
modelRulesCache.set(model, rules);
|
|
247
|
+
return rules;
|
|
248
|
+
}
|
|
249
|
+
_chunkIBVPZSZJjs.__name.call(void 0, getModelRules, "getModelRules");
|
|
250
|
+
async function validatePhecdaByRules(model, input, shouldConvert, index) {
|
|
251
|
+
if (!isPlainObject(input)) throw new ValidateException("data must be an object");
|
|
252
|
+
const rules = getModelRules(model);
|
|
253
|
+
let data = _phecdacore.extractDataByRules.call(void 0, input, rules);
|
|
254
|
+
if (shouldConvert) data = convertExtractedDataByRules(data, rules, index);
|
|
255
|
+
const errs = await _phecdacore.validateWithRules.call(void 0, data, rules);
|
|
256
|
+
if (errs.length) throw new ValidateException(errs[0]);
|
|
257
|
+
return data;
|
|
258
|
+
}
|
|
259
|
+
_chunkIBVPZSZJjs.__name.call(void 0, validatePhecdaByRules, "validatePhecdaByRules");
|
|
260
|
+
var defaultPipe = /* @__PURE__ */ _chunkIBVPZSZJjs.__name.call(void 0, async ({ arg, reflect, meta, index, type, key }, { method }) => {
|
|
206
261
|
if (meta.const) {
|
|
207
262
|
if (arg !== meta.const) throw new ValidateException(`param ${index + 1} must be ${meta.const}`);
|
|
208
263
|
}
|
|
@@ -210,19 +265,13 @@ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({
|
|
|
210
265
|
if (meta.required === false) return arg;
|
|
211
266
|
else throw new ValidateException(`param ${index + 1} is required`);
|
|
212
267
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
} else if (reflect === Boolean) {
|
|
221
|
-
if (arg === "false") arg = false;
|
|
222
|
-
else if (arg === "true") arg = true;
|
|
223
|
-
else throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
268
|
+
const isModel = _phecdacore.isPhecda.call(void 0, reflect);
|
|
269
|
+
const isStrType = isStrTypeParam(type);
|
|
270
|
+
const canUseShallowModelConvert = isStrType && !key;
|
|
271
|
+
if (isModel && isStrType && key) throw new ValidateException("phecda class cannot be used with specified field in query/params/headers in default pipe");
|
|
272
|
+
if (!isModel && isStrType) {
|
|
273
|
+
arg = convertForRequestInput(arg, reflect, index);
|
|
274
|
+
} else if (!isModel) {
|
|
226
275
|
if (reflect === Number && typeof arg !== "number") throw new ValidateException(`param ${index + 1} is not a number`);
|
|
227
276
|
if (reflect === Boolean && typeof arg !== "boolean") throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
228
277
|
if (reflect === String && typeof arg !== "string") throw new ValidateException(`param ${index + 1} is not a string`);
|
|
@@ -245,11 +294,12 @@ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({
|
|
|
245
294
|
break;
|
|
246
295
|
default:
|
|
247
296
|
if (_phecdacore.isPhecda.call(void 0, item)) {
|
|
248
|
-
|
|
249
|
-
|
|
297
|
+
try {
|
|
298
|
+
await validatePhecdaByRules(item, arg, canUseShallowModelConvert, index);
|
|
250
299
|
isCorrect = true;
|
|
251
|
-
|
|
300
|
+
} catch (e2) {
|
|
252
301
|
}
|
|
302
|
+
if (isCorrect) break;
|
|
253
303
|
} else if (typeof item === "function") {
|
|
254
304
|
const ret = await item(arg);
|
|
255
305
|
if (ret) {
|
|
@@ -278,22 +328,19 @@ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({
|
|
|
278
328
|
if (err.length > 0) throw new ValidateException(err[0]);
|
|
279
329
|
}
|
|
280
330
|
}
|
|
281
|
-
if (
|
|
282
|
-
const errs = await _phecdacore.validate.call(void 0, reflect, arg);
|
|
283
|
-
if (errs.length) throw new ValidateException(errs[0]);
|
|
284
|
-
}
|
|
331
|
+
if (isModel) arg = await validatePhecdaByRules(reflect, arg, canUseShallowModelConvert, index);
|
|
285
332
|
return arg;
|
|
286
333
|
}, "defaultPipe");
|
|
287
334
|
|
|
288
335
|
// src/filter.ts
|
|
289
|
-
var defaultFilter = /* @__PURE__ */
|
|
336
|
+
var defaultFilter = /* @__PURE__ */ _chunkIBVPZSZJjs.__name.call(void 0, (e) => {
|
|
290
337
|
if (!(e instanceof Exception)) {
|
|
291
|
-
|
|
292
|
-
if (
|
|
338
|
+
_chunkIBVPZSZJjs.log.call(void 0, e.message, "error");
|
|
339
|
+
if (_chunkIBVPZSZJjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
293
340
|
e = new UndefinedException(e.message || e);
|
|
294
341
|
} else {
|
|
295
|
-
|
|
296
|
-
if (
|
|
342
|
+
_chunkIBVPZSZJjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
343
|
+
if (_chunkIBVPZSZJjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
297
344
|
}
|
|
298
345
|
return e.data;
|
|
299
346
|
}, "defaultFilter");
|
|
@@ -302,7 +349,7 @@ var defaultFilter = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, (e) =>
|
|
|
302
349
|
var debug = _debug2.default.call(void 0, "phecda-server(Context)");
|
|
303
350
|
var Context = (_class = class _Context {
|
|
304
351
|
static {
|
|
305
|
-
|
|
352
|
+
_chunkIBVPZSZJjs.__name.call(void 0, this, "Context");
|
|
306
353
|
}
|
|
307
354
|
|
|
308
355
|
|
|
@@ -316,14 +363,11 @@ var Context = (_class = class _Context {
|
|
|
316
363
|
static __initStatic3() {this.guardRecord = {}}
|
|
317
364
|
static __initStatic4() {this.addonRecord = {}}
|
|
318
365
|
|
|
319
|
-
// protected canGetCtx = true
|
|
320
366
|
constructor(data) {
|
|
321
367
|
this.data = data;
|
|
322
|
-
if (_chunkLLF55NZPjs.IS_DEV)
|
|
323
|
-
data._context = this;
|
|
324
368
|
this.ctx = new Proxy(data, {
|
|
325
369
|
get(target, p) {
|
|
326
|
-
if (!(p in target))
|
|
370
|
+
if (!(p in target)) _chunkIBVPZSZJjs.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);
|
|
327
371
|
return target[p];
|
|
328
372
|
},
|
|
329
373
|
set(target, p, newValue) {
|
|
@@ -361,7 +405,7 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
361
405
|
const { paramsType, data: { ctxs, tag, params, method } } = meta;
|
|
362
406
|
try {
|
|
363
407
|
let res;
|
|
364
|
-
const nextHandler = /* @__PURE__ */
|
|
408
|
+
const nextHandler = /* @__PURE__ */ _chunkIBVPZSZJjs.__name.call(void 0, (index) => {
|
|
365
409
|
return async () => {
|
|
366
410
|
if (index === guards.length) {
|
|
367
411
|
const instance = moduleMap.get(tag);
|
|
@@ -385,7 +429,7 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
385
429
|
return res;
|
|
386
430
|
});
|
|
387
431
|
}
|
|
388
|
-
|
|
432
|
+
_chunkIBVPZSZJjs.__name.call(void 0, next, "next");
|
|
389
433
|
const ret = await guards[index](this.ctx, next);
|
|
390
434
|
if (ret !== void 0) {
|
|
391
435
|
res = ret;
|
|
@@ -430,12 +474,12 @@ function addPipe(key, pipe) {
|
|
|
430
474
|
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
|
|
431
475
|
Context.pipeRecord[key] = pipe;
|
|
432
476
|
}
|
|
433
|
-
|
|
477
|
+
_chunkIBVPZSZJjs.__name.call(void 0, addPipe, "addPipe");
|
|
434
478
|
function addFilter(key, filter) {
|
|
435
479
|
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
|
|
436
480
|
Context.filterRecord[key] = filter;
|
|
437
481
|
}
|
|
438
|
-
|
|
482
|
+
_chunkIBVPZSZJjs.__name.call(void 0, addFilter, "addFilter");
|
|
439
483
|
function addGuard(key, guard, priority = 0) {
|
|
440
484
|
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
|
|
441
485
|
Context.guardRecord[key] = {
|
|
@@ -443,7 +487,7 @@ function addGuard(key, guard, priority = 0) {
|
|
|
443
487
|
priority
|
|
444
488
|
};
|
|
445
489
|
}
|
|
446
|
-
|
|
490
|
+
_chunkIBVPZSZJjs.__name.call(void 0, addGuard, "addGuard");
|
|
447
491
|
function addAddon(key, addon, priority = 0) {
|
|
448
492
|
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
|
|
449
493
|
Context.addonRecord[key] = {
|
|
@@ -451,14 +495,14 @@ function addAddon(key, addon, priority = 0) {
|
|
|
451
495
|
priority
|
|
452
496
|
};
|
|
453
497
|
}
|
|
454
|
-
|
|
498
|
+
_chunkIBVPZSZJjs.__name.call(void 0, addAddon, "addAddon");
|
|
455
499
|
|
|
456
500
|
// src/http/helper.ts
|
|
457
501
|
function resolveDep(ret, key) {
|
|
458
502
|
if (key) return _optionalChain([ret, 'optionalAccess', _ => _[key]]);
|
|
459
503
|
return ret;
|
|
460
504
|
}
|
|
461
|
-
|
|
505
|
+
_chunkIBVPZSZJjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
462
506
|
|
|
463
507
|
// src/decorators/helper.ts
|
|
464
508
|
function shallowClone(obj) {
|
|
@@ -466,11 +510,11 @@ function shallowClone(obj) {
|
|
|
466
510
|
...obj
|
|
467
511
|
};
|
|
468
512
|
}
|
|
469
|
-
|
|
513
|
+
_chunkIBVPZSZJjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
470
514
|
function mergeObject(...args) {
|
|
471
515
|
return Object.assign({}, ...args);
|
|
472
516
|
}
|
|
473
|
-
|
|
517
|
+
_chunkIBVPZSZJjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
474
518
|
|
|
475
519
|
// src/helper.ts
|
|
476
520
|
function createControllerMetaMap(meta, filter) {
|
|
@@ -486,14 +530,14 @@ function createControllerMetaMap(meta, filter) {
|
|
|
486
530
|
});
|
|
487
531
|
}
|
|
488
532
|
}
|
|
489
|
-
|
|
533
|
+
_chunkIBVPZSZJjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
490
534
|
handleMeta();
|
|
491
|
-
|
|
535
|
+
_chunkIBVPZSZJjs.HMR.call(void 0, handleMeta);
|
|
492
536
|
return metaMap;
|
|
493
537
|
}
|
|
494
|
-
|
|
538
|
+
_chunkIBVPZSZJjs.__name.call(void 0, createControllerMetaMap, "createControllerMetaMap");
|
|
495
539
|
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
496
|
-
if (
|
|
540
|
+
if (_chunkIBVPZSZJjs.IS_PURE) return;
|
|
497
541
|
const addonSet = /* @__PURE__ */ new Set();
|
|
498
542
|
const guardSet = /* @__PURE__ */ new Set();
|
|
499
543
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
@@ -538,34 +582,34 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
538
582
|
...filterSet
|
|
539
583
|
].filter((i) => !Context.filterRecord[i]);
|
|
540
584
|
function exit() {
|
|
541
|
-
if (
|
|
542
|
-
|
|
585
|
+
if (_chunkIBVPZSZJjs.IS_STRICT) {
|
|
586
|
+
_chunkIBVPZSZJjs.log.call(void 0, "Does not meet strict mode requirements", "error");
|
|
543
587
|
process.exit(1);
|
|
544
588
|
}
|
|
545
589
|
}
|
|
546
|
-
|
|
590
|
+
_chunkIBVPZSZJjs.__name.call(void 0, exit, "exit");
|
|
547
591
|
if (missAddons.length) {
|
|
548
|
-
|
|
592
|
+
_chunkIBVPZSZJjs.log.call(void 0, `${_picocolors2.default.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
549
593
|
exit();
|
|
550
594
|
}
|
|
551
595
|
if (missGuards.length) {
|
|
552
|
-
|
|
596
|
+
_chunkIBVPZSZJjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
553
597
|
exit();
|
|
554
598
|
}
|
|
555
599
|
if (missPipes.length) {
|
|
556
|
-
|
|
600
|
+
_chunkIBVPZSZJjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
557
601
|
exit();
|
|
558
602
|
}
|
|
559
603
|
if (missFilters.length) {
|
|
560
|
-
|
|
604
|
+
_chunkIBVPZSZJjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
561
605
|
exit();
|
|
562
606
|
}
|
|
563
|
-
warningSet.forEach((warn) =>
|
|
607
|
+
warningSet.forEach((warn) => _chunkIBVPZSZJjs.log.call(void 0, warn, "warn"));
|
|
564
608
|
if (warningSet.size) exit();
|
|
565
609
|
}
|
|
566
|
-
|
|
610
|
+
_chunkIBVPZSZJjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
567
611
|
handleMeta();
|
|
568
|
-
|
|
612
|
+
_chunkIBVPZSZJjs.HMR.call(void 0, handleMeta);
|
|
569
613
|
return {
|
|
570
614
|
addonSet,
|
|
571
615
|
guardSet,
|
|
@@ -573,7 +617,7 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
573
617
|
filterSet
|
|
574
618
|
};
|
|
575
619
|
}
|
|
576
|
-
|
|
620
|
+
_chunkIBVPZSZJjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
577
621
|
function joinUrl(base, ...paths) {
|
|
578
622
|
const joinedPath = [
|
|
579
623
|
base,
|
|
@@ -581,7 +625,7 @@ function joinUrl(base, ...paths) {
|
|
|
581
625
|
].filter((p) => p).map((path) => path.replace(/(^\/)/g, "")).join("/");
|
|
582
626
|
return `/${joinedPath}`;
|
|
583
627
|
}
|
|
584
|
-
|
|
628
|
+
_chunkIBVPZSZJjs.__name.call(void 0, joinUrl, "joinUrl");
|
|
585
629
|
|
|
586
630
|
|
|
587
631
|
|
|
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/common.ts
|
|
5
5
|
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
6
|
-
var
|
|
6
|
+
var IS_RUNTIME = !!process.env.PS_RUNTIME;
|
|
7
7
|
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
8
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
9
|
var IS_PURE = !!process.env.PS_PURE;
|
|
@@ -112,14 +112,14 @@ __name(runMiddleware, "runMiddleware");
|
|
|
112
112
|
|
|
113
113
|
// src/hmr.ts
|
|
114
114
|
function HMR(cb) {
|
|
115
|
-
if (
|
|
115
|
+
if (IS_RUNTIME) {
|
|
116
116
|
if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
|
|
117
117
|
globalThis.__PS_HMR__.push(cb);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
__name(HMR, "HMR");
|
|
121
121
|
async function RELOAD(oldModels, newModels) {
|
|
122
|
-
if (
|
|
122
|
+
if (IS_RUNTIME) {
|
|
123
123
|
log("reload module...");
|
|
124
124
|
for (const cb of globalThis.__PS_HMR__) await cb(oldModels, newModels);
|
|
125
125
|
log("reload done");
|
|
@@ -127,14 +127,14 @@ async function RELOAD(oldModels, newModels) {
|
|
|
127
127
|
}
|
|
128
128
|
__name(RELOAD, "RELOAD");
|
|
129
129
|
function RELAUNCH() {
|
|
130
|
-
if (
|
|
130
|
+
if (IS_RUNTIME) {
|
|
131
131
|
log("relaunch...");
|
|
132
132
|
process.exit(PS_EXIT_CODE.RELAUNCH);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
__name(RELAUNCH, "RELAUNCH");
|
|
136
136
|
function EXIT() {
|
|
137
|
-
if (
|
|
137
|
+
if (IS_RUNTIME) {
|
|
138
138
|
log("exit...");
|
|
139
139
|
process.exit(PS_EXIT_CODE.EXIT);
|
|
140
140
|
}
|
|
@@ -159,4 +159,4 @@ __name(EXIT, "EXIT");
|
|
|
159
159
|
|
|
160
160
|
|
|
161
161
|
|
|
162
|
-
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.
|
|
162
|
+
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_RUNTIME = IS_RUNTIME; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.IS_PURE = IS_PURE; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.runMiddleware = runMiddleware; exports.Mixin = _tsmixer.Mixin; exports.HMR = HMR; exports.RELOAD = RELOAD; exports.RELAUNCH = RELAUNCH; exports.EXIT = EXIT;
|
|
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/common.ts
|
|
5
5
|
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
6
|
-
var
|
|
6
|
+
var IS_RUNTIME = !!process.env.PS_RUNTIME;
|
|
7
7
|
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
8
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
9
|
var IS_PURE = !!process.env.PS_PURE;
|
|
@@ -112,14 +112,14 @@ __name(runMiddleware, "runMiddleware");
|
|
|
112
112
|
|
|
113
113
|
// src/hmr.ts
|
|
114
114
|
function HMR(cb) {
|
|
115
|
-
if (
|
|
115
|
+
if (IS_RUNTIME) {
|
|
116
116
|
if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
|
|
117
117
|
globalThis.__PS_HMR__.push(cb);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
__name(HMR, "HMR");
|
|
121
121
|
async function RELOAD(oldModels, newModels) {
|
|
122
|
-
if (
|
|
122
|
+
if (IS_RUNTIME) {
|
|
123
123
|
log("reload module...");
|
|
124
124
|
for (const cb of globalThis.__PS_HMR__) await cb(oldModels, newModels);
|
|
125
125
|
log("reload done");
|
|
@@ -127,14 +127,14 @@ async function RELOAD(oldModels, newModels) {
|
|
|
127
127
|
}
|
|
128
128
|
__name(RELOAD, "RELOAD");
|
|
129
129
|
function RELAUNCH() {
|
|
130
|
-
if (
|
|
130
|
+
if (IS_RUNTIME) {
|
|
131
131
|
log("relaunch...");
|
|
132
132
|
process.exit(PS_EXIT_CODE.RELAUNCH);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
__name(RELAUNCH, "RELAUNCH");
|
|
136
136
|
function EXIT() {
|
|
137
|
-
if (
|
|
137
|
+
if (IS_RUNTIME) {
|
|
138
138
|
log("exit...");
|
|
139
139
|
process.exit(PS_EXIT_CODE.EXIT);
|
|
140
140
|
}
|
|
@@ -144,7 +144,7 @@ __name(EXIT, "EXIT");
|
|
|
144
144
|
export {
|
|
145
145
|
__name,
|
|
146
146
|
ERROR_SYMBOL,
|
|
147
|
-
|
|
147
|
+
IS_RUNTIME,
|
|
148
148
|
IS_ONLY_GENERATE,
|
|
149
149
|
IS_STRICT,
|
|
150
150
|
IS_PURE,
|