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/rpc/nats/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkQYX5Q7KOjs = require('../../chunk-QYX5Q7KO.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkRVWBJ6LVjs = require('../../chunk-RVWBJ6LV.js');
|
|
10
10
|
|
|
11
11
|
// src/rpc/nats/bind.ts
|
|
12
12
|
var _nats = require('nats');
|
|
@@ -17,14 +17,14 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
17
17
|
const sc = _nats.StringCodec.call(void 0, );
|
|
18
18
|
const subscriptionMap = {};
|
|
19
19
|
const existQueue = /* @__PURE__ */ new Set();
|
|
20
|
-
const metaMap =
|
|
20
|
+
const metaMap = _chunkQYX5Q7KOjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
21
21
|
const { controller, rpc, func, tag } = meta2.data;
|
|
22
22
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _2 => _2.queue]) !== void 0) {
|
|
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
|
guards: globalGuards,
|
|
29
29
|
interceptors: globalInterceptors
|
|
30
30
|
}, "rpc");
|
|
@@ -36,8 +36,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
36
36
|
const { data: { rpc } } = meta2;
|
|
37
37
|
if (rpc) {
|
|
38
38
|
const queue = rpc.queue || tag;
|
|
39
|
-
if (existQueue.has(queue))
|
|
40
|
-
continue;
|
|
39
|
+
if (existQueue.has(queue)) continue;
|
|
41
40
|
existQueue.add(queue);
|
|
42
41
|
subscriptionMap[queue] = nc.subscribe(queue, {
|
|
43
42
|
queue,
|
|
@@ -47,18 +46,16 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
|
|
49
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
51
50
|
async function handleRequest(_, msg) {
|
|
52
51
|
const data = JSON.parse(sc.decode(msg.data));
|
|
53
52
|
const { tag, func, id, _ps, args } = data;
|
|
54
|
-
if (_ps !== 1)
|
|
55
|
-
return;
|
|
53
|
+
if (_ps !== 1) return;
|
|
56
54
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
57
55
|
const meta2 = metaMap.get(tag)[func];
|
|
58
56
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
59
|
-
if (isEvent)
|
|
60
|
-
|
|
61
|
-
const context = new (0, _chunkH6NYBVBVjs.Context)({
|
|
57
|
+
if (isEvent) msg.respond("{}");
|
|
58
|
+
const context = new (0, _chunkQYX5Q7KOjs.Context)({
|
|
62
59
|
type: "nats",
|
|
63
60
|
moduleMap,
|
|
64
61
|
meta: meta2,
|
|
@@ -77,29 +74,26 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
77
74
|
globalFilter,
|
|
78
75
|
globalPipe
|
|
79
76
|
}, (returnData) => {
|
|
80
|
-
if (!isEvent)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})));
|
|
77
|
+
if (!isEvent) msg.respond(sc.encode(JSON.stringify({
|
|
78
|
+
data: returnData,
|
|
79
|
+
id
|
|
80
|
+
})));
|
|
85
81
|
}, (err) => {
|
|
86
|
-
if (!isEvent)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})));
|
|
82
|
+
if (!isEvent) msg.respond(sc.encode(JSON.stringify({
|
|
83
|
+
data: err,
|
|
84
|
+
error: true,
|
|
85
|
+
id
|
|
86
|
+
})));
|
|
92
87
|
});
|
|
93
88
|
}
|
|
94
|
-
|
|
89
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
95
90
|
subscribeQueues();
|
|
96
|
-
|
|
97
|
-
for (const i in subscriptionMap)
|
|
98
|
-
subscriptionMap[i].unsubscribe();
|
|
91
|
+
_chunkQYX5Q7KOjs.HMR.call(void 0, async () => {
|
|
92
|
+
for (const i in subscriptionMap) subscriptionMap[i].unsubscribe();
|
|
99
93
|
await subscribeQueues();
|
|
100
94
|
});
|
|
101
95
|
}
|
|
102
|
-
|
|
96
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, bind, "bind");
|
|
103
97
|
|
|
104
98
|
// src/rpc/nats/client.ts
|
|
105
99
|
|
|
@@ -111,12 +105,10 @@ async function createClient(nc, controllers, opts) {
|
|
|
111
105
|
for (const i in controllers) {
|
|
112
106
|
ret[i] = new Proxy(new controllers[i](), {
|
|
113
107
|
get(target, p) {
|
|
114
|
-
if (typeof target[p] !== "function")
|
|
115
|
-
throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
108
|
+
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
116
109
|
let { tag, queue, isEvent } = target[p]();
|
|
117
110
|
return async (...args) => {
|
|
118
|
-
if (!queue)
|
|
119
|
-
queue = tag;
|
|
111
|
+
if (!queue) queue = tag;
|
|
120
112
|
const id = `${eventId++}`;
|
|
121
113
|
const request = nc.request(queue, sc.encode(JSON.stringify({
|
|
122
114
|
_ps: 1,
|
|
@@ -125,18 +117,15 @@ async function createClient(nc, controllers, opts) {
|
|
|
125
117
|
tag,
|
|
126
118
|
func: p
|
|
127
119
|
})));
|
|
128
|
-
if (isEvent)
|
|
129
|
-
return null;
|
|
120
|
+
if (isEvent) return null;
|
|
130
121
|
return new Promise((resolve, reject) => {
|
|
131
|
-
if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
122
|
+
if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
|
|
123
|
+
type: "exceeded"
|
|
124
|
+
});
|
|
135
125
|
request.catch(reject);
|
|
136
126
|
request.then((msg) => {
|
|
137
127
|
const { data, id: id2, error } = msg.json();
|
|
138
|
-
if (id2)
|
|
139
|
-
handler(data, error);
|
|
128
|
+
if (id2) handler(data, error);
|
|
140
129
|
});
|
|
141
130
|
let isEnd = false;
|
|
142
131
|
const timer = setTimeout(() => {
|
|
@@ -151,12 +140,10 @@ async function createClient(nc, controllers, opts) {
|
|
|
151
140
|
eventCount--;
|
|
152
141
|
isEnd = true;
|
|
153
142
|
clearTimeout(timer);
|
|
154
|
-
if (error)
|
|
155
|
-
|
|
156
|
-
else
|
|
157
|
-
resolve(data);
|
|
143
|
+
if (error) reject(data);
|
|
144
|
+
else resolve(data);
|
|
158
145
|
}
|
|
159
|
-
|
|
146
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, handler, "handler");
|
|
160
147
|
eventCount++;
|
|
161
148
|
});
|
|
162
149
|
};
|
|
@@ -165,7 +152,7 @@ async function createClient(nc, controllers, opts) {
|
|
|
165
152
|
}
|
|
166
153
|
return ret;
|
|
167
154
|
}
|
|
168
|
-
|
|
155
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, createClient, "createClient");
|
|
169
156
|
|
|
170
157
|
|
|
171
158
|
|
package/dist/rpc/nats/index.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
HMR,
|
|
4
4
|
createControllerMetaMap,
|
|
5
5
|
detectAopDep
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-BZKJ5NBU.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__name
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-MESZCLSS.mjs";
|
|
10
10
|
|
|
11
11
|
// src/rpc/nats/bind.ts
|
|
12
12
|
import { StringCodec } from "nats";
|
|
@@ -36,8 +36,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
36
36
|
const { data: { rpc } } = meta2;
|
|
37
37
|
if (rpc) {
|
|
38
38
|
const queue = rpc.queue || tag;
|
|
39
|
-
if (existQueue.has(queue))
|
|
40
|
-
continue;
|
|
39
|
+
if (existQueue.has(queue)) continue;
|
|
41
40
|
existQueue.add(queue);
|
|
42
41
|
subscriptionMap[queue] = nc.subscribe(queue, {
|
|
43
42
|
queue,
|
|
@@ -51,13 +50,11 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
51
50
|
async function handleRequest(_, msg) {
|
|
52
51
|
const data = JSON.parse(sc.decode(msg.data));
|
|
53
52
|
const { tag, func, id, _ps, args } = data;
|
|
54
|
-
if (_ps !== 1)
|
|
55
|
-
return;
|
|
53
|
+
if (_ps !== 1) return;
|
|
56
54
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
57
55
|
const meta2 = metaMap.get(tag)[func];
|
|
58
56
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
59
|
-
if (isEvent)
|
|
60
|
-
msg.respond("{}");
|
|
57
|
+
if (isEvent) msg.respond("{}");
|
|
61
58
|
const context = new Context({
|
|
62
59
|
type: "nats",
|
|
63
60
|
moduleMap,
|
|
@@ -77,25 +74,22 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
77
74
|
globalFilter,
|
|
78
75
|
globalPipe
|
|
79
76
|
}, (returnData) => {
|
|
80
|
-
if (!isEvent)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})));
|
|
77
|
+
if (!isEvent) msg.respond(sc.encode(JSON.stringify({
|
|
78
|
+
data: returnData,
|
|
79
|
+
id
|
|
80
|
+
})));
|
|
85
81
|
}, (err) => {
|
|
86
|
-
if (!isEvent)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})));
|
|
82
|
+
if (!isEvent) msg.respond(sc.encode(JSON.stringify({
|
|
83
|
+
data: err,
|
|
84
|
+
error: true,
|
|
85
|
+
id
|
|
86
|
+
})));
|
|
92
87
|
});
|
|
93
88
|
}
|
|
94
89
|
__name(handleRequest, "handleRequest");
|
|
95
90
|
subscribeQueues();
|
|
96
91
|
HMR(async () => {
|
|
97
|
-
for (const i in subscriptionMap)
|
|
98
|
-
subscriptionMap[i].unsubscribe();
|
|
92
|
+
for (const i in subscriptionMap) subscriptionMap[i].unsubscribe();
|
|
99
93
|
await subscribeQueues();
|
|
100
94
|
});
|
|
101
95
|
}
|
|
@@ -111,12 +105,10 @@ async function createClient(nc, controllers, opts) {
|
|
|
111
105
|
for (const i in controllers) {
|
|
112
106
|
ret[i] = new Proxy(new controllers[i](), {
|
|
113
107
|
get(target, p) {
|
|
114
|
-
if (typeof target[p] !== "function")
|
|
115
|
-
throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
108
|
+
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
116
109
|
let { tag, queue, isEvent } = target[p]();
|
|
117
110
|
return async (...args) => {
|
|
118
|
-
if (!queue)
|
|
119
|
-
queue = tag;
|
|
111
|
+
if (!queue) queue = tag;
|
|
120
112
|
const id = `${eventId++}`;
|
|
121
113
|
const request = nc.request(queue, sc.encode(JSON.stringify({
|
|
122
114
|
_ps: 1,
|
|
@@ -125,18 +117,15 @@ async function createClient(nc, controllers, opts) {
|
|
|
125
117
|
tag,
|
|
126
118
|
func: p
|
|
127
119
|
})));
|
|
128
|
-
if (isEvent)
|
|
129
|
-
return null;
|
|
120
|
+
if (isEvent) return null;
|
|
130
121
|
return new Promise((resolve, reject) => {
|
|
131
|
-
if (opts?.max && eventCount >= opts.max)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
122
|
+
if (opts?.max && eventCount >= opts.max) reject({
|
|
123
|
+
type: "exceeded"
|
|
124
|
+
});
|
|
135
125
|
request.catch(reject);
|
|
136
126
|
request.then((msg) => {
|
|
137
127
|
const { data, id: id2, error } = msg.json();
|
|
138
|
-
if (id2)
|
|
139
|
-
handler(data, error);
|
|
128
|
+
if (id2) handler(data, error);
|
|
140
129
|
});
|
|
141
130
|
let isEnd = false;
|
|
142
131
|
const timer = setTimeout(() => {
|
|
@@ -151,10 +140,8 @@ async function createClient(nc, controllers, opts) {
|
|
|
151
140
|
eventCount--;
|
|
152
141
|
isEnd = true;
|
|
153
142
|
clearTimeout(timer);
|
|
154
|
-
if (error)
|
|
155
|
-
|
|
156
|
-
else
|
|
157
|
-
resolve(data);
|
|
143
|
+
if (error) reject(data);
|
|
144
|
+
else resolve(data);
|
|
158
145
|
}
|
|
159
146
|
__name(handler, "handler");
|
|
160
147
|
eventCount++;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import amqplib from 'amqplib';
|
|
2
|
+
import { F as Factory } from '../../core-Bc2ENEHX.mjs';
|
|
3
|
+
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-vF4Hvnvo.mjs';
|
|
4
|
+
import { T as ToClientMap } from '../../types-BlIBlnVT.mjs';
|
|
5
|
+
import 'phecda-core';
|
|
6
|
+
|
|
7
|
+
interface RabbitmqCtx extends RpcContext {
|
|
8
|
+
type: 'rabbitmq';
|
|
9
|
+
ch: amqplib.Channel;
|
|
10
|
+
msg: amqplib.ConsumeMessage;
|
|
11
|
+
}
|
|
12
|
+
declare function bind(ch: amqplib.Channel, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
|
|
13
|
+
|
|
14
|
+
declare function createClient<S extends Record<string, any>>(ch: amqplib.Channel, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
|
|
15
|
+
|
|
16
|
+
export { type RabbitmqCtx, bind, createClient };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import amqplib from 'amqplib';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../types-
|
|
2
|
+
import { F as Factory } from '../../core-dx9E5x2N.js';
|
|
3
|
+
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-CJSkC9tO.js';
|
|
4
|
+
import { T as ToClientMap } from '../../types-BlIBlnVT.js';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface RabbitmqCtx extends RpcContext {
|
|
@@ -13,4 +13,4 @@ declare function bind(ch: amqplib.Channel, { moduleMap, meta }: Awaited<ReturnTy
|
|
|
13
13
|
|
|
14
14
|
declare function createClient<S extends Record<string, any>>(ch: amqplib.Channel, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
|
|
15
15
|
|
|
16
|
-
export { RabbitmqCtx, bind, createClient };
|
|
16
|
+
export { type RabbitmqCtx, bind, createClient };
|
|
@@ -4,24 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkQYX5Q7KOjs = require('../../chunk-QYX5Q7KO.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkRVWBJ6LVjs = require('../../chunk-RVWBJ6LV.js');
|
|
11
11
|
|
|
12
12
|
// src/rpc/rabbitmq/bind.ts
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
14
|
var debug = _debug2.default.call(void 0, "phecda-server/rabbitmq");
|
|
15
15
|
async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
16
16
|
const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
|
|
17
|
-
const metaMap =
|
|
17
|
+
const metaMap = _chunkQYX5Q7KOjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
18
18
|
const { controller, rpc, func, tag } = meta2.data;
|
|
19
19
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
20
20
|
debug(`register method "${func}" in module "${tag}"`);
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
|
|
24
|
+
_chunkQYX5Q7KOjs.detectAopDep.call(void 0, meta, {
|
|
25
25
|
guards: globalGuards,
|
|
26
26
|
interceptors: globalInterceptors
|
|
27
27
|
}, "rpc");
|
|
@@ -34,8 +34,7 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
34
34
|
const { data: { rpc } } = meta2;
|
|
35
35
|
if (rpc) {
|
|
36
36
|
const queue = rpc.queue || tag;
|
|
37
|
-
if (existQueue.has(queue))
|
|
38
|
-
continue;
|
|
37
|
+
if (existQueue.has(queue)) continue;
|
|
39
38
|
existQueue.add(queue);
|
|
40
39
|
await ch.assertQueue(queue);
|
|
41
40
|
ch.consume(queue, handleRequest, {
|
|
@@ -45,21 +44,20 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
49
48
|
async function handleRequest(msg) {
|
|
50
49
|
function send(queue, data) {
|
|
51
50
|
ch.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, send, "send");
|
|
54
53
|
if (msg) {
|
|
55
54
|
const data = JSON.parse(msg.content.toString());
|
|
56
55
|
const { tag, func, id, queue: clientQueue, _ps, args } = data;
|
|
57
|
-
if (_ps !== 1)
|
|
58
|
-
return;
|
|
56
|
+
if (_ps !== 1) return;
|
|
59
57
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
60
58
|
const meta2 = metaMap.get(tag)[func];
|
|
61
59
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
62
|
-
const context = new (0,
|
|
60
|
+
const context = new (0, _chunkQYX5Q7KOjs.Context)({
|
|
63
61
|
type: "rabbitmq",
|
|
64
62
|
moduleMap,
|
|
65
63
|
meta: meta2,
|
|
@@ -78,30 +76,27 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
78
76
|
globalFilter,
|
|
79
77
|
globalPipe
|
|
80
78
|
}, (returnData) => {
|
|
81
|
-
if (!isEvent)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
79
|
+
if (!isEvent) send(clientQueue, {
|
|
80
|
+
data: returnData,
|
|
81
|
+
id
|
|
82
|
+
});
|
|
86
83
|
}, (err) => {
|
|
87
|
-
if (!isEvent)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
84
|
+
if (!isEvent) send(clientQueue, {
|
|
85
|
+
data: err,
|
|
86
|
+
id,
|
|
87
|
+
error: true
|
|
88
|
+
});
|
|
93
89
|
});
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
|
-
|
|
92
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
97
93
|
subscribeQueues();
|
|
98
|
-
|
|
99
|
-
for (const queue of existQueue)
|
|
100
|
-
await ch.deleteQueue(queue);
|
|
94
|
+
_chunkQYX5Q7KOjs.HMR.call(void 0, async () => {
|
|
95
|
+
for (const queue of existQueue) await ch.deleteQueue(queue);
|
|
101
96
|
await subscribeQueues();
|
|
102
97
|
});
|
|
103
98
|
}
|
|
104
|
-
|
|
99
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, bind, "bind");
|
|
105
100
|
|
|
106
101
|
// src/rpc/rabbitmq/client.ts
|
|
107
102
|
var _events = require('events');
|
|
@@ -110,23 +105,20 @@ async function createClient(ch, controllers, opts) {
|
|
|
110
105
|
let eventCount = 0;
|
|
111
106
|
const ret = {};
|
|
112
107
|
const emitter = new (0, _events.EventEmitter)();
|
|
113
|
-
const clientQueue =
|
|
108
|
+
const clientQueue = _chunkQYX5Q7KOjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
|
|
114
109
|
await ch.assertQueue(clientQueue);
|
|
115
110
|
ch.consume(clientQueue, (msg) => {
|
|
116
|
-
if (!msg)
|
|
117
|
-
return;
|
|
111
|
+
if (!msg) return;
|
|
118
112
|
const { data, id, error } = JSON.parse(msg.content.toString());
|
|
119
113
|
emitter.emit(id, data, error);
|
|
120
114
|
});
|
|
121
115
|
for (const i in controllers) {
|
|
122
116
|
ret[i] = new Proxy(new controllers[i](), {
|
|
123
117
|
get(target, p) {
|
|
124
|
-
if (typeof target[p] !== "function")
|
|
125
|
-
throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
118
|
+
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
126
119
|
let { tag, queue, isEvent } = target[p]();
|
|
127
120
|
return async (...args) => {
|
|
128
|
-
if (!queue)
|
|
129
|
-
queue = tag;
|
|
121
|
+
if (!queue) queue = tag;
|
|
130
122
|
const id = `${eventId++}`;
|
|
131
123
|
ch.sendToQueue(queue, Buffer.from(JSON.stringify({
|
|
132
124
|
_ps: 1,
|
|
@@ -136,13 +128,11 @@ async function createClient(ch, controllers, opts) {
|
|
|
136
128
|
queue: clientQueue,
|
|
137
129
|
func: p
|
|
138
130
|
})));
|
|
139
|
-
if (isEvent)
|
|
140
|
-
return null;
|
|
131
|
+
if (isEvent) return null;
|
|
141
132
|
return new Promise((resolve, reject) => {
|
|
142
|
-
if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
});
|
|
133
|
+
if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
|
|
134
|
+
type: "exceeded"
|
|
135
|
+
});
|
|
146
136
|
let isEnd = false;
|
|
147
137
|
const timer = setTimeout(() => {
|
|
148
138
|
if (!isEnd) {
|
|
@@ -157,12 +147,10 @@ async function createClient(ch, controllers, opts) {
|
|
|
157
147
|
eventCount--;
|
|
158
148
|
isEnd = true;
|
|
159
149
|
clearTimeout(timer);
|
|
160
|
-
if (error)
|
|
161
|
-
|
|
162
|
-
else
|
|
163
|
-
resolve(data);
|
|
150
|
+
if (error) reject(data);
|
|
151
|
+
else resolve(data);
|
|
164
152
|
}
|
|
165
|
-
|
|
153
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, listener, "listener");
|
|
166
154
|
eventCount++;
|
|
167
155
|
emitter.once(id, listener);
|
|
168
156
|
});
|
|
@@ -172,7 +160,7 @@ async function createClient(ch, controllers, opts) {
|
|
|
172
160
|
}
|
|
173
161
|
return ret;
|
|
174
162
|
}
|
|
175
|
-
|
|
163
|
+
_chunkRVWBJ6LVjs.__name.call(void 0, createClient, "createClient");
|
|
176
164
|
|
|
177
165
|
|
|
178
166
|
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
createControllerMetaMap,
|
|
5
5
|
detectAopDep,
|
|
6
6
|
genClientQueue
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-BZKJ5NBU.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-MESZCLSS.mjs";
|
|
11
11
|
|
|
12
12
|
// src/rpc/rabbitmq/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
@@ -34,8 +34,7 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
34
34
|
const { data: { rpc } } = meta2;
|
|
35
35
|
if (rpc) {
|
|
36
36
|
const queue = rpc.queue || tag;
|
|
37
|
-
if (existQueue.has(queue))
|
|
38
|
-
continue;
|
|
37
|
+
if (existQueue.has(queue)) continue;
|
|
39
38
|
existQueue.add(queue);
|
|
40
39
|
await ch.assertQueue(queue);
|
|
41
40
|
ch.consume(queue, handleRequest, {
|
|
@@ -54,8 +53,7 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
54
53
|
if (msg) {
|
|
55
54
|
const data = JSON.parse(msg.content.toString());
|
|
56
55
|
const { tag, func, id, queue: clientQueue, _ps, args } = data;
|
|
57
|
-
if (_ps !== 1)
|
|
58
|
-
return;
|
|
56
|
+
if (_ps !== 1) return;
|
|
59
57
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
60
58
|
const meta2 = metaMap.get(tag)[func];
|
|
61
59
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
@@ -78,26 +76,23 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
78
76
|
globalFilter,
|
|
79
77
|
globalPipe
|
|
80
78
|
}, (returnData) => {
|
|
81
|
-
if (!isEvent)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
79
|
+
if (!isEvent) send(clientQueue, {
|
|
80
|
+
data: returnData,
|
|
81
|
+
id
|
|
82
|
+
});
|
|
86
83
|
}, (err) => {
|
|
87
|
-
if (!isEvent)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
84
|
+
if (!isEvent) send(clientQueue, {
|
|
85
|
+
data: err,
|
|
86
|
+
id,
|
|
87
|
+
error: true
|
|
88
|
+
});
|
|
93
89
|
});
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
92
|
__name(handleRequest, "handleRequest");
|
|
97
93
|
subscribeQueues();
|
|
98
94
|
HMR(async () => {
|
|
99
|
-
for (const queue of existQueue)
|
|
100
|
-
await ch.deleteQueue(queue);
|
|
95
|
+
for (const queue of existQueue) await ch.deleteQueue(queue);
|
|
101
96
|
await subscribeQueues();
|
|
102
97
|
});
|
|
103
98
|
}
|
|
@@ -113,20 +108,17 @@ async function createClient(ch, controllers, opts) {
|
|
|
113
108
|
const clientQueue = genClientQueue(opts?.key);
|
|
114
109
|
await ch.assertQueue(clientQueue);
|
|
115
110
|
ch.consume(clientQueue, (msg) => {
|
|
116
|
-
if (!msg)
|
|
117
|
-
return;
|
|
111
|
+
if (!msg) return;
|
|
118
112
|
const { data, id, error } = JSON.parse(msg.content.toString());
|
|
119
113
|
emitter.emit(id, data, error);
|
|
120
114
|
});
|
|
121
115
|
for (const i in controllers) {
|
|
122
116
|
ret[i] = new Proxy(new controllers[i](), {
|
|
123
117
|
get(target, p) {
|
|
124
|
-
if (typeof target[p] !== "function")
|
|
125
|
-
throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
118
|
+
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
126
119
|
let { tag, queue, isEvent } = target[p]();
|
|
127
120
|
return async (...args) => {
|
|
128
|
-
if (!queue)
|
|
129
|
-
queue = tag;
|
|
121
|
+
if (!queue) queue = tag;
|
|
130
122
|
const id = `${eventId++}`;
|
|
131
123
|
ch.sendToQueue(queue, Buffer.from(JSON.stringify({
|
|
132
124
|
_ps: 1,
|
|
@@ -136,13 +128,11 @@ async function createClient(ch, controllers, opts) {
|
|
|
136
128
|
queue: clientQueue,
|
|
137
129
|
func: p
|
|
138
130
|
})));
|
|
139
|
-
if (isEvent)
|
|
140
|
-
return null;
|
|
131
|
+
if (isEvent) return null;
|
|
141
132
|
return new Promise((resolve, reject) => {
|
|
142
|
-
if (opts?.max && eventCount >= opts.max)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
});
|
|
133
|
+
if (opts?.max && eventCount >= opts.max) reject({
|
|
134
|
+
type: "exceeded"
|
|
135
|
+
});
|
|
146
136
|
let isEnd = false;
|
|
147
137
|
const timer = setTimeout(() => {
|
|
148
138
|
if (!isEnd) {
|
|
@@ -157,10 +147,8 @@ async function createClient(ch, controllers, opts) {
|
|
|
157
147
|
eventCount--;
|
|
158
148
|
isEnd = true;
|
|
159
149
|
clearTimeout(timer);
|
|
160
|
-
if (error)
|
|
161
|
-
|
|
162
|
-
else
|
|
163
|
-
resolve(data);
|
|
150
|
+
if (error) reject(data);
|
|
151
|
+
else resolve(data);
|
|
164
152
|
}
|
|
165
153
|
__name(listener, "listener");
|
|
166
154
|
eventCount++;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Redis from 'ioredis';
|
|
2
|
+
import { F as Factory } from '../../core-Bc2ENEHX.mjs';
|
|
3
|
+
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-vF4Hvnvo.mjs';
|
|
4
|
+
import { T as ToClientMap } from '../../types-BlIBlnVT.mjs';
|
|
5
|
+
import 'phecda-core';
|
|
6
|
+
|
|
7
|
+
interface RedisCtx extends RpcContext {
|
|
8
|
+
type: 'redis';
|
|
9
|
+
redis: Redis;
|
|
10
|
+
msg: string;
|
|
11
|
+
channel: string;
|
|
12
|
+
}
|
|
13
|
+
declare function bind({ sub, pub }: {
|
|
14
|
+
sub: Redis;
|
|
15
|
+
pub: Redis;
|
|
16
|
+
}, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
|
|
17
|
+
|
|
18
|
+
declare function createClient<S extends Record<string, any>>({ pub, sub }: {
|
|
19
|
+
pub: Redis;
|
|
20
|
+
sub: Redis;
|
|
21
|
+
}, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
|
|
22
|
+
|
|
23
|
+
export { type RedisCtx, bind, createClient };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../types-
|
|
2
|
+
import { F as Factory } from '../../core-dx9E5x2N.js';
|
|
3
|
+
import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-CJSkC9tO.js';
|
|
4
|
+
import { T as ToClientMap } from '../../types-BlIBlnVT.js';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface RedisCtx extends RpcContext {
|
|
@@ -20,4 +20,4 @@ declare function createClient<S extends Record<string, any>>({ pub, sub }: {
|
|
|
20
20
|
sub: Redis;
|
|
21
21
|
}, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
|
|
22
22
|
|
|
23
|
-
export { RedisCtx, bind, createClient };
|
|
23
|
+
export { type RedisCtx, bind, createClient };
|