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
@@ -4,12 +4,51 @@ exports.listenSocket = listenSocket;
4
4
  exports.listenSocketFirst = listenSocketFirst;
5
5
  exports.listenSocketAll = listenSocketAll;
6
6
  exports.listenSocketSmart = listenSocketSmart;
7
+ const rpc_protocol_1 = require("./rpc-protocol");
8
+ const rpc_off_1 = require("./rpc-off");
9
+ function createThrottleLatest(ms, sink) {
10
+ let timer = null;
11
+ let pending = null;
12
+ let killed = false;
13
+ function flush() {
14
+ timer = null;
15
+ if (pending) {
16
+ const a = pending;
17
+ pending = null;
18
+ emit(...a);
19
+ }
20
+ }
21
+ function emit(...a) {
22
+ sink(...a);
23
+ if (!killed)
24
+ timer = setTimeout(flush, ms);
25
+ }
26
+ function push(...a) {
27
+ if (killed)
28
+ return;
29
+ if (timer) {
30
+ pending = a;
31
+ return;
32
+ }
33
+ emit(...a);
34
+ }
35
+ function cancel() {
36
+ killed = true;
37
+ if (timer) {
38
+ clearTimeout(timer);
39
+ timer = null;
40
+ }
41
+ pending = null;
42
+ }
43
+ return { push, cancel };
44
+ }
7
45
  function listenSocket(e, d) {
8
- const { stop, addListenClose, status, paramsModify } = d ?? {};
46
+ const { stop, addListenClose, status, paramsModify, throttle } = d ?? {};
9
47
  const { addListen, removeListen, eventClose, removeEventClose } = e;
10
48
  let last = null;
11
49
  let active = null;
12
50
  let resolveWait = null;
51
+ let throttleCh = null;
13
52
  function finish() {
14
53
  if (resolveWait) {
15
54
  resolveWait();
@@ -17,6 +56,10 @@ function listenSocket(e, d) {
17
56
  }
18
57
  }
19
58
  function removeCallback() {
59
+ if (throttleCh) {
60
+ throttleCh.cancel();
61
+ throttleCh = null;
62
+ }
20
63
  if (last) {
21
64
  stop?.(last);
22
65
  last = null;
@@ -29,7 +72,10 @@ function listenSocket(e, d) {
29
72
  finish();
30
73
  return true;
31
74
  }
32
- async function callback(z) {
75
+ function callback(z) {
76
+ if (typeof z !== "function") {
77
+ throw new TypeError("listenSocket.callback expects a function");
78
+ }
33
79
  if (last)
34
80
  stop?.(last);
35
81
  if (active)
@@ -53,9 +99,20 @@ function listenSocket(e, d) {
53
99
  removeCallback();
54
100
  };
55
101
  }
56
- const inner = handler;
102
+ let inner = handler;
103
+ if (throttle) {
104
+ if (throttleCh)
105
+ throttleCh.cancel();
106
+ const ch = createThrottleLatest(throttle, (...a) => handler(...a));
107
+ throttleCh = ch;
108
+ inner = (...a) => ch.push(...a);
109
+ }
57
110
  active = (...a) => {
58
- if (a[0] === "___STOP") {
111
+ if (a[0] === rpc_protocol_1.RPC_STOP) {
112
+ if (throttleCh) {
113
+ throttleCh.cancel();
114
+ throttleCh = null;
115
+ }
59
116
  z(...a);
60
117
  if (last) {
61
118
  stop?.(last);
@@ -73,11 +130,36 @@ function listenSocket(e, d) {
73
130
  };
74
131
  addListen(active, { cbClose: removeCallback });
75
132
  addListenClose?.addListen(removeCallback);
76
- return new Promise((resolve) => {
133
+ const wait = new Promise((resolve) => {
77
134
  resolveWait = () => { resolve(); };
78
135
  });
136
+ return (0, rpc_off_1.makeOff)(wait, removeCallback, { unsubscribe: removeCallback, removeCallback });
137
+ }
138
+ function once(z) {
139
+ if (typeof z !== "function") {
140
+ throw new TypeError("listenSocket.once expects a function");
141
+ }
142
+ let fired = false;
143
+ const oneShot = ((...a) => {
144
+ if (a[0] === rpc_protocol_1.RPC_STOP) {
145
+ removeCallback();
146
+ return;
147
+ }
148
+ if (fired)
149
+ return;
150
+ fired = true;
151
+ try {
152
+ z(...a);
153
+ }
154
+ finally {
155
+ (0, rpc_off_1.endCallback)(z);
156
+ removeCallback();
157
+ }
158
+ });
159
+ return callback(oneShot);
79
160
  }
80
- return { callback, removeCallback };
161
+ function closeStream() { e.close?.(); }
162
+ return { callback, removeCallback, on: callback, once, close: closeStream };
81
163
  }
82
164
  function listenSocketFirst(e, options) {
83
165
  const r = listenSocket(e, {
@@ -86,6 +168,9 @@ function listenSocketFirst(e, options) {
86
168
  });
87
169
  return {
88
170
  callback: r.callback,
171
+ on: r.callback,
172
+ once: r.once,
173
+ close: r.close,
89
174
  removeCallback: r.removeCallback,
90
175
  };
91
176
  }
@@ -93,6 +178,9 @@ function listenSocketAll(e, options) {
93
178
  const r = listenSocket(e, { ...options });
94
179
  return {
95
180
  callback: r.callback,
181
+ on: r.callback,
182
+ once: r.once,
183
+ close: r.close,
96
184
  removeCallback: r.removeCallback,
97
185
  };
98
186
  }
@@ -100,6 +188,9 @@ function listenSocketSmart(e, options) {
100
188
  const r = listenSocket(e, { ...options });
101
189
  return {
102
190
  callback: r.callback,
191
+ on: r.callback,
192
+ once: r.once,
193
+ close: r.close,
103
194
  removeCallback: r.removeCallback,
104
195
  };
105
196
  }
@@ -101,7 +101,7 @@ export declare function CreatAPIFacadeClientOld<T extends object>({ socketKey, s
101
101
  infoStrictly(): any;
102
102
  strictlyInit(obj?: object): Promise<unknown>;
103
103
  };
104
- export declare function CreatAPIFacadeServerOld<T extends object>({ object, socket, socketKey, debug }: {
104
+ export declare function CreatAPIFacadeServerOld<T extends object>(params: {
105
105
  socket: tSocket;
106
106
  object: T;
107
107
  socketKey: string;
@@ -9,7 +9,11 @@ exports.CreatAPIFacadeClientOld = CreatAPIFacadeClientOld;
9
9
  exports.CreatAPIFacadeServerOld = CreatAPIFacadeServerOld;
10
10
  exports.fMiniTest = fMiniTest;
11
11
  const common_1 = require("../core/common");
12
+ const old_ommonsServerMini_1 = require("./old\u0421ommonsServerMini");
12
13
  function funcPromiseServer(data, obj) {
14
+ return (0, old_ommonsServerMini_1.promiseServer)(data, obj);
15
+ }
16
+ function funcPromiseServerOld(data, obj) {
13
17
  const buf = data;
14
18
  data.api({
15
19
  onMessage: async (datum) => {
@@ -86,6 +90,9 @@ function funcPromiseServer2(sendMessage, obj) {
86
90
  };
87
91
  }
88
92
  function funcForWebSocket(data) {
93
+ return (0, old_ommonsServerMini_1.wsWrapper)(data);
94
+ }
95
+ function funcForWebSocketOld(data) {
89
96
  const limit = data.limit;
90
97
  const sendMessage = data.sendMessage;
91
98
  const free = (() => {
@@ -122,6 +129,7 @@ function funcForWebSocket(data) {
122
129
  if (data.data == "___STOP") {
123
130
  callbackMany.delete(mapId);
124
131
  free.numsSet(mapId);
132
+ return;
125
133
  }
126
134
  buf?.(data.data);
127
135
  }
@@ -188,6 +196,9 @@ function funcForWebSocket(data) {
188
196
  };
189
197
  }
190
198
  function funcScreenerClient2(data, wait) {
199
+ return (0, old_ommonsServerMini_1.createClientProxy)(data, wait);
200
+ }
201
+ function funcScreenerClient2Old(data, wait) {
191
202
  const tr = (address) => new Proxy((() => { }), {
192
203
  get(target, p, receiver) {
193
204
  address.push(p);
@@ -328,7 +339,10 @@ function CreatAPIFacadeClientOld({ socketKey, socket, limit }) {
328
339
  }
329
340
  };
330
341
  }
331
- function CreatAPIFacadeServerOld({ object, socket, socketKey, debug = false }) {
342
+ function CreatAPIFacadeServerOld(params) {
343
+ return (0, old_ommonsServerMini_1.createAPIFacadeServer)(params);
344
+ }
345
+ function CreatAPIFacadeServerOldImpl({ object, socket, socketKey, debug = false }) {
332
346
  function ff(obj) {
333
347
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => {
334
348
  return [
@@ -150,6 +150,7 @@ function wsWrapper(soc) {
150
150
  if (msg.data === "___STOP") {
151
151
  cbsMap.delete(id);
152
152
  pool.release(id);
153
+ return;
153
154
  }
154
155
  cb(msg.data);
155
156
  }
@@ -0,0 +1,10 @@
1
+ export declare const Caps: {
2
+ readonly COMPACT: number;
3
+ };
4
+ export type tCaps = number;
5
+ export declare const CAPS_ALL: tCaps;
6
+ export declare const hasCap: (caps: tCaps, c: number) => boolean;
7
+ export type RpcOpt = {
8
+ compact?: boolean;
9
+ };
10
+ export declare function optToCaps(opt?: RpcOpt): tCaps;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasCap = exports.CAPS_ALL = exports.Caps = void 0;
4
+ exports.optToCaps = optToCaps;
5
+ exports.Caps = {
6
+ COMPACT: 1 << 0,
7
+ };
8
+ exports.CAPS_ALL = exports.Caps.COMPACT;
9
+ const hasCap = (caps, c) => (caps & c) === c;
10
+ exports.hasCap = hasCap;
11
+ function optToCaps(opt) {
12
+ let c = exports.CAPS_ALL;
13
+ if (opt?.compact === false)
14
+ c &= ~exports.Caps.COMPACT;
15
+ return c;
16
+ }
@@ -1,4 +1,7 @@
1
1
  import { type SocketTmpl } from "./rpc-protocol";
2
+ import { type RpcLimits } from "./rpc-limits";
3
+ import { makeOff } from "./rpc-off";
4
+ import { type RpcOpt } from "./rpc-caps";
2
5
  type UnwrapPromise<T> = T extends Promise<infer R> ? R : T;
3
6
  export type DeepDataOnly<T> = T extends Function ? never : T extends Array<infer U> ? Array<DeepDataOnly<U>> : T extends object ? {
4
7
  [K in keyof T as T[K] extends Function ? never : K]: DeepDataOnly<T[K]>;
@@ -24,6 +27,10 @@ type ClientApiHandle = {
24
27
  clearCallbacks: () => void;
25
28
  remove: (fn: Function) => void;
26
29
  end: (fn: Function) => void;
30
+ subscriptions: () => {
31
+ key: string;
32
+ consumers: number;
33
+ }[];
27
34
  };
28
35
  export type RpcClientReturn<T extends object> = {
29
36
  func: ClientAPIAll<T>;
@@ -34,13 +41,28 @@ export type RpcClientReturn<T extends object> = {
34
41
  strict: ClientAPIStrict<T>;
35
42
  api: ClientApiHandle;
36
43
  abortAll: (reason: string) => void;
44
+ dispose: (reason?: string, opts?: {
45
+ socketAlive?: boolean;
46
+ }) => void;
47
+ close: (reason?: string, opts?: {
48
+ socketAlive?: boolean;
49
+ }) => void;
37
50
  schema: () => any;
38
51
  readyStrict: () => Promise<void>;
52
+ ready: () => Promise<void>;
39
53
  initStrict: (obj?: object) => Promise<void>;
54
+ init: (obj?: object) => Promise<void>;
55
+ reauth: (token: any) => Promise<any>;
56
+ auth: () => Promise<any>;
57
+ onDisconnect: (cb: (reason: string) => void) => ReturnType<typeof makeOff>;
40
58
  };
41
- export declare function createRpcClient<T extends object>({ socket, socketKey: key, limit }: {
59
+ export declare function createRpcClient<T extends object>({ socket, socketKey: key, limit, limits, dedupeListen, token, opt }: {
42
60
  socket: SocketTmpl;
43
61
  socketKey: string;
44
62
  limit?: number;
63
+ limits?: RpcLimits;
64
+ dedupeListen?: boolean;
65
+ token?: any;
66
+ opt?: RpcOpt;
45
67
  }): RpcClientReturn<T>;
46
68
  export type { ClientApiHandle };