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

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 (86) hide show
  1. package/assets/schema.json +11 -2
  2. package/bin/cli.mjs +62 -9
  3. package/dist/{chunk-G7JFKM2M.js → chunk-IJFIY6QN.js} +1 -9
  4. package/dist/{chunk-Z7NAAE4M.mjs → chunk-VX4BZEL7.mjs} +0 -8
  5. package/dist/{core-CUTbX_IS.d.ts → core-CDzIy2g0.d.ts} +1 -1
  6. package/dist/{core-DIfgUKIU.d.mts → core-jUg1HvYT.d.mts} +1 -1
  7. package/dist/helper.d.mts +2 -4
  8. package/dist/helper.d.ts +2 -4
  9. package/dist/helper.js +2 -4
  10. package/dist/helper.mjs +1 -3
  11. package/dist/http/elysia/index.d.mts +3 -3
  12. package/dist/http/elysia/index.d.ts +3 -3
  13. package/dist/http/elysia/index.js +18 -17
  14. package/dist/http/elysia/index.mjs +2 -1
  15. package/dist/http/express/index.d.mts +3 -3
  16. package/dist/http/express/index.d.ts +3 -3
  17. package/dist/http/express/index.js +17 -16
  18. package/dist/http/express/index.mjs +2 -1
  19. package/dist/http/fastify/index.d.mts +3 -3
  20. package/dist/http/fastify/index.d.ts +3 -3
  21. package/dist/http/fastify/index.js +17 -16
  22. package/dist/http/fastify/index.mjs +2 -1
  23. package/dist/http/h3/index.d.mts +3 -3
  24. package/dist/http/h3/index.d.ts +3 -3
  25. package/dist/http/h3/index.js +18 -17
  26. package/dist/http/h3/index.mjs +2 -1
  27. package/dist/http/hono/index.d.mts +3 -3
  28. package/dist/http/hono/index.d.ts +3 -3
  29. package/dist/http/hono/index.js +15 -14
  30. package/dist/http/hono/index.mjs +2 -1
  31. package/dist/http/hyper-express/index.d.mts +3 -3
  32. package/dist/http/hyper-express/index.d.ts +3 -3
  33. package/dist/http/hyper-express/index.js +16 -15
  34. package/dist/http/hyper-express/index.mjs +2 -1
  35. package/dist/http/koa/index.d.mts +3 -3
  36. package/dist/http/koa/index.d.ts +3 -3
  37. package/dist/http/koa/index.js +17 -16
  38. package/dist/http/koa/index.mjs +2 -1
  39. package/dist/index.d.mts +8 -8
  40. package/dist/index.d.ts +8 -8
  41. package/dist/index.js +19 -19
  42. package/dist/index.mjs +1 -1
  43. package/dist/{meta-CR-D39hQ.d.mts → meta-xvg6V7pH.d.mts} +2 -19
  44. package/dist/{meta-CR-D39hQ.d.ts → meta-xvg6V7pH.d.ts} +2 -19
  45. package/dist/rpc/bullmq/index.d.mts +4 -6
  46. package/dist/rpc/bullmq/index.d.ts +4 -6
  47. package/dist/rpc/bullmq/index.js +7 -75
  48. package/dist/rpc/bullmq/index.mjs +3 -71
  49. package/dist/rpc/electron/index.d.mts +13 -0
  50. package/dist/rpc/electron/index.d.ts +13 -0
  51. package/dist/rpc/electron/index.js +72 -0
  52. package/dist/rpc/electron/index.mjs +72 -0
  53. package/dist/rpc/kafka/index.d.mts +4 -9
  54. package/dist/rpc/kafka/index.d.ts +4 -9
  55. package/dist/rpc/kafka/index.js +7 -86
  56. package/dist/rpc/kafka/index.mjs +3 -82
  57. package/dist/rpc/nats/index.d.mts +4 -6
  58. package/dist/rpc/nats/index.d.ts +4 -6
  59. package/dist/rpc/nats/index.js +7 -67
  60. package/dist/rpc/nats/index.mjs +2 -62
  61. package/dist/rpc/rabbitmq/index.d.mts +4 -6
  62. package/dist/rpc/rabbitmq/index.d.ts +4 -6
  63. package/dist/rpc/rabbitmq/index.js +7 -73
  64. package/dist/rpc/rabbitmq/index.mjs +3 -69
  65. package/dist/rpc/redis/index.d.mts +4 -9
  66. package/dist/rpc/redis/index.d.ts +4 -9
  67. package/dist/rpc/redis/index.js +7 -74
  68. package/dist/rpc/redis/index.mjs +3 -70
  69. package/dist/rpc/ws/index.d.mts +14 -0
  70. package/dist/rpc/ws/index.d.ts +14 -0
  71. package/dist/rpc/ws/index.js +73 -0
  72. package/dist/rpc/ws/index.mjs +73 -0
  73. package/dist/test.d.mts +7 -3
  74. package/dist/test.d.ts +7 -3
  75. package/dist/types-6qaaUIKZ.d.mts +14 -0
  76. package/dist/{types-BF1TDbFV.d.ts → types-B-1OL-3P.d.ts} +1 -1
  77. package/dist/types-BtXOT5rI.d.ts +14 -0
  78. package/dist/{types-DYviSl5B.d.mts → types-Ctd6pLNE.d.mts} +1 -1
  79. package/package.json +13 -2
  80. package/register/index.mjs +0 -1
  81. package/register/loader.mjs +12 -52
  82. package/register/utils.mjs +7 -7
  83. package/assets/ps.json +0 -24
  84. package/assets/tsconfig.json +0 -21
  85. package/dist/types-DYRu0vic.d.ts +0 -19
  86. package/dist/types-DqH1qA-q.d.mts +0 -19
@@ -0,0 +1,13 @@
1
+ import Electron from 'electron';
2
+ import { F as Factory } from '../../core-CDzIy2g0.js';
3
+ import { R as RpcCtx, a as RpcServerOptions } from '../../types-BtXOT5rI.js';
4
+ import 'phecda-core';
5
+ import '../../meta-xvg6V7pH.js';
6
+
7
+ interface ElectronCtx extends RpcCtx {
8
+ type: 'electron';
9
+ event: Electron.IpcMainEvent | Electron.IpcMainInvokeEvent;
10
+ }
11
+ declare function bind(IPC: Electron.IpcMain, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
12
+
13
+ export { type ElectronCtx, bind };
@@ -0,0 +1,72 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkIJFIY6QNjs = require('../../chunk-IJFIY6QN.js');
6
+
7
+
8
+ var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
9
+
10
+ // src/rpc/electron/bind.ts
11
+ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
12
+ var debug = _debug2.default.call(void 0, "phecda-server/electron");
13
+ function bind(IPC, { moduleMap, meta }, opts = {}) {
14
+ const { globalGuards, globalFilter, globalPipe, globalAddons = [] } = opts;
15
+ const metaMap = _chunkIJFIY6QNjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
16
+ const { controller, rpc, func, tag } = meta2.data;
17
+ if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
18
+ debug(`register method "${func}" in module "${tag}"`);
19
+ return true;
20
+ }
21
+ });
22
+ _chunkIJFIY6QNjs.detectAopDep.call(void 0, 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 = _chunkIJFIY6QNjs.Context.getAop(meta2, {
35
+ globalFilter,
36
+ globalGuards,
37
+ globalPipe
38
+ });
39
+ const context = new (0, _chunkIJFIY6QNjs.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
+ _chunk4LLLQOMFjs.__name.call(void 0, callback, "callback");
68
+ }
69
+ _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
70
+
71
+
72
+ exports.bind = bind;
@@ -0,0 +1,72 @@
1
+ import {
2
+ Context,
3
+ createControllerMetaMap,
4
+ detectAopDep
5
+ } from "../../chunk-VX4BZEL7.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-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 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-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 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,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
  var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
@@ -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 = _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
- _chunkG7JFKM2Mjs.Context.applyAddons(globalAddons, {
27
+ _chunkIJFIY6QNjs.Context.applyAddons(globalAddons, {
29
28
  consumer,
30
29
  producer
31
30
  }, "kafka");
@@ -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 = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
61
+ const aop = _chunkIJFIY6QNjs.Context.getAop(meta2, {
63
62
  globalFilter,
64
63
  globalGuards,
65
64
  globalPipe
66
65
  });
67
- const context = new (0, _chunkG7JFKM2Mjs.Context)({
66
+ const context = new (0, _chunkIJFIY6QNjs.Context)({
68
67
  type: "kafka",
69
68
  category: "rpc",
70
69
  moduleMap,
@@ -115,83 +114,5 @@ async function bind({ consumer, producer }, { moduleMap, meta }, opts = {}) {
115
114
  }
116
115
  _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
117
116
 
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 = _chunkG7JFKM2Mjs.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
- _chunk4LLLQOMFjs.__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__ */ _chunk4LLLQOMFjs.__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
- _chunk4LLLQOMFjs.__name.call(void 0, createClient, "createClient");
194
-
195
-
196
117
 
197
- exports.bind = bind; exports.createClient = createClient;
118
+ 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
  __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 };