phecda-server 5.0.0 → 5.0.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/bin/schema.json +7 -0
- package/dist/{chunk-5VMFQOJ7.mjs → chunk-AB4OX3WV.mjs} +13 -5
- package/dist/{chunk-VMXI3KFJ.js → chunk-BXLBWRHS.js} +12 -12
- package/dist/{chunk-C7MN5B36.mjs → chunk-W5EOVGQD.mjs} +1 -1
- package/dist/{chunk-5YYZLGGN.js → chunk-YERBWZCS.js} +13 -5
- package/dist/{core-eb646fe5.d.ts → core-fd134ffa.d.ts} +6 -15
- package/dist/helper-73e8d2f0.d.ts +18 -0
- package/dist/helper-f29f082f.d.ts +19 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +23 -23
- package/dist/index.mjs +2 -2
- package/dist/rpc/bullmq/index.d.ts +2 -3
- package/dist/rpc/bullmq/index.js +14 -17
- package/dist/rpc/bullmq/index.mjs +9 -12
- package/dist/rpc/kafka/index.d.ts +2 -3
- package/dist/rpc/kafka/index.js +14 -17
- package/dist/rpc/kafka/index.mjs +9 -12
- package/dist/rpc/nats/index.d.ts +2 -3
- package/dist/rpc/nats/index.js +13 -16
- package/dist/rpc/nats/index.mjs +9 -12
- package/dist/rpc/rabbitmq/index.d.ts +2 -3
- package/dist/rpc/rabbitmq/index.js +14 -17
- package/dist/rpc/rabbitmq/index.mjs +9 -12
- package/dist/rpc/redis/index.d.ts +2 -3
- package/dist/rpc/redis/index.js +14 -17
- package/dist/rpc/redis/index.mjs +9 -12
- package/dist/server/elysia/index.d.ts +4 -4
- package/dist/server/elysia/index.js +30 -30
- package/dist/server/elysia/index.mjs +17 -17
- package/dist/server/express/index.d.ts +4 -4
- package/dist/server/express/index.js +28 -28
- package/dist/server/express/index.mjs +16 -16
- package/dist/server/fastify/index.d.ts +4 -4
- package/dist/server/fastify/index.js +30 -30
- package/dist/server/fastify/index.mjs +17 -17
- package/dist/server/h3/index.d.ts +5 -10
- package/dist/server/h3/index.js +28 -28
- package/dist/server/h3/index.mjs +16 -16
- package/dist/server/hono/index.d.ts +4 -4
- package/dist/server/hono/index.js +28 -28
- package/dist/server/hono/index.mjs +16 -16
- package/dist/server/hyper-express/index.d.ts +4 -4
- package/dist/server/hyper-express/index.js +28 -28
- package/dist/server/hyper-express/index.mjs +16 -16
- package/dist/server/koa/index.d.ts +4 -4
- package/dist/server/koa/index.js +28 -28
- package/dist/server/koa/index.mjs +16 -16
- package/dist/test.d.ts +1 -2
- package/dist/test.js +8 -1
- package/dist/test.mjs +8 -1
- package/package.json +2 -2
- package/register/loader.mjs +36 -8
- package/dist/helper-88b19c66.d.ts +0 -12
- package/dist/helper-9e206c66.d.ts +0 -12
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
@@ -12,13 +12,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
|
12
12
|
// src/server/hyper-express/bind.ts
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
14
|
var debug = _debug2.default.call(void 0, "phecda-server/hyper-express");
|
|
15
|
-
function bind(router, { moduleMap, meta },
|
|
16
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
15
|
+
function bind(router, { moduleMap, meta }, opts = {}) {
|
|
16
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
17
17
|
route: "/__PHECDA_SERVER__",
|
|
18
|
-
globalGuards: [],
|
|
19
|
-
globalInterceptors: [],
|
|
20
18
|
plugins: [],
|
|
21
|
-
...
|
|
19
|
+
...opts
|
|
22
20
|
};
|
|
23
21
|
const metaMap = /* @__PURE__ */ new Map();
|
|
24
22
|
function handleMeta() {
|
|
@@ -28,14 +26,6 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
28
26
|
if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
|
|
29
27
|
continue;
|
|
30
28
|
debug(`register method "${func}" in module "${tag}"`);
|
|
31
|
-
item.data.guards = [
|
|
32
|
-
...globalGuards,
|
|
33
|
-
...item.data.guards
|
|
34
|
-
];
|
|
35
|
-
item.data.interceptors = [
|
|
36
|
-
...globalInterceptors,
|
|
37
|
-
...item.data.interceptors
|
|
38
|
-
];
|
|
39
29
|
if (metaMap.has(tag))
|
|
40
30
|
metaMap.get(tag)[func] = item;
|
|
41
31
|
else
|
|
@@ -48,27 +38,27 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
48
38
|
async function createRoute() {
|
|
49
39
|
router.post(route, {
|
|
50
40
|
middlewares: [
|
|
51
|
-
...
|
|
41
|
+
..._chunkYERBWZCSjs.Context.usePlugin(plugins)
|
|
52
42
|
]
|
|
53
43
|
}, async (req, res, next) => {
|
|
54
44
|
const body = await req.json();
|
|
55
45
|
async function errorHandler(e) {
|
|
56
|
-
const error = await
|
|
46
|
+
const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
|
|
57
47
|
return res.status(error.status).json(error);
|
|
58
48
|
}
|
|
59
49
|
_chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
60
50
|
if (!Array.isArray(body))
|
|
61
|
-
return errorHandler(new (0,
|
|
51
|
+
return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
|
|
62
52
|
try {
|
|
63
53
|
return Promise.all(body.map((item, i) => {
|
|
64
54
|
return new Promise(async (resolve) => {
|
|
65
55
|
const { tag, func } = item;
|
|
66
56
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
67
57
|
if (!metaMap.has(tag))
|
|
68
|
-
return resolve(await
|
|
58
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
69
59
|
const meta2 = metaMap.get(tag)[func];
|
|
70
60
|
if (!meta2)
|
|
71
|
-
return resolve(await
|
|
61
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
72
62
|
const { data: { params } } = meta2;
|
|
73
63
|
const contextData = {
|
|
74
64
|
type: "hyper-express",
|
|
@@ -82,10 +72,15 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
82
72
|
func,
|
|
83
73
|
next,
|
|
84
74
|
app: router,
|
|
85
|
-
...
|
|
75
|
+
..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, req.headers)
|
|
86
76
|
};
|
|
87
|
-
const context = new (0,
|
|
88
|
-
context.run(
|
|
77
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
78
|
+
context.run({
|
|
79
|
+
globalGuards,
|
|
80
|
+
globalInterceptors,
|
|
81
|
+
globalFilter,
|
|
82
|
+
globalPipe
|
|
83
|
+
}, resolve, resolve);
|
|
89
84
|
});
|
|
90
85
|
})).then((ret) => {
|
|
91
86
|
res.json(ret);
|
|
@@ -101,7 +96,7 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
101
96
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
102
97
|
continue;
|
|
103
98
|
const needBody = params.some((item) => item.type === "body");
|
|
104
|
-
router[http.type](http.prefix + http.route, ...
|
|
99
|
+
router[http.type](http.prefix + http.route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins2), async (req, res, next) => {
|
|
105
100
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
106
101
|
const contextData = {
|
|
107
102
|
type: "hyper-express",
|
|
@@ -118,12 +113,17 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
118
113
|
headers: req.headers,
|
|
119
114
|
next
|
|
120
115
|
};
|
|
121
|
-
const context = new (0,
|
|
116
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
122
117
|
if (http.headers) {
|
|
123
118
|
for (const name in http.headers)
|
|
124
119
|
res.set(name, http.headers[name]);
|
|
125
120
|
}
|
|
126
|
-
await context.run(
|
|
121
|
+
await context.run({
|
|
122
|
+
globalGuards,
|
|
123
|
+
globalInterceptors,
|
|
124
|
+
globalFilter,
|
|
125
|
+
globalPipe
|
|
126
|
+
}, (returnData) => {
|
|
127
127
|
if (res.writableEnded)
|
|
128
128
|
return;
|
|
129
129
|
if (typeof returnData === "string")
|
|
@@ -140,15 +140,15 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
_chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
|
|
143
|
-
|
|
143
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
144
144
|
plugins,
|
|
145
145
|
guards: globalGuards,
|
|
146
146
|
interceptors: globalInterceptors
|
|
147
147
|
});
|
|
148
148
|
handleMeta();
|
|
149
149
|
createRoute();
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
_chunkYERBWZCSjs.HMR.call(void 0, () => {
|
|
151
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
152
152
|
plugins,
|
|
153
153
|
guards: globalGuards,
|
|
154
154
|
interceptors: globalInterceptors
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HMR,
|
|
5
5
|
argToReq,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-AB4OX3WV.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
10
|
} from "../../chunk-ITTD2GBR.mjs";
|
|
@@ -12,13 +12,11 @@ import {
|
|
|
12
12
|
// src/server/hyper-express/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
14
14
|
var debug = Debug("phecda-server/hyper-express");
|
|
15
|
-
function bind(router, { moduleMap, meta },
|
|
16
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
15
|
+
function bind(router, { moduleMap, meta }, opts = {}) {
|
|
16
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
17
17
|
route: "/__PHECDA_SERVER__",
|
|
18
|
-
globalGuards: [],
|
|
19
|
-
globalInterceptors: [],
|
|
20
18
|
plugins: [],
|
|
21
|
-
...
|
|
19
|
+
...opts
|
|
22
20
|
};
|
|
23
21
|
const metaMap = /* @__PURE__ */ new Map();
|
|
24
22
|
function handleMeta() {
|
|
@@ -28,14 +26,6 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
28
26
|
if (controller !== "http" || !http?.type)
|
|
29
27
|
continue;
|
|
30
28
|
debug(`register method "${func}" in module "${tag}"`);
|
|
31
|
-
item.data.guards = [
|
|
32
|
-
...globalGuards,
|
|
33
|
-
...item.data.guards
|
|
34
|
-
];
|
|
35
|
-
item.data.interceptors = [
|
|
36
|
-
...globalInterceptors,
|
|
37
|
-
...item.data.interceptors
|
|
38
|
-
];
|
|
39
29
|
if (metaMap.has(tag))
|
|
40
30
|
metaMap.get(tag)[func] = item;
|
|
41
31
|
else
|
|
@@ -85,7 +75,12 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
85
75
|
...argToReq(params, item.args, req.headers)
|
|
86
76
|
};
|
|
87
77
|
const context = new Context(contextData);
|
|
88
|
-
context.run(
|
|
78
|
+
context.run({
|
|
79
|
+
globalGuards,
|
|
80
|
+
globalInterceptors,
|
|
81
|
+
globalFilter,
|
|
82
|
+
globalPipe
|
|
83
|
+
}, resolve, resolve);
|
|
89
84
|
});
|
|
90
85
|
})).then((ret) => {
|
|
91
86
|
res.json(ret);
|
|
@@ -123,7 +118,12 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
123
118
|
for (const name in http.headers)
|
|
124
119
|
res.set(name, http.headers[name]);
|
|
125
120
|
}
|
|
126
|
-
await context.run(
|
|
121
|
+
await context.run({
|
|
122
|
+
globalGuards,
|
|
123
|
+
globalInterceptors,
|
|
124
|
+
globalFilter,
|
|
125
|
+
globalPipe
|
|
126
|
+
}, (returnData) => {
|
|
127
127
|
if (res.writableEnded)
|
|
128
128
|
return;
|
|
129
129
|
if (typeof returnData === "string")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Router, { RouterParamContext } from '@koa/router';
|
|
2
2
|
import { DefaultContext, DefaultState } from 'koa';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
|
|
4
|
+
import { F as Factory } from '../../core-fd134ffa.js';
|
|
5
|
+
import 'node:http';
|
|
5
6
|
import 'phecda-core';
|
|
6
|
-
import 'http';
|
|
7
7
|
|
|
8
8
|
interface KoaCtx extends HttpContext {
|
|
9
9
|
type: 'koa';
|
|
@@ -11,6 +11,6 @@ interface KoaCtx extends HttpContext {
|
|
|
11
11
|
next: Function;
|
|
12
12
|
app: Router;
|
|
13
13
|
}
|
|
14
|
-
declare function bind(router: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>,
|
|
14
|
+
declare function bind(router: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
15
15
|
|
|
16
16
|
export { KoaCtx, bind };
|
package/dist/server/koa/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
@@ -12,13 +12,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
|
12
12
|
// src/server/koa/bind.ts
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
14
|
var debug = _debug2.default.call(void 0, "phecda-server/koa");
|
|
15
|
-
function bind(router, { moduleMap, meta },
|
|
16
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
15
|
+
function bind(router, { moduleMap, meta }, opts = {}) {
|
|
16
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
17
17
|
route: "/__PHECDA_SERVER__",
|
|
18
|
-
globalGuards: [],
|
|
19
|
-
globalInterceptors: [],
|
|
20
18
|
plugins: [],
|
|
21
|
-
...
|
|
19
|
+
...opts
|
|
22
20
|
};
|
|
23
21
|
const originStack = router.stack.slice(0, router.stack.length);
|
|
24
22
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -29,14 +27,6 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
29
27
|
if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
|
|
30
28
|
continue;
|
|
31
29
|
debug(`register method "${func}" in module "${tag}"`);
|
|
32
|
-
item.data.guards = [
|
|
33
|
-
...globalGuards,
|
|
34
|
-
...item.data.guards
|
|
35
|
-
];
|
|
36
|
-
item.data.interceptors = [
|
|
37
|
-
...globalInterceptors,
|
|
38
|
-
...item.data.interceptors
|
|
39
|
-
];
|
|
40
30
|
if (metaMap.has(tag))
|
|
41
31
|
metaMap.get(tag)[func] = item;
|
|
42
32
|
else
|
|
@@ -47,26 +37,26 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
47
37
|
}
|
|
48
38
|
_chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
49
39
|
async function createRoute() {
|
|
50
|
-
router.post(route, ...
|
|
40
|
+
router.post(route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins), async (ctx, next) => {
|
|
51
41
|
const { body } = ctx.request;
|
|
52
42
|
async function errorHandler(e) {
|
|
53
|
-
const error = await
|
|
43
|
+
const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
|
|
54
44
|
ctx.status = error.status;
|
|
55
45
|
ctx.body = error;
|
|
56
46
|
}
|
|
57
47
|
_chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
58
48
|
if (!Array.isArray(body))
|
|
59
|
-
return errorHandler(new (0,
|
|
49
|
+
return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
|
|
60
50
|
try {
|
|
61
51
|
return Promise.all(body.map((item, i) => {
|
|
62
52
|
return new Promise(async (resolve) => {
|
|
63
53
|
const { tag, func } = item;
|
|
64
54
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
65
55
|
if (!metaMap.has(tag))
|
|
66
|
-
return resolve(await
|
|
56
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
67
57
|
const meta2 = metaMap.get(tag)[func];
|
|
68
58
|
if (!meta2)
|
|
69
|
-
return resolve(await
|
|
59
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
70
60
|
const { data: { params } } = meta2;
|
|
71
61
|
const contextData = {
|
|
72
62
|
type: "koa",
|
|
@@ -77,12 +67,17 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
77
67
|
parallel: true,
|
|
78
68
|
next,
|
|
79
69
|
app: router,
|
|
80
|
-
...
|
|
70
|
+
..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, ctx.headers),
|
|
81
71
|
tag,
|
|
82
72
|
func
|
|
83
73
|
};
|
|
84
|
-
const context = new (0,
|
|
85
|
-
context.run(
|
|
74
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
75
|
+
context.run({
|
|
76
|
+
globalGuards,
|
|
77
|
+
globalInterceptors,
|
|
78
|
+
globalFilter,
|
|
79
|
+
globalPipe
|
|
80
|
+
}, resolve, resolve);
|
|
86
81
|
});
|
|
87
82
|
})).then((ret) => {
|
|
88
83
|
ctx.body = ret;
|
|
@@ -97,7 +92,7 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
97
92
|
const { data: { plugins: plugins2, http } } = meta2;
|
|
98
93
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
99
94
|
continue;
|
|
100
|
-
router[http.type](http.prefix + http.route, ...
|
|
95
|
+
router[http.type](http.prefix + http.route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins2), async (ctx, next) => {
|
|
101
96
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
102
97
|
const contextData = {
|
|
103
98
|
type: "koa",
|
|
@@ -113,12 +108,17 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
113
108
|
headers: ctx.headers,
|
|
114
109
|
next
|
|
115
110
|
};
|
|
116
|
-
const context = new (0,
|
|
111
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
117
112
|
if (http.headers) {
|
|
118
113
|
for (const name in http.headers)
|
|
119
114
|
ctx.set(name, http.headers[name]);
|
|
120
115
|
}
|
|
121
|
-
await context.run(
|
|
116
|
+
await context.run({
|
|
117
|
+
globalGuards,
|
|
118
|
+
globalInterceptors,
|
|
119
|
+
globalFilter,
|
|
120
|
+
globalPipe
|
|
121
|
+
}, (returnData) => {
|
|
122
122
|
if (ctx.res.writableEnded)
|
|
123
123
|
return;
|
|
124
124
|
ctx.body = returnData;
|
|
@@ -133,16 +133,16 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
_chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
|
|
136
|
-
|
|
136
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
137
137
|
plugins,
|
|
138
138
|
guards: globalGuards,
|
|
139
139
|
interceptors: globalInterceptors
|
|
140
140
|
});
|
|
141
141
|
handleMeta();
|
|
142
142
|
createRoute();
|
|
143
|
-
|
|
143
|
+
_chunkYERBWZCSjs.HMR.call(void 0, async () => {
|
|
144
144
|
router.stack = originStack;
|
|
145
|
-
|
|
145
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
146
146
|
plugins,
|
|
147
147
|
guards: globalGuards,
|
|
148
148
|
interceptors: globalInterceptors
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HMR,
|
|
5
5
|
argToReq,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-AB4OX3WV.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
10
|
} from "../../chunk-ITTD2GBR.mjs";
|
|
@@ -12,13 +12,11 @@ import {
|
|
|
12
12
|
// src/server/koa/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
14
14
|
var debug = Debug("phecda-server/koa");
|
|
15
|
-
function bind(router, { moduleMap, meta },
|
|
16
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
15
|
+
function bind(router, { moduleMap, meta }, opts = {}) {
|
|
16
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
17
17
|
route: "/__PHECDA_SERVER__",
|
|
18
|
-
globalGuards: [],
|
|
19
|
-
globalInterceptors: [],
|
|
20
18
|
plugins: [],
|
|
21
|
-
...
|
|
19
|
+
...opts
|
|
22
20
|
};
|
|
23
21
|
const originStack = router.stack.slice(0, router.stack.length);
|
|
24
22
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -29,14 +27,6 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
29
27
|
if (controller !== "http" || !http?.type)
|
|
30
28
|
continue;
|
|
31
29
|
debug(`register method "${func}" in module "${tag}"`);
|
|
32
|
-
item.data.guards = [
|
|
33
|
-
...globalGuards,
|
|
34
|
-
...item.data.guards
|
|
35
|
-
];
|
|
36
|
-
item.data.interceptors = [
|
|
37
|
-
...globalInterceptors,
|
|
38
|
-
...item.data.interceptors
|
|
39
|
-
];
|
|
40
30
|
if (metaMap.has(tag))
|
|
41
31
|
metaMap.get(tag)[func] = item;
|
|
42
32
|
else
|
|
@@ -82,7 +72,12 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
82
72
|
func
|
|
83
73
|
};
|
|
84
74
|
const context = new Context(contextData);
|
|
85
|
-
context.run(
|
|
75
|
+
context.run({
|
|
76
|
+
globalGuards,
|
|
77
|
+
globalInterceptors,
|
|
78
|
+
globalFilter,
|
|
79
|
+
globalPipe
|
|
80
|
+
}, resolve, resolve);
|
|
86
81
|
});
|
|
87
82
|
})).then((ret) => {
|
|
88
83
|
ctx.body = ret;
|
|
@@ -118,7 +113,12 @@ function bind(router, { moduleMap, meta }, ServerOptions = {}) {
|
|
|
118
113
|
for (const name in http.headers)
|
|
119
114
|
ctx.set(name, http.headers[name]);
|
|
120
115
|
}
|
|
121
|
-
await context.run(
|
|
116
|
+
await context.run({
|
|
117
|
+
globalGuards,
|
|
118
|
+
globalInterceptors,
|
|
119
|
+
globalFilter,
|
|
120
|
+
globalPipe
|
|
121
|
+
}, (returnData) => {
|
|
122
122
|
if (ctx.res.writableEnded)
|
|
123
123
|
return;
|
|
124
124
|
ctx.body = returnData;
|
package/dist/test.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import * as supertest from 'supertest';
|
|
|
2
2
|
import { Test } from 'supertest';
|
|
3
3
|
import { Server } from 'node:http';
|
|
4
4
|
import { Construct } from 'phecda-core';
|
|
5
|
-
import { F as Factory, P as PickFunc } from './core-
|
|
6
|
-
import 'http';
|
|
5
|
+
import { F as Factory, P as PickFunc } from './core-fd134ffa.js';
|
|
7
6
|
|
|
8
7
|
declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
9
8
|
get<C extends T[number]>(Module: C): InstanceType<C>;
|
package/dist/test.js
CHANGED
|
@@ -55,7 +55,14 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
55
55
|
else
|
|
56
56
|
ret[item.type] = args[item.index];
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
let agent2 = (isAgent ? Agent : request(app))[ret.func](ret.url);
|
|
59
|
+
if (Object.keys(ret.query).length > 0)
|
|
60
|
+
agent2 = agent2.query(ret.query);
|
|
61
|
+
if (Object.keys(ret.headers).length > 0)
|
|
62
|
+
agent2 = agent2.set(ret.headers);
|
|
63
|
+
if (Object.keys(ret.body).length > 0)
|
|
64
|
+
agent2 = agent2.send(ret.body);
|
|
65
|
+
return agent2;
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
});
|
package/dist/test.mjs
CHANGED
|
@@ -55,7 +55,14 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
55
55
|
else
|
|
56
56
|
ret[item.type] = args[item.index];
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
let agent2 = (isAgent ? Agent : request(app))[ret.func](ret.url);
|
|
59
|
+
if (Object.keys(ret.query).length > 0)
|
|
60
|
+
agent2 = agent2.query(ret.query);
|
|
61
|
+
if (Object.keys(ret.headers).length > 0)
|
|
62
|
+
agent2 = agent2.set(ret.headers);
|
|
63
|
+
if (Object.keys(ret.body).length > 0)
|
|
64
|
+
agent2 = agent2.send(ret.body);
|
|
65
|
+
return agent2;
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-server",
|
|
3
|
-
"version": "5.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
|
+
"description": "server framework that provide IOC/type-reuse/http&rpc-adaptor ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
package/register/loader.mjs
CHANGED
|
@@ -51,14 +51,18 @@ export async function initialize(data) {
|
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
config = require(configPath)
|
|
54
|
+
if (!config.virtualFile)
|
|
55
|
+
config.virtualFile = {}
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
if (!process.env.PS_HMR_BAN) {
|
|
58
|
+
chokidar.watch(configPath, { persistent: true }).on('change', () => {
|
|
59
|
+
port.postMessage(
|
|
60
|
+
JSON.stringify({
|
|
61
|
+
type: 'relaunch',
|
|
62
|
+
}),
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
}
|
|
62
66
|
|
|
63
67
|
if (!config.unimport)
|
|
64
68
|
return
|
|
@@ -96,6 +100,14 @@ function getFileMid(file) {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
export const resolve = async (specifier, context, nextResolve) => {
|
|
103
|
+
// virtual file
|
|
104
|
+
if (config.virtualFile[specifier]) {
|
|
105
|
+
return {
|
|
106
|
+
format: 'ts',
|
|
107
|
+
url: specifier,
|
|
108
|
+
shortCircuit: true,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
99
111
|
// entrypoint
|
|
100
112
|
if (!context.parentURL) {
|
|
101
113
|
entryUrl = specifier
|
|
@@ -107,6 +119,7 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
107
119
|
shortCircuit: true,
|
|
108
120
|
}
|
|
109
121
|
}
|
|
122
|
+
// url import
|
|
110
123
|
if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
|
|
111
124
|
const url = addUrlToGraph(specifier, context.parentURL.split('?')[0])
|
|
112
125
|
|
|
@@ -116,6 +129,8 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
116
129
|
shortCircuit: true,
|
|
117
130
|
}
|
|
118
131
|
}
|
|
132
|
+
|
|
133
|
+
// hmr import
|
|
119
134
|
if (
|
|
120
135
|
context.parentURL.includes('/node_modules/phecda-server')
|
|
121
136
|
&& isAbsolute(specifier)
|
|
@@ -125,6 +140,7 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
125
140
|
.slice(1)
|
|
126
141
|
context.parentURL = entryUrl
|
|
127
142
|
}
|
|
143
|
+
|
|
128
144
|
// import/require from external library
|
|
129
145
|
if (context.parentURL.includes('/node_modules/'))
|
|
130
146
|
return nextResolve(specifier)
|
|
@@ -167,10 +183,20 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
167
183
|
shortCircuit: true,
|
|
168
184
|
}
|
|
169
185
|
}
|
|
186
|
+
|
|
170
187
|
return nextResolve(specifier)
|
|
171
188
|
}
|
|
189
|
+
// @todo the first params may be url or path, need to distinguish
|
|
172
190
|
|
|
173
191
|
export const load = async (url, context, nextLoad) => {
|
|
192
|
+
if (config.virtualFile[url]) {
|
|
193
|
+
return {
|
|
194
|
+
format: 'module',
|
|
195
|
+
source: config.virtualFile[url],
|
|
196
|
+
shortCircuit: true,
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
174
200
|
url = url.split('?')[0]
|
|
175
201
|
if (
|
|
176
202
|
!url.includes('/node_modules/')
|
|
@@ -244,7 +270,9 @@ export const load = async (url, context, nextLoad) => {
|
|
|
244
270
|
const { injectImports } = unimportRet
|
|
245
271
|
return {
|
|
246
272
|
format: 'module',
|
|
247
|
-
source: (
|
|
273
|
+
source: (
|
|
274
|
+
await injectImports(compiled, (url.startsWith('file://') ? fileURLToPath(url) : url).replace(/\\/g, '/'))
|
|
275
|
+
).code,
|
|
248
276
|
shortCircuit: true,
|
|
249
277
|
}
|
|
250
278
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { C as ControllerMetaData } from './core-eb646fe5.js';
|
|
2
|
-
|
|
3
|
-
declare function resolveDep(ret: any, key: string): any;
|
|
4
|
-
interface ServerOptions {
|
|
5
|
-
route?: string;
|
|
6
|
-
globalGuards?: string[];
|
|
7
|
-
globalInterceptors?: string[];
|
|
8
|
-
plugins?: string[];
|
|
9
|
-
}
|
|
10
|
-
declare function argToReq(params: ControllerMetaData['params'], args: any[], headers: Record<string, any>): any;
|
|
11
|
-
|
|
12
|
-
export { ServerOptions as S, argToReq as a, resolveDep as r };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare function genClientQueue(key?: string): string;
|
|
2
|
-
interface RpcServerOptions {
|
|
3
|
-
globalGuards?: string[];
|
|
4
|
-
globalInterceptors?: string[];
|
|
5
|
-
}
|
|
6
|
-
interface RpcClientOptions {
|
|
7
|
-
key?: string;
|
|
8
|
-
timeout?: number;
|
|
9
|
-
max?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { RpcServerOptions as R, RpcClientOptions as a, genClientQueue as g };
|