wenay-common2 1.0.61 → 1.0.62
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/{ObserveAll2 → Observe}/index.d.ts +1 -0
- package/lib/Common/{ObserveAll2 → Observe}/index.js +1 -0
- package/lib/Common/Observe/reactive2.d.ts +21 -0
- package/lib/Common/{ObserveAll2 → Observe}/reactive2.js +6 -6
- 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 +2 -2
- package/lib/Common/{ObserveAll2 → Observe}/store.js +12 -18
- package/lib/Common/async/promiseProgress.d.ts +12 -0
- package/lib/Common/async/promiseProgress.js +29 -0
- package/lib/Common/events/Listen3.d.ts +81 -162
- package/lib/Common/events/Listen3.js +95 -105
- 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 +1 -21
- package/lib/Common/events/replay-conflate.js +4 -4
- package/lib/Common/events/replay-listen.d.ts +19 -65
- package/lib/Common/events/replay-listen.js +8 -11
- 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 +2 -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/Listen2.js +0 -17
- 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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function promiseProgress<T extends any = unknown>(array: ((() => Promise<T>) | (() => any) | Promise<T>)[]): {
|
|
2
|
+
onOk: (cb: (...data: [data: T, i: number, countOk: number, countError: number, count: number]) => any) => import("../events/Listen3").ListenOff;
|
|
3
|
+
onError: (cb: (...data: [error: any, i: number, countOk: number, countError: number, count: number]) => any) => import("../events/Listen3").ListenOff;
|
|
4
|
+
all: () => Promise<any[]>;
|
|
5
|
+
allSettled: () => Promise<PromiseSettledResult<any>[]>;
|
|
6
|
+
items: () => Promise<any>[];
|
|
7
|
+
stats: () => {
|
|
8
|
+
ok: number;
|
|
9
|
+
error: number;
|
|
10
|
+
count: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiseProgress = promiseProgress;
|
|
4
|
+
const Listen_1 = require("../events/Listen");
|
|
5
|
+
function promiseProgress(array) {
|
|
6
|
+
let ok = 0, errorCount = 0;
|
|
7
|
+
const count = array.length;
|
|
8
|
+
const okEvents = (0, Listen_1.listen)();
|
|
9
|
+
const errorEvents = (0, Listen_1.listen)();
|
|
10
|
+
const emitOk = (data, i) => {
|
|
11
|
+
++ok;
|
|
12
|
+
okEvents[0](data, i, ok, errorCount, count);
|
|
13
|
+
};
|
|
14
|
+
const emitError = (error, i) => {
|
|
15
|
+
++errorCount;
|
|
16
|
+
errorEvents[0](error, i, ok, errorCount, count);
|
|
17
|
+
};
|
|
18
|
+
const wrap = (promise, i) => promise.then(r => { emitOk(r, i); return r; }).catch((er) => { emitError(er, i); throw er; });
|
|
19
|
+
const arr = array.map((e, i) => e instanceof Promise ? wrap(e, i) : () => wrap((async () => e())(), i));
|
|
20
|
+
const started = [];
|
|
21
|
+
const startAll = () => arr.map((x, i) => started[i] ??= (typeof x === "function" ? x() : x));
|
|
22
|
+
const onOk = (cb) => okEvents[1].on(cb);
|
|
23
|
+
const onError = (cb) => errorEvents[1].on(cb);
|
|
24
|
+
const all = () => Promise.all(startAll());
|
|
25
|
+
const allSettled = () => Promise.allSettled(startAll());
|
|
26
|
+
const items = () => startAll();
|
|
27
|
+
const stats = () => ({ ok, error: errorCount, count });
|
|
28
|
+
return { onOk, onError, all, allSettled, items, stats };
|
|
29
|
+
}
|
|
@@ -1,208 +1,127 @@
|
|
|
1
|
-
export type Listener<T extends any[]> = (...
|
|
1
|
+
export type Listener<T extends any[]> = (...args: T) => void;
|
|
2
2
|
export type NormalizeTuple<T> = T extends any[] ? T : [T];
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
export type ListenKey = string | symbol;
|
|
4
|
+
export type ListenOff = () => void;
|
|
5
|
+
type CloseCallback = () => void;
|
|
5
6
|
declare const LISTEN_ON_BRAND: unique symbol;
|
|
6
7
|
export type ListenOn<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: {
|
|
7
|
-
cbClose?:
|
|
8
|
-
key?:
|
|
9
|
-
}) =>
|
|
8
|
+
cbClose?: CloseCallback;
|
|
9
|
+
key?: ListenKey;
|
|
10
|
+
}) => ListenOff) & {
|
|
10
11
|
readonly [LISTEN_ON_BRAND]: Z;
|
|
11
12
|
};
|
|
12
13
|
export type ListenOnCurrent<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: {
|
|
13
|
-
cbClose?:
|
|
14
|
-
key?:
|
|
14
|
+
cbClose?: CloseCallback;
|
|
15
|
+
key?: ListenKey;
|
|
15
16
|
current?: ListenCurrent<Z>;
|
|
16
|
-
}) =>
|
|
17
|
+
}) => ListenOff) & {
|
|
17
18
|
readonly [LISTEN_ON_BRAND]: Z;
|
|
18
19
|
};
|
|
19
20
|
export type ListenCurrentProvider<Z extends any[]> = () => Z | undefined;
|
|
20
21
|
export type ListenCurrent<Z extends any[]> = boolean | ListenCurrentProvider<Z>;
|
|
22
|
+
export type ListenCoreApi<T = any> = {
|
|
23
|
+
emit: Listener<NormalizeTuple<T>>;
|
|
24
|
+
has(key: ListenKey): boolean;
|
|
25
|
+
on: ListenOn<NormalizeTuple<T>>;
|
|
26
|
+
off(keyOrCallback: Listener<NormalizeTuple<T>> | null | ListenKey): void;
|
|
27
|
+
once(cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
28
|
+
key?: ListenKey;
|
|
29
|
+
}): ListenOff;
|
|
30
|
+
close(): void;
|
|
31
|
+
count(): number;
|
|
32
|
+
keys(): ListenKey[];
|
|
33
|
+
};
|
|
34
|
+
export type ListenApi<T = any> = ListenCoreApi<T> & {
|
|
35
|
+
isRunning(): boolean;
|
|
36
|
+
run(): void;
|
|
37
|
+
onClose(cb: CloseCallback): ListenOff;
|
|
38
|
+
};
|
|
21
39
|
export type ListenCoreOptions<T = any> = {
|
|
22
40
|
fast?: boolean;
|
|
23
|
-
onRemove?: (
|
|
41
|
+
onRemove?: (key: ListenKey) => void;
|
|
24
42
|
event?: (type: 'add' | 'remove', count: number, api: ListenCoreApi<T>) => void;
|
|
25
43
|
};
|
|
26
|
-
export type ListenOptions<T> = {
|
|
44
|
+
export type ListenOptions<T = any> = {
|
|
27
45
|
event?: (type: 'add' | 'remove', count: number, api: ListenApi<T>) => void;
|
|
28
46
|
fast?: boolean;
|
|
29
|
-
|
|
47
|
+
closeOn?: ListenApi<any>;
|
|
30
48
|
};
|
|
31
49
|
export type ListenStoreOptions<T> = ListenOptions<T> & {
|
|
32
50
|
current: ListenCurrentProvider<NormalizeTuple<T>>;
|
|
33
51
|
};
|
|
34
|
-
export declare function getListenByOn(fn: any): any;
|
|
35
|
-
export declare function isListenOn(fn: any): boolean;
|
|
36
|
-
export declare function registerListenOn(on: Function, api: any): void;
|
|
37
52
|
export type ListenOnBrand<Z extends any[] = any[]> = {
|
|
38
53
|
readonly [LISTEN_ON_BRAND]: Z;
|
|
39
54
|
};
|
|
40
|
-
export declare function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}) => () => void;
|
|
48
|
-
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
49
|
-
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
50
|
-
key?: key;
|
|
51
|
-
}) => () => void;
|
|
52
|
-
close: () => void;
|
|
53
|
-
count: () => number;
|
|
54
|
-
readonly getAllKeys: key[];
|
|
55
|
-
};
|
|
56
|
-
export type ListenCoreApi<T = any> = ReturnType<typeof funcListenCore<T>>;
|
|
57
|
-
export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), options?: ListenOptions<T>): {
|
|
58
|
-
func: Listener<NormalizeTuple<T>>;
|
|
59
|
-
isRun: () => boolean;
|
|
60
|
-
run: () => void;
|
|
61
|
-
close: () => void;
|
|
62
|
-
eventClose: (cb: cbClose) => () => void;
|
|
63
|
-
onClose: (cb: cbClose) => () => void;
|
|
64
|
-
removeEventClose: (cb: cbClose) => void;
|
|
65
|
-
on: ListenOn<NormalizeTuple<T>>;
|
|
66
|
-
off: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
67
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
68
|
-
cbClose?: cbClose;
|
|
69
|
-
key?: key;
|
|
70
|
-
}) => () => void;
|
|
71
|
-
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
72
|
-
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
73
|
-
key?: key;
|
|
74
|
-
}) => () => void;
|
|
75
|
-
count: () => number;
|
|
76
|
-
readonly getAllKeys: key[];
|
|
77
|
-
};
|
|
78
|
-
export type ListenApi<T = any> = ReturnType<typeof funcListenCallbackBase<T>>;
|
|
79
|
-
export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void))): {
|
|
80
|
-
func: Listener<NormalizeTuple<T>>;
|
|
81
|
-
isRun: () => boolean;
|
|
82
|
-
run: () => void;
|
|
83
|
-
close: () => void;
|
|
84
|
-
eventClose: (cb: cbClose) => () => void;
|
|
85
|
-
onClose: (cb: cbClose) => () => void;
|
|
86
|
-
removeEventClose: (cb: cbClose) => void;
|
|
87
|
-
on: ListenOn<NormalizeTuple<T>>;
|
|
88
|
-
off: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
89
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
90
|
-
cbClose?: cbClose;
|
|
91
|
-
key?: key;
|
|
92
|
-
}) => () => void;
|
|
93
|
-
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
94
|
-
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
95
|
-
key?: key;
|
|
96
|
-
}) => () => void;
|
|
97
|
-
count: () => number;
|
|
98
|
-
readonly getAllKeys: key[];
|
|
99
|
-
};
|
|
100
|
-
export declare const funcListenCallback: typeof funcListenCallbackBase;
|
|
101
|
-
export declare function UseListen<T>(data?: ListenOptions<T>): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
102
|
-
func: Listener<NormalizeTuple<T>>;
|
|
103
|
-
isRun: () => boolean;
|
|
104
|
-
run: () => void;
|
|
105
|
-
close: () => void;
|
|
106
|
-
eventClose: (cb: cbClose) => () => void;
|
|
107
|
-
onClose: (cb: cbClose) => () => void;
|
|
108
|
-
removeEventClose: (cb: cbClose) => void;
|
|
109
|
-
on: ListenOn<NormalizeTuple<T>>;
|
|
110
|
-
off: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
111
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
112
|
-
cbClose?: cbClose;
|
|
113
|
-
key?: key;
|
|
114
|
-
}) => () => void;
|
|
115
|
-
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
116
|
-
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
117
|
-
key?: key;
|
|
118
|
-
}) => () => void;
|
|
119
|
-
count: () => number;
|
|
120
|
-
readonly getAllKeys: key[];
|
|
121
|
-
}];
|
|
55
|
+
export declare function getListenByOn(fn: any): any;
|
|
56
|
+
export declare function isListenOn(fn: any): boolean;
|
|
57
|
+
export declare function registerListenOn(on: Function, api: any): void;
|
|
58
|
+
export declare function createListenCore<T>(options?: ListenCoreOptions<T>): ListenCoreApi<T>;
|
|
59
|
+
export declare function createListen<T>(producer: (emit: Listener<NormalizeTuple<T>>) => (void | ListenOff), options?: ListenOptions<T>): ListenApi<T>;
|
|
60
|
+
export declare function createFastListen<T>(producer: (emit: Listener<NormalizeTuple<T>>) => (void | ListenOff)): ListenApi<T>;
|
|
61
|
+
export declare function listen<T>(options?: ListenOptions<T>): readonly [Listener<NormalizeTuple<T>>, ListenApi<T>];
|
|
122
62
|
export declare function withStoreListen<T>(base: ListenApi<T>, currentProvider: ListenCurrentProvider<NormalizeTuple<T>>): {
|
|
123
63
|
on: ListenOnCurrent<NormalizeTuple<T>>;
|
|
124
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
125
|
-
cbClose?: cbClose;
|
|
126
|
-
key?: key;
|
|
127
|
-
current?: ListenCurrent<NormalizeTuple<T>>;
|
|
128
|
-
}) => () => void;
|
|
129
|
-
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
130
64
|
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
131
|
-
key?:
|
|
65
|
+
key?: ListenKey;
|
|
132
66
|
current?: ListenCurrent<NormalizeTuple<T>>;
|
|
133
|
-
}) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
count: () => number;
|
|
67
|
+
}) => ListenOff;
|
|
68
|
+
emit: Listener<NormalizeTuple<T>>;
|
|
69
|
+
has(key: ListenKey): boolean;
|
|
70
|
+
off(keyOrCallback: ListenKey | Listener<NormalizeTuple<T>> | null): void;
|
|
71
|
+
close(): void;
|
|
72
|
+
count(): number;
|
|
73
|
+
keys(): ListenKey[];
|
|
74
|
+
isRunning(): boolean;
|
|
75
|
+
run(): void;
|
|
76
|
+
onClose(cb: CloseCallback): ListenOff;
|
|
144
77
|
};
|
|
145
78
|
export type ListenStoreApi<T> = ReturnType<typeof withStoreListen<T>>;
|
|
146
|
-
export declare function
|
|
79
|
+
export declare function createStoreListen<T>(producer: (emit: Listener<NormalizeTuple<T>>) => (void | ListenOff), options: ListenStoreOptions<T>): {
|
|
147
80
|
on: ListenOnCurrent<NormalizeTuple<T>>;
|
|
148
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
149
|
-
cbClose?: cbClose;
|
|
150
|
-
key?: key;
|
|
151
|
-
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
152
|
-
}) => () => void;
|
|
153
|
-
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
154
81
|
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
155
|
-
key?:
|
|
82
|
+
key?: ListenKey;
|
|
156
83
|
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
157
|
-
}) =>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
count: () => number;
|
|
84
|
+
}) => ListenOff;
|
|
85
|
+
emit: Listener<NormalizeTuple<T>>;
|
|
86
|
+
has(key: ListenKey): boolean;
|
|
87
|
+
off(keyOrCallback: ListenKey | Listener<NormalizeTuple<T>> | null): void;
|
|
88
|
+
close(): void;
|
|
89
|
+
count(): number;
|
|
90
|
+
keys(): ListenKey[];
|
|
91
|
+
isRunning(): boolean;
|
|
92
|
+
run(): void;
|
|
93
|
+
onClose(cb: CloseCallback): ListenOff;
|
|
168
94
|
};
|
|
169
|
-
export declare function
|
|
95
|
+
export declare function listenStore<T>(options: ListenStoreOptions<T>): readonly [Listener<NormalizeTuple<T>>, {
|
|
170
96
|
on: ListenOnCurrent<NormalizeTuple<T>>;
|
|
171
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
172
|
-
cbClose?: cbClose;
|
|
173
|
-
key?: key;
|
|
174
|
-
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
175
|
-
}) => () => void;
|
|
176
|
-
removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
|
|
177
97
|
once: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
178
|
-
key?:
|
|
98
|
+
key?: ListenKey;
|
|
179
99
|
current?: ListenCurrent<NormalizeTuple<T>> | undefined;
|
|
180
|
-
}) =>
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
count: () => number;
|
|
100
|
+
}) => ListenOff;
|
|
101
|
+
emit: Listener<NormalizeTuple<T>>;
|
|
102
|
+
has(key: ListenKey): boolean;
|
|
103
|
+
off(keyOrCallback: ListenKey | Listener<NormalizeTuple<T>> | null): void;
|
|
104
|
+
close(): void;
|
|
105
|
+
count(): number;
|
|
106
|
+
keys(): ListenKey[];
|
|
107
|
+
isRunning(): boolean;
|
|
108
|
+
run(): void;
|
|
109
|
+
onClose(cb: CloseCallback): ListenOff;
|
|
191
110
|
}];
|
|
192
|
-
export declare function
|
|
111
|
+
export declare function toSlimListen<T>(full: ListenApi<T>): {
|
|
193
112
|
on: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
194
|
-
key?:
|
|
195
|
-
}) =>
|
|
196
|
-
off: (
|
|
113
|
+
key?: ListenKey;
|
|
114
|
+
}) => ListenOff;
|
|
115
|
+
off: (keyOrCallback: Listener<NormalizeTuple<T>> | null | ListenKey) => void;
|
|
197
116
|
close: () => void;
|
|
198
117
|
count: () => number;
|
|
199
118
|
};
|
|
200
|
-
export type
|
|
201
|
-
export declare function
|
|
119
|
+
export type SlimListen<T> = ReturnType<typeof toSlimListen<T>>;
|
|
120
|
+
export declare function slimListen<T>(options?: ListenOptions<T>): readonly [Listener<NormalizeTuple<T>>, {
|
|
202
121
|
on: (cb: Listener<NormalizeTuple<T>>, opts?: {
|
|
203
|
-
key?:
|
|
204
|
-
} | undefined) =>
|
|
205
|
-
off: (
|
|
122
|
+
key?: ListenKey;
|
|
123
|
+
} | undefined) => ListenOff;
|
|
124
|
+
off: (keyOrCallback: ListenKey | Listener<NormalizeTuple<T>> | null) => void;
|
|
206
125
|
close: () => void;
|
|
207
126
|
count: () => number;
|
|
208
127
|
}];
|