phecda-server 7.0.0-alpha.0 → 7.0.0-alpha.2
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/bin/cli.mjs +12 -7
- package/dist/{chunk-P75VKZJY.mjs → chunk-3FHZB3Z5.mjs} +48 -17
- package/dist/{chunk-BGXSMOLX.js → chunk-7YQ57BQS.js} +1 -1
- package/dist/{chunk-SW5IKE5H.js → chunk-NQIFUZL4.js} +47 -16
- package/dist/{chunk-5622RBNB.mjs → chunk-XYVMNY2X.mjs} +1 -1
- package/dist/{core-CYwEPfN4.d.ts → core-C1kHRqU9.d.ts} +1 -1
- package/dist/{core-BIcUwV18.d.mts → core-CSiaRU7r.d.mts} +1 -1
- package/dist/helper.d.mts +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +2 -2
- package/dist/helper.mjs +1 -1
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +19 -17
- package/dist/http/elysia/index.mjs +3 -1
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +19 -17
- package/dist/http/express/index.mjs +3 -1
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +18 -16
- package/dist/http/fastify/index.mjs +3 -1
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +18 -16
- package/dist/http/h3/index.mjs +3 -1
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +17 -15
- package/dist/http/hono/index.mjs +3 -1
- 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 +17 -15
- package/dist/http/hyper-express/index.mjs +3 -1
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +19 -17
- package/dist/http/koa/index.mjs +3 -1
- package/dist/index.d.mts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +21 -21
- package/dist/index.mjs +3 -3
- package/dist/{meta-BXKLFTgG.d.mts → meta-D1M85Hef.d.mts} +1 -0
- package/dist/{meta-BXKLFTgG.d.ts → meta-D1M85Hef.d.ts} +1 -0
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +9 -8
- package/dist/rpc/bullmq/index.mjs +2 -1
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +8 -7
- package/dist/rpc/kafka/index.mjs +2 -1
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +8 -7
- package/dist/rpc/nats/index.mjs +2 -1
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +9 -8
- package/dist/rpc/rabbitmq/index.mjs +2 -1
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +9 -8
- package/dist/rpc/redis/index.mjs +2 -1
- package/dist/test.d.mts +3 -3
- package/dist/test.d.ts +3 -3
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/{types-BtbL49Zs.d.mts → types-C9Remkup.d.ts} +2 -1
- package/dist/{types-m3IEDKjP.d.ts → types-JMhFVp-Z.d.mts} +2 -1
- package/dist/{types-VFzEM7LL.d.ts → types-ee1FBodH.d.ts} +2 -1
- package/dist/{types-h40T3cRG.d.mts → types-wbHHC93P.d.mts} +2 -1
- package/package.json +1 -1
- package/register/loader.mjs +366 -367
package/assets/ps.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/phecda-server/assets/schema.json",
|
|
3
|
-
"resolve": [
|
|
4
|
-
{
|
|
5
|
-
"source": "controller",
|
|
6
|
-
"importer": "http",
|
|
7
|
-
"path": ".ps/http.js"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"source": "rpc",
|
|
11
|
-
"importer": "client",
|
|
12
|
-
"path": ".ps/rpc.js"
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
|
-
"unimport": {
|
|
16
|
-
"dirs": ["."],
|
|
17
|
-
"dirsScanOptions": {
|
|
18
|
-
"filePatterns": ["*.{service,controller,module,rpc,edge,guard,
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"virtualFile": {},
|
|
22
|
-
"moduleFile": []
|
|
23
|
-
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/phecda-server/assets/schema.json",
|
|
3
|
+
"resolve": [
|
|
4
|
+
{
|
|
5
|
+
"source": "controller",
|
|
6
|
+
"importer": "http",
|
|
7
|
+
"path": ".ps/http.js"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"source": "rpc",
|
|
11
|
+
"importer": "client",
|
|
12
|
+
"path": ".ps/rpc.js"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"unimport": {
|
|
16
|
+
"dirs": ["."],
|
|
17
|
+
"dirsScanOptions": {
|
|
18
|
+
"filePatterns": ["*.{service,controller,module,rpc,edge,guard,extension,pipe,filter,addon}.ts"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"virtualFile": {},
|
|
22
|
+
"moduleFile": []
|
|
23
|
+
|
|
24
|
+
}
|
package/bin/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { fork } from 'child_process'
|
|
|
3
3
|
import { createRequire } from 'module'
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
|
|
6
|
-
import { dirname,
|
|
6
|
+
import { dirname, resolve } from 'path'
|
|
7
7
|
import pc from 'picocolors'
|
|
8
8
|
import cac from 'cac'
|
|
9
9
|
import fse from 'fs-extra'
|
|
@@ -46,6 +46,11 @@ function startChild(file, args) {
|
|
|
46
46
|
log('only generate code')
|
|
47
47
|
process.exit(0)
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
if (code === 5) {
|
|
51
|
+
log('Does not comply with strict mode', 'error')
|
|
52
|
+
process.exit(0)
|
|
53
|
+
}
|
|
49
54
|
if (code >= 2) {
|
|
50
55
|
// for relaunch
|
|
51
56
|
log('relaunch...')
|
|
@@ -80,11 +85,11 @@ cli
|
|
|
80
85
|
default: 'tsconfig.json',
|
|
81
86
|
})
|
|
82
87
|
.action(async (root, options) => {
|
|
83
|
-
if (
|
|
84
|
-
root
|
|
88
|
+
if (root)
|
|
89
|
+
process.chdir(root)
|
|
85
90
|
|
|
86
|
-
const tsconfigPath =
|
|
87
|
-
const psconfigPath =
|
|
91
|
+
const tsconfigPath = options.tsconfig
|
|
92
|
+
const psconfigPath = options.config
|
|
88
93
|
|
|
89
94
|
if (!fse.existsSync(tsconfigPath)) {
|
|
90
95
|
log(`create ${tsconfigPath}`)
|
|
@@ -111,7 +116,7 @@ cli
|
|
|
111
116
|
.alias('run')
|
|
112
117
|
.action((file, root, options) => {
|
|
113
118
|
if (root)
|
|
114
|
-
process.
|
|
119
|
+
process.chdir(root)
|
|
115
120
|
process.env.PS_CONFIG_FILE = options.config
|
|
116
121
|
|
|
117
122
|
log('process start!')
|
|
@@ -149,7 +154,7 @@ cli
|
|
|
149
154
|
.allowUnknownOptions()
|
|
150
155
|
.action((file, root, options) => {
|
|
151
156
|
if (root)
|
|
152
|
-
process.
|
|
157
|
+
process.chdir(root)
|
|
153
158
|
process.env.PS_GENERATE = 'true'
|
|
154
159
|
process.env.PS_CONFIG_FILE = options.config
|
|
155
160
|
startChild(file, options['--'])
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ERROR_SYMBOL,
|
|
3
3
|
IS_HMR,
|
|
4
|
+
IS_STRICT,
|
|
4
5
|
LOG_LEVEL,
|
|
5
6
|
__name,
|
|
6
7
|
log
|
|
7
8
|
} from "./chunk-WHJ5FALK.mjs";
|
|
8
9
|
|
|
9
10
|
// src/helper.ts
|
|
10
|
-
import
|
|
11
|
+
import pc2 from "picocolors";
|
|
11
12
|
|
|
12
13
|
// src/context.ts
|
|
13
14
|
import Debug from "debug";
|
|
15
|
+
import pc from "picocolors";
|
|
14
16
|
|
|
15
17
|
// src/pipe.ts
|
|
16
18
|
var defaultPipe = /* @__PURE__ */ __name(({ arg }) => {
|
|
@@ -235,14 +237,26 @@ var Context = class _Context {
|
|
|
235
237
|
}
|
|
236
238
|
static getAop(meta, opts) {
|
|
237
239
|
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
238
|
-
const { data: { guards, filter, params } } = meta;
|
|
239
|
-
|
|
240
|
-
guards:
|
|
240
|
+
const { data: { guards, filter, params, tag, func } } = meta;
|
|
241
|
+
const resolved = {
|
|
242
|
+
guards: [
|
|
241
243
|
...globalGuards,
|
|
242
244
|
...guards
|
|
243
|
-
]
|
|
244
|
-
pipe:
|
|
245
|
-
filter:
|
|
245
|
+
],
|
|
246
|
+
pipe: params.map((item) => item.pipe || globalPipe),
|
|
247
|
+
filter: filter || globalFilter
|
|
248
|
+
};
|
|
249
|
+
if (process.env.DEBUG) {
|
|
250
|
+
const { guards: guards2, pipe, filter: filter2 } = resolved;
|
|
251
|
+
debug(`func "${tag}-${func}" aop:
|
|
252
|
+
${pc.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
|
|
253
|
+
${pc.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
|
|
254
|
+
${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
guards: this.getGuards(resolved.guards),
|
|
258
|
+
pipe: this.getPipe(resolved.pipe),
|
|
259
|
+
filter: this.getFilter(resolved.filter)
|
|
246
260
|
};
|
|
247
261
|
}
|
|
248
262
|
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
@@ -268,7 +282,7 @@ var Context = class _Context {
|
|
|
268
282
|
async function next() {
|
|
269
283
|
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
270
284
|
if (ret2 !== void 0) {
|
|
271
|
-
debug(`The ${index + 1}th guard rewrite the response value.`);
|
|
285
|
+
debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
|
|
272
286
|
res = ret2;
|
|
273
287
|
}
|
|
274
288
|
return res;
|
|
@@ -316,17 +330,17 @@ var Context = class _Context {
|
|
|
316
330
|
}
|
|
317
331
|
};
|
|
318
332
|
function addPipe(key, pipe) {
|
|
319
|
-
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe)
|
|
333
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
|
|
320
334
|
Context.pipeRecord[key] = pipe;
|
|
321
335
|
}
|
|
322
336
|
__name(addPipe, "addPipe");
|
|
323
337
|
function addFilter(key, filter) {
|
|
324
|
-
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter)
|
|
338
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
|
|
325
339
|
Context.filterRecord[key] = filter;
|
|
326
340
|
}
|
|
327
341
|
__name(addFilter, "addFilter");
|
|
328
342
|
function addGuard(key, guard, priority = 0) {
|
|
329
|
-
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard)
|
|
343
|
+
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
|
|
330
344
|
Context.guardRecord[key] = {
|
|
331
345
|
value: guard,
|
|
332
346
|
priority
|
|
@@ -334,7 +348,7 @@ function addGuard(key, guard, priority = 0) {
|
|
|
334
348
|
}
|
|
335
349
|
__name(addGuard, "addGuard");
|
|
336
350
|
function addAddon(key, addon, priority = 0) {
|
|
337
|
-
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon)
|
|
351
|
+
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
|
|
338
352
|
Context.addonRecord[key] = {
|
|
339
353
|
value: addon,
|
|
340
354
|
priority
|
|
@@ -428,7 +442,7 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
428
442
|
});
|
|
429
443
|
meta.forEach(({ data }) => {
|
|
430
444
|
if (data.controller !== controller) {
|
|
431
|
-
if (data[controller]) warningSet.add(`
|
|
445
|
+
if (data[controller]) warningSet.add(`Should use ${controller} controller to decorate class "${data.name}"`);
|
|
432
446
|
return;
|
|
433
447
|
}
|
|
434
448
|
if (data.filter) filterSet.add(data.filter);
|
|
@@ -450,11 +464,28 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
450
464
|
const missFilters = [
|
|
451
465
|
...filterSet
|
|
452
466
|
].filter((i) => !Context.filterRecord[i]);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
467
|
+
function exit() {
|
|
468
|
+
if (IS_STRICT) process.exit(5);
|
|
469
|
+
}
|
|
470
|
+
__name(exit, "exit");
|
|
471
|
+
if (missAddons.length) {
|
|
472
|
+
log(`${pc2.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
473
|
+
exit();
|
|
474
|
+
}
|
|
475
|
+
if (missGuards.length) {
|
|
476
|
+
log(`${pc2.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
477
|
+
exit();
|
|
478
|
+
}
|
|
479
|
+
if (missPipes.length) {
|
|
480
|
+
log(`${pc2.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
481
|
+
exit();
|
|
482
|
+
}
|
|
483
|
+
if (missFilters.length) {
|
|
484
|
+
log(`${pc2.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
485
|
+
exit();
|
|
486
|
+
}
|
|
457
487
|
warningSet.forEach((warn) => log(warn, "warn"));
|
|
488
|
+
if (warningSet.size) exit();
|
|
458
489
|
}
|
|
459
490
|
__name(handleMeta, "handleMeta");
|
|
460
491
|
handleMeta();
|
|
@@ -23,7 +23,7 @@ require('reflect-metadata');
|
|
|
23
23
|
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
24
24
|
var _phecdacore = require('phecda-core');
|
|
25
25
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
26
|
-
var debug = _debug2.default.call(void 0, "phecda-server(
|
|
26
|
+
var debug = _debug2.default.call(void 0, "phecda-server(Factory)");
|
|
27
27
|
var emitter = new (0, _events2.default)();
|
|
28
28
|
function defaultServerInject() {
|
|
29
29
|
if (!_phecdacore.getInject.call(void 0, "watcher")) {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
var _chunkJ5CFUN4Vjs = require('./chunk-J5CFUN4V.js');
|
|
8
9
|
|
|
9
10
|
// src/helper.ts
|
|
@@ -12,6 +13,7 @@ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefau
|
|
|
12
13
|
// src/context.ts
|
|
13
14
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
15
|
|
|
16
|
+
|
|
15
17
|
// src/pipe.ts
|
|
16
18
|
var defaultPipe = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, ({ arg }) => {
|
|
17
19
|
return arg;
|
|
@@ -235,14 +237,26 @@ var Context = (_class = class _Context {
|
|
|
235
237
|
}
|
|
236
238
|
static getAop(meta, opts) {
|
|
237
239
|
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
238
|
-
const { data: { guards, filter, params } } = meta;
|
|
239
|
-
|
|
240
|
-
guards:
|
|
240
|
+
const { data: { guards, filter, params, tag, func } } = meta;
|
|
241
|
+
const resolved = {
|
|
242
|
+
guards: [
|
|
241
243
|
...globalGuards,
|
|
242
244
|
...guards
|
|
243
|
-
]
|
|
244
|
-
pipe:
|
|
245
|
-
filter:
|
|
245
|
+
],
|
|
246
|
+
pipe: params.map((item) => item.pipe || globalPipe),
|
|
247
|
+
filter: filter || globalFilter
|
|
248
|
+
};
|
|
249
|
+
if (process.env.DEBUG) {
|
|
250
|
+
const { guards: guards2, pipe, filter: filter2 } = resolved;
|
|
251
|
+
debug(`func "${tag}-${func}" aop:
|
|
252
|
+
${_picocolors2.default.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
|
|
253
|
+
${_picocolors2.default.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
|
|
254
|
+
${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
guards: this.getGuards(resolved.guards),
|
|
258
|
+
pipe: this.getPipe(resolved.pipe),
|
|
259
|
+
filter: this.getFilter(resolved.filter)
|
|
246
260
|
};
|
|
247
261
|
}
|
|
248
262
|
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
@@ -268,7 +282,7 @@ var Context = (_class = class _Context {
|
|
|
268
282
|
async function next() {
|
|
269
283
|
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
270
284
|
if (ret2 !== void 0) {
|
|
271
|
-
debug(`The ${index + 1}th guard rewrite the response value.`);
|
|
285
|
+
debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
|
|
272
286
|
res = ret2;
|
|
273
287
|
}
|
|
274
288
|
return res;
|
|
@@ -316,17 +330,17 @@ var Context = (_class = class _Context {
|
|
|
316
330
|
}
|
|
317
331
|
}, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class.__initStatic4(), _class);
|
|
318
332
|
function addPipe(key, pipe) {
|
|
319
|
-
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe)
|
|
333
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
|
|
320
334
|
Context.pipeRecord[key] = pipe;
|
|
321
335
|
}
|
|
322
336
|
_chunkJ5CFUN4Vjs.__name.call(void 0, addPipe, "addPipe");
|
|
323
337
|
function addFilter(key, filter) {
|
|
324
|
-
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter)
|
|
338
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
|
|
325
339
|
Context.filterRecord[key] = filter;
|
|
326
340
|
}
|
|
327
341
|
_chunkJ5CFUN4Vjs.__name.call(void 0, addFilter, "addFilter");
|
|
328
342
|
function addGuard(key, guard, priority = 0) {
|
|
329
|
-
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard)
|
|
343
|
+
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
|
|
330
344
|
Context.guardRecord[key] = {
|
|
331
345
|
value: guard,
|
|
332
346
|
priority
|
|
@@ -334,7 +348,7 @@ function addGuard(key, guard, priority = 0) {
|
|
|
334
348
|
}
|
|
335
349
|
_chunkJ5CFUN4Vjs.__name.call(void 0, addGuard, "addGuard");
|
|
336
350
|
function addAddon(key, addon, priority = 0) {
|
|
337
|
-
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon)
|
|
351
|
+
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
|
|
338
352
|
Context.addonRecord[key] = {
|
|
339
353
|
value: addon,
|
|
340
354
|
priority
|
|
@@ -428,7 +442,7 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
428
442
|
})]);
|
|
429
443
|
meta.forEach(({ data }) => {
|
|
430
444
|
if (data.controller !== controller) {
|
|
431
|
-
if (data[controller]) warningSet.add(`
|
|
445
|
+
if (data[controller]) warningSet.add(`Should use ${controller} controller to decorate class "${data.name}"`);
|
|
432
446
|
return;
|
|
433
447
|
}
|
|
434
448
|
if (data.filter) filterSet.add(data.filter);
|
|
@@ -450,11 +464,28 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
450
464
|
const missFilters = [
|
|
451
465
|
...filterSet
|
|
452
466
|
].filter((i) => !Context.filterRecord[i]);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
467
|
+
function exit() {
|
|
468
|
+
if (_chunkJ5CFUN4Vjs.IS_STRICT) process.exit(5);
|
|
469
|
+
}
|
|
470
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, exit, "exit");
|
|
471
|
+
if (missAddons.length) {
|
|
472
|
+
_chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
473
|
+
exit();
|
|
474
|
+
}
|
|
475
|
+
if (missGuards.length) {
|
|
476
|
+
_chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
477
|
+
exit();
|
|
478
|
+
}
|
|
479
|
+
if (missPipes.length) {
|
|
480
|
+
_chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
481
|
+
exit();
|
|
482
|
+
}
|
|
483
|
+
if (missFilters.length) {
|
|
484
|
+
_chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
485
|
+
exit();
|
|
486
|
+
}
|
|
457
487
|
warningSet.forEach((warn) => _chunkJ5CFUN4Vjs.log.call(void 0, warn, "warn"));
|
|
488
|
+
if (warningSet.size) exit();
|
|
458
489
|
}
|
|
459
490
|
_chunkJ5CFUN4Vjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
460
491
|
handleMeta();
|
|
@@ -23,7 +23,7 @@ import "reflect-metadata";
|
|
|
23
23
|
import EventEmitter from "node:events";
|
|
24
24
|
import { getInject, getMergedMeta, getMetaKey, getMetaParams, getTag, invokeInit, invokeUnmount, isPhecda, setInject } from "phecda-core";
|
|
25
25
|
import Debug from "debug";
|
|
26
|
-
var debug = Debug("phecda-server(
|
|
26
|
+
var debug = Debug("phecda-server(Factory)");
|
|
27
27
|
var emitter = new EventEmitter();
|
|
28
28
|
function defaultServerInject() {
|
|
29
29
|
if (!getInject("watcher")) {
|
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-D1M85Hef.mjs';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
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-D1M85Hef.js';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
package/dist/helper.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkNQIFUZL4js = require('./chunk-NQIFUZL4.js');
|
|
11
11
|
require('./chunk-J5CFUN4V.js');
|
|
12
12
|
|
|
13
13
|
|
|
@@ -18,4 +18,4 @@ require('./chunk-J5CFUN4V.js');
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
exports.HMR =
|
|
21
|
+
exports.HMR = _chunkNQIFUZL4js.HMR; exports.argToReq = _chunkNQIFUZL4js.argToReq; exports.createControllerMetaMap = _chunkNQIFUZL4js.createControllerMetaMap; exports.detectAopDep = _chunkNQIFUZL4js.detectAopDep; exports.genClientQueue = _chunkNQIFUZL4js.genClientQueue; exports.mergeObject = _chunkNQIFUZL4js.mergeObject; exports.resolveDep = _chunkNQIFUZL4js.resolveDep; exports.shallowClone = _chunkNQIFUZL4js.shallowClone;
|
package/dist/helper.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-wbHHC93P.mjs';
|
|
4
|
+
import { F as Factory } from '../../core-CSiaRU7r.mjs';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-D1M85Hef.mjs';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface ElysiaCtx extends HttpContext {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-ee1FBodH.js';
|
|
4
|
+
import { F as Factory } from '../../core-C1kHRqU9.js';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-D1M85Hef.js';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface ElysiaCtx extends HttpContext {
|
|
@@ -7,7 +7,7 @@ var _chunkMBCHNDAYjs = require('../../chunk-MBCHNDAY.js');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkNQIFUZL4js = require('../../chunk-NQIFUZL4.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
@@ -19,14 +19,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/elysia");
|
|
|
19
19
|
function bind(app, data, opts = {}) {
|
|
20
20
|
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
21
21
|
const { moduleMap, meta } = data;
|
|
22
|
-
const metaMap =
|
|
22
|
+
const metaMap = _chunkNQIFUZL4js.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
23
23
|
const { controller, http, func, tag } = meta2.data;
|
|
24
24
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
25
25
|
debug(`register method "${func}" in module "${tag}"`);
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
|
-
|
|
29
|
+
_chunkNQIFUZL4js.detectAopDep.call(void 0, meta, {
|
|
30
30
|
addons: [
|
|
31
31
|
...globalAddons,
|
|
32
32
|
...parallelAddons
|
|
@@ -35,35 +35,36 @@ function bind(app, data, opts = {}) {
|
|
|
35
35
|
});
|
|
36
36
|
registerRoute();
|
|
37
37
|
function registerRoute() {
|
|
38
|
-
|
|
38
|
+
_chunkNQIFUZL4js.Context.applyAddons(globalAddons, app, "elysia");
|
|
39
39
|
if (parallelRoute) {
|
|
40
40
|
const parallelRouter = new (0, _elysia.Elysia)();
|
|
41
|
-
|
|
41
|
+
_chunkNQIFUZL4js.Context.applyAddons(parallelAddons, app, "elysia");
|
|
42
42
|
parallelRouter.post(parallelRoute, async (c) => {
|
|
43
43
|
const { body } = c;
|
|
44
44
|
async function errorHandler(e) {
|
|
45
|
-
const error = await
|
|
45
|
+
const error = await _chunkNQIFUZL4js.Context.filterRecord.default(e);
|
|
46
46
|
c.set.status = error.status;
|
|
47
47
|
return error;
|
|
48
48
|
}
|
|
49
49
|
_chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
50
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
50
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkNQIFUZL4js.BadRequestException)("data format should be an array"));
|
|
51
51
|
try {
|
|
52
52
|
return Promise.all(body.map((item, i) => {
|
|
53
53
|
return new Promise(async (resolve) => {
|
|
54
54
|
const { tag, func } = item;
|
|
55
55
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
56
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
56
|
+
if (!metaMap.has(tag)) return resolve(await _chunkNQIFUZL4js.Context.filterRecord.default(new (0, _chunkNQIFUZL4js.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
57
57
|
const meta2 = metaMap.get(tag)[func];
|
|
58
|
-
if (!meta2) return resolve(await
|
|
58
|
+
if (!meta2) return resolve(await _chunkNQIFUZL4js.Context.filterRecord.default(new (0, _chunkNQIFUZL4js.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
59
59
|
const { data: { params } } = meta2;
|
|
60
|
-
const aop =
|
|
60
|
+
const aop = _chunkNQIFUZL4js.Context.getAop(meta2, {
|
|
61
61
|
globalGuards,
|
|
62
62
|
globalFilter,
|
|
63
63
|
globalPipe
|
|
64
64
|
});
|
|
65
65
|
const contextData = {
|
|
66
66
|
type: "elysia",
|
|
67
|
+
category: "http",
|
|
67
68
|
parallel: true,
|
|
68
69
|
context: c,
|
|
69
70
|
index: i,
|
|
@@ -72,7 +73,7 @@ function bind(app, data, opts = {}) {
|
|
|
72
73
|
tag,
|
|
73
74
|
func,
|
|
74
75
|
app,
|
|
75
|
-
...
|
|
76
|
+
..._chunkNQIFUZL4js.argToReq.call(void 0, params, item.args, c.headers),
|
|
76
77
|
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
77
78
|
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
78
79
|
...opts2,
|
|
@@ -89,7 +90,7 @@ function bind(app, data, opts = {}) {
|
|
|
89
90
|
throw new Error("elysia can't support getResponse");
|
|
90
91
|
}, "getResponse")
|
|
91
92
|
};
|
|
92
|
-
const context = new (0,
|
|
93
|
+
const context = new (0, _chunkNQIFUZL4js.Context)(contextData);
|
|
93
94
|
context.run(aop, resolve, resolve);
|
|
94
95
|
});
|
|
95
96
|
})).then((ret) => {
|
|
@@ -111,17 +112,18 @@ function bind(app, data, opts = {}) {
|
|
|
111
112
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
112
113
|
let aop;
|
|
113
114
|
if (!dynamic) {
|
|
114
|
-
aop =
|
|
115
|
+
aop = _chunkNQIFUZL4js.Context.getAop(meta2, {
|
|
115
116
|
globalFilter,
|
|
116
117
|
globalGuards,
|
|
117
118
|
globalPipe
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
+
_chunkNQIFUZL4js.Context.applyAddons(addons, subApp, "elysia");
|
|
121
122
|
subApp[http.type](http.prefix + http.route, async (c) => {
|
|
122
123
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
123
124
|
const contextData = {
|
|
124
125
|
type: "elysia",
|
|
126
|
+
category: "http",
|
|
125
127
|
context: c,
|
|
126
128
|
meta: meta2,
|
|
127
129
|
moduleMap,
|
|
@@ -149,16 +151,16 @@ function bind(app, data, opts = {}) {
|
|
|
149
151
|
}, "getResponse")
|
|
150
152
|
};
|
|
151
153
|
if (dynamic) {
|
|
152
|
-
aop =
|
|
154
|
+
aop = _chunkNQIFUZL4js.Context.getAop(meta2, {
|
|
153
155
|
globalFilter,
|
|
154
156
|
globalGuards,
|
|
155
157
|
globalPipe
|
|
156
158
|
});
|
|
157
159
|
}
|
|
158
|
-
const context = new (0,
|
|
160
|
+
const context = new (0, _chunkNQIFUZL4js.Context)(contextData);
|
|
159
161
|
if (http.headers) c.set.headers = http.headers;
|
|
160
162
|
if (dynamic) {
|
|
161
|
-
aop =
|
|
163
|
+
aop = _chunkNQIFUZL4js.Context.getAop(meta2, {
|
|
162
164
|
globalFilter,
|
|
163
165
|
globalGuards,
|
|
164
166
|
globalPipe
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
argToReq,
|
|
8
8
|
createControllerMetaMap,
|
|
9
9
|
detectAopDep
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-3FHZB3Z5.mjs";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
13
|
} from "../../chunk-WHJ5FALK.mjs";
|
|
@@ -64,6 +64,7 @@ function bind(app, data, opts = {}) {
|
|
|
64
64
|
});
|
|
65
65
|
const contextData = {
|
|
66
66
|
type: "elysia",
|
|
67
|
+
category: "http",
|
|
67
68
|
parallel: true,
|
|
68
69
|
context: c,
|
|
69
70
|
index: i,
|
|
@@ -122,6 +123,7 @@ function bind(app, data, opts = {}) {
|
|
|
122
123
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
123
124
|
const contextData = {
|
|
124
125
|
type: "elysia",
|
|
126
|
+
category: "http",
|
|
125
127
|
context: c,
|
|
126
128
|
meta: meta2,
|
|
127
129
|
moduleMap,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-wbHHC93P.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-CSiaRU7r.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-D1M85Hef.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface ExpressCtx extends HttpContext {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-ee1FBodH.js';
|
|
3
|
+
import { F as Factory } from '../../core-C1kHRqU9.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-D1M85Hef.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface ExpressCtx extends HttpContext {
|