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