@loaders.gl/core 5.0.0-beta.5 → 5.0.0-beta.6

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.
Files changed (188) hide show
  1. package/dist/cluster-source.cjs +45 -1
  2. package/dist/cluster-source.cjs.map +1 -1
  3. package/dist/dist.min.js +2 -2
  4. package/dist/federated-table-scan-source.cjs +272 -201
  5. package/dist/federated-table-scan-source.cjs.map +3 -3
  6. package/dist/index.cjs +1 -1
  7. package/dist/lib/init.js +1 -1
  8. package/dist/loader-utils/index.cjs +233 -12
  9. package/dist/loader-utils/index.cjs.map +2 -2
  10. package/dist/loader-utils/index.d.ts +8 -4
  11. package/dist/loader-utils/index.d.ts.map +1 -1
  12. package/dist/loader-utils/index.js +3 -1
  13. package/dist/loader-utils/index.js.map +1 -1
  14. package/dist/loader-utils/json-loader.js +1 -1
  15. package/dist/loader-utils/lib/files/http-file-transport.d.ts +4 -0
  16. package/dist/loader-utils/lib/files/http-file-transport.d.ts.map +1 -1
  17. package/dist/loader-utils/lib/files/http-file-transport.js +45 -1
  18. package/dist/loader-utils/lib/files/http-file-transport.js.map +1 -1
  19. package/dist/loader-utils/lib/files/http-file-types.d.ts +2 -0
  20. package/dist/loader-utils/lib/files/http-file-types.d.ts.map +1 -1
  21. package/dist/loader-utils/lib/files/read-range-response.d.ts +3 -0
  22. package/dist/loader-utils/lib/files/read-range-response.d.ts.map +1 -0
  23. package/dist/loader-utils/lib/files/read-range-response.js +62 -0
  24. package/dist/loader-utils/lib/files/read-range-response.js.map +1 -0
  25. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  26. package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts +38 -0
  27. package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts.map +1 -0
  28. package/dist/loader-utils/lib/scan-utils/logical-table-query.js +96 -0
  29. package/dist/loader-utils/lib/scan-utils/logical-table-query.js.map +1 -0
  30. package/dist/loader-utils/lib/scan-utils/{experimental-scan-options.d.ts → query-options.d.ts} +5 -8
  31. package/dist/loader-utils/lib/scan-utils/query-options.d.ts.map +1 -0
  32. package/dist/loader-utils/lib/scan-utils/{experimental-scan-options.js → query-options.js} +1 -1
  33. package/dist/loader-utils/lib/scan-utils/query-options.js.map +1 -0
  34. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.d.ts +12 -17
  35. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.d.ts.map +1 -1
  36. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.js +5 -5
  37. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.js.map +1 -1
  38. package/dist/loader-utils/lib/scan-utils/table-query.d.ts +33 -3
  39. package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
  40. package/dist/loader-utils/lib/scan-utils/table-query.js.map +1 -1
  41. package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts +2 -2
  42. package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts.map +1 -1
  43. package/dist/loader-utils/lib/scan-utils/table-scan-batch.js +11 -3
  44. package/dist/loader-utils/lib/scan-utils/table-scan-batch.js.map +1 -1
  45. package/dist/loader-utils/lib/sources/data-source.d.ts +4 -0
  46. package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
  47. package/dist/loader-utils/lib/sources/data-source.js +50 -1
  48. package/dist/loader-utils/lib/sources/data-source.js.map +1 -1
  49. package/dist/loader-utils/lib/sources/table-source-collection.d.ts +30 -0
  50. package/dist/loader-utils/lib/sources/table-source-collection.d.ts.map +1 -0
  51. package/dist/loader-utils/lib/sources/table-source-collection.js +5 -0
  52. package/dist/loader-utils/lib/sources/table-source-collection.js.map +1 -0
  53. package/dist/loader-utils/loader-types.d.ts +5 -5
  54. package/dist/loader-utils/loader-types.d.ts.map +1 -1
  55. package/dist/null-loader.js +1 -1
  56. package/dist/null-worker-node.js +1 -1
  57. package/dist/null-worker.js +1 -1
  58. package/dist/scan/arrow-execution/filter-arrow-table.cjs +254 -0
  59. package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +7 -0
  60. package/dist/scan/arrow-execution/filter-arrow-table.d.ts +16 -0
  61. package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -0
  62. package/dist/scan/arrow-execution/filter-arrow-table.js +222 -0
  63. package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -0
  64. package/dist/scan/arrow-execution/project-arrow-table.cjs +70 -0
  65. package/dist/scan/arrow-execution/project-arrow-table.cjs.map +7 -0
  66. package/dist/scan/arrow-execution/project-arrow-table.d.ts +8 -0
  67. package/dist/scan/arrow-execution/project-arrow-table.d.ts.map +1 -0
  68. package/dist/scan/arrow-execution/project-arrow-table.js +39 -0
  69. package/dist/scan/arrow-execution/project-arrow-table.js.map +1 -0
  70. package/dist/scan/arrow-execution.cjs +34 -0
  71. package/dist/scan/arrow-execution.cjs.map +7 -0
  72. package/dist/scan/arrow-execution.d.ts +4 -0
  73. package/dist/scan/arrow-execution.d.ts.map +1 -0
  74. package/dist/scan/arrow-execution.js +6 -0
  75. package/dist/scan/arrow-execution.js.map +1 -0
  76. package/dist/scan/arrow-query.cjs.map +1 -1
  77. package/dist/scan/arrow-query.d.ts +1 -1
  78. package/dist/scan/arrow-query.d.ts.map +1 -1
  79. package/dist/scan/catalog-query-source.cjs +122 -0
  80. package/dist/scan/catalog-query-source.cjs.map +7 -0
  81. package/dist/scan/catalog-query-source.d.ts +6 -0
  82. package/dist/scan/catalog-query-source.d.ts.map +1 -0
  83. package/dist/scan/catalog-query-source.js +115 -0
  84. package/dist/scan/catalog-query-source.js.map +1 -0
  85. package/dist/scan/federated-table-scan-source.cjs +4 -4
  86. package/dist/scan/federated-table-scan-source.cjs.map +2 -2
  87. package/dist/scan/federated-table-scan-source.d.ts +1 -1
  88. package/dist/scan/federated-table-scan-source.d.ts.map +1 -1
  89. package/dist/scan/federated-table-scan-source.js +4 -4
  90. package/dist/scan/federated-table-scan-source.js.map +1 -1
  91. package/dist/scan/index.cjs +188 -4
  92. package/dist/scan/index.cjs.map +4 -4
  93. package/dist/scan/index.d.ts +9 -2
  94. package/dist/scan/index.d.ts.map +1 -1
  95. package/dist/scan/index.js +4 -0
  96. package/dist/scan/index.js.map +1 -1
  97. package/dist/scan/parse-sql-predicate.cjs +3 -3
  98. package/dist/scan/parse-sql-predicate.cjs.map +2 -2
  99. package/dist/scan/parse-sql-predicate.d.ts +5 -2
  100. package/dist/scan/parse-sql-predicate.d.ts.map +1 -1
  101. package/dist/scan/parse-sql-predicate.js +3 -10
  102. package/dist/scan/parse-sql-predicate.js.map +1 -1
  103. package/dist/scan/parse-sql-query.cjs +70 -0
  104. package/dist/scan/parse-sql-query.cjs.map +7 -0
  105. package/dist/scan/parse-sql-query.d.ts +5 -0
  106. package/dist/scan/parse-sql-query.d.ts.map +1 -0
  107. package/dist/scan/parse-sql-query.js +49 -0
  108. package/dist/scan/parse-sql-query.js.map +1 -0
  109. package/dist/scan/parse-sql-select.cjs +215 -0
  110. package/dist/scan/parse-sql-select.cjs.map +7 -0
  111. package/dist/scan/parse-sql-select.d.ts +38 -0
  112. package/dist/scan/parse-sql-select.d.ts.map +1 -0
  113. package/dist/scan/parse-sql-select.js +208 -0
  114. package/dist/scan/parse-sql-select.js.map +1 -0
  115. package/dist/scan/query-arrow-table-in-batches.cjs +65 -0
  116. package/dist/scan/query-arrow-table-in-batches.cjs.map +7 -0
  117. package/dist/scan/query-arrow-table-in-batches.d.ts +8 -0
  118. package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -0
  119. package/dist/scan/query-arrow-table-in-batches.js +44 -0
  120. package/dist/scan/query-arrow-table-in-batches.js.map +1 -0
  121. package/dist/scan/query-arrow-table.cjs +52 -179
  122. package/dist/scan/query-arrow-table.cjs.map +3 -3
  123. package/dist/scan/query-arrow-table.d.ts +4 -37
  124. package/dist/scan/query-arrow-table.d.ts.map +1 -1
  125. package/dist/scan/query-arrow-table.js +37 -188
  126. package/dist/scan/query-arrow-table.js.map +1 -1
  127. package/dist/scan/query.cjs +257 -0
  128. package/dist/scan/query.cjs.map +7 -0
  129. package/dist/scan/query.d.ts +44 -0
  130. package/dist/scan/query.d.ts.map +1 -0
  131. package/dist/scan/query.js +246 -0
  132. package/dist/scan/query.js.map +1 -0
  133. package/dist/scan/resolve-query-source.cjs +59 -0
  134. package/dist/scan/resolve-query-source.cjs.map +7 -0
  135. package/dist/scan/resolve-query-source.d.ts +6 -0
  136. package/dist/scan/resolve-query-source.d.ts.map +1 -0
  137. package/dist/scan/resolve-query-source.js +37 -0
  138. package/dist/scan/resolve-query-source.js.map +1 -0
  139. package/dist/scan/sql-catalog.cjs +110 -0
  140. package/dist/scan/sql-catalog.cjs.map +7 -0
  141. package/dist/scan/sql-catalog.d.ts +47 -0
  142. package/dist/scan/sql-catalog.d.ts.map +1 -0
  143. package/dist/scan/sql-catalog.js +97 -0
  144. package/dist/scan/sql-catalog.js.map +1 -0
  145. package/dist/scan/table-query.cjs.map +2 -2
  146. package/dist/scan/table-query.d.ts +4 -1
  147. package/dist/scan/table-query.d.ts.map +1 -1
  148. package/dist/scan/table-query.js.map +1 -1
  149. package/dist/vector-table-scan-source.cjs +281 -193
  150. package/dist/vector-table-scan-source.cjs.map +3 -3
  151. package/dist/worker-utils/index.cjs +2 -1
  152. package/dist/worker-utils/index.cjs.map +1 -1
  153. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  154. package/dist/worker-utils/lib/library-utils/library-utils.js +1 -1
  155. package/dist/worker-utils/lib/library-utils/library-utils.js.map +1 -1
  156. package/package.json +17 -7
  157. package/src/loader-utils/index.ts +30 -6
  158. package/src/loader-utils/lib/files/http-file-transport.ts +65 -1
  159. package/src/loader-utils/lib/files/http-file-types.ts +2 -0
  160. package/src/loader-utils/lib/files/read-range-response.ts +66 -0
  161. package/src/loader-utils/lib/scan-utils/logical-table-query.ts +164 -0
  162. package/src/loader-utils/lib/scan-utils/query-options.ts +44 -0
  163. package/src/loader-utils/lib/scan-utils/scan-query-metadata.ts +17 -26
  164. package/src/loader-utils/lib/scan-utils/table-query.ts +49 -8
  165. package/src/loader-utils/lib/scan-utils/table-scan-batch.ts +25 -9
  166. package/src/loader-utils/lib/sources/data-source.ts +54 -1
  167. package/src/loader-utils/lib/sources/table-source-collection.ts +38 -0
  168. package/src/loader-utils/loader-types.ts +5 -5
  169. package/src/scan/arrow-execution/filter-arrow-table.ts +293 -0
  170. package/src/scan/arrow-execution/project-arrow-table.ts +53 -0
  171. package/src/scan/arrow-execution.ts +7 -0
  172. package/src/scan/arrow-query.ts +3 -0
  173. package/src/scan/catalog-query-source.ts +132 -0
  174. package/src/scan/federated-table-scan-source.ts +19 -19
  175. package/src/scan/index.ts +28 -4
  176. package/src/scan/parse-sql-predicate.ts +9 -3
  177. package/src/scan/parse-sql-query.ts +53 -0
  178. package/src/scan/parse-sql-select.ts +220 -0
  179. package/src/scan/query-arrow-table-in-batches.ts +58 -0
  180. package/src/scan/query-arrow-table.ts +60 -237
  181. package/src/scan/query.ts +339 -0
  182. package/src/scan/resolve-query-source.ts +47 -0
  183. package/src/scan/sql-catalog.ts +167 -0
  184. package/src/scan/table-query.ts +6 -1
  185. package/src/worker-utils/lib/library-utils/library-utils.ts +1 -1
  186. package/dist/loader-utils/lib/scan-utils/experimental-scan-options.d.ts.map +0 -1
  187. package/dist/loader-utils/lib/scan-utils/experimental-scan-options.js.map +0 -1
  188. package/src/loader-utils/lib/scan-utils/experimental-scan-options.ts +0 -46
@@ -0,0 +1,246 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import * as arrow from 'apache-arrow';
5
+ import { normalizeTableQuery, executeTableScanBatches, planTableQuery, emitQueryComplete, resolveLoaderAuthenticationOptions, isSourceLoader } from '@loaders.gl/core/loader-utils';
6
+ import { convertArrowToSchema, convertSchemaToArrow, convertTableToArrow } from '@loaders.gl/core/schema-utils';
7
+ import { projectArrowTable, filterArrowTable } from "./arrow-execution.js";
8
+ import { createCatalogQuerySource } from "./catalog-query-source.js";
9
+ import { resolveQuerySource } from "./resolve-query-source.js";
10
+ /** Collects the same ordered Arrow batch pipeline exposed by queryInBatches. */
11
+ export async function query(tableQuery, options) {
12
+ let schema;
13
+ const batches = [];
14
+ for await (const batch of queryInBatches(tableQuery, options)) {
15
+ schema = batch.data.schema;
16
+ batches.push(...batch.data.batches);
17
+ }
18
+ const data = new arrow.Table(schema, batches);
19
+ return { shape: 'arrow-table', schema: convertArrowToSchema(data.schema), data };
20
+ }
21
+ /** Executes one logical query with bounded batch buffering and cooperative cancellation. */
22
+ export async function* queryInBatches(tableQuery, options) {
23
+ const startedAt = Date.now();
24
+ let status = 'early-terminated';
25
+ let rowsRead = 0;
26
+ let rowsReturned = 0;
27
+ let batchesRead = 0;
28
+ let sourcesRead = 0;
29
+ let error;
30
+ let ownedSource;
31
+ let earlyTerminationReason;
32
+ try {
33
+ options.signal?.throwIfAborted();
34
+ let parsedQuery;
35
+ if (typeof tableQuery === 'string') {
36
+ const parser = await options.sqlParser;
37
+ options.signal?.throwIfAborted();
38
+ if (typeof parser !== 'function')
39
+ throw new Error('SQL queries require a sqlParser function or promise.');
40
+ parsedQuery = await parser(tableQuery);
41
+ options.signal?.throwIfAborted();
42
+ }
43
+ else
44
+ parsedQuery = tableQuery;
45
+ if (!parsedQuery || typeof parsedQuery !== 'object' || Array.isArray(parsedQuery))
46
+ throw new Error('Table query must be an object.');
47
+ let logicalQuery;
48
+ let source;
49
+ if ('command' in parsedQuery) {
50
+ logicalQuery = {};
51
+ source = createCatalogQuerySource(parsedQuery, options.sources);
52
+ }
53
+ else {
54
+ logicalQuery = parsedQuery;
55
+ source =
56
+ logicalQuery.from === undefined
57
+ ? options.source
58
+ : await resolveQuerySource(logicalQuery.from, options.sources, options.signal);
59
+ }
60
+ if (logicalQuery.from === undefined && typeof source === 'string') {
61
+ const opened = await openQuerySource(options);
62
+ if (opened &&
63
+ typeof opened === 'object' &&
64
+ 'close' in opened &&
65
+ typeof opened.close === 'function')
66
+ ownedSource = opened;
67
+ source = opened;
68
+ }
69
+ options.signal?.throwIfAborted();
70
+ if (!source || typeof source !== 'object')
71
+ throw new Error('Query source must be an Arrow table or table scan source.');
72
+ const inMemory = 'shape' in source && source.shape === 'arrow-table';
73
+ if (!inMemory &&
74
+ (!('read' in source) ||
75
+ typeof source.read !== 'function' ||
76
+ !('getQueryMetadata' in source) ||
77
+ typeof source.getQueryMetadata !== 'function')) {
78
+ throw new Error('Query source must be an Arrow table or table scan source.');
79
+ }
80
+ const metadata = inMemory
81
+ ? undefined
82
+ : await source.getQueryMetadata({ signal: options.signal });
83
+ options.signal?.throwIfAborted();
84
+ if (metadata &&
85
+ (metadata.queryType !== 'table' ||
86
+ metadata.execution.status !== 'supported' ||
87
+ metadata.execution.method !== 'read')) {
88
+ throw new Error('Query source must support table reads.');
89
+ }
90
+ const sourceSchema = inMemory
91
+ ? source.data.schema
92
+ : convertSchemaToArrow(metadata.schema);
93
+ const names = sourceSchema.fields.map(field => field.name);
94
+ const normalized = normalizeTableQuery(names, logicalQuery);
95
+ const outputColumns = [...new Set(normalized.select.map(selection => selection.column))];
96
+ const plan = planTableQuery(names, { columns: outputColumns, predicate: normalized.where });
97
+ const requiredColumns = plan[0].kind === 'scan' ? plan[0].columns : names;
98
+ const capabilities = metadata?.capabilities.table;
99
+ // read() must perform exact filtering when it advertises pushdown+residual, not only pruning.
100
+ const delegatePredicate = Boolean(normalized.where &&
101
+ capabilities &&
102
+ ['pushdown', 'pushdown+residual'].includes(capabilities.predicate));
103
+ const residual = delegatePredicate ? undefined : normalized.where;
104
+ const readOptions = {
105
+ signal: options.signal,
106
+ ...(capabilities && capabilities.projection !== 'unsupported'
107
+ ? { columns: requiredColumns }
108
+ : {}),
109
+ ...(delegatePredicate ? { predicate: normalized.where } : {}),
110
+ ...(!residual &&
111
+ capabilities &&
112
+ ['pushdown', 'pushdown+residual'].includes(capabilities.limit)
113
+ ? { limit: normalized.limit }
114
+ : {})
115
+ };
116
+ const readSchema = convertArrowToSchema(readOptions.columns ? sourceSchema.select([...readOptions.columns]) : sourceSchema);
117
+ const empty = projectArrowTable(new arrow.Table(sourceSchema), normalized.select);
118
+ const comparisonSchema = convertSchemaToArrow(convertArrowToSchema(empty.schema));
119
+ let emitted = false;
120
+ /** Adapts physical batches without pulling ahead of the query consumer. */
121
+ async function* inputs() {
122
+ sourcesRead = 1;
123
+ const batches = inMemory
124
+ ? memoryBatches(source.data)
125
+ : source.read(readOptions);
126
+ for await (const value of batches) {
127
+ options.signal?.throwIfAborted();
128
+ const batch = normalizeBatch(value, readSchema);
129
+ batchesRead++;
130
+ rowsRead += batch.length;
131
+ yield batch;
132
+ }
133
+ }
134
+ for await (const value of executeTableScanBatches(() => inputs(), {
135
+ predicate: residual,
136
+ limit: normalized.limit,
137
+ signal: options.signal
138
+ }, {
139
+ filter: (batch, predicate, signal) => {
140
+ const input = batch;
141
+ const data = predicate ? filterArrowTable(input.data, predicate, { signal }) : input.data;
142
+ return { ...input, ...wrapBatch(data) };
143
+ },
144
+ project: batch => {
145
+ const input = batch;
146
+ return { ...input, ...wrapBatch(projectArrowTable(input.data, normalized.select)) };
147
+ }
148
+ })) {
149
+ const batch = value;
150
+ if (!arrow.util.compareSchemas(comparisonSchema, convertSchemaToArrow(batch.schema)))
151
+ throw new Error('Query output schema does not match source metadata.');
152
+ emitted = true;
153
+ rowsReturned += batch.length;
154
+ yield batch;
155
+ }
156
+ // An empty schema-bearing batch makes collected and streaming empty results identical.
157
+ if (!emitted)
158
+ yield wrapBatch(empty);
159
+ if (normalized.limit !== undefined && rowsReturned >= normalized.limit)
160
+ earlyTerminationReason = 'limit';
161
+ status = earlyTerminationReason ? 'early-terminated' : 'completed';
162
+ }
163
+ catch (failure) {
164
+ error = failure;
165
+ status = options.signal?.aborted ? 'cancelled' : 'failed';
166
+ throw failure;
167
+ }
168
+ finally {
169
+ if (status === 'early-terminated' && !earlyTerminationReason)
170
+ earlyTerminationReason = 'consumer-return';
171
+ try {
172
+ await ownedSource?.close?.();
173
+ }
174
+ catch (failure) {
175
+ if (error === undefined) {
176
+ error = failure;
177
+ status = options.signal?.aborted ? 'cancelled' : 'failed';
178
+ earlyTerminationReason = undefined;
179
+ throw failure;
180
+ }
181
+ }
182
+ finally {
183
+ emitQueryComplete(options.onQueryComplete, Object.freeze({
184
+ status,
185
+ sourcesPlanned: 1,
186
+ sourcesRead,
187
+ batchesRead,
188
+ rowsRead,
189
+ rowsReturned,
190
+ durationMilliseconds: Date.now() - startedAt,
191
+ ...(earlyTerminationReason ? { earlyTerminationReason } : {}),
192
+ ...(error === undefined ? {} : { error })
193
+ }));
194
+ }
195
+ }
196
+ }
197
+ /** Emits original Arrow RecordBatches without copying their buffers. */
198
+ async function* memoryBatches(data) {
199
+ for (const batch of data.batches)
200
+ yield wrapBatch(new arrow.Table(data.schema, [batch]));
201
+ }
202
+ /** Converts supported native table batches to Arrow while preserving their declared schema. */
203
+ function normalizeBatch(value, fallbackSchema) {
204
+ if (!value || typeof value !== 'object' || !('shape' in value))
205
+ throw new Error('Query source returned an unsupported batch.');
206
+ const input = value;
207
+ const batch = { ...input, schema: input.schema ?? fallbackSchema };
208
+ if (!['arrow-table', 'object-row-table', 'array-row-table', 'columnar-table'].includes(batch.shape))
209
+ throw new Error(`Unsupported query batch shape: ${batch.shape}`);
210
+ const data = batch.length === 0 && batch.schema
211
+ ? new arrow.Table(convertSchemaToArrow(batch.schema))
212
+ : convertTableToArrow(batch);
213
+ return { ...batch, ...wrapBatch(data) };
214
+ }
215
+ /** Wraps Arrow data in the standard batch envelope. */
216
+ function wrapBatch(data) {
217
+ return {
218
+ shape: 'arrow-table',
219
+ data,
220
+ schema: convertArrowToSchema(data.schema),
221
+ batchType: 'data',
222
+ length: data.numRows
223
+ };
224
+ }
225
+ /** Opens only explicit URL source loaders; the public query owns the returned source. */
226
+ async function openQuerySource(options) {
227
+ const candidates = Array.isArray(options.loaders) ? options.loaders : [options.loaders];
228
+ if (!candidates.length || candidates.some(loader => !isSourceLoader(loader) || !loader.fromUrl))
229
+ throw new Error('Query source must specify explicit URL-capable source loaders for a URL.');
230
+ const { source, sources, loaders, sqlParser, onQueryComplete, ...sourceOptions } = options;
231
+ const url = source;
232
+ const selected = candidates.length === 1 ? candidates[0] : candidates.find(loader => loader.testURL(url));
233
+ if (!selected)
234
+ throw new Error('No explicit source loader matches the query URL.');
235
+ const implementation = selected.preload ? await selected.preload(url, sourceOptions) : selected;
236
+ options.signal?.throwIfAborted();
237
+ if (!isSourceLoader(implementation) || !implementation.fromUrl)
238
+ throw new Error('Query source preload did not return a URL-capable source loader.');
239
+ const authenticatedOptions = await resolveLoaderAuthenticationOptions(selected.getAuthentications ? selected : implementation, url, { ...sourceOptions, core: { ...sourceOptions.core, ignoreRegisteredLoaders: true } });
240
+ options.signal?.throwIfAborted();
241
+ return implementation.createDataSource(url, authenticatedOptions);
242
+ }
243
+ export { parseSQLQuery } from "./parse-sql-query.js";
244
+ export { parseSQLSelect } from "./parse-sql-select.js";
245
+ export { createSQLCatalog } from "./sql-catalog.js";
246
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/scan/query.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EASjB,kCAAkC,EAClC,cAAc,EACf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,6BAA0B;AACtE,OAAO,EAAC,wBAAwB,EAAC,kCAA+B;AAEhE,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AA2C1D,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,KAAK,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CAAC,kBAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,EACvD,GAAG,EACH,EAAC,GAAG,aAAa,EAAE,IAAI,EAAE,EAAC,GAAG,aAAa,CAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAC,EAAC,CACjF,CAAC;IACF,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,OAAO,cAAc,CAAC,gBAAgB,CAAC,GAAG,EAAE,oBAAyC,CAAC,CAAC;AACzF,CAAC;AAED,OAAO,EAAC,aAAa,EAAC,6BAA0B;AAChD,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAGlD,OAAO,EAAC,gBAAgB,EAAC,yBAAsB"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/scan/resolve-query-source.ts
21
+ var resolve_query_source_exports = {};
22
+ __export(resolve_query_source_exports, {
23
+ createSourceRegistry: () => createSourceRegistry,
24
+ resolveQuerySource: () => resolveQuerySource
25
+ });
26
+ module.exports = __toCommonJS(resolve_query_source_exports);
27
+ var import_loader_utils = require("@loaders.gl/core/loader-utils");
28
+ async function resolveQuerySource(reference, sources, signal) {
29
+ (0, import_loader_utils.validateTableReference)(reference);
30
+ const registry = createSourceRegistry(sources);
31
+ const name = typeof reference === "string" ? reference : reference.source;
32
+ const source = registry.get(name);
33
+ if (!source) throw new Error(`Unknown data source: ${name}`);
34
+ signal?.throwIfAborted();
35
+ if (typeof reference === "string") return source;
36
+ const collection = source;
37
+ if (typeof collection.getTable !== "function")
38
+ throw new Error(`Data source ${name} does not expose named tables.`);
39
+ const table = await collection.getTable(reference.table, { signal });
40
+ signal?.throwIfAborted();
41
+ return table;
42
+ }
43
+ function createSourceRegistry(sources) {
44
+ if (!Array.isArray(sources)) throw new Error("Query requires a sources array.");
45
+ const registry = /* @__PURE__ */ new Map();
46
+ for (const source of sources) {
47
+ if (!source || typeof source.name !== "string" || !source.name.trim())
48
+ throw new Error("Registered data sources require non-empty names.");
49
+ if (registry.has(source.name)) throw new Error(`Duplicate data source name: ${source.name}`);
50
+ registry.set(source.name, source);
51
+ }
52
+ return registry;
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ createSourceRegistry,
57
+ resolveQuerySource
58
+ });
59
+ //# sourceMappingURL=resolve-query-source.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/scan/resolve-query-source.ts"],
4
+ "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {validateTableReference} from '@loaders.gl/core/loader-utils';\nimport type {\n DataSource,\n DataSourceOptions,\n TableReference,\n TableSourceCollection\n} from '@loaders.gl/core/loader-utils';\n\n/** Resolves one literal source/table reference without inspecting unrelated source data. */\nexport async function resolveQuerySource(\n reference: TableReference,\n sources: readonly DataSource<unknown, DataSourceOptions>[] | undefined,\n signal?: AbortSignal\n): Promise<unknown> {\n validateTableReference(reference);\n const registry = createSourceRegistry(sources);\n const name = typeof reference === 'string' ? reference : reference.source;\n const source = registry.get(name);\n if (!source) throw new Error(`Unknown data source: ${name}`);\n signal?.throwIfAborted();\n if (typeof reference === 'string') return source;\n const collection = source as unknown as Partial<TableSourceCollection>;\n if (typeof collection.getTable !== 'function')\n throw new Error(`Data source ${name} does not expose named tables.`);\n const table = await collection.getTable(reference.table, {signal});\n signal?.throwIfAborted();\n return table;\n}\n\n/** Snapshots source identities consistently for FROM and metadata queries. */\nexport function createSourceRegistry(\n sources: readonly DataSource<unknown, DataSourceOptions>[] | undefined\n): ReadonlyMap<string, DataSource<unknown, DataSourceOptions>> {\n if (!Array.isArray(sources)) throw new Error('Query requires a sources array.');\n const registry = new Map<string, DataSource<unknown, DataSourceOptions>>();\n for (const source of sources) {\n if (!source || typeof source.name !== 'string' || !source.name.trim())\n throw new Error('Registered data sources require non-empty names.');\n if (registry.has(source.name)) throw new Error(`Duplicate data source name: ${source.name}`);\n registry.set(source.name, source);\n }\n return registry;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAqC;AASrC,eAAsB,mBACpB,WACA,SACA,QACkB;AAClB,kDAAuB,SAAS;AAChC,QAAM,WAAW,qBAAqB,OAAO;AAC7C,QAAM,OAAO,OAAO,cAAc,WAAW,YAAY,UAAU;AACnE,QAAM,SAAS,SAAS,IAAI,IAAI;AAChC,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,wBAAwB,IAAI,EAAE;AAC3D,UAAQ,eAAe;AACvB,MAAI,OAAO,cAAc,SAAU,QAAO;AAC1C,QAAM,aAAa;AACnB,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,eAAe,IAAI,gCAAgC;AACrE,QAAM,QAAQ,MAAM,WAAW,SAAS,UAAU,OAAO,EAAC,OAAM,CAAC;AACjE,UAAQ,eAAe;AACvB,SAAO;AACT;AAGO,SAAS,qBACd,SAC6D;AAC7D,MAAI,CAAC,MAAM,QAAQ,OAAO,EAAG,OAAM,IAAI,MAAM,iCAAiC;AAC9E,QAAM,WAAW,oBAAI,IAAoD;AACzE,aAAW,UAAU,SAAS;AAC5B,QAAI,CAAC,UAAU,OAAO,OAAO,SAAS,YAAY,CAAC,OAAO,KAAK,KAAK;AAClE,YAAM,IAAI,MAAM,kDAAkD;AACpE,QAAI,SAAS,IAAI,OAAO,IAAI,EAAG,OAAM,IAAI,MAAM,+BAA+B,OAAO,IAAI,EAAE;AAC3F,aAAS,IAAI,OAAO,MAAM,MAAM;AAAA,EAClC;AACA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { DataSource, DataSourceOptions, TableReference } from '@loaders.gl/core/loader-utils';
2
+ /** Resolves one literal source/table reference without inspecting unrelated source data. */
3
+ export declare function resolveQuerySource(reference: TableReference, sources: readonly DataSource<unknown, DataSourceOptions>[] | undefined, signal?: AbortSignal): Promise<unknown>;
4
+ /** Snapshots source identities consistently for FROM and metadata queries. */
5
+ export declare function createSourceRegistry(sources: readonly DataSource<unknown, DataSourceOptions>[] | undefined): ReadonlyMap<string, DataSource<unknown, DataSourceOptions>>;
6
+ //# sourceMappingURL=resolve-query-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-query-source.d.ts","sourceRoot":"","sources":["../../src/scan/resolve-query-source.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,cAAc,EAEf,MAAM,+BAA+B,CAAC;AAEvC,4FAA4F;AAC5F,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,GAAG,SAAS,EACtE,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CAclB;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,GAAG,SAAS,GACrE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAU7D"}
@@ -0,0 +1,37 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { validateTableReference } from '@loaders.gl/core/loader-utils';
5
+ /** Resolves one literal source/table reference without inspecting unrelated source data. */
6
+ export async function resolveQuerySource(reference, sources, signal) {
7
+ validateTableReference(reference);
8
+ const registry = createSourceRegistry(sources);
9
+ const name = typeof reference === 'string' ? reference : reference.source;
10
+ const source = registry.get(name);
11
+ if (!source)
12
+ throw new Error(`Unknown data source: ${name}`);
13
+ signal?.throwIfAborted();
14
+ if (typeof reference === 'string')
15
+ return source;
16
+ const collection = source;
17
+ if (typeof collection.getTable !== 'function')
18
+ throw new Error(`Data source ${name} does not expose named tables.`);
19
+ const table = await collection.getTable(reference.table, { signal });
20
+ signal?.throwIfAborted();
21
+ return table;
22
+ }
23
+ /** Snapshots source identities consistently for FROM and metadata queries. */
24
+ export function createSourceRegistry(sources) {
25
+ if (!Array.isArray(sources))
26
+ throw new Error('Query requires a sources array.');
27
+ const registry = new Map();
28
+ for (const source of sources) {
29
+ if (!source || typeof source.name !== 'string' || !source.name.trim())
30
+ throw new Error('Registered data sources require non-empty names.');
31
+ if (registry.has(source.name))
32
+ throw new Error(`Duplicate data source name: ${source.name}`);
33
+ registry.set(source.name, source);
34
+ }
35
+ return registry;
36
+ }
37
+ //# sourceMappingURL=resolve-query-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-query-source.js","sourceRoot":"","sources":["../../src/scan/resolve-query-source.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,sBAAsB,EAAC,MAAM,+BAA+B,CAAC;AAQrE,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,SAAyB,EACzB,OAAsE,EACtE,MAAoB;IAEpB,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAClC,MAAM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AAC;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7F,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/scan/sql-catalog.ts
21
+ var sql_catalog_exports = {};
22
+ __export(sql_catalog_exports, {
23
+ createSQLCatalog: () => createSQLCatalog
24
+ });
25
+ module.exports = __toCommonJS(sql_catalog_exports);
26
+ var import_loader_utils = require("@loaders.gl/core/loader-utils");
27
+ var import_resolve_query_source = require("./resolve-query-source.cjs");
28
+ function createSQLCatalog(sources) {
29
+ const registry = (0, import_resolve_query_source.createSourceRegistry)(sources);
30
+ const names = Object.freeze([...registry.keys()].map((name) => Object.freeze({ name })));
31
+ function getSource(name) {
32
+ const source = registry.get(name);
33
+ if (!source) throw new Error(`Unknown data source: ${name}`);
34
+ return source;
35
+ }
36
+ async function getTables(sourceName, options = {}) {
37
+ options.signal?.throwIfAborted();
38
+ const selected = sourceName === void 0 ? [...registry.values()] : [getSource(sourceName)];
39
+ const result = [];
40
+ for (const source of selected) {
41
+ options.signal?.throwIfAborted();
42
+ const discovery = source;
43
+ if (typeof discovery.getTablesMetadata === "function") {
44
+ const tables = await discovery.getTablesMetadata(options);
45
+ options.signal?.throwIfAborted();
46
+ const tableNames = /* @__PURE__ */ new Set();
47
+ if (!Array.isArray(tables)) throw new Error("Table discovery must return an array.");
48
+ for (const table of tables) {
49
+ if (!table || typeof table.name !== "string" || !table.name.trim() || tableNames.has(table.name))
50
+ throw new Error("Table metadata requires unique non-empty names.");
51
+ if (table.queryable !== void 0 && typeof table.queryable !== "boolean")
52
+ throw new Error("Table metadata queryable must be a boolean.");
53
+ tableNames.add(table.name);
54
+ result.push({
55
+ ...table,
56
+ sourceName: source.name,
57
+ reference: { source: source.name, table: table.name },
58
+ queryable: table.queryable ?? typeof discovery.getTable === "function"
59
+ });
60
+ }
61
+ } else if (typeof discovery.getQueryMetadata === "function") {
62
+ const metadata = await discovery.getQueryMetadata(options);
63
+ options.signal?.throwIfAborted();
64
+ if (metadata.queryType === "table")
65
+ result.push({
66
+ name: source.name,
67
+ sourceName: source.name,
68
+ reference: source.name,
69
+ schema: metadata.schema,
70
+ queryable: typeof discovery.read === "function" && metadata.execution.status === "supported" && metadata.execution.method === "read"
71
+ });
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ async function getSchema(reference, options = {}) {
77
+ (0, import_loader_utils.validateTableReference)(reference);
78
+ if (reference === void 0) throw new Error("A table reference is required.");
79
+ options.signal?.throwIfAborted();
80
+ const sourceName = typeof reference === "string" ? reference : reference.source;
81
+ const source = getSource(sourceName);
82
+ const discovery = source;
83
+ let schema;
84
+ if (typeof reference === "string") {
85
+ if (typeof discovery.getTablesMetadata === "function")
86
+ throw new Error(
87
+ `DESCRIBE requires a qualified table reference for collection ${sourceName}.`
88
+ );
89
+ if (typeof discovery.getQueryMetadata === "function") {
90
+ const metadata = await discovery.getQueryMetadata(options);
91
+ if (metadata.queryType === "table") schema = metadata.schema;
92
+ }
93
+ } else if (typeof discovery.getTableMetadata === "function") {
94
+ schema = (await discovery.getTableMetadata(reference.table, options)).schema;
95
+ } else {
96
+ schema = (await getTables(sourceName, options)).find(
97
+ (table) => typeof table.reference === "object" && table.name === reference.table
98
+ )?.schema;
99
+ }
100
+ options.signal?.throwIfAborted();
101
+ if (!schema) throw new Error(`No discoverable table schema: ${sourceName}`);
102
+ return schema;
103
+ }
104
+ return Object.freeze({ getSources: () => names, getTables, getSchema });
105
+ }
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ createSQLCatalog
109
+ });
110
+ //# sourceMappingURL=sql-catalog.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/scan/sql-catalog.ts"],
4
+ "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Schema} from '@loaders.gl/core/schema';\nimport type {\n DataSource,\n DataSourceOptions,\n TableReference,\n TableDiscoverySource,\n TableMetadata,\n TableScanSource,\n TableSourceCollection\n} from '@loaders.gl/core/loader-utils';\nimport {validateTableReference} from '@loaders.gl/core/loader-utils';\nimport {createSourceRegistry} from './resolve-query-source';\n\n/** Portable logical metadata commands, independent of SQL parsing and execution controls. */\nexport type SQLCatalogQuery = Readonly<\n | {\n /** Lists locally registered source names. */\n command: 'showSources';\n }\n | {\n /** Lists discoverable tables in registration order. */\n command: 'showTables';\n /** Optional exact source name; omission discovers every registered source. */\n from?: string;\n }\n | {\n /** Describes the fields of one table. */\n command: 'describe';\n /** Literal source name, or separate source and loaded table names. */\n from: TableReference;\n }\n>;\n\n/** One locally registered source, available without metadata I/O. */\nexport type SQLCatalogSource = Readonly<{\n /** Stable DataSource.name. */\n name: string;\n}>;\n\n/** One discovered table with its actual logical FROM reference. */\nexport type SQLCatalogTable = TableMetadata &\n Readonly<{\n /** Parent DataSource.name. */\n sourceName: string;\n /** Literal or qualified reference used by the query API. */\n reference: TableReference;\n /** Whether the provider advertises table query support. */\n queryable: boolean;\n }>;\n\n/** Lazy schema model shared by SQL commands and schema explorer applications. */\nexport interface SQLCatalog {\n /** Lists registered source names without contacting them. */\n getSources(): readonly SQLCatalogSource[];\n /** Discovers tables only in the requested source, or all sources in registration order. */\n getTables(\n sourceName?: string,\n options?: {signal?: AbortSignal}\n ): Promise<readonly SQLCatalogTable[]>;\n /** Discovers one table's portable schema without calling read() or getTable(). */\n getSchema(reference: TableReference, options?: {signal?: AbortSignal}): Promise<Schema>;\n}\n\n/** Creates a lazy metadata catalog over caller-owned sources; it does not open or close them. */\nexport function createSQLCatalog(\n sources: readonly DataSource<unknown, DataSourceOptions>[]\n): SQLCatalog {\n const registry = createSourceRegistry(sources);\n const names = Object.freeze([...registry.keys()].map(name => Object.freeze({name})));\n /** Looks up exact names without falling back to a default source. */\n function getSource(name: string) {\n const source = registry.get(name);\n if (!source) throw new Error(`Unknown data source: ${name}`);\n return source;\n }\n /** Adapts one source's metadata discovery without reading table rows. */\n async function getTables(\n sourceName?: string,\n options: {signal?: AbortSignal} = {}\n ): Promise<readonly SQLCatalogTable[]> {\n options.signal?.throwIfAborted();\n const selected = sourceName === undefined ? [...registry.values()] : [getSource(sourceName)];\n const result: SQLCatalogTable[] = [];\n for (const source of selected) {\n options.signal?.throwIfAborted();\n const discovery = source as unknown as Partial<\n TableDiscoverySource & TableSourceCollection & TableScanSource\n >;\n if (typeof discovery.getTablesMetadata === 'function') {\n const tables = await discovery.getTablesMetadata(options);\n options.signal?.throwIfAborted();\n const tableNames = new Set<string>();\n if (!Array.isArray(tables)) throw new Error('Table discovery must return an array.');\n for (const table of tables) {\n if (\n !table ||\n typeof table.name !== 'string' ||\n !table.name.trim() ||\n tableNames.has(table.name)\n )\n throw new Error('Table metadata requires unique non-empty names.');\n if (table.queryable !== undefined && typeof table.queryable !== 'boolean')\n throw new Error('Table metadata queryable must be a boolean.');\n tableNames.add(table.name);\n result.push({\n ...table,\n sourceName: source.name,\n reference: {source: source.name, table: table.name},\n queryable: table.queryable ?? typeof discovery.getTable === 'function'\n });\n }\n } else if (typeof discovery.getQueryMetadata === 'function') {\n const metadata = await discovery.getQueryMetadata(options);\n options.signal?.throwIfAborted();\n if (metadata.queryType === 'table')\n result.push({\n name: source.name,\n sourceName: source.name,\n reference: source.name,\n schema: metadata.schema,\n queryable:\n typeof discovery.read === 'function' &&\n metadata.execution.status === 'supported' &&\n metadata.execution.method === 'read'\n });\n }\n }\n return result;\n }\n /** Resolves schemas through metadata APIs, never by opening a child table. */\n async function getSchema(\n reference: TableReference,\n options: {signal?: AbortSignal} = {}\n ): Promise<Schema> {\n validateTableReference(reference);\n if (reference === undefined) throw new Error('A table reference is required.');\n options.signal?.throwIfAborted();\n const sourceName = typeof reference === 'string' ? reference : reference.source;\n const source = getSource(sourceName);\n const discovery = source as unknown as Partial<TableDiscoverySource & TableScanSource>;\n let schema: Schema | undefined;\n if (typeof reference === 'string') {\n if (typeof discovery.getTablesMetadata === 'function')\n throw new Error(\n `DESCRIBE requires a qualified table reference for collection ${sourceName}.`\n );\n if (typeof discovery.getQueryMetadata === 'function') {\n const metadata = await discovery.getQueryMetadata(options);\n if (metadata.queryType === 'table') schema = metadata.schema;\n }\n } else if (typeof discovery.getTableMetadata === 'function') {\n schema = (await discovery.getTableMetadata(reference.table, options)).schema;\n } else {\n schema = (await getTables(sourceName, options)).find(\n table => typeof table.reference === 'object' && table.name === reference.table\n )?.schema;\n }\n options.signal?.throwIfAborted();\n if (!schema) throw new Error(`No discoverable table schema: ${sourceName}`);\n return schema;\n }\n return Object.freeze({getSources: () => names, getTables, getSchema});\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,0BAAqC;AACrC,kCAAmC;AAqD5B,SAAS,iBACd,SACY;AACZ,QAAM,eAAW,kDAAqB,OAAO;AAC7C,QAAM,QAAQ,OAAO,OAAO,CAAC,GAAG,SAAS,KAAK,CAAC,EAAE,IA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AM,OAAO,WAAW,UAAS,CAAC;AACtE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,47 @@
1
+ import type { Schema } from '@loaders.gl/core/schema';
2
+ import type { DataSource, DataSourceOptions, TableReference, TableMetadata } from '@loaders.gl/core/loader-utils';
3
+ /** Portable logical metadata commands, independent of SQL parsing and execution controls. */
4
+ export type SQLCatalogQuery = Readonly<{
5
+ /** Lists locally registered source names. */
6
+ command: 'showSources';
7
+ } | {
8
+ /** Lists discoverable tables in registration order. */
9
+ command: 'showTables';
10
+ /** Optional exact source name; omission discovers every registered source. */
11
+ from?: string;
12
+ } | {
13
+ /** Describes the fields of one table. */
14
+ command: 'describe';
15
+ /** Literal source name, or separate source and loaded table names. */
16
+ from: TableReference;
17
+ }>;
18
+ /** One locally registered source, available without metadata I/O. */
19
+ export type SQLCatalogSource = Readonly<{
20
+ /** Stable DataSource.name. */
21
+ name: string;
22
+ }>;
23
+ /** One discovered table with its actual logical FROM reference. */
24
+ export type SQLCatalogTable = TableMetadata & Readonly<{
25
+ /** Parent DataSource.name. */
26
+ sourceName: string;
27
+ /** Literal or qualified reference used by the query API. */
28
+ reference: TableReference;
29
+ /** Whether the provider advertises table query support. */
30
+ queryable: boolean;
31
+ }>;
32
+ /** Lazy schema model shared by SQL commands and schema explorer applications. */
33
+ export interface SQLCatalog {
34
+ /** Lists registered source names without contacting them. */
35
+ getSources(): readonly SQLCatalogSource[];
36
+ /** Discovers tables only in the requested source, or all sources in registration order. */
37
+ getTables(sourceName?: string, options?: {
38
+ signal?: AbortSignal;
39
+ }): Promise<readonly SQLCatalogTable[]>;
40
+ /** Discovers one table's portable schema without calling read() or getTable(). */
41
+ getSchema(reference: TableReference, options?: {
42
+ signal?: AbortSignal;
43
+ }): Promise<Schema>;
44
+ }
45
+ /** Creates a lazy metadata catalog over caller-owned sources; it does not open or close them. */
46
+ export declare function createSQLCatalog(sources: readonly DataSource<unknown, DataSourceOptions>[]): SQLCatalog;
47
+ //# sourceMappingURL=sql-catal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