@loaders.gl/core 5.0.0-rc.1 → 5.0.0-rc.2

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 (93) hide show
  1. package/SCAN-README.md +8 -8
  2. package/dist/arrow-geometry/binary-features.cjs +2 -2
  3. package/dist/arrow-geometry/binary-features.cjs.map +2 -2
  4. package/dist/arrow-geometry/binary-features.js +1 -1
  5. package/dist/arrow-geometry/binary-features.js.map +1 -1
  6. package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs +2 -2
  7. package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs.map +2 -2
  8. package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js +1 -1
  9. package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js.map +1 -1
  10. package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.cjs +2 -2
  11. package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.cjs.map +2 -2
  12. package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.js +1 -1
  13. package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.js.map +1 -1
  14. package/dist/cluster-source.cjs +5 -5
  15. package/dist/cluster-source.cjs.map +2 -2
  16. package/dist/dist.dev.js +61 -13
  17. package/dist/dist.min.js +3 -3
  18. package/dist/federated-table-scan-source.cjs +8 -96
  19. package/dist/federated-table-scan-source.cjs.map +3 -3
  20. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs +2 -2
  21. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs.map +2 -2
  22. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js +1 -1
  23. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js.map +1 -1
  24. package/dist/index.cjs +65 -17
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/lib/api/load.js +36 -7
  27. package/dist/lib/api/load.js.map +1 -1
  28. package/dist/lib/api/parse.js +5 -2
  29. package/dist/lib/api/parse.js.map +1 -1
  30. package/dist/lib/init.js +1 -1
  31. package/dist/loader-utils/index.cjs +38 -14
  32. package/dist/loader-utils/index.cjs.map +2 -2
  33. package/dist/loader-utils/json-loader.js +1 -1
  34. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  35. package/dist/loader-utils/lib/sources/tile-grid.d.ts +1 -1
  36. package/dist/loader-utils/lib/sources/tile-grid.d.ts.map +1 -1
  37. package/dist/loader-utils/lib/sources/tile-grid.js +1 -1
  38. package/dist/loader-utils/lib/sources/tile-grid.js.map +1 -1
  39. package/dist/loader-utils/lib/sources/tile-source-adapter.js +1 -1
  40. package/dist/loader-utils/lib/sources/tile-source-adapter.js.map +1 -1
  41. package/dist/loader-utils/lib/sources/tile-source.d.ts +1 -1
  42. package/dist/loader-utils/lib/sources/tile-source.d.ts.map +1 -1
  43. package/dist/loader-utils/loader-types.d.ts +6 -0
  44. package/dist/loader-utils/loader-types.d.ts.map +1 -1
  45. package/dist/loader-utils/loader-types.js.map +1 -1
  46. package/dist/loader-utils/tile-grid.cjs +5 -5
  47. package/dist/loader-utils/tile-grid.cjs.map +1 -1
  48. package/dist/null-loader.js +1 -1
  49. package/dist/null-worker-node.js +1 -1
  50. package/dist/null-worker.js +1 -1
  51. package/dist/scan/query-scales.cjs +2 -1
  52. package/dist/scan/query-scales.cjs.map +2 -2
  53. package/dist/scan/query-scales.d.ts +2 -1
  54. package/dist/scan/query-scales.d.ts.map +1 -1
  55. package/dist/scan/query-scales.js +2 -1
  56. package/dist/scan/query-scales.js.map +1 -1
  57. package/dist/scan/scan-engine.cjs.map +1 -1
  58. package/dist/scan/scan-engine.d.ts +1 -1
  59. package/dist/scan/scan-engine.js +1 -1
  60. package/dist/scan/sql-predicate-schema.cjs +10 -94
  61. package/dist/scan/sql-predicate-schema.cjs.map +3 -3
  62. package/dist/scan/sql-predicate-schema.d.ts +1 -1
  63. package/dist/scan/sql-predicate-schema.d.ts.map +1 -1
  64. package/dist/scan/sql-predicate-schema.js +9 -103
  65. package/dist/scan/sql-predicate-schema.js.map +1 -1
  66. package/dist/scan/sql-predicate-zod.cjs.map +1 -1
  67. package/dist/scan/sql-predicate-zod.d.ts +1 -1
  68. package/dist/scan/sql-predicate-zod.js +1 -1
  69. package/dist/vector-table-scan-source.cjs +8 -96
  70. package/dist/vector-table-scan-source.cjs.map +3 -3
  71. package/dist/worker-utils/index.cjs +31 -7
  72. package/dist/worker-utils/index.cjs.map +1 -1
  73. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  74. package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +4 -1
  75. package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
  76. package/dist/worker-utils/lib/worker-api/process-on-worker.js +40 -6
  77. package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
  78. package/package.json +24 -104
  79. package/src/arrow-geometry/binary-features.ts +1 -1
  80. package/src/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.ts +1 -1
  81. package/src/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.ts +1 -1
  82. package/src/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.ts +1 -1
  83. package/src/lib/api/load.ts +36 -7
  84. package/src/lib/api/parse.ts +6 -2
  85. package/src/loader-utils/lib/sources/tile-grid.ts +6 -2
  86. package/src/loader-utils/lib/sources/tile-source-adapter.ts +1 -1
  87. package/src/loader-utils/lib/sources/tile-source.ts +1 -1
  88. package/src/loader-utils/loader-types.ts +6 -0
  89. package/src/scan/query-scales.ts +3 -4
  90. package/src/scan/scan-engine.ts +1 -1
  91. package/src/scan/sql-predicate-schema.ts +14 -125
  92. package/src/scan/sql-predicate-zod.ts +1 -1
  93. package/src/worker-utils/lib/worker-api/process-on-worker.ts +39 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/core",
3
- "version": "5.0.0-rc.1",
3
+ "version": "5.0.0-rc.2",
4
4
  "description": "Core loading and writing APIs, workers, schemas, and geometry utilities for loaders.gl",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -224,7 +224,7 @@
224
224
  "import": "./dist/geoarrow/geoarrow-builder.js",
225
225
  "require": "./dist/geoarrow/geoarrow-builder.cjs"
226
226
  },
227
- "./scan": {
227
+ "./query": {
228
228
  "types": "./dist/scan/index.d.ts",
229
229
  "import": "./dist/scan/index.js",
230
230
  "require": "./dist/scan/index.cjs"
@@ -234,82 +234,82 @@
234
234
  "import": "./dist/scan/query-scales.js",
235
235
  "require": "./dist/scan/query-scales.cjs"
236
236
  },
237
- "./scan/arrow-query-worker": {
237
+ "./query/arrow-query-worker": {
238
238
  "types": "./dist/scan/arrow-query-worker.d.ts",
239
239
  "import": "./dist/scan/arrow-query-worker.js",
240
240
  "require": "./dist/scan/arrow-query-worker.cjs"
241
241
  },
242
- "./scan/arrow-query-worker-entry.js": {
242
+ "./query/arrow-query-worker-entry.js": {
243
243
  "types": "./dist/scan/arrow-query-worker-entry.d.ts",
244
244
  "import": "./dist/scan/arrow-query-worker-entry.js",
245
245
  "require": "./dist/scan/arrow-query-worker-entry.cjs"
246
246
  },
247
- "./scan/arrow-query": {
247
+ "./query/arrow-query": {
248
248
  "types": "./dist/scan/arrow-query.d.ts",
249
249
  "import": "./dist/scan/arrow-query.js",
250
250
  "require": "./dist/scan/arrow-query.cjs"
251
251
  },
252
- "./scan/bind-sql-predicate": {
252
+ "./query/bind-sql-predicate": {
253
253
  "types": "./dist/scan/bind-sql-predicate.d.ts",
254
254
  "import": "./dist/scan/bind-sql-predicate.js",
255
255
  "require": "./dist/scan/bind-sql-predicate.cjs"
256
256
  },
257
- "./scan/parse-sql-predicate": {
257
+ "./query/parse-sql-predicate": {
258
258
  "types": "./dist/scan/parse-sql-predicate.d.ts",
259
259
  "import": "./dist/scan/parse-sql-predicate.js",
260
260
  "require": "./dist/scan/parse-sql-predicate.cjs"
261
261
  },
262
- "./scan/query": {
262
+ "./query/sql": {
263
263
  "types": "./dist/scan/query.d.ts",
264
264
  "import": "./dist/scan/query.js",
265
265
  "require": "./dist/scan/query.cjs"
266
266
  },
267
- "./scan/query-arrow-table": {
267
+ "./query/query-arrow-table": {
268
268
  "types": "./dist/scan/query-arrow-table.d.ts",
269
269
  "import": "./dist/scan/query-arrow-table.js",
270
270
  "require": "./dist/scan/query-arrow-table.cjs"
271
271
  },
272
- "./scan/sql-predicate-schema": {
272
+ "./query/sql-predicate-schema": {
273
273
  "types": "./dist/scan/sql-predicate-schema.d.ts",
274
274
  "import": "./dist/scan/sql-predicate-schema.js",
275
275
  "require": "./dist/scan/sql-predicate-schema.cjs"
276
276
  },
277
- "./scan/sql-predicate-types": {
277
+ "./query/sql-predicate-types": {
278
278
  "types": "./dist/scan/sql-predicate-types.d.ts",
279
279
  "import": "./dist/scan/sql-predicate-types.js",
280
280
  "require": "./dist/scan/sql-predicate-types.cjs"
281
281
  },
282
- "./scan/sql-predicate-zod": {
282
+ "./query/sql-predicate-zod": {
283
283
  "types": "./dist/scan/sql-predicate-zod.d.ts",
284
284
  "import": "./dist/scan/sql-predicate-zod.js",
285
285
  "require": "./dist/scan/sql-predicate-zod.cjs"
286
286
  },
287
- "./scan/sql-predicate": {
287
+ "./query/sql-predicate": {
288
288
  "types": "./dist/scan/sql-predicate.d.ts",
289
289
  "import": "./dist/scan/sql-predicate.js",
290
290
  "require": "./dist/scan/sql-predicate.cjs"
291
291
  },
292
- "./scan/table-query": {
292
+ "./query/table-query": {
293
293
  "types": "./dist/scan/table-query.d.ts",
294
294
  "import": "./dist/scan/table-query.js",
295
295
  "require": "./dist/scan/table-query.cjs"
296
296
  },
297
- "./scan/table-query-capabilities": {
297
+ "./query/table-query-capabilities": {
298
298
  "types": "./dist/scan/table-query-capabilities.d.ts",
299
299
  "import": "./dist/scan/table-query-capabilities.js",
300
300
  "require": "./dist/scan/table-query-capabilities.cjs"
301
301
  },
302
- "./scan/rows-to-arrow": {
302
+ "./query/rows-to-arrow": {
303
303
  "types": "./dist/scan/rows-to-arrow.d.ts",
304
304
  "import": "./dist/scan/rows-to-arrow.js",
305
305
  "require": "./dist/scan/rows-to-arrow.cjs"
306
306
  },
307
- "./scan/scan-engine": {
307
+ "./query/scan-engine": {
308
308
  "types": "./dist/scan/scan-engine.d.ts",
309
309
  "import": "./dist/scan/scan-engine.js",
310
310
  "require": "./dist/scan/scan-engine.cjs"
311
311
  },
312
- "./scan/scan-query": {
312
+ "./query/scan-query": {
313
313
  "types": "./dist/scan/scan-query.d.ts",
314
314
  "import": "./dist/scan/scan-query.js",
315
315
  "require": "./dist/scan/scan-query.cjs"
@@ -344,86 +344,6 @@
344
344
  "import": "./dist/arrow-worker-transport.js",
345
345
  "require": "./dist/arrow-worker-transport.cjs"
346
346
  },
347
- "./scan/arrow-execution": {
348
- "types": "./dist/scan/arrow-execution.d.ts",
349
- "import": "./dist/scan/arrow-execution.js",
350
- "require": "./dist/scan/arrow-execution.cjs"
351
- },
352
- "./query": {
353
- "types": "./dist/scan/index.d.ts",
354
- "import": "./dist/scan/index.js",
355
- "require": "./dist/scan/index.cjs"
356
- },
357
- "./query/arrow-query": {
358
- "types": "./dist/scan/arrow-query.d.ts",
359
- "import": "./dist/scan/arrow-query.js",
360
- "require": "./dist/scan/arrow-query.cjs"
361
- },
362
- "./query/bind-sql-predicate": {
363
- "types": "./dist/scan/bind-sql-predicate.d.ts",
364
- "import": "./dist/scan/bind-sql-predicate.js",
365
- "require": "./dist/scan/bind-sql-predicate.cjs"
366
- },
367
- "./query/parse-sql-predicate": {
368
- "types": "./dist/scan/parse-sql-predicate.d.ts",
369
- "import": "./dist/scan/parse-sql-predicate.js",
370
- "require": "./dist/scan/parse-sql-predicate.cjs"
371
- },
372
- "./query/query": {
373
- "types": "./dist/scan/query.d.ts",
374
- "import": "./dist/scan/query.js",
375
- "require": "./dist/scan/query.cjs"
376
- },
377
- "./query/query-arrow-table": {
378
- "types": "./dist/scan/query-arrow-table.d.ts",
379
- "import": "./dist/scan/query-arrow-table.js",
380
- "require": "./dist/scan/query-arrow-table.cjs"
381
- },
382
- "./query/sql-predicate-schema": {
383
- "types": "./dist/scan/sql-predicate-schema.d.ts",
384
- "import": "./dist/scan/sql-predicate-schema.js",
385
- "require": "./dist/scan/sql-predicate-schema.cjs"
386
- },
387
- "./query/sql-predicate-types": {
388
- "types": "./dist/scan/sql-predicate-types.d.ts",
389
- "import": "./dist/scan/sql-predicate-types.js",
390
- "require": "./dist/scan/sql-predicate-types.cjs"
391
- },
392
- "./query/sql-predicate-zod": {
393
- "types": "./dist/scan/sql-predicate-zod.d.ts",
394
- "import": "./dist/scan/sql-predicate-zod.js",
395
- "require": "./dist/scan/sql-predicate-zod.cjs"
396
- },
397
- "./query/sql-predicate": {
398
- "types": "./dist/scan/sql-predicate.d.ts",
399
- "import": "./dist/scan/sql-predicate.js",
400
- "require": "./dist/scan/sql-predicate.cjs"
401
- },
402
- "./query/table-query": {
403
- "types": "./dist/scan/table-query.d.ts",
404
- "import": "./dist/scan/table-query.js",
405
- "require": "./dist/scan/table-query.cjs"
406
- },
407
- "./query/table-query-capabilities": {
408
- "types": "./dist/scan/table-query-capabilities.d.ts",
409
- "import": "./dist/scan/table-query-capabilities.js",
410
- "require": "./dist/scan/table-query-capabilities.cjs"
411
- },
412
- "./query/rows-to-arrow": {
413
- "types": "./dist/scan/rows-to-arrow.d.ts",
414
- "import": "./dist/scan/rows-to-arrow.js",
415
- "require": "./dist/scan/rows-to-arrow.cjs"
416
- },
417
- "./query/scan-engine": {
418
- "types": "./dist/scan/scan-engine.d.ts",
419
- "import": "./dist/scan/scan-engine.js",
420
- "require": "./dist/scan/scan-engine.cjs"
421
- },
422
- "./query/scan-query": {
423
- "types": "./dist/scan/scan-query.d.ts",
424
- "import": "./dist/scan/scan-query.js",
425
- "require": "./dist/scan/scan-query.cjs"
426
- },
427
347
  "./query/arrow-execution": {
428
348
  "types": "./dist/scan/arrow-execution.d.ts",
429
349
  "import": "./dist/scan/arrow-execution.js",
@@ -484,17 +404,17 @@
484
404
  "build-constants": "esbuild src/constants/index.ts --bundle --platform=node --format=cjs --outfile=dist/constants/index.cjs"
485
405
  },
486
406
  "dependencies": {
487
- "@math.gl/core": "5.0.0-rc.2",
488
- "@math.gl/geometry": "5.0.0-rc.2",
489
- "@math.gl/geospatial": "5.0.0-rc.2",
490
- "@math.gl/sql": "5.0.0-rc.2",
491
- "@math.gl/tasks": "5.0.0-rc.2",
407
+ "@math.gl/core": "^5.0.0",
408
+ "@math.gl/geometry": "^5.0.0",
409
+ "@math.gl/geospatial": "^5.0.0",
410
+ "@math.gl/sql": "^5.0.0",
411
+ "@math.gl/tasks": "^5.0.0",
492
412
  "@types/geojson": "^7946.0.7",
493
413
  "apache-arrow": ">= 17.0.0",
494
414
  "probe.gl": "^5.0.0",
495
415
  "zod": "^4.1.12"
496
416
  },
497
- "gitHead": "a4faaba29ad530c05d89cbfa1285122b997e9892",
417
+ "gitHead": "a47963ae004cd33b2ecdffae5f06b594c956a2d5",
498
418
  "peerDependencies": {
499
419
  "sharp": "^0.35.5"
500
420
  },
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import * as arrow from 'apache-arrow';
6
- import {earcut} from '@math.gl/geometry';
6
+ import {earcut} from '@math.gl/geometry/polygon';
7
7
  import type {BinaryFeatureCollection, GeoArrowEncoding} from '@loaders.gl/core/schema';
8
8
  import type {TypedArray} from '@loaders.gl/core/schema';
9
9
  import {updateBoundsFromGeoArrowSamples} from './sampled-bounds';
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable indent */
6
- import {earcut} from '@math.gl/geometry';
6
+ import {earcut} from '@math.gl/geometry/polygon';
7
7
  import type {
8
8
  BinaryAttribute,
9
9
  BinaryFeatureCollection,
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {getPolygonSignedArea} from '@math.gl/geometry';
5
+ import {getPolygonSignedArea} from '@math.gl/geometry/polygon';
6
6
 
7
7
  import {Feature, Position, FlatFeature} from '@loaders.gl/core/schema';
8
8
 
@@ -14,7 +14,7 @@ import type {
14
14
  Table
15
15
  } from '@loaders.gl/core/schema';
16
16
  import {convertTable} from '@loaders.gl/core/schema-utils';
17
- import {earcut} from '@math.gl/geometry';
17
+ import {earcut} from '@math.gl/geometry/polygon';
18
18
  import type {GeoArrowBuilderEncoding} from '@loaders.gl/core/arrow-geometry';
19
19
  import {convertWKBToGeometry} from '@loaders.gl/core/arrow-geometry/geometry-codecs';
20
20
  import {convertWKTToGeometry} from '@loaders.gl/core/arrow-geometry/geometry-codecs';
@@ -116,6 +116,7 @@ export async function load(
116
116
  }
117
117
 
118
118
  resolvedOptions ||= getGlobalLoaderOptions();
119
+ let fetchedResponse: Response | undefined;
119
120
 
120
121
  if (typeof url === 'string' || isBlob(url)) {
121
122
  const selectedLoader = await selectLoader(url, resolvedLoaders as Loader | Loader[], {
@@ -123,31 +124,59 @@ export async function load(
123
124
  core: {...resolvedOptions?.core, nothrow: true}
124
125
  });
125
126
 
127
+ const canFetchBeforePreload = typeof url === 'string' && selectedLoader?.fetchBeforePreload;
126
128
  const loaderImplementation =
127
129
  selectedLoader && (typeof url === 'string' || selectedLoader.createDataSourceSync)
128
- ? await getLoaderImplementation(
130
+ ? getLoaderImplementation(
129
131
  selectedLoader,
130
132
  resolvedOptions,
131
133
  typeof url === 'string' ? url : undefined
132
134
  )
133
135
  : null;
136
+ if (canFetchBeforePreload) {
137
+ const loadOptions = resolvedOptions;
138
+ const controller = new AbortController();
139
+ const fetchOption = loadOptions.core?.fetch;
140
+ const callerSignal =
141
+ loadOptions.signal ||
142
+ context?.signal ||
143
+ (typeof fetchOption === 'object' ? fetchOption?.signal : undefined);
144
+ const signal = callerSignal
145
+ ? AbortSignal.any([callerSignal, controller.signal])
146
+ : controller.signal;
147
+ try {
148
+ [, fetchedResponse] = await Promise.all([
149
+ loaderImplementation,
150
+ resolveLoaderAuthenticationOptions(selectedLoader, url, loadOptions).then(options => {
151
+ signal.throwIfAborted();
152
+ resolvedOptions = resolveAuthenticationOptions(options);
153
+ const fetch = getFetchFunction({...resolvedOptions, signal}, context);
154
+ return fetch(applySearchParamsToUrl(url, resolvedOptions));
155
+ })
156
+ ]);
157
+ } catch (error) {
158
+ controller.abort(error);
159
+ throw error;
160
+ }
161
+ }
162
+ const implementation = await loaderImplementation;
134
163
  if (
135
164
  selectedLoader &&
136
- loaderImplementation?.createDataSourceSync &&
137
- !isLoaderWithParser(loaderImplementation)
165
+ implementation?.createDataSourceSync &&
166
+ !isLoaderWithParser(implementation)
138
167
  ) {
139
168
  throw new Error(
140
169
  `${selectedLoader.id} creates sources. Use createDataSource() instead of load().`
141
170
  );
142
171
  }
143
172
 
144
- if (selectedLoader && loaderImplementation && typeof url === 'string') {
173
+ if (!fetchedResponse && selectedLoader && implementation && typeof url === 'string') {
145
174
  resolvedOptions = await resolveLoaderAuthenticationOptions(
146
- selectedLoader.getAuthentications ? selectedLoader : loaderImplementation,
175
+ selectedLoader.getAuthentications ? selectedLoader : implementation,
147
176
  url,
148
177
  resolvedOptions || {}
149
178
  );
150
- const {parseUrl} = loaderImplementation;
179
+ const {parseUrl} = implementation;
151
180
  if (parseUrl) {
152
181
  const requestUrl = applySearchParamsToUrl(url, resolvedOptions);
153
182
  const options = normalizeOptions(resolvedOptions, selectedLoader, [selectedLoader], url);
@@ -164,7 +193,7 @@ export async function load(
164
193
  let data = url;
165
194
  // url is a string, fetch the url
166
195
  if (typeof url === 'string') {
167
- data = await fetch(applySearchParamsToUrl(url, resolvedOptions));
196
+ data = fetchedResponse ?? (await fetch(applySearchParamsToUrl(url, resolvedOptions)));
168
197
  // URL is Blob or File, fetchFile handles it (alt: we could generate ObjectURL here)
169
198
  }
170
199
 
@@ -185,8 +185,12 @@ async function parseWithLoader(
185
185
  let result: unknown;
186
186
 
187
187
  if (shouldParseWithWorker(loaderWithParser, data, parseOptions, context, loader)) {
188
- data = await getArrayBufferFromData(data, parseOptions);
189
- result = await parseWithWorker(loaderWithParser, data, parseOptions, context, parse);
188
+ // Start the worker while the response body downloads. Transfer only the complete buffer.
189
+ const input =
190
+ isResponse(data) && data.ok
191
+ ? getArrayBufferFromData(data, parseOptions)
192
+ : await getArrayBufferFromData(data, parseOptions);
193
+ result = await parseWithWorker(loaderWithParser, input, parseOptions, context, parse);
190
194
  } else if (isBlob(data) && loaderWithParser.parseBlob) {
191
195
  result = await loaderWithParser.parseBlob(data, parseOptions, context);
192
196
  } else {
@@ -3,8 +3,12 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {GetTileParameters, TileGrid, TileGridMatrix, TileGridLimits} from './tile-source';
6
- import {resolveTileIndex, validateTileMatrix, validateTileMatrixSet} from '@math.gl/geospatial';
7
- import type {TileMatrix, TileMatrixSet, VariableMatrixWidth} from '@math.gl/geospatial';
6
+ import {
7
+ resolveTileIndex,
8
+ validateTileMatrix,
9
+ validateTileMatrixSet
10
+ } from '@math.gl/geospatial/tiles';
11
+ import type {TileMatrix, TileMatrixSet, VariableMatrixWidth} from '@math.gl/geospatial/tiles';
8
12
 
9
13
  /**
10
14
  * Builds a tile grid from advertised per-level metadata. `tileMatrixSet` is set only when every
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {getTileBounds} from '@math.gl/geospatial';
5
+ import {getTileBounds} from '@math.gl/geospatial/tiles';
6
6
  import type {TileSource, GetTileParameters, GetTileDataParameters, TileGrid} from './tile-source';
7
7
  import type {ImageSource, ImageSourceMetadata} from './image-source';
8
8
  import {getRequestedTileMatrix, validateTileGrid, resolveTileGridTile} from './tile-grid';
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {CRSIdentifier} from '@math.gl/geospatial/crs';
6
- import type {TileMatrixLimits, TileMatrixSet, VariableMatrixWidth} from '@math.gl/geospatial';
6
+ import type {TileMatrixLimits, TileMatrixSet, VariableMatrixWidth} from '@math.gl/geospatial/tiles';
7
7
 
8
8
  /**
9
9
  * Props for a TileSource
@@ -185,6 +185,12 @@ export type Loader<
185
185
  * Can be used to avoid a later delay and may return a parser-bearing loader that also supports `parseSync`.
186
186
  */
187
187
  preload?: Preload;
188
+ /**
189
+ * Allows load() to fetch a URL while preloading this parser. Core must own the
190
+ * initial request, including authentication. Use only for loaders that parse
191
+ * a fetched response and declare any authentication hooks on their metadata.
192
+ */
193
+ fetchBeforePreload?: boolean;
188
194
  /** Contributes authentication constructors before requests; application constructors take precedence. */
189
195
  getAuthentications?: (
190
196
  url: string,
@@ -8,11 +8,10 @@ import {
8
8
  compileArrowScales,
9
9
  compileArrowScaleExpression,
10
10
  createStreamingDomainAccumulator,
11
- type CompiledArrowScale,
12
- parseSQLScaleExpression,
13
- type ParsedSQLScale,
14
- type ResolvedScale
11
+ type CompiledArrowScale
15
12
  } from '@math.gl/sql/scales';
13
+ import {parseSQLScaleExpression, type ParsedSQLScale} from '@math.gl/sql/parser';
14
+ import type {ResolvedScale} from '@math.gl/core/color';
16
15
  import {makeArrowTableFromBatches} from '@loaders.gl/core/schema-utils';
17
16
  import {compileArrowExpression, type CompiledArrowExpression} from '@math.gl/sql/arrow';
18
17
  import type {Expression} from '@math.gl/sql/expressions';
@@ -56,7 +56,7 @@ scanBackends.set('arrow', arrowScanBackend);
56
56
  *
57
57
  * This is the extension point for future DuckDB and GPU implementations. The backend package can
58
58
  * register a dynamic loader from application code while the public import remains
59
- * `@loaders.gl/core/scan`.
59
+ * `@loaders.gl/core/query`.
60
60
  */
61
61
  export function registerScanBackend(name: ScanBackendName, loader: ScanBackendLoader): void {
62
62
  if (!name || !loader) {
@@ -3,13 +3,10 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {
6
- isSQLPredicateParameter,
7
- type SQLPredicate,
8
- type SQLPredicateValue
9
- } from './sql-predicate-types';
10
-
11
- const MAXIMUM_PREDICATE_DEPTH = 64;
12
- const MAXIMUM_PREDICATE_NODES = 4096;
6
+ validateSQLPredicate as validateMathSQLPredicate,
7
+ type SQLPredicate as MathSQLPredicate
8
+ } from '@math.gl/sql/parser';
9
+ import type {SQLPredicate} from './sql-predicate-types';
13
10
 
14
11
  /**
15
12
  * JSON Schema for the JSON-serializable portion of the loaders.gl SQL predicate AST.
@@ -127,125 +124,17 @@ export function isSQLPredicate(value: unknown): value is SQLPredicate {
127
124
 
128
125
  /** Validates an unknown portable SQL predicate or throws a path-specific error. */
129
126
  export function validateSQLPredicate(value: unknown): asserts value is SQLPredicate {
130
- const state = {nodes: 0};
131
- validatePredicateNode(value, '$', 0, state);
127
+ validateMathSQLPredicate(value);
128
+ rejectPredicateCasts(value, '$');
132
129
  }
133
130
 
134
- /** Validates one recursive predicate node. */
135
- function validatePredicateNode(
136
- value: unknown,
137
- path: string,
138
- depth: number,
139
- state: {nodes: number}
140
- ): asserts value is SQLPredicate {
141
- if (depth > MAXIMUM_PREDICATE_DEPTH) {
142
- throw new Error(`SQL predicate ${path} exceeds the maximum nesting depth`);
143
- }
144
- state.nodes++;
145
- if (state.nodes > MAXIMUM_PREDICATE_NODES) {
146
- throw new Error('SQL predicate exceeds the maximum node count');
147
- }
148
- if (!isRecord(value) || !hasExactKeys(value, ['op', 'args'])) {
149
- throw new Error(`SQL predicate ${path} must contain only op and args`);
150
- }
151
- if (typeof value.op !== 'string' || !Array.isArray(value.args)) {
152
- throw new Error(`SQL predicate ${path} requires string op and array args`);
153
- }
154
-
155
- switch (value.op) {
156
- case 'and':
157
- case 'or':
158
- if (value.args.length < 2) {
159
- throw new Error(`SQL predicate ${path}.${value.op} requires at least two arguments`);
160
- }
161
- for (let index = 0; index < value.args.length; index++) {
162
- validatePredicateNode(value.args[index], `${path}.args[${index}]`, depth + 1, state);
163
- }
164
- return;
165
- case 'not':
166
- if (value.args.length !== 1) {
167
- throw new Error(`SQL predicate ${path}.not requires exactly one argument`);
168
- }
169
- validatePredicateNode(value.args[0], `${path}.args[0]`, depth + 1, state);
170
- return;
171
- case 'isNull':
172
- if (value.args.length !== 1) {
173
- throw new Error(`SQL predicate ${path}.isNull requires exactly one argument`);
174
- }
175
- validatePredicateProperty(value.args[0], `${path}.args[0]`);
176
- return;
177
- case 'in':
178
- if (value.args.length !== 2 || !Array.isArray(value.args[1]) || value.args[1].length === 0) {
179
- throw new Error(`SQL predicate ${path}.in requires a property and non-empty value list`);
180
- }
181
- validatePredicateProperty(value.args[0], `${path}.args[0]`);
182
- value.args[1].forEach((item, index) =>
183
- validatePredicateValue(item, `${path}.args[1][${index}]`)
184
- );
185
- return;
186
- case '=':
187
- case '<>':
188
- case '<':
189
- case '<=':
190
- case '>':
191
- case '>=':
192
- if (value.args.length !== 2) {
193
- throw new Error(`SQL predicate ${path}.${value.op} requires exactly two arguments`);
194
- }
195
- validatePredicateProperty(value.args[0], `${path}.args[0]`);
196
- validatePredicateValue(value.args[1], `${path}.args[1]`);
197
- return;
198
- default:
199
- throw new Error(`SQL predicate ${path} has unsupported operator ${JSON.stringify(value.op)}`);
131
+ /** Rejects casts after math.gl has validated the structure and bounded its depth. */
132
+ function rejectPredicateCasts(predicate: MathSQLPredicate, path: string): void {
133
+ if (predicate.op === 'and' || predicate.op === 'or' || predicate.op === 'not') {
134
+ predicate.args.forEach((child, index) =>
135
+ rejectPredicateCasts(child, path + '.args[' + index + ']')
136
+ );
137
+ } else if (Object.hasOwn(predicate.args[0], 'casts')) {
138
+ throw new Error('SQL predicate ' + path + '.args[0] requires a non-empty property reference');
200
139
  }
201
140
  }
202
-
203
- /** Validates one property reference. */
204
- function validatePredicateProperty(value: unknown, path: string): void {
205
- if (
206
- !isRecord(value) ||
207
- !hasAllowedKeys(value, ['property', 'quoted']) ||
208
- typeof value.property !== 'string' ||
209
- value.property.length === 0 ||
210
- (value.quoted !== undefined && typeof value.quoted !== 'boolean')
211
- ) {
212
- throw new Error(`SQL predicate ${path} requires a non-empty property reference`);
213
- }
214
- }
215
-
216
- /** Validates one structured-cloneable predicate scalar. */
217
- function validatePredicateValue(value: unknown, path: string): asserts value is SQLPredicateValue {
218
- if (isSQLPredicateParameter(value)) {
219
- return;
220
- }
221
- if (
222
- typeof value === 'boolean' ||
223
- typeof value === 'bigint' ||
224
- typeof value === 'string' ||
225
- value instanceof Uint8Array
226
- ) {
227
- return;
228
- }
229
- if (typeof value === 'number' && Number.isFinite(value)) {
230
- return;
231
- }
232
- if (value instanceof Date && Number.isFinite(value.getTime())) {
233
- return;
234
- }
235
- throw new Error(`SQL predicate ${path} contains an unsupported scalar value`);
236
- }
237
-
238
- /** Returns whether an unknown value is a non-null object. */
239
- function isRecord(value: unknown): value is Record<string, unknown> {
240
- return typeof value === 'object' && value !== null && !Array.isArray(value);
241
- }
242
-
243
- /** Returns whether an object contains exactly the expected enumerable keys. */
244
- function hasExactKeys(value: Record<string, unknown>, expectedKeys: readonly string[]): boolean {
245
- const keys = Object.keys(value);
246
- return keys.length === expectedKeys.length && expectedKeys.every(key => keys.includes(key));
247
- }
248
-
249
- function hasAllowedKeys(value: Record<string, unknown>, allowedKeys: readonly string[]): boolean {
250
- return Object.keys(value).every(key => allowedKeys.includes(key));
251
- }
@@ -24,7 +24,7 @@ const SQLPredicatePropertySchema = z
24
24
  /**
25
25
  * Optional Zod schema for validating the portable loaders.gl SQL predicate AST.
26
26
  *
27
- * Import from `@loaders.gl/core/scan/sql-predicate-zod`; the package root does not load Zod.
27
+ * Import from `@loaders.gl/core/query/sql-predicate-zod`; the package root does not load Zod.
28
28
  */
29
29
  export const SQLPredicateSchema: z.ZodType<SQLPredicate> = z.lazy(() =>
30
30
  z.union([