phecda-server 7.0.0-alpha.9 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/schema.json +12 -9
- package/bin/cli.mjs +95 -36
- package/dist/{chunk-5RBTN33A.js → chunk-4LLLQOMF.js} +10 -5
- package/dist/{chunk-7ZGYJ5OW.mjs → chunk-AIAO6SV6.mjs} +10 -34
- package/dist/{chunk-V5EYXVJT.js → chunk-DPPDWBYO.js} +53 -25
- package/dist/{chunk-CVPZWDXU.mjs → chunk-E7EAPAGM.mjs} +10 -20
- package/dist/{chunk-ODVWOXVB.mjs → chunk-MKRHYZCL.mjs} +30 -2
- package/dist/{chunk-FXTJ3BJ6.mjs → chunk-NQ55PA2X.mjs} +9 -4
- package/dist/{chunk-FX3LDQII.js → chunk-XKK2SQ7W.js} +60 -70
- package/dist/{chunk-KJUD2BKE.js → chunk-ZWPOWMZP.js} +25 -49
- package/dist/{core-D_cz0tKa.d.ts → core-DbqWh47p.d.mts} +3 -2
- package/dist/{core-BDkhrEyf.d.mts → core-Rq7BhPHE.d.ts} +3 -2
- package/dist/helper.d.mts +3 -5
- package/dist/helper.d.ts +3 -5
- package/dist/helper.js +3 -5
- package/dist/helper.mjs +2 -4
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +41 -40
- package/dist/http/elysia/index.mjs +4 -3
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +38 -37
- package/dist/http/express/index.mjs +3 -2
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +39 -38
- package/dist/http/fastify/index.mjs +4 -3
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +39 -38
- package/dist/http/h3/index.mjs +3 -2
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +35 -34
- package/dist/http/hono/index.mjs +3 -2
- 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 +36 -35
- package/dist/http/hyper-express/index.mjs +3 -2
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +38 -37
- package/dist/http/koa/index.mjs +3 -2
- package/dist/index.d.mts +76 -12
- package/dist/index.d.ts +76 -12
- package/dist/index.js +102 -49
- package/dist/index.mjs +66 -13
- package/dist/{meta-BX5jhe4Z.d.mts → meta-BoS1E-Nz.d.mts} +6 -23
- package/dist/{meta-BX5jhe4Z.d.ts → meta-BoS1E-Nz.d.ts} +6 -23
- package/dist/rpc/bullmq/index.d.mts +4 -6
- package/dist/rpc/bullmq/index.d.ts +4 -6
- package/dist/rpc/bullmq/index.js +12 -80
- package/dist/rpc/bullmq/index.mjs +4 -72
- 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 +11 -90
- package/dist/rpc/kafka/index.mjs +4 -83
- package/dist/rpc/nats/index.d.mts +4 -6
- package/dist/rpc/nats/index.d.ts +4 -6
- package/dist/rpc/nats/index.js +12 -72
- package/dist/rpc/nats/index.mjs +3 -63
- package/dist/rpc/rabbitmq/index.d.mts +4 -6
- package/dist/rpc/rabbitmq/index.d.ts +4 -6
- package/dist/rpc/rabbitmq/index.js +13 -79
- package/dist/rpc/rabbitmq/index.mjs +4 -70
- package/dist/rpc/redis/index.d.mts +4 -9
- package/dist/rpc/redis/index.d.ts +4 -9
- package/dist/rpc/redis/index.js +11 -78
- package/dist/rpc/redis/index.mjs +4 -71
- package/dist/rpc/web-ext/index.d.mts +2 -0
- package/dist/rpc/web-ext/index.d.ts +2 -0
- package/dist/rpc/web-ext/index.js +1 -0
- package/dist/rpc/web-ext/index.mjs +0 -0
- 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/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/types-CInz3bD0.d.ts +14 -0
- package/dist/types-E-rqlg3-.d.mts +14 -0
- package/dist/{types-DKVhyZk_.d.mts → types-SCJZFCYt.d.mts} +1 -1
- package/dist/{types-CMeuFoyd.d.ts → types-xruyYmyu.d.ts} +1 -1
- package/package.json +24 -8
- package/register/export.mjs +30 -0
- package/register/index.mjs +2 -3
- package/register/loader.mjs +83 -90
- package/register/utils.mjs +36 -6
- package/assets/ps.json +0 -24
- package/assets/tsconfig.json +0 -21
- package/dist/types-B-rUM9Fm.d.mts +0 -19
- package/dist/types-MxxtkZXw.d.ts +0 -19
|
@@ -2,31 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
var _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.js');
|
|
5
6
|
|
|
6
|
-
var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
|
|
9
|
+
var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
|
|
11
10
|
|
|
12
11
|
// src/rpc/rabbitmq/bind.ts
|
|
13
12
|
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 = _chunkXKK2SQ7Wjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
18
17
|
const { controller, rpc, func, tag } = meta2.data;
|
|
19
18
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
20
19
|
debug(`register method "${func}" in module "${tag}"`);
|
|
21
20
|
return true;
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
|
-
|
|
23
|
+
_chunkXKK2SQ7Wjs.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
|
+
_chunkXKK2SQ7Wjs.Context.applyAddons(globalAddons, ch, "rabbitmq");
|
|
30
29
|
async function subscribeQueues() {
|
|
31
30
|
existQueue.clear();
|
|
32
31
|
for (const [tag, record] of metaMap) {
|
|
@@ -45,12 +44,12 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
_chunk4LLLQOMFjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
49
48
|
async function handleRequest(msg) {
|
|
50
49
|
function send(queue, data) {
|
|
51
50
|
ch.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
_chunk4LLLQOMFjs.__name.call(void 0, send, "send");
|
|
54
53
|
if (msg) {
|
|
55
54
|
const data = JSON.parse(msg.content.toString());
|
|
56
55
|
const { tag, func, id, queue: clientQueue, _ps, args } = data;
|
|
@@ -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 = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
|
|
62
61
|
globalFilter,
|
|
63
62
|
globalGuards,
|
|
64
63
|
globalPipe
|
|
65
64
|
});
|
|
66
|
-
const context = new (0,
|
|
65
|
+
const context = new (0, _chunkXKK2SQ7Wjs.Context)({
|
|
67
66
|
type: "rabbitmq",
|
|
68
67
|
category: "rpc",
|
|
69
68
|
moduleMap,
|
|
@@ -91,79 +90,14 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
|
|
|
91
90
|
});
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
|
-
|
|
93
|
+
_chunk4LLLQOMFjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
95
94
|
subscribeQueues();
|
|
96
|
-
|
|
95
|
+
_chunk4LLLQOMFjs.HMR.call(void 0, async () => {
|
|
97
96
|
for (const queue of existQueue) await ch.deleteQueue(queue);
|
|
98
97
|
await subscribeQueues();
|
|
99
98
|
});
|
|
100
99
|
}
|
|
101
|
-
|
|
102
|
-
|
|
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 = _chunkFX3LDQIIjs.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
|
-
_chunk5RBTN33Ajs.__name.call(void 0, listener, "listener");
|
|
156
|
-
eventCount++;
|
|
157
|
-
emitter.once(id, listener);
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
return ret;
|
|
164
|
-
}
|
|
165
|
-
_chunk5RBTN33Ajs.__name.call(void 0, createClient, "createClient");
|
|
166
|
-
|
|
100
|
+
_chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
|
|
167
101
|
|
|
168
102
|
|
|
169
|
-
exports.bind = bind;
|
|
103
|
+
exports.bind = bind;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
3
|
createControllerMetaMap,
|
|
4
|
-
detectAopDep
|
|
5
|
-
|
|
6
|
-
} from "../../chunk-CVPZWDXU.mjs";
|
|
4
|
+
detectAopDep
|
|
5
|
+
} from "../../chunk-E7EAPAGM.mjs";
|
|
7
6
|
import {
|
|
8
7
|
HMR,
|
|
9
8
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-NQ55PA2X.mjs";
|
|
11
10
|
|
|
12
11
|
// src/rpc/rabbitmq/bind.ts
|
|
13
12
|
import Debug from "debug";
|
|
@@ -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-BX5jhe4Z.mjs';
|
|
2
|
+
import { F as Factory } from '../../core-DbqWh47p.mjs';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
|
|
5
4
|
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.mjs';
|
|
6
6
|
|
|
7
7
|
interface 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-BX5jhe4Z.js';
|
|
2
|
+
import { F as Factory } from '../../core-Rq7BhPHE.js';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
|
|
5
4
|
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.js';
|
|
6
6
|
|
|
7
7
|
interface 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,31 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
var _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.js');
|
|
5
6
|
|
|
6
|
-
var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
|
|
9
|
+
var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
|
|
11
10
|
|
|
12
11
|
// src/rpc/redis/bind.ts
|
|
13
12
|
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 = _chunkXKK2SQ7Wjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
18
17
|
const { controller, rpc, func, tag } = meta2.data;
|
|
19
18
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
20
19
|
debug(`register method "${func}" in module "${tag}"`);
|
|
21
20
|
return true;
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
|
-
|
|
23
|
+
_chunkXKK2SQ7Wjs.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
|
+
_chunkXKK2SQ7Wjs.Context.applyAddons(globalAddons, {
|
|
30
29
|
pub,
|
|
31
30
|
sub
|
|
32
31
|
}, "redis");
|
|
@@ -45,7 +44,7 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
_chunk4LLLQOMFjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
49
48
|
sub.on("message", async (channel, msg) => {
|
|
50
49
|
if (!existQueue.has(channel)) return;
|
|
51
50
|
if (msg) {
|
|
@@ -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 = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
|
|
59
58
|
globalFilter,
|
|
60
59
|
globalGuards,
|
|
61
60
|
globalPipe
|
|
62
61
|
});
|
|
63
|
-
const context = new (0,
|
|
62
|
+
const context = new (0, _chunkXKK2SQ7Wjs.Context)({
|
|
64
63
|
type: "redis",
|
|
65
64
|
category: "rpc",
|
|
66
65
|
moduleMap,
|
|
@@ -92,78 +91,12 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
93
|
subscribeQueues();
|
|
95
|
-
|
|
94
|
+
_chunk4LLLQOMFjs.HMR.call(void 0, async () => {
|
|
96
95
|
for (const queue of existQueue) await sub.unsubscribe(queue);
|
|
97
96
|
subscribeQueues();
|
|
98
97
|
});
|
|
99
98
|
}
|
|
100
|
-
|
|
101
|
-
|
|
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 = _chunkFX3LDQIIjs.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
|
-
_chunk5RBTN33Ajs.__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
|
-
_chunk5RBTN33Ajs.__name.call(void 0, createClient, "createClient");
|
|
166
|
-
|
|
99
|
+
_chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
|
|
167
100
|
|
|
168
101
|
|
|
169
|
-
exports.bind = bind;
|
|
102
|
+
exports.bind = bind;
|
package/dist/rpc/redis/index.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
3
|
createControllerMetaMap,
|
|
4
|
-
detectAopDep
|
|
5
|
-
|
|
6
|
-
} from "../../chunk-CVPZWDXU.mjs";
|
|
4
|
+
detectAopDep
|
|
5
|
+
} from "../../chunk-E7EAPAGM.mjs";
|
|
7
6
|
import {
|
|
8
7
|
HMR,
|
|
9
8
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-NQ55PA2X.mjs";
|
|
11
10
|
|
|
12
11
|
// src/rpc/redis/bind.ts
|
|
13
12
|
import Debug from "debug";
|
|
@@ -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 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import WS from 'ws';
|
|
2
|
+
import { F as Factory } from '../../core-DbqWh47p.mjs';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
|
|
4
|
+
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.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-Rq7BhPHE.js';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
|
|
4
|
+
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.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 _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.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 = _chunkXKK2SQ7Wjs.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
|
+
_chunkXKK2SQ7Wjs.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 = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
|
|
36
|
+
globalFilter,
|
|
37
|
+
globalGuards,
|
|
38
|
+
globalPipe
|
|
39
|
+
});
|
|
40
|
+
const context = new (0, _chunkXKK2SQ7Wjs.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;
|