phecda-server 7.0.0-alpha.8 → 7.0.0
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/README.md +10 -10
- package/assets/schema.json +12 -9
- package/bin/cli.mjs +96 -37
- package/dist/chunk-5SUY5UVC.js +258 -0
- package/dist/chunk-5SUY5UVC.js.map +1 -0
- package/dist/chunk-6JAHCTOT.mjs +334 -0
- package/dist/chunk-6JAHCTOT.mjs.map +1 -0
- package/dist/{chunk-BBNJVYVX.js → chunk-EDAWJVJ4.js} +42 -25
- package/dist/chunk-EDAWJVJ4.js.map +1 -0
- package/dist/{chunk-7EMAZGYO.js → chunk-H7OCHDZT.js} +65 -95
- package/dist/chunk-H7OCHDZT.js.map +1 -0
- package/dist/{chunk-QJIAXSLZ.js → chunk-KRUOHWFR.js} +79 -68
- package/dist/chunk-KRUOHWFR.js.map +1 -0
- package/dist/chunk-KUGU3UGO.js +334 -0
- package/dist/chunk-KUGU3UGO.js.map +1 -0
- package/dist/{chunk-SGMQZRP6.mjs → chunk-LBH4RXQQ.mjs} +12 -42
- package/dist/chunk-LBH4RXQQ.mjs.map +1 -0
- package/dist/{chunk-YKP4ODZA.mjs → chunk-MDPW6WGF.mjs} +32 -6
- package/dist/chunk-MDPW6WGF.mjs.map +1 -0
- package/dist/{chunk-VSGYTGHY.js → chunk-RLFCI3RG.js} +31 -5
- package/dist/chunk-RLFCI3RG.js.map +1 -0
- package/dist/{chunk-7NWDKK7D.mjs → chunk-TTHYUNOT.mjs} +18 -1
- package/dist/chunk-TTHYUNOT.mjs.map +1 -0
- package/dist/chunk-VDOICQ2U.mjs +258 -0
- package/dist/chunk-VDOICQ2U.mjs.map +1 -0
- package/dist/{chunk-B45BN7LY.mjs → chunk-WTJKTICN.mjs} +65 -54
- package/dist/chunk-WTJKTICN.mjs.map +1 -0
- package/dist/{core-BGEsBtTG.d.ts → core-BOo3uGFX.d.ts} +5 -4
- package/dist/{core-BcKywWLd.d.mts → core-CF45G79J.d.mts} +5 -4
- package/dist/core-DbqWh47p.d.mts +50 -0
- package/dist/core-Rq7BhPHE.d.ts +50 -0
- package/dist/helper.d.mts +7 -8
- package/dist/helper.d.ts +7 -8
- package/dist/helper.js +5 -3
- package/dist/helper.js.map +1 -0
- package/dist/helper.mjs +9 -7
- package/dist/helper.mjs.map +1 -0
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +43 -45
- package/dist/http/elysia/index.js.map +1 -0
- package/dist/http/elysia/index.mjs +6 -8
- package/dist/http/elysia/index.mjs.map +1 -0
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +40 -42
- package/dist/http/express/index.js.map +1 -0
- package/dist/http/express/index.mjs +6 -8
- package/dist/http/express/index.mjs.map +1 -0
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +41 -43
- package/dist/http/fastify/index.js.map +1 -0
- package/dist/http/fastify/index.mjs +6 -8
- package/dist/http/fastify/index.mjs.map +1 -0
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +41 -43
- package/dist/http/h3/index.js.map +1 -0
- package/dist/http/h3/index.mjs +5 -7
- package/dist/http/h3/index.mjs.map +1 -0
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +37 -39
- package/dist/http/hono/index.js.map +1 -0
- package/dist/http/hono/index.mjs +5 -7
- package/dist/http/hono/index.mjs.map +1 -0
- 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 +38 -40
- package/dist/http/hyper-express/index.js.map +1 -0
- package/dist/http/hyper-express/index.mjs +5 -7
- package/dist/http/hyper-express/index.mjs.map +1 -0
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +40 -42
- package/dist/http/koa/index.js.map +1 -0
- package/dist/http/koa/index.mjs +6 -8
- package/dist/http/koa/index.mjs.map +1 -0
- package/dist/index.d.mts +76 -12
- package/dist/index.d.ts +76 -12
- package/dist/index.js +103 -49
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +68 -14
- package/dist/index.mjs.map +1 -0
- package/dist/{meta-B_HW7cWh.d.ts → meta-BoS1E-Nz.d.mts} +6 -24
- package/dist/{meta-B_HW7cWh.d.mts → meta-BoS1E-Nz.d.ts} +6 -24
- package/dist/rpc/bullmq/index.d.mts +4 -6
- package/dist/rpc/bullmq/index.d.ts +4 -6
- package/dist/rpc/bullmq/index.js +13 -80
- package/dist/rpc/bullmq/index.js.map +1 -0
- package/dist/rpc/bullmq/index.mjs +6 -73
- package/dist/rpc/bullmq/index.mjs.map +1 -0
- package/dist/rpc/electron/index.d.mts +13 -0
- package/dist/rpc/electron/index.d.ts +13 -0
- package/dist/rpc/electron/index.js +73 -0
- package/dist/rpc/electron/index.js.map +1 -0
- package/dist/rpc/electron/index.mjs +73 -0
- package/dist/rpc/electron/index.mjs.map +1 -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 +12 -90
- package/dist/rpc/kafka/index.js.map +1 -0
- package/dist/rpc/kafka/index.mjs +5 -83
- package/dist/rpc/kafka/index.mjs.map +1 -0
- package/dist/rpc/nats/index.d.mts +4 -6
- package/dist/rpc/nats/index.d.ts +4 -6
- package/dist/rpc/nats/index.js +13 -72
- package/dist/rpc/nats/index.js.map +1 -0
- package/dist/rpc/nats/index.mjs +5 -64
- package/dist/rpc/nats/index.mjs.map +1 -0
- package/dist/rpc/rabbitmq/index.d.mts +4 -6
- package/dist/rpc/rabbitmq/index.d.ts +4 -6
- package/dist/rpc/rabbitmq/index.js +14 -79
- package/dist/rpc/rabbitmq/index.js.map +1 -0
- package/dist/rpc/rabbitmq/index.mjs +6 -71
- package/dist/rpc/rabbitmq/index.mjs.map +1 -0
- package/dist/rpc/redis/index.d.mts +4 -9
- package/dist/rpc/redis/index.d.ts +4 -9
- package/dist/rpc/redis/index.js +12 -78
- package/dist/rpc/redis/index.js.map +1 -0
- package/dist/rpc/redis/index.mjs +6 -72
- package/dist/rpc/redis/index.mjs.map +1 -0
- 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.js.map +1 -0
- package/dist/rpc/web-ext/index.mjs +1 -0
- package/dist/rpc/web-ext/index.mjs.map +1 -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 +74 -0
- package/dist/rpc/ws/index.js.map +1 -0
- package/dist/rpc/ws/index.mjs +74 -0
- package/dist/rpc/ws/index.mjs.map +1 -0
- package/dist/test.d.mts +8 -4
- package/dist/test.d.ts +8 -4
- package/dist/test.js +7 -6
- package/dist/test.js.map +1 -0
- package/dist/test.mjs +3 -2
- package/dist/test.mjs.map +1 -0
- package/dist/types-CInz3bD0.d.ts +14 -0
- package/dist/types-E-rqlg3-.d.mts +14 -0
- package/dist/{types-C2SQ9U9V.d.mts → types-SCJZFCYt.d.mts} +1 -1
- package/dist/{types-PFPIQWVF.d.ts → types-xruyYmyu.d.ts} +1 -1
- package/package.json +24 -8
- package/register/export.mjs +30 -0
- package/register/index.mjs +20 -12
- package/register/loader.mjs +94 -116
- package/register/utils.mjs +36 -6
- package/assets/ps.json +0 -24
- package/assets/tsconfig.json +0 -21
- package/dist/types-CYF0vha6.d.ts +0 -19
- package/dist/types-DEQb_e59.d.mts +0 -19
package/dist/rpc/redis/index.js
CHANGED
|
@@ -2,31 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
var _chunkH7OCHDZTjs = require('../../chunk-H7OCHDZT.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
var _chunk7EMAZGYOjs = require('../../chunk-7EMAZGYO.js');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
var _chunkVSGYTGHYjs = require('../../chunk-VSGYTGHY.js');
|
|
9
|
+
var _chunkRLFCI3RGjs = require('../../chunk-RLFCI3RG.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 = _chunkH7OCHDZTjs.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
|
+
_chunkH7OCHDZTjs.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
|
+
_chunkH7OCHDZTjs.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
|
+
_chunkRLFCI3RGjs.__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 = _chunkH7OCHDZTjs.Context.getAop(meta2, {
|
|
59
58
|
globalFilter,
|
|
60
59
|
globalGuards,
|
|
61
60
|
globalPipe
|
|
62
61
|
});
|
|
63
|
-
const context = new (0,
|
|
62
|
+
const context = new (0, _chunkH7OCHDZTjs.Context)({
|
|
64
63
|
type: "redis",
|
|
65
64
|
category: "rpc",
|
|
66
65
|
moduleMap,
|
|
@@ -92,78 +91,13 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
93
|
subscribeQueues();
|
|
95
|
-
|
|
94
|
+
_chunkRLFCI3RGjs.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 = _chunk7EMAZGYOjs.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
|
-
_chunkVSGYTGHYjs.__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
|
-
_chunkVSGYTGHYjs.__name.call(void 0, createClient, "createClient");
|
|
166
|
-
|
|
99
|
+
_chunkRLFCI3RGjs.__name.call(void 0, bind, "bind");
|
|
167
100
|
|
|
168
101
|
|
|
169
|
-
exports.bind = bind;
|
|
102
|
+
exports.bind = bind;
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["d:\\myproject\\phecda\\packages\\server\\dist\\rpc\\redis\\index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,0DAAgC;AAChC;AACE;AACA;AACF,0DAAgC;AAChC;AACA;AACA,4EAAyB;AACzB,IAAI,MAAM,EAAE,6BAAK,qBAAsB,CAAC;AACxC,SAAS,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,IAAI;AAC1F,EAAE,MAAM,QAAQ,EAAE,sDAAuB,IAAK,EAAE,CAAC,KAAK,EAAE,GAAG;AAC3D,IAAI,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,IAAI;AACrD,IAAI,GAAG,CAAC,WAAW,IAAI,MAAM,mBAAG,GAAG,2BAAE,QAAM,IAAI,KAAK,CAAC,EAAE;AACvD,MAAM,KAAK,CAAC,CAAC,iBAAiB,EAAE,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3D,MAAM,OAAO,IAAI;AACjB,IAAI;AACJ,EAAE,CAAC,CAAC;AACJ,EAAE,2CAAY,IAAK,EAAE;AACrB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,IAAI,EAAE,UAAU;AAC1B,UAAU;AACV,QAAQ,CAAC,CAAC,CAAC;AACX,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG;AAClB,QAAQ,GAAG,CAAC,CAAC,OAAO,EAAE;AACtB,UAAU,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC;AAClD,YAAY,IAAI,EAAE,GAAG;AACrB,YAAY,KAAK,EAAE,IAAI;AACvB,YAAY;AACZ,UAAU,CAAC,CAAC,CAAC;AACb,QAAQ;AACR,MAAM,CAAC,CAAC;AACR,IAAI;AACJ,EAAE,CAAC,CAAC;AACJ,EAAE,eAAe,CAAC,CAAC;AACnB,EAAE,kCAAG,MAAO,CAAC,EAAE,GAAG;AAClB,IAAI,IAAI,CAAC,MAAM,MAAM,GAAG,UAAU,EAAE,MAAM,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;AAChE,IAAI,eAAe,CAAC,CAAC;AACrB,EAAE,CAAC,CAAC;AACJ;AACA,qCAAM,IAAK,EAAE,MAAM,CAAC;AACpB;AACE;AACF,oBAAC","file":"D:\\myproject\\phecda\\packages\\server\\dist\\rpc\\redis\\index.js","sourcesContent":[null]}
|
package/dist/rpc/redis/index.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
|
-
HMR,
|
|
4
3
|
createControllerMetaMap,
|
|
5
|
-
detectAopDep
|
|
6
|
-
|
|
7
|
-
} from "../../chunk-SGMQZRP6.mjs";
|
|
4
|
+
detectAopDep
|
|
5
|
+
} from "../../chunk-LBH4RXQQ.mjs";
|
|
8
6
|
import {
|
|
7
|
+
HMR,
|
|
9
8
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-MDPW6WGF.mjs";
|
|
11
10
|
|
|
12
11
|
// src/rpc/redis/bind.ts
|
|
13
12
|
import Debug from "debug";
|
|
@@ -98,72 +97,7 @@ 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
|
};
|
|
103
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rpc/redis/bind.ts"],"sourcesContent":["import type Redis from 'ioredis'\r\nimport Debug from 'debug'\r\nimport type { Factory } from '../../core'\r\nimport { Context } from '../../context'\r\nimport type { RpcCtx, RpcServerOptions } from '../types'\r\nimport { HMR } from '../../hmr'\r\nimport { createControllerMetaMap, detectAopDep } from '../../helper'\r\n\r\nconst debug = Debug('phecda-server/redis')\r\n\r\nexport interface RedisCtx extends RpcCtx {\r\n type: 'redis'\r\n redis: Redis\r\n msg: string\r\n channel: string\r\n\r\n}\r\n\r\nexport function bind({ sub, pub }: { sub: Redis; pub: Redis }, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts: RpcServerOptions = {}) {\r\n const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts\r\n const metaMap = createControllerMetaMap(meta, (meta) => {\r\n const { controller, rpc, func, tag } = meta.data\r\n if (controller === 'rpc' && rpc?.queue !== undefined) {\r\n debug(`register method \"${func}\" in module \"${tag}\"`)\r\n return true\r\n }\r\n })\r\n\r\n detectAopDep(meta, {\r\n guards: globalGuards,\r\n addons: globalAddons,\r\n }, 'rpc')\r\n\r\n const existQueue = new Set<string>()\r\n\r\n Context.applyAddons(globalAddons, { pub, sub }, 'redis')\r\n async function subscribeQueues() {\r\n existQueue.clear()\r\n\r\n for (const [tag, record] of metaMap) {\r\n for (const func in record) {\r\n const meta = metaMap.get(tag)![func]\r\n const {\r\n data: {\r\n rpc,\r\n },\r\n } = meta\r\n if (rpc) {\r\n const queue = rpc.queue || defaultQueue || tag\r\n\r\n if (existQueue.has(queue))\r\n continue\r\n existQueue.add(queue)\r\n await sub.subscribe(queue)\r\n }\r\n }\r\n }\r\n }\r\n\r\n sub.on('message', async (channel, msg) => {\r\n if (!existQueue.has(channel))\r\n return\r\n\r\n if (msg) {\r\n const data = JSON.parse(msg)\r\n const { func, id, tag, queue: clientQueue, _ps, args } = data\r\n debug(`invoke method \"${func}\" in module \"${tag}\"`)\r\n\r\n if (_ps !== 1)\r\n return\r\n const meta = metaMap.get(tag)![func]\r\n\r\n const {\r\n data: { rpc: { isEvent } = {} },\r\n } = meta\r\n\r\n const aop = Context.getAop(meta, {\r\n globalFilter,\r\n globalGuards,\r\n globalPipe,\r\n })\r\n const context = new Context(<RedisCtx>{\r\n type: 'redis',\r\n category: 'rpc',\r\n moduleMap,\r\n redis: sub,\r\n meta,\r\n msg,\r\n channel,\r\n tag,\r\n func,\r\n args,\r\n id,\r\n isEvent,\r\n queue: channel,\r\n\r\n })\r\n await context.run(aop, (returnData) => {\r\n if (!isEvent)\r\n pub.publish(clientQueue, JSON.stringify({ data: returnData, id }))\r\n }, (err) => {\r\n if (!isEvent) {\r\n pub.publish(clientQueue, JSON.stringify({\r\n data: err,\r\n error: true,\r\n id,\r\n }))\r\n }\r\n })\r\n }\r\n })\r\n\r\n subscribeQueues()\r\n HMR(async () => {\r\n for (const queue of existQueue)\r\n await sub.unsubscribe(queue)\r\n\r\n subscribeQueues()\r\n })\r\n}\r\n"],"mappings":";;;;;;;;;;;AACA,OAAOA,WAAW;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B,KAAKE,OAAOsB,aAAaC,KAAKC,KAAI,IAAKzB;AACzDnB,YAAM,kBAAkBiB,IAAAA,gBAAoBC,GAAAA,GAAM;AAElD,UAAIyB,QAAQ,EACV;AACF,YAAMrC,QAAOO,QAAQmB,IAAId,GAAAA,EAAMD,IAAAA;AAE/B,YAAM,EACJE,MAAM,EAAEH,KAAK,EAAE6B,QAAO,IAAK,CAAC,EAAC,EAAE,IAC7BvC;AAEJ,YAAMwC,MAAMnB,QAAQoB,OAAOzC,OAAM;QAC/BG;QACAD;QACAE;MACF,CAAA;AACA,YAAMsC,UAAU,IAAIrB,QAAkB;QACpCsB,MAAM;QACNC,UAAU;QACV7C;QACA8C,OAAOhD;QACPG,MAAAA;QACAgC;QACAD;QACAnB;QACAD;QACA2B;QACAH;QACAI;QACAzB,OAAOiB;MAET,CAAA;AACA,YAAMW,QAAQI,IAAIN,KAAK,CAACO,eAAAA;AACtB,YAAI,CAACR,QACHzC,KAAIkD,QAAQZ,aAAaH,KAAKgB,UAAU;UAAEpC,MAAMkC;UAAYZ;QAAG,CAAA,CAAA;MACnE,GAAG,CAACe,QAAAA;AACF,YAAI,CAACX,SAAS;AACZzC,cAAIkD,QAAQZ,aAAaH,KAAKgB,UAAU;YACtCpC,MAAMqC;YACNC,OAAO;YACPhB;UACF,CAAA,CAAA;QACF;MACF,CAAA;IACF;EACF,CAAA;AAEAZ,kBAAAA;AACA6B,MAAI,YAAA;AACF,eAAWtC,SAASK,WAClB,OAAMtB,IAAIwD,YAAYvC,KAAAA;AAExBS,oBAAAA;EACF,CAAA;AACF;AArGgB3B;","names":["Debug","debug","Debug","bind","sub","pub","moduleMap","meta","opts","globalGuards","globalFilter","globalPipe","globalAddons","defaultQueue","metaMap","createControllerMetaMap","controller","rpc","func","tag","data","queue","undefined","detectAopDep","guards","addons","existQueue","Set","Context","applyAddons","subscribeQueues","clear","record","get","has","add","subscribe","on","channel","msg","JSON","parse","id","clientQueue","_ps","args","isEvent","aop","getAop","context","type","category","redis","run","returnData","publish","stringify","err","error","HMR","unsubscribe"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["d:\\myproject\\phecda\\packages\\server\\dist\\rpc\\web-ext\\index.js"],"names":[],"mappings":"AAAA","file":"D:\\myproject\\phecda\\packages\\server\\dist\\rpc\\web-ext\\index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -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,74 @@
|
|
|
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 _chunkH7OCHDZTjs = require('../../chunk-H7OCHDZT.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkRLFCI3RGjs = require('../../chunk-RLFCI3RG.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 = _chunkH7OCHDZTjs.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
|
+
_chunkH7OCHDZTjs.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 = _chunkH7OCHDZTjs.Context.getAop(meta2, {
|
|
36
|
+
globalFilter,
|
|
37
|
+
globalGuards,
|
|
38
|
+
globalPipe
|
|
39
|
+
});
|
|
40
|
+
const context = new (0, _chunkH7OCHDZTjs.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
|
+
_chunkRLFCI3RGjs.__name.call(void 0, bind, "bind");
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
exports.bind = bind;
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["d:\\myproject\\phec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,EAAE;AACnB,UAAU,CAAC,CAAC,CAAC;AACb,QAAQ,CAAC,CAAC;AACV,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE;AAClB,MAAM;AACN,IAAI,CAAC,CAAC;AACN,EAAE,CAAC,CAAC;AACJ;AACA,qCAAM,IAAK,EAAE,MAAM,CAAC;AACpB;AACE;AACF,oBAAC","file":"D:\\myproject\\phecda\\packages\\server\\dist\\rpc\\ws\\index.js","sourcesContent":[null]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Context,
|
|
3
|
+
createControllerMetaMap,
|
|
4
|
+
detectAopDep
|
|
5
|
+
} from "../../chunk-LBH4RXQQ.mjs";
|
|
6
|
+
import {
|
|
7
|
+
__name
|
|
8
|
+
} from "../../chunk-MDPW6WGF.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
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rpc/ws/bind.ts"],"sourcesContent":["import type WS from 'ws'\r\nimport Debug from 'debug'\r\n\r\nimport { createControllerMetaMap, detectAopDep } from '../../helper'\r\nimport { Factory } from '../../core'\r\nimport { Context } from '../../context'\r\nimport { RpcCtx, RpcServerOptions } from '../types'\r\nconst debug = Debug('phecda-server/ws')\r\n\r\nexport interface WsCtx extends RpcCtx {\r\n type: 'ws'\r\n ws: WS\r\n wss: WS.Server\r\n}\r\n\r\nexport function bind(wss: WS.Server, data: Awaited<ReturnType<typeof Factory>>, opts: RpcServerOptions = {}) {\r\n const { globalGuards, globalAddons, globalFilter, globalPipe } = opts\r\n const { moduleMap, meta } = data\r\n\r\n const metaMap = createControllerMetaMap(meta, (meta) => {\r\n const { controller, rpc, func, tag } = meta.data\r\n if (controller === 'rpc' && rpc?.queue !== undefined) {\r\n debug(`register method \"${func}\" in module \"${tag}\"`)\r\n return true\r\n }\r\n })\r\n\r\n detectAopDep(meta, {\r\n guards: globalGuards,\r\n addons: globalAddons,\r\n }, 'rpc')\r\n\r\n wss.on('connection', (ws) => {\r\n ws.on('message', async (raw) => {\r\n try {\r\n const data = JSON.parse(raw.toString())\r\n const { func, id, tag, _ps, args, queue } = data\r\n\r\n if (_ps !== 1)\r\n return\r\n\r\n const meta = metaMap.get(tag)![func]\r\n\r\n const {\r\n data: { rpc: { isEvent } = {} },\r\n } = meta\r\n\r\n const aop = Context.getAop(meta, {\r\n globalFilter,\r\n globalGuards,\r\n globalPipe,\r\n })\r\n\r\n const context = new Context<WsCtx>({\r\n type: 'ws' as const,\r\n category: 'rpc' as const,\r\n meta,\r\n moduleMap,\r\n tag,\r\n func,\r\n args,\r\n id,\r\n queue,\r\n wss,\r\n ws,\r\n })\r\n\r\n return await context.run(aop, (returnData) => {\r\n if (!isEvent)\r\n ws.send(JSON.stringify({ id, data: returnData }))\r\n }, (err) => {\r\n if (!isEvent)\r\n\r\n ws.send(JSON.stringify({ id, data: err, error: true }))\r\n })\r\n }\r\n catch (e) {\r\n // not a phecda-client request\r\n }\r\n })\r\n })\r\n}\r\n"],"mappings":";;;;;;;;;;AACA,OAAOA,WAAW;AAMlB,IAAMC,QAAQC,MAAM,kBAAA;AAQb,SAASC,KAAKC,KAAgBC,MAA2CC,OAAyB,CAAC,GAAC;AACzG,QAAM,EAAEC,cAAcC,cAAcC,cAAcC,WAAU,IAAKJ;AACjE,QAAM,EAAEK,WAAWC,KAAI,IAAKP;AAE5B,QAAMQ,UAAUC,wBAAwBF,MAAM,CAACA,UAAAA;AAC7C,UAAM,EAAEG,YA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","globalGuards","globalAddons","globalFilter","globalPipe","moduleMap","meta","metaMap","createControllerMetaMap","controller","rpc","func","tag","queue","undefined","detectAopDep","guards","addons","on","ws","raw","JSON","parse","toString","id","_ps","args","get","isEvent","aop","Context","getAop","context","type","category","run","returnData","send","stringify","err","error","e"]}
|
package/dist/test.d.mts
CHANGED
|
@@ -2,17 +2,21 @@ 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-DbqWh47p.mjs';
|
|
6
|
+
import { C as CustomResponse } from './meta-BoS1E-Nz.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
|
}>;
|
|
11
15
|
type SuperTestRequest<T> = {
|
|
12
16
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
17
|
};
|
|
14
|
-
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "
|
|
18
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "set" | "key" | "use" | "on" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
|
|
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,17 +2,21 @@ 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-Rq7BhPHE.js';
|
|
6
|
+
import { C as CustomResponse } from './meta-BoS1E-Nz.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
|
}>;
|
|
11
15
|
type SuperTestRequest<T> = {
|
|
12
16
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
17
|
};
|
|
14
|
-
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "
|
|
18
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "set" | "key" | "use" | "on" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
|
|
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.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkKRUOHWFRjs = require('./chunk-KRUOHWFR.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkRLFCI3RGjs = require('./chunk-RLFCI3RG.js');
|
|
7
7
|
|
|
8
8
|
// src/test.ts
|
|
9
9
|
var _phecdacore = require('phecda-core');
|
|
10
10
|
async function TestFactory(...Modules) {
|
|
11
|
-
const { moduleMap, modelMap } = await
|
|
11
|
+
const { moduleMap, modelMap } = await _chunkKRUOHWFRjs.Factory.call(void 0, Modules);
|
|
12
12
|
return {
|
|
13
13
|
get(Model) {
|
|
14
14
|
const tag = _phecdacore.getTag.call(void 0, Model);
|
|
@@ -19,7 +19,7 @@ async function TestFactory(...Modules) {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
_chunkRLFCI3RGjs.__name.call(void 0, TestFactory, "TestFactory");
|
|
23
23
|
async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
24
24
|
const { default: request, agent } = await Promise.resolve().then(() => _interopRequireWildcard(require("supertest")));
|
|
25
25
|
const Agent = agent(app);
|
|
@@ -59,12 +59,13 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
_chunkRLFCI3RGjs.__name.call(void 0, module, "module");
|
|
63
63
|
Agent.module = module;
|
|
64
64
|
return Agent;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
_chunkRLFCI3RGjs.__name.call(void 0, TestHttp, "TestHttp");
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
exports.TestFactory = TestFactory; exports.TestHttp = TestHttp;
|
|
71
|
+
//# sourceMappingURL=test.js.map
|
package/dist/test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["d:\\myproject\\phecda\\packages\\server\\dist\\test.js"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;AACA,yCAAoC;AACpC,MAAM,SAAS,WAAW,CAAC,GAAG,OAAO,EAAE;AACvC,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,MAAM,sCAAO,OAAQ,CAAC;AACxD,EAAE,OAAO;AACT,IAAI,GAAG,CAAC,KAAK,EAAE;AACf,MAAM,MAAM,IAAI,EAAE,gCAAM,KAAM,CAAC;AAC/B,MAAM,MAAM,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;AACvC,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC;AAC3E,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,KAAK,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,oC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,IAAI,CAAC,IAAI;AAChC,YAAY,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC;AAC9C,UAAU,CAAC;AACX,UAAU,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,GAAG;AACxC,YAAY,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,QAAQ,EAAE;AACxC,cAAc,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;AACA,cAAA;AACA,YAAA;AACA,YAAA;AACA,cAAA;AACA,cAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA","file":"D:\\myproject\\phecda\\packages\\server\\dist\\test.js","sourcesContent":[null]}
|
package/dist/test.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Factory
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WTJKTICN.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MDPW6WGF.mjs";
|
|
7
7
|
|
|
8
8
|
// src/test.ts
|
|
9
9
|
import { getTag } from "phecda-core";
|
|
@@ -68,3 +68,4 @@ export {
|
|
|
68
68
|
TestFactory,
|
|
69
69
|
TestHttp
|
|
70
70
|
};
|
|
71
|
+
//# sourceMappingURL=test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/test.ts"],"sourcesContent":["import type { Server } from 'node:http'\r\nimport type { SuperAgentTest, Test } from 'supertest'\r\nimport { type Construct, getTag } from 'phecda-core'\r\nimport { Factory } from './core'\r\n\r\nimport type { ControllerMeta } from './meta'\r\nimport { CustomResponse } from './types'\r\n\r\ntype PickFuncKeys<Type> = { [Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never }[keyof Type]\r\nexport type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>\r\nexport async function TestFactory<T extends Construct[]>(...Modules: T) {\r\n const { moduleMap, modelMap } = await Factory(Modules)\r\n\r\n return {\r\n get<C extends T[number]>(Model: C): InstanceType<C> {\r\n const tag = getTag(Model)\r\n const module = moduleMap.get(tag)\r\n\r\n if (!module)\r\n throw new Error(`module \"${String(tag)}\" doesn't exist`)\r\n\r\n if (modelMap.get(module) !== Model)\r\n throw new Error(`module \"${Model.name}\" and \"${String(tag)}\" in modulemap are different modules`)\r\n\r\n return module\r\n },\r\n }\r\n}\r\n\r\nexport type SuperTestRequest<T> = {\r\n [K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;\r\n}\r\n\r\nexport async function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent = true) {\r\n const { default: request, agent } = await import('supertest')\r\n const Agent = agent(app) as SuperAgentTest & { module: typeof module }\r\n\r\n function module<T extends Construct>(Module: T): SuperTestRequest<PickFunc<InstanceType<T>>> {\r\n const tag = getTag(Module)\r\n\r\n const module = moduleMap.get(tag)\r\n if (!module)\r\n throw new Error(`module \"${String(tag)}\" doesn't exist`)\r\n\r\n return new Proxy({}, {\r\n get(_target, p) {\r\n const { data } = (meta as ControllerMeta[]).find(({ data }) => data.name === Module.name && data.func === p && data.tag === tag)!\r\n return (...args: any) => {\r\n const ret = { body: {}, headers: {}, query: {}, func: data.http!.type, url: data.http!.prefix + data.http!.route } as any\r\n\r\n data.params.forEach((item) => {\r\n if (item.type === 'params') {\r\n ret.url = ret.url.replace(`:${item.key}`, args[item.index])\r\n return\r\n }\r\n if (item.type === 'query') {\r\n ret.query[item.key] = args[item.index]\r\n return\r\n }\r\n\r\n // body\r\n if (item.key)\r\n ret[item.type][item.key] = args[item.index]\r\n else\r\n ret[item.type] = args[item.index]\r\n })\r\n // @ts-expect-error @todo miss type\r\n let agent = (isAgent ? Agent : request(app))[ret.func](ret.url)\r\n if (Object.keys(ret.query).length > 0)\r\n agent = agent.query(ret.query)\r\n\r\n if (Object.keys(ret.headers).length > 0)\r\n agent = agent.set(ret.headers)\r\n\r\n if (Object.keys(ret.body).length > 0)\r\n agent = agent.send(ret.body)\r\n\r\n return agent\r\n }\r\n },\r\n }) as any\r\n }\r\n\r\n Agent.module = module\r\n\r\n return Agent\r\n}\r\n"],"mappings":";;;;;;;;AAEA,SAAyBA,cAAc;AAQvC,eAAsBC,eAAsCC,SAAU;AACpE,QAAM,EAAEC,WAAWC,SAAQ,IAAK,MAAMC,QAAQH,OAAAA;AAE9C,SAAO;IACLI,IAAyBC,OAAQ;AAC/B,YAAMC,MAAMC,OAAOF,KAAAA;AACnB,YAAMG,SAASP,UAAUG,IAAIE,GAAAA;AAE7B,UAAI,CAACE,OACH,OAAM,IAAIC,MAAM,WAAWC,OAAOJ,GAAAA,CAAAA,iBAAqB;AAEzD,UAAIJ,SAASE,IAAII,MAAAA,MAAYH,MAC3B,OAAM,IAAII,MAAM,WAAWJ,MAAMM,IAAI,UAAUD,OAAOJ,GAAAA,CAAAA,sCAA0C;AAElG,aAAOE;IACT;EACF;AACF;AAjBsBT;AAuBtB,eAAsBa,SAASC,KAAmB,EAAEZ,WAAWa,KAAI,GAAyCC,UAAU,MAAI;AACxH,QAAM,EAAEC,SAASC,SAASC,MAAK,IAAK,MAAM,OAAO,WAAA;AACjD,QAAMC,QAAQD,MAAML,GAAAA;AAEpB,WAASL,OAA4BY,QAAS;AAC5C,UAAMd,MAAMC,OAAOa,MAAAA;AAEnB,UAAMZ,UAASP,UAAUG,IAAIE,GAAAA;AAC7B,QAAI,CAACE,QACH,OAAM,IAA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/B,cAAIa,OAAOC,KAAKhB,IAAIC,IAAI,EAAEgB,SAAS,EACjC3B,CAAAA,SAAQA,OAAM6B,KAAKnB,IAAIC,IAAI;AAE7B,iBAAOX;QACT;MACF;IACF,CAAA;EACF;AA5CSV;AA8CTW,QAAMX,SAASA;AAEf,SAAOW;AACT;AArDsBP;","names":["getTag","TestFactory","Modules","moduleMap","modelMap","Factory","get","Model","tag","getTag","module","Error","String","name","TestHttp","app","meta","isAgent","default","request","agent","Agent","Module","Proxy","_target","p","data","find","func","args","ret","body","headers","query","http","type","url","prefix","route","params","forEach","item","replace","key","index","Object","keys","length","set","send"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { B as BaseCtx, D as DefaultOptions } from './meta-BoS1E-Nz.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 };
|