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,51 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enhancedWaitRun =
|
|
3
|
+
exports.createTaskQueue = exports.enhancedWaitRun = void 0;
|
|
4
|
+
exports.createThrottle = createThrottle;
|
|
4
5
|
exports.createAsyncQueue = createAsyncQueue;
|
|
5
6
|
exports.enhancedQueueRun = enhancedQueueRun;
|
|
6
7
|
exports.waitRun = waitRun;
|
|
7
8
|
exports.queueRun = queueRun;
|
|
8
|
-
exports.
|
|
9
|
+
exports.createReadyGate = createReadyGate;
|
|
9
10
|
const common_1 = require("../core/common");
|
|
10
|
-
function
|
|
11
|
+
function createThrottle() {
|
|
11
12
|
let last = 0, busy = false, pending;
|
|
12
13
|
let chain = Promise.resolve();
|
|
14
|
+
const throttle = (ms, func) => {
|
|
15
|
+
if (busy || last + ms >= Date.now())
|
|
16
|
+
return;
|
|
17
|
+
busy = true;
|
|
18
|
+
chain = chain.catch(() => { }).then(async () => {
|
|
19
|
+
try {
|
|
20
|
+
return await func();
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
busy = false;
|
|
24
|
+
last = Date.now();
|
|
25
|
+
}
|
|
26
|
+
}).catch(() => { });
|
|
27
|
+
};
|
|
28
|
+
const debounce = (ms, func) => {
|
|
29
|
+
if (!func)
|
|
30
|
+
throw new Error("debounceAsync: func is undefined");
|
|
31
|
+
pending = func;
|
|
32
|
+
if (busy)
|
|
33
|
+
return chain;
|
|
34
|
+
busy = true;
|
|
35
|
+
return chain = chain.finally(async () => {
|
|
36
|
+
try {
|
|
37
|
+
await (0, common_1.sleepAsync)(ms);
|
|
38
|
+
await pending?.();
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
busy = false;
|
|
42
|
+
chain = Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
13
46
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
chain = chain.then(async () => {
|
|
19
|
-
try {
|
|
20
|
-
return await func();
|
|
21
|
-
}
|
|
22
|
-
finally {
|
|
23
|
-
busy = false;
|
|
24
|
-
last = Date.now();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
debounceAsync: (ms, func) => {
|
|
29
|
-
if (!func)
|
|
30
|
-
throw new Error("debounceAsync: func is undefined");
|
|
31
|
-
pending = func;
|
|
32
|
-
if (busy)
|
|
33
|
-
return chain;
|
|
34
|
-
busy = true;
|
|
35
|
-
return chain = chain.finally(async () => {
|
|
36
|
-
try {
|
|
37
|
-
await (0, common_1.sleepAsync)(ms);
|
|
38
|
-
await pending?.();
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
busy = false;
|
|
42
|
-
chain = Promise.resolve();
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
},
|
|
47
|
+
throttle,
|
|
48
|
+
debounce,
|
|
49
|
+
throttleAsync: throttle,
|
|
50
|
+
debounceAsync: debounce,
|
|
46
51
|
};
|
|
47
52
|
}
|
|
53
|
+
exports.enhancedWaitRun = createThrottle;
|
|
48
54
|
function createAsyncQueue(concurrency = 1) {
|
|
55
|
+
if (concurrency < 1)
|
|
56
|
+
throw new Error("createAsyncQueue: concurrency must be >= 1");
|
|
49
57
|
const queue = [];
|
|
50
58
|
let active = 0, resolveIdle = null, idle = null;
|
|
51
59
|
const drain = () => {
|
|
@@ -67,19 +75,25 @@ function createAsyncQueue(concurrency = 1) {
|
|
|
67
75
|
} }); drain(); });
|
|
68
76
|
const onIdle = () => idle ??= new Promise(r => (active === 0 && !queue.length) ? r() : (resolveIdle = r));
|
|
69
77
|
const getQueueSize = () => queue.length;
|
|
70
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
add: enqueue,
|
|
80
|
+
onIdle,
|
|
81
|
+
get size() { return queue.length; },
|
|
82
|
+
enqueue,
|
|
83
|
+
getQueueSize,
|
|
84
|
+
};
|
|
71
85
|
}
|
|
72
86
|
function enhancedQueueRun(maxParallelTasks = 5) {
|
|
73
87
|
const q = createAsyncQueue(maxParallelTasks);
|
|
74
88
|
return {
|
|
75
89
|
get queueSize() { return q.getQueueSize(); },
|
|
76
|
-
enqueue: (task) => { q.enqueue(task); },
|
|
90
|
+
enqueue: (task) => { q.enqueue(task).catch(() => { }); },
|
|
77
91
|
enqueueAndRun: (task) => q.enqueue(task),
|
|
78
92
|
runAll: () => q.onIdle(),
|
|
79
93
|
};
|
|
80
94
|
}
|
|
81
95
|
function waitRun() {
|
|
82
|
-
const w = enhancedWaitRun();
|
|
96
|
+
const w = (0, exports.enhancedWaitRun)();
|
|
83
97
|
return { refreshAsync: w.throttleAsync, refreshAsync2: w.debounceAsync };
|
|
84
98
|
}
|
|
85
99
|
function queueRun(n = 5) {
|
|
@@ -91,14 +105,30 @@ function queueRun(n = 5) {
|
|
|
91
105
|
run: () => q.runAll(),
|
|
92
106
|
};
|
|
93
107
|
}
|
|
94
|
-
function
|
|
95
|
-
let
|
|
108
|
+
function createReadyGate() {
|
|
109
|
+
let isReadyFlag = false;
|
|
96
110
|
const tasks = [];
|
|
111
|
+
const setReady = async () => {
|
|
112
|
+
isReadyFlag = true;
|
|
113
|
+
const run = tasks.splice(0);
|
|
114
|
+
let err;
|
|
115
|
+
for (const fn of run) {
|
|
116
|
+
try {
|
|
117
|
+
await fn();
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
err ??= e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (err !== undefined)
|
|
124
|
+
throw err;
|
|
125
|
+
};
|
|
97
126
|
return {
|
|
98
|
-
add: (fn) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
isReady: () => ready,
|
|
127
|
+
add: (fn) => isReadyFlag ? void fn() : tasks.push(fn),
|
|
128
|
+
ready: setReady,
|
|
129
|
+
isReady: () => isReadyFlag,
|
|
102
130
|
tasks: () => [...tasks],
|
|
131
|
+
setReady,
|
|
103
132
|
};
|
|
104
133
|
}
|
|
134
|
+
exports.createTaskQueue = createReadyGate;
|
|
@@ -11,6 +11,7 @@ type AsyncExtras<T extends (...args: any[]) => any> = ReturnType<T> extends Prom
|
|
|
11
11
|
} : {};
|
|
12
12
|
type EnhancedDecoratorOptions<T extends (...args: any[]) => any> = CommonOptions<T> & AsyncExtras<T>;
|
|
13
13
|
export declare function enhancedDecorator<T extends (...args: any[]) => any>(fn: T, opt?: EnhancedDecoratorOptions<T>): (...args: Parameters<T>) => ReturnType<T>;
|
|
14
|
+
export declare const wrap: typeof enhancedDecorator;
|
|
14
15
|
export declare function enhancedTransformer<T extends (...args: any[]) => any, R>(fn: T, transform: (data: [args: Parameters<T>, result: ReturnType<T>]) => R): (...args: Parameters<T>) => R;
|
|
15
16
|
export declare function Decorator<T extends (...args: any[]) => any>(fn: T, opt?: {
|
|
16
17
|
parameters?: (...a: Parameters<T>) => any;
|
|
@@ -20,5 +21,6 @@ export declare function Decorator<T extends (...args: any[]) => any>(fn: T, opt?
|
|
|
20
21
|
resultModifier?: (res: ReturnType<T>) => ReturnType<T>;
|
|
21
22
|
}): (...args: Parameters<T>) => ReturnType<T>;
|
|
22
23
|
export declare function TransformerResult<T extends (...args: any[]) => any, R>(fn: T, transform: (data: [args: Parameters<T>, result: ReturnType<T>]) => R): (...args: Parameters<T>) => R;
|
|
23
|
-
export declare function
|
|
24
|
+
export declare function around<T extends (...args: any[]) => any, R>(fn: T, transform: (data: [args: Parameters<T>, fn: T]) => R): (...args: Parameters<T>) => R;
|
|
25
|
+
export declare const Transformer: typeof around;
|
|
24
26
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transformer = exports.wrap = void 0;
|
|
3
4
|
exports.enhancedDecorator = enhancedDecorator;
|
|
4
5
|
exports.enhancedTransformer = enhancedTransformer;
|
|
5
6
|
exports.Decorator = Decorator;
|
|
6
7
|
exports.TransformerResult = TransformerResult;
|
|
7
|
-
exports.
|
|
8
|
+
exports.around = around;
|
|
8
9
|
function enhancedDecorator(fn, opt) {
|
|
9
10
|
return (...args) => {
|
|
10
11
|
opt?.beforeParams?.(...args);
|
|
@@ -30,6 +31,7 @@ function enhancedDecorator(fn, opt) {
|
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
exports.wrap = enhancedDecorator;
|
|
33
35
|
function enhancedTransformer(fn, transform) {
|
|
34
36
|
return (...args) => {
|
|
35
37
|
const result = fn(...args);
|
|
@@ -48,6 +50,7 @@ function Decorator(fn, opt) {
|
|
|
48
50
|
function TransformerResult(fn, transform) {
|
|
49
51
|
return enhancedTransformer(fn, transform);
|
|
50
52
|
}
|
|
51
|
-
function
|
|
53
|
+
function around(fn, transform) {
|
|
52
54
|
return (...args) => transform([args, fn]);
|
|
53
55
|
}
|
|
56
|
+
exports.Transformer = around;
|
|
@@ -7,16 +7,16 @@ type const_Date = Omit<Date, "setTime" | "setFullYear" | "setMonth" | "setDate"
|
|
|
7
7
|
export declare function isDate<T>(value: T & (Extract<T, const_Date> extends never ? never : T)): value is Extract<typeof value, const_Date>;
|
|
8
8
|
export { Mutable };
|
|
9
9
|
export declare function shallowClone<T>(val: T): Mutable<T>;
|
|
10
|
-
export declare function _deepClone<T>(src: T, map?: Map<object, object>):
|
|
11
|
-
export declare function deepClone<T>(object: T):
|
|
10
|
+
export declare function _deepClone<T>(src: T, map?: Map<object, object>): any;
|
|
11
|
+
export declare function deepClone<T>(object: T): any;
|
|
12
|
+
export declare const clone: typeof deepClone;
|
|
12
13
|
export declare function deepCloneMutable<T>(value: T): MutableFull<T>;
|
|
13
|
-
export declare function deepCloneObject<T extends object>(object: T):
|
|
14
|
+
export declare function deepCloneObject<T extends object>(object: T): any;
|
|
14
15
|
export declare function deepCloneObjectMutable<T extends object>(object: T): MutableFull<T>;
|
|
15
16
|
export declare function toImmutable<T extends object>(object: T): Immutable<T>;
|
|
16
17
|
export declare function readonlyFull<T>(arg: T): ReadonlyFull<T>;
|
|
17
|
-
export declare function deepEqual
|
|
18
|
-
|
|
19
|
-
}>(object1: T, object2: T): boolean;
|
|
18
|
+
export declare function deepEqual(object1: any, object2: any): boolean;
|
|
19
|
+
export declare const isEqual: typeof deepEqual;
|
|
20
20
|
export declare function shallowEqual<T extends {
|
|
21
21
|
[key: string]: unknown;
|
|
22
22
|
} | undefined>(object1: T, object2: T): boolean;
|
|
@@ -57,21 +57,28 @@ export declare function BSearchNearest(array: ArrayLike<number>, searchValue: nu
|
|
|
57
57
|
export declare function BSearchNearest<T>(array: ArrayLike<T>, searchValue: number, arrayGetValue: (element: T) => number, maxDelta?: number): number;
|
|
58
58
|
export declare function _BSearchNearest<T>(array: ArrayLike<T>, searchValue: number, arrayGetValue: (element: T) => number, maxDelta?: number): number;
|
|
59
59
|
export declare function NormalizeDouble(value: number, digits: number): number;
|
|
60
|
+
export declare function round(value: number, digits?: number): number;
|
|
60
61
|
export declare function MaxCommonDivisor(a: number, b: number, digits?: number): number;
|
|
61
62
|
export declare function MaxCommonDivisorOnArray(values: Iterable<number>, precisDigits?: number): number;
|
|
63
|
+
export declare function gcd(a: number, b: number, digits?: number): number;
|
|
64
|
+
export declare function gcd(values: Iterable<number>, digits?: number): number;
|
|
62
65
|
export declare function GetDblPrecision2(value: number, mindigits: number, maxdigits: number): number;
|
|
63
66
|
export declare function GetDblPrecision(value: number, maxdigits?: number): number;
|
|
67
|
+
export declare function decimals(value: number, maxDigits?: number, minDigits?: number): number;
|
|
64
68
|
export declare function DblToStrAuto(value: number, maxprecis?: number): string;
|
|
69
|
+
export declare const formatAuto: typeof DblToStrAuto;
|
|
65
70
|
export declare function NormalizeDoubleAnd(a: number, options?: {
|
|
66
71
|
digitsPoint?: number;
|
|
67
72
|
digitsR?: number;
|
|
68
73
|
type?: "max" | "min";
|
|
69
74
|
}): number;
|
|
75
|
+
export declare const roundSig: typeof NormalizeDoubleAnd;
|
|
70
76
|
export declare function DblToStrAnd(a: number, options?: {
|
|
71
77
|
digitsPoint?: number;
|
|
72
78
|
digitsR?: number;
|
|
73
79
|
type?: "max" | "min";
|
|
74
80
|
}): string;
|
|
81
|
+
export declare const formatSig: typeof DblToStrAnd;
|
|
75
82
|
export declare function ArrayItemHandler<T extends {
|
|
76
83
|
[key: number]: any;
|
|
77
84
|
}>(getter: (target: T, i: number) => T[number], setter?: (target: T, i: number, value: T[number]) => void): ProxyHandler<T>;
|
|
@@ -113,17 +120,25 @@ export declare class __MyMap<K extends {
|
|
|
113
120
|
get sortedKeys(): readonly K[];
|
|
114
121
|
get Values(): readonly V[];
|
|
115
122
|
assign(other: __MyMap<K, V>): void;
|
|
123
|
+
set(key: K, value: V): void;
|
|
124
|
+
get(key: K): V | undefined;
|
|
125
|
+
has(key: K): boolean;
|
|
126
|
+
delete(key: K): void;
|
|
127
|
+
clear(): void;
|
|
128
|
+
get size(): number;
|
|
116
129
|
}
|
|
117
130
|
export declare class MyMap<K extends {
|
|
118
131
|
valueOf(): number;
|
|
119
132
|
}, V> extends __MyMap<K, V> {
|
|
120
133
|
readonly [key: number]: void;
|
|
121
134
|
Clone(): MyMap<K, V>;
|
|
135
|
+
clone(): MyMap<K, V>;
|
|
122
136
|
}
|
|
123
137
|
export declare class MyNumMap<VAL> extends __MyMap<number, VAL> {
|
|
124
138
|
[key: number]: VAL | undefined;
|
|
125
139
|
constructor();
|
|
126
140
|
Clone(): MyNumMap<VAL>;
|
|
141
|
+
clone(): MyNumMap<VAL>;
|
|
127
142
|
}
|
|
128
143
|
export declare class StructMap<TKey extends (Required<TKey> & {
|
|
129
144
|
[key: string]: number | string;
|
|
@@ -187,9 +202,10 @@ export declare class CancelToken implements ICancelToken {
|
|
|
187
202
|
private _cancel;
|
|
188
203
|
isCancelled(): boolean;
|
|
189
204
|
cancel(): void;
|
|
205
|
+
get aborted(): boolean;
|
|
206
|
+
abort(): void;
|
|
190
207
|
}
|
|
191
208
|
export declare class CancelablePromise<T> extends Promise<T> {
|
|
192
|
-
private static _rejectTmp;
|
|
193
209
|
private readonly _reject?;
|
|
194
210
|
private readonly _onCancel?;
|
|
195
211
|
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, onCancel?: () => void);
|
|
@@ -209,6 +225,7 @@ export declare class Mutex {
|
|
|
209
225
|
private mutex;
|
|
210
226
|
lock(): PromiseLike<() => void>;
|
|
211
227
|
dispatch<T>(fn: () => T | PromiseLike<T>): Promise<T>;
|
|
228
|
+
runExclusive<T>(fn: () => T | PromiseLike<T>): Promise<T>;
|
|
212
229
|
static createLock(): PromiseLike<() => void>;
|
|
213
230
|
}
|
|
214
231
|
export declare function copyToClipboard(textToCopy: string): Promise<any>;
|
|
@@ -232,6 +249,7 @@ export declare class MapExt<K, V> extends Map<K, V> {
|
|
|
232
249
|
private immutArray?;
|
|
233
250
|
set(key: K, value: V): this;
|
|
234
251
|
delete(key: K): boolean;
|
|
252
|
+
clear(): void;
|
|
235
253
|
valuesArrayImmutable(): readonly V[];
|
|
236
254
|
getOrSetFunc(key: K, val: () => V): V;
|
|
237
255
|
getOrSet(key: K, val: V): V;
|
|
@@ -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;
|
|
@@ -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++) {
|
|
@@ -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;
|