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
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.funcListenCallback = void 0;
|
|
4
|
+
exports.getListenByOn = getListenByOn;
|
|
5
|
+
exports.isListenOn = isListenOn;
|
|
6
|
+
exports.funcListenCore = funcListenCore;
|
|
7
|
+
exports.funcListenCallbackBase = funcListenCallbackBase;
|
|
8
|
+
exports.funcListenCallbackFast = funcListenCallbackFast;
|
|
9
|
+
exports.UseListen = UseListen;
|
|
10
|
+
exports.withStoreListen = withStoreListen;
|
|
11
|
+
exports.funcListenCallbackStore = funcListenCallbackStore;
|
|
12
|
+
exports.UseListenStore = UseListenStore;
|
|
13
|
+
exports.toListen2 = toListen2;
|
|
14
|
+
exports.UseListen2 = UseListen2;
|
|
15
|
+
exports.isListenCallback = isListenCallback;
|
|
16
|
+
const listenByOn = new WeakMap();
|
|
17
|
+
function getListenByOn(fn) { return typeof fn == 'function' ? listenByOn.get(fn) : undefined; }
|
|
18
|
+
function isListenOn(fn) { return typeof fn == 'function' && listenByOn.has(fn); }
|
|
19
|
+
function funcListenCore(options = {}) {
|
|
20
|
+
const { fast = true, onRemove, event } = options;
|
|
21
|
+
const subs = new Map();
|
|
22
|
+
let a = (...e) => { subs.forEach(z => z(...e)); };
|
|
23
|
+
let cached = null;
|
|
24
|
+
const getArr = () => cached ?? (cached = Array.from(subs.values()));
|
|
25
|
+
function rebuild() {
|
|
26
|
+
cached = null;
|
|
27
|
+
const size = subs.size;
|
|
28
|
+
if (size == 0) {
|
|
29
|
+
a = null;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (size == 1) {
|
|
33
|
+
a = subs.values().next().value;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (size == 2) {
|
|
37
|
+
const [a0, a1] = getArr();
|
|
38
|
+
a = ((...e) => { a0(...e); a1(...e); });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
a = ((...e) => {
|
|
42
|
+
const ar = getArr();
|
|
43
|
+
for (let i = 0, len = ar.length; i < len; i++)
|
|
44
|
+
ar[i](...e);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function removeOne(k) {
|
|
48
|
+
if (!subs.has(k))
|
|
49
|
+
return;
|
|
50
|
+
subs.delete(k);
|
|
51
|
+
onRemove?.(k);
|
|
52
|
+
if (fast)
|
|
53
|
+
rebuild();
|
|
54
|
+
event?.('remove', subs.size, api);
|
|
55
|
+
}
|
|
56
|
+
const api = {
|
|
57
|
+
func: ((...e) => { a?.(...e); }),
|
|
58
|
+
has: (k) => subs.has(k),
|
|
59
|
+
on: ((cb, { key } = {}) => {
|
|
60
|
+
const k = key ?? Symbol();
|
|
61
|
+
if (subs.has(k)) {
|
|
62
|
+
subs.delete(k);
|
|
63
|
+
onRemove?.(k);
|
|
64
|
+
}
|
|
65
|
+
subs.set(k, cb);
|
|
66
|
+
if (fast)
|
|
67
|
+
rebuild();
|
|
68
|
+
event?.('add', subs.size, api);
|
|
69
|
+
return function off() { removeOne(k); };
|
|
70
|
+
}),
|
|
71
|
+
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
72
|
+
removeListen: (k) => {
|
|
73
|
+
if (typeof k == 'function') {
|
|
74
|
+
for (const [kk, cb] of [...subs])
|
|
75
|
+
if (cb === k)
|
|
76
|
+
removeOne(kk);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (k != null)
|
|
80
|
+
removeOne(k);
|
|
81
|
+
},
|
|
82
|
+
once: (cb, opts = {}) => {
|
|
83
|
+
let off = () => { };
|
|
84
|
+
off = api.on(((...e) => { off(); cb(...e); }), opts);
|
|
85
|
+
return off;
|
|
86
|
+
},
|
|
87
|
+
close: () => {
|
|
88
|
+
subs.clear();
|
|
89
|
+
if (fast)
|
|
90
|
+
rebuild();
|
|
91
|
+
},
|
|
92
|
+
count: () => subs.size,
|
|
93
|
+
get getAllKeys() { return [...subs.keys()]; },
|
|
94
|
+
};
|
|
95
|
+
listenByOn.set(api.on, api);
|
|
96
|
+
return api;
|
|
97
|
+
}
|
|
98
|
+
function funcListenCallbackBase(b, options = {}) {
|
|
99
|
+
const { fast = true, event, addListenClose } = options;
|
|
100
|
+
let closeHooks = null;
|
|
101
|
+
let close = null;
|
|
102
|
+
let closeUnsubscribe = null;
|
|
103
|
+
function forgetKey(k) {
|
|
104
|
+
closeHooks?.delete(k);
|
|
105
|
+
}
|
|
106
|
+
const core = funcListenCore({
|
|
107
|
+
fast,
|
|
108
|
+
onRemove: forgetKey,
|
|
109
|
+
event: event && function forwardRemove(type, count) {
|
|
110
|
+
if (type == 'remove')
|
|
111
|
+
event(type, count, api);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const api = {
|
|
115
|
+
func: core.func,
|
|
116
|
+
isRun: () => close !== null,
|
|
117
|
+
run: () => {
|
|
118
|
+
close = (b(core.func) ?? (() => { }));
|
|
119
|
+
if (addListenClose && !closeUnsubscribe) {
|
|
120
|
+
closeUnsubscribe = addListenClose.on(function onOwnerClose() { api.close(); });
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
close: () => {
|
|
124
|
+
close?.();
|
|
125
|
+
close = null;
|
|
126
|
+
core.close();
|
|
127
|
+
if (closeHooks) {
|
|
128
|
+
const hooks = closeHooks;
|
|
129
|
+
closeHooks = null;
|
|
130
|
+
hooks.forEach(function fireClose(cb) { cb(); });
|
|
131
|
+
}
|
|
132
|
+
if (closeUnsubscribe) {
|
|
133
|
+
closeUnsubscribe();
|
|
134
|
+
closeUnsubscribe = null;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
eventClose: (cb) => {
|
|
138
|
+
closeHooks = closeHooks ?? new Map();
|
|
139
|
+
closeHooks.set(cb, cb);
|
|
140
|
+
return function offClose() { closeHooks?.delete(cb); };
|
|
141
|
+
},
|
|
142
|
+
onClose: (cb) => api.eventClose(cb),
|
|
143
|
+
removeEventClose: (cb) => { closeHooks?.delete(cb); },
|
|
144
|
+
on: ((cb, { cbClose, key } = {}) => {
|
|
145
|
+
const k = key ?? Symbol();
|
|
146
|
+
const off = core.on(cb, { key: k });
|
|
147
|
+
if (cbClose) {
|
|
148
|
+
closeHooks = closeHooks ?? new Map();
|
|
149
|
+
closeHooks.set(k, cbClose);
|
|
150
|
+
}
|
|
151
|
+
event?.('add', core.count(), api);
|
|
152
|
+
return off;
|
|
153
|
+
}),
|
|
154
|
+
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
155
|
+
removeListen: core.removeListen,
|
|
156
|
+
once: (cb, opts = {}) => {
|
|
157
|
+
let off = () => { };
|
|
158
|
+
off = api.on(((...e) => { off(); cb(...e); }), opts);
|
|
159
|
+
return off;
|
|
160
|
+
},
|
|
161
|
+
count: () => core.count(),
|
|
162
|
+
get getAllKeys() { return core.getAllKeys; },
|
|
163
|
+
};
|
|
164
|
+
listenByOn.set(api.on, api);
|
|
165
|
+
return api;
|
|
166
|
+
}
|
|
167
|
+
function funcListenCallbackFast(a) {
|
|
168
|
+
return funcListenCallbackBase(a, { fast: true });
|
|
169
|
+
}
|
|
170
|
+
exports.funcListenCallback = funcListenCallbackBase;
|
|
171
|
+
function UseListen(data = { fast: true }) {
|
|
172
|
+
let t;
|
|
173
|
+
const a = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...data });
|
|
174
|
+
a.run();
|
|
175
|
+
t = a.func;
|
|
176
|
+
return [t, a];
|
|
177
|
+
}
|
|
178
|
+
function withStoreListen(base, currentProvider) {
|
|
179
|
+
function currentValue(current) {
|
|
180
|
+
if (typeof current == 'function')
|
|
181
|
+
return current();
|
|
182
|
+
return current ? currentProvider() : undefined;
|
|
183
|
+
}
|
|
184
|
+
const api = {
|
|
185
|
+
...base,
|
|
186
|
+
on: ((cb, { cbClose, key, current } = {}) => {
|
|
187
|
+
const off = base.on(cb, { cbClose, key });
|
|
188
|
+
if (current) {
|
|
189
|
+
const m = currentValue(current);
|
|
190
|
+
if (m)
|
|
191
|
+
cb(...m);
|
|
192
|
+
}
|
|
193
|
+
return off;
|
|
194
|
+
}),
|
|
195
|
+
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
196
|
+
once: (cb, opts = {}) => {
|
|
197
|
+
if (opts.current) {
|
|
198
|
+
const m = currentValue(opts.current);
|
|
199
|
+
if (m) {
|
|
200
|
+
cb(...m);
|
|
201
|
+
return () => { };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let off = () => { };
|
|
205
|
+
off = base.on(((...e) => { off(); cb(...e); }), { key: opts.key });
|
|
206
|
+
return off;
|
|
207
|
+
},
|
|
208
|
+
get getAllKeys() { return base.getAllKeys; },
|
|
209
|
+
};
|
|
210
|
+
listenByOn.set(api.on, api);
|
|
211
|
+
return api;
|
|
212
|
+
}
|
|
213
|
+
function funcListenCallbackStore(b, options) {
|
|
214
|
+
const { current, ...listenOptions } = options;
|
|
215
|
+
return withStoreListen(funcListenCallbackBase(b, listenOptions), current);
|
|
216
|
+
}
|
|
217
|
+
function UseListenStore(data) {
|
|
218
|
+
const { current, ...listenOptions } = data;
|
|
219
|
+
let t;
|
|
220
|
+
const base = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...listenOptions });
|
|
221
|
+
const listen = withStoreListen(base, current);
|
|
222
|
+
base.run();
|
|
223
|
+
t = base.func;
|
|
224
|
+
return [t, listen];
|
|
225
|
+
}
|
|
226
|
+
function toListen2(full) {
|
|
227
|
+
return {
|
|
228
|
+
on: (cb, opts) => full.on(cb, opts),
|
|
229
|
+
close: () => full.close(),
|
|
230
|
+
count: () => full.count(),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function UseListen2(data = { fast: true }) {
|
|
234
|
+
const [emit, full] = UseListen(data);
|
|
235
|
+
return [emit, toListen2(full)];
|
|
236
|
+
}
|
|
237
|
+
const LISTEN_CORE = ['func', 'addListen', 'removeListen', 'eventClose', 'removeEventClose'];
|
|
238
|
+
function isListenCallback(obj) {
|
|
239
|
+
if (obj == null || typeof obj != 'object')
|
|
240
|
+
return false;
|
|
241
|
+
const ks = new Set(Object.keys(obj));
|
|
242
|
+
for (const k of LISTEN_CORE)
|
|
243
|
+
if (!ks.has(k))
|
|
244
|
+
return false;
|
|
245
|
+
for (const k of LISTEN_CORE)
|
|
246
|
+
if (typeof obj[k] != 'function')
|
|
247
|
+
return false;
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
@@ -18,26 +18,31 @@ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | a
|
|
|
18
18
|
memo: T4;
|
|
19
19
|
snapshot?: (memo: T4) => T3;
|
|
20
20
|
}): {
|
|
21
|
-
run: (cb: import("./
|
|
22
|
-
cbClose?: (
|
|
23
|
-
key?: string;
|
|
21
|
+
run: (cb: import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]>, opts?: {
|
|
22
|
+
cbClose?: () => void;
|
|
23
|
+
key?: string | symbol;
|
|
24
24
|
} | undefined) => () => void;
|
|
25
25
|
snapshot: () => T3 | undefined;
|
|
26
26
|
memo: T4;
|
|
27
27
|
listenA: {
|
|
28
|
-
func: import("./
|
|
28
|
+
func: import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]>;
|
|
29
29
|
isRun: () => boolean;
|
|
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
|
-
|
|
36
|
-
|
|
35
|
+
on: import("./Listen3").ListenOn<[data: getTypeCallback<T>, memo: T3]>;
|
|
36
|
+
addListen: (cb: import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]>, opts?: {
|
|
37
|
+
cbClose?: () => void;
|
|
38
|
+
key?: string | symbol;
|
|
39
|
+
}) => () => void;
|
|
40
|
+
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
|
|
41
|
+
once: (cb: import("./Listen3").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 |
|
|
45
|
+
readonly getAllKeys: (string | symbol)[];
|
|
41
46
|
};
|
|
42
47
|
connect: () => void;
|
|
43
48
|
readonly disconnect: ((a: Omit<Parameters<T>[0], "callback"> & {
|
|
@@ -5,35 +5,45 @@ export declare function SocketServerHook(opt?: {
|
|
|
5
5
|
}): {
|
|
6
6
|
obj: {
|
|
7
7
|
[k: string]: readonly [(a_0: unknown) => void, {
|
|
8
|
-
func: import("./
|
|
8
|
+
func: import("./Listen3").Listener<[unknown]>;
|
|
9
9
|
isRun: () => boolean;
|
|
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
|
-
|
|
16
|
-
|
|
15
|
+
on: import("./Listen3").ListenOn<[unknown]>;
|
|
16
|
+
addListen: (cb: import("./Listen3").Listener<[unknown]>, opts?: {
|
|
17
|
+
cbClose?: () => void;
|
|
18
|
+
key?: string | symbol;
|
|
19
|
+
}) => () => void;
|
|
20
|
+
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[unknown]> | null) => void;
|
|
21
|
+
once: (cb: import("./Listen3").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 |
|
|
25
|
+
readonly getAllKeys: (string | symbol)[];
|
|
21
26
|
}];
|
|
22
27
|
};
|
|
23
28
|
get(tag: string): readonly [(a_0: unknown) => void, {
|
|
24
|
-
func: import("./
|
|
29
|
+
func: import("./Listen3").Listener<[unknown]>;
|
|
25
30
|
isRun: () => boolean;
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
on: import("./Listen3").ListenOn<[unknown]>;
|
|
37
|
+
addListen: (cb: import("./Listen3").Listener<[unknown]>, opts?: {
|
|
38
|
+
cbClose?: () => void;
|
|
39
|
+
key?: string | symbol;
|
|
40
|
+
}) => () => void;
|
|
41
|
+
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[unknown]> | null) => void;
|
|
42
|
+
once: (cb: import("./Listen3").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 |
|
|
46
|
+
readonly getAllKeys: (string | symbol)[];
|
|
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
|
-
|
|
13
|
-
|
|
12
|
+
on: import("./Listen3").ListenOn<NormalizeTuple<TTarget>>;
|
|
13
|
+
addListen: (cb: Listener<NormalizeTuple<TTarget>>, opts?: {
|
|
14
|
+
cbClose?: () => void;
|
|
15
|
+
key?: string | symbol;
|
|
16
|
+
}) => () => void;
|
|
17
|
+
removeListen: (k: (string | symbol) | Listener<NormalizeTuple<TTarget>> | null) => void;
|
|
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 |
|
|
22
|
+
readonly getAllKeys: (string | symbol)[];
|
|
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
|
}
|
|
@@ -22,23 +22,26 @@ class CObjectEventsArr {
|
|
|
22
22
|
AddStart(data) { this.data.unshift(data); this.setup(this.data[0]); }
|
|
23
23
|
AddEnd(data) { this.setup(this.data[this.data.push(data) - 1]); }
|
|
24
24
|
Add(data) { this.setup(this.data[this.data.push(data) - 1]); }
|
|
25
|
+
add(data, opts = {}) { opts.at == 'start' ? this.AddStart(data) : this.AddEnd(data); }
|
|
25
26
|
OnEvent(data) { [...this.data].forEach((e) => { e.func?.(data); if (e.func2) {
|
|
26
27
|
e.func2(data);
|
|
27
28
|
e.del?.();
|
|
28
29
|
} }); }
|
|
30
|
+
emit(data) { this.OnEvent(data); }
|
|
29
31
|
OnSpecEvent(f) { [...this.data].forEach((e) => { const l = e.func?.(); l && f(l); if (e.func2) {
|
|
30
32
|
e.func2();
|
|
31
33
|
e.del?.();
|
|
32
34
|
} }); }
|
|
33
35
|
Clean() {
|
|
34
36
|
const a = [...this.data];
|
|
35
|
-
this.data = [];
|
|
36
37
|
for (let i = a.length - 1; i >= 0; i--) {
|
|
37
38
|
a[i].del?.();
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
clear() { this.Clean(); }
|
|
40
42
|
count() { return this.data.length; }
|
|
41
43
|
get length() { return this.count(); }
|
|
44
|
+
get size() { return this.count(); }
|
|
42
45
|
}
|
|
43
46
|
exports.CObjectEventsArr = CObjectEventsArr;
|
|
44
47
|
class CObjectEventsList {
|
|
@@ -67,22 +70,23 @@ class CObjectEventsList {
|
|
|
67
70
|
AddStart(data) { this.setup(this.data.AddStart(data)); }
|
|
68
71
|
AddEnd(data) { this.setup(this.data.AddEnd(data)); }
|
|
69
72
|
Add(data) { this.setup(this.data.AddEnd(data)); }
|
|
73
|
+
add(data, opts = {}) { opts.at == 'start' ? this.AddStart(data) : this.AddEnd(data); }
|
|
70
74
|
OnEvent(data) { const a = []; this.data.forEach(e => a.push(e)); a.forEach(e => { e.func?.(data); if (e.func2) {
|
|
71
75
|
e.func2(data);
|
|
72
76
|
e.del?.();
|
|
73
77
|
} }); }
|
|
78
|
+
emit(data) { this.OnEvent(data); }
|
|
74
79
|
OnSpecEvent(f) { const a = []; this.data.forEach(e => a.push(e)); a.forEach((e) => { const l = e.func?.(); if (l) {
|
|
75
80
|
f(l);
|
|
76
81
|
} if (e.func2) {
|
|
77
82
|
e.func2();
|
|
78
83
|
e.del?.();
|
|
79
84
|
} }); }
|
|
80
|
-
Clean() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
buf.DeleteLink();
|
|
84
|
-
} }
|
|
85
|
+
Clean() { const a = []; this.data.forEach(e => a.push(e)); for (let i = a.length - 1; i >= 0; i--)
|
|
86
|
+
a[i].del?.(); }
|
|
87
|
+
clear() { this.Clean(); }
|
|
85
88
|
count() { return this.data.countRef(); }
|
|
86
89
|
get length() { return this.count(); }
|
|
90
|
+
get size() { return this.count(); }
|
|
87
91
|
}
|
|
88
92
|
exports.CObjectEventsList = CObjectEventsList;
|
|
@@ -11,6 +11,8 @@ type JoinResult<R> = {
|
|
|
11
11
|
listen: listen<[R, string]>[1];
|
|
12
12
|
pending: Map<string, Map<string, any>>;
|
|
13
13
|
clear: (tid?: string) => void;
|
|
14
|
+
destroy: () => void;
|
|
15
|
+
add: (port: listen<any>[1], key?: string) => void;
|
|
14
16
|
addListen: (listener: listen<any>[1], key?: string) => void;
|
|
15
17
|
};
|
|
16
18
|
export declare function joinListens<T extends Record<string, any[]>>(listens: ListenMap<T>, keyExtractor?: KeyExtractor<any>): JoinResult<CollectedResult<T>>;
|
|
@@ -18,7 +18,7 @@ function joinListens(listens, keyExtractor) {
|
|
|
18
18
|
const result = isArray
|
|
19
19
|
? keys.map(k => bucket.get(k))
|
|
20
20
|
: Object.fromEntries(bucket);
|
|
21
|
-
|
|
21
|
+
buckets.delete(tid);
|
|
22
22
|
set(result, tid);
|
|
23
23
|
};
|
|
24
24
|
const unsubs = [];
|
|
@@ -30,31 +30,32 @@ function joinListens(listens, keyExtractor) {
|
|
|
30
30
|
buckets.get(tid).set(portId, data.length <= 1 ? data[0] : data);
|
|
31
31
|
tryFire(tid);
|
|
32
32
|
};
|
|
33
|
-
listener.addListen(cb);
|
|
34
|
-
unsubs.push(() => listener.removeListen(cb));
|
|
33
|
+
unsubs.push(listener.addListen(cb));
|
|
35
34
|
};
|
|
36
35
|
for (const portId of keys) {
|
|
37
36
|
bindPort(portId, map[portId]);
|
|
38
37
|
}
|
|
38
|
+
function add(listener, key) {
|
|
39
|
+
const portId = isArray ? String(keys.length) : (key ?? String(keys.length));
|
|
40
|
+
if (map[portId])
|
|
41
|
+
return;
|
|
42
|
+
map[portId] = listener;
|
|
43
|
+
keys.push(portId);
|
|
44
|
+
bindPort(portId, listener);
|
|
45
|
+
}
|
|
39
46
|
return {
|
|
40
47
|
listen: out,
|
|
41
48
|
pending: buckets,
|
|
42
49
|
clear: (tid) => {
|
|
43
50
|
tid ? buckets.delete(tid) : buckets.clear();
|
|
44
51
|
},
|
|
45
|
-
destroy: (
|
|
52
|
+
destroy: () => {
|
|
46
53
|
for (const u of unsubs)
|
|
47
54
|
u();
|
|
48
55
|
unsubs.length = 0;
|
|
49
56
|
buckets.clear();
|
|
50
57
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (map[portId])
|
|
54
|
-
return;
|
|
55
|
-
map[portId] = listener;
|
|
56
|
-
keys.push(portId);
|
|
57
|
-
bindPort(portId, listener);
|
|
58
|
-
}
|
|
58
|
+
add,
|
|
59
|
+
addListen: (listener, key) => add(listener, key)
|
|
59
60
|
};
|
|
60
61
|
}
|
|
@@ -27,4 +27,32 @@ export declare const FuncTimeWait: {
|
|
|
27
27
|
byWeight(type: tType, weight?: number): number;
|
|
28
28
|
byWeightTimeNow(type: tType, timeNow?: number, weight?: number): number;
|
|
29
29
|
};
|
|
30
|
+
export declare function createRateWindow(): {
|
|
31
|
+
prune: (type: tType, ms?: number) => void;
|
|
32
|
+
sumWeight: (type: tType, ms?: number) => number;
|
|
33
|
+
readyAt: (type: tType, weight?: number) => number;
|
|
34
|
+
dStatic: {
|
|
35
|
+
[key: string]: [number, number][];
|
|
36
|
+
};
|
|
37
|
+
data: any[];
|
|
38
|
+
add(item: tFunc): void;
|
|
39
|
+
cleanByTime(type: tType, ms?: number): void;
|
|
40
|
+
weight(type: tType, ms?: number): number;
|
|
41
|
+
byWeight(type: tType, weight?: number): number;
|
|
42
|
+
byWeightTimeNow(type: tType, timeNow?: number, weight?: number): number;
|
|
43
|
+
};
|
|
44
|
+
export declare const rateWindow: {
|
|
45
|
+
prune: (type: tType, ms?: number) => void;
|
|
46
|
+
sumWeight: (type: tType, ms?: number) => number;
|
|
47
|
+
readyAt: (type: tType, weight?: number) => number;
|
|
48
|
+
dStatic: {
|
|
49
|
+
[key: string]: [number, number][];
|
|
50
|
+
};
|
|
51
|
+
data: any[];
|
|
52
|
+
add(item: tFunc): void;
|
|
53
|
+
cleanByTime(type: tType, ms?: number): void;
|
|
54
|
+
weight(type: tType, ms?: number): number;
|
|
55
|
+
byWeight(type: tType, weight?: number): number;
|
|
56
|
+
byWeightTimeNow(type: tType, timeNow?: number, weight?: number): number;
|
|
57
|
+
};
|
|
30
58
|
export {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FuncTimeWait = void 0;
|
|
3
|
+
exports.rateWindow = exports.FuncTimeWait = void 0;
|
|
4
4
|
exports.funcTimeW = funcTimeW;
|
|
5
|
+
exports.createRateWindow = createRateWindow;
|
|
5
6
|
function funcTimeW() {
|
|
6
7
|
const dStatic = {};
|
|
7
8
|
const data = [];
|
|
9
|
+
const sortByTime = (arr) => arr.sort((a, b) => a[0] - b[0]);
|
|
8
10
|
return {
|
|
9
11
|
dStatic,
|
|
10
12
|
data,
|
|
@@ -13,11 +15,13 @@ function funcTimeW() {
|
|
|
13
15
|
dStatic[item.type] = [];
|
|
14
16
|
}
|
|
15
17
|
dStatic[item.type].push([item.timeStamp ?? Date.now(), item.weight]);
|
|
18
|
+
sortByTime(dStatic[item.type]);
|
|
16
19
|
},
|
|
17
20
|
cleanByTime(type, ms = 60 * 1000) {
|
|
18
21
|
const arr = dStatic[type];
|
|
19
22
|
if (!arr || arr.length === 0)
|
|
20
23
|
return;
|
|
24
|
+
sortByTime(arr);
|
|
21
25
|
const timeStamp = Date.now();
|
|
22
26
|
if (arr[0][0] > timeStamp - ms)
|
|
23
27
|
return;
|
|
@@ -33,6 +37,7 @@ function funcTimeW() {
|
|
|
33
37
|
const arr = dStatic[type];
|
|
34
38
|
if (!arr || arr.length === 0)
|
|
35
39
|
return 0;
|
|
40
|
+
sortByTime(arr);
|
|
36
41
|
const timeStamp = Date.now();
|
|
37
42
|
let sum = 0;
|
|
38
43
|
let i = arr.length - 1;
|
|
@@ -51,6 +56,7 @@ function funcTimeW() {
|
|
|
51
56
|
const arr = dStatic[type];
|
|
52
57
|
if (!arr || arr.length === 0)
|
|
53
58
|
return 0;
|
|
59
|
+
sortByTime(arr);
|
|
54
60
|
let sum = 0;
|
|
55
61
|
let i = arr.length - 1;
|
|
56
62
|
let result = 0;
|
|
@@ -70,6 +76,7 @@ function funcTimeW() {
|
|
|
70
76
|
const arr = dStatic[type];
|
|
71
77
|
if (!arr || arr.length === 0)
|
|
72
78
|
return 0;
|
|
79
|
+
sortByTime(arr);
|
|
73
80
|
let sum = 0;
|
|
74
81
|
let i = arr.length - 1;
|
|
75
82
|
for (; i >= 0; i--) {
|
|
@@ -94,3 +101,13 @@ function funcTimeW() {
|
|
|
94
101
|
};
|
|
95
102
|
}
|
|
96
103
|
exports.FuncTimeWait = funcTimeW();
|
|
104
|
+
function createRateWindow() {
|
|
105
|
+
const w = funcTimeW();
|
|
106
|
+
return {
|
|
107
|
+
...w,
|
|
108
|
+
prune: w.cleanByTime,
|
|
109
|
+
sumWeight: w.weight,
|
|
110
|
+
readyAt: w.byWeight,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.rateWindow = createRateWindow();
|
package/lib/Common/isProxy.d.ts
CHANGED
package/lib/Common/isProxy.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installProxyTracking = void 0;
|
|
3
4
|
exports.isProxyInit = isProxyInit;
|
|
4
5
|
exports.isProxy = isProxy;
|
|
5
6
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -31,6 +32,7 @@ function isProxyInit() {
|
|
|
31
32
|
init = true;
|
|
32
33
|
set();
|
|
33
34
|
}
|
|
35
|
+
exports.installProxyTracking = isProxyInit;
|
|
34
36
|
function isProxy(a) {
|
|
35
37
|
if (nodeIsProxy)
|
|
36
38
|
return nodeIsProxy(a);
|
|
@@ -4,3 +4,5 @@ export declare function disable(): void;
|
|
|
4
4
|
export declare function __LineFile(lvl?: number): string;
|
|
5
5
|
export declare function __LineFile2(lvl?: number): string;
|
|
6
6
|
export declare function __LineFiles(lvlStart?: number, lvlEnd?: number | undefined): string[];
|
|
7
|
+
export declare const callerLine: typeof __LineFile2;
|
|
8
|
+
export declare const callerLines: typeof __LineFiles;
|