@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.
- package/LICENSE +47 -0
- package/README.md +0 -1
- package/dist/src/Coordinator.d.ts +159 -0
- package/dist/src/Coordinator.d.ts.map +1 -0
- package/dist/src/Coordinator.js +250 -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 +214 -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 +322 -0
- package/dist/src/Selection.js.map +1 -0
- package/dist/src/SelectionClause.d.ts +222 -0
- package/dist/src/SelectionClause.d.ts.map +1 -0
- package/dist/src/SelectionClause.js +168 -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 +56 -0
- package/dist/src/connectors/wasm.d.ts.map +1 -0
- package/dist/src/connectors/wasm.js +116 -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/{src → dist/src}/index.js +8 -11
- package/dist/src/index.js.map +1 -0
- package/dist/src/make-client.d.ts +33 -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 +17 -11
- package/src/Coordinator.ts +396 -0
- package/src/{MosaicClient.js → MosaicClient.ts} +50 -43
- package/src/{Param.js → Param.ts} +29 -28
- package/src/{QueryConsolidator.js → QueryConsolidator.ts} +85 -62
- package/src/{QueryManager.js → QueryManager.ts} +61 -54
- package/src/Selection.ts +391 -0
- package/src/SelectionClause.ts +357 -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} +52 -63
- package/src/index.ts +42 -0
- 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} +30 -31
- 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
|
@@ -1,109 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { ExtractionOptions, Table } from '@uwdata/flechette';
|
|
2
|
+
import type { ArrowQueryRequest, Connector, ExecQueryRequest, JSONQueryRequest, ConnectorQueryRequest } from './Connector.js';
|
|
3
3
|
import * as duckdb from '@duckdb/duckdb-wasm';
|
|
4
4
|
import { decodeIPC } from '../util/decode-ipc.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
interface DuckDBWASMOptions {
|
|
7
|
+
/** Flag to enable logging. */
|
|
8
|
+
log?: boolean;
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
interface DuckDBWASMConnectorOptions extends DuckDBWASMOptions {
|
|
12
|
+
/** Arrow IPC extraction options. */
|
|
13
|
+
ipc?: ExtractionOptions;
|
|
14
|
+
/** Optional pre-existing DuckDB-WASM instance. */
|
|
15
|
+
duckdb?: duckdb.AsyncDuckDB;
|
|
16
|
+
/** Optional pre-existing DuckDB-WASM connection. */
|
|
17
|
+
connection?: duckdb.AsyncDuckDBConnection;
|
|
18
|
+
/** Optional database config. */
|
|
19
|
+
config?: duckdb.DuckDBConfig;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Connect to a DuckDB-WASM instance.
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
24
|
+
* @param options Connector options.
|
|
25
|
+
* @returns A connector instance.
|
|
26
26
|
*/
|
|
27
|
-
export function wasmConnector(options = {}) {
|
|
27
|
+
export function wasmConnector(options: DuckDBWASMConnectorOptions = {}): DuckDBWASMConnector {
|
|
28
28
|
return new DuckDBWASMConnector(options);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* DuckDB-WASM connector.
|
|
33
|
-
* @implements {Connector}
|
|
34
33
|
*/
|
|
35
|
-
export class DuckDBWASMConnector {
|
|
34
|
+
export class DuckDBWASMConnector implements Connector {
|
|
35
|
+
private _ipc?: ExtractionOptions;
|
|
36
|
+
public _options: DuckDBWASMOptions;
|
|
37
|
+
public _db?: duckdb.AsyncDuckDB;
|
|
38
|
+
public _con?: duckdb.AsyncDuckDBConnection;
|
|
39
|
+
public _config?: duckdb.DuckDBConfig;
|
|
40
|
+
public _loadPromise?: Promise<unknown>;
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* Create a new DuckDB-WASM connector instance.
|
|
38
|
-
* @param
|
|
44
|
+
* @param options Connector options.
|
|
39
45
|
*/
|
|
40
|
-
constructor(options = {}) {
|
|
41
|
-
const { ipc, duckdb, connection, ...opts } = options;
|
|
42
|
-
/** @type {ExtractionOptions} */
|
|
46
|
+
constructor(options: DuckDBWASMConnectorOptions = {}) {
|
|
47
|
+
const { ipc, duckdb, connection, config, ...opts } = options;
|
|
43
48
|
this._ipc = ipc;
|
|
44
|
-
/** @type {DuckDBWASMOptions} */
|
|
45
49
|
this._options = opts;
|
|
46
|
-
/** @type {duckdb.AsyncDuckDB} */
|
|
47
50
|
this._db = duckdb;
|
|
48
|
-
/** @type {duckdb.AsyncDuckDBConnection} */
|
|
49
51
|
this._con = connection;
|
|
50
|
-
|
|
51
|
-
this._loadPromise;
|
|
52
|
+
this._config = config;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Get the backing DuckDB-WASM instance.
|
|
56
57
|
* Lazily initializes DuckDB-WASM if not already loaded.
|
|
57
|
-
* @returns
|
|
58
|
+
* @returns The DuckDB-WASM instance.
|
|
58
59
|
*/
|
|
59
|
-
async getDuckDB() {
|
|
60
|
+
async getDuckDB(): Promise<duckdb.AsyncDuckDB> {
|
|
60
61
|
if (!this._db) await connect(this);
|
|
61
|
-
return this._db
|
|
62
|
+
return this._db!;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* Get the backing DuckDB-WASM connection.
|
|
66
67
|
* Lazily initializes DuckDB-WASM if not already loaded.
|
|
67
|
-
* @returns
|
|
68
|
+
* @returns The DuckDB-WASM connection.
|
|
68
69
|
*/
|
|
69
|
-
async getConnection() {
|
|
70
|
+
async getConnection(): Promise<duckdb.AsyncDuckDBConnection> {
|
|
70
71
|
if (!this._con) await connect(this);
|
|
71
|
-
return this._con
|
|
72
|
+
return this._con!;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
* @overload
|
|
80
|
-
* @param {ExecQueryRequest} query
|
|
81
|
-
* @returns {Promise<void>}
|
|
82
|
-
*
|
|
83
|
-
* @overload
|
|
84
|
-
* @param {JSONQueryRequest} query
|
|
85
|
-
* @returns {Promise<Record<string, any>[]>}
|
|
86
|
-
*
|
|
87
|
-
* @param {ArrowQueryRequest | ExecQueryRequest | JSONQueryRequest} query
|
|
88
|
-
* @returns {Promise<Table | void | Record<string, any>[]>}}
|
|
89
|
-
*/
|
|
90
|
-
async query(query) {
|
|
75
|
+
async query(query: ArrowQueryRequest): Promise<Table>;
|
|
76
|
+
async query(query: ExecQueryRequest): Promise<void>;
|
|
77
|
+
async query(query: JSONQueryRequest): Promise<Record<string, unknown>[]>;
|
|
78
|
+
async query(query: ConnectorQueryRequest): Promise<unknown> {
|
|
91
79
|
const { type, sql } = query;
|
|
92
80
|
const con = await this.getConnection();
|
|
93
81
|
const result = await getArrowIPC(con, sql);
|
|
94
82
|
return type === 'exec' ? undefined
|
|
95
83
|
: type === 'arrow' ? decodeIPC(result, this._ipc)
|
|
96
84
|
: decodeIPC(result).toArray();
|
|
97
|
-
}
|
|
85
|
+
}
|
|
98
86
|
}
|
|
99
87
|
|
|
100
88
|
/**
|
|
101
89
|
* Bypass duckdb-wasm query method to get Arrow IPC bytes directly.
|
|
102
90
|
* https://github.com/duckdb/duckdb-wasm/issues/267#issuecomment-2252749509
|
|
103
|
-
* @param
|
|
104
|
-
* @param
|
|
91
|
+
* @param con The DuckDB-WASM connection.
|
|
92
|
+
* @param query The SQL query to run.
|
|
105
93
|
*/
|
|
106
|
-
function getArrowIPC(con, query) {
|
|
94
|
+
function getArrowIPC(con: duckdb.AsyncDuckDBConnection, query: string): Promise<Uint8Array> {
|
|
107
95
|
return new Promise((resolve, reject) => {
|
|
108
96
|
con.useUnsafe(async (bindings, conn) => {
|
|
109
97
|
try {
|
|
@@ -118,10 +106,10 @@ function getArrowIPC(con, query) {
|
|
|
118
106
|
|
|
119
107
|
/**
|
|
120
108
|
* Establish a new database connection for the given connector.
|
|
121
|
-
* @param
|
|
122
|
-
* @returns
|
|
109
|
+
* @param c The connector.
|
|
110
|
+
* @returns Connection promise.
|
|
123
111
|
*/
|
|
124
|
-
function connect(c) {
|
|
112
|
+
function connect(c: DuckDBWASMConnector): Promise<unknown> {
|
|
125
113
|
if (!c._loadPromise) {
|
|
126
114
|
// use a loading promise to avoid race conditions
|
|
127
115
|
// synchronizes multiple callees on the same load
|
|
@@ -129,6 +117,7 @@ function connect(c) {
|
|
|
129
117
|
c._db
|
|
130
118
|
? Promise.resolve(c._db)
|
|
131
119
|
: initDatabase(c._options).then(result => c._db = result))
|
|
120
|
+
.then(db => c._config != undefined ? db.open(c._config).then(() => db) : db)
|
|
132
121
|
.then(db => db.connect())
|
|
133
122
|
.then(result => c._con = result);
|
|
134
123
|
}
|
|
@@ -137,11 +126,11 @@ function connect(c) {
|
|
|
137
126
|
|
|
138
127
|
/**
|
|
139
128
|
* Initialize a new DuckDB-WASM instance.
|
|
140
|
-
* @param
|
|
129
|
+
* @param options Database initialization options.
|
|
141
130
|
*/
|
|
142
131
|
async function initDatabase({
|
|
143
132
|
log = false
|
|
144
|
-
} = {}) {
|
|
133
|
+
}: DuckDBWASMOptions = {}): Promise<duckdb.AsyncDuckDB> {
|
|
145
134
|
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
|
146
135
|
|
|
147
136
|
// Select a bundle based on browser checks
|
|
@@ -151,7 +140,7 @@ async function initDatabase({
|
|
|
151
140
|
new Blob([`importScripts("${bundle.mainWorker}");`], {type: 'text/javascript'})
|
|
152
141
|
);
|
|
153
142
|
|
|
154
|
-
// Instantiate the
|
|
143
|
+
// Instantiate the asynchronous version of DuckDB-wasm
|
|
155
144
|
const worker = new Worker(worker_url);
|
|
156
145
|
const logger = log ? new duckdb.ConsoleLogger() : new duckdb.VoidLogger();
|
|
157
146
|
const db = new duckdb.AsyncDuckDB(logger, worker);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { MosaicClient } from './MosaicClient.js';
|
|
2
|
+
export { makeClient } from './make-client.js';
|
|
3
|
+
export { Coordinator, coordinator } from './Coordinator.js';
|
|
4
|
+
export { Selection, isSelection } from './Selection.js';
|
|
5
|
+
export { Param, isParam } from './Param.js';
|
|
6
|
+
export { Priority } from './QueryManager.js';
|
|
7
|
+
|
|
8
|
+
// deprecated in favor of constructors
|
|
9
|
+
export { restConnector } from './connectors/rest.js';
|
|
10
|
+
export { socketConnector } from './connectors/socket.js';
|
|
11
|
+
export { wasmConnector } from './connectors/wasm.js';
|
|
12
|
+
|
|
13
|
+
export { RestConnector } from './connectors/rest.js';
|
|
14
|
+
export { SocketConnector } from './connectors/socket.js';
|
|
15
|
+
export { DuckDBWASMConnector } from './connectors/wasm.js';
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
clauseInterval,
|
|
19
|
+
clauseIntervals,
|
|
20
|
+
clauseList,
|
|
21
|
+
clausePoint,
|
|
22
|
+
clausePoints,
|
|
23
|
+
clauseMatch,
|
|
24
|
+
clauseMatchAny
|
|
25
|
+
} from './SelectionClause.js';
|
|
26
|
+
|
|
27
|
+
export { decodeIPC } from './util/decode-ipc.js';
|
|
28
|
+
export { distinct } from './util/distinct.js';
|
|
29
|
+
export { isArrowTable } from './util/is-arrow-table.js';
|
|
30
|
+
export { Synchronizer } from './util/synchronizer.js';
|
|
31
|
+
export { throttle } from './util/throttle.js';
|
|
32
|
+
export { toDataColumns } from './util/to-data-columns.js';
|
|
33
|
+
export { queryFieldInfo } from './util/field-info.js';
|
|
34
|
+
export { jsType } from './util/js-type.js';
|
|
35
|
+
export { isActivatable } from './util/is-activatable.js';
|
|
36
|
+
export type { QueryResult } from './util/query-result.js';
|
|
37
|
+
|
|
38
|
+
export * from './types.js';
|
|
39
|
+
|
|
40
|
+
export type * from './connectors/Connector.js';
|
|
41
|
+
export type * from './Selection.js';
|
|
42
|
+
export type * from './SelectionClause.js';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Coordinator } from './Coordinator.js';
|
|
2
|
+
import type { Selection } from './Selection.js';
|
|
3
|
+
import type { FilterExpr } from '@uwdata/mosaic-sql';
|
|
4
|
+
import { type ClientQuery, MosaicClient } from './MosaicClient.js';
|
|
5
|
+
import { coordinator as defaultCoordinator } from './Coordinator.js';
|
|
6
|
+
|
|
7
|
+
export interface MakeClientOptions {
|
|
8
|
+
/** Mosaic coordinator. Defaults to the global coordinator. */
|
|
9
|
+
coordinator?: Coordinator;
|
|
10
|
+
/** A selection whose predicates are fed into the query function to produce the SQL query. */
|
|
11
|
+
selection?: Selection;
|
|
12
|
+
/** A flag (default `true`) indicating if the client should initially be enabled or not. */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
/** A flag (default `true`) indicating if client queries can be sped up using pre-aggregated data.
|
|
15
|
+
* Should be set to `false` if filtering changes the groupby domain of the query. */
|
|
16
|
+
filterStable?: boolean;
|
|
17
|
+
/** An async function to prepare the client before running queries. */
|
|
18
|
+
prepare?: () => Promise<void>;
|
|
19
|
+
/** A function that returns a query from a list of selection predicates. */
|
|
20
|
+
query?: (filter: FilterExpr) => ClientQuery;
|
|
21
|
+
/** Called by the coordinator to return a query result. */
|
|
22
|
+
queryResult?: (data: unknown) => void;
|
|
23
|
+
/** Called by the coordinator to inform the client that a query is pending. */
|
|
24
|
+
queryPending?: () => void;
|
|
25
|
+
/** Called by the coordinator to report a query execution error. */
|
|
26
|
+
queryError?: (error: Error) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Make a new client with the given options, and connect the client to the
|
|
31
|
+
* provided coordinator.
|
|
32
|
+
* @param options The options for making the client.
|
|
33
|
+
* @returns The resulting client.
|
|
34
|
+
*/
|
|
35
|
+
export function makeClient(options: MakeClientOptions): MosaicClient {
|
|
36
|
+
const {
|
|
37
|
+
coordinator = defaultCoordinator(),
|
|
38
|
+
...clientOptions
|
|
39
|
+
} = options;
|
|
40
|
+
const client = new ProxyClient(clientOptions);
|
|
41
|
+
coordinator.connect(client);
|
|
42
|
+
return client;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* An internal class used to implement the makeClient API.
|
|
47
|
+
*/
|
|
48
|
+
class ProxyClient extends MosaicClient {
|
|
49
|
+
private readonly _methods: Omit<MakeClientOptions, 'coordinator' | 'selection' | 'enabled' | 'filterStable'>;
|
|
50
|
+
private readonly _filterStable: boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param options The options for making the client.
|
|
54
|
+
*/
|
|
55
|
+
constructor({
|
|
56
|
+
selection = undefined,
|
|
57
|
+
enabled = true,
|
|
58
|
+
filterStable = true,
|
|
59
|
+
...methods
|
|
60
|
+
}: Omit<MakeClientOptions, 'coordinator'>) {
|
|
61
|
+
super(selection);
|
|
62
|
+
this.enabled = enabled;
|
|
63
|
+
this._methods = methods;
|
|
64
|
+
this._filterStable = filterStable;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get filterStable(): boolean {
|
|
68
|
+
return this._filterStable;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async prepare(): Promise<void> {
|
|
72
|
+
await this._methods.prepare?.();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
query(filter: FilterExpr): ClientQuery {
|
|
76
|
+
return this._methods.query?.(filter) ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
queryResult(data: unknown): this {
|
|
80
|
+
this._methods.queryResult?.(data);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
queryPending(): this {
|
|
85
|
+
this._methods.queryPending?.();
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
queryError(error: Error): this {
|
|
90
|
+
this._methods.queryError?.(error);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
}
|