wenay-common2 1.0.46 → 1.0.49
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 +51 -37
- package/lib/Common/Color.d.ts +3 -0
- package/lib/Common/Color.js +4 -0
- package/lib/Common/ObserveAll2/index.d.ts +2 -0
- package/lib/Common/ObserveAll2/index.js +18 -0
- package/lib/Common/ObserveAll2/reactive2.d.ts +33 -0
- package/lib/Common/ObserveAll2/reactive2.js +254 -0
- package/lib/Common/ObserveAll2/store.d.ts +98 -0
- package/lib/Common/ObserveAll2/store.js +381 -0
- package/lib/Common/Time.d.ts +8 -0
- package/lib/Common/Time.js +41 -14
- package/lib/Common/async/PromiseArrayListen.d.ts +3 -3
- package/lib/Common/async/PromiseArrayListen.js +10 -13
- package/lib/Common/async/createIterableObject.js +1 -1
- package/lib/Common/async/waitRun.d.ts +11 -4
- package/lib/Common/async/waitRun.js +74 -44
- package/lib/Common/core/Decorator.d.ts +3 -1
- package/lib/Common/core/Decorator.js +5 -2
- package/lib/Common/core/common.d.ts +25 -7
- package/lib/Common/core/common.js +114 -34
- package/lib/Common/data/ByteStream.d.ts +1 -1
- package/lib/Common/data/ByteStream.js +21 -8
- package/lib/Common/data/List.d.ts +5 -0
- package/lib/Common/data/List.js +13 -4
- package/lib/Common/data/ListNodeAnd.js +2 -2
- package/lib/Common/data/objectPath.d.ts +4 -0
- package/lib/Common/data/objectPath.js +8 -3
- package/lib/Common/events/Listen.d.ts +1 -55
- package/lib/Common/events/Listen.js +15 -154
- package/lib/Common/events/Listen2.d.ts +1 -0
- package/lib/Common/events/Listen2.js +17 -0
- package/lib/Common/events/Listen3.d.ts +197 -0
- package/lib/Common/events/Listen3.js +249 -0
- package/lib/Common/events/SocketBuffer.d.ts +14 -9
- package/lib/Common/events/SocketServerHook.d.ts +26 -13
- package/lib/Common/events/SocketServerHook.js +2 -1
- package/lib/Common/events/UseListenTransform.d.ts +10 -5
- package/lib/Common/events/event.d.ts +12 -0
- package/lib/Common/events/event.js +10 -6
- package/lib/Common/events/joinListens.d.ts +2 -0
- package/lib/Common/events/joinListens.js +13 -12
- package/lib/Common/funcTimeWait.d.ts +28 -0
- package/lib/Common/funcTimeWait.js +18 -1
- package/lib/Common/isProxy.d.ts +1 -0
- package/lib/Common/isProxy.js +2 -0
- package/lib/Common/node_console.d.ts +2 -0
- package/lib/Common/node_console.js +3 -76
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.d.ts +2 -0
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.js +63 -30
- package/lib/Common/rcp/listen-deep.d.ts +13 -5
- package/lib/Common/rcp/listen-socket.d.ts +21 -3
- package/lib/Common/rcp/listen-socket.js +126 -17
- package/lib/Common/rcp/oldCommonsServer.d.ts +1 -1
- package/lib/Common/rcp/oldCommonsServer.js +15 -1
- package/lib/Common/rcp/old/320/241ommonsServerMini.js +1 -0
- package/lib/Common/rcp/rpc-caps.d.ts +10 -0
- package/lib/Common/rcp/rpc-caps.js +16 -0
- package/lib/Common/rcp/rpc-client.d.ts +23 -1
- package/lib/Common/rcp/rpc-client.js +306 -25
- package/lib/Common/rcp/rpc-clientHub.d.ts +7 -1
- package/lib/Common/rcp/rpc-clientHub.js +25 -2
- package/lib/Common/rcp/rpc-index.d.ts +3 -0
- package/lib/Common/rcp/rpc-index.js +3 -0
- package/lib/Common/rcp/rpc-inproc.d.ts +17 -0
- package/lib/Common/rcp/rpc-inproc.js +30 -0
- package/lib/Common/rcp/rpc-off.d.ts +10 -0
- package/lib/Common/rcp/rpc-off.js +22 -0
- package/lib/Common/rcp/rpc-protocol.d.ts +6 -0
- package/lib/Common/rcp/rpc-protocol.js +4 -2
- package/lib/Common/rcp/rpc-server-auto.d.ts +14 -3
- package/lib/Common/rcp/rpc-server-auto.js +81 -6
- package/lib/Common/rcp/rpc-server.d.ts +17 -2
- package/lib/Common/rcp/rpc-server.js +127 -31
- package/lib/Common/rcp/rpc-shape.d.ts +17 -0
- package/lib/Common/rcp/rpc-shape.js +42 -0
- package/lib/Common/rcp/rpc-walk.js +29 -11
- package/lib/Exchange/Bars.d.ts +3 -0
- package/lib/Exchange/Bars.js +4 -1
- package/lib/Exchange/CParams.d.ts +2 -0
- package/lib/Exchange/CParams.js +21 -14
- package/lib/Exchange/MarketData.d.ts +6 -0
- package/lib/Exchange/MarketData.js +4 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/server/WebHook3.js +22 -9
- package/package.json +3 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callerLines = exports.callerLine = void 0;
|
|
3
4
|
exports.enable = enable;
|
|
4
5
|
exports.disable = disable;
|
|
5
6
|
exports.__LineFile = __LineFile;
|
|
@@ -9,78 +10,6 @@ const { self, window } = globalThis;
|
|
|
9
10
|
let _enabled = false;
|
|
10
11
|
function enable(flag = true) { _enabled = flag; }
|
|
11
12
|
function disable() { _enabled = false; }
|
|
12
|
-
let wrapCallSite;
|
|
13
|
-
function setupLogs2() {
|
|
14
|
-
if (typeof self != 'object' && typeof window != "object") {
|
|
15
|
-
function moduleName(name) { return name; }
|
|
16
|
-
let inspector = require(moduleName('inspector'));
|
|
17
|
-
if (inspector.url() != undefined)
|
|
18
|
-
return;
|
|
19
|
-
try {
|
|
20
|
-
let module = require(moduleName('source-map-support'));
|
|
21
|
-
module.install();
|
|
22
|
-
wrapCallSite = module.wrapCallSite;
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.warn(e);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
_enabled = true;
|
|
29
|
-
const origLogMethod = console.log;
|
|
30
|
-
const origErrorMethod = console.error;
|
|
31
|
-
let _callee;
|
|
32
|
-
for (let methodName of [
|
|
33
|
-
'debug', 'info', 'log', 'warn', 'error', 'group', 'groupCollapsed', 'table', 'timeLog', 'timeEnd',
|
|
34
|
-
'count', 'assert', 'dir', 'dirxml'
|
|
35
|
-
]) {
|
|
36
|
-
const origMethod = console[methodName];
|
|
37
|
-
console[methodName] = ((...args) => {
|
|
38
|
-
if (!_enabled)
|
|
39
|
-
return origMethod(...args);
|
|
40
|
-
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
41
|
-
Error.prepareStackTrace = (_, stack) => stack;
|
|
42
|
-
let callee = new Error().stack[1];
|
|
43
|
-
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
44
|
-
if (!callee) {
|
|
45
|
-
origErrorMethod("сallee is not found in node_console");
|
|
46
|
-
_enabled = false;
|
|
47
|
-
return origMethod(...args);
|
|
48
|
-
}
|
|
49
|
-
if (!methodName.match(/debug|info|log|warn|error|dirxml/)) {
|
|
50
|
-
_callee ??= callee;
|
|
51
|
-
return origMethod(...args);
|
|
52
|
-
}
|
|
53
|
-
if (_callee) {
|
|
54
|
-
callee = _callee;
|
|
55
|
-
_callee = undefined;
|
|
56
|
-
}
|
|
57
|
-
if (wrapCallSite)
|
|
58
|
-
callee = wrapCallSite(callee);
|
|
59
|
-
const fileName = callee.getFileName();
|
|
60
|
-
if (fileName?.includes("source-map-support")) {
|
|
61
|
-
origMethod(...args);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
let fileAndLine = `${fileName}:${callee.getLineNumber()}:${callee.getColumnNumber()} ` + callee.getFunctionName();
|
|
65
|
-
fileAndLine = fileAndLine.replaceAll("\\", "/");
|
|
66
|
-
fileAndLine = fileAndLine.replace("webpack:///", "");
|
|
67
|
-
fileAndLine = fileAndLine.replace("?", "");
|
|
68
|
-
if (!fileAndLine.startsWith("./"))
|
|
69
|
-
if (!fileAndLine.toLowerCase().startsWith("file:///"))
|
|
70
|
-
fileAndLine = "file:///" + fileAndLine;
|
|
71
|
-
let [firstArg, ...otherArgs] = args;
|
|
72
|
-
if (1)
|
|
73
|
-
origMethod(...args, "", fileAndLine);
|
|
74
|
-
else if (typeof firstArg === 'string') {
|
|
75
|
-
origMethod(fileAndLine + ' ' + firstArg, ...otherArgs);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
origMethod(fileAndLine, ...args);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
13
|
function setupLogs() {
|
|
85
14
|
if (typeof self != 'object' && typeof window != "object") {
|
|
86
15
|
function moduleName(name) { return name; }
|
|
@@ -153,8 +82,6 @@ function __LineFile2(lvl = 0) {
|
|
|
153
82
|
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
154
83
|
Error.prepareStackTrace = (_, stack) => stack;
|
|
155
84
|
let e = new Error().stack[lvl + 1];
|
|
156
|
-
if (wrapCallSite)
|
|
157
|
-
e = wrapCallSite(e);
|
|
158
85
|
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
159
86
|
return `${e.getFileName()}:${e.getLineNumber()}:${e.getColumnNumber()} ` + e.getFunctionName();
|
|
160
87
|
}
|
|
@@ -162,9 +89,9 @@ function __LineFiles(lvlStart = 0, lvlEnd = 5) {
|
|
|
162
89
|
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
163
90
|
Error.prepareStackTrace = (_, stack) => stack;
|
|
164
91
|
let e = new Error().stack.slice(lvlStart + 1, lvlEnd);
|
|
165
|
-
if (wrapCallSite)
|
|
166
|
-
e = e.map(e => wrapCallSite(e));
|
|
167
92
|
const msgs = e.map(e => `${e.getFileName()}:${e.getLineNumber()}:${e.getColumnNumber()} ` + e.getFunctionName());
|
|
168
93
|
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
169
94
|
return msgs;
|
|
170
95
|
}
|
|
96
|
+
exports.callerLine = __LineFile2;
|
|
97
|
+
exports.callerLines = __LineFiles;
|
|
@@ -8,42 +8,58 @@ const rpc_protocol_1 = require("./rpc-protocol");
|
|
|
8
8
|
const old_ommonsServerMini_1 = require("./old\u0421ommonsServerMini");
|
|
9
9
|
const rpc_dynamic_1 = require("./rpc-dynamic");
|
|
10
10
|
const rpc_limits_1 = require("./rpc-limits");
|
|
11
|
-
function createRpcServerAuto({ socket, object: target, socketKey: key, debug, hooks, disconnectListen, limits }) {
|
|
12
|
-
const cache = new WeakMap();
|
|
13
|
-
function getListenSocket(parent, disconnectListen) {
|
|
14
|
-
let result = cache.get(parent);
|
|
15
|
-
if (!result) {
|
|
16
|
-
result = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen });
|
|
17
|
-
cache.set(parent, result);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
(0, rpc_server_1.createRpcServer)({
|
|
22
|
-
socket, object: target, socketKey: key, debug, limits,
|
|
23
|
-
hooks: {
|
|
24
|
-
...hooks,
|
|
25
|
-
resolveTransform: (obj) => {
|
|
26
|
-
if (!(0, Listen_1.isListenCallback)(obj))
|
|
27
|
-
return obj;
|
|
28
|
-
return getListenSocket(obj, disconnectListen);
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
11
|
function createRpcServerAuto2({ socket, object: target, socketKey: key, debug = false, hooks, disconnectListen, limits, onProtocolDetect, }) {
|
|
34
12
|
const cache = new WeakMap();
|
|
13
|
+
const listenSockets = new Set();
|
|
14
|
+
function unsubscribeAllActive() {
|
|
15
|
+
for (const w of [...listenSockets])
|
|
16
|
+
w.removeCallback();
|
|
17
|
+
}
|
|
35
18
|
function getListenSocket(parent) {
|
|
36
19
|
let result = cache.get(parent);
|
|
20
|
+
if (result)
|
|
21
|
+
listenSockets.add(result);
|
|
37
22
|
if (!result) {
|
|
38
|
-
|
|
23
|
+
const subs = new Map();
|
|
24
|
+
function subscribe(z) {
|
|
25
|
+
if (typeof z !== "function")
|
|
26
|
+
return Promise.reject(new TypeError("Listen callback expects a function"));
|
|
27
|
+
subs.get(z)?.removeCallback();
|
|
28
|
+
const w = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen });
|
|
29
|
+
subs.set(z, w);
|
|
30
|
+
const done = w.callback(z);
|
|
31
|
+
done.then(() => { if (subs.get(z) == w)
|
|
32
|
+
subs.delete(z); });
|
|
33
|
+
return done;
|
|
34
|
+
}
|
|
35
|
+
function subscribeOnce(z) {
|
|
36
|
+
if (typeof z !== "function")
|
|
37
|
+
return Promise.reject(new TypeError("Listen once expects a function"));
|
|
38
|
+
subs.get(z)?.removeCallback();
|
|
39
|
+
const w = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen });
|
|
40
|
+
subs.set(z, w);
|
|
41
|
+
const done = w.once(z);
|
|
42
|
+
done.then(() => { if (subs.get(z) == w)
|
|
43
|
+
subs.delete(z); });
|
|
44
|
+
return done;
|
|
45
|
+
}
|
|
46
|
+
function unsubscribeAll() {
|
|
47
|
+
subs.forEach(w => w.removeCallback());
|
|
48
|
+
subs.clear();
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
result = { callback: subscribe, removeCallback: unsubscribeAll, on: subscribe, once: subscribeOnce, close: () => parent.close?.() };
|
|
52
|
+
listenSockets.add(result);
|
|
39
53
|
cache.set(parent, result);
|
|
40
54
|
}
|
|
41
55
|
return result;
|
|
42
56
|
}
|
|
43
57
|
function resolveTransform(obj) {
|
|
44
|
-
if (
|
|
45
|
-
return obj;
|
|
46
|
-
|
|
58
|
+
if ((0, Listen_1.isListenCallback)(obj))
|
|
59
|
+
return getListenSocket(obj);
|
|
60
|
+
if ((0, Listen_1.isListenOn)(obj))
|
|
61
|
+
return getListenSocket((0, Listen_1.getListenByOn)(obj));
|
|
62
|
+
return obj;
|
|
47
63
|
}
|
|
48
64
|
function transformTree(obj) {
|
|
49
65
|
let current = obj;
|
|
@@ -61,7 +77,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
61
77
|
out[k] = v;
|
|
62
78
|
continue;
|
|
63
79
|
}
|
|
64
|
-
out[k] = typeof v === 'function' ? v : (v != null && typeof v === 'object') ? transformTree(v) : v;
|
|
80
|
+
out[k] = typeof v === 'function' ? resolveTransform(v) : (v != null && typeof v === 'object') ? transformTree(v) : v;
|
|
65
81
|
}
|
|
66
82
|
return out;
|
|
67
83
|
}
|
|
@@ -96,6 +112,8 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
96
112
|
let protocol = null;
|
|
97
113
|
let v2Handler = null;
|
|
98
114
|
let legacyHandler = null;
|
|
115
|
+
let disposed = false;
|
|
116
|
+
let activeHandler = null;
|
|
99
117
|
function isLegacyStrictRequest(msg) {
|
|
100
118
|
return msg === '___STRICTLY';
|
|
101
119
|
}
|
|
@@ -108,7 +126,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
108
126
|
function isV2Message(msg) {
|
|
109
127
|
if (msg === rpc_protocol_1.Pkt.STRICT)
|
|
110
128
|
return true;
|
|
111
|
-
if (Array.isArray(msg) && (msg[0] === rpc_protocol_1.Pkt.CALL || msg[0] === rpc_protocol_1.Pkt.PIPE))
|
|
129
|
+
if (Array.isArray(msg) && (msg[0] === rpc_protocol_1.Pkt.CALL || msg[0] === rpc_protocol_1.Pkt.PIPE || msg[0] === rpc_protocol_1.Pkt.HELLO))
|
|
112
130
|
return true;
|
|
113
131
|
return false;
|
|
114
132
|
}
|
|
@@ -143,6 +161,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
143
161
|
limits,
|
|
144
162
|
hooks: {
|
|
145
163
|
...hooks,
|
|
164
|
+
onDispose: () => { unsubscribeAllActive(); hooks?.onDispose?.(); },
|
|
146
165
|
resolveTransform,
|
|
147
166
|
},
|
|
148
167
|
});
|
|
@@ -152,7 +171,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
152
171
|
onMsgCb(msg);
|
|
153
172
|
};
|
|
154
173
|
}
|
|
155
|
-
|
|
174
|
+
function handleMessage(msg) {
|
|
156
175
|
if (debug) {
|
|
157
176
|
console.log('[RPC-AUTO2 IN]', typeof msg === 'object' ? JSON.stringify(msg) : msg);
|
|
158
177
|
}
|
|
@@ -197,10 +216,24 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
197
216
|
}
|
|
198
217
|
if (debug)
|
|
199
218
|
console.warn('[RPC-AUTO2] Unknown message format, ignoring:', msg);
|
|
200
|
-
}
|
|
219
|
+
}
|
|
220
|
+
activeHandler = handleMessage;
|
|
221
|
+
socket.on(key, (msg) => activeHandler?.(msg));
|
|
222
|
+
function reset() { unsubscribeAllActive(); protocol = null; legacyHandler = null; v2Handler = null; }
|
|
223
|
+
function dispose(reason) {
|
|
224
|
+
if (disposed)
|
|
225
|
+
return;
|
|
226
|
+
disposed = true;
|
|
227
|
+
activeHandler = null;
|
|
228
|
+
reset();
|
|
229
|
+
if (debug)
|
|
230
|
+
console.log('[RPC-AUTO2] disposed', reason ?? '');
|
|
231
|
+
}
|
|
201
232
|
return {
|
|
202
233
|
getProtocol: () => protocol,
|
|
203
234
|
getLegacySchema: () => legacySchema,
|
|
204
235
|
getResolved: () => resolved,
|
|
236
|
+
dispose,
|
|
237
|
+
reset,
|
|
205
238
|
};
|
|
206
239
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ListenOn } from "../events/Listen";
|
|
2
|
+
import { listenSocket, listenSocketFirst, listenSocketAll, listenSocketSmart, type tSubHandle } from "./listen-socket";
|
|
3
|
+
type WithSubHandle<R> = R extends {
|
|
4
|
+
callback: (...a: infer A) => any;
|
|
5
|
+
} ? Omit<R, 'callback' | 'on' | 'once'> & {
|
|
6
|
+
callback: (...a: A) => tSubHandle & Promise<void>;
|
|
7
|
+
on: (...a: A) => tSubHandle & Promise<void>;
|
|
8
|
+
once: (...a: A) => tSubHandle & Promise<void>;
|
|
9
|
+
} : R;
|
|
2
10
|
type Obj = Record<string, any>;
|
|
3
11
|
type InferArgs<T> = T extends {
|
|
4
12
|
addListen: (cb: (...args: infer R) => void, ...rest: any[]) => any;
|
|
@@ -6,22 +14,22 @@ type InferArgs<T> = T extends {
|
|
|
6
14
|
export type DeepSocketListen<T> = {
|
|
7
15
|
[K in keyof T]: T[K] extends {
|
|
8
16
|
addListen: Function;
|
|
9
|
-
} ? ReturnType<typeof listenSocket<InferArgs<T[K]>>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListen<T[K]> : T[K];
|
|
17
|
+
} ? WithSubHandle<ReturnType<typeof listenSocket<InferArgs<T[K]>>>> : T[K] extends ListenOn<infer Z> ? WithSubHandle<ReturnType<typeof listenSocket<Z>>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListen<T[K]> : T[K];
|
|
10
18
|
};
|
|
11
19
|
export type DeepSocketListenFirst<T> = {
|
|
12
20
|
[K in keyof T]: T[K] extends {
|
|
13
21
|
addListen: Function;
|
|
14
|
-
} ? ReturnType<typeof listenSocketFirst<InferArgs<T[K]>>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListenFirst<T[K]> : T[K];
|
|
22
|
+
} ? ReturnType<typeof listenSocketFirst<InferArgs<T[K]>>> : T[K] extends ListenOn<infer Z> ? ReturnType<typeof listenSocketFirst<Z>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListenFirst<T[K]> : T[K];
|
|
15
23
|
};
|
|
16
24
|
export type DeepSocketListenAll<T> = {
|
|
17
25
|
[K in keyof T]: T[K] extends {
|
|
18
26
|
addListen: Function;
|
|
19
|
-
} ? ReturnType<typeof listenSocketAll<InferArgs<T[K]>>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListenAll<T[K]> : T[K];
|
|
27
|
+
} ? ReturnType<typeof listenSocketAll<InferArgs<T[K]>>> : T[K] extends ListenOn<infer Z> ? ReturnType<typeof listenSocketAll<Z>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListenAll<T[K]> : T[K];
|
|
20
28
|
};
|
|
21
29
|
export type DeepSocketListenSmart<T> = {
|
|
22
30
|
[K in keyof T]: NonNullable<T[K]> extends {
|
|
23
31
|
addListen: Function;
|
|
24
|
-
} ? ReturnType<typeof listenSocketSmart<InferArgs<NonNullable<T[K]>>>> | Extract<T[K], undefined | null> : NonNullable<T[K]> extends (...a: any[]) => any ? T[K] : NonNullable<T[K]> extends typeof Promise ? T[K] : NonNullable<T[K]> extends object ? DeepSocketListenSmart<T[K]> : T[K];
|
|
32
|
+
} ? ReturnType<typeof listenSocketSmart<InferArgs<NonNullable<T[K]>>>> | Extract<T[K], undefined | null> : NonNullable<T[K]> extends ListenOn<infer Z> ? ReturnType<typeof listenSocketSmart<Z>> : NonNullable<T[K]> extends (...a: any[]) => any ? T[K] : NonNullable<T[K]> extends Promise<any> ? T[K] : NonNullable<T[K]> extends typeof Promise ? T[K] : NonNullable<T[K]> extends object ? DeepSocketListenSmart<T[K]> : T[K];
|
|
25
33
|
};
|
|
26
34
|
export declare function matchKeys<T extends Obj, T2 extends Obj>(obj1: T, obj2: T2): boolean;
|
|
27
35
|
export declare function matchKeysList<T extends Obj>(obj1: T, keys: string[]): boolean;
|
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
import { funcListenCallbackBase, type Listener } from "../events/Listen";
|
|
2
|
+
import { type Off } from "./rpc-off";
|
|
2
3
|
type ListenCallbackResult<T extends any[] = any[]> = ReturnType<typeof funcListenCallbackBase<T>>;
|
|
4
|
+
export type tSubHandle = Off<void, {
|
|
5
|
+
unsubscribe: () => void;
|
|
6
|
+
removeCallback: () => void;
|
|
7
|
+
}>;
|
|
3
8
|
export declare function listenSocket<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, d?: {
|
|
4
9
|
readonly status?: () => boolean;
|
|
5
10
|
readonly addListenClose?: ListenCallbackResult<any>;
|
|
6
11
|
readonly stop?: (x: Listener<Z>) => any;
|
|
7
12
|
readonly paramsModify?: (...e: Z) => any[];
|
|
13
|
+
readonly throttle?: number;
|
|
8
14
|
}): {
|
|
9
15
|
callback: (z: Listener<Z>) => Promise<void>;
|
|
10
16
|
removeCallback: () => boolean;
|
|
17
|
+
on: (z: Listener<Z>) => Promise<void>;
|
|
18
|
+
once: (z: Listener<Z>) => Promise<void>;
|
|
19
|
+
close: () => void;
|
|
11
20
|
};
|
|
12
21
|
export declare function listenSocketFirst<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
|
|
13
|
-
callback: (z: (a: Z[0]) => void) =>
|
|
22
|
+
callback: (z: (a: Z[0]) => void) => tSubHandle;
|
|
23
|
+
on: (z: (a: Z[0]) => void) => tSubHandle;
|
|
24
|
+
once: (z: (a: Z[0]) => void) => tSubHandle;
|
|
25
|
+
close: () => void;
|
|
14
26
|
removeCallback: () => boolean;
|
|
15
27
|
};
|
|
16
28
|
export declare function listenSocketAll<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
|
|
17
|
-
callback: (z: (...args: Z) => void) =>
|
|
29
|
+
callback: (z: (...args: Z) => void) => tSubHandle;
|
|
30
|
+
on: (z: (...args: Z) => void) => tSubHandle;
|
|
31
|
+
once: (z: (...args: Z) => void) => tSubHandle;
|
|
32
|
+
close: () => void;
|
|
18
33
|
removeCallback: () => boolean;
|
|
19
34
|
};
|
|
20
35
|
type SmartCallback<Z extends any[]> = Z extends [infer Single] ? (a: Single) => void : (...args: Z) => void;
|
|
21
36
|
export declare function listenSocketSmart<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
|
|
22
|
-
callback: (z: SmartCallback<Z>) =>
|
|
37
|
+
callback: (z: SmartCallback<Z>) => tSubHandle;
|
|
38
|
+
on: (z: SmartCallback<Z>) => tSubHandle;
|
|
39
|
+
once: (z: SmartCallback<Z>) => tSubHandle;
|
|
40
|
+
close: () => void;
|
|
23
41
|
removeCallback: () => boolean;
|
|
24
42
|
};
|
|
25
43
|
export {};
|
|
@@ -4,12 +4,54 @@ exports.listenSocket = listenSocket;
|
|
|
4
4
|
exports.listenSocketFirst = listenSocketFirst;
|
|
5
5
|
exports.listenSocketAll = listenSocketAll;
|
|
6
6
|
exports.listenSocketSmart = listenSocketSmart;
|
|
7
|
+
const rpc_protocol_1 = require("./rpc-protocol");
|
|
8
|
+
const rpc_off_1 = require("./rpc-off");
|
|
9
|
+
function createThrottleLatest(ms, sink) {
|
|
10
|
+
let timer = null;
|
|
11
|
+
let pending = null;
|
|
12
|
+
let killed = false;
|
|
13
|
+
function flush() {
|
|
14
|
+
timer = null;
|
|
15
|
+
if (pending) {
|
|
16
|
+
const a = pending;
|
|
17
|
+
pending = null;
|
|
18
|
+
emit(...a);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function emit(...a) {
|
|
22
|
+
sink(...a);
|
|
23
|
+
if (!killed)
|
|
24
|
+
timer = setTimeout(flush, ms);
|
|
25
|
+
}
|
|
26
|
+
function push(...a) {
|
|
27
|
+
if (killed)
|
|
28
|
+
return;
|
|
29
|
+
if (timer) {
|
|
30
|
+
pending = a;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
emit(...a);
|
|
34
|
+
}
|
|
35
|
+
function cancel() {
|
|
36
|
+
killed = true;
|
|
37
|
+
if (timer) {
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
timer = null;
|
|
40
|
+
}
|
|
41
|
+
pending = null;
|
|
42
|
+
}
|
|
43
|
+
return { push, cancel };
|
|
44
|
+
}
|
|
7
45
|
function listenSocket(e, d) {
|
|
8
|
-
const { stop, addListenClose, status, paramsModify } = d ?? {};
|
|
9
|
-
const
|
|
46
|
+
const { stop, addListenClose, status, paramsModify, throttle } = d ?? {};
|
|
47
|
+
const subscribe = (cb, opts) => typeof e.on == "function" ? e.on(cb, opts) : e.addListen(cb, opts);
|
|
48
|
+
const subscribeClose = addListenClose && ((cb) => typeof addListenClose.on == "function" ? addListenClose.on(cb) : addListenClose.addListen(cb));
|
|
10
49
|
let last = null;
|
|
11
50
|
let active = null;
|
|
51
|
+
let activeOff = null;
|
|
52
|
+
let closeSignalOff = null;
|
|
12
53
|
let resolveWait = null;
|
|
54
|
+
let throttleCh = null;
|
|
13
55
|
function finish() {
|
|
14
56
|
if (resolveWait) {
|
|
15
57
|
resolveWait();
|
|
@@ -17,23 +59,41 @@ function listenSocket(e, d) {
|
|
|
17
59
|
}
|
|
18
60
|
}
|
|
19
61
|
function removeCallback() {
|
|
62
|
+
if (throttleCh) {
|
|
63
|
+
throttleCh.cancel();
|
|
64
|
+
throttleCh = null;
|
|
65
|
+
}
|
|
20
66
|
if (last) {
|
|
21
67
|
stop?.(last);
|
|
22
68
|
last = null;
|
|
23
69
|
}
|
|
24
|
-
if (
|
|
25
|
-
|
|
70
|
+
if (activeOff) {
|
|
71
|
+
activeOff();
|
|
72
|
+
activeOff = null;
|
|
26
73
|
active = null;
|
|
27
74
|
}
|
|
28
|
-
|
|
75
|
+
if (closeSignalOff) {
|
|
76
|
+
closeSignalOff();
|
|
77
|
+
closeSignalOff = null;
|
|
78
|
+
}
|
|
29
79
|
finish();
|
|
30
80
|
return true;
|
|
31
81
|
}
|
|
32
|
-
|
|
82
|
+
function callback(z) {
|
|
83
|
+
if (typeof z !== "function") {
|
|
84
|
+
throw new TypeError("listenSocket.callback expects a function");
|
|
85
|
+
}
|
|
33
86
|
if (last)
|
|
34
87
|
stop?.(last);
|
|
35
|
-
if (
|
|
36
|
-
|
|
88
|
+
if (activeOff) {
|
|
89
|
+
activeOff();
|
|
90
|
+
activeOff = null;
|
|
91
|
+
active = null;
|
|
92
|
+
}
|
|
93
|
+
if (closeSignalOff) {
|
|
94
|
+
closeSignalOff();
|
|
95
|
+
closeSignalOff = null;
|
|
96
|
+
}
|
|
37
97
|
if (resolveWait) {
|
|
38
98
|
resolveWait();
|
|
39
99
|
resolveWait = null;
|
|
@@ -53,31 +113,71 @@ function listenSocket(e, d) {
|
|
|
53
113
|
removeCallback();
|
|
54
114
|
};
|
|
55
115
|
}
|
|
56
|
-
|
|
116
|
+
let inner = handler;
|
|
117
|
+
if (throttle) {
|
|
118
|
+
if (throttleCh)
|
|
119
|
+
throttleCh.cancel();
|
|
120
|
+
const ch = createThrottleLatest(throttle, (...a) => handler(...a));
|
|
121
|
+
throttleCh = ch;
|
|
122
|
+
inner = (...a) => ch.push(...a);
|
|
123
|
+
}
|
|
57
124
|
active = (...a) => {
|
|
58
|
-
if (a[0] ===
|
|
125
|
+
if (a[0] === rpc_protocol_1.RPC_STOP) {
|
|
126
|
+
if (throttleCh) {
|
|
127
|
+
throttleCh.cancel();
|
|
128
|
+
throttleCh = null;
|
|
129
|
+
}
|
|
59
130
|
z(...a);
|
|
60
131
|
if (last) {
|
|
61
132
|
stop?.(last);
|
|
62
133
|
}
|
|
63
134
|
last = null;
|
|
64
|
-
if (
|
|
65
|
-
|
|
135
|
+
if (activeOff) {
|
|
136
|
+
activeOff();
|
|
137
|
+
activeOff = null;
|
|
66
138
|
active = null;
|
|
67
139
|
}
|
|
68
|
-
|
|
140
|
+
if (closeSignalOff) {
|
|
141
|
+
closeSignalOff();
|
|
142
|
+
closeSignalOff = null;
|
|
143
|
+
}
|
|
69
144
|
finish();
|
|
70
145
|
return;
|
|
71
146
|
}
|
|
72
147
|
inner(...a);
|
|
73
148
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
149
|
+
activeOff = subscribe(active, { cbClose: removeCallback });
|
|
150
|
+
closeSignalOff = subscribeClose?.(removeCallback) ?? null;
|
|
151
|
+
const wait = new Promise((resolve) => {
|
|
77
152
|
resolveWait = () => { resolve(); };
|
|
78
153
|
});
|
|
154
|
+
return (0, rpc_off_1.makeOff)(wait, removeCallback, { unsubscribe: removeCallback, removeCallback });
|
|
155
|
+
}
|
|
156
|
+
function once(z) {
|
|
157
|
+
if (typeof z !== "function") {
|
|
158
|
+
throw new TypeError("listenSocket.once expects a function");
|
|
159
|
+
}
|
|
160
|
+
let fired = false;
|
|
161
|
+
const oneShot = ((...a) => {
|
|
162
|
+
if (a[0] === rpc_protocol_1.RPC_STOP) {
|
|
163
|
+
removeCallback();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (fired)
|
|
167
|
+
return;
|
|
168
|
+
fired = true;
|
|
169
|
+
try {
|
|
170
|
+
z(...a);
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
(0, rpc_off_1.endCallback)(z);
|
|
174
|
+
removeCallback();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return callback(oneShot);
|
|
79
178
|
}
|
|
80
|
-
|
|
179
|
+
function closeStream() { e.close?.(); }
|
|
180
|
+
return { callback, removeCallback, on: callback, once, close: closeStream };
|
|
81
181
|
}
|
|
82
182
|
function listenSocketFirst(e, options) {
|
|
83
183
|
const r = listenSocket(e, {
|
|
@@ -86,6 +186,9 @@ function listenSocketFirst(e, options) {
|
|
|
86
186
|
});
|
|
87
187
|
return {
|
|
88
188
|
callback: r.callback,
|
|
189
|
+
on: r.callback,
|
|
190
|
+
once: r.once,
|
|
191
|
+
close: r.close,
|
|
89
192
|
removeCallback: r.removeCallback,
|
|
90
193
|
};
|
|
91
194
|
}
|
|
@@ -93,6 +196,9 @@ function listenSocketAll(e, options) {
|
|
|
93
196
|
const r = listenSocket(e, { ...options });
|
|
94
197
|
return {
|
|
95
198
|
callback: r.callback,
|
|
199
|
+
on: r.callback,
|
|
200
|
+
once: r.once,
|
|
201
|
+
close: r.close,
|
|
96
202
|
removeCallback: r.removeCallback,
|
|
97
203
|
};
|
|
98
204
|
}
|
|
@@ -100,6 +206,9 @@ function listenSocketSmart(e, options) {
|
|
|
100
206
|
const r = listenSocket(e, { ...options });
|
|
101
207
|
return {
|
|
102
208
|
callback: r.callback,
|
|
209
|
+
on: r.callback,
|
|
210
|
+
once: r.once,
|
|
211
|
+
close: r.close,
|
|
103
212
|
removeCallback: r.removeCallback,
|
|
104
213
|
};
|
|
105
214
|
}
|
|
@@ -101,7 +101,7 @@ export declare function CreatAPIFacadeClientOld<T extends object>({ socketKey, s
|
|
|
101
101
|
infoStrictly(): any;
|
|
102
102
|
strictlyInit(obj?: object): Promise<unknown>;
|
|
103
103
|
};
|
|
104
|
-
export declare function CreatAPIFacadeServerOld<T extends object>(
|
|
104
|
+
export declare function CreatAPIFacadeServerOld<T extends object>(params: {
|
|
105
105
|
socket: tSocket;
|
|
106
106
|
object: T;
|
|
107
107
|
socketKey: string;
|
|
@@ -9,7 +9,11 @@ exports.CreatAPIFacadeClientOld = CreatAPIFacadeClientOld;
|
|
|
9
9
|
exports.CreatAPIFacadeServerOld = CreatAPIFacadeServerOld;
|
|
10
10
|
exports.fMiniTest = fMiniTest;
|
|
11
11
|
const common_1 = require("../core/common");
|
|
12
|
+
const old_ommonsServerMini_1 = require("./old\u0421ommonsServerMini");
|
|
12
13
|
function funcPromiseServer(data, obj) {
|
|
14
|
+
return (0, old_ommonsServerMini_1.promiseServer)(data, obj);
|
|
15
|
+
}
|
|
16
|
+
function funcPromiseServerOld(data, obj) {
|
|
13
17
|
const buf = data;
|
|
14
18
|
data.api({
|
|
15
19
|
onMessage: async (datum) => {
|
|
@@ -86,6 +90,9 @@ function funcPromiseServer2(sendMessage, obj) {
|
|
|
86
90
|
};
|
|
87
91
|
}
|
|
88
92
|
function funcForWebSocket(data) {
|
|
93
|
+
return (0, old_ommonsServerMini_1.wsWrapper)(data);
|
|
94
|
+
}
|
|
95
|
+
function funcForWebSocketOld(data) {
|
|
89
96
|
const limit = data.limit;
|
|
90
97
|
const sendMessage = data.sendMessage;
|
|
91
98
|
const free = (() => {
|
|
@@ -122,6 +129,7 @@ function funcForWebSocket(data) {
|
|
|
122
129
|
if (data.data == "___STOP") {
|
|
123
130
|
callbackMany.delete(mapId);
|
|
124
131
|
free.numsSet(mapId);
|
|
132
|
+
return;
|
|
125
133
|
}
|
|
126
134
|
buf?.(data.data);
|
|
127
135
|
}
|
|
@@ -188,6 +196,9 @@ function funcForWebSocket(data) {
|
|
|
188
196
|
};
|
|
189
197
|
}
|
|
190
198
|
function funcScreenerClient2(data, wait) {
|
|
199
|
+
return (0, old_ommonsServerMini_1.createClientProxy)(data, wait);
|
|
200
|
+
}
|
|
201
|
+
function funcScreenerClient2Old(data, wait) {
|
|
191
202
|
const tr = (address) => new Proxy((() => { }), {
|
|
192
203
|
get(target, p, receiver) {
|
|
193
204
|
address.push(p);
|
|
@@ -328,7 +339,10 @@ function CreatAPIFacadeClientOld({ socketKey, socket, limit }) {
|
|
|
328
339
|
}
|
|
329
340
|
};
|
|
330
341
|
}
|
|
331
|
-
function CreatAPIFacadeServerOld(
|
|
342
|
+
function CreatAPIFacadeServerOld(params) {
|
|
343
|
+
return (0, old_ommonsServerMini_1.createAPIFacadeServer)(params);
|
|
344
|
+
}
|
|
345
|
+
function CreatAPIFacadeServerOldImpl({ object, socket, socketKey, debug = false }) {
|
|
332
346
|
function ff(obj) {
|
|
333
347
|
return Object.fromEntries(Object.entries(obj).map(([k, v]) => {
|
|
334
348
|
return [
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const Caps: {
|
|
2
|
+
readonly COMPACT: number;
|
|
3
|
+
};
|
|
4
|
+
export type tCaps = number;
|
|
5
|
+
export declare const CAPS_ALL: tCaps;
|
|
6
|
+
export declare const hasCap: (caps: tCaps, c: number) => boolean;
|
|
7
|
+
export type RpcOpt = {
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function optToCaps(opt?: RpcOpt): tCaps;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasCap = exports.CAPS_ALL = exports.Caps = void 0;
|
|
4
|
+
exports.optToCaps = optToCaps;
|
|
5
|
+
exports.Caps = {
|
|
6
|
+
COMPACT: 1 << 0,
|
|
7
|
+
};
|
|
8
|
+
exports.CAPS_ALL = exports.Caps.COMPACT;
|
|
9
|
+
const hasCap = (caps, c) => (caps & c) === c;
|
|
10
|
+
exports.hasCap = hasCap;
|
|
11
|
+
function optToCaps(opt) {
|
|
12
|
+
let c = exports.CAPS_ALL;
|
|
13
|
+
if (opt?.compact === false)
|
|
14
|
+
c &= ~exports.Caps.COMPACT;
|
|
15
|
+
return c;
|
|
16
|
+
}
|