wenay-common2 1.0.46 → 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 +4 -0
- 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 -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 +38 -5
- package/lib/Common/events/Listen.js +89 -54
- package/lib/Common/events/SocketBuffer.d.ts +9 -4
- 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 +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 +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/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 +1 -0
- package/lib/index.js +2 -1
- package/lib/server/WebHook3.js +22 -9
- package/package.json +2 -1
package/lib/Common/Color.d.ts
CHANGED
|
@@ -24,8 +24,11 @@ export declare function colorGenerator2(data?: {
|
|
|
24
24
|
}): Generator<[number, number, number]>;
|
|
25
25
|
export declare function colorGeneratorByCount2(value?: number, count?: number, index?: number): [number, number, number];
|
|
26
26
|
export declare function colorGeneratorByCount(value?: number, count?: number, index?: number): ColorString;
|
|
27
|
+
export declare const hue: typeof colorGeneratorByCount;
|
|
28
|
+
export declare const hueRGB: typeof colorGeneratorByCount2;
|
|
27
29
|
export declare function colorStringToRGBA(str: ColorString): [number, number, number, number];
|
|
28
30
|
export declare function colorStringToRGBA(str: string): [number, number, number, number] | undefined;
|
|
31
|
+
export declare const toRGBA: typeof colorStringToRGBA;
|
|
29
32
|
export declare function toColorString(str: string): ColorString;
|
|
30
33
|
export declare function isSimilarColors(color1: ColorString | readonly [number, number, number], color2: ColorString | readonly [number, number, number], maxDelta?: number): boolean;
|
|
31
34
|
export {};
|
package/lib/Common/Color.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRGBA = exports.hueRGB = exports.hue = void 0;
|
|
3
4
|
exports.rgb = rgb;
|
|
4
5
|
exports.colorGenerator = colorGenerator;
|
|
5
6
|
exports.colorGenerator2 = colorGenerator2;
|
|
@@ -80,6 +81,8 @@ function colorGeneratorByCount(value = 180, count = 100, index = 1) {
|
|
|
80
81
|
const [r, g, b] = colorGeneratorByCount2(value, count, index);
|
|
81
82
|
return `rgb(${r},${g},${b})`;
|
|
82
83
|
}
|
|
84
|
+
exports.hue = colorGeneratorByCount;
|
|
85
|
+
exports.hueRGB = colorGeneratorByCount2;
|
|
83
86
|
function colorStringToRGBA(str) {
|
|
84
87
|
const rgbRegex = /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i;
|
|
85
88
|
const rgbaRegex = /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d*\.?\d+)\s*\)$/i;
|
|
@@ -99,6 +102,7 @@ function colorStringToRGBA(str) {
|
|
|
99
102
|
}
|
|
100
103
|
return undefined;
|
|
101
104
|
}
|
|
105
|
+
exports.toRGBA = colorStringToRGBA;
|
|
102
106
|
function isValidRGBValue(value) {
|
|
103
107
|
return value >= 0 && value <= 255;
|
|
104
108
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type Fn = () => void;
|
|
2
|
+
type Drain = 'micro' | 'immediate' | number | ((flush: Fn) => void);
|
|
3
|
+
export type Opts = {
|
|
4
|
+
drain?: Drain;
|
|
5
|
+
depth?: number;
|
|
6
|
+
eager?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function reactive<T extends object>(root: T, opts?: Opts): T;
|
|
9
|
+
export declare function onUpdate(p: any, cb: Fn): () => void;
|
|
10
|
+
export declare function flushReactive(p: any): Promise<void>;
|
|
11
|
+
export declare function listenUpdate(p: any): {
|
|
12
|
+
func: import("../events/Listen").Listener<[]>;
|
|
13
|
+
isRun: () => boolean;
|
|
14
|
+
run: () => void;
|
|
15
|
+
close: () => void;
|
|
16
|
+
eventClose: (cb: () => void) => () => void;
|
|
17
|
+
onClose: (cb: () => void) => () => void;
|
|
18
|
+
removeEventClose: (cb: () => void) => void;
|
|
19
|
+
addListen: (cb: import("../events/Listen").Listener<[]>, { cbClose, key }?: {
|
|
20
|
+
cbClose?: (() => void) | undefined;
|
|
21
|
+
key?: string | symbol;
|
|
22
|
+
}) => () => void;
|
|
23
|
+
removeListen: (k: (string | symbol) | import("../events/Listen").Listener<[]> | null) => void;
|
|
24
|
+
on: import("../events/Listen").ListenOn<[]>;
|
|
25
|
+
once: (cb: import("../events/Listen").Listener<[]>, opts?: {
|
|
26
|
+
key?: string | symbol;
|
|
27
|
+
}) => () => void;
|
|
28
|
+
count: () => number;
|
|
29
|
+
readonly getAllKeys: ((string | symbol) | import("../events/Listen").Listener<[]>)[];
|
|
30
|
+
};
|
|
31
|
+
export type Reactive<T extends object> = T;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reactive = reactive;
|
|
4
|
+
exports.onUpdate = onUpdate;
|
|
5
|
+
exports.flushReactive = flushReactive;
|
|
6
|
+
exports.listenUpdate = listenUpdate;
|
|
7
|
+
const Listen_1 = require("../events/Listen");
|
|
8
|
+
const NODE = Symbol('reactive2.node');
|
|
9
|
+
const isObj = (v) => v != null && typeof v == 'object';
|
|
10
|
+
const isReactiveObj = (v) => {
|
|
11
|
+
if (!isObj(v))
|
|
12
|
+
return false;
|
|
13
|
+
if (Array.isArray(v))
|
|
14
|
+
return true;
|
|
15
|
+
const p = Object.getPrototypeOf(v);
|
|
16
|
+
return p == Object.prototype || p == null;
|
|
17
|
+
};
|
|
18
|
+
const hasSetImmediate = typeof setImmediate == 'function';
|
|
19
|
+
function scheduler(drain) {
|
|
20
|
+
if (drain == 'micro')
|
|
21
|
+
return f => queueMicrotask(f);
|
|
22
|
+
if (typeof drain == 'number')
|
|
23
|
+
return f => { setTimeout(f, drain); };
|
|
24
|
+
if (typeof drain == 'function')
|
|
25
|
+
return f => drain(f);
|
|
26
|
+
return hasSetImmediate ? f => { setImmediate(f); } : f => { setTimeout(f, 0); };
|
|
27
|
+
}
|
|
28
|
+
function reactive(root, opts = {}) {
|
|
29
|
+
const { drain = 'immediate', depth = Infinity, eager = false } = opts;
|
|
30
|
+
const fire = scheduler(drain);
|
|
31
|
+
const eng = {
|
|
32
|
+
live: 0, dirty: new Set(), scheduled: false, waiters: new Set(), depth,
|
|
33
|
+
schedule() {
|
|
34
|
+
if (eng.scheduled)
|
|
35
|
+
return;
|
|
36
|
+
eng.scheduled = true;
|
|
37
|
+
fire(function flush() {
|
|
38
|
+
eng.scheduled = false;
|
|
39
|
+
const batch = [...eng.dirty];
|
|
40
|
+
eng.dirty.clear();
|
|
41
|
+
let err;
|
|
42
|
+
for (const n of batch)
|
|
43
|
+
for (const cb of [...n.subs]) {
|
|
44
|
+
try {
|
|
45
|
+
cb();
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
err ??= e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!eng.scheduled && eng.dirty.size == 0) {
|
|
52
|
+
const waiters = [...eng.waiters];
|
|
53
|
+
eng.waiters.clear();
|
|
54
|
+
for (const w of waiters)
|
|
55
|
+
w();
|
|
56
|
+
}
|
|
57
|
+
if (err !== undefined)
|
|
58
|
+
setTimeout(() => { throw err; }, 0);
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const rootNode = makeNode(root, null, 0, eng);
|
|
63
|
+
if (eager)
|
|
64
|
+
prewalk(rootNode);
|
|
65
|
+
return rootNode.proxy;
|
|
66
|
+
}
|
|
67
|
+
function makeNode(target, parent, level, eng) {
|
|
68
|
+
const node = { target, parent, active: true, level, subs: new Set(), kids: new Map(), proxy: null, eng };
|
|
69
|
+
const proxyTarget = (Array.isArray(target) ? [] : {});
|
|
70
|
+
node.proxy = new Proxy(proxyTarget, {
|
|
71
|
+
get(_, k) {
|
|
72
|
+
if (k == NODE)
|
|
73
|
+
return node;
|
|
74
|
+
if (k == 'toJSON' && Array.isArray(proxyTarget) && !Array.isArray(node.target) && node.target?.toJSON === undefined)
|
|
75
|
+
return () => node.target;
|
|
76
|
+
const v = node.target[k];
|
|
77
|
+
if (isReactiveObj(v) && level < eng.depth) {
|
|
78
|
+
let kid = node.kids.get(k);
|
|
79
|
+
if (!kid) {
|
|
80
|
+
kid = makeNode(v, node, level + 1, eng);
|
|
81
|
+
node.kids.set(k, kid);
|
|
82
|
+
}
|
|
83
|
+
else if (kid.target !== v)
|
|
84
|
+
kid.target = v;
|
|
85
|
+
return kid.proxy;
|
|
86
|
+
}
|
|
87
|
+
return v;
|
|
88
|
+
},
|
|
89
|
+
set(_, k, v) {
|
|
90
|
+
if (Object.is(node.target[k], v))
|
|
91
|
+
return true;
|
|
92
|
+
node.target[k] = v;
|
|
93
|
+
if (Array.isArray(proxyTarget) && k == "length")
|
|
94
|
+
proxyTarget.length = v;
|
|
95
|
+
const kid = node.kids.get(k);
|
|
96
|
+
if (kid)
|
|
97
|
+
rebind(kid, v);
|
|
98
|
+
if (eng.live > 0)
|
|
99
|
+
bubble(node);
|
|
100
|
+
return true;
|
|
101
|
+
},
|
|
102
|
+
defineProperty(_, k, d) {
|
|
103
|
+
const old = node.target[k];
|
|
104
|
+
const ok = Reflect.defineProperty(node.target, k, d);
|
|
105
|
+
if (!ok)
|
|
106
|
+
return false;
|
|
107
|
+
if (d.configurable === false) {
|
|
108
|
+
const mirror = Reflect.defineProperty(proxyTarget, k, d);
|
|
109
|
+
if (!mirror)
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const v = node.target[k];
|
|
113
|
+
if (!Object.is(old, v)) {
|
|
114
|
+
const kid = node.kids.get(k);
|
|
115
|
+
if (kid) {
|
|
116
|
+
if (isReactiveObj(v))
|
|
117
|
+
rebind(kid, v);
|
|
118
|
+
else {
|
|
119
|
+
node.kids.delete(k);
|
|
120
|
+
markChanged(kid);
|
|
121
|
+
detachTree(kid);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (eng.live > 0)
|
|
125
|
+
bubble(node);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
deleteProperty(_, k) {
|
|
130
|
+
if (!(k in node.target))
|
|
131
|
+
return true;
|
|
132
|
+
delete node.target[k];
|
|
133
|
+
const kid = node.kids.get(k);
|
|
134
|
+
if (kid) {
|
|
135
|
+
node.kids.delete(k);
|
|
136
|
+
markChanged(kid);
|
|
137
|
+
detachTree(kid);
|
|
138
|
+
}
|
|
139
|
+
if (eng.live > 0)
|
|
140
|
+
bubble(node);
|
|
141
|
+
return true;
|
|
142
|
+
},
|
|
143
|
+
has(_, k) { return k in node.target; },
|
|
144
|
+
ownKeys() {
|
|
145
|
+
const keys = Reflect.ownKeys(node.target);
|
|
146
|
+
for (const k of Reflect.ownKeys(proxyTarget)) {
|
|
147
|
+
const d = Reflect.getOwnPropertyDescriptor(proxyTarget, k);
|
|
148
|
+
if (d?.configurable === false && !keys.includes(k))
|
|
149
|
+
keys.push(k);
|
|
150
|
+
}
|
|
151
|
+
return keys;
|
|
152
|
+
},
|
|
153
|
+
getOwnPropertyDescriptor(_, k) {
|
|
154
|
+
if (Array.isArray(proxyTarget) && k == "length")
|
|
155
|
+
return Reflect.getOwnPropertyDescriptor(proxyTarget, k);
|
|
156
|
+
const pd = Reflect.getOwnPropertyDescriptor(proxyTarget, k);
|
|
157
|
+
if (pd && pd.configurable === false)
|
|
158
|
+
return pd;
|
|
159
|
+
const d = Reflect.getOwnPropertyDescriptor(node.target, k);
|
|
160
|
+
if (d)
|
|
161
|
+
d.configurable = true;
|
|
162
|
+
return d;
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
return node;
|
|
166
|
+
}
|
|
167
|
+
function bubble(from) {
|
|
168
|
+
const eng = from.eng;
|
|
169
|
+
for (let n = from; n && n.active; n = n.parent)
|
|
170
|
+
if (n.subs.size)
|
|
171
|
+
eng.dirty.add(n);
|
|
172
|
+
eng.schedule();
|
|
173
|
+
}
|
|
174
|
+
function rebind(node, next) {
|
|
175
|
+
node.target = next;
|
|
176
|
+
if (node.subs.size)
|
|
177
|
+
node.eng.dirty.add(node);
|
|
178
|
+
for (const [k, kid] of [...node.kids]) {
|
|
179
|
+
const cv = isReactiveObj(next) ? next[k] : undefined;
|
|
180
|
+
if (isReactiveObj(cv))
|
|
181
|
+
rebind(kid, cv);
|
|
182
|
+
else {
|
|
183
|
+
node.kids.delete(k);
|
|
184
|
+
markChanged(kid);
|
|
185
|
+
detachTree(kid);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function markChanged(node) {
|
|
190
|
+
if (node.subs.size)
|
|
191
|
+
node.eng.dirty.add(node);
|
|
192
|
+
for (const kid of node.kids.values())
|
|
193
|
+
markChanged(kid);
|
|
194
|
+
}
|
|
195
|
+
function detachTree(node) {
|
|
196
|
+
if (!node.active)
|
|
197
|
+
return;
|
|
198
|
+
node.active = false;
|
|
199
|
+
node.parent = null;
|
|
200
|
+
for (const kid of node.kids.values())
|
|
201
|
+
detachTree(kid);
|
|
202
|
+
node.kids.clear();
|
|
203
|
+
}
|
|
204
|
+
function prewalk(node) {
|
|
205
|
+
if (node.level >= node.eng.depth)
|
|
206
|
+
return;
|
|
207
|
+
for (const k of Reflect.ownKeys(node.target)) {
|
|
208
|
+
if (isReactiveObj(node.target[k])) {
|
|
209
|
+
node.proxy[k];
|
|
210
|
+
const kid = node.kids.get(k);
|
|
211
|
+
if (kid)
|
|
212
|
+
prewalk(kid);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function onUpdate(p, cb) {
|
|
217
|
+
const node = p && p[NODE];
|
|
218
|
+
if (!node)
|
|
219
|
+
throw new Error('onUpdate: not a reactive object');
|
|
220
|
+
if (!node.active)
|
|
221
|
+
throw new Error('onUpdate: reactive object is detached');
|
|
222
|
+
const sub = () => cb();
|
|
223
|
+
node.subs.add(sub);
|
|
224
|
+
node.eng.live++;
|
|
225
|
+
let done = false;
|
|
226
|
+
return () => { if (done)
|
|
227
|
+
return; done = true; if (node.subs.delete(sub))
|
|
228
|
+
node.eng.live--; };
|
|
229
|
+
}
|
|
230
|
+
function flushReactive(p) {
|
|
231
|
+
const node = p && p[NODE];
|
|
232
|
+
if (!node)
|
|
233
|
+
throw new Error('flushReactive: not a reactive object');
|
|
234
|
+
const eng = node.eng;
|
|
235
|
+
if (!eng.scheduled && eng.dirty.size == 0)
|
|
236
|
+
return Promise.resolve();
|
|
237
|
+
return new Promise(resolve => { eng.waiters.add(resolve); });
|
|
238
|
+
}
|
|
239
|
+
function listenUpdate(p) {
|
|
240
|
+
const listen = (0, Listen_1.funcListenCallbackBase)((emit) => onUpdate(p, () => emit()), {
|
|
241
|
+
event: (type, count, api) => {
|
|
242
|
+
if (type == "add" && count == 1 && !api.isRun())
|
|
243
|
+
api.run();
|
|
244
|
+
if (type == "remove" && count == 0 && api.isRun())
|
|
245
|
+
api.close();
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
return listen;
|
|
249
|
+
}
|
package/lib/Common/Time.d.ts
CHANGED
|
@@ -191,12 +191,18 @@ export declare function timeLocalToStr_yyyymmdd_hhmmss(date: const_Date, dateDel
|
|
|
191
191
|
export declare function timeLocalToStr_yyyymmdd_hhmmss_ms(date: const_Date, dateDelim?: string): string;
|
|
192
192
|
export declare function timeToString_yyyymmdd_hhmm_offset(date: const_Date): string;
|
|
193
193
|
export declare function timeToString_yyyymmdd_hhmmss_offset(date: const_Date): string;
|
|
194
|
+
export type tTimeFormatPattern = 'HH:mm:ss' | 'HH:mm:ss.SSS' | 'yyyy-MM-dd' | 'yyyy-MM-dd HH:mm' | 'yyyy-MM-dd HH:mm:ss' | 'yyyy-MM-dd HH:mm:ss.SSS' | 'yyyy-MM-dd HH:mm O' | 'yyyy-MM-dd HH:mm:ss O';
|
|
195
|
+
export declare function format(date: const_Date, pattern: tTimeFormatPattern, opts?: {
|
|
196
|
+
utc?: boolean;
|
|
197
|
+
}): string;
|
|
194
198
|
export declare function convertDatesToStrings(arg: any): any;
|
|
195
199
|
export declare function toPrintObject(arg: any): any;
|
|
196
200
|
export declare function durationToStr(duration_ms: number): string;
|
|
197
201
|
export declare function durationToStrNullable(duration_ms: number | null | undefined): string | null;
|
|
198
202
|
export declare function durationToStr_h_mm_ss(duration_ms: number): string;
|
|
199
203
|
export declare function durationToStr_h_mm_ss_ms(duration_ms: number): string;
|
|
204
|
+
export type tDurationFormatPattern = 'H:mm:ss' | 'H:mm:ss.SSS';
|
|
205
|
+
export declare function formatDuration(duration_ms: number, pattern?: tDurationFormatPattern): string;
|
|
200
206
|
export declare class CDelayer {
|
|
201
207
|
protected remainPause: number;
|
|
202
208
|
sleepAsync(pause_ms_getter: () => number | null): Promise<void>;
|
|
@@ -204,3 +210,5 @@ export declare class CDelayer {
|
|
|
204
210
|
type NullableTime = const_Date | undefined | null;
|
|
205
211
|
export declare function MinTime<T1 extends NullableTime, T2 extends NullableTime>(time1: T1, time2: T2): T1 | NonNullable<T2>;
|
|
206
212
|
export declare function MaxTime<T1 extends NullableTime, T2 extends NullableTime>(time1: T1, time2: T2): T1 | NonNullable<T2>;
|
|
213
|
+
export declare const minDate: typeof MinTime;
|
|
214
|
+
export declare const maxDate: typeof MaxTime;
|
package/lib/Common/Time.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CDelayer = exports.Period = exports.PeriodSpan = exports.TF = exports.TIME_UNIT = exports.M1_MS = exports.H1_MS = exports.D1_MS = exports.W1_MS = exports.W1_S = exports.D1_S = exports.H1_S = void 0;
|
|
3
|
+
exports.maxDate = exports.minDate = exports.CDelayer = exports.Period = exports.PeriodSpan = exports.TF = exports.TIME_UNIT = exports.M1_MS = exports.H1_MS = exports.D1_MS = exports.W1_MS = exports.W1_S = exports.D1_S = exports.H1_S = void 0;
|
|
4
4
|
exports.timeToStr_hhmmss_ms = timeToStr_hhmmss_ms;
|
|
5
5
|
exports.timeToStr_hhmmss = timeToStr_hhmmss;
|
|
6
6
|
exports.timeToStr_yyyymmdd_hhmm = timeToStr_yyyymmdd_hhmm;
|
|
@@ -14,12 +14,14 @@ exports.timeLocalToStr_yyyymmdd_hhmmss = timeLocalToStr_yyyymmdd_hhmmss;
|
|
|
14
14
|
exports.timeLocalToStr_yyyymmdd_hhmmss_ms = timeLocalToStr_yyyymmdd_hhmmss_ms;
|
|
15
15
|
exports.timeToString_yyyymmdd_hhmm_offset = timeToString_yyyymmdd_hhmm_offset;
|
|
16
16
|
exports.timeToString_yyyymmdd_hhmmss_offset = timeToString_yyyymmdd_hhmmss_offset;
|
|
17
|
+
exports.format = format;
|
|
17
18
|
exports.convertDatesToStrings = convertDatesToStrings;
|
|
18
19
|
exports.toPrintObject = toPrintObject;
|
|
19
20
|
exports.durationToStr = durationToStr;
|
|
20
21
|
exports.durationToStrNullable = durationToStrNullable;
|
|
21
22
|
exports.durationToStr_h_mm_ss = durationToStr_h_mm_ss;
|
|
22
23
|
exports.durationToStr_h_mm_ss_ms = durationToStr_h_mm_ss_ms;
|
|
24
|
+
exports.formatDuration = formatDuration;
|
|
23
25
|
exports.MinTime = MinTime;
|
|
24
26
|
exports.MaxTime = MaxTime;
|
|
25
27
|
const common_1 = require("./core/common");
|
|
@@ -293,6 +295,19 @@ function timeLocalToStr_yyyymmdd_hhmmss(date, dateDelim = "-") { return timeLoca
|
|
|
293
295
|
function timeLocalToStr_yyyymmdd_hhmmss_ms(date, dateDelim = "-") { return timeLocalToStr_yyyymmdd_hhmmss(date, dateDelim) + "." + str3(date.getMilliseconds()); }
|
|
294
296
|
function timeToString_yyyymmdd_hhmm_offset(date) { let offset = date.getTimezoneOffset(); return timeLocalToStr_yyyymmdd_hhmm(date) + " GMT" + (offset < 0 ? '+' : '') + (-offset / 60); }
|
|
295
297
|
function timeToString_yyyymmdd_hhmmss_offset(date) { let offset = date.getTimezoneOffset(); return timeLocalToStr_yyyymmdd_hhmmss(date) + " GMT" + (offset < 0 ? '+' : '') + (-offset / 60); }
|
|
298
|
+
function format(date, pattern, opts) {
|
|
299
|
+
let utc = opts?.utc ?? true;
|
|
300
|
+
switch (pattern) {
|
|
301
|
+
case 'HH:mm:ss': return utc ? timeToStr_hhmmss(date) : timeLocalToStr_hhmmss(date);
|
|
302
|
+
case 'HH:mm:ss.SSS': return utc ? timeToStr_hhmmss_ms(date) : (timeLocalToStr_hhmmss(date) + '.' + str3(date.getMilliseconds()));
|
|
303
|
+
case 'yyyy-MM-dd': return utc ? timeToStr_yyyymmdd_hhmm(date).slice(0, 10) : timeLocalToStr_yyyymmdd(date);
|
|
304
|
+
case 'yyyy-MM-dd HH:mm': return utc ? timeToStr_yyyymmdd_hhmm(date) : timeLocalToStr_yyyymmdd_hhmm(date);
|
|
305
|
+
case 'yyyy-MM-dd HH:mm:ss': return utc ? timeToStr_yyyymmdd_hhmmss(date) : timeLocalToStr_yyyymmdd_hhmmss(date);
|
|
306
|
+
case 'yyyy-MM-dd HH:mm:ss.SSS': return utc ? timeToStr_yyyymmdd_hhmmss_ms(date) : timeLocalToStr_yyyymmdd_hhmmss_ms(date);
|
|
307
|
+
case 'yyyy-MM-dd HH:mm O': return timeToString_yyyymmdd_hhmm_offset(date);
|
|
308
|
+
case 'yyyy-MM-dd HH:mm:ss O': return timeToString_yyyymmdd_hhmmss_offset(date);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
296
311
|
Date.prototype.toString = function () { return timeToString_yyyymmdd_hhmmss_offset(this); };
|
|
297
312
|
Date.prototype.toDateString = function () { return timeLocalToStr_yyyymmdd(this); };
|
|
298
313
|
Date.prototype.toTimeString = function () { let offset = this.getTimezoneOffset(); return timeLocalToStr_hhmmss(this) + " GMT" + (offset < 0 ? '+' : '') + (-offset / 60); };
|
|
@@ -331,25 +346,32 @@ function replaceConsoleCommands() {
|
|
|
331
346
|
}
|
|
332
347
|
function durationToStr(duration_ms) {
|
|
333
348
|
let units = [[exports.D1_MS, "д"], [exports.H1_MS, "ч"], [exports.M1_MS, "м"], [1000, "c"], [1, "мс"]];
|
|
334
|
-
let
|
|
349
|
+
let firstUnit = null;
|
|
350
|
+
let firstCount = 0;
|
|
335
351
|
let str = "";
|
|
336
352
|
for (let unit of units) {
|
|
337
353
|
let unitCountFloat = duration_ms / unit[0];
|
|
338
|
-
if (unitCountFloat < 1.1 &&
|
|
354
|
+
if (unitCountFloat < 1.1 && firstUnit == null)
|
|
355
|
+
continue;
|
|
356
|
+
if (firstUnit == null && unitCountFloat <= 10) {
|
|
357
|
+
firstUnit = unit;
|
|
358
|
+
firstCount = Math.floor(unitCountFloat);
|
|
359
|
+
duration_ms %= unit[0];
|
|
339
360
|
continue;
|
|
340
|
-
let unitCount;
|
|
341
|
-
if (lastUnit || unitCountFloat > 10) {
|
|
342
|
-
unitCount = Math.round(unitCountFloat);
|
|
343
|
-
lastUnit = unit;
|
|
344
361
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
362
|
+
let unitCount = Math.round(unitCountFloat);
|
|
363
|
+
if (firstUnit && unitCount * unit[0] >= firstUnit[0]) {
|
|
364
|
+
firstCount++;
|
|
365
|
+
unitCount = 0;
|
|
366
|
+
}
|
|
367
|
+
if (firstUnit)
|
|
368
|
+
str += firstCount + firstUnit[1] + " ";
|
|
369
|
+
if (unitCount > 0 || firstUnit == null)
|
|
370
|
+
str += unitCount + unit[1] + " ";
|
|
371
|
+
return str;
|
|
352
372
|
}
|
|
373
|
+
if (firstUnit)
|
|
374
|
+
str += firstCount + firstUnit[1] + " ";
|
|
353
375
|
return str;
|
|
354
376
|
}
|
|
355
377
|
function durationToStrNullable(duration_ms) { return duration_ms == null ? null : durationToStr(duration_ms); }
|
|
@@ -358,6 +380,9 @@ function durationToStr_h_mm_ss(duration_ms) {
|
|
|
358
380
|
return Math.trunc(duration_ms / exports.H1_MS) + ":" + str2(time.getUTCMinutes()) + ":" + str2(time.getUTCSeconds());
|
|
359
381
|
}
|
|
360
382
|
function durationToStr_h_mm_ss_ms(duration_ms) { return durationToStr_h_mm_ss(duration_ms) + "." + str3(Math.trunc(duration_ms % 1000)); }
|
|
383
|
+
function formatDuration(duration_ms, pattern = 'H:mm:ss') {
|
|
384
|
+
return pattern == 'H:mm:ss.SSS' ? durationToStr_h_mm_ss_ms(duration_ms) : durationToStr_h_mm_ss(duration_ms);
|
|
385
|
+
}
|
|
361
386
|
async function sleepAsync(msec) {
|
|
362
387
|
return new Promise((resolve, reject) => { setTimeout(resolve, msec); });
|
|
363
388
|
}
|
|
@@ -391,3 +416,5 @@ function MinTime(time1, time2) {
|
|
|
391
416
|
function MaxTime(time1, time2) {
|
|
392
417
|
return time1 && time2 && time1.valueOf() >= time2.valueOf() ? time1 : time2 ?? time1;
|
|
393
418
|
}
|
|
419
|
+
exports.minDate = MinTime;
|
|
420
|
+
exports.maxDate = MaxTime;
|
|
@@ -2,10 +2,10 @@ export declare function PromiseArrayListen<T extends any = unknown>(array: ((()
|
|
|
2
2
|
listenOk: (a: (...d: [data: T, i: number, countOk: number, countError: number, count: number]) => any) => () => void;
|
|
3
3
|
listenError: (a: (...d: [error: any, i: number, countOk: number, countError: number, count: number]) => any) => () => void;
|
|
4
4
|
promise: {
|
|
5
|
-
all: () => Promise<
|
|
6
|
-
allSettled: () => Promise<PromiseSettledResult<
|
|
5
|
+
all: () => Promise<any[]>;
|
|
6
|
+
allSettled: () => Promise<PromiseSettledResult<any>[]>;
|
|
7
7
|
};
|
|
8
|
-
getData():
|
|
8
|
+
getData(): Promise<any>[];
|
|
9
9
|
status(): {
|
|
10
10
|
ok: number;
|
|
11
11
|
error: number;
|
|
@@ -15,23 +15,20 @@ function PromiseArrayListen(array) {
|
|
|
15
15
|
++errorCount;
|
|
16
16
|
c[0](error, i, ok, errorCount, count);
|
|
17
17
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const wrap = (promise, i) => promise.then(r => { a(r, i); return r; }).catch((er) => { b(er, i); throw er; });
|
|
19
|
+
const arr = array.map((e, i) => e instanceof Promise ? wrap(e, i)
|
|
20
|
+
: () => wrap((async () => e())(), i));
|
|
21
|
+
const started = [];
|
|
22
|
+
const startAll = () => arr.map((x, i) => started[i] ??= (typeof x === 'function' ? x() : x));
|
|
20
23
|
return {
|
|
21
|
-
listenOk: (a) =>
|
|
22
|
-
|
|
23
|
-
return () => t[1].removeListen(a);
|
|
24
|
-
},
|
|
25
|
-
listenError: (a) => {
|
|
26
|
-
c[1].addListen(a);
|
|
27
|
-
return () => c[1].removeListen(a);
|
|
28
|
-
},
|
|
24
|
+
listenOk: (a) => t[1].addListen(a),
|
|
25
|
+
listenError: (a) => c[1].addListen(a),
|
|
29
26
|
promise: {
|
|
30
|
-
all: () => Promise.all(
|
|
31
|
-
allSettled: () => Promise.allSettled(
|
|
27
|
+
all: () => Promise.all(startAll()),
|
|
28
|
+
allSettled: () => Promise.allSettled(startAll()),
|
|
32
29
|
},
|
|
33
30
|
getData() {
|
|
34
|
-
return
|
|
31
|
+
return startAll();
|
|
35
32
|
},
|
|
36
33
|
status() {
|
|
37
34
|
return { ok, error: errorCount, count };
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function createThrottle(): {
|
|
2
|
+
throttle: (ms: number, func: () => any) => void;
|
|
3
|
+
debounce: (ms: number, func: () => any) => Promise<void>;
|
|
2
4
|
throttleAsync: (ms: number, func: () => any) => void;
|
|
3
5
|
debounceAsync: (ms: number, func: () => any) => Promise<void>;
|
|
4
6
|
};
|
|
7
|
+
export declare const enhancedWaitRun: typeof createThrottle;
|
|
5
8
|
export declare function createAsyncQueue(concurrency?: number): {
|
|
6
|
-
|
|
9
|
+
add: <T>(task: () => Promise<T>) => Promise<T>;
|
|
7
10
|
onIdle: () => Promise<void>;
|
|
11
|
+
readonly size: number;
|
|
12
|
+
enqueue: <T>(task: () => Promise<T>) => Promise<T>;
|
|
8
13
|
getQueueSize: () => number;
|
|
9
14
|
};
|
|
10
15
|
export declare function enhancedQueueRun(maxParallelTasks?: number): {
|
|
@@ -23,9 +28,11 @@ export declare function queueRun(n?: number): {
|
|
|
23
28
|
nextRun: () => Promise<any>;
|
|
24
29
|
run: () => Promise<void>;
|
|
25
30
|
};
|
|
26
|
-
export declare function
|
|
31
|
+
export declare function createReadyGate(): {
|
|
27
32
|
add: (fn: () => any) => number | undefined;
|
|
28
|
-
|
|
33
|
+
ready: () => Promise<void>;
|
|
29
34
|
isReady: () => boolean;
|
|
30
35
|
tasks: () => (() => any)[];
|
|
36
|
+
setReady: () => Promise<void>;
|
|
31
37
|
};
|
|
38
|
+
export declare const createTaskQueue: typeof createReadyGate;
|