phecda-server 5.2.3 → 5.2.5
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/dist/{chunk-VYDBNZJ2.mjs → chunk-2NTXVYQC.mjs} +1 -8
- package/dist/{chunk-Q4AGVGVA.mjs → chunk-2O6X54P5.mjs} +103 -105
- package/dist/{chunk-AWY6FTH4.js → chunk-6QLTBEXP.js} +70 -86
- package/dist/{chunk-H6NYBVBV.js → chunk-6T4UZ4LV.js} +130 -132
- package/dist/{chunk-FNJWO324.js → chunk-H2FWLKXN.js} +2 -9
- package/dist/{chunk-IJNA24EZ.mjs → chunk-JJJ7AUEF.mjs} +39 -55
- package/dist/{chunk-YAVIRFUE.mjs → chunk-MGADYFW4.mjs} +28 -49
- package/dist/{chunk-J5SL4QLN.js → chunk-MKZOLLJS.js} +39 -60
- package/dist/core-BIm7dkko.d.mts +27 -0
- package/dist/{core-7f6d2be6.d.ts → core-C3cON4Um.d.ts} +1 -1
- package/dist/helper.d.mts +27 -0
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/index.d.mts +246 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +73 -64
- package/dist/index.mjs +48 -39
- package/dist/rpc/bullmq/index.d.mts +21 -0
- package/dist/rpc/bullmq/index.d.ts +4 -4
- package/dist/rpc/bullmq/index.js +30 -43
- package/dist/rpc/bullmq/index.mjs +20 -33
- package/dist/rpc/kafka/index.d.mts +24 -0
- package/dist/rpc/kafka/index.d.ts +4 -4
- package/dist/rpc/kafka/index.js +25 -34
- package/dist/rpc/kafka/index.mjs +17 -26
- package/dist/rpc/nats/index.d.mts +15 -0
- package/dist/rpc/nats/index.d.ts +4 -4
- package/dist/rpc/nats/index.js +33 -46
- package/dist/rpc/nats/index.mjs +24 -37
- package/dist/rpc/rabbitmq/index.d.mts +16 -0
- package/dist/rpc/rabbitmq/index.d.ts +4 -4
- package/dist/rpc/rabbitmq/index.js +34 -46
- package/dist/rpc/rabbitmq/index.mjs +23 -35
- package/dist/rpc/redis/index.d.mts +23 -0
- package/dist/rpc/redis/index.d.ts +4 -4
- package/dist/rpc/redis/index.js +27 -38
- package/dist/rpc/redis/index.mjs +18 -29
- package/dist/server/elysia/index.d.mts +18 -0
- package/dist/server/elysia/index.d.ts +4 -4
- package/dist/server/elysia/index.js +22 -27
- package/dist/server/elysia/index.mjs +8 -13
- package/dist/server/express/index.d.mts +18 -0
- package/dist/server/express/index.d.ts +4 -4
- package/dist/server/express/index.js +24 -33
- package/dist/server/express/index.mjs +11 -20
- package/dist/server/fastify/index.d.mts +20 -0
- package/dist/server/fastify/index.d.ts +4 -4
- package/dist/server/fastify/index.js +23 -30
- package/dist/server/fastify/index.mjs +10 -17
- package/dist/server/h3/index.d.mts +16 -0
- package/dist/server/h3/index.d.ts +4 -4
- package/dist/server/h3/index.js +21 -25
- package/dist/server/h3/index.mjs +10 -14
- package/dist/server/hono/index.d.mts +16 -0
- package/dist/server/hono/index.d.ts +4 -4
- package/dist/server/hono/index.js +22 -30
- package/dist/server/hono/index.mjs +10 -18
- package/dist/server/hyper-express/index.d.mts +18 -0
- package/dist/server/hyper-express/index.d.ts +4 -4
- package/dist/server/hyper-express/index.js +23 -32
- package/dist/server/hyper-express/index.mjs +11 -20
- package/dist/server/koa/index.d.mts +18 -0
- package/dist/server/koa/index.d.ts +4 -4
- package/dist/server/koa/index.js +22 -29
- package/dist/server/koa/index.mjs +9 -16
- package/dist/test.d.mts +18 -0
- package/dist/test.d.ts +3 -3
- package/dist/test.js +14 -22
- package/dist/test.mjs +10 -18
- package/dist/types-B-y2TwhC.d.mts +17 -0
- package/dist/types-ByP1fKMe.d.mts +27 -0
- package/dist/{types-68f2ec2a.d.ts → types-C5sdDiDQ.d.ts} +11 -2
- package/dist/{types-f3b79218.d.ts → types-CIZbw8S2.d.ts} +2 -2
- package/dist/{types-81be0ba3.d.ts → types-CdQey96H.d.mts} +1 -1
- package/dist/types-CdQey96H.d.ts +108 -0
- package/package.json +3 -3
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Define
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-JJJ7AUEF.mjs";
|
|
4
4
|
import {
|
|
5
5
|
BadRequestException,
|
|
6
6
|
Context,
|
|
7
7
|
argToReq,
|
|
8
8
|
createControllerMetaMap,
|
|
9
9
|
detectAopDep
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-2O6X54P5.mjs";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-2NTXVYQC.mjs";
|
|
14
14
|
|
|
15
15
|
// src/server/fastify/bind.ts
|
|
16
16
|
import Debug from "debug";
|
|
@@ -51,18 +51,15 @@ function bind(fastify, data, opts = {}) {
|
|
|
51
51
|
return res.status(error.status).send(error);
|
|
52
52
|
}
|
|
53
53
|
__name(errorHandler, "errorHandler");
|
|
54
|
-
if (!Array.isArray(body))
|
|
55
|
-
return errorHandler(new BadRequestException("data format should be an array"));
|
|
54
|
+
if (!Array.isArray(body)) return errorHandler(new BadRequestException("data format should be an array"));
|
|
56
55
|
try {
|
|
57
56
|
return Promise.all(body.map((item, i) => {
|
|
58
57
|
return new Promise(async (resolve) => {
|
|
59
58
|
const { tag, func } = item;
|
|
60
59
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
61
|
-
if (!metaMap.has(tag))
|
|
62
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
60
|
+
if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
63
61
|
const meta2 = metaMap.get(tag)[func];
|
|
64
|
-
if (!meta2)
|
|
65
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
62
|
+
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
66
63
|
const { data: { params } } = meta2;
|
|
67
64
|
const contextData = {
|
|
68
65
|
type: "fastify",
|
|
@@ -99,8 +96,7 @@ function bind(fastify, data, opts = {}) {
|
|
|
99
96
|
for (const func in record) {
|
|
100
97
|
const meta2 = metaMap.get(tag)[func];
|
|
101
98
|
const { data: { plugins, define, http } } = meta2;
|
|
102
|
-
if (!http?.type)
|
|
103
|
-
continue;
|
|
99
|
+
if (!http?.type) continue;
|
|
104
100
|
fastify2.register((fastify3, _opts, done2) => {
|
|
105
101
|
Context.usePlugin(plugins, "fastify").forEach((p) => {
|
|
106
102
|
p[Symbol.for("skip-override")] = true;
|
|
@@ -124,8 +120,7 @@ function bind(fastify, data, opts = {}) {
|
|
|
124
120
|
};
|
|
125
121
|
const context = new Context(contextData);
|
|
126
122
|
if (http.headers) {
|
|
127
|
-
for (const name in http.headers)
|
|
128
|
-
res.header(name, http.headers[name]);
|
|
123
|
+
for (const name in http.headers) res.header(name, http.headers[name]);
|
|
129
124
|
}
|
|
130
125
|
return context.run({
|
|
131
126
|
globalGuards,
|
|
@@ -133,12 +128,10 @@ function bind(fastify, data, opts = {}) {
|
|
|
133
128
|
globalFilter,
|
|
134
129
|
globalPipe
|
|
135
130
|
}, (returnData) => {
|
|
136
|
-
if (res.sent)
|
|
137
|
-
return;
|
|
131
|
+
if (res.sent) return;
|
|
138
132
|
return returnData;
|
|
139
133
|
}, (err) => {
|
|
140
|
-
if (res.sent)
|
|
141
|
-
return;
|
|
134
|
+
if (res.sent) return;
|
|
142
135
|
res.status(err.status).send(err);
|
|
143
136
|
});
|
|
144
137
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { H3Event, Router, _RequestMiddleware } from 'h3';
|
|
2
|
+
import { F as Factory } from '../../core-BIm7dkko.mjs';
|
|
3
|
+
import { a as HttpContext, H as HttpOptions } from '../../types-ByP1fKMe.mjs';
|
|
4
|
+
import 'phecda-core';
|
|
5
|
+
import '../../types-CdQey96H.mjs';
|
|
6
|
+
import 'node:http';
|
|
7
|
+
|
|
8
|
+
interface H3Ctx extends HttpContext {
|
|
9
|
+
type: 'h3';
|
|
10
|
+
event: H3Event;
|
|
11
|
+
app: Router;
|
|
12
|
+
}
|
|
13
|
+
type Plugin = _RequestMiddleware;
|
|
14
|
+
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
15
|
+
|
|
16
|
+
export { type H3Ctx, type Plugin, bind };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { H3Event, Router, _RequestMiddleware } from 'h3';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { a as HttpContext, H as HttpOptions } from '../../types-
|
|
2
|
+
import { F as Factory } from '../../core-C3cON4Um.js';
|
|
3
|
+
import { a as HttpContext, H as HttpOptions } from '../../types-C5sdDiDQ.js';
|
|
4
4
|
import 'phecda-core';
|
|
5
|
-
import '../../types-
|
|
5
|
+
import '../../types-CdQey96H.js';
|
|
6
6
|
import 'node:http';
|
|
7
7
|
|
|
8
8
|
interface H3Ctx extends HttpContext {
|
|
@@ -13,4 +13,4 @@ interface H3Ctx extends HttpContext {
|
|
|
13
13
|
type Plugin = _RequestMiddleware;
|
|
14
14
|
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
15
15
|
|
|
16
|
-
export { H3Ctx, Plugin, bind };
|
|
16
|
+
export { type H3Ctx, type Plugin, bind };
|
package/dist/server/h3/index.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk6T4UZ4LVjs = require('../../chunk-6T4UZ4LV.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkH2FWLKXNjs = require('../../chunk-H2FWLKXN.js');
|
|
11
11
|
|
|
12
12
|
// src/server/h3/bind.ts
|
|
13
13
|
var _h3 = require('h3');
|
|
@@ -16,14 +16,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/h3");
|
|
|
16
16
|
function bind(router, data, opts = {}) {
|
|
17
17
|
const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
|
|
18
18
|
const { moduleMap, meta } = data;
|
|
19
|
-
const metaMap =
|
|
19
|
+
const metaMap = _chunk6T4UZ4LVjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
20
20
|
const { controller, http, func, tag } = meta2.data;
|
|
21
21
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
22
22
|
debug(`register method "${func}" in module "${tag}"`);
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
_chunk6T4UZ4LVjs.detectAopDep.call(void 0, meta, {
|
|
27
27
|
plugins: [
|
|
28
28
|
...globalPlugins,
|
|
29
29
|
...parallelPlugins
|
|
@@ -35,32 +35,29 @@ function bind(router, data, opts = {}) {
|
|
|
35
35
|
async function registerRoute() {
|
|
36
36
|
if (parallelRoute) {
|
|
37
37
|
router.post(parallelRoute, _h3.eventHandler.call(void 0, {
|
|
38
|
-
onRequest:
|
|
38
|
+
onRequest: _chunk6T4UZ4LVjs.Context.usePlugin([
|
|
39
39
|
...globalPlugins,
|
|
40
40
|
...parallelPlugins
|
|
41
41
|
], "h3").map(_h3.defineRequestMiddleware),
|
|
42
|
-
handler: async (event) => {
|
|
42
|
+
handler: /* @__PURE__ */ _chunkH2FWLKXNjs.__name.call(void 0, async (event) => {
|
|
43
43
|
const body = await _h3.readBody.call(void 0, event, {
|
|
44
44
|
strict: true
|
|
45
45
|
});
|
|
46
46
|
async function errorHandler(e) {
|
|
47
|
-
const error = await
|
|
47
|
+
const error = await _chunk6T4UZ4LVjs.Context.filterRecord.default(e);
|
|
48
48
|
_h3.setResponseStatus.call(void 0, event, error.status);
|
|
49
49
|
return error;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
if (!Array.isArray(body))
|
|
53
|
-
return errorHandler(new (0, _chunkH6NYBVBVjs.BadRequestException)("data format should be an array"));
|
|
51
|
+
_chunkH2FWLKXNjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
52
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunk6T4UZ4LVjs.BadRequestException)("data format should be an array"));
|
|
54
53
|
try {
|
|
55
54
|
return Promise.all(body.map((item, i) => {
|
|
56
55
|
return new Promise(async (resolve) => {
|
|
57
56
|
const { tag, func } = item;
|
|
58
57
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
59
|
-
if (!metaMap.has(tag))
|
|
60
|
-
return resolve(await _chunkH6NYBVBVjs.Context.filterRecord.default(new (0, _chunkH6NYBVBVjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
58
|
+
if (!metaMap.has(tag)) return resolve(await _chunk6T4UZ4LVjs.Context.filterRecord.default(new (0, _chunk6T4UZ4LVjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
61
59
|
const meta2 = metaMap.get(tag)[func];
|
|
62
|
-
if (!meta2)
|
|
63
|
-
return resolve(await _chunkH6NYBVBVjs.Context.filterRecord.default(new (0, _chunkH6NYBVBVjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
60
|
+
if (!meta2) return resolve(await _chunk6T4UZ4LVjs.Context.filterRecord.default(new (0, _chunk6T4UZ4LVjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
64
61
|
const { data: { params } } = meta2;
|
|
65
62
|
const contextData = {
|
|
66
63
|
type: "h3",
|
|
@@ -72,9 +69,9 @@ function bind(router, data, opts = {}) {
|
|
|
72
69
|
func,
|
|
73
70
|
parallel: true,
|
|
74
71
|
app: router,
|
|
75
|
-
...
|
|
72
|
+
..._chunk6T4UZ4LVjs.argToReq.call(void 0, params, item.args, _h3.getRequestHeaders.call(void 0, event))
|
|
76
73
|
};
|
|
77
|
-
const context = new (0,
|
|
74
|
+
const context = new (0, _chunk6T4UZ4LVjs.Context)(contextData);
|
|
78
75
|
context.run({
|
|
79
76
|
globalGuards,
|
|
80
77
|
globalInterceptors,
|
|
@@ -86,22 +83,21 @@ function bind(router, data, opts = {}) {
|
|
|
86
83
|
} catch (e) {
|
|
87
84
|
return errorHandler(e);
|
|
88
85
|
}
|
|
89
|
-
}
|
|
86
|
+
}, "handler")
|
|
90
87
|
}));
|
|
91
88
|
}
|
|
92
89
|
for (const [tag, record] of metaMap) {
|
|
93
90
|
for (const func in record) {
|
|
94
91
|
const meta2 = metaMap.get(tag)[func];
|
|
95
92
|
const { data: { http, params, plugins } } = meta2;
|
|
96
|
-
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
97
|
-
continue;
|
|
93
|
+
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
98
94
|
const needBody = params.some((item) => item.type === "body");
|
|
99
95
|
router[http.type](http.prefix + http.route, _h3.eventHandler.call(void 0, {
|
|
100
|
-
onRequest:
|
|
96
|
+
onRequest: _chunk6T4UZ4LVjs.Context.usePlugin([
|
|
101
97
|
...globalPlugins,
|
|
102
98
|
...plugins
|
|
103
99
|
], "h3").map(_h3.defineRequestMiddleware),
|
|
104
|
-
handler: async (event) => {
|
|
100
|
+
handler: /* @__PURE__ */ _chunkH2FWLKXNjs.__name.call(void 0, async (event) => {
|
|
105
101
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
106
102
|
const contextData = {
|
|
107
103
|
type: "h3",
|
|
@@ -118,7 +114,7 @@ function bind(router, data, opts = {}) {
|
|
|
118
114
|
strict: true
|
|
119
115
|
}) : void 0
|
|
120
116
|
};
|
|
121
|
-
const context = new (0,
|
|
117
|
+
const context = new (0, _chunk6T4UZ4LVjs.Context)(contextData);
|
|
122
118
|
_h3.setHeaders.call(void 0, event, http.headers || {});
|
|
123
119
|
return context.run({
|
|
124
120
|
globalGuards,
|
|
@@ -129,14 +125,14 @@ function bind(router, data, opts = {}) {
|
|
|
129
125
|
_h3.setResponseStatus.call(void 0, event, err.status);
|
|
130
126
|
return err;
|
|
131
127
|
});
|
|
132
|
-
}
|
|
128
|
+
}, "handler")
|
|
133
129
|
}));
|
|
134
130
|
}
|
|
135
131
|
}
|
|
136
132
|
}
|
|
137
|
-
|
|
133
|
+
_chunkH2FWLKXNjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
138
134
|
}
|
|
139
|
-
|
|
135
|
+
_chunkH2FWLKXNjs.__name.call(void 0, bind, "bind");
|
|
140
136
|
|
|
141
137
|
|
|
142
138
|
exports.bind = bind;
|
package/dist/server/h3/index.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
argToReq,
|
|
5
5
|
createControllerMetaMap,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-2O6X54P5.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-2NTXVYQC.mjs";
|
|
11
11
|
|
|
12
12
|
// src/server/h3/bind.ts
|
|
13
13
|
import { defineRequestMiddleware, eventHandler, getQuery, getRequestHeaders, getRouterParams, readBody, setHeaders, setResponseStatus } from "h3";
|
|
@@ -39,7 +39,7 @@ function bind(router, data, opts = {}) {
|
|
|
39
39
|
...globalPlugins,
|
|
40
40
|
...parallelPlugins
|
|
41
41
|
], "h3").map(defineRequestMiddleware),
|
|
42
|
-
handler: async (event) => {
|
|
42
|
+
handler: /* @__PURE__ */ __name(async (event) => {
|
|
43
43
|
const body = await readBody(event, {
|
|
44
44
|
strict: true
|
|
45
45
|
});
|
|
@@ -49,18 +49,15 @@ function bind(router, data, opts = {}) {
|
|
|
49
49
|
return error;
|
|
50
50
|
}
|
|
51
51
|
__name(errorHandler, "errorHandler");
|
|
52
|
-
if (!Array.isArray(body))
|
|
53
|
-
return errorHandler(new BadRequestException("data format should be an array"));
|
|
52
|
+
if (!Array.isArray(body)) return errorHandler(new BadRequestException("data format should be an array"));
|
|
54
53
|
try {
|
|
55
54
|
return Promise.all(body.map((item, i) => {
|
|
56
55
|
return new Promise(async (resolve) => {
|
|
57
56
|
const { tag, func } = item;
|
|
58
57
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
59
|
-
if (!metaMap.has(tag))
|
|
60
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
58
|
+
if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
61
59
|
const meta2 = metaMap.get(tag)[func];
|
|
62
|
-
if (!meta2)
|
|
63
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
60
|
+
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
64
61
|
const { data: { params } } = meta2;
|
|
65
62
|
const contextData = {
|
|
66
63
|
type: "h3",
|
|
@@ -86,22 +83,21 @@ function bind(router, data, opts = {}) {
|
|
|
86
83
|
} catch (e) {
|
|
87
84
|
return errorHandler(e);
|
|
88
85
|
}
|
|
89
|
-
}
|
|
86
|
+
}, "handler")
|
|
90
87
|
}));
|
|
91
88
|
}
|
|
92
89
|
for (const [tag, record] of metaMap) {
|
|
93
90
|
for (const func in record) {
|
|
94
91
|
const meta2 = metaMap.get(tag)[func];
|
|
95
92
|
const { data: { http, params, plugins } } = meta2;
|
|
96
|
-
if (!http?.type)
|
|
97
|
-
continue;
|
|
93
|
+
if (!http?.type) continue;
|
|
98
94
|
const needBody = params.some((item) => item.type === "body");
|
|
99
95
|
router[http.type](http.prefix + http.route, eventHandler({
|
|
100
96
|
onRequest: Context.usePlugin([
|
|
101
97
|
...globalPlugins,
|
|
102
98
|
...plugins
|
|
103
99
|
], "h3").map(defineRequestMiddleware),
|
|
104
|
-
handler: async (event) => {
|
|
100
|
+
handler: /* @__PURE__ */ __name(async (event) => {
|
|
105
101
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
106
102
|
const contextData = {
|
|
107
103
|
type: "h3",
|
|
@@ -129,7 +125,7 @@ function bind(router, data, opts = {}) {
|
|
|
129
125
|
setResponseStatus(event, err.status);
|
|
130
126
|
return err;
|
|
131
127
|
});
|
|
132
|
-
}
|
|
128
|
+
}, "handler")
|
|
133
129
|
}));
|
|
134
130
|
}
|
|
135
131
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context, Hono, MiddlewareHandler } from 'hono';
|
|
2
|
+
import { a as HttpContext, H as HttpOptions } from '../../types-ByP1fKMe.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BIm7dkko.mjs';
|
|
4
|
+
import 'node:http';
|
|
5
|
+
import '../../types-CdQey96H.mjs';
|
|
6
|
+
import 'phecda-core';
|
|
7
|
+
|
|
8
|
+
interface HonoCtx extends HttpContext {
|
|
9
|
+
type: 'hono';
|
|
10
|
+
context: Context;
|
|
11
|
+
app: Hono;
|
|
12
|
+
}
|
|
13
|
+
type Plugin = MiddlewareHandler;
|
|
14
|
+
declare function bind(router: Hono, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
15
|
+
|
|
16
|
+
export { type HonoCtx, type Plugin, bind };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context, Hono, MiddlewareHandler } from 'hono';
|
|
2
|
-
import { a as HttpContext, H as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { a as HttpContext, H as HttpOptions } from '../../types-C5sdDiDQ.js';
|
|
3
|
+
import { F as Factory } from '../../core-C3cON4Um.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../types-
|
|
5
|
+
import '../../types-CdQey96H.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface HonoCtx extends HttpContext {
|
|
@@ -13,4 +13,4 @@ interface HonoCtx extends HttpContext {
|
|
|
13
13
|
type Plugin = MiddlewareHandler;
|
|
14
14
|
declare function bind(router: Hono, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
15
15
|
|
|
16
|
-
export { HonoCtx, Plugin, bind };
|
|
16
|
+
export { type HonoCtx, type Plugin, bind };
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk6T4UZ4LVjs = require('../../chunk-6T4UZ4LV.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkH2FWLKXNjs = require('../../chunk-H2FWLKXN.js');
|
|
11
11
|
|
|
12
12
|
// src/server/hono/bind.ts
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
@@ -15,14 +15,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/hono");
|
|
|
15
15
|
function bind(router, data, opts = {}) {
|
|
16
16
|
const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
|
|
17
17
|
const { moduleMap, meta } = data;
|
|
18
|
-
const metaMap =
|
|
18
|
+
const metaMap = _chunk6T4UZ4LVjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
19
19
|
const { controller, http, func, tag } = meta2.data;
|
|
20
20
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
21
21
|
debug(`register method "${func}" in module "${tag}"`);
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
|
|
25
|
+
_chunk6T4UZ4LVjs.detectAopDep.call(void 0, meta, {
|
|
26
26
|
plugins: [
|
|
27
27
|
...globalPlugins,
|
|
28
28
|
...parallelPlugins
|
|
@@ -32,28 +32,25 @@ function bind(router, data, opts = {}) {
|
|
|
32
32
|
});
|
|
33
33
|
registerRoute();
|
|
34
34
|
async function registerRoute() {
|
|
35
|
-
|
|
35
|
+
_chunk6T4UZ4LVjs.Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
|
|
36
36
|
if (parallelRoute) {
|
|
37
|
-
router.post(parallelRoute, ...
|
|
37
|
+
router.post(parallelRoute, ..._chunk6T4UZ4LVjs.Context.usePlugin(parallelPlugins, "hono"), async (c) => {
|
|
38
38
|
const body = await c.req.json();
|
|
39
39
|
async function errorHandler(e) {
|
|
40
|
-
const error = await
|
|
40
|
+
const error = await _chunk6T4UZ4LVjs.Context.filterRecord.default(e);
|
|
41
41
|
c.status(error.status);
|
|
42
42
|
return c.json(error);
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
if (!Array.isArray(body))
|
|
46
|
-
return errorHandler(new (0, _chunkH6NYBVBVjs.BadRequestException)("data format should be an array"));
|
|
44
|
+
_chunkH2FWLKXNjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
45
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunk6T4UZ4LVjs.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))
|
|
53
|
-
return resolve(await _chunkH6NYBVBVjs.Context.filterRecord.default(new (0, _chunkH6NYBVBVjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
51
|
+
if (!metaMap.has(tag)) return resolve(await _chunk6T4UZ4LVjs.Context.filterRecord.default(new (0, _chunk6T4UZ4LVjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
54
52
|
const meta2 = metaMap.get(tag)[func];
|
|
55
|
-
if (!meta2)
|
|
56
|
-
return resolve(await _chunkH6NYBVBVjs.Context.filterRecord.default(new (0, _chunkH6NYBVBVjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
53
|
+
if (!meta2) return resolve(await _chunk6T4UZ4LVjs.Context.filterRecord.default(new (0, _chunk6T4UZ4LVjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
57
54
|
const { data: { params } } = meta2;
|
|
58
55
|
const contextData = {
|
|
59
56
|
type: "hono",
|
|
@@ -65,9 +62,9 @@ function bind(router, data, opts = {}) {
|
|
|
65
62
|
tag,
|
|
66
63
|
func,
|
|
67
64
|
app: router,
|
|
68
|
-
...
|
|
65
|
+
..._chunk6T4UZ4LVjs.argToReq.call(void 0, params, item.args, c.req.header())
|
|
69
66
|
};
|
|
70
|
-
const context = new (0,
|
|
67
|
+
const context = new (0, _chunk6T4UZ4LVjs.Context)(contextData);
|
|
71
68
|
context.run({
|
|
72
69
|
globalGuards,
|
|
73
70
|
globalInterceptors,
|
|
@@ -87,10 +84,9 @@ function bind(router, data, opts = {}) {
|
|
|
87
84
|
for (const func in record) {
|
|
88
85
|
const meta2 = metaMap.get(tag)[func];
|
|
89
86
|
const { data: { params, plugins, http } } = meta2;
|
|
90
|
-
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
91
|
-
continue;
|
|
87
|
+
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
92
88
|
const needBody = params.some((item) => item.type === "body");
|
|
93
|
-
router[http.type](http.prefix + http.route, ...
|
|
89
|
+
router[http.type](http.prefix + http.route, ..._chunk6T4UZ4LVjs.Context.usePlugin(plugins, "hono"), async (c) => {
|
|
94
90
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
95
91
|
const contextData = {
|
|
96
92
|
type: "hono",
|
|
@@ -105,10 +101,9 @@ function bind(router, data, opts = {}) {
|
|
|
105
101
|
headers: c.req.header(),
|
|
106
102
|
app: router
|
|
107
103
|
};
|
|
108
|
-
const context = new (0,
|
|
104
|
+
const context = new (0, _chunk6T4UZ4LVjs.Context)(contextData);
|
|
109
105
|
if (http.headers) {
|
|
110
|
-
for (const name in http.headers)
|
|
111
|
-
c.header(name, http.headers[name]);
|
|
106
|
+
for (const name in http.headers) c.header(name, http.headers[name]);
|
|
112
107
|
}
|
|
113
108
|
return context.run({
|
|
114
109
|
globalGuards,
|
|
@@ -116,12 +111,9 @@ function bind(router, data, opts = {}) {
|
|
|
116
111
|
globalFilter,
|
|
117
112
|
globalPipe
|
|
118
113
|
}, (returnData) => {
|
|
119
|
-
if (returnData instanceof Response)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return c.text(returnData);
|
|
123
|
-
else
|
|
124
|
-
return c.json(returnData);
|
|
114
|
+
if (returnData instanceof Response) return returnData;
|
|
115
|
+
if (typeof returnData === "string") return c.text(returnData);
|
|
116
|
+
else return c.json(returnData);
|
|
125
117
|
}, (err) => {
|
|
126
118
|
c.status(err.status);
|
|
127
119
|
return c.json(err);
|
|
@@ -130,9 +122,9 @@ function bind(router, data, opts = {}) {
|
|
|
130
122
|
}
|
|
131
123
|
}
|
|
132
124
|
}
|
|
133
|
-
|
|
125
|
+
_chunkH2FWLKXNjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
134
126
|
}
|
|
135
|
-
|
|
127
|
+
_chunkH2FWLKXNjs.__name.call(void 0, bind, "bind");
|
|
136
128
|
|
|
137
129
|
|
|
138
130
|
exports.bind = bind;
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
argToReq,
|
|
5
5
|
createControllerMetaMap,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-2O6X54P5.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-2NTXVYQC.mjs";
|
|
11
11
|
|
|
12
12
|
// src/server/hono/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
@@ -42,18 +42,15 @@ function bind(router, data, opts = {}) {
|
|
|
42
42
|
return c.json(error);
|
|
43
43
|
}
|
|
44
44
|
__name(errorHandler, "errorHandler");
|
|
45
|
-
if (!Array.isArray(body))
|
|
46
|
-
return errorHandler(new BadRequestException("data format should be an array"));
|
|
45
|
+
if (!Array.isArray(body)) return errorHandler(new 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))
|
|
53
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
51
|
+
if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
54
52
|
const meta2 = metaMap.get(tag)[func];
|
|
55
|
-
if (!meta2)
|
|
56
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
53
|
+
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
57
54
|
const { data: { params } } = meta2;
|
|
58
55
|
const contextData = {
|
|
59
56
|
type: "hono",
|
|
@@ -87,8 +84,7 @@ function bind(router, data, opts = {}) {
|
|
|
87
84
|
for (const func in record) {
|
|
88
85
|
const meta2 = metaMap.get(tag)[func];
|
|
89
86
|
const { data: { params, plugins, http } } = meta2;
|
|
90
|
-
if (!http?.type)
|
|
91
|
-
continue;
|
|
87
|
+
if (!http?.type) continue;
|
|
92
88
|
const needBody = params.some((item) => item.type === "body");
|
|
93
89
|
router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "hono"), async (c) => {
|
|
94
90
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
@@ -107,8 +103,7 @@ function bind(router, data, opts = {}) {
|
|
|
107
103
|
};
|
|
108
104
|
const context = new Context(contextData);
|
|
109
105
|
if (http.headers) {
|
|
110
|
-
for (const name in http.headers)
|
|
111
|
-
c.header(name, http.headers[name]);
|
|
106
|
+
for (const name in http.headers) c.header(name, http.headers[name]);
|
|
112
107
|
}
|
|
113
108
|
return context.run({
|
|
114
109
|
globalGuards,
|
|
@@ -116,12 +111,9 @@ function bind(router, data, opts = {}) {
|
|
|
116
111
|
globalFilter,
|
|
117
112
|
globalPipe
|
|
118
113
|
}, (returnData) => {
|
|
119
|
-
if (returnData instanceof Response)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return c.text(returnData);
|
|
123
|
-
else
|
|
124
|
-
return c.json(returnData);
|
|
114
|
+
if (returnData instanceof Response) return returnData;
|
|
115
|
+
if (typeof returnData === "string") return c.text(returnData);
|
|
116
|
+
else return c.json(returnData);
|
|
125
117
|
}, (err) => {
|
|
126
118
|
c.status(err.status);
|
|
127
119
|
return c.json(err);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Request, Response, Router, MiddlewareHandler } from 'hyper-express';
|
|
2
|
+
import { a as HttpContext, H as HttpOptions } from '../../types-ByP1fKMe.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BIm7dkko.mjs';
|
|
4
|
+
import 'node:http';
|
|
5
|
+
import '../../types-CdQey96H.mjs';
|
|
6
|
+
import 'phecda-core';
|
|
7
|
+
|
|
8
|
+
interface HyperExpressCtx extends HttpContext {
|
|
9
|
+
type: 'hyper-express';
|
|
10
|
+
request: Request;
|
|
11
|
+
response: Response;
|
|
12
|
+
next: Function;
|
|
13
|
+
app: Router;
|
|
14
|
+
}
|
|
15
|
+
type Plugin = MiddlewareHandler;
|
|
16
|
+
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
17
|
+
|
|
18
|
+
export { type HyperExpressCtx, type Plugin, bind };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, MiddlewareHandler } from 'hyper-express';
|
|
2
|
-
import { a as HttpContext, H as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { a as HttpContext, H as HttpOptions } from '../../types-C5sdDiDQ.js';
|
|
3
|
+
import { F as Factory } from '../../core-C3cON4Um.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../types-
|
|
5
|
+
import '../../types-CdQey96H.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface HyperExpressCtx extends HttpContext {
|
|
@@ -15,4 +15,4 @@ interface HyperExpressCtx extends HttpContext {
|
|
|
15
15
|
type Plugin = MiddlewareHandler;
|
|
16
16
|
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
17
17
|
|
|
18
|
-
export { HyperExpressCtx, Plugin, bind };
|
|
18
|
+
export { type HyperExpressCtx, type Plugin, bind };
|