@uwdata/mosaic-core 0.17.0 → 0.19.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.
Files changed (178) hide show
  1. package/LICENSE +47 -0
  2. package/README.md +0 -1
  3. package/dist/src/Coordinator.d.ts +159 -0
  4. package/dist/src/Coordinator.d.ts.map +1 -0
  5. package/dist/src/Coordinator.js +250 -0
  6. package/dist/src/Coordinator.js.map +1 -0
  7. package/dist/src/MosaicClient.d.ts +138 -0
  8. package/dist/src/MosaicClient.d.ts.map +1 -0
  9. package/dist/src/MosaicClient.js +214 -0
  10. package/dist/src/MosaicClient.js.map +1 -0
  11. package/dist/src/Param.d.ts +56 -0
  12. package/dist/src/Param.d.ts.map +1 -0
  13. package/dist/src/Param.js +89 -0
  14. package/dist/src/Param.js.map +1 -0
  15. package/dist/src/QueryConsolidator.d.ts +11 -0
  16. package/dist/src/QueryConsolidator.d.ts.map +1 -0
  17. package/dist/src/QueryConsolidator.js +249 -0
  18. package/dist/src/QueryConsolidator.js.map +1 -0
  19. package/dist/src/QueryManager.d.ts +77 -0
  20. package/dist/src/QueryManager.d.ts.map +1 -0
  21. package/dist/src/QueryManager.js +174 -0
  22. package/dist/src/QueryManager.js.map +1 -0
  23. package/dist/src/Selection.d.ts +222 -0
  24. package/dist/src/Selection.d.ts.map +1 -0
  25. package/dist/src/Selection.js +322 -0
  26. package/dist/src/Selection.js.map +1 -0
  27. package/dist/src/SelectionClause.d.ts +222 -0
  28. package/dist/src/SelectionClause.d.ts.map +1 -0
  29. package/dist/src/SelectionClause.js +168 -0
  30. package/dist/src/SelectionClause.js.map +1 -0
  31. package/dist/src/connectors/Connector.d.ts +26 -0
  32. package/dist/src/connectors/Connector.d.ts.map +1 -0
  33. package/dist/src/connectors/Connector.js +2 -0
  34. package/dist/src/connectors/Connector.js.map +1 -0
  35. package/dist/src/connectors/rest.d.ts +24 -0
  36. package/dist/src/connectors/rest.d.ts.map +1 -0
  37. package/dist/src/connectors/rest.js +37 -0
  38. package/dist/src/connectors/rest.js.map +1 -0
  39. package/dist/src/connectors/socket.d.ts +40 -0
  40. package/dist/src/connectors/socket.d.ts.map +1 -0
  41. package/dist/src/connectors/socket.js +115 -0
  42. package/dist/src/connectors/socket.js.map +1 -0
  43. package/dist/src/connectors/wasm.d.ts +56 -0
  44. package/dist/src/connectors/wasm.d.ts.map +1 -0
  45. package/dist/src/connectors/wasm.js +116 -0
  46. package/dist/src/connectors/wasm.js.map +1 -0
  47. package/dist/src/index.d.ts +28 -0
  48. package/dist/src/index.d.ts.map +1 -0
  49. package/{src → dist/src}/index.js +8 -11
  50. package/dist/src/index.js.map +1 -0
  51. package/dist/src/make-client.d.ts +33 -0
  52. package/dist/src/make-client.d.ts.map +1 -0
  53. package/dist/src/make-client.js +52 -0
  54. package/dist/src/make-client.js.map +1 -0
  55. package/dist/src/preagg/PreAggregator.d.ts +150 -0
  56. package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
  57. package/dist/src/preagg/PreAggregator.js +382 -0
  58. package/dist/src/preagg/PreAggregator.js.map +1 -0
  59. package/dist/src/preagg/preagg-columns.d.ts +16 -0
  60. package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
  61. package/dist/src/preagg/preagg-columns.js +95 -0
  62. package/dist/src/preagg/preagg-columns.js.map +1 -0
  63. package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
  64. package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
  65. package/dist/src/preagg/sufficient-statistics.js +446 -0
  66. package/dist/src/preagg/sufficient-statistics.js.map +1 -0
  67. package/dist/src/types.d.ts +77 -0
  68. package/dist/src/types.d.ts.map +1 -0
  69. package/dist/src/types.js +2 -0
  70. package/dist/src/types.js.map +1 -0
  71. package/dist/src/util/AsyncDispatch.d.ts +121 -0
  72. package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
  73. package/dist/src/util/AsyncDispatch.js +188 -0
  74. package/dist/src/util/AsyncDispatch.js.map +1 -0
  75. package/dist/src/util/cache.d.ts +19 -0
  76. package/dist/src/util/cache.d.ts.map +1 -0
  77. package/dist/src/util/cache.js +66 -0
  78. package/dist/src/util/cache.js.map +1 -0
  79. package/dist/src/util/decode-ipc.d.ts +12 -0
  80. package/dist/src/util/decode-ipc.d.ts.map +1 -0
  81. package/{src → dist/src}/util/decode-ipc.js +5 -6
  82. package/dist/src/util/decode-ipc.js.map +1 -0
  83. package/dist/src/util/distinct.d.ts +3 -0
  84. package/dist/src/util/distinct.d.ts.map +1 -0
  85. package/dist/src/util/distinct.js +16 -0
  86. package/dist/src/util/distinct.js.map +1 -0
  87. package/dist/src/util/field-info.d.ts +26 -0
  88. package/dist/src/util/field-info.d.ts.map +1 -0
  89. package/dist/src/util/field-info.js +91 -0
  90. package/dist/src/util/field-info.js.map +1 -0
  91. package/dist/src/util/hash.d.ts +2 -0
  92. package/dist/src/util/hash.d.ts.map +1 -0
  93. package/dist/src/util/hash.js +26 -0
  94. package/dist/src/util/hash.js.map +1 -0
  95. package/dist/src/util/is-activatable.d.ts +8 -0
  96. package/dist/src/util/is-activatable.d.ts.map +1 -0
  97. package/dist/src/util/is-activatable.js +10 -0
  98. package/dist/src/util/is-activatable.js.map +1 -0
  99. package/dist/src/util/is-arrow-table.d.ts +9 -0
  100. package/dist/src/util/is-arrow-table.d.ts.map +1 -0
  101. package/dist/src/util/is-arrow-table.js +11 -0
  102. package/dist/src/util/is-arrow-table.js.map +1 -0
  103. package/dist/src/util/js-type.d.ts +9 -0
  104. package/dist/src/util/js-type.d.ts.map +1 -0
  105. package/dist/src/util/js-type.js +59 -0
  106. package/dist/src/util/js-type.js.map +1 -0
  107. package/dist/src/util/priority-queue.d.ts +35 -0
  108. package/dist/src/util/priority-queue.d.ts.map +1 -0
  109. package/dist/src/util/priority-queue.js +81 -0
  110. package/dist/src/util/priority-queue.js.map +1 -0
  111. package/dist/src/util/query-result.d.ts +47 -0
  112. package/dist/src/util/query-result.d.ts.map +1 -0
  113. package/dist/src/util/query-result.js +83 -0
  114. package/dist/src/util/query-result.js.map +1 -0
  115. package/dist/src/util/synchronizer.d.ts +36 -0
  116. package/dist/src/util/synchronizer.d.ts.map +1 -0
  117. package/dist/src/util/synchronizer.js +52 -0
  118. package/dist/src/util/synchronizer.js.map +1 -0
  119. package/dist/src/util/throttle.d.ts +12 -0
  120. package/dist/src/util/throttle.d.ts.map +1 -0
  121. package/dist/src/util/throttle.js +51 -0
  122. package/dist/src/util/throttle.js.map +1 -0
  123. package/dist/src/util/to-data-columns.d.ts +22 -0
  124. package/dist/src/util/to-data-columns.d.ts.map +1 -0
  125. package/dist/src/util/to-data-columns.js +51 -0
  126. package/dist/src/util/to-data-columns.js.map +1 -0
  127. package/dist/src/util/void-logger.d.ts +13 -0
  128. package/dist/src/util/void-logger.d.ts.map +1 -0
  129. package/dist/src/util/void-logger.js +13 -0
  130. package/dist/src/util/void-logger.js.map +1 -0
  131. package/package.json +17 -11
  132. package/src/Coordinator.ts +396 -0
  133. package/src/{MosaicClient.js → MosaicClient.ts} +50 -43
  134. package/src/{Param.js → Param.ts} +29 -28
  135. package/src/{QueryConsolidator.js → QueryConsolidator.ts} +85 -62
  136. package/src/{QueryManager.js → QueryManager.ts} +61 -54
  137. package/src/Selection.ts +391 -0
  138. package/src/SelectionClause.ts +357 -0
  139. package/src/connectors/Connector.ts +6 -6
  140. package/src/connectors/rest.ts +56 -0
  141. package/src/connectors/{socket.js → socket.ts} +53 -42
  142. package/src/connectors/{wasm.js → wasm.ts} +52 -63
  143. package/src/index.ts +42 -0
  144. package/src/make-client.ts +93 -0
  145. package/src/preagg/{PreAggregator.js → PreAggregator.ts} +164 -145
  146. package/src/preagg/{preagg-columns.js → preagg-columns.ts} +27 -24
  147. package/src/preagg/{sufficient-statistics.js → sufficient-statistics.ts} +160 -110
  148. package/src/types.ts +24 -9
  149. package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
  150. package/src/util/{cache.js → cache.ts} +25 -15
  151. package/src/util/decode-ipc.ts +15 -0
  152. package/src/util/{distinct.js → distinct.ts} +3 -3
  153. package/src/util/{field-info.js → field-info.ts} +30 -31
  154. package/src/util/{hash.js → hash.ts} +4 -4
  155. package/src/util/is-activatable.ts +11 -0
  156. package/src/util/is-arrow-table.ts +12 -0
  157. package/src/util/{js-type.js → js-type.ts} +7 -5
  158. package/src/util/{priority-queue.js → priority-queue.ts} +32 -20
  159. package/src/util/{query-result.js → query-result.ts} +24 -17
  160. package/src/util/synchronizer.ts +56 -0
  161. package/src/util/throttle.ts +59 -0
  162. package/src/util/to-data-columns.ts +65 -0
  163. package/src/util/void-logger.ts +23 -0
  164. package/src/Coordinator.js +0 -313
  165. package/src/Selection.js +0 -380
  166. package/src/SelectionClause.js +0 -159
  167. package/src/connectors/rest.js +0 -38
  168. package/src/index-types.ts +0 -5
  169. package/src/make-client.js +0 -101
  170. package/src/util/is-activatable.js +0 -8
  171. package/src/util/is-arrow-table.js +0 -10
  172. package/src/util/selection-types.ts +0 -137
  173. package/src/util/synchronizer.js +0 -47
  174. package/src/util/throttle.js +0 -54
  175. package/src/util/to-data-columns.js +0 -60
  176. package/src/util/void-logger.js +0 -13
  177. package/tsconfig.json +0 -9
  178. package/vitest.config.ts +0 -3
@@ -0,0 +1,391 @@
1
+ import { type MosaicClient } from './MosaicClient.js';
2
+ import { type ExprNode, FilterExpr, literal, MaybeArray, or } from '@uwdata/mosaic-sql';
3
+ import { Param } from './Param.js';
4
+ import { ClauseSource, SelectionClause } from './SelectionClause.js';
5
+
6
+ export interface SelectionOptions {
7
+ /** Boolean flag indicating cross-filtered resolution. If true, selection clauses will not be applied to the clients they are associated with. */
8
+ cross?: boolean;
9
+ /** Boolean flag indicating if a lack of clauses should correspond to an empty selection with no records. This setting determines the default selection state. */
10
+ empty?: boolean;
11
+ /** Upstream selections whose clauses should be included as part of the new selection. Any clauses published to upstream selections will be relayed to the new selection. */
12
+ include?: Selection | Selection[];
13
+ }
14
+
15
+ export interface SelectionResolverOptions extends Pick<SelectionOptions, "empty" | "cross"> {
16
+ /** Boolean flag to indicate a union strategy. If false, an intersection strategy is used. */
17
+ union?: boolean;
18
+ /** Boolean flag to indicate single clauses only. */
19
+ single?: boolean;
20
+ }
21
+
22
+ /**
23
+ * Test if a value is a Selection instance.
24
+ * @param x The value to test.
25
+ * @returns True if the input is a Selection, false otherwise.
26
+ */
27
+ export function isSelection(x: unknown): x is Selection {
28
+ return x instanceof Selection;
29
+ }
30
+
31
+ function create(options: SelectionResolverOptions, include?: Selection | Selection[]): Selection {
32
+ return new Selection(
33
+ new SelectionResolver(options),
34
+ include ? [include].flat() : undefined
35
+ );
36
+ }
37
+
38
+ type SelectionClauseArray = SelectionClause[] & { active?: SelectionClause };
39
+ type ResolvedPredicate = MaybeArray<string | boolean | ExprNode> | undefined;
40
+
41
+ /**
42
+ * Represents a dynamic set of query filter predicates.
43
+ */
44
+ export class Selection extends Param<SelectionClauseArray> {
45
+ _resolved: SelectionClauseArray;
46
+ _resolver: SelectionResolver;
47
+ _relay: Set<Selection>;
48
+
49
+ /**
50
+ * Create a new Selection instance with an
51
+ * intersect (conjunction) resolution strategy.
52
+ * @param options The selection options.
53
+ * @returns The new Selection instance.
54
+ */
55
+ static intersect({ cross = false, empty = false, include = [] }: SelectionOptions = {}): Selection {
56
+ return create({ cross, empty }, include);
57
+ }
58
+
59
+ /**
60
+ * Create a new Selection instance with a
61
+ * union (disjunction) resolution strategy.
62
+ * @param options The selection options.
63
+ * @returns The new Selection instance.
64
+ */
65
+ static union({ cross = false, empty = false, include = [] }: SelectionOptions = {}): Selection {
66
+ return create({ cross, empty, union: true }, include);
67
+ }
68
+
69
+ /**
70
+ * Create a new Selection instance with a singular resolution strategy
71
+ * that keeps only the most recent selection clause.
72
+ * @param options The selection options.
73
+ * @returns The new Selection instance.
74
+ */
75
+ static single({ cross = false, empty = false, include = [] }: SelectionOptions = {}): Selection {
76
+ return create({ cross, empty, single: true }, include);
77
+ }
78
+
79
+ /**
80
+ * Create a new Selection instance with a
81
+ * cross-filtered intersect resolution strategy.
82
+ * @param options The selection options.
83
+ * @returns The new Selection instance.
84
+ */
85
+ static crossfilter({ empty = false, include = [] }: Omit<SelectionOptions, 'cross'> = {}): Selection {
86
+ return create({ cross: true, empty }, include);
87
+ }
88
+
89
+ /**
90
+ * Create a new Selection instance.
91
+ * @param resolver The selection resolution
92
+ * strategy to apply.
93
+ * @param include Upstream selections whose clauses
94
+ * should be included as part of this selection. Any clauses published
95
+ * to these upstream selections will be relayed to this selection.
96
+ */
97
+ constructor(resolver = new SelectionResolver(), include: Selection[] = []) {
98
+ super([]);
99
+ this._resolved = this._value!;
100
+ this._resolver = resolver;
101
+ this._relay = new Set();
102
+ if (Array.isArray(include)) {
103
+ for (const sel of include) {
104
+ sel._relay.add(this);
105
+ }
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Create a cloned copy of this Selection instance.
111
+ * @returns A clone of this selection.
112
+ */
113
+ clone(): Selection {
114
+ const s = new Selection(this._resolver);
115
+ s._value = s._resolved = this._value!;
116
+ return s;
117
+ }
118
+
119
+ /**
120
+ * Create a clone of this Selection with clauses corresponding
121
+ * to the provided source removed.
122
+ * @param source The clause source to remove.
123
+ * @returns A cloned and updated Selection.
124
+ */
125
+ remove(source: ClauseSource): Selection {
126
+ const s = this.clone();
127
+ s._value = s._resolved = s._resolver.resolve(
128
+ this._resolved,
129
+ { source } as SelectionClause
130
+ );
131
+ s._value.active = { source } as SelectionClause;
132
+ return s;
133
+ }
134
+
135
+ /**
136
+ * The selection clause resolver.
137
+ */
138
+ get resolver(): SelectionResolver {
139
+ return this._resolver;
140
+ }
141
+
142
+ /**
143
+ * Indicate if this selection has a single resolution strategy.
144
+ */
145
+ get single(): boolean {
146
+ return this._resolver.single;
147
+ }
148
+
149
+ /**
150
+ * The current array of selection clauses.
151
+ */
152
+ get clauses(): SelectionClauseArray {
153
+ return super.value!;
154
+ }
155
+
156
+ /**
157
+ * The current active (most recently updated) selection clause.
158
+ */
159
+ get active(): SelectionClause {
160
+ return this.clauses.active!;
161
+ }
162
+
163
+ /**
164
+ * The value corresponding to the current active selection clause.
165
+ * This method ensures compatibility where a normal Param is expected.
166
+ */
167
+ // @ts-expect-error return type differs from Param parent class
168
+ get value(): unknown {
169
+ return this.active?.value;
170
+ }
171
+
172
+ /**
173
+ * The value corresponding to a given source. Returns undefined if
174
+ * this selection does not include a clause from this source.
175
+ * @param source The clause source to look up the value for.
176
+ */
177
+ valueFor(source: unknown): unknown {
178
+ return this.clauses.find(c => c.source === source)?.value;
179
+ }
180
+
181
+ /**
182
+ * Emit an activate event with the given selection clause.
183
+ * @param clause The clause representing the potential activation.
184
+ */
185
+ activate(clause: SelectionClause): void {
186
+ // @ts-expect-error selection operates differently than scalar param
187
+ this.emit('activate', clause);
188
+ this._relay.forEach(sel => sel.activate(clause));
189
+ }
190
+
191
+ /**
192
+ * Update the selection with a new selection clause.
193
+ * @param clause The selection clause to add.
194
+ * @returns This Selection instance.
195
+ */
196
+ // @ts-expect-error selection and param use differing value types
197
+ update(clause: SelectionClause): this {
198
+ // we maintain an up-to-date list of all resolved clauses
199
+ // this ensures consistent clause state across unemitted event values
200
+ this._resolved = this._resolver.resolve(this._resolved, clause, true);
201
+ this._resolved.active = clause;
202
+ this._relay.forEach(sel => sel.update(clause));
203
+ return super.update(this._resolved);
204
+ }
205
+
206
+ /**
207
+ * Reset the selection state by removing all provided clauses. If no clause
208
+ * array is provided as an argument, all current clauses are removed. The
209
+ * reset method (if defined) is invoked on all corresponding clause sources.
210
+ * The reset is relayed to downstream selections that include this selection.
211
+ * @param clauses The clauses to remove. If unspecified, all current clauses are removed.
212
+ * @returns This selection instance.
213
+ */
214
+ reset(clauses?: SelectionClause[]): this {
215
+ clauses ??= this._resolved;
216
+ clauses.forEach(c => c.source?.reset?.());
217
+ this._resolved = this._resolved.filter(c => clauses!.includes(c));
218
+ this._relay.forEach(sel => sel.reset(clauses));
219
+ return super.update(this._resolved = []);
220
+ }
221
+
222
+ /**
223
+ * Upon value-typed updates, sets the current clause list to the
224
+ * input value and returns the active clause value.
225
+ * @param type The event type.
226
+ * @param value The input event value.
227
+ * @returns For value-typed events, returns the active clause
228
+ * values. Otherwise returns the input event value as-is.
229
+ */
230
+ // @ts-expect-error selection and param use differing value types
231
+ willEmit(type: string, value: unknown): unknown {
232
+ if (type === 'value') {
233
+ this._value = value as SelectionClauseArray;
234
+ return this.value;
235
+ }
236
+ return value;
237
+ }
238
+
239
+ /**
240
+ * Upon value-typed updates, returns a dispatch queue filter function.
241
+ * The return value depends on the selection resolution strategy.
242
+ * @param type The event type.
243
+ * @param value The new event value that will be enqueued.
244
+ * @returns A dispatch queue filter function. For non-value events,
245
+ * returns a function that always returns null (no filtering).
246
+ */
247
+ // @ts-expect-error selection and param use differing value types
248
+ emitQueueFilter(
249
+ type: string,
250
+ value: SelectionClauseArray
251
+ ): ((value: SelectionClauseArray) => boolean) | null {
252
+ return type === 'value'
253
+ ? this._resolver.queueFilter(value)
254
+ : null;
255
+ }
256
+
257
+ /**
258
+ * Indicates if a selection clause should not be applied to a given client.
259
+ * The return value depends on the selection resolution strategy.
260
+ * @param client The client to test. If null or undefined, return false.
261
+ * @param clause The selection clause.
262
+ * @returns True if the client should be skipped, false otherwise.
263
+ */
264
+ skip(client: MosaicClient | null | undefined, clause: SelectionClause): boolean {
265
+ return this._resolver.skip(client, clause);
266
+ }
267
+
268
+ /**
269
+ * Return a selection query predicate for the given client.
270
+ * @param client The client whose data may be filtered. If null or undefined, return a predicate with all clauses.
271
+ * @param noSkip Disable skipping of active
272
+ * cross-filtered sources. If set true, the source of the active
273
+ * clause in a cross-filtered selection will not be skipped.
274
+ * @returns The query predicate for filtering client data,
275
+ * based on the current state of this selection.
276
+ */
277
+ predicate(client: MosaicClient | null | undefined = undefined, noSkip: boolean = false): ResolvedPredicate {
278
+ const { clauses } = this;
279
+ const active = noSkip ? null : clauses.active;
280
+ return this._resolver.predicate(clauses, active!, client);
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Implements selection clause resolution strategies.
286
+ */
287
+ export class SelectionResolver {
288
+ union: boolean;
289
+ cross: boolean;
290
+ single: boolean;
291
+ empty: boolean;
292
+
293
+ /**
294
+ * Create a new selection resolved instance.
295
+ * @param options The resolution strategy options.
296
+ * @param options.union Boolean flag to indicate a union strategy.
297
+ * If false, an intersection strategy is used.
298
+ * @param options.cross Boolean flag to indicate cross-filtering.
299
+ * @param options.single Boolean flag to indicate single clauses only.
300
+ * @param options.empty Boolean flag indicating if a lack
301
+ * of clauses should correspond to an empty selection with no records. This
302
+ * setting determines the default selection state.
303
+ */
304
+ constructor({ union, cross, single, empty }: SelectionResolverOptions = {}) {
305
+ this.union = !!union;
306
+ this.cross = !!cross;
307
+ this.single = !!single;
308
+ this.empty = !!empty;
309
+ }
310
+
311
+ /**
312
+ * Resolve a list of selection clauses according to the resolution strategy.
313
+ * @param clauseList An array of selection clauses.
314
+ * @param clause A new selection clause to add.
315
+ * @returns An updated array of selection clauses.
316
+ */
317
+ resolve(
318
+ clauseList: SelectionClause[],
319
+ clause: SelectionClause,
320
+ reset: boolean = false
321
+ ): SelectionClause[] {
322
+ const { source, predicate } = clause;
323
+ const filtered = clauseList.filter(c => source !== c.source);
324
+ const clauses = this.single ? [] : filtered;
325
+ if (this.single && reset) filtered.forEach(c => c.source?.reset?.());
326
+ if (predicate) clauses.push(clause);
327
+ return clauses;
328
+ }
329
+
330
+ /**
331
+ * Indicates if a selection clause should not be applied to a given client.
332
+ * The return value depends on the resolution strategy.
333
+ * @param client The client to test. If null or undefined, return false.
334
+ * @param clause The selection clause.
335
+ * @returns True if the client should be skipped, false otherwise.
336
+ */
337
+ skip(client: MosaicClient | null | undefined, clause: SelectionClause): boolean {
338
+ if (client == null) {
339
+ return false;
340
+ }
341
+ return Boolean(this.cross && clause?.clients?.has(client));
342
+ }
343
+
344
+ /**
345
+ * Return a selection query predicate for the given client.
346
+ * @param clauseList An array of selection clauses.
347
+ * @param active The current active selection clause.
348
+ * @param client The client whose data may be filtered. If null or undefined, return all clauses.
349
+ * @returns The query predicate for filtering client data,
350
+ * based on the current state of this selection.
351
+ */
352
+ predicate(
353
+ clauseList: SelectionClause[],
354
+ active: SelectionClause,
355
+ client: MosaicClient | null | undefined
356
+ ): ResolvedPredicate {
357
+ const { empty, union } = this;
358
+
359
+ if (empty && !clauseList.length) {
360
+ return [literal(false)];
361
+ }
362
+
363
+ // do nothing if cross-filtering and client is currently active
364
+ if (this.skip(client, active)) return undefined;
365
+
366
+ // remove client-specific predicates if cross-filtering
367
+ const predicates: FilterExpr = clauseList
368
+ .filter(clause => !this.skip(client, clause))
369
+ .map(clause => clause.predicate!);
370
+
371
+ // return appropriate conjunction or disjunction
372
+ // an array of predicates is implicitly conjunctive
373
+ return union && predicates.length > 1 ? or(predicates) : predicates;
374
+ }
375
+
376
+ /**
377
+ * Returns a filter function for queued selection updates.
378
+ * @param value The new event value that will be enqueued.
379
+ * @returns A dispatch queue filter
380
+ * function, or null if all unemitted event values should be filtered.
381
+ */
382
+ queueFilter(
383
+ value: SelectionClauseArray
384
+ ): ((value: SelectionClauseArray) => boolean) | null {
385
+ if (this.cross) {
386
+ const source = value.active?.source;
387
+ return value => value.active?.source !== source;
388
+ }
389
+ return null;
390
+ }
391
+ }