phecda-server 5.0.2 → 5.1.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 (57) hide show
  1. package/README.md +4 -102
  2. package/bin/cli.mjs +17 -14
  3. package/dist/{chunk-RCTOVYZY.mjs → chunk-2HKQPZDT.mjs} +1 -1
  4. package/dist/{chunk-BXLBWRHS.js → chunk-3BV2GRS7.js} +38 -38
  5. package/dist/{chunk-AB4OX3WV.mjs → chunk-665MB62T.mjs} +127 -99
  6. package/dist/{chunk-YERBWZCS.js → chunk-FSBD5R22.js} +180 -152
  7. package/dist/{chunk-F5YWXY5W.js → chunk-HMPTPTFL.js} +17 -17
  8. package/dist/{chunk-W5EOVGQD.mjs → chunk-UU6RHGRF.mjs} +2 -2
  9. package/dist/{chunk-ITTD2GBR.mjs → chunk-VLV3AO3H.mjs} +7 -19
  10. package/dist/{chunk-YR5Q5F2K.js → chunk-ZP7HNASU.js} +7 -19
  11. package/dist/{core-fd134ffa.d.ts → core-39f27fe8.d.ts} +4 -3
  12. package/dist/{helper-73e8d2f0.d.ts → helper-6133f78f.d.ts} +1 -1
  13. package/dist/{helper-f29f082f.d.ts → helper-fcbf6aa8.d.ts} +4 -3
  14. package/dist/index.d.ts +27 -32
  15. package/dist/index.js +44 -40
  16. package/dist/index.mjs +14 -10
  17. package/dist/rpc/bullmq/index.d.ts +10 -6
  18. package/dist/rpc/bullmq/index.js +32 -53
  19. package/dist/rpc/bullmq/index.mjs +26 -47
  20. package/dist/rpc/kafka/index.d.ts +10 -4
  21. package/dist/rpc/kafka/index.js +20 -37
  22. package/dist/rpc/kafka/index.mjs +15 -32
  23. package/dist/rpc/nats/index.d.ts +2 -2
  24. package/dist/rpc/nats/index.js +20 -34
  25. package/dist/rpc/nats/index.mjs +13 -27
  26. package/dist/rpc/rabbitmq/index.d.ts +2 -2
  27. package/dist/rpc/rabbitmq/index.js +23 -37
  28. package/dist/rpc/rabbitmq/index.mjs +14 -28
  29. package/dist/rpc/redis/index.d.ts +10 -4
  30. package/dist/rpc/redis/index.js +23 -37
  31. package/dist/rpc/redis/index.mjs +16 -30
  32. package/dist/server/elysia/index.d.ts +4 -3
  33. package/dist/server/elysia/index.js +77 -94
  34. package/dist/server/elysia/index.mjs +74 -91
  35. package/dist/server/express/index.d.ts +5 -4
  36. package/dist/server/express/index.js +79 -93
  37. package/dist/server/express/index.mjs +77 -91
  38. package/dist/server/fastify/index.d.ts +8 -5
  39. package/dist/server/fastify/index.js +83 -102
  40. package/dist/server/fastify/index.mjs +79 -98
  41. package/dist/server/h3/index.d.ts +5 -4
  42. package/dist/server/h3/index.js +81 -97
  43. package/dist/server/h3/index.mjs +80 -96
  44. package/dist/server/hono/index.d.ts +5 -4
  45. package/dist/server/hono/index.js +73 -90
  46. package/dist/server/hono/index.mjs +72 -89
  47. package/dist/server/hyper-express/index.d.ts +6 -5
  48. package/dist/server/hyper-express/index.js +78 -96
  49. package/dist/server/hyper-express/index.mjs +77 -95
  50. package/dist/server/koa/index.d.ts +5 -4
  51. package/dist/server/koa/index.js +79 -92
  52. package/dist/server/koa/index.mjs +76 -89
  53. package/dist/test.d.ts +1 -1
  54. package/dist/test.js +6 -6
  55. package/dist/test.mjs +2 -2
  56. package/package.json +9 -8
  57. package/register/loader.mjs +19 -5
@@ -3,33 +3,29 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
7
6
 
7
+ var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
8
8
 
9
- var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
9
+
10
+ var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
10
11
 
11
12
  // src/rpc/rabbitmq/bind.ts
12
13
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
13
14
  var debug = _debug2.default.call(void 0, "phecda-server/rabbitmq");
14
15
  async function bind(ch, { moduleMap, meta }, opts = {}) {
15
16
  const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
16
- const metaMap = /* @__PURE__ */ new Map();
17
- const existQueue = /* @__PURE__ */ new Set();
18
- function handleMeta() {
19
- metaMap.clear();
20
- for (const item of meta) {
21
- const { tag, func, controller, rpc } = item.data;
22
- if (controller !== "rpc" || _optionalChain([rpc, 'optionalAccess', _ => _.queue]) === void 0)
23
- continue;
24
- if (metaMap.has(tag))
25
- metaMap.get(tag)[func] = item;
26
- else
27
- metaMap.set(tag, {
28
- [func]: item
29
- });
17
+ const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
18
+ const { controller, rpc, func, tag } = meta2.data;
19
+ if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
20
+ debug(`register method "${func}" in module "${tag}"`);
21
+ return true;
30
22
  }
31
- }
32
- _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
23
+ });
24
+ _chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
25
+ guards: globalGuards,
26
+ interceptors: globalInterceptors
27
+ }, "rpc");
28
+ const existQueue = /* @__PURE__ */ new Set();
33
29
  async function subscribeQueues() {
34
30
  existQueue.clear();
35
31
  for (const [tag, record] of metaMap) {
@@ -49,12 +45,12 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
49
45
  }
50
46
  }
51
47
  }
52
- _chunkYR5Q5F2Kjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
48
+ _chunkZP7HNASUjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
53
49
  async function handleRequest(msg) {
54
50
  function send(queue, data) {
55
51
  ch.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
56
52
  }
57
- _chunkYR5Q5F2Kjs.__name.call(void 0, send, "send");
53
+ _chunkZP7HNASUjs.__name.call(void 0, send, "send");
58
54
  if (msg) {
59
55
  const data = JSON.parse(msg.content.toString());
60
56
  const { tag, func, id, queue: clientQueue, _ps, args } = data;
@@ -63,7 +59,7 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
63
59
  debug(`invoke method "${func}" in module "${tag}"`);
64
60
  const meta2 = metaMap.get(tag)[func];
65
61
  const { data: { rpc: { isEvent } = {} } } = meta2;
66
- const context = new (0, _chunkYERBWZCSjs.Context)({
62
+ const context = new (0, _chunkFSBD5R22js.Context)({
67
63
  type: "rabbitmq",
68
64
  moduleMap,
69
65
  meta: meta2,
@@ -97,25 +93,15 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
97
93
  });
98
94
  }
99
95
  }
100
- _chunkYR5Q5F2Kjs.__name.call(void 0, handleRequest, "handleRequest");
101
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
102
- guards: globalGuards,
103
- interceptors: globalInterceptors
104
- }, "rpc");
105
- handleMeta();
96
+ _chunkZP7HNASUjs.__name.call(void 0, handleRequest, "handleRequest");
106
97
  subscribeQueues();
107
- _chunkYERBWZCSjs.HMR.call(void 0, async () => {
108
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
109
- guards: globalGuards,
110
- interceptors: globalInterceptors
111
- }, "rpc");
112
- handleMeta();
98
+ _chunkFSBD5R22js.HMR.call(void 0, async () => {
113
99
  for (const queue of existQueue)
114
100
  await ch.deleteQueue(queue);
115
101
  await subscribeQueues();
116
102
  });
117
103
  }
118
- _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
104
+ _chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
119
105
 
120
106
  // src/rpc/rabbitmq/client.ts
121
107
  var _events = require('events');
@@ -124,7 +110,7 @@ async function createClient(ch, controllers, opts) {
124
110
  let eventCount = 0;
125
111
  const ret = {};
126
112
  const emitter = new (0, _events.EventEmitter)();
127
- const clientQueue = _chunkYERBWZCSjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
113
+ const clientQueue = _chunkFSBD5R22js.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
128
114
  await ch.assertQueue(clientQueue);
129
115
  ch.consume(clientQueue, (msg) => {
130
116
  if (!msg)
@@ -176,7 +162,7 @@ async function createClient(ch, controllers, opts) {
176
162
  else
177
163
  resolve(data);
178
164
  }
179
- _chunkYR5Q5F2Kjs.__name.call(void 0, listener, "listener");
165
+ _chunkZP7HNASUjs.__name.call(void 0, listener, "listener");
180
166
  eventCount++;
181
167
  emitter.once(id, listener);
182
168
  });
@@ -186,7 +172,7 @@ async function createClient(ch, controllers, opts) {
186
172
  }
187
173
  return ret;
188
174
  }
189
- _chunkYR5Q5F2Kjs.__name.call(void 0, createClient, "createClient");
175
+ _chunkZP7HNASUjs.__name.call(void 0, createClient, "createClient");
190
176
 
191
177
 
192
178
 
@@ -1,35 +1,31 @@
1
1
  import {
2
2
  Context,
3
3
  HMR,
4
+ createControllerMetaMap,
4
5
  detectAopDep,
5
6
  genClientQueue
6
- } from "../../chunk-AB4OX3WV.mjs";
7
+ } from "../../chunk-665MB62T.mjs";
7
8
  import {
8
9
  __name
9
- } from "../../chunk-ITTD2GBR.mjs";
10
+ } from "../../chunk-VLV3AO3H.mjs";
10
11
 
11
12
  // src/rpc/rabbitmq/bind.ts
12
13
  import Debug from "debug";
13
14
  var debug = Debug("phecda-server/rabbitmq");
14
15
  async function bind(ch, { moduleMap, meta }, opts = {}) {
15
16
  const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
16
- const metaMap = /* @__PURE__ */ new Map();
17
- const existQueue = /* @__PURE__ */ new Set();
18
- function handleMeta() {
19
- metaMap.clear();
20
- for (const item of meta) {
21
- const { tag, func, controller, rpc } = item.data;
22
- if (controller !== "rpc" || rpc?.queue === void 0)
23
- continue;
24
- if (metaMap.has(tag))
25
- metaMap.get(tag)[func] = item;
26
- else
27
- metaMap.set(tag, {
28
- [func]: item
29
- });
17
+ const metaMap = createControllerMetaMap(meta, (meta2) => {
18
+ const { controller, rpc, func, tag } = meta2.data;
19
+ if (controller === "rpc" && rpc?.queue !== void 0) {
20
+ debug(`register method "${func}" in module "${tag}"`);
21
+ return true;
30
22
  }
31
- }
32
- __name(handleMeta, "handleMeta");
23
+ });
24
+ detectAopDep(meta, {
25
+ guards: globalGuards,
26
+ interceptors: globalInterceptors
27
+ }, "rpc");
28
+ const existQueue = /* @__PURE__ */ new Set();
33
29
  async function subscribeQueues() {
34
30
  existQueue.clear();
35
31
  for (const [tag, record] of metaMap) {
@@ -98,18 +94,8 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
98
94
  }
99
95
  }
100
96
  __name(handleRequest, "handleRequest");
101
- detectAopDep(meta, {
102
- guards: globalGuards,
103
- interceptors: globalInterceptors
104
- }, "rpc");
105
- handleMeta();
106
97
  subscribeQueues();
107
98
  HMR(async () => {
108
- detectAopDep(meta, {
109
- guards: globalGuards,
110
- interceptors: globalInterceptors
111
- }, "rpc");
112
- handleMeta();
113
99
  for (const queue of existQueue)
114
100
  await ch.deleteQueue(queue);
115
101
  await subscribeQueues();
@@ -1,6 +1,6 @@
1
1
  import Redis from 'ioredis';
2
- import { F as Factory, T as ToClientMap } from '../../core-fd134ffa.js';
3
- import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../helper-73e8d2f0.js';
2
+ import { F as Factory, T as ToClientMap } from '../../core-39f27fe8.js';
3
+ import { b as RpcContext, R as RpcServerOptions, a as RpcClientOptions } from '../../helper-6133f78f.js';
4
4
  import 'phecda-core';
5
5
 
6
6
  interface RedisCtx extends RpcContext {
@@ -9,8 +9,14 @@ interface RedisCtx extends RpcContext {
9
9
  msg: string;
10
10
  channel: string;
11
11
  }
12
- declare function bind(sub: Redis, pub: Redis, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
12
+ declare function bind({ sub, pub }: {
13
+ sub: Redis;
14
+ pub: Redis;
15
+ }, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
13
16
 
14
- declare function createClient<S extends Record<string, any>>(pub: Redis, sub: Redis, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
17
+ declare function createClient<S extends Record<string, any>>({ pub, sub }: {
18
+ pub: Redis;
19
+ sub: Redis;
20
+ }, controllers: S, opts?: RpcClientOptions): Promise<ToClientMap<S>>;
15
21
 
16
22
  export { RedisCtx, bind, createClient };
@@ -3,33 +3,29 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
7
6
 
7
+ var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
8
8
 
9
- var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
9
+
10
+ var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
10
11
 
11
12
  // src/rpc/redis/bind.ts
12
13
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
13
14
  var debug = _debug2.default.call(void 0, "phecda-server/redis");
14
- function bind(sub, pub, { moduleMap, meta }, opts = {}) {
15
+ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
15
16
  const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
16
- const metaMap = /* @__PURE__ */ new Map();
17
- const existQueue = /* @__PURE__ */ new Set();
18
- function handleMeta() {
19
- metaMap.clear();
20
- for (const item of meta) {
21
- const { tag, func, controller, rpc } = item.data;
22
- if (controller !== "rpc" || _optionalChain([rpc, 'optionalAccess', _ => _.queue]) === void 0)
23
- continue;
24
- if (metaMap.has(tag))
25
- metaMap.get(tag)[func] = item;
26
- else
27
- metaMap.set(tag, {
28
- [func]: item
29
- });
17
+ const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
18
+ const { controller, rpc, func, tag } = meta2.data;
19
+ if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
20
+ debug(`register method "${func}" in module "${tag}"`);
21
+ return true;
30
22
  }
31
- }
32
- _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
23
+ });
24
+ _chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
25
+ guards: globalGuards,
26
+ interceptors: globalInterceptors
27
+ }, "rpc");
28
+ const existQueue = /* @__PURE__ */ new Set();
33
29
  async function subscribeQueues() {
34
30
  existQueue.clear();
35
31
  for (const [tag, record] of metaMap) {
@@ -46,7 +42,7 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
46
42
  }
47
43
  }
48
44
  }
49
- _chunkYR5Q5F2Kjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
45
+ _chunkZP7HNASUjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
50
46
  sub.on("message", async (channel, msg) => {
51
47
  if (!existQueue.has(channel))
52
48
  return;
@@ -58,7 +54,7 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
58
54
  return;
59
55
  const meta2 = metaMap.get(tag)[func];
60
56
  const { data: { rpc: { isEvent } = {} } } = meta2;
61
- const context = new (0, _chunkYERBWZCSjs.Context)({
57
+ const context = new (0, _chunkFSBD5R22js.Context)({
62
58
  type: "redis",
63
59
  moduleMap,
64
60
  redis: sub,
@@ -94,33 +90,23 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
94
90
  });
95
91
  }
96
92
  });
97
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
98
- guards: globalGuards,
99
- interceptors: globalInterceptors
100
- }, "rpc");
101
- handleMeta();
102
93
  subscribeQueues();
103
- _chunkYERBWZCSjs.HMR.call(void 0, async () => {
104
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
105
- guards: globalGuards,
106
- interceptors: globalInterceptors
107
- }, "rpc");
108
- handleMeta();
94
+ _chunkFSBD5R22js.HMR.call(void 0, async () => {
109
95
  for (const queue of existQueue)
110
96
  await sub.unsubscribe(queue);
111
97
  subscribeQueues();
112
98
  });
113
99
  }
114
- _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
100
+ _chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
115
101
 
116
102
  // src/rpc/redis/client.ts
117
103
  var _events = require('events'); var _events2 = _interopRequireDefault(_events);
118
- async function createClient(pub, sub, controllers, opts) {
104
+ async function createClient({ pub, sub }, controllers, opts) {
119
105
  const ret = {};
120
106
  let eventId = 1;
121
107
  let eventCount = 0;
122
108
  const emitter = new (0, _events2.default)();
123
- const clientQueue = _chunkYERBWZCSjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
109
+ const clientQueue = _chunkFSBD5R22js.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
124
110
  await sub.subscribe(clientQueue);
125
111
  for (const i in controllers) {
126
112
  ret[i] = new Proxy(new controllers[i](), {
@@ -166,7 +152,7 @@ async function createClient(pub, sub, controllers, opts) {
166
152
  else
167
153
  resolve(data);
168
154
  }
169
- _chunkYR5Q5F2Kjs.__name.call(void 0, listener, "listener");
155
+ _chunkZP7HNASUjs.__name.call(void 0, listener, "listener");
170
156
  eventCount++;
171
157
  emitter.once(id, listener);
172
158
  });
@@ -182,7 +168,7 @@ async function createClient(pub, sub, controllers, opts) {
182
168
  });
183
169
  return ret;
184
170
  }
185
- _chunkYR5Q5F2Kjs.__name.call(void 0, createClient, "createClient");
171
+ _chunkZP7HNASUjs.__name.call(void 0, createClient, "createClient");
186
172
 
187
173
 
188
174
 
@@ -1,35 +1,31 @@
1
1
  import {
2
2
  Context,
3
3
  HMR,
4
+ createControllerMetaMap,
4
5
  detectAopDep,
5
6
  genClientQueue
6
- } from "../../chunk-AB4OX3WV.mjs";
7
+ } from "../../chunk-665MB62T.mjs";
7
8
  import {
8
9
  __name
9
- } from "../../chunk-ITTD2GBR.mjs";
10
+ } from "../../chunk-VLV3AO3H.mjs";
10
11
 
11
12
  // src/rpc/redis/bind.ts
12
13
  import Debug from "debug";
13
14
  var debug = Debug("phecda-server/redis");
14
- function bind(sub, pub, { moduleMap, meta }, opts = {}) {
15
+ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
15
16
  const { globalGuards, globalInterceptors, globalFilter, globalPipe } = opts;
16
- const metaMap = /* @__PURE__ */ new Map();
17
- const existQueue = /* @__PURE__ */ new Set();
18
- function handleMeta() {
19
- metaMap.clear();
20
- for (const item of meta) {
21
- const { tag, func, controller, rpc } = item.data;
22
- if (controller !== "rpc" || rpc?.queue === void 0)
23
- continue;
24
- if (metaMap.has(tag))
25
- metaMap.get(tag)[func] = item;
26
- else
27
- metaMap.set(tag, {
28
- [func]: item
29
- });
17
+ const metaMap = createControllerMetaMap(meta, (meta2) => {
18
+ const { controller, rpc, func, tag } = meta2.data;
19
+ if (controller === "rpc" && rpc?.queue !== void 0) {
20
+ debug(`register method "${func}" in module "${tag}"`);
21
+ return true;
30
22
  }
31
- }
32
- __name(handleMeta, "handleMeta");
23
+ });
24
+ detectAopDep(meta, {
25
+ guards: globalGuards,
26
+ interceptors: globalInterceptors
27
+ }, "rpc");
28
+ const existQueue = /* @__PURE__ */ new Set();
33
29
  async function subscribeQueues() {
34
30
  existQueue.clear();
35
31
  for (const [tag, record] of metaMap) {
@@ -94,18 +90,8 @@ function bind(sub, pub, { moduleMap, meta }, opts = {}) {
94
90
  });
95
91
  }
96
92
  });
97
- detectAopDep(meta, {
98
- guards: globalGuards,
99
- interceptors: globalInterceptors
100
- }, "rpc");
101
- handleMeta();
102
93
  subscribeQueues();
103
94
  HMR(async () => {
104
- detectAopDep(meta, {
105
- guards: globalGuards,
106
- interceptors: globalInterceptors
107
- }, "rpc");
108
- handleMeta();
109
95
  for (const queue of existQueue)
110
96
  await sub.unsubscribe(queue);
111
97
  subscribeQueues();
@@ -115,7 +101,7 @@ __name(bind, "bind");
115
101
 
116
102
  // src/rpc/redis/client.ts
117
103
  import EventEmitter from "events";
118
- async function createClient(pub, sub, controllers, opts) {
104
+ async function createClient({ pub, sub }, controllers, opts) {
119
105
  const ret = {};
120
106
  let eventId = 1;
121
107
  let eventCount = 0;
@@ -1,7 +1,7 @@
1
1
  import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
2
2
  import { BaseMacro } from 'elysia/dist/types';
3
- import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
4
- import { F as Factory } from '../../core-fd134ffa.js';
3
+ import { a as HttpContext, H as HttpOptions } from '../../helper-fcbf6aa8.js';
4
+ import { F as Factory } from '../../core-39f27fe8.js';
5
5
  import 'node:http';
6
6
  import 'phecda-core';
7
7
 
@@ -10,7 +10,8 @@ interface ElysiaCtx extends HttpContext {
10
10
  app: Elysia$1;
11
11
  context: Context;
12
12
  }
13
+ type Plugin = (app: Elysia$1<any>) => void;
13
14
  declare function bind(app: Elysia$1<any>, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
14
15
  declare function Elysia(opts: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>): any;
15
16
 
16
- export { Elysia, ElysiaCtx, bind };
17
+ export { Elysia, ElysiaCtx, Plugin, bind };
@@ -1,105 +1,103 @@
1
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
2
 
3
- var _chunkBXLBWRHSjs = require('../../chunk-BXLBWRHS.js');
3
+ var _chunk3BV2GRS7js = require('../../chunk-3BV2GRS7.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
10
+ var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
11
11
 
12
12
 
13
- var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
13
+ var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
14
14
 
15
15
  // src/server/elysia/bind.ts
16
16
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
17
  var _elysia = require('elysia');
18
18
  var debug = _debug2.default.call(void 0, "phecda-server/elysia");
19
19
  function bind(app, data, opts = {}) {
20
- const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
21
- route: "/__PHECDA_SERVER__",
22
- plugins: [],
23
- ...opts
24
- };
20
+ const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
25
21
  const { moduleMap, meta } = data;
26
- const metaMap = /* @__PURE__ */ new Map();
27
- function handleMeta() {
28
- metaMap.clear();
29
- for (const item of meta) {
30
- const { tag, func, controller, http } = item.data;
31
- if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
32
- continue;
22
+ const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
23
+ const { controller, http, func, tag } = meta2.data;
24
+ if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
33
25
  debug(`register method "${func}" in module "${tag}"`);
34
- if (metaMap.has(tag))
35
- metaMap.get(tag)[func] = item;
36
- else
37
- metaMap.set(tag, {
38
- [func]: item
39
- });
26
+ return true;
40
27
  }
41
- }
42
- _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
43
- async function createRoute() {
28
+ });
29
+ _chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
30
+ plugins: [
31
+ ...globalPlugins,
32
+ ...parallelPlugins
33
+ ],
34
+ guards: globalGuards,
35
+ interceptors: globalInterceptors
36
+ });
37
+ registerRoute();
38
+ async function registerRoute() {
39
+ _chunkFSBD5R22js.Context.usePlugin(globalPlugins, "elysia").forEach((p) => p(app));
44
40
  const parallelRouter = new (0, _elysia.Elysia)();
45
- _chunkYERBWZCSjs.Context.usePlugin(plugins).forEach((p) => p(parallelRouter));
46
- parallelRouter.post(route, async (c) => {
47
- const { body } = c;
48
- async function errorHandler(e) {
49
- const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
50
- c.set.status = error.status;
51
- return error;
52
- }
53
- _chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
54
- if (!Array.isArray(body))
55
- return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
56
- try {
57
- return Promise.all(body.map((item, i) => {
58
- return new Promise(async (resolve) => {
59
- const { tag, func } = item;
60
- debug(`(parallel)invoke method "${func}" in module "${tag}"`);
61
- if (!metaMap.has(tag))
62
- return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
63
- const meta2 = metaMap.get(tag)[func];
64
- if (!meta2)
65
- return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
66
- const { data: { params } } = meta2;
67
- const contextData = {
68
- type: "elysia",
69
- parallel: true,
70
- context: c,
71
- index: i,
72
- meta: meta2,
73
- moduleMap,
74
- tag,
75
- func,
76
- app,
77
- ..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, c.headers)
78
- };
79
- const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
80
- context.run({
81
- globalGuards,
82
- globalInterceptors,
83
- globalFilter,
84
- globalPipe
85
- }, resolve, resolve);
41
+ _chunkFSBD5R22js.Context.usePlugin(parallelPlugins, "elysia").forEach((p) => p(parallelRouter));
42
+ if (parallelRoute) {
43
+ parallelRouter.post(parallelRoute, async (c) => {
44
+ const { body } = c;
45
+ async function errorHandler(e) {
46
+ const error = await _chunkFSBD5R22js.Context.filterRecord.default(e);
47
+ c.set.status = error.status;
48
+ return error;
49
+ }
50
+ _chunkZP7HNASUjs.__name.call(void 0, errorHandler, "errorHandler");
51
+ if (!Array.isArray(body))
52
+ return errorHandler(new (0, _chunkFSBD5R22js.BadRequestException)("data format should be an array"));
53
+ try {
54
+ return Promise.all(body.map((item, i) => {
55
+ return new Promise(async (resolve) => {
56
+ const { tag, func } = item;
57
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
58
+ if (!metaMap.has(tag))
59
+ return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`module "${tag}" doesn't exist`)));
60
+ const meta2 = metaMap.get(tag)[func];
61
+ if (!meta2)
62
+ return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
63
+ const { data: { params } } = meta2;
64
+ const contextData = {
65
+ type: "elysia",
66
+ parallel: true,
67
+ context: c,
68
+ index: i,
69
+ meta: meta2,
70
+ moduleMap,
71
+ tag,
72
+ func,
73
+ app,
74
+ ..._chunkFSBD5R22js.argToReq.call(void 0, params, item.args, c.headers)
75
+ };
76
+ const context = new (0, _chunkFSBD5R22js.Context)(contextData);
77
+ context.run({
78
+ globalGuards,
79
+ globalInterceptors,
80
+ globalFilter,
81
+ globalPipe
82
+ }, resolve, resolve);
83
+ });
84
+ })).then((ret) => {
85
+ return ret;
86
86
  });
87
- })).then((ret) => {
88
- return ret;
89
- });
90
- } catch (e) {
91
- return errorHandler(e);
92
- }
93
- });
87
+ } catch (e) {
88
+ return errorHandler(e);
89
+ }
90
+ });
91
+ }
94
92
  app.use(parallelRouter);
95
93
  for (const [tag, record] of metaMap) {
96
94
  for (const func in record) {
97
95
  const meta2 = metaMap.get(tag)[func];
98
- const { data: { define, plugins: plugins2, http } } = meta2;
96
+ const { data: { define, plugins, http } } = meta2;
99
97
  const funcRouter = new (0, _elysia.Elysia)();
100
98
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
101
99
  continue;
102
- _chunkYERBWZCSjs.Context.usePlugin(plugins2).forEach((p) => p(funcRouter));
100
+ _chunkFSBD5R22js.Context.usePlugin(plugins, "elysia").forEach((p) => p(funcRouter));
103
101
  funcRouter[http.type](http.prefix + http.route, async (c) => {
104
102
  debug(`invoke method "${func}" in module "${tag}"`);
105
103
  const contextData = {
@@ -115,7 +113,7 @@ function bind(app, data, opts = {}) {
115
113
  headers: c.headers,
116
114
  app
117
115
  };
118
- const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
116
+ const context = new (0, _chunkFSBD5R22js.Context)(contextData);
119
117
  if (http.headers)
120
118
  c.set.headers = http.headers;
121
119
  return context.run({
@@ -132,28 +130,13 @@ function bind(app, data, opts = {}) {
132
130
  }
133
131
  }
134
132
  }
135
- _chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
136
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
137
- plugins,
138
- guards: globalGuards,
139
- interceptors: globalInterceptors
140
- });
141
- handleMeta();
142
- createRoute();
143
- _chunkYERBWZCSjs.HMR.call(void 0, async () => {
144
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
145
- plugins,
146
- guards: globalGuards,
147
- interceptors: globalInterceptors
148
- });
149
- handleMeta();
150
- });
133
+ _chunkZP7HNASUjs.__name.call(void 0, registerRoute, "registerRoute");
151
134
  }
152
- _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
135
+ _chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
153
136
  function Elysia(opts) {
154
- return _chunkBXLBWRHSjs.Define.call(void 0, "elysia", opts);
137
+ return _chunk3BV2GRS7js.Define.call(void 0, "elysia", opts);
155
138
  }
156
- _chunkYR5Q5F2Kjs.__name.call(void 0, Elysia, "Elysia");
139
+ _chunkZP7HNASUjs.__name.call(void 0, Elysia, "Elysia");
157
140
 
158
141
 
159
142