1
1
import { socketConnector } from './connectors/socket.js' ;
2
2
import { DataCubeIndexer } from './DataCubeIndexer.js' ;
3
+ import { MosaicClient } from './MosaicClient.js' ;
3
4
import { QueryManager , Priority } from './QueryManager.js' ;
4
5
import { queryFieldInfo } from './util/field-info.js' ;
6
+ import { QueryResult } from './util/query-result.js' ;
5
7
import { voidLogger } from './util/void-logger.js' ;
6
8
7
9
/**
@@ -24,6 +26,10 @@ export function coordinator(instance) {
24
26
return _instance ;
25
27
}
26
28
29
+ /**
30
+ * @typedef {import('@uwdata/mosaic-sql').Query | string } QueryType
31
+ */
32
+
27
33
/**
28
34
* A Mosaic Coordinator manages all database communication for clients and
29
35
* handles selection updates. The Coordinator also performs optimizations
@@ -34,7 +40,8 @@ export function coordinator(instance) {
34
40
* @param {* } [options.manager] The query manager to use.
35
41
* @param {boolean } [options.cache=true] Boolean flag to enable/disable query caching.
36
42
* @param {boolean } [options.consolidate=true] Boolean flag to enable/disable query consolidation.
37
- * @param {object } [options.indexes] Data cube indexer options.
43
+ * @param {import('./DataCubeIndexer.js').DataCubeIndexerOptions } [options.indexes]
44
+ * Data cube indexer options.
38
45
*/
39
46
export class Coordinator {
40
47
constructor ( db = socketConnector ( ) , {
@@ -48,10 +55,10 @@ export class Coordinator {
48
55
this . manager = manager ;
49
56
this . manager . cache ( cache ) ;
50
57
this . manager . consolidate ( consolidate ) ;
51
- this . dataCubeIndexer = new DataCubeIndexer ( this , indexes ) ;
52
- this . logger ( logger ) ;
53
58
this . databaseConnector ( db ) ;
59
+ this . logger ( logger ) ;
54
60
this . clear ( ) ;
61
+ this . dataCubeIndexer = new DataCubeIndexer ( this , indexes ) ;
55
62
}
56
63
57
64
/**
@@ -98,7 +105,7 @@ export class Coordinator {
98
105
/**
99
106
* Cancel previosuly submitted query requests. These queries will be
100
107
* canceled if they are queued but have not yet been submitted.
101
- * @param {import('./util/query-result.js'). QueryResult[] } requests An array
108
+ * @param {QueryResult[] } requests An array
102
109
* of query result objects, such as those returned by the `query` method.
103
110
*/
104
111
cancel ( requests ) {
@@ -107,29 +114,30 @@ export class Coordinator {
107
114
108
115
/**
109
116
* Issue a query for which no result (return value) is needed.
110
- * @param {import('@uwdata/mosaic-sql').Query | string } query The query.
117
+ * @param {QueryType | QueryType[] } query The query or an array of queries.
118
+ * Each query should be either a Query builder object or a SQL string.
111
119
* @param {object } [options] An options object.
112
120
* @param {number } [options.priority] The query priority, defaults to
113
121
* `Priority.Normal`.
114
- * @returns {import('./util/query-result.js'). QueryResult } A query result
122
+ * @returns {QueryResult } A query result
115
123
* promise.
116
124
*/
117
125
exec ( query , { priority = Priority . Normal } = { } ) {
118
- query = Array . isArray ( query ) ? query . join ( ';\n' ) : query ;
126
+ query = Array . isArray ( query ) ? query . filter ( x => x ) . join ( ';\n' ) : query ;
119
127
return this . manager . request ( { type : 'exec' , query } , priority ) ;
120
128
}
121
129
122
130
/**
123
131
* Issue a query to the backing database. The submitted query may be
124
132
* consolidate with other queries and its results may be cached.
125
- * @param {import('@uwdata/mosaic-sql').Query | string } query The query.
133
+ * @param {QueryType } query The query as either a Query builder object
134
+ * or a SQL string.
126
135
* @param {object } [options] An options object.
127
136
* @param {'arrow' | 'json' } [options.type] The query result format type.
128
137
* @param {boolean } [options.cache=true] If true, cache the query result.
129
138
* @param {number } [options.priority] The query priority, defaults to
130
139
* `Priority.Normal`.
131
- * @returns {import('./util/query-result.js').QueryResult } A query result
132
- * promise.
140
+ * @returns {QueryResult } A query result promise.
133
141
*/
134
142
query ( query , {
135
143
type = 'arrow' ,
@@ -143,11 +151,11 @@ export class Coordinator {
143
151
/**
144
152
* Issue a query to prefetch data for later use. The query result is cached
145
153
* for efficient future access.
146
- * @param {import('@uwdata/mosaic-sql').Query | string } query The query.
154
+ * @param {QueryType } query The query as either a Query builder object
155
+ * or a SQL string.
147
156
* @param {object } [options] An options object.
148
157
* @param {'arrow' | 'json' } [options.type] The query result format type.
149
- * @returns {import('./util/query-result.js').QueryResult } A query result
150
- * promise.
158
+ * @returns {QueryResult } A query result promise.
151
159
*/
152
160
prefetch ( query , options = { } ) {
153
161
return this . query ( query , { ...options , cache : true , priority : Priority . Low } ) ;
@@ -159,7 +167,7 @@ export class Coordinator {
159
167
* @param {string } name The name of the bundle.
160
168
* @param {[string | {sql: string}, {alias: string}] } queries The queries to save into the bundle.
161
169
* @param {number } priority Request priority.
162
- * @returns
170
+ * @returns { QueryResult } A query result promise.
163
171
*/
164
172
createBundle ( name , queries , priority = Priority . Low ) {
165
173
const options = { name, queries : queries . map ( q => typeof q == 'string' ? { sql : q } : q ) } ;
@@ -170,7 +178,7 @@ export class Coordinator {
170
178
* Load a bundle into the cache.
171
179
* @param {string } name The name of the bundle.
172
180
* @param {number } priority Request priority.
173
- * @returns
181
+ * @returns { QueryResult } A query result promise.
174
182
*/
175
183
loadBundle ( name , priority = Priority . High ) {
176
184
const options = { name } ;
@@ -182,8 +190,8 @@ export class Coordinator {
182
190
/**
183
191
* Update client data by submitting the given query and returning the
184
192
* data (or error) to the client.
185
- * @param {import('./MosaicClient.js'). MosaicClient } client A Mosaic client.
186
- * @param {import('@uwdata/mosaic-sql').Query | string } query The data query.
193
+ * @param {MosaicClient } client A Mosaic client.
194
+ * @param {QueryType } query The data query.
187
195
* @param {number } [priority] The query priority.
188
196
* @returns {Promise } A Promise that resolves upon completion of the update.
189
197
*/
@@ -201,10 +209,8 @@ export class Coordinator {
201
209
* Issue a query request for a client. If the query is null or undefined,
202
210
* the client is simply updated. Otherwise `updateClient` is called. As a
203
211
* side effect, this method clears the current data cube indexer state.
204
- * @param {import('./MosaicClient.js').MosaicClient } client The client
205
- * to update.
206
- * @param {import('@uwdata/mosaic-sql').Query | string | null } [query]
207
- * The query to issue.
212
+ * @param {MosaicClient } client The client to update.
213
+ * @param {QueryType | null } [query] The query to issue.
208
214
*/
209
215
requestQuery ( client , query ) {
210
216
this . dataCubeIndexer . clear ( ) ;
@@ -215,8 +221,7 @@ export class Coordinator {
215
221
216
222
/**
217
223
* Connect a client to the coordinator.
218
- * @param {import('./MosaicClient.js').MosaicClient } client The Mosaic
219
- * client to connect.
224
+ * @param {MosaicClient } client The Mosaic client to connect.
220
225
*/
221
226
async connect ( client ) {
222
227
const { clients } = this ;
@@ -247,8 +252,7 @@ export class Coordinator {
247
252
248
253
/**
249
254
* Disconnect a client from the coordinator.
250
- * @param {import('./MosaicClient.js').MosaicClient } client The Mosaic
251
- * client to disconnect.
255
+ * @param {MosaicClient } client The Mosaic client to disconnect.
252
256
*/
253
257
disconnect ( client ) {
254
258
const { clients, filterGroups } = this ;
@@ -267,8 +271,8 @@ export class Coordinator {
267
271
* Connect a selection-client pair to the coordinator to process updates.
268
272
* @param {Coordinator } mc The Mosaic coordinator.
269
273
* @param {import('./Selection.js').Selection } selection A selection.
270
- * @param {import('./ MosaicClient.js').MosaicClient } client A Mosiac
271
- * client that is filtered by the given selection.
274
+ * @param {MosaicClient } client A Mosiac client that is filtered by the
275
+ * given selection.
272
276
*/
273
277
function connectSelection ( mc , selection , client ) {
274
278
if ( ! selection ) return ;
0 commit comments