@uwdata/mosaic-core 0.16.2 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +0 -1
- package/dist/src/Coordinator.d.ts +147 -0
- package/dist/src/Coordinator.d.ts.map +1 -0
- package/dist/src/Coordinator.js +269 -0
- package/dist/src/Coordinator.js.map +1 -0
- package/dist/{types → src}/MosaicClient.d.ts +37 -42
- package/dist/src/MosaicClient.d.ts.map +1 -0
- package/dist/src/MosaicClient.js +213 -0
- package/dist/src/MosaicClient.js.map +1 -0
- package/dist/src/Param.d.ts +56 -0
- package/dist/src/Param.d.ts.map +1 -0
- package/dist/src/Param.js +89 -0
- package/dist/src/Param.js.map +1 -0
- package/dist/src/QueryConsolidator.d.ts +11 -0
- package/dist/src/QueryConsolidator.d.ts.map +1 -0
- package/dist/src/QueryConsolidator.js +249 -0
- package/dist/src/QueryConsolidator.js.map +1 -0
- package/dist/src/QueryManager.d.ts +77 -0
- package/dist/src/QueryManager.d.ts.map +1 -0
- package/dist/src/QueryManager.js +174 -0
- package/dist/src/QueryManager.js.map +1 -0
- package/dist/src/Selection.d.ts +222 -0
- package/dist/src/Selection.d.ts.map +1 -0
- package/dist/src/Selection.js +319 -0
- package/dist/src/Selection.js.map +1 -0
- package/dist/src/SelectionClause.d.ts +192 -0
- package/dist/src/SelectionClause.d.ts.map +1 -0
- package/dist/src/SelectionClause.js +126 -0
- package/dist/src/SelectionClause.js.map +1 -0
- package/dist/{types → src}/connectors/Connector.d.ts +6 -5
- package/dist/src/connectors/Connector.d.ts.map +1 -0
- package/dist/src/connectors/Connector.js +2 -0
- package/dist/src/connectors/Connector.js.map +1 -0
- package/dist/src/connectors/rest.d.ts +24 -0
- package/dist/src/connectors/rest.d.ts.map +1 -0
- package/dist/src/connectors/rest.js +37 -0
- package/dist/src/connectors/rest.js.map +1 -0
- package/dist/src/connectors/socket.d.ts +40 -0
- package/dist/src/connectors/socket.d.ts.map +1 -0
- package/dist/src/connectors/socket.js +115 -0
- package/dist/src/connectors/socket.js.map +1 -0
- package/dist/src/connectors/wasm.d.ts +53 -0
- package/dist/src/connectors/wasm.d.ts.map +1 -0
- package/dist/src/connectors/wasm.js +113 -0
- package/dist/src/connectors/wasm.js.map +1 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +25 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/make-client.d.ts +35 -0
- package/dist/src/make-client.d.ts.map +1 -0
- package/dist/src/make-client.js +52 -0
- package/dist/src/make-client.js.map +1 -0
- package/dist/{types → src}/preagg/PreAggregator.d.ts +64 -94
- package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
- package/dist/src/preagg/PreAggregator.js +382 -0
- package/dist/src/preagg/PreAggregator.js.map +1 -0
- package/dist/{types → src}/preagg/preagg-columns.d.ts +10 -8
- package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
- package/dist/src/preagg/preagg-columns.js +95 -0
- package/dist/src/preagg/preagg-columns.js.map +1 -0
- package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
- package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
- package/dist/src/preagg/sufficient-statistics.js +446 -0
- package/dist/src/preagg/sufficient-statistics.js.map +1 -0
- package/dist/{types → src}/types.d.ts +23 -9
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/{types → src}/util/AsyncDispatch.d.ts +53 -32
- package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
- package/dist/src/util/AsyncDispatch.js +188 -0
- package/dist/src/util/AsyncDispatch.js.map +1 -0
- package/dist/src/util/cache.d.ts +19 -0
- package/dist/src/util/cache.d.ts.map +1 -0
- package/dist/src/util/cache.js +66 -0
- package/dist/src/util/cache.js.map +1 -0
- package/dist/src/util/decode-ipc.d.ts +12 -0
- package/dist/src/util/decode-ipc.d.ts.map +1 -0
- package/{src → dist/src}/util/decode-ipc.js +5 -6
- package/dist/src/util/decode-ipc.js.map +1 -0
- package/dist/src/util/distinct.d.ts +3 -0
- package/dist/src/util/distinct.d.ts.map +1 -0
- package/dist/src/util/distinct.js +16 -0
- package/dist/src/util/distinct.js.map +1 -0
- package/dist/src/util/field-info.d.ts +26 -0
- package/dist/src/util/field-info.d.ts.map +1 -0
- package/dist/src/util/field-info.js +91 -0
- package/dist/src/util/field-info.js.map +1 -0
- package/dist/src/util/hash.d.ts +2 -0
- package/dist/src/util/hash.d.ts.map +1 -0
- package/dist/src/util/hash.js +26 -0
- package/dist/src/util/hash.js.map +1 -0
- package/dist/src/util/is-activatable.d.ts +8 -0
- package/dist/src/util/is-activatable.d.ts.map +1 -0
- package/dist/src/util/is-activatable.js +10 -0
- package/dist/src/util/is-activatable.js.map +1 -0
- package/dist/src/util/is-arrow-table.d.ts +9 -0
- package/dist/src/util/is-arrow-table.d.ts.map +1 -0
- package/dist/src/util/is-arrow-table.js +11 -0
- package/dist/src/util/is-arrow-table.js.map +1 -0
- package/dist/src/util/js-type.d.ts +9 -0
- package/dist/src/util/js-type.d.ts.map +1 -0
- package/dist/src/util/js-type.js +59 -0
- package/dist/src/util/js-type.js.map +1 -0
- package/dist/{types → src}/util/priority-queue.d.ts +12 -14
- package/dist/src/util/priority-queue.d.ts.map +1 -0
- package/dist/src/util/priority-queue.js +81 -0
- package/dist/src/util/priority-queue.js.map +1 -0
- package/dist/src/util/query-result.d.ts +47 -0
- package/dist/src/util/query-result.d.ts.map +1 -0
- package/dist/src/util/query-result.js +83 -0
- package/dist/src/util/query-result.js.map +1 -0
- package/dist/src/util/synchronizer.d.ts +36 -0
- package/dist/src/util/synchronizer.d.ts.map +1 -0
- package/dist/src/util/synchronizer.js +52 -0
- package/dist/src/util/synchronizer.js.map +1 -0
- package/dist/src/util/throttle.d.ts +12 -0
- package/dist/src/util/throttle.d.ts.map +1 -0
- package/dist/src/util/throttle.js +51 -0
- package/dist/src/util/throttle.js.map +1 -0
- package/dist/src/util/to-data-columns.d.ts +22 -0
- package/dist/src/util/to-data-columns.d.ts.map +1 -0
- package/dist/src/util/to-data-columns.js +51 -0
- package/dist/src/util/to-data-columns.js.map +1 -0
- package/dist/src/util/void-logger.d.ts +13 -0
- package/dist/src/util/void-logger.d.ts.map +1 -0
- package/dist/src/util/void-logger.js +13 -0
- package/dist/src/util/void-logger.js.map +1 -0
- package/package.json +15 -13
- package/src/Coordinator.ts +367 -0
- package/src/{MosaicClient.js → MosaicClient.ts} +49 -43
- package/src/{Param.js → Param.ts} +29 -28
- package/src/{QueryConsolidator.js → QueryConsolidator.ts} +81 -58
- package/src/{QueryManager.js → QueryManager.ts} +61 -54
- package/src/Selection.ts +388 -0
- package/src/SelectionClause.ts +275 -0
- package/src/connectors/Connector.ts +6 -6
- package/src/connectors/rest.ts +56 -0
- package/src/connectors/{socket.js → socket.ts} +53 -42
- package/src/connectors/{wasm.js → wasm.ts} +46 -62
- package/src/{index.js → index.ts} +13 -1
- package/src/make-client.ts +93 -0
- package/src/preagg/{PreAggregator.js → PreAggregator.ts} +164 -145
- package/src/preagg/{preagg-columns.js → preagg-columns.ts} +27 -24
- package/src/preagg/{sufficient-statistics.js → sufficient-statistics.ts} +161 -110
- package/src/types.ts +24 -9
- package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
- package/src/util/{cache.js → cache.ts} +25 -15
- package/src/util/decode-ipc.ts +15 -0
- package/src/util/{distinct.js → distinct.ts} +3 -3
- package/src/util/{field-info.js → field-info.ts} +31 -32
- package/src/util/{hash.js → hash.ts} +4 -4
- package/src/util/is-activatable.ts +11 -0
- package/src/util/is-arrow-table.ts +12 -0
- package/src/util/{js-type.js → js-type.ts} +7 -5
- package/src/util/{priority-queue.js → priority-queue.ts} +32 -20
- package/src/util/{query-result.js → query-result.ts} +24 -17
- package/src/util/synchronizer.ts +56 -0
- package/src/util/throttle.ts +59 -0
- package/src/util/to-data-columns.ts +65 -0
- package/src/util/void-logger.ts +23 -0
- package/dist/types/Coordinator.d.ts +0 -164
- package/dist/types/Param.d.ts +0 -47
- package/dist/types/QueryConsolidator.d.ts +0 -9
- package/dist/types/QueryManager.d.ts +0 -91
- package/dist/types/Selection.d.ts +0 -235
- package/dist/types/SelectionClause.d.ts +0 -105
- package/dist/types/connectors/rest.d.ts +0 -13
- package/dist/types/connectors/socket.d.ts +0 -100
- package/dist/types/connectors/wasm.d.ts +0 -135
- package/dist/types/index-types.d.ts +0 -4
- package/dist/types/index.d.ts +0 -19
- package/dist/types/make-client.d.ts +0 -78
- package/dist/types/preagg/sufficient-statistics.d.ts +0 -13
- package/dist/types/util/cache.d.ts +0 -17
- package/dist/types/util/decode-ipc.d.ts +0 -12
- package/dist/types/util/distinct.d.ts +0 -2
- package/dist/types/util/field-info.d.ts +0 -23
- package/dist/types/util/hash.d.ts +0 -1
- package/dist/types/util/is-activatable.d.ts +0 -6
- package/dist/types/util/is-arrow-table.d.ts +0 -8
- package/dist/types/util/js-type.d.ts +0 -7
- package/dist/types/util/query-result.d.ts +0 -44
- package/dist/types/util/selection-types.d.ts +0 -114
- package/dist/types/util/synchronizer.d.ts +0 -29
- package/dist/types/util/throttle.d.ts +0 -13
- package/dist/types/util/to-data-columns.d.ts +0 -29
- package/dist/types/util/void-logger.d.ts +0 -10
- package/jsconfig.json +0 -11
- package/src/Coordinator.js +0 -337
- package/src/Selection.js +0 -380
- package/src/SelectionClause.js +0 -159
- package/src/connectors/rest.js +0 -38
- package/src/index-types.ts +0 -4
- package/src/make-client.js +0 -101
- package/src/util/is-activatable.js +0 -8
- package/src/util/is-arrow-table.js +0 -10
- package/src/util/selection-types.ts +0 -137
- package/src/util/synchronizer.js +0 -47
- package/src/util/throttle.js +0 -54
- package/src/util/to-data-columns.js +0 -60
- package/src/util/void-logger.js +0 -13
- package/tsconfig.json +0 -11
- package/vitest.config.ts +0 -3
|
@@ -5,23 +5,30 @@ export const QueryState = Object.freeze({
|
|
|
5
5
|
done: Symbol('done')
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
+
type QueryStateType = typeof QueryState[keyof typeof QueryState];
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* A query result Promise that can allows external callers
|
|
10
12
|
* to resolve or reject the Promise.
|
|
11
13
|
*/
|
|
12
|
-
export class QueryResult extends Promise {
|
|
14
|
+
export class QueryResult<T = unknown> extends Promise<T> {
|
|
15
|
+
private _resolve!: (value: T | PromiseLike<T>) => void;
|
|
16
|
+
private _reject!: (reason?: unknown) => void;
|
|
17
|
+
private _state: QueryStateType;
|
|
18
|
+
private _value: T | undefined;
|
|
19
|
+
|
|
13
20
|
/**
|
|
14
21
|
* Create a new query result Promise.
|
|
15
22
|
*/
|
|
16
23
|
constructor() {
|
|
17
|
-
let resolve;
|
|
18
|
-
let reject;
|
|
24
|
+
let resolve: (value: T | PromiseLike<T>) => void;
|
|
25
|
+
let reject: (reason?: unknown) => void;
|
|
19
26
|
super((r, e) => {
|
|
20
27
|
resolve = r;
|
|
21
28
|
reject = e;
|
|
22
29
|
});
|
|
23
|
-
this._resolve = resolve
|
|
24
|
-
this._reject = reject
|
|
30
|
+
this._resolve = resolve!;
|
|
31
|
+
this._reject = reject!;
|
|
25
32
|
this._state = QueryState.pending;
|
|
26
33
|
this._value = undefined;
|
|
27
34
|
}
|
|
@@ -29,10 +36,10 @@ export class QueryResult extends Promise {
|
|
|
29
36
|
/**
|
|
30
37
|
* Resolve the result Promise with a prepared value or the provided value.
|
|
31
38
|
* This method will only succeed if either a value is provided or the promise is ready.
|
|
32
|
-
* @param
|
|
33
|
-
* @returns
|
|
39
|
+
* @param value The result value.
|
|
40
|
+
* @returns This QueryResult instance.
|
|
34
41
|
*/
|
|
35
|
-
fulfill(value) {
|
|
42
|
+
fulfill(value?: T): this {
|
|
36
43
|
if (this._value !== undefined) {
|
|
37
44
|
if (value !== undefined) {
|
|
38
45
|
throw Error('Promise is ready and fulfill has a provided value');
|
|
@@ -51,10 +58,10 @@ export class QueryResult extends Promise {
|
|
|
51
58
|
|
|
52
59
|
/**
|
|
53
60
|
* Prepare to resolve with the provided value.
|
|
54
|
-
* @param
|
|
55
|
-
* @returns
|
|
61
|
+
* @param value The result value.
|
|
62
|
+
* @returns This QueryResult instance.
|
|
56
63
|
*/
|
|
57
|
-
ready(value) {
|
|
64
|
+
ready(value: T): this {
|
|
58
65
|
this._state = QueryState.ready;
|
|
59
66
|
this._value = value;
|
|
60
67
|
return this;
|
|
@@ -62,10 +69,10 @@ export class QueryResult extends Promise {
|
|
|
62
69
|
|
|
63
70
|
/**
|
|
64
71
|
* Rejects the result Promise with the provided error.
|
|
65
|
-
* @param
|
|
66
|
-
* @returns
|
|
72
|
+
* @param error The error value.
|
|
73
|
+
* @returns This QueryResult instance.
|
|
67
74
|
*/
|
|
68
|
-
reject(error) {
|
|
75
|
+
reject(error: unknown): this {
|
|
69
76
|
this._state = QueryState.error;
|
|
70
77
|
this._reject(error);
|
|
71
78
|
return this;
|
|
@@ -73,12 +80,12 @@ export class QueryResult extends Promise {
|
|
|
73
80
|
|
|
74
81
|
/**
|
|
75
82
|
* Returns the state of this query result.
|
|
76
|
-
* @returns
|
|
83
|
+
* @returns The current state symbol.
|
|
77
84
|
*/
|
|
78
|
-
get state() {
|
|
85
|
+
get state(): QueryStateType {
|
|
79
86
|
return this._state;
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
// necessary to make Promise subclass act like a Promise
|
|
84
|
-
QueryResult.prototype.constructor = Promise;
|
|
91
|
+
QueryResult.prototype.constructor = Promise;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronizer class to aid synchronization of updates on multiple pending operations.
|
|
3
|
+
*/
|
|
4
|
+
export class Synchronizer<T = unknown> {
|
|
5
|
+
private _set: Set<T>;
|
|
6
|
+
private _done: () => void;
|
|
7
|
+
private _promise: Promise<void>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a new synchronizer instance.
|
|
11
|
+
*/
|
|
12
|
+
constructor() {
|
|
13
|
+
this._set = new Set<T>();
|
|
14
|
+
this._done = () => {};
|
|
15
|
+
this._promise = new Promise<void>(resolve => this._done = resolve);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mark an item as pending.
|
|
20
|
+
* @param item An item to synchronize on.
|
|
21
|
+
*/
|
|
22
|
+
pending(item: T): void {
|
|
23
|
+
this._set.add(item);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Mark a pending item as ready, indicating it is
|
|
28
|
+
* ready for a synchronized update.
|
|
29
|
+
* @param item An item to synchronize on.
|
|
30
|
+
* @returns True if the synchronizer is ready to
|
|
31
|
+
* resolve, false otherwise.
|
|
32
|
+
*/
|
|
33
|
+
ready(item: T): boolean {
|
|
34
|
+
this._set.delete(item);
|
|
35
|
+
return this._set.size === 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resolve the current synchronization cycle, causing the synchronize
|
|
40
|
+
* promise to resolve and thereby trigger downstream updates.
|
|
41
|
+
*/
|
|
42
|
+
resolve(): void {
|
|
43
|
+
this._promise = new Promise<void>(resolve => {
|
|
44
|
+
this._done();
|
|
45
|
+
this._done = resolve;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The promise for the current synchronization cycle.
|
|
51
|
+
* @returns The synchronization promise.
|
|
52
|
+
*/
|
|
53
|
+
get promise(): Promise<void> {
|
|
54
|
+
return this._promise;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const NIL = {};
|
|
2
|
+
|
|
3
|
+
interface QueueItem<E> {
|
|
4
|
+
event: E;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Throttle invocations of a callback function. The callback must return
|
|
9
|
+
* a Promise. Upon repeated invocation, the callback will not be invoked
|
|
10
|
+
* until a prior Promise resolves. If multiple invocations occurs while
|
|
11
|
+
* waiting, only the most recent invocation will be pending.
|
|
12
|
+
* @param callback The callback function.
|
|
13
|
+
* @param debounce Flag indicating if invocations
|
|
14
|
+
* should also be debounced within the current animation frame.
|
|
15
|
+
* @returns A new function that throttles access to the callback.
|
|
16
|
+
*/
|
|
17
|
+
export function throttle<E, T>(
|
|
18
|
+
callback: (event?: E) => Promise<T> | null,
|
|
19
|
+
debounce: boolean = false
|
|
20
|
+
): (event?: E) => void {
|
|
21
|
+
let curr: Promise<unknown> | null;
|
|
22
|
+
let next: QueueItem<E> | undefined | null;
|
|
23
|
+
let pending: E | undefined | typeof NIL = NIL;
|
|
24
|
+
|
|
25
|
+
function invoke(event?: E): void {
|
|
26
|
+
curr = callback(event)
|
|
27
|
+
?.catch(() => {})
|
|
28
|
+
.finally(() => {
|
|
29
|
+
if (next) {
|
|
30
|
+
const { event: value } = next;
|
|
31
|
+
next = null;
|
|
32
|
+
invoke(value);
|
|
33
|
+
} else {
|
|
34
|
+
curr = null;
|
|
35
|
+
}
|
|
36
|
+
}) || null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function enqueue(event: E): void {
|
|
40
|
+
next = { event };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function process(event?: E): void {
|
|
44
|
+
if (curr) enqueue(event!); else invoke(event);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function delay(event?: E): void {
|
|
48
|
+
if (pending !== event) {
|
|
49
|
+
requestAnimationFrame(() => {
|
|
50
|
+
const e = pending as E;
|
|
51
|
+
pending = NIL;
|
|
52
|
+
process(e);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
pending = event;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return debounce ? delay : process;
|
|
59
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isArrowTable } from './is-arrow-table.js';
|
|
2
|
+
import type { Table } from '@uwdata/flechette';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* An Array or TypedArray
|
|
6
|
+
*/
|
|
7
|
+
type Arrayish = Array<unknown> | Int8Array | Uint8Array | Uint8ClampedArray
|
|
8
|
+
| Int16Array | Uint16Array | Int32Array | Uint32Array
|
|
9
|
+
| Float32Array | Float64Array;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Data columns structure with either named columns or values array
|
|
13
|
+
*/
|
|
14
|
+
type DataColumns =
|
|
15
|
+
| { numRows: number; columns: Record<string, Arrayish> }
|
|
16
|
+
| { numRows: number; values: Arrayish };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Convert input data to a set of column arrays.
|
|
20
|
+
* @param data The input data.
|
|
21
|
+
* @returns An object with named column arrays.
|
|
22
|
+
*/
|
|
23
|
+
export function toDataColumns(data: unknown): DataColumns {
|
|
24
|
+
if (isArrowTable(data)) {
|
|
25
|
+
return arrowToColumns(data);
|
|
26
|
+
} else if (Array.isArray(data)) {
|
|
27
|
+
return arrayToColumns(data);
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error('Unrecognized data format.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Convert an Arrow table to a set of column arrays.
|
|
35
|
+
* @param data An Arrow Table.
|
|
36
|
+
* @returns An object with named column arrays.
|
|
37
|
+
*/
|
|
38
|
+
function arrowToColumns(data: Table): DataColumns {
|
|
39
|
+
const { numRows } = data;
|
|
40
|
+
return { numRows, columns: data.toColumns() as Record<string, Arrayish> };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Convert an array of values to a set of column arrays.
|
|
45
|
+
* If the array values are objects, build out named columns.
|
|
46
|
+
* We use the keys of the first object as the column names.
|
|
47
|
+
* Otherwise, use a special "values" array.
|
|
48
|
+
* @param data An array of data objects.
|
|
49
|
+
* @returns An object with named column arrays.
|
|
50
|
+
*/
|
|
51
|
+
function arrayToColumns(data: Record<string,unknown>[]): DataColumns {
|
|
52
|
+
const numRows = data.length;
|
|
53
|
+
if (typeof data[0] === 'object') {
|
|
54
|
+
const names = numRows ? Object.keys(data[0]!) : [];
|
|
55
|
+
const columns: Record<string, unknown[]> = {};
|
|
56
|
+
if (names.length > 0) {
|
|
57
|
+
names.forEach(name => {
|
|
58
|
+
columns[name] = data.map(d => d[name]);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return { numRows, columns };
|
|
62
|
+
} else {
|
|
63
|
+
return { numRows, values: data };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface Logger {
|
|
2
|
+
debug(...args: unknown[]): void;
|
|
3
|
+
info(...args: unknown[]): void;
|
|
4
|
+
log(...args: unknown[]): void;
|
|
5
|
+
warn(...args: unknown[]): void;
|
|
6
|
+
error(...args: unknown[]): void;
|
|
7
|
+
group(label?: string): void;
|
|
8
|
+
groupCollapsed(label?: string): void;
|
|
9
|
+
groupEnd(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function voidLogger(): Logger {
|
|
13
|
+
return {
|
|
14
|
+
debug(): void {},
|
|
15
|
+
info(): void {},
|
|
16
|
+
log(): void {},
|
|
17
|
+
warn(): void {},
|
|
18
|
+
error(): void {},
|
|
19
|
+
group(): void {},
|
|
20
|
+
groupCollapsed(): void {},
|
|
21
|
+
groupEnd(): void {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set or retrieve the coordinator instance.
|
|
3
|
-
* @param {Coordinator} [instance] the coordinator instance to set
|
|
4
|
-
* @returns {Coordinator} the coordinator instance
|
|
5
|
-
*/
|
|
6
|
-
export function coordinator(instance?: Coordinator): Coordinator;
|
|
7
|
-
/**
|
|
8
|
-
* A Mosaic Coordinator manages all database communication for clients and
|
|
9
|
-
* handles selection updates. The Coordinator also performs optimizations
|
|
10
|
-
* including query caching, consolidation, and pre-aggregation.
|
|
11
|
-
*/
|
|
12
|
-
export class Coordinator {
|
|
13
|
-
/**
|
|
14
|
-
* @param {Connector} [db] Database connector. Defaults to a web socket connection.
|
|
15
|
-
* @param {object} [options] Coordinator options.
|
|
16
|
-
* @param {Logger} [options.logger=console] The logger to use, defaults to `console`.
|
|
17
|
-
* @param {QueryManager} [options.manager] The query manager to use.
|
|
18
|
-
* @param {boolean} [options.cache=true] Boolean flag to enable/disable query caching.
|
|
19
|
-
* @param {boolean} [options.consolidate=true] Boolean flag to enable/disable query consolidation.
|
|
20
|
-
* @param {PreAggregateOptions} [options.preagg] Options for the Pre-aggregator.
|
|
21
|
-
*/
|
|
22
|
-
constructor(db?: Connector, { logger, manager, cache, consolidate, preagg }?: {
|
|
23
|
-
logger?: Logger;
|
|
24
|
-
manager?: QueryManager;
|
|
25
|
-
cache?: boolean;
|
|
26
|
-
consolidate?: boolean;
|
|
27
|
-
preagg?: PreAggregateOptions;
|
|
28
|
-
});
|
|
29
|
-
/** @type {QueryManager} */
|
|
30
|
-
manager: QueryManager;
|
|
31
|
-
preaggregator: PreAggregator;
|
|
32
|
-
/**
|
|
33
|
-
* Clear the coordinator state.
|
|
34
|
-
* @param {object} [options] Options object.
|
|
35
|
-
* @param {boolean} [options.clients=true] If true, disconnect all clients.
|
|
36
|
-
* @param {boolean} [options.cache=true] If true, clear the query cache.
|
|
37
|
-
*/
|
|
38
|
-
clear({ clients, cache }?: {
|
|
39
|
-
clients?: boolean;
|
|
40
|
-
cache?: boolean;
|
|
41
|
-
}): void;
|
|
42
|
-
filterGroups: Map<any, any>;
|
|
43
|
-
clients: Set<any>;
|
|
44
|
-
/**
|
|
45
|
-
* Get or set the database connector.
|
|
46
|
-
* @param {Connector} [db] The database connector to use.
|
|
47
|
-
* @returns {Connector} The current database connector.
|
|
48
|
-
*/
|
|
49
|
-
databaseConnector(db?: Connector): Connector;
|
|
50
|
-
/**
|
|
51
|
-
* Get or set the logger.
|
|
52
|
-
* @param {Logger} [logger] The logger to use.
|
|
53
|
-
* @returns {Logger} The current logger
|
|
54
|
-
*/
|
|
55
|
-
logger(logger?: Logger, ...args: any[]): Logger;
|
|
56
|
-
_logger: Logger;
|
|
57
|
-
/**
|
|
58
|
-
* Cancel previosuly submitted query requests. These queries will be
|
|
59
|
-
* canceled if they are queued but have not yet been submitted.
|
|
60
|
-
* @param {QueryResult[]} requests An array
|
|
61
|
-
* of query result objects, such as those returned by the `query` method.
|
|
62
|
-
*/
|
|
63
|
-
cancel(requests: QueryResult[]): void;
|
|
64
|
-
/**
|
|
65
|
-
* Issue a query for which no result (return value) is needed.
|
|
66
|
-
* @param {QueryType[] | QueryType} query The query or an array of queries.
|
|
67
|
-
* Each query should be either a Query builder object or a SQL string.
|
|
68
|
-
* @param {object} [options] An options object.
|
|
69
|
-
* @param {number} [options.priority] The query priority, defaults to
|
|
70
|
-
* `Priority.Normal`.
|
|
71
|
-
* @returns {QueryResult} A query result promise.
|
|
72
|
-
*/
|
|
73
|
-
exec(query: QueryType[] | QueryType, { priority }?: {
|
|
74
|
-
priority?: number;
|
|
75
|
-
}): QueryResult;
|
|
76
|
-
/**
|
|
77
|
-
* Issue a query to the backing database. The submitted query may be
|
|
78
|
-
* consolidate with other queries and its results may be cached.
|
|
79
|
-
* @param {QueryType} query The query as either a Query builder objec
|
|
80
|
-
* or a SQL string.
|
|
81
|
-
* @param {object} [options] An options object.
|
|
82
|
-
* @param {'arrow' | 'json'} [options.type] The query result format type.
|
|
83
|
-
* @param {boolean} [options.cache=true] If true, cache the query result
|
|
84
|
-
* client-side within the QueryManager.
|
|
85
|
-
* @param {boolean} [options.persist] If true, request the database
|
|
86
|
-
* server to persist a cached query server-side.
|
|
87
|
-
* @param {number} [options.priority] The query priority, defaults to
|
|
88
|
-
* `Priority.Normal`.
|
|
89
|
-
* @returns {QueryResult} A query result promise.
|
|
90
|
-
*/
|
|
91
|
-
query(query: QueryType, { type, cache, priority, ...options }?: {
|
|
92
|
-
type?: "arrow" | "json";
|
|
93
|
-
cache?: boolean;
|
|
94
|
-
persist?: boolean;
|
|
95
|
-
priority?: number;
|
|
96
|
-
}): QueryResult;
|
|
97
|
-
/**
|
|
98
|
-
* Issue a query to prefetch data for later use. The query result is cached
|
|
99
|
-
* for efficient future access.
|
|
100
|
-
* @param {QueryType} query The query as either a Query builder object
|
|
101
|
-
* or a SQL string.
|
|
102
|
-
* @param {object} [options] An options object.
|
|
103
|
-
* @param {'arrow' | 'json'} [options.type] The query result format type.
|
|
104
|
-
* @returns {QueryResult} A query result promise.
|
|
105
|
-
*/
|
|
106
|
-
prefetch(query: QueryType, options?: {
|
|
107
|
-
type?: "arrow" | "json";
|
|
108
|
-
}): QueryResult;
|
|
109
|
-
/**
|
|
110
|
-
* Create a bundle of queries that can be loaded into the cache.
|
|
111
|
-
*
|
|
112
|
-
* @param {string} name The name of the bundle.
|
|
113
|
-
* @param {[string | {sql: string}, {alias: string}]} queries The queries to save into the bundle.
|
|
114
|
-
* @param {number} priority Request priority.
|
|
115
|
-
* @returns {QueryResult} A query result promise.
|
|
116
|
-
*/
|
|
117
|
-
createBundle(name: string, queries: [string | {
|
|
118
|
-
sql: string;
|
|
119
|
-
}, {
|
|
120
|
-
alias: string;
|
|
121
|
-
}], priority?: number): QueryResult;
|
|
122
|
-
/**
|
|
123
|
-
* Load a bundle into the cache.
|
|
124
|
-
* @param {string} name The name of the bundle.
|
|
125
|
-
* @param {number} priority Request priority.
|
|
126
|
-
* @returns {QueryResult} A query result promise.
|
|
127
|
-
*/
|
|
128
|
-
loadBundle(name: string, priority?: number): QueryResult;
|
|
129
|
-
/**
|
|
130
|
-
* Update client data by submitting the given query and returning the
|
|
131
|
-
* data (or error) to the client.
|
|
132
|
-
* @param {MosaicClient} client A Mosaic client.
|
|
133
|
-
* @param {QueryType} query The data query.
|
|
134
|
-
* @param {number} [priority] The query priority.
|
|
135
|
-
* @returns {Promise} A Promise that resolves upon completion of the update.
|
|
136
|
-
*/
|
|
137
|
-
updateClient(client: MosaicClient, query: QueryType, priority?: number): Promise<any>;
|
|
138
|
-
/**
|
|
139
|
-
* Issue a query request for a client. If the query is null or undefined,
|
|
140
|
-
* the client is simply updated. Otherwise `updateClient` is called. As a
|
|
141
|
-
* side effect, this method clears the current preaggregator state.
|
|
142
|
-
* @param {MosaicClient} client The client to update.
|
|
143
|
-
* @param {QueryType | null} [query] The query to issue.
|
|
144
|
-
*/
|
|
145
|
-
requestQuery(client: MosaicClient, query?: QueryType | null): Promise<any>;
|
|
146
|
-
/**
|
|
147
|
-
* Connect a client to the coordinator.
|
|
148
|
-
* @param {MosaicClient} client The Mosaic client to connect.
|
|
149
|
-
*/
|
|
150
|
-
connect(client: MosaicClient): void;
|
|
151
|
-
/**
|
|
152
|
-
* Disconnect a client from the coordinator.
|
|
153
|
-
* @param {MosaicClient} client The Mosaic client to disconnect.
|
|
154
|
-
*/
|
|
155
|
-
disconnect(client: MosaicClient): void;
|
|
156
|
-
}
|
|
157
|
-
import { QueryManager } from './QueryManager.js';
|
|
158
|
-
import { PreAggregator } from './preagg/PreAggregator.js';
|
|
159
|
-
import type { Connector } from './connectors/Connector.js';
|
|
160
|
-
import type { Logger } from './types.js';
|
|
161
|
-
import type { QueryResult } from './util/query-result.js';
|
|
162
|
-
import type { QueryType } from './types.js';
|
|
163
|
-
import type { MosaicClient } from './MosaicClient.js';
|
|
164
|
-
import type { PreAggregateOptions } from './preagg/PreAggregator.js';
|
package/dist/types/Param.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test if a value is a Param instance.
|
|
3
|
-
* @param {*} x The value to test.
|
|
4
|
-
* @returns {x is Param} True if the input is a Param, false otherwise.
|
|
5
|
-
*/
|
|
6
|
-
export function isParam(x: any): x is Param;
|
|
7
|
-
/**
|
|
8
|
-
* Represents a dynamic parameter that dispatches updates
|
|
9
|
-
* upon parameter changes.
|
|
10
|
-
*/
|
|
11
|
-
export class Param extends AsyncDispatch {
|
|
12
|
-
/**
|
|
13
|
-
* Create a new Param instance with the given initial value.
|
|
14
|
-
* @param {*} value The initial value of the Param.
|
|
15
|
-
* @returns {Param} The new Param instance.
|
|
16
|
-
*/
|
|
17
|
-
static value(value: any): Param;
|
|
18
|
-
/**
|
|
19
|
-
* Create a new Param instance over an array of initial values,
|
|
20
|
-
* which may contain nested Params.
|
|
21
|
-
* @param {*} values The initial values of the Param.
|
|
22
|
-
* @returns {Param} The new Param instance.
|
|
23
|
-
*/
|
|
24
|
-
static array(values: any): Param;
|
|
25
|
-
/**
|
|
26
|
-
* Create a new Param instance.
|
|
27
|
-
* @param {*} value The initial value of the Param.
|
|
28
|
-
*/
|
|
29
|
-
constructor(value: any);
|
|
30
|
-
_value: any;
|
|
31
|
-
/**
|
|
32
|
-
* The current value of the Param.
|
|
33
|
-
*/
|
|
34
|
-
get value(): any;
|
|
35
|
-
/**
|
|
36
|
-
* Update the Param value
|
|
37
|
-
* @param {*} value The new value of the Param.
|
|
38
|
-
* @param {object} [options] The update options.
|
|
39
|
-
* @param {boolean} [options.force] A boolean flag indicating if the Param
|
|
40
|
-
* should emit a 'value' event even if the internal value is unchanged.
|
|
41
|
-
* @returns {this} This Param instance.
|
|
42
|
-
*/
|
|
43
|
-
update(value: any, { force }?: {
|
|
44
|
-
force?: boolean;
|
|
45
|
-
}): this;
|
|
46
|
-
}
|
|
47
|
-
import { AsyncDispatch } from './util/AsyncDispatch.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a consolidator to combine structurally compatible queries.
|
|
3
|
-
* @param {*} enqueue Query manager enqueue method
|
|
4
|
-
* @param {*} cache Client-side query cache (sql -> data)
|
|
5
|
-
* @returns A consolidator object
|
|
6
|
-
*/
|
|
7
|
-
export function consolidator(enqueue: any, cache: any): {
|
|
8
|
-
add(entry: any, priority: any): void;
|
|
9
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
export const Priority: Readonly<{
|
|
2
|
-
High: 0;
|
|
3
|
-
Normal: 1;
|
|
4
|
-
Low: 2;
|
|
5
|
-
}>;
|
|
6
|
-
export class QueryManager {
|
|
7
|
-
constructor(maxConcurrentRequests?: number);
|
|
8
|
-
/** @type {PriorityQueue} */
|
|
9
|
-
queue: PriorityQueue;
|
|
10
|
-
/** @type {Connector} */
|
|
11
|
-
db: Connector;
|
|
12
|
-
/** @type {Cache} */
|
|
13
|
-
clientCache: Cache;
|
|
14
|
-
/** @type {Logger} */
|
|
15
|
-
_logger: Logger;
|
|
16
|
-
/** @type {boolean} */
|
|
17
|
-
_logQueries: boolean;
|
|
18
|
-
/** @type {ReturnType<typeof consolidator> | null} */
|
|
19
|
-
_consolidate: ReturnType<typeof consolidator> | null;
|
|
20
|
-
/**
|
|
21
|
-
* Requests pending with the query manager.
|
|
22
|
-
* @type {QueryResult[]}
|
|
23
|
-
*/
|
|
24
|
-
pendingResults: QueryResult[];
|
|
25
|
-
/** @type {number} */
|
|
26
|
-
maxConcurrentRequests: number;
|
|
27
|
-
/** @type {boolean} */
|
|
28
|
-
pendingExec: boolean;
|
|
29
|
-
next(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Add an entry to the query queue with a priority.
|
|
32
|
-
* @param {object} entry The entry to add.
|
|
33
|
-
* @param {*} [entry.request] The query request.
|
|
34
|
-
* @param {QueryResult} [entry.result] The query result.
|
|
35
|
-
* @param {number} priority The query priority, defaults to `Priority.Normal`.
|
|
36
|
-
*/
|
|
37
|
-
enqueue(entry: {
|
|
38
|
-
request?: any;
|
|
39
|
-
result?: QueryResult;
|
|
40
|
-
}, priority?: number): void;
|
|
41
|
-
/**
|
|
42
|
-
* Submit the query to the connector.
|
|
43
|
-
* @param {*} request The request.
|
|
44
|
-
* @param {QueryResult} result The query result.
|
|
45
|
-
*/
|
|
46
|
-
submit(request: any, result: QueryResult): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Get or set the current query cache.
|
|
49
|
-
* @param {Cache | boolean} [value]
|
|
50
|
-
* @returns {Cache}
|
|
51
|
-
*/
|
|
52
|
-
cache(value?: Cache | boolean): Cache;
|
|
53
|
-
/**
|
|
54
|
-
* Get or set the current logger.
|
|
55
|
-
* @param {Logger} [value]
|
|
56
|
-
* @returns {Logger}
|
|
57
|
-
*/
|
|
58
|
-
logger(value?: Logger): Logger;
|
|
59
|
-
/**
|
|
60
|
-
* Get or set if queries should be logged.
|
|
61
|
-
* @param {boolean} [value]
|
|
62
|
-
* @returns {boolean}
|
|
63
|
-
*/
|
|
64
|
-
logQueries(value?: boolean): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Get or set the database connector.
|
|
67
|
-
* @param {Connector} [connector]
|
|
68
|
-
* @returns {Connector}
|
|
69
|
-
*/
|
|
70
|
-
connector(connector?: Connector): Connector;
|
|
71
|
-
/**
|
|
72
|
-
* Indicate if query consolidation should be performed.
|
|
73
|
-
* @param {boolean} flag
|
|
74
|
-
*/
|
|
75
|
-
consolidate(flag: boolean): void;
|
|
76
|
-
/**
|
|
77
|
-
* Request a query result.
|
|
78
|
-
* @param {*} request The request.
|
|
79
|
-
* @param {number} priority The query priority, defaults to `Priority.Normal`.
|
|
80
|
-
* @returns {QueryResult} A query result promise.
|
|
81
|
-
*/
|
|
82
|
-
request(request: any, priority?: number): QueryResult;
|
|
83
|
-
cancel(requests: any): void;
|
|
84
|
-
clear(): void;
|
|
85
|
-
}
|
|
86
|
-
import { PriorityQueue } from './util/priority-queue.js';
|
|
87
|
-
import type { Connector } from './connectors/Connector.js';
|
|
88
|
-
import type { Cache } from './types.js';
|
|
89
|
-
import type { Logger } from './types.js';
|
|
90
|
-
import { consolidator } from './QueryConsolidator.js';
|
|
91
|
-
import { QueryResult } from './util/query-result.js';
|