wenay-common2 1.0.61 → 1.0.63
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 +8 -8
- package/lib/Common/Observe/index.d.ts +5 -0
- package/lib/Common/{ObserveAll2 → Observe}/index.js +3 -1
- package/lib/Common/Observe/reactive.d.ts +21 -0
- package/lib/Common/{ObserveAll2/reactive2.js → Observe/reactive.js} +7 -7
- package/lib/Common/Observe/reactive2.d.ts +1 -0
- package/lib/Common/{events/Listen2.js → Observe/reactive2.js} +1 -1
- package/lib/Common/Observe/store-manager.d.ts +123 -0
- package/lib/Common/Observe/store-manager.js +227 -0
- package/lib/Common/Observe/store-offline.d.ts +88 -0
- package/lib/Common/Observe/store-offline.js +278 -0
- package/lib/Common/{ObserveAll2 → Observe}/store-replay.d.ts +9 -38
- package/lib/Common/{ObserveAll2 → Observe}/store-replay.js +1 -1
- package/lib/Common/{ObserveAll2 → Observe}/store.d.ts +3 -3
- package/lib/Common/{ObserveAll2 → Observe}/store.js +25 -31
- package/lib/Common/async/promiseProgress.d.ts +12 -0
- package/lib/Common/async/promiseProgress.js +29 -0
- package/lib/Common/events/Listen.d.ts +129 -1
- package/lib/Common/events/Listen.js +243 -15
- package/lib/Common/events/Listen3.d.ts +1 -210
- package/lib/Common/events/Listen3.js +15 -253
- package/lib/Common/events/SocketBuffer.d.ts +13 -33
- package/lib/Common/events/SocketBuffer.js +8 -8
- package/lib/Common/events/SocketServerHook.d.ts +5 -45
- package/lib/Common/events/SocketServerHook.js +1 -1
- package/lib/Common/events/joinListens.d.ts +6 -7
- package/lib/Common/events/joinListens.js +3 -4
- package/lib/Common/events/mapListen.d.ts +4 -0
- package/lib/Common/events/mapListen.js +25 -0
- package/lib/Common/events/replay-conflate.d.ts +2 -22
- package/lib/Common/events/replay-conflate.js +5 -5
- package/lib/Common/events/replay-history.d.ts +1 -1
- package/lib/Common/events/replay-listen.d.ts +20 -66
- package/lib/Common/events/replay-listen.js +10 -13
- package/lib/Common/events/replay-wire.d.ts +1 -1
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.d.ts +3 -3
- package/lib/Common/rcp/createRpcServerAutoWithProtocolDetection.js +10 -10
- package/lib/Common/rcp/listen-deep.d.ts +10 -10
- package/lib/Common/rcp/listen-deep.js +1 -1
- package/lib/Common/rcp/listen-socket.d.ts +13 -13
- package/lib/Common/rcp/listen-socket.js +4 -3
- package/lib/Common/rcp/rpc-client-auto.d.ts +2 -2
- package/lib/Common/rcp/rpc-client-auto.js +3 -2
- package/lib/Common/rcp/rpc-client.js +6 -4
- package/lib/Common/rcp/rpc-index.d.ts +2 -1
- package/lib/Common/rcp/rpc-index.js +3 -2
- package/lib/Common/rcp/rpc-path.d.ts +1 -0
- package/lib/Common/rcp/rpc-path.js +6 -0
- package/lib/Common/rcp/rpc-server-auto.d.ts +2 -2
- package/lib/Common/rcp/rpc-server-auto.js +7 -11
- package/lib/Common/rcp/rpc-server.js +11 -7
- package/lib/client.d.ts +1 -1
- package/lib/client.js +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.js +4 -5
- package/package.json +5 -3
- package/lib/Common/ObserveAll2/index.d.ts +0 -3
- package/lib/Common/ObserveAll2/reactive2.d.ts +0 -61
- package/lib/Common/async/PromiseArrayListen.d.ts +0 -14
- package/lib/Common/async/PromiseArrayListen.js +0 -37
- package/lib/Common/events/Listen2.d.ts +0 -1
- package/lib/Common/events/UseListenTransform.d.ts +0 -24
- package/lib/Common/events/UseListenTransform.js +0 -28
- package/lib/Common/rcp/test.d.ts +0 -1
- package/lib/Common/rcp/test.js +0 -79
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Listener, ListenApi, ListenCurrent, ListenCurrentProvider, ListenOnBrand, ListenOptions, NormalizeTuple } from './
|
|
1
|
+
import { Listener, ListenApi, ListenCurrent, ListenCurrentProvider, ListenOnBrand, ListenOptions, NormalizeTuple } from './Listen';
|
|
2
2
|
type key = string | symbol;
|
|
3
3
|
type cbClose = () => void;
|
|
4
4
|
export declare const IS_REPLAY_LISTEN: unique symbol;
|
|
@@ -32,99 +32,53 @@ type ReplayOnOptions<Z extends any[]> = {
|
|
|
32
32
|
};
|
|
33
33
|
export type ListenOnReplay<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: ReplayOnOptions<Z>) => (() => void)) & ListenOnBrand<Z>;
|
|
34
34
|
export declare function withReplayListen<T>(base: ListenApi<T>, options?: ReplayListenOptions<NormalizeTuple<T>>): {
|
|
35
|
-
|
|
35
|
+
emit: Listener<NormalizeTuple<T>>;
|
|
36
36
|
head: () => number;
|
|
37
37
|
isStale: () => boolean;
|
|
38
38
|
lastTs: () => number;
|
|
39
39
|
close: () => void;
|
|
40
40
|
getSince: (seq: number) => ReplayEvent<NormalizeTuple<T>>[] | undefined;
|
|
41
|
-
line:
|
|
42
|
-
func: Listener<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
43
|
-
isRun: () => boolean;
|
|
44
|
-
run: () => void;
|
|
45
|
-
close: () => void;
|
|
46
|
-
eventClose: (cb: () => void) => () => void;
|
|
47
|
-
onClose: (cb: () => void) => () => void;
|
|
48
|
-
removeEventClose: (cb: () => void) => void;
|
|
49
|
-
on: import("./Listen3").ListenOn<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
50
|
-
off: (k: (string | symbol) | Listener<[ReplayEvent<NormalizeTuple<T>>]> | null) => void;
|
|
51
|
-
addListen: (cb: Listener<[ReplayEvent<NormalizeTuple<T>>]>, opts?: {
|
|
52
|
-
cbClose?: () => void;
|
|
53
|
-
key?: string | symbol;
|
|
54
|
-
}) => () => void;
|
|
55
|
-
removeListen: (k: (string | symbol) | Listener<[ReplayEvent<NormalizeTuple<T>>]> | null) => void;
|
|
56
|
-
once: (cb: Listener<[ReplayEvent<NormalizeTuple<T>>]>, opts?: {
|
|
57
|
-
key?: string | symbol;
|
|
58
|
-
}) => () => void;
|
|
59
|
-
count: () => number;
|
|
60
|
-
readonly getAllKeys: (string | symbol)[];
|
|
61
|
-
};
|
|
41
|
+
line: ListenApi<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
62
42
|
hasKeyframe: boolean;
|
|
63
43
|
keyframe: () => ReplayEvent<NormalizeTuple<T>> | undefined;
|
|
64
44
|
frame: (sinceSeq: number, hint?: unknown) => ReplayEvent<NormalizeTuple<T>>[];
|
|
65
45
|
on: ListenOnReplay<NormalizeTuple<T>>;
|
|
66
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: ReplayOnOptions<NormalizeTuple<T>>) => () => void;
|
|
67
|
-
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
68
46
|
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
69
47
|
key?: key;
|
|
70
48
|
current?: ListenCurrent<NormalizeTuple<T>>;
|
|
71
49
|
}) => () => void;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
count: () => number;
|
|
50
|
+
has(key: import("./Listen").ListenKey): boolean;
|
|
51
|
+
off(keyOrCallback: import("./Listen").ListenKey | Listener<NormalizeTuple<T>> | null): void;
|
|
52
|
+
count(): number;
|
|
53
|
+
keys(): import("./Listen").ListenKey[];
|
|
54
|
+
isRunning(): boolean;
|
|
55
|
+
run(): void;
|
|
56
|
+
onClose(cb: () => void): import("./Listen").ListenOff;
|
|
80
57
|
};
|
|
81
58
|
export type ListenReplayApi<T> = ReturnType<typeof withReplayListen<T>>;
|
|
82
59
|
export type ReplayListenUseOptions<T> = ListenOptions<T> & ReplayListenOptions<NormalizeTuple<T>>;
|
|
83
|
-
export declare function
|
|
84
|
-
|
|
60
|
+
export declare function replayListen<T>(options?: ReplayListenUseOptions<T>): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
61
|
+
emit: Listener<NormalizeTuple<T>>;
|
|
85
62
|
head: () => number;
|
|
86
63
|
isStale: () => boolean;
|
|
87
64
|
lastTs: () => number;
|
|
88
65
|
close: () => void;
|
|
89
66
|
getSince: (seq: number) => ReplayEvent<NormalizeTuple<T>>[] | undefined;
|
|
90
|
-
line:
|
|
91
|
-
func: Listener<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
92
|
-
isRun: () => boolean;
|
|
93
|
-
run: () => void;
|
|
94
|
-
close: () => void;
|
|
95
|
-
eventClose: (cb: () => void) => () => void;
|
|
96
|
-
onClose: (cb: () => void) => () => void;
|
|
97
|
-
removeEventClose: (cb: () => void) => void;
|
|
98
|
-
on: import("./Listen3").ListenOn<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
99
|
-
off: (k: (string | symbol) | Listener<[ReplayEvent<NormalizeTuple<T>>]> | null) => void;
|
|
100
|
-
addListen: (cb: Listener<[ReplayEvent<NormalizeTuple<T>>]>, opts?: {
|
|
101
|
-
cbClose?: () => void;
|
|
102
|
-
key?: string | symbol;
|
|
103
|
-
}) => () => void;
|
|
104
|
-
removeListen: (k: (string | symbol) | Listener<[ReplayEvent<NormalizeTuple<T>>]> | null) => void;
|
|
105
|
-
once: (cb: Listener<[ReplayEvent<NormalizeTuple<T>>]>, opts?: {
|
|
106
|
-
key?: string | symbol;
|
|
107
|
-
}) => () => void;
|
|
108
|
-
count: () => number;
|
|
109
|
-
readonly getAllKeys: (string | symbol)[];
|
|
110
|
-
};
|
|
67
|
+
line: ListenApi<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
111
68
|
hasKeyframe: boolean;
|
|
112
69
|
keyframe: () => ReplayEvent<NormalizeTuple<T>> | undefined;
|
|
113
70
|
frame: (sinceSeq: number, hint?: unknown) => ReplayEvent<NormalizeTuple<T>>[];
|
|
114
71
|
on: ListenOnReplay<NormalizeTuple<T>>;
|
|
115
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: ReplayOnOptions<NormalizeTuple<T>>) => () => void;
|
|
116
|
-
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
117
72
|
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
118
73
|
key?: key;
|
|
119
74
|
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
120
75
|
}) => () => void;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
count: () => number;
|
|
76
|
+
has(key: import("./Listen").ListenKey): boolean;
|
|
77
|
+
off(keyOrCallback: import("./Listen").ListenKey | Listener<NormalizeTuple<T>> | null): void;
|
|
78
|
+
count(): number;
|
|
79
|
+
keys(): import("./Listen").ListenKey[];
|
|
80
|
+
isRunning(): boolean;
|
|
81
|
+
run(): void;
|
|
82
|
+
onClose(cb: () => void): import("./Listen").ListenOff;
|
|
129
83
|
}];
|
|
130
84
|
export {};
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IS_REPLAY_LISTEN = void 0;
|
|
4
4
|
exports.isReplayListen = isReplayListen;
|
|
5
5
|
exports.withReplayListen = withReplayListen;
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.replayListen = replayListen;
|
|
7
|
+
const Listen_1 = require("./Listen");
|
|
8
8
|
exports.IS_REPLAY_LISTEN = Symbol.for('isReplayListen');
|
|
9
9
|
function isReplayListen(obj) {
|
|
10
10
|
return !!obj && typeof obj == 'object' && Object.prototype.hasOwnProperty.call(obj, exports.IS_REPLAY_LISTEN);
|
|
@@ -16,7 +16,7 @@ function withReplayListen(base, options = {}) {
|
|
|
16
16
|
let head = 0;
|
|
17
17
|
const ring = [];
|
|
18
18
|
let emitting = null;
|
|
19
|
-
const line = (0,
|
|
19
|
+
const line = (0, Listen_1.createListen)(() => { });
|
|
20
20
|
line.run();
|
|
21
21
|
function journalSince(seq) {
|
|
22
22
|
if (getSince)
|
|
@@ -78,7 +78,7 @@ function withReplayListen(base, options = {}) {
|
|
|
78
78
|
}
|
|
79
79
|
const api = {
|
|
80
80
|
...base,
|
|
81
|
-
|
|
81
|
+
emit: function emitJournaled(...e) {
|
|
82
82
|
const ev = { seq: ++head, ts: now(), event: e };
|
|
83
83
|
if (history > 0)
|
|
84
84
|
ring[(ev.seq - 1) % history] = ev;
|
|
@@ -86,11 +86,11 @@ function withReplayListen(base, options = {}) {
|
|
|
86
86
|
lastEv = ev;
|
|
87
87
|
onJournal?.(ev);
|
|
88
88
|
touchStale(ev.ts);
|
|
89
|
-
line.
|
|
89
|
+
line.emit(ev);
|
|
90
90
|
const prev = emitting;
|
|
91
91
|
emitting = ev;
|
|
92
92
|
try {
|
|
93
|
-
base.
|
|
93
|
+
base.emit(...e);
|
|
94
94
|
}
|
|
95
95
|
finally {
|
|
96
96
|
emitting = prev;
|
|
@@ -165,8 +165,6 @@ function withReplayListen(base, options = {}) {
|
|
|
165
165
|
replaying = false;
|
|
166
166
|
return off;
|
|
167
167
|
}),
|
|
168
|
-
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
169
|
-
removeListen: (k) => api.off(k),
|
|
170
168
|
once: (cb, opts = {}) => {
|
|
171
169
|
if (opts.current) {
|
|
172
170
|
const m = currentValue(opts.current);
|
|
@@ -179,18 +177,17 @@ function withReplayListen(base, options = {}) {
|
|
|
179
177
|
off = base.on(((...e) => { off(); cb(...e); }), { key: opts.key });
|
|
180
178
|
return off;
|
|
181
179
|
},
|
|
182
|
-
get getAllKeys() { return base.getAllKeys; },
|
|
183
180
|
};
|
|
184
181
|
Object.defineProperty(api, exports.IS_REPLAY_LISTEN, { value: true });
|
|
185
|
-
(0,
|
|
182
|
+
(0, Listen_1.registerListenOn)(api.on, api);
|
|
186
183
|
return api;
|
|
187
184
|
}
|
|
188
|
-
function
|
|
185
|
+
function replayListen(options = {}) {
|
|
189
186
|
const { current, frame, history, getSince, onJournal, now, staleMs, onStale, ...listenOptions } = options;
|
|
190
187
|
let t;
|
|
191
|
-
const base = (0,
|
|
188
|
+
const base = (0, Listen_1.createListen)((e) => { t = e; }, { fast: true, ...listenOptions });
|
|
192
189
|
const listen = withReplayListen(base, { current, frame, history, getSince, onJournal, now, staleMs, onStale });
|
|
193
190
|
base.run();
|
|
194
|
-
t = listen.
|
|
191
|
+
t = listen.emit;
|
|
195
192
|
return [t, listen];
|
|
196
193
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Listener, NormalizeTuple } from './
|
|
1
|
+
import { Listener, NormalizeTuple } from './Listen';
|
|
2
2
|
import { ListenReplayApi, ReplayEvent, StaleInfo } from './replay-listen';
|
|
3
3
|
import { conflateReplay, ConflateOpts } from './replay-conflate';
|
|
4
4
|
export type ReplayExpose<T> = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createListen } from "../events/Listen";
|
|
2
2
|
import { type PromiseServerHooks, type RpcLimits } from "./rpc-server";
|
|
3
3
|
import { DeepSocketListen } from "./listen-deep";
|
|
4
4
|
import { type SocketTmpl } from "./rpc-protocol";
|
|
5
|
-
type ListenCallbackBase<T extends any[] = any[]> = ReturnType<typeof
|
|
5
|
+
type ListenCallbackBase<T extends any[] = any[]> = ReturnType<typeof createListen<T>>;
|
|
6
6
|
type ClientProtocol = 'v2' | 'legacy' | null;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function createRpcServerAutoDetect<T extends object>({ socket, object: target, socketKey: key, debug, hooks, disconnectListen, limits, onProtocolDetect, }: {
|
|
8
8
|
socket: SocketTmpl;
|
|
9
9
|
object: T;
|
|
10
10
|
socketKey: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createRpcServerAutoDetect = createRpcServerAutoDetect;
|
|
4
4
|
const Listen_1 = require("../events/Listen");
|
|
5
5
|
const listen_socket_1 = require("./listen-socket");
|
|
6
6
|
const rpc_server_1 = require("./rpc-server");
|
|
@@ -8,7 +8,7 @@ const rpc_protocol_1 = require("./rpc-protocol");
|
|
|
8
8
|
const old_ommonsServerMini_1 = require("./old\u0421ommonsServerMini");
|
|
9
9
|
const rpc_dynamic_1 = require("./rpc-dynamic");
|
|
10
10
|
const rpc_limits_1 = require("./rpc-limits");
|
|
11
|
-
function
|
|
11
|
+
function createRpcServerAutoDetect({ socket, object: target, socketKey: key, debug = false, hooks, disconnectListen, limits, onProtocolDetect, }) {
|
|
12
12
|
const cache = new WeakMap();
|
|
13
13
|
const listenSockets = new Set();
|
|
14
14
|
function unsubscribeAllActive() {
|
|
@@ -25,7 +25,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
25
25
|
if (typeof z !== "function")
|
|
26
26
|
return Promise.reject(new TypeError("Listen callback expects a function"));
|
|
27
27
|
subs.get(z)?.off();
|
|
28
|
-
const w = (0, listen_socket_1.listenSocket)(parent, {
|
|
28
|
+
const w = (0, listen_socket_1.listenSocket)(parent, { closeOn: disconnectListen });
|
|
29
29
|
subs.set(z, w);
|
|
30
30
|
const done = w.on(z);
|
|
31
31
|
done.then(() => { if (subs.get(z) == w)
|
|
@@ -36,7 +36,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
36
36
|
if (typeof z !== "function")
|
|
37
37
|
return Promise.reject(new TypeError("Listen once expects a function"));
|
|
38
38
|
subs.get(z)?.off();
|
|
39
|
-
const w = (0, listen_socket_1.listenSocket)(parent, {
|
|
39
|
+
const w = (0, listen_socket_1.listenSocket)(parent, { closeOn: disconnectListen });
|
|
40
40
|
subs.set(z, w);
|
|
41
41
|
const done = w.once(z);
|
|
42
42
|
done.then(() => { if (subs.get(z) == w)
|
|
@@ -173,7 +173,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
173
173
|
}
|
|
174
174
|
function handleMessage(msg) {
|
|
175
175
|
if (debug) {
|
|
176
|
-
console.log('[RPC-
|
|
176
|
+
console.log('[RPC-AUTO-DETECT IN]', typeof msg === 'object' ? JSON.stringify(msg) : msg);
|
|
177
177
|
}
|
|
178
178
|
if (protocol === 'legacy') {
|
|
179
179
|
if (isLegacyStrictRequest(msg)) {
|
|
@@ -190,7 +190,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
190
190
|
if (isLegacyStrictRequest(msg)) {
|
|
191
191
|
protocol = 'legacy';
|
|
192
192
|
if (debug)
|
|
193
|
-
console.log('[RPC-
|
|
193
|
+
console.log('[RPC-AUTO-DETECT] Protocol detected: legacy (___STRICTLY)');
|
|
194
194
|
onProtocolDetect?.('legacy');
|
|
195
195
|
initLegacy();
|
|
196
196
|
socket.emit(key, { STRICTLY: legacySchema });
|
|
@@ -199,7 +199,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
199
199
|
if (isLegacyMessage(msg)) {
|
|
200
200
|
protocol = 'legacy';
|
|
201
201
|
if (debug)
|
|
202
|
-
console.log('[RPC-
|
|
202
|
+
console.log('[RPC-AUTO-DETECT] Protocol detected: legacy (mapId message)');
|
|
203
203
|
onProtocolDetect?.('legacy');
|
|
204
204
|
initLegacy();
|
|
205
205
|
legacyHandler(msg);
|
|
@@ -208,14 +208,14 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
208
208
|
if (isV2Message(msg)) {
|
|
209
209
|
protocol = 'v2';
|
|
210
210
|
if (debug)
|
|
211
|
-
console.log('[RPC-
|
|
211
|
+
console.log('[RPC-AUTO-DETECT] Protocol detected: v2');
|
|
212
212
|
onProtocolDetect?.('v2');
|
|
213
213
|
initV2();
|
|
214
214
|
v2Handler(msg);
|
|
215
215
|
return;
|
|
216
216
|
}
|
|
217
217
|
if (debug)
|
|
218
|
-
console.warn('[RPC-
|
|
218
|
+
console.warn('[RPC-AUTO-DETECT] Unknown message format, ignoring:', msg);
|
|
219
219
|
}
|
|
220
220
|
activeHandler = handleMessage;
|
|
221
221
|
socket.on(key, (msg) => activeHandler?.(msg));
|
|
@@ -227,7 +227,7 @@ function createRpcServerAuto2({ socket, object: target, socketKey: key, debug =
|
|
|
227
227
|
activeHandler = null;
|
|
228
228
|
reset();
|
|
229
229
|
if (debug)
|
|
230
|
-
console.log('[RPC-
|
|
230
|
+
console.log('[RPC-AUTO-DETECT] disposed', reason ?? '');
|
|
231
231
|
}
|
|
232
232
|
return {
|
|
233
233
|
getProtocol: () => protocol,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type ListenOn } from "../events/Listen";
|
|
2
2
|
import type { ReplayEvent } from "../events/replay-listen";
|
|
3
|
-
import { listenSocket, listenSocketFirst, listenSocketAll, listenSocketSmart, type
|
|
3
|
+
import { listenSocket, listenSocketFirst, listenSocketAll, listenSocketSmart, type SubscriptionHandle } from "./listen-socket";
|
|
4
4
|
type WithSubHandle<R> = R extends {
|
|
5
5
|
callback: (...a: infer A) => any;
|
|
6
6
|
} ? Omit<R, 'callback' | 'on' | 'once'> & {
|
|
7
|
-
callback: (...a: A) =>
|
|
8
|
-
on: (...a: A) =>
|
|
9
|
-
once: (...a: A) =>
|
|
7
|
+
callback: (...a: A) => SubscriptionHandle & Promise<void>;
|
|
8
|
+
on: (...a: A) => SubscriptionHandle & Promise<void>;
|
|
9
|
+
once: (...a: A) => SubscriptionHandle & Promise<void>;
|
|
10
10
|
} : R;
|
|
11
11
|
type Obj = Record<string, any>;
|
|
12
12
|
export type InferArgs<T> = T extends {
|
|
13
|
-
|
|
13
|
+
on: (cb: (...args: infer R) => void, ...rest: any[]) => any;
|
|
14
14
|
} ? R : never;
|
|
15
15
|
export type ReplaySocketListen<Z extends any[]> = WithSubHandle<ReturnType<typeof listenSocket<Z>>> & {
|
|
16
16
|
line: WithSubHandle<ReturnType<typeof listenSocket<[ReplayEvent<Z>]>>>;
|
|
@@ -20,29 +20,29 @@ export type ReplaySocketListen<Z extends any[]> = WithSubHandle<ReturnType<typeo
|
|
|
20
20
|
frame: (seq: number, hint?: unknown) => Promise<ReplayEvent<Z>[]>;
|
|
21
21
|
};
|
|
22
22
|
export type IsReplayMember<V> = V extends {
|
|
23
|
-
addListen: Function;
|
|
24
23
|
getSince: Function;
|
|
25
24
|
keyframe: Function;
|
|
26
25
|
line: object;
|
|
26
|
+
on: Function;
|
|
27
27
|
} ? true : false;
|
|
28
28
|
export type DeepSocketListen<T> = {
|
|
29
29
|
[K in keyof T]: IsReplayMember<T[K]> extends true ? ReplaySocketListen<InferArgs<T[K]>> : T[K] extends {
|
|
30
|
-
|
|
30
|
+
on: Function;
|
|
31
31
|
} ? WithSubHandle<ReturnType<typeof listenSocket<InferArgs<T[K]>>>> : T[K] extends ListenOn<infer Z> ? WithSubHandle<ReturnType<typeof listenSocket<Z>>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListen<T[K]> : T[K];
|
|
32
32
|
};
|
|
33
33
|
export type DeepSocketListenFirst<T> = {
|
|
34
34
|
[K in keyof T]: T[K] extends {
|
|
35
|
-
|
|
35
|
+
on: Function;
|
|
36
36
|
} ? ReturnType<typeof listenSocketFirst<InferArgs<T[K]>>> : T[K] extends ListenOn<infer Z> ? ReturnType<typeof listenSocketFirst<Z>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListenFirst<T[K]> : T[K];
|
|
37
37
|
};
|
|
38
38
|
export type DeepSocketListenAll<T> = {
|
|
39
39
|
[K in keyof T]: T[K] extends {
|
|
40
|
-
|
|
40
|
+
on: Function;
|
|
41
41
|
} ? ReturnType<typeof listenSocketAll<InferArgs<T[K]>>> : T[K] extends ListenOn<infer Z> ? ReturnType<typeof listenSocketAll<Z>> : T[K] extends (...a: any[]) => any ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends typeof Promise ? T[K] : T[K] extends object ? DeepSocketListenAll<T[K]> : T[K];
|
|
42
42
|
};
|
|
43
43
|
export type DeepSocketListenSmart<T> = {
|
|
44
44
|
[K in keyof T]: IsReplayMember<NonNullable<T[K]>> extends true ? ReplaySocketListen<InferArgs<NonNullable<T[K]>>> | Extract<T[K], undefined | null> : NonNullable<T[K]> extends {
|
|
45
|
-
|
|
45
|
+
on: Function;
|
|
46
46
|
} ? ReturnType<typeof listenSocketSmart<InferArgs<NonNullable<T[K]>>>> | Extract<T[K], undefined | null> : NonNullable<T[K]> extends ListenOn<infer Z> ? ReturnType<typeof listenSocketSmart<Z>> : NonNullable<T[K]> extends (...a: any[]) => any ? T[K] : NonNullable<T[K]> extends Promise<any> ? T[K] : NonNullable<T[K]> extends typeof Promise ? T[K] : NonNullable<T[K]> extends object ? DeepSocketListenSmart<T[K]> : T[K];
|
|
47
47
|
};
|
|
48
48
|
export declare function matchKeys<T extends Obj, T2 extends Obj>(obj1: T, obj2: T2): boolean;
|
|
@@ -32,7 +32,7 @@ function deepMapByKeysList(obj1, keys, func) {
|
|
|
32
32
|
function deepMapByKeys(obj1, obj2, func) {
|
|
33
33
|
return deepMapByKeysList(obj1, Object.keys(obj2), func);
|
|
34
34
|
}
|
|
35
|
-
const NOOP_LISTEN = (0, Listen_1.
|
|
35
|
+
const NOOP_LISTEN = (0, Listen_1.createListen)((_e) => { });
|
|
36
36
|
function deepListenFirst(obj, data) {
|
|
37
37
|
return deepMapByKeys(obj, NOOP_LISTEN, (e) => (0, listen_socket_1.listenSocketFirst)(e, data));
|
|
38
38
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createListen, type Listener } from "../events/Listen";
|
|
2
2
|
import { type Off } from "./rpc-off";
|
|
3
|
-
type ListenCallbackResult<T extends any[] = any[]> = ReturnType<typeof
|
|
4
|
-
export type
|
|
3
|
+
type ListenCallbackResult<T extends any[] = any[]> = ReturnType<typeof createListen<T>>;
|
|
4
|
+
export type SubscriptionHandle = Off<void, {
|
|
5
5
|
off: () => void;
|
|
6
6
|
unsubscribe: () => void;
|
|
7
7
|
removeCallback: () => void;
|
|
8
8
|
}>;
|
|
9
9
|
export declare function listenSocket<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, d?: {
|
|
10
10
|
readonly status?: () => boolean;
|
|
11
|
-
readonly
|
|
11
|
+
readonly closeOn?: ListenCallbackResult<any>;
|
|
12
12
|
readonly stop?: (x: Listener<Z>) => any;
|
|
13
13
|
readonly paramsModify?: (...e: Z) => any[];
|
|
14
14
|
readonly throttle?: number;
|
|
@@ -21,26 +21,26 @@ export declare function listenSocket<Z extends any[] = any[]>(e: ListenCallbackR
|
|
|
21
21
|
close: () => void;
|
|
22
22
|
};
|
|
23
23
|
export declare function listenSocketFirst<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
|
|
24
|
-
callback: (z: (a: Z[0]) => void) =>
|
|
25
|
-
on: (z: (a: Z[0]) => void) =>
|
|
26
|
-
once: (z: (a: Z[0]) => void) =>
|
|
24
|
+
callback: (z: (a: Z[0]) => void) => SubscriptionHandle;
|
|
25
|
+
on: (z: (a: Z[0]) => void) => SubscriptionHandle;
|
|
26
|
+
once: (z: (a: Z[0]) => void) => SubscriptionHandle;
|
|
27
27
|
close: () => void;
|
|
28
28
|
off: () => boolean;
|
|
29
29
|
removeCallback: () => boolean;
|
|
30
30
|
};
|
|
31
31
|
export declare function listenSocketAll<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
|
|
32
|
-
callback: (z: (...args: Z) => void) =>
|
|
33
|
-
on: (z: (...args: Z) => void) =>
|
|
34
|
-
once: (z: (...args: Z) => void) =>
|
|
32
|
+
callback: (z: (...args: Z) => void) => SubscriptionHandle;
|
|
33
|
+
on: (z: (...args: Z) => void) => SubscriptionHandle;
|
|
34
|
+
once: (z: (...args: Z) => void) => SubscriptionHandle;
|
|
35
35
|
close: () => void;
|
|
36
36
|
off: () => boolean;
|
|
37
37
|
removeCallback: () => boolean;
|
|
38
38
|
};
|
|
39
39
|
type SmartCallback<Z extends any[]> = Z extends [infer Single] ? (a: Single) => void : (...args: Z) => void;
|
|
40
40
|
export declare function listenSocketSmart<Z extends any[] = any[]>(e: ListenCallbackResult<Z>, options?: Omit<Parameters<typeof listenSocket>[1], "paramsModify">): {
|
|
41
|
-
callback: (z: SmartCallback<Z>) =>
|
|
42
|
-
on: (z: SmartCallback<Z>) =>
|
|
43
|
-
once: (z: SmartCallback<Z>) =>
|
|
41
|
+
callback: (z: SmartCallback<Z>) => SubscriptionHandle;
|
|
42
|
+
on: (z: SmartCallback<Z>) => SubscriptionHandle;
|
|
43
|
+
once: (z: SmartCallback<Z>) => SubscriptionHandle;
|
|
44
44
|
close: () => void;
|
|
45
45
|
off: () => boolean;
|
|
46
46
|
removeCallback: () => boolean;
|
|
@@ -43,9 +43,10 @@ function createThrottleLatest(ms, sink) {
|
|
|
43
43
|
return { push, cancel };
|
|
44
44
|
}
|
|
45
45
|
function listenSocket(e, d) {
|
|
46
|
-
const { stop,
|
|
47
|
-
const
|
|
48
|
-
const
|
|
46
|
+
const { stop, status, paramsModify, throttle } = d ?? {};
|
|
47
|
+
const closeOn = d?.closeOn;
|
|
48
|
+
const subscribe = (cb, opts) => e.on(cb, opts);
|
|
49
|
+
const subscribeClose = closeOn && ((cb) => closeOn.on(cb));
|
|
49
50
|
let last = null;
|
|
50
51
|
let active = null;
|
|
51
52
|
let activeOff = null;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createListen } from "../events/Listen";
|
|
2
2
|
import type { DeepSocketListen } from "./listen-deep";
|
|
3
3
|
import type { ClientAPIStrict } from "./rpc-client";
|
|
4
4
|
type ClientAutoOptions = {
|
|
5
5
|
readonly mode?: "smart" | "first" | "all";
|
|
6
6
|
readonly status?: () => boolean;
|
|
7
|
-
readonly
|
|
7
|
+
readonly closeOn?: ReturnType<typeof createListen<any>>;
|
|
8
8
|
};
|
|
9
9
|
export type ClientAutoResult<T> = DeepSocketListen<T>;
|
|
10
10
|
export type AutoClientAPI<T> = ClientAPIStrict<DeepSocketListen<T>>;
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createRpcClientAuto = createRpcClientAuto;
|
|
4
4
|
const listen_deep_1 = require("./listen-deep");
|
|
5
5
|
function createRpcClientAuto(api, options) {
|
|
6
|
-
const { mode = "smart", status
|
|
6
|
+
const { mode = "smart", status } = options ?? {};
|
|
7
|
+
const closeOn = options?.closeOn;
|
|
7
8
|
const listenOptions = {
|
|
8
9
|
...(status ? { status } : {}),
|
|
9
|
-
...(
|
|
10
|
+
...(closeOn ? { closeOn } : {}),
|
|
10
11
|
};
|
|
11
12
|
switch (mode) {
|
|
12
13
|
case "first":
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRpcClient = createRpcClient;
|
|
4
4
|
const rpc_protocol_1 = require("./rpc-protocol");
|
|
5
|
+
const rpc_path_1 = require("./rpc-path");
|
|
5
6
|
const id_pool_1 = require("../id-pool");
|
|
6
7
|
const rpc_walk_1 = require("./rpc-walk");
|
|
7
8
|
const rpc_limits_1 = require("./rpc-limits");
|
|
@@ -219,7 +220,7 @@ function createClient(socket, key, opts) {
|
|
|
219
220
|
}
|
|
220
221
|
return step;
|
|
221
222
|
});
|
|
222
|
-
const ref = routeCache[
|
|
223
|
+
const ref = routeCache[(0, rpc_path_1.rpcPathKey)(path)] ?? path;
|
|
223
224
|
if (!wait) {
|
|
224
225
|
socket.emit(key, [rpc_protocol_1.Pkt.PIPE, 0, ref, cleanSteps, false]);
|
|
225
226
|
return Promise.resolve();
|
|
@@ -280,7 +281,7 @@ function createClient(socket, key, opts) {
|
|
|
280
281
|
return wait ? Promise.reject(new Error("RPC client disposed")) : Promise.resolve();
|
|
281
282
|
const cbIds = [];
|
|
282
283
|
const clean = (0, rpc_walk_1.pack)(args, pool, callbacks, cbIds);
|
|
283
|
-
const ref = routeCache[
|
|
284
|
+
const ref = routeCache[(0, rpc_path_1.rpcPathKey)(path)] ?? path;
|
|
284
285
|
if (!wait) {
|
|
285
286
|
socket.emit(key, [rpc_protocol_1.Pkt.CALL, 0, ref, clean, false]);
|
|
286
287
|
return Promise.resolve();
|
|
@@ -301,7 +302,8 @@ function createClient(socket, key, opts) {
|
|
|
301
302
|
function subscribeShared(path, args) {
|
|
302
303
|
if (disposed)
|
|
303
304
|
return Promise.reject(new Error("RPC client disposed"));
|
|
304
|
-
const
|
|
305
|
+
const listenPathKey = (0, rpc_path_1.rpcPathKey)(path.slice(0, -1));
|
|
306
|
+
const skey = listenPathKey + "::" + JSON.stringify(args.map(listenKeyArg));
|
|
305
307
|
let sub = wireSubs.get(skey);
|
|
306
308
|
if (!sub) {
|
|
307
309
|
const created = { consumers: new Set(), stop: () => { } };
|
|
@@ -353,7 +355,7 @@ function createClient(socket, key, opts) {
|
|
|
353
355
|
const sendCall = (path, args, wait) => {
|
|
354
356
|
const last = path[path.length - 1];
|
|
355
357
|
if (dedupe && wait && path.length > 1 && (last == "callback" || last == "on") && args.some(a => typeof a == "function")) {
|
|
356
|
-
const isListen = declaredListens ? declaredListens.has(path.slice(0, -1)
|
|
358
|
+
const isListen = declaredListens ? declaredListens.has((0, rpc_path_1.rpcPathKey)(path.slice(0, -1))) : true;
|
|
357
359
|
if (isListen)
|
|
358
360
|
return subscribeShared(path, args);
|
|
359
361
|
}
|
|
@@ -3,6 +3,7 @@ export * from "./rpc-off";
|
|
|
3
3
|
export * from "./listen-deep";
|
|
4
4
|
export * from "./rpc-dynamic";
|
|
5
5
|
export * from "./rpc-protocol";
|
|
6
|
+
export * from "./rpc-path";
|
|
6
7
|
export * from "./rpc-caps";
|
|
7
8
|
export * from "./rpc-limits";
|
|
8
9
|
export * from "./rpc-walk";
|
|
@@ -11,5 +12,5 @@ export * from "./rpc-server";
|
|
|
11
12
|
export * from "./rpc-client-auto";
|
|
12
13
|
export * from "./rpc-server-auto";
|
|
13
14
|
export * from "./rpc-clientHub";
|
|
14
|
-
export {
|
|
15
|
+
export { createRpcServerAutoDetect } from "./createRpcServerAutoWithProtocolDetection";
|
|
15
16
|
export * from "./rpc-inproc";
|
|
@@ -14,12 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.createRpcServerAutoDetect = void 0;
|
|
18
18
|
__exportStar(require("./listen-socket"), exports);
|
|
19
19
|
__exportStar(require("./rpc-off"), exports);
|
|
20
20
|
__exportStar(require("./listen-deep"), exports);
|
|
21
21
|
__exportStar(require("./rpc-dynamic"), exports);
|
|
22
22
|
__exportStar(require("./rpc-protocol"), exports);
|
|
23
|
+
__exportStar(require("./rpc-path"), exports);
|
|
23
24
|
__exportStar(require("./rpc-caps"), exports);
|
|
24
25
|
__exportStar(require("./rpc-limits"), exports);
|
|
25
26
|
__exportStar(require("./rpc-walk"), exports);
|
|
@@ -29,5 +30,5 @@ __exportStar(require("./rpc-client-auto"), exports);
|
|
|
29
30
|
__exportStar(require("./rpc-server-auto"), exports);
|
|
30
31
|
__exportStar(require("./rpc-clientHub"), exports);
|
|
31
32
|
var createRpcServerAutoWithProtocolDetection_1 = require("./createRpcServerAutoWithProtocolDetection");
|
|
32
|
-
Object.defineProperty(exports, "
|
|
33
|
+
Object.defineProperty(exports, "createRpcServerAutoDetect", { enumerable: true, get: function () { return createRpcServerAutoWithProtocolDetection_1.createRpcServerAutoDetect; } });
|
|
33
34
|
__exportStar(require("./rpc-inproc"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function rpcPathKey(path: readonly string[]): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createListen } from "../events/Listen";
|
|
2
2
|
import { type PromiseServerHooks, type RpcLimits, type RpcServerAuth, type RpcOpt } from "./rpc-server";
|
|
3
3
|
import { DeepSocketListen } from "./listen-deep";
|
|
4
4
|
import { SocketTmpl } from "./rpc-protocol";
|
|
5
|
-
type ListenCallbackBase<T extends any[] = any[]> = ReturnType<typeof
|
|
5
|
+
type ListenCallbackBase<T extends any[] = any[]> = ReturnType<typeof createListen<T>>;
|
|
6
6
|
export type RpcReplayOpts = {
|
|
7
7
|
pending?: () => number;
|
|
8
8
|
highWater?: number;
|