phecda-server 6.0.1 → 6.1.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/dist/{chunk-YUXERDQ6.mjs → chunk-2CFYUXPM.mjs} +9 -12
- package/dist/{chunk-HDQAT2IM.mjs → chunk-3H3T54IC.mjs} +116 -87
- package/dist/{chunk-TZYATAJX.js → chunk-DVTBLV6I.js} +62 -65
- package/dist/{chunk-UXD62LGG.mjs → chunk-G7TD2VB7.mjs} +10 -2
- package/dist/{chunk-F3W3NN7F.mjs → chunk-J7B24YSE.mjs} +1 -1
- package/dist/{chunk-XCND2QW3.js → chunk-JDV2XJYE.js} +25 -25
- package/dist/chunk-NL6QBQAR.js +266 -0
- package/dist/{chunk-GHFSIZUO.js → chunk-TVT62GIX.js} +11 -3
- package/dist/core-BlN0Spy9.d.ts +47 -0
- package/dist/core-P1CsH6jz.d.mts +47 -0
- package/dist/helper.d.mts +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/index.d.mts +12 -11
- package/dist/index.d.ts +12 -11
- package/dist/index.js +49 -43
- package/dist/index.mjs +19 -13
- package/dist/{types-BlIBlnVT.d.ts → meta-KtfiBIde.d.mts} +44 -44
- package/dist/{types-BlIBlnVT.d.mts → meta-KtfiBIde.d.ts} +44 -44
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +12 -12
- package/dist/rpc/bullmq/index.mjs +2 -2
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +12 -12
- package/dist/rpc/kafka/index.mjs +2 -2
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +11 -11
- package/dist/rpc/nats/index.mjs +2 -2
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +13 -13
- package/dist/rpc/rabbitmq/index.mjs +2 -2
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +11 -11
- package/dist/rpc/redis/index.mjs +2 -2
- package/dist/server/elysia/index.d.mts +3 -3
- package/dist/server/elysia/index.d.ts +3 -3
- package/dist/server/elysia/index.js +44 -32
- package/dist/server/elysia/index.mjs +17 -5
- package/dist/server/express/index.d.mts +3 -3
- package/dist/server/express/index.d.ts +3 -3
- package/dist/server/express/index.js +34 -30
- package/dist/server/express/index.mjs +8 -4
- package/dist/server/fastify/index.d.mts +3 -3
- package/dist/server/fastify/index.d.ts +3 -3
- package/dist/server/fastify/index.js +35 -31
- package/dist/server/fastify/index.mjs +9 -5
- package/dist/server/h3/index.d.mts +3 -3
- package/dist/server/h3/index.d.ts +3 -3
- package/dist/server/h3/index.js +34 -30
- package/dist/server/h3/index.mjs +8 -4
- package/dist/server/hono/index.d.mts +3 -3
- package/dist/server/hono/index.d.ts +3 -3
- package/dist/server/hono/index.js +33 -29
- package/dist/server/hono/index.mjs +8 -4
- package/dist/server/hyper-express/index.d.mts +3 -3
- package/dist/server/hyper-express/index.d.ts +3 -3
- package/dist/server/hyper-express/index.js +33 -29
- package/dist/server/hyper-express/index.mjs +8 -4
- package/dist/server/koa/index.d.mts +3 -3
- package/dist/server/koa/index.d.ts +3 -3
- package/dist/server/koa/index.js +34 -30
- package/dist/server/koa/index.mjs +8 -4
- 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-BCJhmpQh.d.ts → types-BvD3B5Ny.d.mts} +4 -2
- package/dist/{types-Dgxirc9f.d.mts → types-DIw7B6Up.d.ts} +4 -2
- package/dist/{types-B-ZFZajI.d.ts → types-JVT0mgLD.d.ts} +1 -1
- package/dist/{types-AgVwUXPC.d.mts → types-t9D1fU6G.d.mts} +1 -1
- package/package.json +2 -2
- package/dist/chunk-LYEZ6RGX.js +0 -237
- package/dist/core-Blq8frmr.d.ts +0 -30
- package/dist/core-D2oL8Ge0.d.mts +0 -30
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
argToReq,
|
|
5
5
|
createControllerMetaMap,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-2CFYUXPM.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-G7TD2VB7.mjs";
|
|
11
11
|
|
|
12
12
|
// src/server/hyper-express/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
@@ -71,7 +71,9 @@ function bind(router, data, opts = {}) {
|
|
|
71
71
|
delCookie: /* @__PURE__ */ __name((key) => res.clearCookie(key), "delCookie"),
|
|
72
72
|
redirect: /* @__PURE__ */ __name((url) => res.redirect(url), "redirect"),
|
|
73
73
|
setResHeaders: /* @__PURE__ */ __name((headers) => res.set(headers), "setResHeaders"),
|
|
74
|
-
setResStatus: /* @__PURE__ */ __name((code) => res.status(code), "setResStatus")
|
|
74
|
+
setResStatus: /* @__PURE__ */ __name((code) => res.status(code), "setResStatus"),
|
|
75
|
+
getRequest: /* @__PURE__ */ __name(() => req, "getRequest"),
|
|
76
|
+
getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
|
|
75
77
|
};
|
|
76
78
|
const context = new Context(contextData);
|
|
77
79
|
context.run({
|
|
@@ -116,7 +118,9 @@ function bind(router, data, opts = {}) {
|
|
|
116
118
|
delCookie: /* @__PURE__ */ __name((key) => res.clearCookie(key), "delCookie"),
|
|
117
119
|
redirect: /* @__PURE__ */ __name((url) => res.redirect(url), "redirect"),
|
|
118
120
|
setResHeaders: /* @__PURE__ */ __name((headers) => res.set(headers), "setResHeaders"),
|
|
119
|
-
setResStatus: /* @__PURE__ */ __name((code) => res.status(code), "setResStatus")
|
|
121
|
+
setResStatus: /* @__PURE__ */ __name((code) => res.status(code), "setResStatus"),
|
|
122
|
+
getRequest: /* @__PURE__ */ __name(() => req, "getRequest"),
|
|
123
|
+
getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
|
|
120
124
|
};
|
|
121
125
|
const context = new Context(contextData);
|
|
122
126
|
if (http.headers) {
|
|
@@ -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-BvD3B5Ny.mjs';
|
|
4
|
+
import { F as Factory } from '../../core-P1CsH6jz.mjs';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../
|
|
6
|
+
import '../../meta-KtfiBIde.mjs';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface KoaCtx extends HttpContext {
|
|
@@ -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-DIw7B6Up.js';
|
|
4
|
+
import { F as Factory } from '../../core-BlN0Spy9.js';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../
|
|
6
|
+
import '../../meta-KtfiBIde.js';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface KoaCtx extends HttpContext {
|
package/dist/server/koa/index.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkDVTBLV6Ijs = require('../../chunk-DVTBLV6I.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkTVT62GIXjs = require('../../chunk-TVT62GIX.js');
|
|
12
12
|
|
|
13
13
|
// src/server/koa/bind.ts
|
|
14
14
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
@@ -17,14 +17,14 @@ 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
19
|
const originStack = router.stack.slice(0, router.stack.length);
|
|
20
|
-
const metaMap =
|
|
20
|
+
const metaMap = _chunkDVTBLV6Ijs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
21
21
|
const { controller, http, func, tag } = meta2.data;
|
|
22
22
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
23
23
|
debug(`register method "${func}" in module "${tag}"`);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
_chunkDVTBLV6Ijs.detectAopDep.call(void 0, meta, {
|
|
28
28
|
plugins: [
|
|
29
29
|
...globalPlugins,
|
|
30
30
|
...parallelPlugins
|
|
@@ -34,25 +34,25 @@ function bind(router, data, opts = {}) {
|
|
|
34
34
|
});
|
|
35
35
|
registerRoute();
|
|
36
36
|
async function registerRoute() {
|
|
37
|
-
|
|
37
|
+
_chunkDVTBLV6Ijs.Context.usePlugin(globalPlugins, "koa").forEach((p) => router.use(p));
|
|
38
38
|
if (parallelRoute) {
|
|
39
|
-
router.post(parallelRoute, ...
|
|
39
|
+
router.post(parallelRoute, ..._chunkDVTBLV6Ijs.Context.usePlugin(parallelPlugins, "koa"), async (ctx, next) => {
|
|
40
40
|
const { body } = ctx.request;
|
|
41
41
|
async function errorHandler(e) {
|
|
42
|
-
const error = await
|
|
42
|
+
const error = await _chunkDVTBLV6Ijs.Context.filterRecord.default(e);
|
|
43
43
|
ctx.status = error.status;
|
|
44
44
|
ctx.body = error;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
46
|
+
_chunkTVT62GIXjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
47
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkDVTBLV6Ijs.BadRequestException)("data format should be an array"));
|
|
48
48
|
try {
|
|
49
49
|
return Promise.all(body.map((item, i) => {
|
|
50
50
|
return new Promise(async (resolve) => {
|
|
51
51
|
const { tag, func } = item;
|
|
52
52
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
53
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
53
|
+
if (!metaMap.has(tag)) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
54
54
|
const meta2 = metaMap.get(tag)[func];
|
|
55
|
-
if (!meta2) return resolve(await
|
|
55
|
+
if (!meta2) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
56
56
|
const { data: { params } } = meta2;
|
|
57
57
|
const contextData = {
|
|
58
58
|
type: "koa",
|
|
@@ -63,19 +63,21 @@ function bind(router, data, opts = {}) {
|
|
|
63
63
|
parallel: true,
|
|
64
64
|
next,
|
|
65
65
|
app: router,
|
|
66
|
-
...
|
|
66
|
+
..._chunkDVTBLV6Ijs.argToReq.call(void 0, params, item.args, ctx.headers),
|
|
67
67
|
tag,
|
|
68
68
|
func,
|
|
69
|
-
getCookie: /* @__PURE__ */
|
|
70
|
-
setCookie: /* @__PURE__ */
|
|
71
|
-
delCookie: /* @__PURE__ */
|
|
69
|
+
getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
|
|
70
|
+
setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
|
|
71
|
+
delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
|
|
72
72
|
expires: /* @__PURE__ */ new Date(0)
|
|
73
73
|
}), "delCookie"),
|
|
74
|
-
redirect: /* @__PURE__ */
|
|
75
|
-
setResHeaders: /* @__PURE__ */
|
|
76
|
-
setResStatus: /* @__PURE__ */
|
|
74
|
+
redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
|
|
75
|
+
setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
|
|
76
|
+
setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
|
|
77
|
+
getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => ctx.req, "getRequest"),
|
|
78
|
+
getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => ctx.res, "getResponse")
|
|
77
79
|
};
|
|
78
|
-
const context = new (0,
|
|
80
|
+
const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
|
|
79
81
|
context.run({
|
|
80
82
|
globalGuards,
|
|
81
83
|
globalInterceptors,
|
|
@@ -96,7 +98,7 @@ function bind(router, data, opts = {}) {
|
|
|
96
98
|
const meta2 = metaMap.get(tag)[func];
|
|
97
99
|
const { data: { plugins, http } } = meta2;
|
|
98
100
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
99
|
-
router[http.type](http.prefix + http.route, ...
|
|
101
|
+
router[http.type](http.prefix + http.route, ..._chunkDVTBLV6Ijs.Context.usePlugin(plugins, "koa"), async (ctx, next) => {
|
|
100
102
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
101
103
|
const contextData = {
|
|
102
104
|
type: "koa",
|
|
@@ -111,16 +113,18 @@ function bind(router, data, opts = {}) {
|
|
|
111
113
|
body: ctx.request.body,
|
|
112
114
|
headers: ctx.headers,
|
|
113
115
|
next,
|
|
114
|
-
getCookie: /* @__PURE__ */
|
|
115
|
-
setCookie: /* @__PURE__ */
|
|
116
|
-
delCookie: /* @__PURE__ */
|
|
116
|
+
getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
|
|
117
|
+
setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
|
|
118
|
+
delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
|
|
117
119
|
expires: /* @__PURE__ */ new Date(0)
|
|
118
120
|
}), "delCookie"),
|
|
119
|
-
redirect: /* @__PURE__ */
|
|
120
|
-
setResHeaders: /* @__PURE__ */
|
|
121
|
-
setResStatus: /* @__PURE__ */
|
|
121
|
+
redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
|
|
122
|
+
setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
|
|
123
|
+
setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
|
|
124
|
+
getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => ctx.req, "getRequest"),
|
|
125
|
+
getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => ctx.res, "getResponse")
|
|
122
126
|
};
|
|
123
|
-
const context = new (0,
|
|
127
|
+
const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
|
|
124
128
|
if (http.headers) ctx.set(http.headers);
|
|
125
129
|
await context.run({
|
|
126
130
|
globalGuards,
|
|
@@ -139,13 +143,13 @@ function bind(router, data, opts = {}) {
|
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
_chunkTVT62GIXjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
147
|
+
_chunkDVTBLV6Ijs.HMR.call(void 0, async () => {
|
|
144
148
|
router.stack = originStack;
|
|
145
149
|
registerRoute();
|
|
146
150
|
});
|
|
147
151
|
}
|
|
148
|
-
|
|
152
|
+
_chunkTVT62GIXjs.__name.call(void 0, bind, "bind");
|
|
149
153
|
|
|
150
154
|
|
|
151
155
|
exports.bind = bind;
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
argToReq,
|
|
6
6
|
createControllerMetaMap,
|
|
7
7
|
detectAopDep
|
|
8
|
-
} from "../../chunk-
|
|
8
|
+
} from "../../chunk-2CFYUXPM.mjs";
|
|
9
9
|
import {
|
|
10
10
|
__name
|
|
11
|
-
} from "../../chunk-
|
|
11
|
+
} from "../../chunk-G7TD2VB7.mjs";
|
|
12
12
|
|
|
13
13
|
// src/server/koa/bind.ts
|
|
14
14
|
import Debug from "debug";
|
|
@@ -73,7 +73,9 @@ function bind(router, data, opts = {}) {
|
|
|
73
73
|
}), "delCookie"),
|
|
74
74
|
redirect: /* @__PURE__ */ __name((url) => ctx.redirect(url), "redirect"),
|
|
75
75
|
setResHeaders: /* @__PURE__ */ __name((headers) => ctx.set(headers), "setResHeaders"),
|
|
76
|
-
setResStatus: /* @__PURE__ */ __name((status) => ctx.status = status, "setResStatus")
|
|
76
|
+
setResStatus: /* @__PURE__ */ __name((status) => ctx.status = status, "setResStatus"),
|
|
77
|
+
getRequest: /* @__PURE__ */ __name(() => ctx.req, "getRequest"),
|
|
78
|
+
getResponse: /* @__PURE__ */ __name(() => ctx.res, "getResponse")
|
|
77
79
|
};
|
|
78
80
|
const context = new Context(contextData);
|
|
79
81
|
context.run({
|
|
@@ -118,7 +120,9 @@ function bind(router, data, opts = {}) {
|
|
|
118
120
|
}), "delCookie"),
|
|
119
121
|
redirect: /* @__PURE__ */ __name((url) => ctx.redirect(url), "redirect"),
|
|
120
122
|
setResHeaders: /* @__PURE__ */ __name((headers) => ctx.set(headers), "setResHeaders"),
|
|
121
|
-
setResStatus: /* @__PURE__ */ __name((status) => ctx.status = status, "setResStatus")
|
|
123
|
+
setResStatus: /* @__PURE__ */ __name((status) => ctx.status = status, "setResStatus"),
|
|
124
|
+
getRequest: /* @__PURE__ */ __name(() => ctx.req, "getRequest"),
|
|
125
|
+
getResponse: /* @__PURE__ */ __name(() => ctx.res, "getResponse")
|
|
122
126
|
};
|
|
123
127
|
const context = new Context(contextData);
|
|
124
128
|
if (http.headers) ctx.set(http.headers);
|
package/dist/test.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import * as supertest from 'supertest';
|
|
|
2
2
|
import { Test } from 'supertest';
|
|
3
3
|
import { Server } from 'node:http';
|
|
4
4
|
import { Construct } from 'phecda-core';
|
|
5
|
-
import { F as Factory } from './core-
|
|
6
|
-
import { P as PickFunc } from './
|
|
5
|
+
import { F as Factory } from './core-P1CsH6jz.mjs';
|
|
6
|
+
import { P as PickFunc } from './meta-KtfiBIde.mjs';
|
|
7
7
|
|
|
8
8
|
declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
9
9
|
get<C extends T[number]>(Model: C): InstanceType<C>;
|
|
@@ -11,7 +11,7 @@ declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
|
11
11
|
type SuperTestRequest<T> = {
|
|
12
12
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
13
|
};
|
|
14
|
-
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "
|
|
14
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "key" | "query" | "use" | "on" | "set" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
|
|
15
15
|
module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
|
|
16
16
|
}>;
|
|
17
17
|
|
package/dist/test.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as supertest from 'supertest';
|
|
|
2
2
|
import { Test } from 'supertest';
|
|
3
3
|
import { Server } from 'node:http';
|
|
4
4
|
import { Construct } from 'phecda-core';
|
|
5
|
-
import { F as Factory } from './core-
|
|
6
|
-
import { P as PickFunc } from './
|
|
5
|
+
import { F as Factory } from './core-BlN0Spy9.js';
|
|
6
|
+
import { P as PickFunc } from './meta-KtfiBIde.js';
|
|
7
7
|
|
|
8
8
|
declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
9
9
|
get<C extends T[number]>(Model: C): InstanceType<C>;
|
|
@@ -11,7 +11,7 @@ declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
|
11
11
|
type SuperTestRequest<T> = {
|
|
12
12
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
13
|
};
|
|
14
|
-
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "
|
|
14
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "key" | "query" | "use" | "on" | "set" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
|
|
15
15
|
module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
|
|
16
16
|
}>;
|
|
17
17
|
|
package/dist/test.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNL6QBQARjs = require('./chunk-NL6QBQAR.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkTVT62GIXjs = require('./chunk-TVT62GIX.js');
|
|
7
7
|
|
|
8
8
|
// src/test.ts
|
|
9
9
|
var _phecdacore = require('phecda-core');
|
|
10
10
|
async function TestFactory(...Modules) {
|
|
11
|
-
const { moduleMap, modelMap } = await
|
|
11
|
+
const { moduleMap, modelMap } = await _chunkNL6QBQARjs.Factory.call(void 0, Modules);
|
|
12
12
|
return {
|
|
13
13
|
get(Model) {
|
|
14
14
|
const tag = _phecdacore.getTag.call(void 0, Model);
|
|
@@ -19,7 +19,7 @@ async function TestFactory(...Modules) {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
_chunkTVT62GIXjs.__name.call(void 0, TestFactory, "TestFactory");
|
|
23
23
|
async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
24
24
|
const { default: request, agent } = await Promise.resolve().then(() => _interopRequireWildcard(require("supertest")));
|
|
25
25
|
const Agent = agent(app);
|
|
@@ -59,11 +59,11 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
_chunkTVT62GIXjs.__name.call(void 0, module, "module");
|
|
63
63
|
Agent.module = module;
|
|
64
64
|
return Agent;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
_chunkTVT62GIXjs.__name.call(void 0, TestHttp, "TestHttp");
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
package/dist/test.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IncomingHttpHeaders } from 'node:http';
|
|
2
|
-
import { D as DefaultOptions, B as BaseContext } from './
|
|
1
|
+
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { D as DefaultOptions, B as BaseContext } from './meta-KtfiBIde.mjs';
|
|
3
3
|
|
|
4
4
|
interface HttpOptions extends DefaultOptions {
|
|
5
5
|
/**
|
|
@@ -28,6 +28,8 @@ interface HttpContext extends BaseContext {
|
|
|
28
28
|
delCookie(key: string): void;
|
|
29
29
|
setResHeaders: (headers: Record<string, string>) => void;
|
|
30
30
|
setResStatus: (status: number) => void;
|
|
31
|
+
getRequest: () => IncomingMessage;
|
|
32
|
+
getResponse: () => ServerResponse;
|
|
31
33
|
}
|
|
32
34
|
interface CookieSerializeOptions {
|
|
33
35
|
domain?: string | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IncomingHttpHeaders } from 'node:http';
|
|
2
|
-
import { D as DefaultOptions, B as BaseContext } from './
|
|
1
|
+
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { D as DefaultOptions, B as BaseContext } from './meta-KtfiBIde.js';
|
|
3
3
|
|
|
4
4
|
interface HttpOptions extends DefaultOptions {
|
|
5
5
|
/**
|
|
@@ -28,6 +28,8 @@ interface HttpContext extends BaseContext {
|
|
|
28
28
|
delCookie(key: string): void;
|
|
29
29
|
setResHeaders: (headers: Record<string, string>) => void;
|
|
30
30
|
setResStatus: (status: number) => void;
|
|
31
|
+
getRequest: () => IncomingMessage;
|
|
32
|
+
getResponse: () => ServerResponse;
|
|
31
33
|
}
|
|
32
34
|
interface CookieSerializeOptions {
|
|
33
35
|
domain?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-server",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
|
|
5
5
|
"author": "fgsreally",
|
|
6
6
|
"license": "MIT",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"picocolors": "^1.0.0",
|
|
147
147
|
"reflect-metadata": "^0.1.13",
|
|
148
148
|
"ts-mixer": "^6.0.4",
|
|
149
|
-
"phecda-core": "4.0.
|
|
149
|
+
"phecda-core": "4.0.1"
|
|
150
150
|
},
|
|
151
151
|
"devDependencies": {
|
|
152
152
|
"@koa/router": "^12.0.1",
|
package/dist/chunk-LYEZ6RGX.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkGHFSIZUOjs = require('./chunk-GHFSIZUO.js');
|
|
7
|
-
|
|
8
|
-
// src/meta.ts
|
|
9
|
-
var Meta = class {
|
|
10
|
-
static {
|
|
11
|
-
_chunkGHFSIZUOjs.__name.call(void 0, this, "Meta");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor(data, paramsType) {
|
|
16
|
-
this.data = data;
|
|
17
|
-
this.paramsType = paramsType;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// src/core.ts
|
|
22
|
-
require('reflect-metadata');
|
|
23
|
-
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
24
|
-
var _phecdacore = require('phecda-core');
|
|
25
|
-
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
26
|
-
var debug = _debug2.default.call(void 0, "phecda-server(createPhecda)");
|
|
27
|
-
var emitter = new (0, _events2.default)();
|
|
28
|
-
async function createPhecda(models, opts = {}) {
|
|
29
|
-
const moduleMap = /* @__PURE__ */ new Map();
|
|
30
|
-
const meta = [];
|
|
31
|
-
const modelMap = /* @__PURE__ */ new WeakMap();
|
|
32
|
-
const modelSet = /* @__PURE__ */ new WeakSet();
|
|
33
|
-
const dependenceGraph = /* @__PURE__ */ new Map();
|
|
34
|
-
const { parseModule = /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (meta2) => meta2, "parseMeta"), generators } = opts;
|
|
35
|
-
if (!_phecdacore.getInject.call(void 0, "watcher")) {
|
|
36
|
-
_phecdacore.setInject.call(void 0, "watcher", ({ eventName, instance, property, options }) => {
|
|
37
|
-
const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
|
|
38
|
-
if (_optionalChain([options, 'optionalAccess', _ => _.once])) emitter.once(eventName, fn);
|
|
39
|
-
else emitter.on(eventName, fn);
|
|
40
|
-
return () => {
|
|
41
|
-
emitter.off(eventName, fn);
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async function del(tag) {
|
|
46
|
-
if (!moduleMap.has(tag)) return;
|
|
47
|
-
const module = moduleMap.get(tag);
|
|
48
|
-
debug(`unmount module "${String(tag)}"`);
|
|
49
|
-
await _phecdacore.invokeUnmount.call(void 0, module);
|
|
50
|
-
debug(`del module "${String(tag)}"`);
|
|
51
|
-
moduleMap.delete(tag);
|
|
52
|
-
modelMap.delete(module);
|
|
53
|
-
for (let i = meta.length - 1; i >= 0; i--) {
|
|
54
|
-
if (meta[i].data.tag === tag) meta.splice(i, 1);
|
|
55
|
-
}
|
|
56
|
-
return module;
|
|
57
|
-
}
|
|
58
|
-
_chunkGHFSIZUOjs.__name.call(void 0, del, "del");
|
|
59
|
-
async function destroy() {
|
|
60
|
-
debug("destroy all");
|
|
61
|
-
for (const [tag] of moduleMap) await del(tag);
|
|
62
|
-
}
|
|
63
|
-
_chunkGHFSIZUOjs.__name.call(void 0, destroy, "destroy");
|
|
64
|
-
async function add(Model) {
|
|
65
|
-
const tag = _phecdacore.getTag.call(void 0, Model);
|
|
66
|
-
const oldInstance = await del(tag);
|
|
67
|
-
const { module: newModule } = await buildDepModule(Model);
|
|
68
|
-
if (oldInstance && dependenceGraph.has(tag)) {
|
|
69
|
-
debug(`replace module "${String(tag)}"`);
|
|
70
|
-
[
|
|
71
|
-
...dependenceGraph.get(tag)
|
|
72
|
-
].forEach((tag2) => {
|
|
73
|
-
const module = moduleMap.get(tag2);
|
|
74
|
-
for (const key in module) {
|
|
75
|
-
if (module[key] === oldInstance) module[key] = newModule;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
_chunkGHFSIZUOjs.__name.call(void 0, add, "add");
|
|
81
|
-
async function buildDepModule(Model) {
|
|
82
|
-
const paramtypes = getParamTypes(Model);
|
|
83
|
-
let module;
|
|
84
|
-
const tag = _phecdacore.getTag.call(void 0, Model);
|
|
85
|
-
if (moduleMap.has(tag)) {
|
|
86
|
-
module = moduleMap.get(tag);
|
|
87
|
-
if (!module) throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
|
|
88
|
-
if (modelMap.get(module) !== Model && !modelSet.has(Model)) {
|
|
89
|
-
modelSet.add(Model);
|
|
90
|
-
if (module instanceof Model) _chunkGHFSIZUOjs.log.call(void 0, `Module taged ${String(tag)} has been overridden`);
|
|
91
|
-
else _chunkGHFSIZUOjs.log.call(void 0, `Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
module,
|
|
95
|
-
tag
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
moduleMap.set(tag, void 0);
|
|
99
|
-
debug(`instantiate module "${String(tag)}"`);
|
|
100
|
-
if (paramtypes) {
|
|
101
|
-
const paramtypesInstances = [];
|
|
102
|
-
for (const i in paramtypes) {
|
|
103
|
-
const { module: sub, tag: subTag } = await buildDepModule(paramtypes[i]);
|
|
104
|
-
paramtypesInstances[i] = sub;
|
|
105
|
-
if (!dependenceGraph.has(subTag)) dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
|
|
106
|
-
dependenceGraph.get(subTag).add(tag);
|
|
107
|
-
}
|
|
108
|
-
module = parseModule(new Model(...paramtypesInstances));
|
|
109
|
-
} else {
|
|
110
|
-
module = parseModule(new Model());
|
|
111
|
-
}
|
|
112
|
-
meta.push(...getMetaFromInstance(module, tag, Model.name).map(parseMeta).filter((item) => !!item));
|
|
113
|
-
debug(`init module "${String(tag)}"`);
|
|
114
|
-
if (!_chunkGHFSIZUOjs.IS_ONLY_GENERATE) await _phecdacore.invokeInit.call(void 0, module);
|
|
115
|
-
debug(`add module "${String(tag)}"`);
|
|
116
|
-
moduleMap.set(tag, module);
|
|
117
|
-
modelMap.set(module, Model);
|
|
118
|
-
return {
|
|
119
|
-
module,
|
|
120
|
-
tag
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
_chunkGHFSIZUOjs.__name.call(void 0, buildDepModule, "buildDepModule");
|
|
124
|
-
for (const model of models) await buildDepModule(model);
|
|
125
|
-
async function generateCode() {
|
|
126
|
-
if (generators && _chunkGHFSIZUOjs.IS_HMR) {
|
|
127
|
-
return Promise.all(generators.map((generator) => {
|
|
128
|
-
debug(`generate "${generator.name}" code to ${generator.path}`);
|
|
129
|
-
return generator.output(meta);
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
_chunkGHFSIZUOjs.__name.call(void 0, generateCode, "generateCode");
|
|
134
|
-
generateCode().then(() => {
|
|
135
|
-
if (_chunkGHFSIZUOjs.IS_ONLY_GENERATE) process.exit(4);
|
|
136
|
-
});
|
|
137
|
-
if (_chunkGHFSIZUOjs.IS_HMR) {
|
|
138
|
-
if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
|
|
139
|
-
_optionalChain([globalThis, 'access', _2 => _2.__PS_HMR__, 'optionalAccess', _3 => _3.push, 'call', _4 => _4(async (files) => {
|
|
140
|
-
debug("reload files ");
|
|
141
|
-
for (const file of files) {
|
|
142
|
-
const models2 = await Promise.resolve().then(() => _interopRequireWildcard(require(file)));
|
|
143
|
-
for (const i in models2) {
|
|
144
|
-
if (_phecdacore.isPhecda.call(void 0, models2[i])) await add(models2[i]);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
generateCode();
|
|
148
|
-
})]);
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
moduleMap,
|
|
152
|
-
modelMap,
|
|
153
|
-
meta,
|
|
154
|
-
add,
|
|
155
|
-
del,
|
|
156
|
-
destroy
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
_chunkGHFSIZUOjs.__name.call(void 0, createPhecda, "createPhecda");
|
|
160
|
-
var Factory = createPhecda;
|
|
161
|
-
function getMetaFromInstance(instance, tag, name) {
|
|
162
|
-
const propertyKeys = _phecdacore.getMetaKey.call(void 0, instance).filter((item) => typeof item === "string");
|
|
163
|
-
const baseMeta = _phecdacore.getMergedMeta.call(void 0, instance, void 0);
|
|
164
|
-
const ctxs = baseMeta.ctxs;
|
|
165
|
-
return propertyKeys.filter((i) => typeof instance[i] === "function").map((i) => {
|
|
166
|
-
const meta = _phecdacore.getMergedMeta.call(void 0, instance, i);
|
|
167
|
-
const metaData = {
|
|
168
|
-
...meta,
|
|
169
|
-
name,
|
|
170
|
-
tag,
|
|
171
|
-
func: i
|
|
172
|
-
};
|
|
173
|
-
if (baseMeta.controller) {
|
|
174
|
-
if (typeof tag !== "string") _chunkGHFSIZUOjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
|
|
175
|
-
metaData.controller = baseMeta.controller;
|
|
176
|
-
metaData[baseMeta.controller] = {
|
|
177
|
-
...baseMeta[baseMeta.controller],
|
|
178
|
-
...meta[baseMeta.controller]
|
|
179
|
-
};
|
|
180
|
-
const params = _phecdacore.getMetaParams.call(void 0, instance, i).map((item) => _phecdacore.getMergedMeta.call(void 0, instance, i, item));
|
|
181
|
-
params.forEach((item, index) => {
|
|
182
|
-
if (!item.pipe) item.pipe = meta.pipe || baseMeta.pipe;
|
|
183
|
-
if (!item.define) item.define = {};
|
|
184
|
-
item.index = index;
|
|
185
|
-
});
|
|
186
|
-
metaData.ctxs = ctxs;
|
|
187
|
-
metaData.params = params;
|
|
188
|
-
metaData.filter = meta.filter || baseMeta.filter;
|
|
189
|
-
metaData.define = {
|
|
190
|
-
...baseMeta.define,
|
|
191
|
-
...meta.define
|
|
192
|
-
};
|
|
193
|
-
for (const item of [
|
|
194
|
-
"plugins",
|
|
195
|
-
"guards",
|
|
196
|
-
"interceptors"
|
|
197
|
-
]) {
|
|
198
|
-
const set = new Set(baseMeta[item]);
|
|
199
|
-
if (meta[item]) {
|
|
200
|
-
meta[item].forEach((part) => {
|
|
201
|
-
set.delete(part);
|
|
202
|
-
set.add(part);
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
metaData[item] = [
|
|
206
|
-
...set
|
|
207
|
-
];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
_chunkGHFSIZUOjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
|
|
214
|
-
function deepFreeze(object) {
|
|
215
|
-
Object.freeze(object);
|
|
216
|
-
Object.getOwnPropertyNames(object).forEach((prop) => {
|
|
217
|
-
if (object[prop] !== null && (typeof object[prop] === "object" || typeof object[prop] === "function") && !Object.isFrozen(object[prop])) deepFreeze(object[prop]);
|
|
218
|
-
});
|
|
219
|
-
return object;
|
|
220
|
-
}
|
|
221
|
-
_chunkGHFSIZUOjs.__name.call(void 0, deepFreeze, "deepFreeze");
|
|
222
|
-
function getParamTypes(Model, key) {
|
|
223
|
-
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
224
|
-
}
|
|
225
|
-
_chunkGHFSIZUOjs.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
226
|
-
function isObject(o) {
|
|
227
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
228
|
-
}
|
|
229
|
-
_chunkGHFSIZUOjs.__name.call(void 0, isObject, "isObject");
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
exports.Meta = Meta; exports.emitter = emitter; exports.createPhecda = createPhecda; exports.Factory = Factory; exports.isObject = isObject;
|