phecda-server 5.2.4 → 5.2.6
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-IJNA24EZ.mjs → chunk-5E2AVYP2.mjs} +39 -55
- package/dist/{chunk-AWY6FTH4.js → chunk-AUAAKHWS.js} +70 -86
- package/dist/{chunk-Q4AGVGVA.mjs → chunk-BZKJ5NBU.mjs} +103 -105
- package/dist/{chunk-LGP5AT6W.mjs → chunk-LHLQIQPH.mjs} +51 -70
- package/dist/{chunk-VYDBNZJ2.mjs → chunk-MESZCLSS.mjs} +1 -10
- package/dist/{chunk-UJAI73O6.js → chunk-N4ULJDEQ.js} +62 -81
- package/dist/{chunk-H6NYBVBV.js → chunk-QYX5Q7KO.js} +130 -132
- package/dist/{chunk-FNJWO324.js → chunk-RVWBJ6LV.js} +2 -11
- package/dist/core-Bc2ENEHX.d.mts +29 -0
- package/dist/{core-7f6d2be6.d.ts → core-dx9E5x2N.d.ts} +7 -5
- package/dist/helper.d.mts +27 -0
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/index.d.mts +244 -0
- package/dist/index.d.ts +16 -18
- package/dist/index.js +81 -90
- package/dist/index.mjs +61 -70
- package/dist/rpc/bullmq/index.d.mts +21 -0
- package/dist/rpc/bullmq/index.d.ts +4 -4
- package/dist/rpc/bullmq/index.js +30 -43
- package/dist/rpc/bullmq/index.mjs +20 -33
- package/dist/rpc/kafka/index.d.mts +24 -0
- package/dist/rpc/kafka/index.d.ts +4 -4
- package/dist/rpc/kafka/index.js +25 -34
- package/dist/rpc/kafka/index.mjs +17 -26
- package/dist/rpc/nats/index.d.mts +15 -0
- package/dist/rpc/nats/index.d.ts +4 -4
- package/dist/rpc/nats/index.js +33 -46
- package/dist/rpc/nats/index.mjs +24 -37
- package/dist/rpc/rabbitmq/index.d.mts +16 -0
- package/dist/rpc/rabbitmq/index.d.ts +4 -4
- package/dist/rpc/rabbitmq/index.js +34 -46
- package/dist/rpc/rabbitmq/index.mjs +23 -35
- package/dist/rpc/redis/index.d.mts +23 -0
- package/dist/rpc/redis/index.d.ts +4 -4
- package/dist/rpc/redis/index.js +27 -38
- package/dist/rpc/redis/index.mjs +18 -29
- package/dist/server/elysia/index.d.mts +18 -0
- package/dist/server/elysia/index.d.ts +4 -4
- package/dist/server/elysia/index.js +22 -27
- package/dist/server/elysia/index.mjs +8 -13
- package/dist/server/express/index.d.mts +18 -0
- package/dist/server/express/index.d.ts +4 -4
- package/dist/server/express/index.js +24 -33
- package/dist/server/express/index.mjs +11 -20
- package/dist/server/fastify/index.d.mts +20 -0
- package/dist/server/fastify/index.d.ts +4 -4
- package/dist/server/fastify/index.js +23 -30
- package/dist/server/fastify/index.mjs +10 -17
- package/dist/server/h3/index.d.mts +16 -0
- package/dist/server/h3/index.d.ts +4 -4
- package/dist/server/h3/index.js +21 -25
- package/dist/server/h3/index.mjs +10 -14
- package/dist/server/hono/index.d.mts +16 -0
- package/dist/server/hono/index.d.ts +4 -4
- package/dist/server/hono/index.js +22 -30
- package/dist/server/hono/index.mjs +10 -18
- package/dist/server/hyper-express/index.d.mts +18 -0
- package/dist/server/hyper-express/index.d.ts +4 -4
- package/dist/server/hyper-express/index.js +23 -32
- package/dist/server/hyper-express/index.mjs +11 -20
- package/dist/server/koa/index.d.mts +18 -0
- package/dist/server/koa/index.d.ts +4 -4
- package/dist/server/koa/index.js +22 -29
- package/dist/server/koa/index.mjs +9 -16
- package/dist/test.d.mts +18 -0
- package/dist/test.d.ts +4 -4
- package/dist/test.js +19 -27
- package/dist/test.mjs +16 -24
- package/dist/{types-81be0ba3.d.ts → types-BlIBlnVT.d.mts} +1 -2
- package/dist/types-BlIBlnVT.d.ts +107 -0
- package/dist/{types-f3b79218.d.ts → types-CJSkC9tO.d.ts} +2 -2
- package/dist/types-Dp5ixUqW.d.mts +27 -0
- package/dist/{types-0a76c4bc.d.ts → types-PY43OKEP.d.ts} +2 -2
- package/dist/types-vF4Hvnvo.d.mts +17 -0
- package/package.json +3 -3
package/dist/server/koa/index.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkQYX5Q7KOjs = require('../../chunk-QYX5Q7KO.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkRVWBJ6LVjs = require('../../chunk-RVWBJ6LV.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 = _chunkQYX5Q7KOjs.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
|
+
_chunkQYX5Q7KOjs.detectAopDep.call(void 0, meta, {
|
|
28
28
|
plugins: [
|
|
29
29
|
...globalPlugins,
|
|
30
30
|
...parallelPlugins
|
|
@@ -34,28 +34,25 @@ function bind(router, data, opts = {}) {
|
|
|
34
34
|
});
|
|
35
35
|
registerRoute();
|
|
36
36
|
async function registerRoute() {
|
|
37
|
-
|
|
37
|
+
_chunkQYX5Q7KOjs.Context.usePlugin(globalPlugins, "koa").forEach((p) => router.use(p));
|
|
38
38
|
if (parallelRoute) {
|
|
39
|
-
router.post(parallelRoute, ...
|
|
39
|
+
router.post(parallelRoute, ..._chunkQYX5Q7KOjs.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 _chunkQYX5Q7KOjs.Context.filterRecord.default(e);
|
|
43
43
|
ctx.status = error.status;
|
|
44
44
|
ctx.body = error;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
if (!Array.isArray(body))
|
|
48
|
-
return errorHandler(new (0, _chunkH6NYBVBVjs.BadRequestException)("data format should be an array"));
|
|
46
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
47
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunkQYX5Q7KOjs.BadRequestException)("data format should be an array"));
|
|
49
48
|
try {
|
|
50
49
|
return Promise.all(body.map((item, i) => {
|
|
51
50
|
return new Promise(async (resolve) => {
|
|
52
51
|
const { tag, func } = item;
|
|
53
52
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
54
|
-
if (!metaMap.has(tag))
|
|
55
|
-
return resolve(await _chunkH6NYBVBVjs.Context.filterRecord.default(new (0, _chunkH6NYBVBVjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
53
|
+
if (!metaMap.has(tag)) return resolve(await _chunkQYX5Q7KOjs.Context.filterRecord.default(new (0, _chunkQYX5Q7KOjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
56
54
|
const meta2 = metaMap.get(tag)[func];
|
|
57
|
-
if (!meta2)
|
|
58
|
-
return resolve(await _chunkH6NYBVBVjs.Context.filterRecord.default(new (0, _chunkH6NYBVBVjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
55
|
+
if (!meta2) return resolve(await _chunkQYX5Q7KOjs.Context.filterRecord.default(new (0, _chunkQYX5Q7KOjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
59
56
|
const { data: { params } } = meta2;
|
|
60
57
|
const contextData = {
|
|
61
58
|
type: "koa",
|
|
@@ -66,11 +63,11 @@ function bind(router, data, opts = {}) {
|
|
|
66
63
|
parallel: true,
|
|
67
64
|
next,
|
|
68
65
|
app: router,
|
|
69
|
-
...
|
|
66
|
+
..._chunkQYX5Q7KOjs.argToReq.call(void 0, params, item.args, ctx.headers),
|
|
70
67
|
tag,
|
|
71
68
|
func
|
|
72
69
|
};
|
|
73
|
-
const context = new (0,
|
|
70
|
+
const context = new (0, _chunkQYX5Q7KOjs.Context)(contextData);
|
|
74
71
|
context.run({
|
|
75
72
|
globalGuards,
|
|
76
73
|
globalInterceptors,
|
|
@@ -90,9 +87,8 @@ function bind(router, data, opts = {}) {
|
|
|
90
87
|
for (const func in record) {
|
|
91
88
|
const meta2 = metaMap.get(tag)[func];
|
|
92
89
|
const { data: { plugins, http } } = meta2;
|
|
93
|
-
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
94
|
-
|
|
95
|
-
router[http.type](http.prefix + http.route, ..._chunkH6NYBVBVjs.Context.usePlugin(plugins, "koa"), async (ctx, next) => {
|
|
90
|
+
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
91
|
+
router[http.type](http.prefix + http.route, ..._chunkQYX5Q7KOjs.Context.usePlugin(plugins, "koa"), async (ctx, next) => {
|
|
96
92
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
97
93
|
const contextData = {
|
|
98
94
|
type: "koa",
|
|
@@ -108,10 +104,9 @@ function bind(router, data, opts = {}) {
|
|
|
108
104
|
headers: ctx.headers,
|
|
109
105
|
next
|
|
110
106
|
};
|
|
111
|
-
const context = new (0,
|
|
107
|
+
const context = new (0, _chunkQYX5Q7KOjs.Context)(contextData);
|
|
112
108
|
if (http.headers) {
|
|
113
|
-
for (const name in http.headers)
|
|
114
|
-
ctx.set(name, http.headers[name]);
|
|
109
|
+
for (const name in http.headers) ctx.set(name, http.headers[name]);
|
|
115
110
|
}
|
|
116
111
|
await context.run({
|
|
117
112
|
globalGuards,
|
|
@@ -119,12 +114,10 @@ function bind(router, data, opts = {}) {
|
|
|
119
114
|
globalFilter,
|
|
120
115
|
globalPipe
|
|
121
116
|
}, (returnData) => {
|
|
122
|
-
if (ctx.res.writableEnded)
|
|
123
|
-
return;
|
|
117
|
+
if (ctx.res.writableEnded) return;
|
|
124
118
|
ctx.body = returnData;
|
|
125
119
|
}, (err) => {
|
|
126
|
-
if (ctx.res.writableEnded)
|
|
127
|
-
return;
|
|
120
|
+
if (ctx.res.writableEnded) return;
|
|
128
121
|
ctx.status = err.status;
|
|
129
122
|
ctx.body = err;
|
|
130
123
|
});
|
|
@@ -132,13 +125,13 @@ function bind(router, data, opts = {}) {
|
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
129
|
+
_chunkQYX5Q7KOjs.HMR.call(void 0, async () => {
|
|
137
130
|
router.stack = originStack;
|
|
138
131
|
registerRoute();
|
|
139
132
|
});
|
|
140
133
|
}
|
|
141
|
-
|
|
134
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, bind, "bind");
|
|
142
135
|
|
|
143
136
|
|
|
144
137
|
exports.bind = bind;
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
argToReq,
|
|
6
6
|
createControllerMetaMap,
|
|
7
7
|
detectAopDep
|
|
8
|
-
} from "../../chunk-
|
|
8
|
+
} from "../../chunk-BZKJ5NBU.mjs";
|
|
9
9
|
import {
|
|
10
10
|
__name
|
|
11
|
-
} from "../../chunk-
|
|
11
|
+
} from "../../chunk-MESZCLSS.mjs";
|
|
12
12
|
|
|
13
13
|
// src/server/koa/bind.ts
|
|
14
14
|
import Debug from "debug";
|
|
@@ -44,18 +44,15 @@ function bind(router, data, opts = {}) {
|
|
|
44
44
|
ctx.body = error;
|
|
45
45
|
}
|
|
46
46
|
__name(errorHandler, "errorHandler");
|
|
47
|
-
if (!Array.isArray(body))
|
|
48
|
-
return errorHandler(new BadRequestException("data format should be an array"));
|
|
47
|
+
if (!Array.isArray(body)) return errorHandler(new BadRequestException("data format should be an array"));
|
|
49
48
|
try {
|
|
50
49
|
return Promise.all(body.map((item, i) => {
|
|
51
50
|
return new Promise(async (resolve) => {
|
|
52
51
|
const { tag, func } = item;
|
|
53
52
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
54
|
-
if (!metaMap.has(tag))
|
|
55
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
53
|
+
if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
|
|
56
54
|
const meta2 = metaMap.get(tag)[func];
|
|
57
|
-
if (!meta2)
|
|
58
|
-
return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
55
|
+
if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
|
|
59
56
|
const { data: { params } } = meta2;
|
|
60
57
|
const contextData = {
|
|
61
58
|
type: "koa",
|
|
@@ -90,8 +87,7 @@ function bind(router, data, opts = {}) {
|
|
|
90
87
|
for (const func in record) {
|
|
91
88
|
const meta2 = metaMap.get(tag)[func];
|
|
92
89
|
const { data: { plugins, http } } = meta2;
|
|
93
|
-
if (!http?.type)
|
|
94
|
-
continue;
|
|
90
|
+
if (!http?.type) continue;
|
|
95
91
|
router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "koa"), async (ctx, next) => {
|
|
96
92
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
97
93
|
const contextData = {
|
|
@@ -110,8 +106,7 @@ function bind(router, data, opts = {}) {
|
|
|
110
106
|
};
|
|
111
107
|
const context = new Context(contextData);
|
|
112
108
|
if (http.headers) {
|
|
113
|
-
for (const name in http.headers)
|
|
114
|
-
ctx.set(name, http.headers[name]);
|
|
109
|
+
for (const name in http.headers) ctx.set(name, http.headers[name]);
|
|
115
110
|
}
|
|
116
111
|
await context.run({
|
|
117
112
|
globalGuards,
|
|
@@ -119,12 +114,10 @@ function bind(router, data, opts = {}) {
|
|
|
119
114
|
globalFilter,
|
|
120
115
|
globalPipe
|
|
121
116
|
}, (returnData) => {
|
|
122
|
-
if (ctx.res.writableEnded)
|
|
123
|
-
return;
|
|
117
|
+
if (ctx.res.writableEnded) return;
|
|
124
118
|
ctx.body = returnData;
|
|
125
119
|
}, (err) => {
|
|
126
|
-
if (ctx.res.writableEnded)
|
|
127
|
-
return;
|
|
120
|
+
if (ctx.res.writableEnded) return;
|
|
128
121
|
ctx.status = err.status;
|
|
129
122
|
ctx.body = err;
|
|
130
123
|
});
|
package/dist/test.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as supertest from 'supertest';
|
|
2
|
+
import { Test } from 'supertest';
|
|
3
|
+
import { Server } from 'node:http';
|
|
4
|
+
import { Construct } from 'phecda-core';
|
|
5
|
+
import { F as Factory } from './core-Bc2ENEHX.mjs';
|
|
6
|
+
import { P as PickFunc } from './types-BlIBlnVT.mjs';
|
|
7
|
+
|
|
8
|
+
declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
9
|
+
get<C extends T[number]>(Model: C): InstanceType<C>;
|
|
10
|
+
}>;
|
|
11
|
+
type SuperTestRequest<T> = {
|
|
12
|
+
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
|
+
};
|
|
14
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "use" | "on" | "set" | "query" | "type" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "key" | "pfx" | "cert"> & {
|
|
15
|
+
module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
export { type SuperTestRequest, TestFactory, TestHttp };
|
package/dist/test.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ 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 './types-
|
|
5
|
+
import { F as Factory } from './core-dx9E5x2N.js';
|
|
6
|
+
import { P as PickFunc } from './types-BlIBlnVT.js';
|
|
7
7
|
|
|
8
8
|
declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
|
|
9
|
-
get<C extends T[number]>(
|
|
9
|
+
get<C extends T[number]>(Model: C): InstanceType<C>;
|
|
10
10
|
}>;
|
|
11
11
|
type SuperTestRequest<T> = {
|
|
12
12
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
@@ -15,4 +15,4 @@ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<Return
|
|
|
15
15
|
module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
|
|
16
16
|
}>;
|
|
17
17
|
|
|
18
|
-
export { SuperTestRequest, TestFactory, TestHttp };
|
|
18
|
+
export { type SuperTestRequest, TestFactory, TestHttp };
|
package/dist/test.js
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
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 _chunkN4ULJDEQjs = require('./chunk-N4ULJDEQ.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkRVWBJ6LVjs = require('./chunk-RVWBJ6LV.js');
|
|
7
7
|
|
|
8
8
|
// src/test.ts
|
|
9
9
|
var _phecdacore = require('phecda-core');
|
|
10
10
|
async function TestFactory(...Modules) {
|
|
11
|
-
const { moduleMap,
|
|
11
|
+
const { moduleMap, modelMap } = await _chunkN4ULJDEQjs.Factory.call(void 0, Modules);
|
|
12
12
|
return {
|
|
13
|
-
get(
|
|
14
|
-
const tag = _phecdacore.getTag.call(void 0,
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error(`module "${Module.name}" and "${String(tag)}" in modulemap are different modules`);
|
|
20
|
-
return instance;
|
|
13
|
+
get(Model) {
|
|
14
|
+
const tag = _phecdacore.getTag.call(void 0, Model);
|
|
15
|
+
const module = moduleMap.get(tag);
|
|
16
|
+
if (!module) throw new Error(`module "${String(tag)}" doesn't exist`);
|
|
17
|
+
if (modelMap.get(module) !== Model) throw new Error(`module "${Model.name}" and "${String(tag)}" in modulemap are different modules`);
|
|
18
|
+
return module;
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, TestFactory, "TestFactory");
|
|
25
23
|
async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
26
24
|
const { default: request, agent } = await Promise.resolve().then(() => _interopRequireWildcard(require("supertest")));
|
|
27
25
|
const Agent = agent(app);
|
|
28
26
|
function module(Module) {
|
|
29
27
|
const tag = _phecdacore.getTag.call(void 0, Module);
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
32
|
-
throw new Error(`module "${String(tag)}" doesn't exist`);
|
|
28
|
+
const module2 = moduleMap.get(tag);
|
|
29
|
+
if (!module2) throw new Error(`module "${String(tag)}" doesn't exist`);
|
|
33
30
|
return new Proxy({}, {
|
|
34
31
|
get(_target, p) {
|
|
35
32
|
const { data } = meta.find(({ data: data2 }) => data2.name === Module.name && data2.func === p && data2.tag === tag);
|
|
@@ -50,28 +47,23 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
50
47
|
ret.query[item.key] = args[item.index];
|
|
51
48
|
return;
|
|
52
49
|
}
|
|
53
|
-
if (item.key)
|
|
54
|
-
|
|
55
|
-
else
|
|
56
|
-
ret[item.type] = args[item.index];
|
|
50
|
+
if (item.key) ret[item.type][item.key] = args[item.index];
|
|
51
|
+
else ret[item.type] = args[item.index];
|
|
57
52
|
});
|
|
58
53
|
let agent2 = (isAgent ? Agent : request(app))[ret.func](ret.url);
|
|
59
|
-
if (Object.keys(ret.query).length > 0)
|
|
60
|
-
|
|
61
|
-
if (Object.keys(ret.
|
|
62
|
-
agent2 = agent2.set(ret.headers);
|
|
63
|
-
if (Object.keys(ret.body).length > 0)
|
|
64
|
-
agent2 = agent2.send(ret.body);
|
|
54
|
+
if (Object.keys(ret.query).length > 0) agent2 = agent2.query(ret.query);
|
|
55
|
+
if (Object.keys(ret.headers).length > 0) agent2 = agent2.set(ret.headers);
|
|
56
|
+
if (Object.keys(ret.body).length > 0) agent2 = agent2.send(ret.body);
|
|
65
57
|
return agent2;
|
|
66
58
|
};
|
|
67
59
|
}
|
|
68
60
|
});
|
|
69
61
|
}
|
|
70
|
-
|
|
62
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, module, "module");
|
|
71
63
|
Agent.module = module;
|
|
72
64
|
return Agent;
|
|
73
65
|
}
|
|
74
|
-
|
|
66
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, TestHttp, "TestHttp");
|
|
75
67
|
|
|
76
68
|
|
|
77
69
|
|
package/dist/test.mjs
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Factory
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LHLQIQPH.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MESZCLSS.mjs";
|
|
7
7
|
|
|
8
8
|
// src/test.ts
|
|
9
9
|
import { getTag } from "phecda-core";
|
|
10
10
|
async function TestFactory(...Modules) {
|
|
11
|
-
const { moduleMap,
|
|
11
|
+
const { moduleMap, modelMap } = await Factory(Modules);
|
|
12
12
|
return {
|
|
13
|
-
get(
|
|
14
|
-
const tag = getTag(
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error(`module "${Module.name}" and "${String(tag)}" in modulemap are different modules`);
|
|
20
|
-
return instance;
|
|
13
|
+
get(Model) {
|
|
14
|
+
const tag = getTag(Model);
|
|
15
|
+
const module = moduleMap.get(tag);
|
|
16
|
+
if (!module) throw new Error(`module "${String(tag)}" doesn't exist`);
|
|
17
|
+
if (modelMap.get(module) !== Model) throw new Error(`module "${Model.name}" and "${String(tag)}" in modulemap are different modules`);
|
|
18
|
+
return module;
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
21
|
}
|
|
@@ -27,9 +25,8 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
27
25
|
const Agent = agent(app);
|
|
28
26
|
function module(Module) {
|
|
29
27
|
const tag = getTag(Module);
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
32
|
-
throw new Error(`module "${String(tag)}" doesn't exist`);
|
|
28
|
+
const module2 = moduleMap.get(tag);
|
|
29
|
+
if (!module2) throw new Error(`module "${String(tag)}" doesn't exist`);
|
|
33
30
|
return new Proxy({}, {
|
|
34
31
|
get(_target, p) {
|
|
35
32
|
const { data } = meta.find(({ data: data2 }) => data2.name === Module.name && data2.func === p && data2.tag === tag);
|
|
@@ -50,18 +47,13 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
50
47
|
ret.query[item.key] = args[item.index];
|
|
51
48
|
return;
|
|
52
49
|
}
|
|
53
|
-
if (item.key)
|
|
54
|
-
|
|
55
|
-
else
|
|
56
|
-
ret[item.type] = args[item.index];
|
|
50
|
+
if (item.key) ret[item.type][item.key] = args[item.index];
|
|
51
|
+
else ret[item.type] = args[item.index];
|
|
57
52
|
});
|
|
58
53
|
let agent2 = (isAgent ? Agent : request(app))[ret.func](ret.url);
|
|
59
|
-
if (Object.keys(ret.query).length > 0)
|
|
60
|
-
|
|
61
|
-
if (Object.keys(ret.
|
|
62
|
-
agent2 = agent2.set(ret.headers);
|
|
63
|
-
if (Object.keys(ret.body).length > 0)
|
|
64
|
-
agent2 = agent2.send(ret.body);
|
|
54
|
+
if (Object.keys(ret.query).length > 0) agent2 = agent2.query(ret.query);
|
|
55
|
+
if (Object.keys(ret.headers).length > 0) agent2 = agent2.set(ret.headers);
|
|
56
|
+
if (Object.keys(ret.body).length > 0) agent2 = agent2.send(ret.body);
|
|
65
57
|
return agent2;
|
|
66
58
|
};
|
|
67
59
|
}
|
|
@@ -43,7 +43,6 @@ interface ControllerMeta extends Meta {
|
|
|
43
43
|
data: ControllerMetaData;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
declare const UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
|
|
47
46
|
declare const ERROR_SYMBOL = "__PS_ERROR__";
|
|
48
47
|
declare const IS_HMR: boolean;
|
|
49
48
|
declare const IS_ONLY_GENERATE: boolean;
|
|
@@ -105,4 +104,4 @@ declare class CustomResponse<Value> {
|
|
|
105
104
|
}
|
|
106
105
|
type ExtractResponse<Class extends CustomResponse<any>> = Class extends CustomResponse<infer Value> ? Value : never;
|
|
107
106
|
|
|
108
|
-
export { BaseContext as B, ControllerMetaData as C, DefaultOptions as D, Emitter as E, IS_HMR as I, LOG_LEVEL as L, MetaData as M, OmitFunction as O, PickFunc as P, ServiceMetaData as S, ToClientMap as T,
|
|
107
|
+
export { type BaseContext as B, type ControllerMetaData as C, type DefaultOptions as D, type Emitter as E, IS_HMR as I, LOG_LEVEL as L, type MetaData as M, type OmitFunction as O, type PickFunc as P, type ServiceMetaData as S, type ToClientMap as T, type BaseError as a, type ToClientInstance as b, type ToClientFn as c, type BaseReturn as d, type BaseRequestType as e, CustomResponse as f, type ExtractResponse as g, Meta as h, type ControllerMeta as i, ERROR_SYMBOL as j, IS_ONLY_GENERATE as k, IS_STRICT as l, PS_EXIT_CODE as m };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Events, Construct } from 'phecda-core';
|
|
2
|
+
|
|
3
|
+
interface ServiceMetaData {
|
|
4
|
+
func: string;
|
|
5
|
+
name: string;
|
|
6
|
+
tag: string;
|
|
7
|
+
define?: any;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
interface ControllerMetaData extends ServiceMetaData {
|
|
11
|
+
controller: string;
|
|
12
|
+
http?: {
|
|
13
|
+
type: BaseRequestType;
|
|
14
|
+
prefix: string;
|
|
15
|
+
route: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
};
|
|
18
|
+
rpc?: {
|
|
19
|
+
queue?: string;
|
|
20
|
+
isEvent?: boolean;
|
|
21
|
+
};
|
|
22
|
+
ctxs?: string[];
|
|
23
|
+
params: {
|
|
24
|
+
type: string;
|
|
25
|
+
index: number;
|
|
26
|
+
key: string;
|
|
27
|
+
pipe?: string;
|
|
28
|
+
define: Record<string, any>;
|
|
29
|
+
}[];
|
|
30
|
+
guards: string[];
|
|
31
|
+
pipe?: string;
|
|
32
|
+
filter?: string;
|
|
33
|
+
interceptors: string[];
|
|
34
|
+
plugins: string[];
|
|
35
|
+
}
|
|
36
|
+
type MetaData = ControllerMetaData | ServiceMetaData;
|
|
37
|
+
declare class Meta {
|
|
38
|
+
data: MetaData;
|
|
39
|
+
paramsType: any[];
|
|
40
|
+
constructor(data: MetaData, paramsType: any[]);
|
|
41
|
+
}
|
|
42
|
+
interface ControllerMeta extends Meta {
|
|
43
|
+
data: ControllerMetaData;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare const ERROR_SYMBOL = "__PS_ERROR__";
|
|
47
|
+
declare const IS_HMR: boolean;
|
|
48
|
+
declare const IS_ONLY_GENERATE: boolean;
|
|
49
|
+
declare const IS_STRICT: boolean;
|
|
50
|
+
declare const LOG_LEVEL: number;
|
|
51
|
+
declare enum PS_EXIT_CODE {
|
|
52
|
+
RELAUNCH = 2,
|
|
53
|
+
CODE = 4
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Emitter {
|
|
57
|
+
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
58
|
+
once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
59
|
+
off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
60
|
+
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
61
|
+
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
62
|
+
}
|
|
63
|
+
type AnyFunction = (...args: any) => any;
|
|
64
|
+
type ParseInstance<Instance extends Record<string, AnyFunction>> = {
|
|
65
|
+
[Key in keyof Instance]: ToClientFn<Instance[Key]>;
|
|
66
|
+
};
|
|
67
|
+
type PickFuncKeys<Type> = {
|
|
68
|
+
[Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never;
|
|
69
|
+
}[keyof Type];
|
|
70
|
+
type ToClientMap<ControllerMap extends Record<string, Construct>> = {
|
|
71
|
+
[Key in keyof ControllerMap]: ToClientInstance<InstanceType<ControllerMap[Key]>>;
|
|
72
|
+
};
|
|
73
|
+
type ToClientInstance<Instance extends Record<string, any>> = ParseInstance<PickFunc<Instance>>;
|
|
74
|
+
type ToClientFn<Func extends AnyFunction> = (...p: Parameters<Func>) => Promise<BaseReturn<ReturnType<Func>>>;
|
|
75
|
+
type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
|
|
76
|
+
type OmitFunction<Instance> = Omit<Instance, PickFuncKeys<Instance>>;
|
|
77
|
+
interface BaseContext {
|
|
78
|
+
meta: ControllerMeta;
|
|
79
|
+
moduleMap: Record<string, any>;
|
|
80
|
+
type: string;
|
|
81
|
+
tag: string;
|
|
82
|
+
func: string;
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
85
|
+
interface DefaultOptions {
|
|
86
|
+
globalGuards?: string[];
|
|
87
|
+
globalInterceptors?: string[];
|
|
88
|
+
globalFilter?: string;
|
|
89
|
+
globalPipe?: string;
|
|
90
|
+
}
|
|
91
|
+
interface BaseError {
|
|
92
|
+
[ERROR_SYMBOL]: true;
|
|
93
|
+
status: number;
|
|
94
|
+
message: string;
|
|
95
|
+
description: string;
|
|
96
|
+
}
|
|
97
|
+
type BaseReturn<T> = Awaited<T> extends {
|
|
98
|
+
toJSON(): infer R;
|
|
99
|
+
} ? R : Awaited<T>;
|
|
100
|
+
type BaseRequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
101
|
+
declare const ResponseSymbol: unique symbol;
|
|
102
|
+
declare class CustomResponse<Value> {
|
|
103
|
+
[ResponseSymbol]: Value;
|
|
104
|
+
}
|
|
105
|
+
type ExtractResponse<Class extends CustomResponse<any>> = Class extends CustomResponse<infer Value> ? Value : never;
|
|
106
|
+
|
|
107
|
+
export { type BaseContext as B, type ControllerMetaData as C, type DefaultOptions as D, type Emitter as E, IS_HMR as I, LOG_LEVEL as L, type MetaData as M, type OmitFunction as O, type PickFunc as P, type ServiceMetaData as S, type ToClientMap as T, type BaseError as a, type ToClientInstance as b, type ToClientFn as c, type BaseReturn as d, type BaseRequestType as e, CustomResponse as f, type ExtractResponse as g, Meta as h, type ControllerMeta as i, ERROR_SYMBOL as j, IS_ONLY_GENERATE as k, IS_STRICT as l, PS_EXIT_CODE as m };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DefaultOptions, B as BaseContext } from './types-
|
|
1
|
+
import { D as DefaultOptions, B as BaseContext } from './types-BlIBlnVT.js';
|
|
2
2
|
|
|
3
3
|
interface RpcServerOptions extends DefaultOptions {
|
|
4
4
|
}
|
|
@@ -14,4 +14,4 @@ interface RpcContext extends BaseContext {
|
|
|
14
14
|
isEvent?: boolean;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export { RpcServerOptions as R, RpcClientOptions as a, RpcContext as b };
|
|
17
|
+
export type { RpcServerOptions as R, RpcClientOptions as a, RpcContext as b };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IncomingHttpHeaders } from 'node:http';
|
|
2
|
+
import { D as DefaultOptions, B as BaseContext } from './types-BlIBlnVT.mjs';
|
|
3
|
+
|
|
4
|
+
interface HttpOptions extends DefaultOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 专用路由的值,默认为/__PHECDA_SERVER__,处理phecda-client发出的合并请求
|
|
7
|
+
*/
|
|
8
|
+
parallelRoute?: string | false;
|
|
9
|
+
/**
|
|
10
|
+
* 专用路由的插件(work for merge request),
|
|
11
|
+
*/
|
|
12
|
+
parallelPlugins?: string[];
|
|
13
|
+
/**
|
|
14
|
+
* only work for http server
|
|
15
|
+
*/
|
|
16
|
+
globalPlugins?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface HttpContext extends BaseContext {
|
|
19
|
+
parallel?: true;
|
|
20
|
+
index?: number;
|
|
21
|
+
query: Record<string, any>;
|
|
22
|
+
params: Record<string, string>;
|
|
23
|
+
body: Record<string, any>;
|
|
24
|
+
headers: IncomingHttpHeaders;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type { HttpOptions as H, HttpContext as a };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingHttpHeaders } from 'node:http';
|
|
2
|
-
import { D as DefaultOptions, B as BaseContext } from './types-
|
|
2
|
+
import { D as DefaultOptions, B as BaseContext } from './types-BlIBlnVT.js';
|
|
3
3
|
|
|
4
4
|
interface HttpOptions extends DefaultOptions {
|
|
5
5
|
/**
|
|
@@ -24,4 +24,4 @@ interface HttpContext extends BaseContext {
|
|
|
24
24
|
headers: IncomingHttpHeaders;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export { HttpOptions as H, HttpContext as a };
|
|
27
|
+
export type { HttpOptions as H, HttpContext as a };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { D as DefaultOptions, B as BaseContext } from './types-BlIBlnVT.mjs';
|
|
2
|
+
|
|
3
|
+
interface RpcServerOptions extends DefaultOptions {
|
|
4
|
+
}
|
|
5
|
+
interface RpcClientOptions {
|
|
6
|
+
key?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
}
|
|
10
|
+
interface RpcContext extends BaseContext {
|
|
11
|
+
args: any[];
|
|
12
|
+
id: string;
|
|
13
|
+
queue: string;
|
|
14
|
+
isEvent?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { RpcServerOptions as R, RpcClientOptions as a, RpcContext as b };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-server",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.6",
|
|
4
4
|
"description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
|
|
5
5
|
"author": "fgsreally",
|
|
6
6
|
"license": "MIT",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"fs-extra": "^11.2.0",
|
|
146
146
|
"picocolors": "^1.0.0",
|
|
147
147
|
"reflect-metadata": "^0.1.13",
|
|
148
|
-
"phecda-core": "3.0.
|
|
148
|
+
"phecda-core": "3.0.2"
|
|
149
149
|
},
|
|
150
150
|
"devDependencies": {
|
|
151
151
|
"@koa/router": "^12.0.1",
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
"mock-amqplib": "^1.8.2",
|
|
174
174
|
"nats": "^2.22.0",
|
|
175
175
|
"supertest": "^6.3.3",
|
|
176
|
-
"tsup": "^
|
|
176
|
+
"tsup": "^8.1.0",
|
|
177
177
|
"typescript": "^5.4.5",
|
|
178
178
|
"unimport": "^3.7.1"
|
|
179
179
|
},
|