@cereusdb/minimal 0.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/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @cereusdb/minimal
2
+
3
+ Smallest public CereusDB browser package. Includes the shared browser API, GEOS-backed spatial SQL, relation joins, distance joins, and `ST_KNN` in the current in-memory browser MVP.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @cereusdb/minimal
9
+ ```
10
+
11
+ ## SQL function availability
12
+
13
+ Current runtime surface:
14
+
15
+ - `130` runtime `ST_*` names
16
+ - `0` runtime `RS_*` names
17
+
18
+ Included function families:
19
+
20
+ - Core SedonaDB scalar and aggregate functions from the pure-Rust runtime: constructors, WKT/WKB/EWKT/EWKB parsing, serializers, coordinate accessors, bounding-box helpers, SRID/CRS helpers, geometry properties, component access, affine transforms, and aggregates such as `ST_Collect_Agg`.
21
+ - `geo` functions such as `ST_Area`, `ST_Length`, `ST_Perimeter`, `ST_Distance`, `ST_DWithin`, `ST_Buffer`, `ST_Centroid`, `ST_Intersects`, `ST_LineInterpolatePoint`, `ST_AsGeoJSON`, `ST_Intersection_Agg`, and `ST_Union_Agg`.
22
+ - GEOS-backed predicates and operations such as `ST_Contains`, `ST_Within`, `ST_Covers`, `ST_CoveredBy`, `ST_Crosses`, `ST_Touches`, `ST_Overlaps`, `ST_Disjoint`, `ST_Equals`, `ST_Relate`, `ST_Intersection`, `ST_Union`, `ST_Difference`, `ST_SymDifference`, `ST_ConvexHull`, `ST_ConcaveHull`, `ST_Simplify`, `ST_Boundary`, `ST_UnaryUnion`, `ST_LineMerge`, `ST_Polygonize`, `ST_Snap`, `ST_MakeValid`, `ST_IsValid`, and `ST_IsValidReason`.
23
+ - Spatial join MVP support for relation joins, distance joins, and `ST_KNN`.
24
+
25
+ Not included in this package:
26
+
27
+ - `ST_Transform`
28
+ - S2 geography kernels
29
+ - Raster `RS_*` functions
30
+
31
+ ## JS / TS API
32
+
33
+ Exports:
34
+
35
+ - `CereusDB`
36
+ - `CereusDBOptions`
37
+ - `RasterFormat`
38
+ - `QueryResult`
39
+
40
+ Main types:
41
+
42
+ ```ts
43
+ type RasterFormat = 'geotiff' | 'tiff';
44
+
45
+ interface CereusDBOptions {
46
+ wasmUrl?: string;
47
+ wasmSource?:
48
+ | RequestInfo
49
+ | URL
50
+ | Response
51
+ | BufferSource
52
+ | WebAssembly.Module
53
+ | Promise<Response>;
54
+ }
55
+ ```
56
+
57
+ Main API:
58
+
59
+ ```ts
60
+ class CereusDB {
61
+ static create(options?: CereusDBOptions): Promise<CereusDB>;
62
+ sql(query: string): Promise<Uint8Array>;
63
+ sqlJSON(query: string): Promise<Record<string, unknown>[]>;
64
+ registerRemoteParquet(name: string, url: string): Promise<void>;
65
+ registerFile(name: string, file: File): Promise<void>;
66
+ registerGeoJSON(name: string, geojson: string | object): void;
67
+ registerRaster(name: string, data: BufferSource, format: RasterFormat): void;
68
+ registerGeoTIFF(name: string, data: BufferSource): void;
69
+ dropTable(name: string): void;
70
+ tables(): string[];
71
+ version(): string;
72
+ }
73
+ ```
74
+
75
+ API notes:
76
+
77
+ - `sql()` returns Arrow IPC bytes as `Uint8Array`.
78
+ - `sqlJSON()` returns parsed JSON rows.
79
+ - `registerFile()` supports `.parquet`, `.geoparquet`, `.geojson`, and `.json` in this package.
80
+ - `registerRaster()` and `registerGeoTIFF()` are part of the shared wrapper, but raster registration requires `@cereusdb/full`.
81
+
82
+ ## Example
83
+
84
+ ```ts
85
+ import { CereusDB } from '@cereusdb/minimal';
86
+
87
+ const db = await CereusDB.create();
88
+
89
+ const rows = await db.sqlJSON(`
90
+ SELECT ST_AsText(ST_Buffer(ST_Point(0, 0), 1.0)) AS geom
91
+ `);
92
+
93
+ console.log(rows);
94
+ ```
@@ -0,0 +1,64 @@
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
+ }
17
+ export type RasterFormat = 'geotiff' | 'tiff';
18
+ export declare class CereusDB {
19
+ private inner;
20
+ private constructor();
21
+ /**
22
+ * Create and initialize a new CereusDB instance.
23
+ * This loads the WASM module and initializes the query engine.
24
+ */
25
+ static create(options?: CereusDBOptions): Promise<CereusDB>;
26
+ /**
27
+ * Execute a SQL query and return results as Arrow IPC bytes.
28
+ */
29
+ sql(query: string): Promise<Uint8Array>;
30
+ /**
31
+ * Execute a SQL query and return results as JSON.
32
+ */
33
+ sqlJSON(query: string): Promise<Record<string, unknown>[]>;
34
+ /**
35
+ * Register a remote Parquet file as a table.
36
+ * The server must support CORS.
37
+ */
38
+ registerRemoteParquet(name: string, url: string): Promise<void>;
39
+ /**
40
+ * Register a local file (from File API / drag-and-drop) as a table.
41
+ * Currently supports Parquet, GeoJSON, and GeoTIFF rasters.
42
+ */
43
+ registerFile(name: string, file: File): Promise<void>;
44
+ /**
45
+ * Register a GeoJSON object or string as a table.
46
+ */
47
+ registerGeoJSON(name: string, geojson: string | object): void;
48
+ /**
49
+ * Register a raster buffer as a single-column raster table.
50
+ * Requires the full GDAL-enabled package build.
51
+ */
52
+ registerRaster(name: string, data: BufferSource, format: RasterFormat): void;
53
+ /**
54
+ * Register a GeoTIFF buffer as a single-column raster table.
55
+ * Requires the full GDAL-enabled package build.
56
+ */
57
+ registerGeoTIFF(name: string, data: BufferSource): void;
58
+ /** Drop a table. */
59
+ dropTable(name: string): void;
60
+ /** List registered tables. */
61
+ tables(): string[];
62
+ /** Version string. */
63
+ version(): string;
64
+ }
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ import init, { CereusDB as WasmCereusDB } from './wasm/cereusdb.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
+ return new CereusDB(inner);
33
+ }
34
+ /**
35
+ * Execute a SQL query and return results as Arrow IPC bytes.
36
+ */
37
+ async sql(query) {
38
+ return await this.inner.sql(query);
39
+ }
40
+ /**
41
+ * Execute a SQL query and return results as JSON.
42
+ */
43
+ async sqlJSON(query) {
44
+ const json = await this.inner.sql_json(query);
45
+ return JSON.parse(json);
46
+ }
47
+ /**
48
+ * Register a remote Parquet file as a table.
49
+ * The server must support CORS.
50
+ */
51
+ async registerRemoteParquet(name, url) {
52
+ await this.inner.register_remote_parquet(name, url);
53
+ }
54
+ /**
55
+ * Register a local file (from File API / drag-and-drop) as a table.
56
+ * Currently supports Parquet, GeoJSON, and GeoTIFF rasters.
57
+ */
58
+ async registerFile(name, file) {
59
+ const buffer = new Uint8Array(await file.arrayBuffer());
60
+ const ext = file.name.split('.').pop()?.toLowerCase();
61
+ if (ext === 'parquet' || ext === 'geoparquet') {
62
+ await this.inner.register_parquet_buffer(name, buffer);
63
+ }
64
+ else if (ext === 'geojson' || ext === 'json') {
65
+ const text = new TextDecoder().decode(buffer);
66
+ this.inner.register_geojson(name, text);
67
+ }
68
+ else if (ext === 'tif' || ext === 'tiff') {
69
+ this.registerRaster(name, buffer, 'geotiff');
70
+ }
71
+ else {
72
+ throw new Error(`Unsupported file format: .${ext}`);
73
+ }
74
+ }
75
+ /**
76
+ * Register a GeoJSON object or string as a table.
77
+ */
78
+ registerGeoJSON(name, geojson) {
79
+ const str = typeof geojson === 'string' ? geojson : JSON.stringify(geojson);
80
+ this.inner.register_geojson(name, str);
81
+ }
82
+ /**
83
+ * Register a raster buffer as a single-column raster table.
84
+ * Requires the full GDAL-enabled package build.
85
+ */
86
+ registerRaster(name, data, format) {
87
+ this.inner.register_raster_buffer(name, normalizeRasterFormat(format), toUint8Array(data));
88
+ }
89
+ /**
90
+ * Register a GeoTIFF buffer as a single-column raster table.
91
+ * Requires the full GDAL-enabled package build.
92
+ */
93
+ registerGeoTIFF(name, data) {
94
+ this.registerRaster(name, data, 'geotiff');
95
+ }
96
+ /** Drop a table. */
97
+ dropTable(name) {
98
+ this.inner.drop_table(name);
99
+ }
100
+ /** List registered tables. */
101
+ tables() {
102
+ return this.inner.tables();
103
+ }
104
+ /** Version string. */
105
+ version() {
106
+ return this.inner.version();
107
+ }
108
+ }
@@ -0,0 +1,132 @@
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 a Uint8Array containing Parquet data as a named table.
32
+ * Use for files obtained via the browser File API.
33
+ */
34
+ register_parquet_buffer(table_name: string, data: Uint8Array): Promise<void>;
35
+ /**
36
+ * Register a raster buffer as a single-column raster table.
37
+ * Requires the full GDAL-enabled build.
38
+ */
39
+ register_raster_buffer(table_name: string, format: string, data: Uint8Array): void;
40
+ /**
41
+ * Register a remote Parquet file URL as a named table.
42
+ * Pre-fetches the entire file via HTTP, then loads into memory.
43
+ * The server must support CORS.
44
+ */
45
+ register_remote_parquet(table_name: string, url: string): Promise<void>;
46
+ /**
47
+ * Execute a SQL query.
48
+ * Returns results as Arrow IPC bytes (Uint8Array).
49
+ * The caller can decode this with the apache-arrow JS library.
50
+ */
51
+ sql(query: string): Promise<Uint8Array>;
52
+ /**
53
+ * Execute a SQL query and return results as a JSON string.
54
+ * Convenience method for simple use cases.
55
+ */
56
+ sql_json(query: string): Promise<string>;
57
+ /**
58
+ * List all registered table names.
59
+ */
60
+ tables(): any;
61
+ /**
62
+ * Get version information.
63
+ */
64
+ version(): string;
65
+ }
66
+
67
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
68
+
69
+ export interface InitOutput {
70
+ readonly memory: WebAssembly.Memory;
71
+ readonly __wasm_call_ctors: () => void;
72
+ readonly __libc_calloc: (a: number, b: number) => number;
73
+ readonly calloc: (a: number, b: number) => number;
74
+ readonly __libc_free: (a: number) => void;
75
+ readonly free: (a: number) => void;
76
+ readonly __libc_malloc: (a: number) => number;
77
+ readonly malloc: (a: number) => number;
78
+ readonly __wbg_cereusdb_free: (a: number, b: number) => void;
79
+ readonly _abort_js: () => void;
80
+ readonly cereusdb_create: () => [number, number, number];
81
+ readonly cereusdb_drop_table: (a: number, b: number, c: number) => [number, number];
82
+ readonly cereusdb_register_geojson: (a: number, b: number, c: number, d: number, e: number) => [number, number];
83
+ readonly cereusdb_register_geotiff_buffer: (a: number, b: number, c: number, d: number, e: number) => [number, number];
84
+ readonly cereusdb_register_parquet_buffer: (a: number, b: number, c: number, d: number, e: number) => any;
85
+ readonly cereusdb_register_raster_buffer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
86
+ readonly cereusdb_register_remote_parquet: (a: number, b: number, c: number, d: number, e: number) => any;
87
+ readonly cereusdb_sql: (a: number, b: number, c: number) => any;
88
+ readonly cereusdb_sql_json: (a: number, b: number, c: number) => any;
89
+ readonly cereusdb_tables: (a: number) => [number, number, number];
90
+ readonly cereusdb_version: (a: number) => [number, number];
91
+ readonly emscripten_builtin_malloc_usable_size: (a: number) => number;
92
+ readonly malloc_usable_size: (a: number) => number;
93
+ readonly emscripten_builtin_memalign: (a: number, b: number) => number;
94
+ readonly posix_memalign: (a: number, b: number, c: number) => number;
95
+ readonly realloc: (a: number, b: number) => number;
96
+ readonly abort: () => void;
97
+ readonly emscripten_builtin_free: (a: number) => void;
98
+ readonly emscripten_builtin_malloc: (a: number) => number;
99
+ readonly __cpp_exception: WebAssembly.Tag;
100
+ readonly wasm_bindgen__closure__destroy__he74b42d6a982a3c3: (a: number, b: number) => void;
101
+ readonly wasm_bindgen__convert__closures_____invoke__hf2284274f3d5489c: (a: number, b: number, c: any) => [number, number];
102
+ readonly wasm_bindgen__convert__closures_____invoke__h34d4f60983fa9e41: (a: number, b: number, c: any, d: any) => void;
103
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
104
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
105
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
106
+ readonly __externref_table_alloc: () => number;
107
+ readonly __wbindgen_externrefs: WebAssembly.Table;
108
+ readonly __externref_table_dealloc: (a: number) => void;
109
+ readonly __wbindgen_start: () => void;
110
+ }
111
+
112
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
113
+
114
+ /**
115
+ * Instantiates the given `module`, which can either be bytes or
116
+ * a precompiled `WebAssembly.Module`.
117
+ *
118
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
119
+ *
120
+ * @returns {InitOutput}
121
+ */
122
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
123
+
124
+ /**
125
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
126
+ * for everything else, calls `WebAssembly.instantiate` directly.
127
+ *
128
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
129
+ *
130
+ * @returns {Promise<InitOutput>}
131
+ */
132
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;