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
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.CCachedValue2 = exports.CCachedValueT = exports.WeakMapExt = exports.MapExt = exports.CObjectID = exports.Mutex = exports.MyTimerInterval = exports.CancelablePromise = exports.CancelToken = exports.VirtualItems = exports.ArraySet = exports.ArrayMap = exports.StructSet = exports.StructMap = exports.MyNumMap = exports.MyMap = exports.__MyMap = exports.BSearchAsync = exports.E_MATCH = exports.E_SORTMODE = exports.CBase = void 0;
|
|
36
|
+
exports.CCachedValue2 = exports.CCachedValueT = exports.WeakMapExt = exports.MapExt = exports.CObjectID = exports.Mutex = exports.MyTimerInterval = exports.CancelablePromise = exports.CancelToken = exports.VirtualItems = exports.ArraySet = exports.ArrayMap = exports.StructSet = exports.StructMap = exports.MyNumMap = exports.MyMap = exports.__MyMap = exports.formatSig = exports.roundSig = exports.formatAuto = exports.BSearchAsync = exports.E_MATCH = exports.E_SORTMODE = exports.CBase = exports.isEqual = exports.clone = void 0;
|
|
37
37
|
exports.GetEnumKeys = GetEnumKeys;
|
|
38
38
|
exports.isDate = isDate;
|
|
39
39
|
exports.shallowClone = shallowClone;
|
|
@@ -55,10 +55,13 @@ exports.BSearchValueInRange = BSearchValueInRange;
|
|
|
55
55
|
exports.BSearchNearest = BSearchNearest;
|
|
56
56
|
exports._BSearchNearest = _BSearchNearest;
|
|
57
57
|
exports.NormalizeDouble = NormalizeDouble;
|
|
58
|
+
exports.round = round;
|
|
58
59
|
exports.MaxCommonDivisor = MaxCommonDivisor;
|
|
59
60
|
exports.MaxCommonDivisorOnArray = MaxCommonDivisorOnArray;
|
|
61
|
+
exports.gcd = gcd;
|
|
60
62
|
exports.GetDblPrecision2 = GetDblPrecision2;
|
|
61
63
|
exports.GetDblPrecision = GetDblPrecision;
|
|
64
|
+
exports.decimals = decimals;
|
|
62
65
|
exports.DblToStrAuto = DblToStrAuto;
|
|
63
66
|
exports.NormalizeDoubleAnd = NormalizeDoubleAnd;
|
|
64
67
|
exports.DblToStrAnd = DblToStrAnd;
|
|
@@ -95,36 +98,43 @@ function shallowClone(val) {
|
|
|
95
98
|
function _deepClone(src, map) {
|
|
96
99
|
if (!src || typeof src != "object")
|
|
97
100
|
return src;
|
|
101
|
+
const srcObj = src;
|
|
102
|
+
const cached = map?.get(srcObj);
|
|
103
|
+
if (cached)
|
|
104
|
+
return cached;
|
|
105
|
+
const cloneValue = (value) => value && typeof value == "object"
|
|
106
|
+
? _deepClone(value, map)
|
|
107
|
+
: typeof value == "function"
|
|
108
|
+
? value.bind(newobject)
|
|
109
|
+
: value;
|
|
98
110
|
let newobject = src instanceof Array ? [] : {};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
newobject = new Map(src.entries());
|
|
103
|
-
else { }
|
|
104
|
-
if (src instanceof Date)
|
|
111
|
+
map ??= new Map();
|
|
112
|
+
map.set(srcObj, newobject);
|
|
113
|
+
if (src instanceof Date) {
|
|
105
114
|
newobject = new Date(src);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
newobject
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
map.set(srcObj, newobject);
|
|
116
|
+
return newobject;
|
|
117
|
+
}
|
|
118
|
+
if (src instanceof Set) {
|
|
119
|
+
newobject = new Set();
|
|
120
|
+
map.set(srcObj, newobject);
|
|
121
|
+
for (const value of src)
|
|
122
|
+
newobject.add(cloneValue(value));
|
|
123
|
+
return newobject;
|
|
124
|
+
}
|
|
125
|
+
if (src instanceof Map) {
|
|
126
|
+
newobject = new Map();
|
|
127
|
+
map.set(srcObj, newobject);
|
|
128
|
+
for (const [key, value] of src)
|
|
129
|
+
newobject.set(cloneValue(key), cloneValue(value));
|
|
130
|
+
return newobject;
|
|
131
|
+
}
|
|
132
|
+
for (let [key, value] of Object.entries(src))
|
|
133
|
+
newobject[key] = cloneValue(value);
|
|
125
134
|
return newobject;
|
|
126
135
|
}
|
|
127
136
|
function deepClone(object) { return _deepClone(object); }
|
|
137
|
+
exports.clone = deepClone;
|
|
128
138
|
function deepCloneMutable(value) { return deepClone(value); }
|
|
129
139
|
function deepCloneObject(object) {
|
|
130
140
|
if (object == undefined)
|
|
@@ -140,6 +150,30 @@ function readonlyFull(arg) { return arg; }
|
|
|
140
150
|
function deepEqual(object1, object2) {
|
|
141
151
|
if (object1 == object2)
|
|
142
152
|
return true;
|
|
153
|
+
if (object1 == null || object2 == null)
|
|
154
|
+
return false;
|
|
155
|
+
if (typeof object1 != "object" || typeof object2 != "object")
|
|
156
|
+
return false;
|
|
157
|
+
if (object1.constructor !== object2.constructor)
|
|
158
|
+
return false;
|
|
159
|
+
if (object1 instanceof Date)
|
|
160
|
+
return object1.getTime() === object2.getTime();
|
|
161
|
+
if (object1 instanceof Map) {
|
|
162
|
+
if (object1.size !== object2.size)
|
|
163
|
+
return false;
|
|
164
|
+
for (const [k, v] of object1)
|
|
165
|
+
if (!object2.has(k) || !deepEqual(v, object2.get(k)))
|
|
166
|
+
return false;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
if (object1 instanceof Set) {
|
|
170
|
+
if (object1.size !== object2.size)
|
|
171
|
+
return false;
|
|
172
|
+
for (const v of object1)
|
|
173
|
+
if (!object2.has(v))
|
|
174
|
+
return false;
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
143
177
|
const keys1 = Object.keys(object1);
|
|
144
178
|
const keys2 = Object.keys(object2);
|
|
145
179
|
if (keys1.length != keys2.length)
|
|
@@ -155,6 +189,7 @@ function deepEqual(object1, object2) {
|
|
|
155
189
|
}
|
|
156
190
|
return true;
|
|
157
191
|
}
|
|
192
|
+
exports.isEqual = deepEqual;
|
|
158
193
|
function shallowEqual(object1, object2) {
|
|
159
194
|
if (!object1 || !object2)
|
|
160
195
|
return object1 == object2;
|
|
@@ -290,9 +325,9 @@ function BSearchValueInRange(from, to, precision, compare, matchMode) {
|
|
|
290
325
|
if (precision == 0)
|
|
291
326
|
throw new Error("precision=0");
|
|
292
327
|
let count = Math.round((to - from) / precision) + 1;
|
|
293
|
-
const sortMode =
|
|
328
|
+
const sortMode = precision > 0 ? E_SORTMODE.ASCEND : E_SORTMODE.DESCEND;
|
|
294
329
|
count = Math.abs(count);
|
|
295
|
-
let i = BSearchIndex(count, (index) => compare(from + precision * index), matchMode);
|
|
330
|
+
let i = BSearchIndex(count, (index) => compare(from + precision * index), matchMode, sortMode);
|
|
296
331
|
if (i == -1)
|
|
297
332
|
return null;
|
|
298
333
|
return from + precision * i;
|
|
@@ -311,7 +346,7 @@ function _BSearchNearest(array, searchValue, arrayGetValue, maxDelta) {
|
|
|
311
346
|
let indexes = [];
|
|
312
347
|
if (i == -1)
|
|
313
348
|
i = array.length - 1;
|
|
314
|
-
else if (i
|
|
349
|
+
else if (i > 0)
|
|
315
350
|
indexes.push(i - 1);
|
|
316
351
|
indexes.push(i);
|
|
317
352
|
let delta = maxDelta ?? Number.MAX_VALUE;
|
|
@@ -326,17 +361,18 @@ function _BSearchNearest(array, searchValue, arrayGetValue, maxDelta) {
|
|
|
326
361
|
return index;
|
|
327
362
|
}
|
|
328
363
|
function NormalizeDouble(value, digits) { let factor = 10 ** digits; return Math.round(value * factor) / factor; }
|
|
364
|
+
function round(value, digits = 0) { return NormalizeDouble(value, digits); }
|
|
329
365
|
function fabs(value) { return Math.abs(value); }
|
|
330
|
-
function
|
|
366
|
+
function roundInt(value) { return Math.round(value); }
|
|
331
367
|
function __GetMaxCommonDivisor(a, b, digits) {
|
|
332
368
|
let precis = 0.1 ** (digits) / 2;
|
|
333
369
|
while (true) {
|
|
334
370
|
if (b < precis)
|
|
335
371
|
return NormalizeDouble(a, digits);
|
|
336
|
-
a = fabs(a -
|
|
372
|
+
a = fabs(a - roundInt(a / b) * b);
|
|
337
373
|
if (a < precis)
|
|
338
374
|
return NormalizeDouble(b, digits);
|
|
339
|
-
b = fabs(b -
|
|
375
|
+
b = fabs(b - roundInt(b / a) * a);
|
|
340
376
|
}
|
|
341
377
|
}
|
|
342
378
|
function __GetMaxCommonDivisorInteger(a, b) {
|
|
@@ -372,6 +408,11 @@ function MaxCommonDivisorOnArray(values, precisDigits = 8) {
|
|
|
372
408
|
}
|
|
373
409
|
return divis;
|
|
374
410
|
}
|
|
411
|
+
function gcd(a, b, digits) {
|
|
412
|
+
if (typeof a == "number")
|
|
413
|
+
return MaxCommonDivisor(a, b, digits ?? 8);
|
|
414
|
+
return MaxCommonDivisorOnArray(a, b ?? 8);
|
|
415
|
+
}
|
|
375
416
|
function GetDblPrecision2(value, mindigits, maxdigits) {
|
|
376
417
|
maxdigits = Math.min(maxdigits, 16);
|
|
377
418
|
let epsilon = Math.pow(0.1, maxdigits + 1);
|
|
@@ -386,6 +427,7 @@ function GetDblPrecision2(value, mindigits, maxdigits) {
|
|
|
386
427
|
}
|
|
387
428
|
;
|
|
388
429
|
function GetDblPrecision(value, maxdigits = 8) { return GetDblPrecision2(value, 0, maxdigits); }
|
|
430
|
+
function decimals(value, maxDigits = 8, minDigits = 0) { return GetDblPrecision2(value, minDigits, maxDigits); }
|
|
389
431
|
function DblToStrAuto2(value, minprecis, maxprecis) { return value?.toFixed(GetDblPrecision2(value, minprecis, maxprecis)); }
|
|
390
432
|
function DblToStrAuto(value, maxprecis = 8) {
|
|
391
433
|
let digits = maxprecis;
|
|
@@ -396,6 +438,7 @@ function DblToStrAuto(value, maxprecis = 8) {
|
|
|
396
438
|
maxprecis = 0;
|
|
397
439
|
return DblToStrAuto2(value, 0, maxprecis);
|
|
398
440
|
}
|
|
441
|
+
exports.formatAuto = DblToStrAuto;
|
|
399
442
|
function NormalizeDoubleAnd(a, options) {
|
|
400
443
|
if (a == 0)
|
|
401
444
|
return a;
|
|
@@ -414,6 +457,7 @@ function NormalizeDoubleAnd(a, options) {
|
|
|
414
457
|
return func(a / (10 ** (k - w))) * (10 ** (k - w));
|
|
415
458
|
return func(a / (10 ** (k - w))) * (10 ** (k - w));
|
|
416
459
|
}
|
|
460
|
+
exports.roundSig = NormalizeDoubleAnd;
|
|
417
461
|
function DblToStrAnd(a, options) {
|
|
418
462
|
let { digitsPoint: w = 4, digitsR: r } = options ?? {};
|
|
419
463
|
if (!r && a % 1.0 == 0)
|
|
@@ -431,6 +475,7 @@ function DblToStrAnd(a, options) {
|
|
|
431
475
|
return (func(a / (10 ** (k - w + 1))) * (10 ** (k - w + 1))).toString();
|
|
432
476
|
return (func(a / (10 ** (k - w + 1))) * (10 ** (k - w + 1))).toFixed(w - k - 1);
|
|
433
477
|
}
|
|
478
|
+
exports.formatSig = DblToStrAnd;
|
|
434
479
|
function testDblToStrAnd() {
|
|
435
480
|
const r = 0.047952487787;
|
|
436
481
|
for (let i = -10; i < 10; i++) {
|
|
@@ -506,7 +551,7 @@ class __MyMap {
|
|
|
506
551
|
Set(key, value) { this.map[key.valueOf()] = { key, value }; this.keys = null; this.OnModify?.(key); }
|
|
507
552
|
Get(key) { let pair = this.map[key.valueOf()]; return pair ? pair.value : undefined; }
|
|
508
553
|
Contains(key) { return this.map[key.valueOf()] != undefined; }
|
|
509
|
-
TryAdd(key, value) { if (
|
|
554
|
+
TryAdd(key, value) { if (this.Contains(key))
|
|
510
555
|
return false; this.Set(key, value); return true; }
|
|
511
556
|
Add(key, value) { if (!this.TryAdd(key, value))
|
|
512
557
|
throw new Error(`Key ${key} is already exists for ${typeof value}`); }
|
|
@@ -519,10 +564,17 @@ class __MyMap {
|
|
|
519
564
|
get Values() { if (!this.keys)
|
|
520
565
|
this.createArrays(); return this.values; }
|
|
521
566
|
assign(other) { this.map = other.map.clone(); this.keys = other.keys; this.values = other.values; }
|
|
567
|
+
set(key, value) { this.Set(key, value); }
|
|
568
|
+
get(key) { return this.Get(key); }
|
|
569
|
+
has(key) { return this.Contains(key); }
|
|
570
|
+
delete(key) { this.Remove(key); }
|
|
571
|
+
clear() { this.Clear(); }
|
|
572
|
+
get size() { return this.Count(); }
|
|
522
573
|
}
|
|
523
574
|
exports.__MyMap = __MyMap;
|
|
524
575
|
class MyMap extends __MyMap {
|
|
525
576
|
Clone() { let newobj = new MyMap(); newobj.assign(this); return newobj; }
|
|
577
|
+
clone() { return this.Clone(); }
|
|
526
578
|
}
|
|
527
579
|
exports.MyMap = MyMap;
|
|
528
580
|
class MyNumMap extends __MyMap {
|
|
@@ -531,6 +583,7 @@ class MyNumMap extends __MyMap {
|
|
|
531
583
|
return CreateArrayProxy(this, (i) => this.Get(i), (key, value) => this.Set(key, value ?? (() => { throw new Error("undefined value"); })()));
|
|
532
584
|
}
|
|
533
585
|
Clone() { let newobj = new MyNumMap(); newobj.assign(this); return newobj; }
|
|
586
|
+
clone() { return this.Clone(); }
|
|
534
587
|
}
|
|
535
588
|
exports.MyNumMap = MyNumMap;
|
|
536
589
|
class StructMap {
|
|
@@ -563,7 +616,20 @@ class StructMap {
|
|
|
563
616
|
}
|
|
564
617
|
return obj;
|
|
565
618
|
}
|
|
566
|
-
has(key) {
|
|
619
|
+
has(key) {
|
|
620
|
+
let items = key instanceof Array ? key : Object.values(key);
|
|
621
|
+
if (items.length == 0)
|
|
622
|
+
return false;
|
|
623
|
+
let obj = this._data;
|
|
624
|
+
for (let item of items) {
|
|
625
|
+
if (typeof obj != "object" && typeof obj != "function")
|
|
626
|
+
return false;
|
|
627
|
+
if (obj == null || !(item in obj))
|
|
628
|
+
return false;
|
|
629
|
+
obj = obj[item];
|
|
630
|
+
}
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
567
633
|
keys() { return this._keys; }
|
|
568
634
|
values() { return this._values; }
|
|
569
635
|
*entries() { for (let [i, key] of this._keys.entries())
|
|
@@ -606,15 +672,17 @@ class CancelToken {
|
|
|
606
672
|
_cancel = false;
|
|
607
673
|
isCancelled() { return this._cancel; }
|
|
608
674
|
cancel() { this._cancel = true; }
|
|
675
|
+
get aborted() { return this.isCancelled(); }
|
|
676
|
+
abort() { this.cancel(); }
|
|
609
677
|
}
|
|
610
678
|
exports.CancelToken = CancelToken;
|
|
611
679
|
class CancelablePromise extends Promise {
|
|
612
|
-
static _rejectTmp;
|
|
613
680
|
_reject;
|
|
614
681
|
_onCancel;
|
|
615
682
|
constructor(executor, onCancel) {
|
|
616
|
-
|
|
617
|
-
|
|
683
|
+
let rejectCaptured;
|
|
684
|
+
super((resolve, reject) => { rejectCaptured = reject; executor(resolve, reject); });
|
|
685
|
+
this._reject = rejectCaptured;
|
|
618
686
|
this._onCancel = onCancel;
|
|
619
687
|
}
|
|
620
688
|
cancel(msg) { if (this._onCancel)
|
|
@@ -674,6 +742,7 @@ class Mutex {
|
|
|
674
742
|
unlock();
|
|
675
743
|
}
|
|
676
744
|
}
|
|
745
|
+
runExclusive(fn) { return this.dispatch(fn); }
|
|
677
746
|
static createLock() { return (new Mutex).lock(); }
|
|
678
747
|
}
|
|
679
748
|
exports.Mutex = Mutex;
|
|
@@ -716,11 +785,22 @@ class CObjectID {
|
|
|
716
785
|
}
|
|
717
786
|
exports.CObjectID = CObjectID;
|
|
718
787
|
const stringifyDefault = JSON.stringify;
|
|
719
|
-
JSON.stringify = (value, replacer, space) =>
|
|
788
|
+
JSON.stringify = (value, replacer, space) => {
|
|
789
|
+
const allow = Array.isArray(replacer)
|
|
790
|
+
? new Set(replacer.filter(v => typeof v == "string" || typeof v == "number").map(String))
|
|
791
|
+
: null;
|
|
792
|
+
return stringifyDefault(value, (key, val) => {
|
|
793
|
+
if (allow && key !== "" && !allow.has(key))
|
|
794
|
+
return undefined;
|
|
795
|
+
const next = val instanceof CObjectID ? val.value + "" : val;
|
|
796
|
+
return typeof replacer == "function" ? replacer(key, next) : next;
|
|
797
|
+
}, space);
|
|
798
|
+
};
|
|
720
799
|
class MapExt extends Map {
|
|
721
800
|
immutArray;
|
|
722
801
|
set(key, value) { this.immutArray = undefined; return super.set(key, value); }
|
|
723
802
|
delete(key) { this.immutArray = undefined; return super.delete(key); }
|
|
803
|
+
clear() { this.immutArray = undefined; return super.clear(); }
|
|
724
804
|
valuesArrayImmutable() { return this.immutArray ??= [...this.values()]; }
|
|
725
805
|
getOrSetFunc(key, val) {
|
|
726
806
|
let v = this.get(key);
|
|
@@ -39,7 +39,7 @@ export declare class ByteStreamW {
|
|
|
39
39
|
pushNumber(value: number, type: NumericTypes | Nullable<NumericTypes>): boolean;
|
|
40
40
|
pushNumbers(values: readonly number[], type: NumericTypes | Nullable<NumericTypes>): this | null;
|
|
41
41
|
pushArrayByFunc<T>(array: Iterable<T>, func: (stream: ByteStreamW, item: T) => boolean | void, maxlength?: number): this | null;
|
|
42
|
-
protected _getWriteFuncForNumeric(type: NumericTypes | Nullable<NumericTypes>): (stream: ByteStreamW, value: number) => boolean;
|
|
42
|
+
protected _getWriteFuncForNumeric(type: NumericTypes | Nullable<NumericTypes>): (stream: ByteStreamW, value: number | null) => boolean;
|
|
43
43
|
pushArrayNumeric(array: Iterable<number>, type: NumericTypes | Nullable<NumericTypes>, maxlength?: number): this | null;
|
|
44
44
|
pushArray<T extends WritableToBytes>(array: Iterable<T> | Int8Array | Uint8Array, maxlength?: number): this | null;
|
|
45
45
|
pushArrayOfNullable<T extends WritableToBytes | null>(array: Iterable<T>, maxlength?: number): this | null;
|
|
@@ -4,7 +4,10 @@ exports.ByteStreamR = exports.ByteStreamW = exports.Nullable = void 0;
|
|
|
4
4
|
exports.nullable = nullable;
|
|
5
5
|
function createCopyOfBuffer(src, length = src.byteLength) {
|
|
6
6
|
let dst = new ArrayBuffer(length);
|
|
7
|
-
|
|
7
|
+
const bytes = src instanceof DataView
|
|
8
|
+
? new Uint8Array(src.buffer, src.byteOffset, Math.min(src.byteLength, length))
|
|
9
|
+
: new Uint8Array(src, 0, Math.min(src.byteLength, length));
|
|
10
|
+
new Uint8Array(dst).set(bytes);
|
|
8
11
|
return dst;
|
|
9
12
|
}
|
|
10
13
|
class Nullable {
|
|
@@ -45,7 +48,7 @@ class ByteStreamW {
|
|
|
45
48
|
_isThrowable = true;
|
|
46
49
|
_buffer() { return this._view?.buffer; }
|
|
47
50
|
resize(size) {
|
|
48
|
-
let buf = createCopyOfBuffer(this.
|
|
51
|
+
let buf = createCopyOfBuffer(this._view, size);
|
|
49
52
|
this._view = new DataView(buf);
|
|
50
53
|
}
|
|
51
54
|
constructor(view) {
|
|
@@ -57,7 +60,7 @@ class ByteStreamW {
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
get length() { return this._pos; }
|
|
60
|
-
get data() { return new DataView(this._buffer(),
|
|
63
|
+
get data() { return new DataView(this._buffer(), this._view.byteOffset, this._pos); }
|
|
61
64
|
noThrow() { let other = new ByteStreamW(this._view); other._pos = this._pos; other._isThrowable = false; return other; }
|
|
62
65
|
_ensureAllocation(bytes) {
|
|
63
66
|
let minSize = this._pos + bytes;
|
|
@@ -73,18 +76,9 @@ class ByteStreamW {
|
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
|
-
_setInt8(pos, value) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this._view.setUint8(pos, value); }
|
|
80
|
-
_setInt16(pos, value) { if ((value & 1 << 15) != 0)
|
|
81
|
-
this._view.setInt16(pos, value);
|
|
82
|
-
else
|
|
83
|
-
this._view.setUint16(pos, value); }
|
|
84
|
-
_setInt32(pos, value) { if ((value & 1 << 31) != 0)
|
|
85
|
-
this._view.setInt32(pos, value);
|
|
86
|
-
else
|
|
87
|
-
this._view.setUint32(pos, value); }
|
|
79
|
+
_setInt8(pos, value) { this._view.setInt8(pos, value); }
|
|
80
|
+
_setInt16(pos, value) { this._view.setInt16(pos, value); }
|
|
81
|
+
_setInt32(pos, value) { this._view.setInt32(pos, value); }
|
|
88
82
|
_push(value, bytes, isInteger) {
|
|
89
83
|
let pos = this._pos;
|
|
90
84
|
this._ensureAllocation(bytes);
|
|
@@ -110,11 +104,11 @@ class ByteStreamW {
|
|
|
110
104
|
break;
|
|
111
105
|
case 6:
|
|
112
106
|
this._setInt32(pos, value);
|
|
113
|
-
this._setInt16(pos + 4, value /
|
|
107
|
+
this._setInt16(pos + 4, Math.floor(value / 0x100000000));
|
|
114
108
|
break;
|
|
115
109
|
case 8:
|
|
116
110
|
this._setInt32(pos, value);
|
|
117
|
-
this._setInt32(pos + 4, value /
|
|
111
|
+
this._setInt32(pos + 4, Math.floor(value / 0x100000000));
|
|
118
112
|
break;
|
|
119
113
|
default: throw ("Wrong byte length: " + bytes);
|
|
120
114
|
}
|
|
@@ -175,7 +169,15 @@ class ByteStreamW {
|
|
|
175
169
|
let typeInfo = getNumericTypeInfo(type);
|
|
176
170
|
if (!typeInfo)
|
|
177
171
|
throw ("Wrong type: " + type);
|
|
178
|
-
return (stream, value) => {
|
|
172
|
+
return (stream, value) => {
|
|
173
|
+
if (isNullable) {
|
|
174
|
+
if (stream.pushBool(value != null) == null)
|
|
175
|
+
return false;
|
|
176
|
+
if (value == null)
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return stream._push(value, typeInfo.size, typeInfo.integer) != null;
|
|
180
|
+
};
|
|
179
181
|
}
|
|
180
182
|
pushArrayNumeric(array, type, maxlength) {
|
|
181
183
|
return this.pushArrayByFunc(array, this._getWriteFuncForNumeric(type), maxlength);
|
|
@@ -186,10 +188,7 @@ class ByteStreamW {
|
|
|
186
188
|
this._ensureAllocation(length + 4);
|
|
187
189
|
this.pushInt32(length);
|
|
188
190
|
let arrayClass = (array instanceof Int8Array) ? Int8Array : Uint8Array;
|
|
189
|
-
|
|
190
|
-
array = new arrayClass(array.buffer, 0, length);
|
|
191
|
-
}
|
|
192
|
-
new arrayClass(this._buffer()).set(array, this._pos);
|
|
191
|
+
new arrayClass(this._buffer(), this._view.byteOffset + this._pos, length).set(array.subarray(0, length));
|
|
193
192
|
this._pos += length;
|
|
194
193
|
return this;
|
|
195
194
|
}
|
|
@@ -259,10 +258,10 @@ class ByteStreamR_ {
|
|
|
259
258
|
switch (bytes) {
|
|
260
259
|
case 1: return view.getInt8(pos);
|
|
261
260
|
case 2: return view.getInt16(pos);
|
|
262
|
-
case 3: return view.
|
|
261
|
+
case 3: return view.getUint16(pos) + (view.getInt8(pos + 2) << 16);
|
|
263
262
|
case 4: return view.getInt32(pos);
|
|
264
|
-
case 6: return view.
|
|
265
|
-
case 8: return view.
|
|
263
|
+
case 6: return view.getUint32(pos) + view.getInt16(pos + 4) * 0x100000000;
|
|
264
|
+
case 8: return view.getUint32(pos) + view.getInt32(pos + 4) * 0x100000000;
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
else {
|
|
@@ -271,8 +270,8 @@ class ByteStreamR_ {
|
|
|
271
270
|
case 2: return view.getUint16(pos);
|
|
272
271
|
case 3: return view.getUint16(pos) | (view.getUint8(pos + 2) << 16);
|
|
273
272
|
case 4: return view.getUint32(pos);
|
|
274
|
-
case 6: return view.getUint32(pos)
|
|
275
|
-
case 8: return view.getUint32(pos)
|
|
273
|
+
case 6: return view.getUint32(pos) + view.getUint16(pos + 4) * 0x100000000;
|
|
274
|
+
case 8: return view.getUint32(pos) + view.getUint32(pos + 4) * 0x100000000;
|
|
276
275
|
}
|
|
277
276
|
}
|
|
278
277
|
}
|
|
@@ -350,6 +349,11 @@ class ByteStreamR_ {
|
|
|
350
349
|
let size = this.readUint32();
|
|
351
350
|
if (size == null)
|
|
352
351
|
return null;
|
|
352
|
+
if (this._pos + size > this._view.byteLength)
|
|
353
|
+
if (this.isThrowable)
|
|
354
|
+
throw ("Array read out of range");
|
|
355
|
+
else
|
|
356
|
+
return null;
|
|
353
357
|
let bufpos = this._view.byteOffset + this._pos;
|
|
354
358
|
const out = new arrayClass(this._view.buffer.slice(bufpos, bufpos + size));
|
|
355
359
|
this._pos += size;
|
|
@@ -24,13 +24,14 @@ export declare class CList<T, TNode extends ListNode<T> = ListNode<T>> implement
|
|
|
24
24
|
get last(): CListNode<T> | undefined;
|
|
25
25
|
get count(): number;
|
|
26
26
|
get length(): number;
|
|
27
|
+
get size(): number;
|
|
27
28
|
readonly [Symbol.iterator]: () => Generator<TNode, void, unknown>;
|
|
28
29
|
constructor(values?: Iterable<T>);
|
|
29
30
|
nodes(): Generator<TNode, void, unknown>;
|
|
30
31
|
values(): Generator<T, void, unknown>;
|
|
31
32
|
reversedNodes(): Generator<TNode, void, unknown>;
|
|
32
33
|
reversedValues(): Generator<T, void, unknown>;
|
|
33
|
-
entries(): Generator<
|
|
34
|
+
entries(): Generator<readonly [number, T], void, unknown>;
|
|
34
35
|
next(node: ListNode<T>): TNode | undefined;
|
|
35
36
|
prev(node: ListNode<T>): TNode | undefined;
|
|
36
37
|
find(value: T): TNode | undefined;
|
|
@@ -53,6 +54,10 @@ export declare class CList<T, TNode extends ListNode<T> = ListNode<T>> implement
|
|
|
53
54
|
delete(node: ListNode<T>): void;
|
|
54
55
|
deleteFirst(): void;
|
|
55
56
|
deleteLast(): void;
|
|
57
|
+
push(value: T): ListNode<T>;
|
|
58
|
+
unshift(value: T): ListNode<T>;
|
|
59
|
+
pop(): T | undefined;
|
|
60
|
+
shift(): T | undefined;
|
|
56
61
|
clear(): void;
|
|
57
62
|
private validateNode;
|
|
58
63
|
private newNode;
|
package/lib/Common/data/List.js
CHANGED
|
@@ -18,18 +18,24 @@ class CList {
|
|
|
18
18
|
get last() { return this._last; }
|
|
19
19
|
get count() { return this._count; }
|
|
20
20
|
get length() { return this._count; }
|
|
21
|
+
get size() { return this._count; }
|
|
21
22
|
[Symbol.iterator] = this.nodes;
|
|
22
23
|
constructor(values = []) { for (let value of values)
|
|
23
24
|
this.add(value); }
|
|
24
|
-
*nodes() { for (let node = this._first
|
|
25
|
-
yield node;
|
|
25
|
+
*nodes() { for (let node = this._first; node != null;) {
|
|
26
|
+
yield node;
|
|
27
|
+
node = node.next;
|
|
28
|
+
} }
|
|
26
29
|
*values() { for (let node of this)
|
|
27
30
|
yield node.value; }
|
|
28
|
-
*reversedNodes() { for (let node = this._last
|
|
29
|
-
yield node;
|
|
31
|
+
*reversedNodes() { for (let node = this._last; node != null;) {
|
|
32
|
+
yield node;
|
|
33
|
+
node = node.prev;
|
|
34
|
+
} }
|
|
30
35
|
*reversedValues() { for (let node of this.reversedNodes())
|
|
31
36
|
yield node.value; }
|
|
32
|
-
*entries() {
|
|
37
|
+
*entries() { let i = 0; for (let node of this.nodes())
|
|
38
|
+
yield [i++, node.value]; }
|
|
33
39
|
next(node) { return this.validateNode(node) ? node.next : (() => { throw "Wrong node list"; })(); }
|
|
34
40
|
;
|
|
35
41
|
prev(node) { return this.validateNode(node) ? node.prev : (() => { throw "Wrong node list"; })(); }
|
|
@@ -102,7 +108,16 @@ class CList {
|
|
|
102
108
|
let newNode = this.newNode(value);
|
|
103
109
|
newNode.next = node.next;
|
|
104
110
|
newNode.prev = node.prev;
|
|
111
|
+
if (node.prev)
|
|
112
|
+
node.prev.next = newNode;
|
|
113
|
+
else
|
|
114
|
+
this._first = newNode;
|
|
115
|
+
if (node.next)
|
|
116
|
+
node.next.prev = newNode;
|
|
117
|
+
else
|
|
118
|
+
this._last = newNode;
|
|
105
119
|
node.list = undefined;
|
|
120
|
+
node.next = node.prev = undefined;
|
|
106
121
|
this._immutableList = undefined;
|
|
107
122
|
return newNode;
|
|
108
123
|
}
|
|
@@ -133,9 +148,16 @@ class CList {
|
|
|
133
148
|
this.delete(this._first); }
|
|
134
149
|
deleteLast() { if (this._last)
|
|
135
150
|
this.delete(this._last); }
|
|
151
|
+
push(value) { return this.addLast(value); }
|
|
152
|
+
unshift(value) { return this.addFirst(value); }
|
|
153
|
+
pop() { let value = this._last?.value; this.deleteLast(); return value; }
|
|
154
|
+
shift() { let value = this._first?.value; this.deleteFirst(); return value; }
|
|
136
155
|
clear() {
|
|
137
156
|
for (let node = this._first; node != null; node = node.next)
|
|
138
|
-
|
|
157
|
+
node.list = undefined;
|
|
158
|
+
this._first = this._last = undefined;
|
|
159
|
+
this._count = 0;
|
|
160
|
+
this._immutableList = undefined;
|
|
139
161
|
}
|
|
140
162
|
validateNode(node) {
|
|
141
163
|
if (!(node instanceof CListNode))
|
|
@@ -68,12 +68,12 @@ class CListNodeAnd extends CBaseList {
|
|
|
68
68
|
isForbidden() { return this._stop; }
|
|
69
69
|
isExists() { return this.isForbidden() || this._prev._stop || this._next._stop; }
|
|
70
70
|
static _Add(prev, next, home, a) { let buf = new CListNodeAnd(prev, next, home); buf.data = a; return buf; }
|
|
71
|
-
AddNext(a) { return a instanceof CListNodeAnd ? a._Init(this, this._next, this) :
|
|
72
|
-
AddPrev(a) { return a instanceof CListNodeAnd ? a._Init(this._prev, this, this) :
|
|
71
|
+
AddNext(a) { return a instanceof CListNodeAnd ? a._Init(this, this._next, this) : arguments.length ? CListNodeAnd._Add(this, this._next, this._home, a) : new CListNodeAnd(this, this._next); }
|
|
72
|
+
AddPrev(a) { return a instanceof CListNodeAnd ? a._Init(this._prev, this, this) : arguments.length ? CListNodeAnd._Add(this._prev, this, this._home, a) : new CListNodeAnd(this._prev, this); }
|
|
73
73
|
AddEnd(a) { return this._stop ? this.AddPrev(a) : this._End().AddNext(a); }
|
|
74
74
|
AddStart(a) { return this._stop ? this.AddNext(a) : this._First().AddPrev(a); }
|
|
75
75
|
forEach(el) {
|
|
76
|
-
for (let buf = this.First(); buf
|
|
76
|
+
for (let buf = this.First(); buf && !buf.isForbidden();) {
|
|
77
77
|
let t = buf.Next();
|
|
78
78
|
el(buf.data, buf);
|
|
79
79
|
buf = t;
|
|
@@ -2,10 +2,14 @@ export type ObjectKeyPath<TObject extends object = object, TValue = unknown> = r
|
|
|
2
2
|
export declare function objectSetValueByPath<TObj extends {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}, TVal>(obj: TObj, path: ObjectKeyPath<TObj, TVal>, value: TVal): void;
|
|
5
|
+
export declare const objectSet: typeof objectSetValueByPath;
|
|
5
6
|
export declare function objectGetValueByPath<TObj extends {
|
|
6
7
|
readonly [key: string]: any;
|
|
7
8
|
}, TVal>(object: TObj, path: ObjectKeyPath<TObj, TVal>): TVal;
|
|
9
|
+
export declare const objectGet: typeof objectGetValueByPath;
|
|
8
10
|
export declare function objectDeleteValueByPath<TObj extends {
|
|
9
11
|
readonly [key: string]: any;
|
|
10
12
|
}, TVal>(object: TObj, path: ObjectKeyPath<TObj, TVal>): boolean;
|
|
13
|
+
export declare const objectUnset: typeof objectDeleteValueByPath;
|
|
11
14
|
export declare function iterateDeepObjectEntries<TObj extends object>(obj: TObj, filter?: (key: string, value: unknown, path: ObjectKeyPath<TObj>) => boolean, currentPath?: ObjectKeyPath<TObj>): Generator<[key: string, value: unknown, path: ObjectKeyPath<TObj>]>;
|
|
15
|
+
export declare const deepEntries: typeof iterateDeepObjectEntries;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepEntries = exports.objectUnset = exports.objectGet = exports.objectSet = void 0;
|
|
3
4
|
exports.objectSetValueByPath = objectSetValueByPath;
|
|
4
5
|
exports.objectGetValueByPath = objectGetValueByPath;
|
|
5
6
|
exports.objectDeleteValueByPath = objectDeleteValueByPath;
|
|
@@ -13,10 +14,11 @@ function objectSetValueByPath(obj, path, value) {
|
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
16
|
let val = obj[key];
|
|
16
|
-
if (typeof val != "object")
|
|
17
|
+
if (val == null || typeof val != "object")
|
|
17
18
|
throw "value is not an object: " + val;
|
|
18
19
|
return objectSetValueByPath(val, path.slice(1), value);
|
|
19
20
|
}
|
|
21
|
+
exports.objectSet = objectSetValueByPath;
|
|
20
22
|
function objectGetValueByPath(object, path) {
|
|
21
23
|
if (path.length == 0)
|
|
22
24
|
throw "empty path!";
|
|
@@ -26,10 +28,11 @@ function objectGetValueByPath(object, path) {
|
|
|
26
28
|
let val = object[key];
|
|
27
29
|
if (path.length == 1)
|
|
28
30
|
return val;
|
|
29
|
-
if (typeof val != "object")
|
|
31
|
+
if (val == null || typeof val != "object")
|
|
30
32
|
throw "value is not an object: " + val;
|
|
31
33
|
return objectGetValueByPath(val, path.slice(1));
|
|
32
34
|
}
|
|
35
|
+
exports.objectGet = objectGetValueByPath;
|
|
33
36
|
function objectDeleteValueByPath(object, path) {
|
|
34
37
|
if (path.length == 0)
|
|
35
38
|
throw "empty path!";
|
|
@@ -42,10 +45,11 @@ function objectDeleteValueByPath(object, path) {
|
|
|
42
45
|
return true;
|
|
43
46
|
}
|
|
44
47
|
let val = object[key];
|
|
45
|
-
if (typeof val != "object")
|
|
48
|
+
if (val == null || typeof val != "object")
|
|
46
49
|
throw "value is not an object: " + val;
|
|
47
50
|
return objectDeleteValueByPath(val, path.slice(1));
|
|
48
51
|
}
|
|
52
|
+
exports.objectUnset = objectDeleteValueByPath;
|
|
49
53
|
function* iterateDeepObjectEntries(obj, filter, currentPath = []) {
|
|
50
54
|
if (obj)
|
|
51
55
|
for (let [key, val] of Object.entries(obj)) {
|
|
@@ -57,3 +61,4 @@ function* iterateDeepObjectEntries(obj, filter, currentPath = []) {
|
|
|
57
61
|
yield* iterateDeepObjectEntries(val, filter, keyPath);
|
|
58
62
|
}
|
|
59
63
|
}
|
|
64
|
+
exports.deepEntries = iterateDeepObjectEntries;
|