phecda-server 7.0.0-alpha.11 → 7.0.0-alpha.12

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 (72) hide show
  1. package/dist/{chunk-G7JFKM2M.js → chunk-IJFIY6QN.js} +1 -9
  2. package/dist/{chunk-Z7NAAE4M.mjs → chunk-VX4BZEL7.mjs} +0 -8
  3. package/dist/{core-CUTbX_IS.d.ts → core-CDzIy2g0.d.ts} +1 -1
  4. package/dist/{core-DIfgUKIU.d.mts → core-jUg1HvYT.d.mts} +1 -1
  5. package/dist/helper.d.mts +2 -4
  6. package/dist/helper.d.ts +2 -4
  7. package/dist/helper.js +2 -4
  8. package/dist/helper.mjs +1 -3
  9. package/dist/http/elysia/index.d.mts +3 -3
  10. package/dist/http/elysia/index.d.ts +3 -3
  11. package/dist/http/elysia/index.js +18 -17
  12. package/dist/http/elysia/index.mjs +2 -1
  13. package/dist/http/express/index.d.mts +3 -3
  14. package/dist/http/express/index.d.ts +3 -3
  15. package/dist/http/express/index.js +17 -16
  16. package/dist/http/express/index.mjs +2 -1
  17. package/dist/http/fastify/index.d.mts +3 -3
  18. package/dist/http/fastify/index.d.ts +3 -3
  19. package/dist/http/fastify/index.js +17 -16
  20. package/dist/http/fastify/index.mjs +2 -1
  21. package/dist/http/h3/index.d.mts +3 -3
  22. package/dist/http/h3/index.d.ts +3 -3
  23. package/dist/http/h3/index.js +18 -17
  24. package/dist/http/h3/index.mjs +2 -1
  25. package/dist/http/hono/index.d.mts +3 -3
  26. package/dist/http/hono/index.d.ts +3 -3
  27. package/dist/http/hono/index.js +15 -14
  28. package/dist/http/hono/index.mjs +2 -1
  29. package/dist/http/hyper-express/index.d.mts +3 -3
  30. package/dist/http/hyper-express/index.d.ts +3 -3
  31. package/dist/http/hyper-express/index.js +16 -15
  32. package/dist/http/hyper-express/index.mjs +2 -1
  33. package/dist/http/koa/index.d.mts +3 -3
  34. package/dist/http/koa/index.d.ts +3 -3
  35. package/dist/http/koa/index.js +17 -16
  36. package/dist/http/koa/index.mjs +2 -1
  37. package/dist/index.d.mts +8 -8
  38. package/dist/index.d.ts +8 -8
  39. package/dist/index.js +19 -19
  40. package/dist/index.mjs +1 -1
  41. package/dist/{meta-CR-D39hQ.d.mts → meta-xvg6V7pH.d.mts} +2 -19
  42. package/dist/{meta-CR-D39hQ.d.ts → meta-xvg6V7pH.d.ts} +2 -19
  43. package/dist/rpc/bullmq/index.d.mts +4 -6
  44. package/dist/rpc/bullmq/index.d.ts +4 -6
  45. package/dist/rpc/bullmq/index.js +7 -75
  46. package/dist/rpc/bullmq/index.mjs +3 -71
  47. package/dist/rpc/kafka/index.d.mts +4 -9
  48. package/dist/rpc/kafka/index.d.ts +4 -9
  49. package/dist/rpc/kafka/index.js +7 -86
  50. package/dist/rpc/kafka/index.mjs +3 -82
  51. package/dist/rpc/nats/index.d.mts +4 -6
  52. package/dist/rpc/nats/index.d.ts +4 -6
  53. package/dist/rpc/nats/index.js +7 -67
  54. package/dist/rpc/nats/index.mjs +2 -62
  55. package/dist/rpc/rabbitmq/index.d.mts +4 -6
  56. package/dist/rpc/rabbitmq/index.d.ts +4 -6
  57. package/dist/rpc/rabbitmq/index.js +7 -73
  58. package/dist/rpc/rabbitmq/index.mjs +3 -69
  59. package/dist/rpc/redis/index.d.mts +4 -9
  60. package/dist/rpc/redis/index.d.ts +4 -9
  61. package/dist/rpc/redis/index.js +7 -74
  62. package/dist/rpc/redis/index.mjs +3 -70
  63. package/dist/test.d.mts +7 -3
  64. package/dist/test.d.ts +7 -3
  65. package/dist/types-6qaaUIKZ.d.mts +14 -0
  66. package/dist/{types-BF1TDbFV.d.ts → types-B-1OL-3P.d.ts} +1 -1
  67. package/dist/types-BtXOT5rI.d.ts +14 -0
  68. package/dist/{types-DYviSl5B.d.mts → types-Ctd6pLNE.d.mts} +1 -1
  69. package/package.json +1 -1
  70. package/register/loader.mjs +0 -9
  71. package/dist/types-DYRu0vic.d.ts +0 -19
  72. package/dist/types-DqH1qA-q.d.mts +0 -19
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
- detectAopDep,
5
- genClientQueue
6
- } from "../../chunk-Z7NAAE4M.mjs";
4
+ detectAopDep
5
+ } from "../../chunk-VX4BZEL7.mjs";
7
6
  import {
8
7
  __name
9
8
  } from "../../chunk-NQ55PA2X.mjs";
@@ -114,84 +113,6 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
114
113
  });
115
114
  }
116
115
  __name(bind, "bind");
117
-
118
- // src/rpc/kafka/client.ts
119
- import { EventEmitter } from "events";
120
- async function createClient({ producer, consumer }, controllers, opts) {
121
- let eventId = 1;
122
- let eventCount = 1;
123
- const ret = {};
124
- const emitter = new EventEmitter();
125
- const clientQueue = genClientQueue(opts?.key);
126
- await consumer.subscribe({
127
- topic: clientQueue,
128
- fromBeginning: true
129
- });
130
- for (const i in controllers) {
131
- ret[i] = new Proxy(new controllers[i](), {
132
- get(target, p) {
133
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
134
- let { tag, queue, isEvent } = target[p]();
135
- return async (...args) => {
136
- if (!queue) queue = tag;
137
- const id = `${eventId++}`;
138
- producer.send({
139
- topic: queue,
140
- messages: [
141
- {
142
- value: JSON.stringify({
143
- _ps: 1,
144
- id,
145
- tag,
146
- queue: clientQueue,
147
- func: p,
148
- args
149
- })
150
- }
151
- ]
152
- });
153
- if (isEvent) return null;
154
- return new Promise((resolve, reject) => {
155
- if (opts?.max && eventCount >= opts.max) reject({
156
- type: "exceeded"
157
- });
158
- let isEnd = false;
159
- const timer = setTimeout(() => {
160
- if (!isEnd) {
161
- eventCount--;
162
- emitter.off(id, listener);
163
- reject({
164
- type: "timeout"
165
- });
166
- }
167
- }, opts?.timeout || 5e3);
168
- function listener(data, error) {
169
- eventCount--;
170
- isEnd = true;
171
- clearTimeout(timer);
172
- if (error) reject(data);
173
- else resolve(data);
174
- }
175
- __name(listener, "listener");
176
- eventCount++;
177
- emitter.once(id, listener);
178
- });
179
- };
180
- }
181
- });
182
- }
183
- await consumer.run({
184
- eachMessage: /* @__PURE__ */ __name(async ({ message, topic }) => {
185
- if (clientQueue === topic && message.value) {
186
- const { data, id, error } = JSON.parse(message.value.toString());
187
- emitter.emit(id, data, error);
188
- }
189
- }, "eachMessage")
190
- });
191
- return ret;
192
- }
193
- __name(createClient, "createClient");
194
116
  export {
195
- bind,
196
- createClient
117
+ bind
197
118
  };
@@ -1,8 +1,8 @@
1
1
  import { NatsConnection } from 'nats';
2
- import { F as Factory } from '../../core-DIfgUKIU.mjs';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-DqH1qA-q.mjs';
4
- import { T as ToClientMap } from '../../meta-CR-D39hQ.mjs';
2
+ import { F as Factory } from '../../core-jUg1HvYT.mjs';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-6qaaUIKZ.mjs';
5
4
  import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.mjs';
6
6
 
7
7
  interface NatsCtx extends RpcCtx {
8
8
  type: 'nats';
@@ -10,6 +10,4 @@ interface NatsCtx extends RpcCtx {
10
10
  }
11
11
  declare function bind(nc: NatsConnection, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
12
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 };
13
+ export { type NatsCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import { NatsConnection } from 'nats';
2
- import { F as Factory } from '../../core-CUTbX_IS.js';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-DYRu0vic.js';
4
- import { T as ToClientMap } from '../../meta-CR-D39hQ.js';
2
+ import { F as Factory } from '../../core-CDzIy2g0.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-BtXOT5rI.js';
5
4
  import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.js';
6
6
 
7
7
  interface NatsCtx extends RpcCtx {
8
8
  type: 'nats';
@@ -10,6 +10,4 @@ interface NatsCtx extends RpcCtx {
10
10
  }
11
11
  declare function bind(nc: NatsConnection, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
12
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 };
13
+ export { type NatsCtx, bind };
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkG7JFKM2Mjs = require('../../chunk-G7JFKM2M.js');
5
+ var _chunkIJFIY6QNjs = require('../../chunk-IJFIY6QN.js');
6
6
 
7
7
 
8
8
 
@@ -17,18 +17,18 @@ 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 = _chunkG7JFKM2Mjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
+ const metaMap = _chunkIJFIY6QNjs.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
- _chunkG7JFKM2Mjs.detectAopDep.call(void 0, meta, {
27
+ _chunkIJFIY6QNjs.detectAopDep.call(void 0, meta, {
28
28
  addons: globalAddons,
29
29
  guards: globalGuards
30
30
  }, "rpc");
31
- _chunkG7JFKM2Mjs.Context.applyAddons(globalAddons, nc, "nats");
31
+ _chunkIJFIY6QNjs.Context.applyAddons(globalAddons, nc, "nats");
32
32
  async function subscribeQueues() {
33
33
  existQueue.clear();
34
34
  for (const [tag, record] of metaMap) {
@@ -56,12 +56,12 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
56
56
  const meta2 = metaMap.get(tag)[func];
57
57
  const { data: { rpc: { isEvent } = {} } } = meta2;
58
58
  if (isEvent) msg.respond("{}");
59
- const aop = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
59
+ const aop = _chunkIJFIY6QNjs.Context.getAop(meta2, {
60
60
  globalFilter,
61
61
  globalGuards,
62
62
  globalPipe
63
63
  });
64
- const context = new (0, _chunkG7JFKM2Mjs.Context)({
64
+ const context = new (0, _chunkIJFIY6QNjs.Context)({
65
65
  type: "nats",
66
66
  category: "rpc",
67
67
  moduleMap,
@@ -97,65 +97,5 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
97
97
  }
98
98
  _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
99
99
 
100
- // src/rpc/nats/client.ts
101
100
 
102
- async function createClient(nc, controllers, opts) {
103
- let eventId = 1;
104
- let eventCount = 0;
105
- const sc = _nats.StringCodec.call(void 0, );
106
- const ret = {};
107
- for (const i in controllers) {
108
- ret[i] = new Proxy(new controllers[i](), {
109
- get(target, p) {
110
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
111
- let { tag, queue, isEvent } = target[p]();
112
- return async (...args) => {
113
- if (!queue) queue = tag;
114
- const id = `${eventId++}`;
115
- const request = nc.request(queue, sc.encode(JSON.stringify({
116
- _ps: 1,
117
- id,
118
- args,
119
- tag,
120
- func: p
121
- })));
122
- if (isEvent) return null;
123
- return new Promise((resolve, reject) => {
124
- if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
125
- type: "exceeded"
126
- });
127
- request.catch(reject);
128
- request.then((msg) => {
129
- const { data, id: id2, error } = msg.json();
130
- if (id2) handler(data, error);
131
- });
132
- let isEnd = false;
133
- const timer = setTimeout(() => {
134
- if (!isEnd) {
135
- eventCount--;
136
- reject({
137
- type: "timeout"
138
- });
139
- }
140
- }, _optionalChain([opts, 'optionalAccess', _4 => _4.timeout]) || 5e3);
141
- function handler(data, error) {
142
- eventCount--;
143
- isEnd = true;
144
- clearTimeout(timer);
145
- if (error) reject(data);
146
- else resolve(data);
147
- }
148
- _chunk4LLLQOMFjs.__name.call(void 0, handler, "handler");
149
- eventCount++;
150
- });
151
- };
152
- }
153
- });
154
- }
155
- return ret;
156
- }
157
- _chunk4LLLQOMFjs.__name.call(void 0, createClient, "createClient");
158
-
159
-
160
-
161
- exports.bind = bind; exports.createClient = createClient;
101
+ exports.bind = bind;
@@ -2,7 +2,7 @@ import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
4
  detectAopDep
5
- } from "../../chunk-Z7NAAE4M.mjs";
5
+ } from "../../chunk-VX4BZEL7.mjs";
6
6
  import {
7
7
  HMR,
8
8
  __name
@@ -96,66 +96,6 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
96
96
  });
97
97
  }
98
98
  __name(bind, "bind");
99
-
100
- // src/rpc/nats/client.ts
101
- import { StringCodec as StringCodec2 } from "nats";
102
- async function createClient(nc, controllers, opts) {
103
- let eventId = 1;
104
- let eventCount = 0;
105
- const sc = StringCodec2();
106
- const ret = {};
107
- for (const i in controllers) {
108
- ret[i] = new Proxy(new controllers[i](), {
109
- get(target, p) {
110
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
111
- let { tag, queue, isEvent } = target[p]();
112
- return async (...args) => {
113
- if (!queue) queue = tag;
114
- const id = `${eventId++}`;
115
- const request = nc.request(queue, sc.encode(JSON.stringify({
116
- _ps: 1,
117
- id,
118
- args,
119
- tag,
120
- func: p
121
- })));
122
- if (isEvent) return null;
123
- return new Promise((resolve, reject) => {
124
- if (opts?.max && eventCount >= opts.max) reject({
125
- type: "exceeded"
126
- });
127
- request.catch(reject);
128
- request.then((msg) => {
129
- const { data, id: id2, error } = msg.json();
130
- if (id2) handler(data, error);
131
- });
132
- let isEnd = false;
133
- const timer = setTimeout(() => {
134
- if (!isEnd) {
135
- eventCount--;
136
- reject({
137
- type: "timeout"
138
- });
139
- }
140
- }, opts?.timeout || 5e3);
141
- function handler(data, error) {
142
- eventCount--;
143
- isEnd = true;
144
- clearTimeout(timer);
145
- if (error) reject(data);
146
- else resolve(data);
147
- }
148
- __name(handler, "handler");
149
- eventCount++;
150
- });
151
- };
152
- }
153
- });
154
- }
155
- return ret;
156
- }
157
- __name(createClient, "createClient");
158
99
  export {
159
- bind,
160
- createClient
100
+ bind
161
101
  };
@@ -1,8 +1,8 @@
1
1
  import amqplib from 'amqplib';
2
- import { F as Factory } from '../../core-DIfgUKIU.mjs';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-DqH1qA-q.mjs';
4
- import { T as ToClientMap } from '../../meta-CR-D39hQ.mjs';
2
+ import { F as Factory } from '../../core-jUg1HvYT.mjs';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-6qaaUIKZ.mjs';
5
4
  import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.mjs';
6
6
 
7
7
  interface RabbitmqCtx extends RpcCtx {
8
8
  type: 'rabbitmq';
@@ -11,6 +11,4 @@ interface RabbitmqCtx extends RpcCtx {
11
11
  }
12
12
  declare function bind(ch: amqplib.Channel, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
13
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 };
14
+ export { type RabbitmqCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import amqplib from 'amqplib';
2
- import { F as Factory } from '../../core-CUTbX_IS.js';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-DYRu0vic.js';
4
- import { T as ToClientMap } from '../../meta-CR-D39hQ.js';
2
+ import { F as Factory } from '../../core-CDzIy2g0.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-BtXOT5rI.js';
5
4
  import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.js';
6
6
 
7
7
  interface RabbitmqCtx extends RpcCtx {
8
8
  type: 'rabbitmq';
@@ -11,6 +11,4 @@ interface RabbitmqCtx extends RpcCtx {
11
11
  }
12
12
  declare function bind(ch: amqplib.Channel, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
13
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 };
14
+ export { type RabbitmqCtx, bind };
@@ -2,8 +2,7 @@
2
2
 
3
3
 
4
4
 
5
-
6
- var _chunkG7JFKM2Mjs = require('../../chunk-G7JFKM2M.js');
5
+ var _chunkIJFIY6QNjs = require('../../chunk-IJFIY6QN.js');
7
6
 
8
7
 
9
8
 
@@ -14,19 +13,19 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
14
13
  var debug = _debug2.default.call(void 0, "phecda-server/rabbitmq");
15
14
  async function bind(ch, { moduleMap, meta }, opts = {}) {
16
15
  const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
17
- const metaMap = _chunkG7JFKM2Mjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
16
+ const metaMap = _chunkIJFIY6QNjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
18
17
  const { controller, rpc, func, tag } = meta2.data;
19
18
  if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
20
19
  debug(`register method "${func}" in module "${tag}"`);
21
20
  return true;
22
21
  }
23
22
  });
24
- _chunkG7JFKM2Mjs.detectAopDep.call(void 0, meta, {
23
+ _chunkIJFIY6QNjs.detectAopDep.call(void 0, meta, {
25
24
  guards: globalGuards,
26
25
  addons: globalAddons
27
26
  }, "rpc");
28
27
  const existQueue = /* @__PURE__ */ new Set();
29
- _chunkG7JFKM2Mjs.Context.applyAddons(globalAddons, ch, "rabbitmq");
28
+ _chunkIJFIY6QNjs.Context.applyAddons(globalAddons, ch, "rabbitmq");
30
29
  async function subscribeQueues() {
31
30
  existQueue.clear();
32
31
  for (const [tag, record] of metaMap) {
@@ -58,12 +57,12 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
58
57
  debug(`invoke method "${func}" in module "${tag}"`);
59
58
  const meta2 = metaMap.get(tag)[func];
60
59
  const { data: { rpc: { isEvent } = {} } } = meta2;
61
- const aop = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
60
+ const aop = _chunkIJFIY6QNjs.Context.getAop(meta2, {
62
61
  globalFilter,
63
62
  globalGuards,
64
63
  globalPipe
65
64
  });
66
- const context = new (0, _chunkG7JFKM2Mjs.Context)({
65
+ const context = new (0, _chunkIJFIY6QNjs.Context)({
67
66
  type: "rabbitmq",
68
67
  category: "rpc",
69
68
  moduleMap,
@@ -100,70 +99,5 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
100
99
  }
101
100
  _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
102
101
 
103
- // src/rpc/rabbitmq/client.ts
104
- var _events = require('events');
105
- async function createClient(ch, controllers, opts) {
106
- let eventId = 1;
107
- let eventCount = 0;
108
- const ret = {};
109
- const emitter = new (0, _events.EventEmitter)();
110
- const clientQueue = _chunkG7JFKM2Mjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
111
- await ch.assertQueue(clientQueue);
112
- ch.consume(clientQueue, (msg) => {
113
- if (!msg) return;
114
- const { data, id, error } = JSON.parse(msg.content.toString());
115
- emitter.emit(id, data, error);
116
- });
117
- for (const i in controllers) {
118
- ret[i] = new Proxy(new controllers[i](), {
119
- get(target, p) {
120
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
121
- let { tag, queue, isEvent } = target[p]();
122
- return async (...args) => {
123
- if (!queue) queue = tag;
124
- const id = `${eventId++}`;
125
- ch.sendToQueue(queue, Buffer.from(JSON.stringify({
126
- _ps: 1,
127
- id,
128
- args,
129
- tag,
130
- queue: clientQueue,
131
- func: p
132
- })));
133
- if (isEvent) return null;
134
- return new Promise((resolve, reject) => {
135
- if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
136
- type: "exceeded"
137
- });
138
- let isEnd = false;
139
- const timer = setTimeout(() => {
140
- if (!isEnd) {
141
- eventCount--;
142
- emitter.off(id, listener);
143
- reject({
144
- type: "timeout"
145
- });
146
- }
147
- }, _optionalChain([opts, 'optionalAccess', _4 => _4.timeout]) || 5e3);
148
- function listener(data, error) {
149
- eventCount--;
150
- isEnd = true;
151
- clearTimeout(timer);
152
- if (error) reject(data);
153
- else resolve(data);
154
- }
155
- _chunk4LLLQOMFjs.__name.call(void 0, listener, "listener");
156
- eventCount++;
157
- emitter.once(id, listener);
158
- });
159
- };
160
- }
161
- });
162
- }
163
- return ret;
164
- }
165
- _chunk4LLLQOMFjs.__name.call(void 0, createClient, "createClient");
166
-
167
-
168
102
 
169
- exports.bind = bind; exports.createClient = createClient;
103
+ exports.bind = bind;
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
- detectAopDep,
5
- genClientQueue
6
- } from "../../chunk-Z7NAAE4M.mjs";
4
+ detectAopDep
5
+ } from "../../chunk-VX4BZEL7.mjs";
7
6
  import {
8
7
  HMR,
9
8
  __name
@@ -99,71 +98,6 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
99
98
  });
100
99
  }
101
100
  __name(bind, "bind");
102
-
103
- // src/rpc/rabbitmq/client.ts
104
- import { EventEmitter } from "events";
105
- async function createClient(ch, controllers, opts) {
106
- let eventId = 1;
107
- let eventCount = 0;
108
- const ret = {};
109
- const emitter = new EventEmitter();
110
- const clientQueue = genClientQueue(opts?.key);
111
- await ch.assertQueue(clientQueue);
112
- ch.consume(clientQueue, (msg) => {
113
- if (!msg) return;
114
- const { data, id, error } = JSON.parse(msg.content.toString());
115
- emitter.emit(id, data, error);
116
- });
117
- for (const i in controllers) {
118
- ret[i] = new Proxy(new controllers[i](), {
119
- get(target, p) {
120
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
121
- let { tag, queue, isEvent } = target[p]();
122
- return async (...args) => {
123
- if (!queue) queue = tag;
124
- const id = `${eventId++}`;
125
- ch.sendToQueue(queue, Buffer.from(JSON.stringify({
126
- _ps: 1,
127
- id,
128
- args,
129
- tag,
130
- queue: clientQueue,
131
- func: p
132
- })));
133
- if (isEvent) return null;
134
- return new Promise((resolve, reject) => {
135
- if (opts?.max && eventCount >= opts.max) reject({
136
- type: "exceeded"
137
- });
138
- let isEnd = false;
139
- const timer = setTimeout(() => {
140
- if (!isEnd) {
141
- eventCount--;
142
- emitter.off(id, listener);
143
- reject({
144
- type: "timeout"
145
- });
146
- }
147
- }, opts?.timeout || 5e3);
148
- function listener(data, error) {
149
- eventCount--;
150
- isEnd = true;
151
- clearTimeout(timer);
152
- if (error) reject(data);
153
- else resolve(data);
154
- }
155
- __name(listener, "listener");
156
- eventCount++;
157
- emitter.once(id, listener);
158
- });
159
- };
160
- }
161
- });
162
- }
163
- return ret;
164
- }
165
- __name(createClient, "createClient");
166
101
  export {
167
- bind,
168
- createClient
102
+ bind
169
103
  };
@@ -1,8 +1,8 @@
1
1
  import Redis from 'ioredis';
2
- import { F as Factory } from '../../core-DIfgUKIU.mjs';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-DqH1qA-q.mjs';
4
- import { T as ToClientMap } from '../../meta-CR-D39hQ.mjs';
2
+ import { F as Factory } from '../../core-jUg1HvYT.mjs';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-6qaaUIKZ.mjs';
5
4
  import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.mjs';
6
6
 
7
7
  interface RedisCtx extends RpcCtx {
8
8
  type: 'redis';
@@ -15,9 +15,4 @@ declare function bind({ sub, pub }: {
15
15
  pub: Redis;
16
16
  }, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
17
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 };
18
+ export { type RedisCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import Redis from 'ioredis';
2
- import { F as Factory } from '../../core-CUTbX_IS.js';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-DYRu0vic.js';
4
- import { T as ToClientMap } from '../../meta-CR-D39hQ.js';
2
+ import { F as Factory } from '../../core-CDzIy2g0.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-BtXOT5rI.js';
5
4
  import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.js';
6
6
 
7
7
  interface RedisCtx extends RpcCtx {
8
8
  type: 'redis';
@@ -15,9 +15,4 @@ declare function bind({ sub, pub }: {
15
15
  pub: Redis;
16
16
  }, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
17
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 };
18
+ export { type RedisCtx, bind };