@loaders.gl/core 5.0.0-beta.6 → 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.
- package/dist/arrow-geometry/geojson-table.cjs +26 -15
- package/dist/arrow-geometry/geojson-table.cjs.map +2 -2
- package/dist/arrow-geometry/geojson-table.d.ts +8 -1
- package/dist/arrow-geometry/geojson-table.d.ts.map +1 -1
- package/dist/arrow-geometry/geojson-table.js +18 -9
- package/dist/arrow-geometry/geojson-table.js.map +1 -1
- package/dist/cluster-source.cjs +78 -8
- package/dist/cluster-source.cjs.map +3 -3
- package/dist/dist.dev.js +354 -319
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +187 -179
- package/dist/federated-table-scan-source.cjs.map +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs +4 -8
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs.map +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.d.ts.map +1 -1
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js +4 -8
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js.map +1 -1
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.cjs +3 -2
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.cjs.map +2 -2
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.d.ts.map +1 -1
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.js +3 -2
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.js.map +1 -1
- package/dist/geoarrow/metadata/geoarrow-metadata.cjs +44 -2
- package/dist/geoarrow/metadata/geoarrow-metadata.cjs.map +4 -4
- package/dist/geoarrow/metadata/geoarrow-metadata.d.ts.map +1 -1
- package/dist/geoarrow/metadata/geoarrow-metadata.js +3 -4
- package/dist/geoarrow/metadata/geoarrow-metadata.js.map +1 -1
- package/dist/index.cjs +351 -281
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/api/create-data-source.d.ts +14 -9
- package/dist/lib/api/create-data-source.d.ts.map +1 -1
- package/dist/lib/api/create-data-source.js +55 -45
- package/dist/lib/api/create-data-source.js.map +1 -1
- package/dist/lib/api/encode.d.ts +1 -1
- package/dist/lib/api/encode.d.ts.map +1 -1
- package/dist/lib/api/encode.js +11 -2
- package/dist/lib/api/encode.js.map +1 -1
- package/dist/lib/api/load-in-batches.d.ts +3 -2
- package/dist/lib/api/load-in-batches.d.ts.map +1 -1
- package/dist/lib/api/load-in-batches.js.map +1 -1
- package/dist/lib/api/load-loader.d.ts +3 -3
- package/dist/lib/api/load-loader.d.ts.map +1 -1
- package/dist/lib/api/load-loader.js +14 -18
- package/dist/lib/api/load-loader.js.map +1 -1
- package/dist/lib/api/load.d.ts +7 -3
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +11 -64
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse-file.d.ts +5 -3
- package/dist/lib/api/parse-file.d.ts.map +1 -1
- package/dist/lib/api/parse-file.js +12 -7
- package/dist/lib/api/parse-file.js.map +1 -1
- package/dist/lib/api/parse-in-batches.d.ts +5 -3
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +14 -3
- package/dist/lib/api/parse-in-batches.js.map +1 -1
- package/dist/lib/api/parse-sync.d.ts +5 -3
- package/dist/lib/api/parse-sync.d.ts.map +1 -1
- package/dist/lib/api/parse-sync.js +8 -6
- package/dist/lib/api/parse-sync.js.map +1 -1
- package/dist/lib/api/parse.d.ts +5 -3
- package/dist/lib/api/parse.d.ts.map +1 -1
- package/dist/lib/api/parse.js +26 -15
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/api/select-loader.d.ts +4 -2
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +43 -40
- package/dist/lib/api/select-loader.js.map +1 -1
- package/dist/lib/api/select-source.d.ts.map +1 -1
- package/dist/lib/api/select-source.js +1 -1
- package/dist/lib/api/select-source.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/loader-utils/loggers.d.ts +2 -37
- package/dist/lib/loader-utils/loggers.d.ts.map +1 -1
- package/dist/lib/loader-utils/loggers.js +2 -63
- package/dist/lib/loader-utils/loggers.js.map +1 -1
- package/dist/lib/loader-utils/native-arrow.d.ts +11 -0
- package/dist/lib/loader-utils/native-arrow.d.ts.map +1 -0
- package/dist/lib/loader-utils/native-arrow.js +52 -0
- package/dist/lib/loader-utils/native-arrow.js.map +1 -0
- package/dist/lib/loader-utils/option-defaults.js +2 -2
- package/dist/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +21 -10
- package/dist/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/loader-utils/index.cjs +143 -42
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/index.d.ts +2 -2
- package/dist/loader-utils/index.d.ts.map +1 -1
- package/dist/loader-utils/index.js +1 -1
- package/dist/loader-utils/index.js.map +1 -1
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.d.ts +24 -1
- package/dist/loader-utils/lib/log-utils/log.d.ts.map +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +32 -1
- package/dist/loader-utils/lib/log-utils/log.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts +5 -0
- package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/logical-table-query.js +13 -5
- package/dist/loader-utils/lib/scan-utils/logical-table-query.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts +5 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.js +6 -0
- package/dist/loader-utils/lib/scan-utils/table-query.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts +6 -1
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.js +27 -20
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.js.map +1 -1
- package/dist/loader-utils/lib/sources/data-source.js +3 -3
- package/dist/loader-utils/lib/sources/data-source.js.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js +15 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +102 -27
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/loader-utils/loader-types.js.map +1 -1
- package/dist/loader-utils/source-types.d.ts +5 -5
- package/dist/loader-utils/source-types.d.ts.map +1 -1
- package/dist/loader-utils/source-types.js +5 -1
- package/dist/loader-utils/source-types.js.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/polyfills/index.cjs +3 -2
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +2 -2
- package/dist/polyfills/index.js.map +1 -1
- package/dist/scan/arrow-execution/expressions.cjs +110 -0
- package/dist/scan/arrow-execution/expressions.cjs.map +7 -0
- package/dist/scan/arrow-execution/expressions.d.ts +9 -0
- package/dist/scan/arrow-execution/expressions.d.ts.map +1 -0
- package/dist/scan/arrow-execution/expressions.js +60 -0
- package/dist/scan/arrow-execution/expressions.js.map +1 -0
- package/dist/scan/arrow-execution/filter-arrow-table.cjs +15 -3
- package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +2 -2
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts +2 -0
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.js +10 -2
- package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -1
- package/dist/scan/index.cjs +21 -6
- package/dist/scan/index.cjs.map +2 -2
- package/dist/scan/index.d.ts +2 -1
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +1 -1
- package/dist/scan/index.js.map +1 -1
- package/dist/scan/parse-sql-predicate.cjs +3 -294
- package/dist/scan/parse-sql-predicate.cjs.map +3 -3
- package/dist/scan/parse-sql-predicate.d.ts +1 -7
- package/dist/scan/parse-sql-predicate.d.ts.map +1 -1
- package/dist/scan/parse-sql-predicate.js +5 -307
- package/dist/scan/parse-sql-predicate.js.map +1 -1
- package/dist/scan/query-progressive.cjs +191 -0
- package/dist/scan/query-progressive.cjs.map +7 -0
- package/dist/scan/query-progressive.d.ts +39 -0
- package/dist/scan/query-progressive.d.ts.map +1 -0
- package/dist/scan/query-progressive.js +174 -0
- package/dist/scan/query-progressive.js.map +1 -0
- package/dist/scan/query.cjs +143 -22
- package/dist/scan/query.cjs.map +3 -3
- package/dist/scan/query.d.ts +27 -9
- package/dist/scan/query.d.ts.map +1 -1
- package/dist/scan/query.js +180 -18
- package/dist/scan/query.js.map +1 -1
- package/dist/schema-utils/index.cjs +262 -241
- package/dist/schema-utils/index.cjs.map +2 -2
- package/dist/schema-utils/index.d.ts +1 -0
- package/dist/schema-utils/index.d.ts.map +1 -1
- package/dist/schema-utils/index.js +1 -0
- package/dist/schema-utils/index.js.map +1 -1
- package/dist/schema-utils/lib/schema/deduce-table-schema.js +4 -2
- package/dist/schema-utils/lib/schema/deduce-table-schema.js.map +1 -1
- package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.d.ts +28 -0
- package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.d.ts.map +1 -0
- package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.js +26 -0
- package/dist/schema-utils/lib/table/tables/convert-arrow-table-wrapper.js.map +1 -0
- package/dist/schema-utils/lib/table/tables/row-utils.js +2 -2
- package/dist/schema-utils/lib/table/tables/row-utils.js.map +1 -1
- package/dist/vector-table-scan-source.cjs +12 -4
- package/dist/vector-table-scan-source.cjs.map +1 -1
- package/dist/worker-utils/index.cjs +49 -9
- package/dist/worker-utils/index.cjs.map +3 -3
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/library-utils/library-utils.d.ts.map +1 -1
- package/dist/worker-utils/lib/library-utils/library-utils.js +2 -1
- package/dist/worker-utils/lib/library-utils/library-utils.js.map +1 -1
- package/dist/worker-utils/lib/process-utils/child-process-proxy.d.ts.map +1 -1
- package/dist/worker-utils/lib/process-utils/child-process-proxy.js +8 -7
- package/dist/worker-utils/lib/process-utils/child-process-proxy.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/get-worker-url.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/get-worker-url.js +5 -2
- package/dist/worker-utils/lib/worker-api/get-worker-url.js.map +1 -1
- package/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js +1 -6
- package/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js.map +1 -1
- package/package.json +8 -7
- package/src/arrow-geometry/geojson-table.ts +27 -17
- package/src/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.ts +4 -11
- package/src/geoarrow/mesharrow/arrow-fixed-size-list-utils.ts +3 -2
- package/src/geoarrow/metadata/geoarrow-metadata.ts +3 -4
- package/src/index.ts +1 -1
- package/src/lib/api/create-data-source.ts +136 -58
- package/src/lib/api/encode.ts +14 -3
- package/src/lib/api/load-in-batches.ts +15 -7
- package/src/lib/api/load-loader.ts +21 -20
- package/src/lib/api/load.ts +49 -121
- package/src/lib/api/parse-file.ts +42 -23
- package/src/lib/api/parse-in-batches.ts +49 -12
- package/src/lib/api/parse-sync.ts +37 -19
- package/src/lib/api/parse.ts +51 -30
- package/src/lib/api/select-loader.ts +56 -53
- package/src/lib/api/select-source.ts +7 -1
- package/src/lib/loader-utils/loggers.ts +2 -70
- package/src/lib/loader-utils/native-arrow.ts +70 -0
- package/src/lib/loader-utils/option-defaults.ts +2 -2
- package/src/lib/loader-utils/option-utils.ts +21 -10
- package/src/loader-utils/index.ts +2 -1
- package/src/loader-utils/lib/log-utils/log.ts +39 -1
- package/src/loader-utils/lib/scan-utils/logical-table-query.ts +18 -8
- package/src/loader-utils/lib/scan-utils/table-query.ts +10 -1
- package/src/loader-utils/lib/scan-utils/table-scan-batch.ts +36 -25
- package/src/loader-utils/lib/sources/data-source.ts +3 -3
- package/src/loader-utils/lib/worker-loader-utils/parse-with-worker.ts +16 -1
- package/src/loader-utils/loader-types.ts +168 -43
- package/src/loader-utils/source-types.ts +12 -6
- package/src/polyfills/index.ts +3 -3
- package/src/scan/arrow-execution/expressions.ts +86 -0
- package/src/scan/arrow-execution/filter-arrow-table.ts +19 -3
- package/src/scan/index.ts +7 -1
- package/src/scan/parse-sql-predicate.ts +8 -367
- package/src/scan/query-progressive.ts +231 -0
- package/src/scan/query.ts +247 -24
- package/src/schema-utils/index.ts +5 -0
- package/src/schema-utils/lib/schema/deduce-table-schema.ts +4 -2
- package/src/schema-utils/lib/table/tables/convert-arrow-table-wrapper.ts +58 -0
- package/src/schema-utils/lib/table/tables/row-utils.ts +2 -2
- package/src/worker-utils/lib/library-utils/library-utils.ts +2 -1
- package/src/worker-utils/lib/process-utils/child-process-proxy.ts +8 -7
- package/src/worker-utils/lib/worker-api/get-worker-url.ts +4 -3
- package/src/worker-utils/lib/worker-utils/get-loadable-worker-url.ts +1 -6
- package/dist/scan/parse-sql-query.cjs +0 -70
- package/dist/scan/parse-sql-query.cjs.map +0 -7
- package/dist/scan/parse-sql-query.d.ts +0 -5
- package/dist/scan/parse-sql-query.d.ts.map +0 -1
- package/dist/scan/parse-sql-query.js +0 -49
- package/dist/scan/parse-sql-query.js.map +0 -1
- package/dist/scan/parse-sql-select.cjs +0 -215
- package/dist/scan/parse-sql-select.cjs.map +0 -7
- package/dist/scan/parse-sql-select.d.ts +0 -38
- package/dist/scan/parse-sql-select.d.ts.map +0 -1
- package/dist/scan/parse-sql-select.js +0 -208
- package/dist/scan/parse-sql-select.js.map +0 -1
- package/src/scan/parse-sql-query.ts +0 -53
- package/src/scan/parse-sql-select.ts +0 -220
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
planTableQuery,
|
|
12
12
|
validateTableQueryLimit,
|
|
13
|
+
validateTableQueryOffset,
|
|
13
14
|
type TableQuery,
|
|
14
15
|
type TableReference,
|
|
15
16
|
type TableQueryPlanStep
|
|
@@ -31,6 +32,8 @@ export type NormalizedTableQuery<PredicateT = ColumnarPredicate> = Readonly<{
|
|
|
31
32
|
select: readonly NormalizedTableSelection[];
|
|
32
33
|
/** Predicate resolved against source names before aliases. */
|
|
33
34
|
where?: PredicateT;
|
|
35
|
+
/** Global number of filtered rows skipped before applying the limit. */
|
|
36
|
+
offset?: number;
|
|
34
37
|
/** Global post-filter row limit. */
|
|
35
38
|
limit?: number;
|
|
36
39
|
}>;
|
|
@@ -46,6 +49,7 @@ export type LogicalTableQueryProjectStep = Readonly<{
|
|
|
46
49
|
/** Scan, filter, aliased projection, and limit operations in execution order. */
|
|
47
50
|
export type LogicalTableQueryPlan<PredicateT = ColumnarPredicate> = readonly (
|
|
48
51
|
| Exclude<TableQueryPlanStep<PredicateT>, {kind: 'project'}>
|
|
52
|
+
| Readonly<{kind: 'offset'; offset: number}>
|
|
49
53
|
| LogicalTableQueryProjectStep
|
|
50
54
|
)[];
|
|
51
55
|
|
|
@@ -60,7 +64,7 @@ export function normalizeTableQuery<
|
|
|
60
64
|
throw new Error('Table query must be an object.');
|
|
61
65
|
}
|
|
62
66
|
for (const key of Object.keys(query)) {
|
|
63
|
-
if (!['from', 'select', 'where', 'limit'].includes(key)) {
|
|
67
|
+
if (!['from', 'select', 'where', 'offset', 'limit'].includes(key)) {
|
|
64
68
|
throw new Error(`Unsupported table query option: ${key}`);
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -68,6 +72,7 @@ export function normalizeTableQuery<
|
|
|
68
72
|
throw new Error('Table query select must be a non-empty array.');
|
|
69
73
|
}
|
|
70
74
|
validateTableReference(query.from);
|
|
75
|
+
validateTableQueryOffset(query.offset);
|
|
71
76
|
validateTableQueryLimit(query.limit);
|
|
72
77
|
if (query.where !== undefined) {
|
|
73
78
|
validateColumnarPredicate(query.where, new Set(sourceColumnNames));
|
|
@@ -117,6 +122,7 @@ export function normalizeTableQuery<
|
|
|
117
122
|
? {}
|
|
118
123
|
: {from: typeof query.from === 'string' ? query.from : Object.freeze({...query.from})}),
|
|
119
124
|
...(query.where === undefined ? {} : {where: query.where}),
|
|
125
|
+
...(query.offset === undefined ? {} : {offset: query.offset}),
|
|
120
126
|
...(query.limit === undefined ? {} : {limit: query.limit})
|
|
121
127
|
});
|
|
122
128
|
}
|
|
@@ -134,13 +140,17 @@ export function planLogicalTableQuery<
|
|
|
134
140
|
predicate: normalized.where,
|
|
135
141
|
limit: normalized.limit
|
|
136
142
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
const steps: LogicalTableQueryPlan<PredicateT>[number][] = [];
|
|
144
|
+
for (const step of plan) {
|
|
145
|
+
if (step.kind === 'limit' && normalized.offset !== undefined)
|
|
146
|
+
steps.push(Object.freeze({kind: 'offset', offset: normalized.offset}));
|
|
147
|
+
steps.push(
|
|
148
|
+
step.kind === 'project' ? Object.freeze({kind: 'project', select: normalized.select}) : step
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (normalized.limit === undefined && normalized.offset !== undefined)
|
|
152
|
+
steps.push(Object.freeze({kind: 'offset', offset: normalized.offset}));
|
|
153
|
+
return Object.freeze(steps);
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
/** Validates identifiers without interpreting dots or rewriting quoted names. */
|
|
@@ -39,7 +39,9 @@ export type TableQuery<
|
|
|
39
39
|
select?: readonly TableSelection[];
|
|
40
40
|
/** Predicate evaluated against source columns before output aliases are applied. */
|
|
41
41
|
where?: PredicateT;
|
|
42
|
-
/**
|
|
42
|
+
/** Number of filtered rows skipped before applying the limit. */
|
|
43
|
+
offset?: number;
|
|
44
|
+
/** Maximum number of rows retained after filtering and offset. */
|
|
43
45
|
limit?: number;
|
|
44
46
|
}>;
|
|
45
47
|
|
|
@@ -202,3 +204,10 @@ export function validateTableQueryLimit(limit: number | undefined): void {
|
|
|
202
204
|
throw new Error('Table query limit must be a non-negative safe integer.');
|
|
203
205
|
}
|
|
204
206
|
}
|
|
207
|
+
|
|
208
|
+
/** Validates a logical row offset before any batches are read. */
|
|
209
|
+
export function validateTableQueryOffset(offset: number | undefined): void {
|
|
210
|
+
if (offset !== undefined && (!Number.isSafeInteger(offset) || offset < 0)) {
|
|
211
|
+
throw new Error('Table query offset must be a non-negative safe integer.');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -6,7 +6,7 @@ import type {ArrowTable, ArrowTableBatch, TableBatch} from '@loaders.gl/core/sch
|
|
|
6
6
|
import type {TableScanReadOptions, TableQueryExecutionSummary} from './scan-query-metadata';
|
|
7
7
|
import {emitQueryComplete} from './scan-query-metadata';
|
|
8
8
|
import {filterColumnarRowIndices, validateColumnarPredicate} from './columnar-predicate';
|
|
9
|
-
import {validateTableQueryLimit} from './table-query';
|
|
9
|
+
import {validateTableQueryLimit, validateTableQueryOffset} from './table-query';
|
|
10
10
|
|
|
11
11
|
/** Reads source batches while allowing the shared executor to observe fetched bytes. */
|
|
12
12
|
export type TableScanBatchReader = (
|
|
@@ -40,10 +40,18 @@ export function makeTableScanBatch(table: ArrowTable): ArrowTableBatch {
|
|
|
40
40
|
*/
|
|
41
41
|
export async function* executeTableScanBatches(
|
|
42
42
|
readBatches: TableScanBatchReader,
|
|
43
|
-
options: TableScanReadOptions
|
|
43
|
+
options: TableScanReadOptions &
|
|
44
|
+
Readonly<{
|
|
45
|
+
/** Number of rows to skip after residual filtering. */
|
|
46
|
+
offset?: number;
|
|
47
|
+
/** Omits empty batches from the output stream. */
|
|
48
|
+
skipEmptyBatches?: boolean;
|
|
49
|
+
}> = {},
|
|
44
50
|
operators: TableScanBatchOperators = {}
|
|
45
51
|
): AsyncIterable<TableBatch> {
|
|
46
52
|
validateTableQueryLimit(options.limit);
|
|
53
|
+
validateTableQueryOffset(options.offset);
|
|
54
|
+
let skip = options.offset ?? 0;
|
|
47
55
|
const startedAt = Date.now();
|
|
48
56
|
let sourcesRead = 0;
|
|
49
57
|
let batchesRead = 0;
|
|
@@ -85,26 +93,23 @@ export async function* executeTableScanBatches(
|
|
|
85
93
|
rowsTested += batch.length;
|
|
86
94
|
rowsRetained += filteredBatch.length;
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
filteredBatch
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
if (projectedBatch.length <= remaining) {
|
|
93
|
-
remaining -= projectedBatch.length;
|
|
94
|
-
rowsReturned += projectedBatch.length;
|
|
95
|
-
yield projectedBatch;
|
|
96
|
-
if (remaining === 0) {
|
|
97
|
-
earlyTerminationReason = 'limit';
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
options.signal?.throwIfAborted();
|
|
101
|
-
} else {
|
|
102
|
-
const outputBatch = truncateTableBatch(projectedBatch, remaining);
|
|
103
|
-
rowsReturned += outputBatch.length;
|
|
104
|
-
earlyTerminationReason = 'limit';
|
|
105
|
-
yield outputBatch;
|
|
106
|
-
return;
|
|
96
|
+
if (skip >= filteredBatch.length && (skip > 0 || options.skipEmptyBatches)) {
|
|
97
|
+
skip -= filteredBatch.length;
|
|
98
|
+
continue;
|
|
107
99
|
}
|
|
100
|
+
const end = Math.min(filteredBatch.length, skip + remaining);
|
|
101
|
+
const window =
|
|
102
|
+
skip || end < filteredBatch.length
|
|
103
|
+
? sliceTableBatch(filteredBatch, skip, end)
|
|
104
|
+
: filteredBatch;
|
|
105
|
+
skip = 0;
|
|
106
|
+
const output = (operators.project || projectTableBatch)(window, options.columns);
|
|
107
|
+
remaining -= window.length;
|
|
108
|
+
rowsReturned += output.length;
|
|
109
|
+
if (remaining === 0) earlyTerminationReason = 'limit';
|
|
110
|
+
yield output;
|
|
111
|
+
if (remaining === 0) return;
|
|
112
|
+
options.signal?.throwIfAborted();
|
|
108
113
|
}
|
|
109
114
|
status = 'completed';
|
|
110
115
|
} catch (error) {
|
|
@@ -141,8 +146,14 @@ export async function* executeTableScanBatches(
|
|
|
141
146
|
|
|
142
147
|
/** Truncates a batch without changing its native representation. */
|
|
143
148
|
export function truncateTableBatch(batch: TableBatch, length: number): TableBatch {
|
|
149
|
+
return sliceTableBatch(batch, 0, length);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Slices rows in a batch, preserving Arrow buffers and the batch shape. */
|
|
153
|
+
function sliceTableBatch(batch: TableBatch, start: number, end: number): TableBatch {
|
|
154
|
+
const length = end - start;
|
|
144
155
|
if (batch.shape === 'object-row-table' || batch.shape === 'array-row-table') {
|
|
145
|
-
return {...batch, data: batch.data.slice(
|
|
156
|
+
return {...batch, data: batch.data.slice(start, end), length} as TableBatch;
|
|
146
157
|
}
|
|
147
158
|
if (batch.shape === 'columnar-table') {
|
|
148
159
|
return {
|
|
@@ -150,14 +161,14 @@ export function truncateTableBatch(batch: TableBatch, length: number): TableBatc
|
|
|
150
161
|
data: Object.fromEntries(
|
|
151
162
|
Object.entries(batch.data).map(([name, values]) => [
|
|
152
163
|
name,
|
|
153
|
-
Array.from(values as ArrayLike<unknown>).slice(
|
|
164
|
+
Array.from(values as ArrayLike<unknown>).slice(start, end)
|
|
154
165
|
])
|
|
155
166
|
),
|
|
156
167
|
length
|
|
157
168
|
};
|
|
158
169
|
}
|
|
159
|
-
if (batch.shape === 'arrow-table') return {...batch, data: batch.data.slice(
|
|
160
|
-
return {...batch, features: batch.features.slice(
|
|
170
|
+
if (batch.shape === 'arrow-table') return {...batch, data: batch.data.slice(start, end), length};
|
|
171
|
+
return {...batch, features: batch.features.slice(start, end), length};
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
/** Projects a batch in the caller-requested order while preserving its shape. */
|
|
@@ -7,7 +7,7 @@ import type {BatchableDataType, DataType, SyncDataType} from '../../types';
|
|
|
7
7
|
import type {ReadableFile} from '../files/file';
|
|
8
8
|
import {mergeOptions} from '../option-utils/merge-options';
|
|
9
9
|
import {resolvePath} from '../path-utils/file-aliases';
|
|
10
|
-
import {
|
|
10
|
+
import {getLoaderLog} from '../log-utils/log';
|
|
11
11
|
import {getAuthenticatedFetch} from '../request-utils/request-credentials';
|
|
12
12
|
import {resolveAuthenticationOptions} from '../request-utils/authentication';
|
|
13
13
|
|
|
@@ -169,7 +169,7 @@ export abstract class DataSource<DataT, OptionsT extends DataSourceOptions> {
|
|
|
169
169
|
if (callback) {
|
|
170
170
|
callback(normalizedError, this);
|
|
171
171
|
} else {
|
|
172
|
-
|
|
172
|
+
getLoaderLog(this.options).warn(`${this.constructor.name}: ${normalizedError.message}`)();
|
|
173
173
|
}
|
|
174
174
|
return normalizedError;
|
|
175
175
|
}
|
|
@@ -237,7 +237,7 @@ function normalizeError(error: unknown, message: string): Error {
|
|
|
237
237
|
function unavailableCoreApiMethod(methodName: keyof CoreAPI) {
|
|
238
238
|
return () => {
|
|
239
239
|
throw new Error(
|
|
240
|
-
`CoreAPI.${methodName} is unavailable. Use @loaders.gl/core.
|
|
240
|
+
`CoreAPI.${methodName} is unavailable. Use @loaders.gl/core.createDataSourceSync().`
|
|
241
241
|
);
|
|
242
242
|
};
|
|
243
243
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {NullLog} from '../log-utils/log';
|
|
5
6
|
import {
|
|
6
7
|
canProcessOnWorker,
|
|
7
8
|
canProcessOnWorkerInBatches,
|
|
@@ -317,7 +318,16 @@ function getWorkerOptions(options: StrictLoaderOptions = {}, loader?: Loader) {
|
|
|
317
318
|
...portableOptions,
|
|
318
319
|
signal: undefined,
|
|
319
320
|
onProgress: undefined,
|
|
320
|
-
|
|
321
|
+
log: isDisabledLog(portableOptions.log) ? null : undefined,
|
|
322
|
+
...(portableOptions.core
|
|
323
|
+
? {
|
|
324
|
+
core: {
|
|
325
|
+
...portableOptions.core,
|
|
326
|
+
authentications: undefined,
|
|
327
|
+
log: isDisabledLog(portableOptions.core.log) ? null : undefined
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
: {})
|
|
321
331
|
};
|
|
322
332
|
const serializedOptions = JSON.parse(
|
|
323
333
|
JSON.stringify(optionsToSerialize, (_key, value) => {
|
|
@@ -398,3 +408,8 @@ function isLoaderWithWorkerResultDeserializer(
|
|
|
398
408
|
'function'
|
|
399
409
|
);
|
|
400
410
|
}
|
|
411
|
+
|
|
412
|
+
/** Preserves explicit log suppression when crossing the worker boundary. */
|
|
413
|
+
function isDisabledLog(logger: unknown): boolean {
|
|
414
|
+
return logger === null || logger instanceof NullLog;
|
|
415
|
+
}
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import type * as arrow from 'apache-arrow';
|
|
6
|
+
import type {Logger} from 'probe.gl/log';
|
|
7
|
+
|
|
5
8
|
import type {Format} from './format-types';
|
|
6
9
|
import type {LoadWorker, WorkerOptions, WorkerProgress} from '@loaders.gl/core/worker-utils';
|
|
7
10
|
import {DataType, FetchLike, TransformBatches} from './types';
|
|
8
11
|
import {ReadableFile} from './lib/files/file';
|
|
9
|
-
import type {CoreAPI} from './lib/sources/data-source';
|
|
12
|
+
import type {CoreAPI, DataSourceOptions} from './lib/sources/data-source';
|
|
10
13
|
import type {Credential, AuthenticationConstructor} from './lib/request-utils/authentication';
|
|
11
14
|
import type {QueryOptions} from './lib/scan-utils/query-options';
|
|
12
15
|
|
|
@@ -46,7 +49,7 @@ export type StrictLoaderOptions = Pick<WorkerOptions, 'signal' | 'onProgress'> &
|
|
|
46
49
|
|
|
47
50
|
// general
|
|
48
51
|
/** Experimental: Supply a logger to the parser */
|
|
49
|
-
log?:
|
|
52
|
+
log?: Logger | null;
|
|
50
53
|
|
|
51
54
|
// batched parsing
|
|
52
55
|
|
|
@@ -131,7 +134,7 @@ export type LoaderOptions = Pick<WorkerOptions, 'signal' | 'onProgress'> & {
|
|
|
131
134
|
/** @deprecated Use options.core.nothrow */
|
|
132
135
|
nothrow?: boolean;
|
|
133
136
|
/** @deprecated Use options.core.log */
|
|
134
|
-
log?:
|
|
137
|
+
log?: Logger | null;
|
|
135
138
|
/** @deprecated Use options.core.useLocalLibraries */
|
|
136
139
|
useLocalLibraries?: boolean;
|
|
137
140
|
/** @deprecated Use options.core.CDN */
|
|
@@ -178,7 +181,18 @@ type PreloadOptions = {
|
|
|
178
181
|
/**
|
|
179
182
|
* A worker loader definition that can be used with `@loaders.gl/core` functions
|
|
180
183
|
*/
|
|
181
|
-
export type Loader<
|
|
184
|
+
export type Loader<
|
|
185
|
+
DataT = any,
|
|
186
|
+
BatchT = any,
|
|
187
|
+
LoaderOptionsT = StrictLoaderOptions,
|
|
188
|
+
SourceT = unknown
|
|
189
|
+
> = Format & {
|
|
190
|
+
/** Constructs a source synchronously from an available implementation. */
|
|
191
|
+
createDataSourceSync?: (
|
|
192
|
+
data: any,
|
|
193
|
+
options: LoaderOptionsT & DataSourceOptions,
|
|
194
|
+
coreApi?: CoreAPI
|
|
195
|
+
) => SourceT;
|
|
182
196
|
/** The result type of this loader */
|
|
183
197
|
dataType?: DataT;
|
|
184
198
|
/** The batched result type of this loader */
|
|
@@ -191,6 +205,9 @@ export type Loader<DataT = any, BatchT = any, LoaderOptionsT = StrictLoaderOptio
|
|
|
191
205
|
*/
|
|
192
206
|
subloaders?: Readonly<Record<string, Loader>>;
|
|
193
207
|
|
|
208
|
+
/** Default public output shape applied by the core parse and load APIs. */
|
|
209
|
+
defaultShape?: string;
|
|
210
|
+
|
|
194
211
|
/** Default Options */
|
|
195
212
|
options: LoaderOptionsT;
|
|
196
213
|
/** Deprecated Options */
|
|
@@ -274,10 +291,31 @@ export type Loader<DataT = any, BatchT = any, LoaderOptionsT = StrictLoaderOptio
|
|
|
274
291
|
export type LoaderWithParser<
|
|
275
292
|
DataT = any,
|
|
276
293
|
BatchT = any,
|
|
277
|
-
LoaderOptionsT = StrictLoaderOptions
|
|
278
|
-
|
|
294
|
+
LoaderOptionsT = StrictLoaderOptions,
|
|
295
|
+
SourceT = unknown
|
|
296
|
+
> = Loader<DataT, BatchT, LoaderOptionsT, SourceT> & {
|
|
297
|
+
/** Parses data from a URL using the loader's own request strategy. */
|
|
298
|
+
parseUrl?: (url: string, options?: LoaderOptionsT, context?: LoaderContext) => Promise<DataT>;
|
|
299
|
+
/**
|
|
300
|
+
* Optionally selects a parser representation for an atomic core parse call.
|
|
301
|
+
* Core uses the returned options for decoding and applies convert on the caller
|
|
302
|
+
* after decoding or worker hydration. Direct parser calls do not invoke this hook.
|
|
303
|
+
*/
|
|
304
|
+
prepareParseOutput?: (options: StrictLoaderOptions) => {
|
|
305
|
+
options: StrictLoaderOptions;
|
|
306
|
+
convert: (result: DataT) => DataT;
|
|
307
|
+
} | null;
|
|
308
|
+
/**
|
|
309
|
+
* Optionally selects a parser representation for core batch parsing.
|
|
310
|
+
* Core applies convert lazily to decoded or hydrated batches on the caller.
|
|
311
|
+
* The hook applies to native batch parsers and receives no core metadata envelopes.
|
|
312
|
+
*/
|
|
313
|
+
prepareParseBatchOutput?: (options: StrictLoaderOptions) => {
|
|
314
|
+
options: StrictLoaderOptions;
|
|
315
|
+
convert: (batch: BatchT) => BatchT;
|
|
316
|
+
} | null;
|
|
279
317
|
/** Parse asynchronously and atomically from an arraybuffer */
|
|
280
|
-
parse
|
|
318
|
+
parse?: (
|
|
281
319
|
arrayBuffer: ArrayBuffer,
|
|
282
320
|
options?: LoaderOptionsT,
|
|
283
321
|
context?: LoaderContext
|
|
@@ -427,59 +465,146 @@ export type LoaderContext = {
|
|
|
427
465
|
*/
|
|
428
466
|
type Preload = (url: string, options?: PreloadOptions) => any;
|
|
429
467
|
|
|
430
|
-
/**
|
|
431
|
-
export type LoaderOptionsType<T = Loader> =
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
468
|
+
/** Extracts the declared parser options, including from metadata-only loaders. */
|
|
469
|
+
export type LoaderOptionsType<T = Loader> = T extends {preload: (...args: any[]) => infer Parser}
|
|
470
|
+
? LoaderOptionsType<Awaited<Parser>>
|
|
471
|
+
: T extends {parse: (data: any, options?: infer Options, ...args: any[]) => any}
|
|
472
|
+
? NonNullable<Options> extends LoaderOptions
|
|
473
|
+
? NonNullable<Options>
|
|
474
|
+
: LoaderOptions
|
|
475
|
+
: T extends Loader<unknown, unknown, infer Options>
|
|
476
|
+
? Options
|
|
477
|
+
: never;
|
|
478
|
+
|
|
479
|
+
/** Extracts shapes from the loader's declared option namespaces. */
|
|
480
|
+
export type LoaderShapeType<T extends Loader = Loader> = T extends unknown
|
|
481
|
+
? {
|
|
482
|
+
[Key in Exclude<keyof T['options'], 'core'>]: NonNullable<LoaderOptionsType<T>[Key]> extends {
|
|
483
|
+
shape?: infer Shape;
|
|
484
|
+
}
|
|
485
|
+
? Extract<Shape, string>
|
|
486
|
+
: never;
|
|
487
|
+
}[Exclude<keyof T['options'], 'core'>]
|
|
488
|
+
: never;
|
|
440
489
|
type LoaderShapeOrString<Shape extends string> = [Shape] extends [never] ? string : Shape;
|
|
441
490
|
export type LoaderOptionsWithShape<
|
|
442
491
|
Options extends LoaderOptions,
|
|
443
492
|
Shape extends string
|
|
444
|
-
> = Options extends LoaderOptions
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
493
|
+
> = Options extends LoaderOptions ? Options & {core?: {shape?: LoaderShapeOrString<Shape>}} : never;
|
|
494
|
+
/** Checks declared options while allowing an options variable with a dynamic common shape. */
|
|
495
|
+
export type LoaderCallOptions<T extends Loader, Options extends LoaderOptions> = Options &
|
|
496
|
+
(T extends {defaultShape: 'arrow'}
|
|
497
|
+
? LoaderOptionsType<T> &
|
|
498
|
+
(Options extends {core: {shape: infer Shape}}
|
|
499
|
+
? string extends Shape
|
|
500
|
+
? LoaderOptions
|
|
501
|
+
: LoaderOptionsWithShape<LoaderOptions, LoaderShapeType<T>>
|
|
502
|
+
: LoaderOptions)
|
|
503
|
+
: LoaderOptions);
|
|
504
|
+
|
|
505
|
+
/** Extracts possible shape selections, including optional option namespaces. */
|
|
506
|
+
type OptionShape<Options> = Options extends {shape?: infer Shape} ? Extract<Shape, string> : never;
|
|
507
|
+
|
|
508
|
+
/** Extracts required shape selections without treating omitted options as native output. */
|
|
509
|
+
type RequiredOptionShape<Options> = [Options] extends [{shape: infer Shape}]
|
|
510
|
+
? Extract<Shape, string>
|
|
511
|
+
: never;
|
|
512
|
+
|
|
513
|
+
/** Extracts loader-scoped selection from the declared option namespaces. */
|
|
514
|
+
type ScopedOutputShape<T, Options, Required extends boolean = false> = T extends {
|
|
515
|
+
options: infer Defaults;
|
|
516
|
+
}
|
|
517
|
+
? {
|
|
518
|
+
[Key in Exclude<keyof Defaults, 'core'> & keyof Options]: Required extends true
|
|
519
|
+
? RequiredOptionShape<Options[Key]>
|
|
520
|
+
: OptionShape<Options[Key]>;
|
|
521
|
+
}[Exclude<keyof Defaults, 'core'> & keyof Options]
|
|
448
522
|
: never;
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
523
|
+
|
|
524
|
+
/** Resolves an explicit loader-scoped selection before the common shape default. */
|
|
525
|
+
type RequiredOutputShape<T, Options> = [ScopedOutputShape<T, Options, true>] extends [never]
|
|
526
|
+
? [ScopedOutputShape<T, Options>] extends [never]
|
|
527
|
+
? Options extends {core: infer Core}
|
|
528
|
+
? RequiredOptionShape<Core>
|
|
529
|
+
: never
|
|
530
|
+
: never
|
|
531
|
+
: ScopedOutputShape<T, Options, true>;
|
|
532
|
+
|
|
533
|
+
/** Evaluates each options variant independently, including an absent options object. */
|
|
534
|
+
type NativeArrowOutput<T, Options, Wrapped, Native> = [Options] extends [never]
|
|
535
|
+
? NativeArrowOutputForOption<T, undefined, Wrapped, Native>
|
|
536
|
+
: Options extends unknown
|
|
537
|
+
? NativeArrowOutputForOption<T, Options, Wrapped, Native>
|
|
538
|
+
: never;
|
|
539
|
+
|
|
540
|
+
/** Selects native output when certain and a union when shape selection is dynamic. */
|
|
541
|
+
type NativeArrowOutputForOption<T, Options, Wrapped, Native> = [
|
|
542
|
+
Extract<Wrapped, {shape: 'arrow-table'}>
|
|
543
|
+
] extends [never]
|
|
544
|
+
? Wrapped
|
|
545
|
+
: [RequiredOutputShape<T, Options>] extends [never]
|
|
546
|
+
? [
|
|
547
|
+
| ScopedOutputShape<T, Options>
|
|
548
|
+
| (Options extends {core?: infer Core} ? OptionShape<Core> : never)
|
|
549
|
+
] extends [never]
|
|
550
|
+
? T extends {defaultShape: 'arrow'}
|
|
551
|
+
? Native
|
|
552
|
+
: Wrapped
|
|
553
|
+
: T extends {defaultShape: 'arrow'}
|
|
554
|
+
? Native | Wrapped
|
|
555
|
+
: 'arrow' extends
|
|
556
|
+
| ScopedOutputShape<T, Options>
|
|
557
|
+
| (Options extends {core?: infer Core} ? OptionShape<Core> : never)
|
|
558
|
+
? Native | Wrapped
|
|
559
|
+
: Wrapped
|
|
560
|
+
: 'arrow' extends RequiredOutputShape<T, Options>
|
|
561
|
+
? Exclude<RequiredOutputShape<T, Options>, 'arrow'> extends never
|
|
562
|
+
? Native
|
|
563
|
+
: Native | Wrapped
|
|
564
|
+
: Wrapped;
|
|
565
|
+
|
|
566
|
+
/** Typescript helper to extract the public data type, accounting for native Arrow output. */
|
|
567
|
+
export type LoaderReturnType<T = Loader, Options = never> =
|
|
568
|
+
T extends Loader<infer Return, unknown, unknown>
|
|
569
|
+
? NativeArrowOutput<T, Options, Return, arrow.Table>
|
|
570
|
+
: never;
|
|
571
|
+
/** Typescript helper to extract the public batch type, accounting for native Arrow output. */
|
|
572
|
+
export type LoaderBatchType<T = Loader, Options = never> =
|
|
573
|
+
T extends Loader<unknown, infer Batch, unknown>
|
|
574
|
+
? NativeArrowOutput<T, Options, Batch, arrow.RecordBatch>
|
|
575
|
+
: never;
|
|
455
576
|
|
|
456
577
|
/** Typescript helper to extract options type from an array of loader types */
|
|
457
578
|
export type LoaderArrayOptionsType<LoadersT extends Loader[] = Loader[]> = LoaderOptionsWithShape<
|
|
458
|
-
LoadersT[number]
|
|
579
|
+
LoaderOptionsType<LoadersT[number]>,
|
|
459
580
|
LoaderShapeType<LoadersT[number]>
|
|
460
581
|
>;
|
|
461
|
-
/** Typescript helper to extract data type from
|
|
462
|
-
export type LoaderArrayReturnType<
|
|
463
|
-
LoadersT[
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
582
|
+
/** Typescript helper to extract data type from an array of loader types. */
|
|
583
|
+
export type LoaderArrayReturnType<
|
|
584
|
+
LoadersT extends Loader[] = Loader[],
|
|
585
|
+
Options = never
|
|
586
|
+
> = LoaderReturnType<LoadersT[number], Options>;
|
|
587
|
+
/** Typescript helper to extract batch type from an array of loader types. */
|
|
588
|
+
export type LoaderArrayBatchType<
|
|
589
|
+
LoadersT extends Loader[] = Loader[],
|
|
590
|
+
Options = never
|
|
591
|
+
> = LoaderBatchType<LoadersT[number], Options>;
|
|
467
592
|
|
|
468
593
|
/**
|
|
469
594
|
* Parses `data` asynchronously using the supplied loader, parse function provided via the loader context
|
|
470
595
|
*/
|
|
471
596
|
export async function parseFromContext<
|
|
472
597
|
LoaderT extends Loader,
|
|
473
|
-
OptionsT extends StrictLoaderOptions = LoaderOptionsWithShape<
|
|
598
|
+
const OptionsT extends StrictLoaderOptions | undefined = LoaderOptionsWithShape<
|
|
474
599
|
LoaderOptionsType<LoaderT>,
|
|
475
600
|
LoaderShapeType<LoaderT>
|
|
476
601
|
>
|
|
477
602
|
>(
|
|
478
603
|
data: ArrayBuffer,
|
|
479
604
|
loader: LoaderT,
|
|
480
|
-
options: OptionsT
|
|
605
|
+
options: OptionsT,
|
|
481
606
|
context: LoaderContext
|
|
482
|
-
): Promise<LoaderReturnType<LoaderT>>;
|
|
607
|
+
): Promise<LoaderReturnType<LoaderT, OptionsT>>;
|
|
483
608
|
|
|
484
609
|
/**
|
|
485
610
|
* Parses `data` asynchronously by matching one of the supplied loader
|
|
@@ -513,13 +638,13 @@ export async function parseFromContext(
|
|
|
513
638
|
*/
|
|
514
639
|
export function parseSyncFromContext<
|
|
515
640
|
LoaderT extends Loader,
|
|
516
|
-
OptionsT extends StrictLoaderOptions = LoaderOptionsType<LoaderT>
|
|
641
|
+
const OptionsT extends StrictLoaderOptions | undefined = LoaderOptionsType<LoaderT>
|
|
517
642
|
>(
|
|
518
643
|
data: ArrayBuffer,
|
|
519
644
|
loader: LoaderT,
|
|
520
|
-
options: OptionsT
|
|
645
|
+
options: OptionsT,
|
|
521
646
|
context: LoaderContext
|
|
522
|
-
): LoaderReturnType<LoaderT> {
|
|
647
|
+
): LoaderReturnType<LoaderT, OptionsT> {
|
|
523
648
|
if (!context._parseSync) {
|
|
524
649
|
throw new Error('parseSync');
|
|
525
650
|
}
|
|
@@ -531,13 +656,13 @@ export function parseSyncFromContext<
|
|
|
531
656
|
*/
|
|
532
657
|
export async function parseInBatchesFromContext<
|
|
533
658
|
LoaderT extends Loader,
|
|
534
|
-
OptionsT extends StrictLoaderOptions = LoaderOptionsType<LoaderT>
|
|
659
|
+
const OptionsT extends StrictLoaderOptions | undefined = LoaderOptionsType<LoaderT>
|
|
535
660
|
>(
|
|
536
661
|
data: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer> | Response,
|
|
537
662
|
loader: LoaderT,
|
|
538
|
-
options: OptionsT
|
|
663
|
+
options: OptionsT,
|
|
539
664
|
context: LoaderContext
|
|
540
|
-
): Promise<AsyncIterable<LoaderBatchType<LoaderT>>> {
|
|
665
|
+
): Promise<AsyncIterable<LoaderBatchType<LoaderT, OptionsT>>> {
|
|
541
666
|
if (!context._parseInBatches) {
|
|
542
667
|
throw new Error('parseInBatches');
|
|
543
668
|
}
|
|
@@ -7,7 +7,7 @@ import type {CoreAPI, DataSource, DataSourceOptions} from './lib/sources/data-so
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A `SourceLoader` is a top-level loader that constructs a runtime `DataSource`.
|
|
10
|
-
* It allows source-style loaders to participate in core
|
|
10
|
+
* It allows source-style loaders to participate in core source selection and `createDataSource()`.
|
|
11
11
|
* @example
|
|
12
12
|
* `createDataSource(... , [MVTSourceLoader, PMTilesSourceLoader, ...])
|
|
13
13
|
*/
|
|
@@ -17,7 +17,7 @@ export type SourceLoader<
|
|
|
17
17
|
DataSourceOptions
|
|
18
18
|
>,
|
|
19
19
|
LoaderOptionsT extends LoaderOptions & DataSourceOptions = LoaderOptions & DataSourceOptions
|
|
20
|
-
> = Loader<DataSourceT, never, LoaderOptionsT> & {
|
|
20
|
+
> = Loader<DataSourceT, never, LoaderOptionsT, DataSourceT> & {
|
|
21
21
|
/** Type of source created by this source loader */
|
|
22
22
|
dataSource?: DataSourceT;
|
|
23
23
|
/** Type of options used when creating sources */
|
|
@@ -38,7 +38,7 @@ export type SourceLoader<
|
|
|
38
38
|
/** Test data */
|
|
39
39
|
testData?: (data: Blob) => boolean;
|
|
40
40
|
/** Create a runtime data source */
|
|
41
|
-
|
|
41
|
+
createDataSourceSync(
|
|
42
42
|
data: string | Blob,
|
|
43
43
|
options: Readonly<DataSourceT['optionsType']>,
|
|
44
44
|
coreApi?: CoreAPI
|
|
@@ -46,17 +46,23 @@ export type SourceLoader<
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export function isSourceLoader(loader?: unknown): loader is SourceLoader {
|
|
49
|
-
return Boolean(
|
|
49
|
+
return Boolean(
|
|
50
|
+
loader &&
|
|
51
|
+
typeof loader === 'object' &&
|
|
52
|
+
'createDataSourceSync' in loader &&
|
|
53
|
+
'fromUrl' in loader &&
|
|
54
|
+
'testURL' in loader
|
|
55
|
+
);
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
/** Extracts the full public options contract, including fields absent from runtime defaults. */
|
|
53
59
|
export type SourcePropsType<SourceT extends SourceLoader> = NonNullable<
|
|
54
|
-
Parameters<SourceT['
|
|
60
|
+
Parameters<SourceT['createDataSourceSync']>[1]
|
|
55
61
|
>;
|
|
56
62
|
|
|
57
63
|
/** Typescript helper to extract the source options type from a source type */
|
|
58
64
|
export type SourceDataSourceType<SourceT extends SourceLoader> = ReturnType<
|
|
59
|
-
SourceT['
|
|
65
|
+
SourceT['createDataSourceSync']
|
|
60
66
|
>;
|
|
61
67
|
|
|
62
68
|
/** Combines options for all candidate sources instead of accepting one candidate's untyped keys. */
|
package/src/polyfills/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
/* eslint-disable dot-notation */
|
|
6
|
+
import {log as loaderLog} from 'probe.gl/log';
|
|
6
7
|
import {isBrowser} from './utils/is-browser';
|
|
7
8
|
|
|
8
9
|
import {TextDecoder, TextEncoder} from './text-encoder/text-encoder';
|
|
@@ -42,10 +43,9 @@ export const File = globalThis.File;
|
|
|
42
43
|
installFilePolyfills();
|
|
43
44
|
|
|
44
45
|
if (isBrowser) {
|
|
45
|
-
|
|
46
|
-
console.error(
|
|
46
|
+
loaderLog.error(
|
|
47
47
|
'loaders.gl: The @loaders.gl/core/polyfills should only be used in Node.js environments'
|
|
48
|
-
);
|
|
48
|
+
)();
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
globalThis.loaders = globalThis.loaders || {};
|