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
package/dist/helper.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
require('./chunk-
|
|
10
|
+
var _chunkSW5IKE5Hjs = require('./chunk-SW5IKE5H.js');
|
|
11
|
+
require('./chunk-J5CFUN4V.js');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
@@ -18,4 +18,4 @@ require('./chunk-GHFSIZUO.js');
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
exports.HMR =
|
|
21
|
+
exports.HMR = _chunkSW5IKE5Hjs.HMR; exports.argToReq = _chunkSW5IKE5Hjs.argToReq; exports.createControllerMetaMap = _chunkSW5IKE5Hjs.createControllerMetaMap; exports.detectAopDep = _chunkSW5IKE5Hjs.detectAopDep; exports.genClientQueue = _chunkSW5IKE5Hjs.genClientQueue; exports.mergeObject = _chunkSW5IKE5Hjs.mergeObject; exports.resolveDep = _chunkSW5IKE5Hjs.resolveDep; exports.shallowClone = _chunkSW5IKE5Hjs.shallowClone;
|
package/dist/helper.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-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 ElysiaCtx extends HttpContext {
|
|
@@ -11,8 +11,8 @@ interface ElysiaCtx extends HttpContext {
|
|
|
11
11
|
app: Elysia$1;
|
|
12
12
|
context: Context;
|
|
13
13
|
}
|
|
14
|
-
type
|
|
14
|
+
type Addon = (app: Elysia$1<any>) => void;
|
|
15
15
|
declare function bind(app: Elysia$1<any>, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
16
16
|
declare function Elysia(opts: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>): any;
|
|
17
17
|
|
|
18
|
-
export { Elysia, type ElysiaCtx,
|
|
18
|
+
export { type Addon, Elysia, type ElysiaCtx, bind };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-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 ElysiaCtx extends HttpContext {
|
|
@@ -11,8 +11,8 @@ interface ElysiaCtx extends HttpContext {
|
|
|
11
11
|
app: Elysia$1;
|
|
12
12
|
context: Context;
|
|
13
13
|
}
|
|
14
|
-
type
|
|
14
|
+
type Addon = (app: Elysia$1<any>) => void;
|
|
15
15
|
declare function bind(app: Elysia$1<any>, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
16
16
|
declare function Elysia(opts: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>): any;
|
|
17
17
|
|
|
18
|
-
export { Elysia, type ElysiaCtx,
|
|
18
|
+
export { type Addon, Elysia, type ElysiaCtx, bind };
|
|
@@ -1,63 +1,67 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkMBCHNDAYjs = require('../../chunk-MBCHNDAY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
14
14
|
|
|
15
|
-
// src/
|
|
15
|
+
// src/http/elysia/bind.ts
|
|
16
16
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
17
17
|
var _elysia = require('elysia');
|
|
18
18
|
var debug = _debug2.default.call(void 0, "phecda-server/elysia");
|
|
19
19
|
function bind(app, data, opts = {}) {
|
|
20
|
-
const { globalGuards,
|
|
20
|
+
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
21
21
|
const { moduleMap, meta } = data;
|
|
22
|
-
const metaMap =
|
|
22
|
+
const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
23
23
|
const { controller, http, func, tag } = meta2.data;
|
|
24
24
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
25
25
|
debug(`register method "${func}" in module "${tag}"`);
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
...
|
|
32
|
-
...
|
|
29
|
+
_chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
|
|
30
|
+
addons: [
|
|
31
|
+
...globalAddons,
|
|
32
|
+
...parallelAddons
|
|
33
33
|
],
|
|
34
|
-
guards: globalGuards
|
|
35
|
-
interceptors: globalInterceptors
|
|
34
|
+
guards: globalGuards
|
|
36
35
|
});
|
|
37
36
|
registerRoute();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const parallelRouter = new (0, _elysia.Elysia)();
|
|
41
|
-
_chunk7SYPUIBYjs.Context.usePlugin(parallelPlugins, "elysia").forEach((p) => p(parallelRouter));
|
|
37
|
+
function registerRoute() {
|
|
38
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, app, "elysia");
|
|
42
39
|
if (parallelRoute) {
|
|
40
|
+
const parallelRouter = new (0, _elysia.Elysia)();
|
|
41
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, app, "elysia");
|
|
43
42
|
parallelRouter.post(parallelRoute, async (c) => {
|
|
44
43
|
const { body } = c;
|
|
45
44
|
async function errorHandler(e) {
|
|
46
|
-
const error = await
|
|
45
|
+
const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
|
|
47
46
|
c.set.status = error.status;
|
|
48
47
|
return error;
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
49
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
50
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
|
|
52
51
|
try {
|
|
53
52
|
return Promise.all(body.map((item, i) => {
|
|
54
53
|
return new Promise(async (resolve) => {
|
|
55
54
|
const { tag, func } = item;
|
|
56
55
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
57
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
56
|
+
if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
58
57
|
const meta2 = metaMap.get(tag)[func];
|
|
59
|
-
if (!meta2) return resolve(await
|
|
58
|
+
if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
60
59
|
const { data: { params } } = meta2;
|
|
60
|
+
const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
61
|
+
globalGuards,
|
|
62
|
+
globalFilter,
|
|
63
|
+
globalPipe
|
|
64
|
+
});
|
|
61
65
|
const contextData = {
|
|
62
66
|
type: "elysia",
|
|
63
67
|
parallel: true,
|
|
@@ -68,30 +72,25 @@ function bind(app, data, opts = {}) {
|
|
|
68
72
|
tag,
|
|
69
73
|
func,
|
|
70
74
|
app,
|
|
71
|
-
...
|
|
72
|
-
getCookie: /* @__PURE__ */
|
|
73
|
-
setCookie: /* @__PURE__ */
|
|
75
|
+
..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, c.headers),
|
|
76
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
77
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
74
78
|
...opts2,
|
|
75
79
|
value
|
|
76
80
|
}), "setCookie"),
|
|
77
|
-
delCookie: /* @__PURE__ */
|
|
78
|
-
redirect: /* @__PURE__ */
|
|
79
|
-
setResHeaders: /* @__PURE__ */
|
|
80
|
-
setResStatus: /* @__PURE__ */
|
|
81
|
-
getRequest: /* @__PURE__ */
|
|
81
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
|
|
82
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
83
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
|
|
84
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
|
|
85
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
|
|
82
86
|
throw new Error("elysia can't support getRequest");
|
|
83
87
|
}, "getRequest"),
|
|
84
|
-
getResponse: /* @__PURE__ */
|
|
88
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
|
|
85
89
|
throw new Error("elysia can't support getResponse");
|
|
86
90
|
}, "getResponse")
|
|
87
91
|
};
|
|
88
|
-
const context = new (0,
|
|
89
|
-
context.run(
|
|
90
|
-
globalGuards,
|
|
91
|
-
globalInterceptors,
|
|
92
|
-
globalFilter,
|
|
93
|
-
globalPipe
|
|
94
|
-
}, resolve, resolve);
|
|
92
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
|
|
93
|
+
context.run(aop, resolve, resolve);
|
|
95
94
|
});
|
|
96
95
|
})).then((ret) => {
|
|
97
96
|
return ret;
|
|
@@ -100,16 +99,26 @@ function bind(app, data, opts = {}) {
|
|
|
100
99
|
return errorHandler(e);
|
|
101
100
|
}
|
|
102
101
|
});
|
|
102
|
+
app.use(parallelRouter);
|
|
103
103
|
}
|
|
104
|
-
app.use(parallelRouter);
|
|
105
104
|
for (const [tag, record] of metaMap) {
|
|
106
105
|
for (const func in record) {
|
|
107
106
|
const meta2 = metaMap.get(tag)[func];
|
|
108
|
-
const { data: { define,
|
|
109
|
-
const
|
|
107
|
+
const { data: { define, addons, http } } = meta2;
|
|
108
|
+
const subApp = new (0, _elysia.Elysia)({
|
|
109
|
+
prefix: ""
|
|
110
|
+
});
|
|
110
111
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
let aop;
|
|
113
|
+
if (!dynamic) {
|
|
114
|
+
aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
115
|
+
globalFilter,
|
|
116
|
+
globalGuards,
|
|
117
|
+
globalPipe
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(addons, subApp, "elysia");
|
|
121
|
+
subApp[http.type](http.prefix + http.route, async (c) => {
|
|
113
122
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
114
123
|
const contextData = {
|
|
115
124
|
type: "elysia",
|
|
@@ -123,45 +132,54 @@ function bind(app, data, opts = {}) {
|
|
|
123
132
|
params: c.params,
|
|
124
133
|
headers: c.headers,
|
|
125
134
|
app,
|
|
126
|
-
getCookie: /* @__PURE__ */
|
|
127
|
-
setCookie: /* @__PURE__ */
|
|
135
|
+
getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
136
|
+
setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
128
137
|
...opts2,
|
|
129
138
|
value
|
|
130
139
|
}), "setCookie"),
|
|
131
|
-
delCookie: /* @__PURE__ */
|
|
132
|
-
redirect: /* @__PURE__ */
|
|
133
|
-
setResHeaders: /* @__PURE__ */
|
|
134
|
-
setResStatus: /* @__PURE__ */
|
|
135
|
-
getRequest: /* @__PURE__ */
|
|
140
|
+
delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
|
|
141
|
+
redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
142
|
+
setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
|
|
143
|
+
setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
|
|
144
|
+
getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
|
|
136
145
|
throw new Error("elysia can't support getRequest");
|
|
137
146
|
}, "getRequest"),
|
|
138
|
-
getResponse: /* @__PURE__ */
|
|
147
|
+
getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
|
|
139
148
|
throw new Error("elysia can't support getResponse");
|
|
140
149
|
}, "getResponse")
|
|
141
150
|
};
|
|
142
|
-
|
|
151
|
+
if (dynamic) {
|
|
152
|
+
aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
153
|
+
globalFilter,
|
|
154
|
+
globalGuards,
|
|
155
|
+
globalPipe
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
|
|
143
159
|
if (http.headers) c.set.headers = http.headers;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
if (dynamic) {
|
|
161
|
+
aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
162
|
+
globalFilter,
|
|
163
|
+
globalGuards,
|
|
164
|
+
globalPipe
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return context.run(aop, (returnData) => returnData, (err) => {
|
|
150
168
|
c.set.status = err.status;
|
|
151
169
|
return err;
|
|
152
170
|
});
|
|
153
171
|
}, define.elysia);
|
|
154
|
-
app.use(
|
|
172
|
+
app.use(subApp);
|
|
155
173
|
}
|
|
156
174
|
}
|
|
157
175
|
}
|
|
158
|
-
|
|
176
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
159
177
|
}
|
|
160
|
-
|
|
178
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
|
|
161
179
|
function Elysia(opts) {
|
|
162
|
-
return
|
|
180
|
+
return _chunkMBCHNDAYjs.Define.call(void 0, "elysia", opts);
|
|
163
181
|
}
|
|
164
|
-
|
|
182
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Elysia, "Elysia");
|
|
165
183
|
|
|
166
184
|
|
|
167
185
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Define
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-HMVLXNV3.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-P75VKZJY.mjs";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
14
14
|
|
|
15
|
-
// src/
|
|
15
|
+
// src/http/elysia/bind.ts
|
|
16
16
|
import Debug from "debug";
|
|
17
17
|
import { Elysia as App } from "elysia";
|
|
18
18
|
var debug = Debug("phecda-server/elysia");
|
|
19
19
|
function bind(app, data, opts = {}) {
|
|
20
|
-
const { globalGuards,
|
|
20
|
+
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
21
21
|
const { moduleMap, meta } = data;
|
|
22
22
|
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
23
23
|
const { controller, http, func, tag } = meta2.data;
|
|
@@ -27,19 +27,18 @@ function bind(app, data, opts = {}) {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
detectAopDep(meta, {
|
|
30
|
-
|
|
31
|
-
...
|
|
32
|
-
...
|
|
30
|
+
addons: [
|
|
31
|
+
...globalAddons,
|
|
32
|
+
...parallelAddons
|
|
33
33
|
],
|
|
34
|
-
guards: globalGuards
|
|
35
|
-
interceptors: globalInterceptors
|
|
34
|
+
guards: globalGuards
|
|
36
35
|
});
|
|
37
36
|
registerRoute();
|
|
38
|
-
|
|
39
|
-
Context.
|
|
40
|
-
const parallelRouter = new App();
|
|
41
|
-
Context.usePlugin(parallelPlugins, "elysia").forEach((p) => p(parallelRouter));
|
|
37
|
+
function registerRoute() {
|
|
38
|
+
Context.applyAddons(globalAddons, app, "elysia");
|
|
42
39
|
if (parallelRoute) {
|
|
40
|
+
const parallelRouter = new App();
|
|
41
|
+
Context.applyAddons(parallelAddons, app, "elysia");
|
|
43
42
|
parallelRouter.post(parallelRoute, async (c) => {
|
|
44
43
|
const { body } = c;
|
|
45
44
|
async function errorHandler(e) {
|
|
@@ -58,6 +57,11 @@ function bind(app, data, opts = {}) {
|
|
|
58
57
|
const meta2 = metaMap.get(tag)[func];
|
|
59
58
|
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
60
59
|
const { data: { params } } = meta2;
|
|
60
|
+
const aop = Context.getAop(meta2, {
|
|
61
|
+
globalGuards,
|
|
62
|
+
globalFilter,
|
|
63
|
+
globalPipe
|
|
64
|
+
});
|
|
61
65
|
const contextData = {
|
|
62
66
|
type: "elysia",
|
|
63
67
|
parallel: true,
|
|
@@ -86,12 +90,7 @@ function bind(app, data, opts = {}) {
|
|
|
86
90
|
}, "getResponse")
|
|
87
91
|
};
|
|
88
92
|
const context = new Context(contextData);
|
|
89
|
-
context.run(
|
|
90
|
-
globalGuards,
|
|
91
|
-
globalInterceptors,
|
|
92
|
-
globalFilter,
|
|
93
|
-
globalPipe
|
|
94
|
-
}, resolve, resolve);
|
|
93
|
+
context.run(aop, resolve, resolve);
|
|
95
94
|
});
|
|
96
95
|
})).then((ret) => {
|
|
97
96
|
return ret;
|
|
@@ -100,16 +99,26 @@ function bind(app, data, opts = {}) {
|
|
|
100
99
|
return errorHandler(e);
|
|
101
100
|
}
|
|
102
101
|
});
|
|
102
|
+
app.use(parallelRouter);
|
|
103
103
|
}
|
|
104
|
-
app.use(parallelRouter);
|
|
105
104
|
for (const [tag, record] of metaMap) {
|
|
106
105
|
for (const func in record) {
|
|
107
106
|
const meta2 = metaMap.get(tag)[func];
|
|
108
|
-
const { data: { define,
|
|
109
|
-
const
|
|
107
|
+
const { data: { define, addons, http } } = meta2;
|
|
108
|
+
const subApp = new App({
|
|
109
|
+
prefix: ""
|
|
110
|
+
});
|
|
110
111
|
if (!http?.type) continue;
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
let aop;
|
|
113
|
+
if (!dynamic) {
|
|
114
|
+
aop = Context.getAop(meta2, {
|
|
115
|
+
globalFilter,
|
|
116
|
+
globalGuards,
|
|
117
|
+
globalPipe
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
Context.applyAddons(addons, subApp, "elysia");
|
|
121
|
+
subApp[http.type](http.prefix + http.route, async (c) => {
|
|
113
122
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
114
123
|
const contextData = {
|
|
115
124
|
type: "elysia",
|
|
@@ -139,19 +148,28 @@ function bind(app, data, opts = {}) {
|
|
|
139
148
|
throw new Error("elysia can't support getResponse");
|
|
140
149
|
}, "getResponse")
|
|
141
150
|
};
|
|
151
|
+
if (dynamic) {
|
|
152
|
+
aop = Context.getAop(meta2, {
|
|
153
|
+
globalFilter,
|
|
154
|
+
globalGuards,
|
|
155
|
+
globalPipe
|
|
156
|
+
});
|
|
157
|
+
}
|
|
142
158
|
const context = new Context(contextData);
|
|
143
159
|
if (http.headers) c.set.headers = http.headers;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
if (dynamic) {
|
|
161
|
+
aop = Context.getAop(meta2, {
|
|
162
|
+
globalFilter,
|
|
163
|
+
globalGuards,
|
|
164
|
+
globalPipe
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return context.run(aop, (returnData) => returnData, (err) => {
|
|
150
168
|
c.set.status = err.status;
|
|
151
169
|
return err;
|
|
152
170
|
});
|
|
153
171
|
}, define.elysia);
|
|
154
|
-
app.use(
|
|
172
|
+
app.use(subApp);
|
|
155
173
|
}
|
|
156
174
|
}
|
|
157
175
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-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 ExpressCtx extends HttpContext {
|
|
@@ -12,7 +12,7 @@ interface ExpressCtx extends HttpContext {
|
|
|
12
12
|
next: Function;
|
|
13
13
|
app: Router;
|
|
14
14
|
}
|
|
15
|
-
type
|
|
15
|
+
type Addon = RequestHandler;
|
|
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 ExpressCtx, bind };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as HttpContext, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpContext, a as HttpOptions } from '../../types-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 ExpressCtx extends HttpContext {
|
|
@@ -12,7 +12,7 @@ interface ExpressCtx extends HttpContext {
|
|
|
12
12
|
next: Function;
|
|
13
13
|
app: Router;
|
|
14
14
|
}
|
|
15
|
-
type
|
|
15
|
+
type Addon = RequestHandler;
|
|
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 ExpressCtx, bind };
|