@cereusdb/standard 0.2.0 → 0.3.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/README.md CHANGED
@@ -10,11 +10,15 @@ This package includes browser object stores for ranged remote Parquet reads and
10
10
  npm install @cereusdb/standard
11
11
  ```
12
12
 
13
+ ## Parquet support
14
+
15
+ Parquet files compressed with Snappy, Gzip, Brotli, LZ4, or ZSTD can be registered.
16
+
13
17
  ## SQL function availability
14
18
 
15
19
  Current runtime surface:
16
20
 
17
- - `131` runtime `ST_*` names
21
+ - `151` runtime `ST_*` names
18
22
  - `0` runtime `RS_*` names
19
23
 
20
24
  Included function families:
@@ -37,6 +41,20 @@ Not included in this package:
37
41
 
38
42
  Browser object stores are included in `@cereusdb/standard`. Use `registerObjectStores()` to configure `http`, `s3`, `gcs`, or `azure` providers, then `registerParquetTable()` to register an exact Parquet object or provider-backed prefix.
39
43
 
44
+ ## Loading the WASM module
45
+
46
+ The wasm binary ships as a separate file, `dist/wasm/cereusdb_bg.wasm`. The default entry finds it automatically, and bundlers emit it as an asset.
47
+
48
+ If you host the wasm yourself, or your bundler inlines assets into large `data:application/wasm;base64,...` strings, use the `external` entry. It has no built-in wasm reference and requires `wasmUrl` or `wasmSource`:
49
+
50
+ ```ts
51
+ import { CereusDB } from '@cereusdb/standard/external';
52
+
53
+ const db = await CereusDB.create({ wasmUrl: '/wasm/cereusdb_bg.wasm' });
54
+ ```
55
+
56
+ Copy `node_modules/@cereusdb/standard/dist/wasm/cereusdb_bg.wasm` to your static assets, or import its URL with Vite: `import wasmUrl from '@cereusdb/standard/wasm?url'`. See the [WASM loading guide](https://github.com/tobilg/cereusdb/blob/main/packages/documentation/guides/wasm-loading.md) for details.
57
+
40
58
  ## JS / TS API
41
59
 
42
60
  Exports:
@@ -0,0 +1,98 @@
1
+ export interface QueryResult {
2
+ /** Raw JSON data parsed from query */
3
+ data: Record<string, unknown>[];
4
+ /** Number of rows */
5
+ numRows: number;
6
+ /** Raw Arrow IPC bytes */
7
+ toIPC(): Uint8Array;
8
+ /** Convert to array of plain JS objects */
9
+ toJSON(): Record<string, unknown>[];
10
+ }
11
+ export interface CereusDBOptions {
12
+ /** Custom WASM module URL (for CDN hosting) */
13
+ wasmUrl?: string;
14
+ /** Preloaded WASM bytes/module for Node or custom loaders. */
15
+ wasmSource?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module | Promise<Response>;
16
+ /** Browser-backed object stores to register at startup. */
17
+ objectStores?: ObjectStoreRegistryConfig;
18
+ }
19
+ export type RasterFormat = 'geotiff' | 'tiff';
20
+ export type ObjectStoreProvider = 'http' | 's3' | 'gcs' | 'azure';
21
+ export interface ObjectStoreRegistryConfig {
22
+ /** Maximum concurrent browser fetches used by object_store. */
23
+ maxConcurrency?: number;
24
+ /** Stores registered by URL prefix. */
25
+ stores: ObjectStoreConfig[];
26
+ }
27
+ export interface ObjectStoreConfig {
28
+ /** Optional diagnostic name. */
29
+ name?: string;
30
+ /** Backing provider. */
31
+ provider: ObjectStoreProvider;
32
+ /** URL prefix, for example https://host, s3://bucket, gs://bucket. */
33
+ url: string;
34
+ /** Upstream object_store option keys and primitive values. */
35
+ options?: Record<string, string | number | boolean>;
36
+ }
37
+ export interface RegisterParquetTableOptions {
38
+ /** File extension used during listing discovery. Defaults to .parquet. */
39
+ fileExtension?: string;
40
+ /** Optional DataFusion target partition count. */
41
+ targetPartitions?: number;
42
+ }
43
+ export declare class CereusDB {
44
+ private inner;
45
+ private constructor();
46
+ /**
47
+ * Create and initialize a new CereusDB instance.
48
+ * This loads the WASM module and initializes the query engine.
49
+ */
50
+ static create(options?: CereusDBOptions): Promise<CereusDB>;
51
+ /**
52
+ * Execute a SQL query and return results as Arrow IPC bytes.
53
+ */
54
+ sql(query: string): Promise<Uint8Array>;
55
+ /**
56
+ * Execute a SQL query and return results as JSON.
57
+ */
58
+ sqlJSON(query: string): Promise<Record<string, unknown>[]>;
59
+ /**
60
+ * Register a remote Parquet file as a table.
61
+ * The server must support CORS.
62
+ */
63
+ registerRemoteParquet(name: string, url: string): Promise<void>;
64
+ /**
65
+ * Register browser-backed object stores for ranged and listing reads.
66
+ */
67
+ registerObjectStores(config: ObjectStoreRegistryConfig): void;
68
+ /**
69
+ * Register a remote Parquet object or prefix through DataFusion's listing table path.
70
+ */
71
+ registerParquetTable(name: string, url: string, options?: RegisterParquetTableOptions): Promise<void>;
72
+ /**
73
+ * Register a local file (from File API / drag-and-drop) as a table.
74
+ * Currently supports Parquet, GeoJSON, and GeoTIFF rasters.
75
+ */
76
+ registerFile(name: string, file: File): Promise<void>;
77
+ /**
78
+ * Register a GeoJSON object or string as a table.
79
+ */
80
+ registerGeoJSON(name: string, geojson: string | object): void;
81
+ /**
82
+ * Register a raster buffer as a single-column raster table.
83
+ * Requires the full GDAL-enabled package build.
84
+ */
85
+ registerRaster(name: string, data: BufferSource, format: RasterFormat): void;
86
+ /**
87
+ * Register a GeoTIFF buffer as a single-column raster table.
88
+ * Requires the full GDAL-enabled package build.
89
+ */
90
+ registerGeoTIFF(name: string, data: BufferSource): void;
91
+ /** Drop a table. */
92
+ dropTable(name: string): void;
93
+ /** List registered tables. */
94
+ tables(): string[];
95
+ /** Version string. */
96
+ version(): string;
97
+ private objectStoreApi;
98
+ }
@@ -0,0 +1,132 @@
1
+ import init, { CereusDB as WasmCereusDB } from './wasm/cereusdb-external.js';
2
+ function toUint8Array(data) {
3
+ if (ArrayBuffer.isView(data)) {
4
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
5
+ }
6
+ return new Uint8Array(data);
7
+ }
8
+ function normalizeRasterFormat(format) {
9
+ const normalized = format.trim().toLowerCase();
10
+ if (normalized === 'geotiff' || normalized === 'tiff') {
11
+ return normalized;
12
+ }
13
+ throw new Error(`Unsupported raster format: ${format}`);
14
+ }
15
+ export class CereusDB {
16
+ constructor(inner) {
17
+ this.inner = inner;
18
+ }
19
+ /**
20
+ * Create and initialize a new CereusDB instance.
21
+ * This loads the WASM module and initializes the query engine.
22
+ */
23
+ static async create(options) {
24
+ const source = options?.wasmSource ?? options?.wasmUrl;
25
+ if (source === undefined) {
26
+ await init();
27
+ }
28
+ else {
29
+ await init({ module_or_path: source });
30
+ }
31
+ const inner = WasmCereusDB.create();
32
+ const db = new CereusDB(inner);
33
+ if (options?.objectStores !== undefined) {
34
+ db.registerObjectStores(options.objectStores);
35
+ }
36
+ return db;
37
+ }
38
+ /**
39
+ * Execute a SQL query and return results as Arrow IPC bytes.
40
+ */
41
+ async sql(query) {
42
+ return await this.inner.sql(query);
43
+ }
44
+ /**
45
+ * Execute a SQL query and return results as JSON.
46
+ */
47
+ async sqlJSON(query) {
48
+ const json = await this.inner.sql_json(query);
49
+ return JSON.parse(json);
50
+ }
51
+ /**
52
+ * Register a remote Parquet file as a table.
53
+ * The server must support CORS.
54
+ */
55
+ async registerRemoteParquet(name, url) {
56
+ await this.inner.register_remote_parquet(name, url);
57
+ }
58
+ /**
59
+ * Register browser-backed object stores for ranged and listing reads.
60
+ */
61
+ registerObjectStores(config) {
62
+ this.objectStoreApi().register_object_stores(config);
63
+ }
64
+ /**
65
+ * Register a remote Parquet object or prefix through DataFusion's listing table path.
66
+ */
67
+ async registerParquetTable(name, url, options = {}) {
68
+ await this.objectStoreApi().register_parquet_table(name, url, options);
69
+ }
70
+ /**
71
+ * Register a local file (from File API / drag-and-drop) as a table.
72
+ * Currently supports Parquet, GeoJSON, and GeoTIFF rasters.
73
+ */
74
+ async registerFile(name, file) {
75
+ const buffer = new Uint8Array(await file.arrayBuffer());
76
+ const ext = file.name.split('.').pop()?.toLowerCase();
77
+ if (ext === 'parquet' || ext === 'geoparquet') {
78
+ await this.inner.register_parquet_buffer(name, buffer);
79
+ }
80
+ else if (ext === 'geojson' || ext === 'json') {
81
+ const text = new TextDecoder().decode(buffer);
82
+ this.inner.register_geojson(name, text);
83
+ }
84
+ else if (ext === 'tif' || ext === 'tiff') {
85
+ this.registerRaster(name, buffer, 'geotiff');
86
+ }
87
+ else {
88
+ throw new Error(`Unsupported file format: .${ext}`);
89
+ }
90
+ }
91
+ /**
92
+ * Register a GeoJSON object or string as a table.
93
+ */
94
+ registerGeoJSON(name, geojson) {
95
+ const str = typeof geojson === 'string' ? geojson : JSON.stringify(geojson);
96
+ this.inner.register_geojson(name, str);
97
+ }
98
+ /**
99
+ * Register a raster buffer as a single-column raster table.
100
+ * Requires the full GDAL-enabled package build.
101
+ */
102
+ registerRaster(name, data, format) {
103
+ this.inner.register_raster_buffer(name, normalizeRasterFormat(format), toUint8Array(data));
104
+ }
105
+ /**
106
+ * Register a GeoTIFF buffer as a single-column raster table.
107
+ * Requires the full GDAL-enabled package build.
108
+ */
109
+ registerGeoTIFF(name, data) {
110
+ this.registerRaster(name, data, 'geotiff');
111
+ }
112
+ /** Drop a table. */
113
+ dropTable(name) {
114
+ this.inner.drop_table(name);
115
+ }
116
+ /** List registered tables. */
117
+ tables() {
118
+ return this.inner.tables();
119
+ }
120
+ /** Version string. */
121
+ version() {
122
+ return this.inner.version();
123
+ }
124
+ objectStoreApi() {
125
+ const api = this.inner;
126
+ if (typeof api.register_object_stores !== 'function' ||
127
+ typeof api.register_parquet_table !== 'function') {
128
+ throw new Error('Browser object stores are not available in this CereusDB build');
129
+ }
130
+ return api;
131
+ }
132
+ }
@@ -0,0 +1,153 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Main CereusDB instance for browser use.
6
+ * Wraps a DataFusion SessionContext with spatial extensions registered.
7
+ */
8
+ export class CereusDB {
9
+ private constructor();
10
+ free(): void;
11
+ [Symbol.dispose](): void;
12
+ /**
13
+ * Create a new CereusDB instance.
14
+ * Initializes DataFusion context and registers all spatial functions.
15
+ */
16
+ static create(): CereusDB;
17
+ /**
18
+ * Drop a registered table.
19
+ */
20
+ drop_table(table_name: string): void;
21
+ /**
22
+ * Register a GeoJSON string as a named table.
23
+ */
24
+ register_geojson(table_name: string, geojson: string): void;
25
+ /**
26
+ * Register a GeoTIFF buffer as a single-column raster table.
27
+ * Requires the full GDAL-enabled build.
28
+ */
29
+ register_geotiff_buffer(table_name: string, data: Uint8Array): void;
30
+ /**
31
+ * Register browser-backed object stores for ranged/listing reads.
32
+ */
33
+ register_object_stores(config: any): void;
34
+ /**
35
+ * Register a Uint8Array containing Parquet data as a named table.
36
+ * Use for files obtained via the browser File API.
37
+ */
38
+ register_parquet_buffer(table_name: string, data: Uint8Array): Promise<void>;
39
+ /**
40
+ * Register a remote Parquet object or prefix as a DataFusion listing table.
41
+ */
42
+ register_parquet_table(table_name: string, table_url: string, options: any): Promise<void>;
43
+ /**
44
+ * Register a raster buffer as a single-column raster table.
45
+ * Requires the full GDAL-enabled build.
46
+ */
47
+ register_raster_buffer(table_name: string, format: string, data: Uint8Array): void;
48
+ /**
49
+ * Register a remote Parquet file URL as a named table.
50
+ * Pre-fetches the entire file via HTTP, then loads into memory.
51
+ * The server must support CORS.
52
+ */
53
+ register_remote_parquet(table_name: string, url: string): Promise<void>;
54
+ /**
55
+ * Execute a SQL query.
56
+ * Returns results as Arrow IPC bytes (Uint8Array).
57
+ * The caller can decode this with the apache-arrow JS library.
58
+ */
59
+ sql(query: string): Promise<Uint8Array>;
60
+ /**
61
+ * Execute a SQL query and return results as a JSON string.
62
+ * Convenience method for simple use cases.
63
+ */
64
+ sql_json(query: string): Promise<string>;
65
+ /**
66
+ * List all registered table names.
67
+ */
68
+ tables(): any;
69
+ /**
70
+ * Get version information.
71
+ *
72
+ * Release builds set `CEREUSDB_VERSION` to the full npm version, including
73
+ * prerelease suffixes; other builds fall back to the crate version.
74
+ */
75
+ version(): string;
76
+ }
77
+
78
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
79
+
80
+ export interface InitOutput {
81
+ readonly memory: WebAssembly.Memory;
82
+ readonly __wasm_call_ctors: () => void;
83
+ readonly __libc_calloc: (a: number, b: number) => number;
84
+ readonly calloc: (a: number, b: number) => number;
85
+ readonly __libc_free: (a: number) => void;
86
+ readonly free: (a: number) => void;
87
+ readonly __libc_malloc: (a: number) => number;
88
+ readonly malloc: (a: number) => number;
89
+ readonly __wbg_cereusdb_free: (a: number, b: number) => void;
90
+ readonly _abort_js: () => void;
91
+ readonly cereusdb_create: () => [number, number, number];
92
+ readonly cereusdb_drop_table: (a: number, b: number, c: number) => [number, number];
93
+ readonly cereusdb_register_geojson: (a: number, b: number, c: number, d: number, e: number) => [number, number];
94
+ readonly cereusdb_register_geotiff_buffer: (a: number, b: number, c: number, d: number, e: number) => [number, number];
95
+ readonly cereusdb_register_object_stores: (a: number, b: any) => [number, number];
96
+ readonly cereusdb_register_parquet_buffer: (a: number, b: number, c: number, d: number, e: number) => any;
97
+ readonly cereusdb_register_parquet_table: (a: number, b: number, c: number, d: number, e: number, f: any) => any;
98
+ readonly cereusdb_register_raster_buffer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
99
+ readonly cereusdb_register_remote_parquet: (a: number, b: number, c: number, d: number, e: number) => any;
100
+ readonly cereusdb_sql: (a: number, b: number, c: number) => any;
101
+ readonly cereusdb_sql_json: (a: number, b: number, c: number) => any;
102
+ readonly cereusdb_tables: (a: number) => [number, number, number];
103
+ readonly cereusdb_version: (a: number) => [number, number];
104
+ readonly emscripten_builtin_malloc_usable_size: (a: number) => number;
105
+ readonly malloc_usable_size: (a: number) => number;
106
+ readonly emscripten_builtin_memalign: (a: number, b: number) => number;
107
+ readonly posix_memalign: (a: number, b: number, c: number) => number;
108
+ readonly realloc: (a: number, b: number) => number;
109
+ readonly abort: () => void;
110
+ readonly emscripten_builtin_free: (a: number) => void;
111
+ readonly emscripten_builtin_malloc: (a: number) => number;
112
+ readonly rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
113
+ readonly rust_zstd_wasm_shim_free: (a: number) => void;
114
+ readonly rust_zstd_wasm_shim_malloc: (a: number) => number;
115
+ readonly rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
116
+ readonly rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
117
+ readonly rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
118
+ readonly rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
119
+ readonly rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
120
+ readonly __cpp_exception: WebAssembly.Tag;
121
+ readonly wasm_bindgen__closure__destroy__h8db467765ce434ac: (a: number, b: number) => void;
122
+ readonly wasm_bindgen__convert__closures_____invoke__h7573a8a64f443504: (a: number, b: number, c: any) => [number, number];
123
+ readonly wasm_bindgen__convert__closures_____invoke__h3bcc27440de746c0: (a: number, b: number, c: any, d: any) => void;
124
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
125
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
126
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
127
+ readonly __externref_table_alloc: () => number;
128
+ readonly __wbindgen_externrefs: WebAssembly.Table;
129
+ readonly __externref_table_dealloc: (a: number) => void;
130
+ readonly __wbindgen_start: () => void;
131
+ }
132
+
133
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
134
+
135
+ /**
136
+ * Instantiates the given `module`, which can either be bytes or
137
+ * a precompiled `WebAssembly.Module`.
138
+ *
139
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
140
+ *
141
+ * @returns {InitOutput}
142
+ */
143
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
144
+
145
+ /**
146
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
147
+ * for everything else, calls `WebAssembly.instantiate` directly.
148
+ *
149
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
150
+ *
151
+ * @returns {Promise<InitOutput>}
152
+ */
153
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;