@uwdata/mosaic-core 0.17.0 → 0.18.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 +147 -0
  4. package/dist/src/Coordinator.d.ts.map +1 -0
  5. package/dist/src/Coordinator.js +269 -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 +213 -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 +319 -0
  26. package/dist/src/Selection.js.map +1 -0
  27. package/dist/src/SelectionClause.d.ts +192 -0
  28. package/dist/src/SelectionClause.d.ts.map +1 -0
  29. package/dist/src/SelectionClause.js +126 -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 +53 -0
  44. package/dist/src/connectors/wasm.d.ts.map +1 -0
  45. package/dist/src/connectors/wasm.js +113 -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/dist/src/index.js +25 -0
  50. package/dist/src/index.js.map +1 -0
  51. package/dist/src/make-client.d.ts +35 -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 +16 -10
  132. package/src/Coordinator.ts +367 -0
  133. package/src/{MosaicClient.js → MosaicClient.ts} +49 -43
  134. package/src/{Param.js → Param.ts} +29 -28
  135. package/src/{QueryConsolidator.js → QueryConsolidator.ts} +81 -58
  136. package/src/{QueryManager.js → QueryManager.ts} +61 -54
  137. package/src/Selection.ts +388 -0
  138. package/src/SelectionClause.ts +275 -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} +46 -62
  143. package/src/{index.js → index.ts} +13 -1
  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} +31 -32
  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,319 @@
1
+ import { literal, or } from '@uwdata/mosaic-sql';
2
+ import { Param } from './Param.js';
3
+ /**
4
+ * Test if a value is a Selection instance.
5
+ * @param x The value to test.
6
+ * @returns True if the input is a Selection, false otherwise.
7
+ */
8
+ export function isSelection(x) {
9
+ return x instanceof Selection;
10
+ }
11
+ function create(options, include) {
12
+ return new Selection(new SelectionResolver(options), include ? [include].flat() : undefined);
13
+ }
14
+ /**
15
+ * Represents a dynamic set of query filter predicates.
16
+ */
17
+ export class Selection extends Param {
18
+ _resolved;
19
+ _resolver;
20
+ _relay;
21
+ /**
22
+ * Create a new Selection instance with an
23
+ * intersect (conjunction) resolution strategy.
24
+ * @param options The selection options.
25
+ * @returns The new Selection instance.
26
+ */
27
+ static intersect({ cross = false, empty = false, include = [] } = {}) {
28
+ return create({ cross, empty }, include);
29
+ }
30
+ /**
31
+ * Create a new Selection instance with a
32
+ * union (disjunction) resolution strategy.
33
+ * @param options The selection options.
34
+ * @returns The new Selection instance.
35
+ */
36
+ static union({ cross = false, empty = false, include = [] } = {}) {
37
+ return create({ cross, empty, union: true }, include);
38
+ }
39
+ /**
40
+ * Create a new Selection instance with a singular resolution strategy
41
+ * that keeps only the most recent selection clause.
42
+ * @param options The selection options.
43
+ * @returns The new Selection instance.
44
+ */
45
+ static single({ cross = false, empty = false, include = [] } = {}) {
46
+ return create({ cross, empty, single: true }, include);
47
+ }
48
+ /**
49
+ * Create a new Selection instance with a
50
+ * cross-filtered intersect resolution strategy.
51
+ * @param options The selection options.
52
+ * @returns The new Selection instance.
53
+ */
54
+ static crossfilter({ empty = false, include = [] } = {}) {
55
+ return create({ cross: true, empty }, include);
56
+ }
57
+ /**
58
+ * Create a new Selection instance.
59
+ * @param resolver The selection resolution
60
+ * strategy to apply.
61
+ * @param include Upstream selections whose clauses
62
+ * should be included as part of this selection. Any clauses published
63
+ * to these upstream selections will be relayed to this selection.
64
+ */
65
+ constructor(resolver = new SelectionResolver(), include = []) {
66
+ super([]);
67
+ this._resolved = this._value;
68
+ this._resolver = resolver;
69
+ this._relay = new Set();
70
+ if (Array.isArray(include)) {
71
+ for (const sel of include) {
72
+ sel._relay.add(this);
73
+ }
74
+ }
75
+ }
76
+ /**
77
+ * Create a cloned copy of this Selection instance.
78
+ * @returns A clone of this selection.
79
+ */
80
+ clone() {
81
+ const s = new Selection(this._resolver);
82
+ s._value = s._resolved = this._value;
83
+ return s;
84
+ }
85
+ /**
86
+ * Create a clone of this Selection with clauses corresponding
87
+ * to the provided source removed.
88
+ * @param source The clause source to remove.
89
+ * @returns A cloned and updated Selection.
90
+ */
91
+ remove(source) {
92
+ const s = this.clone();
93
+ s._value = s._resolved = s._resolver.resolve(this._resolved, { source });
94
+ s._value.active = { source };
95
+ return s;
96
+ }
97
+ /**
98
+ * The selection clause resolver.
99
+ */
100
+ get resolver() {
101
+ return this._resolver;
102
+ }
103
+ /**
104
+ * Indicate if this selection has a single resolution strategy.
105
+ */
106
+ get single() {
107
+ return this._resolver.single;
108
+ }
109
+ /**
110
+ * The current array of selection clauses.
111
+ */
112
+ get clauses() {
113
+ return super.value;
114
+ }
115
+ /**
116
+ * The current active (most recently updated) selection clause.
117
+ */
118
+ get active() {
119
+ return this.clauses.active;
120
+ }
121
+ /**
122
+ * The value corresponding to the current active selection clause.
123
+ * This method ensures compatibility where a normal Param is expected.
124
+ */
125
+ // @ts-expect-error return type differs from Param parent class
126
+ get value() {
127
+ return this.active?.value;
128
+ }
129
+ /**
130
+ * The value corresponding to a given source. Returns undefined if
131
+ * this selection does not include a clause from this source.
132
+ * @param source The clause source to look up the value for.
133
+ */
134
+ valueFor(source) {
135
+ return this.clauses.find(c => c.source === source)?.value;
136
+ }
137
+ /**
138
+ * Emit an activate event with the given selection clause.
139
+ * @param clause The clause representing the potential activation.
140
+ */
141
+ activate(clause) {
142
+ // @ts-expect-error selection operates differently than scalar param
143
+ this.emit('activate', clause);
144
+ this._relay.forEach(sel => sel.activate(clause));
145
+ }
146
+ /**
147
+ * Update the selection with a new selection clause.
148
+ * @param clause The selection clause to add.
149
+ * @returns This Selection instance.
150
+ */
151
+ // @ts-expect-error selection and param use differing value types
152
+ update(clause) {
153
+ // we maintain an up-to-date list of all resolved clauses
154
+ // this ensures consistent clause state across unemitted event values
155
+ this._resolved = this._resolver.resolve(this._resolved, clause, true);
156
+ this._resolved.active = clause;
157
+ this._relay.forEach(sel => sel.update(clause));
158
+ return super.update(this._resolved);
159
+ }
160
+ /**
161
+ * Reset the selection state by removing all provided clauses. If no clause
162
+ * array is provided as an argument, all current clauses are removed. The
163
+ * reset method (if defined) is invoked on all corresponding clause sources.
164
+ * The reset is relayed to downstream selections that include this selection.
165
+ * @param clauses The clauses to remove. If unspecified, all current clauses are removed.
166
+ * @returns This selection instance.
167
+ */
168
+ reset(clauses) {
169
+ clauses ??= this._resolved;
170
+ clauses.forEach(c => c.source?.reset?.());
171
+ this._resolved = this._resolved.filter(c => clauses.includes(c));
172
+ this._relay.forEach(sel => sel.reset(clauses));
173
+ return super.update(this._resolved = []);
174
+ }
175
+ /**
176
+ * Upon value-typed updates, sets the current clause list to the
177
+ * input value and returns the active clause value.
178
+ * @param type The event type.
179
+ * @param value The input event value.
180
+ * @returns For value-typed events, returns the active clause
181
+ * values. Otherwise returns the input event value as-is.
182
+ */
183
+ // @ts-expect-error selection and param use differing value types
184
+ willEmit(type, value) {
185
+ if (type === 'value') {
186
+ this._value = value;
187
+ return this.value;
188
+ }
189
+ return value;
190
+ }
191
+ /**
192
+ * Upon value-typed updates, returns a dispatch queue filter function.
193
+ * The return value depends on the selection resolution strategy.
194
+ * @param type The event type.
195
+ * @param value The new event value that will be enqueued.
196
+ * @returns A dispatch queue filter function. For non-value events,
197
+ * returns a function that always returns null (no filtering).
198
+ */
199
+ // @ts-expect-error selection and param use differing value types
200
+ emitQueueFilter(type, value) {
201
+ return type === 'value'
202
+ ? this._resolver.queueFilter(value)
203
+ : null;
204
+ }
205
+ /**
206
+ * Indicates if a selection clause should not be applied to a given client.
207
+ * The return value depends on the selection resolution strategy.
208
+ * @param client The client to test.
209
+ * @param clause The selection clause.
210
+ * @returns True if the client should be skipped, false otherwise.
211
+ */
212
+ skip(client, clause) {
213
+ return this._resolver.skip(client, clause);
214
+ }
215
+ /**
216
+ * Return a selection query predicate for the given client.
217
+ * @param client The client whose data may be filtered.
218
+ * @param noSkip Disable skipping of active
219
+ * cross-filtered sources. If set true, the source of the active
220
+ * clause in a cross-filtered selection will not be skipped.
221
+ * @returns The query predicate for filtering client data,
222
+ * based on the current state of this selection.
223
+ */
224
+ predicate(client, noSkip = false) {
225
+ const { clauses } = this;
226
+ const active = noSkip ? null : clauses.active;
227
+ return this._resolver.predicate(clauses, active, client);
228
+ }
229
+ }
230
+ /**
231
+ * Implements selection clause resolution strategies.
232
+ */
233
+ export class SelectionResolver {
234
+ union;
235
+ cross;
236
+ single;
237
+ empty;
238
+ /**
239
+ * Create a new selection resolved instance.
240
+ * @param options The resolution strategy options.
241
+ * @param options.union Boolean flag to indicate a union strategy.
242
+ * If false, an intersection strategy is used.
243
+ * @param options.cross Boolean flag to indicate cross-filtering.
244
+ * @param options.single Boolean flag to indicate single clauses only.
245
+ * @param options.empty Boolean flag indicating if a lack
246
+ * of clauses should correspond to an empty selection with no records. This
247
+ * setting determines the default selection state.
248
+ */
249
+ constructor({ union, cross, single, empty } = {}) {
250
+ this.union = !!union;
251
+ this.cross = !!cross;
252
+ this.single = !!single;
253
+ this.empty = !!empty;
254
+ }
255
+ /**
256
+ * Resolve a list of selection clauses according to the resolution strategy.
257
+ * @param clauseList An array of selection clauses.
258
+ * @param clause A new selection clause to add.
259
+ * @returns An updated array of selection clauses.
260
+ */
261
+ resolve(clauseList, clause, reset = false) {
262
+ const { source, predicate } = clause;
263
+ const filtered = clauseList.filter(c => source !== c.source);
264
+ const clauses = this.single ? [] : filtered;
265
+ if (this.single && reset)
266
+ filtered.forEach(c => c.source?.reset?.());
267
+ if (predicate)
268
+ clauses.push(clause);
269
+ return clauses;
270
+ }
271
+ /**
272
+ * Indicates if a selection clause should not be applied to a given client.
273
+ * The return value depends on the resolution strategy.
274
+ * @param client The selection clause.
275
+ * @param clause The client to test.
276
+ * @returns True if the client should be skipped, false otherwise.
277
+ */
278
+ skip(client, clause) {
279
+ return Boolean(this.cross && clause?.clients?.has(client));
280
+ }
281
+ /**
282
+ * Return a selection query predicate for the given client.
283
+ * @param clauseList An array of selection clauses.
284
+ * @param active The current active selection clause.
285
+ * @param client The client whose data may be filtered.
286
+ * @returns The query predicate for filtering client data,
287
+ * based on the current state of this selection.
288
+ */
289
+ predicate(clauseList, active, client) {
290
+ const { empty, union } = this;
291
+ if (empty && !clauseList.length) {
292
+ return [literal(false)];
293
+ }
294
+ // do nothing if cross-filtering and client is currently active
295
+ if (this.skip(client, active))
296
+ return undefined;
297
+ // remove client-specific predicates if cross-filtering
298
+ const predicates = clauseList
299
+ .filter(clause => !this.skip(client, clause))
300
+ .map(clause => clause.predicate);
301
+ // return appropriate conjunction or disjunction
302
+ // an array of predicates is implicitly conjunctive
303
+ return union && predicates.length > 1 ? or(predicates) : predicates;
304
+ }
305
+ /**
306
+ * Returns a filter function for queued selection updates.
307
+ * @param value The new event value that will be enqueued.
308
+ * @returns A dispatch queue filter
309
+ * function, or null if all unemitted event values should be filtered.
310
+ */
311
+ queueFilter(value) {
312
+ if (this.cross) {
313
+ const source = value.active?.source;
314
+ return value => value.active?.source !== source;
315
+ }
316
+ return null;
317
+ }
318
+ }
319
+ //# sourceMappingURL=Selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Selection.js","sourceRoot":"","sources":["../../src/Selection.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,OAAO,EAAc,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAmBnC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,OAAO,CAAC,YAAY,SAAS,CAAC;AAChC,CAAC;AAED,SAAS,MAAM,CAAC,OAAiC,EAAE,OAAiC;IAClF,OAAO,IAAI,SAAS,CAClB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CACvC,CAAC;AACJ,CAAC;AAKD;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAA2B;IACxD,SAAS,CAAuB;IAChC,SAAS,CAAoB;IAC7B,MAAM,CAAiB;IAEvB;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,OAAO,GAAG,EAAE,KAAuB,EAAE;QACpF,OAAO,MAAM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Ae,UAAU;aACtC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aAC5C,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,SAAU,CAAC,CAAC;QAEpC,gDAAgD;QAChD,mDAAmD;QACnD,OAAO,KAAK,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IACtE,CAAC;IAED;;;;;OAKG;IACH,WAAW,CACT,KAA2B;QAE3B,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;YACpC,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;QAClD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,192 @@
1
+ import { MosaicClient } from './MosaicClient.js';
2
+ import { type ExprNode, type ExprValue, type ScaleOptions, type ScaleDomain, contains, prefix, regexp_matches, suffix } from '@uwdata/mosaic-sql';
3
+ /**
4
+ * Selection clause metadata to guide possible query optimizations.
5
+ * Sub-interfaces provide more information about the specifics of a
6
+ * given selection based on the selection type.
7
+ */
8
+ export interface ClauseMetadata {
9
+ /**
10
+ * The selection type, such as `'point'`, `'interval'`, or `'match'`.
11
+ */
12
+ type: string;
13
+ }
14
+ /**
15
+ * Selection clause metadata indicating selection of one or more discrete
16
+ * point values, typically based on equality or is distinctiveness checks.
17
+ */
18
+ export interface PointMetadata extends ClauseMetadata {
19
+ type: 'point';
20
+ }
21
+ /**
22
+ * Selection clause metadata indicating text search matching.
23
+ */
24
+ export interface MatchMetadata extends ClauseMetadata {
25
+ type: MatchMethod;
26
+ /** The text search matching method used. */
27
+ method?: 'contains' | 'prefix' | 'suffix' | 'regexp' | (string & {});
28
+ }
29
+ /** A binning method name. */
30
+ export type BinMethod = 'floor' | 'ceil' | 'round';
31
+ /**
32
+ * Selection clause metadata for one or more selected intervals. This
33
+ * metadata can be used to determine appropriate data-space binning
34
+ * schemes that correspond to pixel-level bins in screen space.
35
+ */
36
+ export interface IntervalMetadata extends ClauseMetadata {
37
+ type: 'interval';
38
+ /**
39
+ * The interactive pixel size used by the generating component.
40
+ * Values larger than one indicate intervals that "snap-to" values
41
+ * greater than a single pixel. If unspecified, assumed to be `1`.
42
+ */
43
+ pixelSize?: number;
44
+ /**
45
+ * An array of one or more scale descriptors that describe the
46
+ * mapping from data values to screen pixels.
47
+ */
48
+ scales?: ScaleOptions[];
49
+ /**
50
+ * A hint for the binning method to use when discretizing the
51
+ * interval domain. If unspecified, the default is `'floor'`.
52
+ */
53
+ bin?: BinMethod;
54
+ }
55
+ export interface ClauseSource {
56
+ reset?: () => void;
57
+ }
58
+ /**
59
+ * A selection clause representing filtering criteria
60
+ * to apply within a Mosaic Selection.
61
+ */
62
+ export interface SelectionClause {
63
+ /**
64
+ * A unique identifier (according to object equality) for the source
65
+ * component that generated this clause. In many cases, this is a
66
+ * reference to the originating component itself.
67
+ */
68
+ source: ClauseSource;
69
+ /**
70
+ * A set of Mosaic clients associated with this clause that should not
71
+ * be updated when this clause is applied in a cross-filtering context.
72
+ */
73
+ clients?: Set<MosaicClient>;
74
+ /**
75
+ * A selected value associated with this clause. For example, for a 1D
76
+ * interval selection clause the value may be a [lo, hi] array.
77
+ */
78
+ value: unknown;
79
+ /**
80
+ * A predicate SQL expression suitable for use in a query WHERE clause.
81
+ * The predicate should apply filtering criteria consistent with this
82
+ * clause's *value* property.
83
+ */
84
+ predicate: ExprNode | null;
85
+ /**
86
+ * Optional clause metadata that varies based on the selection type.
87
+ * The metadata can be used to optimize selection queries, for example
88
+ * by creating materialized views of pre-aggregated data when applicable.
89
+ */
90
+ meta?: ClauseMetadata;
91
+ }
92
+ /**
93
+ * Generate a selection clause for a single selected point value.
94
+ * @param field The table column or expression to select.
95
+ * @param value The selected value.
96
+ * @param options Additional clause properties.
97
+ * @param options.source The source component generating this clause.
98
+ * @param options.clients The Mosaic clients associated
99
+ * with this clause. These clients are not filtered by this clause in
100
+ * cross-filtering contexts.
101
+ * @returns The generated selection clause.
102
+ */
103
+ export declare function clausePoint(field: ExprValue, value: unknown, { source, clients }: {
104
+ source: ClauseSource;
105
+ clients?: Set<MosaicClient>;
106
+ }): SelectionClause;
107
+ /**
108
+ * Generate a selection clause for multiple selected point values.
109
+ * @param fields The table columns or expressions to select.
110
+ * @param value The selected values, as an array of
111
+ * arrays. Each subarray contains values for each *fields* entry.
112
+ * @param options Additional clause properties.
113
+ * @param options.source The source component generating this clause.
114
+ * @param options.clients The Mosaic clients associated
115
+ * with this clause. These clients are not filtered by this clause in
116
+ * cross-filtering contexts.
117
+ * @returns The generated selection clause.
118
+ */
119
+ export declare function clausePoints(fields: ExprValue[], value: unknown[][] | null | undefined, { source, clients }: {
120
+ source: ClauseSource;
121
+ clients?: Set<MosaicClient>;
122
+ }): SelectionClause;
123
+ /**
124
+ * Generate a selection clause for a selected 1D interval.
125
+ * @param field The table column or expression to select.
126
+ * @param value The selected interval as a [lo, hi] array.
127
+ * @param options Additional clause properties.
128
+ * @param options.source The source component generating this clause.
129
+ * @param options.clients The Mosaic clients associated
130
+ * with this clause. These clients are not filtered by this clause in
131
+ * cross-filtering contexts.
132
+ * @param options.scale The scale mapping descriptor.
133
+ * @param options.bin A binning method hint.
134
+ * @param options.pixelSize The interactive pixel size.
135
+ * @returns The generated selection clause.
136
+ */
137
+ export declare function clauseInterval(field: ExprValue, value: ScaleDomain | null | undefined, { source, clients, bin, scale, pixelSize }: {
138
+ source: ClauseSource;
139
+ clients?: Set<MosaicClient>;
140
+ scale?: ScaleOptions;
141
+ bin?: BinMethod;
142
+ pixelSize?: number;
143
+ }): SelectionClause;
144
+ /**
145
+ * Generate a selection clause for multiple selected intervals.
146
+ * @param fields The table columns or expressions to select.
147
+ * @param value The selected intervals, as an array of extents.
148
+ * @param options Additional clause properties.
149
+ * @param options.source The source component generating this clause.
150
+ * @param options.clients The Mosaic clients associated
151
+ * with this clause. These clients are not filtered by this clause in
152
+ * cross-filtering contexts.
153
+ * @param options.scales The scale mapping descriptors,
154
+ * in an order matching the given *fields* and *value* extents.
155
+ * @param options.bin A binning method hint.
156
+ * @param options.pixelSize The interactive pixel size.
157
+ * @returns The generated selection clause.
158
+ */
159
+ export declare function clauseIntervals(fields: ExprValue[], value: ScaleDomain[] | null | undefined, { source, clients, bin, scales, pixelSize }: {
160
+ source: ClauseSource;
161
+ clients?: Set<MosaicClient>;
162
+ scales?: ScaleOptions[];
163
+ bin?: BinMethod;
164
+ pixelSize?: number;
165
+ }): SelectionClause;
166
+ declare const MATCH_METHODS: {
167
+ contains: typeof contains;
168
+ prefix: typeof prefix;
169
+ suffix: typeof suffix;
170
+ regexp: typeof regexp_matches;
171
+ };
172
+ /** Text search matching methods. */
173
+ export type MatchMethod = keyof typeof MATCH_METHODS | (string & {});
174
+ /**
175
+ * Generate a selection clause for text search matching.
176
+ * @param field The table column or expression to select.
177
+ * @param value The selected text search query string.
178
+ * @param options Additional clause properties.
179
+ * @param options.source The source component generating this clause.
180
+ * @param options.clients The Mosaic clients associated
181
+ * with this clause. These clients are not filtered by this clause in
182
+ * cross-filtering contexts.
183
+ * @param options.method The text matching method to use. Defaults to `'contains'`.
184
+ * @returns The generated selection clause.
185
+ */
186
+ export declare function clauseMatch(field: ExprValue, value: string | null | undefined, { source, clients, method }: {
187
+ source: ClauseSource;
188
+ clients?: Set<MosaicClient>;
189
+ method?: MatchMethod;
190
+ }): SelectionClause;
191
+ export {};
192
+ //# sourceMappingURL=SelectionClause.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectionClause.d.ts","sourceRoot":"","sources":["../../src/SelectionClause.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACj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AC,CAAC;IAC5B,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,eAAe,CAWlB;AAED,QAAA,MAAM,aAAa;;;;;CAAuD,CAAC;AAE3E,oCAAoC;AACpC,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,aAAa,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,EAC9E,MAAM,EACN,OAAmB,EACnB,MAAmB,EACpB,EAAE;IACD,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,eAAe,CAKlB"}
@@ -0,0 +1,126 @@
1
+ import { isMosaicClient } from './MosaicClient.js';
2
+ import { and, contains, isBetween, isIn, isNotDistinct, literal, or, prefix, regexp_matches, suffix } from '@uwdata/mosaic-sql';
3
+ /**
4
+ * Generate a selection clause for a single selected point value.
5
+ * @param field The table column or expression to select.
6
+ * @param value The selected value.
7
+ * @param options Additional clause properties.
8
+ * @param options.source The source component generating this clause.
9
+ * @param options.clients The Mosaic clients associated
10
+ * with this clause. These clients are not filtered by this clause in
11
+ * cross-filtering contexts.
12
+ * @returns The generated selection clause.
13
+ */
14
+ export function clausePoint(field, value, { source, clients = isMosaicClient(source) ? new Set([source]) : undefined }) {
15
+ const predicate = value !== undefined
16
+ ? isIn(field, [literal(value)])
17
+ : null;
18
+ return {
19
+ meta: { type: 'point' },
20
+ source,
21
+ clients,
22
+ value,
23
+ predicate
24
+ };
25
+ }
26
+ /**
27
+ * Generate a selection clause for multiple selected point values.
28
+ * @param fields The table columns or expressions to select.
29
+ * @param value The selected values, as an array of
30
+ * arrays. Each subarray contains values for each *fields* entry.
31
+ * @param options Additional clause properties.
32
+ * @param options.source The source component generating this clause.
33
+ * @param options.clients The Mosaic clients associated
34
+ * with this clause. These clients are not filtered by this clause in
35
+ * cross-filtering contexts.
36
+ * @returns The generated selection clause.
37
+ */
38
+ export function clausePoints(fields, value, { source, clients = isMosaicClient(source) ? new Set([source]) : undefined }) {
39
+ let predicate = null;
40
+ if (value) {
41
+ const clauses = value.length && fields.length === 1
42
+ ? [isIn(fields[0], value.map(v => literal(v[0])))]
43
+ : value.map(v => and(v.map((_, i) => isNotDistinct(fields[i], literal(_)))));
44
+ predicate = value.length === 0 ? literal(false)
45
+ : clauses.length > 1 ? or(clauses)
46
+ : clauses[0];
47
+ }
48
+ return {
49
+ meta: { type: 'point' },
50
+ source,
51
+ clients,
52
+ value,
53
+ predicate
54
+ };
55
+ }
56
+ /**
57
+ * Generate a selection clause for a selected 1D interval.
58
+ * @param field The table column or expression to select.
59
+ * @param value The selected interval as a [lo, hi] array.
60
+ * @param options Additional clause properties.
61
+ * @param options.source The source component generating this clause.
62
+ * @param options.clients The Mosaic clients associated
63
+ * with this clause. These clients are not filtered by this clause in
64
+ * cross-filtering contexts.
65
+ * @param options.scale The scale mapping descriptor.
66
+ * @param options.bin A binning method hint.
67
+ * @param options.pixelSize The interactive pixel size.
68
+ * @returns The generated selection clause.
69
+ */
70
+ export function clauseInterval(field, value, { source, clients = isMosaicClient(source) ? new Set([source]) : undefined, bin, scale, pixelSize = 1 }) {
71
+ const predicate = value != null ? isBetween(field, value) : null;
72
+ const meta = {
73
+ type: 'interval',
74
+ scales: scale && [scale],
75
+ bin,
76
+ pixelSize
77
+ };
78
+ return { meta, source, clients, value, predicate };
79
+ }
80
+ /**
81
+ * Generate a selection clause for multiple selected intervals.
82
+ * @param fields The table columns or expressions to select.
83
+ * @param value The selected intervals, as an array of extents.
84
+ * @param options Additional clause properties.
85
+ * @param options.source The source component generating this clause.
86
+ * @param options.clients The Mosaic clients associated
87
+ * with this clause. These clients are not filtered by this clause in
88
+ * cross-filtering contexts.
89
+ * @param options.scales The scale mapping descriptors,
90
+ * in an order matching the given *fields* and *value* extents.
91
+ * @param options.bin A binning method hint.
92
+ * @param options.pixelSize The interactive pixel size.
93
+ * @returns The generated selection clause.
94
+ */
95
+ export function clauseIntervals(fields, value, { source, clients = isMosaicClient(source) ? new Set([source]) : undefined, bin, scales = [], pixelSize = 1 }) {
96
+ const predicate = value != null
97
+ ? and(fields.map((f, i) => isBetween(f, value[i])))
98
+ : null;
99
+ const meta = {
100
+ type: 'interval',
101
+ scales,
102
+ bin,
103
+ pixelSize
104
+ };
105
+ return { meta, source, clients, value, predicate };
106
+ }
107
+ const MATCH_METHODS = { contains, prefix, suffix, regexp: regexp_matches };
108
+ /**
109
+ * Generate a selection clause for text search matching.
110
+ * @param field The table column or expression to select.
111
+ * @param value The selected text search query string.
112
+ * @param options Additional clause properties.
113
+ * @param options.source The source component generating this clause.
114
+ * @param options.clients The Mosaic clients associated
115
+ * with this clause. These clients are not filtered by this clause in
116
+ * cross-filtering contexts.
117
+ * @param options.method The text matching method to use. Defaults to `'contains'`.
118
+ * @returns The generated selection clause.
119
+ */
120
+ export function clauseMatch(field, value, { source, clients = undefined, method = 'contains' }) {
121
+ const fn = MATCH_METHODS[method];
122
+ const predicate = value ? fn(field, literal(value)) : null;
123
+ const meta = { type: 'match', method };
124
+ return { meta, source, clients, value, predicate };
125
+ }
126
+ //# sourceMappingURL=SelectionClause.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectionClause.js","sourceRoot":"","sources":["../../src/SelectionClause.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAgB,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAsE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;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