phecda-server 7.0.0-alpha.9 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/assets/schema.json +12 -9
  2. package/bin/cli.mjs +95 -36
  3. package/dist/{chunk-5RBTN33A.js → chunk-4LLLQOMF.js} +10 -5
  4. package/dist/{chunk-7ZGYJ5OW.mjs → chunk-AIAO6SV6.mjs} +10 -34
  5. package/dist/{chunk-V5EYXVJT.js → chunk-DPPDWBYO.js} +53 -25
  6. package/dist/{chunk-CVPZWDXU.mjs → chunk-E7EAPAGM.mjs} +10 -20
  7. package/dist/{chunk-ODVWOXVB.mjs → chunk-MKRHYZCL.mjs} +30 -2
  8. package/dist/{chunk-FXTJ3BJ6.mjs → chunk-NQ55PA2X.mjs} +9 -4
  9. package/dist/{chunk-FX3LDQII.js → chunk-XKK2SQ7W.js} +60 -70
  10. package/dist/{chunk-KJUD2BKE.js → chunk-ZWPOWMZP.js} +25 -49
  11. package/dist/{core-D_cz0tKa.d.ts → core-DbqWh47p.d.mts} +3 -2
  12. package/dist/{core-BDkhrEyf.d.mts → core-Rq7BhPHE.d.ts} +3 -2
  13. package/dist/helper.d.mts +3 -5
  14. package/dist/helper.d.ts +3 -5
  15. package/dist/helper.js +3 -5
  16. package/dist/helper.mjs +2 -4
  17. package/dist/http/elysia/index.d.mts +4 -4
  18. package/dist/http/elysia/index.d.ts +4 -4
  19. package/dist/http/elysia/index.js +41 -40
  20. package/dist/http/elysia/index.mjs +4 -3
  21. package/dist/http/express/index.d.mts +3 -3
  22. package/dist/http/express/index.d.ts +3 -3
  23. package/dist/http/express/index.js +38 -37
  24. package/dist/http/express/index.mjs +3 -2
  25. package/dist/http/fastify/index.d.mts +3 -3
  26. package/dist/http/fastify/index.d.ts +3 -3
  27. package/dist/http/fastify/index.js +39 -38
  28. package/dist/http/fastify/index.mjs +4 -3
  29. package/dist/http/h3/index.d.mts +3 -3
  30. package/dist/http/h3/index.d.ts +3 -3
  31. package/dist/http/h3/index.js +39 -38
  32. package/dist/http/h3/index.mjs +3 -2
  33. package/dist/http/hono/index.d.mts +3 -3
  34. package/dist/http/hono/index.d.ts +3 -3
  35. package/dist/http/hono/index.js +35 -34
  36. package/dist/http/hono/index.mjs +3 -2
  37. package/dist/http/hyper-express/index.d.mts +3 -3
  38. package/dist/http/hyper-express/index.d.ts +3 -3
  39. package/dist/http/hyper-express/index.js +36 -35
  40. package/dist/http/hyper-express/index.mjs +3 -2
  41. package/dist/http/koa/index.d.mts +3 -3
  42. package/dist/http/koa/index.d.ts +3 -3
  43. package/dist/http/koa/index.js +38 -37
  44. package/dist/http/koa/index.mjs +3 -2
  45. package/dist/index.d.mts +76 -12
  46. package/dist/index.d.ts +76 -12
  47. package/dist/index.js +102 -49
  48. package/dist/index.mjs +66 -13
  49. package/dist/{meta-BX5jhe4Z.d.mts → meta-BoS1E-Nz.d.mts} +6 -23
  50. package/dist/{meta-BX5jhe4Z.d.ts → meta-BoS1E-Nz.d.ts} +6 -23
  51. package/dist/rpc/bullmq/index.d.mts +4 -6
  52. package/dist/rpc/bullmq/index.d.ts +4 -6
  53. package/dist/rpc/bullmq/index.js +12 -80
  54. package/dist/rpc/bullmq/index.mjs +4 -72
  55. package/dist/rpc/electron/index.d.mts +13 -0
  56. package/dist/rpc/electron/index.d.ts +13 -0
  57. package/dist/rpc/electron/index.js +72 -0
  58. package/dist/rpc/electron/index.mjs +72 -0
  59. package/dist/rpc/kafka/index.d.mts +4 -9
  60. package/dist/rpc/kafka/index.d.ts +4 -9
  61. package/dist/rpc/kafka/index.js +11 -90
  62. package/dist/rpc/kafka/index.mjs +4 -83
  63. package/dist/rpc/nats/index.d.mts +4 -6
  64. package/dist/rpc/nats/index.d.ts +4 -6
  65. package/dist/rpc/nats/index.js +12 -72
  66. package/dist/rpc/nats/index.mjs +3 -63
  67. package/dist/rpc/rabbitmq/index.d.mts +4 -6
  68. package/dist/rpc/rabbitmq/index.d.ts +4 -6
  69. package/dist/rpc/rabbitmq/index.js +13 -79
  70. package/dist/rpc/rabbitmq/index.mjs +4 -70
  71. package/dist/rpc/redis/index.d.mts +4 -9
  72. package/dist/rpc/redis/index.d.ts +4 -9
  73. package/dist/rpc/redis/index.js +11 -78
  74. package/dist/rpc/redis/index.mjs +4 -71
  75. package/dist/rpc/web-ext/index.d.mts +2 -0
  76. package/dist/rpc/web-ext/index.d.ts +2 -0
  77. package/dist/rpc/web-ext/index.js +1 -0
  78. package/dist/rpc/web-ext/index.mjs +0 -0
  79. package/dist/rpc/ws/index.d.mts +14 -0
  80. package/dist/rpc/ws/index.d.ts +14 -0
  81. package/dist/rpc/ws/index.js +73 -0
  82. package/dist/rpc/ws/index.mjs +73 -0
  83. package/dist/test.d.mts +7 -3
  84. package/dist/test.d.ts +7 -3
  85. package/dist/test.js +6 -6
  86. package/dist/test.mjs +2 -2
  87. package/dist/types-CInz3bD0.d.ts +14 -0
  88. package/dist/types-E-rqlg3-.d.mts +14 -0
  89. package/dist/{types-DKVhyZk_.d.mts → types-SCJZFCYt.d.mts} +1 -1
  90. package/dist/{types-CMeuFoyd.d.ts → types-xruyYmyu.d.ts} +1 -1
  91. package/package.json +24 -8
  92. package/register/export.mjs +30 -0
  93. package/register/index.mjs +2 -3
  94. package/register/loader.mjs +83 -90
  95. package/register/utils.mjs +36 -6
  96. package/assets/ps.json +0 -24
  97. package/assets/tsconfig.json +0 -21
  98. package/dist/types-B-rUM9Fm.d.mts +0 -19
  99. package/dist/types-MxxtkZXw.d.ts +0 -19
@@ -0,0 +1,72 @@
1
+ import {
2
+ Context,
3
+ createControllerMetaMap,
4
+ detectAopDep
5
+ } from "../../chunk-E7EAPAGM.mjs";
6
+ import {
7
+ __name
8
+ } from "../../chunk-NQ55PA2X.mjs";
9
+
10
+ // src/rpc/electron/bind.ts
11
+ import Debug from "debug";
12
+ var debug = Debug("phecda-server/electron");
13
+ function bind(IPC, { moduleMap, meta }, opts = {}) {
14
+ const { globalGuards, globalFilter, globalPipe, globalAddons = [] } = opts;
15
+ const metaMap = createControllerMetaMap(meta, (meta2) => {
16
+ const { controller, rpc, func, tag } = meta2.data;
17
+ if (controller === "rpc" && rpc?.queue !== void 0) {
18
+ debug(`register method "${func}" in module "${tag}"`);
19
+ return true;
20
+ }
21
+ });
22
+ detectAopDep(meta, {
23
+ guards: globalGuards,
24
+ addons: globalAddons
25
+ }, "rpc");
26
+ IPC.handle("phecda-server:invoke", callback);
27
+ IPC.on("phecda-server:send", callback);
28
+ async function callback(event, data) {
29
+ const { func, id, tag, _ps, args } = data || {};
30
+ debug(`invoke method "${func}" in module "${tag}"`);
31
+ if (_ps !== 1) return;
32
+ const meta2 = metaMap.get(tag)[func];
33
+ const { data: { rpc: { isEvent } = {} } } = meta2;
34
+ const aop = Context.getAop(meta2, {
35
+ globalFilter,
36
+ globalGuards,
37
+ globalPipe
38
+ });
39
+ const context = new Context({
40
+ type: "electron",
41
+ category: "rpc",
42
+ moduleMap,
43
+ meta: meta2,
44
+ tag,
45
+ func,
46
+ args,
47
+ id,
48
+ isEvent,
49
+ queue: tag,
50
+ event
51
+ });
52
+ return await context.run(aop, (returnData) => {
53
+ if (!isEvent) return {
54
+ data: returnData,
55
+ id
56
+ };
57
+ }, (err) => {
58
+ if (!isEvent) {
59
+ return {
60
+ data: err,
61
+ error: true,
62
+ id
63
+ };
64
+ }
65
+ });
66
+ }
67
+ __name(callback, "callback");
68
+ }
69
+ __name(bind, "bind");
70
+ export {
71
+ bind
72
+ };
@@ -1,8 +1,8 @@
1
1
  import { Consumer, Producer } from 'kafkajs';
2
- import { F as Factory } from '../../core-BDkhrEyf.mjs';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-B-rUM9Fm.mjs';
4
- import { T as ToClientMap } from '../../meta-BX5jhe4Z.mjs';
2
+ import { F as Factory } from '../../core-DbqWh47p.mjs';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
5
4
  import 'phecda-core';
5
+ import '../../meta-BoS1E-Nz.mjs';
6
6
 
7
7
  interface KafkaCtx extends RpcCtx {
8
8
  type: 'kafka';
@@ -16,9 +16,4 @@ declare function bind({ consumer, producer }: {
16
16
  producer: Producer;
17
17
  }, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
18
18
 
19
- declare function createClient<S extends Record<string, any>>({ producer, consumer }: {
20
- producer: Producer;
21
- consumer: Consumer;
22
- }, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
23
-
24
- export { type KafkaCtx, bind, createClient };
19
+ export { type KafkaCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import { Consumer, Producer } from 'kafkajs';
2
- import { F as Factory } from '../../core-D_cz0tKa.js';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-MxxtkZXw.js';
4
- import { T as ToClientMap } from '../../meta-BX5jhe4Z.js';
2
+ import { F as Factory } from '../../core-Rq7BhPHE.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
5
4
  import 'phecda-core';
5
+ import '../../meta-BoS1E-Nz.js';
6
6
 
7
7
  interface KafkaCtx extends RpcCtx {
8
8
  type: 'kafka';
@@ -16,9 +16,4 @@ declare function bind({ consumer, producer }: {
16
16
  producer: Producer;
17
17
  }, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): Promise<void>;
18
18
 
19
- declare function createClient<S extends Record<string, any>>({ producer, consumer }: {
20
- producer: Producer;
21
- consumer: Consumer;
22
- }, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
23
-
24
- export { type KafkaCtx, bind, createClient };
19
+ export { type KafkaCtx, bind };
@@ -2,11 +2,10 @@
2
2
 
3
3
 
4
4
 
5
+ var _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.js');
5
6
 
6
- var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
7
7
 
8
-
9
- var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
8
+ var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
10
9
 
11
10
  // src/rpc/kafka/bind.ts
12
11
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
@@ -14,18 +13,18 @@ var debug = _debug2.default.call(void 0, "phecda-server/kafka");
14
13
  async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
15
14
  const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
16
15
  const existQueue = /* @__PURE__ */ new Set();
17
- const metaMap = _chunkFX3LDQIIjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
16
+ const metaMap = _chunkXKK2SQ7Wjs.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
- _chunkFX3LDQIIjs.detectAopDep.call(void 0, meta, {
23
+ _chunkXKK2SQ7Wjs.detectAopDep.call(void 0, meta, {
25
24
  guards: globalGuards,
26
25
  addons: globalAddons
27
26
  }, "rpc");
28
- _chunkFX3LDQIIjs.Context.applyAddons(globalAddons, {
27
+ _chunkXKK2SQ7Wjs.Context.applyAddons(globalAddons, {
29
28
  consumer,
30
29
  producer
31
30
  }, "kafka");
@@ -47,10 +46,10 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
47
46
  }
48
47
  }
49
48
  }
50
- _chunk5RBTN33Ajs.__name.call(void 0, subscribeQueues, "subscribeQueues");
49
+ _chunk4LLLQOMFjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
51
50
  await subscribeQueues();
52
51
  await consumer.run({
53
- eachMessage: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, async ({ message, partition, topic, heartbeat, pause }) => {
52
+ eachMessage: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, async ({ message, partition, topic, heartbeat, pause }) => {
54
53
  if (!existQueue.has(topic)) return;
55
54
  const data = JSON.parse(message.value.toString());
56
55
  const { tag, func, id, queue: clientQueue, _ps, args } = data;
@@ -59,12 +58,12 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
59
58
  const meta2 = metaMap.get(tag)[func];
60
59
  const { data: { rpc } } = meta2;
61
60
  const isEvent = rpc.isEvent;
62
- const aop = _chunkFX3LDQIIjs.Context.getAop(meta2, {
61
+ const aop = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
63
62
  globalFilter,
64
63
  globalGuards,
65
64
  globalPipe
66
65
  });
67
- const context = new (0, _chunkFX3LDQIIjs.Context)({
66
+ const context = new (0, _chunkXKK2SQ7Wjs.Context)({
68
67
  type: "kafka",
69
68
  category: "rpc",
70
69
  moduleMap,
@@ -113,85 +112,7 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
113
112
  }, "eachMessage")
114
113
  });
115
114
  }
116
- _chunk5RBTN33Ajs.__name.call(void 0, bind, "bind");
117
-
118
- // src/rpc/kafka/client.ts
119
- var _events = require('events');
120
- async function createClient({ producer, consumer }, controllers, opts) {
121
- let eventId = 1;
122
- let eventCount = 1;
123
- const ret = {};
124
- const emitter = new (0, _events.EventEmitter)();
125
- const clientQueue = _chunkFX3LDQIIjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.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 (_optionalChain([opts, 'optionalAccess', _3 => _3.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
- }, _optionalChain([opts, 'optionalAccess', _4 => _4.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
- _chunk5RBTN33Ajs.__name.call(void 0, listener, "listener");
176
- eventCount++;
177
- emitter.once(id, listener);
178
- });
179
- };
180
- }
181
- });
182
- }
183
- await consumer.run({
184
- eachMessage: /* @__PURE__ */ _chunk5RBTN33Ajs.__name.call(void 0, 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
- _chunk5RBTN33Ajs.__name.call(void 0, createClient, "createClient");
194
-
115
+ _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
195
116
 
196
117
 
197
- exports.bind = bind; exports.createClient = createClient;
118
+ exports.bind = bind;
@@ -1,12 +1,11 @@
1
1
  import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
- detectAopDep,
5
- genClientQueue
6
- } from "../../chunk-CVPZWDXU.mjs";
4
+ detectAopDep
5
+ } from "../../chunk-E7EAPAGM.mjs";
7
6
  import {
8
7
  __name
9
- } from "../../chunk-FXTJ3BJ6.mjs";
8
+ } from "../../chunk-NQ55PA2X.mjs";
10
9
 
11
10
  // src/rpc/kafka/bind.ts
12
11
  import Debug from "debug";
@@ -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-BDkhrEyf.mjs';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-B-rUM9Fm.mjs';
4
- import { T as ToClientMap } from '../../meta-BX5jhe4Z.mjs';
2
+ import { F as Factory } from '../../core-DbqWh47p.mjs';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
5
4
  import 'phecda-core';
5
+ import '../../meta-BoS1E-Nz.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-D_cz0tKa.js';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-MxxtkZXw.js';
4
- import { T as ToClientMap } from '../../meta-BX5jhe4Z.js';
2
+ import { F as Factory } from '../../core-Rq7BhPHE.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
5
4
  import 'phecda-core';
5
+ import '../../meta-BoS1E-Nz.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,11 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
5
+ var _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.js');
6
6
 
7
7
 
8
8
 
9
- var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
9
+ var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
10
10
 
11
11
  // src/rpc/nats/bind.ts
12
12
  var _nats = require('nats');
@@ -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 = _chunkFX3LDQIIjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
+ const metaMap = _chunkXKK2SQ7Wjs.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
- _chunkFX3LDQIIjs.detectAopDep.call(void 0, meta, {
27
+ _chunkXKK2SQ7Wjs.detectAopDep.call(void 0, meta, {
28
28
  addons: globalAddons,
29
29
  guards: globalGuards
30
30
  }, "rpc");
31
- _chunkFX3LDQIIjs.Context.applyAddons(globalAddons, nc, "nats");
31
+ _chunkXKK2SQ7Wjs.Context.applyAddons(globalAddons, nc, "nats");
32
32
  async function subscribeQueues() {
33
33
  existQueue.clear();
34
34
  for (const [tag, record] of metaMap) {
@@ -47,7 +47,7 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
47
47
  }
48
48
  }
49
49
  }
50
- _chunk5RBTN33Ajs.__name.call(void 0, subscribeQueues, "subscribeQueues");
50
+ _chunk4LLLQOMFjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
51
51
  async function handleRequest(_, msg) {
52
52
  const data = JSON.parse(sc.decode(msg.data));
53
53
  const { tag, func, id, _ps, args } = data;
@@ -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 = _chunkFX3LDQIIjs.Context.getAop(meta2, {
59
+ const aop = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
60
60
  globalFilter,
61
61
  globalGuards,
62
62
  globalPipe
63
63
  });
64
- const context = new (0, _chunkFX3LDQIIjs.Context)({
64
+ const context = new (0, _chunkXKK2SQ7Wjs.Context)({
65
65
  type: "nats",
66
66
  category: "rpc",
67
67
  moduleMap,
@@ -88,74 +88,14 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
88
88
  })));
89
89
  });
90
90
  }
91
- _chunk5RBTN33Ajs.__name.call(void 0, handleRequest, "handleRequest");
91
+ _chunk4LLLQOMFjs.__name.call(void 0, handleRequest, "handleRequest");
92
92
  subscribeQueues();
93
- _chunk5RBTN33Ajs.HMR.call(void 0, async () => {
93
+ _chunk4LLLQOMFjs.HMR.call(void 0, async () => {
94
94
  for (const i in subscriptionMap) subscriptionMap[i].unsubscribe();
95
95
  await subscribeQueues();
96
96
  });
97
97
  }
98
- _chunk5RBTN33Ajs.__name.call(void 0, bind, "bind");
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
- _chunk5RBTN33Ajs.__name.call(void 0, handler, "handler");
149
- eventCount++;
150
- });
151
- };
152
- }
153
- });
154
- }
155
- return ret;
156
- }
157
- _chunk5RBTN33Ajs.__name.call(void 0, createClient, "createClient");
158
-
159
-
160
-
161
- exports.bind = bind; exports.createClient = createClient;
101
+ exports.bind = bind;
@@ -2,11 +2,11 @@ import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
4
  detectAopDep
5
- } from "../../chunk-CVPZWDXU.mjs";
5
+ } from "../../chunk-E7EAPAGM.mjs";
6
6
  import {
7
7
  HMR,
8
8
  __name
9
- } from "../../chunk-FXTJ3BJ6.mjs";
9
+ } from "../../chunk-NQ55PA2X.mjs";
10
10
 
11
11
  // src/rpc/nats/bind.ts
12
12
  import { StringCodec } from "nats";
@@ -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-BDkhrEyf.mjs';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-B-rUM9Fm.mjs';
4
- import { T as ToClientMap } from '../../meta-BX5jhe4Z.mjs';
2
+ import { F as Factory } from '../../core-DbqWh47p.mjs';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
5
4
  import 'phecda-core';
5
+ import '../../meta-BoS1E-Nz.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-D_cz0tKa.js';
3
- import { R as RpcCtx, a as RpcServerOptions, b as RpcClientOptions } from '../../types-MxxtkZXw.js';
4
- import { T as ToClientMap } from '../../meta-BX5jhe4Z.js';
2
+ import { F as Factory } from '../../core-Rq7BhPHE.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
5
4
  import 'phecda-core';
5
+ import '../../meta-BoS1E-Nz.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 };