@uwdata/mosaic-core 0.16.2 → 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.
- package/LICENSE +1 -1
- package/README.md +0 -1
- package/dist/src/Coordinator.d.ts +147 -0
- package/dist/src/Coordinator.d.ts.map +1 -0
- package/dist/src/Coordinator.js +269 -0
- package/dist/src/Coordinator.js.map +1 -0
- package/dist/{types → src}/MosaicClient.d.ts +37 -42
- package/dist/src/MosaicClient.d.ts.map +1 -0
- package/dist/src/MosaicClient.js +213 -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 +319 -0
- package/dist/src/Selection.js.map +1 -0
- package/dist/src/SelectionClause.d.ts +192 -0
- package/dist/src/SelectionClause.d.ts.map +1 -0
- package/dist/src/SelectionClause.js +126 -0
- package/dist/src/SelectionClause.js.map +1 -0
- package/dist/{types → src}/connectors/Connector.d.ts +6 -5
- 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 +53 -0
- package/dist/src/connectors/wasm.d.ts.map +1 -0
- package/dist/src/connectors/wasm.js +113 -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/dist/src/index.js +25 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/make-client.d.ts +35 -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/{types → src}/preagg/PreAggregator.d.ts +64 -94
- 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/{types → src}/preagg/preagg-columns.d.ts +10 -8
- 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/{types → src}/types.d.ts +23 -9
- 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/{types → src}/util/AsyncDispatch.d.ts +53 -32
- 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/{types → src}/util/priority-queue.d.ts +12 -14
- 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 +15 -13
- package/src/Coordinator.ts +367 -0
- package/src/{MosaicClient.js → MosaicClient.ts} +49 -43
- package/src/{Param.js → Param.ts} +29 -28
- package/src/{QueryConsolidator.js → QueryConsolidator.ts} +81 -58
- package/src/{QueryManager.js → QueryManager.ts} +61 -54
- package/src/Selection.ts +388 -0
- package/src/SelectionClause.ts +275 -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} +46 -62
- package/src/{index.js → index.ts} +13 -1
- 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} +161 -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} +31 -32
- 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/dist/types/Coordinator.d.ts +0 -164
- package/dist/types/Param.d.ts +0 -47
- package/dist/types/QueryConsolidator.d.ts +0 -9
- package/dist/types/QueryManager.d.ts +0 -91
- package/dist/types/Selection.d.ts +0 -235
- package/dist/types/SelectionClause.d.ts +0 -105
- package/dist/types/connectors/rest.d.ts +0 -13
- package/dist/types/connectors/socket.d.ts +0 -100
- package/dist/types/connectors/wasm.d.ts +0 -135
- package/dist/types/index-types.d.ts +0 -4
- package/dist/types/index.d.ts +0 -19
- package/dist/types/make-client.d.ts +0 -78
- package/dist/types/preagg/sufficient-statistics.d.ts +0 -13
- package/dist/types/util/cache.d.ts +0 -17
- package/dist/types/util/decode-ipc.d.ts +0 -12
- package/dist/types/util/distinct.d.ts +0 -2
- package/dist/types/util/field-info.d.ts +0 -23
- package/dist/types/util/hash.d.ts +0 -1
- package/dist/types/util/is-activatable.d.ts +0 -6
- package/dist/types/util/is-arrow-table.d.ts +0 -8
- package/dist/types/util/js-type.d.ts +0 -7
- package/dist/types/util/query-result.d.ts +0 -44
- package/dist/types/util/selection-types.d.ts +0 -114
- package/dist/types/util/synchronizer.d.ts +0 -29
- package/dist/types/util/throttle.d.ts +0 -13
- package/dist/types/util/to-data-columns.d.ts +0 -29
- package/dist/types/util/void-logger.d.ts +0 -10
- package/jsconfig.json +0 -11
- package/src/Coordinator.js +0 -337
- 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 -4
- 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 -11
- package/vitest.config.ts +0 -3
package/src/Coordinator.js
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
/** @import { Connector } from './connectors/Connector.js' */
|
|
2
|
-
/** @import { PreAggregateOptions } from './preagg/PreAggregator.js' */
|
|
3
|
-
/** @import { QueryResult } from './util/query-result.js' */
|
|
4
|
-
/** @import { SelectionClause } from './util/selection-types.js' */
|
|
5
|
-
/** @import { MosaicClient } from './MosaicClient.js' */
|
|
6
|
-
/** @import { Selection } from './Selection.js' */
|
|
7
|
-
/** @import { Logger, QueryType } from './types.js' */
|
|
8
|
-
import { socketConnector } from './connectors/socket.js';
|
|
9
|
-
import { PreAggregator } from './preagg/PreAggregator.js';
|
|
10
|
-
import { voidLogger } from './util/void-logger.js';
|
|
11
|
-
import { QueryManager, Priority } from './QueryManager.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The singleton Coordinator instance.
|
|
15
|
-
* @type {Coordinator}
|
|
16
|
-
*/
|
|
17
|
-
let _instance;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Set or retrieve the coordinator instance.
|
|
21
|
-
* @param {Coordinator} [instance] the coordinator instance to set
|
|
22
|
-
* @returns {Coordinator} the coordinator instance
|
|
23
|
-
*/
|
|
24
|
-
export function coordinator(instance) {
|
|
25
|
-
if (instance) {
|
|
26
|
-
_instance = instance;
|
|
27
|
-
} else if (_instance == null) {
|
|
28
|
-
_instance = new Coordinator();
|
|
29
|
-
}
|
|
30
|
-
return _instance;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A Mosaic Coordinator manages all database communication for clients and
|
|
35
|
-
* handles selection updates. The Coordinator also performs optimizations
|
|
36
|
-
* including query caching, consolidation, and pre-aggregation.
|
|
37
|
-
*/
|
|
38
|
-
export class Coordinator {
|
|
39
|
-
/**
|
|
40
|
-
* @param {Connector} [db] Database connector. Defaults to a web socket connection.
|
|
41
|
-
* @param {object} [options] Coordinator options.
|
|
42
|
-
* @param {Logger} [options.logger=console] The logger to use, defaults to `console`.
|
|
43
|
-
* @param {QueryManager} [options.manager] The query manager to use.
|
|
44
|
-
* @param {boolean} [options.cache=true] Boolean flag to enable/disable query caching.
|
|
45
|
-
* @param {boolean} [options.consolidate=true] Boolean flag to enable/disable query consolidation.
|
|
46
|
-
* @param {PreAggregateOptions} [options.preagg] Options for the Pre-aggregator.
|
|
47
|
-
*/
|
|
48
|
-
constructor(db = socketConnector(), {
|
|
49
|
-
logger = console,
|
|
50
|
-
manager = new QueryManager(),
|
|
51
|
-
cache = true,
|
|
52
|
-
consolidate = true,
|
|
53
|
-
preagg = {}
|
|
54
|
-
} = {}) {
|
|
55
|
-
/** @type {QueryManager} */
|
|
56
|
-
this.manager = manager;
|
|
57
|
-
this.manager.cache(cache);
|
|
58
|
-
this.manager.consolidate(consolidate);
|
|
59
|
-
this.databaseConnector(db);
|
|
60
|
-
this.logger(logger);
|
|
61
|
-
this.clear();
|
|
62
|
-
this.preaggregator = new PreAggregator(this, preagg);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Clear the coordinator state.
|
|
67
|
-
* @param {object} [options] Options object.
|
|
68
|
-
* @param {boolean} [options.clients=true] If true, disconnect all clients.
|
|
69
|
-
* @param {boolean} [options.cache=true] If true, clear the query cache.
|
|
70
|
-
*/
|
|
71
|
-
clear({ clients = true, cache = true } = {}) {
|
|
72
|
-
this.manager.clear();
|
|
73
|
-
if (clients) {
|
|
74
|
-
this.filterGroups?.forEach(group => group.disconnect());
|
|
75
|
-
this.filterGroups = new Map;
|
|
76
|
-
this.clients?.forEach(client => this.disconnect(client));
|
|
77
|
-
this.clients = new Set;
|
|
78
|
-
}
|
|
79
|
-
if (cache) this.manager.cache().clear();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Get or set the database connector.
|
|
84
|
-
* @param {Connector} [db] The database connector to use.
|
|
85
|
-
* @returns {Connector} The current database connector.
|
|
86
|
-
*/
|
|
87
|
-
databaseConnector(db) {
|
|
88
|
-
return this.manager.connector(db);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get or set the logger.
|
|
93
|
-
* @param {Logger} [logger] The logger to use.
|
|
94
|
-
* @returns {Logger} The current logger
|
|
95
|
-
*/
|
|
96
|
-
logger(logger) {
|
|
97
|
-
if (arguments.length) {
|
|
98
|
-
this._logger = logger || voidLogger();
|
|
99
|
-
this.manager.logger(this._logger);
|
|
100
|
-
}
|
|
101
|
-
return this._logger;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// -- Query Management ----
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Cancel previosuly submitted query requests. These queries will be
|
|
108
|
-
* canceled if they are queued but have not yet been submitted.
|
|
109
|
-
* @param {QueryResult[]} requests An array
|
|
110
|
-
* of query result objects, such as those returned by the `query` method.
|
|
111
|
-
*/
|
|
112
|
-
cancel(requests) {
|
|
113
|
-
this.manager.cancel(requests);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Issue a query for which no result (return value) is needed.
|
|
118
|
-
* @param {QueryType[] | QueryType} query The query or an array of queries.
|
|
119
|
-
* Each query should be either a Query builder object or a SQL string.
|
|
120
|
-
* @param {object} [options] An options object.
|
|
121
|
-
* @param {number} [options.priority] The query priority, defaults to
|
|
122
|
-
* `Priority.Normal`.
|
|
123
|
-
* @returns {QueryResult} A query result promise.
|
|
124
|
-
*/
|
|
125
|
-
exec(query, { priority = Priority.Normal } = {}) {
|
|
126
|
-
query = Array.isArray(query) ? query.filter(x => x).join(';\n') : query;
|
|
127
|
-
return this.manager.request({ type: 'exec', query }, priority);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Issue a query to the backing database. The submitted query may be
|
|
132
|
-
* consolidate with other queries and its results may be cached.
|
|
133
|
-
* @param {QueryType} query The query as either a Query builder objec
|
|
134
|
-
* or a SQL string.
|
|
135
|
-
* @param {object} [options] An options object.
|
|
136
|
-
* @param {'arrow' | 'json'} [options.type] The query result format type.
|
|
137
|
-
* @param {boolean} [options.cache=true] If true, cache the query result
|
|
138
|
-
* client-side within the QueryManager.
|
|
139
|
-
* @param {boolean} [options.persist] If true, request the database
|
|
140
|
-
* server to persist a cached query server-side.
|
|
141
|
-
* @param {number} [options.priority] The query priority, defaults to
|
|
142
|
-
* `Priority.Normal`.
|
|
143
|
-
* @returns {QueryResult} A query result promise.
|
|
144
|
-
*/
|
|
145
|
-
query(query, {
|
|
146
|
-
type = 'arrow',
|
|
147
|
-
cache = true,
|
|
148
|
-
priority = Priority.Normal,
|
|
149
|
-
...options
|
|
150
|
-
} = {}) {
|
|
151
|
-
return this.manager.request({ type, query, cache, options }, priority);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Issue a query to prefetch data for later use. The query result is cached
|
|
156
|
-
* for efficient future access.
|
|
157
|
-
* @param {QueryType} query The query as either a Query builder object
|
|
158
|
-
* or a SQL string.
|
|
159
|
-
* @param {object} [options] An options object.
|
|
160
|
-
* @param {'arrow' | 'json'} [options.type] The query result format type.
|
|
161
|
-
* @returns {QueryResult} A query result promise.
|
|
162
|
-
*/
|
|
163
|
-
prefetch(query, options = {}) {
|
|
164
|
-
return this.query(query, { ...options, cache: true, priority: Priority.Low });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Create a bundle of queries that can be loaded into the cache.
|
|
169
|
-
*
|
|
170
|
-
* @param {string} name The name of the bundle.
|
|
171
|
-
* @param {[string | {sql: string}, {alias: string}]} queries The queries to save into the bundle.
|
|
172
|
-
* @param {number} priority Request priority.
|
|
173
|
-
* @returns {QueryResult} A query result promise.
|
|
174
|
-
*/
|
|
175
|
-
createBundle(name, queries, priority = Priority.Low) {
|
|
176
|
-
const options = { name, queries: queries.map(q => typeof q == 'string' ? {sql: q} : q) };
|
|
177
|
-
return this.manager.request({ type: 'create-bundle', options }, priority);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Load a bundle into the cache.
|
|
182
|
-
* @param {string} name The name of the bundle.
|
|
183
|
-
* @param {number} priority Request priority.
|
|
184
|
-
* @returns {QueryResult} A query result promise.
|
|
185
|
-
*/
|
|
186
|
-
loadBundle(name, priority = Priority.High) {
|
|
187
|
-
const options = { name };
|
|
188
|
-
return this.manager.request({ type: 'load-bundle', options }, priority);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// -- Client Management ----
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Update client data by submitting the given query and returning the
|
|
195
|
-
* data (or error) to the client.
|
|
196
|
-
* @param {MosaicClient} client A Mosaic client.
|
|
197
|
-
* @param {QueryType} query The data query.
|
|
198
|
-
* @param {number} [priority] The query priority.
|
|
199
|
-
* @returns {Promise} A Promise that resolves upon completion of the update.
|
|
200
|
-
*/
|
|
201
|
-
updateClient(client, query, priority = Priority.Normal) {
|
|
202
|
-
client.queryPending();
|
|
203
|
-
return client._pending = this.query(query, { priority })
|
|
204
|
-
.then(
|
|
205
|
-
data => client.queryResult(data).update(),
|
|
206
|
-
err => { this._logger.error(err); client.queryError(err); }
|
|
207
|
-
)
|
|
208
|
-
.catch(err => this._logger.error(err));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Issue a query request for a client. If the query is null or undefined,
|
|
213
|
-
* the client is simply updated. Otherwise `updateClient` is called. As a
|
|
214
|
-
* side effect, this method clears the current preaggregator state.
|
|
215
|
-
* @param {MosaicClient} client The client to update.
|
|
216
|
-
* @param {QueryType | null} [query] The query to issue.
|
|
217
|
-
*/
|
|
218
|
-
requestQuery(client, query) {
|
|
219
|
-
this.preaggregator.clear();
|
|
220
|
-
return query
|
|
221
|
-
? this.updateClient(client, query)
|
|
222
|
-
: Promise.resolve(client.update());
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Connect a client to the coordinator.
|
|
227
|
-
* @param {MosaicClient} client The Mosaic client to connect.
|
|
228
|
-
*/
|
|
229
|
-
connect(client) {
|
|
230
|
-
const { clients } = this;
|
|
231
|
-
|
|
232
|
-
if (clients.has(client)) {
|
|
233
|
-
throw new Error('Client already connected.');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// add client to client set
|
|
237
|
-
clients.add(client);
|
|
238
|
-
|
|
239
|
-
// register coordinator on client instance
|
|
240
|
-
client.coordinator = this;
|
|
241
|
-
|
|
242
|
-
// initialize client lifecycle
|
|
243
|
-
client.initialize();
|
|
244
|
-
|
|
245
|
-
// connect filter selection
|
|
246
|
-
connectSelection(this, client.filterBy, client);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Disconnect a client from the coordinator.
|
|
251
|
-
* @param {MosaicClient} client The Mosaic client to disconnect.
|
|
252
|
-
*/
|
|
253
|
-
disconnect(client) {
|
|
254
|
-
const { clients, filterGroups } = this;
|
|
255
|
-
if (!clients.has(client)) return;
|
|
256
|
-
clients.delete(client);
|
|
257
|
-
client.coordinator = null;
|
|
258
|
-
|
|
259
|
-
const group = filterGroups.get(client.filterBy);
|
|
260
|
-
if (group) {
|
|
261
|
-
group.clients.delete(client);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Connect a selection-client pair to the coordinator to process updates.
|
|
268
|
-
* @param {Coordinator} mc The Mosaic coordinator.
|
|
269
|
-
* @param {Selection} selection A selection.
|
|
270
|
-
* @param {MosaicClient} client A Mosiac client that is filtered by the
|
|
271
|
-
* given selection.
|
|
272
|
-
*/
|
|
273
|
-
function connectSelection(mc, selection, client) {
|
|
274
|
-
if (!selection) return;
|
|
275
|
-
let entry = mc.filterGroups.get(selection);
|
|
276
|
-
if (!entry) {
|
|
277
|
-
const activate = clause => activateSelection(mc, selection, clause);
|
|
278
|
-
const value = () => updateSelection(mc, selection);
|
|
279
|
-
|
|
280
|
-
selection.addEventListener('activate', activate);
|
|
281
|
-
selection.addEventListener('value', value);
|
|
282
|
-
|
|
283
|
-
entry = {
|
|
284
|
-
selection,
|
|
285
|
-
clients: new Set,
|
|
286
|
-
disconnect() {
|
|
287
|
-
selection.removeEventListener('activate', activate);
|
|
288
|
-
selection.removeEventListener('value', value);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
mc.filterGroups.set(selection, entry);
|
|
292
|
-
}
|
|
293
|
-
entry.clients.add(client);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Activate a selection, providing a clause indicative of potential
|
|
298
|
-
* next updates. Activation provides a preview of likely next events,
|
|
299
|
-
* enabling potential precomputation to optimize updates.
|
|
300
|
-
* @param {Coordinator} mc The Mosaic coordinator.
|
|
301
|
-
* @param {Selection} selection A selection.
|
|
302
|
-
* @param {SelectionClause} clause A selection clause for the activation.
|
|
303
|
-
*/
|
|
304
|
-
function activateSelection(mc, selection, clause) {
|
|
305
|
-
const { preaggregator, filterGroups } = mc;
|
|
306
|
-
const { clients } = filterGroups.get(selection);
|
|
307
|
-
for (const client of clients) {
|
|
308
|
-
if (client.enabled) {
|
|
309
|
-
preaggregator.request(client, selection, clause);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Process an updated selection value, querying filtered data for any
|
|
316
|
-
* associated clients.
|
|
317
|
-
* @param {Coordinator} mc The Mosaic coordinator.
|
|
318
|
-
* @param {Selection} selection A selection.
|
|
319
|
-
* @returns {Promise} A Promise that resolves when the update completes.
|
|
320
|
-
*/
|
|
321
|
-
function updateSelection(mc, selection) {
|
|
322
|
-
const { preaggregator, filterGroups } = mc;
|
|
323
|
-
const { clients } = filterGroups.get(selection);
|
|
324
|
-
const { active } = selection;
|
|
325
|
-
return Promise.allSettled(Array.from(clients, client => {
|
|
326
|
-
if (!client.enabled) return client.requestQuery();
|
|
327
|
-
const info = preaggregator.request(client, selection, active);
|
|
328
|
-
const filter = info ? null : selection.predicate(client);
|
|
329
|
-
|
|
330
|
-
// skip due to cross-filtering
|
|
331
|
-
if (info?.skip || (!info && !filter)) return;
|
|
332
|
-
|
|
333
|
-
// @ts-ignore
|
|
334
|
-
const query = info?.query(active.predicate) ?? client.query(filter);
|
|
335
|
-
return mc.updateClient(client, query);
|
|
336
|
-
}));
|
|
337
|
-
}
|