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,255 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.funcListenCore = funcListenCore;
|
|
8
|
-
exports.funcListenCallbackBase = funcListenCallbackBase;
|
|
9
|
-
exports.funcListenCallbackFast = funcListenCallbackFast;
|
|
10
|
-
exports.UseListen = UseListen;
|
|
11
|
-
exports.withStoreListen = withStoreListen;
|
|
12
|
-
exports.funcListenCallbackStore = funcListenCallbackStore;
|
|
13
|
-
exports.UseListenStore = UseListenStore;
|
|
14
|
-
exports.toListen2 = toListen2;
|
|
15
|
-
exports.UseListen2 = UseListen2;
|
|
16
|
-
exports.isListenCallback = isListenCallback;
|
|
17
|
-
const listenByOn = new WeakMap();
|
|
18
|
-
function getListenByOn(fn) { return typeof fn == 'function' ? listenByOn.get(fn) : undefined; }
|
|
19
|
-
function isListenOn(fn) { return typeof fn == 'function' && listenByOn.has(fn); }
|
|
20
|
-
function registerListenOn(on, api) { listenByOn.set(on, api); }
|
|
21
|
-
function funcListenCore(options = {}) {
|
|
22
|
-
const { fast = true, onRemove, event } = options;
|
|
23
|
-
const subs = new Map();
|
|
24
|
-
let a = (...e) => { subs.forEach(z => z(...e)); };
|
|
25
|
-
let cached = null;
|
|
26
|
-
const getArr = () => cached ?? (cached = Array.from(subs.values()));
|
|
27
|
-
function rebuild() {
|
|
28
|
-
cached = null;
|
|
29
|
-
const size = subs.size;
|
|
30
|
-
if (size == 0) {
|
|
31
|
-
a = null;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (size == 1) {
|
|
35
|
-
a = subs.values().next().value;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (size == 2) {
|
|
39
|
-
const [a0, a1] = getArr();
|
|
40
|
-
a = ((...e) => { a0(...e); a1(...e); });
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
a = ((...e) => {
|
|
44
|
-
const ar = getArr();
|
|
45
|
-
for (let i = 0, len = ar.length; i < len; i++)
|
|
46
|
-
ar[i](...e);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function removeOne(k) {
|
|
50
|
-
if (!subs.has(k))
|
|
51
|
-
return;
|
|
52
|
-
subs.delete(k);
|
|
53
|
-
onRemove?.(k);
|
|
54
|
-
if (fast)
|
|
55
|
-
rebuild();
|
|
56
|
-
event?.('remove', subs.size, api);
|
|
57
|
-
}
|
|
58
|
-
const api = {
|
|
59
|
-
func: ((...e) => { a?.(...e); }),
|
|
60
|
-
has: (k) => subs.has(k),
|
|
61
|
-
on: ((cb, { key } = {}) => {
|
|
62
|
-
const k = key ?? Symbol();
|
|
63
|
-
if (subs.has(k)) {
|
|
64
|
-
subs.delete(k);
|
|
65
|
-
onRemove?.(k);
|
|
66
|
-
}
|
|
67
|
-
subs.set(k, cb);
|
|
68
|
-
if (fast)
|
|
69
|
-
rebuild();
|
|
70
|
-
event?.('add', subs.size, api);
|
|
71
|
-
return function off() { removeOne(k); };
|
|
72
|
-
}),
|
|
73
|
-
off: (k) => {
|
|
74
|
-
if (typeof k == 'function') {
|
|
75
|
-
for (const [kk, cb] of [...subs])
|
|
76
|
-
if (cb === k)
|
|
77
|
-
removeOne(kk);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (k != null)
|
|
81
|
-
removeOne(k);
|
|
82
|
-
},
|
|
83
|
-
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
84
|
-
removeListen: (k) => api.off(k),
|
|
85
|
-
once: (cb, opts = {}) => {
|
|
86
|
-
let off = () => { };
|
|
87
|
-
off = api.on(((...e) => { off(); cb(...e); }), opts);
|
|
88
|
-
return off;
|
|
89
|
-
},
|
|
90
|
-
close: () => {
|
|
91
|
-
subs.clear();
|
|
92
|
-
if (fast)
|
|
93
|
-
rebuild();
|
|
94
|
-
},
|
|
95
|
-
count: () => subs.size,
|
|
96
|
-
get getAllKeys() { return [...subs.keys()]; },
|
|
97
|
-
};
|
|
98
|
-
listenByOn.set(api.on, api);
|
|
99
|
-
return api;
|
|
100
|
-
}
|
|
101
|
-
function funcListenCallbackBase(b, options = {}) {
|
|
102
|
-
const { fast = true, event, addListenClose } = options;
|
|
103
|
-
let closeHooks = null;
|
|
104
|
-
let close = null;
|
|
105
|
-
let closeUnsubscribe = null;
|
|
106
|
-
function forgetKey(k) {
|
|
107
|
-
closeHooks?.delete(k);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
108
7
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
isRun: () => close !== null,
|
|
120
|
-
run: () => {
|
|
121
|
-
close = (b(core.func) ?? (() => { }));
|
|
122
|
-
if (addListenClose && !closeUnsubscribe) {
|
|
123
|
-
closeUnsubscribe = addListenClose.on(function onOwnerClose() { api.close(); });
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
close: () => {
|
|
127
|
-
close?.();
|
|
128
|
-
close = null;
|
|
129
|
-
core.close();
|
|
130
|
-
if (closeHooks) {
|
|
131
|
-
const hooks = closeHooks;
|
|
132
|
-
closeHooks = null;
|
|
133
|
-
hooks.forEach(function fireClose(cb) { cb(); });
|
|
134
|
-
}
|
|
135
|
-
if (closeUnsubscribe) {
|
|
136
|
-
closeUnsubscribe();
|
|
137
|
-
closeUnsubscribe = null;
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
eventClose: (cb) => {
|
|
141
|
-
closeHooks = closeHooks ?? new Map();
|
|
142
|
-
closeHooks.set(cb, cb);
|
|
143
|
-
return function offClose() { closeHooks?.delete(cb); };
|
|
144
|
-
},
|
|
145
|
-
onClose: (cb) => api.eventClose(cb),
|
|
146
|
-
removeEventClose: (cb) => { closeHooks?.delete(cb); },
|
|
147
|
-
on: ((cb, { cbClose, key } = {}) => {
|
|
148
|
-
const k = key ?? Symbol();
|
|
149
|
-
const off = core.on(cb, { key: k });
|
|
150
|
-
if (cbClose) {
|
|
151
|
-
closeHooks = closeHooks ?? new Map();
|
|
152
|
-
closeHooks.set(k, cbClose);
|
|
153
|
-
}
|
|
154
|
-
event?.('add', core.count(), api);
|
|
155
|
-
return off;
|
|
156
|
-
}),
|
|
157
|
-
off: core.off,
|
|
158
|
-
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
159
|
-
removeListen: (k) => api.off(k),
|
|
160
|
-
once: (cb, opts = {}) => {
|
|
161
|
-
let off = () => { };
|
|
162
|
-
off = api.on(((...e) => { off(); cb(...e); }), opts);
|
|
163
|
-
return off;
|
|
164
|
-
},
|
|
165
|
-
count: () => core.count(),
|
|
166
|
-
get getAllKeys() { return core.getAllKeys; },
|
|
167
|
-
};
|
|
168
|
-
listenByOn.set(api.on, api);
|
|
169
|
-
return api;
|
|
170
|
-
}
|
|
171
|
-
function funcListenCallbackFast(a) {
|
|
172
|
-
return funcListenCallbackBase(a, { fast: true });
|
|
173
|
-
}
|
|
174
|
-
exports.funcListenCallback = funcListenCallbackBase;
|
|
175
|
-
function UseListen(data = { fast: true }) {
|
|
176
|
-
let t;
|
|
177
|
-
const a = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...data });
|
|
178
|
-
a.run();
|
|
179
|
-
t = a.func;
|
|
180
|
-
return [t, a];
|
|
181
|
-
}
|
|
182
|
-
function withStoreListen(base, currentProvider) {
|
|
183
|
-
function currentValue(current) {
|
|
184
|
-
if (typeof current == 'function')
|
|
185
|
-
return current();
|
|
186
|
-
return current ? currentProvider() : undefined;
|
|
187
|
-
}
|
|
188
|
-
const api = {
|
|
189
|
-
...base,
|
|
190
|
-
on: ((cb, { cbClose, key, current } = {}) => {
|
|
191
|
-
const off = base.on(cb, { cbClose, key });
|
|
192
|
-
if (current) {
|
|
193
|
-
const m = currentValue(current);
|
|
194
|
-
if (m)
|
|
195
|
-
cb(...m);
|
|
196
|
-
}
|
|
197
|
-
return off;
|
|
198
|
-
}),
|
|
199
|
-
addListen: (cb, opts = {}) => api.on(cb, opts),
|
|
200
|
-
removeListen: (k) => api.off(k),
|
|
201
|
-
once: (cb, opts = {}) => {
|
|
202
|
-
if (opts.current) {
|
|
203
|
-
const m = currentValue(opts.current);
|
|
204
|
-
if (m) {
|
|
205
|
-
cb(...m);
|
|
206
|
-
return () => { };
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
let off = () => { };
|
|
210
|
-
off = base.on(((...e) => { off(); cb(...e); }), { key: opts.key });
|
|
211
|
-
return off;
|
|
212
|
-
},
|
|
213
|
-
get getAllKeys() { return base.getAllKeys; },
|
|
214
|
-
};
|
|
215
|
-
listenByOn.set(api.on, api);
|
|
216
|
-
return api;
|
|
217
|
-
}
|
|
218
|
-
function funcListenCallbackStore(b, options) {
|
|
219
|
-
const { current, ...listenOptions } = options;
|
|
220
|
-
return withStoreListen(funcListenCallbackBase(b, listenOptions), current);
|
|
221
|
-
}
|
|
222
|
-
function UseListenStore(data) {
|
|
223
|
-
const { current, ...listenOptions } = data;
|
|
224
|
-
let t;
|
|
225
|
-
const base = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...listenOptions });
|
|
226
|
-
const listen = withStoreListen(base, current);
|
|
227
|
-
base.run();
|
|
228
|
-
t = base.func;
|
|
229
|
-
return [t, listen];
|
|
230
|
-
}
|
|
231
|
-
function toListen2(full) {
|
|
232
|
-
return {
|
|
233
|
-
on: (cb, opts) => full.on(cb, opts),
|
|
234
|
-
off: (k) => full.off(k),
|
|
235
|
-
close: () => full.close(),
|
|
236
|
-
count: () => full.count(),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
function UseListen2(data = { fast: true }) {
|
|
240
|
-
const [emit, full] = UseListen(data);
|
|
241
|
-
return [emit, toListen2(full)];
|
|
242
|
-
}
|
|
243
|
-
const LISTEN_CORE = ['func', 'addListen', 'removeListen', 'eventClose', 'removeEventClose'];
|
|
244
|
-
function isListenCallback(obj) {
|
|
245
|
-
if (obj == null || typeof obj != 'object')
|
|
246
|
-
return false;
|
|
247
|
-
const ks = new Set(Object.keys(obj));
|
|
248
|
-
for (const k of LISTEN_CORE)
|
|
249
|
-
if (!ks.has(k))
|
|
250
|
-
return false;
|
|
251
|
-
for (const k of LISTEN_CORE)
|
|
252
|
-
if (typeof obj[k] != 'function')
|
|
253
|
-
return false;
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Listen"), exports);
|
|
@@ -1,53 +1,33 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type SocketSource<T extends any> = (data: {
|
|
2
2
|
callback: (data: T) => void;
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}, ...b: any[]) => (any | (() => any));
|
|
5
|
-
export type
|
|
5
|
+
export type SocketPayload<T extends SocketSource<any>> = T extends SocketSource<infer R> ? R : never;
|
|
6
6
|
type ParametersOther<T extends (forget: any, ...args: any) => any> = T extends (forget: any, ...args: infer P) => any ? P : never;
|
|
7
|
-
type
|
|
8
|
-
export declare function
|
|
7
|
+
type NonUndefined<T> = T extends undefined ? never : T;
|
|
8
|
+
export declare function socketBuffer<T extends SocketSource<any | any[]>, T2 extends (readonly unknown[]) | undefined, T3 extends {
|
|
9
9
|
[key: string]: unknown;
|
|
10
|
-
}, T4 extends T3 | (() => T3)>(func: T, callbackMain: (data:
|
|
11
|
-
callback: (...data:
|
|
10
|
+
}, T4 extends T3 | (() => T3)>(func: T, callbackMain: (data: SocketPayload<T>, memo: T3 | T4) => T2, memo?: T3 | T4): (a: Omit<Parameters<T>[0], "callback"> & {
|
|
11
|
+
callback: (...data: NonUndefined<T2>) => any;
|
|
12
12
|
}, ...b: ParametersOther<T>) => ReturnType<T>;
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function listenSnapshot<T extends SocketSource<any | any[]>, T2 extends (readonly unknown[]) | undefined, T3 extends {
|
|
14
14
|
[key: string]: unknown;
|
|
15
15
|
}, T4 extends T3 | (() => T3)>({ func, memo, callbackSave, snapshot }: {
|
|
16
16
|
func: () => T;
|
|
17
|
-
callbackSave: (data:
|
|
17
|
+
callbackSave: (data: SocketPayload<T>, memo: T3) => T2;
|
|
18
18
|
memo: T4;
|
|
19
19
|
snapshot?: (memo: T4) => T3;
|
|
20
20
|
}): {
|
|
21
|
-
run: (cb: import("./
|
|
21
|
+
run: (cb: import("./Listen").Listener<[data: SocketPayload<T>, memo: T3]>, opts?: {
|
|
22
22
|
cbClose?: () => void;
|
|
23
|
-
key?:
|
|
24
|
-
} | undefined) => ()
|
|
23
|
+
key?: import("./Listen").ListenKey;
|
|
24
|
+
} | undefined) => import("./Listen").ListenOff;
|
|
25
25
|
snapshot: () => T3 | undefined;
|
|
26
26
|
memo: T4;
|
|
27
|
-
listenA:
|
|
28
|
-
func: import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]>;
|
|
29
|
-
isRun: () => boolean;
|
|
30
|
-
run: () => void;
|
|
31
|
-
close: () => void;
|
|
32
|
-
eventClose: (cb: () => void) => () => void;
|
|
33
|
-
onClose: (cb: () => void) => () => void;
|
|
34
|
-
removeEventClose: (cb: () => void) => void;
|
|
35
|
-
on: import("./Listen3").ListenOn<[data: getTypeCallback<T>, memo: T3]>;
|
|
36
|
-
off: (k: (string | symbol) | import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
|
|
37
|
-
addListen: (cb: import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]>, opts?: {
|
|
38
|
-
cbClose?: () => void;
|
|
39
|
-
key?: string | symbol;
|
|
40
|
-
}) => () => void;
|
|
41
|
-
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
|
|
42
|
-
once: (cb: import("./Listen3").Listener<[data: getTypeCallback<T>, memo: T3]>, opts?: {
|
|
43
|
-
key?: string | symbol;
|
|
44
|
-
}) => () => void;
|
|
45
|
-
count: () => number;
|
|
46
|
-
readonly getAllKeys: (string | symbol)[];
|
|
47
|
-
};
|
|
27
|
+
listenA: import("./Listen").ListenApi<[data: SocketPayload<T>, memo: T3]>;
|
|
48
28
|
connect: () => void;
|
|
49
29
|
readonly disconnect: ((a: Omit<Parameters<T>[0], "callback"> & {
|
|
50
|
-
callback: (...data:
|
|
30
|
+
callback: (...data: NonUndefined<T2>) => any;
|
|
51
31
|
}, ...b: ParametersOther<T>) => ReturnType<T>) | null;
|
|
52
32
|
};
|
|
53
33
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.socketBuffer = socketBuffer;
|
|
4
|
+
exports.listenSnapshot = listenSnapshot;
|
|
5
5
|
const Listen_1 = require("./Listen");
|
|
6
|
-
function
|
|
6
|
+
function socketBuffer(func, callbackMain, memo = {}) {
|
|
7
7
|
return (a, ...b) => func({
|
|
8
8
|
...a, callback: (v) => {
|
|
9
9
|
const z = callbackMain(v, memo);
|
|
@@ -12,9 +12,9 @@ function socketBuffer3(func, callbackMain, memo = {}) {
|
|
|
12
12
|
}
|
|
13
13
|
}, ...b);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function listenSnapshot({ func, memo = {}, callbackSave, snapshot }) {
|
|
16
16
|
let d = null;
|
|
17
|
-
const [callback, listenA] = (0, Listen_1.
|
|
17
|
+
const [callback, listenA] = (0, Listen_1.listen)({
|
|
18
18
|
event: (type, count, api) => {
|
|
19
19
|
if (type == "remove" && count == 0) {
|
|
20
20
|
api.close();
|
|
@@ -27,14 +27,14 @@ function funcListenCallbackSnapshot({ func, memo = {}, callbackSave, snapshot })
|
|
|
27
27
|
});
|
|
28
28
|
const connect = () => {
|
|
29
29
|
if (d == null)
|
|
30
|
-
d =
|
|
30
|
+
d = socketBuffer(func(), callbackSave, memo)({ callback });
|
|
31
31
|
};
|
|
32
32
|
const run = (...params) => {
|
|
33
|
-
if (!listenA.
|
|
33
|
+
if (!listenA.isRunning()) {
|
|
34
34
|
snapshot?.(memo);
|
|
35
35
|
connect();
|
|
36
36
|
}
|
|
37
|
-
return listenA.
|
|
37
|
+
return listenA.on(...params);
|
|
38
38
|
};
|
|
39
39
|
return {
|
|
40
40
|
run, snapshot: () => snapshot?.(memo), memo, listenA, connect, get disconnect() {
|
|
@@ -4,58 +4,18 @@ export declare function SocketServerHook(opt?: {
|
|
|
4
4
|
transformer?: transformer;
|
|
5
5
|
}): {
|
|
6
6
|
obj: {
|
|
7
|
-
[k: string]: readonly [(
|
|
8
|
-
func: import("./Listen3").Listener<[unknown]>;
|
|
9
|
-
isRun: () => boolean;
|
|
10
|
-
run: () => void;
|
|
11
|
-
close: () => void;
|
|
12
|
-
eventClose: (cb: () => void) => () => void;
|
|
13
|
-
onClose: (cb: () => void) => () => void;
|
|
14
|
-
removeEventClose: (cb: () => void) => void;
|
|
15
|
-
on: import("./Listen3").ListenOn<[unknown]>;
|
|
16
|
-
off: (k: (string | symbol) | import("./Listen3").Listener<[unknown]> | null) => void;
|
|
17
|
-
addListen: (cb: import("./Listen3").Listener<[unknown]>, opts?: {
|
|
18
|
-
cbClose?: () => void;
|
|
19
|
-
key?: string | symbol;
|
|
20
|
-
}) => () => void;
|
|
21
|
-
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[unknown]> | null) => void;
|
|
22
|
-
once: (cb: import("./Listen3").Listener<[unknown]>, opts?: {
|
|
23
|
-
key?: string | symbol;
|
|
24
|
-
}) => () => void;
|
|
25
|
-
count: () => number;
|
|
26
|
-
readonly getAllKeys: (string | symbol)[];
|
|
27
|
-
}];
|
|
7
|
+
[k: string]: readonly [import("./Listen").Listener<[unknown]>, import("./Listen").ListenApi<unknown>];
|
|
28
8
|
};
|
|
29
|
-
get(tag: string): readonly [(
|
|
30
|
-
func: import("./Listen3").Listener<[unknown]>;
|
|
31
|
-
isRun: () => boolean;
|
|
32
|
-
run: () => void;
|
|
33
|
-
close: () => void;
|
|
34
|
-
eventClose: (cb: () => void) => () => void;
|
|
35
|
-
onClose: (cb: () => void) => () => void;
|
|
36
|
-
removeEventClose: (cb: () => void) => void;
|
|
37
|
-
on: import("./Listen3").ListenOn<[unknown]>;
|
|
38
|
-
off: (k: (string | symbol) | import("./Listen3").Listener<[unknown]> | null) => void;
|
|
39
|
-
addListen: (cb: import("./Listen3").Listener<[unknown]>, opts?: {
|
|
40
|
-
cbClose?: () => void;
|
|
41
|
-
key?: string | symbol;
|
|
42
|
-
}) => () => void;
|
|
43
|
-
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[unknown]> | null) => void;
|
|
44
|
-
once: (cb: import("./Listen3").Listener<[unknown]>, opts?: {
|
|
45
|
-
key?: string | symbol;
|
|
46
|
-
}) => () => void;
|
|
47
|
-
count: () => number;
|
|
48
|
-
readonly getAllKeys: (string | symbol)[];
|
|
49
|
-
}];
|
|
9
|
+
get(tag: string): readonly [import("./Listen").Listener<[unknown]>, import("./Listen").ListenApi<unknown>];
|
|
50
10
|
provider: (tag: string, data: any) => void;
|
|
51
11
|
};
|
|
52
12
|
export declare function WebSocketServerHook(s: ReturnType<typeof SocketServerHook>, paramsSoc?: Parameters<typeof soc>[1], disconnect?: () => any): {
|
|
53
13
|
disconnect(): void;
|
|
54
14
|
get: {
|
|
55
15
|
[k: string]: {
|
|
56
|
-
callback: (z: (...args: any[]) => void) => import("../rcp/listen-socket").
|
|
57
|
-
on: (z: (...args: any[]) => void) => import("../rcp/listen-socket").
|
|
58
|
-
once: (z: (...args: any[]) => void) => import("../rcp/listen-socket").
|
|
16
|
+
callback: (z: (...args: any[]) => void) => import("../rcp/listen-socket").SubscriptionHandle;
|
|
17
|
+
on: (z: (...args: any[]) => void) => import("../rcp/listen-socket").SubscriptionHandle;
|
|
18
|
+
once: (z: (...args: any[]) => void) => import("../rcp/listen-socket").SubscriptionHandle;
|
|
59
19
|
close: () => void;
|
|
60
20
|
off: () => boolean;
|
|
61
21
|
removeCallback: () => boolean;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type
|
|
1
|
+
import { listen as createListenPair } from "./Listen";
|
|
2
|
+
export type ListenPair<T extends any[] = any[]> = ReturnType<typeof createListenPair<T>>;
|
|
3
3
|
type KeyExtractor<D> = (data: D) => string | undefined;
|
|
4
4
|
export type ListenMap<T extends Record<string, any>> = {
|
|
5
|
-
[K in keyof T]:
|
|
5
|
+
[K in keyof T]: ListenPair<T[K]>[1];
|
|
6
6
|
};
|
|
7
7
|
type CollectedResult<T extends Record<string, any>> = {
|
|
8
8
|
[K in keyof T]: T[K];
|
|
9
9
|
};
|
|
10
10
|
type JoinResult<R> = {
|
|
11
|
-
listen:
|
|
11
|
+
listen: ListenPair<[R, string]>[1];
|
|
12
12
|
pending: Map<string, Map<string, any>>;
|
|
13
13
|
clear: (tid?: string) => void;
|
|
14
14
|
destroy: () => void;
|
|
15
|
-
add: (port:
|
|
16
|
-
addListen: (listener: listen<any>[1], key?: string) => void;
|
|
15
|
+
add: (port: ListenPair<any>[1], key?: string) => void;
|
|
17
16
|
};
|
|
18
17
|
export declare function joinListens<T extends Record<string, any[]>>(listens: ListenMap<T>, keyExtractor?: KeyExtractor<any>): JoinResult<CollectedResult<T>>;
|
|
19
|
-
export declare function joinListens<D extends any[] = any[]>(listens:
|
|
18
|
+
export declare function joinListens<D extends any[] = any[]>(listens: ListenPair<D>[1][], keyExtractor?: KeyExtractor<any>): JoinResult<D[][]>;
|
|
20
19
|
export {};
|
|
@@ -7,7 +7,7 @@ function joinListens(listens, keyExtractor) {
|
|
|
7
7
|
const map = isArray
|
|
8
8
|
? Object.fromEntries(listens.map((l, i) => [String(i), l]))
|
|
9
9
|
: listens;
|
|
10
|
-
const [set, out] = (0, Listen_1.
|
|
10
|
+
const [set, out] = (0, Listen_1.listen)();
|
|
11
11
|
const keys = Object.keys(map);
|
|
12
12
|
const buckets = new Map();
|
|
13
13
|
const getKey = (data) => keyExtractor?.(data) ?? "_";
|
|
@@ -30,7 +30,7 @@ function joinListens(listens, keyExtractor) {
|
|
|
30
30
|
buckets.get(tid).set(portId, data.length <= 1 ? data[0] : data);
|
|
31
31
|
tryFire(tid);
|
|
32
32
|
};
|
|
33
|
-
unsubs.push(listener.
|
|
33
|
+
unsubs.push(listener.on(cb));
|
|
34
34
|
};
|
|
35
35
|
for (const portId of keys) {
|
|
36
36
|
bindPort(portId, map[portId]);
|
|
@@ -55,7 +55,6 @@ function joinListens(listens, keyExtractor) {
|
|
|
55
55
|
unsubs.length = 0;
|
|
56
56
|
buckets.clear();
|
|
57
57
|
},
|
|
58
|
-
add
|
|
59
|
-
addListen: (listener, key) => add(listener, key)
|
|
58
|
+
add
|
|
60
59
|
};
|
|
61
60
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Listener, NormalizeTuple, ListenApi } from "./Listen";
|
|
2
|
+
export declare function mapListen<TSource extends any[], TTarget extends any[]>(sourceListen: ListenApi<TSource>, transform: (...args: NormalizeTuple<TSource>) => TTarget | null, options?: {
|
|
3
|
+
closeOn?: ListenApi<any>;
|
|
4
|
+
}): readonly [Listener<NormalizeTuple<TTarget>>, ListenApi<TTarget>];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapListen = mapListen;
|
|
4
|
+
const Listen_1 = require("./Listen");
|
|
5
|
+
function mapListen(sourceListen, transform, options) {
|
|
6
|
+
let unsubscribeFromSource = null;
|
|
7
|
+
const [emit, targetListen] = (0, Listen_1.listen)({
|
|
8
|
+
event: (type, count) => {
|
|
9
|
+
if (type == "add" && count == 1) {
|
|
10
|
+
const sourceCallback = (...args) => {
|
|
11
|
+
const result = transform(...args);
|
|
12
|
+
if (result !== null)
|
|
13
|
+
emit(...result);
|
|
14
|
+
};
|
|
15
|
+
unsubscribeFromSource = sourceListen.on(sourceCallback);
|
|
16
|
+
}
|
|
17
|
+
if (type == "remove" && count == 0 && unsubscribeFromSource) {
|
|
18
|
+
unsubscribeFromSource();
|
|
19
|
+
unsubscribeFromSource = null;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
closeOn: options?.closeOn,
|
|
23
|
+
});
|
|
24
|
+
return [emit, targetListen];
|
|
25
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NormalizeTuple } from './
|
|
1
|
+
import { NormalizeTuple } from './Listen';
|
|
2
2
|
import { ListenReplayApi, ReplayEvent } from './replay-listen';
|
|
3
3
|
export type ConflateOpts<Z extends any[] = any[]> = {
|
|
4
4
|
pending: () => number;
|
|
@@ -10,27 +10,7 @@ export type ConflateOpts<Z extends any[] = any[]> = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function conflateReplay<T>(replay: ListenReplayApi<T>, opts: ConflateOpts<NormalizeTuple<T>>): {
|
|
12
12
|
api: {
|
|
13
|
-
line:
|
|
14
|
-
func: import("./Listen3").Listener<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
15
|
-
isRun: () => boolean;
|
|
16
|
-
run: () => void;
|
|
17
|
-
close: () => void;
|
|
18
|
-
eventClose: (cb: () => void) => () => void;
|
|
19
|
-
onClose: (cb: () => void) => () => void;
|
|
20
|
-
removeEventClose: (cb: () => void) => void;
|
|
21
|
-
on: import("./Listen3").ListenOn<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
22
|
-
off: (k: (string | symbol) | import("./Listen3").Listener<[ReplayEvent<NormalizeTuple<T>>]> | null) => void;
|
|
23
|
-
addListen: (cb: import("./Listen3").Listener<[ReplayEvent<NormalizeTuple<T>>]>, opts?: {
|
|
24
|
-
cbClose?: () => void;
|
|
25
|
-
key?: string | symbol;
|
|
26
|
-
}) => () => void;
|
|
27
|
-
removeListen: (k: (string | symbol) | import("./Listen3").Listener<[ReplayEvent<NormalizeTuple<T>>]> | null) => void;
|
|
28
|
-
once: (cb: import("./Listen3").Listener<[ReplayEvent<NormalizeTuple<T>>]>, opts?: {
|
|
29
|
-
key?: string | symbol;
|
|
30
|
-
}) => () => void;
|
|
31
|
-
count: () => number;
|
|
32
|
-
readonly getAllKeys: (string | symbol)[];
|
|
33
|
-
};
|
|
13
|
+
line: import("./Listen").ListenApi<[ReplayEvent<NormalizeTuple<T>>]>;
|
|
34
14
|
since: (seq: number) => ReplayEvent<NormalizeTuple<T>>[] | null;
|
|
35
15
|
keyframe: () => ReplayEvent<NormalizeTuple<T>> | null;
|
|
36
16
|
frame: (seq: number, hint?: unknown) => ReplayEvent<NormalizeTuple<T>>[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.conflateReplay = conflateReplay;
|
|
4
|
-
const
|
|
4
|
+
const Listen_1 = require("./Listen");
|
|
5
5
|
function conflateReplay(replay, opts) {
|
|
6
6
|
const { pending, highWater, lowWater = 0, pollMs = 25, keyOf, maxKeys = 1024 } = opts;
|
|
7
7
|
if (!replay.hasKeyframe)
|
|
8
8
|
throw new TypeError('conflateReplay: нужен current-провайдер (keyframe recovery)');
|
|
9
|
-
const gate = (0,
|
|
9
|
+
const gate = (0, Listen_1.createListen)(() => { });
|
|
10
10
|
gate.run();
|
|
11
11
|
let conflating = false;
|
|
12
12
|
let closed = false;
|
|
@@ -40,13 +40,13 @@ function conflateReplay(replay, opts) {
|
|
|
40
40
|
held = null;
|
|
41
41
|
flushes++;
|
|
42
42
|
for (const ev of tail)
|
|
43
|
-
gate.
|
|
43
|
+
gate.emit(ev);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const kf = replay.keyframe();
|
|
47
47
|
if (kf) {
|
|
48
48
|
keyframes++;
|
|
49
|
-
gate.
|
|
49
|
+
gate.emit(kf);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function absorb(ev) {
|
|
@@ -79,7 +79,7 @@ function conflateReplay(replay, opts) {
|
|
|
79
79
|
dropped++;
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
gate.
|
|
82
|
+
gate.emit(ev);
|
|
83
83
|
});
|
|
84
84
|
function close() {
|
|
85
85
|
if (closed)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Listener, NormalizeTuple } from './
|
|
1
|
+
import { Listener, NormalizeTuple } from './Listen';
|
|
2
2
|
import { ListenOnReplay, ListenReplayApi, ReplayEvent } from './replay-listen';
|
|
3
3
|
export type ReplayStorage<Z extends any[] = any[]> = {
|
|
4
4
|
putEvent: (ev: ReplayEvent<Z>) => void;
|