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
@@ -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/redis");
15
14
  function bind({ sub, pub }, { 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, {
28
+ _chunkIJFIY6QNjs.Context.applyAddons(globalAddons, {
30
29
  pub,
31
30
  sub
32
31
  }, "redis");
@@ -55,12 +54,12 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
55
54
  if (_ps !== 1) return;
56
55
  const meta2 = metaMap.get(tag)[func];
57
56
  const { data: { rpc: { isEvent } = {} } } = meta2;
58
- const aop = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
57
+ const aop = _chunkIJFIY6QNjs.Context.getAop(meta2, {
59
58
  globalFilter,
60
59
  globalGuards,
61
60
  globalPipe
62
61
  });
63
- const context = new (0, _chunkG7JFKM2Mjs.Context)({
62
+ const context = new (0, _chunkIJFIY6QNjs.Context)({
64
63
  type: "redis",
65
64
  category: "rpc",
66
65
  moduleMap,
@@ -99,71 +98,5 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
99
98
  }
100
99
  _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
101
100
 
102
- // src/rpc/redis/client.ts
103
- var _events = require('events'); var _events2 = _interopRequireDefault(_events);
104
- async function createClient({ pub, sub }, controllers, opts) {
105
- const ret = {};
106
- let eventId = 1;
107
- let eventCount = 0;
108
- const emitter = new (0, _events2.default)();
109
- const clientQueue = _chunkG7JFKM2Mjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
110
- await sub.subscribe(clientQueue);
111
- for (const i in controllers) {
112
- ret[i] = new Proxy(new controllers[i](), {
113
- get(target, p) {
114
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
115
- let { tag, queue, isEvent } = target[p]();
116
- return async (...args) => {
117
- if (!queue) queue = tag;
118
- const id = `${eventId++}`;
119
- pub.publish(queue, JSON.stringify({
120
- _ps: 1,
121
- args,
122
- id,
123
- queue: clientQueue,
124
- tag,
125
- func: p
126
- }));
127
- if (isEvent) return null;
128
- return new Promise((resolve, reject) => {
129
- if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
130
- type: "exceeded"
131
- });
132
- let isEnd = false;
133
- const timer = setTimeout(() => {
134
- if (!isEnd) {
135
- eventCount--;
136
- emitter.off(id, listener);
137
- reject({
138
- type: "timeout"
139
- });
140
- }
141
- }, _optionalChain([opts, 'optionalAccess', _4 => _4.timeout]) || 5e3);
142
- function listener(data, error) {
143
- eventCount--;
144
- isEnd = true;
145
- clearTimeout(timer);
146
- if (error) reject(data);
147
- else resolve(data);
148
- }
149
- _chunk4LLLQOMFjs.__name.call(void 0, listener, "listener");
150
- eventCount++;
151
- emitter.once(id, listener);
152
- });
153
- };
154
- }
155
- });
156
- }
157
- sub.on("message", async (channel, msg) => {
158
- if (channel === clientQueue && msg) {
159
- const { data, id, error } = JSON.parse(msg);
160
- emitter.emit(id, data, error);
161
- }
162
- });
163
- return ret;
164
- }
165
- _chunk4LLLQOMFjs.__name.call(void 0, createClient, "createClient");
166
-
167
-
168
101
 
169
- exports.bind = bind; exports.createClient = createClient;
102
+ 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
@@ -98,72 +97,6 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
98
97
  });
99
98
  }
100
99
  __name(bind, "bind");
101
-
102
- // src/rpc/redis/client.ts
103
- import EventEmitter from "events";
104
- async function createClient({ pub, sub }, controllers, opts) {
105
- const ret = {};
106
- let eventId = 1;
107
- let eventCount = 0;
108
- const emitter = new EventEmitter();
109
- const clientQueue = genClientQueue(opts?.key);
110
- await sub.subscribe(clientQueue);
111
- for (const i in controllers) {
112
- ret[i] = new Proxy(new controllers[i](), {
113
- get(target, p) {
114
- if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
115
- let { tag, queue, isEvent } = target[p]();
116
- return async (...args) => {
117
- if (!queue) queue = tag;
118
- const id = `${eventId++}`;
119
- pub.publish(queue, JSON.stringify({
120
- _ps: 1,
121
- args,
122
- id,
123
- queue: clientQueue,
124
- tag,
125
- func: p
126
- }));
127
- if (isEvent) return null;
128
- return new Promise((resolve, reject) => {
129
- if (opts?.max && eventCount >= opts.max) reject({
130
- type: "exceeded"
131
- });
132
- let isEnd = false;
133
- const timer = setTimeout(() => {
134
- if (!isEnd) {
135
- eventCount--;
136
- emitter.off(id, listener);
137
- reject({
138
- type: "timeout"
139
- });
140
- }
141
- }, opts?.timeout || 5e3);
142
- function listener(data, error) {
143
- eventCount--;
144
- isEnd = true;
145
- clearTimeout(timer);
146
- if (error) reject(data);
147
- else resolve(data);
148
- }
149
- __name(listener, "listener");
150
- eventCount++;
151
- emitter.once(id, listener);
152
- });
153
- };
154
- }
155
- });
156
- }
157
- sub.on("message", async (channel, msg) => {
158
- if (channel === clientQueue && msg) {
159
- const { data, id, error } = JSON.parse(msg);
160
- emitter.emit(id, data, error);
161
- }
162
- });
163
- return ret;
164
- }
165
- __name(createClient, "createClient");
166
100
  export {
167
- bind,
168
- createClient
101
+ bind
169
102
  };
package/dist/test.d.mts CHANGED
@@ -2,9 +2,13 @@ import * as supertest from 'supertest';
2
2
  import { Test } from 'supertest';
3
3
  import { Server } from 'node:http';
4
4
  import { Construct } from 'phecda-core';
5
- import { F as Factory } from './core-DIfgUKIU.mjs';
6
- import { P as PickFunc } from './meta-CR-D39hQ.mjs';
5
+ import { F as Factory } from './core-jUg1HvYT.mjs';
6
+ import { e as CustomResponse } from './meta-xvg6V7pH.mjs';
7
7
 
8
+ type PickFuncKeys<Type> = {
9
+ [Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never;
10
+ }[keyof Type];
11
+ type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
8
12
  declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
9
13
  get<C extends T[number]>(Model: C): InstanceType<C>;
10
14
  }>;
@@ -15,4 +19,4 @@ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<Return
15
19
  module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
16
20
  }>;
17
21
 
18
- export { type SuperTestRequest, TestFactory, TestHttp };
22
+ export { type PickFunc, type SuperTestRequest, TestFactory, TestHttp };
package/dist/test.d.ts CHANGED
@@ -2,9 +2,13 @@ import * as supertest from 'supertest';
2
2
  import { Test } from 'supertest';
3
3
  import { Server } from 'node:http';
4
4
  import { Construct } from 'phecda-core';
5
- import { F as Factory } from './core-CUTbX_IS.js';
6
- import { P as PickFunc } from './meta-CR-D39hQ.js';
5
+ import { F as Factory } from './core-CDzIy2g0.js';
6
+ import { e as CustomResponse } from './meta-xvg6V7pH.js';
7
7
 
8
+ type PickFuncKeys<Type> = {
9
+ [Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never;
10
+ }[keyof Type];
11
+ type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
8
12
  declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
9
13
  get<C extends T[number]>(Model: C): InstanceType<C>;
10
14
  }>;
@@ -15,4 +19,4 @@ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<Return
15
19
  module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
16
20
  }>;
17
21
 
18
- export { type SuperTestRequest, TestFactory, TestHttp };
22
+ export { type PickFunc, type SuperTestRequest, TestFactory, TestHttp };
@@ -0,0 +1,14 @@
1
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.mjs';
2
+
3
+ interface RpcServerOptions extends DefaultOptions {
4
+ defaultQueue?: string;
5
+ }
6
+ interface RpcCtx extends BaseCtx {
7
+ args: any[];
8
+ id: string;
9
+ queue: string;
10
+ isEvent?: boolean;
11
+ category: 'rpc';
12
+ }
13
+
14
+ export type { RpcCtx as R, RpcServerOptions as a };
@@ -1,5 +1,5 @@
1
1
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.js';
2
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.js';
3
3
 
4
4
  interface HttpOptions extends DefaultOptions {
5
5
  /**
@@ -0,0 +1,14 @@
1
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.js';
2
+
3
+ interface RpcServerOptions extends DefaultOptions {
4
+ defaultQueue?: string;
5
+ }
6
+ interface RpcCtx extends BaseCtx {
7
+ args: any[];
8
+ id: string;
9
+ queue: string;
10
+ isEvent?: boolean;
11
+ category: 'rpc';
12
+ }
13
+
14
+ export type { RpcCtx as R, RpcServerOptions as a };
@@ -1,5 +1,5 @@
1
1
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.mjs';
2
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.mjs';
3
3
 
4
4
  interface HttpOptions extends DefaultOptions {
5
5
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "7.0.0-alpha.11",
3
+ "version": "7.0.0-alpha.12",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -180,7 +180,6 @@ export const resolve = async (specifier, context, nextResolve) => {
180
180
  // }
181
181
  // }
182
182
 
183
-
184
183
  // hmr import
185
184
  if (
186
185
  context.parentURL.includes('/node_modules/phecda-server')
@@ -236,7 +235,6 @@ export const resolve = async (specifier, context, nextResolve) => {
236
235
  }
237
236
  }
238
237
 
239
-
240
238
  const resolveRet = await nextResolve(specifier)
241
239
 
242
240
  // ts resolve fail in some cases
@@ -248,9 +246,6 @@ export const resolve = async (specifier, context, nextResolve) => {
248
246
  // @todo the first params may be url or path, need to distinguish
249
247
 
250
248
  export const load = async (url, context, nextLoad) => {
251
-
252
-
253
-
254
249
  if (config.virtualFile[url]) {
255
250
  return {
256
251
  format: 'module',
@@ -265,8 +260,6 @@ export const load = async (url, context, nextLoad) => {
265
260
  delete context.importAttributes.ps
266
261
  }
267
262
 
268
-
269
-
270
263
  url = url.split('?')[0]
271
264
  if (
272
265
  !url.includes('/node_modules/')
@@ -324,8 +317,6 @@ export const load = async (url, context, nextLoad) => {
324
317
  const compiled = (await compile(code, url)).replace(/_ts_metadata\(\"design:paramtypes\"\,/g, '_ts_metadata("design:paramtypes",()=>')// handle cycle
325
318
 
326
319
  if (unimportRet) {
327
-
328
-
329
320
  const { injectImports } = unimportRet
330
321
 
331
322
  return {
@@ -1,19 +0,0 @@
1
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.js';
2
-
3
- interface RpcServerOptions extends DefaultOptions {
4
- defaultQueue?: string;
5
- }
6
- interface RpcClientOptions {
7
- key?: string;
8
- timeout?: number;
9
- max?: number;
10
- }
11
- interface RpcCtx extends BaseCtx {
12
- args: any[];
13
- id: string;
14
- queue: string;
15
- isEvent?: boolean;
16
- category: 'rpc';
17
- }
18
-
19
- export type { RpcCtx as R, RpcServerOptions as a, RpcClientOptions as b };
@@ -1,19 +0,0 @@
1
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.mjs';
2
-
3
- interface RpcServerOptions extends DefaultOptions {
4
- defaultQueue?: string;
5
- }
6
- interface RpcClientOptions {
7
- key?: string;
8
- timeout?: number;
9
- max?: number;
10
- }
11
- interface RpcCtx extends BaseCtx {
12
- args: any[];
13
- id: string;
14
- queue: string;
15
- isEvent?: boolean;
16
- category: 'rpc';
17
- }
18
-
19
- export type { RpcCtx as R, RpcServerOptions as a, RpcClientOptions as b };