phecda-server 7.0.0-alpha.7 → 7.0.0-alpha.9
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 +10 -1
- package/dist/{chunk-M5HGFUCV.js → chunk-5RBTN33A.js} +23 -3
- package/dist/{chunk-RGSKKTHD.mjs → chunk-7ZGYJ5OW.mjs} +88 -54
- package/dist/{chunk-IRXNF6ZE.mjs → chunk-CVPZWDXU.mjs} +39 -30
- package/dist/{chunk-MENRZSGW.js → chunk-FX3LDQII.js} +88 -79
- package/dist/{chunk-C5BVKEGW.mjs → chunk-FXTJ3BJ6.mjs} +25 -5
- package/dist/{chunk-XSMUJ77A.js → chunk-KJUD2BKE.js} +103 -69
- package/dist/{chunk-JPSXNDXP.mjs → chunk-ODVWOXVB.mjs} +1 -1
- package/dist/{chunk-VYMSCWXC.js → chunk-V5EYXVJT.js} +24 -24
- package/dist/{core-DU7gQKSk.d.mts → core-BDkhrEyf.d.mts} +4 -3
- package/dist/{core-CzElxZoF.d.ts → core-D_cz0tKa.d.ts} +4 -3
- package/dist/helper.d.mts +7 -5
- package/dist/helper.d.ts +7 -5
- package/dist/helper.js +8 -3
- package/dist/helper.mjs +10 -5
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +41 -44
- package/dist/http/elysia/index.mjs +7 -10
- package/dist/http/express/index.d.mts +4 -4
- package/dist/http/express/index.d.ts +4 -4
- package/dist/http/express/index.js +38 -41
- package/dist/http/express/index.mjs +7 -10
- package/dist/http/fastify/index.d.mts +4 -4
- package/dist/http/fastify/index.d.ts +4 -4
- package/dist/http/fastify/index.js +39 -42
- package/dist/http/fastify/index.mjs +7 -10
- package/dist/http/h3/index.d.mts +4 -4
- package/dist/http/h3/index.d.ts +4 -4
- package/dist/http/h3/index.js +39 -42
- package/dist/http/h3/index.mjs +7 -10
- package/dist/http/hono/index.d.mts +4 -4
- package/dist/http/hono/index.d.ts +4 -4
- package/dist/http/hono/index.js +35 -39
- package/dist/http/hono/index.mjs +3 -7
- package/dist/http/hyper-express/index.d.mts +4 -4
- package/dist/http/hyper-express/index.d.ts +4 -4
- package/dist/http/hyper-express/index.js +36 -39
- package/dist/http/hyper-express/index.mjs +6 -9
- package/dist/http/koa/index.d.mts +4 -4
- package/dist/http/koa/index.d.ts +4 -4
- package/dist/http/koa/index.js +38 -41
- package/dist/http/koa/index.mjs +7 -10
- package/dist/index.d.mts +35 -33
- package/dist/index.d.ts +35 -33
- package/dist/index.js +42 -43
- package/dist/index.mjs +15 -16
- package/dist/{meta-BTnLXuCa.d.ts → meta-BX5jhe4Z.d.mts} +3 -4
- package/dist/{meta-BTnLXuCa.d.mts → meta-BX5jhe4Z.d.ts} +3 -4
- package/dist/rpc/bullmq/index.d.mts +4 -4
- package/dist/rpc/bullmq/index.d.ts +4 -4
- package/dist/rpc/bullmq/index.js +14 -14
- package/dist/rpc/bullmq/index.mjs +3 -3
- package/dist/rpc/kafka/index.d.mts +4 -4
- package/dist/rpc/kafka/index.d.ts +4 -4
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +2 -2
- package/dist/rpc/nats/index.d.mts +4 -4
- package/dist/rpc/nats/index.d.ts +4 -4
- package/dist/rpc/nats/index.js +13 -13
- package/dist/rpc/nats/index.mjs +3 -3
- package/dist/rpc/rabbitmq/index.d.mts +4 -4
- package/dist/rpc/rabbitmq/index.d.ts +4 -4
- package/dist/rpc/rabbitmq/index.js +15 -15
- package/dist/rpc/rabbitmq/index.mjs +3 -3
- package/dist/rpc/redis/index.d.mts +4 -4
- package/dist/rpc/redis/index.d.ts +4 -4
- package/dist/rpc/redis/index.js +13 -13
- package/dist/rpc/redis/index.mjs +3 -3
- 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-CbfaGkPA.d.ts → types-B-rUM9Fm.d.mts} +3 -3
- package/dist/{types--E-OCZhC.d.ts → types-CMeuFoyd.d.ts} +3 -3
- package/dist/{types-BxlzVoRv.d.mts → types-DKVhyZk_.d.mts} +3 -3
- package/dist/{types-BYqBeqrs.d.mts → types-MxxtkZXw.d.ts} +3 -3
- package/package.json +3 -2
- package/register/index.mjs +20 -11
- package/register/loader.mjs +13 -28
|
@@ -1,16 +1,16 @@
|
|
|
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 _chunkV5EYXVJTjs = require('../../chunk-V5EYXVJT.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
|
|
14
14
|
|
|
15
15
|
// src/http/elysia/bind.ts
|
|
16
16
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
@@ -19,14 +19,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/elysia");
|
|
|
19
19
|
function bind(app, data, opts = {}) {
|
|
20
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 = _chunkFX3LDQIIjs.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
|
-
|
|
29
|
+
_chunkFX3LDQIIjs.detectAopDep.call(void 0, meta, {
|
|
30
30
|
addons: [
|
|
31
31
|
...globalAddons,
|
|
32
32
|
...parallelAddons
|
|
@@ -35,29 +35,28 @@ function bind(app, data, opts = {}) {
|
|
|
35
35
|
});
|
|
36
36
|
registerRoute();
|
|
37
37
|
function registerRoute() {
|
|
38
|
-
|
|
38
|
+
_chunkFX3LDQIIjs.Context.applyAddons(globalAddons, app, "elysia");
|
|
39
39
|
if (parallelRoute) {
|
|
40
40
|
const parallelRouter = new (0, _elysia.Elysia)();
|
|
41
|
-
|
|
41
|
+
_chunkFX3LDQIIjs.Context.applyAddons(parallelAddons, app, "elysia");
|
|
42
42
|
parallelRouter.post(parallelRoute, async (c) => {
|
|
43
43
|
const { body } = c;
|
|
44
44
|
async function errorHandler(e) {
|
|
45
|
-
const error = await
|
|
45
|
+
const error = await _chunkFX3LDQIIjs.Context.filterRecord.default(e);
|
|
46
46
|
c.set.status = error.status;
|
|
47
47
|
return error;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
49
|
+
_chunk5RBTN33Ajs.__name.call(void 0, errorHandler, "errorHandler");
|
|
50
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkFX3LDQIIjs.BadRequestException)("data format should be an array"));
|
|
51
51
|
try {
|
|
52
52
|
return Promise.all(body.map((item, i) => {
|
|
53
53
|
return new Promise(async (resolve) => {
|
|
54
54
|
const { tag, func } = item;
|
|
55
55
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
56
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
56
|
+
if (!metaMap.has(tag)) return resolve(await _chunkFX3LDQIIjs.Context.filterRecord.default(new (0, _chunkFX3LDQIIjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
57
57
|
const meta2 = metaMap.get(tag)[func];
|
|
58
|
-
if (!meta2) return resolve(await
|
|
59
|
-
const
|
|
60
|
-
const aop = _chunkMENRZSGWjs.Context.getAop(meta2, {
|
|
58
|
+
if (!meta2) return resolve(await _chunkFX3LDQIIjs.Context.filterRecord.default(new (0, _chunkFX3LDQIIjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
59
|
+
const aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
61
60
|
globalGuards,
|
|
62
61
|
globalFilter,
|
|
63
62
|
globalPipe
|
|
@@ -70,27 +69,25 @@ function bind(app, data, opts = {}) {
|
|
|
70
69
|
index: i,
|
|
71
70
|
meta: meta2,
|
|
72
71
|
moduleMap,
|
|
73
|
-
tag,
|
|
74
|
-
func,
|
|
75
72
|
app,
|
|
76
|
-
...
|
|
77
|
-
getCookie: /* @__PURE__ */
|
|
78
|
-
setCookie: /* @__PURE__ */
|
|
73
|
+
...item,
|
|
74
|
+
getCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
75
|
+
setCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
79
76
|
...opts2,
|
|
80
77
|
value
|
|
81
78
|
}), "setCookie"),
|
|
82
|
-
delCookie: /* @__PURE__ */
|
|
83
|
-
redirect: /* @__PURE__ */
|
|
84
|
-
setResHeaders: /* @__PURE__ */
|
|
85
|
-
setResStatus: /* @__PURE__ */
|
|
86
|
-
getRequest: /* @__PURE__ */
|
|
79
|
+
delCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
|
|
80
|
+
redirect: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
81
|
+
setResHeaders: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
|
|
82
|
+
setResStatus: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
|
|
83
|
+
getRequest: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => {
|
|
87
84
|
throw new Error("elysia can't support getRequest");
|
|
88
85
|
}, "getRequest"),
|
|
89
|
-
getResponse: /* @__PURE__ */
|
|
86
|
+
getResponse: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => {
|
|
90
87
|
throw new Error("elysia can't support getResponse");
|
|
91
88
|
}, "getResponse")
|
|
92
89
|
};
|
|
93
|
-
const context = new (0,
|
|
90
|
+
const context = new (0, _chunkFX3LDQIIjs.Context)(contextData);
|
|
94
91
|
context.run(aop, resolve, resolve);
|
|
95
92
|
});
|
|
96
93
|
})).then((ret) => {
|
|
@@ -112,14 +109,14 @@ function bind(app, data, opts = {}) {
|
|
|
112
109
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
113
110
|
let aop;
|
|
114
111
|
if (!dynamic) {
|
|
115
|
-
aop =
|
|
112
|
+
aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
116
113
|
globalFilter,
|
|
117
114
|
globalGuards,
|
|
118
115
|
globalPipe
|
|
119
116
|
});
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
subApp[http.type](http.prefix
|
|
118
|
+
_chunkFX3LDQIIjs.Context.applyAddons(addons, subApp, "elysia");
|
|
119
|
+
subApp[http.type](_chunkFX3LDQIIjs.joinUrl.call(void 0, http.prefix, http.route), async (c) => {
|
|
123
120
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
124
121
|
const contextData = {
|
|
125
122
|
type: "elysia",
|
|
@@ -134,33 +131,33 @@ function bind(app, data, opts = {}) {
|
|
|
134
131
|
params: c.params,
|
|
135
132
|
headers: c.headers,
|
|
136
133
|
app,
|
|
137
|
-
getCookie: /* @__PURE__ */
|
|
138
|
-
setCookie: /* @__PURE__ */
|
|
134
|
+
getCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
135
|
+
setCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
139
136
|
...opts2,
|
|
140
137
|
value
|
|
141
138
|
}), "setCookie"),
|
|
142
|
-
delCookie: /* @__PURE__ */
|
|
143
|
-
redirect: /* @__PURE__ */
|
|
144
|
-
setResHeaders: /* @__PURE__ */
|
|
145
|
-
setResStatus: /* @__PURE__ */
|
|
146
|
-
getRequest: /* @__PURE__ */
|
|
139
|
+
delCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
|
|
140
|
+
redirect: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
141
|
+
setResHeaders: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
|
|
142
|
+
setResStatus: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
|
|
143
|
+
getRequest: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => {
|
|
147
144
|
throw new Error("elysia can't support getRequest");
|
|
148
145
|
}, "getRequest"),
|
|
149
|
-
getResponse: /* @__PURE__ */
|
|
146
|
+
getResponse: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => {
|
|
150
147
|
throw new Error("elysia can't support getResponse");
|
|
151
148
|
}, "getResponse")
|
|
152
149
|
};
|
|
153
150
|
if (dynamic) {
|
|
154
|
-
aop =
|
|
151
|
+
aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
155
152
|
globalFilter,
|
|
156
153
|
globalGuards,
|
|
157
154
|
globalPipe
|
|
158
155
|
});
|
|
159
156
|
}
|
|
160
|
-
const context = new (0,
|
|
157
|
+
const context = new (0, _chunkFX3LDQIIjs.Context)(contextData);
|
|
161
158
|
if (http.headers) c.set.headers = http.headers;
|
|
162
159
|
if (dynamic) {
|
|
163
|
-
aop =
|
|
160
|
+
aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
164
161
|
globalFilter,
|
|
165
162
|
globalGuards,
|
|
166
163
|
globalPipe
|
|
@@ -175,13 +172,13 @@ function bind(app, data, opts = {}) {
|
|
|
175
172
|
}
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
|
-
|
|
175
|
+
_chunk5RBTN33Ajs.__name.call(void 0, registerRoute, "registerRoute");
|
|
179
176
|
}
|
|
180
|
-
|
|
177
|
+
_chunk5RBTN33Ajs.__name.call(void 0, bind, "bind");
|
|
181
178
|
function Elysia(opts) {
|
|
182
|
-
return
|
|
179
|
+
return _chunkV5EYXVJTjs.Define.call(void 0, "elysia", opts);
|
|
183
180
|
}
|
|
184
|
-
|
|
181
|
+
_chunk5RBTN33Ajs.__name.call(void 0, Elysia, "Elysia");
|
|
185
182
|
|
|
186
183
|
|
|
187
184
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Define
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-ODVWOXVB.mjs";
|
|
4
4
|
import {
|
|
5
5
|
BadRequestException,
|
|
6
6
|
Context,
|
|
7
|
-
argToReq,
|
|
8
7
|
createControllerMetaMap,
|
|
9
|
-
detectAopDep
|
|
10
|
-
|
|
8
|
+
detectAopDep,
|
|
9
|
+
joinUrl
|
|
10
|
+
} from "../../chunk-CVPZWDXU.mjs";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-FXTJ3BJ6.mjs";
|
|
14
14
|
|
|
15
15
|
// src/http/elysia/bind.ts
|
|
16
16
|
import Debug from "debug";
|
|
@@ -56,7 +56,6 @@ function bind(app, data, opts = {}) {
|
|
|
56
56
|
if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
57
57
|
const meta2 = metaMap.get(tag)[func];
|
|
58
58
|
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
59
|
-
const { data: { params } } = meta2;
|
|
60
59
|
const aop = Context.getAop(meta2, {
|
|
61
60
|
globalGuards,
|
|
62
61
|
globalFilter,
|
|
@@ -70,10 +69,8 @@ function bind(app, data, opts = {}) {
|
|
|
70
69
|
index: i,
|
|
71
70
|
meta: meta2,
|
|
72
71
|
moduleMap,
|
|
73
|
-
tag,
|
|
74
|
-
func,
|
|
75
72
|
app,
|
|
76
|
-
...
|
|
73
|
+
...item,
|
|
77
74
|
getCookie: /* @__PURE__ */ __name((key) => c.cookie[key].value, "getCookie"),
|
|
78
75
|
setCookie: /* @__PURE__ */ __name((key, value, opts2 = {}) => c.cookie[key].set({
|
|
79
76
|
...opts2,
|
|
@@ -119,7 +116,7 @@ function bind(app, data, opts = {}) {
|
|
|
119
116
|
});
|
|
120
117
|
}
|
|
121
118
|
Context.applyAddons(addons, subApp, "elysia");
|
|
122
|
-
subApp[http.type](http.prefix
|
|
119
|
+
subApp[http.type](joinUrl(http.prefix, http.route), async (c) => {
|
|
123
120
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
124
121
|
const contextData = {
|
|
125
122
|
type: "elysia",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-DKVhyZk_.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BDkhrEyf.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-BX5jhe4Z.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
|
-
interface ExpressCtx extends
|
|
8
|
+
interface ExpressCtx extends HttpCtx {
|
|
9
9
|
type: 'express';
|
|
10
10
|
request: Request;
|
|
11
11
|
response: Response;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-CMeuFoyd.js';
|
|
3
|
+
import { F as Factory } from '../../core-D_cz0tKa.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-BX5jhe4Z.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
|
-
interface ExpressCtx extends
|
|
8
|
+
interface ExpressCtx extends HttpCtx {
|
|
9
9
|
type: 'express';
|
|
10
10
|
request: Request;
|
|
11
11
|
response: Response;
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
|
|
7
8
|
|
|
8
|
-
var _chunkMENRZSGWjs = require('../../chunk-MENRZSGW.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
|
|
12
12
|
|
|
13
13
|
// src/http/express/bind.ts
|
|
14
14
|
var _express = require('express');
|
|
@@ -18,14 +18,14 @@ function bind(router, data, opts = {}) {
|
|
|
18
18
|
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
19
19
|
const { moduleMap, meta } = data;
|
|
20
20
|
const originStack = router.stack.slice(0, router.stack.length);
|
|
21
|
-
const metaMap =
|
|
21
|
+
const metaMap = _chunkFX3LDQIIjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
22
22
|
const { controller, http, func, tag } = meta2.data;
|
|
23
23
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
24
24
|
debug(`register method "${func}" in module "${tag}"`);
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
|
|
28
|
+
_chunkFX3LDQIIjs.detectAopDep.call(void 0, meta, {
|
|
29
29
|
addons: [
|
|
30
30
|
...globalAddons,
|
|
31
31
|
...parallelAddons
|
|
@@ -33,33 +33,32 @@ function bind(router, data, opts = {}) {
|
|
|
33
33
|
guards: globalGuards
|
|
34
34
|
});
|
|
35
35
|
registerRoute();
|
|
36
|
-
|
|
36
|
+
_chunk5RBTN33Ajs.HMR.call(void 0, async () => {
|
|
37
37
|
router.stack = originStack;
|
|
38
38
|
registerRoute();
|
|
39
39
|
});
|
|
40
40
|
function registerRoute() {
|
|
41
|
-
|
|
41
|
+
_chunkFX3LDQIIjs.Context.applyAddons(globalAddons, router, "express");
|
|
42
42
|
if (parallelRoute) {
|
|
43
43
|
const subRouter = _express.Router.call(void 0, );
|
|
44
|
-
|
|
44
|
+
_chunkFX3LDQIIjs.Context.applyAddons(parallelAddons, subRouter, "express");
|
|
45
45
|
subRouter.use(async (req, res, next) => {
|
|
46
46
|
const { body } = req;
|
|
47
47
|
async function errorHandler(e) {
|
|
48
|
-
const error = await
|
|
48
|
+
const error = await _chunkFX3LDQIIjs.Context.filterRecord.default(e);
|
|
49
49
|
return res.status(error.status).json(error);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
51
|
+
_chunk5RBTN33Ajs.__name.call(void 0, errorHandler, "errorHandler");
|
|
52
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkFX3LDQIIjs.BadRequestException)("data format should be an array"));
|
|
53
53
|
try {
|
|
54
54
|
return Promise.all(body.map((item, i) => {
|
|
55
55
|
return new Promise(async (resolve) => {
|
|
56
56
|
const { tag, func } = item;
|
|
57
57
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
58
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
58
|
+
if (!metaMap.has(tag)) return resolve(await _chunkFX3LDQIIjs.Context.filterRecord.default(new (0, _chunkFX3LDQIIjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
59
59
|
const meta2 = metaMap.get(tag)[func];
|
|
60
|
-
if (!meta2) return resolve(await
|
|
61
|
-
const
|
|
62
|
-
const aop = _chunkMENRZSGWjs.Context.getAop(meta2, {
|
|
60
|
+
if (!meta2) return resolve(await _chunkFX3LDQIIjs.Context.filterRecord.default(new (0, _chunkFX3LDQIIjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
61
|
+
const aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
63
62
|
globalFilter,
|
|
64
63
|
globalGuards,
|
|
65
64
|
globalPipe
|
|
@@ -73,23 +72,21 @@ function bind(router, data, opts = {}) {
|
|
|
73
72
|
meta: meta2,
|
|
74
73
|
response: res,
|
|
75
74
|
moduleMap,
|
|
76
|
-
tag,
|
|
77
|
-
func,
|
|
78
75
|
next,
|
|
79
76
|
app: router,
|
|
80
|
-
...
|
|
81
|
-
getCookie: /* @__PURE__ */
|
|
82
|
-
setCookie: /* @__PURE__ */
|
|
83
|
-
delCookie: /* @__PURE__ */
|
|
77
|
+
...item,
|
|
78
|
+
getCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
|
|
79
|
+
setCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
|
|
80
|
+
delCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => res.cookie(key, "", {
|
|
84
81
|
expires: /* @__PURE__ */ new Date(0)
|
|
85
82
|
}), "delCookie"),
|
|
86
|
-
redirect: /* @__PURE__ */
|
|
87
|
-
setResHeaders: /* @__PURE__ */
|
|
88
|
-
setResStatus: /* @__PURE__ */
|
|
89
|
-
getRequest: /* @__PURE__ */
|
|
90
|
-
getResponse: /* @__PURE__ */
|
|
83
|
+
redirect: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
|
|
84
|
+
setResHeaders: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
|
|
85
|
+
setResStatus: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
|
|
86
|
+
getRequest: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => req, "getRequest"),
|
|
87
|
+
getResponse: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => res, "getResponse")
|
|
91
88
|
};
|
|
92
|
-
const context = new (0,
|
|
89
|
+
const context = new (0, _chunkFX3LDQIIjs.Context)(contextData);
|
|
93
90
|
context.run(aop, resolve, resolve);
|
|
94
91
|
});
|
|
95
92
|
})).then((ret) => {
|
|
@@ -108,15 +105,15 @@ function bind(router, data, opts = {}) {
|
|
|
108
105
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
109
106
|
let aop;
|
|
110
107
|
if (!dynamic) {
|
|
111
|
-
aop =
|
|
108
|
+
aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
112
109
|
globalFilter,
|
|
113
110
|
globalGuards,
|
|
114
111
|
globalPipe
|
|
115
112
|
});
|
|
116
113
|
}
|
|
117
114
|
const subRouter = _express.Router.call(void 0, );
|
|
118
|
-
|
|
119
|
-
subRouter[http.type](http.prefix
|
|
115
|
+
_chunkFX3LDQIIjs.Context.applyAddons(addons, subRouter, "express");
|
|
116
|
+
subRouter[http.type](_chunkFX3LDQIIjs.joinUrl.call(void 0, http.prefix, http.route), async (req, res, next) => {
|
|
120
117
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
121
118
|
const contextData = {
|
|
122
119
|
type: "express",
|
|
@@ -133,21 +130,21 @@ function bind(router, data, opts = {}) {
|
|
|
133
130
|
headers: req.headers,
|
|
134
131
|
app: router,
|
|
135
132
|
next,
|
|
136
|
-
getCookie: /* @__PURE__ */
|
|
137
|
-
setCookie: /* @__PURE__ */
|
|
138
|
-
delCookie: /* @__PURE__ */
|
|
133
|
+
getCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
|
|
134
|
+
setCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
|
|
135
|
+
delCookie: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (key) => res.cookie(key, "", {
|
|
139
136
|
expires: /* @__PURE__ */ new Date(0)
|
|
140
137
|
}), "delCookie"),
|
|
141
|
-
redirect: /* @__PURE__ */
|
|
142
|
-
setResHeaders: /* @__PURE__ */
|
|
143
|
-
setResStatus: /* @__PURE__ */
|
|
144
|
-
getRequest: /* @__PURE__ */
|
|
145
|
-
getResponse: /* @__PURE__ */
|
|
138
|
+
redirect: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
|
|
139
|
+
setResHeaders: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
|
|
140
|
+
setResStatus: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
|
|
141
|
+
getRequest: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => req, "getRequest"),
|
|
142
|
+
getResponse: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, () => res, "getResponse")
|
|
146
143
|
};
|
|
147
|
-
const context = new (0,
|
|
144
|
+
const context = new (0, _chunkFX3LDQIIjs.Context)(contextData);
|
|
148
145
|
if (http.headers) res.set(http.headers);
|
|
149
146
|
if (dynamic) {
|
|
150
|
-
aop =
|
|
147
|
+
aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
|
|
151
148
|
globalFilter,
|
|
152
149
|
globalGuards,
|
|
153
150
|
globalPipe
|
|
@@ -166,9 +163,9 @@ function bind(router, data, opts = {}) {
|
|
|
166
163
|
}
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
|
-
|
|
166
|
+
_chunk5RBTN33Ajs.__name.call(void 0, registerRoute, "registerRoute");
|
|
170
167
|
}
|
|
171
|
-
|
|
168
|
+
_chunk5RBTN33Ajs.__name.call(void 0, bind, "bind");
|
|
172
169
|
|
|
173
170
|
|
|
174
171
|
exports.bind = bind;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BadRequestException,
|
|
3
3
|
Context,
|
|
4
|
-
HMR,
|
|
5
|
-
argToReq,
|
|
6
4
|
createControllerMetaMap,
|
|
7
|
-
detectAopDep
|
|
8
|
-
|
|
5
|
+
detectAopDep,
|
|
6
|
+
joinUrl
|
|
7
|
+
} from "../../chunk-CVPZWDXU.mjs";
|
|
9
8
|
import {
|
|
9
|
+
HMR,
|
|
10
10
|
__name
|
|
11
|
-
} from "../../chunk-
|
|
11
|
+
} from "../../chunk-FXTJ3BJ6.mjs";
|
|
12
12
|
|
|
13
13
|
// src/http/express/bind.ts
|
|
14
14
|
import { Router } from "express";
|
|
@@ -58,7 +58,6 @@ function bind(router, data, opts = {}) {
|
|
|
58
58
|
if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
59
59
|
const meta2 = metaMap.get(tag)[func];
|
|
60
60
|
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
61
|
-
const { data: { params } } = meta2;
|
|
62
61
|
const aop = Context.getAop(meta2, {
|
|
63
62
|
globalFilter,
|
|
64
63
|
globalGuards,
|
|
@@ -73,11 +72,9 @@ function bind(router, data, opts = {}) {
|
|
|
73
72
|
meta: meta2,
|
|
74
73
|
response: res,
|
|
75
74
|
moduleMap,
|
|
76
|
-
tag,
|
|
77
|
-
func,
|
|
78
75
|
next,
|
|
79
76
|
app: router,
|
|
80
|
-
...
|
|
77
|
+
...item,
|
|
81
78
|
getCookie: /* @__PURE__ */ __name((key) => req.cookies[key], "getCookie"),
|
|
82
79
|
setCookie: /* @__PURE__ */ __name((key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
|
|
83
80
|
delCookie: /* @__PURE__ */ __name((key) => res.cookie(key, "", {
|
|
@@ -116,7 +113,7 @@ function bind(router, data, opts = {}) {
|
|
|
116
113
|
}
|
|
117
114
|
const subRouter = Router();
|
|
118
115
|
Context.applyAddons(addons, subRouter, "express");
|
|
119
|
-
subRouter[http.type](http.prefix
|
|
116
|
+
subRouter[http.type](joinUrl(http.prefix, http.route), async (req, res, next) => {
|
|
120
117
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
121
118
|
const contextData = {
|
|
122
119
|
type: "express",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback, FastifyRegisterOptions, FastifyPluginOptions, RouteShorthandOptions } from 'fastify';
|
|
2
|
-
import { H as
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-DKVhyZk_.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BDkhrEyf.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-BX5jhe4Z.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
|
-
interface FastifyCtx extends
|
|
8
|
+
interface FastifyCtx extends HttpCtx {
|
|
9
9
|
type: 'fastify';
|
|
10
10
|
request: FastifyRequest;
|
|
11
11
|
response: FastifyReply;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback, FastifyRegisterOptions, FastifyPluginOptions, RouteShorthandOptions } from 'fastify';
|
|
2
|
-
import { H as
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-CMeuFoyd.js';
|
|
3
|
+
import { F as Factory } from '../../core-D_cz0tKa.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-BX5jhe4Z.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
|
-
interface FastifyCtx extends
|
|
8
|
+
interface FastifyCtx extends HttpCtx {
|
|
9
9
|
type: 'fastify';
|
|
10
10
|
request: FastifyRequest;
|
|
11
11
|
response: FastifyReply;
|