phecda-server 6.0.2 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.mjs +160 -157
- package/dist/{chunk-HDQAT2IM.mjs → chunk-5622RBNB.mjs} +118 -90
- package/dist/chunk-BGXSMOLX.js +265 -0
- package/dist/{chunk-F3W3NN7F.mjs → chunk-HMVLXNV3.mjs} +5 -14
- package/dist/{chunk-GHFSIZUO.js → chunk-J5CFUN4V.js} +18 -3
- package/dist/{chunk-XCND2QW3.js → chunk-MBCHNDAY.js} +27 -36
- package/dist/{chunk-WXFZZZRY.mjs → chunk-P75VKZJY.mjs} +101 -137
- package/dist/chunk-SW5IKE5H.js +503 -0
- package/dist/{chunk-UXD62LGG.mjs → chunk-WHJ5FALK.mjs} +17 -2
- package/dist/core-BIcUwV18.d.mts +47 -0
- package/dist/core-CYwEPfN4.d.ts +47 -0
- package/dist/helper.d.mts +4 -6
- package/dist/helper.d.ts +4 -6
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/{server → http}/elysia/index.d.mts +5 -5
- package/dist/{server → http}/elysia/index.d.ts +5 -5
- package/dist/{server → http}/elysia/index.js +80 -62
- package/dist/{server → http}/elysia/index.mjs +50 -32
- package/dist/{server → http}/express/index.d.mts +5 -5
- package/dist/{server → http}/express/index.d.ts +5 -5
- package/dist/{server → http}/express/index.js +71 -55
- package/dist/{server → http}/express/index.mjs +42 -26
- package/dist/{server → http}/fastify/index.d.mts +5 -5
- package/dist/{server → http}/fastify/index.d.ts +5 -5
- package/dist/{server → http}/fastify/index.js +72 -72
- package/dist/{server → http}/fastify/index.mjs +47 -47
- package/dist/{server → http}/h3/index.d.mts +5 -5
- package/dist/{server → http}/h3/index.d.ts +5 -5
- package/dist/http/h3/index.js +160 -0
- package/dist/{server → http}/h3/index.mjs +68 -62
- package/dist/{server → http}/hono/index.d.mts +5 -5
- package/dist/{server → http}/hono/index.d.ts +5 -5
- package/dist/{server → http}/hono/index.js +69 -54
- package/dist/{server → http}/hono/index.mjs +41 -26
- package/dist/{server → http}/hyper-express/index.d.mts +5 -5
- package/dist/{server → http}/hyper-express/index.d.ts +5 -5
- package/dist/{server → http}/hyper-express/index.js +69 -56
- package/dist/{server → http}/hyper-express/index.mjs +41 -28
- package/dist/{server → http}/koa/index.d.mts +5 -5
- package/dist/{server → http}/koa/index.d.ts +5 -5
- package/dist/{server → http}/koa/index.js +71 -55
- package/dist/{server → http}/koa/index.mjs +42 -26
- package/dist/index.d.mts +53 -41
- package/dist/index.d.ts +53 -41
- package/dist/index.js +62 -78
- package/dist/index.mjs +46 -62
- package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
- package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
- package/dist/rpc/bullmq/index.d.mts +6 -6
- package/dist/rpc/bullmq/index.d.ts +6 -6
- package/dist/rpc/bullmq/index.js +24 -24
- package/dist/rpc/bullmq/index.mjs +14 -14
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +25 -21
- package/dist/rpc/kafka/index.mjs +15 -11
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +22 -21
- package/dist/rpc/nats/index.mjs +13 -12
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +23 -22
- package/dist/rpc/rabbitmq/index.mjs +12 -11
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +24 -20
- package/dist/rpc/redis/index.mjs +15 -11
- package/dist/test.d.mts +3 -3
- package/dist/test.d.ts +3 -3
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
- package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
- package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
- package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
- package/package.json +24 -24
- package/dist/chunk-7SYPUIBY.js +0 -539
- package/dist/chunk-LYEZ6RGX.js +0 -237
- package/dist/core-2SNw8m2B.d.mts +0 -30
- package/dist/core-BmJJLUqj.d.ts +0 -30
- package/dist/server/h3/index.js +0 -154
|
@@ -4,16 +4,17 @@ import {
|
|
|
4
4
|
argToReq,
|
|
5
5
|
createControllerMetaMap,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-P75VKZJY.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
11
11
|
|
|
12
|
-
// src/
|
|
12
|
+
// src/http/hyper-express/bind.ts
|
|
13
|
+
import { Router } from "hyper-express";
|
|
13
14
|
import Debug from "debug";
|
|
14
15
|
var debug = Debug("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
19
|
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
19
20
|
const { controller, http, func, tag } = meta2.data;
|
|
@@ -23,20 +24,18 @@ function bind(router, data, opts = {}) {
|
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
detectAopDep(meta, {
|
|
26
|
-
|
|
27
|
-
...
|
|
28
|
-
...
|
|
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
|
-
Context.
|
|
35
|
+
Context.applyAddons(globalAddons, router, "hyper-express");
|
|
36
36
|
if (parallelRoute) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, async (req, res, next) => {
|
|
37
|
+
const subRouter = new Router();
|
|
38
|
+
subRouter.post(parallelRoute, async (req, res, next) => {
|
|
40
39
|
const body = await req.json();
|
|
41
40
|
async function errorHandler(e) {
|
|
42
41
|
const error = await Context.filterRecord.default(e);
|
|
@@ -53,6 +52,11 @@ function bind(router, data, opts = {}) {
|
|
|
53
52
|
const meta2 = metaMap.get(tag)[func];
|
|
54
53
|
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
55
54
|
const { data: { params } } = meta2;
|
|
55
|
+
const aop = Context.getAop(meta2, {
|
|
56
|
+
globalFilter,
|
|
57
|
+
globalGuards,
|
|
58
|
+
globalPipe
|
|
59
|
+
});
|
|
56
60
|
const contextData = {
|
|
57
61
|
type: "hyper-express",
|
|
58
62
|
parallel: true,
|
|
@@ -63,9 +67,9 @@ function bind(router, data, opts = {}) {
|
|
|
63
67
|
moduleMap,
|
|
64
68
|
tag,
|
|
65
69
|
func,
|
|
66
|
-
next,
|
|
67
70
|
app: router,
|
|
68
71
|
...argToReq(params, item.args, req.headers),
|
|
72
|
+
next,
|
|
69
73
|
getCookie: /* @__PURE__ */ __name((key) => req.cookies[key], "getCookie"),
|
|
70
74
|
setCookie: /* @__PURE__ */ __name((key, value, opts2) => res.cookie(key, value, opts2?.expires && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
|
|
71
75
|
delCookie: /* @__PURE__ */ __name((key) => res.clearCookie(key), "delCookie"),
|
|
@@ -76,12 +80,7 @@ function bind(router, data, opts = {}) {
|
|
|
76
80
|
getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
|
|
77
81
|
};
|
|
78
82
|
const context = new Context(contextData);
|
|
79
|
-
context.run(
|
|
80
|
-
globalGuards,
|
|
81
|
-
globalInterceptors,
|
|
82
|
-
globalFilter,
|
|
83
|
-
globalPipe
|
|
84
|
-
}, resolve, resolve);
|
|
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 (!http?.type) continue;
|
|
99
99
|
const needBody = params.some((item) => item.type === "body");
|
|
100
|
-
|
|
100
|
+
let aop;
|
|
101
|
+
if (!dynamic) {
|
|
102
|
+
aop = Context.getAop(meta2, {
|
|
103
|
+
globalFilter,
|
|
104
|
+
globalGuards,
|
|
105
|
+
globalPipe
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const subRouter = new Router();
|
|
109
|
+
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",
|
|
@@ -126,12 +136,14 @@ function bind(router, data, opts = {}) {
|
|
|
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 = 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,6 +152,7 @@ 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
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Router, { RouterParamContext } from '@koa/router';
|
|
2
2
|
import { DefaultContext, DefaultState } from 'koa';
|
|
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-h40T3cRG.mjs';
|
|
4
|
+
import { F as Factory } from '../../core-BIcUwV18.mjs';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-BXKLFTgG.mjs';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface KoaCtx extends HttpContext {
|
|
@@ -12,7 +12,7 @@ interface KoaCtx extends HttpContext {
|
|
|
12
12
|
next: Function;
|
|
13
13
|
app: Router;
|
|
14
14
|
}
|
|
15
|
-
type
|
|
15
|
+
type Addon = Router.Middleware;
|
|
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 KoaCtx, bind };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Router, { RouterParamContext } from '@koa/router';
|
|
2
2
|
import { DefaultContext, DefaultState } from 'koa';
|
|
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-VFzEM7LL.js';
|
|
4
|
+
import { F as Factory } from '../../core-CYwEPfN4.js';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-BXKLFTgG.js';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface KoaCtx extends HttpContext {
|
|
@@ -12,7 +12,7 @@ interface KoaCtx extends HttpContext {
|
|
|
12
12
|
next: Function;
|
|
13
13
|
app: Router;
|
|
14
14
|
}
|
|
15
|
-
type
|
|
15
|
+
type Addon = Router.Middleware;
|
|
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 KoaCtx, bind };
|
|
@@ -5,55 +5,62 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
12
12
|
|
|
13
|
-
// src/
|
|
13
|
+
// src/http/koa/bind.ts
|
|
14
|
+
var _router = require('@koa/router'); var _router2 = _interopRequireDefault(_router);
|
|
14
15
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
15
16
|
var debug = _debug2.default.call(void 0, "phecda-server/koa");
|
|
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 originStack = router.stack.slice(0, router.stack.length);
|
|
20
|
-
const metaMap =
|
|
21
|
+
const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
21
22
|
const { controller, http, func, tag } = meta2.data;
|
|
22
23
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
23
24
|
debug(`register method "${func}" in module "${tag}"`);
|
|
24
25
|
return true;
|
|
25
26
|
}
|
|
26
27
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...
|
|
30
|
-
...
|
|
28
|
+
_chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
|
|
29
|
+
addons: [
|
|
30
|
+
...globalAddons,
|
|
31
|
+
...parallelAddons
|
|
31
32
|
],
|
|
32
|
-
guards: globalGuards
|
|
33
|
-
interceptors: globalInterceptors
|
|
33
|
+
guards: globalGuards
|
|
34
34
|
});
|
|
35
35
|
registerRoute();
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
function registerRoute() {
|
|
37
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, router, "koa");
|
|
38
38
|
if (parallelRoute) {
|
|
39
|
-
|
|
39
|
+
const subRouter = new (0, _router2.default)();
|
|
40
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, subRouter, "koa");
|
|
41
|
+
subRouter.post(parallelRoute, async (ctx, next) => {
|
|
40
42
|
const { body } = ctx.request;
|
|
41
43
|
async function errorHandler(e) {
|
|
42
|
-
const error = await
|
|
44
|
+
const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
|
|
43
45
|
ctx.status = error.status;
|
|
44
46
|
ctx.body = error;
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
48
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
49
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
|
|
48
50
|
try {
|
|
49
51
|
return Promise.all(body.map((item, i) => {
|
|
50
52
|
return new Promise(async (resolve) => {
|
|
51
53
|
const { tag, func } = item;
|
|
52
54
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
53
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
55
|
+
if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
54
56
|
const meta2 = metaMap.get(tag)[func];
|
|
55
|
-
if (!meta2) return resolve(await
|
|
57
|
+
if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
56
58
|
const { data: { params } } = meta2;
|
|
59
|
+
const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
60
|
+
globalGuards,
|
|
61
|
+
globalFilter,
|
|
62
|
+
globalPipe
|
|
63
|
+
});
|
|
57
64
|
const contextData = {
|
|
58
65
|
type: "koa",
|
|
59
66
|
index: i,
|
|
@@ -63,27 +70,22 @@ function bind(router, data, opts = {}) {
|
|
|
63
70
|
parallel: true,
|
|
64
71
|
next,
|
|
65
72
|
app: router,
|
|
66
|
-
...
|
|
73
|
+
..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, ctx.headers),
|
|
67
74
|
tag,
|
|
68
75
|
func,
|
|
69
|
-
getCookie: /* @__PURE__ */
|
|
70
|
-
setCookie: /* @__PURE__ */
|
|
71
|
-
delCookie: /* @__PURE__ */
|
|
76
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
|
|
77
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
|
|
78
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
|
|
72
79
|
expires: /* @__PURE__ */ new Date(0)
|
|
73
80
|
}), "delCookie"),
|
|
74
|
-
redirect: /* @__PURE__ */
|
|
75
|
-
setResHeaders: /* @__PURE__ */
|
|
76
|
-
setResStatus: /* @__PURE__ */
|
|
77
|
-
getRequest: /* @__PURE__ */
|
|
78
|
-
getResponse: /* @__PURE__ */
|
|
81
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
|
|
82
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
|
|
83
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
|
|
84
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.req, "getRequest"),
|
|
85
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.res, "getResponse")
|
|
79
86
|
};
|
|
80
|
-
const context = new (0,
|
|
81
|
-
context.run(
|
|
82
|
-
globalGuards,
|
|
83
|
-
globalInterceptors,
|
|
84
|
-
globalFilter,
|
|
85
|
-
globalPipe
|
|
86
|
-
}, resolve, resolve);
|
|
87
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
|
|
88
|
+
context.run(aop, resolve, resolve);
|
|
87
89
|
});
|
|
88
90
|
})).then((ret) => {
|
|
89
91
|
ctx.body = ret;
|
|
@@ -92,13 +94,24 @@ function bind(router, data, opts = {}) {
|
|
|
92
94
|
return errorHandler(e);
|
|
93
95
|
}
|
|
94
96
|
});
|
|
97
|
+
router.use(subRouter.routes()).use(subRouter.allowedMethods());
|
|
95
98
|
}
|
|
96
99
|
for (const [tag, record] of metaMap) {
|
|
97
100
|
for (const func in record) {
|
|
98
101
|
const meta2 = metaMap.get(tag)[func];
|
|
99
|
-
const { data: {
|
|
102
|
+
const { data: { addons, http } } = meta2;
|
|
100
103
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
101
|
-
|
|
104
|
+
let aop;
|
|
105
|
+
if (!dynamic) {
|
|
106
|
+
aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
107
|
+
globalFilter,
|
|
108
|
+
globalGuards,
|
|
109
|
+
globalPipe
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const subRouter = new (0, _router2.default)();
|
|
113
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(addons, subRouter, "koa");
|
|
114
|
+
router[http.type](http.prefix + http.route, async (ctx, next) => {
|
|
102
115
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
103
116
|
const contextData = {
|
|
104
117
|
type: "koa",
|
|
@@ -113,25 +126,27 @@ function bind(router, data, opts = {}) {
|
|
|
113
126
|
body: ctx.request.body,
|
|
114
127
|
headers: ctx.headers,
|
|
115
128
|
next,
|
|
116
|
-
getCookie: /* @__PURE__ */
|
|
117
|
-
setCookie: /* @__PURE__ */
|
|
118
|
-
delCookie: /* @__PURE__ */
|
|
129
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
|
|
130
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
|
|
131
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
|
|
119
132
|
expires: /* @__PURE__ */ new Date(0)
|
|
120
133
|
}), "delCookie"),
|
|
121
|
-
redirect: /* @__PURE__ */
|
|
122
|
-
setResHeaders: /* @__PURE__ */
|
|
123
|
-
setResStatus: /* @__PURE__ */
|
|
124
|
-
getRequest: /* @__PURE__ */
|
|
125
|
-
getResponse: /* @__PURE__ */
|
|
134
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
|
|
135
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
|
|
136
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
|
|
137
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.req, "getRequest"),
|
|
138
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.res, "getResponse")
|
|
126
139
|
};
|
|
127
|
-
const context = new (0,
|
|
140
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
|
|
128
141
|
if (http.headers) ctx.set(http.headers);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
if (dynamic) {
|
|
143
|
+
aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
144
|
+
globalFilter,
|
|
145
|
+
globalGuards,
|
|
146
|
+
globalPipe
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
await context.run(aop, (returnData) => {
|
|
135
150
|
if (ctx.res.writableEnded) return;
|
|
136
151
|
ctx.body = returnData;
|
|
137
152
|
}, (err) => {
|
|
@@ -140,16 +155,17 @@ function bind(router, data, opts = {}) {
|
|
|
140
155
|
ctx.body = err;
|
|
141
156
|
});
|
|
142
157
|
});
|
|
158
|
+
router.use(subRouter.routes()).use(subRouter.allowedMethods());
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
}
|
|
146
|
-
|
|
147
|
-
|
|
162
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
163
|
+
_chunkSW5IKE5Hjs.HMR.call(void 0, async () => {
|
|
148
164
|
router.stack = originStack;
|
|
149
165
|
registerRoute();
|
|
150
166
|
});
|
|
151
167
|
}
|
|
152
|
-
|
|
168
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
|
|
153
169
|
|
|
154
170
|
|
|
155
171
|
exports.bind = bind;
|
|
@@ -5,16 +5,17 @@ import {
|
|
|
5
5
|
argToReq,
|
|
6
6
|
createControllerMetaMap,
|
|
7
7
|
detectAopDep
|
|
8
|
-
} from "../../chunk-
|
|
8
|
+
} from "../../chunk-P75VKZJY.mjs";
|
|
9
9
|
import {
|
|
10
10
|
__name
|
|
11
|
-
} from "../../chunk-
|
|
11
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
12
12
|
|
|
13
|
-
// src/
|
|
13
|
+
// src/http/koa/bind.ts
|
|
14
|
+
import Router from "@koa/router";
|
|
14
15
|
import Debug from "debug";
|
|
15
16
|
var debug = Debug("phecda-server/koa");
|
|
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 originStack = router.stack.slice(0, router.stack.length);
|
|
20
21
|
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
@@ -25,18 +26,19 @@ function bind(router, data, opts = {}) {
|
|
|
25
26
|
}
|
|
26
27
|
});
|
|
27
28
|
detectAopDep(meta, {
|
|
28
|
-
|
|
29
|
-
...
|
|
30
|
-
...
|
|
29
|
+
addons: [
|
|
30
|
+
...globalAddons,
|
|
31
|
+
...parallelAddons
|
|
31
32
|
],
|
|
32
|
-
guards: globalGuards
|
|
33
|
-
interceptors: globalInterceptors
|
|
33
|
+
guards: globalGuards
|
|
34
34
|
});
|
|
35
35
|
registerRoute();
|
|
36
|
-
|
|
37
|
-
Context.
|
|
36
|
+
function registerRoute() {
|
|
37
|
+
Context.applyAddons(globalAddons, router, "koa");
|
|
38
38
|
if (parallelRoute) {
|
|
39
|
-
|
|
39
|
+
const subRouter = new Router();
|
|
40
|
+
Context.applyAddons(parallelAddons, subRouter, "koa");
|
|
41
|
+
subRouter.post(parallelRoute, async (ctx, next) => {
|
|
40
42
|
const { body } = ctx.request;
|
|
41
43
|
async function errorHandler(e) {
|
|
42
44
|
const error = await Context.filterRecord.default(e);
|
|
@@ -54,6 +56,11 @@ function bind(router, data, opts = {}) {
|
|
|
54
56
|
const meta2 = metaMap.get(tag)[func];
|
|
55
57
|
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
56
58
|
const { data: { params } } = meta2;
|
|
59
|
+
const aop = Context.getAop(meta2, {
|
|
60
|
+
globalGuards,
|
|
61
|
+
globalFilter,
|
|
62
|
+
globalPipe
|
|
63
|
+
});
|
|
57
64
|
const contextData = {
|
|
58
65
|
type: "koa",
|
|
59
66
|
index: i,
|
|
@@ -78,12 +85,7 @@ function bind(router, data, opts = {}) {
|
|
|
78
85
|
getResponse: /* @__PURE__ */ __name(() => ctx.res, "getResponse")
|
|
79
86
|
};
|
|
80
87
|
const context = new Context(contextData);
|
|
81
|
-
context.run(
|
|
82
|
-
globalGuards,
|
|
83
|
-
globalInterceptors,
|
|
84
|
-
globalFilter,
|
|
85
|
-
globalPipe
|
|
86
|
-
}, resolve, resolve);
|
|
88
|
+
context.run(aop, resolve, resolve);
|
|
87
89
|
});
|
|
88
90
|
})).then((ret) => {
|
|
89
91
|
ctx.body = ret;
|
|
@@ -92,13 +94,24 @@ function bind(router, data, opts = {}) {
|
|
|
92
94
|
return errorHandler(e);
|
|
93
95
|
}
|
|
94
96
|
});
|
|
97
|
+
router.use(subRouter.routes()).use(subRouter.allowedMethods());
|
|
95
98
|
}
|
|
96
99
|
for (const [tag, record] of metaMap) {
|
|
97
100
|
for (const func in record) {
|
|
98
101
|
const meta2 = metaMap.get(tag)[func];
|
|
99
|
-
const { data: {
|
|
102
|
+
const { data: { addons, http } } = meta2;
|
|
100
103
|
if (!http?.type) continue;
|
|
101
|
-
|
|
104
|
+
let aop;
|
|
105
|
+
if (!dynamic) {
|
|
106
|
+
aop = Context.getAop(meta2, {
|
|
107
|
+
globalFilter,
|
|
108
|
+
globalGuards,
|
|
109
|
+
globalPipe
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const subRouter = new Router();
|
|
113
|
+
Context.applyAddons(addons, subRouter, "koa");
|
|
114
|
+
router[http.type](http.prefix + http.route, async (ctx, next) => {
|
|
102
115
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
103
116
|
const contextData = {
|
|
104
117
|
type: "koa",
|
|
@@ -126,12 +139,14 @@ function bind(router, data, opts = {}) {
|
|
|
126
139
|
};
|
|
127
140
|
const context = new Context(contextData);
|
|
128
141
|
if (http.headers) ctx.set(http.headers);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
if (dynamic) {
|
|
143
|
+
aop = Context.getAop(meta2, {
|
|
144
|
+
globalFilter,
|
|
145
|
+
globalGuards,
|
|
146
|
+
globalPipe
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
await context.run(aop, (returnData) => {
|
|
135
150
|
if (ctx.res.writableEnded) return;
|
|
136
151
|
ctx.body = returnData;
|
|
137
152
|
}, (err) => {
|
|
@@ -140,6 +155,7 @@ function bind(router, data, opts = {}) {
|
|
|
140
155
|
ctx.body = err;
|
|
141
156
|
});
|
|
142
157
|
});
|
|
158
|
+
router.use(subRouter.routes()).use(subRouter.allowedMethods());
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
}
|