wenay-common2 1.0.61 → 1.0.63
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 +8 -8
- package/lib/Common/Observe/index.d.ts +5 -0
- package/lib/Common/{ObserveAll2 → Observe}/index.js +3 -1
- package/lib/Common/Observe/reactive.d.ts +21 -0
- package/lib/Common/{ObserveAll2/reactive2.js → Observe/reactive.js} +7 -7
- package/lib/Common/Observe/reactive2.d.ts +1 -0
- package/lib/Common/{events/Listen2.js → Observe/reactive2.js} +1 -1
- package/lib/Common/Observe/store-manager.d.ts +123 -0
- package/lib/Common/Observe/store-manager.js +227 -0
- package/lib/Common/Observe/store-offline.d.ts +88 -0
- package/lib/Common/Observe/store-offline.js +278 -0
- package/lib/Common/{ObserveAll2 → Observe}/store-replay.d.ts +9 -38
- package/lib/Common/{ObserveAll2 → Observe}/store-replay.js +1 -1
- package/lib/Common/{ObserveAll2 → Observe}/store.d.ts +3 -3
- package/lib/Common/{ObserveAll2 → Observe}/store.js +25 -31
- package/lib/Common/async/promiseProgress.d.ts +12 -0
- package/lib/Common/async/promiseProgress.js +29 -0
- package/lib/Common/events/Listen.d.ts +129 -1
- package/lib/Common/events/Listen.js +243 -15
- package/lib/Common/events/Listen3.d.ts +1 -210
- package/lib/Common/events/Listen3.js +15 -253
- package/lib/Common/events/SocketBuffer.d.ts +13 -33
- package/lib/Common/events/SocketBuffer.js +8 -8
- package/lib/Common/events/SocketServerHook.d.ts +5 -45
- package/lib/Common/events/SocketServerHook.js +1 -1
- package/lib/Common/events/joinListens.d.ts +6 -7
- package/lib/Common/events/joinListens.js +3 -4
- package/lib/Common/events/mapListen.d.ts +4 -0
- package/lib/Common/events/mapListen.js +25 -0
- package/lib/Common/events/replay-conflate.d.ts +2 -22
- package/lib/Common/events/replay-conflate.js +5 -5
- package/lib/Common/events/replay-history.d.ts +1 -1
- package/lib/Common/events/replay-listen.d.ts +20 -66
- package/lib/Common/events/replay-listen.js +10 -13
- package/lib/Common/events/replay-wire.d.ts +1 -1
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.d.ts +3 -3
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.js +10 -10
- package/lib/Common/rcp/listen-deep.d.ts +10 -10
- package/lib/Common/rcp/listen-deep.js +1 -1
- package/lib/Common/rcp/listen-socket.d.ts +13 -13
- package/lib/Common/rcp/listen-socket.js +4 -3
- package/lib/Common/rcp/rpc-client-auto.d.ts +2 -2
- package/lib/Common/rcp/rpc-client-auto.js +3 -2
- package/lib/Common/rcp/rpc-client.js +6 -4
- package/lib/Common/rcp/rpc-index.d.ts +2 -1
- package/lib/Common/rcp/rpc-index.js +3 -2
- package/lib/Common/rcp/rpc-path.d.ts +1 -0
- package/lib/Common/rcp/rpc-path.js +6 -0
- package/lib/Common/rcp/rpc-server-auto.d.ts +2 -2
- package/lib/Common/rcp/rpc-server-auto.js +7 -11
- package/lib/Common/rcp/rpc-server.js +11 -7
- package/lib/client.d.ts +1 -1
- package/lib/client.js +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.js +4 -5
- package/package.json +5 -3
- package/lib/Common/ObserveAll2/index.d.ts +0 -3
- package/lib/Common/ObserveAll2/reactive2.d.ts +0 -61
- package/lib/Common/async/PromiseArrayListen.d.ts +0 -14
- package/lib/Common/async/PromiseArrayListen.js +0 -37
- package/lib/Common/events/Listen2.d.ts +0 -1
- package/lib/Common/events/UseListenTransform.d.ts +0 -24
- package/lib/Common/events/UseListenTransform.js +0 -28
- package/lib/Common/rcp/test.d.ts +0 -1
- package/lib/Common/rcp/test.js +0 -79
|
@@ -29,7 +29,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
|
|
|
29
29
|
if (!registry.has(parent))
|
|
30
30
|
registry.set(parent, { subs });
|
|
31
31
|
subs.get(z)?.off();
|
|
32
|
-
const w = (0, listen_socket_1.listenSocket)(parent, {
|
|
32
|
+
const w = (0, listen_socket_1.listenSocket)(parent, { closeOn: disconnectListen, throttle: nodeThrottle });
|
|
33
33
|
subs.set(z, w);
|
|
34
34
|
const done = w.on(z);
|
|
35
35
|
done.then(() => {
|
|
@@ -48,7 +48,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
|
|
|
48
48
|
if (!registry.has(parent))
|
|
49
49
|
registry.set(parent, { subs });
|
|
50
50
|
subs.get(z)?.off();
|
|
51
|
-
const w = (0, listen_socket_1.listenSocket)(parent, {
|
|
51
|
+
const w = (0, listen_socket_1.listenSocket)(parent, { closeOn: disconnectListen, throttle: nodeThrottle });
|
|
52
52
|
let fired = false;
|
|
53
53
|
const oneShot = (...a) => {
|
|
54
54
|
if (fired)
|
|
@@ -111,16 +111,12 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
|
|
|
111
111
|
if (gatesHooked || !disconnectListen)
|
|
112
112
|
return;
|
|
113
113
|
gatesHooked = true;
|
|
114
|
-
|
|
115
|
-
if (typeof dl.on == "function")
|
|
116
|
-
dl.on(closeAllGates);
|
|
117
|
-
else
|
|
118
|
-
dl.addListen(closeAllGates);
|
|
114
|
+
disconnectListen.on(closeAllGates);
|
|
119
115
|
}
|
|
120
116
|
function gatedLineNode(parent) {
|
|
121
117
|
const { pending: pendingOpt, highWater = Infinity, lowWater = 0, pollMs = 25 } = replayOpts ?? {};
|
|
122
118
|
const pending = pendingOpt ?? (() => socket?.conn?.writeBuffer?.length ?? 0);
|
|
123
|
-
const out = (0, Listen_1.
|
|
119
|
+
const out = (0, Listen_1.createListen)(() => { });
|
|
124
120
|
out.run();
|
|
125
121
|
let lastSent = typeof parent.head == "function" ? parent.head() : 0;
|
|
126
122
|
let gated = false;
|
|
@@ -150,7 +146,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
|
|
|
150
146
|
const emitStop = !closed;
|
|
151
147
|
close();
|
|
152
148
|
if (emitStop)
|
|
153
|
-
out.
|
|
149
|
+
out.emit(rpc_protocol_1.RPC_STOP);
|
|
154
150
|
out.close?.();
|
|
155
151
|
}
|
|
156
152
|
function recoverIfDrained() {
|
|
@@ -171,7 +167,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
|
|
|
171
167
|
for (const ev of envs) {
|
|
172
168
|
if (ev.seq > lastSent)
|
|
173
169
|
lastSent = ev.seq;
|
|
174
|
-
out.
|
|
170
|
+
out.emit(ev);
|
|
175
171
|
}
|
|
176
172
|
}
|
|
177
173
|
const offLine = parent.line.on(function gateForward(ev) {
|
|
@@ -186,7 +182,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
|
|
|
186
182
|
return;
|
|
187
183
|
}
|
|
188
184
|
lastSent = ev.seq;
|
|
189
|
-
out.
|
|
185
|
+
out.emit(ev);
|
|
190
186
|
});
|
|
191
187
|
gateClosers.add(close);
|
|
192
188
|
hookGateTeardown();
|
|
@@ -6,6 +6,7 @@ const rpc_limits_1 = require("./rpc-limits");
|
|
|
6
6
|
const rpc_walk_1 = require("./rpc-walk");
|
|
7
7
|
const rpc_shape_1 = require("./rpc-shape");
|
|
8
8
|
const rpc_protocol_1 = require("./rpc-protocol");
|
|
9
|
+
const rpc_path_1 = require("./rpc-path");
|
|
9
10
|
const rpc_caps_1 = require("./rpc-caps");
|
|
10
11
|
const myThrow_1 = require("../../toError/myThrow");
|
|
11
12
|
const SERVERS = new WeakMap();
|
|
@@ -64,33 +65,36 @@ function createServer(socket, key, target, hooks, limits, auth, opt) {
|
|
|
64
65
|
}
|
|
65
66
|
let methods = [];
|
|
66
67
|
let contexts = [];
|
|
68
|
+
let methodPaths = [];
|
|
67
69
|
let routeMap = {};
|
|
68
70
|
let listenPaths = [];
|
|
69
71
|
let strictSchema = {};
|
|
70
72
|
let currentTarget = target;
|
|
71
73
|
function buildDispatch(t) {
|
|
72
|
-
const m = [], cx = [], rm = {}, lp = [];
|
|
74
|
+
const m = [], cx = [], paths = [], rm = {}, lp = [];
|
|
73
75
|
const resolved = transformTree(t);
|
|
74
76
|
(function index(obj, prefix) {
|
|
75
77
|
for (const k of Object.keys(obj)) {
|
|
76
78
|
if (!(0, rpc_limits_1.isSafeKey)(k))
|
|
77
79
|
continue;
|
|
78
80
|
const v = obj[k];
|
|
79
|
-
const path = prefix
|
|
81
|
+
const path = [...prefix, k];
|
|
80
82
|
if (typeof v == "function") {
|
|
81
|
-
rm[path] = m.length;
|
|
83
|
+
rm[(0, rpc_path_1.rpcPathKey)(path)] = m.length;
|
|
82
84
|
m.push(v);
|
|
83
85
|
cx.push(obj);
|
|
86
|
+
paths.push(path);
|
|
84
87
|
}
|
|
85
88
|
else if (v && typeof v == "object" && !(0, rpc_dynamic_1.isNoStrict)(v)) {
|
|
86
89
|
if (hasRpcListen(v))
|
|
87
|
-
lp.push(path);
|
|
90
|
+
lp.push((0, rpc_path_1.rpcPathKey)(path));
|
|
88
91
|
index(v, path);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
|
-
})(resolved,
|
|
94
|
+
})(resolved, []);
|
|
92
95
|
methods = m;
|
|
93
96
|
contexts = cx;
|
|
97
|
+
methodPaths = paths;
|
|
94
98
|
routeMap = rm;
|
|
95
99
|
listenPaths = lp;
|
|
96
100
|
strictSchema = serialize(resolved);
|
|
@@ -213,7 +217,7 @@ function createServer(socket, key, target, hooks, limits, auth, opt) {
|
|
|
213
217
|
send([rpc_protocol_1.Pkt.RESP, reqId, null, (0, rpc_walk_1.errToObj)(new rpc_limits_1.PayloadLimitError("path too long"))]);
|
|
214
218
|
return;
|
|
215
219
|
}
|
|
216
|
-
const idx = routeMap[
|
|
220
|
+
const idx = routeMap[(0, rpc_path_1.rpcPathKey)(ref)];
|
|
217
221
|
if (idx !== undefined) {
|
|
218
222
|
fn = methods[idx];
|
|
219
223
|
ctx = contexts[idx];
|
|
@@ -245,7 +249,7 @@ function createServer(socket, key, target, hooks, limits, auth, opt) {
|
|
|
245
249
|
}
|
|
246
250
|
if (hooks?.onRequest) {
|
|
247
251
|
const keyArr = typeof ref == "number"
|
|
248
|
-
?
|
|
252
|
+
? methodPaths[ref] ?? []
|
|
249
253
|
: ref;
|
|
250
254
|
const allowed = await hooks.onRequest({ key: keyArr, request: rawArgsOrSteps, fnName: keyArr[keyArr.length - 1] ?? "", fn: fn });
|
|
251
255
|
if (allowed == false) {
|
package/lib/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from "./Common/core/BaseTypes";
|
|
|
3
3
|
export * from "./Common/core/common";
|
|
4
4
|
export * from "./Common/core/MemoFunc";
|
|
5
5
|
export * from "./Common/async/waitRun";
|
|
6
|
-
export * from "./Common/async/
|
|
6
|
+
export * from "./Common/async/promiseProgress";
|
|
7
7
|
export * from "./Common/async/createIterableObject";
|
|
8
8
|
export * from "./Common/data/List";
|
|
9
9
|
export * from "./Common/data/ListNodeAnd";
|
package/lib/client.js
CHANGED
|
@@ -42,7 +42,7 @@ __exportStar(require("./Common/core/BaseTypes"), exports);
|
|
|
42
42
|
__exportStar(require("./Common/core/common"), exports);
|
|
43
43
|
__exportStar(require("./Common/core/MemoFunc"), exports);
|
|
44
44
|
__exportStar(require("./Common/async/waitRun"), exports);
|
|
45
|
-
__exportStar(require("./Common/async/
|
|
45
|
+
__exportStar(require("./Common/async/promiseProgress"), exports);
|
|
46
46
|
__exportStar(require("./Common/async/createIterableObject"), exports);
|
|
47
47
|
__exportStar(require("./Common/data/List"), exports);
|
|
48
48
|
__exportStar(require("./Common/data/ListNodeAnd"), exports);
|
package/lib/index.d.ts
CHANGED
|
@@ -6,18 +6,17 @@ export * from "./Common/core/common";
|
|
|
6
6
|
export * from "./Common/core/DeepCompareKeys";
|
|
7
7
|
export * from "./Common/core/MemoFunc";
|
|
8
8
|
export * from "./Common/async/waitRun";
|
|
9
|
-
export * from "./Common/async/
|
|
9
|
+
export * from "./Common/async/promiseProgress";
|
|
10
10
|
export * from "./Common/async/createIterableObject";
|
|
11
11
|
export * from "./Common/data/List";
|
|
12
12
|
export * from "./Common/data/ListNodeAnd";
|
|
13
13
|
export * from "./Common/data/objectPath";
|
|
14
14
|
export * from "./Common/events/Listen";
|
|
15
|
-
export * as ListenNext from "./Common/events/Listen2";
|
|
16
15
|
export * from "./Common/events/event";
|
|
17
16
|
export * from "./Common/events/SocketBuffer";
|
|
18
17
|
export * from "./Common/events/SocketServerHook";
|
|
19
18
|
export * from "./Common/events/joinListens";
|
|
20
|
-
export * from "./Common/events/
|
|
19
|
+
export * from "./Common/events/mapListen";
|
|
21
20
|
export * from "./Common/rcp/rpc-index";
|
|
22
21
|
export * from "./Common/Color";
|
|
23
22
|
export * from "./Common/funcTimeWait";
|
|
@@ -32,5 +31,5 @@ export * as Bars from "./Exchange/Bars";
|
|
|
32
31
|
export * as Params from "./Exchange/CParams";
|
|
33
32
|
export * as Time from "./Common/Time";
|
|
34
33
|
export * as Color from "./Common/Color";
|
|
35
|
-
export * as
|
|
34
|
+
export * as Observe from "./Common/Observe";
|
|
36
35
|
export * as Replay from "./Common/events/replay-index";
|
package/lib/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Replay = exports.
|
|
39
|
+
exports.Replay = exports.Observe = exports.Color = exports.Time = exports.Params = exports.Bars = exports.Math = void 0;
|
|
40
40
|
__exportStar(require("./Common/node_console"), exports);
|
|
41
41
|
__exportStar(require("./Common/core/Decorator"), exports);
|
|
42
42
|
__exportStar(require("./Common/core/BaseTypes"), exports);
|
|
@@ -45,18 +45,17 @@ __exportStar(require("./Common/core/common"), exports);
|
|
|
45
45
|
__exportStar(require("./Common/core/DeepCompareKeys"), exports);
|
|
46
46
|
__exportStar(require("./Common/core/MemoFunc"), exports);
|
|
47
47
|
__exportStar(require("./Common/async/waitRun"), exports);
|
|
48
|
-
__exportStar(require("./Common/async/
|
|
48
|
+
__exportStar(require("./Common/async/promiseProgress"), exports);
|
|
49
49
|
__exportStar(require("./Common/async/createIterableObject"), exports);
|
|
50
50
|
__exportStar(require("./Common/data/List"), exports);
|
|
51
51
|
__exportStar(require("./Common/data/ListNodeAnd"), exports);
|
|
52
52
|
__exportStar(require("./Common/data/objectPath"), exports);
|
|
53
53
|
__exportStar(require("./Common/events/Listen"), exports);
|
|
54
|
-
exports.ListenNext = __importStar(require("./Common/events/Listen2"));
|
|
55
54
|
__exportStar(require("./Common/events/event"), exports);
|
|
56
55
|
__exportStar(require("./Common/events/SocketBuffer"), exports);
|
|
57
56
|
__exportStar(require("./Common/events/SocketServerHook"), exports);
|
|
58
57
|
__exportStar(require("./Common/events/joinListens"), exports);
|
|
59
|
-
__exportStar(require("./Common/events/
|
|
58
|
+
__exportStar(require("./Common/events/mapListen"), exports);
|
|
60
59
|
__exportStar(require("./Common/rcp/rpc-index"), exports);
|
|
61
60
|
__exportStar(require("./Common/Color"), exports);
|
|
62
61
|
__exportStar(require("./Common/funcTimeWait"), exports);
|
|
@@ -71,5 +70,5 @@ exports.Bars = __importStar(require("./Exchange/Bars"));
|
|
|
71
70
|
exports.Params = __importStar(require("./Exchange/CParams"));
|
|
72
71
|
exports.Time = __importStar(require("./Common/Time"));
|
|
73
72
|
exports.Color = __importStar(require("./Common/Color"));
|
|
74
|
-
exports.
|
|
73
|
+
exports.Observe = __importStar(require("./Common/Observe"));
|
|
75
74
|
exports.Replay = __importStar(require("./Common/events/replay-index"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wenay-common2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"description": "Common library",
|
|
5
5
|
"strict": true,
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -23,13 +23,15 @@
|
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./lib/index.js",
|
|
26
|
-
"./observe
|
|
27
|
-
"./listen2": "./lib/Common/events/Listen2.js",
|
|
26
|
+
"./observe": "./lib/Common/Observe/index.js",
|
|
28
27
|
"./replay": "./lib/Common/events/replay-index.js",
|
|
29
28
|
"./lib/client": "./lib/client.js",
|
|
30
29
|
"./lib/server": "./lib/server.js",
|
|
31
30
|
"./client": "./lib/client.js",
|
|
32
31
|
"./server": "./lib/server.js",
|
|
33
32
|
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"express": "^5.2.1"
|
|
34
36
|
}
|
|
35
37
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
type Fn = () => void;
|
|
2
|
-
export type ReactiveChange = {
|
|
3
|
-
paths: PropertyKey[][];
|
|
4
|
-
};
|
|
5
|
-
type PathUpdateFn = (change: ReactiveChange) => void;
|
|
6
|
-
type Drain = 'micro' | 'immediate' | number | ((flush: Fn) => void);
|
|
7
|
-
export type Opts = {
|
|
8
|
-
drain?: Drain;
|
|
9
|
-
depth?: number;
|
|
10
|
-
eager?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export declare function reactive<T extends object>(root: T, opts?: Opts): T;
|
|
13
|
-
export declare function isReactive(p: any): boolean;
|
|
14
|
-
export declare function toRaw<T>(p: T): T;
|
|
15
|
-
export declare function onUpdate(p: any, cb: Fn): () => void;
|
|
16
|
-
export declare function onUpdatePaths(p: any, cb: PathUpdateFn): () => void;
|
|
17
|
-
export declare function flushReactive(p: any): Promise<void>;
|
|
18
|
-
export declare function listenUpdate(p: any): {
|
|
19
|
-
func: import("../events/Listen3").Listener<[]>;
|
|
20
|
-
isRun: () => boolean;
|
|
21
|
-
run: () => void;
|
|
22
|
-
close: () => void;
|
|
23
|
-
eventClose: (cb: () => void) => () => void;
|
|
24
|
-
onClose: (cb: () => void) => () => void;
|
|
25
|
-
removeEventClose: (cb: () => void) => void;
|
|
26
|
-
on: import("../events/Listen3").ListenOn<[]>;
|
|
27
|
-
off: (k: (string | symbol) | import("../events/Listen3").Listener<[]> | null) => void;
|
|
28
|
-
addListen: (cb: import("../events/Listen3").Listener<[]>, opts?: {
|
|
29
|
-
cbClose?: () => void;
|
|
30
|
-
key?: string | symbol;
|
|
31
|
-
}) => () => void;
|
|
32
|
-
removeListen: (k: (string | symbol) | import("../events/Listen3").Listener<[]> | null) => void;
|
|
33
|
-
once: (cb: import("../events/Listen3").Listener<[]>, opts?: {
|
|
34
|
-
key?: string | symbol;
|
|
35
|
-
}) => () => void;
|
|
36
|
-
count: () => number;
|
|
37
|
-
readonly getAllKeys: (string | symbol)[];
|
|
38
|
-
};
|
|
39
|
-
export declare function listenUpdatePaths(p: any): {
|
|
40
|
-
func: import("../events/Listen3").Listener<[ReactiveChange]>;
|
|
41
|
-
isRun: () => boolean;
|
|
42
|
-
run: () => void;
|
|
43
|
-
close: () => void;
|
|
44
|
-
eventClose: (cb: () => void) => () => void;
|
|
45
|
-
onClose: (cb: () => void) => () => void;
|
|
46
|
-
removeEventClose: (cb: () => void) => void;
|
|
47
|
-
on: import("../events/Listen3").ListenOn<[ReactiveChange]>;
|
|
48
|
-
off: (k: (string | symbol) | import("../events/Listen3").Listener<[ReactiveChange]> | null) => void;
|
|
49
|
-
addListen: (cb: import("../events/Listen3").Listener<[ReactiveChange]>, opts?: {
|
|
50
|
-
cbClose?: () => void;
|
|
51
|
-
key?: string | symbol;
|
|
52
|
-
}) => () => void;
|
|
53
|
-
removeListen: (k: (string | symbol) | import("../events/Listen3").Listener<[ReactiveChange]> | null) => void;
|
|
54
|
-
once: (cb: import("../events/Listen3").Listener<[ReactiveChange]>, opts?: {
|
|
55
|
-
key?: string | symbol;
|
|
56
|
-
}) => () => void;
|
|
57
|
-
count: () => number;
|
|
58
|
-
readonly getAllKeys: (string | symbol)[];
|
|
59
|
-
};
|
|
60
|
-
export type Reactive<T extends object> = T;
|
|
61
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare function PromiseArrayListen<T extends any = unknown>(array: ((() => Promise<T>) | (() => any) | Promise<T>)[]): {
|
|
2
|
-
listenOk: (a: (...d: [data: T, i: number, countOk: number, countError: number, count: number]) => any) => () => void;
|
|
3
|
-
listenError: (a: (...d: [error: any, i: number, countOk: number, countError: number, count: number]) => any) => () => void;
|
|
4
|
-
promise: {
|
|
5
|
-
all: () => Promise<any[]>;
|
|
6
|
-
allSettled: () => Promise<PromiseSettledResult<any>[]>;
|
|
7
|
-
};
|
|
8
|
-
getData(): Promise<any>[];
|
|
9
|
-
status(): {
|
|
10
|
-
ok: number;
|
|
11
|
-
error: number;
|
|
12
|
-
count: number;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromiseArrayListen = PromiseArrayListen;
|
|
4
|
-
const Listen_1 = require("../events/Listen");
|
|
5
|
-
function PromiseArrayListen(array) {
|
|
6
|
-
let ok = 0, errorCount = 0;
|
|
7
|
-
const count = array.length;
|
|
8
|
-
const t = (0, Listen_1.UseListen)();
|
|
9
|
-
const c = (0, Listen_1.UseListen)();
|
|
10
|
-
const a = (data, i) => {
|
|
11
|
-
++ok;
|
|
12
|
-
t[0](data, i, ok, errorCount, count);
|
|
13
|
-
};
|
|
14
|
-
const b = (error, i) => {
|
|
15
|
-
++errorCount;
|
|
16
|
-
c[0](error, i, ok, errorCount, count);
|
|
17
|
-
};
|
|
18
|
-
const wrap = (promise, i) => promise.then(r => { a(r, i); return r; }).catch((er) => { b(er, i); throw er; });
|
|
19
|
-
const arr = array.map((e, i) => e instanceof Promise ? wrap(e, i)
|
|
20
|
-
: () => wrap((async () => e())(), i));
|
|
21
|
-
const started = [];
|
|
22
|
-
const startAll = () => arr.map((x, i) => started[i] ??= (typeof x === 'function' ? x() : x));
|
|
23
|
-
return {
|
|
24
|
-
listenOk: (a) => t[1].addListen(a),
|
|
25
|
-
listenError: (a) => c[1].addListen(a),
|
|
26
|
-
promise: {
|
|
27
|
-
all: () => Promise.all(startAll()),
|
|
28
|
-
allSettled: () => Promise.allSettled(startAll()),
|
|
29
|
-
},
|
|
30
|
-
getData() {
|
|
31
|
-
return startAll();
|
|
32
|
-
},
|
|
33
|
-
status() {
|
|
34
|
-
return { ok, error: errorCount, count };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Listen3";
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { funcListenCallbackBase, Listener, NormalizeTuple } from "./Listen";
|
|
2
|
-
export declare function UseListenTransform<TSource extends any[], TTarget extends any[]>(sourceListen: ReturnType<typeof funcListenCallbackBase<TSource>>, transform: (...args: NormalizeTuple<TSource>) => TTarget | null, options?: {
|
|
3
|
-
addListenClose?: ReturnType<typeof funcListenCallbackBase<any>>;
|
|
4
|
-
}): readonly [(...a: NormalizeTuple<TTarget>) => void, {
|
|
5
|
-
func: Listener<NormalizeTuple<TTarget>>;
|
|
6
|
-
isRun: () => boolean;
|
|
7
|
-
run: () => void;
|
|
8
|
-
close: () => void;
|
|
9
|
-
eventClose: (cb: () => void) => () => void;
|
|
10
|
-
onClose: (cb: () => void) => () => void;
|
|
11
|
-
removeEventClose: (cb: () => void) => void;
|
|
12
|
-
on: import("./Listen3").ListenOn<NormalizeTuple<TTarget>>;
|
|
13
|
-
off: (k: (string | symbol) | Listener<NormalizeTuple<TTarget>> | null) => void;
|
|
14
|
-
addListen: (cb: Listener<NormalizeTuple<TTarget>>, opts?: {
|
|
15
|
-
cbClose?: () => void;
|
|
16
|
-
key?: string | symbol;
|
|
17
|
-
}) => () => void;
|
|
18
|
-
removeListen: (k: (string | symbol) | Listener<NormalizeTuple<TTarget>> | null) => void;
|
|
19
|
-
once: (cb: Listener<NormalizeTuple<TTarget>>, opts?: {
|
|
20
|
-
key?: string | symbol;
|
|
21
|
-
}) => () => void;
|
|
22
|
-
count: () => number;
|
|
23
|
-
readonly getAllKeys: (string | symbol)[];
|
|
24
|
-
}];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UseListenTransform = UseListenTransform;
|
|
4
|
-
const Listen_1 = require("./Listen");
|
|
5
|
-
function UseListenTransform(sourceListen, transform, options) {
|
|
6
|
-
let unsubscribeFromSource = null;
|
|
7
|
-
const [emit, targetListen] = (0, Listen_1.UseListen)({
|
|
8
|
-
event: (type, count, api) => {
|
|
9
|
-
if (type === "add" && count === 1) {
|
|
10
|
-
const sourceCallback = (...args) => {
|
|
11
|
-
const result = transform(...args);
|
|
12
|
-
if (result !== null) {
|
|
13
|
-
emit(...result);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
unsubscribeFromSource = sourceListen.addListen(sourceCallback);
|
|
17
|
-
}
|
|
18
|
-
if (type === "remove" && count === 0) {
|
|
19
|
-
if (unsubscribeFromSource) {
|
|
20
|
-
unsubscribeFromSource();
|
|
21
|
-
unsubscribeFromSource = null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
addListenClose: options?.addListenClose
|
|
26
|
-
});
|
|
27
|
-
return [emit, targetListen];
|
|
28
|
-
}
|
package/lib/Common/rcp/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/Common/rcp/test.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_1 = __importDefault(require("express"));
|
|
7
|
-
const http_1 = require("http");
|
|
8
|
-
const socket_io_1 = require("socket.io");
|
|
9
|
-
const socket_io_client_1 = require("socket.io-client");
|
|
10
|
-
const rpc_clientHub_1 = require("./rpc-clientHub");
|
|
11
|
-
const rpc_server_auto_1 = require("./rpc-server-auto");
|
|
12
|
-
const Listen_1 = require("../events/Listen");
|
|
13
|
-
const common_1 = require("../core/common");
|
|
14
|
-
const facade = () => {
|
|
15
|
-
return {
|
|
16
|
-
math: {
|
|
17
|
-
add: async (a, b) => a + b,
|
|
18
|
-
multiply: async (a, b) => a * b,
|
|
19
|
-
callback: async (a) => {
|
|
20
|
-
for (let i = 0; i < 100; i++) {
|
|
21
|
-
await (0, common_1.sleepAsync)(50);
|
|
22
|
-
a.callback({ a: new Date(), b: new Date(Date.now() - 100000) }, 43);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
greet: async (name) => {
|
|
27
|
-
console.log('get ' + name);
|
|
28
|
-
return false;
|
|
29
|
-
},
|
|
30
|
-
date: async (date) => {
|
|
31
|
-
await (0, common_1.sleepAsync)(1000);
|
|
32
|
-
return ({ msg: `Hello!`, map: new Map([['ds', 43]]), youDate: date, now: new Date() });
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
async function startServer(port) {
|
|
37
|
-
const app = (0, express_1.default)();
|
|
38
|
-
const httpServer = (0, http_1.createServer)(app);
|
|
39
|
-
const ioServer = new socket_io_1.Server(httpServer);
|
|
40
|
-
ioServer.on('connection', (socket) => {
|
|
41
|
-
console.log('[server] клиент подключился');
|
|
42
|
-
const [disconnect, disconnectListen] = (0, Listen_1.UseListen)();
|
|
43
|
-
socket.on('disconnect', disconnect);
|
|
44
|
-
(0, rpc_server_auto_1.createRpcServerAuto)({
|
|
45
|
-
socket: {
|
|
46
|
-
emit: (key, data) => socket.emit(key, data),
|
|
47
|
-
on: (key, cb) => socket.on(key, cb),
|
|
48
|
-
},
|
|
49
|
-
socketKey: 'rpc',
|
|
50
|
-
object: facade(),
|
|
51
|
-
disconnectListen,
|
|
52
|
-
debug: true,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
await new Promise((resolve) => httpServer.listen(port, resolve));
|
|
56
|
-
console.log(`[server] слушает :${port}`);
|
|
57
|
-
return httpServer;
|
|
58
|
-
}
|
|
59
|
-
async function startClient(port) {
|
|
60
|
-
const hub = (0, rpc_clientHub_1.createRpcClientHub)(() => (0, socket_io_client_1.io)(`http://localhost:${port}`, { transports: ['websocket'], forceNew: true }), (r) => ({ api: r('rpc') }));
|
|
61
|
-
const clients = await hub.setToken(null);
|
|
62
|
-
console.log('[client] подключились, ждём схему...');
|
|
63
|
-
clients.api.api.log(true);
|
|
64
|
-
await clients.api.readyStrict();
|
|
65
|
-
console.log('[client] схема получена, schema:', clients.api.schema());
|
|
66
|
-
return { hub, clients };
|
|
67
|
-
}
|
|
68
|
-
async function runTest() {
|
|
69
|
-
const PORT = 4020;
|
|
70
|
-
const httpServer = await startServer(PORT);
|
|
71
|
-
const { hub, clients } = await startClient(PORT);
|
|
72
|
-
const api = clients.api.func;
|
|
73
|
-
console.log('test World');
|
|
74
|
-
const greetResult = await api.greet('World');
|
|
75
|
-
console.log('[test] greet("World") =', greetResult);
|
|
76
|
-
hub.socket?.disconnect?.();
|
|
77
|
-
httpServer.close(() => console.log('[server] остановлен'));
|
|
78
|
-
}
|
|
79
|
-
runTest().catch(console.error);
|