wenay-common2 1.0.45 → 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.
Files changed (95) hide show
  1. package/lib/Common/Color.d.ts +3 -0
  2. package/lib/Common/Color.js +11 -3
  3. package/lib/Common/ObserveAll2/reactive2.d.ts +32 -0
  4. package/lib/Common/ObserveAll2/reactive2.js +249 -0
  5. package/lib/Common/Time.d.ts +8 -0
  6. package/lib/Common/Time.js +41 -14
  7. package/lib/Common/async/PromiseArrayListen.d.ts +3 -3
  8. package/lib/Common/async/PromiseArrayListen.js +10 -14
  9. package/lib/Common/async/createIterableObject.js +2 -2
  10. package/lib/Common/async/waitRun.d.ts +12 -5
  11. package/lib/Common/async/waitRun.js +75 -45
  12. package/lib/Common/core/Decorator.d.ts +3 -1
  13. package/lib/Common/core/Decorator.js +7 -3
  14. package/lib/Common/core/DeepCompareKeys.js +4 -0
  15. package/lib/Common/core/MemoFunc.js +2 -2
  16. package/lib/Common/core/common.d.ts +25 -7
  17. package/lib/Common/core/common.js +118 -38
  18. package/lib/Common/data/ByteStream.d.ts +1 -1
  19. package/lib/Common/data/ByteStream.js +31 -27
  20. package/lib/Common/data/List.d.ts +6 -1
  21. package/lib/Common/data/List.js +28 -6
  22. package/lib/Common/data/ListNodeAnd.js +3 -3
  23. package/lib/Common/data/objectPath.d.ts +4 -0
  24. package/lib/Common/data/objectPath.js +8 -3
  25. package/lib/Common/events/Listen.d.ts +38 -5
  26. package/lib/Common/events/Listen.js +89 -54
  27. package/lib/Common/events/SocketBuffer.d.ts +9 -4
  28. package/lib/Common/events/SocketBuffer.js +1 -0
  29. package/lib/Common/events/SocketServerHook.d.ts +20 -7
  30. package/lib/Common/events/SocketServerHook.js +2 -1
  31. package/lib/Common/events/UseListenTransform.d.ts +8 -3
  32. package/lib/Common/events/event.d.ts +12 -0
  33. package/lib/Common/events/event.js +27 -12
  34. package/lib/Common/events/joinListens.d.ts +2 -0
  35. package/lib/Common/events/joinListens.js +20 -12
  36. package/lib/Common/funcTimeWait.d.ts +28 -2
  37. package/lib/Common/funcTimeWait.js +20 -21
  38. package/lib/Common/id-pool.js +12 -2
  39. package/lib/Common/inputAutoStep.js +2 -2
  40. package/lib/Common/isProxy.d.ts +1 -0
  41. package/lib/Common/isProxy.js +2 -0
  42. package/lib/Common/math/Math.d.ts +1 -0
  43. package/lib/Common/math/Math.js +7 -1
  44. package/lib/Common/math/other.js +2 -1
  45. package/lib/Common/math/scoreLana.js +3 -2
  46. package/lib/Common/node_console.d.ts +2 -0
  47. package/lib/Common/node_console.js +3 -76
  48. package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.d.ts +2 -0
  49. package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.js +63 -30
  50. package/lib/Common/rcp/listen-deep.d.ts +13 -5
  51. package/lib/Common/rcp/listen-deep.js +1 -6
  52. package/lib/Common/rcp/listen-socket.d.ts +21 -3
  53. package/lib/Common/rcp/listen-socket.js +97 -6
  54. package/lib/Common/rcp/oldCommonsServer.d.ts +1 -1
  55. package/lib/Common/rcp/oldCommonsServer.js +15 -1
  56. package/lib/Common/rcp/old/320/241ommonsServerMini.js +1 -0
  57. package/lib/Common/rcp/rpc-caps.d.ts +10 -0
  58. package/lib/Common/rcp/rpc-caps.js +16 -0
  59. package/lib/Common/rcp/rpc-client.d.ts +23 -1
  60. package/lib/Common/rcp/rpc-client.js +306 -25
  61. package/lib/Common/rcp/rpc-clientHub.d.ts +7 -1
  62. package/lib/Common/rcp/rpc-clientHub.js +25 -2
  63. package/lib/Common/rcp/rpc-index.d.ts +3 -0
  64. package/lib/Common/rcp/rpc-index.js +3 -0
  65. package/lib/Common/rcp/rpc-inproc.d.ts +17 -0
  66. package/lib/Common/rcp/rpc-inproc.js +30 -0
  67. package/lib/Common/rcp/rpc-off.d.ts +10 -0
  68. package/lib/Common/rcp/rpc-off.js +22 -0
  69. package/lib/Common/rcp/rpc-protocol.d.ts +6 -0
  70. package/lib/Common/rcp/rpc-protocol.js +4 -2
  71. package/lib/Common/rcp/rpc-server-auto.d.ts +14 -3
  72. package/lib/Common/rcp/rpc-server-auto.js +81 -6
  73. package/lib/Common/rcp/rpc-server.d.ts +17 -2
  74. package/lib/Common/rcp/rpc-server.js +127 -31
  75. package/lib/Common/rcp/rpc-shape.d.ts +17 -0
  76. package/lib/Common/rcp/rpc-shape.js +42 -0
  77. package/lib/Common/rcp/rpc-walk.js +29 -11
  78. package/lib/Common/rcp/test.d.ts +1 -0
  79. package/lib/Common/rcp/test.js +78 -0
  80. package/lib/Exchange/Bars.d.ts +3 -0
  81. package/lib/Exchange/Bars.js +9 -4
  82. package/lib/Exchange/CParams.d.ts +2 -0
  83. package/lib/Exchange/CParams.js +22 -15
  84. package/lib/Exchange/MarketData.d.ts +6 -0
  85. package/lib/Exchange/MarketData.js +5 -1
  86. package/lib/index.d.ts +1 -0
  87. package/lib/index.js +2 -1
  88. package/lib/server/WebHook3.d.ts +1 -0
  89. package/lib/server/WebHook3.js +45 -16
  90. package/lib/server/fsKeyVolume.js +20 -3
  91. package/lib/toError/myThrow.d.ts +20 -1
  92. package/lib/toError/myThrow.js +32 -19
  93. package/package.json +2 -1
  94. package/lib/Common/Error/myThrow.d.ts +0 -5
  95. package/lib/Common/Error/myThrow.js +0 -23
@@ -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: string | Listener<NormalizeTuple<T>> | null) => void;
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: (string | Listener<NormalizeTuple<T>>)[];
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: string | Listener<NormalizeTuple<T>> | null) => void;
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: (string | Listener<NormalizeTuple<T>>)[];
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 evClose = new Map();
11
- const sinh = new Map();
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.clear();
59
- evClose.forEach(cb => cb());
60
- evClose.clear();
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.delete(cb); };
108
+ return () => { evClose?.delete(cb); };
69
109
  },
110
+ onClose: (cb) => api.eventClose(cb),
70
111
  removeEventClose: (cb) => {
71
- const e = sinh.get(cb);
112
+ const e = sinh?.get(cb);
72
113
  if (e)
73
- evClose.delete(e);
74
- sinh.delete(cb);
75
- evClose.delete(cb);
114
+ evClose?.delete(e);
115
+ sinh?.delete(cb);
116
+ evClose?.delete(cb);
76
117
  },
77
118
  addListen: (cb, { cbClose, key } = {}) => {
78
- const k = key ?? cb;
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
- if (evClose.has(k)) {
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 () => api.removeListen(k);
136
+ return () => removeKey(k);
96
137
  },
97
138
  removeListen: (k) => {
98
- obj.delete(k);
99
- const e = evClose.get(k);
100
- if (fast)
101
- rebuild();
102
- evClose.delete(k);
103
- if (e) {
104
- evClose.delete(e);
105
- sinh.delete(e);
106
- }
107
- event?.("remove", obj.size, api);
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
- let referenceKeys = null;
126
- let referenceTypes = null;
127
- function getReferenceData() {
128
- if (!referenceKeys || !referenceTypes) {
129
- const demo = funcListenCallbackBase(() => { });
130
- referenceKeys = Object.keys(demo).sort();
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 objKeys = Object.keys(obj).sort();
142
- const { keys: refKeys, types: refTypes } = getReferenceData();
143
- if (objKeys.length !== refKeys.length)
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
- for (const key of refKeys) {
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"> & {
@@ -19,6 +19,7 @@ function funcListenCallbackSnapshot({ func, memo = {}, callbackSave, snapshot })
19
19
  if (type == "remove" && count == 0) {
20
20
  api.close();
21
21
  d?.();
22
+ d = null;
22
23
  }
23
24
  if (type == "add" && count == 1)
24
25
  api.run();
@@ -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) => 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
  }
@@ -16,24 +16,32 @@ class CObjectEventsArr {
16
16
  }
17
17
  console.error("элемент уже был удален");
18
18
  console.trace();
19
- data.OnDel?.();
20
19
  console.log(this.count());
21
20
  };
22
21
  }
23
22
  AddStart(data) { this.data.unshift(data); this.setup(this.data[0]); }
24
23
  AddEnd(data) { this.setup(this.data[this.data.push(data) - 1]); }
25
24
  Add(data) { this.setup(this.data[this.data.push(data) - 1]); }
26
- OnEvent(data) { [...this.data].forEach((e) => { e.func?.(data); e.func2?.(data); }); }
27
- OnSpecEvent(f) { [...this.data].forEach((e) => { const l = e.func?.(); l && f(l); e.func2?.(); }); }
25
+ add(data, opts = {}) { opts.at == 'start' ? this.AddStart(data) : this.AddEnd(data); }
26
+ OnEvent(data) { [...this.data].forEach((e) => { e.func?.(data); if (e.func2) {
27
+ e.func2(data);
28
+ e.del?.();
29
+ } }); }
30
+ emit(data) { this.OnEvent(data); }
31
+ OnSpecEvent(f) { [...this.data].forEach((e) => { const l = e.func?.(); l && f(l); if (e.func2) {
32
+ e.func2();
33
+ e.del?.();
34
+ } }); }
28
35
  Clean() {
29
36
  const a = [...this.data];
30
- this.data = [];
31
37
  for (let i = a.length - 1; i >= 0; i--) {
32
38
  a[i].del?.();
33
39
  }
34
40
  }
41
+ clear() { this.Clean(); }
35
42
  count() { return this.data.length; }
36
43
  get length() { return this.count(); }
44
+ get size() { return this.count(); }
37
45
  }
38
46
  exports.CObjectEventsArr = CObjectEventsArr;
39
47
  class CObjectEventsList {
@@ -62,16 +70,23 @@ class CObjectEventsList {
62
70
  AddStart(data) { this.setup(this.data.AddStart(data)); }
63
71
  AddEnd(data) { this.setup(this.data.AddEnd(data)); }
64
72
  Add(data) { this.setup(this.data.AddEnd(data)); }
65
- OnEvent(data) { this.data.forEach(e => { e.func?.(data); e.func2?.(data); }); }
66
- OnSpecEvent(f) { this.data.forEach((e) => { const l = e.func?.(); if (l) {
73
+ add(data, opts = {}) { opts.at == 'start' ? this.AddStart(data) : this.AddEnd(data); }
74
+ OnEvent(data) { const a = []; this.data.forEach(e => a.push(e)); a.forEach(e => { e.func?.(data); if (e.func2) {
75
+ e.func2(data);
76
+ e.del?.();
77
+ } }); }
78
+ emit(data) { this.OnEvent(data); }
79
+ OnSpecEvent(f) { const a = []; this.data.forEach(e => a.push(e)); a.forEach((e) => { const l = e.func?.(); if (l) {
67
80
  f(l);
68
- } e.func2?.(); }); }
69
- Clean() { let r = this.data.First(); while (r) {
70
- const buf = r;
71
- r = r?.Next();
72
- buf.DeleteLink();
73
- } }
81
+ } if (e.func2) {
82
+ e.func2();
83
+ e.del?.();
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(); }
74
88
  count() { return this.data.countRef(); }
75
89
  get length() { return this.count(); }
90
+ get size() { return this.count(); }
76
91
  }
77
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,36 +18,44 @@ function joinListens(listens, keyExtractor) {
18
18
  const result = isArray
19
19
  ? keys.map(k => bucket.get(k))
20
20
  : Object.fromEntries(bucket);
21
- bucket.clear();
21
+ buckets.delete(tid);
22
22
  set(result, tid);
23
23
  };
24
+ const unsubs = [];
24
25
  const bindPort = (portId, listener) => {
25
- listener.addListen((...data) => {
26
+ const cb = (...data) => {
26
27
  const tid = getKey(data[0]);
27
28
  if (!buckets.has(tid))
28
29
  buckets.set(tid, new Map());
29
30
  buckets.get(tid).set(portId, data.length <= 1 ? data[0] : data);
30
31
  tryFire(tid);
31
- });
32
+ };
33
+ unsubs.push(listener.addListen(cb));
32
34
  };
33
35
  for (const portId of keys) {
34
36
  bindPort(portId, map[portId]);
35
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
+ }
36
46
  return {
37
47
  listen: out,
38
48
  pending: buckets,
39
49
  clear: (tid) => {
40
50
  tid ? buckets.delete(tid) : buckets.clear();
41
51
  },
42
- destroy: (tid) => {
52
+ destroy: () => {
53
+ for (const u of unsubs)
54
+ u();
55
+ unsubs.length = 0;
56
+ buckets.clear();
43
57
  },
44
- addListen: (listener, key) => {
45
- const portId = isArray ? String(keys.length) : (key ?? String(keys.length));
46
- if (map[portId])
47
- return;
48
- map[portId] = listener;
49
- keys.push(portId);
50
- bindPort(portId, listener);
51
- }
58
+ add,
59
+ addListen: (listener, key) => add(listener, key)
52
60
  };
53
61
  }
@@ -13,7 +13,6 @@ export declare function funcTimeW(): {
13
13
  add(item: tFunc): void;
14
14
  cleanByTime(type: tType, ms?: number): void;
15
15
  weight(type: tType, ms?: number): number;
16
- weightNow(type: tType, ms?: number): number;
17
16
  byWeight(type: tType, weight?: number): number;
18
17
  byWeightTimeNow(type: tType, timeNow?: number, weight?: number): number;
19
18
  };
@@ -25,7 +24,34 @@ export declare const FuncTimeWait: {
25
24
  add(item: tFunc): void;
26
25
  cleanByTime(type: tType, ms?: number): void;
27
26
  weight(type: tType, ms?: number): number;
28
- weightNow(type: tType, ms?: number): number;
27
+ byWeight(type: tType, weight?: number): number;
28
+ byWeightTimeNow(type: tType, timeNow?: number, weight?: number): number;
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;
29
55
  byWeight(type: tType, weight?: number): number;
30
56
  byWeightTimeNow(type: tType, timeNow?: number, weight?: number): number;
31
57
  };