@walkthru-earth/objex-utils 1.0.0 → 1.2.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 +99 -0
- package/dist/index.cjs +1224 -956
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +230 -7
- package/dist/index.d.ts +230 -7
- package/dist/index.js +1202 -957
- package/dist/index.js.map +1 -1
- package/docs/README.md +102 -0
- package/docs/cog.md +303 -0
- package/docs/errors.md +34 -0
- package/docs/file-sort.md +67 -0
- package/docs/file-types.md +141 -0
- package/docs/formatting.md +192 -0
- package/docs/geometry.md +198 -0
- package/docs/local-storage.md +51 -0
- package/docs/markdown-sql.md +109 -0
- package/docs/parquet-metadata.md +133 -0
- package/docs/query-engine.md +140 -0
- package/docs/storage.md +251 -0
- package/docs/types-constants.md +173 -0
- package/package.json +9 -3
package/dist/index.d.cts
CHANGED
|
@@ -11,8 +11,12 @@ declare const STORAGE_KEYS: {
|
|
|
11
11
|
};
|
|
12
12
|
/** EPSG codes considered WGS84 (no reprojection needed). */
|
|
13
13
|
declare const WGS84_CODES: Set<number>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Default target CRS for ST_Transform. Uses OGC:CRS84 (longitude, latitude)
|
|
16
|
+
* to match GeoParquet 1.1+ spec and DuckDB v1.5's canonical form.
|
|
17
|
+
* Functionally equivalent to EPSG:4326 under `geometry_always_xy = true`.
|
|
18
|
+
*/
|
|
19
|
+
declare const DEFAULT_TARGET_CRS = "OGC:CRS84";
|
|
16
20
|
/** DuckDB-WASM initialization timeout in ms. */
|
|
17
21
|
declare const DUCKDB_INIT_TIMEOUT_MS = 30000;
|
|
18
22
|
/** Maximum entries kept in query history. */
|
|
@@ -119,15 +123,27 @@ interface SchemaField {
|
|
|
119
123
|
type: string;
|
|
120
124
|
nullable: boolean;
|
|
121
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Abstraction over a DuckDB query source. Decouples schema / CRS / count
|
|
128
|
+
* helpers from assuming a file-backed path. `ref` is the FROM-clause target
|
|
129
|
+
* inserted into generated SQL (e.g. `read_parquet('url')` for files, or
|
|
130
|
+
* `attached_db."schema"."table"` for attached databases). `filePath` is
|
|
131
|
+
* optional and only used as a shortcut for Parquet file-level metadata
|
|
132
|
+
* queries (`parquet_kv_metadata`, `parquet_file_metadata`), not for SQL.
|
|
133
|
+
*/
|
|
134
|
+
interface QuerySource {
|
|
135
|
+
ref: string;
|
|
136
|
+
filePath?: string;
|
|
137
|
+
}
|
|
122
138
|
interface QueryEngine {
|
|
123
139
|
query(connId: string, sql: string): Promise<QueryResult>;
|
|
124
140
|
queryForMap(connId: string, sql: string, geomCol: string, geomColType: string, sourceCrs?: string | null): Promise<MapQueryResult>;
|
|
125
|
-
getSchema(connId: string,
|
|
126
|
-
getRowCount(connId: string,
|
|
141
|
+
getSchema(connId: string, source: QuerySource): Promise<SchemaField[]>;
|
|
142
|
+
getRowCount(connId: string, source: QuerySource): Promise<number>;
|
|
127
143
|
/** Detect CRS from GeoParquet metadata. Returns e.g. 'EPSG:27700' or null if WGS84/unknown. */
|
|
128
|
-
detectCrs(connId: string,
|
|
144
|
+
detectCrs(connId: string, source: QuerySource, geomCol: string): Promise<string | null>;
|
|
129
145
|
/** Combined schema + CRS detection in a single connection (fewer web worker round-trips). */
|
|
130
|
-
getSchemaAndCrs?(connId: string,
|
|
146
|
+
getSchemaAndCrs?(connId: string, source: QuerySource, findGeoCol: (schema: SchemaField[]) => string | null): Promise<{
|
|
131
147
|
schema: SchemaField[];
|
|
132
148
|
geomCol: string | null;
|
|
133
149
|
crs: string | null;
|
|
@@ -135,6 +151,10 @@ interface QueryEngine {
|
|
|
135
151
|
queryCancellable?(connId: string, sql: string): QueryHandle;
|
|
136
152
|
queryForMapCancellable?(connId: string, sql: string, geomCol: string, geomColType: string, sourceCrs?: string | null): MapQueryHandle;
|
|
137
153
|
forceCancel?(): Promise<void>;
|
|
154
|
+
/** Register a file buffer in DuckDB-WASM's virtual filesystem for ATTACH. */
|
|
155
|
+
registerFileBuffer?(name: string, buffer: Uint8Array): Promise<void>;
|
|
156
|
+
/** Drop a previously registered file from DuckDB-WASM's virtual filesystem. */
|
|
157
|
+
dropFile?(name: string): Promise<void>;
|
|
138
158
|
releaseMemory(): Promise<void>;
|
|
139
159
|
dispose(): Promise<void>;
|
|
140
160
|
}
|
|
@@ -179,6 +199,17 @@ interface Tab {
|
|
|
179
199
|
connectionId?: string;
|
|
180
200
|
extension: string;
|
|
181
201
|
size?: number;
|
|
202
|
+
/**
|
|
203
|
+
* When set, the tab reads data from a SQL FROM-clause target (e.g. an
|
|
204
|
+
* attached DuckLake/DuckDB/SQLite table) rather than a file URL. The ref
|
|
205
|
+
* is inserted directly into generated SQL, so it must be fully-qualified
|
|
206
|
+
* and pre-quoted, e.g. `__objex_db__."main"."air_quality"`.
|
|
207
|
+
*
|
|
208
|
+
* When `sourceRef` is set, file-specific loading paths (hyparquet
|
|
209
|
+
* metadata, `parquet_kv_metadata`, etc.) are skipped, and schema / CRS /
|
|
210
|
+
* row count are derived from the SQL source directly via DuckDB.
|
|
211
|
+
*/
|
|
212
|
+
sourceRef?: string;
|
|
182
213
|
}
|
|
183
214
|
interface WriteResult {
|
|
184
215
|
key: string;
|
|
@@ -208,6 +239,60 @@ interface StorageAdapter {
|
|
|
208
239
|
readonly supportsWrite: boolean;
|
|
209
240
|
}
|
|
210
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Provider registry — single source of truth for all cloud storage providers.
|
|
244
|
+
*
|
|
245
|
+
* Centralizes endpoint patterns, regions, auth methods, and UI metadata.
|
|
246
|
+
* Used by ConnectionDialog, browser-cloud adapter, host-detection, url-state, etc.
|
|
247
|
+
*/
|
|
248
|
+
type ProviderId = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'b2' | 'digitalocean' | 'wasabi' | 'contabo' | 'hetzner' | 'linode' | 'ovhcloud';
|
|
249
|
+
interface ProviderRegion {
|
|
250
|
+
code: string;
|
|
251
|
+
label: string;
|
|
252
|
+
}
|
|
253
|
+
interface ProviderDef {
|
|
254
|
+
/** Display label in the UI. */
|
|
255
|
+
label: string;
|
|
256
|
+
/** Short description shown as helper text. */
|
|
257
|
+
description: string;
|
|
258
|
+
/** Auth method used by this provider. */
|
|
259
|
+
authMethod: 'sigv4' | 'sas-token';
|
|
260
|
+
/** Whether the region field is relevant for this provider. */
|
|
261
|
+
needsRegion: boolean;
|
|
262
|
+
/** Whether the endpoint field is required. */
|
|
263
|
+
needsEndpoint: boolean;
|
|
264
|
+
/** Default region when creating a new connection. */
|
|
265
|
+
defaultRegion: string;
|
|
266
|
+
/**
|
|
267
|
+
* Endpoint template with `{region}` placeholder.
|
|
268
|
+
* If null, the user must provide a custom endpoint (e.g. MinIO).
|
|
269
|
+
* If a fixed string (no `{region}`), it's always the same (e.g. GCS).
|
|
270
|
+
*/
|
|
271
|
+
endpointTemplate: string | null;
|
|
272
|
+
/** Known regions with labels. Empty = free-form region input. */
|
|
273
|
+
regions: ProviderRegion[];
|
|
274
|
+
/** Bucket label override (e.g. Azure uses "Container"). */
|
|
275
|
+
bucketLabel?: string;
|
|
276
|
+
/** Default endpoint placeholder shown in the input. */
|
|
277
|
+
endpointPlaceholder: string;
|
|
278
|
+
/** URI schemes that map to this provider (lowercase, without "://"). */
|
|
279
|
+
schemes: string[];
|
|
280
|
+
}
|
|
281
|
+
declare const PROVIDERS: Record<ProviderId, ProviderDef>;
|
|
282
|
+
/** All provider IDs, ordered for the UI. */
|
|
283
|
+
declare const PROVIDER_IDS: ProviderId[];
|
|
284
|
+
/** Get provider def, falling back to S3 for unknown. */
|
|
285
|
+
declare function getProvider(id: string): ProviderDef;
|
|
286
|
+
/** Build endpoint URL from template + region. */
|
|
287
|
+
declare function buildEndpointFromTemplate(id: ProviderId, region: string): string;
|
|
288
|
+
/**
|
|
289
|
+
* Build the base URL for API requests (endpoint + bucket).
|
|
290
|
+
* Used by browser-cloud adapter and url-state.
|
|
291
|
+
*/
|
|
292
|
+
declare function buildProviderBaseUrl(provider: ProviderId, endpoint: string, bucket: string, region: string): string;
|
|
293
|
+
/** Check if a provider uses the GCS JSON API (not S3 XML). */
|
|
294
|
+
declare function isGcsProvider(provider: string, endpoint: string): boolean;
|
|
295
|
+
|
|
211
296
|
/**
|
|
212
297
|
* Minimal adapter for direct HTTPS URLs (source: 'url').
|
|
213
298
|
* Only supports read/head — no listing or writing.
|
|
@@ -226,6 +311,60 @@ declare class UrlAdapter implements StorageAdapter {
|
|
|
226
311
|
copy(): Promise<WriteResult>;
|
|
227
312
|
}
|
|
228
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Cloud storage protocol URL utilities — pure TS, no Svelte dependency.
|
|
316
|
+
*
|
|
317
|
+
* Converts cloud protocol URLs (s3://, gs://) to HTTPS URLs for browser access.
|
|
318
|
+
* Provider-aware native scheme lookup.
|
|
319
|
+
*/
|
|
320
|
+
/**
|
|
321
|
+
* Map provider to its native URI scheme prefix.
|
|
322
|
+
* Derived from the registry's `schemes` array (first entry is the primary scheme).
|
|
323
|
+
* Falls back to 's3' for providers without a scheme (S3-compatible).
|
|
324
|
+
*/
|
|
325
|
+
declare function getNativeScheme(provider: string): string;
|
|
326
|
+
/**
|
|
327
|
+
* Safely decode a percent-encoded URI component.
|
|
328
|
+
* Returns the original string if decoding fails (malformed sequences).
|
|
329
|
+
*/
|
|
330
|
+
declare function safeDecodeURIComponent(s: string): string;
|
|
331
|
+
/**
|
|
332
|
+
* Convert a cloud storage protocol URL (s3://, gs://) to an HTTPS URL
|
|
333
|
+
* for browser access. Returns the original URL if already HTTP(S) or unknown.
|
|
334
|
+
*
|
|
335
|
+
* Supported:
|
|
336
|
+
* - `s3://bucket/key` → `https://s3.{region}.amazonaws.com/{bucket}/{key}`
|
|
337
|
+
* (region auto-detected from bucket name when possible)
|
|
338
|
+
* - `gs://bucket/key` → `https://storage.googleapis.com/{bucket}/{key}`
|
|
339
|
+
*/
|
|
340
|
+
declare function resolveCloudUrl(url: string): string;
|
|
341
|
+
|
|
342
|
+
/** SampleFormat tag value → human label. */
|
|
343
|
+
declare const SF_LABELS: Record<number, string>;
|
|
344
|
+
interface GeoBounds {
|
|
345
|
+
west: number;
|
|
346
|
+
south: number;
|
|
347
|
+
east: number;
|
|
348
|
+
north: number;
|
|
349
|
+
}
|
|
350
|
+
interface CogInfo {
|
|
351
|
+
width: number;
|
|
352
|
+
height: number;
|
|
353
|
+
bandCount: number;
|
|
354
|
+
dataType: string;
|
|
355
|
+
bounds: GeoBounds;
|
|
356
|
+
downsampled?: boolean;
|
|
357
|
+
}
|
|
358
|
+
/** Safely clamp a number to a range, treating NaN/Infinity as the fallback. */
|
|
359
|
+
declare function safeClamp(v: number, lo: number, hi: number, fallback: number): number;
|
|
360
|
+
/** Clamp geographic bounds to valid MapLibre web-Mercator range. */
|
|
361
|
+
declare function clampBounds(b: GeoBounds): GeoBounds;
|
|
362
|
+
/**
|
|
363
|
+
* Build a data-type label from GeoTIFF sample format and bits per sample.
|
|
364
|
+
* e.g. "uint8", "float32", "int16"
|
|
365
|
+
*/
|
|
366
|
+
declare function buildDataTypeLabel(sampleFormat: number, bitsPerSample: number): string;
|
|
367
|
+
|
|
229
368
|
type TypeCategory = 'number' | 'string' | 'date' | 'boolean' | 'geo' | 'binary' | 'json' | 'other';
|
|
230
369
|
declare function classifyType(duckdbType: string): TypeCategory;
|
|
231
370
|
declare function typeColor(category: TypeCategory): string;
|
|
@@ -241,6 +380,42 @@ declare function typeLabel(category: TypeCategory): string;
|
|
|
241
380
|
*/
|
|
242
381
|
declare function handleLoadError(err: unknown): string | null;
|
|
243
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Escape a CSV field value per RFC 4180.
|
|
385
|
+
*/
|
|
386
|
+
declare function escapeCsvField(value: string): string;
|
|
387
|
+
/**
|
|
388
|
+
* Serialize column/row data to a CSV string.
|
|
389
|
+
* Pure function — no browser APIs, works in Node.js.
|
|
390
|
+
*/
|
|
391
|
+
declare function serializeToCsv(columns: string[], rows: Record<string, unknown>[]): string;
|
|
392
|
+
/**
|
|
393
|
+
* Serialize column/row data to a formatted JSON string.
|
|
394
|
+
* Pure function — no browser APIs, works in Node.js.
|
|
395
|
+
*/
|
|
396
|
+
declare function serializeToJson(columns: string[], rows: Record<string, unknown>[]): string;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Pure file entry sorting — framework-agnostic, works in Node.js.
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
type SortField = 'name' | 'size' | 'modified' | 'extension';
|
|
403
|
+
type SortDirection = 'asc' | 'desc';
|
|
404
|
+
interface SortConfig {
|
|
405
|
+
field: SortField;
|
|
406
|
+
direction: SortDirection;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Sort file entries by the given config.
|
|
410
|
+
* Directories always sort before files regardless of sort field.
|
|
411
|
+
* Returns a new array (does not mutate the input).
|
|
412
|
+
*/
|
|
413
|
+
declare function sortFileEntries(entries: FileEntry[], config: SortConfig): FileEntry[];
|
|
414
|
+
/**
|
|
415
|
+
* Toggle sort config: same field flips direction, new field starts ascending.
|
|
416
|
+
*/
|
|
417
|
+
declare function toggleSortField(current: SortConfig, field: SortField): SortConfig;
|
|
418
|
+
|
|
244
419
|
/**
|
|
245
420
|
* Formats a byte count into a human-readable string.
|
|
246
421
|
*/
|
|
@@ -310,6 +485,54 @@ interface HexRow {
|
|
|
310
485
|
*/
|
|
311
486
|
declare function generateHexDump(data: Uint8Array, bytesPerRow?: number): HexRow[];
|
|
312
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Generic localStorage helpers with SSR safety.
|
|
490
|
+
*
|
|
491
|
+
* Used by connection, settings, and query-history stores to avoid
|
|
492
|
+
* repeating the same load/persist/try-catch/SSR-guard pattern.
|
|
493
|
+
*/
|
|
494
|
+
/**
|
|
495
|
+
* Load a JSON value from localStorage.
|
|
496
|
+
* Returns `defaultValue` on SSR, missing key, or parse error.
|
|
497
|
+
*/
|
|
498
|
+
declare function loadFromStorage<T>(key: string, defaultValue: T): T;
|
|
499
|
+
/**
|
|
500
|
+
* Persist a JSON-serializable value to localStorage.
|
|
501
|
+
* Silently no-ops on SSR or storage errors (quota, private browsing).
|
|
502
|
+
*/
|
|
503
|
+
declare function persistToStorage(key: string, value: unknown): void;
|
|
504
|
+
|
|
505
|
+
interface SqlBlock {
|
|
506
|
+
name: string;
|
|
507
|
+
sql: string;
|
|
508
|
+
startLine: number;
|
|
509
|
+
endLine: number;
|
|
510
|
+
}
|
|
511
|
+
interface ParsedMarkdownDocument {
|
|
512
|
+
frontmatter: Record<string, any>;
|
|
513
|
+
content: string;
|
|
514
|
+
sqlBlocks: SqlBlock[];
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Parse a markdown document with YAML frontmatter and SQL code blocks.
|
|
518
|
+
*
|
|
519
|
+
* Evidence-compatible syntax:
|
|
520
|
+
* ```sql query_name
|
|
521
|
+
* SELECT * FROM table
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
declare function parseMarkdownDocument(markdown: string): Promise<ParsedMarkdownDocument>;
|
|
525
|
+
/**
|
|
526
|
+
* Interpolate template variables in markdown text.
|
|
527
|
+
* Supports {queryName.rows[0].columnName} syntax.
|
|
528
|
+
*/
|
|
529
|
+
declare function interpolateTemplates(text: string, queryResults: Map<string, Record<string, any>[]>): string;
|
|
530
|
+
/**
|
|
531
|
+
* Replace SQL blocks in markdown content with placeholder markers
|
|
532
|
+
* that can be replaced with rendered components.
|
|
533
|
+
*/
|
|
534
|
+
declare function markSqlBlocks(content: string): string;
|
|
535
|
+
|
|
313
536
|
/**
|
|
314
537
|
* Lightweight Parquet metadata reader using hyparquet.
|
|
315
538
|
*
|
|
@@ -478,4 +701,4 @@ declare function findGeoColumnFromRows(rows: Record<string, unknown>[], schema:
|
|
|
478
701
|
type: string;
|
|
479
702
|
}[]): string | null;
|
|
480
703
|
|
|
481
|
-
export { COPY_FEEDBACK_MS, type Connection, type ConnectionConfig, DEFAULT_TARGET_CRS, DUCKDB_INIT_TIMEOUT_MS, type Defaults, type DuckDbReadFn, type FileCategory, type FileEntry, type FileTypeInfo, type GeoArrowGeomType, type GeoArrowResult, type GeoColumnMeta, type GeoParquetMeta, type GeoType, type HexRow, LAYER_HUE_MULTIPLIER, type ListPage, MAX_QUERY_HISTORY_ENTRIES, type MapQueryHandle, type MapQueryResult, type ParquetFileMetadata, type ParsedGeometry, type ParsedStorageUrl, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, SQL_PREVIEW_LENGTH, STORAGE_KEYS, type SchemaField, type StorageAdapter, type StorageProvider, type Tab, type Theme, type TypeCategory, UrlAdapter, VIEWER_DIR_EXTENSIONS, type ViewerKind, WGS84_CODES, type WriteResult, buildDuckDbSource, buildGeoArrowTables, classifyType, describeParseResult, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, formatValue, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getViewerKind, handleLoadError, isCloudNativeFormat, isQueryable, jsonReplacerBigInt, looksLikeUrl, normalizeGeomType, parseStorageUrl, parseWKB, readParquetMetadata, toBinary, typeBadgeClass, typeColor, typeLabel };
|
|
704
|
+
export { COPY_FEEDBACK_MS, type CogInfo, type Connection, type ConnectionConfig, DEFAULT_TARGET_CRS, DUCKDB_INIT_TIMEOUT_MS, type Defaults, type DuckDbReadFn, type FileCategory, type FileEntry, type FileTypeInfo, type GeoArrowGeomType, type GeoArrowResult, type GeoBounds, type GeoColumnMeta, type GeoParquetMeta, type GeoType, type HexRow, LAYER_HUE_MULTIPLIER, type ListPage, MAX_QUERY_HISTORY_ENTRIES, type MapQueryHandle, type MapQueryResult, PROVIDERS, PROVIDER_IDS, type ParquetFileMetadata, type ParsedGeometry, type ParsedMarkdownDocument, type ParsedStorageUrl, type ProviderDef, type ProviderId, type ProviderRegion, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, SF_LABELS, SQL_PREVIEW_LENGTH, STORAGE_KEYS, type SchemaField, type SortConfig, type SortDirection, type SortField, type SqlBlock, type StorageAdapter, type StorageProvider, type Tab, type Theme, type TypeCategory, UrlAdapter, VIEWER_DIR_EXTENSIONS, type ViewerKind, WGS84_CODES, type WriteResult, buildDataTypeLabel, buildDuckDbSource, buildEndpointFromTemplate, buildGeoArrowTables, buildProviderBaseUrl, clampBounds, classifyType, describeParseResult, escapeCsvField, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, formatValue, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getNativeScheme, getProvider, getViewerKind, handleLoadError, interpolateTemplates, isCloudNativeFormat, isGcsProvider, isQueryable, jsonReplacerBigInt, loadFromStorage, looksLikeUrl, markSqlBlocks, normalizeGeomType, parseMarkdownDocument, parseStorageUrl, parseWKB, persistToStorage, readParquetMetadata, resolveCloudUrl, safeClamp, safeDecodeURIComponent, serializeToCsv, serializeToJson, sortFileEntries, toBinary, toggleSortField, typeBadgeClass, typeColor, typeLabel };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,12 @@ declare const STORAGE_KEYS: {
|
|
|
11
11
|
};
|
|
12
12
|
/** EPSG codes considered WGS84 (no reprojection needed). */
|
|
13
13
|
declare const WGS84_CODES: Set<number>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Default target CRS for ST_Transform. Uses OGC:CRS84 (longitude, latitude)
|
|
16
|
+
* to match GeoParquet 1.1+ spec and DuckDB v1.5's canonical form.
|
|
17
|
+
* Functionally equivalent to EPSG:4326 under `geometry_always_xy = true`.
|
|
18
|
+
*/
|
|
19
|
+
declare const DEFAULT_TARGET_CRS = "OGC:CRS84";
|
|
16
20
|
/** DuckDB-WASM initialization timeout in ms. */
|
|
17
21
|
declare const DUCKDB_INIT_TIMEOUT_MS = 30000;
|
|
18
22
|
/** Maximum entries kept in query history. */
|
|
@@ -119,15 +123,27 @@ interface SchemaField {
|
|
|
119
123
|
type: string;
|
|
120
124
|
nullable: boolean;
|
|
121
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Abstraction over a DuckDB query source. Decouples schema / CRS / count
|
|
128
|
+
* helpers from assuming a file-backed path. `ref` is the FROM-clause target
|
|
129
|
+
* inserted into generated SQL (e.g. `read_parquet('url')` for files, or
|
|
130
|
+
* `attached_db."schema"."table"` for attached databases). `filePath` is
|
|
131
|
+
* optional and only used as a shortcut for Parquet file-level metadata
|
|
132
|
+
* queries (`parquet_kv_metadata`, `parquet_file_metadata`), not for SQL.
|
|
133
|
+
*/
|
|
134
|
+
interface QuerySource {
|
|
135
|
+
ref: string;
|
|
136
|
+
filePath?: string;
|
|
137
|
+
}
|
|
122
138
|
interface QueryEngine {
|
|
123
139
|
query(connId: string, sql: string): Promise<QueryResult>;
|
|
124
140
|
queryForMap(connId: string, sql: string, geomCol: string, geomColType: string, sourceCrs?: string | null): Promise<MapQueryResult>;
|
|
125
|
-
getSchema(connId: string,
|
|
126
|
-
getRowCount(connId: string,
|
|
141
|
+
getSchema(connId: string, source: QuerySource): Promise<SchemaField[]>;
|
|
142
|
+
getRowCount(connId: string, source: QuerySource): Promise<number>;
|
|
127
143
|
/** Detect CRS from GeoParquet metadata. Returns e.g. 'EPSG:27700' or null if WGS84/unknown. */
|
|
128
|
-
detectCrs(connId: string,
|
|
144
|
+
detectCrs(connId: string, source: QuerySource, geomCol: string): Promise<string | null>;
|
|
129
145
|
/** Combined schema + CRS detection in a single connection (fewer web worker round-trips). */
|
|
130
|
-
getSchemaAndCrs?(connId: string,
|
|
146
|
+
getSchemaAndCrs?(connId: string, source: QuerySource, findGeoCol: (schema: SchemaField[]) => string | null): Promise<{
|
|
131
147
|
schema: SchemaField[];
|
|
132
148
|
geomCol: string | null;
|
|
133
149
|
crs: string | null;
|
|
@@ -135,6 +151,10 @@ interface QueryEngine {
|
|
|
135
151
|
queryCancellable?(connId: string, sql: string): QueryHandle;
|
|
136
152
|
queryForMapCancellable?(connId: string, sql: string, geomCol: string, geomColType: string, sourceCrs?: string | null): MapQueryHandle;
|
|
137
153
|
forceCancel?(): Promise<void>;
|
|
154
|
+
/** Register a file buffer in DuckDB-WASM's virtual filesystem for ATTACH. */
|
|
155
|
+
registerFileBuffer?(name: string, buffer: Uint8Array): Promise<void>;
|
|
156
|
+
/** Drop a previously registered file from DuckDB-WASM's virtual filesystem. */
|
|
157
|
+
dropFile?(name: string): Promise<void>;
|
|
138
158
|
releaseMemory(): Promise<void>;
|
|
139
159
|
dispose(): Promise<void>;
|
|
140
160
|
}
|
|
@@ -179,6 +199,17 @@ interface Tab {
|
|
|
179
199
|
connectionId?: string;
|
|
180
200
|
extension: string;
|
|
181
201
|
size?: number;
|
|
202
|
+
/**
|
|
203
|
+
* When set, the tab reads data from a SQL FROM-clause target (e.g. an
|
|
204
|
+
* attached DuckLake/DuckDB/SQLite table) rather than a file URL. The ref
|
|
205
|
+
* is inserted directly into generated SQL, so it must be fully-qualified
|
|
206
|
+
* and pre-quoted, e.g. `__objex_db__."main"."air_quality"`.
|
|
207
|
+
*
|
|
208
|
+
* When `sourceRef` is set, file-specific loading paths (hyparquet
|
|
209
|
+
* metadata, `parquet_kv_metadata`, etc.) are skipped, and schema / CRS /
|
|
210
|
+
* row count are derived from the SQL source directly via DuckDB.
|
|
211
|
+
*/
|
|
212
|
+
sourceRef?: string;
|
|
182
213
|
}
|
|
183
214
|
interface WriteResult {
|
|
184
215
|
key: string;
|
|
@@ -208,6 +239,60 @@ interface StorageAdapter {
|
|
|
208
239
|
readonly supportsWrite: boolean;
|
|
209
240
|
}
|
|
210
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Provider registry — single source of truth for all cloud storage providers.
|
|
244
|
+
*
|
|
245
|
+
* Centralizes endpoint patterns, regions, auth methods, and UI metadata.
|
|
246
|
+
* Used by ConnectionDialog, browser-cloud adapter, host-detection, url-state, etc.
|
|
247
|
+
*/
|
|
248
|
+
type ProviderId = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'b2' | 'digitalocean' | 'wasabi' | 'contabo' | 'hetzner' | 'linode' | 'ovhcloud';
|
|
249
|
+
interface ProviderRegion {
|
|
250
|
+
code: string;
|
|
251
|
+
label: string;
|
|
252
|
+
}
|
|
253
|
+
interface ProviderDef {
|
|
254
|
+
/** Display label in the UI. */
|
|
255
|
+
label: string;
|
|
256
|
+
/** Short description shown as helper text. */
|
|
257
|
+
description: string;
|
|
258
|
+
/** Auth method used by this provider. */
|
|
259
|
+
authMethod: 'sigv4' | 'sas-token';
|
|
260
|
+
/** Whether the region field is relevant for this provider. */
|
|
261
|
+
needsRegion: boolean;
|
|
262
|
+
/** Whether the endpoint field is required. */
|
|
263
|
+
needsEndpoint: boolean;
|
|
264
|
+
/** Default region when creating a new connection. */
|
|
265
|
+
defaultRegion: string;
|
|
266
|
+
/**
|
|
267
|
+
* Endpoint template with `{region}` placeholder.
|
|
268
|
+
* If null, the user must provide a custom endpoint (e.g. MinIO).
|
|
269
|
+
* If a fixed string (no `{region}`), it's always the same (e.g. GCS).
|
|
270
|
+
*/
|
|
271
|
+
endpointTemplate: string | null;
|
|
272
|
+
/** Known regions with labels. Empty = free-form region input. */
|
|
273
|
+
regions: ProviderRegion[];
|
|
274
|
+
/** Bucket label override (e.g. Azure uses "Container"). */
|
|
275
|
+
bucketLabel?: string;
|
|
276
|
+
/** Default endpoint placeholder shown in the input. */
|
|
277
|
+
endpointPlaceholder: string;
|
|
278
|
+
/** URI schemes that map to this provider (lowercase, without "://"). */
|
|
279
|
+
schemes: string[];
|
|
280
|
+
}
|
|
281
|
+
declare const PROVIDERS: Record<ProviderId, ProviderDef>;
|
|
282
|
+
/** All provider IDs, ordered for the UI. */
|
|
283
|
+
declare const PROVIDER_IDS: ProviderId[];
|
|
284
|
+
/** Get provider def, falling back to S3 for unknown. */
|
|
285
|
+
declare function getProvider(id: string): ProviderDef;
|
|
286
|
+
/** Build endpoint URL from template + region. */
|
|
287
|
+
declare function buildEndpointFromTemplate(id: ProviderId, region: string): string;
|
|
288
|
+
/**
|
|
289
|
+
* Build the base URL for API requests (endpoint + bucket).
|
|
290
|
+
* Used by browser-cloud adapter and url-state.
|
|
291
|
+
*/
|
|
292
|
+
declare function buildProviderBaseUrl(provider: ProviderId, endpoint: string, bucket: string, region: string): string;
|
|
293
|
+
/** Check if a provider uses the GCS JSON API (not S3 XML). */
|
|
294
|
+
declare function isGcsProvider(provider: string, endpoint: string): boolean;
|
|
295
|
+
|
|
211
296
|
/**
|
|
212
297
|
* Minimal adapter for direct HTTPS URLs (source: 'url').
|
|
213
298
|
* Only supports read/head — no listing or writing.
|
|
@@ -226,6 +311,60 @@ declare class UrlAdapter implements StorageAdapter {
|
|
|
226
311
|
copy(): Promise<WriteResult>;
|
|
227
312
|
}
|
|
228
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Cloud storage protocol URL utilities — pure TS, no Svelte dependency.
|
|
316
|
+
*
|
|
317
|
+
* Converts cloud protocol URLs (s3://, gs://) to HTTPS URLs for browser access.
|
|
318
|
+
* Provider-aware native scheme lookup.
|
|
319
|
+
*/
|
|
320
|
+
/**
|
|
321
|
+
* Map provider to its native URI scheme prefix.
|
|
322
|
+
* Derived from the registry's `schemes` array (first entry is the primary scheme).
|
|
323
|
+
* Falls back to 's3' for providers without a scheme (S3-compatible).
|
|
324
|
+
*/
|
|
325
|
+
declare function getNativeScheme(provider: string): string;
|
|
326
|
+
/**
|
|
327
|
+
* Safely decode a percent-encoded URI component.
|
|
328
|
+
* Returns the original string if decoding fails (malformed sequences).
|
|
329
|
+
*/
|
|
330
|
+
declare function safeDecodeURIComponent(s: string): string;
|
|
331
|
+
/**
|
|
332
|
+
* Convert a cloud storage protocol URL (s3://, gs://) to an HTTPS URL
|
|
333
|
+
* for browser access. Returns the original URL if already HTTP(S) or unknown.
|
|
334
|
+
*
|
|
335
|
+
* Supported:
|
|
336
|
+
* - `s3://bucket/key` → `https://s3.{region}.amazonaws.com/{bucket}/{key}`
|
|
337
|
+
* (region auto-detected from bucket name when possible)
|
|
338
|
+
* - `gs://bucket/key` → `https://storage.googleapis.com/{bucket}/{key}`
|
|
339
|
+
*/
|
|
340
|
+
declare function resolveCloudUrl(url: string): string;
|
|
341
|
+
|
|
342
|
+
/** SampleFormat tag value → human label. */
|
|
343
|
+
declare const SF_LABELS: Record<number, string>;
|
|
344
|
+
interface GeoBounds {
|
|
345
|
+
west: number;
|
|
346
|
+
south: number;
|
|
347
|
+
east: number;
|
|
348
|
+
north: number;
|
|
349
|
+
}
|
|
350
|
+
interface CogInfo {
|
|
351
|
+
width: number;
|
|
352
|
+
height: number;
|
|
353
|
+
bandCount: number;
|
|
354
|
+
dataType: string;
|
|
355
|
+
bounds: GeoBounds;
|
|
356
|
+
downsampled?: boolean;
|
|
357
|
+
}
|
|
358
|
+
/** Safely clamp a number to a range, treating NaN/Infinity as the fallback. */
|
|
359
|
+
declare function safeClamp(v: number, lo: number, hi: number, fallback: number): number;
|
|
360
|
+
/** Clamp geographic bounds to valid MapLibre web-Mercator range. */
|
|
361
|
+
declare function clampBounds(b: GeoBounds): GeoBounds;
|
|
362
|
+
/**
|
|
363
|
+
* Build a data-type label from GeoTIFF sample format and bits per sample.
|
|
364
|
+
* e.g. "uint8", "float32", "int16"
|
|
365
|
+
*/
|
|
366
|
+
declare function buildDataTypeLabel(sampleFormat: number, bitsPerSample: number): string;
|
|
367
|
+
|
|
229
368
|
type TypeCategory = 'number' | 'string' | 'date' | 'boolean' | 'geo' | 'binary' | 'json' | 'other';
|
|
230
369
|
declare function classifyType(duckdbType: string): TypeCategory;
|
|
231
370
|
declare function typeColor(category: TypeCategory): string;
|
|
@@ -241,6 +380,42 @@ declare function typeLabel(category: TypeCategory): string;
|
|
|
241
380
|
*/
|
|
242
381
|
declare function handleLoadError(err: unknown): string | null;
|
|
243
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Escape a CSV field value per RFC 4180.
|
|
385
|
+
*/
|
|
386
|
+
declare function escapeCsvField(value: string): string;
|
|
387
|
+
/**
|
|
388
|
+
* Serialize column/row data to a CSV string.
|
|
389
|
+
* Pure function — no browser APIs, works in Node.js.
|
|
390
|
+
*/
|
|
391
|
+
declare function serializeToCsv(columns: string[], rows: Record<string, unknown>[]): string;
|
|
392
|
+
/**
|
|
393
|
+
* Serialize column/row data to a formatted JSON string.
|
|
394
|
+
* Pure function — no browser APIs, works in Node.js.
|
|
395
|
+
*/
|
|
396
|
+
declare function serializeToJson(columns: string[], rows: Record<string, unknown>[]): string;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Pure file entry sorting — framework-agnostic, works in Node.js.
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
type SortField = 'name' | 'size' | 'modified' | 'extension';
|
|
403
|
+
type SortDirection = 'asc' | 'desc';
|
|
404
|
+
interface SortConfig {
|
|
405
|
+
field: SortField;
|
|
406
|
+
direction: SortDirection;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Sort file entries by the given config.
|
|
410
|
+
* Directories always sort before files regardless of sort field.
|
|
411
|
+
* Returns a new array (does not mutate the input).
|
|
412
|
+
*/
|
|
413
|
+
declare function sortFileEntries(entries: FileEntry[], config: SortConfig): FileEntry[];
|
|
414
|
+
/**
|
|
415
|
+
* Toggle sort config: same field flips direction, new field starts ascending.
|
|
416
|
+
*/
|
|
417
|
+
declare function toggleSortField(current: SortConfig, field: SortField): SortConfig;
|
|
418
|
+
|
|
244
419
|
/**
|
|
245
420
|
* Formats a byte count into a human-readable string.
|
|
246
421
|
*/
|
|
@@ -310,6 +485,54 @@ interface HexRow {
|
|
|
310
485
|
*/
|
|
311
486
|
declare function generateHexDump(data: Uint8Array, bytesPerRow?: number): HexRow[];
|
|
312
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Generic localStorage helpers with SSR safety.
|
|
490
|
+
*
|
|
491
|
+
* Used by connection, settings, and query-history stores to avoid
|
|
492
|
+
* repeating the same load/persist/try-catch/SSR-guard pattern.
|
|
493
|
+
*/
|
|
494
|
+
/**
|
|
495
|
+
* Load a JSON value from localStorage.
|
|
496
|
+
* Returns `defaultValue` on SSR, missing key, or parse error.
|
|
497
|
+
*/
|
|
498
|
+
declare function loadFromStorage<T>(key: string, defaultValue: T): T;
|
|
499
|
+
/**
|
|
500
|
+
* Persist a JSON-serializable value to localStorage.
|
|
501
|
+
* Silently no-ops on SSR or storage errors (quota, private browsing).
|
|
502
|
+
*/
|
|
503
|
+
declare function persistToStorage(key: string, value: unknown): void;
|
|
504
|
+
|
|
505
|
+
interface SqlBlock {
|
|
506
|
+
name: string;
|
|
507
|
+
sql: string;
|
|
508
|
+
startLine: number;
|
|
509
|
+
endLine: number;
|
|
510
|
+
}
|
|
511
|
+
interface ParsedMarkdownDocument {
|
|
512
|
+
frontmatter: Record<string, any>;
|
|
513
|
+
content: string;
|
|
514
|
+
sqlBlocks: SqlBlock[];
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Parse a markdown document with YAML frontmatter and SQL code blocks.
|
|
518
|
+
*
|
|
519
|
+
* Evidence-compatible syntax:
|
|
520
|
+
* ```sql query_name
|
|
521
|
+
* SELECT * FROM table
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
declare function parseMarkdownDocument(markdown: string): Promise<ParsedMarkdownDocument>;
|
|
525
|
+
/**
|
|
526
|
+
* Interpolate template variables in markdown text.
|
|
527
|
+
* Supports {queryName.rows[0].columnName} syntax.
|
|
528
|
+
*/
|
|
529
|
+
declare function interpolateTemplates(text: string, queryResults: Map<string, Record<string, any>[]>): string;
|
|
530
|
+
/**
|
|
531
|
+
* Replace SQL blocks in markdown content with placeholder markers
|
|
532
|
+
* that can be replaced with rendered components.
|
|
533
|
+
*/
|
|
534
|
+
declare function markSqlBlocks(content: string): string;
|
|
535
|
+
|
|
313
536
|
/**
|
|
314
537
|
* Lightweight Parquet metadata reader using hyparquet.
|
|
315
538
|
*
|
|
@@ -478,4 +701,4 @@ declare function findGeoColumnFromRows(rows: Record<string, unknown>[], schema:
|
|
|
478
701
|
type: string;
|
|
479
702
|
}[]): string | null;
|
|
480
703
|
|
|
481
|
-
export { COPY_FEEDBACK_MS, type Connection, type ConnectionConfig, DEFAULT_TARGET_CRS, DUCKDB_INIT_TIMEOUT_MS, type Defaults, type DuckDbReadFn, type FileCategory, type FileEntry, type FileTypeInfo, type GeoArrowGeomType, type GeoArrowResult, type GeoColumnMeta, type GeoParquetMeta, type GeoType, type HexRow, LAYER_HUE_MULTIPLIER, type ListPage, MAX_QUERY_HISTORY_ENTRIES, type MapQueryHandle, type MapQueryResult, type ParquetFileMetadata, type ParsedGeometry, type ParsedStorageUrl, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, SQL_PREVIEW_LENGTH, STORAGE_KEYS, type SchemaField, type StorageAdapter, type StorageProvider, type Tab, type Theme, type TypeCategory, UrlAdapter, VIEWER_DIR_EXTENSIONS, type ViewerKind, WGS84_CODES, type WriteResult, buildDuckDbSource, buildGeoArrowTables, classifyType, describeParseResult, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, formatValue, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getViewerKind, handleLoadError, isCloudNativeFormat, isQueryable, jsonReplacerBigInt, looksLikeUrl, normalizeGeomType, parseStorageUrl, parseWKB, readParquetMetadata, toBinary, typeBadgeClass, typeColor, typeLabel };
|
|
704
|
+
export { COPY_FEEDBACK_MS, type CogInfo, type Connection, type ConnectionConfig, DEFAULT_TARGET_CRS, DUCKDB_INIT_TIMEOUT_MS, type Defaults, type DuckDbReadFn, type FileCategory, type FileEntry, type FileTypeInfo, type GeoArrowGeomType, type GeoArrowResult, type GeoBounds, type GeoColumnMeta, type GeoParquetMeta, type GeoType, type HexRow, LAYER_HUE_MULTIPLIER, type ListPage, MAX_QUERY_HISTORY_ENTRIES, type MapQueryHandle, type MapQueryResult, PROVIDERS, PROVIDER_IDS, type ParquetFileMetadata, type ParsedGeometry, type ParsedMarkdownDocument, type ParsedStorageUrl, type ProviderDef, type ProviderId, type ProviderRegion, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, SF_LABELS, SQL_PREVIEW_LENGTH, STORAGE_KEYS, type SchemaField, type SortConfig, type SortDirection, type SortField, type SqlBlock, type StorageAdapter, type StorageProvider, type Tab, type Theme, type TypeCategory, UrlAdapter, VIEWER_DIR_EXTENSIONS, type ViewerKind, WGS84_CODES, type WriteResult, buildDataTypeLabel, buildDuckDbSource, buildEndpointFromTemplate, buildGeoArrowTables, buildProviderBaseUrl, clampBounds, classifyType, describeParseResult, escapeCsvField, extractBounds, extractEpsgFromGeoMeta, extractGeometryTypes, findGeoColumn, findGeoColumnFromRows, formatDate, formatFileSize, formatValue, generateHexDump, getDuckDbReadFn, getFileExtension, getFileTypeInfo, getMimeType, getNativeScheme, getProvider, getViewerKind, handleLoadError, interpolateTemplates, isCloudNativeFormat, isGcsProvider, isQueryable, jsonReplacerBigInt, loadFromStorage, looksLikeUrl, markSqlBlocks, normalizeGeomType, parseMarkdownDocument, parseStorageUrl, parseWKB, persistToStorage, readParquetMetadata, resolveCloudUrl, safeClamp, safeDecodeURIComponent, serializeToCsv, serializeToJson, sortFileEntries, toBinary, toggleSortField, typeBadgeClass, typeColor, typeLabel };
|