phecda-server 6.0.2 → 7.0.0-alpha.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/bin/cli.mjs +160 -157
- package/dist/{chunk-HDQAT2IM.mjs → chunk-5622RBNB.mjs} +118 -90
- package/dist/chunk-BGXSMOLX.js +265 -0
- package/dist/{chunk-F3W3NN7F.mjs → chunk-HMVLXNV3.mjs} +5 -14
- package/dist/{chunk-GHFSIZUO.js → chunk-J5CFUN4V.js} +18 -3
- package/dist/{chunk-XCND2QW3.js → chunk-MBCHNDAY.js} +27 -36
- package/dist/{chunk-WXFZZZRY.mjs → chunk-P75VKZJY.mjs} +101 -137
- package/dist/chunk-SW5IKE5H.js +503 -0
- package/dist/{chunk-UXD62LGG.mjs → chunk-WHJ5FALK.mjs} +17 -2
- package/dist/core-BIcUwV18.d.mts +47 -0
- package/dist/core-CYwEPfN4.d.ts +47 -0
- package/dist/helper.d.mts +4 -6
- package/dist/helper.d.ts +4 -6
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/{server → http}/elysia/index.d.mts +5 -5
- package/dist/{server → http}/elysia/index.d.ts +5 -5
- package/dist/{server → http}/elysia/index.js +80 -62
- package/dist/{server → http}/elysia/index.mjs +50 -32
- package/dist/{server → http}/express/index.d.mts +5 -5
- package/dist/{server → http}/express/index.d.ts +5 -5
- package/dist/{server → http}/express/index.js +71 -55
- package/dist/{server → http}/express/index.mjs +42 -26
- package/dist/{server → http}/fastify/index.d.mts +5 -5
- package/dist/{server → http}/fastify/index.d.ts +5 -5
- package/dist/{server → http}/fastify/index.js +72 -72
- package/dist/{server → http}/fastify/index.mjs +47 -47
- package/dist/{server → http}/h3/index.d.mts +5 -5
- package/dist/{server → http}/h3/index.d.ts +5 -5
- package/dist/http/h3/index.js +160 -0
- package/dist/{server → http}/h3/index.mjs +68 -62
- package/dist/{server → http}/hono/index.d.mts +5 -5
- package/dist/{server → http}/hono/index.d.ts +5 -5
- package/dist/{server → http}/hono/index.js +69 -54
- package/dist/{server → http}/hono/index.mjs +41 -26
- package/dist/{server → http}/hyper-express/index.d.mts +5 -5
- package/dist/{server → http}/hyper-express/index.d.ts +5 -5
- package/dist/{server → http}/hyper-express/index.js +69 -56
- package/dist/{server → http}/hyper-express/index.mjs +41 -28
- package/dist/{server → http}/koa/index.d.mts +5 -5
- package/dist/{server → http}/koa/index.d.ts +5 -5
- package/dist/{server → http}/koa/index.js +71 -55
- package/dist/{server → http}/koa/index.mjs +42 -26
- package/dist/index.d.mts +53 -41
- package/dist/index.d.ts +53 -41
- package/dist/index.js +62 -78
- package/dist/index.mjs +46 -62
- package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
- package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
- package/dist/rpc/bullmq/index.d.mts +6 -6
- package/dist/rpc/bullmq/index.d.ts +6 -6
- package/dist/rpc/bullmq/index.js +24 -24
- package/dist/rpc/bullmq/index.mjs +14 -14
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +25 -21
- package/dist/rpc/kafka/index.mjs +15 -11
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +22 -21
- package/dist/rpc/nats/index.mjs +13 -12
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +23 -22
- package/dist/rpc/rabbitmq/index.mjs +12 -11
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +24 -20
- package/dist/rpc/redis/index.mjs +15 -11
- 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-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
- package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
- package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
- package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
- package/package.json +24 -24
- package/dist/chunk-7SYPUIBY.js +0 -539
- package/dist/chunk-LYEZ6RGX.js +0 -237
- package/dist/core-2SNw8m2B.d.mts +0 -30
- package/dist/core-BmJJLUqj.d.ts +0 -30
- package/dist/server/h3/index.js +0 -154
package/dist/rpc/bullmq/index.js
CHANGED
|
@@ -4,47 +4,47 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
11
11
|
|
|
12
|
-
// src/rpc/bullmq/
|
|
12
|
+
// src/rpc/bullmq/create.ts
|
|
13
13
|
var _bullmq = require('bullmq');
|
|
14
14
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
15
15
|
var debug = _debug2.default.call(void 0, "phecda-server/bullmq");
|
|
16
16
|
async function create({ moduleMap, meta }, opts = {}) {
|
|
17
|
-
const { globalGuards,
|
|
17
|
+
const { globalGuards, globalFilter, globalPipe, workerOpts, queueOpts, defaultQueue } = opts;
|
|
18
18
|
const workerMap = {};
|
|
19
19
|
const queueMap = {};
|
|
20
20
|
const existQueue = /* @__PURE__ */ new Set();
|
|
21
|
-
const metaMap =
|
|
21
|
+
const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
22
22
|
const { controller, rpc, func, tag } = meta2.data;
|
|
23
23
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
24
24
|
debug(`register method "${func}" in module "${tag}"`);
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
|
|
29
|
-
guards: globalGuards
|
|
30
|
-
interceptors: globalInterceptors
|
|
28
|
+
_chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
|
|
29
|
+
guards: globalGuards
|
|
31
30
|
}, "rpc");
|
|
32
31
|
async function subscribeQueues() {
|
|
33
32
|
existQueue.clear();
|
|
34
33
|
for (const [tag, record] of metaMap) {
|
|
35
34
|
for (const func in record) {
|
|
36
35
|
const meta2 = metaMap.get(tag)[func];
|
|
37
|
-
const { data: { rpc } } = meta2;
|
|
36
|
+
const { data: { rpc, addons } } = meta2;
|
|
38
37
|
if (rpc) {
|
|
39
|
-
const queue = rpc.queue || tag;
|
|
38
|
+
const queue = rpc.queue || defaultQueue || tag;
|
|
40
39
|
if (existQueue.has(queue)) continue;
|
|
41
40
|
existQueue.add(queue);
|
|
42
41
|
workerMap[queue] = new (0, _bullmq.Worker)(queue, handleRequest, workerOpts);
|
|
42
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(addons, workerMap[queue], "bullmq");
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
48
48
|
async function handleRequest(job) {
|
|
49
49
|
const { data } = job;
|
|
50
50
|
const { tag, func, args, id, queue: clientQueue, _ps } = data;
|
|
@@ -53,7 +53,12 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
53
53
|
const meta2 = metaMap.get(tag)[func];
|
|
54
54
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
55
55
|
if (!isEvent && !(clientQueue in queueMap)) queueMap[clientQueue] = new (0, _bullmq.Queue)(clientQueue, queueOpts);
|
|
56
|
-
const
|
|
56
|
+
const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
57
|
+
globalFilter,
|
|
58
|
+
globalGuards,
|
|
59
|
+
globalPipe
|
|
60
|
+
});
|
|
61
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)({
|
|
57
62
|
type: "bullmq",
|
|
58
63
|
moduleMap,
|
|
59
64
|
meta: meta2,
|
|
@@ -65,12 +70,7 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
65
70
|
queue: job.queueName,
|
|
66
71
|
isEvent
|
|
67
72
|
});
|
|
68
|
-
await context.run({
|
|
69
|
-
globalGuards,
|
|
70
|
-
globalInterceptors,
|
|
71
|
-
globalFilter,
|
|
72
|
-
globalPipe
|
|
73
|
-
}, (returnData) => {
|
|
73
|
+
await context.run(aop, (returnData) => {
|
|
74
74
|
if (!isEvent) queueMap[clientQueue].add(`${tag}-${func}`, {
|
|
75
75
|
data: returnData,
|
|
76
76
|
id
|
|
@@ -85,9 +85,9 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
89
89
|
subscribeQueues();
|
|
90
|
-
|
|
90
|
+
_chunkSW5IKE5Hjs.HMR.call(void 0, async () => {
|
|
91
91
|
for (const i in workerMap) await workerMap[i].close(true);
|
|
92
92
|
for (const i in queueMap) await queueMap[i].close();
|
|
93
93
|
await subscribeQueues();
|
|
@@ -97,7 +97,7 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
97
97
|
queueMap
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, create, "create");
|
|
101
101
|
|
|
102
102
|
// src/rpc/bullmq/client.ts
|
|
103
103
|
var _events = require('events');
|
|
@@ -108,7 +108,7 @@ async function createClient(controllers, opts = {}) {
|
|
|
108
108
|
const { max, workerOpts, queueOpts, timeout, key } = opts;
|
|
109
109
|
const ret = {};
|
|
110
110
|
const emitter = new (0, _events.EventEmitter)();
|
|
111
|
-
const clientQueue =
|
|
111
|
+
const clientQueue = _chunkSW5IKE5Hjs.genClientQueue.call(void 0, key);
|
|
112
112
|
const queueMap = {};
|
|
113
113
|
new (0, _bullmq.Worker)(clientQueue, async (job) => {
|
|
114
114
|
const { data, id, error } = job.data;
|
|
@@ -153,7 +153,7 @@ async function createClient(controllers, opts = {}) {
|
|
|
153
153
|
if (error) reject(data);
|
|
154
154
|
else resolve(data);
|
|
155
155
|
}
|
|
156
|
-
|
|
156
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, listener, "listener");
|
|
157
157
|
eventCount++;
|
|
158
158
|
emitter.once(id, listener);
|
|
159
159
|
});
|
|
@@ -163,7 +163,7 @@ async function createClient(controllers, opts = {}) {
|
|
|
163
163
|
}
|
|
164
164
|
return ret;
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, createClient, "createClient");
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
|
|
@@ -4,17 +4,17 @@ import {
|
|
|
4
4
|
createControllerMetaMap,
|
|
5
5
|
detectAopDep,
|
|
6
6
|
genClientQueue
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-P75VKZJY.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
11
11
|
|
|
12
|
-
// src/rpc/bullmq/
|
|
12
|
+
// src/rpc/bullmq/create.ts
|
|
13
13
|
import { Queue, Worker } from "bullmq";
|
|
14
14
|
import Debug from "debug";
|
|
15
15
|
var debug = Debug("phecda-server/bullmq");
|
|
16
16
|
async function create({ moduleMap, meta }, opts = {}) {
|
|
17
|
-
const { globalGuards,
|
|
17
|
+
const { globalGuards, globalFilter, globalPipe, workerOpts, queueOpts, defaultQueue } = opts;
|
|
18
18
|
const workerMap = {};
|
|
19
19
|
const queueMap = {};
|
|
20
20
|
const existQueue = /* @__PURE__ */ new Set();
|
|
@@ -26,20 +26,20 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
detectAopDep(meta, {
|
|
29
|
-
guards: globalGuards
|
|
30
|
-
interceptors: globalInterceptors
|
|
29
|
+
guards: globalGuards
|
|
31
30
|
}, "rpc");
|
|
32
31
|
async function subscribeQueues() {
|
|
33
32
|
existQueue.clear();
|
|
34
33
|
for (const [tag, record] of metaMap) {
|
|
35
34
|
for (const func in record) {
|
|
36
35
|
const meta2 = metaMap.get(tag)[func];
|
|
37
|
-
const { data: { rpc } } = meta2;
|
|
36
|
+
const { data: { rpc, addons } } = meta2;
|
|
38
37
|
if (rpc) {
|
|
39
|
-
const queue = rpc.queue || tag;
|
|
38
|
+
const queue = rpc.queue || defaultQueue || tag;
|
|
40
39
|
if (existQueue.has(queue)) continue;
|
|
41
40
|
existQueue.add(queue);
|
|
42
41
|
workerMap[queue] = new Worker(queue, handleRequest, workerOpts);
|
|
42
|
+
Context.applyAddons(addons, workerMap[queue], "bullmq");
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -53,6 +53,11 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
53
53
|
const meta2 = metaMap.get(tag)[func];
|
|
54
54
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
55
55
|
if (!isEvent && !(clientQueue in queueMap)) queueMap[clientQueue] = new Queue(clientQueue, queueOpts);
|
|
56
|
+
const aop = Context.getAop(meta2, {
|
|
57
|
+
globalFilter,
|
|
58
|
+
globalGuards,
|
|
59
|
+
globalPipe
|
|
60
|
+
});
|
|
56
61
|
const context = new Context({
|
|
57
62
|
type: "bullmq",
|
|
58
63
|
moduleMap,
|
|
@@ -65,12 +70,7 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
65
70
|
queue: job.queueName,
|
|
66
71
|
isEvent
|
|
67
72
|
});
|
|
68
|
-
await context.run({
|
|
69
|
-
globalGuards,
|
|
70
|
-
globalInterceptors,
|
|
71
|
-
globalFilter,
|
|
72
|
-
globalPipe
|
|
73
|
-
}, (returnData) => {
|
|
73
|
+
await context.run(aop, (returnData) => {
|
|
74
74
|
if (!isEvent) queueMap[clientQueue].add(`${tag}-${func}`, {
|
|
75
75
|
data: returnData,
|
|
76
76
|
id
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Consumer, Producer } from 'kafkajs';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../meta-
|
|
2
|
+
import { F as Factory } from '../../core-BIcUwV18.mjs';
|
|
3
|
+
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-BtbL49Zs.mjs';
|
|
4
|
+
import { T as ToClientMap } from '../../meta-BXKLFTgG.mjs';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface KafkaCtx extends RpcContext {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Consumer, Producer } from 'kafkajs';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../meta-
|
|
2
|
+
import { F as Factory } from '../../core-CYwEPfN4.js';
|
|
3
|
+
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-m3IEDKjP.js';
|
|
4
|
+
import { T as ToClientMap } from '../../meta-BXKLFTgG.js';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface KafkaCtx extends RpcContext {
|
package/dist/rpc/kafka/index.js
CHANGED
|
@@ -3,28 +3,32 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
10
10
|
|
|
11
11
|
// src/rpc/kafka/bind.ts
|
|
12
12
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
13
13
|
var debug = _debug2.default.call(void 0, "phecda-server/kafka");
|
|
14
14
|
async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
15
|
-
const { globalGuards,
|
|
15
|
+
const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
|
|
16
16
|
const existQueue = /* @__PURE__ */ new Set();
|
|
17
|
-
const metaMap =
|
|
17
|
+
const metaMap = _chunkSW5IKE5Hjs.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
|
+
_chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
|
|
25
25
|
guards: globalGuards,
|
|
26
|
-
|
|
26
|
+
addons: globalAddons
|
|
27
27
|
}, "rpc");
|
|
28
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, {
|
|
29
|
+
consumer,
|
|
30
|
+
producer
|
|
31
|
+
}, "kafka");
|
|
28
32
|
async function subscribeQueues() {
|
|
29
33
|
existQueue.clear();
|
|
30
34
|
for (const [tag, record] of metaMap) {
|
|
@@ -32,7 +36,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
32
36
|
const meta2 = metaMap.get(tag)[func];
|
|
33
37
|
const { data: { rpc } } = meta2;
|
|
34
38
|
if (rpc) {
|
|
35
|
-
const queue = rpc.queue || tag;
|
|
39
|
+
const queue = rpc.queue || defaultQueue || tag;
|
|
36
40
|
if (existQueue.has(queue)) continue;
|
|
37
41
|
existQueue.add(queue);
|
|
38
42
|
await consumer.subscribe({
|
|
@@ -43,10 +47,10 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
|
|
50
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
47
51
|
await subscribeQueues();
|
|
48
52
|
await consumer.run({
|
|
49
|
-
eachMessage: /* @__PURE__ */
|
|
53
|
+
eachMessage: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, async ({ message, partition, topic, heartbeat, pause }) => {
|
|
50
54
|
if (!existQueue.has(topic)) return;
|
|
51
55
|
const data = JSON.parse(message.value.toString());
|
|
52
56
|
const { tag, func, id, queue: clientQueue, _ps, args } = data;
|
|
@@ -55,7 +59,12 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
55
59
|
const meta2 = metaMap.get(tag)[func];
|
|
56
60
|
const { data: { rpc } } = meta2;
|
|
57
61
|
const isEvent = rpc.isEvent;
|
|
58
|
-
const
|
|
62
|
+
const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
63
|
+
globalFilter,
|
|
64
|
+
globalGuards,
|
|
65
|
+
globalPipe
|
|
66
|
+
});
|
|
67
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)({
|
|
59
68
|
type: "kafka",
|
|
60
69
|
moduleMap,
|
|
61
70
|
meta: meta2,
|
|
@@ -70,12 +79,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
70
79
|
isEvent,
|
|
71
80
|
queue: topic
|
|
72
81
|
});
|
|
73
|
-
await context.run({
|
|
74
|
-
globalGuards,
|
|
75
|
-
globalInterceptors,
|
|
76
|
-
globalFilter,
|
|
77
|
-
globalPipe
|
|
78
|
-
}, (returnData) => {
|
|
82
|
+
await context.run(aop, (returnData) => {
|
|
79
83
|
if (!isEvent) {
|
|
80
84
|
producer.send({
|
|
81
85
|
topic: clientQueue,
|
|
@@ -108,7 +112,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
108
112
|
}, "eachMessage")
|
|
109
113
|
});
|
|
110
114
|
}
|
|
111
|
-
|
|
115
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
|
|
112
116
|
|
|
113
117
|
// src/rpc/kafka/client.ts
|
|
114
118
|
var _events = require('events');
|
|
@@ -117,7 +121,7 @@ async function createClient({ producer, consumer }, controllers, opts) {
|
|
|
117
121
|
let eventCount = 1;
|
|
118
122
|
const ret = {};
|
|
119
123
|
const emitter = new (0, _events.EventEmitter)();
|
|
120
|
-
const clientQueue =
|
|
124
|
+
const clientQueue = _chunkSW5IKE5Hjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
|
|
121
125
|
await consumer.subscribe({
|
|
122
126
|
topic: clientQueue,
|
|
123
127
|
fromBeginning: true
|
|
@@ -167,7 +171,7 @@ async function createClient({ producer, consumer }, controllers, opts) {
|
|
|
167
171
|
if (error) reject(data);
|
|
168
172
|
else resolve(data);
|
|
169
173
|
}
|
|
170
|
-
|
|
174
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, listener, "listener");
|
|
171
175
|
eventCount++;
|
|
172
176
|
emitter.once(id, listener);
|
|
173
177
|
});
|
|
@@ -176,7 +180,7 @@ async function createClient({ producer, consumer }, controllers, opts) {
|
|
|
176
180
|
});
|
|
177
181
|
}
|
|
178
182
|
await consumer.run({
|
|
179
|
-
eachMessage: /* @__PURE__ */
|
|
183
|
+
eachMessage: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, async ({ message, topic }) => {
|
|
180
184
|
if (clientQueue === topic && message.value) {
|
|
181
185
|
const { data, id, error } = JSON.parse(message.value.toString());
|
|
182
186
|
emitter.emit(id, data, error);
|
|
@@ -185,7 +189,7 @@ async function createClient({ producer, consumer }, controllers, opts) {
|
|
|
185
189
|
});
|
|
186
190
|
return ret;
|
|
187
191
|
}
|
|
188
|
-
|
|
192
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, createClient, "createClient");
|
|
189
193
|
|
|
190
194
|
|
|
191
195
|
|
package/dist/rpc/kafka/index.mjs
CHANGED
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
createControllerMetaMap,
|
|
4
4
|
detectAopDep,
|
|
5
5
|
genClientQueue
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-P75VKZJY.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__name
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
10
10
|
|
|
11
11
|
// src/rpc/kafka/bind.ts
|
|
12
12
|
import Debug from "debug";
|
|
13
13
|
var debug = Debug("phecda-server/kafka");
|
|
14
14
|
async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
15
|
-
const { globalGuards,
|
|
15
|
+
const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
|
|
16
16
|
const existQueue = /* @__PURE__ */ new Set();
|
|
17
17
|
const metaMap = createControllerMetaMap(meta, (meta2) => {
|
|
18
18
|
const { controller, rpc, func, tag } = meta2.data;
|
|
@@ -23,8 +23,12 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
23
23
|
});
|
|
24
24
|
detectAopDep(meta, {
|
|
25
25
|
guards: globalGuards,
|
|
26
|
-
|
|
26
|
+
addons: globalAddons
|
|
27
27
|
}, "rpc");
|
|
28
|
+
Context.applyAddons(globalAddons, {
|
|
29
|
+
consumer,
|
|
30
|
+
producer
|
|
31
|
+
}, "kafka");
|
|
28
32
|
async function subscribeQueues() {
|
|
29
33
|
existQueue.clear();
|
|
30
34
|
for (const [tag, record] of metaMap) {
|
|
@@ -32,7 +36,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
32
36
|
const meta2 = metaMap.get(tag)[func];
|
|
33
37
|
const { data: { rpc } } = meta2;
|
|
34
38
|
if (rpc) {
|
|
35
|
-
const queue = rpc.queue || tag;
|
|
39
|
+
const queue = rpc.queue || defaultQueue || tag;
|
|
36
40
|
if (existQueue.has(queue)) continue;
|
|
37
41
|
existQueue.add(queue);
|
|
38
42
|
await consumer.subscribe({
|
|
@@ -55,6 +59,11 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
55
59
|
const meta2 = metaMap.get(tag)[func];
|
|
56
60
|
const { data: { rpc } } = meta2;
|
|
57
61
|
const isEvent = rpc.isEvent;
|
|
62
|
+
const aop = Context.getAop(meta2, {
|
|
63
|
+
globalFilter,
|
|
64
|
+
globalGuards,
|
|
65
|
+
globalPipe
|
|
66
|
+
});
|
|
58
67
|
const context = new Context({
|
|
59
68
|
type: "kafka",
|
|
60
69
|
moduleMap,
|
|
@@ -70,12 +79,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
|
|
|
70
79
|
isEvent,
|
|
71
80
|
queue: topic
|
|
72
81
|
});
|
|
73
|
-
await context.run({
|
|
74
|
-
globalGuards,
|
|
75
|
-
globalInterceptors,
|
|
76
|
-
globalFilter,
|
|
77
|
-
globalPipe
|
|
78
|
-
}, (returnData) => {
|
|
82
|
+
await context.run(aop, (returnData) => {
|
|
79
83
|
if (!isEvent) {
|
|
80
84
|
producer.send({
|
|
81
85
|
topic: clientQueue,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NatsConnection } from 'nats';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../meta-
|
|
2
|
+
import { F as Factory } from '../../core-BIcUwV18.mjs';
|
|
3
|
+
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-BtbL49Zs.mjs';
|
|
4
|
+
import { T as ToClientMap } from '../../meta-BXKLFTgG.mjs';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface NatsCtx extends RpcContext {
|
package/dist/rpc/nats/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NatsConnection } from 'nats';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../meta-
|
|
2
|
+
import { F as Factory } from '../../core-CYwEPfN4.js';
|
|
3
|
+
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-m3IEDKjP.js';
|
|
4
|
+
import { T as ToClientMap } from '../../meta-BXKLFTgG.js';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface NatsCtx extends RpcContext {
|
package/dist/rpc/nats/index.js
CHANGED
|
@@ -3,31 +3,32 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
|
|
10
10
|
|
|
11
11
|
// src/rpc/nats/bind.ts
|
|
12
12
|
var _nats = require('nats');
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
14
|
var debug = _debug2.default.call(void 0, "phecda-server/nats");
|
|
15
15
|
async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
16
|
-
const { globalGuards,
|
|
16
|
+
const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = 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 = _chunkSW5IKE5Hjs.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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
_chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
|
|
28
|
+
addons: globalAddons,
|
|
29
|
+
guards: globalGuards
|
|
30
30
|
}, "rpc");
|
|
31
|
+
_chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, nc, "nats");
|
|
31
32
|
async function subscribeQueues() {
|
|
32
33
|
existQueue.clear();
|
|
33
34
|
for (const [tag, record] of metaMap) {
|
|
@@ -35,7 +36,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
35
36
|
const meta2 = metaMap.get(tag)[func];
|
|
36
37
|
const { data: { rpc } } = meta2;
|
|
37
38
|
if (rpc) {
|
|
38
|
-
const queue = rpc.queue || tag;
|
|
39
|
+
const queue = rpc.queue || defaultQueue || tag;
|
|
39
40
|
if (existQueue.has(queue)) continue;
|
|
40
41
|
existQueue.add(queue);
|
|
41
42
|
subscriptionMap[queue] = nc.subscribe(queue, {
|
|
@@ -46,7 +47,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
50
51
|
async function handleRequest(_, msg) {
|
|
51
52
|
const data = JSON.parse(sc.decode(msg.data));
|
|
52
53
|
const { tag, func, id, _ps, args } = data;
|
|
@@ -55,7 +56,12 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
55
56
|
const meta2 = metaMap.get(tag)[func];
|
|
56
57
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
57
58
|
if (isEvent) msg.respond("{}");
|
|
58
|
-
const
|
|
59
|
+
const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
|
|
60
|
+
globalFilter,
|
|
61
|
+
globalGuards,
|
|
62
|
+
globalPipe
|
|
63
|
+
});
|
|
64
|
+
const context = new (0, _chunkSW5IKE5Hjs.Context)({
|
|
59
65
|
type: "nats",
|
|
60
66
|
moduleMap,
|
|
61
67
|
meta: meta2,
|
|
@@ -68,12 +74,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
68
74
|
// @ts-expect-error nats ts problem
|
|
69
75
|
queue: msg._msg.subject.toString()
|
|
70
76
|
});
|
|
71
|
-
await context.run({
|
|
72
|
-
globalGuards,
|
|
73
|
-
globalInterceptors,
|
|
74
|
-
globalFilter,
|
|
75
|
-
globalPipe
|
|
76
|
-
}, (returnData) => {
|
|
77
|
+
await context.run(aop, (returnData) => {
|
|
77
78
|
if (!isEvent) msg.respond(sc.encode(JSON.stringify({
|
|
78
79
|
data: returnData,
|
|
79
80
|
id
|
|
@@ -86,14 +87,14 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
86
87
|
})));
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
90
91
|
subscribeQueues();
|
|
91
|
-
|
|
92
|
+
_chunkSW5IKE5Hjs.HMR.call(void 0, async () => {
|
|
92
93
|
for (const i in subscriptionMap) subscriptionMap[i].unsubscribe();
|
|
93
94
|
await subscribeQueues();
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
|
|
97
98
|
|
|
98
99
|
// src/rpc/nats/client.ts
|
|
99
100
|
|
|
@@ -143,7 +144,7 @@ async function createClient(nc, controllers, opts) {
|
|
|
143
144
|
if (error) reject(data);
|
|
144
145
|
else resolve(data);
|
|
145
146
|
}
|
|
146
|
-
|
|
147
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, handler, "handler");
|
|
147
148
|
eventCount++;
|
|
148
149
|
});
|
|
149
150
|
};
|
|
@@ -152,7 +153,7 @@ async function createClient(nc, controllers, opts) {
|
|
|
152
153
|
}
|
|
153
154
|
return ret;
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, createClient, "createClient");
|
|
156
157
|
|
|
157
158
|
|
|
158
159
|
|
package/dist/rpc/nats/index.mjs
CHANGED
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
HMR,
|
|
4
4
|
createControllerMetaMap,
|
|
5
5
|
detectAopDep
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-P75VKZJY.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__name
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-WHJ5FALK.mjs";
|
|
10
10
|
|
|
11
11
|
// src/rpc/nats/bind.ts
|
|
12
12
|
import { StringCodec } from "nats";
|
|
13
13
|
import Debug from "debug";
|
|
14
14
|
var debug = Debug("phecda-server/nats");
|
|
15
15
|
async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
16
|
-
const { globalGuards,
|
|
16
|
+
const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
|
|
17
17
|
const sc = StringCodec();
|
|
18
18
|
const subscriptionMap = {};
|
|
19
19
|
const existQueue = /* @__PURE__ */ new Set();
|
|
@@ -25,9 +25,10 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
detectAopDep(meta, {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
addons: globalAddons,
|
|
29
|
+
guards: globalGuards
|
|
30
30
|
}, "rpc");
|
|
31
|
+
Context.applyAddons(globalAddons, nc, "nats");
|
|
31
32
|
async function subscribeQueues() {
|
|
32
33
|
existQueue.clear();
|
|
33
34
|
for (const [tag, record] of metaMap) {
|
|
@@ -35,7 +36,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
35
36
|
const meta2 = metaMap.get(tag)[func];
|
|
36
37
|
const { data: { rpc } } = meta2;
|
|
37
38
|
if (rpc) {
|
|
38
|
-
const queue = rpc.queue || tag;
|
|
39
|
+
const queue = rpc.queue || defaultQueue || tag;
|
|
39
40
|
if (existQueue.has(queue)) continue;
|
|
40
41
|
existQueue.add(queue);
|
|
41
42
|
subscriptionMap[queue] = nc.subscribe(queue, {
|
|
@@ -55,6 +56,11 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
55
56
|
const meta2 = metaMap.get(tag)[func];
|
|
56
57
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
57
58
|
if (isEvent) msg.respond("{}");
|
|
59
|
+
const aop = Context.getAop(meta2, {
|
|
60
|
+
globalFilter,
|
|
61
|
+
globalGuards,
|
|
62
|
+
globalPipe
|
|
63
|
+
});
|
|
58
64
|
const context = new Context({
|
|
59
65
|
type: "nats",
|
|
60
66
|
moduleMap,
|
|
@@ -68,12 +74,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
|
|
|
68
74
|
// @ts-expect-error nats ts problem
|
|
69
75
|
queue: msg._msg.subject.toString()
|
|
70
76
|
});
|
|
71
|
-
await context.run({
|
|
72
|
-
globalGuards,
|
|
73
|
-
globalInterceptors,
|
|
74
|
-
globalFilter,
|
|
75
|
-
globalPipe
|
|
76
|
-
}, (returnData) => {
|
|
77
|
+
await context.run(aop, (returnData) => {
|
|
77
78
|
if (!isEvent) msg.respond(sc.encode(JSON.stringify({
|
|
78
79
|
data: returnData,
|
|
79
80
|
id
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import amqplib from 'amqplib';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../meta-
|
|
2
|
+
import { F as Factory } from '../../core-BIcUwV18.mjs';
|
|
3
|
+
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-BtbL49Zs.mjs';
|
|
4
|
+
import { T as ToClientMap } from '../../meta-BXKLFTgG.mjs';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface RabbitmqCtx extends RpcContext {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import amqplib from 'amqplib';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-
|
|
4
|
-
import { T as ToClientMap } from '../../meta-
|
|
2
|
+
import { F as Factory } from '../../core-CYwEPfN4.js';
|
|
3
|
+
import { R as RpcContext, a as RpcServerOptions, b as RpcClientOptions } from '../../types-m3IEDKjP.js';
|
|
4
|
+
import { T as ToClientMap } from '../../meta-BXKLFTgG.js';
|
|
5
5
|
import 'phecda-core';
|
|
6
6
|
|
|
7
7
|
interface RabbitmqCtx extends RpcContext {
|