phecda-server 6.1.0 → 7.0.0-alpha.1
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 +165 -157
- package/dist/{chunk-NL6QBQAR.js → chunk-7YQ57BQS.js} +21 -22
- package/dist/chunk-GSPBHZBH.js +534 -0
- package/dist/{chunk-J7B24YSE.mjs → chunk-HMVLXNV3.mjs} +5 -14
- package/dist/{chunk-TVT62GIX.js → chunk-J5CFUN4V.js} +8 -1
- package/dist/{chunk-JDV2XJYE.js → chunk-MBCHNDAY.js} +27 -36
- package/dist/{chunk-2CFYUXPM.mjs → chunk-V7EI76QQ.mjs} +136 -141
- package/dist/{chunk-G7TD2VB7.mjs → chunk-WHJ5FALK.mjs} +7 -0
- package/dist/{chunk-3H3T54IC.mjs → chunk-XYVMNY2X.mjs} +4 -5
- package/dist/{core-P1CsH6jz.d.mts → core-BIcUwV18.d.mts} +1 -1
- package/dist/{core-BlN0Spy9.d.ts → core-CYwEPfN4.d.ts} +1 -1
- 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 +52 -41
- package/dist/index.d.ts +52 -41
- package/dist/index.js +59 -81
- package/dist/index.mjs +39 -61
- 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 +23 -23
- package/register/loader.mjs +366 -367
- package/dist/chunk-DVTBLV6I.js +0 -539
- package/dist/server/h3/index.js +0 -154
|
@@ -4,55 +4,61 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkGSPBHZBHjs = require('../../chunk-GSPBHZBH.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
11
11
|
|
|
12
|
-
// src/
|
|
12
|
+
// src/http/hono/bind.ts
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
|
+
var _hono = require('hono');
|
|
14
15
|
var _cookie = require('hono/cookie');
|
|
15
16
|
var debug = _debug2.default.call(void 0, "phecda-server/hono");
|
|
16
17
|
function bind(router, data, opts = {}) {
|
|
17
|
-
const { globalGuards,
|
|
18
|
+
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
18
19
|
const { moduleMap, meta } = data;
|
|
19
|
-
const metaMap =
|
|
20
|
+
const metaMap = _chunkGSPBHZBHjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
20
21
|
const { controller, http, func, tag } = meta2.data;
|
|
21
22
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
22
23
|
debug(`register method "${func}" in module "${tag}"`);
|
|
23
24
|
return true;
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
...
|
|
29
|
-
...
|
|
27
|
+
_chunkGSPBHZBHjs.detectAopDep.call(void 0, meta, {
|
|
28
|
+
addons: [
|
|
29
|
+
...globalAddons,
|
|
30
|
+
...parallelAddons
|
|
30
31
|
],
|
|
31
|
-
guards: globalGuards
|
|
32
|
-
interceptors: globalInterceptors
|
|
32
|
+
guards: globalGuards
|
|
33
33
|
});
|
|
34
34
|
registerRoute();
|
|
35
|
-
|
|
36
|
-
_chunkDVTBLV6Ijs.Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
|
|
35
|
+
function registerRoute() {
|
|
37
36
|
if (parallelRoute) {
|
|
38
|
-
|
|
37
|
+
const subApp = new (0, _hono.Hono)();
|
|
38
|
+
_chunkGSPBHZBHjs.Context.applyAddons(parallelAddons, subApp, "hono");
|
|
39
|
+
subApp.post("", async (c) => {
|
|
39
40
|
const body = await c.req.json();
|
|
40
41
|
async function errorHandler(e) {
|
|
41
|
-
const error = await
|
|
42
|
+
const error = await _chunkGSPBHZBHjs.Context.filterRecord.default(e);
|
|
42
43
|
c.status(error.status);
|
|
43
44
|
return c.json(error);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
46
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
47
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkGSPBHZBHjs.BadRequestException)("data format should be an array"));
|
|
47
48
|
try {
|
|
48
49
|
return Promise.all(body.map((item, i) => {
|
|
49
50
|
return new Promise(async (resolve) => {
|
|
50
51
|
const { tag, func } = item;
|
|
51
52
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
52
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
53
|
+
if (!metaMap.has(tag)) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
53
54
|
const meta2 = metaMap.get(tag)[func];
|
|
54
|
-
if (!meta2) return resolve(await
|
|
55
|
+
if (!meta2) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
55
56
|
const { data: { params } } = meta2;
|
|
57
|
+
const aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
|
|
58
|
+
globalFilter,
|
|
59
|
+
globalGuards,
|
|
60
|
+
globalPipe
|
|
61
|
+
});
|
|
56
62
|
const contextData = {
|
|
57
63
|
type: "hono",
|
|
58
64
|
parallel: true,
|
|
@@ -63,25 +69,20 @@ function bind(router, data, opts = {}) {
|
|
|
63
69
|
tag,
|
|
64
70
|
func,
|
|
65
71
|
app: router,
|
|
66
|
-
...
|
|
67
|
-
getCookie: /* @__PURE__ */
|
|
68
|
-
delCookie: /* @__PURE__ */
|
|
69
|
-
setCookie: /* @__PURE__ */
|
|
70
|
-
redirect: /* @__PURE__ */
|
|
71
|
-
setResHeaders: /* @__PURE__ */
|
|
72
|
+
..._chunkGSPBHZBHjs.argToReq.call(void 0, params, item.args, c.req.header()),
|
|
73
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
|
|
74
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
|
|
75
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
|
|
76
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
77
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => {
|
|
72
78
|
for (const name in headers) c.header(name, headers[name]);
|
|
73
79
|
}, "setResHeaders"),
|
|
74
|
-
setResStatus: /* @__PURE__ */
|
|
75
|
-
getRequest: /* @__PURE__ */
|
|
76
|
-
getResponse: /* @__PURE__ */
|
|
80
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
|
|
81
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.req.raw, "getRequest"),
|
|
82
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.res, "getResponse")
|
|
77
83
|
};
|
|
78
|
-
const context = new (0,
|
|
79
|
-
context.run(
|
|
80
|
-
globalGuards,
|
|
81
|
-
globalInterceptors,
|
|
82
|
-
globalFilter,
|
|
83
|
-
globalPipe
|
|
84
|
-
}, resolve, resolve);
|
|
84
|
+
const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
|
|
85
|
+
context.run(aop, resolve, resolve);
|
|
85
86
|
});
|
|
86
87
|
})).then((ret) => {
|
|
87
88
|
return c.json(ret);
|
|
@@ -90,14 +91,25 @@ function bind(router, data, opts = {}) {
|
|
|
90
91
|
return errorHandler(e);
|
|
91
92
|
}
|
|
92
93
|
});
|
|
94
|
+
router.route(parallelRoute, subApp);
|
|
93
95
|
}
|
|
94
96
|
for (const [tag, record] of metaMap) {
|
|
95
97
|
for (const func in record) {
|
|
96
98
|
const meta2 = metaMap.get(tag)[func];
|
|
97
|
-
const { data: { params,
|
|
99
|
+
const { data: { params, addons, http } } = meta2;
|
|
98
100
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
99
101
|
const needBody = params.some((item) => item.type === "body");
|
|
100
|
-
|
|
102
|
+
let aop;
|
|
103
|
+
if (!dynamic) {
|
|
104
|
+
aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
|
|
105
|
+
globalFilter,
|
|
106
|
+
globalGuards,
|
|
107
|
+
globalPipe
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const subApp = new (0, _hono.Hono)();
|
|
111
|
+
_chunkGSPBHZBHjs.Context.applyAddons(addons, subApp, "hono");
|
|
112
|
+
subApp[http.type](http.route, async (c) => {
|
|
101
113
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
102
114
|
const contextData = {
|
|
103
115
|
type: "hono",
|
|
@@ -111,27 +123,29 @@ function bind(router, data, opts = {}) {
|
|
|
111
123
|
params: c.req.param(),
|
|
112
124
|
headers: c.req.header(),
|
|
113
125
|
app: router,
|
|
114
|
-
getCookie: /* @__PURE__ */
|
|
115
|
-
delCookie: /* @__PURE__ */
|
|
116
|
-
setCookie: /* @__PURE__ */
|
|
117
|
-
redirect: /* @__PURE__ */
|
|
118
|
-
setResHeaders: /* @__PURE__ */
|
|
126
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
|
|
127
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
|
|
128
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
|
|
129
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
130
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => {
|
|
119
131
|
for (const name in headers) c.header(name, headers[name]);
|
|
120
132
|
}, "setResHeaders"),
|
|
121
|
-
setResStatus: /* @__PURE__ */
|
|
122
|
-
getRequest: /* @__PURE__ */
|
|
123
|
-
getResponse: /* @__PURE__ */
|
|
133
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
|
|
134
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.req.raw, "getRequest"),
|
|
135
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.res, "getResponse")
|
|
124
136
|
};
|
|
125
|
-
const context = new (0,
|
|
137
|
+
const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
|
|
126
138
|
if (http.headers) {
|
|
127
139
|
for (const name in http.headers) c.header(name, http.headers[name]);
|
|
128
140
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
if (dynamic) {
|
|
142
|
+
aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
|
|
143
|
+
globalFilter,
|
|
144
|
+
globalGuards,
|
|
145
|
+
globalPipe
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return context.run(aop, (returnData) => {
|
|
135
149
|
if (returnData instanceof Response) return returnData;
|
|
136
150
|
if (typeof returnData === "string") return c.text(returnData);
|
|
137
151
|
else return c.json(returnData);
|
|
@@ -140,12 +154,13 @@ function bind(router, data, opts = {}) {
|
|
|
140
154
|
return c.json(err);
|
|
141
155
|
});
|
|
142
156
|
});
|
|
157
|
+
router.route(http.prefix, subApp);
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
160
|
}
|
|
146
|
-
|
|
161
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
147
162
|
}
|
|
148
|
-
|
|
163
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
|
|
149
164
|
|
|
150
165
|
|
|
151
166
|
exports.bind = bind;
|
|
@@ -4,17 +4,18 @@ import {
|
|
|
4
4
|
argToReq,
|
|
5
5
|
createControllerMetaMap,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-V7EI76QQ.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
11
11
|
|
|
12
|
-
// src/
|
|
12
|
+
// src/http/hono/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
14
|
+
import { Hono } from "hono";
|
|
14
15
|
import { deleteCookie, getCookie, setCookie } from "hono/cookie";
|
|
15
16
|
var debug = Debug("phecda-server/hono");
|
|
16
17
|
function bind(router, data, opts = {}) {
|
|
17
|
-
const { globalGuards,
|
|
18
|
+
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
18
19
|
const { moduleMap, meta } = data;
|
|
19
20
|
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
20
21
|
const { controller, http, func, tag } = meta2.data;
|
|
@@ -24,18 +25,18 @@ function bind(router, data, opts = {}) {
|
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
detectAopDep(meta, {
|
|
27
|
-
|
|
28
|
-
...
|
|
29
|
-
...
|
|
28
|
+
addons: [
|
|
29
|
+
...globalAddons,
|
|
30
|
+
...parallelAddons
|
|
30
31
|
],
|
|
31
|
-
guards: globalGuards
|
|
32
|
-
interceptors: globalInterceptors
|
|
32
|
+
guards: globalGuards
|
|
33
33
|
});
|
|
34
34
|
registerRoute();
|
|
35
|
-
|
|
36
|
-
Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
|
|
35
|
+
function registerRoute() {
|
|
37
36
|
if (parallelRoute) {
|
|
38
|
-
|
|
37
|
+
const subApp = new Hono();
|
|
38
|
+
Context.applyAddons(parallelAddons, subApp, "hono");
|
|
39
|
+
subApp.post("", async (c) => {
|
|
39
40
|
const body = await c.req.json();
|
|
40
41
|
async function errorHandler(e) {
|
|
41
42
|
const error = await Context.filterRecord.default(e);
|
|
@@ -53,6 +54,11 @@ function bind(router, data, opts = {}) {
|
|
|
53
54
|
const meta2 = metaMap.get(tag)[func];
|
|
54
55
|
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
55
56
|
const { data: { params } } = meta2;
|
|
57
|
+
const aop = Context.getAop(meta2, {
|
|
58
|
+
globalFilter,
|
|
59
|
+
globalGuards,
|
|
60
|
+
globalPipe
|
|
61
|
+
});
|
|
56
62
|
const contextData = {
|
|
57
63
|
type: "hono",
|
|
58
64
|
parallel: true,
|
|
@@ -76,12 +82,7 @@ function bind(router, data, opts = {}) {
|
|
|
76
82
|
getResponse: /* @__PURE__ */ __name(() => c.res, "getResponse")
|
|
77
83
|
};
|
|
78
84
|
const context = new Context(contextData);
|
|
79
|
-
context.run(
|
|
80
|
-
globalGuards,
|
|
81
|
-
globalInterceptors,
|
|
82
|
-
globalFilter,
|
|
83
|
-
globalPipe
|
|
84
|
-
}, resolve, resolve);
|
|
85
|
+
context.run(aop, resolve, resolve);
|
|
85
86
|
});
|
|
86
87
|
})).then((ret) => {
|
|
87
88
|
return c.json(ret);
|
|
@@ -90,14 +91,25 @@ function bind(router, data, opts = {}) {
|
|
|
90
91
|
return errorHandler(e);
|
|
91
92
|
}
|
|
92
93
|
});
|
|
94
|
+
router.route(parallelRoute, subApp);
|
|
93
95
|
}
|
|
94
96
|
for (const [tag, record] of metaMap) {
|
|
95
97
|
for (const func in record) {
|
|
96
98
|
const meta2 = metaMap.get(tag)[func];
|
|
97
|
-
const { data: { params,
|
|
99
|
+
const { data: { params, addons, http } } = meta2;
|
|
98
100
|
if (!http?.type) continue;
|
|
99
101
|
const needBody = params.some((item) => item.type === "body");
|
|
100
|
-
|
|
102
|
+
let aop;
|
|
103
|
+
if (!dynamic) {
|
|
104
|
+
aop = Context.getAop(meta2, {
|
|
105
|
+
globalFilter,
|
|
106
|
+
globalGuards,
|
|
107
|
+
globalPipe
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const subApp = new Hono();
|
|
111
|
+
Context.applyAddons(addons, subApp, "hono");
|
|
112
|
+
subApp[http.type](http.route, async (c) => {
|
|
101
113
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
102
114
|
const contextData = {
|
|
103
115
|
type: "hono",
|
|
@@ -126,12 +138,14 @@ function bind(router, data, opts = {}) {
|
|
|
126
138
|
if (http.headers) {
|
|
127
139
|
for (const name in http.headers) c.header(name, http.headers[name]);
|
|
128
140
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
if (dynamic) {
|
|
142
|
+
aop = Context.getAop(meta2, {
|
|
143
|
+
globalFilter,
|
|
144
|
+
globalGuards,
|
|
145
|
+
globalPipe
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return context.run(aop, (returnData) => {
|
|
135
149
|
if (returnData instanceof Response) return returnData;
|
|
136
150
|
if (typeof returnData === "string") return c.text(returnData);
|
|
137
151
|
else return c.json(returnData);
|
|
@@ -140,6 +154,7 @@ function bind(router, data, opts = {}) {
|
|
|
140
154
|
return c.json(err);
|
|
141
155
|
});
|
|
142
156
|
});
|
|
157
|
+
router.route(http.prefix, subApp);
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
160
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, MiddlewareHandler } from 'hyper-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-h40T3cRG.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BIcUwV18.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-BXKLFTgG.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface HyperExpressCtx extends HttpContext {
|
|
@@ -12,7 +12,7 @@ interface HyperExpressCtx extends HttpContext {
|
|
|
12
12
|
next: Function;
|
|
13
13
|
app: Router;
|
|
14
14
|
}
|
|
15
|
-
type
|
|
15
|
+
type Addon = MiddlewareHandler;
|
|
16
16
|
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
17
17
|
|
|
18
|
-
export { type
|
|
18
|
+
export { type Addon, type HyperExpressCtx, bind };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, MiddlewareHandler } from 'hyper-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-VFzEM7LL.js';
|
|
3
|
+
import { F as Factory } from '../../core-CYwEPfN4.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-BXKLFTgG.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface HyperExpressCtx extends HttpContext {
|
|
@@ -12,7 +12,7 @@ interface HyperExpressCtx extends HttpContext {
|
|
|
12
12
|
next: Function;
|
|
13
13
|
app: Router;
|
|
14
14
|
}
|
|
15
|
-
type
|
|
15
|
+
type Addon = MiddlewareHandler;
|
|
16
16
|
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
17
17
|
|
|
18
|
-
export { type
|
|
18
|
+
export { type Addon, type HyperExpressCtx, bind };
|
|
@@ -4,55 +4,59 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkGSPBHZBHjs = require('../../chunk-GSPBHZBH.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
11
11
|
|
|
12
|
-
// src/
|
|
12
|
+
// src/http/hyper-express/bind.ts
|
|
13
|
+
var _hyperexpress = require('hyper-express');
|
|
13
14
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
15
|
var debug = _debug2.default.call(void 0, "phecda-server/hyper-express");
|
|
15
16
|
function bind(router, data, opts = {}) {
|
|
16
|
-
const { globalGuards,
|
|
17
|
+
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
17
18
|
const { moduleMap, meta } = data;
|
|
18
|
-
const metaMap =
|
|
19
|
+
const metaMap = _chunkGSPBHZBHjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
19
20
|
const { controller, http, func, tag } = meta2.data;
|
|
20
21
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
21
22
|
debug(`register method "${func}" in module "${tag}"`);
|
|
22
23
|
return true;
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...
|
|
28
|
-
...
|
|
26
|
+
_chunkGSPBHZBHjs.detectAopDep.call(void 0, meta, {
|
|
27
|
+
addons: [
|
|
28
|
+
...globalAddons,
|
|
29
|
+
...parallelAddons
|
|
29
30
|
],
|
|
30
|
-
guards: globalGuards
|
|
31
|
-
interceptors: globalInterceptors
|
|
31
|
+
guards: globalGuards
|
|
32
32
|
});
|
|
33
33
|
registerRoute();
|
|
34
34
|
async function registerRoute() {
|
|
35
|
-
|
|
35
|
+
_chunkGSPBHZBHjs.Context.applyAddons(globalAddons, router, "hyper-express");
|
|
36
36
|
if (parallelRoute) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, async (req, res, next) => {
|
|
37
|
+
const subRouter = new (0, _hyperexpress.Router)();
|
|
38
|
+
subRouter.post(parallelRoute, async (req, res, next) => {
|
|
40
39
|
const body = await req.json();
|
|
41
40
|
async function errorHandler(e) {
|
|
42
|
-
const error = await
|
|
41
|
+
const error = await _chunkGSPBHZBHjs.Context.filterRecord.default(e);
|
|
43
42
|
return res.status(error.status).json(error);
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
44
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
45
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkGSPBHZBHjs.BadRequestException)("data format should be an array"));
|
|
47
46
|
try {
|
|
48
47
|
return Promise.all(body.map((item, i) => {
|
|
49
48
|
return new Promise(async (resolve) => {
|
|
50
49
|
const { tag, func } = item;
|
|
51
50
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
52
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
51
|
+
if (!metaMap.has(tag)) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
53
52
|
const meta2 = metaMap.get(tag)[func];
|
|
54
|
-
if (!meta2) return resolve(await
|
|
53
|
+
if (!meta2) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
55
54
|
const { data: { params } } = meta2;
|
|
55
|
+
const aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
|
|
56
|
+
globalFilter,
|
|
57
|
+
globalGuards,
|
|
58
|
+
globalPipe
|
|
59
|
+
});
|
|
56
60
|
const contextData = {
|
|
57
61
|
type: "hyper-express",
|
|
58
62
|
parallel: true,
|
|
@@ -63,25 +67,20 @@ function bind(router, data, opts = {}) {
|
|
|
63
67
|
moduleMap,
|
|
64
68
|
tag,
|
|
65
69
|
func,
|
|
66
|
-
next,
|
|
67
70
|
app: router,
|
|
68
|
-
...
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
..._chunkGSPBHZBHjs.argToReq.call(void 0, params, item.args, req.headers),
|
|
72
|
+
next,
|
|
73
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
|
|
74
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, _optionalChain([opts2, 'optionalAccess', _2 => _2.expires]) && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
|
|
75
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
|
|
76
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
|
|
77
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
|
|
78
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
|
|
79
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
|
|
80
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
|
|
77
81
|
};
|
|
78
|
-
const context = new (0,
|
|
79
|
-
context.run(
|
|
80
|
-
globalGuards,
|
|
81
|
-
globalInterceptors,
|
|
82
|
-
globalFilter,
|
|
83
|
-
globalPipe
|
|
84
|
-
}, resolve, resolve);
|
|
82
|
+
const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
|
|
83
|
+
context.run(aop, resolve, resolve);
|
|
85
84
|
});
|
|
86
85
|
})).then((ret) => {
|
|
87
86
|
res.json(ret);
|
|
@@ -90,14 +89,25 @@ function bind(router, data, opts = {}) {
|
|
|
90
89
|
return errorHandler(e);
|
|
91
90
|
}
|
|
92
91
|
});
|
|
92
|
+
router.use(subRouter);
|
|
93
93
|
}
|
|
94
94
|
for (const [tag, record] of metaMap) {
|
|
95
95
|
for (const func in record) {
|
|
96
96
|
const meta2 = metaMap.get(tag)[func];
|
|
97
|
-
const { data: { params,
|
|
97
|
+
const { data: { params, addons, http } } = meta2;
|
|
98
98
|
if (!_optionalChain([http, 'optionalAccess', _3 => _3.type])) continue;
|
|
99
99
|
const needBody = params.some((item) => item.type === "body");
|
|
100
|
-
|
|
100
|
+
let aop;
|
|
101
|
+
if (!dynamic) {
|
|
102
|
+
aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
|
|
103
|
+
globalFilter,
|
|
104
|
+
globalGuards,
|
|
105
|
+
globalPipe
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const subRouter = new (0, _hyperexpress.Router)();
|
|
109
|
+
_chunkGSPBHZBHjs.Context.applyAddons(addons, subRouter, "hyper-express");
|
|
110
|
+
subRouter[http.type](http.prefix + http.route, async (req, res, next) => {
|
|
101
111
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
102
112
|
const contextData = {
|
|
103
113
|
type: "hyper-express",
|
|
@@ -113,25 +123,27 @@ function bind(router, data, opts = {}) {
|
|
|
113
123
|
params: req.path_parameters,
|
|
114
124
|
headers: req.headers,
|
|
115
125
|
next,
|
|
116
|
-
getCookie: /* @__PURE__ */
|
|
117
|
-
setCookie: /* @__PURE__ */
|
|
118
|
-
delCookie: /* @__PURE__ */
|
|
119
|
-
redirect: /* @__PURE__ */
|
|
120
|
-
setResHeaders: /* @__PURE__ */
|
|
121
|
-
setResStatus: /* @__PURE__ */
|
|
122
|
-
getRequest: /* @__PURE__ */
|
|
123
|
-
getResponse: /* @__PURE__ */
|
|
126
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
|
|
127
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, _optionalChain([opts2, 'optionalAccess', _4 => _4.expires]) && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
|
|
128
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
|
|
129
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
|
|
130
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
|
|
131
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
|
|
132
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
|
|
133
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
|
|
124
134
|
};
|
|
125
|
-
const context = new (0,
|
|
135
|
+
const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
|
|
126
136
|
if (http.headers) {
|
|
127
137
|
for (const name in http.headers) res.set(name, http.headers[name]);
|
|
128
138
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
if (dynamic) {
|
|
140
|
+
aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
|
|
141
|
+
globalFilter,
|
|
142
|
+
globalGuards,
|
|
143
|
+
globalPipe
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
await context.run(aop, (returnData) => {
|
|
135
147
|
if (res.writableEnded) return;
|
|
136
148
|
if (typeof returnData === "string") res.send(returnData);
|
|
137
149
|
else res.json(returnData);
|
|
@@ -140,12 +152,13 @@ function bind(router, data, opts = {}) {
|
|
|
140
152
|
res.status(err.status).json(err);
|
|
141
153
|
});
|
|
142
154
|
});
|
|
155
|
+
router.use(subRouter);
|
|
143
156
|
}
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
|
-
|
|
159
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
147
160
|
}
|
|
148
|
-
|
|
161
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
|
|
149
162
|
|
|
150
163
|
|
|
151
164
|
exports.bind = bind;
|