@walkthru-earth/objex-utils 0.1.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,34 @@
1
1
  import { Table } from 'apache-arrow';
2
2
 
3
+ /**
4
+ * Shared constants used across the application.
5
+ * Centralizes magic strings, numbers, and sets to prevent duplication.
6
+ */
7
+ declare const STORAGE_KEYS: {
8
+ readonly SETTINGS: "obstore-explore-settings";
9
+ readonly CONNECTIONS: "obstore-explore-connections";
10
+ readonly QUERY_HISTORY: "obstore-explore-query-history";
11
+ };
12
+ /** EPSG codes considered WGS84 (no reprojection needed). */
13
+ declare const WGS84_CODES: Set<number>;
14
+ /** Default target CRS for ST_Transform. */
15
+ declare const DEFAULT_TARGET_CRS = "EPSG:4326";
16
+ /** DuckDB-WASM initialization timeout in ms. */
17
+ declare const DUCKDB_INIT_TIMEOUT_MS = 30000;
18
+ /** Maximum entries kept in query history. */
19
+ declare const MAX_QUERY_HISTORY_ENTRIES = 200;
20
+ /** SQL preview truncation length (characters). */
21
+ declare const SQL_PREVIEW_LENGTH = 120;
22
+ /** Extensions that represent "virtual files" — directories that open as viewers. */
23
+ declare const VIEWER_DIR_EXTENSIONS: Set<string>;
24
+ /**
25
+ * Golden-angle-based hue multiplier for evenly distributing layer colors.
26
+ * 137 ≈ 360 × (1 − 1/φ) where φ is the golden ratio.
27
+ */
28
+ declare const LAYER_HUE_MULTIPLIER = 137;
29
+ /** Duration (ms) to show "Copied!" feedback before resetting. */
30
+ declare const COPY_FEEDBACK_MS = 2000;
31
+
3
32
  /**
4
33
  * Centralized file type detection module.
5
34
  *
@@ -121,7 +150,7 @@ interface FileEntry {
121
150
  interface Connection {
122
151
  id: string;
123
152
  name: string;
124
- provider: 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj';
153
+ provider: string;
125
154
  endpoint: string;
126
155
  bucket: string;
127
156
  region: string;
@@ -131,7 +160,7 @@ interface Connection {
131
160
  }
132
161
  interface ConnectionConfig {
133
162
  name: string;
134
- provider: 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj';
163
+ provider: string;
135
164
  endpoint: string;
136
165
  bucket: string;
137
166
  region: string;
@@ -179,6 +208,60 @@ interface StorageAdapter {
179
208
  readonly supportsWrite: boolean;
180
209
  }
181
210
 
211
+ /**
212
+ * Provider registry — single source of truth for all cloud storage providers.
213
+ *
214
+ * Centralizes endpoint patterns, regions, auth methods, and UI metadata.
215
+ * Used by ConnectionDialog, browser-cloud adapter, host-detection, url-state, etc.
216
+ */
217
+ type ProviderId = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'b2' | 'digitalocean' | 'wasabi' | 'contabo' | 'hetzner' | 'linode' | 'ovhcloud';
218
+ interface ProviderRegion {
219
+ code: string;
220
+ label: string;
221
+ }
222
+ interface ProviderDef {
223
+ /** Display label in the UI. */
224
+ label: string;
225
+ /** Short description shown as helper text. */
226
+ description: string;
227
+ /** Auth method used by this provider. */
228
+ authMethod: 'sigv4' | 'sas-token';
229
+ /** Whether the region field is relevant for this provider. */
230
+ needsRegion: boolean;
231
+ /** Whether the endpoint field is required. */
232
+ needsEndpoint: boolean;
233
+ /** Default region when creating a new connection. */
234
+ defaultRegion: string;
235
+ /**
236
+ * Endpoint template with `{region}` placeholder.
237
+ * If null, the user must provide a custom endpoint (e.g. MinIO).
238
+ * If a fixed string (no `{region}`), it's always the same (e.g. GCS).
239
+ */
240
+ endpointTemplate: string | null;
241
+ /** Known regions with labels. Empty = free-form region input. */
242
+ regions: ProviderRegion[];
243
+ /** Bucket label override (e.g. Azure uses "Container"). */
244
+ bucketLabel?: string;
245
+ /** Default endpoint placeholder shown in the input. */
246
+ endpointPlaceholder: string;
247
+ /** URI schemes that map to this provider (lowercase, without "://"). */
248
+ schemes: string[];
249
+ }
250
+ declare const PROVIDERS: Record<ProviderId, ProviderDef>;
251
+ /** All provider IDs, ordered for the UI. */
252
+ declare const PROVIDER_IDS: ProviderId[];
253
+ /** Get provider def, falling back to S3 for unknown. */
254
+ declare function getProvider(id: string): ProviderDef;
255
+ /** Build endpoint URL from template + region. */
256
+ declare function buildEndpointFromTemplate(id: ProviderId, region: string): string;
257
+ /**
258
+ * Build the base URL for API requests (endpoint + bucket).
259
+ * Used by browser-cloud adapter and url-state.
260
+ */
261
+ declare function buildProviderBaseUrl(provider: ProviderId, endpoint: string, bucket: string, region: string): string;
262
+ /** Check if a provider uses the GCS JSON API (not S3 XML). */
263
+ declare function isGcsProvider(provider: string, endpoint: string): boolean;
264
+
182
265
  /**
183
266
  * Minimal adapter for direct HTTPS URLs (source: 'url').
184
267
  * Only supports read/head — no listing or writing.
@@ -197,12 +280,85 @@ declare class UrlAdapter implements StorageAdapter {
197
280
  copy(): Promise<WriteResult>;
198
281
  }
199
282
 
283
+ /**
284
+ * Cloud storage protocol URL utilities — pure TS, no Svelte dependency.
285
+ *
286
+ * Converts cloud protocol URLs (s3://, gs://) to HTTPS URLs for browser access.
287
+ * Provider-aware native scheme lookup.
288
+ */
289
+ /**
290
+ * Map provider to its native URI scheme prefix.
291
+ * Derived from the registry's `schemes` array (first entry is the primary scheme).
292
+ * Falls back to 's3' for providers without a scheme (S3-compatible).
293
+ */
294
+ declare function getNativeScheme(provider: string): string;
295
+ /**
296
+ * Safely decode a percent-encoded URI component.
297
+ * Returns the original string if decoding fails (malformed sequences).
298
+ */
299
+ declare function safeDecodeURIComponent(s: string): string;
300
+ /**
301
+ * Convert a cloud storage protocol URL (s3://, gs://) to an HTTPS URL
302
+ * for browser access. Returns the original URL if already HTTP(S) or unknown.
303
+ *
304
+ * Supported:
305
+ * - `s3://bucket/key` → `https://s3.{region}.amazonaws.com/{bucket}/{key}`
306
+ * (region auto-detected from bucket name when possible)
307
+ * - `gs://bucket/key` → `https://storage.googleapis.com/{bucket}/{key}`
308
+ */
309
+ declare function resolveCloudUrl(url: string): string;
310
+
200
311
  type TypeCategory = 'number' | 'string' | 'date' | 'boolean' | 'geo' | 'binary' | 'json' | 'other';
201
312
  declare function classifyType(duckdbType: string): TypeCategory;
202
313
  declare function typeColor(category: TypeCategory): string;
203
314
  declare function typeBadgeClass(category: TypeCategory): string;
204
315
  declare function typeLabel(category: TypeCategory): string;
205
316
 
317
+ /**
318
+ * Shared error handling for async viewer load operations.
319
+ */
320
+ /**
321
+ * Extract an error message from an unknown caught value.
322
+ * Returns null for AbortError (caller should silently return).
323
+ */
324
+ declare function handleLoadError(err: unknown): string | null;
325
+
326
+ /**
327
+ * Escape a CSV field value per RFC 4180.
328
+ */
329
+ declare function escapeCsvField(value: string): string;
330
+ /**
331
+ * Serialize column/row data to a CSV string.
332
+ * Pure function — no browser APIs, works in Node.js.
333
+ */
334
+ declare function serializeToCsv(columns: string[], rows: Record<string, unknown>[]): string;
335
+ /**
336
+ * Serialize column/row data to a formatted JSON string.
337
+ * Pure function — no browser APIs, works in Node.js.
338
+ */
339
+ declare function serializeToJson(columns: string[], rows: Record<string, unknown>[]): string;
340
+
341
+ /**
342
+ * Pure file entry sorting — framework-agnostic, works in Node.js.
343
+ */
344
+
345
+ type SortField = 'name' | 'size' | 'modified' | 'extension';
346
+ type SortDirection = 'asc' | 'desc';
347
+ interface SortConfig {
348
+ field: SortField;
349
+ direction: SortDirection;
350
+ }
351
+ /**
352
+ * Sort file entries by the given config.
353
+ * Directories always sort before files regardless of sort field.
354
+ * Returns a new array (does not mutate the input).
355
+ */
356
+ declare function sortFileEntries(entries: FileEntry[], config: SortConfig): FileEntry[];
357
+ /**
358
+ * Toggle sort config: same field flips direction, new field starts ascending.
359
+ */
360
+ declare function toggleSortField(current: SortConfig, field: SortField): SortConfig;
361
+
206
362
  /**
207
363
  * Formats a byte count into a human-readable string.
208
364
  */
@@ -217,6 +373,16 @@ declare function formatDate(timestamp: number): string;
217
373
  * Returns an empty string if no extension is found.
218
374
  */
219
375
  declare function getFileExtension(filename: string): string;
376
+ /**
377
+ * JSON replacer that converts BigInt values to strings.
378
+ * Use with `JSON.stringify(value, jsonReplacerBigInt)`.
379
+ */
380
+ declare function jsonReplacerBigInt(_key: string, value: unknown): unknown;
381
+ /**
382
+ * Format a value for display in tables, attribute panels, and exports.
383
+ * Handles null, undefined, Date, BigInt, and objects uniformly.
384
+ */
385
+ declare function formatValue(value: unknown): string;
220
386
 
221
387
  /**
222
388
  * Direct WKB → GeoArrow bridge (zero-copy).
@@ -262,6 +428,54 @@ interface HexRow {
262
428
  */
263
429
  declare function generateHexDump(data: Uint8Array, bytesPerRow?: number): HexRow[];
264
430
 
431
+ /**
432
+ * Generic localStorage helpers with SSR safety.
433
+ *
434
+ * Used by connection, settings, and query-history stores to avoid
435
+ * repeating the same load/persist/try-catch/SSR-guard pattern.
436
+ */
437
+ /**
438
+ * Load a JSON value from localStorage.
439
+ * Returns `defaultValue` on SSR, missing key, or parse error.
440
+ */
441
+ declare function loadFromStorage<T>(key: string, defaultValue: T): T;
442
+ /**
443
+ * Persist a JSON-serializable value to localStorage.
444
+ * Silently no-ops on SSR or storage errors (quota, private browsing).
445
+ */
446
+ declare function persistToStorage(key: string, value: unknown): void;
447
+
448
+ interface SqlBlock {
449
+ name: string;
450
+ sql: string;
451
+ startLine: number;
452
+ endLine: number;
453
+ }
454
+ interface ParsedMarkdownDocument {
455
+ frontmatter: Record<string, any>;
456
+ content: string;
457
+ sqlBlocks: SqlBlock[];
458
+ }
459
+ /**
460
+ * Parse a markdown document with YAML frontmatter and SQL code blocks.
461
+ *
462
+ * Evidence-compatible syntax:
463
+ * ```sql query_name
464
+ * SELECT * FROM table
465
+ * ```
466
+ */
467
+ declare function parseMarkdownDocument(markdown: string): ParsedMarkdownDocument;
468
+ /**
469
+ * Interpolate template variables in markdown text.
470
+ * Supports {queryName.rows[0].columnName} syntax.
471
+ */
472
+ declare function interpolateTemplates(text: string, queryResults: Map<string, Record<string, any>[]>): string;
473
+ /**
474
+ * Replace SQL blocks in markdown content with placeholder markers
475
+ * that can be replaced with rendered components.
476
+ */
477
+ declare function markSqlBlocks(content: string): string;
478
+
265
479
  /**
266
480
  * Lightweight Parquet metadata reader using hyparquet.
267
481
  *
@@ -358,7 +572,7 @@ declare function extractBounds(geo: GeoParquetMeta): [number, number, number, nu
358
572
  *
359
573
  * Also handles plain bucket names (no protocol).
360
574
  */
361
- type StorageProvider = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'unknown';
575
+ type StorageProvider = string;
362
576
  interface ParsedStorageUrl {
363
577
  bucket: string;
364
578
  region: string;
@@ -430,4 +644,4 @@ declare function findGeoColumnFromRows(rows: Record<string, unknown>[], schema:
430
644
  type: string;
431
645
  }[]): string | null;
432
646
 
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 };
647
+ 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, PROVIDERS, PROVIDER_IDS, type ParquetFileMetadata, type ParsedGeometry, type ParsedMarkdownDocument, type ParsedStorageUrl, type ProviderDef, type ProviderId, type ProviderRegion, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, 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, buildDuckDbSource, buildEndpointFromTemplate, buildGeoArrowTables, buildProviderBaseUrl, 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, safeDecodeURIComponent, serializeToCsv, serializeToJson, sortFileEntries, toBinary, toggleSortField, typeBadgeClass, typeColor, typeLabel };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,34 @@
1
1
  import { Table } from 'apache-arrow';
2
2
 
3
+ /**
4
+ * Shared constants used across the application.
5
+ * Centralizes magic strings, numbers, and sets to prevent duplication.
6
+ */
7
+ declare const STORAGE_KEYS: {
8
+ readonly SETTINGS: "obstore-explore-settings";
9
+ readonly CONNECTIONS: "obstore-explore-connections";
10
+ readonly QUERY_HISTORY: "obstore-explore-query-history";
11
+ };
12
+ /** EPSG codes considered WGS84 (no reprojection needed). */
13
+ declare const WGS84_CODES: Set<number>;
14
+ /** Default target CRS for ST_Transform. */
15
+ declare const DEFAULT_TARGET_CRS = "EPSG:4326";
16
+ /** DuckDB-WASM initialization timeout in ms. */
17
+ declare const DUCKDB_INIT_TIMEOUT_MS = 30000;
18
+ /** Maximum entries kept in query history. */
19
+ declare const MAX_QUERY_HISTORY_ENTRIES = 200;
20
+ /** SQL preview truncation length (characters). */
21
+ declare const SQL_PREVIEW_LENGTH = 120;
22
+ /** Extensions that represent "virtual files" — directories that open as viewers. */
23
+ declare const VIEWER_DIR_EXTENSIONS: Set<string>;
24
+ /**
25
+ * Golden-angle-based hue multiplier for evenly distributing layer colors.
26
+ * 137 ≈ 360 × (1 − 1/φ) where φ is the golden ratio.
27
+ */
28
+ declare const LAYER_HUE_MULTIPLIER = 137;
29
+ /** Duration (ms) to show "Copied!" feedback before resetting. */
30
+ declare const COPY_FEEDBACK_MS = 2000;
31
+
3
32
  /**
4
33
  * Centralized file type detection module.
5
34
  *
@@ -121,7 +150,7 @@ interface FileEntry {
121
150
  interface Connection {
122
151
  id: string;
123
152
  name: string;
124
- provider: 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj';
153
+ provider: string;
125
154
  endpoint: string;
126
155
  bucket: string;
127
156
  region: string;
@@ -131,7 +160,7 @@ interface Connection {
131
160
  }
132
161
  interface ConnectionConfig {
133
162
  name: string;
134
- provider: 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj';
163
+ provider: string;
135
164
  endpoint: string;
136
165
  bucket: string;
137
166
  region: string;
@@ -179,6 +208,60 @@ interface StorageAdapter {
179
208
  readonly supportsWrite: boolean;
180
209
  }
181
210
 
211
+ /**
212
+ * Provider registry — single source of truth for all cloud storage providers.
213
+ *
214
+ * Centralizes endpoint patterns, regions, auth methods, and UI metadata.
215
+ * Used by ConnectionDialog, browser-cloud adapter, host-detection, url-state, etc.
216
+ */
217
+ type ProviderId = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'b2' | 'digitalocean' | 'wasabi' | 'contabo' | 'hetzner' | 'linode' | 'ovhcloud';
218
+ interface ProviderRegion {
219
+ code: string;
220
+ label: string;
221
+ }
222
+ interface ProviderDef {
223
+ /** Display label in the UI. */
224
+ label: string;
225
+ /** Short description shown as helper text. */
226
+ description: string;
227
+ /** Auth method used by this provider. */
228
+ authMethod: 'sigv4' | 'sas-token';
229
+ /** Whether the region field is relevant for this provider. */
230
+ needsRegion: boolean;
231
+ /** Whether the endpoint field is required. */
232
+ needsEndpoint: boolean;
233
+ /** Default region when creating a new connection. */
234
+ defaultRegion: string;
235
+ /**
236
+ * Endpoint template with `{region}` placeholder.
237
+ * If null, the user must provide a custom endpoint (e.g. MinIO).
238
+ * If a fixed string (no `{region}`), it's always the same (e.g. GCS).
239
+ */
240
+ endpointTemplate: string | null;
241
+ /** Known regions with labels. Empty = free-form region input. */
242
+ regions: ProviderRegion[];
243
+ /** Bucket label override (e.g. Azure uses "Container"). */
244
+ bucketLabel?: string;
245
+ /** Default endpoint placeholder shown in the input. */
246
+ endpointPlaceholder: string;
247
+ /** URI schemes that map to this provider (lowercase, without "://"). */
248
+ schemes: string[];
249
+ }
250
+ declare const PROVIDERS: Record<ProviderId, ProviderDef>;
251
+ /** All provider IDs, ordered for the UI. */
252
+ declare const PROVIDER_IDS: ProviderId[];
253
+ /** Get provider def, falling back to S3 for unknown. */
254
+ declare function getProvider(id: string): ProviderDef;
255
+ /** Build endpoint URL from template + region. */
256
+ declare function buildEndpointFromTemplate(id: ProviderId, region: string): string;
257
+ /**
258
+ * Build the base URL for API requests (endpoint + bucket).
259
+ * Used by browser-cloud adapter and url-state.
260
+ */
261
+ declare function buildProviderBaseUrl(provider: ProviderId, endpoint: string, bucket: string, region: string): string;
262
+ /** Check if a provider uses the GCS JSON API (not S3 XML). */
263
+ declare function isGcsProvider(provider: string, endpoint: string): boolean;
264
+
182
265
  /**
183
266
  * Minimal adapter for direct HTTPS URLs (source: 'url').
184
267
  * Only supports read/head — no listing or writing.
@@ -197,12 +280,85 @@ declare class UrlAdapter implements StorageAdapter {
197
280
  copy(): Promise<WriteResult>;
198
281
  }
199
282
 
283
+ /**
284
+ * Cloud storage protocol URL utilities — pure TS, no Svelte dependency.
285
+ *
286
+ * Converts cloud protocol URLs (s3://, gs://) to HTTPS URLs for browser access.
287
+ * Provider-aware native scheme lookup.
288
+ */
289
+ /**
290
+ * Map provider to its native URI scheme prefix.
291
+ * Derived from the registry's `schemes` array (first entry is the primary scheme).
292
+ * Falls back to 's3' for providers without a scheme (S3-compatible).
293
+ */
294
+ declare function getNativeScheme(provider: string): string;
295
+ /**
296
+ * Safely decode a percent-encoded URI component.
297
+ * Returns the original string if decoding fails (malformed sequences).
298
+ */
299
+ declare function safeDecodeURIComponent(s: string): string;
300
+ /**
301
+ * Convert a cloud storage protocol URL (s3://, gs://) to an HTTPS URL
302
+ * for browser access. Returns the original URL if already HTTP(S) or unknown.
303
+ *
304
+ * Supported:
305
+ * - `s3://bucket/key` → `https://s3.{region}.amazonaws.com/{bucket}/{key}`
306
+ * (region auto-detected from bucket name when possible)
307
+ * - `gs://bucket/key` → `https://storage.googleapis.com/{bucket}/{key}`
308
+ */
309
+ declare function resolveCloudUrl(url: string): string;
310
+
200
311
  type TypeCategory = 'number' | 'string' | 'date' | 'boolean' | 'geo' | 'binary' | 'json' | 'other';
201
312
  declare function classifyType(duckdbType: string): TypeCategory;
202
313
  declare function typeColor(category: TypeCategory): string;
203
314
  declare function typeBadgeClass(category: TypeCategory): string;
204
315
  declare function typeLabel(category: TypeCategory): string;
205
316
 
317
+ /**
318
+ * Shared error handling for async viewer load operations.
319
+ */
320
+ /**
321
+ * Extract an error message from an unknown caught value.
322
+ * Returns null for AbortError (caller should silently return).
323
+ */
324
+ declare function handleLoadError(err: unknown): string | null;
325
+
326
+ /**
327
+ * Escape a CSV field value per RFC 4180.
328
+ */
329
+ declare function escapeCsvField(value: string): string;
330
+ /**
331
+ * Serialize column/row data to a CSV string.
332
+ * Pure function — no browser APIs, works in Node.js.
333
+ */
334
+ declare function serializeToCsv(columns: string[], rows: Record<string, unknown>[]): string;
335
+ /**
336
+ * Serialize column/row data to a formatted JSON string.
337
+ * Pure function — no browser APIs, works in Node.js.
338
+ */
339
+ declare function serializeToJson(columns: string[], rows: Record<string, unknown>[]): string;
340
+
341
+ /**
342
+ * Pure file entry sorting — framework-agnostic, works in Node.js.
343
+ */
344
+
345
+ type SortField = 'name' | 'size' | 'modified' | 'extension';
346
+ type SortDirection = 'asc' | 'desc';
347
+ interface SortConfig {
348
+ field: SortField;
349
+ direction: SortDirection;
350
+ }
351
+ /**
352
+ * Sort file entries by the given config.
353
+ * Directories always sort before files regardless of sort field.
354
+ * Returns a new array (does not mutate the input).
355
+ */
356
+ declare function sortFileEntries(entries: FileEntry[], config: SortConfig): FileEntry[];
357
+ /**
358
+ * Toggle sort config: same field flips direction, new field starts ascending.
359
+ */
360
+ declare function toggleSortField(current: SortConfig, field: SortField): SortConfig;
361
+
206
362
  /**
207
363
  * Formats a byte count into a human-readable string.
208
364
  */
@@ -217,6 +373,16 @@ declare function formatDate(timestamp: number): string;
217
373
  * Returns an empty string if no extension is found.
218
374
  */
219
375
  declare function getFileExtension(filename: string): string;
376
+ /**
377
+ * JSON replacer that converts BigInt values to strings.
378
+ * Use with `JSON.stringify(value, jsonReplacerBigInt)`.
379
+ */
380
+ declare function jsonReplacerBigInt(_key: string, value: unknown): unknown;
381
+ /**
382
+ * Format a value for display in tables, attribute panels, and exports.
383
+ * Handles null, undefined, Date, BigInt, and objects uniformly.
384
+ */
385
+ declare function formatValue(value: unknown): string;
220
386
 
221
387
  /**
222
388
  * Direct WKB → GeoArrow bridge (zero-copy).
@@ -262,6 +428,54 @@ interface HexRow {
262
428
  */
263
429
  declare function generateHexDump(data: Uint8Array, bytesPerRow?: number): HexRow[];
264
430
 
431
+ /**
432
+ * Generic localStorage helpers with SSR safety.
433
+ *
434
+ * Used by connection, settings, and query-history stores to avoid
435
+ * repeating the same load/persist/try-catch/SSR-guard pattern.
436
+ */
437
+ /**
438
+ * Load a JSON value from localStorage.
439
+ * Returns `defaultValue` on SSR, missing key, or parse error.
440
+ */
441
+ declare function loadFromStorage<T>(key: string, defaultValue: T): T;
442
+ /**
443
+ * Persist a JSON-serializable value to localStorage.
444
+ * Silently no-ops on SSR or storage errors (quota, private browsing).
445
+ */
446
+ declare function persistToStorage(key: string, value: unknown): void;
447
+
448
+ interface SqlBlock {
449
+ name: string;
450
+ sql: string;
451
+ startLine: number;
452
+ endLine: number;
453
+ }
454
+ interface ParsedMarkdownDocument {
455
+ frontmatter: Record<string, any>;
456
+ content: string;
457
+ sqlBlocks: SqlBlock[];
458
+ }
459
+ /**
460
+ * Parse a markdown document with YAML frontmatter and SQL code blocks.
461
+ *
462
+ * Evidence-compatible syntax:
463
+ * ```sql query_name
464
+ * SELECT * FROM table
465
+ * ```
466
+ */
467
+ declare function parseMarkdownDocument(markdown: string): ParsedMarkdownDocument;
468
+ /**
469
+ * Interpolate template variables in markdown text.
470
+ * Supports {queryName.rows[0].columnName} syntax.
471
+ */
472
+ declare function interpolateTemplates(text: string, queryResults: Map<string, Record<string, any>[]>): string;
473
+ /**
474
+ * Replace SQL blocks in markdown content with placeholder markers
475
+ * that can be replaced with rendered components.
476
+ */
477
+ declare function markSqlBlocks(content: string): string;
478
+
265
479
  /**
266
480
  * Lightweight Parquet metadata reader using hyparquet.
267
481
  *
@@ -358,7 +572,7 @@ declare function extractBounds(geo: GeoParquetMeta): [number, number, number, nu
358
572
  *
359
573
  * Also handles plain bucket names (no protocol).
360
574
  */
361
- type StorageProvider = 's3' | 'gcs' | 'r2' | 'minio' | 'azure' | 'storj' | 'unknown';
575
+ type StorageProvider = string;
362
576
  interface ParsedStorageUrl {
363
577
  bucket: string;
364
578
  region: string;
@@ -430,4 +644,4 @@ declare function findGeoColumnFromRows(rows: Record<string, unknown>[], schema:
430
644
  type: string;
431
645
  }[]): string | null;
432
646
 
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 };
647
+ 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, PROVIDERS, PROVIDER_IDS, type ParquetFileMetadata, type ParsedGeometry, type ParsedMarkdownDocument, type ParsedStorageUrl, type ProviderDef, type ProviderId, type ProviderRegion, QueryCancelledError, type QueryEngine, type QueryHandle, type QueryResult, 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, buildDuckDbSource, buildEndpointFromTemplate, buildGeoArrowTables, buildProviderBaseUrl, 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, safeDecodeURIComponent, serializeToCsv, serializeToJson, sortFileEntries, toBinary, toggleSortField, typeBadgeClass, typeColor, typeLabel };