@perspective-dev/client 4.5.2 → 5.1.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/dist/cdn/perspective-server.worker.js +1 -1
- package/dist/cdn/perspective-server.worker.js.map +3 -3
- package/dist/cdn/perspective.js +2 -2
- package/dist/cdn/perspective.js.map +4 -4
- package/dist/esm/perspective.browser.d.ts +50 -1
- package/dist/esm/perspective.inline.js +2 -2
- package/dist/esm/perspective.inline.js.map +4 -4
- package/dist/esm/perspective.js +2 -2
- package/dist/esm/perspective.js.map +4 -4
- package/dist/esm/perspective.node.d.ts +3 -0
- package/dist/esm/perspective.node.js +75 -21
- package/dist/esm/perspective.node.js.map +3 -3
- package/dist/esm/ts-rs/AggSpec.d.ts +8 -0
- package/dist/esm/ts-rs/Features.d.ts +59 -0
- package/dist/esm/ts-rs/ViewConfig.d.ts +2 -0
- package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +9 -0
- package/dist/esm/ts-rs/WindowAggregate.d.ts +1 -0
- package/dist/esm/ts-rs/WindowSort.d.ts +7 -0
- package/dist/esm/ts-rs/WindowSortDir.d.ts +6 -0
- package/dist/esm/ts-rs/WindowSpec.d.ts +46 -0
- package/dist/esm/ts-rs/Windows.d.ts +10 -0
- package/dist/esm/virtual_server.d.ts +8 -34
- package/dist/esm/virtual_servers/clickhouse.js +1 -1
- package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
- package/dist/esm/virtual_servers/duckdb.d.ts +6 -26
- package/dist/esm/virtual_servers/duckdb.js +1 -1
- package/dist/esm/virtual_servers/duckdb.js.map +3 -3
- package/dist/esm/wasm/features.d.ts +4 -0
- package/dist/wasm/perspective-js.d.ts +96 -6
- package/dist/wasm/perspective-js.js +11 -11
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +5 -5
- package/package.json +1 -1
- package/src/rust/lib.rs +6 -0
- package/src/rust/typed_array.rs +88 -54
- package/src/rust/virtual_server.rs +98 -2
- package/src/ts/perspective.browser.ts +176 -20
- package/src/ts/perspective.cdn.ts +11 -5
- package/src/ts/perspective.node.ts +39 -8
- package/src/ts/ts-rs/AggSpec.ts +10 -0
- package/src/ts/ts-rs/Features.ts +54 -0
- package/src/ts/ts-rs/ViewConfig.ts +2 -1
- package/src/ts/ts-rs/ViewConfigUpdate.ts +9 -0
- package/src/ts/ts-rs/WindowAggregate.ts +3 -0
- package/src/ts/ts-rs/WindowSort.ts +9 -0
- package/src/ts/ts-rs/WindowSortDir.ts +8 -0
- package/src/ts/ts-rs/WindowSpec.ts +46 -0
- package/src/ts/ts-rs/Windows.ts +10 -0
- package/src/ts/virtual_server.ts +17 -55
- package/src/ts/virtual_servers/clickhouse.ts +45 -2
- package/src/ts/virtual_servers/duckdb.ts +46 -4
- package/src/ts/wasm/cdn.ts +32 -0
- package/src/ts/wasm/engine.ts +7 -5
- package/src/ts/wasm/features.ts +31 -0
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A table hosted by a `VirtualServerHandler`, as returned by
|
|
6
|
+
* `getHostedTables()`. A plain `string` is shorthand for `{ name }`.
|
|
7
|
+
*/
|
|
8
|
+
export interface VirtualHostedTable {
|
|
9
|
+
name: string;
|
|
10
|
+
index?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handler interface that you implement to provide custom data sources.
|
|
16
|
+
*
|
|
17
|
+
* All methods will be called by the `VirtualServer` when handling protocol
|
|
18
|
+
* messages from Perspective clients. Methods can return values directly or
|
|
19
|
+
* return Promises for asynchronous operations (e.g., database queries).
|
|
20
|
+
* Optional methods fall back to defaults documented per-method.
|
|
21
|
+
*/
|
|
22
|
+
export interface VirtualServerHandler {
|
|
23
|
+
getHostedTables():
|
|
24
|
+
| (string | VirtualHostedTable)[]
|
|
25
|
+
| Promise<(string | VirtualHostedTable)[]>;
|
|
26
|
+
tableSchema(
|
|
27
|
+
tableId: string,
|
|
28
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
29
|
+
tableSize(tableId: string): number | Promise<number>;
|
|
30
|
+
tableMakeView(
|
|
31
|
+
tableId: string,
|
|
32
|
+
viewId: string,
|
|
33
|
+
config: ViewConfigUpdate,
|
|
34
|
+
): void | Promise<void>;
|
|
35
|
+
viewDelete(viewId: string): void | Promise<void>;
|
|
36
|
+
viewGetData(
|
|
37
|
+
viewId: string,
|
|
38
|
+
config: ViewConfig,
|
|
39
|
+
schema: Record<string, ColumnType>,
|
|
40
|
+
viewport: ViewWindow,
|
|
41
|
+
dataSlice: VirtualDataSlice,
|
|
42
|
+
): void | Promise<void>;
|
|
43
|
+
|
|
44
|
+
/** Defaults to `tableSchema(viewId)`. */
|
|
45
|
+
viewSchema?(
|
|
46
|
+
viewId: string,
|
|
47
|
+
config: ViewConfig,
|
|
48
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
49
|
+
|
|
50
|
+
/** Defaults to `tableSize(viewId)`. */
|
|
51
|
+
viewSize?(viewId: string): number | Promise<number>;
|
|
52
|
+
|
|
53
|
+
/** Defaults to the length of `tableSchema(tableId)`. */
|
|
54
|
+
tableColumnsSize?(tableId: string): number | Promise<number>;
|
|
55
|
+
|
|
56
|
+
/** Defaults to the length of `viewSchema(viewId, config)`. */
|
|
57
|
+
viewColumnSize?(
|
|
58
|
+
viewId: string,
|
|
59
|
+
config: ViewConfig,
|
|
60
|
+
): number | Promise<number>;
|
|
61
|
+
|
|
62
|
+
/** Required when `getFeatures()` reports `expressions: true`. */
|
|
63
|
+
tableValidateExpression?(
|
|
64
|
+
tableId: string,
|
|
65
|
+
expression: string,
|
|
66
|
+
): ColumnType | Promise<ColumnType>;
|
|
67
|
+
|
|
68
|
+
viewGetMinMax?(
|
|
69
|
+
viewId: string,
|
|
70
|
+
columnName: string,
|
|
71
|
+
config: ViewConfig,
|
|
72
|
+
): { min: Scalar; max: Scalar } | Promise<{ min: Scalar; max: Scalar }>;
|
|
73
|
+
|
|
74
|
+
/** Defaults to no optional features. */
|
|
75
|
+
getFeatures?(): Features | Promise<Features>;
|
|
76
|
+
|
|
77
|
+
/** Defaults to port `0`. */
|
|
78
|
+
tableMakePort?(): number | Promise<number>;
|
|
79
|
+
|
|
80
|
+
makeTable?(
|
|
81
|
+
tableId: string,
|
|
82
|
+
data: string | Uint8Array,
|
|
83
|
+
): void | Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
4
88
|
export type * from "../../src/ts/ts-rs/ViewWindow.d.ts";
|
|
5
89
|
export type * from "../../src/ts/ts-rs/ColumnType.d.ts";
|
|
6
90
|
export type * from "../../src/ts/ts-rs/ColumnWindow.d.ts";
|
|
@@ -18,6 +102,9 @@ export type * from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
|
18
102
|
export type * from "../../src/ts/ts-rs/JoinOptions.ts";
|
|
19
103
|
export type * from "../../src/ts/ts-rs/JoinType.ts";
|
|
20
104
|
export type * from "../../src/ts/ts-rs/TypedArrayWindow.ts";
|
|
105
|
+
export type * from "../../src/ts/ts-rs/Features.ts";
|
|
106
|
+
export type * from "../../src/ts/ts-rs/AggSpec.ts";
|
|
107
|
+
export type * from "../../src/ts/ts-rs/WindowAggregate.ts";
|
|
21
108
|
|
|
22
109
|
import type {ColumnWindow} from "../../src/ts/ts-rs/ColumnWindow.d.ts";
|
|
23
110
|
import type {ColumnType} from "../../src/ts/ts-rs/ColumnType.d.ts";
|
|
@@ -32,6 +119,9 @@ import type {OnUpdateOptions} from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
|
|
|
32
119
|
import type {UpdateOptions} from "../../src/ts/ts-rs/UpdateOptions.d.ts";
|
|
33
120
|
import type {DeleteOptions} from "../../src/ts/ts-rs/DeleteOptions.d.ts";
|
|
34
121
|
import type {SystemInfo} from "../../src/ts/ts-rs/SystemInfo.d.ts";
|
|
122
|
+
import type {ViewConfig} from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
123
|
+
import type {Scalar} from "../../src/ts/ts-rs/Scalar.d.ts";
|
|
124
|
+
import type {Features} from "../../src/ts/ts-rs/Features.ts";
|
|
35
125
|
|
|
36
126
|
|
|
37
127
|
|
|
@@ -773,7 +863,7 @@ export class VirtualServer {
|
|
|
773
863
|
free(): void;
|
|
774
864
|
[Symbol.dispose](): void;
|
|
775
865
|
handleRequest(bytes: Uint8Array): Promise<any>;
|
|
776
|
-
constructor(handler:
|
|
866
|
+
constructor(handler: VirtualServerHandler);
|
|
777
867
|
}
|
|
778
868
|
|
|
779
869
|
export function init(): void;
|
|
@@ -874,11 +964,11 @@ export interface InitOutput {
|
|
|
874
964
|
readonly virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
875
965
|
readonly virtualserver_handleRequest: (a: number, b: number, c: number) => number;
|
|
876
966
|
readonly virtualserver_new: (a: number, b: number) => void;
|
|
877
|
-
readonly
|
|
878
|
-
readonly
|
|
879
|
-
readonly
|
|
880
|
-
readonly
|
|
881
|
-
readonly
|
|
967
|
+
readonly __wasm_bindgen_func_elem_1125: (a: number, b: number) => void;
|
|
968
|
+
readonly __wasm_bindgen_func_elem_4193: (a: number, b: number) => void;
|
|
969
|
+
readonly __wasm_bindgen_func_elem_11388: (a: number, b: number, c: number, d: number) => void;
|
|
970
|
+
readonly __wasm_bindgen_func_elem_4210: (a: number, b: number, c: number) => void;
|
|
971
|
+
readonly __wasm_bindgen_func_elem_1843: (a: number, b: number) => number;
|
|
882
972
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
883
973
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
884
974
|
readonly __wbindgen_export3: (a: number) => void;
|
|
@@ -1649,7 +1649,7 @@ export class VirtualServer {
|
|
|
1649
1649
|
return takeObject(ret);
|
|
1650
1650
|
}
|
|
1651
1651
|
/**
|
|
1652
|
-
* @param {
|
|
1652
|
+
* @param {VirtualServerHandler} handler
|
|
1653
1653
|
*/
|
|
1654
1654
|
constructor(handler) {
|
|
1655
1655
|
try {
|
|
@@ -2016,7 +2016,7 @@ function __wbg_get_imports() {
|
|
|
2016
2016
|
const a = state0.a;
|
|
2017
2017
|
state0.a = 0;
|
|
2018
2018
|
try {
|
|
2019
|
-
return
|
|
2019
|
+
return __wasm_bindgen_func_elem_11388(a, state0.b, arg0, arg1);
|
|
2020
2020
|
} finally {
|
|
2021
2021
|
state0.a = a;
|
|
2022
2022
|
}
|
|
@@ -2175,12 +2175,12 @@ function __wbg_get_imports() {
|
|
|
2175
2175
|
},
|
|
2176
2176
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
2177
2177
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 12, function: Function { arguments: [], shim_idx: 31, ret: NamedExternref("Promise<any>"), inner_ret: Some(NamedExternref("Promise<any>")) }, mutable: false }) -> Externref`.
|
|
2178
|
-
const ret = makeClosure(arg0, arg1, wasm.
|
|
2178
|
+
const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1125, __wasm_bindgen_func_elem_1843);
|
|
2179
2179
|
return addHeapObject(ret);
|
|
2180
2180
|
},
|
|
2181
2181
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
2182
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
2183
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
2182
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 575, function: Function { arguments: [Externref], shim_idx: 576, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2183
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4193, __wasm_bindgen_func_elem_4210);
|
|
2184
2184
|
return addHeapObject(ret);
|
|
2185
2185
|
},
|
|
2186
2186
|
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
@@ -2257,17 +2257,17 @@ function __wbg_get_imports() {
|
|
|
2257
2257
|
};
|
|
2258
2258
|
}
|
|
2259
2259
|
|
|
2260
|
-
function
|
|
2261
|
-
const ret = wasm.
|
|
2260
|
+
function __wasm_bindgen_func_elem_1843(arg0, arg1) {
|
|
2261
|
+
const ret = wasm.__wasm_bindgen_func_elem_1843(arg0, arg1);
|
|
2262
2262
|
return takeObject(ret);
|
|
2263
2263
|
}
|
|
2264
2264
|
|
|
2265
|
-
function
|
|
2266
|
-
wasm.
|
|
2265
|
+
function __wasm_bindgen_func_elem_4210(arg0, arg1, arg2) {
|
|
2266
|
+
wasm.__wasm_bindgen_func_elem_4210(arg0, arg1, addHeapObject(arg2));
|
|
2267
2267
|
}
|
|
2268
2268
|
|
|
2269
|
-
function
|
|
2270
|
-
wasm.
|
|
2269
|
+
function __wasm_bindgen_func_elem_11388(arg0, arg1, arg2, arg3) {
|
|
2270
|
+
wasm.__wasm_bindgen_func_elem_11388(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
2271
2271
|
}
|
|
2272
2272
|
|
|
2273
2273
|
const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
Binary file
|
|
@@ -93,11 +93,11 @@ export const virtualdataslice_setIntegerCol: (a: number, b: number, c: number, d
|
|
|
93
93
|
export const virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
94
94
|
export const virtualserver_handleRequest: (a: number, b: number, c: number) => number;
|
|
95
95
|
export const virtualserver_new: (a: number, b: number) => void;
|
|
96
|
-
export const
|
|
97
|
-
export const
|
|
98
|
-
export const
|
|
99
|
-
export const
|
|
100
|
-
export const
|
|
96
|
+
export const __wasm_bindgen_func_elem_1125: (a: number, b: number) => void;
|
|
97
|
+
export const __wasm_bindgen_func_elem_4193: (a: number, b: number) => void;
|
|
98
|
+
export const __wasm_bindgen_func_elem_11388: (a: number, b: number, c: number, d: number) => void;
|
|
99
|
+
export const __wasm_bindgen_func_elem_4210: (a: number, b: number, c: number) => void;
|
|
100
|
+
export const __wasm_bindgen_func_elem_1843: (a: number, b: number) => number;
|
|
101
101
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
102
102
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
103
103
|
export const __wbindgen_export3: (a: number) => void;
|
package/package.json
CHANGED
package/src/rust/lib.rs
CHANGED
|
@@ -64,6 +64,9 @@ export type * from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
|
64
64
|
export type * from "../../src/ts/ts-rs/JoinOptions.ts";
|
|
65
65
|
export type * from "../../src/ts/ts-rs/JoinType.ts";
|
|
66
66
|
export type * from "../../src/ts/ts-rs/TypedArrayWindow.ts";
|
|
67
|
+
export type * from "../../src/ts/ts-rs/Features.ts";
|
|
68
|
+
export type * from "../../src/ts/ts-rs/AggSpec.ts";
|
|
69
|
+
export type * from "../../src/ts/ts-rs/WindowAggregate.ts";
|
|
67
70
|
|
|
68
71
|
import type {ColumnWindow} from "../../src/ts/ts-rs/ColumnWindow.d.ts";
|
|
69
72
|
import type {ColumnType} from "../../src/ts/ts-rs/ColumnType.d.ts";
|
|
@@ -78,6 +81,9 @@ import type {OnUpdateOptions} from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
|
|
|
78
81
|
import type {UpdateOptions} from "../../src/ts/ts-rs/UpdateOptions.d.ts";
|
|
79
82
|
import type {DeleteOptions} from "../../src/ts/ts-rs/DeleteOptions.d.ts";
|
|
80
83
|
import type {SystemInfo} from "../../src/ts/ts-rs/SystemInfo.d.ts";
|
|
84
|
+
import type {ViewConfig} from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
85
|
+
import type {Scalar} from "../../src/ts/ts-rs/Scalar.d.ts";
|
|
86
|
+
import type {Features} from "../../src/ts/ts-rs/Features.ts";
|
|
81
87
|
"#;
|
|
82
88
|
|
|
83
89
|
#[cfg(feature = "export-init")]
|
package/src/rust/typed_array.rs
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
use std::io::Cursor;
|
|
14
14
|
|
|
15
|
-
use arrow_array::Array as _;
|
|
16
15
|
use arrow_array::cast::AsArray;
|
|
17
16
|
use arrow_array::types::*;
|
|
17
|
+
use arrow_array::{Array as _, ArrowPrimitiveType, PrimitiveArray};
|
|
18
18
|
use arrow_ipc::reader::StreamReader;
|
|
19
19
|
use arrow_schema::{DataType, TimeUnit};
|
|
20
20
|
use js_sys::{Array, Function, JsString, Uint8Array};
|
|
@@ -49,6 +49,31 @@ impl From<TypedArrayWindow> for ViewWindow {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
fn zero_invalid_slots<T: ArrowPrimitiveType>(arr: &PrimitiveArray<T>) {
|
|
53
|
+
let Some(nulls) = arr.nulls() else { return };
|
|
54
|
+
let ptr = arr.values().as_ptr() as *mut T::Native;
|
|
55
|
+
let chunks = nulls.inner().bit_chunks();
|
|
56
|
+
let mut base = 0;
|
|
57
|
+
for chunk in chunks.iter() {
|
|
58
|
+
if chunk != u64::MAX {
|
|
59
|
+
for bit in 0..64 {
|
|
60
|
+
if chunk & (1 << bit) == 0 {
|
|
61
|
+
unsafe { ptr.add(base + bit).write(T::default_value()) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
base += 64;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let rem = chunks.remainder_bits();
|
|
70
|
+
for bit in 0..chunks.remainder_len() {
|
|
71
|
+
if rem & (1 << bit) == 0 {
|
|
72
|
+
unsafe { ptr.add(base + bit).write(T::default_value()) };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
52
77
|
/// Decode an Arrow IPC batch and call `callback` once with all columns.
|
|
53
78
|
///
|
|
54
79
|
/// Callback signature:
|
|
@@ -83,13 +108,23 @@ pub(crate) async fn decode_and_call(
|
|
|
83
108
|
let js_validities = Array::new_with_length(num_cols as u32);
|
|
84
109
|
let js_dicts = Array::new_with_length(num_cols as u32);
|
|
85
110
|
|
|
86
|
-
// Storage for
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
111
|
+
// Storage for type-conversion buffers (Int64/Date32/Timestamp and
|
|
112
|
+
// `float32` narrowing). These MUST outlive the callback because
|
|
113
|
+
// `js_sys::*Array::view()` creates zero-copy views into their heap
|
|
114
|
+
// memory. Using `Box<[T]>` (rather than `Vec<T>`) yields a stable
|
|
115
|
+
// data pointer that won't move when the outer Vec grows, so a view
|
|
116
|
+
// created before the push stays valid.
|
|
90
117
|
let mut f32_storage: Vec<Box<[f32]>> = Vec::new();
|
|
91
118
|
let mut f64_storage: Vec<Box<[f64]>> = Vec::new();
|
|
92
119
|
|
|
120
|
+
// The bytes under a NULL slot in the source Arrow are UNDEFINED —
|
|
121
|
+
// the perspective engine zero-fills them but e.g. DuckDB's Arrow
|
|
122
|
+
// output leaves NaN (which, unlike the garbage a consumer merely
|
|
123
|
+
// *displays* wrong, poisons any consumer that aggregates, e.g. the
|
|
124
|
+
// treemap's bottom-up value sums). `zero_invalid_slots` normalizes
|
|
125
|
+
// every column in place — forcing invalid slots to 0 so all backends
|
|
126
|
+
// present the same value contract — without giving up the zero-copy
|
|
127
|
+
// view.
|
|
93
128
|
for col_idx in 0..num_cols {
|
|
94
129
|
let field = schema.field(col_idx);
|
|
95
130
|
let col = batch.column(col_idx);
|
|
@@ -99,32 +134,41 @@ pub(crate) async fn decode_and_call(
|
|
|
99
134
|
|
|
100
135
|
match col.data_type() {
|
|
101
136
|
DataType::UInt32 => {
|
|
102
|
-
let
|
|
103
|
-
|
|
137
|
+
let typed = col.as_primitive::<UInt32Type>();
|
|
138
|
+
zero_invalid_slots(typed);
|
|
139
|
+
let arr = unsafe { js_sys::Uint32Array::view(typed.values().as_ref()) };
|
|
104
140
|
js_values.set(col_idx as u32, arr.into());
|
|
105
141
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
106
142
|
},
|
|
107
143
|
DataType::Int32 => {
|
|
108
|
-
let
|
|
109
|
-
|
|
144
|
+
let typed = col.as_primitive::<Int32Type>();
|
|
145
|
+
zero_invalid_slots(typed);
|
|
146
|
+
let arr = unsafe { js_sys::Int32Array::view(typed.values().as_ref()) };
|
|
110
147
|
js_values.set(col_idx as u32, arr.into());
|
|
111
148
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
112
149
|
},
|
|
113
150
|
DataType::Float32 => {
|
|
114
|
-
let
|
|
115
|
-
|
|
151
|
+
let typed = col.as_primitive::<Float32Type>();
|
|
152
|
+
zero_invalid_slots(typed);
|
|
153
|
+
let arr = unsafe { js_sys::Float32Array::view(typed.values().as_ref()) };
|
|
116
154
|
js_values.set(col_idx as u32, arr.into());
|
|
117
155
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
118
156
|
},
|
|
119
157
|
DataType::Float64 => {
|
|
158
|
+
let typed = col.as_primitive::<Float64Type>();
|
|
159
|
+
zero_invalid_slots(typed);
|
|
120
160
|
if float32 {
|
|
121
|
-
let vals =
|
|
122
|
-
|
|
161
|
+
let vals: Box<[f32]> = typed.values().iter().map(|&v| v as f32).collect();
|
|
162
|
+
|
|
163
|
+
let arr = unsafe { js_sys::Float32Array::view(&vals) };
|
|
164
|
+
f32_storage.push(vals);
|
|
165
|
+
js_values.set(col_idx as u32, arr.into());
|
|
123
166
|
} else {
|
|
124
|
-
let
|
|
125
|
-
|
|
167
|
+
let arr = unsafe { js_sys::Float64Array::view(typed.values().as_ref()) };
|
|
168
|
+
|
|
126
169
|
js_values.set(col_idx as u32, arr.into());
|
|
127
170
|
}
|
|
171
|
+
|
|
128
172
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
129
173
|
},
|
|
130
174
|
DataType::Date32 => {
|
|
@@ -133,32 +177,51 @@ pub(crate) async fn decode_and_call(
|
|
|
133
177
|
// timestamps, so the `float32` flag is intentionally ignored
|
|
134
178
|
// for date/timestamp columns.
|
|
135
179
|
let typed = col.as_primitive::<Date32Type>();
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
180
|
+
zero_invalid_slots(typed);
|
|
181
|
+
let vals: Box<[f64]> = typed
|
|
182
|
+
.values()
|
|
183
|
+
.iter()
|
|
184
|
+
.map(|&v| v as f64 * 86_400_000.0)
|
|
185
|
+
.collect();
|
|
186
|
+
|
|
187
|
+
let arr = unsafe { js_sys::Float64Array::view(&vals) };
|
|
188
|
+
f64_storage.push(vals);
|
|
189
|
+
js_values.set(col_idx as u32, arr.into());
|
|
143
190
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
144
191
|
},
|
|
145
192
|
DataType::Timestamp(TimeUnit::Millisecond, _) => {
|
|
146
193
|
let typed = col.as_primitive::<TimestampMillisecondType>();
|
|
147
|
-
|
|
194
|
+
zero_invalid_slots(typed);
|
|
195
|
+
let vals: Box<[f64]> = typed.values().iter().map(|&v| v as f64).collect();
|
|
196
|
+
|
|
197
|
+
let arr = unsafe { js_sys::Float64Array::view(&vals) };
|
|
198
|
+
f64_storage.push(vals);
|
|
199
|
+
js_values.set(col_idx as u32, arr.into());
|
|
148
200
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
149
201
|
},
|
|
150
202
|
DataType::Int64 => {
|
|
151
203
|
let typed = col.as_primitive::<Int64Type>();
|
|
204
|
+
zero_invalid_slots(typed);
|
|
152
205
|
if float32 {
|
|
153
|
-
|
|
206
|
+
let vals: Box<[f32]> = typed.values().iter().map(|&v| v as f32).collect();
|
|
207
|
+
|
|
208
|
+
let arr = unsafe { js_sys::Float32Array::view(&vals) };
|
|
209
|
+
f32_storage.push(vals);
|
|
210
|
+
js_values.set(col_idx as u32, arr.into());
|
|
154
211
|
} else {
|
|
155
|
-
|
|
212
|
+
let vals: Box<[f64]> = typed.values().iter().map(|&v| v as f64).collect();
|
|
213
|
+
|
|
214
|
+
let arr = unsafe { js_sys::Float64Array::view(&vals) };
|
|
215
|
+
f64_storage.push(vals);
|
|
216
|
+
js_values.set(col_idx as u32, arr.into());
|
|
156
217
|
}
|
|
218
|
+
|
|
157
219
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
158
220
|
},
|
|
159
221
|
DataType::Dictionary(..) => {
|
|
160
222
|
let dict = col.as_dictionary::<Int32Type>();
|
|
161
223
|
let keys = dict.keys();
|
|
224
|
+
zero_invalid_slots(keys);
|
|
162
225
|
let arr = unsafe { js_sys::Int32Array::view(keys.values().as_ref()) };
|
|
163
226
|
js_values.set(col_idx as u32, arr.into());
|
|
164
227
|
|
|
@@ -188,35 +251,6 @@ pub(crate) async fn decode_and_call(
|
|
|
188
251
|
);
|
|
189
252
|
}
|
|
190
253
|
|
|
191
|
-
// Second pass: fill in value views for columns backed by f32_storage /
|
|
192
|
-
// f64_storage. The Box<[T]> buffers are heap-allocated and stable; their
|
|
193
|
-
// data pointers remain valid even as the outer Vec grows.
|
|
194
|
-
let mut f32_idx = 0;
|
|
195
|
-
let mut f64_idx = 0;
|
|
196
|
-
for col_idx in 0..num_cols {
|
|
197
|
-
let col = batch.column(col_idx);
|
|
198
|
-
let uses_f32_storage = matches!(
|
|
199
|
-
(col.data_type(), float32),
|
|
200
|
-
(DataType::Float64, true) | (DataType::Int64, true),
|
|
201
|
-
);
|
|
202
|
-
let uses_f64_storage = matches!(
|
|
203
|
-
(col.data_type(), float32),
|
|
204
|
-
(DataType::Date32, _)
|
|
205
|
-
| (DataType::Timestamp(TimeUnit::Millisecond, _), _)
|
|
206
|
-
| (DataType::Int64, false),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
if uses_f32_storage {
|
|
210
|
-
let arr = unsafe { js_sys::Float32Array::view(&f32_storage[f32_idx]) };
|
|
211
|
-
js_values.set(col_idx as u32, arr.into());
|
|
212
|
-
f32_idx += 1;
|
|
213
|
-
} else if uses_f64_storage {
|
|
214
|
-
let arr = unsafe { js_sys::Float64Array::view(&f64_storage[f64_idx]) };
|
|
215
|
-
js_values.set(col_idx as u32, arr.into());
|
|
216
|
-
f64_idx += 1;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
254
|
let ret = callback.call4(
|
|
221
255
|
&JsValue::UNDEFINED,
|
|
222
256
|
&js_names.into(),
|
|
@@ -74,6 +74,102 @@ fn jsvalue_to_scalar(val: &JsValue) -> perspective_client::config::Scalar {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// This interface is the TypeScript contract for [`JsServerHandler`] below.
|
|
78
|
+
// There is no codegen tying the two together - every method dispatched via
|
|
79
|
+
// `Reflect::get` in this file MUST be declared here, with the exact argument
|
|
80
|
+
// and return types the `Reflect` call sites accept. Keep them in sync when
|
|
81
|
+
// editing either.
|
|
82
|
+
#[wasm_bindgen(typescript_custom_section)]
|
|
83
|
+
const TS_VIRTUAL_SERVER_HANDLER: &'static str = r#"
|
|
84
|
+
/**
|
|
85
|
+
* A table hosted by a `VirtualServerHandler`, as returned by
|
|
86
|
+
* `getHostedTables()`. A plain `string` is shorthand for `{ name }`.
|
|
87
|
+
*/
|
|
88
|
+
export interface VirtualHostedTable {
|
|
89
|
+
name: string;
|
|
90
|
+
index?: string;
|
|
91
|
+
limit?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Handler interface that you implement to provide custom data sources.
|
|
96
|
+
*
|
|
97
|
+
* All methods will be called by the `VirtualServer` when handling protocol
|
|
98
|
+
* messages from Perspective clients. Methods can return values directly or
|
|
99
|
+
* return Promises for asynchronous operations (e.g., database queries).
|
|
100
|
+
* Optional methods fall back to defaults documented per-method.
|
|
101
|
+
*/
|
|
102
|
+
export interface VirtualServerHandler {
|
|
103
|
+
getHostedTables():
|
|
104
|
+
| (string | VirtualHostedTable)[]
|
|
105
|
+
| Promise<(string | VirtualHostedTable)[]>;
|
|
106
|
+
tableSchema(
|
|
107
|
+
tableId: string,
|
|
108
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
109
|
+
tableSize(tableId: string): number | Promise<number>;
|
|
110
|
+
tableMakeView(
|
|
111
|
+
tableId: string,
|
|
112
|
+
viewId: string,
|
|
113
|
+
config: ViewConfigUpdate,
|
|
114
|
+
): void | Promise<void>;
|
|
115
|
+
viewDelete(viewId: string): void | Promise<void>;
|
|
116
|
+
viewGetData(
|
|
117
|
+
viewId: string,
|
|
118
|
+
config: ViewConfig,
|
|
119
|
+
schema: Record<string, ColumnType>,
|
|
120
|
+
viewport: ViewWindow,
|
|
121
|
+
dataSlice: VirtualDataSlice,
|
|
122
|
+
): void | Promise<void>;
|
|
123
|
+
|
|
124
|
+
/** Defaults to `tableSchema(viewId)`. */
|
|
125
|
+
viewSchema?(
|
|
126
|
+
viewId: string,
|
|
127
|
+
config: ViewConfig,
|
|
128
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
129
|
+
|
|
130
|
+
/** Defaults to `tableSize(viewId)`. */
|
|
131
|
+
viewSize?(viewId: string): number | Promise<number>;
|
|
132
|
+
|
|
133
|
+
/** Defaults to the length of `tableSchema(tableId)`. */
|
|
134
|
+
tableColumnsSize?(tableId: string): number | Promise<number>;
|
|
135
|
+
|
|
136
|
+
/** Defaults to the length of `viewSchema(viewId, config)`. */
|
|
137
|
+
viewColumnSize?(
|
|
138
|
+
viewId: string,
|
|
139
|
+
config: ViewConfig,
|
|
140
|
+
): number | Promise<number>;
|
|
141
|
+
|
|
142
|
+
/** Required when `getFeatures()` reports `expressions: true`. */
|
|
143
|
+
tableValidateExpression?(
|
|
144
|
+
tableId: string,
|
|
145
|
+
expression: string,
|
|
146
|
+
): ColumnType | Promise<ColumnType>;
|
|
147
|
+
|
|
148
|
+
viewGetMinMax?(
|
|
149
|
+
viewId: string,
|
|
150
|
+
columnName: string,
|
|
151
|
+
config: ViewConfig,
|
|
152
|
+
): { min: Scalar; max: Scalar } | Promise<{ min: Scalar; max: Scalar }>;
|
|
153
|
+
|
|
154
|
+
/** Defaults to no optional features. */
|
|
155
|
+
getFeatures?(): Features | Promise<Features>;
|
|
156
|
+
|
|
157
|
+
/** Defaults to port `0`. */
|
|
158
|
+
tableMakePort?(): number | Promise<number>;
|
|
159
|
+
|
|
160
|
+
makeTable?(
|
|
161
|
+
tableId: string,
|
|
162
|
+
data: string | Uint8Array,
|
|
163
|
+
): void | Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
"#;
|
|
166
|
+
|
|
167
|
+
#[wasm_bindgen]
|
|
168
|
+
extern "C" {
|
|
169
|
+
#[wasm_bindgen(typescript_type = "VirtualServerHandler")]
|
|
170
|
+
pub type JsVirtualServerHandler;
|
|
171
|
+
}
|
|
172
|
+
|
|
77
173
|
pub struct JsServerHandler(Object);
|
|
78
174
|
|
|
79
175
|
impl JsServerHandler {
|
|
@@ -785,9 +881,9 @@ pub struct VirtualServer(Rc<UnsafeCell<virtual_server::VirtualServer<JsServerHan
|
|
|
785
881
|
#[wasm_bindgen]
|
|
786
882
|
impl VirtualServer {
|
|
787
883
|
#[wasm_bindgen(constructor)]
|
|
788
|
-
pub fn new(handler:
|
|
884
|
+
pub fn new(handler: JsVirtualServerHandler) -> Result<VirtualServer, JsValue> {
|
|
789
885
|
Ok(VirtualServer(Rc::new(UnsafeCell::new(
|
|
790
|
-
virtual_server::VirtualServer::new(JsServerHandler(handler)),
|
|
886
|
+
virtual_server::VirtualServer::new(JsServerHandler(handler.unchecked_into())),
|
|
791
887
|
))))
|
|
792
888
|
}
|
|
793
889
|
|