@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.
- package/LICENSE +47 -0
- package/README.md +0 -1
- package/dist/src/Coordinator.d.ts +159 -0
- package/dist/src/Coordinator.d.ts.map +1 -0
- package/dist/src/Coordinator.js +250 -0
- package/dist/src/Coordinator.js.map +1 -0
- package/dist/src/MosaicClient.d.ts +138 -0
- package/dist/src/MosaicClient.d.ts.map +1 -0
- package/dist/src/MosaicClient.js +214 -0
- package/dist/src/MosaicClient.js.map +1 -0
- package/dist/src/Param.d.ts +56 -0
- package/dist/src/Param.d.ts.map +1 -0
- package/dist/src/Param.js +89 -0
- package/dist/src/Param.js.map +1 -0
- package/dist/src/QueryConsolidator.d.ts +11 -0
- package/dist/src/QueryConsolidator.d.ts.map +1 -0
- package/dist/src/QueryConsolidator.js +249 -0
- package/dist/src/QueryConsolidator.js.map +1 -0
- package/dist/src/QueryManager.d.ts +77 -0
- package/dist/src/QueryManager.d.ts.map +1 -0
- package/dist/src/QueryManager.js +174 -0
- package/dist/src/QueryManager.js.map +1 -0
- package/dist/src/Selection.d.ts +222 -0
- package/dist/src/Selection.d.ts.map +1 -0
- package/dist/src/Selection.js +322 -0
- package/dist/src/Selection.js.map +1 -0
- package/dist/src/SelectionClause.d.ts +222 -0
- package/dist/src/SelectionClause.d.ts.map +1 -0
- package/dist/src/SelectionClause.js +168 -0
- package/dist/src/SelectionClause.js.map +1 -0
- package/dist/src/connectors/Connector.d.ts +26 -0
- package/dist/src/connectors/Connector.d.ts.map +1 -0
- package/dist/src/connectors/Connector.js +2 -0
- package/dist/src/connectors/Connector.js.map +1 -0
- package/dist/src/connectors/rest.d.ts +24 -0
- package/dist/src/connectors/rest.d.ts.map +1 -0
- package/dist/src/connectors/rest.js +37 -0
- package/dist/src/connectors/rest.js.map +1 -0
- package/dist/src/connectors/socket.d.ts +40 -0
- package/dist/src/connectors/socket.d.ts.map +1 -0
- package/dist/src/connectors/socket.js +115 -0
- package/dist/src/connectors/socket.js.map +1 -0
- package/dist/src/connectors/wasm.d.ts +56 -0
- package/dist/src/connectors/wasm.d.ts.map +1 -0
- package/dist/src/connectors/wasm.js +116 -0
- package/dist/src/connectors/wasm.js.map +1 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +8 -11
- package/dist/src/index.js.map +1 -0
- package/dist/src/make-client.d.ts +33 -0
- package/dist/src/make-client.d.ts.map +1 -0
- package/dist/src/make-client.js +52 -0
- package/dist/src/make-client.js.map +1 -0
- package/dist/src/preagg/PreAggregator.d.ts +150 -0
- package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
- package/dist/src/preagg/PreAggregator.js +382 -0
- package/dist/src/preagg/PreAggregator.js.map +1 -0
- package/dist/src/preagg/preagg-columns.d.ts +16 -0
- package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
- package/dist/src/preagg/preagg-columns.js +95 -0
- package/dist/src/preagg/preagg-columns.js.map +1 -0
- package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
- package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
- package/dist/src/preagg/sufficient-statistics.js +446 -0
- package/dist/src/preagg/sufficient-statistics.js.map +1 -0
- package/dist/src/types.d.ts +77 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/util/AsyncDispatch.d.ts +121 -0
- package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
- package/dist/src/util/AsyncDispatch.js +188 -0
- package/dist/src/util/AsyncDispatch.js.map +1 -0
- package/dist/src/util/cache.d.ts +19 -0
- package/dist/src/util/cache.d.ts.map +1 -0
- package/dist/src/util/cache.js +66 -0
- package/dist/src/util/cache.js.map +1 -0
- package/dist/src/util/decode-ipc.d.ts +12 -0
- package/dist/src/util/decode-ipc.d.ts.map +1 -0
- package/{src → dist/src}/util/decode-ipc.js +5 -6
- package/dist/src/util/decode-ipc.js.map +1 -0
- package/dist/src/util/distinct.d.ts +3 -0
- package/dist/src/util/distinct.d.ts.map +1 -0
- package/dist/src/util/distinct.js +16 -0
- package/dist/src/util/distinct.js.map +1 -0
- package/dist/src/util/field-info.d.ts +26 -0
- package/dist/src/util/field-info.d.ts.map +1 -0
- package/dist/src/util/field-info.js +91 -0
- package/dist/src/util/field-info.js.map +1 -0
- package/dist/src/util/hash.d.ts +2 -0
- package/dist/src/util/hash.d.ts.map +1 -0
- package/dist/src/util/hash.js +26 -0
- package/dist/src/util/hash.js.map +1 -0
- package/dist/src/util/is-activatable.d.ts +8 -0
- package/dist/src/util/is-activatable.d.ts.map +1 -0
- package/dist/src/util/is-activatable.js +10 -0
- package/dist/src/util/is-activatable.js.map +1 -0
- package/dist/src/util/is-arrow-table.d.ts +9 -0
- package/dist/src/util/is-arrow-table.d.ts.map +1 -0
- package/dist/src/util/is-arrow-table.js +11 -0
- package/dist/src/util/is-arrow-table.js.map +1 -0
- package/dist/src/util/js-type.d.ts +9 -0
- package/dist/src/util/js-type.d.ts.map +1 -0
- package/dist/src/util/js-type.js +59 -0
- package/dist/src/util/js-type.js.map +1 -0
- package/dist/src/util/priority-queue.d.ts +35 -0
- package/dist/src/util/priority-queue.d.ts.map +1 -0
- package/dist/src/util/priority-queue.js +81 -0
- package/dist/src/util/priority-queue.js.map +1 -0
- package/dist/src/util/query-result.d.ts +47 -0
- package/dist/src/util/query-result.d.ts.map +1 -0
- package/dist/src/util/query-result.js +83 -0
- package/dist/src/util/query-result.js.map +1 -0
- package/dist/src/util/synchronizer.d.ts +36 -0
- package/dist/src/util/synchronizer.d.ts.map +1 -0
- package/dist/src/util/synchronizer.js +52 -0
- package/dist/src/util/synchronizer.js.map +1 -0
- package/dist/src/util/throttle.d.ts +12 -0
- package/dist/src/util/throttle.d.ts.map +1 -0
- package/dist/src/util/throttle.js +51 -0
- package/dist/src/util/throttle.js.map +1 -0
- package/dist/src/util/to-data-columns.d.ts +22 -0
- package/dist/src/util/to-data-columns.d.ts.map +1 -0
- package/dist/src/util/to-data-columns.js +51 -0
- package/dist/src/util/to-data-columns.js.map +1 -0
- package/dist/src/util/void-logger.d.ts +13 -0
- package/dist/src/util/void-logger.d.ts.map +1 -0
- package/dist/src/util/void-logger.js +13 -0
- package/dist/src/util/void-logger.js.map +1 -0
- package/package.json +17 -11
- package/src/Coordinator.ts +396 -0
- package/src/{MosaicClient.js → MosaicClient.ts} +50 -43
- package/src/{Param.js → Param.ts} +29 -28
- package/src/{QueryConsolidator.js → QueryConsolidator.ts} +85 -62
- package/src/{QueryManager.js → QueryManager.ts} +61 -54
- package/src/Selection.ts +391 -0
- package/src/SelectionClause.ts +357 -0
- package/src/connectors/Connector.ts +6 -6
- package/src/connectors/rest.ts +56 -0
- package/src/connectors/{socket.js → socket.ts} +53 -42
- package/src/connectors/{wasm.js → wasm.ts} +52 -63
- package/src/index.ts +42 -0
- package/src/make-client.ts +93 -0
- package/src/preagg/{PreAggregator.js → PreAggregator.ts} +164 -145
- package/src/preagg/{preagg-columns.js → preagg-columns.ts} +27 -24
- package/src/preagg/{sufficient-statistics.js → sufficient-statistics.ts} +160 -110
- package/src/types.ts +24 -9
- package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
- package/src/util/{cache.js → cache.ts} +25 -15
- package/src/util/decode-ipc.ts +15 -0
- package/src/util/{distinct.js → distinct.ts} +3 -3
- package/src/util/{field-info.js → field-info.ts} +30 -31
- package/src/util/{hash.js → hash.ts} +4 -4
- package/src/util/is-activatable.ts +11 -0
- package/src/util/is-arrow-table.ts +12 -0
- package/src/util/{js-type.js → js-type.ts} +7 -5
- package/src/util/{priority-queue.js → priority-queue.ts} +32 -20
- package/src/util/{query-result.js → query-result.ts} +24 -17
- package/src/util/synchronizer.ts +56 -0
- package/src/util/throttle.ts +59 -0
- package/src/util/to-data-columns.ts +65 -0
- package/src/util/void-logger.ts +23 -0
- package/src/Coordinator.js +0 -313
- package/src/Selection.js +0 -380
- package/src/SelectionClause.js +0 -159
- package/src/connectors/rest.js +0 -38
- package/src/index-types.ts +0 -5
- package/src/make-client.js +0 -101
- package/src/util/is-activatable.js +0 -8
- package/src/util/is-arrow-table.js +0 -10
- package/src/util/selection-types.ts +0 -137
- package/src/util/synchronizer.js +0 -47
- package/src/util/throttle.js +0 -54
- package/src/util/to-data-columns.js +0 -60
- package/src/util/void-logger.js +0 -13
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -3
package/src/Selection.ts
ADDED
|
@@ -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
|
+
}
|