phecda-server 5.0.2 → 5.1.1
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/README.md +4 -102
- package/bin/cli.mjs +17 -14
- package/dist/{chunk-RCTOVYZY.mjs → chunk-2HKQPZDT.mjs} +1 -1
- package/dist/{chunk-BXLBWRHS.js → chunk-3BV2GRS7.js} +38 -38
- package/dist/{chunk-AB4OX3WV.mjs → chunk-665MB62T.mjs} +127 -99
- package/dist/{chunk-YERBWZCS.js → chunk-FSBD5R22.js} +180 -152
- package/dist/{chunk-F5YWXY5W.js → chunk-HMPTPTFL.js} +17 -17
- package/dist/{chunk-W5EOVGQD.mjs → chunk-UU6RHGRF.mjs} +2 -2
- package/dist/{chunk-ITTD2GBR.mjs → chunk-VLV3AO3H.mjs} +7 -19
- package/dist/{chunk-YR5Q5F2K.js → chunk-ZP7HNASU.js} +7 -19
- package/dist/{core-fd134ffa.d.ts → core-39f27fe8.d.ts} +4 -3
- package/dist/{helper-73e8d2f0.d.ts → helper-6133f78f.d.ts} +1 -1
- package/dist/{helper-f29f082f.d.ts → helper-fcbf6aa8.d.ts} +4 -3
- package/dist/index.d.ts +27 -32
- package/dist/index.js +44 -40
- package/dist/index.mjs +14 -10
- package/dist/rpc/bullmq/index.d.ts +10 -6
- package/dist/rpc/bullmq/index.js +32 -53
- package/dist/rpc/bullmq/index.mjs +26 -47
- package/dist/rpc/kafka/index.d.ts +10 -4
- package/dist/rpc/kafka/index.js +20 -37
- package/dist/rpc/kafka/index.mjs +15 -32
- package/dist/rpc/nats/index.d.ts +2 -2
- package/dist/rpc/nats/index.js +20 -34
- package/dist/rpc/nats/index.mjs +13 -27
- package/dist/rpc/rabbitmq/index.d.ts +2 -2
- package/dist/rpc/rabbitmq/index.js +23 -37
- package/dist/rpc/rabbitmq/index.mjs +14 -28
- package/dist/rpc/redis/index.d.ts +10 -4
- package/dist/rpc/redis/index.js +23 -37
- package/dist/rpc/redis/index.mjs +16 -30
- package/dist/server/elysia/index.d.ts +4 -3
- package/dist/server/elysia/index.js +77 -94
- package/dist/server/elysia/index.mjs +74 -91
- package/dist/server/express/index.d.ts +5 -4
- package/dist/server/express/index.js +79 -93
- package/dist/server/express/index.mjs +77 -91
- package/dist/server/fastify/index.d.ts +8 -5
- package/dist/server/fastify/index.js +83 -102
- package/dist/server/fastify/index.mjs +79 -98
- package/dist/server/h3/index.d.ts +5 -4
- package/dist/server/h3/index.js +81 -97
- package/dist/server/h3/index.mjs +80 -96
- package/dist/server/hono/index.d.ts +5 -4
- package/dist/server/hono/index.js +73 -90
- package/dist/server/hono/index.mjs +72 -89
- package/dist/server/hyper-express/index.d.ts +6 -5
- package/dist/server/hyper-express/index.js +78 -96
- package/dist/server/hyper-express/index.mjs +77 -95
- package/dist/server/koa/index.d.ts +5 -4
- package/dist/server/koa/index.js +79 -92
- package/dist/server/koa/index.mjs +76 -89
- package/dist/test.d.ts +1 -1
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/package.json +9 -8
- package/register/loader.mjs +19 -5
|
@@ -3,33 +3,29 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
7
6
|
|
|
7
|
+
var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
|
|
10
11
|
|
|
11
12
|
// src/rpc/rabbitmq/bind.ts
|
|
12
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
13
14
|
var debug = _debug2.default.call(void 0, "phecda-server/rabbitmq");
|
|
14
15
|
async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
15
16
|
const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
|
|
16
|
-
const metaMap =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { tag, func, controller, rpc } = item.data;
|
|
22
|
-
if (controller !== "rpc" || _optionalChain([rpc, 'optionalAccess', _ => _.queue]) === void 0)
|
|
23
|
-
continue;
|
|
24
|
-
if (metaMap.has(tag))
|
|
25
|
-
metaMap.get(tag)[func] = item;
|
|
26
|
-
else
|
|
27
|
-
metaMap.set(tag, {
|
|
28
|
-
[func]: item
|
|
29
|
-
});
|
|
17
|
+
const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
18
|
+
const { controller, rpc, func, tag } = meta2.data;
|
|
19
|
+
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
20
|
+
debug(`register method "${func}" in module "${tag}"`);
|
|
21
|
+
return true;
|
|
30
22
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
23
|
+
});
|
|
24
|
+
_chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
|
|
25
|
+
guards: globalGuards,
|
|
26
|
+
interceptors: globalInterceptors
|
|
27
|
+
}, "rpc");
|
|
28
|
+
const existQueue = /* @__PURE__ */ new Set();
|
|
33
29
|
async function subscribeQueues() {
|
|
34
30
|
existQueue.clear();
|
|
35
31
|
for (const [tag, record] of metaMap) {
|
|
@@ -49,12 +45,12 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
|
-
|
|
48
|
+
_chunkZP7HNASUjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
53
49
|
async function handleRequest(msg) {
|
|
54
50
|
function send(queue, data) {
|
|
55
51
|
ch.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
|
|
56
52
|
}
|
|
57
|
-
|
|
53
|
+
_chunkZP7HNASUjs.__name.call(void 0, send, "send");
|
|
58
54
|
if (msg) {
|
|
59
55
|
const data = JSON.parse(msg.content.toString());
|
|
60
56
|
const { tag, func, id, queue: clientQueue, _ps, args } = data;
|
|
@@ -63,7 +59,7 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
63
59
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
64
60
|
const meta2 = metaMap.get(tag)[func];
|
|
65
61
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
66
|
-
const context = new (0,
|
|
62
|
+
const context = new (0, _chunkFSBD5R22js.Context)({
|
|
67
63
|
type: "rabbitmq",
|
|
68
64
|
moduleMap,
|
|
69
65
|
meta: meta2,
|
|
@@ -97,25 +93,15 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
97
93
|
});
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
|
-
|
|
101
|
-
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
102
|
-
guards: globalGuards,
|
|
103
|
-
interceptors: globalInterceptors
|
|
104
|
-
}, "rpc");
|
|
105
|
-
handleMeta();
|
|
96
|
+
_chunkZP7HNASUjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
106
97
|
subscribeQueues();
|
|
107
|
-
|
|
108
|
-
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
109
|
-
guards: globalGuards,
|
|
110
|
-
interceptors: globalInterceptors
|
|
111
|
-
}, "rpc");
|
|
112
|
-
handleMeta();
|
|
98
|
+
_chunkFSBD5R22js.HMR.call(void 0, async () => {
|
|
113
99
|
for (const queue of existQueue)
|
|
114
100
|
await ch.deleteQueue(queue);
|
|
115
101
|
await subscribeQueues();
|
|
116
102
|
});
|
|
117
103
|
}
|
|
118
|
-
|
|
104
|
+
_chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
|
|
119
105
|
|
|
120
106
|
// src/rpc/rabbitmq/client.ts
|
|
121
107
|
var _events = require('events');
|
|
@@ -124,7 +110,7 @@ async function createClient(ch, controllers, opts) {
|
|
|
124
110
|
let eventCount = 0;
|
|
125
111
|
const ret = {};
|
|
126
112
|
const emitter = new (0, _events.EventEmitter)();
|
|
127
|
-
const clientQueue =
|
|
113
|
+
const clientQueue = _chunkFSBD5R22js.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
|
|
128
114
|
await ch.assertQueue(clientQueue);
|
|
129
115
|
ch.consume(clientQueue, (msg) => {
|
|
130
116
|
if (!msg)
|
|
@@ -176,7 +162,7 @@ async function createClient(ch, controllers, opts) {
|
|
|
176
162
|
else
|
|
177
163
|
resolve(data);
|
|
178
164
|
}
|
|
179
|
-
|
|
165
|
+
_chunkZP7HNASUjs.__name.call(void 0, listener, "listener");
|
|
180
166
|
eventCount++;
|
|
181
167
|
emitter.once(id, listener);
|
|
182
168
|
});
|
|
@@ -186,7 +172,7 @@ async function createClient(ch, controllers, opts) {
|
|
|
186
172
|
}
|
|
187
173
|
return ret;
|
|
188
174
|
}
|
|
189
|
-
|
|
175
|
+
_chunkZP7HNASUjs.__name.call(void 0, createClient, "createClient");
|
|
190
176
|
|
|
191
177
|
|
|
192
178
|
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
3
|
HMR,
|
|
4
|
+
createControllerMetaMap,
|
|
4
5
|
detectAopDep,
|
|
5
6
|
genClientQueue
|
|
6
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-665MB62T.mjs";
|
|
7
8
|
import {
|
|
8
9
|
__name
|
|
9
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-VLV3AO3H.mjs";
|
|
10
11
|
|
|
11
12
|
// src/rpc/rabbitmq/bind.ts
|
|
12
13
|
import Debug from "debug";
|
|
13
14
|
var debug = Debug("phecda-server/rabbitmq");
|
|
14
15
|
async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
15
16
|
const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
|
|
16
|
-
const metaMap =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { tag, func, controller, rpc } = item.data;
|
|
22
|
-
if (controller !== "rpc" || rpc?.queue === void 0)
|
|
23
|
-
continue;
|
|
24
|
-
if (metaMap.has(tag))
|
|
25
|
-
metaMap.get(tag)[func] = item;
|
|
26
|
-
else
|
|
27
|
-
metaMap.set(tag, {
|
|
28
|
-
[func]: item
|
|
29
|
-
});
|
|
17
|
+
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
18
|
+
const { controller, rpc, func, tag } = meta2.data;
|
|
19
|
+
if (controller === "rpc" && rpc?.queue !== void 0) {
|
|
20
|
+
debug(`register method "${func}" in module "${tag}"`);
|
|
21
|
+
return true;
|
|
30
22
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
23
|
+
});
|
|
24
|
+
detectAopDep(meta, {
|
|
25
|
+
guards: globalGuards,
|
|
26
|
+
interceptors: globalInterceptors
|
|
27
|
+
}, "rpc");
|
|
28
|
+
const existQueue = /* @__PURE__ */ new Set();
|
|
33
29
|
async function subscribeQueues() {
|
|
34
30
|
existQueue.clear();
|
|
35
31
|
for (const [tag, record] of metaMap) {
|
|
@@ -98,18 +94,8 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
96
|
__name(handleRequest, "handleRequest");
|
|
101
|
-
detectAopDep(meta, {
|
|
102
|
-
guards: globalGuards,
|
|
103
|
-
interceptors: globalInterceptors
|
|
104
|
-
}, "rpc");
|
|
105
|
-
handleMeta();
|
|
106
97
|
subscribeQueues();
|
|
107
98
|
HMR(async () => {
|
|
108
|
-
detectAopDep(meta, {
|
|
109
|
-
guards: globalGuards,
|
|
110
|
-
interceptors: globalInterceptors
|
|
111
|
-
}, "rpc");
|
|
112
|
-
handleMeta();
|
|
113
99
|
for (const queue of existQueue)
|
|
114
100
|
await ch.deleteQueue(queue);
|
|
115
101
|
await subscribeQueues();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { F as Factory, T as ToClientMap } from '../../core-
|
|
3
|
-
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../helper-
|
|
2
|
+
import { F as Factory, T as ToClientMap } from '../../core-39f27fe8.js';
|
|
3
|
+
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../helper-6133f78f.js';
|
|
4
4
|
import 'phecda-core';
|
|
5
5
|
|
|
6
6
|
interface RedisCtx extends RpcContext {
|
|
@@ -9,8 +9,14 @@ interface RedisCtx extends RpcContext {
|
|
|
9
9
|
msg: string;
|
|
10
10
|
channel: string;
|
|
11
11
|
}
|
|
12
|
-
declare function bind(sub
|
|
12
|
+
declare function bind({ sub, pub }: {
|
|
13
|
+
sub: Redis;
|
|
14
|
+
pub: Redis;
|
|
15
|
+
}, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
|
|
13
16
|
|
|
14
|
-
declare function createClient<S extends Record<string, any>>(pub
|
|
17
|
+
declare function createClient<S extends Record<string, any>>({ pub, sub }: {
|
|
18
|
+
pub: Redis;
|
|
19
|
+
sub: Redis;
|
|
20
|
+
}, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
|
|
15
21
|
|
|
16
22
|
export { RedisCtx, bind, createClient };
|
package/dist/rpc/redis/index.js
CHANGED
|
@@ -3,33 +3,29 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
7
6
|
|
|
7
|
+
var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
|
|
10
11
|
|
|
11
12
|
// src/rpc/redis/bind.ts
|
|
12
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
13
14
|
var debug = _debug2.default.call(void 0, "phecda-server/redis");
|
|
14
|
-
function bind(sub, pub, { moduleMap, meta }, opts = {}) {
|
|
15
|
+
function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
15
16
|
const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
|
|
16
|
-
const metaMap =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { tag, func, controller, rpc } = item.data;
|
|
22
|
-
if (controller !== "rpc" || _optionalChain([rpc, 'optionalAccess', _ => _.queue]) === void 0)
|
|
23
|
-
continue;
|
|
24
|
-
if (metaMap.has(tag))
|
|
25
|
-
metaMap.get(tag)[func] = item;
|
|
26
|
-
else
|
|
27
|
-
metaMap.set(tag, {
|
|
28
|
-
[func]: item
|
|
29
|
-
});
|
|
17
|
+
const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
18
|
+
const { controller, rpc, func, tag } = meta2.data;
|
|
19
|
+
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
20
|
+
debug(`register method "${func}" in module "${tag}"`);
|
|
21
|
+
return true;
|
|
30
22
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
23
|
+
});
|
|
24
|
+
_chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
|
|
25
|
+
guards: globalGuards,
|
|
26
|
+
interceptors: globalInterceptors
|
|
27
|
+
}, "rpc");
|
|
28
|
+
const existQueue = /* @__PURE__ */ new Set();
|
|
33
29
|
async function subscribeQueues() {
|
|
34
30
|
existQueue.clear();
|
|
35
31
|
for (const [tag, record] of metaMap) {
|
|
@@ -46,7 +42,7 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
|
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
|
-
|
|
45
|
+
_chunkZP7HNASUjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
50
46
|
sub.on("message", async (channel, msg) => {
|
|
51
47
|
if (!existQueue.has(channel))
|
|
52
48
|
return;
|
|
@@ -58,7 +54,7 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
|
|
|
58
54
|
return;
|
|
59
55
|
const meta2 = metaMap.get(tag)[func];
|
|
60
56
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
61
|
-
const context = new (0,
|
|
57
|
+
const context = new (0, _chunkFSBD5R22js.Context)({
|
|
62
58
|
type: "redis",
|
|
63
59
|
moduleMap,
|
|
64
60
|
redis: sub,
|
|
@@ -94,33 +90,23 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
|
|
|
94
90
|
});
|
|
95
91
|
}
|
|
96
92
|
});
|
|
97
|
-
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
98
|
-
guards: globalGuards,
|
|
99
|
-
interceptors: globalInterceptors
|
|
100
|
-
}, "rpc");
|
|
101
|
-
handleMeta();
|
|
102
93
|
subscribeQueues();
|
|
103
|
-
|
|
104
|
-
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
105
|
-
guards: globalGuards,
|
|
106
|
-
interceptors: globalInterceptors
|
|
107
|
-
}, "rpc");
|
|
108
|
-
handleMeta();
|
|
94
|
+
_chunkFSBD5R22js.HMR.call(void 0, async () => {
|
|
109
95
|
for (const queue of existQueue)
|
|
110
96
|
await sub.unsubscribe(queue);
|
|
111
97
|
subscribeQueues();
|
|
112
98
|
});
|
|
113
99
|
}
|
|
114
|
-
|
|
100
|
+
_chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
|
|
115
101
|
|
|
116
102
|
// src/rpc/redis/client.ts
|
|
117
103
|
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
118
|
-
async function createClient(pub, sub, controllers, opts) {
|
|
104
|
+
async function createClient({ pub, sub }, controllers, opts) {
|
|
119
105
|
const ret = {};
|
|
120
106
|
let eventId = 1;
|
|
121
107
|
let eventCount = 0;
|
|
122
108
|
const emitter = new (0, _events2.default)();
|
|
123
|
-
const clientQueue =
|
|
109
|
+
const clientQueue = _chunkFSBD5R22js.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
|
|
124
110
|
await sub.subscribe(clientQueue);
|
|
125
111
|
for (const i in controllers) {
|
|
126
112
|
ret[i] = new Proxy(new controllers[i](), {
|
|
@@ -166,7 +152,7 @@ async function createClient(pub, sub, controllers, opts) {
|
|
|
166
152
|
else
|
|
167
153
|
resolve(data);
|
|
168
154
|
}
|
|
169
|
-
|
|
155
|
+
_chunkZP7HNASUjs.__name.call(void 0, listener, "listener");
|
|
170
156
|
eventCount++;
|
|
171
157
|
emitter.once(id, listener);
|
|
172
158
|
});
|
|
@@ -182,7 +168,7 @@ async function createClient(pub, sub, controllers, opts) {
|
|
|
182
168
|
});
|
|
183
169
|
return ret;
|
|
184
170
|
}
|
|
185
|
-
|
|
171
|
+
_chunkZP7HNASUjs.__name.call(void 0, createClient, "createClient");
|
|
186
172
|
|
|
187
173
|
|
|
188
174
|
|
package/dist/rpc/redis/index.mjs
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
3
|
HMR,
|
|
4
|
+
createControllerMetaMap,
|
|
4
5
|
detectAopDep,
|
|
5
6
|
genClientQueue
|
|
6
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-665MB62T.mjs";
|
|
7
8
|
import {
|
|
8
9
|
__name
|
|
9
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-VLV3AO3H.mjs";
|
|
10
11
|
|
|
11
12
|
// src/rpc/redis/bind.ts
|
|
12
13
|
import Debug from "debug";
|
|
13
14
|
var debug = Debug("phecda-server/redis");
|
|
14
|
-
function bind(sub, pub, { moduleMap, meta }, opts = {}) {
|
|
15
|
+
function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
15
16
|
const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
|
|
16
|
-
const metaMap =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { tag, func, controller, rpc } = item.data;
|
|
22
|
-
if (controller !== "rpc" || rpc?.queue === void 0)
|
|
23
|
-
continue;
|
|
24
|
-
if (metaMap.has(tag))
|
|
25
|
-
metaMap.get(tag)[func] = item;
|
|
26
|
-
else
|
|
27
|
-
metaMap.set(tag, {
|
|
28
|
-
[func]: item
|
|
29
|
-
});
|
|
17
|
+
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
18
|
+
const { controller, rpc, func, tag } = meta2.data;
|
|
19
|
+
if (controller === "rpc" && rpc?.queue !== void 0) {
|
|
20
|
+
debug(`register method "${func}" in module "${tag}"`);
|
|
21
|
+
return true;
|
|
30
22
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
23
|
+
});
|
|
24
|
+
detectAopDep(meta, {
|
|
25
|
+
guards: globalGuards,
|
|
26
|
+
interceptors: globalInterceptors
|
|
27
|
+
}, "rpc");
|
|
28
|
+
const existQueue = /* @__PURE__ */ new Set();
|
|
33
29
|
async function subscribeQueues() {
|
|
34
30
|
existQueue.clear();
|
|
35
31
|
for (const [tag, record] of metaMap) {
|
|
@@ -94,18 +90,8 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
|
|
|
94
90
|
});
|
|
95
91
|
}
|
|
96
92
|
});
|
|
97
|
-
detectAopDep(meta, {
|
|
98
|
-
guards: globalGuards,
|
|
99
|
-
interceptors: globalInterceptors
|
|
100
|
-
}, "rpc");
|
|
101
|
-
handleMeta();
|
|
102
93
|
subscribeQueues();
|
|
103
94
|
HMR(async () => {
|
|
104
|
-
detectAopDep(meta, {
|
|
105
|
-
guards: globalGuards,
|
|
106
|
-
interceptors: globalInterceptors
|
|
107
|
-
}, "rpc");
|
|
108
|
-
handleMeta();
|
|
109
95
|
for (const queue of existQueue)
|
|
110
96
|
await sub.unsubscribe(queue);
|
|
111
97
|
subscribeQueues();
|
|
@@ -115,7 +101,7 @@ __name(bind, "bind");
|
|
|
115
101
|
|
|
116
102
|
// src/rpc/redis/client.ts
|
|
117
103
|
import EventEmitter from "events";
|
|
118
|
-
async function createClient(pub, sub, controllers, opts) {
|
|
104
|
+
async function createClient({ pub, sub }, controllers, opts) {
|
|
119
105
|
const ret = {};
|
|
120
106
|
let eventId = 1;
|
|
121
107
|
let eventCount = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { a as HttpContext, H as HttpOptions } from '../../helper-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { a as HttpContext, H as HttpOptions } from '../../helper-fcbf6aa8.js';
|
|
4
|
+
import { F as Factory } from '../../core-39f27fe8.js';
|
|
5
5
|
import 'node:http';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
@@ -10,7 +10,8 @@ interface ElysiaCtx extends HttpContext {
|
|
|
10
10
|
app: Elysia$1;
|
|
11
11
|
context: Context;
|
|
12
12
|
}
|
|
13
|
+
type Plugin = (app: Elysia$1<any>) => void;
|
|
13
14
|
declare function bind(app: Elysia$1<any>, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
14
15
|
declare function Elysia(opts: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>): any;
|
|
15
16
|
|
|
16
|
-
export { Elysia, ElysiaCtx, bind };
|
|
17
|
+
export { Elysia, ElysiaCtx, Plugin, bind };
|
|
@@ -1,105 +1,103 @@
|
|
|
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 _chunk3BV2GRS7js = require('../../chunk-3BV2GRS7.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
|
|
14
14
|
|
|
15
15
|
// src/server/elysia/bind.ts
|
|
16
16
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
17
17
|
var _elysia = require('elysia');
|
|
18
18
|
var debug = _debug2.default.call(void 0, "phecda-server/elysia");
|
|
19
19
|
function bind(app, data, opts = {}) {
|
|
20
|
-
const { globalGuards, globalInterceptors,
|
|
21
|
-
route: "/__PHECDA_SERVER__",
|
|
22
|
-
plugins: [],
|
|
23
|
-
...opts
|
|
24
|
-
};
|
|
20
|
+
const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
|
|
25
21
|
const { moduleMap, meta } = data;
|
|
26
|
-
const metaMap =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (const item of meta) {
|
|
30
|
-
const { tag, func, controller, http } = item.data;
|
|
31
|
-
if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
|
|
32
|
-
continue;
|
|
22
|
+
const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
23
|
+
const { controller, http, func, tag } = meta2.data;
|
|
24
|
+
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
33
25
|
debug(`register method "${func}" in module "${tag}"`);
|
|
34
|
-
|
|
35
|
-
metaMap.get(tag)[func] = item;
|
|
36
|
-
else
|
|
37
|
-
metaMap.set(tag, {
|
|
38
|
-
[func]: item
|
|
39
|
-
});
|
|
26
|
+
return true;
|
|
40
27
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
});
|
|
29
|
+
_chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
|
|
30
|
+
plugins: [
|
|
31
|
+
...globalPlugins,
|
|
32
|
+
...parallelPlugins
|
|
33
|
+
],
|
|
34
|
+
guards: globalGuards,
|
|
35
|
+
interceptors: globalInterceptors
|
|
36
|
+
});
|
|
37
|
+
registerRoute();
|
|
38
|
+
async function registerRoute() {
|
|
39
|
+
_chunkFSBD5R22js.Context.usePlugin(globalPlugins, "elysia").forEach((p) => p(app));
|
|
44
40
|
const parallelRouter = new (0, _elysia.Elysia)();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
41
|
+
_chunkFSBD5R22js.Context.usePlugin(parallelPlugins, "elysia").forEach((p) => p(parallelRouter));
|
|
42
|
+
if (parallelRoute) {
|
|
43
|
+
parallelRouter.post(parallelRoute, async (c) => {
|
|
44
|
+
const { body } = c;
|
|
45
|
+
async function errorHandler(e) {
|
|
46
|
+
const error = await _chunkFSBD5R22js.Context.filterRecord.default(e);
|
|
47
|
+
c.set.status = error.status;
|
|
48
|
+
return error;
|
|
49
|
+
}
|
|
50
|
+
_chunkZP7HNASUjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
51
|
+
if (!Array.isArray(body))
|
|
52
|
+
return errorHandler(new (0, _chunkFSBD5R22js.BadRequestException)("data format should be an array"));
|
|
53
|
+
try {
|
|
54
|
+
return Promise.all(body.map((item, i) => {
|
|
55
|
+
return new Promise(async (resolve) => {
|
|
56
|
+
const { tag, func } = item;
|
|
57
|
+
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
58
|
+
if (!metaMap.has(tag))
|
|
59
|
+
return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
60
|
+
const meta2 = metaMap.get(tag)[func];
|
|
61
|
+
if (!meta2)
|
|
62
|
+
return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
63
|
+
const { data: { params } } = meta2;
|
|
64
|
+
const contextData = {
|
|
65
|
+
type: "elysia",
|
|
66
|
+
parallel: true,
|
|
67
|
+
context: c,
|
|
68
|
+
index: i,
|
|
69
|
+
meta: meta2,
|
|
70
|
+
moduleMap,
|
|
71
|
+
tag,
|
|
72
|
+
func,
|
|
73
|
+
app,
|
|
74
|
+
..._chunkFSBD5R22js.argToReq.call(void 0, params, item.args, c.headers)
|
|
75
|
+
};
|
|
76
|
+
const context = new (0, _chunkFSBD5R22js.Context)(contextData);
|
|
77
|
+
context.run({
|
|
78
|
+
globalGuards,
|
|
79
|
+
globalInterceptors,
|
|
80
|
+
globalFilter,
|
|
81
|
+
globalPipe
|
|
82
|
+
}, resolve, resolve);
|
|
83
|
+
});
|
|
84
|
+
})).then((ret) => {
|
|
85
|
+
return ret;
|
|
86
86
|
});
|
|
87
|
-
}
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
});
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return errorHandler(e);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
94
92
|
app.use(parallelRouter);
|
|
95
93
|
for (const [tag, record] of metaMap) {
|
|
96
94
|
for (const func in record) {
|
|
97
95
|
const meta2 = metaMap.get(tag)[func];
|
|
98
|
-
const { data: { define, plugins
|
|
96
|
+
const { data: { define, plugins, http } } = meta2;
|
|
99
97
|
const funcRouter = new (0, _elysia.Elysia)();
|
|
100
98
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
101
99
|
continue;
|
|
102
|
-
|
|
100
|
+
_chunkFSBD5R22js.Context.usePlugin(plugins, "elysia").forEach((p) => p(funcRouter));
|
|
103
101
|
funcRouter[http.type](http.prefix + http.route, async (c) => {
|
|
104
102
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
105
103
|
const contextData = {
|
|
@@ -115,7 +113,7 @@ function bind(app, data, opts = {}) {
|
|
|
115
113
|
headers: c.headers,
|
|
116
114
|
app
|
|
117
115
|
};
|
|
118
|
-
const context = new (0,
|
|
116
|
+
const context = new (0, _chunkFSBD5R22js.Context)(contextData);
|
|
119
117
|
if (http.headers)
|
|
120
118
|
c.set.headers = http.headers;
|
|
121
119
|
return context.run({
|
|
@@ -132,28 +130,13 @@ function bind(app, data, opts = {}) {
|
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
|
-
|
|
136
|
-
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
137
|
-
plugins,
|
|
138
|
-
guards: globalGuards,
|
|
139
|
-
interceptors: globalInterceptors
|
|
140
|
-
});
|
|
141
|
-
handleMeta();
|
|
142
|
-
createRoute();
|
|
143
|
-
_chunkYERBWZCSjs.HMR.call(void 0, async () => {
|
|
144
|
-
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
145
|
-
plugins,
|
|
146
|
-
guards: globalGuards,
|
|
147
|
-
interceptors: globalInterceptors
|
|
148
|
-
});
|
|
149
|
-
handleMeta();
|
|
150
|
-
});
|
|
133
|
+
_chunkZP7HNASUjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
151
134
|
}
|
|
152
|
-
|
|
135
|
+
_chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
|
|
153
136
|
function Elysia(opts) {
|
|
154
|
-
return
|
|
137
|
+
return _chunk3BV2GRS7js.Define.call(void 0, "elysia", opts);
|
|
155
138
|
}
|
|
156
|
-
|
|
139
|
+
_chunkZP7HNASUjs.__name.call(void 0, Elysia, "Elysia");
|
|
157
140
|
|
|
158
141
|
|
|
159
142
|
|