@loaders.gl/core 5.0.0-beta.7 → 5.0.0-beta.8

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 (233) hide show
  1. package/dist/arrow-geometry/geojson-table.cjs +26 -15
  2. package/dist/arrow-geometry/geojson-table.cjs.map +2 -2
  3. package/dist/arrow-geometry/geojson-table.d.ts +8 -1
  4. package/dist/arrow-geometry/geojson-table.d.ts.map +1 -1
  5. package/dist/arrow-geometry/geojson-table.js +18 -9
  6. package/dist/arrow-geometry/geojson-table.js.map +1 -1
  7. package/dist/cluster-source.cjs +78 -8
  8. package/dist/cluster-source.cjs.map +3 -3
  9. package/dist/dist.dev.js +354 -319
  10. package/dist/dist.min.js +3 -3
  11. package/dist/federated-table-scan-source.cjs +177 -176
  12. package/dist/federated-table-scan-source.cjs.map +2 -2
  13. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs +4 -8
  14. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs.map +2 -2
  15. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.d.ts.map +1 -1
  16. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js +4 -8
  17. package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js.map +1 -1
  18. package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.cjs +3 -2
  19. package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.cjs.map +2 -2
  20. package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.d.ts.map +1 -1
  21. package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.js +3 -2
  22. package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.js.map +1 -1
  23. package/dist/geoarrow/metadata/geoarrow-metadata.cjs +44 -2
  24. package/dist/geoarrow/metadata/geoarrow-metadata.cjs.map +4 -4
  25. package/dist/geoarrow/metadata/geoarrow-metadata.d.ts.map +1 -1
  26. package/dist/geoarrow/metadata/geoarrow-metadata.js +3 -4
  27. package/dist/geoarrow/metadata/geoarrow-metadata.js.map +1 -1
  28. package/dist/index.cjs +351 -281
  29. package/dist/index.cjs.map +3 -3
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/lib/api/create-data-source.d.ts +14 -9
  35. package/dist/lib/api/create-data-source.d.ts.map +1 -1
  36. package/dist/lib/api/create-data-source.js +55 -45
  37. package/dist/lib/api/create-data-source.js.map +1 -1
  38. package/dist/lib/api/encode.d.ts +1 -1
  39. package/dist/lib/api/encode.d.ts.map +1 -1
  40. package/dist/lib/api/encode.js +11 -2
  41. package/dist/lib/api/encode.js.map +1 -1
  42. package/dist/lib/api/load-in-batches.d.ts +3 -2
  43. package/dist/lib/api/load-in-batches.d.ts.map +1 -1
  44. package/dist/lib/api/load-in-batches.js.map +1 -1
  45. package/dist/lib/api/load-loader.d.ts +3 -3
  46. package/dist/lib/api/load-loader.d.ts.map +1 -1
  47. package/dist/lib/api/load-loader.js +14 -18
  48. package/dist/lib/api/load-loader.js.map +1 -1
  49. package/dist/lib/api/load.d.ts +7 -3
  50. package/dist/lib/api/load.d.ts.map +1 -1
  51. package/dist/lib/api/load.js +11 -64
  52. package/dist/lib/api/load.js.map +1 -1
  53. package/dist/lib/api/parse-file.d.ts +5 -3
  54. package/dist/lib/api/parse-file.d.ts.map +1 -1
  55. package/dist/lib/api/parse-file.js +12 -7
  56. package/dist/lib/api/parse-file.js.map +1 -1
  57. package/dist/lib/api/parse-in-batches.d.ts +5 -3
  58. package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
  59. package/dist/lib/api/parse-in-batches.js +14 -3
  60. package/dist/lib/api/parse-in-batches.js.map +1 -1
  61. package/dist/lib/api/parse-sync.d.ts +5 -3
  62. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  63. package/dist/lib/api/parse-sync.js +8 -6
  64. package/dist/lib/api/parse-sync.js.map +1 -1
  65. package/dist/lib/api/parse.d.ts +5 -3
  66. package/dist/lib/api/parse.d.ts.map +1 -1
  67. package/dist/lib/api/parse.js +26 -15
  68. package/dist/lib/api/parse.js.map +1 -1
  69. package/dist/lib/api/select-loader.d.ts +4 -2
  70. package/dist/lib/api/select-loader.d.ts.map +1 -1
  71. package/dist/lib/api/select-loader.js +43 -40
  72. package/dist/lib/api/select-loader.js.map +1 -1
  73. package/dist/lib/api/select-source.d.ts.map +1 -1
  74. package/dist/lib/api/select-source.js +1 -1
  75. package/dist/lib/api/select-source.js.map +1 -1
  76. package/dist/lib/init.js +1 -1
  77. package/dist/lib/loader-utils/loggers.d.ts +2 -37
  78. package/dist/lib/loader-utils/loggers.d.ts.map +1 -1
  79. package/dist/lib/loader-utils/loggers.js +2 -63
  80. package/dist/lib/loader-utils/loggers.js.map +1 -1
  81. package/dist/lib/loader-utils/native-arrow.d.ts +11 -0
  82. package/dist/lib/loader-utils/native-arrow.d.ts.map +1 -0
  83. package/dist/lib/loader-utils/native-arrow.js +52 -0
  84. package/dist/lib/loader-utils/native-arrow.js.map +1 -0
  85. package/dist/lib/loader-utils/option-defaults.js +2 -2
  86. package/dist/lib/loader-utils/option-defaults.js.map +1 -1
  87. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  88. package/dist/lib/loader-utils/option-utils.js +21 -10
  89. package/dist/lib/loader-utils/option-utils.js.map +1 -1
  90. package/dist/loader-utils/index.cjs +143 -42
  91. package/dist/loader-utils/index.cjs.map +3 -3
  92. package/dist/loader-utils/index.d.ts +2 -2
  93. package/dist/loader-utils/index.d.ts.map +1 -1
  94. package/dist/loader-utils/index.js +1 -1
  95. package/dist/loader-utils/index.js.map +1 -1
  96. package/dist/loader-utils/json-loader.js +1 -1
  97. package/dist/loader-utils/lib/log-utils/log.d.ts +24 -1
  98. package/dist/loader-utils/lib/log-utils/log.d.ts.map +1 -1
  99. package/dist/loader-utils/lib/log-utils/log.js +32 -1
  100. package/dist/loader-utils/lib/log-utils/log.js.map +1 -1
  101. package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts +5 -0
  102. package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts.map +1 -1
  103. package/dist/loader-utils/lib/scan-utils/logical-table-query.js +13 -5
  104. package/dist/loader-utils/lib/scan-utils/logical-table-query.js.map +1 -1
  105. package/dist/loader-utils/lib/scan-utils/table-query.d.ts +5 -1
  106. package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
  107. package/dist/loader-utils/lib/scan-utils/table-query.js +6 -0
  108. package/dist/loader-utils/lib/scan-utils/table-query.js.map +1 -1
  109. package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts +6 -1
  110. package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts.map +1 -1
  111. package/dist/loader-utils/lib/scan-utils/table-scan-batch.js +27 -20
  112. package/dist/loader-utils/lib/scan-utils/table-scan-batch.js.map +1 -1
  113. package/dist/loader-utils/lib/sources/data-source.js +3 -3
  114. package/dist/loader-utils/lib/sources/data-source.js.map +1 -1
  115. package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
  116. package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js +15 -1
  117. package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  118. package/dist/loader-utils/loader-types.d.ts +102 -27
  119. package/dist/loader-utils/loader-types.d.ts.map +1 -1
  120. package/dist/loader-utils/loader-types.js.map +1 -1
  121. package/dist/loader-utils/source-types.d.ts +5 -5
  122. package/dist/loader-utils/source-types.d.ts.map +1 -1
  123. package/dist/loader-utils/source-types.js +5 -1
  124. package/dist/loader-utils/source-types.js.map +1 -1
  125. package/dist/null-loader.js +1 -1
  126. package/dist/null-worker-node.js +1 -1
  127. package/dist/null-worker.js +1 -1
  128. package/dist/polyfills/index.cjs +3 -2
  129. package/dist/polyfills/index.d.ts.map +1 -1
  130. package/dist/polyfills/index.js +2 -2
  131. package/dist/polyfills/index.js.map +1 -1
  132. package/dist/scan/arrow-execution/expressions.cjs +9 -9
  133. package/dist/scan/arrow-execution/expressions.cjs.map +3 -3
  134. package/dist/scan/arrow-execution/expressions.d.ts +3 -3
  135. package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
  136. package/dist/scan/arrow-execution/expressions.js +4 -4
  137. package/dist/scan/arrow-execution/expressions.js.map +1 -1
  138. package/dist/scan/index.cjs +21 -6
  139. package/dist/scan/index.cjs.map +2 -2
  140. package/dist/scan/index.d.ts +2 -1
  141. package/dist/scan/index.d.ts.map +1 -1
  142. package/dist/scan/index.js +1 -1
  143. package/dist/scan/index.js.map +1 -1
  144. package/dist/scan/parse-sql-predicate.cjs +1 -1
  145. package/dist/scan/parse-sql-predicate.cjs.map +1 -1
  146. package/dist/scan/parse-sql-predicate.js +1 -1
  147. package/dist/scan/parse-sql-predicate.js.map +1 -1
  148. package/dist/scan/query-progressive.cjs +191 -0
  149. package/dist/scan/query-progressive.cjs.map +7 -0
  150. package/dist/scan/query-progressive.d.ts +39 -0
  151. package/dist/scan/query-progressive.d.ts.map +1 -0
  152. package/dist/scan/query-progressive.js +174 -0
  153. package/dist/scan/query-progressive.js.map +1 -0
  154. package/dist/scan/query.cjs +42 -8
  155. package/dist/scan/query.cjs.map +3 -3
  156. package/dist/scan/query.d.ts +26 -6
  157. package/dist/scan/query.d.ts.map +1 -1
  158. package/dist/scan/query.js +48 -7
  159. package/dist/scan/query.js.map +1 -1
  160. package/dist/schema-utils/index.cjs +262 -241
  161. package/dist/schema-utils/index.cjs.map +2 -2
  162. package/dist/schema-utils/index.d.ts +1 -0
  163. package/dist/schema-utils/index.d.ts.map +1 -1
  164. package/dist/schema-utils/index.js +1 -0
  165. package/dist/schema-utils/index.js.map +1 -1
  166. package/dist/schema-utils/lib/schema/deduce-table-schema.js +4 -2
  167. package/dist/schema-utils/lib/schema/deduce-table-schema.js.map +1 -1
  168. package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.d.ts +28 -0
  169. package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.d.ts.map +1 -0
  170. package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.js +26 -0
  171. package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.js.map +1 -0
  172. package/dist/schema-utils/lib/table/tables/row-utils.js +2 -2
  173. package/dist/schema-utils/lib/table/tables/row-utils.js.map +1 -1
  174. package/dist/vector-table-scan-source.cjs +2 -1
  175. package/dist/vector-table-scan-source.cjs.map +1 -1
  176. package/dist/worker-utils/index.cjs +49 -9
  177. package/dist/worker-utils/index.cjs.map +3 -3
  178. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  179. package/dist/worker-utils/lib/library-utils/library-utils.d.ts.map +1 -1
  180. package/dist/worker-utils/lib/library-utils/library-utils.js +2 -1
  181. package/dist/worker-utils/lib/library-utils/library-utils.js.map +1 -1
  182. package/dist/worker-utils/lib/process-utils/child-process-proxy.d.ts.map +1 -1
  183. package/dist/worker-utils/lib/process-utils/child-process-proxy.js +8 -7
  184. package/dist/worker-utils/lib/process-utils/child-process-proxy.js.map +1 -1
  185. package/dist/worker-utils/lib/worker-api/get-worker-url.d.ts.map +1 -1
  186. package/dist/worker-utils/lib/worker-api/get-worker-url.js +5 -2
  187. package/dist/worker-utils/lib/worker-api/get-worker-url.js.map +1 -1
  188. package/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js +1 -6
  189. package/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js.map +1 -1
  190. package/package.json +8 -7
  191. package/src/arrow-geometry/geojson-table.ts +27 -17
  192. package/src/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.ts +4 -11
  193. package/src/geoarrow/mesharrow/arrow-fixed-size-list-utils.ts +3 -2
  194. package/src/geoarrow/metadata/geoarrow-metadata.ts +3 -4
  195. package/src/index.ts +1 -1
  196. package/src/lib/api/create-data-source.ts +136 -58
  197. package/src/lib/api/encode.ts +14 -3
  198. package/src/lib/api/load-in-batches.ts +15 -7
  199. package/src/lib/api/load-loader.ts +21 -20
  200. package/src/lib/api/load.ts +49 -121
  201. package/src/lib/api/parse-file.ts +42 -23
  202. package/src/lib/api/parse-in-batches.ts +49 -12
  203. package/src/lib/api/parse-sync.ts +37 -19
  204. package/src/lib/api/parse.ts +51 -30
  205. package/src/lib/api/select-loader.ts +56 -53
  206. package/src/lib/api/select-source.ts +7 -1
  207. package/src/lib/loader-utils/loggers.ts +2 -70
  208. package/src/lib/loader-utils/native-arrow.ts +70 -0
  209. package/src/lib/loader-utils/option-defaults.ts +2 -2
  210. package/src/lib/loader-utils/option-utils.ts +21 -10
  211. package/src/loader-utils/index.ts +2 -1
  212. package/src/loader-utils/lib/log-utils/log.ts +39 -1
  213. package/src/loader-utils/lib/scan-utils/logical-table-query.ts +18 -8
  214. package/src/loader-utils/lib/scan-utils/table-query.ts +10 -1
  215. package/src/loader-utils/lib/scan-utils/table-scan-batch.ts +36 -25
  216. package/src/loader-utils/lib/sources/data-source.ts +3 -3
  217. package/src/loader-utils/lib/worker-loader-utils/parse-with-worker.ts +16 -1
  218. package/src/loader-utils/loader-types.ts +168 -43
  219. package/src/loader-utils/source-types.ts +12 -6
  220. package/src/polyfills/index.ts +3 -3
  221. package/src/scan/arrow-execution/expressions.ts +5 -5
  222. package/src/scan/index.ts +7 -1
  223. package/src/scan/parse-sql-predicate.ts +1 -1
  224. package/src/scan/query-progressive.ts +231 -0
  225. package/src/scan/query.ts +92 -10
  226. package/src/schema-utils/index.ts +5 -0
  227. package/src/schema-utils/lib/schema/deduce-table-schema.ts +4 -2
  228. package/src/schema-utils/lib/table/tables/convert-arrow-table-wrapper.ts +58 -0
  229. package/src/schema-utils/lib/table/tables/row-utils.ts +2 -2
  230. package/src/worker-utils/lib/library-utils/library-utils.ts +2 -1
  231. package/src/worker-utils/lib/process-utils/child-process-proxy.ts +8 -7
  232. package/src/worker-utils/lib/worker-api/get-worker-url.ts +4 -3
  233. package/src/worker-utils/lib/worker-utils/get-loadable-worker-url.ts +1 -6
@@ -2,18 +2,21 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
+ import {getNativeArrowOptions, unwrapArrowTable} from '../loader-utils/native-arrow';
6
+
5
7
  import {resolveLoaderAuthenticationOptions} from '@loaders.gl/core/loader-utils';
6
8
  import type {
9
+ LoaderArrayOptionsType,
10
+ LoaderShapeType,
11
+ LoaderOptionsType,
12
+ LoaderOptionsWithShape,
13
+ LoaderCallOptions,
7
14
  Loader,
8
15
  LoaderContext,
9
16
  LoaderOptions,
10
- LoaderOptionsWithShape,
11
17
  DataType,
12
18
  LoaderWithParser,
13
- LoaderOptionsType,
14
- LoaderShapeType,
15
19
  LoaderReturnType,
16
- LoaderArrayOptionsType,
17
20
  LoaderArrayReturnType,
18
21
  StrictLoaderOptions
19
22
  } from '@loaders.gl/core/loader-utils';
@@ -22,8 +25,7 @@ import {
22
25
  shouldParseWithWorker,
23
26
  mergeOptions,
24
27
  isResponse,
25
- isBlob,
26
- isSourceLoader
28
+ isBlob
27
29
  } from '@loaders.gl/core/loader-utils';
28
30
  import {validateWorkerVersion} from '@loaders.gl/core/worker-utils';
29
31
  import {isLoaderObject} from '../loader-utils/normalize-loader';
@@ -32,7 +34,7 @@ import {getArrayBufferOrStringFromData} from '../loader-utils/get-data';
32
34
  import {getArrayBufferFromData} from '../loader-utils/get-data';
33
35
  import {getLoaderContext, getLoadersFromContext} from '../loader-utils/loader-context';
34
36
  import {getResourceUrl} from '../utils/resource-utils';
35
- import {getLoaderImplementation} from './load-loader';
37
+ import {getLoaderImplementation, isLoaderWithParser} from './load-loader';
36
38
  import {selectLoader} from './select-loader';
37
39
 
38
40
  // type LoaderArrayType<T> = T extends (infer Loader)[] ? LoaderOptionsType<Loader> : T
@@ -40,31 +42,45 @@ import {selectLoader} from './select-loader';
40
42
  /**
41
43
  * Parses `data` asynchronously using the supplied loader
42
44
  */
45
+ export async function parse<LoaderT extends Loader>(
46
+ data: DataType | Promise<DataType>,
47
+ loader: LoaderT,
48
+ options?: undefined,
49
+ context?: LoaderContext
50
+ ): Promise<LoaderReturnType<LoaderT>>;
51
+
43
52
  export async function parse<
44
53
  LoaderT extends Loader,
45
- OptionsT extends LoaderOptions = LoaderOptionsWithShape<
54
+ const OptionsT extends LoaderOptions = LoaderOptionsWithShape<
46
55
  LoaderOptionsType<LoaderT>,
47
56
  LoaderShapeType<LoaderT>
48
57
  >
49
58
  >(
50
59
  data: DataType | Promise<DataType>,
51
60
  loader: LoaderT,
52
- options?: OptionsT,
61
+ options?: OptionsT & LoaderCallOptions<NoInfer<LoaderT>, NoInfer<OptionsT>>,
53
62
  context?: LoaderContext
54
- ): Promise<LoaderReturnType<LoaderT>>;
63
+ ): Promise<LoaderReturnType<LoaderT, OptionsT>>;
55
64
 
56
65
  /**
57
66
  * Parses `data` asynchronously by matching one of the supplied loader
58
67
  */
68
+ export async function parse<LoaderArrayT extends Loader[]>(
69
+ data: DataType | Promise<DataType>,
70
+ loaders: LoaderArrayT,
71
+ options?: undefined,
72
+ context?: LoaderContext
73
+ ): Promise<LoaderArrayReturnType<LoaderArrayT>>;
74
+
59
75
  export async function parse<
60
76
  LoaderArrayT extends Loader[],
61
- OptionsT extends LoaderOptions = LoaderArrayOptionsType<LoaderArrayT>
77
+ const OptionsT extends LoaderOptions = LoaderArrayOptionsType<LoaderArrayT>
62
78
  >(
63
79
  data: DataType | Promise<DataType>,
64
80
  loaders: LoaderArrayT,
65
81
  options?: OptionsT,
66
82
  context?: LoaderContext
67
- ): Promise<LoaderArrayReturnType<LoaderArrayT>>;
83
+ ): Promise<LoaderArrayReturnType<LoaderArrayT, OptionsT>>;
68
84
 
69
85
  /**
70
86
  * Parses data asynchronously by matching a pre-registered loader
@@ -116,12 +132,6 @@ export async function parse(
116
132
  return null;
117
133
  }
118
134
 
119
- if (isSourceLoader(loader)) {
120
- throw new Error(
121
- `${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parse().`
122
- );
123
- }
124
-
125
135
  // Normalize options
126
136
  // @ts-expect-error candidateLoaders
127
137
  const normalizedOptions = normalizeOptions(options, loader, candidateLoaders, url); // Could be invalid...
@@ -136,14 +146,16 @@ export async function parse(
136
146
  );
137
147
 
138
148
  // Get a context (if already present, will be unchanged)
149
+ const nativeArrowOptions = getNativeArrowOptions(loader, strictOptions, false);
139
150
  context = getLoaderContext(
140
151
  // @ts-expect-error
141
152
  {url, _parse: parse, loaders: candidateLoaders},
142
- strictOptions,
153
+ nativeArrowOptions || strictOptions,
143
154
  context || null
144
155
  );
145
156
 
146
- return await parseWithLoader(loader, data, strictOptions, context);
157
+ const result = await parseWithLoader(loader, data, nativeArrowOptions || strictOptions, context);
158
+ return nativeArrowOptions ? unwrapArrowTable(result) : result;
147
159
  }
148
160
 
149
161
  // TODO - should accept loader.parseAsyncIterator and concatenate.
@@ -168,18 +180,24 @@ async function parseWithLoader(
168
180
 
169
181
  const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
170
182
 
171
- if (shouldParseWithWorker(loaderWithParser, data, options, context, loader)) {
172
- data = await getArrayBufferFromData(data, options);
173
- return await parseWithWorker(loaderWithParser, data, options, context, parse);
183
+ if (loaderWithParser.createDataSourceSync && !isLoaderWithParser(loaderWithParser)) {
184
+ throw new Error(`${loader.id} creates sources. Use createDataSource() to open a source.`);
174
185
  }
175
186
 
176
- if (isBlob(data) && loaderWithParser.parseBlob) {
177
- return await loaderWithParser.parseBlob(data, options, context);
187
+ const output = loaderWithParser.prepareParseOutput?.(options);
188
+ const parseOptions = output?.options ?? options;
189
+ let result: unknown;
190
+
191
+ if (shouldParseWithWorker(loaderWithParser, data, parseOptions, context, loader)) {
192
+ data = await getArrayBufferFromData(data, parseOptions);
193
+ result = await parseWithWorker(loaderWithParser, data, parseOptions, context, parse);
194
+ } else if (isBlob(data) && loaderWithParser.parseBlob) {
195
+ result = await loaderWithParser.parseBlob(data, parseOptions, context);
196
+ } else {
197
+ data = await getArrayBufferOrStringFromData(data, loader, parseOptions);
198
+ result = await parseWithLoaderImplementation(loaderWithParser, data, parseOptions, context);
178
199
  }
179
-
180
- data = await getArrayBufferOrStringFromData(data, loader, options);
181
-
182
- return await parseWithLoaderImplementation(loaderWithParser, data, options, context);
200
+ return output ? output.convert(result) : result;
183
201
  }
184
202
 
185
203
  async function parseWithLoaderImplementation(
@@ -201,13 +219,16 @@ async function parseWithLoaderImplementation(
201
219
  return await loader.parse(data as ArrayBuffer, options, context);
202
220
  }
203
221
 
204
- // All parser-bearing sync loaders should also offer `parse` so async APIs can use them.
205
222
  if (loader.parseSync) {
206
223
  throw new Error(
207
224
  `${loader.name} loader: 'parse' not available on parser-bearing sync loader. Add an async 'parse' function to this loader, or call preload(loader) before parseSync(). ${context.url || ''}`
208
225
  );
209
226
  }
210
227
 
228
+ if (loader.createDataSourceSync) {
229
+ throw new Error(`${loader.id} creates sources. Use createDataSource() to open a source.`);
230
+ }
231
+
211
232
  // TBD - If asynchronous parser not available, return null
212
233
  throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
213
234
  }
@@ -34,12 +34,14 @@ const EXT_PATTERN = /\.([^.]+)$/;
34
34
  * @param loaders
35
35
  * @param options
36
36
  * @param context used internally, applications should not provide this parameter
37
+ * @param operation selects the URL matching priority for parsing or source creation
37
38
  */
38
39
  export async function selectLoader(
39
40
  data: DataType,
40
41
  loaders: Loader[] | Loader = [],
41
42
  options?: LoaderOptions,
42
- context?: LoaderContext
43
+ context?: LoaderContext,
44
+ operation: 'parse' | 'source' = 'parse'
43
45
  ): Promise<Loader | null> {
44
46
  if (!validHTTPResponse(data)) {
45
47
  return null;
@@ -48,40 +50,29 @@ export async function selectLoader(
48
50
  const normalizedOptions = normalizeLoaderOptions(options || {});
49
51
  normalizedOptions.core ||= {};
50
52
 
51
- if (data instanceof Response && mayContainText(data)) {
52
- const text = await data.clone().text();
53
- const textLoader = selectLoaderSync(
54
- text,
55
- loaders,
56
- {...normalizedOptions, core: {...normalizedOptions.core, nothrow: true}},
57
- context
58
- );
59
- if (textLoader) {
60
- return textLoader;
61
- }
53
+ if (loaders && !Array.isArray(loaders)) {
54
+ return normalizeLoader(loaders);
62
55
  }
63
56
 
64
- // First make a sync attempt, disabling exceptions
65
- let loader = selectLoaderSync(
66
- data,
67
- loaders,
68
- {...normalizedOptions, core: {...normalizedOptions.core, nothrow: true}},
69
- context
70
- );
71
- if (loader) {
72
- return loader;
73
- }
57
+ const text = data instanceof Response && mayContainText(data) ? await data.clone().text() : null;
58
+ let initialBytes: ArrayBuffer | undefined;
74
59
 
75
- // For Blobs and Files, try to asynchronously read a small initial slice and test again with that
76
- // to see if we can detect by initial content
77
- if (isBlob(data)) {
78
- data = await data.slice(0, 10).arrayBuffer();
79
- loader = selectLoaderSync(data, loaders, normalizedOptions, context);
60
+ async function matchCandidates(candidates: Loader[]): Promise<Loader | null> {
61
+ normalizeLoaders(candidates);
62
+ const loader =
63
+ (text !== null &&
64
+ selectLoaderInternal(text, candidates, normalizedOptions, context, operation)) ||
65
+ selectLoaderInternal(data, candidates, normalizedOptions, context, operation);
66
+ if (!loader && isBlob(data) && candidates.length) {
67
+ initialBytes ??= await data.slice(0, 10).arrayBuffer();
68
+ return selectLoaderInternal(initialBytes, candidates, normalizedOptions, context, operation);
69
+ }
70
+ return loader;
80
71
  }
81
72
 
82
- if (!loader && data instanceof Response && mayContainText(data)) {
83
- const text = await data.clone().text();
84
- loader = selectLoaderSync(text, loaders, normalizedOptions, context);
73
+ let loader = await matchCandidates(loaders || []);
74
+ if (!loader && !normalizedOptions.core.ignoreRegisteredLoaders) {
75
+ loader = await matchCandidates(getRegisteredLoaders());
85
76
  }
86
77
 
87
78
  // no loader available
@@ -110,12 +101,14 @@ function mayContainText(response: Response): boolean {
110
101
  * @param loaders
111
102
  * @param options
112
103
  * @param context used internally, applications should not provide this parameter
104
+ * @param operation selects the URL matching priority for parsing or source creation
113
105
  */
114
106
  export function selectLoaderSync(
115
107
  data: DataType,
116
108
  loaders: Loader[] | Loader = [],
117
109
  options?: LoaderOptions,
118
- context?: LoaderContext
110
+ context?: LoaderContext,
111
+ operation: 'parse' | 'source' = 'parse'
119
112
  ): Loader | null {
120
113
  if (!validHTTPResponse(data)) {
121
114
  return null;
@@ -132,22 +125,19 @@ export function selectLoaderSync(
132
125
  return normalizeLoader(loaders);
133
126
  }
134
127
 
135
- // Build list of candidate loaders that will be searched in order for a match
136
- let candidateLoaders: Loader[] = [];
137
- // First search supplied loaders
138
- if (loaders) {
139
- candidateLoaders = candidateLoaders.concat(loaders);
140
- }
141
- // Then fall back to registered loaders
142
- if (!normalizedOptions.core.ignoreRegisteredLoaders) {
143
- candidateLoaders.push(...getRegisteredLoaders());
128
+ const candidates = loaders || [];
129
+ normalizeLoaders(candidates);
130
+ let loader = selectLoaderInternal(data, candidates, normalizedOptions, context, operation);
131
+ if (!loader && !normalizedOptions.core.ignoreRegisteredLoaders) {
132
+ loader = selectLoaderInternal(
133
+ data,
134
+ getRegisteredLoaders(),
135
+ normalizedOptions,
136
+ context,
137
+ operation
138
+ );
144
139
  }
145
140
 
146
- // TODO - remove support for legacy loaders
147
- normalizeLoaders(candidateLoaders);
148
-
149
- const loader = selectLoaderInternal(data, candidateLoaders, normalizedOptions, context);
150
-
151
141
  // no loader available
152
142
  if (!loader && !normalizedOptions.core.nothrow) {
153
143
  throw new Error(getNoValidLoaderMessage(data));
@@ -162,7 +152,8 @@ function selectLoaderInternal(
162
152
  data: DataType,
163
153
  loaders: Loader[],
164
154
  options?: LoaderOptions,
165
- context?: LoaderContext
155
+ context?: LoaderContext,
156
+ operation: 'parse' | 'source' = 'parse'
166
157
  ) {
167
158
  const url = getResourceUrl(data);
168
159
  const type = getResourceMIMEType(data);
@@ -186,20 +177,32 @@ function selectLoaderInternal(
186
177
  reason = `match forced by supplied MIME type ${options?.core?.mimeType}`;
187
178
  }
188
179
 
189
- loader = loader || findSourceLoaderByTestURL(loaders, testUrl);
190
- reason = reason || (loader ? `matched source url ${testUrl}` : '');
180
+ // Source URL rules take priority only when opening a data source.
181
+ if (!loader && operation === 'source') {
182
+ loader = findSourceLoaderByTestURL(loaders, testUrl);
183
+ reason = loader ? `matched source url ${testUrl}` : '';
184
+ }
191
185
 
192
- // Look up loader by url
193
- loader = loader || findLoaderByUrl(loaders, testUrl);
186
+ // A declared source URL test is authoritative during automatic source selection.
187
+ const fallbackLoaders =
188
+ operation === 'source' && testUrl
189
+ ? loaders.filter(candidate => !isSourceLoader(candidate))
190
+ : loaders;
191
+ loader = loader || findLoaderByUrl(fallbackLoaders, testUrl);
194
192
  reason = reason || (loader ? `matched url ${testUrl}` : '');
195
193
 
194
+ if (!loader && operation === 'parse') {
195
+ loader = findSourceLoaderByTestURL(loaders, testUrl);
196
+ reason = loader ? `matched source url ${testUrl}` : '';
197
+ }
198
+
196
199
  // Look up loader by mime type
197
- loader = loader || findLoaderByMIMEType(loaders, type);
200
+ loader = loader || findLoaderByMIMEType(fallbackLoaders, type);
198
201
  reason = reason || (loader ? `matched MIME type ${type}` : '');
199
202
 
200
203
  // Look for loader via initial bytes (Note: not always accessible (e.g. Response, stream, async iterator)
201
204
  // @ts-ignore Blob | Response
202
- loader = loader || findLoaderByInitialBytes(loaders, data);
205
+ loader = loader || findLoaderByInitialBytes(fallbackLoaders, data);
203
206
  // @ts-ignore Blob | Response
204
207
  reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : '');
205
208
 
@@ -210,7 +213,7 @@ function selectLoaderInternal(
210
213
 
211
214
  // Look up loader by fallback mime type
212
215
  if (options?.core?.fallbackMimeType) {
213
- loader = loader || findLoaderByMIMEType(loaders, options?.core?.fallbackMimeType);
216
+ loader = loader || findLoaderByMIMEType(fallbackLoaders, options?.core?.fallbackMimeType);
214
217
  reason = reason || (loader ? `matched fallback MIME type ${type}` : '');
215
218
  }
216
219
 
@@ -18,7 +18,13 @@ export function selectSource(
18
18
  const type = options?.type || 'auto';
19
19
  let selectedSource: SourceLoader | null = null;
20
20
  if (type === 'auto') {
21
- selectedSource = selectLoaderSync(url, sources, {core: {nothrow: true}}) as SourceLoader | null;
21
+ selectedSource = selectLoaderSync(
22
+ url,
23
+ sources,
24
+ {core: {nothrow: true}},
25
+ undefined,
26
+ 'source'
27
+ ) as SourceLoader | null;
22
28
  } else {
23
29
  selectedSource = getSourceOfType(type, sources);
24
30
  }
@@ -2,73 +2,5 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- // probe.gl Log compatible loggers
6
-
7
- import {Log} from 'probe.gl/log';
8
-
9
- /** Default probe.gl logger used by loaders.gl. */
10
- export const probeLog = new Log({id: 'loaders.gl'});
11
-
12
- type LogFunction = () => void;
13
-
14
- /** Logger implementation that intentionally drops all messages. */
15
- export class NullLog {
16
- /** Drops a log message. */
17
- log(): LogFunction {
18
- return () => {};
19
- }
20
- /** Drops an info message. */
21
- info(): LogFunction {
22
- return () => {};
23
- }
24
- /** Logs one message once; no-op for the null logger. */
25
- once(): LogFunction {
26
- return () => {};
27
- }
28
- /** Drops a warning message. */
29
- warn(): LogFunction {
30
- return () => {};
31
- }
32
- /** Drops an error message. */
33
- error(): LogFunction {
34
- return () => {};
35
- }
36
- }
37
-
38
- /** Logger implementation that forwards messages to the global console. */
39
- export class ConsoleLog {
40
- /** Console-like object used for message output. */
41
- console;
42
- /** Messages already emitted through `once`. */
43
- private onceMessages = new Set<string>();
44
-
45
- /** Creates a console-backed logger. */
46
- constructor() {
47
- this.console = console; // eslint-disable-line
48
- }
49
- /** Logs a message to the console. */
50
- log(...args: unknown[]): LogFunction {
51
- return this.console.log.bind(this.console, ...args);
52
- }
53
- /** Logs an informational message to the console. */
54
- info(...args: unknown[]): LogFunction {
55
- return this.console.info.bind(this.console, ...args);
56
- }
57
- /** Logs one message once to the console. */
58
- once(...args: unknown[]): LogFunction {
59
- const message = String(args[0]);
60
- if (this.onceMessages.has(message)) {
61
- return () => {};
62
- }
63
- this.onceMessages.add(message);
64
- return this.console.info.bind(this.console, ...args);
65
- }
66
- /** Logs a warning message to the console. */
67
- warn(...args: unknown[]): LogFunction {
68
- return this.console.warn.bind(this.console, ...args);
69
- }
70
- /** Logs an error message to the console. */
71
- error(...args: unknown[]): LogFunction {
72
- return this.console.error.bind(this.console, ...args);
73
- }
74
- }
5
+ export {ConsoleLog} from 'probe.gl/log';
6
+ export {log as probeLog, NullLog} from '../../loader-utils/lib/log-utils/log';
@@ -0,0 +1,70 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type * as arrow from 'apache-arrow';
6
+ import type {Loader, StrictLoaderOptions} from '@loaders.gl/core/loader-utils';
7
+
8
+ /** Finds the option namespace used by a loader for shape selection. */
9
+ export function getShapeOptionKey(loader: Loader): string | undefined {
10
+ const keys = Object.keys(loader.options || {}).filter(key => {
11
+ const value = loader.options?.[key];
12
+ return key !== 'core' && value && typeof value === 'object' && 'shape' in value;
13
+ });
14
+ return keys.includes(loader.id) ? loader.id : keys.length === 1 ? keys[0] : undefined;
15
+ }
16
+
17
+ /** Keeps native Arrow selection at the API boundary; parsers and workers receive wrappers. */
18
+ export function getNativeArrowOptions(
19
+ loader: Loader,
20
+ options: StrictLoaderOptions,
21
+ inBatches = false
22
+ ): StrictLoaderOptions | null {
23
+ const key = getShapeOptionKey(loader);
24
+ const scopedOptions = key && options[key];
25
+ if (
26
+ !scopedOptions ||
27
+ typeof scopedOptions !== 'object' ||
28
+ !('shape' in scopedOptions) ||
29
+ scopedOptions.shape !== 'arrow'
30
+ ) {
31
+ return null;
32
+ }
33
+ if (inBatches && options.core?.metadata) {
34
+ throw new Error(
35
+ 'shape: "arrow" does not support core.metadata; use "arrow-table" for batch metadata'
36
+ );
37
+ }
38
+ return {
39
+ ...options,
40
+ core: {...options.core, ...(options.core?.shape === 'arrow' ? {shape: 'arrow-table'} : {})},
41
+ [key!]: {...scopedOptions, shape: 'arrow-table'}
42
+ };
43
+ }
44
+
45
+ /** Returns the hydrated native table without copying its columns. */
46
+ export function unwrapArrowTable(result: unknown): arrow.Table {
47
+ const table = result as {shape?: string; data?: arrow.Table} | null;
48
+ if (table?.shape !== 'arrow-table' || !table.data || !Array.isArray(table.data.batches)) {
49
+ throw new Error('shape: "arrow" requires a loader that supports "arrow-table" output');
50
+ }
51
+ return table.data;
52
+ }
53
+
54
+ /** Yields every record batch, preserving order and iterator cancellation. */
55
+ export async function* unwrapArrowBatches(
56
+ batches: AsyncIterable<unknown> | Iterable<unknown>
57
+ ): AsyncIterable<arrow.RecordBatch> {
58
+ for await (const batch of batches) {
59
+ const batchType = (batch as {batchType?: string} | null)?.batchType;
60
+ // JSON parsers can emit document metadata and partial/final document envelopes.
61
+ if (
62
+ batchType === 'metadata' ||
63
+ batchType === 'partial-result' ||
64
+ batchType === 'final-result'
65
+ ) {
66
+ continue;
67
+ }
68
+ yield* unwrapArrowTable(batch).batches;
69
+ }
70
+ }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type {LoaderOptions} from '@loaders.gl/core/loader-utils';
6
6
  import {isBrowser} from '@loaders.gl/core/loader-utils';
7
- import {ConsoleLog} from './loggers';
7
+ import {probeLog} from './loggers';
8
8
 
9
9
  export const DEFAULT_LOADER_OPTIONS: LoaderOptions = {
10
10
  searchParams: undefined,
@@ -17,7 +17,7 @@ export const DEFAULT_LOADER_OPTIONS: LoaderOptions = {
17
17
  ignoreRegisteredLoaders: undefined,
18
18
  nothrow: false,
19
19
  shape: undefined,
20
- log: new ConsoleLog(), // A probe.gl compatible (`log.log()()` syntax) that just logs to console
20
+ log: probeLog,
21
21
  useLocalLibraries: false,
22
22
  subloaders: undefined,
23
23
 
@@ -9,10 +9,12 @@ import {
9
9
  isPureObject,
10
10
  isObject,
11
11
  StrictLoaderOptions,
12
+ getLoaderLog,
12
13
  path
13
14
  } from '@loaders.gl/core/loader-utils';
14
- import {probeLog, NullLog} from './loggers';
15
+ import {probeLog} from './loggers';
15
16
  import {DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS} from './option-defaults';
17
+ import {getShapeOptionKey} from './native-arrow';
16
18
  import {stripQueryString} from '../utils/url-utils';
17
19
 
18
20
  const CORE_LOADER_OPTION_KEYS = [
@@ -274,16 +276,21 @@ function normalizeOptionsInternal(
274
276
  }
275
277
  moveDeprecatedTopLevelOptionsToCore(mergedOptions);
276
278
 
277
- // LOGGING: options.log can be set to `null` to defeat logging
278
- if (mergedOptions.core?.log === null) {
279
- mergedOptions.core = {...mergedOptions.core, log: new NullLog()};
279
+ const shapeKey = loader.defaultShape && getShapeOptionKey(loader);
280
+ if (shapeKey) {
281
+ mergedOptions[shapeKey] = {
282
+ ...(loaderDefaultOptions[shapeKey] as object),
283
+ shape: loader.defaultShape
284
+ };
280
285
  }
281
-
282
286
  mergeNestedFields(mergedOptions, normalizeLoaderOptions(getGlobalLoaderOptions()));
283
287
 
284
288
  const userOptions = normalizeLoaderOptions(options);
285
289
  mergeNestedFields(mergedOptions, userOptions);
286
290
  applyCoreShapeDefault(mergedOptions, userOptions, loader);
291
+ if (mergedOptions.core?.log === null) {
292
+ mergedOptions.core = {...mergedOptions.core, log: getLoaderLog(mergedOptions)};
293
+ }
287
294
 
288
295
  addUrlOptions(mergedOptions, url);
289
296
  addDeprecatedTopLevelOptions(mergedOptions);
@@ -308,23 +315,27 @@ function applyCoreShapeDefault(
308
315
  return;
309
316
  }
310
317
 
311
- const loaderScopedDefaults = loader.options?.[loader.id];
318
+ const shapeOptionKey = getShapeOptionKey(loader);
319
+ if (!shapeOptionKey) {
320
+ return;
321
+ }
322
+ const loaderScopedDefaults = loader.options?.[shapeOptionKey];
312
323
  if (!isPureObject(loaderScopedDefaults) || !('shape' in loaderScopedDefaults)) {
313
324
  return;
314
325
  }
315
326
 
316
- const globalLoaderScopedOptions = getGlobalLoaderOptions()[loader.id];
327
+ const globalLoaderScopedOptions = getGlobalLoaderOptions()[shapeOptionKey];
317
328
  if (isPureObject(globalLoaderScopedOptions) && 'shape' in globalLoaderScopedOptions) {
318
329
  return;
319
330
  }
320
331
 
321
- const userLoaderScopedOptions = userOptions[loader.id];
332
+ const userLoaderScopedOptions = userOptions[shapeOptionKey];
322
333
  if (isPureObject(userLoaderScopedOptions) && 'shape' in userLoaderScopedOptions) {
323
334
  return;
324
335
  }
325
336
 
326
- const loaderScopedOptions = mergedOptions[loader.id];
327
- mergedOptions[loader.id] = {
337
+ const loaderScopedOptions = mergedOptions[shapeOptionKey];
338
+ mergedOptions[shapeOptionKey] = {
328
339
  ...(isPureObject(loaderScopedOptions) ? loaderScopedOptions : {}),
329
340
  shape: coreShape
330
341
  };
@@ -35,6 +35,7 @@ export type {
35
35
  LoaderOptions,
36
36
  LoaderShapeType,
37
37
  LoaderOptionsWithShape,
38
+ LoaderCallOptions,
38
39
  LoaderOptionsType,
39
40
  LoaderReturnType,
40
41
  LoaderBatchType,
@@ -71,7 +72,7 @@ export {
71
72
  document
72
73
  } from './lib/env-utils/globals';
73
74
 
74
- export {log} from './lib/log-utils/log';
75
+ export {log, getLoaderLog} from './lib/log-utils/log';
75
76
 
76
77
  export type {ReadableStreamType} from './lib/javascript-utils/is-type';
77
78
  export {
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Log} from 'probe.gl/log';
5
+ import {Log, type Logger} from 'probe.gl/log';
6
6
 
7
7
  // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
8
8
  // __VERSION__ is injected by babel-plugin-version-inline
@@ -26,3 +26,41 @@ function createLog() {
26
26
  }
27
27
 
28
28
  export const log = createLog();
29
+
30
+ /** A logger that discards messages. */
31
+ export class NullLog implements Logger {
32
+ /** Discards debug messages. */
33
+ log() {
34
+ return ignoreMessage;
35
+ }
36
+ /** Discards informational messages. */
37
+ info() {
38
+ return ignoreMessage;
39
+ }
40
+ /** Discards messages marked to be emitted once. */
41
+ once() {
42
+ return ignoreMessage;
43
+ }
44
+ /** Discards warnings. */
45
+ warn() {
46
+ return ignoreMessage;
47
+ }
48
+ /** Discards errors. */
49
+ error() {
50
+ return ignoreMessage;
51
+ }
52
+ }
53
+
54
+ /** Discards a deferred log message. */
55
+ function ignoreMessage(): void {}
56
+
57
+ const nullLog = new NullLog();
58
+
59
+ /** Resolves a caller's operation logger. A null logger suppresses diagnostics. */
60
+ export function getLoaderLog(options?: {
61
+ core?: {log?: Logger | null};
62
+ log?: Logger | null;
63
+ }): Logger {
64
+ const logger = options?.core?.log !== undefined ? options.core.log : options?.log;
65
+ return logger === null ? nullLog : logger || log;
66
+ }