phecda-server 5.2.4 → 5.2.5

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.
Files changed (77) hide show
  1. package/dist/{chunk-VYDBNZJ2.mjs → chunk-2NTXVYQC.mjs} +1 -8
  2. package/dist/{chunk-Q4AGVGVA.mjs → chunk-2O6X54P5.mjs} +103 -105
  3. package/dist/{chunk-AWY6FTH4.js → chunk-6QLTBEXP.js} +70 -86
  4. package/dist/{chunk-H6NYBVBV.js → chunk-6T4UZ4LV.js} +130 -132
  5. package/dist/{chunk-FNJWO324.js → chunk-H2FWLKXN.js} +2 -9
  6. package/dist/{chunk-IJNA24EZ.mjs → chunk-JJJ7AUEF.mjs} +39 -55
  7. package/dist/{chunk-LGP5AT6W.mjs → chunk-MGADYFW4.mjs} +28 -49
  8. package/dist/{chunk-UJAI73O6.js → chunk-MKZOLLJS.js} +39 -60
  9. package/dist/core-BIm7dkko.d.mts +27 -0
  10. package/dist/{core-7f6d2be6.d.ts → core-C3cON4Um.d.ts} +1 -1
  11. package/dist/helper.d.mts +27 -0
  12. package/dist/helper.d.ts +1 -1
  13. package/dist/helper.js +3 -3
  14. package/dist/helper.mjs +2 -2
  15. package/dist/index.d.mts +246 -0
  16. package/dist/index.d.ts +7 -7
  17. package/dist/index.js +73 -64
  18. package/dist/index.mjs +48 -39
  19. package/dist/rpc/bullmq/index.d.mts +21 -0
  20. package/dist/rpc/bullmq/index.d.ts +4 -4
  21. package/dist/rpc/bullmq/index.js +30 -43
  22. package/dist/rpc/bullmq/index.mjs +20 -33
  23. package/dist/rpc/kafka/index.d.mts +24 -0
  24. package/dist/rpc/kafka/index.d.ts +4 -4
  25. package/dist/rpc/kafka/index.js +25 -34
  26. package/dist/rpc/kafka/index.mjs +17 -26
  27. package/dist/rpc/nats/index.d.mts +15 -0
  28. package/dist/rpc/nats/index.d.ts +4 -4
  29. package/dist/rpc/nats/index.js +33 -46
  30. package/dist/rpc/nats/index.mjs +24 -37
  31. package/dist/rpc/rabbitmq/index.d.mts +16 -0
  32. package/dist/rpc/rabbitmq/index.d.ts +4 -4
  33. package/dist/rpc/rabbitmq/index.js +34 -46
  34. package/dist/rpc/rabbitmq/index.mjs +23 -35
  35. package/dist/rpc/redis/index.d.mts +23 -0
  36. package/dist/rpc/redis/index.d.ts +4 -4
  37. package/dist/rpc/redis/index.js +27 -38
  38. package/dist/rpc/redis/index.mjs +18 -29
  39. package/dist/server/elysia/index.d.mts +18 -0
  40. package/dist/server/elysia/index.d.ts +4 -4
  41. package/dist/server/elysia/index.js +22 -27
  42. package/dist/server/elysia/index.mjs +8 -13
  43. package/dist/server/express/index.d.mts +18 -0
  44. package/dist/server/express/index.d.ts +4 -4
  45. package/dist/server/express/index.js +24 -33
  46. package/dist/server/express/index.mjs +11 -20
  47. package/dist/server/fastify/index.d.mts +20 -0
  48. package/dist/server/fastify/index.d.ts +4 -4
  49. package/dist/server/fastify/index.js +23 -30
  50. package/dist/server/fastify/index.mjs +10 -17
  51. package/dist/server/h3/index.d.mts +16 -0
  52. package/dist/server/h3/index.d.ts +4 -4
  53. package/dist/server/h3/index.js +21 -25
  54. package/dist/server/h3/index.mjs +10 -14
  55. package/dist/server/hono/index.d.mts +16 -0
  56. package/dist/server/hono/index.d.ts +4 -4
  57. package/dist/server/hono/index.js +22 -30
  58. package/dist/server/hono/index.mjs +10 -18
  59. package/dist/server/hyper-express/index.d.mts +18 -0
  60. package/dist/server/hyper-express/index.d.ts +4 -4
  61. package/dist/server/hyper-express/index.js +23 -32
  62. package/dist/server/hyper-express/index.mjs +11 -20
  63. package/dist/server/koa/index.d.mts +18 -0
  64. package/dist/server/koa/index.d.ts +4 -4
  65. package/dist/server/koa/index.js +22 -29
  66. package/dist/server/koa/index.mjs +9 -16
  67. package/dist/test.d.mts +18 -0
  68. package/dist/test.d.ts +3 -3
  69. package/dist/test.js +14 -22
  70. package/dist/test.mjs +10 -18
  71. package/dist/types-B-y2TwhC.d.mts +17 -0
  72. package/dist/types-ByP1fKMe.d.mts +27 -0
  73. package/dist/{types-0a76c4bc.d.ts → types-C5sdDiDQ.d.ts} +2 -2
  74. package/dist/{types-f3b79218.d.ts → types-CIZbw8S2.d.ts} +2 -2
  75. package/dist/{types-81be0ba3.d.ts → types-CdQey96H.d.mts} +1 -1
  76. package/dist/types-CdQey96H.d.ts +108 -0
  77. package/package.json +3 -3
@@ -3,10 +3,10 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkH6NYBVBVjs = require('../../chunk-H6NYBVBV.js');
6
+ var _chunk6T4UZ4LVjs = require('../../chunk-6T4UZ4LV.js');
7
7
 
8
8
 
9
- var _chunkFNJWO324js = require('../../chunk-FNJWO324.js');
9
+ var _chunkH2FWLKXNjs = require('../../chunk-H2FWLKXN.js');
10
10
 
11
11
  // src/rpc/kafka/bind.ts
12
12
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
@@ -14,14 +14,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/kafka");
14
14
  async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
15
15
  const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
16
16
  const existQueue = /* @__PURE__ */ new Set();
17
- const metaMap = _chunkH6NYBVBVjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
17
+ const metaMap = _chunk6T4UZ4LVjs.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
- _chunkH6NYBVBVjs.detectAopDep.call(void 0, meta, {
24
+ _chunk6T4UZ4LVjs.detectAopDep.call(void 0, meta, {
25
25
  guards: globalGuards,
26
26
  interceptors: globalInterceptors
27
27
  }, "rpc");
@@ -33,8 +33,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
33
33
  const { data: { rpc } } = meta2;
34
34
  if (rpc) {
35
35
  const queue = rpc.queue || tag;
36
- if (existQueue.has(queue))
37
- continue;
36
+ if (existQueue.has(queue)) continue;
38
37
  existQueue.add(queue);
39
38
  await consumer.subscribe({
40
39
  topic: queue,
@@ -44,21 +43,19 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
44
43
  }
45
44
  }
46
45
  }
47
- _chunkFNJWO324js.__name.call(void 0, subscribeQueues, "subscribeQueues");
46
+ _chunkH2FWLKXNjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
48
47
  await subscribeQueues();
49
48
  await consumer.run({
50
- eachMessage: async ({ message, partition, topic, heartbeat, pause }) => {
51
- if (!existQueue.has(topic))
52
- return;
49
+ eachMessage: /* @__PURE__ */ _chunkH2FWLKXNjs.__name.call(void 0, async ({ message, partition, topic, heartbeat, pause }) => {
50
+ if (!existQueue.has(topic)) return;
53
51
  const data = JSON.parse(message.value.toString());
54
52
  const { tag, func, id, queue: clientQueue, _ps, args } = data;
55
- if (_ps !== 1)
56
- return;
53
+ if (_ps !== 1) return;
57
54
  debug(`invoke method "${func}" in module "${tag}"`);
58
55
  const meta2 = metaMap.get(tag)[func];
59
56
  const { data: { rpc } } = meta2;
60
57
  const isEvent = rpc.isEvent;
61
- const context = new (0, _chunkH6NYBVBVjs.Context)({
58
+ const context = new (0, _chunk6T4UZ4LVjs.Context)({
62
59
  type: "kafka",
63
60
  moduleMap,
64
61
  meta: meta2,
@@ -108,10 +105,10 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
108
105
  });
109
106
  }
110
107
  });
111
- }
108
+ }, "eachMessage")
112
109
  });
113
110
  }
114
- _chunkFNJWO324js.__name.call(void 0, bind, "bind");
111
+ _chunkH2FWLKXNjs.__name.call(void 0, bind, "bind");
115
112
 
116
113
  // src/rpc/kafka/client.ts
117
114
  var _events = require('events');
@@ -120,7 +117,7 @@ async function createClient({ producer, consumer }, controllers, opts) {
120
117
  let eventCount = 1;
121
118
  const ret = {};
122
119
  const emitter = new (0, _events.EventEmitter)();
123
- const clientQueue = _chunkH6NYBVBVjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
120
+ const clientQueue = _chunk6T4UZ4LVjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
124
121
  await consumer.subscribe({
125
122
  topic: clientQueue,
126
123
  fromBeginning: true
@@ -128,12 +125,10 @@ async function createClient({ producer, consumer }, controllers, opts) {
128
125
  for (const i in controllers) {
129
126
  ret[i] = new Proxy(new controllers[i](), {
130
127
  get(target, p) {
131
- if (typeof target[p] !== "function")
132
- throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
128
+ if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
133
129
  let { tag, queue, isEvent } = target[p]();
134
130
  return async (...args) => {
135
- if (!queue)
136
- queue = tag;
131
+ if (!queue) queue = tag;
137
132
  const id = `${eventId++}`;
138
133
  producer.send({
139
134
  topic: queue,
@@ -150,13 +145,11 @@ async function createClient({ producer, consumer }, controllers, opts) {
150
145
  }
151
146
  ]
152
147
  });
153
- if (isEvent)
154
- return null;
148
+ if (isEvent) return null;
155
149
  return new Promise((resolve, reject) => {
156
- if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max)
157
- reject({
158
- type: "exceeded"
159
- });
150
+ if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
151
+ type: "exceeded"
152
+ });
160
153
  let isEnd = false;
161
154
  const timer = setTimeout(() => {
162
155
  if (!isEnd) {
@@ -171,12 +164,10 @@ async function createClient({ producer, consumer }, controllers, opts) {
171
164
  eventCount--;
172
165
  isEnd = true;
173
166
  clearTimeout(timer);
174
- if (error)
175
- reject(data);
176
- else
177
- resolve(data);
167
+ if (error) reject(data);
168
+ else resolve(data);
178
169
  }
179
- _chunkFNJWO324js.__name.call(void 0, listener, "listener");
170
+ _chunkH2FWLKXNjs.__name.call(void 0, listener, "listener");
180
171
  eventCount++;
181
172
  emitter.once(id, listener);
182
173
  });
@@ -185,16 +176,16 @@ async function createClient({ producer, consumer }, controllers, opts) {
185
176
  });
186
177
  }
187
178
  await consumer.run({
188
- eachMessage: async ({ message, topic }) => {
179
+ eachMessage: /* @__PURE__ */ _chunkH2FWLKXNjs.__name.call(void 0, async ({ message, topic }) => {
189
180
  if (clientQueue === topic && message.value) {
190
181
  const { data, id, error } = JSON.parse(message.value.toString());
191
182
  emitter.emit(id, data, error);
192
183
  }
193
- }
184
+ }, "eachMessage")
194
185
  });
195
186
  return ret;
196
187
  }
197
- _chunkFNJWO324js.__name.call(void 0, createClient, "createClient");
188
+ _chunkH2FWLKXNjs.__name.call(void 0, createClient, "createClient");
198
189
 
199
190
 
200
191
 
@@ -3,10 +3,10 @@ import {
3
3
  createControllerMetaMap,
4
4
  detectAopDep,
5
5
  genClientQueue
6
- } from "../../chunk-Q4AGVGVA.mjs";
6
+ } from "../../chunk-2O6X54P5.mjs";
7
7
  import {
8
8
  __name
9
- } from "../../chunk-VYDBNZJ2.mjs";
9
+ } from "../../chunk-2NTXVYQC.mjs";
10
10
 
11
11
  // src/rpc/kafka/bind.ts
12
12
  import Debug from "debug";
@@ -33,8 +33,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
33
33
  const { data: { rpc } } = meta2;
34
34
  if (rpc) {
35
35
  const queue = rpc.queue || tag;
36
- if (existQueue.has(queue))
37
- continue;
36
+ if (existQueue.has(queue)) continue;
38
37
  existQueue.add(queue);
39
38
  await consumer.subscribe({
40
39
  topic: queue,
@@ -47,13 +46,11 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
47
46
  __name(subscribeQueues, "subscribeQueues");
48
47
  await subscribeQueues();
49
48
  await consumer.run({
50
- eachMessage: async ({ message, partition, topic, heartbeat, pause }) => {
51
- if (!existQueue.has(topic))
52
- return;
49
+ eachMessage: /* @__PURE__ */ __name(async ({ message, partition, topic, heartbeat, pause }) => {
50
+ if (!existQueue.has(topic)) return;
53
51
  const data = JSON.parse(message.value.toString());
54
52
  const { tag, func, id, queue: clientQueue, _ps, args } = data;
55
- if (_ps !== 1)
56
- return;
53
+ if (_ps !== 1) return;
57
54
  debug(`invoke method "${func}" in module "${tag}"`);
58
55
  const meta2 = metaMap.get(tag)[func];
59
56
  const { data: { rpc } } = meta2;
@@ -108,7 +105,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
108
105
  });
109
106
  }
110
107
  });
111
- }
108
+ }, "eachMessage")
112
109
  });
113
110
  }
114
111
  __name(bind, "bind");
@@ -128,12 +125,10 @@ async function createClient({ producer, consumer }, controllers, opts) {
128
125
  for (const i in controllers) {
129
126
  ret[i] = new Proxy(new controllers[i](), {
130
127
  get(target, p) {
131
- if (typeof target[p] !== "function")
132
- throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
128
+ if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
133
129
  let { tag, queue, isEvent } = target[p]();
134
130
  return async (...args) => {
135
- if (!queue)
136
- queue = tag;
131
+ if (!queue) queue = tag;
137
132
  const id = `${eventId++}`;
138
133
  producer.send({
139
134
  topic: queue,
@@ -150,13 +145,11 @@ async function createClient({ producer, consumer }, controllers, opts) {
150
145
  }
151
146
  ]
152
147
  });
153
- if (isEvent)
154
- return null;
148
+ if (isEvent) return null;
155
149
  return new Promise((resolve, reject) => {
156
- if (opts?.max && eventCount >= opts.max)
157
- reject({
158
- type: "exceeded"
159
- });
150
+ if (opts?.max && eventCount >= opts.max) reject({
151
+ type: "exceeded"
152
+ });
160
153
  let isEnd = false;
161
154
  const timer = setTimeout(() => {
162
155
  if (!isEnd) {
@@ -171,10 +164,8 @@ async function createClient({ producer, consumer }, controllers, opts) {
171
164
  eventCount--;
172
165
  isEnd = true;
173
166
  clearTimeout(timer);
174
- if (error)
175
- reject(data);
176
- else
177
- resolve(data);
167
+ if (error) reject(data);
168
+ else resolve(data);
178
169
  }
179
170
  __name(listener, "listener");
180
171
  eventCount++;
@@ -185,12 +176,12 @@ async function createClient({ producer, consumer }, controllers, opts) {
185
176
  });
186
177
  }
187
178
  await consumer.run({
188
- eachMessage: async ({ message, topic }) => {
179
+ eachMessage: /* @__PURE__ */ __name(async ({ message, topic }) => {
189
180
  if (clientQueue === topic && message.value) {
190
181
  const { data, id, error } = JSON.parse(message.value.toString());
191
182
  emitter.emit(id, data, error);
192
183
  }
193
- }
184
+ }, "eachMessage")
194
185
  });
195
186
  return ret;
196
187
  }
@@ -0,0 +1,15 @@
1
+ import { NatsConnection } from 'nats';
2
+ import { F as Factory } from '../../core-BIm7dkko.mjs';
3
+ import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-B-y2TwhC.mjs';
4
+ import { T as ToClientMap } from '../../types-CdQey96H.mjs';
5
+ import 'phecda-core';
6
+
7
+ interface NatsCtx extends RpcContext {
8
+ type: 'nats';
9
+ msg: any;
10
+ }
11
+ declare function bind(nc: NatsConnection, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
12
+
13
+ declare function createClient<S extends Record<string, any>>(nc: NatsConnection, controllers: S, opts?: Omit<RpcClientOptions, 'key'>): Promise<ToClientMap<S>>;
14
+
15
+ export { type NatsCtx, bind, createClient };
@@ -1,7 +1,7 @@
1
1
  import { NatsConnection } from 'nats';
2
- import { F as Factory } from '../../core-7f6d2be6.js';
3
- import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-f3b79218.js';
4
- import { T as ToClientMap } from '../../types-81be0ba3.js';
2
+ import { F as Factory } from '../../core-C3cON4Um.js';
3
+ import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-CIZbw8S2.js';
4
+ import { T as ToClientMap } from '../../types-CdQey96H.js';
5
5
  import 'phecda-core';
6
6
 
7
7
  interface NatsCtx extends RpcContext {
@@ -12,4 +12,4 @@ declare function bind(nc: NatsConnection, { moduleMap, meta }: Awaited<ReturnTyp
12
12
 
13
13
  declare function createClient<S extends Record<string, any>>(nc: NatsConnection, controllers: S, opts?: Omit<RpcClientOptions, 'key'>): Promise<ToClientMap<S>>;
14
14
 
15
- export { NatsCtx, bind, createClient };
15
+ export { type NatsCtx, bind, createClient };
@@ -3,10 +3,10 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkH6NYBVBVjs = require('../../chunk-H6NYBVBV.js');
6
+ var _chunk6T4UZ4LVjs = require('../../chunk-6T4UZ4LV.js');
7
7
 
8
8
 
9
- var _chunkFNJWO324js = require('../../chunk-FNJWO324.js');
9
+ var _chunkH2FWLKXNjs = require('../../chunk-H2FWLKXN.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 = _chunkH6NYBVBVjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
+ const metaMap = _chunk6T4UZ4LVjs.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
- _chunkH6NYBVBVjs.detectAopDep.call(void 0, meta, {
27
+ _chunk6T4UZ4LVjs.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
- _chunkFNJWO324js.__name.call(void 0, subscribeQueues, "subscribeQueues");
49
+ _chunkH2FWLKXNjs.__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
- msg.respond("{}");
61
- const context = new (0, _chunkH6NYBVBVjs.Context)({
57
+ if (isEvent) msg.respond("{}");
58
+ const context = new (0, _chunk6T4UZ4LVjs.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
- msg.respond(sc.encode(JSON.stringify({
82
- data: returnData,
83
- id
84
- })));
77
+ if (!isEvent) msg.respond(sc.encode(JSON.stringify({
78
+ data: returnData,
79
+ id
80
+ })));
85
81
  }, (err) => {
86
- if (!isEvent)
87
- msg.respond(sc.encode(JSON.stringify({
88
- data: err,
89
- error: true,
90
- id
91
- })));
82
+ if (!isEvent) msg.respond(sc.encode(JSON.stringify({
83
+ data: err,
84
+ error: true,
85
+ id
86
+ })));
92
87
  });
93
88
  }
94
- _chunkFNJWO324js.__name.call(void 0, handleRequest, "handleRequest");
89
+ _chunkH2FWLKXNjs.__name.call(void 0, handleRequest, "handleRequest");
95
90
  subscribeQueues();
96
- _chunkH6NYBVBVjs.HMR.call(void 0, async () => {
97
- for (const i in subscriptionMap)
98
- subscriptionMap[i].unsubscribe();
91
+ _chunk6T4UZ4LVjs.HMR.call(void 0, async () => {
92
+ for (const i in subscriptionMap) subscriptionMap[i].unsubscribe();
99
93
  await subscribeQueues();
100
94
  });
101
95
  }
102
- _chunkFNJWO324js.__name.call(void 0, bind, "bind");
96
+ _chunkH2FWLKXNjs.__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
- reject({
133
- type: "exceeded"
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
- reject(data);
156
- else
157
- resolve(data);
143
+ if (error) reject(data);
144
+ else resolve(data);
158
145
  }
159
- _chunkFNJWO324js.__name.call(void 0, handler, "handler");
146
+ _chunkH2FWLKXNjs.__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
- _chunkFNJWO324js.__name.call(void 0, createClient, "createClient");
155
+ _chunkH2FWLKXNjs.__name.call(void 0, createClient, "createClient");
169
156
 
170
157
 
171
158
 
@@ -3,10 +3,10 @@ import {
3
3
  HMR,
4
4
  createControllerMetaMap,
5
5
  detectAopDep
6
- } from "../../chunk-Q4AGVGVA.mjs";
6
+ } from "../../chunk-2O6X54P5.mjs";
7
7
  import {
8
8
  __name
9
- } from "../../chunk-VYDBNZJ2.mjs";
9
+ } from "../../chunk-2NTXVYQC.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
- msg.respond(sc.encode(JSON.stringify({
82
- data: returnData,
83
- id
84
- })));
77
+ if (!isEvent) msg.respond(sc.encode(JSON.stringify({
78
+ data: returnData,
79
+ id
80
+ })));
85
81
  }, (err) => {
86
- if (!isEvent)
87
- msg.respond(sc.encode(JSON.stringify({
88
- data: err,
89
- error: true,
90
- id
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
- reject({
133
- type: "exceeded"
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
- reject(data);
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-BIm7dkko.mjs';
3
+ import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-B-y2TwhC.mjs';
4
+ import { T as ToClientMap } from '../../types-CdQey96H.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-7f6d2be6.js';
3
- import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-f3b79218.js';
4
- import { T as ToClientMap } from '../../types-81be0ba3.js';
2
+ import { F as Factory } from '../../core-C3cON4Um.js';
3
+ import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../types-CIZbw8S2.js';
4
+ import { T as ToClientMap } from '../../types-CdQey96H.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 };