phecda-server 6.0.2 → 7.0.0-alpha.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 +160 -157
- package/dist/{chunk-HDQAT2IM.mjs → chunk-5622RBNB.mjs} +118 -90
- package/dist/chunk-BGXSMOLX.js +265 -0
- package/dist/{chunk-F3W3NN7F.mjs → chunk-HMVLXNV3.mjs} +5 -14
- package/dist/{chunk-GHFSIZUO.js → chunk-J5CFUN4V.js} +18 -3
- package/dist/{chunk-XCND2QW3.js → chunk-MBCHNDAY.js} +27 -36
- package/dist/{chunk-WXFZZZRY.mjs → chunk-P75VKZJY.mjs} +101 -137
- package/dist/chunk-SW5IKE5H.js +503 -0
- package/dist/{chunk-UXD62LGG.mjs → chunk-WHJ5FALK.mjs} +17 -2
- package/dist/core-BIcUwV18.d.mts +47 -0
- package/dist/core-CYwEPfN4.d.ts +47 -0
- package/dist/helper.d.mts +4 -6
- package/dist/helper.d.ts +4 -6
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/{server → http}/elysia/index.d.mts +5 -5
- package/dist/{server → http}/elysia/index.d.ts +5 -5
- package/dist/{server → http}/elysia/index.js +80 -62
- package/dist/{server → http}/elysia/index.mjs +50 -32
- package/dist/{server → http}/express/index.d.mts +5 -5
- package/dist/{server → http}/express/index.d.ts +5 -5
- package/dist/{server → http}/express/index.js +71 -55
- package/dist/{server → http}/express/index.mjs +42 -26
- package/dist/{server → http}/fastify/index.d.mts +5 -5
- package/dist/{server → http}/fastify/index.d.ts +5 -5
- package/dist/{server → http}/fastify/index.js +72 -72
- package/dist/{server → http}/fastify/index.mjs +47 -47
- package/dist/{server → http}/h3/index.d.mts +5 -5
- package/dist/{server → http}/h3/index.d.ts +5 -5
- package/dist/http/h3/index.js +160 -0
- package/dist/{server → http}/h3/index.mjs +68 -62
- package/dist/{server → http}/hono/index.d.mts +5 -5
- package/dist/{server → http}/hono/index.d.ts +5 -5
- package/dist/{server → http}/hono/index.js +69 -54
- package/dist/{server → http}/hono/index.mjs +41 -26
- package/dist/{server → http}/hyper-express/index.d.mts +5 -5
- package/dist/{server → http}/hyper-express/index.d.ts +5 -5
- package/dist/{server → http}/hyper-express/index.js +69 -56
- package/dist/{server → http}/hyper-express/index.mjs +41 -28
- package/dist/{server → http}/koa/index.d.mts +5 -5
- package/dist/{server → http}/koa/index.d.ts +5 -5
- package/dist/{server → http}/koa/index.js +71 -55
- package/dist/{server → http}/koa/index.mjs +42 -26
- package/dist/index.d.mts +53 -41
- package/dist/index.d.ts +53 -41
- package/dist/index.js +62 -78
- package/dist/index.mjs +46 -62
- package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
- package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
- package/dist/rpc/bullmq/index.d.mts +6 -6
- package/dist/rpc/bullmq/index.d.ts +6 -6
- package/dist/rpc/bullmq/index.js +24 -24
- package/dist/rpc/bullmq/index.mjs +14 -14
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +25 -21
- package/dist/rpc/kafka/index.mjs +15 -11
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +22 -21
- package/dist/rpc/nats/index.mjs +13 -12
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +23 -22
- package/dist/rpc/rabbitmq/index.mjs +12 -11
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +24 -20
- package/dist/rpc/redis/index.mjs +15 -11
- 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-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
- package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
- package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
- package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
- package/package.json +24 -24
- package/dist/chunk-7SYPUIBY.js +0 -539
- package/dist/chunk-LYEZ6RGX.js +0 -237
- package/dist/core-2SNw8m2B.d.mts +0 -30
- package/dist/core-BmJJLUqj.d.ts +0 -30
- package/dist/server/h3/index.js +0 -154
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkJ5CFUN4Vjs = require('./chunk-J5CFUN4V.js');
|
|
8
|
+
|
|
9
|
+
// src/helper.ts
|
|
10
|
+
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
11
|
+
|
|
12
|
+
// src/context.ts
|
|
13
|
+
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
|
+
|
|
15
|
+
// src/pipe.ts
|
|
16
|
+
var defaultPipe = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, ({ arg }) => {
|
|
17
|
+
return arg;
|
|
18
|
+
}, "defaultPipe");
|
|
19
|
+
|
|
20
|
+
// src/exception/base.ts
|
|
21
|
+
var Exception = class extends Error {
|
|
22
|
+
static {
|
|
23
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "Exception");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
constructor(message, status = 0, description = "Exception") {
|
|
29
|
+
super(message), this.message = message, this.status = status, this.description = description;
|
|
30
|
+
}
|
|
31
|
+
get data() {
|
|
32
|
+
return {
|
|
33
|
+
message: this.message,
|
|
34
|
+
description: this.description,
|
|
35
|
+
status: this.status,
|
|
36
|
+
[_chunkJ5CFUN4Vjs.ERROR_SYMBOL]: true
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/exception/undefine.ts
|
|
42
|
+
var UndefinedException = class extends Exception {
|
|
43
|
+
static {
|
|
44
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "UndefinedException");
|
|
45
|
+
}
|
|
46
|
+
constructor(message) {
|
|
47
|
+
super(message, 500, "Undefined error");
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/exception/validate.ts
|
|
52
|
+
var ValidateException = class extends Exception {
|
|
53
|
+
static {
|
|
54
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "ValidateException");
|
|
55
|
+
}
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message, 400, "Validate exception");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/exception/forbidden.ts
|
|
62
|
+
var ForbiddenException = class extends Exception {
|
|
63
|
+
static {
|
|
64
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "ForbiddenException");
|
|
65
|
+
}
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super(message, 403, "Forbidden resource");
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/exception/bad-request.ts
|
|
72
|
+
var BadRequestException = class extends Exception {
|
|
73
|
+
static {
|
|
74
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "BadRequestException");
|
|
75
|
+
}
|
|
76
|
+
constructor(message) {
|
|
77
|
+
super(message, 400, "Bad Request");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/exception/not-found.ts
|
|
82
|
+
var NotFoundException = class extends Exception {
|
|
83
|
+
static {
|
|
84
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "NotFoundException");
|
|
85
|
+
}
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super(message, 404, "Not Found");
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/exception/conflict.ts
|
|
92
|
+
var ConflictException = class extends Exception {
|
|
93
|
+
static {
|
|
94
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "ConflictException");
|
|
95
|
+
}
|
|
96
|
+
constructor(message) {
|
|
97
|
+
super(message, 409, "Conflict");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/exception/bad-gateway.ts
|
|
102
|
+
var BadGatewayException = class extends Exception {
|
|
103
|
+
static {
|
|
104
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "BadGatewayException");
|
|
105
|
+
}
|
|
106
|
+
constructor(message) {
|
|
107
|
+
super(message, 502, "Bad Gatrway");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/exception/invalid-input.ts
|
|
112
|
+
var InvalidInputException = class extends Exception {
|
|
113
|
+
static {
|
|
114
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "InvalidInputException");
|
|
115
|
+
}
|
|
116
|
+
constructor(message) {
|
|
117
|
+
super(message, 502, "Invalid Input");
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/exception/media-type.ts
|
|
122
|
+
var UnsupportedMediaTypeException = class extends Exception {
|
|
123
|
+
static {
|
|
124
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "UnsupportedMediaTypeException");
|
|
125
|
+
}
|
|
126
|
+
constructor(message) {
|
|
127
|
+
super(message, 415, "Unsupported Media Type");
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/exception/payload-large.ts
|
|
132
|
+
var PayloadLargeException = class extends Exception {
|
|
133
|
+
static {
|
|
134
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "PayloadLargeException");
|
|
135
|
+
}
|
|
136
|
+
constructor(message) {
|
|
137
|
+
super(message, 413, "Payload Too Large");
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/exception/timeout.ts
|
|
142
|
+
var TimeoutException = class extends Exception {
|
|
143
|
+
static {
|
|
144
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "TimeoutException");
|
|
145
|
+
}
|
|
146
|
+
constructor(message) {
|
|
147
|
+
super(message, 408, "Request Timeout");
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/exception/unauthorized.ts
|
|
152
|
+
var UnauthorizedException = class extends Exception {
|
|
153
|
+
static {
|
|
154
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "UnauthorizedException");
|
|
155
|
+
}
|
|
156
|
+
constructor(message) {
|
|
157
|
+
super(message, 401, "Unauthorized");
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/exception/unavailable-service.ts
|
|
162
|
+
var ServiceUnavailableException = class extends Exception {
|
|
163
|
+
static {
|
|
164
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "ServiceUnavailableException");
|
|
165
|
+
}
|
|
166
|
+
constructor(message) {
|
|
167
|
+
super(message, 503, "Service Unavailable");
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/exception/framework.ts
|
|
172
|
+
var FrameworkException = class extends Exception {
|
|
173
|
+
static {
|
|
174
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "FrameworkException");
|
|
175
|
+
}
|
|
176
|
+
constructor(message) {
|
|
177
|
+
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/exception/timer.ts
|
|
182
|
+
var TimerException = class extends Exception {
|
|
183
|
+
static {
|
|
184
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "TimerException");
|
|
185
|
+
}
|
|
186
|
+
constructor(message) {
|
|
187
|
+
super(message, 0, "Timer Error");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/exception/worker.ts
|
|
192
|
+
var WorkerException = class extends Exception {
|
|
193
|
+
static {
|
|
194
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "WorkerException");
|
|
195
|
+
}
|
|
196
|
+
constructor(message) {
|
|
197
|
+
super(message, 0, "Worker Error");
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/filter.ts
|
|
202
|
+
var defaultFilter = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (e) => {
|
|
203
|
+
if (!(e instanceof Exception)) {
|
|
204
|
+
_chunkJ5CFUN4Vjs.log.call(void 0, e.message, "error");
|
|
205
|
+
if (_chunkJ5CFUN4Vjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
206
|
+
e = new UndefinedException(e.message || e);
|
|
207
|
+
} else {
|
|
208
|
+
_chunkJ5CFUN4Vjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
209
|
+
if (_chunkJ5CFUN4Vjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
210
|
+
}
|
|
211
|
+
return e.data;
|
|
212
|
+
}, "defaultFilter");
|
|
213
|
+
|
|
214
|
+
// src/context.ts
|
|
215
|
+
var debug = _debug2.default.call(void 0, "phecda-server(Context)");
|
|
216
|
+
var Context = (_class = class _Context {
|
|
217
|
+
static {
|
|
218
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, this, "Context");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
static __initStatic() {this.filterRecord = {
|
|
224
|
+
default: defaultFilter
|
|
225
|
+
}}
|
|
226
|
+
static __initStatic2() {this.pipeRecord = {
|
|
227
|
+
default: defaultPipe
|
|
228
|
+
}}
|
|
229
|
+
static __initStatic3() {this.guardRecord = {}}
|
|
230
|
+
static __initStatic4() {this.addonRecord = {}}
|
|
231
|
+
constructor(data) {
|
|
232
|
+
this.data = data;
|
|
233
|
+
if (_chunkJ5CFUN4Vjs.IS_HMR)
|
|
234
|
+
data._context = this;
|
|
235
|
+
}
|
|
236
|
+
static getAop(meta, opts) {
|
|
237
|
+
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
238
|
+
const { data: { guards, filter, params } } = meta;
|
|
239
|
+
return {
|
|
240
|
+
guards: this.getGuards([
|
|
241
|
+
...globalGuards,
|
|
242
|
+
...guards
|
|
243
|
+
]),
|
|
244
|
+
pipe: this.getPipe(params.map((item) => item.pipe || globalPipe)),
|
|
245
|
+
filter: this.getFilter(filter || globalFilter)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
249
|
+
const { meta, moduleMap } = this.data;
|
|
250
|
+
const { paramsType, data: { ctxs, tag, params, func } } = meta;
|
|
251
|
+
try {
|
|
252
|
+
let res;
|
|
253
|
+
const nextHandler = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (index) => {
|
|
254
|
+
return async () => {
|
|
255
|
+
if (index === guards.length) {
|
|
256
|
+
const instance = moduleMap.get(tag);
|
|
257
|
+
if (ctxs) {
|
|
258
|
+
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
259
|
+
}
|
|
260
|
+
const args = await Promise.all(params.map((item, i) => pipe[i]({
|
|
261
|
+
arg: resolveDep(this.data[item.type], item.key),
|
|
262
|
+
reflect: paramsType[item.index],
|
|
263
|
+
...item
|
|
264
|
+
}, this.data)));
|
|
265
|
+
res = await instance[func](...args);
|
|
266
|
+
} else {
|
|
267
|
+
let nextPromise;
|
|
268
|
+
async function next() {
|
|
269
|
+
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
270
|
+
if (ret2 !== void 0) {
|
|
271
|
+
debug(`The ${index + 1}th guard rewrite the response value.`);
|
|
272
|
+
res = ret2;
|
|
273
|
+
}
|
|
274
|
+
return res;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, next, "next");
|
|
278
|
+
const ret = await guards[index](this.data, next);
|
|
279
|
+
if (ret !== void 0) {
|
|
280
|
+
res = ret;
|
|
281
|
+
} else {
|
|
282
|
+
if (!nextPromise) await next();
|
|
283
|
+
else await nextPromise;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}, "nextHandler");
|
|
288
|
+
await nextHandler(0)();
|
|
289
|
+
return successCb(res);
|
|
290
|
+
} catch (e) {
|
|
291
|
+
const err = await filter(e, this.data);
|
|
292
|
+
return failCb(err);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
static getPipe(pipe) {
|
|
296
|
+
return pipe.map((pipe2) => {
|
|
297
|
+
return _Context.pipeRecord[pipe2] || _Context.pipeRecord.default;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
static getFilter(filter = "default") {
|
|
301
|
+
return _Context.filterRecord[filter] || _Context.filterRecord.default;
|
|
302
|
+
}
|
|
303
|
+
static getGuards(guards) {
|
|
304
|
+
const ret = [];
|
|
305
|
+
for (const guard of new Set(guards)) {
|
|
306
|
+
if (guard in _Context.guardRecord) ret.push(_Context.guardRecord[guard]);
|
|
307
|
+
}
|
|
308
|
+
return ret.sort((a, b) => b.priority - a.priority).map((item) => item.value);
|
|
309
|
+
}
|
|
310
|
+
static applyAddons(addons, router, framework) {
|
|
311
|
+
const ret = [];
|
|
312
|
+
for (const a of new Set(addons)) {
|
|
313
|
+
if (a in _Context.addonRecord) ret.push(_Context.addonRecord[a]);
|
|
314
|
+
}
|
|
315
|
+
ret.sort((a, b) => b.priority - a.priority).forEach((item) => item.value(router, framework));
|
|
316
|
+
}
|
|
317
|
+
}, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class.__initStatic4(), _class);
|
|
318
|
+
function addPipe(key, pipe) {
|
|
319
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) _chunkJ5CFUN4Vjs.log.call(void 0, `overwrite Pipe "${String(key)}"`, "warn");
|
|
320
|
+
Context.pipeRecord[key] = pipe;
|
|
321
|
+
}
|
|
322
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, addPipe, "addPipe");
|
|
323
|
+
function addFilter(key, filter) {
|
|
324
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) _chunkJ5CFUN4Vjs.log.call(void 0, `overwrite Filter "${String(key)}"`, "warn");
|
|
325
|
+
Context.filterRecord[key] = filter;
|
|
326
|
+
}
|
|
327
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, addFilter, "addFilter");
|
|
328
|
+
function addGuard(key, guard, priority = 0) {
|
|
329
|
+
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) _chunkJ5CFUN4Vjs.log.call(void 0, `overwrite Guard "${String(key)}"`, "warn");
|
|
330
|
+
Context.guardRecord[key] = {
|
|
331
|
+
value: guard,
|
|
332
|
+
priority
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, addGuard, "addGuard");
|
|
336
|
+
function addAddon(key, addon, priority = 0) {
|
|
337
|
+
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) _chunkJ5CFUN4Vjs.log.call(void 0, `overwrite Addon "${String(key)}"`, "warn");
|
|
338
|
+
Context.addonRecord[key] = {
|
|
339
|
+
value: addon,
|
|
340
|
+
priority
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, addAddon, "addAddon");
|
|
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");
|
|
350
|
+
|
|
351
|
+
// src/http/helper.ts
|
|
352
|
+
function resolveDep(ret, key) {
|
|
353
|
+
if (key) return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
|
|
354
|
+
return ret;
|
|
355
|
+
}
|
|
356
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
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");
|
|
371
|
+
|
|
372
|
+
// src/rpc/helper.ts
|
|
373
|
+
var _os = require('os');
|
|
374
|
+
function genClientQueue(key) {
|
|
375
|
+
return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
|
|
376
|
+
}
|
|
377
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
378
|
+
|
|
379
|
+
// src/decorators/helper.ts
|
|
380
|
+
function shallowClone(obj) {
|
|
381
|
+
return {
|
|
382
|
+
...obj
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
386
|
+
function mergeObject(...args) {
|
|
387
|
+
return Object.assign({}, ...args);
|
|
388
|
+
}
|
|
389
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
390
|
+
|
|
391
|
+
// src/helper.ts
|
|
392
|
+
function createControllerMetaMap(meta, filter) {
|
|
393
|
+
const metaMap = /* @__PURE__ */ new Map();
|
|
394
|
+
function handleMeta() {
|
|
395
|
+
metaMap.clear();
|
|
396
|
+
for (const item of meta) {
|
|
397
|
+
const { tag, func } = item.data;
|
|
398
|
+
if (!filter(item)) continue;
|
|
399
|
+
if (metaMap.has(tag)) metaMap.get(tag)[func] = item;
|
|
400
|
+
else metaMap.set(tag, {
|
|
401
|
+
[func]: item
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
406
|
+
handleMeta();
|
|
407
|
+
HMR(handleMeta);
|
|
408
|
+
return metaMap;
|
|
409
|
+
}
|
|
410
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, createControllerMetaMap, "createControllerMetaMap");
|
|
411
|
+
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
412
|
+
const addonSet = /* @__PURE__ */ new Set();
|
|
413
|
+
const guardSet = /* @__PURE__ */ new Set();
|
|
414
|
+
const pipeSet = /* @__PURE__ */ new Set();
|
|
415
|
+
const filterSet = /* @__PURE__ */ new Set();
|
|
416
|
+
const warningSet = /* @__PURE__ */ new Set();
|
|
417
|
+
function handleMeta() {
|
|
418
|
+
addonSet.clear();
|
|
419
|
+
guardSet.clear();
|
|
420
|
+
pipeSet.clear();
|
|
421
|
+
filterSet.clear();
|
|
422
|
+
warningSet.clear();
|
|
423
|
+
_optionalChain([addons, 'optionalAccess', _5 => _5.forEach, 'call', _6 => _6((item) => {
|
|
424
|
+
addonSet.add(item);
|
|
425
|
+
})]);
|
|
426
|
+
_optionalChain([guards, 'optionalAccess', _7 => _7.forEach, 'call', _8 => _8((item) => {
|
|
427
|
+
guardSet.add(item);
|
|
428
|
+
})]);
|
|
429
|
+
meta.forEach(({ data }) => {
|
|
430
|
+
if (data.controller !== controller) {
|
|
431
|
+
if (data[controller]) warningSet.add(`Module "${data.tag === data.name ? data.name : `${data.name}(${data.tag})`}" should use ${controller} controller to decorate class or remove ${controller} decorator on method "${data.func}"`);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (data.filter) filterSet.add(data.filter);
|
|
435
|
+
data.guards.forEach((i) => guardSet.add(i));
|
|
436
|
+
data.addons.forEach((i) => addonSet.add(i));
|
|
437
|
+
data.params.forEach((i) => {
|
|
438
|
+
if (i.pipe) pipeSet.add(i.pipe);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
const missAddons = [
|
|
442
|
+
...addonSet
|
|
443
|
+
].filter((i) => !Context.addonRecord[i]);
|
|
444
|
+
const missGuards = [
|
|
445
|
+
...guardSet
|
|
446
|
+
].filter((i) => !Context.guardRecord[i]);
|
|
447
|
+
const missPipes = [
|
|
448
|
+
...pipeSet
|
|
449
|
+
].filter((i) => !Context.pipeRecord[i]);
|
|
450
|
+
const missFilters = [
|
|
451
|
+
...filterSet
|
|
452
|
+
].filter((i) => !Context.filterRecord[i]);
|
|
453
|
+
if (missAddons.length) _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
454
|
+
if (missGuards.length) _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
455
|
+
if (missPipes.length) _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
456
|
+
if (missFilters.length) _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
457
|
+
warningSet.forEach((warn) => _chunkJ5CFUN4Vjs.log.call(void 0, warn, "warn"));
|
|
458
|
+
}
|
|
459
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
460
|
+
handleMeta();
|
|
461
|
+
HMR(handleMeta);
|
|
462
|
+
return {
|
|
463
|
+
addonSet,
|
|
464
|
+
guardSet,
|
|
465
|
+
pipeSet,
|
|
466
|
+
filterSet
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
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.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.createControllerMetaMap = createControllerMetaMap; exports.detectAopDep = detectAopDep;
|
|
@@ -17,13 +17,19 @@ var PS_EXIT_CODE;
|
|
|
17
17
|
import pc from "picocolors";
|
|
18
18
|
import { Mixin } from "ts-mixer";
|
|
19
19
|
var time;
|
|
20
|
-
var internalLogger
|
|
20
|
+
var internalLogger;
|
|
21
21
|
function setLogger(logger) {
|
|
22
22
|
internalLogger = logger;
|
|
23
23
|
}
|
|
24
24
|
__name(setLogger, "setLogger");
|
|
25
|
+
function getLogger() {
|
|
26
|
+
return internalLogger;
|
|
27
|
+
}
|
|
28
|
+
__name(getLogger, "getLogger");
|
|
25
29
|
function log(msg, level = "log") {
|
|
30
|
+
if (internalLogger) internalLogger[level](msg);
|
|
26
31
|
const logLevel = {
|
|
32
|
+
debug: -1,
|
|
27
33
|
info: 0,
|
|
28
34
|
log: 1,
|
|
29
35
|
warn: 2,
|
|
@@ -31,6 +37,7 @@ function log(msg, level = "log") {
|
|
|
31
37
|
}[level];
|
|
32
38
|
if (logLevel < LOG_LEVEL) return;
|
|
33
39
|
const color = {
|
|
40
|
+
debug: "bgMagenta",
|
|
34
41
|
error: "red",
|
|
35
42
|
info: "gray",
|
|
36
43
|
warn: "yellow",
|
|
@@ -40,9 +47,15 @@ function log(msg, level = "log") {
|
|
|
40
47
|
const current = Date.now();
|
|
41
48
|
const interval = time && current - time ? `+${current - time}` : "";
|
|
42
49
|
time = current;
|
|
43
|
-
|
|
50
|
+
console[level](`${pc.magenta("[phecda-server]")} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`);
|
|
44
51
|
}
|
|
45
52
|
__name(log, "log");
|
|
53
|
+
function runMiddleware(ctx, middleware) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
middleware(ctx.getRequest(), ctx.getResponse(), resolve);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
__name(runMiddleware, "runMiddleware");
|
|
46
59
|
|
|
47
60
|
export {
|
|
48
61
|
__name,
|
|
@@ -53,6 +66,8 @@ export {
|
|
|
53
66
|
LOG_LEVEL,
|
|
54
67
|
PS_EXIT_CODE,
|
|
55
68
|
setLogger,
|
|
69
|
+
getLogger,
|
|
56
70
|
log,
|
|
71
|
+
runMiddleware,
|
|
57
72
|
Mixin
|
|
58
73
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Construct } from 'phecda-core';
|
|
2
|
+
import { b as MetaData, M as Meta, E as Emitter } from './meta-BXKLFTgG.mjs';
|
|
3
|
+
|
|
4
|
+
declare abstract class Generator {
|
|
5
|
+
private _path;
|
|
6
|
+
constructor(path?: string);
|
|
7
|
+
abstract name: string;
|
|
8
|
+
get path(): string;
|
|
9
|
+
abstract generateCode(meta: MetaData[]): string;
|
|
10
|
+
output(meta: Meta[]): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare const emitter: Emitter;
|
|
14
|
+
interface Options {
|
|
15
|
+
parseModule?: (module: any) => any;
|
|
16
|
+
parseMeta?: (meta: Meta) => Meta | null | undefined;
|
|
17
|
+
generators?: Generator[];
|
|
18
|
+
namespace?: string;
|
|
19
|
+
}
|
|
20
|
+
declare function defaultServerInject(): void;
|
|
21
|
+
declare const phecdaNamespace: Map<string, ServerPhecda>;
|
|
22
|
+
declare class ServerPhecda {
|
|
23
|
+
moduleMap: Map<PropertyKey, any>;
|
|
24
|
+
meta: Meta[];
|
|
25
|
+
modelMap: WeakMap<any, Construct>;
|
|
26
|
+
modelSet: WeakSet<Construct>;
|
|
27
|
+
dependenceGraph: Map<PropertyKey, Set<PropertyKey>>;
|
|
28
|
+
parseModule: (module: any) => any;
|
|
29
|
+
parseMeta: (meta: Meta) => Meta | null | undefined;
|
|
30
|
+
generators: Generator[];
|
|
31
|
+
constructor(options: Options);
|
|
32
|
+
start(models: Construct[]): Promise<void>;
|
|
33
|
+
add(Model: Construct): Promise<void>;
|
|
34
|
+
del(tag: PropertyKey): Promise<any>;
|
|
35
|
+
destroy(): Promise<void>;
|
|
36
|
+
protected buildDepModule(Model: Construct): Promise<{
|
|
37
|
+
module: any;
|
|
38
|
+
tag: PropertyKey;
|
|
39
|
+
}>;
|
|
40
|
+
has(modelOrTag: Construct | PropertyKey): boolean;
|
|
41
|
+
get<Model extends Construct>(modelOrTag: Model | PropertyKey): InstanceType<Model>;
|
|
42
|
+
}
|
|
43
|
+
declare function Factory(models: Construct[], opts?: Options): Promise<ServerPhecda>;
|
|
44
|
+
declare function useS<Model extends Construct>(model: Model, namespace?: string): InstanceType<Model>;
|
|
45
|
+
declare function useS(namespace?: string): ServerPhecda;
|
|
46
|
+
|
|
47
|
+
export { Factory as F, Generator as G, type Options as O, ServerPhecda as S, defaultServerInject as d, emitter as e, phecdaNamespace as p, useS as u };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Construct } from 'phecda-core';
|
|
2
|
+
import { b as MetaData, M as Meta, E as Emitter } from './meta-BXKLFTgG.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class Generator {
|
|
5
|
+
private _path;
|
|
6
|
+
constructor(path?: string);
|
|
7
|
+
abstract name: string;
|
|
8
|
+
get path(): string;
|
|
9
|
+
abstract generateCode(meta: MetaData[]): string;
|
|
10
|
+
output(meta: Meta[]): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare const emitter: Emitter;
|
|
14
|
+
interface Options {
|
|
15
|
+
parseModule?: (module: any) => any;
|
|
16
|
+
parseMeta?: (meta: Meta) => Meta | null | undefined;
|
|
17
|
+
generators?: Generator[];
|
|
18
|
+
namespace?: string;
|
|
19
|
+
}
|
|
20
|
+
declare function defaultServerInject(): void;
|
|
21
|
+
declare const phecdaNamespace: Map<string, ServerPhecda>;
|
|
22
|
+
declare class ServerPhecda {
|
|
23
|
+
moduleMap: Map<PropertyKey, any>;
|
|
24
|
+
meta: Meta[];
|
|
25
|
+
modelMap: WeakMap<any, Construct>;
|
|
26
|
+
modelSet: WeakSet<Construct>;
|
|
27
|
+
dependenceGraph: Map<PropertyKey, Set<PropertyKey>>;
|
|
28
|
+
parseModule: (module: any) => any;
|
|
29
|
+
parseMeta: (meta: Meta) => Meta | null | undefined;
|
|
30
|
+
generators: Generator[];
|
|
31
|
+
constructor(options: Options);
|
|
32
|
+
start(models: Construct[]): Promise<void>;
|
|
33
|
+
add(Model: Construct): Promise<void>;
|
|
34
|
+
del(tag: PropertyKey): Promise<any>;
|
|
35
|
+
destroy(): Promise<void>;
|
|
36
|
+
protected buildDepModule(Model: Construct): Promise<{
|
|
37
|
+
module: any;
|
|
38
|
+
tag: PropertyKey;
|
|
39
|
+
}>;
|
|
40
|
+
has(modelOrTag: Construct | PropertyKey): boolean;
|
|
41
|
+
get<Model extends Construct>(modelOrTag: Model | PropertyKey): InstanceType<Model>;
|
|
42
|
+
}
|
|
43
|
+
declare function Factory(models: Construct[], opts?: Options): Promise<ServerPhecda>;
|
|
44
|
+
declare function useS<Model extends Construct>(model: Model, namespace?: string): InstanceType<Model>;
|
|
45
|
+
declare function useS(namespace?: string): ServerPhecda;
|
|
46
|
+
|
|
47
|
+
export { Factory as F, Generator as G, type Options as O, ServerPhecda as S, defaultServerInject as d, emitter as e, phecdaNamespace as p, useS as u };
|
package/dist/helper.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-
|
|
1
|
+
import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-BXKLFTgG.mjs';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
|
@@ -12,14 +12,12 @@ declare function shallowClone(obj: any): any;
|
|
|
12
12
|
declare function mergeObject(...args: any[]): any;
|
|
13
13
|
|
|
14
14
|
declare function createControllerMetaMap(meta: Meta[], filter: (meta: Meta) => boolean | void): Map<string, Record<string, ControllerMeta>>;
|
|
15
|
-
declare function detectAopDep(meta: Meta[], { guards,
|
|
15
|
+
declare function detectAopDep(meta: Meta[], { guards, addons }?: {
|
|
16
16
|
guards?: string[];
|
|
17
|
-
|
|
18
|
-
plugins?: string[];
|
|
17
|
+
addons?: string[];
|
|
19
18
|
}, controller?: string): {
|
|
20
|
-
|
|
19
|
+
addonSet: Set<string>;
|
|
21
20
|
guardSet: Set<string>;
|
|
22
|
-
interceptorSet: Set<string>;
|
|
23
21
|
pipeSet: Set<string>;
|
|
24
22
|
filterSet: Set<string>;
|
|
25
23
|
};
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-
|
|
1
|
+
import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-BXKLFTgG.js';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
|
@@ -12,14 +12,12 @@ declare function shallowClone(obj: any): any;
|
|
|
12
12
|
declare function mergeObject(...args: any[]): any;
|
|
13
13
|
|
|
14
14
|
declare function createControllerMetaMap(meta: Meta[], filter: (meta: Meta) => boolean | void): Map<string, Record<string, ControllerMeta>>;
|
|
15
|
-
declare function detectAopDep(meta: Meta[], { guards,
|
|
15
|
+
declare function detectAopDep(meta: Meta[], { guards, addons }?: {
|
|
16
16
|
guards?: string[];
|
|
17
|
-
|
|
18
|
-
plugins?: string[];
|
|
17
|
+
addons?: string[];
|
|
19
18
|
}, controller?: string): {
|
|
20
|
-
|
|
19
|
+
addonSet: Set<string>;
|
|
21
20
|
guardSet: Set<string>;
|
|
22
|
-
interceptorSet: Set<string>;
|
|
23
21
|
pipeSet: Set<string>;
|
|
24
22
|
filterSet: Set<string>;
|
|
25
23
|
};
|