wenay-common2 1.0.1

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.
Files changed (94) hide show
  1. package/lib/Common/Color.d.ts +31 -0
  2. package/lib/Common/Color.js +115 -0
  3. package/lib/Common/Time.d.ts +206 -0
  4. package/lib/Common/Time.js +393 -0
  5. package/lib/Common/WebHook2.d.ts +0 -0
  6. package/lib/Common/WebHook2.js +1 -0
  7. package/lib/Common/WebHook3.d.ts +39 -0
  8. package/lib/Common/WebHook3.js +211 -0
  9. package/lib/Common/async/PromiseArrayListen.d.ts +14 -0
  10. package/lib/Common/async/PromiseArrayListen.js +41 -0
  11. package/lib/Common/async/createIterableObject.d.ts +6 -0
  12. package/lib/Common/async/createIterableObject.js +66 -0
  13. package/lib/Common/async/waitRun.d.ts +31 -0
  14. package/lib/Common/async/waitRun.js +104 -0
  15. package/lib/Common/core/BaseTypes.d.ts +38 -0
  16. package/lib/Common/core/BaseTypes.js +2 -0
  17. package/lib/Common/core/Decorator.d.ts +24 -0
  18. package/lib/Common/core/Decorator.js +50 -0
  19. package/lib/Common/core/MemoFunc.d.ts +19 -0
  20. package/lib/Common/core/MemoFunc.js +99 -0
  21. package/lib/Common/core/common.d.ts +253 -0
  22. package/lib/Common/core/common.js +773 -0
  23. package/lib/Common/data/ByteStream.d.ts +96 -0
  24. package/lib/Common/data/ByteStream.js +440 -0
  25. package/lib/Common/data/List.d.ts +64 -0
  26. package/lib/Common/data/List.js +193 -0
  27. package/lib/Common/data/ListNodeAnd.d.ts +46 -0
  28. package/lib/Common/data/ListNodeAnd.js +89 -0
  29. package/lib/Common/data/objectPath.d.ts +11 -0
  30. package/lib/Common/data/objectPath.js +59 -0
  31. package/lib/Common/events/Listen.d.ts +55 -0
  32. package/lib/Common/events/Listen.js +124 -0
  33. package/lib/Common/events/SocketBuffer.d.ts +41 -0
  34. package/lib/Common/events/SocketBuffer.js +43 -0
  35. package/lib/Common/events/SocketServerHook.d.ts +47 -0
  36. package/lib/Common/events/SocketServerHook.js +38 -0
  37. package/lib/Common/events/event.d.ts +34 -0
  38. package/lib/Common/events/event.js +77 -0
  39. package/lib/Common/events/joinListens.d.ts +17 -0
  40. package/lib/Common/events/joinListens.js +40 -0
  41. package/lib/Common/fsKeyVolume.d.ts +34 -0
  42. package/lib/Common/fsKeyVolume.js +92 -0
  43. package/lib/Common/funcTimeWait.d.ts +29 -0
  44. package/lib/Common/funcTimeWait.js +116 -0
  45. package/lib/Common/id-pool.d.ts +5 -0
  46. package/lib/Common/id-pool.js +12 -0
  47. package/lib/Common/inputAutoStep.d.ts +14 -0
  48. package/lib/Common/inputAutoStep.js +65 -0
  49. package/lib/Common/isProxy.d.ts +2 -0
  50. package/lib/Common/isProxy.js +40 -0
  51. package/lib/Common/math/Math.d.ts +12 -0
  52. package/lib/Common/math/Math.js +73 -0
  53. package/lib/Common/math/other.d.ts +23 -0
  54. package/lib/Common/math/other.js +70 -0
  55. package/lib/Common/math/scoreLana.d.ts +22 -0
  56. package/lib/Common/math/scoreLana.js +67 -0
  57. package/lib/Common/node_console.d.ts +6 -0
  58. package/lib/Common/node_console.js +170 -0
  59. package/lib/Common/rcp/listen-deep.d.ts +20 -0
  60. package/lib/Common/rcp/listen-deep.js +49 -0
  61. package/lib/Common/rcp/listen-socket.d.ts +25 -0
  62. package/lib/Common/rcp/listen-socket.js +105 -0
  63. package/lib/Common/rcp/rpc-client-auto.d.ts +12 -0
  64. package/lib/Common/rcp/rpc-client-auto.js +20 -0
  65. package/lib/Common/rcp/rpc-client.d.ts +30 -0
  66. package/lib/Common/rcp/rpc-client.js +169 -0
  67. package/lib/Common/rcp/rpc-dynamic.d.ts +2 -0
  68. package/lib/Common/rcp/rpc-dynamic.js +12 -0
  69. package/lib/Common/rcp/rpc-index.d.ts +8 -0
  70. package/lib/Common/rcp/rpc-index.js +24 -0
  71. package/lib/Common/rcp/rpc-limits.d.ts +14 -0
  72. package/lib/Common/rcp/rpc-limits.js +24 -0
  73. package/lib/Common/rcp/rpc-protocol.d.ts +12 -0
  74. package/lib/Common/rcp/rpc-protocol.js +4 -0
  75. package/lib/Common/rcp/rpc-server-auto.d.ts +15 -0
  76. package/lib/Common/rcp/rpc-server-auto.js +28 -0
  77. package/lib/Common/rcp/rpc-server.d.ts +27 -0
  78. package/lib/Common/rcp/rpc-server.js +175 -0
  79. package/lib/Common/rcp/rpc-walk.d.ts +8 -0
  80. package/lib/Common/rcp/rpc-walk.js +82 -0
  81. package/lib/Exchange/Bars.d.ts +181 -0
  82. package/lib/Exchange/Bars.js +475 -0
  83. package/lib/Exchange/CParams.d.ts +225 -0
  84. package/lib/Exchange/CParams.js +244 -0
  85. package/lib/client.d.ts +31 -0
  86. package/lib/client.js +70 -0
  87. package/lib/index.d.ts +31 -0
  88. package/lib/index.js +70 -0
  89. package/lib/server.d.ts +3 -0
  90. package/lib/server.js +19 -0
  91. package/lib/toError/myThrow.d.ts +5 -0
  92. package/lib/toError/myThrow.js +23 -0
  93. package/lib/tsconfig.json +6 -0
  94. package/package.json +32 -0
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CList = void 0;
4
+ class CListNode {
5
+ value;
6
+ list;
7
+ next;
8
+ prev;
9
+ [Symbol.species] = this;
10
+ constructor(list, value) { this.list = list; this.value = value; }
11
+ }
12
+ class CList {
13
+ _first;
14
+ _last;
15
+ _count = 0;
16
+ _immutableList;
17
+ get first() { return this._first; }
18
+ get last() { return this._last; }
19
+ get count() { return this._count; }
20
+ get length() { return this._count; }
21
+ [Symbol.iterator] = this.nodes;
22
+ constructor(values = []) { for (let value of values)
23
+ this.add(value); }
24
+ *nodes() { for (let node = this._first, next = node?.next; node != null; node = next, next = next?.next)
25
+ yield node; }
26
+ *values() { for (let node of this)
27
+ yield node.value; }
28
+ *reversedNodes() { for (let node = this._last, next = node?.prev; node != null; node = next, next = next?.prev)
29
+ yield node; }
30
+ *reversedValues() { for (let node of this.reversedNodes())
31
+ yield node.value; }
32
+ *entries() { return this.nodes; }
33
+ next(node) { return this.validateNode(node) ? node.next : (() => { throw "Wrong node list"; })(); }
34
+ ;
35
+ prev(node) { return this.validateNode(node) ? node.prev : (() => { throw "Wrong node list"; })(); }
36
+ ;
37
+ find(value) { for (let node of this.nodes())
38
+ if (node.value == value)
39
+ return node; return undefined; }
40
+ findLast(value) { for (let node of this.reversedNodes())
41
+ if (node.value == value)
42
+ return node; return undefined; }
43
+ containsValue(value) { return this.find(value) != undefined; }
44
+ containsNode(node) { return this.validateNode(node); }
45
+ has(data) { return data instanceof CListNode ? this.containsNode(data) : this.containsValue(data); }
46
+ toImmutable() { return this._immutableList ??= new CList(this.values()); }
47
+ _addFirst(value) {
48
+ this._count = 1;
49
+ this._immutableList = undefined;
50
+ return this._first = this._last = this.newNode(value);
51
+ }
52
+ addFirst(value) {
53
+ if (this._first)
54
+ return this.addBefore(this._first, value);
55
+ return this._addFirst(value);
56
+ }
57
+ addLast(value) {
58
+ if (this._last)
59
+ return this.addAfter(this._last, value);
60
+ return this._addFirst(value);
61
+ }
62
+ addAfter(node, value) {
63
+ if (!this.validateNode(node))
64
+ throw "Wrong node list";
65
+ let newNode = this.newNode(value);
66
+ newNode.prev = node;
67
+ newNode.next = node.next;
68
+ if (node.next)
69
+ node.next.prev = newNode;
70
+ else
71
+ this._last = newNode;
72
+ node.next = newNode;
73
+ this._count++;
74
+ this._immutableList = undefined;
75
+ return newNode;
76
+ }
77
+ addBefore(node, value) {
78
+ if (!this.validateNode(node))
79
+ throw "Wrong node list";
80
+ let newNode = this.newNode(value);
81
+ newNode.next = node;
82
+ newNode.prev = node.prev;
83
+ if (node.prev)
84
+ node.prev.next = newNode;
85
+ else
86
+ this._first = newNode;
87
+ node.prev = newNode;
88
+ this._count++;
89
+ this._immutableList = undefined;
90
+ return newNode;
91
+ }
92
+ add(value) { return this.addLast(value); }
93
+ set(node, value) {
94
+ if (!this.validateNode(node))
95
+ throw "Wrong node list";
96
+ node.value = value;
97
+ return node;
98
+ }
99
+ replace(node, value) {
100
+ if (!this.validateNode(node))
101
+ throw "Wrong node list";
102
+ let newNode = this.newNode(value);
103
+ newNode.next = node.next;
104
+ newNode.prev = node.prev;
105
+ node.list = undefined;
106
+ this._immutableList = undefined;
107
+ return newNode;
108
+ }
109
+ deleteNode(node) {
110
+ if (!this.validateNode(node))
111
+ throw "Wrong node list";
112
+ if (node.prev)
113
+ node.prev.next = node.next;
114
+ if (node.next)
115
+ node.next.prev = node.prev;
116
+ if (node == this._first)
117
+ this._first = node.next;
118
+ if (node == this._last)
119
+ this._last = node.prev;
120
+ node.list = undefined;
121
+ this._count--;
122
+ this._immutableList = undefined;
123
+ }
124
+ delete(nodeOrValue) {
125
+ { }
126
+ if (nodeOrValue instanceof CListNode)
127
+ return this.deleteNode(nodeOrValue);
128
+ for (let node of this.nodes())
129
+ if (node.value == nodeOrValue)
130
+ this.deleteNode(node);
131
+ }
132
+ deleteFirst() { if (this._first)
133
+ this.delete(this._first); }
134
+ deleteLast() { if (this._last)
135
+ this.delete(this._last); }
136
+ clear() {
137
+ for (let node = this._first; node != null; node = node.next)
138
+ this.delete(node);
139
+ }
140
+ validateNode(node) {
141
+ if (!(node instanceof CListNode))
142
+ throw "Wrong node object";
143
+ return node.list == this;
144
+ }
145
+ newNode(value) { return new CListNode(this, value); }
146
+ }
147
+ exports.CList = CList;
148
+ function test() {
149
+ function print(...args) { console.log(...args); }
150
+ let list = new CList();
151
+ let node10 = list.add(10);
152
+ print(...list.values());
153
+ let node20 = list.add(20);
154
+ print(...list.values());
155
+ let node15 = list.addAfter(node10, 15);
156
+ print(...list.values());
157
+ let node30 = list.addAfter(node20, 30);
158
+ print(...list.values());
159
+ let node25 = list.addBefore(node30, 25);
160
+ print(...list.values());
161
+ let node5 = list.addBefore(node10, 5);
162
+ print(...list.values());
163
+ let node0 = list.addFirst(0);
164
+ print(...list.values());
165
+ print("count:", list.count);
166
+ print("deleting node20");
167
+ list.delete(node20);
168
+ print(...list.values());
169
+ print("count:", list.count);
170
+ print("contains node20:", list.has(node20));
171
+ print("contains 20:", list.has(20));
172
+ print("find 20 -> value:", list.find(20)?.value);
173
+ print("contains node10:", list.has(node10));
174
+ print("contains 10:", list.has(10));
175
+ print("find 10 -> value:", list.find(10)?.value);
176
+ print("adding last 5");
177
+ let nodeLast = list.add(5);
178
+ print(...list.values());
179
+ let listImm = list.toImmutable();
180
+ print("findLast 5 -> prevValue: ", listImm.findLast(5)?.prev?.value);
181
+ print("node15 prev:", list.prev(node15)?.value);
182
+ print("node15 next:", list.next(node15)?.value);
183
+ print("node0 prev:", list.prev(node0)?.value);
184
+ print("nodeLast next:", listImm.next(nodeLast)?.next);
185
+ print("reversed: ", ...list.reversedValues());
186
+ print("deleting 5");
187
+ list.delete(5);
188
+ print(...list.values());
189
+ print("clearing");
190
+ list.clear();
191
+ print(...list.values());
192
+ print("count:", list.count);
193
+ }
@@ -0,0 +1,46 @@
1
+ declare class CBaseList<T> {
2
+ data: T | undefined;
3
+ }
4
+ export declare class CListNodeAnd<T> extends CBaseList<T> implements iListNodeMini {
5
+ get count(): number;
6
+ private _stop;
7
+ protected _count: number;
8
+ private _prev;
9
+ private _next;
10
+ private _home;
11
+ private _Init;
12
+ constructor(prev?: CListNodeAnd<T>, next?: CListNodeAnd<T>, home?: CListNodeAnd<T>);
13
+ static _valueG: number;
14
+ static _valueG2: number;
15
+ readonly id: number;
16
+ valueOf(): number;
17
+ countRef(): number;
18
+ Prev(): CListNodeAnd<T> | undefined;
19
+ Next(): CListNodeAnd<T> | undefined;
20
+ isPrev(): boolean;
21
+ isNext(): boolean;
22
+ private _First;
23
+ private _End;
24
+ First(): CListNodeAnd<T> | undefined;
25
+ End(): CListNodeAnd<T> | undefined;
26
+ get dataFirst(): T | undefined;
27
+ get dataEnd(): T | undefined;
28
+ get dataPrev(): T | undefined;
29
+ get dataNext(): T | undefined;
30
+ get dataThis(): T | undefined;
31
+ isForbidden(): boolean;
32
+ isExists(): boolean;
33
+ private static _Add;
34
+ AddNext(a?: CListNodeAnd<T> | T): CListNodeAnd<T>;
35
+ AddPrev(a?: CListNodeAnd<T> | T): CListNodeAnd<T>;
36
+ AddEnd(a?: CListNodeAnd<T> | T): CListNodeAnd<T>;
37
+ AddStart(a?: CListNodeAnd<T> | T): CListNodeAnd<T>;
38
+ forEach(el: (item: T, e?: CListNodeAnd<T>) => void): void;
39
+ GetArray(): T[];
40
+ find(el: (e: CListNodeAnd<T>) => boolean): CListNodeAnd<T> | undefined;
41
+ DeleteLink(): void;
42
+ }
43
+ export interface iListNodeMini {
44
+ DeleteLink(): void;
45
+ }
46
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CListNodeAnd = void 0;
4
+ class CBaseList {
5
+ data;
6
+ }
7
+ class CListNodeAnd extends CBaseList {
8
+ get count() {
9
+ return this._home?._count ?? -1;
10
+ }
11
+ _stop = false;
12
+ _count = 0;
13
+ _prev = this;
14
+ _next = this;
15
+ _home;
16
+ _Init(prev, next, home) {
17
+ this._prev = prev;
18
+ this._next = next;
19
+ prev._next = next._prev = this;
20
+ this._home = home;
21
+ this.countRef();
22
+ return this;
23
+ }
24
+ constructor(prev, next, home) {
25
+ super();
26
+ CListNodeAnd._valueG++;
27
+ CListNodeAnd._valueG2++;
28
+ this.id = CListNodeAnd._valueG;
29
+ if (prev && next && home) {
30
+ this._Init(prev, next, home);
31
+ }
32
+ else {
33
+ this._stop = true;
34
+ this._home = this;
35
+ }
36
+ }
37
+ ;
38
+ static _valueG = 0;
39
+ static _valueG2 = 0;
40
+ id = CListNodeAnd._valueG;
41
+ valueOf() { return this.id; }
42
+ countRef() {
43
+ let count = 0;
44
+ for (let i = this.First(); i; i = i.Next()) {
45
+ count++;
46
+ }
47
+ if (this._home)
48
+ this._home._count = count;
49
+ return count;
50
+ }
51
+ Prev() { return !this._prev._stop ? this._prev : undefined; }
52
+ Next() { return !this._next._stop ? this._next : undefined; }
53
+ isPrev() { return !this._prev._stop; }
54
+ isNext() { return !this._next._stop; }
55
+ _First() { let buf = this; while (!buf._stop) {
56
+ buf = buf._prev;
57
+ } return buf; }
58
+ _End() { let buf = this; while (!buf._stop) {
59
+ buf = buf._next;
60
+ } return buf; }
61
+ First() { return this._First().Next(); }
62
+ End() { return this._End().Prev(); }
63
+ get dataFirst() { return this._First().dataNext; }
64
+ get dataEnd() { return this._End().dataPrev; }
65
+ get dataPrev() { return this.Prev()?.data; }
66
+ get dataNext() { return this.Next()?.data; }
67
+ get dataThis() { return this._stop ? undefined : this.data; }
68
+ isForbidden() { return this._stop; }
69
+ isExists() { return this.isForbidden() || this._prev._stop || this._next._stop; }
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) : a ? 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) : a ? CListNodeAnd._Add(this._prev, this, this._home, a) : new CListNodeAnd(this._prev, this); }
73
+ AddEnd(a) { return this._stop ? this.AddPrev(a) : this._End().AddNext(a); }
74
+ AddStart(a) { return this._stop ? this.AddNext(a) : this._First().AddPrev(a); }
75
+ forEach(el) {
76
+ for (let buf = this.First(); buf?.data && !buf.isForbidden();) {
77
+ let t = buf.Next();
78
+ el(buf.data, buf);
79
+ buf = t;
80
+ }
81
+ }
82
+ GetArray() { let a = []; this.forEach(e => a.push(e)); return a; }
83
+ find(el) { let buf = this.First(); for (; buf; buf = buf.Next()) {
84
+ if (el(buf))
85
+ return buf;
86
+ } return undefined; }
87
+ DeleteLink() { this._prev._next = this._next; this._next._prev = this._prev; this._prev = this._next = this; this._stop = true; this._home?.countRef(); CListNodeAnd._valueG2--; this._home = undefined; }
88
+ }
89
+ exports.CListNodeAnd = CListNodeAnd;
@@ -0,0 +1,11 @@
1
+ export type ObjectKeyPath<TObject extends object = object, TValue = unknown> = readonly string[];
2
+ export declare function objectSetValueByPath<TObj extends {
3
+ [key: string]: any;
4
+ }, TVal>(obj: TObj, path: ObjectKeyPath<TObj, TVal>, value: TVal): void;
5
+ export declare function objectGetValueByPath<TObj extends {
6
+ readonly [key: string]: any;
7
+ }, TVal>(object: TObj, path: ObjectKeyPath<TObj, TVal>): TVal;
8
+ export declare function objectDeleteValueByPath<TObj extends {
9
+ readonly [key: string]: any;
10
+ }, TVal>(object: TObj, path: ObjectKeyPath<TObj, TVal>): boolean;
11
+ 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>]>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectSetValueByPath = objectSetValueByPath;
4
+ exports.objectGetValueByPath = objectGetValueByPath;
5
+ exports.objectDeleteValueByPath = objectDeleteValueByPath;
6
+ exports.iterateDeepObjectEntries = iterateDeepObjectEntries;
7
+ function objectSetValueByPath(obj, path, value) {
8
+ if (path.length == 0)
9
+ throw "empty path!";
10
+ let key = path[0];
11
+ if (path.length == 1) {
12
+ obj[key] = value;
13
+ return;
14
+ }
15
+ let val = obj[key];
16
+ if (typeof val != "object")
17
+ throw "value is not an object: " + val;
18
+ return objectSetValueByPath(val, path.slice(1), value);
19
+ }
20
+ function objectGetValueByPath(object, path) {
21
+ if (path.length == 0)
22
+ throw "empty path!";
23
+ let key = path[0];
24
+ if (!(key in object))
25
+ throw "key is not in object: " + key;
26
+ let val = object[key];
27
+ if (path.length == 1)
28
+ return val;
29
+ if (typeof val != "object")
30
+ throw "value is not an object: " + val;
31
+ return objectGetValueByPath(val, path.slice(1));
32
+ }
33
+ function objectDeleteValueByPath(object, path) {
34
+ if (path.length == 0)
35
+ throw "empty path!";
36
+ let key = path[0];
37
+ if (path.length == 1)
38
+ if (!(key in object))
39
+ return false;
40
+ else {
41
+ delete object[key];
42
+ return true;
43
+ }
44
+ let val = object[key];
45
+ if (typeof val != "object")
46
+ throw "value is not an object: " + val;
47
+ return objectDeleteValueByPath(val, path.slice(1));
48
+ }
49
+ function* iterateDeepObjectEntries(obj, filter, currentPath = []) {
50
+ if (obj)
51
+ for (let [key, val] of Object.entries(obj)) {
52
+ let keyPath = currentPath.concat(key);
53
+ if (filter?.(key, val, keyPath) == false)
54
+ continue;
55
+ yield [key, val, keyPath];
56
+ if (typeof (val) == "object")
57
+ yield* iterateDeepObjectEntries(val, filter, keyPath);
58
+ }
59
+ }
@@ -0,0 +1,55 @@
1
+ export type Listener<T extends any[]> = (...r: T) => void;
2
+ type NormalizeTuple<T> = T extends any[] ? T : [T];
3
+ export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), data?: {
4
+ event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void;
5
+ fast?: boolean;
6
+ }): {
7
+ func: Listener<NormalizeTuple<T>>;
8
+ isRun: () => boolean;
9
+ run: () => void;
10
+ close: () => void;
11
+ eventClose: (cb: () => void) => () => void;
12
+ removeEventClose: (cb: () => void) => void;
13
+ addListen: (cb: Listener<NormalizeTuple<T>>, cbClose?: () => void) => () => void;
14
+ removeListen: (cb: Listener<NormalizeTuple<T>> | null) => void;
15
+ count: () => number;
16
+ readonly getAllKeys: Listener<NormalizeTuple<T>>[];
17
+ };
18
+ export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void))): {
19
+ func: Listener<NormalizeTuple<T>>;
20
+ isRun: () => boolean;
21
+ run: () => void;
22
+ close: () => void;
23
+ eventClose: (cb: () => void) => () => void;
24
+ removeEventClose: (cb: () => void) => void;
25
+ addListen: (cb: Listener<NormalizeTuple<T>>, cbClose?: (() => void) | undefined) => () => void;
26
+ removeListen: (cb: Listener<NormalizeTuple<T>> | null) => void;
27
+ count: () => number;
28
+ readonly getAllKeys: Listener<NormalizeTuple<T_1>>[];
29
+ };
30
+ export declare function funcListenCallback<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void)), event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void, fast?: boolean): {
31
+ func: Listener<NormalizeTuple<T>>;
32
+ isRun: () => boolean;
33
+ run: () => void;
34
+ close: () => void;
35
+ eventClose: (cb: () => void) => () => void;
36
+ removeEventClose: (cb: () => void) => void;
37
+ addListen: (cb: Listener<NormalizeTuple<T>>, cbClose?: (() => void) | undefined) => () => void;
38
+ removeListen: (cb: Listener<NormalizeTuple<T>> | null) => void;
39
+ count: () => number;
40
+ readonly getAllKeys: Listener<NormalizeTuple<T_1>>[];
41
+ };
42
+ export declare function UseListen<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, {
43
+ func: Listener<NormalizeTuple<T>>;
44
+ isRun: () => boolean;
45
+ run: () => void;
46
+ close: () => void;
47
+ eventClose: (cb: () => void) => () => void;
48
+ removeEventClose: (cb: () => void) => void;
49
+ addListen: (cb: Listener<NormalizeTuple<T>>, cbClose?: (() => void) | undefined) => () => void;
50
+ removeListen: (cb: Listener<NormalizeTuple<T>> | null) => void;
51
+ count: () => number;
52
+ readonly getAllKeys: Listener<NormalizeTuple<T_1>>[];
53
+ }];
54
+ export declare function isListenCallback(obj: any): obj is ReturnType<typeof funcListenCallbackBase>;
55
+ export {};
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.funcListenCallbackBase = funcListenCallbackBase;
4
+ exports.funcListenCallbackFast = funcListenCallbackFast;
5
+ exports.funcListenCallback = funcListenCallback;
6
+ exports.UseListen = UseListen;
7
+ exports.isListenCallback = isListenCallback;
8
+ function funcListenCallbackBase(b, data) {
9
+ const { fast = true, event } = data ?? {};
10
+ const obj = new Map();
11
+ const evClose = new Map();
12
+ const sinh = new Map();
13
+ let a = (...e) => { obj.forEach(z => z(...e)); };
14
+ let close = null;
15
+ let cached = null;
16
+ const getArr = () => cached ?? (cached = Array.from(obj.values()));
17
+ const rebuild = () => {
18
+ cached = null;
19
+ const size = obj.size;
20
+ if (size === 0) {
21
+ a = null;
22
+ return;
23
+ }
24
+ if (size === 1) {
25
+ a = obj.values().next().value;
26
+ return;
27
+ }
28
+ if (size === 2) {
29
+ const [a0, a1] = getArr();
30
+ a = ((...e) => { a0(...e); a1(...e); });
31
+ return;
32
+ }
33
+ a = ((...e) => {
34
+ const ar = getArr();
35
+ for (let i = 0, len = ar.length; i < len; i++)
36
+ ar[i](...e);
37
+ });
38
+ };
39
+ const func = (...e) => { a?.(...e); };
40
+ const run = () => { close = (b(func) ?? (() => { })); };
41
+ const api = {
42
+ func,
43
+ isRun: () => close !== null,
44
+ run,
45
+ close: () => {
46
+ close?.();
47
+ close = null;
48
+ obj.clear();
49
+ if (fast)
50
+ rebuild();
51
+ sinh.clear();
52
+ evClose.forEach(cb => cb());
53
+ evClose.clear();
54
+ },
55
+ eventClose: (cb) => {
56
+ evClose.set(cb, cb);
57
+ return () => { evClose.delete(cb); };
58
+ },
59
+ removeEventClose: (cb) => {
60
+ const e = sinh.get(cb);
61
+ if (e)
62
+ evClose.delete(e);
63
+ sinh.delete(cb);
64
+ evClose.delete(cb);
65
+ },
66
+ addListen: (cb, cbClose) => {
67
+ obj.set(cb, cb);
68
+ if (cbClose) {
69
+ if (evClose.has(cb)) {
70
+ const r = evClose.get(cb);
71
+ if (r !== cbClose) {
72
+ evClose.delete(r);
73
+ evClose.delete(cb);
74
+ sinh.delete(r);
75
+ }
76
+ }
77
+ evClose.set(cb, cbClose);
78
+ sinh.set(cbClose, cb);
79
+ }
80
+ if (fast)
81
+ rebuild();
82
+ event?.("add", obj.size, api);
83
+ return () => api.removeListen(cb);
84
+ },
85
+ removeListen: (cb) => {
86
+ obj.delete(cb);
87
+ const e = evClose.get(cb);
88
+ if (fast)
89
+ rebuild();
90
+ evClose.delete(cb);
91
+ if (e) {
92
+ evClose.delete(e);
93
+ sinh.delete(e);
94
+ }
95
+ event?.("remove", obj.size, api);
96
+ },
97
+ count: () => obj.size,
98
+ get getAllKeys() { return [...obj.keys()]; }
99
+ };
100
+ return api;
101
+ }
102
+ function funcListenCallbackFast(a) {
103
+ return funcListenCallbackBase(a, { fast: true });
104
+ }
105
+ function funcListenCallback(a, event, fast = true) {
106
+ return funcListenCallbackBase(a, { event, fast });
107
+ }
108
+ function UseListen(data = { fast: true }) {
109
+ let t;
110
+ const a = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...data });
111
+ a.run();
112
+ t = a.func;
113
+ return [t, a];
114
+ }
115
+ function isListenCallback(obj) {
116
+ if (obj == null || typeof obj !== "object")
117
+ return false;
118
+ const obj2 = obj;
119
+ return (typeof obj2.addListen === "function" &&
120
+ typeof obj2.removeListen === "function" &&
121
+ typeof obj2.eventClose === "function" &&
122
+ typeof obj2.func === "function" &&
123
+ typeof obj2.count === "function");
124
+ }
@@ -0,0 +1,41 @@
1
+ export type realSocket2<T extends any> = (data: {
2
+ callback: (data: T) => void;
3
+ [key: string]: any;
4
+ }, ...b: any[]) => (any | (() => any));
5
+ export type getTypeCallback<T extends realSocket2<any>> = T extends realSocket2<infer R> ? R : never;
6
+ type ParametersOther<T extends (forget: any, ...args: any) => any> = T extends (forget: any, ...args: infer P) => any ? P : never;
7
+ type tr22<T> = T extends undefined ? never : T;
8
+ export declare function socketBuffer3<T extends realSocket2<any | any[]>, T2 extends (readonly unknown[]) | undefined, T3 extends {
9
+ [key: string]: unknown;
10
+ }, T4 extends T3 | (() => T3)>(func: T, callbackMain: (data: getTypeCallback<T>, memo: T3 | T4) => T2, memo?: T3 | T4): (a: Omit<Parameters<T>[0], "callback"> & {
11
+ callback: (...data: tr22<T2>) => any;
12
+ }, ...b: ParametersOther<T>) => ReturnType<T>;
13
+ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | any[]>, T2 extends (readonly unknown[]) | undefined, T3 extends {
14
+ [key: string]: unknown;
15
+ }, T4 extends T3 | (() => T3)>({ func, memo, callbackSave, snapshot }: {
16
+ func: () => T;
17
+ callbackSave: (data: getTypeCallback<T>, memo: T3) => T2;
18
+ memo: T4;
19
+ snapshot?: (memo: T4) => T3;
20
+ }): {
21
+ run: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, cbClose?: (() => void) | undefined) => () => void;
22
+ snapshot: () => T3 | undefined;
23
+ memo: T4;
24
+ listenA: {
25
+ func: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>;
26
+ isRun: () => boolean;
27
+ run: () => void;
28
+ close: () => void;
29
+ eventClose: (cb: () => void) => () => void;
30
+ removeEventClose: (cb: () => void) => void;
31
+ addListen: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, cbClose?: (() => void) | undefined) => () => void;
32
+ removeListen: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
33
+ count: () => number;
34
+ readonly getAllKeys: import("./Listen").Listener<T_1 extends any[] ? T_1 : [T_1]>[];
35
+ };
36
+ connect: () => void;
37
+ readonly disconnect: ((a: Omit<Parameters<T>[0], "callback"> & {
38
+ callback: (...data: tr22<T2>) => any;
39
+ }, ...b: ParametersOther<T>) => ReturnType<T>) | null;
40
+ };
41
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.socketBuffer3 = socketBuffer3;
4
+ exports.funcListenCallbackSnapshot = funcListenCallbackSnapshot;
5
+ const Listen_1 = require("./Listen");
6
+ function socketBuffer3(func, callbackMain, memo = {}) {
7
+ return (a, ...b) => func({
8
+ ...a, callback: (v) => {
9
+ const z = callbackMain(v, memo);
10
+ if (z)
11
+ a.callback(...z);
12
+ }
13
+ }, ...b);
14
+ }
15
+ function funcListenCallbackSnapshot({ func, memo = {}, callbackSave, snapshot }) {
16
+ let d = null;
17
+ const [callback, listenA] = (0, Listen_1.UseListen)({
18
+ event: (type, count, api) => {
19
+ if (type == "remove" && count == 0) {
20
+ api.close();
21
+ d?.();
22
+ }
23
+ if (type == "add" && count == 1)
24
+ api.run();
25
+ }
26
+ });
27
+ const connect = () => {
28
+ if (d == null)
29
+ d = socketBuffer3(func(), callbackSave, memo)({ callback });
30
+ };
31
+ const run = (...params) => {
32
+ if (!listenA.isRun()) {
33
+ snapshot?.(memo);
34
+ connect();
35
+ }
36
+ return listenA.addListen(...params);
37
+ };
38
+ return {
39
+ run, snapshot: () => snapshot?.(memo), memo, listenA, connect, get disconnect() {
40
+ return d;
41
+ }
42
+ };
43
+ }