wenay-common2 1.0.52 → 1.0.55

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 (34) hide show
  1. package/lib/Common/ObserveAll2/index.d.ts +1 -0
  2. package/lib/Common/ObserveAll2/index.js +1 -0
  3. package/lib/Common/ObserveAll2/reactive2.d.ts +28 -0
  4. package/lib/Common/ObserveAll2/reactive2.js +108 -18
  5. package/lib/Common/ObserveAll2/store-replay.d.ts +102 -0
  6. package/lib/Common/ObserveAll2/store-replay.js +53 -0
  7. package/lib/Common/ObserveAll2/store.d.ts +39 -27
  8. package/lib/Common/ObserveAll2/store.js +301 -25
  9. package/lib/Common/events/Listen3.d.ts +17 -4
  10. package/lib/Common/events/Listen3.js +9 -3
  11. package/lib/Common/events/SocketBuffer.d.ts +1 -0
  12. package/lib/Common/events/SocketServerHook.d.ts +3 -0
  13. package/lib/Common/events/UseListenTransform.d.ts +1 -0
  14. package/lib/Common/events/replay-conflate.d.ts +45 -0
  15. package/lib/Common/events/replay-conflate.js +99 -0
  16. package/lib/Common/events/replay-history.d.ts +55 -0
  17. package/lib/Common/events/replay-history.js +123 -0
  18. package/lib/Common/events/replay-index.d.ts +4 -0
  19. package/lib/Common/events/replay-index.js +20 -0
  20. package/lib/Common/events/replay-listen.d.ts +114 -0
  21. package/lib/Common/events/replay-listen.js +134 -0
  22. package/lib/Common/events/replay-wire.d.ts +43 -0
  23. package/lib/Common/events/replay-wire.js +84 -0
  24. package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.js +6 -6
  25. package/lib/Common/rcp/listen-socket.d.ts +6 -1
  26. package/lib/Common/rcp/listen-socket.js +23 -14
  27. package/lib/Common/rcp/rpc-client.js +1 -1
  28. package/lib/Common/rcp/rpc-limits.d.ts +1 -0
  29. package/lib/Common/rcp/rpc-limits.js +1 -0
  30. package/lib/Common/rcp/rpc-server-auto.js +8 -8
  31. package/lib/Common/rcp/rpc-walk.js +13 -0
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +2 -1
  34. package/package.json +2 -1
@@ -13,7 +13,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
13
13
  const listenSockets = new Set();
14
14
  function unsubscribeAllActive() {
15
15
  for (const w of [...listenSockets])
16
- w.removeCallback();
16
+ w.off();
17
17
  }
18
18
  function getListenSocket(parent) {
19
19
  let result = cache.get(parent);
@@ -24,10 +24,10 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
24
24
  function subscribe(z) {
25
25
  if (typeof z !== "function")
26
26
  return Promise.reject(new TypeError("Listen callback expects a function"));
27
- subs.get(z)?.removeCallback();
27
+ subs.get(z)?.off();
28
28
  const w = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen });
29
29
  subs.set(z, w);
30
- const done = w.callback(z);
30
+ const done = w.on(z);
31
31
  done.then(() => { if (subs.get(z) == w)
32
32
  subs.delete(z); });
33
33
  return done;
@@ -35,7 +35,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
35
35
  function subscribeOnce(z) {
36
36
  if (typeof z !== "function")
37
37
  return Promise.reject(new TypeError("Listen once expects a function"));
38
- subs.get(z)?.removeCallback();
38
+ subs.get(z)?.off();
39
39
  const w = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen });
40
40
  subs.set(z, w);
41
41
  const done = w.once(z);
@@ -44,11 +44,11 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
44
44
  return done;
45
45
  }
46
46
  function unsubscribeAll() {
47
- subs.forEach(w => w.removeCallback());
47
+ subs.forEach(w => w.off());
48
48
  subs.clear();
49
49
  return true;
50
50
  }
51
- result = { callback: subscribe, removeCallback: unsubscribeAll, on: subscribe, once: subscribeOnce, close: () => parent.close?.() };
51
+ result = { on: subscribe, off: unsubscribeAll, callback: subscribe, removeCallback: unsubscribeAll, once: subscribeOnce, close: () => parent.close?.() };
52
52
  listenSockets.add(result);
53
53
  cache.set(parent, result);
54
54
  }
@@ -2,6 +2,7 @@ import { funcListenCallbackBase, type Listener } from "../events/Listen";
2
2
  import { type Off } from "./rpc-off";
3
3
  type ListenCallbackResult<T extends any[] = any[]> = ReturnType<typeof funcListenCallbackBase<T>>;
4
4
  export type tSubHandle = Off<void, {
5
+ off: () => void;
5
6
  unsubscribe: () => void;
6
7
  removeCallback: () => void;
7
8
  }>;
@@ -12,9 +13,10 @@ export declare function listenSocket<Z extends any[] = any[]>(e: ListenCallbackR
12
13
  readonly paramsModify?: (...e: Z) => any[];
13
14
  readonly throttle?: number;
14
15
  }): {
16
+ on: (z: Listener<Z>) => Promise<void>;
17
+ off: () => boolean;
15
18
  callback: (z: Listener<Z>) => Promise<void>;
16
19
  removeCallback: () => boolean;
17
- on: (z: Listener<Z>) => Promise<void>;
18
20
  once: (z: Listener<Z>) => Promise<void>;
19
21
  close: () => void;
20
22
  };
@@ -23,6 +25,7 @@ export declare function listenSocketFirst<Z extends any[] = any[]>(e: ListenCall
23
25
  on: (z: (a: Z[0]) => void) => tSubHandle;
24
26
  once: (z: (a: Z[0]) => void) => tSubHandle;
25
27
  close: () => void;
28
+ off: () => boolean;
26
29
  removeCallback: () => boolean;
27
30
  };
28
31
  export declare function listenSocketAll<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
@@ -30,6 +33,7 @@ export declare function listenSocketAll<Z extends any[] = any[]>(e: ListenCallba
30
33
  on: (z: (...args: Z) => void) => tSubHandle;
31
34
  once: (z: (...args: Z) => void) => tSubHandle;
32
35
  close: () => void;
36
+ off: () => boolean;
33
37
  removeCallback: () => boolean;
34
38
  };
35
39
  type SmartCallback<Z extends any[]> = Z extends [infer Single] ? (a: Single) => void : (...args: Z) => void;
@@ -38,6 +42,7 @@ export declare function listenSocketSmart<Z extends any[] = any[]>(e: ListenCall
38
42
  on: (z: SmartCallback<Z>) => tSubHandle;
39
43
  once: (z: SmartCallback<Z>) => tSubHandle;
40
44
  close: () => void;
45
+ off: () => boolean;
41
46
  removeCallback: () => boolean;
42
47
  };
43
48
  export {};
@@ -58,7 +58,7 @@ function listenSocket(e, d) {
58
58
  resolveWait = null;
59
59
  }
60
60
  }
61
- function removeCallback() {
61
+ function off() {
62
62
  if (throttleCh) {
63
63
  throttleCh.cancel();
64
64
  throttleCh = null;
@@ -79,9 +79,10 @@ function listenSocket(e, d) {
79
79
  finish();
80
80
  return true;
81
81
  }
82
- function callback(z) {
82
+ const removeCallback = off;
83
+ function on(z) {
83
84
  if (typeof z !== "function") {
84
- throw new TypeError("listenSocket.callback expects a function");
85
+ throw new TypeError("listenSocket.on expects a function");
85
86
  }
86
87
  if (last)
87
88
  stop?.(last);
@@ -110,7 +111,7 @@ function listenSocket(e, d) {
110
111
  if (status())
111
112
  wrapped(...a);
112
113
  else
113
- removeCallback();
114
+ off();
114
115
  };
115
116
  }
116
117
  let inner = handler;
@@ -146,12 +147,12 @@ function listenSocket(e, d) {
146
147
  }
147
148
  inner(...a);
148
149
  };
149
- activeOff = subscribe(active, { cbClose: removeCallback });
150
- closeSignalOff = subscribeClose?.(removeCallback) ?? null;
150
+ activeOff = subscribe(active, { cbClose: off });
151
+ closeSignalOff = subscribeClose?.(off) ?? null;
151
152
  const wait = new Promise((resolve) => {
152
153
  resolveWait = () => { resolve(); };
153
154
  });
154
- return (0, rpc_off_1.makeOff)(wait, removeCallback, { unsubscribe: removeCallback, removeCallback });
155
+ return (0, rpc_off_1.makeOff)(wait, off, { off, unsubscribe: off, removeCallback });
155
156
  }
156
157
  function once(z) {
157
158
  if (typeof z !== "function") {
@@ -160,7 +161,7 @@ function listenSocket(e, d) {
160
161
  let fired = false;
161
162
  const oneShot = ((...a) => {
162
163
  if (a[0] === rpc_protocol_1.RPC_STOP) {
163
- removeCallback();
164
+ off();
164
165
  return;
165
166
  }
166
167
  if (fired)
@@ -171,13 +172,18 @@ function listenSocket(e, d) {
171
172
  }
172
173
  finally {
173
174
  (0, rpc_off_1.endCallback)(z);
174
- removeCallback();
175
+ off();
175
176
  }
176
177
  });
177
- return callback(oneShot);
178
+ return on(oneShot);
178
179
  }
179
180
  function closeStream() { e.close?.(); }
180
- return { callback, removeCallback, on: callback, once, close: closeStream };
181
+ function callback(z) {
182
+ if (typeof z !== "function")
183
+ throw new TypeError("listenSocket.callback expects a function");
184
+ return on(z);
185
+ }
186
+ return { on, off, callback, removeCallback, once, close: closeStream };
181
187
  }
182
188
  function listenSocketFirst(e, options) {
183
189
  const r = listenSocket(e, {
@@ -186,9 +192,10 @@ function listenSocketFirst(e, options) {
186
192
  });
187
193
  return {
188
194
  callback: r.callback,
189
- on: r.callback,
195
+ on: r.on,
190
196
  once: r.once,
191
197
  close: r.close,
198
+ off: r.off,
192
199
  removeCallback: r.removeCallback,
193
200
  };
194
201
  }
@@ -196,9 +203,10 @@ function listenSocketAll(e, options) {
196
203
  const r = listenSocket(e, { ...options });
197
204
  return {
198
205
  callback: r.callback,
199
- on: r.callback,
206
+ on: r.on,
200
207
  once: r.once,
201
208
  close: r.close,
209
+ off: r.off,
202
210
  removeCallback: r.removeCallback,
203
211
  };
204
212
  }
@@ -206,9 +214,10 @@ function listenSocketSmart(e, options) {
206
214
  const r = listenSocket(e, { ...options });
207
215
  return {
208
216
  callback: r.callback,
209
- on: r.callback,
217
+ on: r.on,
210
218
  once: r.once,
211
219
  close: r.close,
220
+ off: r.off,
212
221
  removeCallback: r.removeCallback,
213
222
  };
214
223
  }
@@ -348,7 +348,7 @@ function createClient(socket, key, opts) {
348
348
  if (sub.consumers.size == 0)
349
349
  sub.stop();
350
350
  };
351
- return (0, rpc_off_1.makeOff)(p, unsub, { unsubscribe: unsub, removeCallback: unsub });
351
+ return (0, rpc_off_1.makeOff)(p, unsub, { off: unsub, unsubscribe: unsub, removeCallback: unsub });
352
352
  }
353
353
  const sendCall = (path, args, wait) => {
354
354
  const last = path[path.length - 1];
@@ -7,6 +7,7 @@ export type RpcLimits = {
7
7
  maxStringLen?: number;
8
8
  maxCallbacks?: number;
9
9
  maxPathLen?: number;
10
+ maxBinaryLen?: number;
10
11
  };
11
12
  export declare const resolveLimits: (opts?: RpcLimits) => Required<RpcLimits>;
12
13
  export declare class PayloadLimitError extends Error {
@@ -12,6 +12,7 @@ const DEFAULT_LIMITS = {
12
12
  maxStringLen: 1_000_000,
13
13
  maxCallbacks: 100,
14
14
  maxPathLen: 16,
15
+ maxBinaryLen: 8_000_000,
15
16
  };
16
17
  const resolveLimits = (opts) => opts ? { ...DEFAULT_LIMITS, ...opts } : DEFAULT_LIMITS;
17
18
  exports.resolveLimits = resolveLimits;
@@ -10,7 +10,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
10
10
  const registry = new Map();
11
11
  function unsubscribeAllActive() {
12
12
  for (const { subs } of registry.values()) {
13
- subs.forEach(w => w.removeCallback());
13
+ subs.forEach(w => w.off());
14
14
  subs.clear();
15
15
  }
16
16
  registry.clear();
@@ -26,10 +26,10 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
26
26
  return Promise.resolve();
27
27
  if (!registry.has(parent))
28
28
  registry.set(parent, { subs });
29
- subs.get(z)?.removeCallback();
29
+ subs.get(z)?.off();
30
30
  const w = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen, throttle });
31
31
  subs.set(z, w);
32
- const done = w.callback(z);
32
+ const done = w.on(z);
33
33
  done.then(() => {
34
34
  if (subs.get(z) == w)
35
35
  subs.delete(z);
@@ -45,7 +45,7 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
45
45
  return Promise.resolve();
46
46
  if (!registry.has(parent))
47
47
  registry.set(parent, { subs });
48
- subs.get(z)?.removeCallback();
48
+ subs.get(z)?.off();
49
49
  const w = (0, listen_socket_1.listenSocket)(parent, { addListenClose: disconnectListen, throttle });
50
50
  let fired = false;
51
51
  const oneShot = (...a) => {
@@ -57,23 +57,23 @@ function createRpcServerAuto({ socket, object: target, socketKey: key, debug, ho
57
57
  z(rpc_protocol_1.RPC_STOP);
58
58
  }
59
59
  finally {
60
- w.removeCallback();
60
+ w.off();
61
61
  }
62
62
  };
63
63
  subs.set(z, w);
64
- const done = w.callback(oneShot);
64
+ const done = w.on(oneShot);
65
65
  done.then(() => { if (subs.get(z) == w)
66
66
  subs.delete(z); if (subs.size == 0)
67
67
  registry.delete(parent); });
68
68
  return done;
69
69
  }
70
70
  function unsubscribeAll() {
71
- subs.forEach(w => w.removeCallback());
71
+ subs.forEach(w => w.off());
72
72
  subs.clear();
73
73
  registry.delete(parent);
74
74
  return true;
75
75
  }
76
- result = { callback: subscribe, removeCallback: unsubscribeAll, on: subscribe, once: subscribeOnce, close: () => parent.close?.() };
76
+ result = { on: subscribe, off: unsubscribeAll, callback: subscribe, removeCallback: unsubscribeAll, once: subscribeOnce, close: () => parent.close?.() };
77
77
  result[rpc_protocol_1.IS_RPC_LISTEN] = true;
78
78
  cache.set(parent, result);
79
79
  }
@@ -32,6 +32,13 @@ const SERIALIZERS = [
32
32
  (v) => v instanceof RegExp ? [REGEXP_MARKER, { source: v.source, flags: v.flags }] : null,
33
33
  (v) => typeof v === "bigint" ? [BIGINT_MARKER, v.toString()] : null,
34
34
  ];
35
+ function binaryByteLength(v) {
36
+ if (ArrayBuffer.isView(v))
37
+ return v.byteLength;
38
+ if (v instanceof ArrayBuffer)
39
+ return v.byteLength;
40
+ return null;
41
+ }
35
42
  function walk(val, onLeaf, lim, depth = 0) {
36
43
  if (lim) {
37
44
  if (depth > lim.maxDepth)
@@ -41,6 +48,12 @@ function walk(val, onLeaf, lim, depth = 0) {
41
48
  }
42
49
  if (val == null || typeof val !== "object")
43
50
  return onLeaf(val);
51
+ const bin = binaryByteLength(val);
52
+ if (bin != null) {
53
+ if (lim && bin > lim.maxBinaryLen)
54
+ throw new rpc_limits_1.PayloadLimitError("binary too long");
55
+ return val;
56
+ }
44
57
  if (val instanceof Date || val instanceof Map || val instanceof Set || val instanceof RegExp)
45
58
  return onLeaf(val);
46
59
  const ks0 = Object.keys(val);
package/lib/index.d.ts CHANGED
@@ -33,3 +33,4 @@ export * as Params from "./Exchange/CParams";
33
33
  export * as Time from "./Common/Time";
34
34
  export * as Color from "./Common/Color";
35
35
  export * as ObserveAll2 from "./Common/ObserveAll2";
36
+ export * as Replay from "./Common/events/replay-index";
package/lib/index.js CHANGED
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ObserveAll2 = exports.Color = exports.Time = exports.Params = exports.Bars = exports.Math = exports.ListenNext = void 0;
39
+ exports.Replay = exports.ObserveAll2 = exports.Color = exports.Time = exports.Params = exports.Bars = exports.Math = exports.ListenNext = void 0;
40
40
  __exportStar(require("./Common/node_console"), exports);
41
41
  __exportStar(require("./Common/core/Decorator"), exports);
42
42
  __exportStar(require("./Common/core/BaseTypes"), exports);
@@ -72,3 +72,4 @@ exports.Params = __importStar(require("./Exchange/CParams"));
72
72
  exports.Time = __importStar(require("./Common/Time"));
73
73
  exports.Color = __importStar(require("./Common/Color"));
74
74
  exports.ObserveAll2 = __importStar(require("./Common/ObserveAll2"));
75
+ exports.Replay = __importStar(require("./Common/events/replay-index"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wenay-common2",
3
- "version": "1.0.52",
3
+ "version": "1.0.55",
4
4
  "description": "Common library",
5
5
  "strict": true,
6
6
  "main": "lib/index.js",
@@ -25,6 +25,7 @@
25
25
  ".": "./lib/index.js",
26
26
  "./observe-all2": "./lib/Common/ObserveAll2/index.js",
27
27
  "./listen2": "./lib/Common/events/Listen2.js",
28
+ "./replay": "./lib/Common/events/replay-index.js",
28
29
  "./lib/client": "./lib/client.js",
29
30
  "./lib/server": "./lib/server.js",
30
31
  "./client": "./lib/client.js",