wenay-common2 1.0.45 → 1.0.48
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/lib/Common/Color.d.ts +3 -0
- package/lib/Common/Color.js +11 -3
- package/lib/Common/ObserveAll2/reactive2.d.ts +32 -0
- package/lib/Common/ObserveAll2/reactive2.js +249 -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 -14
- package/lib/Common/async/createIterableObject.js +2 -2
- package/lib/Common/async/waitRun.d.ts +12 -5
- package/lib/Common/async/waitRun.js +75 -45
- package/lib/Common/core/Decorator.d.ts +3 -1
- package/lib/Common/core/Decorator.js +7 -3
- package/lib/Common/core/DeepCompareKeys.js +4 -0
- package/lib/Common/core/MemoFunc.js +2 -2
- package/lib/Common/core/common.d.ts +25 -7
- package/lib/Common/core/common.js +118 -38
- package/lib/Common/data/ByteStream.d.ts +1 -1
- package/lib/Common/data/ByteStream.js +31 -27
- package/lib/Common/data/List.d.ts +6 -1
- package/lib/Common/data/List.js +28 -6
- package/lib/Common/data/ListNodeAnd.js +3 -3
- package/lib/Common/data/objectPath.d.ts +4 -0
- package/lib/Common/data/objectPath.js +8 -3
- package/lib/Common/events/Listen.d.ts +38 -5
- package/lib/Common/events/Listen.js +89 -54
- package/lib/Common/events/SocketBuffer.d.ts +9 -4
- package/lib/Common/events/SocketBuffer.js +1 -0
- package/lib/Common/events/SocketServerHook.d.ts +20 -7
- package/lib/Common/events/SocketServerHook.js +2 -1
- package/lib/Common/events/UseListenTransform.d.ts +8 -3
- package/lib/Common/events/event.d.ts +12 -0
- package/lib/Common/events/event.js +27 -12
- package/lib/Common/events/joinListens.d.ts +2 -0
- package/lib/Common/events/joinListens.js +20 -12
- package/lib/Common/funcTimeWait.d.ts +28 -2
- package/lib/Common/funcTimeWait.js +20 -21
- package/lib/Common/id-pool.js +12 -2
- package/lib/Common/inputAutoStep.js +2 -2
- package/lib/Common/isProxy.d.ts +1 -0
- package/lib/Common/isProxy.js +2 -0
- package/lib/Common/math/Math.d.ts +1 -0
- package/lib/Common/math/Math.js +7 -1
- package/lib/Common/math/other.js +2 -1
- package/lib/Common/math/scoreLana.js +3 -2
- 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-deep.js +1 -6
- package/lib/Common/rcp/listen-socket.d.ts +21 -3
- package/lib/Common/rcp/listen-socket.js +97 -6
- 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/Common/rcp/test.d.ts +1 -0
- package/lib/Common/rcp/test.js +78 -0
- package/lib/Exchange/Bars.d.ts +3 -0
- package/lib/Exchange/Bars.js +9 -4
- package/lib/Exchange/CParams.d.ts +2 -0
- package/lib/Exchange/CParams.js +22 -15
- package/lib/Exchange/MarketData.d.ts +6 -0
- package/lib/Exchange/MarketData.js +5 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/server/WebHook3.d.ts +1 -0
- package/lib/server/WebHook3.js +45 -16
- package/lib/server/fsKeyVolume.js +20 -3
- package/lib/toError/myThrow.d.ts +20 -1
- package/lib/toError/myThrow.js +32 -19
- package/package.json +2 -1
- package/lib/Common/Error/myThrow.d.ts +0 -5
- package/lib/Common/Error/myThrow.js +0 -23
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FuncTimeWait = void 0;
|
|
3
|
+
exports.rateWindow = exports.FuncTimeWait = void 0;
|
|
4
4
|
exports.funcTimeW = funcTimeW;
|
|
5
|
+
exports.createRateWindow = createRateWindow;
|
|
5
6
|
function funcTimeW() {
|
|
6
7
|
const dStatic = {};
|
|
7
8
|
const data = [];
|
|
9
|
+
const sortByTime = (arr) => arr.sort((a, b) => a[0] - b[0]);
|
|
8
10
|
return {
|
|
9
11
|
dStatic,
|
|
10
12
|
data,
|
|
@@ -13,11 +15,13 @@ function funcTimeW() {
|
|
|
13
15
|
dStatic[item.type] = [];
|
|
14
16
|
}
|
|
15
17
|
dStatic[item.type].push([item.timeStamp ?? Date.now(), item.weight]);
|
|
18
|
+
sortByTime(dStatic[item.type]);
|
|
16
19
|
},
|
|
17
20
|
cleanByTime(type, ms = 60 * 1000) {
|
|
18
21
|
const arr = dStatic[type];
|
|
19
22
|
if (!arr || arr.length === 0)
|
|
20
23
|
return;
|
|
24
|
+
sortByTime(arr);
|
|
21
25
|
const timeStamp = Date.now();
|
|
22
26
|
if (arr[0][0] > timeStamp - ms)
|
|
23
27
|
return;
|
|
@@ -33,24 +37,7 @@ function funcTimeW() {
|
|
|
33
37
|
const arr = dStatic[type];
|
|
34
38
|
if (!arr || arr.length === 0)
|
|
35
39
|
return 0;
|
|
36
|
-
|
|
37
|
-
let sum = 0;
|
|
38
|
-
let i = arr.length - 1;
|
|
39
|
-
for (; i >= 0; i--) {
|
|
40
|
-
const [_time, _weight] = arr[i];
|
|
41
|
-
if (_time < timeStamp - ms)
|
|
42
|
-
break;
|
|
43
|
-
sum += _weight;
|
|
44
|
-
}
|
|
45
|
-
if (i >= 0) {
|
|
46
|
-
arr.splice(0, i + 1);
|
|
47
|
-
}
|
|
48
|
-
return sum;
|
|
49
|
-
},
|
|
50
|
-
weightNow(type, ms = 60 * 1000) {
|
|
51
|
-
const arr = dStatic[type];
|
|
52
|
-
if (!arr || arr.length === 0)
|
|
53
|
-
return 0;
|
|
40
|
+
sortByTime(arr);
|
|
54
41
|
const timeStamp = Date.now();
|
|
55
42
|
let sum = 0;
|
|
56
43
|
let i = arr.length - 1;
|
|
@@ -69,13 +56,14 @@ function funcTimeW() {
|
|
|
69
56
|
const arr = dStatic[type];
|
|
70
57
|
if (!arr || arr.length === 0)
|
|
71
58
|
return 0;
|
|
59
|
+
sortByTime(arr);
|
|
72
60
|
let sum = 0;
|
|
73
61
|
let i = arr.length - 1;
|
|
74
62
|
let result = 0;
|
|
75
63
|
for (; i >= 0; i--) {
|
|
76
64
|
sum += arr[i][1];
|
|
77
65
|
if (sum > weight) {
|
|
78
|
-
result = arr[i + 1]?.[0] ?? 0;
|
|
66
|
+
result = arr[i + 1]?.[0] ?? arr[i][0];
|
|
79
67
|
break;
|
|
80
68
|
}
|
|
81
69
|
}
|
|
@@ -88,6 +76,7 @@ function funcTimeW() {
|
|
|
88
76
|
const arr = dStatic[type];
|
|
89
77
|
if (!arr || arr.length === 0)
|
|
90
78
|
return 0;
|
|
79
|
+
sortByTime(arr);
|
|
91
80
|
let sum = 0;
|
|
92
81
|
let i = arr.length - 1;
|
|
93
82
|
for (; i >= 0; i--) {
|
|
@@ -100,7 +89,7 @@ function funcTimeW() {
|
|
|
100
89
|
for (; i >= 0; i--) {
|
|
101
90
|
sum += arr[i][1];
|
|
102
91
|
if (sum > weight) {
|
|
103
|
-
result = arr[i + 1]?.[0] ?? 0;
|
|
92
|
+
result = arr[i + 1]?.[0] ?? arr[i][0];
|
|
104
93
|
break;
|
|
105
94
|
}
|
|
106
95
|
}
|
|
@@ -112,3 +101,13 @@ function funcTimeW() {
|
|
|
112
101
|
};
|
|
113
102
|
}
|
|
114
103
|
exports.FuncTimeWait = funcTimeW();
|
|
104
|
+
function createRateWindow() {
|
|
105
|
+
const w = funcTimeW();
|
|
106
|
+
return {
|
|
107
|
+
...w,
|
|
108
|
+
prune: w.cleanByTime,
|
|
109
|
+
sumWeight: w.weight,
|
|
110
|
+
readyAt: w.byWeight,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.rateWindow = createRateWindow();
|
package/lib/Common/id-pool.js
CHANGED
|
@@ -3,10 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createIdPool = void 0;
|
|
4
4
|
const createIdPool = () => {
|
|
5
5
|
const s = [];
|
|
6
|
+
const free = new Set();
|
|
6
7
|
let n = 0;
|
|
7
8
|
return {
|
|
8
|
-
next: () =>
|
|
9
|
-
|
|
9
|
+
next: () => {
|
|
10
|
+
const id = s.length > 0 ? s.pop() : ++n;
|
|
11
|
+
free.delete(id);
|
|
12
|
+
return id;
|
|
13
|
+
},
|
|
14
|
+
release(id) {
|
|
15
|
+
if (id < 1 || id > n || free.has(id))
|
|
16
|
+
return;
|
|
17
|
+
free.add(id);
|
|
18
|
+
s.push(id);
|
|
19
|
+
}
|
|
10
20
|
};
|
|
11
21
|
};
|
|
12
22
|
exports.createIdPool = createIdPool;
|
|
@@ -30,14 +30,14 @@ function SetAutoStepForElement(element, params = { maxStep: 1 }) {
|
|
|
30
30
|
_digits = digits;
|
|
31
31
|
_step = step;
|
|
32
32
|
if (_min != null) {
|
|
33
|
-
if (Math.abs(_min) % step
|
|
33
|
+
if (Math.abs(_min) % step > 1e-9 && step - Math.abs(_min) % step > 1e-9)
|
|
34
34
|
_min = Math.floor(Math.abs(_min) / step) * step * Math.sign(minDefault);
|
|
35
35
|
element.min = _min + "";
|
|
36
36
|
}
|
|
37
37
|
element.step = step + "";
|
|
38
38
|
return step;
|
|
39
39
|
}
|
|
40
|
-
let modeAuto = !_step || (_step < 1 && Math.log10(_step - Math.
|
|
40
|
+
let modeAuto = !_step || (_step < 1 && Math.abs(Math.log10(_step) - Math.round(Math.log10(_step))) < 1e-9);
|
|
41
41
|
const modeAuto0 = modeAuto;
|
|
42
42
|
if (modeAuto) {
|
|
43
43
|
calculateStep((_step ? (Math.round(parseFloat(element.value) / _step) * _step) : element.value) + "");
|
package/lib/Common/isProxy.d.ts
CHANGED
package/lib/Common/isProxy.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installProxyTracking = void 0;
|
|
3
4
|
exports.isProxyInit = isProxyInit;
|
|
4
5
|
exports.isProxy = isProxy;
|
|
5
6
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -31,6 +32,7 @@ function isProxyInit() {
|
|
|
31
32
|
init = true;
|
|
32
33
|
set();
|
|
33
34
|
}
|
|
35
|
+
exports.installProxyTracking = isProxyInit;
|
|
34
36
|
function isProxy(a) {
|
|
35
37
|
if (nodeIsProxy)
|
|
36
38
|
return nodeIsProxy(a);
|
|
@@ -5,6 +5,7 @@ type tCorrelationByBuffer = {
|
|
|
5
5
|
export declare function CorrelationRollingByBuffer(data: tCorrelationByBuffer): {
|
|
6
6
|
init(data: tCorrelationByBuffer): void;
|
|
7
7
|
clear(data?: tCorrelationByBuffer): void;
|
|
8
|
+
remove(key1: any, key2?: any): void;
|
|
8
9
|
corr2(val1: number, val2: number, key1: any, key2: any): {
|
|
9
10
|
corr: number;
|
|
10
11
|
};
|
package/lib/Common/math/Math.js
CHANGED
|
@@ -26,8 +26,14 @@ function CorrelationRollingByBuffer(data) {
|
|
|
26
26
|
if (data)
|
|
27
27
|
this.init(data);
|
|
28
28
|
},
|
|
29
|
+
remove(key1, key2) {
|
|
30
|
+
if (key2 === undefined)
|
|
31
|
+
map.delete(key1);
|
|
32
|
+
else
|
|
33
|
+
map.get(key1)?.delete(key2);
|
|
34
|
+
},
|
|
29
35
|
corr2(val1, val2, key1, key2) {
|
|
30
|
-
const buffer =
|
|
36
|
+
const buffer = getBuffer(key1, key2);
|
|
31
37
|
buffer.history1.push(val1);
|
|
32
38
|
buffer.history2.push(val2);
|
|
33
39
|
let dropped1 = 0;
|
package/lib/Common/math/other.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
function PriceTOSumPercent(price) {
|
|
3
|
-
|
|
3
|
+
const base = price[0];
|
|
4
|
+
return base ? price.map(e => e / base) : price.map(() => 0);
|
|
4
5
|
}
|
|
5
6
|
function strategyStepOfStepAll(symbols_) {
|
|
6
7
|
const symbols = symbols_.map(e => ({ price: PriceTOSumPercent(e.price), key: e.key }));
|
|
@@ -22,7 +22,8 @@ function strategyStepOfStepAllL(symbols) {
|
|
|
22
22
|
return result;
|
|
23
23
|
}
|
|
24
24
|
function PriceTOSumPercentL(price) {
|
|
25
|
-
|
|
25
|
+
const base = price[0];
|
|
26
|
+
return base ? price.map(e => e / base) : price.map(() => 0);
|
|
26
27
|
}
|
|
27
28
|
function strategyStepOfStepL({ t1, t2, minK: _minK, percentM: _percentM, onlyBuy: _onlyBuy }) {
|
|
28
29
|
const onlyBuy = !!_onlyBuy;
|
|
@@ -62,6 +63,6 @@ function strategyStepOfStepL({ t1, t2, minK: _minK, percentM: _percentM, onlyBuy
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
const k1 = day.profitDays / result1.length;
|
|
65
|
-
const k2 = day.profit / ((day.profit + day.loss) || 1);
|
|
66
|
+
const k2 = day.profit / ((day.profit + Math.abs(day.loss)) || 1);
|
|
66
67
|
return k1 * k2;
|
|
67
68
|
}
|
|
@@ -4,3 +4,5 @@ export declare function disable(): void;
|
|
|
4
4
|
export declare function __LineFile(lvl?: number): string;
|
|
5
5
|
export declare function __LineFile2(lvl?: number): string;
|
|
6
6
|
export declare function __LineFiles(lvlStart?: number, lvlEnd?: number | undefined): string[];
|
|
7
|
+
export declare const callerLine: typeof __LineFile2;
|
|
8
|
+
export declare const callerLines: typeof __LineFiles;
|
|
@@ -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;
|
|
@@ -30,12 +30,7 @@ function deepMapByKeysList(obj1, keys, func) {
|
|
|
30
30
|
return Object.fromEntries(Object.entries(obj1).map(([k, v]) => [k, deepMapByKeysList(v, keys, func)]));
|
|
31
31
|
}
|
|
32
32
|
function deepMapByKeys(obj1, obj2, func) {
|
|
33
|
-
|
|
34
|
-
return obj1;
|
|
35
|
-
const keys = Object.keys(obj2);
|
|
36
|
-
if (matchKeysList(obj1, keys))
|
|
37
|
-
return func(obj1);
|
|
38
|
-
return Object.fromEntries(Object.entries(obj1).map(([k, v]) => [k, deepMapByKeysList(v, keys, func)]));
|
|
33
|
+
return deepMapByKeysList(obj1, Object.keys(obj2), func);
|
|
39
34
|
}
|
|
40
35
|
const NOOP_LISTEN = (0, Listen_1.funcListenCallbackBase)((_e) => { });
|
|
41
36
|
function deepListenFirst(obj, data) {
|
|
@@ -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 {};
|