@uwdata/mosaic-core 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/LICENSE +47 -0
  2. package/README.md +0 -1
  3. package/dist/src/Coordinator.d.ts +159 -0
  4. package/dist/src/Coordinator.d.ts.map +1 -0
  5. package/dist/src/Coordinator.js +250 -0
  6. package/dist/src/Coordinator.js.map +1 -0
  7. package/dist/src/MosaicClient.d.ts +138 -0
  8. package/dist/src/MosaicClient.d.ts.map +1 -0
  9. package/dist/src/MosaicClient.js +214 -0
  10. package/dist/src/MosaicClient.js.map +1 -0
  11. package/dist/src/Param.d.ts +56 -0
  12. package/dist/src/Param.d.ts.map +1 -0
  13. package/dist/src/Param.js +89 -0
  14. package/dist/src/Param.js.map +1 -0
  15. package/dist/src/QueryConsolidator.d.ts +11 -0
  16. package/dist/src/QueryConsolidator.d.ts.map +1 -0
  17. package/dist/src/QueryConsolidator.js +249 -0
  18. package/dist/src/QueryConsolidator.js.map +1 -0
  19. package/dist/src/QueryManager.d.ts +77 -0
  20. package/dist/src/QueryManager.d.ts.map +1 -0
  21. package/dist/src/QueryManager.js +174 -0
  22. package/dist/src/QueryManager.js.map +1 -0
  23. package/dist/src/Selection.d.ts +222 -0
  24. package/dist/src/Selection.d.ts.map +1 -0
  25. package/dist/src/Selection.js +322 -0
  26. package/dist/src/Selection.js.map +1 -0
  27. package/dist/src/SelectionClause.d.ts +222 -0
  28. package/dist/src/SelectionClause.d.ts.map +1 -0
  29. package/dist/src/SelectionClause.js +168 -0
  30. package/dist/src/SelectionClause.js.map +1 -0
  31. package/dist/src/connectors/Connector.d.ts +26 -0
  32. package/dist/src/connectors/Connector.d.ts.map +1 -0
  33. package/dist/src/connectors/Connector.js +2 -0
  34. package/dist/src/connectors/Connector.js.map +1 -0
  35. package/dist/src/connectors/rest.d.ts +24 -0
  36. package/dist/src/connectors/rest.d.ts.map +1 -0
  37. package/dist/src/connectors/rest.js +37 -0
  38. package/dist/src/connectors/rest.js.map +1 -0
  39. package/dist/src/connectors/socket.d.ts +40 -0
  40. package/dist/src/connectors/socket.d.ts.map +1 -0
  41. package/dist/src/connectors/socket.js +115 -0
  42. package/dist/src/connectors/socket.js.map +1 -0
  43. package/dist/src/connectors/wasm.d.ts +56 -0
  44. package/dist/src/connectors/wasm.d.ts.map +1 -0
  45. package/dist/src/connectors/wasm.js +116 -0
  46. package/dist/src/connectors/wasm.js.map +1 -0
  47. package/dist/src/index.d.ts +28 -0
  48. package/dist/src/index.d.ts.map +1 -0
  49. package/{src → dist/src}/index.js +8 -11
  50. package/dist/src/index.js.map +1 -0
  51. package/dist/src/make-client.d.ts +33 -0
  52. package/dist/src/make-client.d.ts.map +1 -0
  53. package/dist/src/make-client.js +52 -0
  54. package/dist/src/make-client.js.map +1 -0
  55. package/dist/src/preagg/PreAggregator.d.ts +150 -0
  56. package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
  57. package/dist/src/preagg/PreAggregator.js +382 -0
  58. package/dist/src/preagg/PreAggregator.js.map +1 -0
  59. package/dist/src/preagg/preagg-columns.d.ts +16 -0
  60. package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
  61. package/dist/src/preagg/preagg-columns.js +95 -0
  62. package/dist/src/preagg/preagg-columns.js.map +1 -0
  63. package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
  64. package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
  65. package/dist/src/preagg/sufficient-statistics.js +446 -0
  66. package/dist/src/preagg/sufficient-statistics.js.map +1 -0
  67. package/dist/src/types.d.ts +77 -0
  68. package/dist/src/types.d.ts.map +1 -0
  69. package/dist/src/types.js +2 -0
  70. package/dist/src/types.js.map +1 -0
  71. package/dist/src/util/AsyncDispatch.d.ts +121 -0
  72. package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
  73. package/dist/src/util/AsyncDispatch.js +188 -0
  74. package/dist/src/util/AsyncDispatch.js.map +1 -0
  75. package/dist/src/util/cache.d.ts +19 -0
  76. package/dist/src/util/cache.d.ts.map +1 -0
  77. package/dist/src/util/cache.js +66 -0
  78. package/dist/src/util/cache.js.map +1 -0
  79. package/dist/src/util/decode-ipc.d.ts +12 -0
  80. package/dist/src/util/decode-ipc.d.ts.map +1 -0
  81. package/{src → dist/src}/util/decode-ipc.js +5 -6
  82. package/dist/src/util/decode-ipc.js.map +1 -0
  83. package/dist/src/util/distinct.d.ts +3 -0
  84. package/dist/src/util/distinct.d.ts.map +1 -0
  85. package/dist/src/util/distinct.js +16 -0
  86. package/dist/src/util/distinct.js.map +1 -0
  87. package/dist/src/util/field-info.d.ts +26 -0
  88. package/dist/src/util/field-info.d.ts.map +1 -0
  89. package/dist/src/util/field-info.js +91 -0
  90. package/dist/src/util/field-info.js.map +1 -0
  91. package/dist/src/util/hash.d.ts +2 -0
  92. package/dist/src/util/hash.d.ts.map +1 -0
  93. package/dist/src/util/hash.js +26 -0
  94. package/dist/src/util/hash.js.map +1 -0
  95. package/dist/src/util/is-activatable.d.ts +8 -0
  96. package/dist/src/util/is-activatable.d.ts.map +1 -0
  97. package/dist/src/util/is-activatable.js +10 -0
  98. package/dist/src/util/is-activatable.js.map +1 -0
  99. package/dist/src/util/is-arrow-table.d.ts +9 -0
  100. package/dist/src/util/is-arrow-table.d.ts.map +1 -0
  101. package/dist/src/util/is-arrow-table.js +11 -0
  102. package/dist/src/util/is-arrow-table.js.map +1 -0
  103. package/dist/src/util/js-type.d.ts +9 -0
  104. package/dist/src/util/js-type.d.ts.map +1 -0
  105. package/dist/src/util/js-type.js +59 -0
  106. package/dist/src/util/js-type.js.map +1 -0
  107. package/dist/src/util/priority-queue.d.ts +35 -0
  108. package/dist/src/util/priority-queue.d.ts.map +1 -0
  109. package/dist/src/util/priority-queue.js +81 -0
  110. package/dist/src/util/priority-queue.js.map +1 -0
  111. package/dist/src/util/query-result.d.ts +47 -0
  112. package/dist/src/util/query-result.d.ts.map +1 -0
  113. package/dist/src/util/query-result.js +83 -0
  114. package/dist/src/util/query-result.js.map +1 -0
  115. package/dist/src/util/synchronizer.d.ts +36 -0
  116. package/dist/src/util/synchronizer.d.ts.map +1 -0
  117. package/dist/src/util/synchronizer.js +52 -0
  118. package/dist/src/util/synchronizer.js.map +1 -0
  119. package/dist/src/util/throttle.d.ts +12 -0
  120. package/dist/src/util/throttle.d.ts.map +1 -0
  121. package/dist/src/util/throttle.js +51 -0
  122. package/dist/src/util/throttle.js.map +1 -0
  123. package/dist/src/util/to-data-columns.d.ts +22 -0
  124. package/dist/src/util/to-data-columns.d.ts.map +1 -0
  125. package/dist/src/util/to-data-columns.js +51 -0
  126. package/dist/src/util/to-data-columns.js.map +1 -0
  127. package/dist/src/util/void-logger.d.ts +13 -0
  128. package/dist/src/util/void-logger.d.ts.map +1 -0
  129. package/dist/src/util/void-logger.js +13 -0
  130. package/dist/src/util/void-logger.js.map +1 -0
  131. package/package.json +17 -11
  132. package/src/Coordinator.ts +396 -0
  133. package/src/{MosaicClient.js → MosaicClient.ts} +50 -43
  134. package/src/{Param.js → Param.ts} +29 -28
  135. package/src/{QueryConsolidator.js → QueryConsolidator.ts} +85 -62
  136. package/src/{QueryManager.js → QueryManager.ts} +61 -54
  137. package/src/Selection.ts +391 -0
  138. package/src/SelectionClause.ts +357 -0
  139. package/src/connectors/Connector.ts +6 -6
  140. package/src/connectors/rest.ts +56 -0
  141. package/src/connectors/{socket.js → socket.ts} +53 -42
  142. package/src/connectors/{wasm.js → wasm.ts} +52 -63
  143. package/src/index.ts +42 -0
  144. package/src/make-client.ts +93 -0
  145. package/src/preagg/{PreAggregator.js → PreAggregator.ts} +164 -145
  146. package/src/preagg/{preagg-columns.js → preagg-columns.ts} +27 -24
  147. package/src/preagg/{sufficient-statistics.js → sufficient-statistics.ts} +160 -110
  148. package/src/types.ts +24 -9
  149. package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
  150. package/src/util/{cache.js → cache.ts} +25 -15
  151. package/src/util/decode-ipc.ts +15 -0
  152. package/src/util/{distinct.js → distinct.ts} +3 -3
  153. package/src/util/{field-info.js → field-info.ts} +30 -31
  154. package/src/util/{hash.js → hash.ts} +4 -4
  155. package/src/util/is-activatable.ts +11 -0
  156. package/src/util/is-arrow-table.ts +12 -0
  157. package/src/util/{js-type.js → js-type.ts} +7 -5
  158. package/src/util/{priority-queue.js → priority-queue.ts} +32 -20
  159. package/src/util/{query-result.js → query-result.ts} +24 -17
  160. package/src/util/synchronizer.ts +56 -0
  161. package/src/util/throttle.ts +59 -0
  162. package/src/util/to-data-columns.ts +65 -0
  163. package/src/util/void-logger.ts +23 -0
  164. package/src/Coordinator.js +0 -313
  165. package/src/Selection.js +0 -380
  166. package/src/SelectionClause.js +0 -159
  167. package/src/connectors/rest.js +0 -38
  168. package/src/index-types.ts +0 -5
  169. package/src/make-client.js +0 -101
  170. package/src/util/is-activatable.js +0 -8
  171. package/src/util/is-arrow-table.js +0 -10
  172. package/src/util/selection-types.ts +0 -137
  173. package/src/util/synchronizer.js +0 -47
  174. package/src/util/throttle.js +0 -54
  175. package/src/util/to-data-columns.js +0 -60
  176. package/src/util/void-logger.js +0 -13
  177. package/tsconfig.json +0 -9
  178. package/vitest.config.ts +0 -3
package/LICENSE ADDED
@@ -0,0 +1,47 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023-2025, UW Interactive Data Lab
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ ---
31
+
32
+ Portions of this software are derived from Observable Plot, which is released
33
+ under the ISC license.
34
+
35
+ Copyright 2020-2023 Observable, Inc.
36
+
37
+ Permission to use, copy, modify, and/or distribute this software for any purpose
38
+ with or without fee is hereby granted, provided that the above copyright notice
39
+ and this permission notice appear in all copies.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
42
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
43
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
44
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
45
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
46
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
47
+ THIS SOFTWARE.
package/README.md CHANGED
@@ -4,4 +4,3 @@
4
4
 
5
5
  The core Mosaic components: a central coordinator, parameters (`Param`) and selections (`Selection`) for linking scalar values or query predicates (respectively) across Mosaic clients, and filter groups with materialized views of pre-aggregated data. The Mosaic coordinator can send queries either over the network to a backing server (`socket` and `rest` clients) or to a client-side [DuckDB-WASM](https://github.com/duckdb/duckdb-wasm) instance (`wasm` client).
6
6
 
7
- The `mosaic-core` facilities are included as part of the [vgplot](https://github.com/uwdata/mosaic/tree/main/packages/vgplot) API.
@@ -0,0 +1,159 @@
1
+ import { type Connector } from './connectors/Connector.js';
2
+ import { PreAggregator, type PreAggregateOptions } from './preagg/PreAggregator.js';
3
+ import { QueryManager } from './QueryManager.js';
4
+ import { type Selection } from './Selection.js';
5
+ import { type Logger, type QueryType } from './types.js';
6
+ import { type QueryResult } from './util/query-result.js';
7
+ import { type MosaicClient } from './MosaicClient.js';
8
+ import { MaybeArray } from '@uwdata/mosaic-sql';
9
+ import { Table } from '@uwdata/flechette';
10
+ interface FilterGroupEntry {
11
+ selection: Selection;
12
+ clients: Set<MosaicClient>;
13
+ disconnect(): void;
14
+ }
15
+ /**
16
+ * Set or retrieve the coordinator instance.
17
+ * @param instance The coordinator instance to set
18
+ * @returns The coordinator instance
19
+ */
20
+ export declare function coordinator(instance?: Coordinator): Coordinator;
21
+ /**
22
+ * A Mosaic Coordinator manages all database communication for clients and
23
+ * handles selection updates. The Coordinator also performs optimizations
24
+ * including query caching, consolidation, and pre-aggregation.
25
+ */
26
+ export declare class Coordinator {
27
+ manager: QueryManager;
28
+ preaggregator: PreAggregator;
29
+ clients: Set<MosaicClient>;
30
+ filterGroups: Map<Selection, FilterGroupEntry>;
31
+ protected _logger: Logger;
32
+ /**
33
+ * @param db Database connector. Defaults to a web socket connection.
34
+ * @param options Coordinator options.
35
+ * @param options.logger The logger to use, defaults to `console`.
36
+ * @param options.manager The query manager to use.
37
+ * @param options.cache Boolean flag to enable/disable query caching.
38
+ * @param options.consolidate Boolean flag to enable/disable query consolidation.
39
+ * @param options.preagg Options for the Pre-aggregator.
40
+ */
41
+ constructor(db?: Connector, options?: {
42
+ logger?: Logger | null;
43
+ manager?: QueryManager;
44
+ cache?: boolean;
45
+ consolidate?: boolean;
46
+ preagg?: PreAggregateOptions;
47
+ });
48
+ /**
49
+ * Clear the coordinator state.
50
+ * @param options Options object.
51
+ * @param options.clients If true, disconnect all clients.
52
+ * @param options.cache If true, clear the query cache.
53
+ */
54
+ clear(options?: {
55
+ clients?: boolean;
56
+ cache?: boolean;
57
+ }): void;
58
+ /**
59
+ * Get or set the database connector.
60
+ * @param db The database connector to use.
61
+ * @returns The current database connector.
62
+ */
63
+ databaseConnector(): Connector | null;
64
+ databaseConnector(db: Connector): Connector;
65
+ /**
66
+ * Get or set the logger.
67
+ * @param logger The logger to use.
68
+ * @returns The current logger
69
+ */
70
+ logger(logger?: Logger | null): Logger;
71
+ /**
72
+ * Cancel previously submitted query requests. These queries will be
73
+ * canceled if they are queued but have not yet been submitted.
74
+ * @param requests An array of query result objects, such as those returned by the `query` method.
75
+ */
76
+ cancel(requests: QueryResult[]): void;
77
+ /**
78
+ * Issue a query for which no result (return value) is needed.
79
+ * @param query The query or an array of queries. Each query should be either a Query builder object or a SQL string.
80
+ * @param options An options object.
81
+ * @param options.priority The query priority, defaults to `Priority.Normal`.
82
+ * @returns A query result promise.
83
+ */
84
+ exec(query: MaybeArray<QueryType>, options?: {
85
+ priority?: number;
86
+ }): QueryResult;
87
+ /**
88
+ * Issue a query to the backing database. The submitted query may be
89
+ * consolidate with other queries and its results may be cached.
90
+ * @param query The query as either a Query builder object or a SQL string.
91
+ * @param options An options object.
92
+ * @param options.type The query result format type.
93
+ * @param options.cache If true, cache the query result client-side within the QueryManager.
94
+ * @param options.persist If true, request the database server to persist a cached query server-side.
95
+ * @param options.priority The query priority, defaults to `Priority.Normal`.
96
+ * @returns A query result promise.
97
+ */
98
+ query(query: QueryType, options?: {
99
+ type?: 'arrow';
100
+ cache?: boolean;
101
+ persist?: boolean;
102
+ priority?: number;
103
+ [key: string]: unknown;
104
+ }): QueryResult<Table>;
105
+ query(query: QueryType, options?: {
106
+ type?: 'json';
107
+ cache?: boolean;
108
+ persist?: boolean;
109
+ priority?: number;
110
+ [key: string]: unknown;
111
+ }): QueryResult<unknown>;
112
+ /**
113
+ * Issue a query to prefetch data for later use. The query result is cached
114
+ * for efficient future access.
115
+ * @param query The query as either a Query builder object or a SQL string.
116
+ * @param options An options object.
117
+ * @param options.type The query result format type.
118
+ * @returns A query result promise.
119
+ */
120
+ prefetch(query: QueryType, options?: {
121
+ type?: 'arrow';
122
+ [key: string]: unknown;
123
+ }): QueryResult<Table>;
124
+ prefetch(query: QueryType, options?: {
125
+ type?: 'json';
126
+ [key: string]: unknown;
127
+ }): QueryResult<unknown>;
128
+ /**
129
+ * Update client data by submitting the given query and returning the()
130
+ * data (or error) to the client.
131
+ * @param client A Mosaic client.
132
+ * @param query The data query.
133
+ * @param priority The query priority.
134
+ * @returns A Promise that resolves upon completion of the update.
135
+ */
136
+ updateClient(client: MosaicClient, query: QueryType, priority?: number): Promise<unknown>;
137
+ /**
138
+ * Issue a query request for a client. If the query is null or undefined,
139
+ * the client is simply updated. Otherwise `updateClient` is called. As a
140
+ * side effect, this method clears the current preaggregator state.
141
+ * @param client The client to update.
142
+ * @param query The query to issue.
143
+ */
144
+ requestQuery(client: MosaicClient, query?: QueryType | null): Promise<unknown>;
145
+ /**
146
+ * Connect a client to the coordinator.
147
+ * Throws an error if the client is already connected.
148
+ * @param client The Mosaic client to connect.
149
+ */
150
+ connect(client: MosaicClient): void;
151
+ /**
152
+ * Disconnect a client from the coordinator.
153
+ * This method has no effect if the client is already disconnected.
154
+ * @param client The Mosaic client to disconnect.
155
+ */
156
+ disconnect(client: MosaicClient): void;
157
+ }
158
+ export {};
159
+ //# sourceMappingURL=Coordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Coordinator.d.ts","sourceRoot":"","sources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,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GACnD,WAAW,CAAC,KAAK,CAAC;IACrB,QAAQ,CACN,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAClD,WAAW,CAAC,OAAO,CAAC;IAUvB;;;;;;;OAOG;IACH,YAAY,CACV,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,SAAS,EAChB,QAAQ,GAAE,MAAwB,GACjC,OAAO,CAAC,OAAO,CAAC;IAUnB;;;;;;OAMG;IACH,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;IAO9E;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAoBnC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;CAWvC"}
@@ -0,0 +1,250 @@
1
+ import { SocketConnector } from './connectors/socket.js';
2
+ import { PreAggregator } from './preagg/PreAggregator.js';
3
+ import { voidLogger } from './util/void-logger.js';
4
+ import { QueryManager, Priority } from './QueryManager.js';
5
+ /**
6
+ * The singleton Coordinator instance.
7
+ */
8
+ let _instance;
9
+ /**
10
+ * Set or retrieve the coordinator instance.
11
+ * @param instance The coordinator instance to set
12
+ * @returns The coordinator instance
13
+ */
14
+ export function coordinator(instance) {
15
+ if (instance) {
16
+ _instance = instance;
17
+ }
18
+ else if (_instance == null) {
19
+ _instance = new Coordinator();
20
+ }
21
+ return _instance;
22
+ }
23
+ /**
24
+ * A Mosaic Coordinator manages all database communication for clients and
25
+ * handles selection updates. The Coordinator also performs optimizations
26
+ * including query caching, consolidation, and pre-aggregation.
27
+ */
28
+ export class Coordinator {
29
+ manager;
30
+ preaggregator;
31
+ clients = new Set;
32
+ filterGroups = new Map;
33
+ _logger = voidLogger();
34
+ /**
35
+ * @param db Database connector. Defaults to a web socket connection.
36
+ * @param options Coordinator options.
37
+ * @param options.logger The logger to use, defaults to `console`.
38
+ * @param options.manager The query manager to use.
39
+ * @param options.cache Boolean flag to enable/disable query caching.
40
+ * @param options.consolidate Boolean flag to enable/disable query consolidation.
41
+ * @param options.preagg Options for the Pre-aggregator.
42
+ */
43
+ constructor(db = new SocketConnector(), options = {}) {
44
+ const { logger = console, manager = new QueryManager(), cache = true, consolidate = true, preagg = {} } = options;
45
+ this.manager = manager;
46
+ this.manager.cache(cache);
47
+ this.manager.consolidate(consolidate);
48
+ this.databaseConnector(db);
49
+ this.logger(logger);
50
+ this.clear();
51
+ this.preaggregator = new PreAggregator(this, preagg);
52
+ }
53
+ /**
54
+ * Clear the coordinator state.
55
+ * @param options Options object.
56
+ * @param options.clients If true, disconnect all clients.
57
+ * @param options.cache If true, clear the query cache.
58
+ */
59
+ clear(options = {}) {
60
+ const { clients = true, cache = true } = options;
61
+ this.manager.clear();
62
+ if (clients) {
63
+ this.filterGroups?.forEach(group => group.disconnect());
64
+ this.filterGroups = new Map;
65
+ this.clients?.forEach(client => this.disconnect(client));
66
+ this.clients = new Set;
67
+ }
68
+ if (cache)
69
+ this.manager.cache().clear();
70
+ }
71
+ databaseConnector(db) {
72
+ return db
73
+ ? this.manager.connector(db)
74
+ : this.manager.connector();
75
+ }
76
+ /**
77
+ * Get or set the logger.
78
+ * @param logger The logger to use.
79
+ * @returns The current logger
80
+ */
81
+ logger(logger) {
82
+ if (arguments.length) {
83
+ this._logger = logger || voidLogger();
84
+ this.manager.logger(this._logger);
85
+ }
86
+ return this._logger;
87
+ }
88
+ // -- Query Management ----
89
+ /**
90
+ * Cancel previously submitted query requests. These queries will be
91
+ * canceled if they are queued but have not yet been submitted.
92
+ * @param requests An array of query result objects, such as those returned by the `query` method.
93
+ */
94
+ cancel(requests) {
95
+ this.manager.cancel(requests);
96
+ }
97
+ /**
98
+ * Issue a query for which no result (return value) is needed.
99
+ * @param query The query or an array of queries. Each query should be either a Query builder object or a SQL string.
100
+ * @param options An options object.
101
+ * @param options.priority The query priority, defaults to `Priority.Normal`.
102
+ * @returns A query result promise.
103
+ */
104
+ exec(query, options = {}) {
105
+ const { priority = Priority.Normal } = options;
106
+ query = Array.isArray(query) ? query.filter(x => x).join(';\n') : query;
107
+ return this.manager.request({ type: 'exec', query }, priority);
108
+ }
109
+ query(query, options = {}) {
110
+ const { type = 'arrow', cache = true, priority = Priority.Normal, ...otherOptions } = options;
111
+ return this.manager.request({ type, query, cache, options: otherOptions }, priority);
112
+ }
113
+ prefetch(query, options = {}) {
114
+ return this.query(query, { ...options, cache: true, priority: Priority.Low });
115
+ }
116
+ // -- Client Management ----
117
+ /**
118
+ * Update client data by submitting the given query and returning the()
119
+ * data (or error) to the client.
120
+ * @param client A Mosaic client.
121
+ * @param query The data query.
122
+ * @param priority The query priority.
123
+ * @returns A Promise that resolves upon completion of the update.
124
+ */
125
+ updateClient(client, query, priority = Priority.Normal) {
126
+ client.queryPending();
127
+ return client._pending = this.query(query, { priority })
128
+ .then(data => client.queryResult(data).update(), err => { this._logger?.error(err); client.queryError(err); })
129
+ .catch(err => this._logger?.error(err));
130
+ }
131
+ /**
132
+ * Issue a query request for a client. If the query is null or undefined,
133
+ * the client is simply updated. Otherwise `updateClient` is called. As a
134
+ * side effect, this method clears the current preaggregator state.
135
+ * @param client The client to update.
136
+ * @param query The query to issue.
137
+ */
138
+ requestQuery(client, query) {
139
+ this.preaggregator.clear();
140
+ return query
141
+ ? this.updateClient(client, query)
142
+ : Promise.resolve(client.update());
143
+ }
144
+ /**
145
+ * Connect a client to the coordinator.
146
+ * Throws an error if the client is already connected.
147
+ * @param client The Mosaic client to connect.
148
+ */
149
+ connect(client) {
150
+ const { clients } = this;
151
+ if (clients?.has(client)) {
152
+ throw new Error('Client already connected.');
153
+ }
154
+ // add client to client set
155
+ clients?.add(client);
156
+ // register coordinator on client instance
157
+ client.coordinator = this;
158
+ // initialize client lifecycle
159
+ client.initialize();
160
+ // connect filter selection
161
+ connectSelection(this, client.filterBy, client);
162
+ }
163
+ /**
164
+ * Disconnect a client from the coordinator.
165
+ * This method has no effect if the client is already disconnected.
166
+ * @param client The Mosaic client to disconnect.
167
+ */
168
+ disconnect(client) {
169
+ const { clients, filterGroups } = this;
170
+ if (!clients?.has(client))
171
+ return;
172
+ clients.delete(client);
173
+ client.coordinator = null;
174
+ const group = filterGroups?.get(client.filterBy);
175
+ if (group) {
176
+ group.clients.delete(client);
177
+ }
178
+ }
179
+ }
180
+ /**
181
+ * Connect a selection-client pair to the coordinator to process updates.
182
+ * @param mc The Mosaic coordinator.
183
+ * @param selection A selection.
184
+ * @param client A Mosaic client that is filtered by the given selection.
185
+ */
186
+ function connectSelection(mc, selection, client) {
187
+ if (!selection)
188
+ return;
189
+ let entry = mc.filterGroups?.get(selection);
190
+ if (!entry) {
191
+ const activate = (clause) => activateSelection(mc, selection, clause);
192
+ const value = () => updateSelection(mc, selection);
193
+ // @ts-expect-error todo: update selection dispatch types
194
+ selection.addEventListener('activate', activate);
195
+ selection.addEventListener('value', value);
196
+ entry = {
197
+ selection,
198
+ clients: new Set,
199
+ disconnect() {
200
+ // @ts-expect-error todo: update selection dispatch types
201
+ selection.removeEventListener('activate', activate);
202
+ selection.removeEventListener('value', value);
203
+ }
204
+ };
205
+ mc.filterGroups?.set(selection, entry);
206
+ }
207
+ entry.clients.add(client);
208
+ }
209
+ /**
210
+ * Activate a selection, providing a clause indicative of potential
211
+ * next updates. Activation provides a preview of likely next events,
212
+ * enabling potential precomputation to optimize updates.
213
+ * @param mc The Mosaic coordinator.
214
+ * @param selection A selection.
215
+ * @param clause A selection clause for the activation.
216
+ */
217
+ function activateSelection(mc, selection, clause) {
218
+ const { preaggregator, filterGroups } = mc;
219
+ const { clients } = filterGroups.get(selection);
220
+ for (const client of clients) {
221
+ if (client.enabled) {
222
+ preaggregator.request(client, selection, clause);
223
+ }
224
+ }
225
+ }
226
+ /**
227
+ * Process an updated selection value, querying filtered data for any
228
+ * associated clients.
229
+ * @param mc The Mosaic coordinator.
230
+ * @param selection A selection.
231
+ * @returns A Promise that resolves when the update completes.
232
+ */
233
+ function updateSelection(mc, selection) {
234
+ const { preaggregator, filterGroups } = mc;
235
+ const { clients } = filterGroups.get(selection);
236
+ const { active } = selection;
237
+ return Promise.allSettled(Array.from(clients, (client) => {
238
+ if (!client.enabled)
239
+ return client.requestQuery();
240
+ const info = preaggregator.request(client, selection, active);
241
+ const filter = info ? null : selection.predicate(client);
242
+ // skip due to cross-filtering
243
+ if (info?.skip || (!info && !filter))
244
+ return;
245
+ // @ts-expect-error FIXME
246
+ const query = info?.query(active.predicate) ?? client.query(filter);
247
+ return mc.updateClient(client, query);
248
+ }));
249
+ }
250
+ //# sourceMappingURL=Coordinator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Coordinator.js","sourceRoot":"","sources":["../../src/Coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAA4B,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAe3D;;GAEG;AACH,IAAI,SAAsB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,QAAsB;IAEtB,IAAI,QAAQ,EAAE,CAAC;QACb,SAAS,GAAG,QAAQ,CAAC;IACvB,CAAC;SAAM,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QAC7B,SAAS,GAAG,IAAI,WAAW,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACf,OAAO,CAAe;IACtB,aAAa,CAAgB;IAC7B,OAAO,GAAG,IAAI,GAAiB,CAAC;IAChC,YAA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B,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;IAC3C,MAAM,EAAE,OAAO,EAAE,GAAG,YAAa,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;IAClD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC7B,OAAO,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAoB,EAAE,EAAE;QACrE,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEzD,8BAA8B;QAC9B,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC;YAAE,OAAO;QAE7C,yBAAyB;QACzB,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpE,OAAO,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,138 @@
1
+ import { FilterExpr, type Query } from '@uwdata/mosaic-sql';
2
+ import { type Coordinator } from './Coordinator.js';
3
+ import { type Selection } from './Selection.js';
4
+ export type ClientQuery = Query | string | null;
5
+ export declare function isMosaicClient(x: unknown): x is MosaicClient;
6
+ /**
7
+ * A Mosaic client is a data consumer that indicates its data needs to a
8
+ * Mosaic coordinator via the query method. The coordinator is responsible
9
+ * for issuing queries and returning results to the client.
10
+ *
11
+ * The client life-cycle consists of connection to a coordinator,
12
+ * initialization (potentially involving queries for data schema and summary
13
+ * statistic information), and then interactive queries that may be driven by
14
+ * an associated selection. When no longer needed, a client should be
15
+ * disconnected from the coordinator.
16
+ *
17
+ * When enabled, a client will initialize and respond to query update requests.
18
+ * If disabled, the client will delay initialization and not respond to queries
19
+ * until enabled again. Disabling a client can improve system performance when
20
+ * associated interface elements are offscreen or disabled.
21
+ */
22
+ export declare class MosaicClient {
23
+ _filterBy: Selection | undefined;
24
+ _requestUpdate: () => void;
25
+ _coordinator: Coordinator | null;
26
+ _pending: Promise<unknown>;
27
+ _enabled: boolean;
28
+ _initialized: boolean;
29
+ _request: Query | boolean | null;
30
+ /**
31
+ * Create a new client instance.
32
+ * @param filterSelection An optional selection to
33
+ * interactively filter this client's data. If provided, a coordinator
34
+ * will re-query and update the client when the selection updates.
35
+ */
36
+ constructor(filterSelection?: Selection);
37
+ /**
38
+ * @returns this client's connected coordinator.
39
+ */
40
+ get coordinator(): Coordinator | null;
41
+ /**
42
+ * Set this client's connected coordinator.
43
+ */
44
+ set coordinator(coordinator: Coordinator | null);
45
+ /**
46
+ * Return this client's enabled state.
47
+ */
48
+ get enabled(): boolean;
49
+ /**
50
+ * Set this client's enabled state;
51
+ */
52
+ set enabled(state: boolean);
53
+ /**
54
+ * Return a Promise that resolves once the client has updated.
55
+ */
56
+ get pending(): Promise<unknown>;
57
+ /**
58
+ * @returns this client's filter selection.
59
+ */
60
+ get filterBy(): Selection | undefined;
61
+ /**
62
+ * Return a boolean indicating if the client query can be sped up with
63
+ * materialized views of pre-aggregated data. Should return true if changes
64
+ * to the filterBy selection do not change the groupby domain of the client
65
+ * query.
66
+ */
67
+ get filterStable(): boolean;
68
+ /**
69
+ * Prepare the client before the `query()` method is called. Subclasses
70
+ * should override this method as needed, potentially issuing one or more
71
+ * queries to gather data or metadata needed prior to `query` calls.
72
+ */
73
+ prepare(): Promise<void>;
74
+ /**
75
+ * Return a query specifying the data needed by this client.
76
+ * @param filter The filtering criteria to apply in the query.
77
+ * @returns The client query
78
+ */
79
+ query(filter?: FilterExpr | null): ClientQuery;
80
+ /**
81
+ * Called by the coordinator to inform the client that a query is pending.
82
+ * @returns this
83
+ */
84
+ queryPending(): this;
85
+ /**
86
+ * Called by the coordinator to return a query result.
87
+ * @param data The query result.
88
+ * @returns this
89
+ */
90
+ queryResult(data: unknown): this;
91
+ /**
92
+ * Called by the coordinator to report a query execution error.
93
+ * @param error
94
+ * @returns this
95
+ */
96
+ queryError(error: Error): this;
97
+ /**
98
+ * Request the coordinator to execute a query for this client.
99
+ * If an explicit query is not provided, the client `query` method will
100
+ * be called, filtered by the current `filterBy` selection. This method has
101
+ * no effect if the client is not connected to a coordinator. If the client
102
+ * is connected by currently disabled, the request will be serviced if the
103
+ * client is later enabled.
104
+ * @param query The query to request. If unspecified, the query
105
+ * will be determined by the client's `query` method and the current
106
+ * `filterBy` selection state.
107
+ */
108
+ requestQuery(query?: Query): Promise<unknown> | null;
109
+ /**
110
+ * Request that the coordinator perform a throttled update of this client
111
+ * using the default query. Unlike requestQuery, for which every call results
112
+ * in an executed query, multiple calls to requestUpdate may be consolidated
113
+ * into a single update. This method has no effect if the client is not
114
+ * connected to a coordinator. If the client is connected but currently
115
+ * disabled, the request will be serviced if the client is later enabled.
116
+ */
117
+ requestUpdate(): void;
118
+ /**
119
+ * Reset this client, calling the prepare method and query requests. This
120
+ * method has no effect if the client is not registered with a coordinator.
121
+ */
122
+ initialize(): void;
123
+ /**
124
+ * Remove this client: disconnect from the coordinator and free up any
125
+ * resource use. This method has no effect if the client is not connected
126
+ * to a coordinator.
127
+ *
128
+ * If overriding this method in a client subclass, be sure to also
129
+ * disconnect from the coordinator.
130
+ */
131
+ destroy(): void;
132
+ /**
133
+ * Requests a client update, for example to (re-)render an interface
134
+ * component.
135
+ */
136
+ update(): this | Promise<unknown>;
137
+ }
138
+ //# sourceMappingURL=MosaicClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MosaicClient.d.ts","sourceRoot":"","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