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
|
@@ -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;
|
|
@@ -166,7 +169,15 @@ class ByteStreamW {
|
|
|
166
169
|
let typeInfo = getNumericTypeInfo(type);
|
|
167
170
|
if (!typeInfo)
|
|
168
171
|
throw ("Wrong type: " + type);
|
|
169
|
-
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
|
+
};
|
|
170
181
|
}
|
|
171
182
|
pushArrayNumeric(array, type, maxlength) {
|
|
172
183
|
return this.pushArrayByFunc(array, this._getWriteFuncForNumeric(type), maxlength);
|
|
@@ -177,10 +188,7 @@ class ByteStreamW {
|
|
|
177
188
|
this._ensureAllocation(length + 4);
|
|
178
189
|
this.pushInt32(length);
|
|
179
190
|
let arrayClass = (array instanceof Int8Array) ? Int8Array : Uint8Array;
|
|
180
|
-
|
|
181
|
-
array = new arrayClass(array.buffer, 0, length);
|
|
182
|
-
}
|
|
183
|
-
new arrayClass(this._buffer()).set(array, this._pos);
|
|
191
|
+
new arrayClass(this._buffer(), this._view.byteOffset + this._pos, length).set(array.subarray(0, length));
|
|
184
192
|
this._pos += length;
|
|
185
193
|
return this;
|
|
186
194
|
}
|
|
@@ -341,6 +349,11 @@ class ByteStreamR_ {
|
|
|
341
349
|
let size = this.readUint32();
|
|
342
350
|
if (size == null)
|
|
343
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;
|
|
344
357
|
let bufpos = this._view.byteOffset + this._pos;
|
|
345
358
|
const out = new arrayClass(this._view.buffer.slice(bufpos, bufpos + size));
|
|
346
359
|
this._pos += size;
|
|
@@ -24,6 +24,7 @@ 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>;
|
|
@@ -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,15 +18,20 @@ 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
37
|
*entries() { let i = 0; for (let node of this.nodes())
|
|
@@ -143,6 +148,10 @@ class CList {
|
|
|
143
148
|
this.delete(this._first); }
|
|
144
149
|
deleteLast() { if (this._last)
|
|
145
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; }
|
|
146
155
|
clear() {
|
|
147
156
|
for (let node = this._first; node != null; node = node.next)
|
|
148
157
|
node.list = undefined;
|
|
@@ -68,8 +68,8 @@ 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) {
|
|
@@ -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;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export type Listener<T extends any[]> = (...r: T) => void;
|
|
2
2
|
export type NormalizeTuple<T> = T extends any[] ? T : [T];
|
|
3
|
-
type key = string;
|
|
3
|
+
type key = string | symbol;
|
|
4
|
+
declare const LISTEN_ON_BRAND: unique symbol;
|
|
5
|
+
export type ListenOn<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: {
|
|
6
|
+
cbClose?: () => void;
|
|
7
|
+
key?: string;
|
|
8
|
+
}) => (() => void)) & {
|
|
9
|
+
readonly [LISTEN_ON_BRAND]: Z;
|
|
10
|
+
};
|
|
11
|
+
export declare function getListenByOn(fn: any): any;
|
|
12
|
+
export declare function isListenOn(fn: any): boolean;
|
|
4
13
|
export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), { fast, event, addListenClose }?: {
|
|
5
14
|
event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void;
|
|
6
15
|
fast?: boolean;
|
|
@@ -11,12 +20,17 @@ export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple
|
|
|
11
20
|
run: () => void;
|
|
12
21
|
close: () => void;
|
|
13
22
|
eventClose: (cb: () => void) => () => void;
|
|
23
|
+
onClose: (cb: () => void) => () => void;
|
|
14
24
|
removeEventClose: (cb: (() => void)) => void;
|
|
15
25
|
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
16
26
|
cbClose?: () => void;
|
|
17
27
|
key?: key;
|
|
18
28
|
}) => () => void;
|
|
19
29
|
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
30
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
31
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
32
|
+
key?: key;
|
|
33
|
+
}) => () => void;
|
|
20
34
|
count: () => number;
|
|
21
35
|
readonly getAllKeys: (Listener<NormalizeTuple<T>> | key)[];
|
|
22
36
|
};
|
|
@@ -26,14 +40,19 @@ export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTupl
|
|
|
26
40
|
run: () => void;
|
|
27
41
|
close: () => void;
|
|
28
42
|
eventClose: (cb: () => void) => () => void;
|
|
43
|
+
onClose: (cb: () => void) => () => void;
|
|
29
44
|
removeEventClose: (cb: () => void) => void;
|
|
30
45
|
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
31
46
|
cbClose?: (() => void) | undefined;
|
|
32
47
|
key?: key;
|
|
33
48
|
}) => () => void;
|
|
34
|
-
removeListen: (k:
|
|
49
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
50
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
51
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
52
|
+
key?: key;
|
|
53
|
+
}) => () => void;
|
|
35
54
|
count: () => number;
|
|
36
|
-
readonly getAllKeys: (
|
|
55
|
+
readonly getAllKeys: (key | Listener<NormalizeTuple<T>>)[];
|
|
37
56
|
};
|
|
38
57
|
export declare const funcListenCallback: typeof funcListenCallbackBase;
|
|
39
58
|
export declare function UseListen<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
@@ -42,14 +61,28 @@ export declare function UseListen<T>(data?: Parameters<typeof funcListenCallback
|
|
|
42
61
|
run: () => void;
|
|
43
62
|
close: () => void;
|
|
44
63
|
eventClose: (cb: () => void) => () => void;
|
|
64
|
+
onClose: (cb: () => void) => () => void;
|
|
45
65
|
removeEventClose: (cb: () => void) => void;
|
|
46
66
|
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
47
67
|
cbClose?: (() => void) | undefined;
|
|
48
68
|
key?: key;
|
|
49
69
|
}) => () => void;
|
|
50
|
-
removeListen: (k:
|
|
70
|
+
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
71
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
72
|
+
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
73
|
+
key?: key;
|
|
74
|
+
}) => () => void;
|
|
51
75
|
count: () => number;
|
|
52
|
-
readonly getAllKeys: (
|
|
76
|
+
readonly getAllKeys: (key | Listener<NormalizeTuple<T>>)[];
|
|
53
77
|
}];
|
|
78
|
+
export type Listen2<T> = {
|
|
79
|
+
on: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
80
|
+
key?: string;
|
|
81
|
+
}) => (() => void);
|
|
82
|
+
close: () => void;
|
|
83
|
+
count: () => number;
|
|
84
|
+
};
|
|
85
|
+
export declare function toListen2<T>(full: ReturnType<typeof funcListenCallbackBase<T>>): Listen2<T>;
|
|
86
|
+
export declare function UseListen2<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, Listen2<T>];
|
|
54
87
|
export declare function isListenCallback(obj: any): obj is ReturnType<typeof funcListenCallbackBase>;
|
|
55
88
|
export {};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.funcListenCallback = void 0;
|
|
4
|
+
exports.getListenByOn = getListenByOn;
|
|
5
|
+
exports.isListenOn = isListenOn;
|
|
4
6
|
exports.funcListenCallbackBase = funcListenCallbackBase;
|
|
5
7
|
exports.funcListenCallbackFast = funcListenCallbackFast;
|
|
6
8
|
exports.UseListen = UseListen;
|
|
9
|
+
exports.toListen2 = toListen2;
|
|
10
|
+
exports.UseListen2 = UseListen2;
|
|
7
11
|
exports.isListenCallback = isListenCallback;
|
|
12
|
+
const listenByOn = new WeakMap();
|
|
13
|
+
function getListenByOn(fn) { return typeof fn == "function" ? listenByOn.get(fn) : undefined; }
|
|
14
|
+
function isListenOn(fn) { return typeof fn == "function" && listenByOn.has(fn); }
|
|
8
15
|
function funcListenCallbackBase(b, { fast = true, event, addListenClose } = {}) {
|
|
9
16
|
const obj = new Map();
|
|
10
|
-
const
|
|
11
|
-
|
|
17
|
+
const cbKeys = new Map();
|
|
18
|
+
let evClose = null;
|
|
19
|
+
let sinh = null;
|
|
12
20
|
let a = (...e) => { obj.forEach(z => z(...e)); };
|
|
13
21
|
let close = null;
|
|
14
22
|
let cached = null;
|
|
@@ -37,6 +45,34 @@ function funcListenCallbackBase(b, { fast = true, event, addListenClose } = {})
|
|
|
37
45
|
});
|
|
38
46
|
};
|
|
39
47
|
const func = (...e) => { a?.(...e); };
|
|
48
|
+
function forgetKey(k) {
|
|
49
|
+
const removed = obj.get(k);
|
|
50
|
+
if (typeof removed == "function") {
|
|
51
|
+
const keys = cbKeys.get(removed);
|
|
52
|
+
if (keys) {
|
|
53
|
+
const i = keys.indexOf(k);
|
|
54
|
+
if (i >= 0)
|
|
55
|
+
keys.splice(i, 1);
|
|
56
|
+
if (keys.length == 0)
|
|
57
|
+
cbKeys.delete(removed);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const e = evClose?.get(k);
|
|
61
|
+
evClose?.delete(k);
|
|
62
|
+
if (e) {
|
|
63
|
+
evClose?.delete(e);
|
|
64
|
+
sinh?.delete(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function removeKey(k) {
|
|
68
|
+
if (!obj.has(k))
|
|
69
|
+
return;
|
|
70
|
+
obj.delete(k);
|
|
71
|
+
forgetKey(k);
|
|
72
|
+
if (fast)
|
|
73
|
+
rebuild();
|
|
74
|
+
event?.("remove", obj.size, api);
|
|
75
|
+
}
|
|
40
76
|
const run = () => {
|
|
41
77
|
close = (b(func) ?? (() => { }));
|
|
42
78
|
if (addListenClose && !closeUnsubscribe) {
|
|
@@ -53,62 +89,69 @@ function funcListenCallbackBase(b, { fast = true, event, addListenClose } = {})
|
|
|
53
89
|
close?.();
|
|
54
90
|
close = null;
|
|
55
91
|
obj.clear();
|
|
92
|
+
cbKeys.clear();
|
|
56
93
|
if (fast)
|
|
57
94
|
rebuild();
|
|
58
|
-
sinh
|
|
59
|
-
|
|
60
|
-
|
|
95
|
+
sinh = null;
|
|
96
|
+
if (evClose) {
|
|
97
|
+
evClose.forEach(cb => cb());
|
|
98
|
+
evClose = null;
|
|
99
|
+
}
|
|
61
100
|
if (closeUnsubscribe) {
|
|
62
101
|
closeUnsubscribe();
|
|
63
102
|
closeUnsubscribe = null;
|
|
64
103
|
}
|
|
65
104
|
},
|
|
66
105
|
eventClose: (cb) => {
|
|
106
|
+
evClose = evClose ?? new Map();
|
|
67
107
|
evClose.set(cb, cb);
|
|
68
|
-
return () => { evClose
|
|
108
|
+
return () => { evClose?.delete(cb); };
|
|
69
109
|
},
|
|
110
|
+
onClose: (cb) => api.eventClose(cb),
|
|
70
111
|
removeEventClose: (cb) => {
|
|
71
|
-
const e = sinh
|
|
112
|
+
const e = sinh?.get(cb);
|
|
72
113
|
if (e)
|
|
73
|
-
evClose
|
|
74
|
-
sinh
|
|
75
|
-
evClose
|
|
114
|
+
evClose?.delete(e);
|
|
115
|
+
sinh?.delete(cb);
|
|
116
|
+
evClose?.delete(cb);
|
|
76
117
|
},
|
|
77
118
|
addListen: (cb, { cbClose, key } = {}) => {
|
|
78
|
-
const k = key ??
|
|
119
|
+
const k = key ?? Symbol();
|
|
120
|
+
if (obj.has(k))
|
|
121
|
+
forgetKey(k);
|
|
79
122
|
obj.set(k, cb);
|
|
123
|
+
let keys = cbKeys.get(cb);
|
|
124
|
+
if (!keys)
|
|
125
|
+
cbKeys.set(cb, keys = []);
|
|
126
|
+
keys.push(k);
|
|
80
127
|
if (cbClose) {
|
|
81
|
-
|
|
82
|
-
const r = evClose.get(k);
|
|
83
|
-
if (r !== cbClose) {
|
|
84
|
-
evClose.delete(r);
|
|
85
|
-
evClose.delete(k);
|
|
86
|
-
sinh.delete(r);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
128
|
+
evClose = evClose ?? new Map();
|
|
89
129
|
evClose.set(k, cbClose);
|
|
130
|
+
sinh = sinh ?? new Map();
|
|
90
131
|
sinh.set(cbClose, cb);
|
|
91
132
|
}
|
|
92
133
|
if (fast)
|
|
93
134
|
rebuild();
|
|
94
135
|
event?.("add", obj.size, api);
|
|
95
|
-
return () =>
|
|
136
|
+
return () => removeKey(k);
|
|
96
137
|
},
|
|
97
138
|
removeListen: (k) => {
|
|
98
|
-
obj.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
139
|
+
if (typeof k == "function" && !obj.has(k))
|
|
140
|
+
for (const kk of [...(cbKeys.get(k) ?? [])])
|
|
141
|
+
removeKey(kk);
|
|
142
|
+
else
|
|
143
|
+
removeKey(k);
|
|
144
|
+
},
|
|
145
|
+
on: ((cb, opts = {}) => api.addListen(cb, opts)),
|
|
146
|
+
once: (cb, opts = {}) => {
|
|
147
|
+
let off = () => { };
|
|
148
|
+
off = api.addListen(((...e) => { off(); cb(...e); }), opts);
|
|
149
|
+
return off;
|
|
108
150
|
},
|
|
109
151
|
count: () => obj.size,
|
|
110
152
|
get getAllKeys() { return [...obj.keys()]; }
|
|
111
153
|
};
|
|
154
|
+
listenByOn.set(api.on, api);
|
|
112
155
|
return api;
|
|
113
156
|
}
|
|
114
157
|
function funcListenCallbackFast(a) {
|
|
@@ -122,35 +165,27 @@ function UseListen(data = { fast: true }) {
|
|
|
122
165
|
t = a.func;
|
|
123
166
|
return [t, a];
|
|
124
167
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
referenceTypes = new Map();
|
|
132
|
-
for (const key of referenceKeys) {
|
|
133
|
-
referenceTypes.set(key, typeof demo[key]);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return { keys: referenceKeys, types: referenceTypes };
|
|
168
|
+
function toListen2(full) {
|
|
169
|
+
return {
|
|
170
|
+
on: (cb, opts) => full.addListen(cb, opts),
|
|
171
|
+
close: () => full.close(),
|
|
172
|
+
count: () => full.count(),
|
|
173
|
+
};
|
|
137
174
|
}
|
|
175
|
+
function UseListen2(data = { fast: true }) {
|
|
176
|
+
const [emit, full] = UseListen(data);
|
|
177
|
+
return [emit, toListen2(full)];
|
|
178
|
+
}
|
|
179
|
+
const LISTEN_CORE = ["func", "addListen", "removeListen", "eventClose", "removeEventClose"];
|
|
138
180
|
function isListenCallback(obj) {
|
|
139
181
|
if (obj == null || typeof obj !== "object")
|
|
140
182
|
return false;
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
return false;
|
|
145
|
-
for (let i = 0; i < refKeys.length; i++) {
|
|
146
|
-
if (objKeys[i] !== refKeys[i])
|
|
183
|
+
const ks = new Set(Object.keys(obj));
|
|
184
|
+
for (const k of LISTEN_CORE)
|
|
185
|
+
if (!ks.has(k))
|
|
147
186
|
return false;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const expectedType = refTypes.get(key);
|
|
151
|
-
const actualType = typeof obj[key];
|
|
152
|
-
if (actualType !== expectedType)
|
|
187
|
+
for (const k of LISTEN_CORE)
|
|
188
|
+
if (typeof obj[k] !== "function")
|
|
153
189
|
return false;
|
|
154
|
-
}
|
|
155
190
|
return true;
|
|
156
191
|
}
|
|
@@ -20,7 +20,7 @@ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | a
|
|
|
20
20
|
}): {
|
|
21
21
|
run: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, params_1?: {
|
|
22
22
|
cbClose?: (() => void) | undefined;
|
|
23
|
-
key?: string;
|
|
23
|
+
key?: string | symbol;
|
|
24
24
|
} | undefined) => () => void;
|
|
25
25
|
snapshot: () => T3 | undefined;
|
|
26
26
|
memo: T4;
|
|
@@ -30,14 +30,19 @@ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | a
|
|
|
30
30
|
run: () => void;
|
|
31
31
|
close: () => void;
|
|
32
32
|
eventClose: (cb: () => void) => () => void;
|
|
33
|
+
onClose: (cb: () => void) => () => void;
|
|
33
34
|
removeEventClose: (cb: () => void) => void;
|
|
34
35
|
addListen: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, { cbClose, key }?: {
|
|
35
36
|
cbClose?: (() => void) | undefined;
|
|
36
|
-
key?: string;
|
|
37
|
+
key?: string | symbol;
|
|
38
|
+
}) => () => void;
|
|
39
|
+
removeListen: (k: (string | symbol) | import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
|
|
40
|
+
on: import("./Listen").ListenOn<[data: getTypeCallback<T>, memo: T3]>;
|
|
41
|
+
once: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, opts?: {
|
|
42
|
+
key?: string | symbol;
|
|
37
43
|
}) => () => void;
|
|
38
|
-
removeListen: (k: string | import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
|
|
39
44
|
count: () => number;
|
|
40
|
-
readonly getAllKeys: (string | import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>)[];
|
|
45
|
+
readonly getAllKeys: ((string | symbol) | import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>)[];
|
|
41
46
|
};
|
|
42
47
|
connect: () => void;
|
|
43
48
|
readonly disconnect: ((a: Omit<Parameters<T>[0], "callback"> & {
|
|
@@ -10,14 +10,19 @@ export declare function SocketServerHook(opt?: {
|
|
|
10
10
|
run: () => void;
|
|
11
11
|
close: () => void;
|
|
12
12
|
eventClose: (cb: () => void) => () => void;
|
|
13
|
+
onClose: (cb: () => void) => () => void;
|
|
13
14
|
removeEventClose: (cb: () => void) => void;
|
|
14
15
|
addListen: (cb: import("./Listen").Listener<[unknown]>, { cbClose, key }?: {
|
|
15
16
|
cbClose?: (() => void) | undefined;
|
|
16
|
-
key?: string;
|
|
17
|
+
key?: string | symbol;
|
|
18
|
+
}) => () => void;
|
|
19
|
+
removeListen: (k: (string | symbol) | import("./Listen").Listener<[unknown]> | null) => void;
|
|
20
|
+
on: import("./Listen").ListenOn<[unknown]>;
|
|
21
|
+
once: (cb: import("./Listen").Listener<[unknown]>, opts?: {
|
|
22
|
+
key?: string | symbol;
|
|
17
23
|
}) => () => void;
|
|
18
|
-
removeListen: (k: string | import("./Listen").Listener<[unknown]> | null) => void;
|
|
19
24
|
count: () => number;
|
|
20
|
-
readonly getAllKeys: (string | import("./Listen").Listener<[unknown]>)[];
|
|
25
|
+
readonly getAllKeys: ((string | symbol) | import("./Listen").Listener<[unknown]>)[];
|
|
21
26
|
}];
|
|
22
27
|
};
|
|
23
28
|
get(tag: string): readonly [(a_0: unknown) => void, {
|
|
@@ -26,14 +31,19 @@ export declare function SocketServerHook(opt?: {
|
|
|
26
31
|
run: () => void;
|
|
27
32
|
close: () => void;
|
|
28
33
|
eventClose: (cb: () => void) => () => void;
|
|
34
|
+
onClose: (cb: () => void) => () => void;
|
|
29
35
|
removeEventClose: (cb: () => void) => void;
|
|
30
36
|
addListen: (cb: import("./Listen").Listener<[unknown]>, { cbClose, key }?: {
|
|
31
37
|
cbClose?: (() => void) | undefined;
|
|
32
|
-
key?: string;
|
|
38
|
+
key?: string | symbol;
|
|
39
|
+
}) => () => void;
|
|
40
|
+
removeListen: (k: (string | symbol) | import("./Listen").Listener<[unknown]> | null) => void;
|
|
41
|
+
on: import("./Listen").ListenOn<[unknown]>;
|
|
42
|
+
once: (cb: import("./Listen").Listener<[unknown]>, opts?: {
|
|
43
|
+
key?: string | symbol;
|
|
33
44
|
}) => () => void;
|
|
34
|
-
removeListen: (k: string | import("./Listen").Listener<[unknown]> | null) => void;
|
|
35
45
|
count: () => number;
|
|
36
|
-
readonly getAllKeys: (string | import("./Listen").Listener<[unknown]>)[];
|
|
46
|
+
readonly getAllKeys: ((string | symbol) | import("./Listen").Listener<[unknown]>)[];
|
|
37
47
|
}];
|
|
38
48
|
provider: (tag: string, data: any) => void;
|
|
39
49
|
};
|
|
@@ -41,7 +51,10 @@ export declare function WebSocketServerHook(s: ReturnType<typeof SocketServerHoo
|
|
|
41
51
|
disconnect(): void;
|
|
42
52
|
get: {
|
|
43
53
|
[k: string]: {
|
|
44
|
-
callback: (z: (...args: any[]) => void) =>
|
|
54
|
+
callback: (z: (...args: any[]) => void) => import("../rcp/listen-socket").tSubHandle;
|
|
55
|
+
on: (z: (...args: any[]) => void) => import("../rcp/listen-socket").tSubHandle;
|
|
56
|
+
once: (z: (...args: any[]) => void) => import("../rcp/listen-socket").tSubHandle;
|
|
57
|
+
close: () => void;
|
|
45
58
|
removeCallback: () => boolean;
|
|
46
59
|
};
|
|
47
60
|
};
|
|
@@ -23,9 +23,10 @@ function SocketServerHook(opt) {
|
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
25
|
function WebSocketServerHook(s, paramsSoc, disconnect) {
|
|
26
|
+
const wrappers = {};
|
|
26
27
|
const get = new Proxy(s.obj, {
|
|
27
28
|
get(target, p, receiver) {
|
|
28
|
-
return (0, listen_socket_1.listenSocketSmart)(s.get(p)[1], paramsSoc);
|
|
29
|
+
return wrappers[p] ??= (0, listen_socket_1.listenSocketSmart)(s.get(p)[1], paramsSoc);
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
32
|
return {
|
|
@@ -7,12 +7,17 @@ export declare function UseListenTransform<TSource extends any[], TTarget extend
|
|
|
7
7
|
run: () => void;
|
|
8
8
|
close: () => void;
|
|
9
9
|
eventClose: (cb: () => void) => () => void;
|
|
10
|
+
onClose: (cb: () => void) => () => void;
|
|
10
11
|
removeEventClose: (cb: () => void) => void;
|
|
11
12
|
addListen: (cb: Listener<NormalizeTuple<TTarget>>, { cbClose, key }?: {
|
|
12
13
|
cbClose?: (() => void) | undefined;
|
|
13
|
-
key?: string;
|
|
14
|
+
key?: string | symbol;
|
|
15
|
+
}) => () => void;
|
|
16
|
+
removeListen: (k: (string | symbol) | Listener<NormalizeTuple<TTarget>> | null) => void;
|
|
17
|
+
on: import("./Listen").ListenOn<NormalizeTuple<TTarget>>;
|
|
18
|
+
once: (cb: Listener<NormalizeTuple<TTarget>>, opts?: {
|
|
19
|
+
key?: string | symbol;
|
|
14
20
|
}) => () => void;
|
|
15
|
-
removeListen: (k: string | Listener<NormalizeTuple<TTarget>> | null) => void;
|
|
16
21
|
count: () => number;
|
|
17
|
-
readonly getAllKeys: (string | Listener<NormalizeTuple<TTarget>>)[];
|
|
22
|
+
readonly getAllKeys: ((string | symbol) | Listener<NormalizeTuple<TTarget>>)[];
|
|
18
23
|
}];
|
|
@@ -10,11 +10,17 @@ export declare class CObjectEventsArr<T extends object> {
|
|
|
10
10
|
AddStart(data: tListEvent): void;
|
|
11
11
|
AddEnd(data: tListEvent): void;
|
|
12
12
|
Add(data: tListEvent): void;
|
|
13
|
+
add(data: tListEvent, opts?: {
|
|
14
|
+
at?: 'start' | 'end';
|
|
15
|
+
}): void;
|
|
13
16
|
OnEvent(data?: any): void;
|
|
17
|
+
emit(data?: any): void;
|
|
14
18
|
OnSpecEvent(f: (e: T) => void): void;
|
|
15
19
|
Clean(): void;
|
|
20
|
+
clear(): void;
|
|
16
21
|
count(): number;
|
|
17
22
|
get length(): number;
|
|
23
|
+
get size(): number;
|
|
18
24
|
}
|
|
19
25
|
export declare class CObjectEventsList<T = unknown> {
|
|
20
26
|
constructor(log?: boolean);
|
|
@@ -26,9 +32,15 @@ export declare class CObjectEventsList<T = unknown> {
|
|
|
26
32
|
AddStart(data: tListEvent): void;
|
|
27
33
|
AddEnd(data: tListEvent): void;
|
|
28
34
|
Add(data: tListEvent): void;
|
|
35
|
+
add(data: tListEvent, opts?: {
|
|
36
|
+
at?: 'start' | 'end';
|
|
37
|
+
}): void;
|
|
29
38
|
OnEvent(data?: T): void;
|
|
39
|
+
emit(data?: T): void;
|
|
30
40
|
OnSpecEvent<R>(f: (e?: R) => void): void;
|
|
31
41
|
Clean(): void;
|
|
42
|
+
clear(): void;
|
|
32
43
|
count(): number;
|
|
33
44
|
get length(): number;
|
|
45
|
+
get size(): number;
|
|
34
46
|
}
|