insite-subscriptions-client 1.0.295 → 2.0.0
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/package.json +13 -12
- package/{lib/Subscription.js → src/Subscription.ts} +21 -26
- package/{lib/SubscriptionArray.js → src/SubscriptionArray.ts} +56 -22
- package/{lib/SubscriptionGroup/SubscriptionGroup.js → src/SubscriptionGroup/SubscriptionGroup.ts} +86 -59
- package/src/SubscriptionGroup/SubscriptionGroupItem.ts +391 -0
- package/src/SubscriptionGroup/common.ts +13 -0
- package/src/SubscriptionGroup/index.ts +8 -0
- package/src/SubscriptionGroup/types.ts +121 -0
- package/{lib/SubscriptionMap.js → src/SubscriptionMap.ts} +128 -66
- package/src/SubscriptionObject.ts +168 -0
- package/src/index.ts +19 -0
- package/bun.lockb +0 -0
- package/lib/SubscriptionGroup/SubscriptionGroupItem.js +0 -300
- package/lib/SubscriptionGroup/common.js +0 -1
- package/lib/SubscriptionGroup/index.js +0 -1
- package/lib/SubscriptionObject.js +0 -153
- package/lib/index.js +0 -21
- /package/{lib/symbols.js → src/symbols.ts} +0 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
|
+
import { debounce, removeOne, StatefulPromise } from "@nesvet/n";
|
|
3
|
+
import { type SubscriptionArrayUpdated, SubscriptionArrayWithSubscription } from "../SubscriptionArray";
|
|
4
|
+
import { type SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "../SubscriptionMap";
|
|
5
|
+
import { type Updated as SubscriptionObjectUpdated, SubscriptionObjectWithSubscription } from "../SubscriptionObject";
|
|
6
|
+
import {
|
|
7
|
+
renewSymbol,
|
|
8
|
+
setHandleUpdateSymbol,
|
|
9
|
+
subscribeSymbol,
|
|
10
|
+
unsubscribeSymbol
|
|
11
|
+
} from "../symbols";
|
|
12
|
+
import { privates } from "./common";
|
|
13
|
+
import type { SubscriptionGroup } from "./SubscriptionGroup";
|
|
14
|
+
import type {
|
|
15
|
+
Definition,
|
|
16
|
+
SubscriptionHandle,
|
|
17
|
+
SubscriptionOnBeforeInit,
|
|
18
|
+
SubscriptionType,
|
|
19
|
+
SubscriptionUpdated,
|
|
20
|
+
SubscriptionUpdates,
|
|
21
|
+
SubscriptionValue
|
|
22
|
+
} from "./types";
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
type HandleSubscription<T> = (_: any, updated: SubscriptionUpdated<T>, updates: SubscriptionUpdates<T>) => void;
|
|
29
|
+
|
|
30
|
+
function isUpdatedMapOrArray(updated: SubscriptionUpdated<SubscriptionType>): updated is SubscriptionArrayUpdated | SubscriptionMapUpdated {
|
|
31
|
+
return Array.isArray(updated);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export class SubscriptionGroupItem<T extends SubscriptionType = SubscriptionType, D extends Definition<T> = Definition<T>> extends EventEmitter {
|
|
36
|
+
constructor(definition: D, group: SubscriptionGroup) {
|
|
37
|
+
super();
|
|
38
|
+
|
|
39
|
+
this.name = definition.name;
|
|
40
|
+
|
|
41
|
+
this.define(definition, group);
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
name;
|
|
46
|
+
group?: SubscriptionGroup;
|
|
47
|
+
value?: SubscriptionValue<T>;
|
|
48
|
+
type!: "object" | T;
|
|
49
|
+
publicationName!: Definition<T>["publicationName"];
|
|
50
|
+
params!: Definition<T>["params"];
|
|
51
|
+
handle!: Definition<T>["handle"];
|
|
52
|
+
onBeforeInit!: Definition<T>["onBeforeInit"];
|
|
53
|
+
preventBind!: Definition<T>["preventBind"];
|
|
54
|
+
|
|
55
|
+
emitUpdate!: (updated?: SubscriptionUpdated<T>) => void;
|
|
56
|
+
|
|
57
|
+
isLoaded = false;
|
|
58
|
+
isInited = false;
|
|
59
|
+
|
|
60
|
+
#loadPromise!: StatefulPromise<SubscriptionGroupItem<T, D>>;
|
|
61
|
+
#initPromise!: StatefulPromise<SubscriptionGroupItem<T, D>>;
|
|
62
|
+
#unloadPromise!: StatefulPromise<SubscriptionGroupItem<T, D>>;
|
|
63
|
+
|
|
64
|
+
define(definition: Definition<T>, group: SubscriptionGroup | undefined = this.group) {
|
|
65
|
+
if (!group)
|
|
66
|
+
throw new Error("group is undefined");
|
|
67
|
+
|
|
68
|
+
const {
|
|
69
|
+
value,
|
|
70
|
+
type = "object",
|
|
71
|
+
publicationName,
|
|
72
|
+
params,
|
|
73
|
+
handle,
|
|
74
|
+
onBeforeInit,
|
|
75
|
+
debounce: debounceLimit = SubscriptionGroupItem.debounceLimit,
|
|
76
|
+
preventBind
|
|
77
|
+
} = definition;
|
|
78
|
+
|
|
79
|
+
if (this.group) {
|
|
80
|
+
if (
|
|
81
|
+
(!value || this.value === value) &&
|
|
82
|
+
this.type === type &&
|
|
83
|
+
this.publicationName === publicationName &&
|
|
84
|
+
JSON.stringify(this.params) === JSON.stringify(params) &&
|
|
85
|
+
this.handle === handle &&
|
|
86
|
+
this.onBeforeInit === onBeforeInit
|
|
87
|
+
)
|
|
88
|
+
return this.#applyOptions({ debounceLimit, preventBind });
|
|
89
|
+
|
|
90
|
+
this.detach();
|
|
91
|
+
delete this.value;
|
|
92
|
+
delete this.publicationName;
|
|
93
|
+
delete this.params;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.type = type;
|
|
97
|
+
this.handle = handle;
|
|
98
|
+
this.onBeforeInit = onBeforeInit;
|
|
99
|
+
if (value)
|
|
100
|
+
this.value = value;
|
|
101
|
+
else {
|
|
102
|
+
this.publicationName = publicationName ?? this.name;
|
|
103
|
+
this.params = params ?? [];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.#applyOptions({ debounceLimit, preventBind });
|
|
107
|
+
|
|
108
|
+
this.#attachTo(group);
|
|
109
|
+
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#applyOptions({ debounceLimit, preventBind }: { debounceLimit?: number; preventBind?: boolean }) {
|
|
114
|
+
|
|
115
|
+
const emitUpdate: typeof this.emitUpdate = updated => {
|
|
116
|
+
this.emit("update", this.value, updated);
|
|
117
|
+
this.group?.emit(`update.${this.name}`, this.value, updated);
|
|
118
|
+
this.group?.emitUpdate();
|
|
119
|
+
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (typeof debounceLimit == "number") {
|
|
123
|
+
let debouncedUpdated: SubscriptionUpdated<T> | undefined;
|
|
124
|
+
let group: SubscriptionGroup;
|
|
125
|
+
|
|
126
|
+
const emitUpdateDebounced = debounce(() => {
|
|
127
|
+
|
|
128
|
+
const isDetached = !this.group;
|
|
129
|
+
|
|
130
|
+
if (isDetached)
|
|
131
|
+
this.group = group;
|
|
132
|
+
|
|
133
|
+
emitUpdate(debouncedUpdated!);
|
|
134
|
+
|
|
135
|
+
if (isDetached)
|
|
136
|
+
delete this.group;
|
|
137
|
+
|
|
138
|
+
debouncedUpdated = undefined;
|
|
139
|
+
|
|
140
|
+
}, debounceLimit);
|
|
141
|
+
|
|
142
|
+
this.emitUpdate = updated => {
|
|
143
|
+
if (updated !== undefined)
|
|
144
|
+
if (isUpdatedMapOrArray(updated))
|
|
145
|
+
if (isUpdatedMapOrArray(debouncedUpdated!))
|
|
146
|
+
for (const item of updated)
|
|
147
|
+
debouncedUpdated.push(item as any);
|
|
148
|
+
else
|
|
149
|
+
debouncedUpdated = Object.assign([ ...updated ], {
|
|
150
|
+
added: [ ...updated.added ],
|
|
151
|
+
deleted: [ ...updated.deleted ]
|
|
152
|
+
}) as SubscriptionUpdated<T>;
|
|
153
|
+
else if (typeof updated == "object")
|
|
154
|
+
if (debouncedUpdated)
|
|
155
|
+
Object.assign(debouncedUpdated, updated);
|
|
156
|
+
else
|
|
157
|
+
debouncedUpdated = { ...updated };
|
|
158
|
+
else
|
|
159
|
+
debouncedUpdated = updated;
|
|
160
|
+
|
|
161
|
+
group = this.group!;
|
|
162
|
+
|
|
163
|
+
return emitUpdateDebounced();
|
|
164
|
+
};
|
|
165
|
+
} else
|
|
166
|
+
this.emitUpdate = emitUpdate;
|
|
167
|
+
|
|
168
|
+
if (this.preventBind === undefined)
|
|
169
|
+
delete this.preventBind;
|
|
170
|
+
else
|
|
171
|
+
this.preventBind = preventBind;
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#attachTo(group: SubscriptionGroup) {
|
|
176
|
+
if (!this.group) {
|
|
177
|
+
this.group = group;
|
|
178
|
+
|
|
179
|
+
this.group.items.push(this);
|
|
180
|
+
this.group.items[this.name] = this;
|
|
181
|
+
|
|
182
|
+
if (!this.#loadPromise || this.#loadPromise.isFulfilled)
|
|
183
|
+
this.#loadPromise = new StatefulPromise();
|
|
184
|
+
|
|
185
|
+
if (!this.#initPromise || this.#initPromise.isFulfilled)
|
|
186
|
+
this.#initPromise = new StatefulPromise();
|
|
187
|
+
|
|
188
|
+
if (!this.#unloadPromise || this.#unloadPromise.isFulfilled)
|
|
189
|
+
this.#unloadPromise = new StatefulPromise();
|
|
190
|
+
|
|
191
|
+
switch (this.type) {
|
|
192
|
+
case "array": {
|
|
193
|
+
const handleSubscription = this.#handleSubscription as HandleSubscription<"array">;
|
|
194
|
+
if (this.value)
|
|
195
|
+
(this.value as SubscriptionArrayWithSubscription)[setHandleUpdateSymbol](handleSubscription);
|
|
196
|
+
else
|
|
197
|
+
this.value = new SubscriptionArrayWithSubscription(this.publicationName!, this.params!, handleSubscription, false) as SubscriptionValue<T>;
|
|
198
|
+
break;
|
|
199
|
+
} case "map": {
|
|
200
|
+
const handleSubscription = this.#handleSubscription as HandleSubscription<"map">;
|
|
201
|
+
if (this.value)
|
|
202
|
+
(this.value as SubscriptionMapWithSubscription)[setHandleUpdateSymbol](handleSubscription);
|
|
203
|
+
else
|
|
204
|
+
this.value = new SubscriptionMapWithSubscription(this.publicationName!, this.params!, handleSubscription, false) as SubscriptionValue<T>;
|
|
205
|
+
break;
|
|
206
|
+
} default: {
|
|
207
|
+
const handleSubscription = this.#handleSubscription as HandleSubscription<"object">;
|
|
208
|
+
if (this.value)
|
|
209
|
+
(this.value as SubscriptionObjectWithSubscription)[setHandleUpdateSymbol](handleSubscription);
|
|
210
|
+
else
|
|
211
|
+
this.value = new SubscriptionObjectWithSubscription(this.publicationName!, this.params!, handleSubscription, false) as SubscriptionValue<T>;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
this.group.values.push(this.value);
|
|
216
|
+
this.group.values[this.name] = this.value;
|
|
217
|
+
|
|
218
|
+
if (this.onBeforeInit)
|
|
219
|
+
switch (this.type) {
|
|
220
|
+
case "array":
|
|
221
|
+
(this.onBeforeInit as SubscriptionOnBeforeInit<"array">).call(this.group, this.value as SubscriptionArrayWithSubscription);
|
|
222
|
+
break;
|
|
223
|
+
case "map":
|
|
224
|
+
(this.onBeforeInit as SubscriptionOnBeforeInit<"map">).call(this.group, this.value as SubscriptionMapWithSubscription);
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
(this.onBeforeInit as SubscriptionOnBeforeInit<"object">).call(this.group, this.value as SubscriptionObjectWithSubscription);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
detach() {
|
|
234
|
+
|
|
235
|
+
if (this.group) {
|
|
236
|
+
this.value?.[unsubscribeSymbol]();
|
|
237
|
+
|
|
238
|
+
this.isLoaded = false;
|
|
239
|
+
this.#unload();
|
|
240
|
+
|
|
241
|
+
delete this.group.values[this.name];
|
|
242
|
+
removeOne(this.group.values, this.value);
|
|
243
|
+
delete this.group.items[this.name];
|
|
244
|
+
removeOne(this.group.items, this);
|
|
245
|
+
|
|
246
|
+
delete this.group;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
#loadUpdated: null | SubscriptionUpdated<T> = null;
|
|
252
|
+
|
|
253
|
+
#handleSubscription: HandleSubscription<T> = (_, updated, updates) => {
|
|
254
|
+
if (updates)
|
|
255
|
+
if (this.group!.isLoaded) {
|
|
256
|
+
if (this.handle)
|
|
257
|
+
switch (this.type) {
|
|
258
|
+
case "array":
|
|
259
|
+
(this.handle as SubscriptionHandle<"array">).call(this.group!, updated as SubscriptionArrayUpdated, this.group!);
|
|
260
|
+
break;
|
|
261
|
+
case "map":
|
|
262
|
+
(this.handle as SubscriptionHandle<"map">).call(this.group!, updated as SubscriptionMapUpdated, this.group!);
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
(this.handle as SubscriptionHandle<"object">).call(this.group!, updated as SubscriptionObjectUpdated, this.group!);
|
|
266
|
+
}
|
|
267
|
+
this.emitUpdate(updated);
|
|
268
|
+
} else {
|
|
269
|
+
this.#loadUpdated = updated;
|
|
270
|
+
this.isLoaded = true;
|
|
271
|
+
privates.groupLoad!(this.group!);
|
|
272
|
+
}
|
|
273
|
+
else if (this.isLoaded) {
|
|
274
|
+
this.isLoaded = false;
|
|
275
|
+
privates.groupUnload!(this.group!);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (!this.isInited) {
|
|
279
|
+
this.isInited = true;
|
|
280
|
+
privates.groupInit!(this.group!);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
#load() {
|
|
286
|
+
|
|
287
|
+
if (this.#loadUpdated) {
|
|
288
|
+
if (this.handle)
|
|
289
|
+
switch (this.type) {
|
|
290
|
+
case "array":
|
|
291
|
+
(this.handle as SubscriptionHandle<"array">).call(this.group!, this.#loadUpdated as SubscriptionArrayUpdated, this.group!);
|
|
292
|
+
break;
|
|
293
|
+
case "map":
|
|
294
|
+
(this.handle as SubscriptionHandle<"map">).call(this.group!, this.#loadUpdated as SubscriptionMapUpdated, this.group!);
|
|
295
|
+
break;
|
|
296
|
+
default:
|
|
297
|
+
(this.handle as SubscriptionHandle<"object">).call(this.group!, this.#loadUpdated as SubscriptionObjectUpdated, this.group!);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
this.#loadUpdated = null;
|
|
301
|
+
|
|
302
|
+
this.emit("load", this.value);
|
|
303
|
+
|
|
304
|
+
this.#loadPromise.resolve(this);
|
|
305
|
+
|
|
306
|
+
if (this.#unloadPromise.isFulfilled)
|
|
307
|
+
this.#unloadPromise = new StatefulPromise();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
#init() {
|
|
313
|
+
|
|
314
|
+
this.emit("init", this.value);
|
|
315
|
+
|
|
316
|
+
this.#initPromise.resolve(this);
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
#unload() {
|
|
321
|
+
|
|
322
|
+
if (this.handle)
|
|
323
|
+
switch (this.type) {
|
|
324
|
+
case "array":
|
|
325
|
+
(this.handle as SubscriptionHandle<"array">).call(this.group!, null, this.group!);
|
|
326
|
+
break;
|
|
327
|
+
case "map":
|
|
328
|
+
(this.handle as SubscriptionHandle<"map">).call(this.group!, null, this.group!);
|
|
329
|
+
break;
|
|
330
|
+
default:
|
|
331
|
+
(this.handle as SubscriptionHandle<"object">).call(this.group!, null, this.group!);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
this.emit("unload", this.value);
|
|
335
|
+
|
|
336
|
+
this.#unloadPromise.resolve(this);
|
|
337
|
+
|
|
338
|
+
if (this.#loadPromise.isFulfilled)
|
|
339
|
+
this.#loadPromise = new StatefulPromise();
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
loaded() {
|
|
344
|
+
return this.#loadPromise;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
inited() {
|
|
348
|
+
return this.#initPromise;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
unloaded() {
|
|
352
|
+
return this.#unloadPromise;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
subscribe() {
|
|
356
|
+
return this.value?.[subscribeSymbol]();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
unsubscribe() {
|
|
360
|
+
return this.value?.[unsubscribeSymbol]();
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
renew(publicationName: Definition<T>["publicationName"], params: Definition<T>["params"]) {
|
|
364
|
+
return this.value?.[renewSymbol](publicationName, params);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
valueOf() {
|
|
368
|
+
return this.value;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
static debounceLimit = 4;
|
|
373
|
+
|
|
374
|
+
static {
|
|
375
|
+
|
|
376
|
+
privates.itemLoad = <
|
|
377
|
+
DP extends Definition<TP>,
|
|
378
|
+
TP extends SubscriptionType
|
|
379
|
+
>(item: SubscriptionGroupItem<TP, DP>) => item.#load();
|
|
380
|
+
privates.itemInit = <
|
|
381
|
+
DP extends Definition<TP>,
|
|
382
|
+
TP extends SubscriptionType
|
|
383
|
+
>(item: SubscriptionGroupItem<TP, DP>) => item.#init();
|
|
384
|
+
privates.itemUnload = <
|
|
385
|
+
DP extends Definition<TP>,
|
|
386
|
+
TP extends SubscriptionType
|
|
387
|
+
>(item: SubscriptionGroupItem<TP, DP>) => item.#unload();
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SubscriptionGroup } from "./SubscriptionGroup";
|
|
2
|
+
import type { SubscriptionGroupItem } from "./SubscriptionGroupItem";
|
|
3
|
+
import type { SubscriptionType } from "./types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const privates: {
|
|
7
|
+
groupLoad?: (group: SubscriptionGroup) => void;
|
|
8
|
+
groupInit?: (group: SubscriptionGroup) => void;
|
|
9
|
+
groupUnload?: (group: SubscriptionGroup) => void;
|
|
10
|
+
itemLoad?: <T extends SubscriptionType>(item: SubscriptionGroupItem<T>) => void;
|
|
11
|
+
itemInit?: <T extends SubscriptionType>(item: SubscriptionGroupItem<T>) => void;
|
|
12
|
+
itemUnload?: <T extends SubscriptionType>(item: SubscriptionGroupItem<T>) => void;
|
|
13
|
+
} = {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./SubscriptionGroup";
|
|
2
|
+
export {
|
|
3
|
+
Definition as SubscriptionGroupDefinition,
|
|
4
|
+
ParseValues as ParseSubscriptionGroupValues,
|
|
5
|
+
SubscriptionHandle as SubscriptionGroupSubscriptionHandle,
|
|
6
|
+
SubscriptionType as SubscriptionGroupSubscriptionType,
|
|
7
|
+
UnparsedDefinition as SubscriptionGroupUnparsedDefinition
|
|
8
|
+
} from "./types";
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SubscriptionArrayUpdated,
|
|
3
|
+
Updates as SubscriptionArrayUpdates,
|
|
4
|
+
SubscriptionArrayWithSubscription
|
|
5
|
+
} from "../SubscriptionArray";
|
|
6
|
+
import type {
|
|
7
|
+
SubscriptionMapUpdated,
|
|
8
|
+
Updates as SubscriptionMapUpdates,
|
|
9
|
+
SubscriptionMapWithSubscription
|
|
10
|
+
} from "../SubscriptionMap";
|
|
11
|
+
import type {
|
|
12
|
+
Updated as SubscriptionObjectUpdated,
|
|
13
|
+
Updates as SubscriptionObjectUpdates,
|
|
14
|
+
SubscriptionObjectWithSubscription
|
|
15
|
+
} from "../SubscriptionObject";
|
|
16
|
+
import type { SubscriptionGroup } from "./SubscriptionGroup";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export type SubscriptionType = "array" | "map" | "object";
|
|
23
|
+
|
|
24
|
+
export type SubscriptionUpdated<T> =
|
|
25
|
+
T extends "array" ?
|
|
26
|
+
SubscriptionArrayUpdated<any> :
|
|
27
|
+
T extends "map" ?
|
|
28
|
+
SubscriptionMapUpdated<any> :
|
|
29
|
+
T extends "object" ?
|
|
30
|
+
SubscriptionObjectUpdated :
|
|
31
|
+
never;
|
|
32
|
+
|
|
33
|
+
export type SubscriptionValue<T> =
|
|
34
|
+
T extends "array" ?
|
|
35
|
+
SubscriptionArrayWithSubscription<any> :
|
|
36
|
+
T extends "map" ?
|
|
37
|
+
SubscriptionMapWithSubscription<any> :
|
|
38
|
+
T extends "object" ?
|
|
39
|
+
SubscriptionObjectWithSubscription :
|
|
40
|
+
never;
|
|
41
|
+
|
|
42
|
+
export type SubscriptionHandle<T> =
|
|
43
|
+
T extends "array" ?
|
|
44
|
+
(updated: null | SubscriptionArrayUpdated<any>, group: SubscriptionGroup) => void :
|
|
45
|
+
T extends "map" ?
|
|
46
|
+
(updated: null | SubscriptionMapUpdated<any>, group: SubscriptionGroup) => void :
|
|
47
|
+
T extends "object" ?
|
|
48
|
+
(updated: null | SubscriptionObjectUpdated, group: SubscriptionGroup) => void :
|
|
49
|
+
never;
|
|
50
|
+
|
|
51
|
+
export type SubscriptionOnBeforeInit<T> =
|
|
52
|
+
T extends "array" ?
|
|
53
|
+
(value: SubscriptionArrayWithSubscription<any>) => void :
|
|
54
|
+
T extends "map" ?
|
|
55
|
+
(value: SubscriptionMapWithSubscription<any>) => void :
|
|
56
|
+
T extends "object" ?
|
|
57
|
+
(value: SubscriptionObjectWithSubscription) => void :
|
|
58
|
+
never;
|
|
59
|
+
|
|
60
|
+
export type SubscriptionUpdates<T> =
|
|
61
|
+
T extends "array" ?
|
|
62
|
+
SubscriptionArrayUpdates :
|
|
63
|
+
T extends "map" ?
|
|
64
|
+
SubscriptionMapUpdates :
|
|
65
|
+
T extends "object" ?
|
|
66
|
+
SubscriptionObjectUpdates :
|
|
67
|
+
never;
|
|
68
|
+
|
|
69
|
+
export type Definition<T extends SubscriptionType = SubscriptionType> = {
|
|
70
|
+
name: string;
|
|
71
|
+
value?: SubscriptionValue<T>;
|
|
72
|
+
type?: T;
|
|
73
|
+
publicationName?: string;
|
|
74
|
+
params?: unknown[];
|
|
75
|
+
handle?: (...args: any[]) => void;
|
|
76
|
+
onBeforeInit?: (...args: any[]) => void;
|
|
77
|
+
debounce?: number;
|
|
78
|
+
preventBind?: boolean;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type TupleDefinition = unknown[];
|
|
82
|
+
|
|
83
|
+
export type UnparsedDefinition<T extends SubscriptionType = SubscriptionType> = Definition<T> | TupleDefinition;
|
|
84
|
+
|
|
85
|
+
type ResolveObjectValue<T> =
|
|
86
|
+
T extends { value: infer V } ? V :
|
|
87
|
+
T extends { type: "array" } ? SubscriptionArrayWithSubscription<any> :
|
|
88
|
+
T extends { type: "map" } ? SubscriptionMapWithSubscription<any> :
|
|
89
|
+
T extends { type: "object" } ? SubscriptionObjectWithSubscription :
|
|
90
|
+
SubscriptionObjectWithSubscription;
|
|
91
|
+
|
|
92
|
+
type ResolveArrayValue<T extends any[]> =
|
|
93
|
+
T[1] extends object ? T[1] :
|
|
94
|
+
T[1] extends "array" ? SubscriptionArrayWithSubscription<any> :
|
|
95
|
+
T[1] extends "map" ? SubscriptionMapWithSubscription<any> :
|
|
96
|
+
T[1] extends "object" ? SubscriptionObjectWithSubscription :
|
|
97
|
+
SubscriptionObjectWithSubscription;
|
|
98
|
+
|
|
99
|
+
type ResolveValue<U> =
|
|
100
|
+
U extends object ?
|
|
101
|
+
ResolveObjectValue<U> :
|
|
102
|
+
U extends any[] ?
|
|
103
|
+
ResolveArrayValue<U> :
|
|
104
|
+
never;
|
|
105
|
+
|
|
106
|
+
export type ParseValues<T extends Array<any[] | object>> =
|
|
107
|
+
{
|
|
108
|
+
[K in keyof T as T[K] extends { name: infer N } ?
|
|
109
|
+
N extends string ?
|
|
110
|
+
N :
|
|
111
|
+
never :
|
|
112
|
+
T[K] extends [infer F, any] ?
|
|
113
|
+
F extends string ?
|
|
114
|
+
F :
|
|
115
|
+
never :
|
|
116
|
+
never
|
|
117
|
+
]: ResolveValue<T[K]>;
|
|
118
|
+
} &
|
|
119
|
+
T extends Array<infer U> ?
|
|
120
|
+
ResolveValue<U>[] :
|
|
121
|
+
never;
|