@walkthru-earth/objex-utils 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/LICENSE +396 -0
- package/dist/index.cjs +2543 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +433 -0
- package/dist/index.d.ts +433 -0
- package/dist/index.js +2512 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { Table } from 'apache-arrow';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Centralized file type detection module.
|
|
5
|
+
*
|
|
6
|
+
* Single source of truth for extension → icon, color, label, category,
|
|
7
|
+
* viewer, DuckDB read function, MIME type, and queryability.
|
|
8
|
+
*
|
|
9
|
+
* Used by: FileRow, FileTreeSidebar, ViewerRouter, TableViewer, WasmQueryEngine, etc.
|
|
10
|
+
*/
|
|
11
|
+
type FileCategory = 'data' | 'geo' | 'code' | 'document' | 'config' | 'image' | 'video' | 'audio' | 'archive' | 'database' | '3d' | 'other';
|
|
12
|
+
type ViewerKind = 'table' | 'image' | 'video' | 'audio' | 'markdown' | 'code' | 'cog' | 'pmtiles' | 'flatgeobuf' | 'pdf' | '3d' | 'archive' | 'database' | 'zarr' | 'copc' | 'notebook' | 'raw';
|
|
13
|
+
type DuckDbReadFn = 'read_parquet' | 'read_csv' | 'read_json' | 'ST_Read';
|
|
14
|
+
interface FileTypeInfo {
|
|
15
|
+
/** Lucide icon name */
|
|
16
|
+
icon: string;
|
|
17
|
+
/** Tailwind color classes (light + dark) */
|
|
18
|
+
color: string;
|
|
19
|
+
/** Human-readable type label, e.g. "Apache Parquet" */
|
|
20
|
+
label: string;
|
|
21
|
+
/** High-level category */
|
|
22
|
+
category: FileCategory;
|
|
23
|
+
/** Which viewer component to use */
|
|
24
|
+
viewer: ViewerKind;
|
|
25
|
+
/** Whether this file can be queried with DuckDB */
|
|
26
|
+
queryable: boolean;
|
|
27
|
+
/** DuckDB read function (null if not queryable) */
|
|
28
|
+
duckdbReadFn: DuckDbReadFn | null;
|
|
29
|
+
/** MIME type */
|
|
30
|
+
mimeType: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns full file type information for a given extension.
|
|
34
|
+
* Extension may be with or without leading dot: ".parquet" or "parquet".
|
|
35
|
+
*/
|
|
36
|
+
declare function getFileTypeInfo(extension: string, isDir?: boolean): FileTypeInfo;
|
|
37
|
+
/** Returns the DuckDB read function name for a file path. Falls back to read_parquet. */
|
|
38
|
+
declare function getDuckDbReadFn(pathOrExt: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a DuckDB FROM-clause expression for a file.
|
|
41
|
+
*
|
|
42
|
+
* For GeoJSON files the raw `read_json_auto` returns a single row with the
|
|
43
|
+
* FeatureCollection structure (`type`, `features`, `bbox`). This helper
|
|
44
|
+
* unnests the features array so each feature becomes its own row with
|
|
45
|
+
* property columns + a geometry column.
|
|
46
|
+
*/
|
|
47
|
+
declare function buildDuckDbSource(pathOrExt: string, url: string): string;
|
|
48
|
+
declare function isCloudNativeFormat(pathOrExt: string): boolean;
|
|
49
|
+
/** Returns the viewer kind for a given extension. */
|
|
50
|
+
declare function getViewerKind(extension: string): ViewerKind;
|
|
51
|
+
/** Returns whether a file can be queried with DuckDB. */
|
|
52
|
+
declare function isQueryable(extension: string): boolean;
|
|
53
|
+
/** Returns the MIME type for a file extension. */
|
|
54
|
+
declare function getMimeType(extension: string): string;
|
|
55
|
+
|
|
56
|
+
declare class QueryCancelledError extends Error {
|
|
57
|
+
constructor();
|
|
58
|
+
}
|
|
59
|
+
interface QueryHandle {
|
|
60
|
+
result: Promise<QueryResult>;
|
|
61
|
+
cancel: () => Promise<boolean>;
|
|
62
|
+
}
|
|
63
|
+
interface MapQueryHandle {
|
|
64
|
+
result: Promise<MapQueryResult>;
|
|
65
|
+
cancel: () => Promise<boolean>;
|
|
66
|
+
}
|
|
67
|
+
interface QueryResult {
|
|
68
|
+
columns: string[];
|
|
69
|
+
types: string[];
|
|
70
|
+
rowCount: number;
|
|
71
|
+
/** Pre-parsed rows — avoids Arrow version mismatch in WASM engine */
|
|
72
|
+
rows: Record<string, any>[];
|
|
73
|
+
}
|
|
74
|
+
/** Raw column data for map rendering (bypasses toJSON serialization). */
|
|
75
|
+
interface MapQueryResult {
|
|
76
|
+
/** Geometry column as raw WKB binary arrays */
|
|
77
|
+
wkbArrays: Uint8Array[];
|
|
78
|
+
/** Geometry type from ST_GeometryType (e.g., 'POLYGON') */
|
|
79
|
+
geometryType: string;
|
|
80
|
+
/** Non-geometry attribute columns: name → JS values */
|
|
81
|
+
attributes: Map<string, {
|
|
82
|
+
values: any[];
|
|
83
|
+
type: string;
|
|
84
|
+
}>;
|
|
85
|
+
/** Number of rows */
|
|
86
|
+
rowCount: number;
|
|
87
|
+
}
|
|
88
|
+
interface SchemaField {
|
|
89
|
+
name: string;
|
|
90
|
+
type: string;
|
|
91
|
+
nullable: boolean;
|
|
92
|
+
}
|
|
93
|
+
interface QueryEngine {
|
|
94
|
+
query(connId: string, sql: string): Promise<QueryResult>;
|
|
95
|
+
queryForMap(connId: string, sql: string, geomCol: string, geomColType: string, sourceCrs?: string | null): Promise<MapQueryResult>;
|
|
96
|
+
getSchema(connId: string, path: string): Promise<SchemaField[]>;
|
|
97
|
+
getRowCount(connId: string, path: string): Promise<number>;
|
|
98
|
+
/** Detect CRS from GeoParquet metadata. Returns e.g. 'EPSG:27700' or null if WGS84/unknown. */
|
|
99
|
+
detectCrs(connId: string, path: string, geomCol: string): Promise<string | null>;
|
|
100
|
+
/** Combined schema + CRS detection in a single connection (fewer web worker round-trips). */
|
|
101
|
+
getSchemaAndCrs?(connId: string, path: string, findGeoCol: (schema: SchemaField[]) => string | null): Promise<{
|
|
102
|
+
schema: SchemaField[];
|
|
103
|
+
geomCol: string | null;
|
|
104
|
+
crs: string | null;
|
|
105
|
+
}>;
|
|
106
|
+
queryCancellable?(connId: string, sql: string): QueryHandle;
|
|
107
|
+
queryForMapCancellable?(connId: string, sql: string, geomCol: string, geomColType: string, sourceCrs?: string | null): MapQueryHandle;
|
|
108
|
+
forceCancel?(): Promise<void>;
|
|
109
|
+
releaseMemory(): Promise<void>;
|
|
110
|
+
dispose(): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface FileEntry {
|
|
114
|
+
name: string;
|
|
115
|
+
path: string;
|
|
116
|
+
is_dir: boolean;
|
|
117
|
+
size: number;
|
|
118
|
+
modified: number;
|
|
119
|
+
extension: string;
|
|
120
|
+
}
|
|
121
|
+
interface Connection {
|
|
122
|
+
id: string;
|
|
123
|
+
name: string;
|
|
124
|
+
provider: 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj';
|
|
125
|
+
endpoint: string;
|
|
126
|
+
bucket: string;
|
|
127
|
+
region: string;
|
|
128
|
+
anonymous: boolean;
|
|
129
|
+
authMethod?: 'sigv4' | 'sas-token';
|
|
130
|
+
rootPrefix?: string;
|
|
131
|
+
}
|
|
132
|
+
interface ConnectionConfig {
|
|
133
|
+
name: string;
|
|
134
|
+
provider: 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj';
|
|
135
|
+
endpoint: string;
|
|
136
|
+
bucket: string;
|
|
137
|
+
region: string;
|
|
138
|
+
access_key?: string;
|
|
139
|
+
secret_key?: string;
|
|
140
|
+
sas_token?: string;
|
|
141
|
+
anonymous: boolean;
|
|
142
|
+
authMethod?: 'sigv4' | 'sas-token';
|
|
143
|
+
rootPrefix?: string;
|
|
144
|
+
}
|
|
145
|
+
interface Tab {
|
|
146
|
+
id: string;
|
|
147
|
+
name: string;
|
|
148
|
+
path: string;
|
|
149
|
+
source: 'remote' | 'url';
|
|
150
|
+
connectionId?: string;
|
|
151
|
+
extension: string;
|
|
152
|
+
size?: number;
|
|
153
|
+
}
|
|
154
|
+
interface WriteResult {
|
|
155
|
+
key: string;
|
|
156
|
+
size: number;
|
|
157
|
+
e_tag?: string;
|
|
158
|
+
}
|
|
159
|
+
type Theme = 'light' | 'dark' | 'system';
|
|
160
|
+
|
|
161
|
+
/** A single page of listing results with optional continuation. */
|
|
162
|
+
interface ListPage {
|
|
163
|
+
entries: FileEntry[];
|
|
164
|
+
continuationToken?: string;
|
|
165
|
+
hasMore: boolean;
|
|
166
|
+
}
|
|
167
|
+
interface StorageAdapter {
|
|
168
|
+
list(path: string, signal?: AbortSignal): Promise<FileEntry[]>;
|
|
169
|
+
read(path: string, offset?: number, length?: number, signal?: AbortSignal): Promise<Uint8Array>;
|
|
170
|
+
head(path: string, signal?: AbortSignal): Promise<FileEntry>;
|
|
171
|
+
/** Fetch a single page of listing results. Supports progressive rendering. */
|
|
172
|
+
listPage?(path: string, continuationToken?: string, pageSize?: number, signal?: AbortSignal): Promise<ListPage>;
|
|
173
|
+
put(key: string, data: Uint8Array, contentType?: string): Promise<WriteResult>;
|
|
174
|
+
delete(key: string): Promise<void>;
|
|
175
|
+
deletePrefix(prefix: string): Promise<{
|
|
176
|
+
deleted: number;
|
|
177
|
+
}>;
|
|
178
|
+
copy(srcKey: string, destKey: string): Promise<WriteResult>;
|
|
179
|
+
readonly supportsWrite: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Minimal adapter for direct HTTPS URLs (source: 'url').
|
|
184
|
+
* Only supports read/head — no listing or writing.
|
|
185
|
+
* The `path` parameter is the full HTTPS URL.
|
|
186
|
+
*/
|
|
187
|
+
declare class UrlAdapter implements StorageAdapter {
|
|
188
|
+
readonly supportsWrite = false;
|
|
189
|
+
read(url: string, offset?: number, length?: number, signal?: AbortSignal): Promise<Uint8Array>;
|
|
190
|
+
head(url: string, signal?: AbortSignal): Promise<FileEntry>;
|
|
191
|
+
list(): Promise<FileEntry[]>;
|
|
192
|
+
put(): Promise<WriteResult>;
|
|
193
|
+
delete(): Promise<void>;
|
|
194
|
+
deletePrefix(): Promise<{
|
|
195
|
+
deleted: number;
|
|
196
|
+
}>;
|
|
197
|
+
copy(): Promise<WriteResult>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type TypeCategory = 'number' | 'string' | 'date' | 'boolean' | 'geo' | 'binary' | 'json' | 'other';
|
|
201
|
+
declare function classifyType(duckdbType: string): TypeCategory;
|
|
202
|
+
declare function typeColor(category: TypeCategory): string;
|
|
203
|
+
declare function typeBadgeClass(category: TypeCategory): string;
|
|
204
|
+
declare function typeLabel(category: TypeCategory): string;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Formats a byte count into a human-readable string.
|
|
208
|
+
*/
|
|
209
|
+
declare function formatFileSize(bytes: number): string;
|
|
210
|
+
/**
|
|
211
|
+
* Formats a unix timestamp (milliseconds) to a human-readable date string.
|
|
212
|
+
* Shows relative time for recent dates, absolute for older ones.
|
|
213
|
+
*/
|
|
214
|
+
declare function formatDate(timestamp: number): string;
|
|
215
|
+
/**
|
|
216
|
+
* Extracts the file extension from a filename, including the leading dot.
|
|
217
|
+
* Returns an empty string if no extension is found.
|
|
218
|
+
*/
|
|
219
|
+
declare function getFileExtension(filename: string): string;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Direct WKB → GeoArrow bridge (zero-copy).
|
|
223
|
+
*
|
|
224
|
+
* Reads raw WKB binary directly into pre-allocated Arrow typed arrays
|
|
225
|
+
* without any intermediate JS object allocation. No parseWKB(), no GeoJSON.
|
|
226
|
+
*
|
|
227
|
+
* Data flow: WKB Uint8Array[] → DataView binary reads → Float64Array/Int32Array
|
|
228
|
+
* → arrow.makeData() → arrow.Table with ARROW:extension:name metadata
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
type GeoArrowGeomType = 'point' | 'linestring' | 'polygon' | 'multipoint' | 'multilinestring' | 'multipolygon';
|
|
232
|
+
interface GeoArrowResult {
|
|
233
|
+
table: Table;
|
|
234
|
+
geometryType: GeoArrowGeomType;
|
|
235
|
+
bounds: [number, number, number, number];
|
|
236
|
+
/** Maps local table row index → original WKB array index (for selection lookup). */
|
|
237
|
+
sourceIndices: number[];
|
|
238
|
+
}
|
|
239
|
+
/** Map DuckDB ST_GeometryType output to our normalized type. */
|
|
240
|
+
declare function normalizeGeomType(raw: string): GeoArrowGeomType;
|
|
241
|
+
/**
|
|
242
|
+
* Build GeoArrow tables from raw WKB arrays, automatically splitting by geometry type.
|
|
243
|
+
* Returns one GeoArrowResult per non-empty type group, with shared merged bounds.
|
|
244
|
+
*
|
|
245
|
+
* @param wkbArrays Raw WKB binary arrays from DuckDB
|
|
246
|
+
* @param attributes Attribute columns (non-geometry)
|
|
247
|
+
* @param knownGeomType If provided (e.g. from GeoParquet metadata), skip classification
|
|
248
|
+
*/
|
|
249
|
+
declare function buildGeoArrowTables(wkbArrays: Uint8Array[], attributes: Map<string, {
|
|
250
|
+
values: any[];
|
|
251
|
+
type: string;
|
|
252
|
+
}>, knownGeomType?: GeoArrowGeomType): GeoArrowResult[];
|
|
253
|
+
|
|
254
|
+
interface HexRow {
|
|
255
|
+
offset: string;
|
|
256
|
+
hex: string[];
|
|
257
|
+
ascii: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Generates a hex dump from binary data.
|
|
261
|
+
* Returns rows of offset | hex bytes | ASCII representation.
|
|
262
|
+
*/
|
|
263
|
+
declare function generateHexDump(data: Uint8Array, bytesPerRow?: number): HexRow[];
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Lightweight Parquet metadata reader using hyparquet.
|
|
267
|
+
*
|
|
268
|
+
* Reads schema, row count, CRS, and geometry types from the Parquet footer
|
|
269
|
+
* via a single HTTP range request (~512KB). No DuckDB boot needed.
|
|
270
|
+
*
|
|
271
|
+
* This provides instant metadata display before DuckDB-WASM finishes loading.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
interface GeoColumnMeta {
|
|
275
|
+
encoding: string;
|
|
276
|
+
geometryTypes: string[];
|
|
277
|
+
crs: any | null;
|
|
278
|
+
bbox?: number[];
|
|
279
|
+
}
|
|
280
|
+
interface GeoParquetMeta {
|
|
281
|
+
primaryColumn: string;
|
|
282
|
+
columns: Record<string, GeoColumnMeta>;
|
|
283
|
+
}
|
|
284
|
+
interface ParquetFileMetadata {
|
|
285
|
+
/** Total number of rows across all row groups. */
|
|
286
|
+
rowCount: number;
|
|
287
|
+
/** Column schema (name + type). */
|
|
288
|
+
schema: {
|
|
289
|
+
name: string;
|
|
290
|
+
type: string;
|
|
291
|
+
}[];
|
|
292
|
+
/** GeoParquet "geo" metadata if present. */
|
|
293
|
+
geo: GeoParquetMeta | null;
|
|
294
|
+
/** True when file has legacy GeoParquet metadata (schema_version 0.x without "version" field). */
|
|
295
|
+
legacyGeoParquet: boolean;
|
|
296
|
+
/** Tool that created the file (e.g. "pyarrow 15.0.0"). */
|
|
297
|
+
createdBy: string | null;
|
|
298
|
+
/** Number of row groups. */
|
|
299
|
+
numRowGroups: number;
|
|
300
|
+
/** Primary compression codec (e.g. "SNAPPY", "ZSTD"). */
|
|
301
|
+
compression: string | null;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Read Parquet footer metadata from a remote URL using hyparquet.
|
|
305
|
+
* Uses HTTP range requests — typically a single ~512KB fetch.
|
|
306
|
+
*/
|
|
307
|
+
declare function readParquetMetadata(url: string): Promise<ParquetFileMetadata>;
|
|
308
|
+
/**
|
|
309
|
+
* Extract EPSG code from GeoParquet CRS metadata.
|
|
310
|
+
* Returns null for WGS84/CRS84 (no reprojection needed).
|
|
311
|
+
*/
|
|
312
|
+
declare function extractEpsgFromGeoMeta(geo: GeoParquetMeta): string | null;
|
|
313
|
+
/**
|
|
314
|
+
* Extract normalized geometry types from GeoParquet metadata.
|
|
315
|
+
* Returns the set of geometry types for the primary column.
|
|
316
|
+
*/
|
|
317
|
+
declare function extractGeometryTypes(geo: GeoParquetMeta): GeoArrowGeomType[];
|
|
318
|
+
/**
|
|
319
|
+
* Extract bounds from GeoParquet metadata (bbox field).
|
|
320
|
+
* Returns [minX, minY, maxX, maxY] or null.
|
|
321
|
+
*/
|
|
322
|
+
declare function extractBounds(geo: GeoParquetMeta): [number, number, number, number] | null;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Universal cloud storage URL / bucket parser.
|
|
326
|
+
*
|
|
327
|
+
* Accepts the many URI/URL formats that users commonly paste and extracts
|
|
328
|
+
* the correct bucket, region, endpoint, and provider.
|
|
329
|
+
*
|
|
330
|
+
* Supported URI schemes:
|
|
331
|
+
* s3:// s3a:// s3n:// aws:// — Amazon S3 / S3-compatible
|
|
332
|
+
* r2:// — Cloudflare R2
|
|
333
|
+
* gs:// gcs:// — Google Cloud Storage
|
|
334
|
+
* azure:// az:// — Azure Blob Storage
|
|
335
|
+
* abfs:// abfss:// — Azure Data Lake (ADLS Gen2)
|
|
336
|
+
* wasbs:// — Azure Blob (Hadoop WASB driver)
|
|
337
|
+
* swift:// — OpenStack Swift
|
|
338
|
+
* file:// filesystem:// — Local filesystem
|
|
339
|
+
*
|
|
340
|
+
* Supported HTTPS URL patterns:
|
|
341
|
+
* https://<bucket>.s3.<region>.amazonaws.com[/prefix] — AWS virtual-hosted
|
|
342
|
+
* https://s3.<region>.amazonaws.com/<bucket>[/prefix] — AWS path-style
|
|
343
|
+
* https://s3.amazonaws.com/<bucket> — AWS global
|
|
344
|
+
* https://<account>.r2.cloudflarestorage.com/<bucket> — Cloudflare R2
|
|
345
|
+
* https://storage.googleapis.com/<bucket> — Google Cloud Storage
|
|
346
|
+
* https://<bucket>.storage.googleapis.com[/prefix] — GCS virtual-hosted
|
|
347
|
+
* https://<bucket>.<region>.digitaloceanspaces.com — DigitalOcean Spaces
|
|
348
|
+
* https://<region>.digitaloceanspaces.com/<bucket> — DO Spaces path-style
|
|
349
|
+
* https://s3.<region>.wasabisys.com/<bucket> — Wasabi
|
|
350
|
+
* https://f<id>.backblazeb2.com/file/<bucket> — Backblaze B2
|
|
351
|
+
* https://<bucket>.s3.<region>.backblazeb2.com — B2 S3-compatible
|
|
352
|
+
* https://<bucket>.oss-<region>.aliyuncs.com — Alibaba Cloud OSS
|
|
353
|
+
* https://<bucket>.cos.<region>.myqcloud.com — Tencent COS
|
|
354
|
+
* https://storage.yandexcloud.net/<bucket> — Yandex Cloud
|
|
355
|
+
* https://gateway.storjshare.io/<bucket> — Storj S3 gateway
|
|
356
|
+
* https://link.storjshare.io/raw/<access>/<bucket> — Storj linksharing
|
|
357
|
+
* https://<custom-endpoint>/<bucket> — Generic S3-compatible
|
|
358
|
+
*
|
|
359
|
+
* Also handles plain bucket names (no protocol).
|
|
360
|
+
*/
|
|
361
|
+
type StorageProvider = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'unknown';
|
|
362
|
+
interface ParsedStorageUrl {
|
|
363
|
+
bucket: string;
|
|
364
|
+
region: string;
|
|
365
|
+
endpoint: string;
|
|
366
|
+
provider: StorageProvider;
|
|
367
|
+
/** Original prefix/path after bucket, if any */
|
|
368
|
+
prefix: string;
|
|
369
|
+
}
|
|
370
|
+
interface Defaults {
|
|
371
|
+
region?: string;
|
|
372
|
+
endpoint?: string;
|
|
373
|
+
provider?: StorageProvider;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Parse a user-provided bucket/URL string into structured storage connection parts.
|
|
377
|
+
*/
|
|
378
|
+
declare function parseStorageUrl(input: string, defaults?: Defaults): ParsedStorageUrl;
|
|
379
|
+
/**
|
|
380
|
+
* Returns true if the input looks like a URL/URI rather than a plain bucket name.
|
|
381
|
+
* Covers all recognized cloud storage URI schemes.
|
|
382
|
+
*/
|
|
383
|
+
declare function looksLikeUrl(input: string): boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Given a parsed URL result, build a human-readable summary of what was detected.
|
|
386
|
+
*/
|
|
387
|
+
declare function describeParseResult(parsed: ParsedStorageUrl): string;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Lightweight WKB (Well-Known Binary) parser for extracting coordinates.
|
|
391
|
+
* Supports Point, LineString, Polygon, and Multi* variants.
|
|
392
|
+
* Handles standard WKB, ISO WKB (with Z/M), and EWKB (PostGIS SRID).
|
|
393
|
+
*/
|
|
394
|
+
type GeoType = 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'Unknown';
|
|
395
|
+
interface ParsedGeometry {
|
|
396
|
+
type: GeoType;
|
|
397
|
+
coordinates: number[] | number[][] | number[][][] | number[][][][];
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Normalize binary data from various formats to Uint8Array.
|
|
401
|
+
* Handles Uint8Array, ArrayBuffer, number arrays, hex strings,
|
|
402
|
+
* and DuckDB toJSON() blob objects ({0: byte, 1: byte, ...}).
|
|
403
|
+
*/
|
|
404
|
+
declare function toBinary(value: unknown): Uint8Array | null;
|
|
405
|
+
/**
|
|
406
|
+
* Parse a WKB binary blob into coordinates and geometry type.
|
|
407
|
+
*/
|
|
408
|
+
declare function parseWKB(data: Uint8Array): ParsedGeometry | null;
|
|
409
|
+
/**
|
|
410
|
+
* Find the geometry column name from a schema.
|
|
411
|
+
*
|
|
412
|
+
* Detection priority:
|
|
413
|
+
* 1. Column type contains a geometry keyword (GEOMETRY, POINT, WKB, etc.)
|
|
414
|
+
* 2. Exact well-known column name with BLOB/BINARY type
|
|
415
|
+
* 3. Exact well-known column name regardless of type
|
|
416
|
+
* 4. Column name contains a geo-related substring with BLOB/BINARY type
|
|
417
|
+
* 5. Column name contains a geo-related substring regardless of type
|
|
418
|
+
*/
|
|
419
|
+
declare function findGeoColumn(schema: {
|
|
420
|
+
name: string;
|
|
421
|
+
type: string;
|
|
422
|
+
}[]): string | null;
|
|
423
|
+
/**
|
|
424
|
+
* Fallback: probe actual row data to find a column containing WKB geometry.
|
|
425
|
+
* Use this when schema-only detection via `findGeoColumn()` returns null.
|
|
426
|
+
* Samples the first row and checks each BLOB/binary column for WKB magic bytes.
|
|
427
|
+
*/
|
|
428
|
+
declare function findGeoColumnFromRows(rows: Record<string, unknown>[], schema: {
|
|
429
|
+
name: string;
|
|
430
|
+
type: string;
|
|
431
|
+
}[]): string | null;
|
|
432
|
+
|
|
433
|
+
export { type Connection, type ConnectionConfig, type Defaults, type DuckDbReadFn, type FileCategory, type FileEntry, type FileTypeInfo, type GeoArrowGeomType, type GeoArrowResult, type GeoColumnMeta, type GeoParquetMeta, type GeoType, type HexRow, type ListPage, type MapQueryHandle, type MapQueryResult, type ParquetFileMetadata, type ParsedGeometry, type ParsedStorageUrl, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, type SchemaField, type StorageAdapter, type StorageProvider, type Tab, type Theme, type TypeCategory, UrlAdapter, type ViewerKind, type WriteResult, buildDuckDbSource, buildGeoArrowTables, classifyType, describeParseResult, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getViewerKind, isCloudNativeFormat, isQueryable, looksLikeUrl, normalizeGeomType, parseStorageUrl, parseWKB, readParquetMetadata, toBinary, typeBadgeClass, typeColor, typeLabel };
|