@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.
- package/LICENSE +47 -0
- 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/src/MosaicClient.d.ts +138 -0
- 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/src/connectors/Connector.d.ts +26 -0
- package/dist/src/connectors/Connector.d.ts.map +1 -0
- package/dist/src/connectors/Connector.js +2 -0
- package/dist/src/connectors/Connector.js.map +1 -0
- package/dist/src/connectors/rest.d.ts +24 -0
- package/dist/src/connectors/rest.d.ts.map +1 -0
- package/dist/src/connectors/rest.js +37 -0
- package/dist/src/connectors/rest.js.map +1 -0
- package/dist/src/connectors/socket.d.ts +40 -0
- package/dist/src/connectors/socket.d.ts.map +1 -0
- package/dist/src/connectors/socket.js +115 -0
- package/dist/src/connectors/socket.js.map +1 -0
- package/dist/src/connectors/wasm.d.ts +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/src/preagg/PreAggregator.d.ts +150 -0
- package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
- package/dist/src/preagg/PreAggregator.js +382 -0
- package/dist/src/preagg/PreAggregator.js.map +1 -0
- package/dist/src/preagg/preagg-columns.d.ts +16 -0
- package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
- package/dist/src/preagg/preagg-columns.js +95 -0
- package/dist/src/preagg/preagg-columns.js.map +1 -0
- package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
- package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
- package/dist/src/preagg/sufficient-statistics.js +446 -0
- package/dist/src/preagg/sufficient-statistics.js.map +1 -0
- package/dist/src/types.d.ts +77 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/util/AsyncDispatch.d.ts +121 -0
- package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
- package/dist/src/util/AsyncDispatch.js +188 -0
- package/dist/src/util/AsyncDispatch.js.map +1 -0
- package/dist/src/util/cache.d.ts +19 -0
- package/dist/src/util/cache.d.ts.map +1 -0
- package/dist/src/util/cache.js +66 -0
- package/dist/src/util/cache.js.map +1 -0
- package/dist/src/util/decode-ipc.d.ts +12 -0
- package/dist/src/util/decode-ipc.d.ts.map +1 -0
- package/{src → dist/src}/util/decode-ipc.js +5 -6
- package/dist/src/util/decode-ipc.js.map +1 -0
- package/dist/src/util/distinct.d.ts +3 -0
- package/dist/src/util/distinct.d.ts.map +1 -0
- package/dist/src/util/distinct.js +16 -0
- package/dist/src/util/distinct.js.map +1 -0
- package/dist/src/util/field-info.d.ts +26 -0
- package/dist/src/util/field-info.d.ts.map +1 -0
- package/dist/src/util/field-info.js +91 -0
- package/dist/src/util/field-info.js.map +1 -0
- package/dist/src/util/hash.d.ts +2 -0
- package/dist/src/util/hash.d.ts.map +1 -0
- package/dist/src/util/hash.js +26 -0
- package/dist/src/util/hash.js.map +1 -0
- package/dist/src/util/is-activatable.d.ts +8 -0
- package/dist/src/util/is-activatable.d.ts.map +1 -0
- package/dist/src/util/is-activatable.js +10 -0
- package/dist/src/util/is-activatable.js.map +1 -0
- package/dist/src/util/is-arrow-table.d.ts +9 -0
- package/dist/src/util/is-arrow-table.d.ts.map +1 -0
- package/dist/src/util/is-arrow-table.js +11 -0
- package/dist/src/util/is-arrow-table.js.map +1 -0
- package/dist/src/util/js-type.d.ts +9 -0
- package/dist/src/util/js-type.d.ts.map +1 -0
- package/dist/src/util/js-type.js +59 -0
- package/dist/src/util/js-type.js.map +1 -0
- package/dist/src/util/priority-queue.d.ts +35 -0
- package/dist/src/util/priority-queue.d.ts.map +1 -0
- package/dist/src/util/priority-queue.js +81 -0
- package/dist/src/util/priority-queue.js.map +1 -0
- package/dist/src/util/query-result.d.ts +47 -0
- package/dist/src/util/query-result.d.ts.map +1 -0
- package/dist/src/util/query-result.js +83 -0
- package/dist/src/util/query-result.js.map +1 -0
- package/dist/src/util/synchronizer.d.ts +36 -0
- package/dist/src/util/synchronizer.d.ts.map +1 -0
- package/dist/src/util/synchronizer.js +52 -0
- package/dist/src/util/synchronizer.js.map +1 -0
- package/dist/src/util/throttle.d.ts +12 -0
- package/dist/src/util/throttle.d.ts.map +1 -0
- package/dist/src/util/throttle.js +51 -0
- package/dist/src/util/throttle.js.map +1 -0
- package/dist/src/util/to-data-columns.d.ts +22 -0
- package/dist/src/util/to-data-columns.d.ts.map +1 -0
- package/dist/src/util/to-data-columns.js +51 -0
- package/dist/src/util/to-data-columns.js.map +1 -0
- package/dist/src/util/void-logger.d.ts +13 -0
- package/dist/src/util/void-logger.d.ts.map +1 -0
- package/dist/src/util/void-logger.js +13 -0
- package/dist/src/util/void-logger.js.map +1 -0
- package/package.json +16 -10
- 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} +160 -110
- package/src/types.ts +24 -9
- package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
- package/src/util/{cache.js → cache.ts} +25 -15
- package/src/util/decode-ipc.ts +15 -0
- package/src/util/{distinct.js → distinct.ts} +3 -3
- package/src/util/{field-info.js → field-info.ts} +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/src/Coordinator.js +0 -313
- package/src/Selection.js +0 -380
- package/src/SelectionClause.js +0 -159
- package/src/connectors/rest.js +0 -38
- package/src/index-types.ts +0 -5
- package/src/make-client.js +0 -101
- package/src/util/is-activatable.js +0 -8
- package/src/util/is-arrow-table.js +0 -10
- package/src/util/selection-types.ts +0 -137
- package/src/util/synchronizer.js +0 -47
- package/src/util/throttle.js +0 -54
- package/src/util/to-data-columns.js +0 -60
- package/src/util/void-logger.js +0 -13
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -3
package/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,147 @@
|
|
|
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
|
+
interface FilterGroupEntry {
|
|
10
|
+
selection: Selection;
|
|
11
|
+
clients: Set<MosaicClient>;
|
|
12
|
+
disconnect(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Set or retrieve the coordinator instance.
|
|
16
|
+
* @param instance The coordinator instance to set
|
|
17
|
+
* @returns The coordinator instance
|
|
18
|
+
*/
|
|
19
|
+
export declare function coordinator(instance?: Coordinator): Coordinator;
|
|
20
|
+
/**
|
|
21
|
+
* A Mosaic Coordinator manages all database communication for clients and
|
|
22
|
+
* handles selection updates. The Coordinator also performs optimizations
|
|
23
|
+
* including query caching, consolidation, and pre-aggregation.
|
|
24
|
+
*/
|
|
25
|
+
export declare class Coordinator {
|
|
26
|
+
manager: QueryManager;
|
|
27
|
+
preaggregator: PreAggregator;
|
|
28
|
+
clients: Set<MosaicClient>;
|
|
29
|
+
filterGroups: Map<Selection, FilterGroupEntry>;
|
|
30
|
+
protected _logger: Logger;
|
|
31
|
+
/**
|
|
32
|
+
* @param db Database connector. Defaults to a web socket connection.
|
|
33
|
+
* @param options Coordinator options.
|
|
34
|
+
* @param options.logger The logger to use, defaults to `console`.
|
|
35
|
+
* @param options.manager The query manager to use.
|
|
36
|
+
* @param options.cache Boolean flag to enable/disable query caching.
|
|
37
|
+
* @param options.consolidate Boolean flag to enable/disable query consolidation.
|
|
38
|
+
* @param options.preagg Options for the Pre-aggregator.
|
|
39
|
+
*/
|
|
40
|
+
constructor(db?: Connector, options?: {
|
|
41
|
+
logger?: Logger | null;
|
|
42
|
+
manager?: QueryManager;
|
|
43
|
+
cache?: boolean;
|
|
44
|
+
consolidate?: boolean;
|
|
45
|
+
preagg?: PreAggregateOptions;
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Clear the coordinator state.
|
|
49
|
+
* @param options Options object.
|
|
50
|
+
* @param options.clients If true, disconnect all clients.
|
|
51
|
+
* @param options.cache If true, clear the query cache.
|
|
52
|
+
*/
|
|
53
|
+
clear(options?: {
|
|
54
|
+
clients?: boolean;
|
|
55
|
+
cache?: boolean;
|
|
56
|
+
}): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get or set the database connector.
|
|
59
|
+
* @param db The database connector to use.
|
|
60
|
+
* @returns The current database connector.
|
|
61
|
+
*/
|
|
62
|
+
databaseConnector(): Connector | null;
|
|
63
|
+
databaseConnector(db: Connector): Connector;
|
|
64
|
+
/**
|
|
65
|
+
* Get or set the logger.
|
|
66
|
+
* @param logger The logger to use.
|
|
67
|
+
* @returns The current logger
|
|
68
|
+
*/
|
|
69
|
+
logger(logger?: Logger | null): Logger;
|
|
70
|
+
/**
|
|
71
|
+
* Cancel previously submitted query requests. These queries will be
|
|
72
|
+
* canceled if they are queued but have not yet been submitted.
|
|
73
|
+
* @param requests An array of query result objects, such as those returned by the `query` method.
|
|
74
|
+
*/
|
|
75
|
+
cancel(requests: QueryResult[]): void;
|
|
76
|
+
/**
|
|
77
|
+
* Issue a query for which no result (return value) is needed.
|
|
78
|
+
* @param query The query or an array of queries. Each query should be either a Query builder object or a SQL string.
|
|
79
|
+
* @param options An options object.
|
|
80
|
+
* @param options.priority The query priority, defaults to `Priority.Normal`.
|
|
81
|
+
* @returns A query result promise.
|
|
82
|
+
*/
|
|
83
|
+
exec(query: MaybeArray<QueryType>, options?: {
|
|
84
|
+
priority?: number;
|
|
85
|
+
}): QueryResult;
|
|
86
|
+
/**
|
|
87
|
+
* Issue a query to the backing database. The submitted query may be
|
|
88
|
+
* consolidate with other queries and its results may be cached.
|
|
89
|
+
* @param query The query as either a Query builder object or a SQL string.
|
|
90
|
+
* @param options An options object.
|
|
91
|
+
* @param options.type The query result format type.
|
|
92
|
+
* @param options.cache If true, cache the query result client-side within the QueryManager.
|
|
93
|
+
* @param options.persist If true, request the database server to persist a cached query server-side.
|
|
94
|
+
* @param options.priority The query priority, defaults to `Priority.Normal`.
|
|
95
|
+
* @returns A query result promise.
|
|
96
|
+
*/
|
|
97
|
+
query(query: QueryType, options?: {
|
|
98
|
+
type?: 'arrow' | 'json';
|
|
99
|
+
cache?: boolean;
|
|
100
|
+
persist?: boolean;
|
|
101
|
+
priority?: number;
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
}): QueryResult;
|
|
104
|
+
/**
|
|
105
|
+
* Issue a query to prefetch data for later use. The query result is cached
|
|
106
|
+
* for efficient future access.
|
|
107
|
+
* @param query The query as either a Query builder object or a SQL string.
|
|
108
|
+
* @param options An options object.
|
|
109
|
+
* @param options.type The query result format type.
|
|
110
|
+
* @returns A query result promise.
|
|
111
|
+
*/
|
|
112
|
+
prefetch(query: QueryType, options?: {
|
|
113
|
+
type?: 'arrow' | 'json';
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}): QueryResult;
|
|
116
|
+
/**
|
|
117
|
+
* Update client data by submitting the given query and returning the()
|
|
118
|
+
* data (or error) to the client.
|
|
119
|
+
* @param client A Mosaic client.
|
|
120
|
+
* @param query The data query.
|
|
121
|
+
* @param priority The query priority.
|
|
122
|
+
* @returns A Promise that resolves upon completion of the update.
|
|
123
|
+
*/
|
|
124
|
+
updateClient(client: MosaicClient, query: QueryType, priority?: number): Promise<unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* Issue a query request for a client. If the query is null or undefined,
|
|
127
|
+
* the client is simply updated. Otherwise `updateClient` is called. As a
|
|
128
|
+
* side effect, this method clears the current preaggregator state.
|
|
129
|
+
* @param client The client to update.
|
|
130
|
+
* @param query The query to issue.
|
|
131
|
+
*/
|
|
132
|
+
requestQuery(client: MosaicClient, query?: QueryType | null): Promise<unknown>;
|
|
133
|
+
/**
|
|
134
|
+
* Connect a client to the coordinator.
|
|
135
|
+
* Throws an error if the client is already connected.
|
|
136
|
+
* @param client The Mosaic client to connect.
|
|
137
|
+
*/
|
|
138
|
+
connect(client: MosaicClient): void;
|
|
139
|
+
/**
|
|
140
|
+
* Disconnect a client from the coordinator.
|
|
141
|
+
* This method has no effect if the client is already disconnected.
|
|
142
|
+
* @param client The Mosaic client to disconnect.
|
|
143
|
+
*/
|
|
144
|
+
disconnect(client: MosaicClient): void;
|
|
145
|
+
}
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=Coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Coordinator.d.ts","sourceRoot":"","sources":["../../src/Coordinator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAY,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,KAAK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AE,MAAM,CAAA;KAAO,GAClC,WAAW;IAMd;;;;;;;;;;OAUG;IACH,KAAK,CACH,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE;QACP,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;QACxB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACnB,GACL,WAAW;IAUd;;;;;;;OAOG;IACH,QAAQ,CACN,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAO,GAChE,WAAW;IAMd;;;;;;;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,269 @@
|
|
|
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
|
+
/**
|
|
110
|
+
* Issue a query to the backing database. The submitted query may be
|
|
111
|
+
* consolidate with other queries and its results may be cached.
|
|
112
|
+
* @param query The query as either a Query builder object or a SQL string.
|
|
113
|
+
* @param options An options object.
|
|
114
|
+
* @param options.type The query result format type.
|
|
115
|
+
* @param options.cache If true, cache the query result client-side within the QueryManager.
|
|
116
|
+
* @param options.persist If true, request the database server to persist a cached query server-side.
|
|
117
|
+
* @param options.priority The query priority, defaults to `Priority.Normal`.
|
|
118
|
+
* @returns A query result promise.
|
|
119
|
+
*/
|
|
120
|
+
query(query, options = {}) {
|
|
121
|
+
const { type = 'arrow', cache = true, priority = Priority.Normal, ...otherOptions } = options;
|
|
122
|
+
return this.manager.request({ type, query, cache, options: otherOptions }, priority);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Issue a query to prefetch data for later use. The query result is cached
|
|
126
|
+
* for efficient future access.
|
|
127
|
+
* @param query The query as either a Query builder object or a SQL string.
|
|
128
|
+
* @param options An options object.
|
|
129
|
+
* @param options.type The query result format type.
|
|
130
|
+
* @returns A query result promise.
|
|
131
|
+
*/
|
|
132
|
+
prefetch(query, options = {}) {
|
|
133
|
+
return this.query(query, { ...options, cache: true, priority: Priority.Low });
|
|
134
|
+
}
|
|
135
|
+
// -- Client Management ----
|
|
136
|
+
/**
|
|
137
|
+
* Update client data by submitting the given query and returning the()
|
|
138
|
+
* data (or error) to the client.
|
|
139
|
+
* @param client A Mosaic client.
|
|
140
|
+
* @param query The data query.
|
|
141
|
+
* @param priority The query priority.
|
|
142
|
+
* @returns A Promise that resolves upon completion of the update.
|
|
143
|
+
*/
|
|
144
|
+
updateClient(client, query, priority = Priority.Normal) {
|
|
145
|
+
client.queryPending();
|
|
146
|
+
return client._pending = this.query(query, { priority })
|
|
147
|
+
.then(data => client.queryResult(data).update(), err => { this._logger?.error(err); client.queryError(err); })
|
|
148
|
+
.catch(err => this._logger?.error(err));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Issue a query request for a client. If the query is null or undefined,
|
|
152
|
+
* the client is simply updated. Otherwise `updateClient` is called. As a
|
|
153
|
+
* side effect, this method clears the current preaggregator state.
|
|
154
|
+
* @param client The client to update.
|
|
155
|
+
* @param query The query to issue.
|
|
156
|
+
*/
|
|
157
|
+
requestQuery(client, query) {
|
|
158
|
+
this.preaggregator.clear();
|
|
159
|
+
return query
|
|
160
|
+
? this.updateClient(client, query)
|
|
161
|
+
: Promise.resolve(client.update());
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Connect a client to the coordinator.
|
|
165
|
+
* Throws an error if the client is already connected.
|
|
166
|
+
* @param client The Mosaic client to connect.
|
|
167
|
+
*/
|
|
168
|
+
connect(client) {
|
|
169
|
+
const { clients } = this;
|
|
170
|
+
if (clients?.has(client)) {
|
|
171
|
+
throw new Error('Client already connected.');
|
|
172
|
+
}
|
|
173
|
+
// add client to client set
|
|
174
|
+
clients?.add(client);
|
|
175
|
+
// register coordinator on client instance
|
|
176
|
+
client.coordinator = this;
|
|
177
|
+
// initialize client lifecycle
|
|
178
|
+
client.initialize();
|
|
179
|
+
// connect filter selection
|
|
180
|
+
connectSelection(this, client.filterBy, client);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Disconnect a client from the coordinator.
|
|
184
|
+
* This method has no effect if the client is already disconnected.
|
|
185
|
+
* @param client The Mosaic client to disconnect.
|
|
186
|
+
*/
|
|
187
|
+
disconnect(client) {
|
|
188
|
+
const { clients, filterGroups } = this;
|
|
189
|
+
if (!clients?.has(client))
|
|
190
|
+
return;
|
|
191
|
+
clients.delete(client);
|
|
192
|
+
client.coordinator = null;
|
|
193
|
+
const group = filterGroups?.get(client.filterBy);
|
|
194
|
+
if (group) {
|
|
195
|
+
group.clients.delete(client);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Connect a selection-client pair to the coordinator to process updates.
|
|
201
|
+
* @param mc The Mosaic coordinator.
|
|
202
|
+
* @param selection A selection.
|
|
203
|
+
* @param client A Mosaic client that is filtered by the given selection.
|
|
204
|
+
*/
|
|
205
|
+
function connectSelection(mc, selection, client) {
|
|
206
|
+
if (!selection)
|
|
207
|
+
return;
|
|
208
|
+
let entry = mc.filterGroups?.get(selection);
|
|
209
|
+
if (!entry) {
|
|
210
|
+
const activate = (clause) => activateSelection(mc, selection, clause);
|
|
211
|
+
const value = () => updateSelection(mc, selection);
|
|
212
|
+
// @ts-expect-error todo: update selection dispatch types
|
|
213
|
+
selection.addEventListener('activate', activate);
|
|
214
|
+
selection.addEventListener('value', value);
|
|
215
|
+
entry = {
|
|
216
|
+
selection,
|
|
217
|
+
clients: new Set,
|
|
218
|
+
disconnect() {
|
|
219
|
+
// @ts-expect-error todo: update selection dispatch types
|
|
220
|
+
selection.removeEventListener('activate', activate);
|
|
221
|
+
selection.removeEventListener('value', value);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
mc.filterGroups?.set(selection, entry);
|
|
225
|
+
}
|
|
226
|
+
entry.clients.add(client);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Activate a selection, providing a clause indicative of potential
|
|
230
|
+
* next updates. Activation provides a preview of likely next events,
|
|
231
|
+
* enabling potential precomputation to optimize updates.
|
|
232
|
+
* @param mc The Mosaic coordinator.
|
|
233
|
+
* @param selection A selection.
|
|
234
|
+
* @param clause A selection clause for the activation.
|
|
235
|
+
*/
|
|
236
|
+
function activateSelection(mc, selection, clause) {
|
|
237
|
+
const { preaggregator, filterGroups } = mc;
|
|
238
|
+
const { clients } = filterGroups.get(selection);
|
|
239
|
+
for (const client of clients) {
|
|
240
|
+
if (client.enabled) {
|
|
241
|
+
preaggregator.request(client, selection, clause);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Process an updated selection value, querying filtered data for any
|
|
247
|
+
* associated clients.
|
|
248
|
+
* @param mc The Mosaic coordinator.
|
|
249
|
+
* @param selection A selection.
|
|
250
|
+
* @returns A Promise that resolves when the update completes.
|
|
251
|
+
*/
|
|
252
|
+
function updateSelection(mc, selection) {
|
|
253
|
+
const { preaggregator, filterGroups } = mc;
|
|
254
|
+
const { clients } = filterGroups.get(selection);
|
|
255
|
+
const { active } = selection;
|
|
256
|
+
return Promise.allSettled(Array.from(clients, (client) => {
|
|
257
|
+
if (!client.enabled)
|
|
258
|
+
return client.requestQuery();
|
|
259
|
+
const info = preaggregator.request(client, selection, active);
|
|
260
|
+
const filter = info ? null : selection.predicate(client);
|
|
261
|
+
// skip due to cross-filtering
|
|
262
|
+
if (info?.skip || (!info && !filter))
|
|
263
|
+
return;
|
|
264
|
+
// @ts-expect-error FIXME
|
|
265
|
+
const query = info?.query(active.predicate) ?? client.query(filter);
|
|
266
|
+
return mc.updateClient(client, query);
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
//# 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;AAc3D;;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,SAA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
|
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 @@
|
|
|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