@loaders.gl/arrow 4.2.0-alpha.4 → 4.2.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-loader.d.ts +1 -1
- package/dist/arrow-loader.d.ts.map +1 -1
- package/dist/arrow-loader.js +30 -19
- package/dist/arrow-worker.js +4 -2
- package/dist/arrow-writer.d.ts +1 -1
- package/dist/arrow-writer.d.ts.map +1 -1
- package/dist/arrow-writer.js +23 -16
- package/dist/dist.dev.js +361 -333
- package/dist/dist.min.js +23 -0
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +345 -288
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js +151 -124
- package/dist/geoarrow/get-arrow-bounds.js +32 -22
- package/dist/geoarrow-loader.d.ts +1 -1
- package/dist/geoarrow-loader.d.ts.map +1 -1
- package/dist/geoarrow-loader.js +22 -15
- package/dist/geoarrow-writer.js +25 -16
- package/dist/index.cjs +55 -71
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +16 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/lib/arrow-table-batch.d.ts +1 -1
- package/dist/lib/arrow-table-batch.d.ts.map +1 -1
- package/dist/lib/arrow-table-batch.js +55 -51
- package/dist/lib/arrow-table.js +3 -1
- package/dist/lib/encode-arrow.d.ts +1 -1
- package/dist/lib/encode-arrow.d.ts.map +1 -1
- package/dist/lib/encode-arrow.js +31 -16
- package/dist/lib/encode-geoarrow.d.ts +1 -1
- package/dist/lib/encode-geoarrow.d.ts.map +1 -1
- package/dist/lib/encode-geoarrow.js +31 -16
- package/dist/parsers/parse-arrow-in-batches.d.ts +2 -2
- package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -1
- package/dist/parsers/parse-arrow-in-batches.js +49 -21
- package/dist/parsers/parse-arrow-sync.d.ts +1 -1
- package/dist/parsers/parse-arrow-sync.d.ts.map +1 -1
- package/dist/parsers/parse-arrow-sync.js +26 -22
- package/dist/parsers/parse-geoarrow-in-batches.d.ts +1 -1
- package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -1
- package/dist/parsers/parse-geoarrow-in-batches.js +7 -2
- package/dist/parsers/parse-geoarrow-sync.d.ts +1 -1
- package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -1
- package/dist/parsers/parse-geoarrow-sync.js +12 -10
- package/dist/schema/arrow-type-utils.js +36 -9
- package/dist/schema/convert-arrow-schema.js +253 -240
- package/dist/tables/convert-arrow-to-columnar-table.d.ts +1 -1
- package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -1
- package/dist/tables/convert-arrow-to-columnar-table.js +22 -13
- package/dist/tables/convert-arrow-to-geojson-table.d.ts +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.js +47 -32
- package/dist/tables/convert-columnar-to-row-table.js +22 -16
- package/dist/tables/convert-table-to-arrow.js +58 -1
- package/dist/triangulate-on-worker.js +24 -19
- package/dist/triangulation-worker.js +6 -1
- package/dist/types.js +8 -6
- package/dist/workers/arrow-worker.js +3 -1
- package/dist/workers/hard-clone.js +93 -49
- package/dist/workers/triangulation-worker-node.d.ts +1 -1
- package/dist/workers/triangulation-worker-node.d.ts.map +1 -1
- package/dist/workers/triangulation-worker-node.js +3 -1
- package/dist/workers/triangulation-worker.js +48 -48
- package/package.json +13 -8
- package/dist/arrow-loader.js.map +0 -1
- package/dist/arrow-writer.js.map +0 -1
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +0 -1
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js.map +0 -1
- package/dist/geoarrow/get-arrow-bounds.js.map +0 -1
- package/dist/geoarrow-loader.js.map +0 -1
- package/dist/geoarrow-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/arrow-table-batch.js.map +0 -1
- package/dist/lib/arrow-table.js.map +0 -1
- package/dist/lib/encode-arrow.js.map +0 -1
- package/dist/lib/encode-geoarrow.js.map +0 -1
- package/dist/parsers/parse-arrow-in-batches.js.map +0 -1
- package/dist/parsers/parse-arrow-sync.js.map +0 -1
- package/dist/parsers/parse-geoarrow-in-batches.js.map +0 -1
- package/dist/parsers/parse-geoarrow-sync.js.map +0 -1
- package/dist/schema/arrow-type-utils.js.map +0 -1
- package/dist/schema/convert-arrow-schema.js.map +0 -1
- package/dist/tables/convert-arrow-to-columnar-table.js.map +0 -1
- package/dist/tables/convert-arrow-to-geojson-table.js.map +0 -1
- package/dist/tables/convert-columnar-to-row-table.js.map +0 -1
- package/dist/tables/convert-table-to-arrow.js.map +0 -1
- package/dist/triangulate-on-worker.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/arrow-worker.js.map +0 -1
- package/dist/workers/hard-clone.js.map +0 -1
- package/dist/workers/triangulation-worker-node.js.map +0 -1
- package/dist/workers/triangulation-worker.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
|
+
var __create = Object.create;
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
};
|
|
13
19
|
var __export = (target, all) => {
|
|
14
20
|
for (var name in all)
|
|
15
21
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,11 +28,31 @@ var __exports__ = (() => {
|
|
|
22
28
|
}
|
|
23
29
|
return to;
|
|
24
30
|
};
|
|
31
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
25
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __publicField = (obj, key, value) => {
|
|
42
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
26
45
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
|
|
46
|
+
// external-global-plugin:@loaders.gl/core
|
|
47
|
+
var require_core = __commonJS({
|
|
48
|
+
"external-global-plugin:@loaders.gl/core"(exports, module) {
|
|
49
|
+
module.exports = globalThis.loaders;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// bundle.ts
|
|
54
|
+
var bundle_exports = {};
|
|
55
|
+
__export(bundle_exports, {
|
|
30
56
|
ArrowLoader: () => ArrowLoader,
|
|
31
57
|
ArrowWorkerLoader: () => ArrowWorkerLoader,
|
|
32
58
|
ArrowWriter: () => ArrowWriter,
|
|
@@ -54,10 +80,14 @@ var __exports__ = (() => {
|
|
|
54
80
|
triangulateOnWorker: () => triangulateOnWorker,
|
|
55
81
|
updateBoundsFromGeoArrowSamples: () => updateBoundsFromGeoArrowSamples
|
|
56
82
|
});
|
|
83
|
+
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
57
84
|
|
|
58
85
|
// ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
|
|
59
86
|
var DEFAULT_ROW_COUNT = 100;
|
|
60
87
|
var BaseTableBatchAggregator = class {
|
|
88
|
+
schema;
|
|
89
|
+
options;
|
|
90
|
+
shape;
|
|
61
91
|
length = 0;
|
|
62
92
|
rows = null;
|
|
63
93
|
cursor = 0;
|
|
@@ -158,6 +188,8 @@ var __exports__ = (() => {
|
|
|
158
188
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
159
189
|
var DEFAULT_ROW_COUNT2 = 100;
|
|
160
190
|
var RowTableBatchAggregator = class {
|
|
191
|
+
schema;
|
|
192
|
+
options;
|
|
161
193
|
length = 0;
|
|
162
194
|
objectRows = null;
|
|
163
195
|
arrayRows = null;
|
|
@@ -223,6 +255,7 @@ var __exports__ = (() => {
|
|
|
223
255
|
batchType: "data",
|
|
224
256
|
data: rows,
|
|
225
257
|
length: this.length,
|
|
258
|
+
// @ts-expect-error we should infer a schema
|
|
226
259
|
schema: this.schema,
|
|
227
260
|
cursor: this.cursor
|
|
228
261
|
};
|
|
@@ -232,6 +265,7 @@ var __exports__ = (() => {
|
|
|
232
265
|
// ../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts
|
|
233
266
|
var DEFAULT_ROW_COUNT3 = 100;
|
|
234
267
|
var ColumnarTableBatchAggregator = class {
|
|
268
|
+
schema;
|
|
235
269
|
length = 0;
|
|
236
270
|
allocated = 0;
|
|
237
271
|
columns = {};
|
|
@@ -276,6 +310,7 @@ var __exports__ = (() => {
|
|
|
276
310
|
};
|
|
277
311
|
return batch;
|
|
278
312
|
}
|
|
313
|
+
// HELPERS
|
|
279
314
|
_reallocateColumns() {
|
|
280
315
|
if (this.length < this.allocated) {
|
|
281
316
|
return;
|
|
@@ -314,7 +349,9 @@ var __exports__ = (() => {
|
|
|
314
349
|
_limitMB: 0
|
|
315
350
|
};
|
|
316
351
|
var ERR_MESSAGE = "TableBatchBuilder";
|
|
317
|
-
var
|
|
352
|
+
var _TableBatchBuilder = class {
|
|
353
|
+
schema;
|
|
354
|
+
options;
|
|
318
355
|
aggregator = null;
|
|
319
356
|
batchCount = 0;
|
|
320
357
|
bytesUsed = 0;
|
|
@@ -325,10 +362,7 @@ var __exports__ = (() => {
|
|
|
325
362
|
rowBytes = 0;
|
|
326
363
|
constructor(schema, options) {
|
|
327
364
|
this.schema = schema;
|
|
328
|
-
this.options = {
|
|
329
|
-
...DEFAULT_OPTIONS,
|
|
330
|
-
...options
|
|
331
|
-
};
|
|
365
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
332
366
|
}
|
|
333
367
|
limitReached() {
|
|
334
368
|
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
@@ -339,6 +373,7 @@ var __exports__ = (() => {
|
|
|
339
373
|
}
|
|
340
374
|
return false;
|
|
341
375
|
}
|
|
376
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
342
377
|
addRow(row) {
|
|
343
378
|
if (this.limitReached()) {
|
|
344
379
|
return;
|
|
@@ -352,6 +387,7 @@ var __exports__ = (() => {
|
|
|
352
387
|
this.addObjectRow(row);
|
|
353
388
|
}
|
|
354
389
|
}
|
|
390
|
+
/** Add one row to the batch */
|
|
355
391
|
addArrayRow(row) {
|
|
356
392
|
if (!this.aggregator) {
|
|
357
393
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -359,6 +395,7 @@ var __exports__ = (() => {
|
|
|
359
395
|
}
|
|
360
396
|
this.aggregator.addArrayRow(row);
|
|
361
397
|
}
|
|
398
|
+
/** Add one row to the batch */
|
|
362
399
|
addObjectRow(row) {
|
|
363
400
|
if (!this.aggregator) {
|
|
364
401
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -366,6 +403,7 @@ var __exports__ = (() => {
|
|
|
366
403
|
}
|
|
367
404
|
this.aggregator.addObjectRow(row);
|
|
368
405
|
}
|
|
406
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
369
407
|
chunkComplete(chunk) {
|
|
370
408
|
if (chunk instanceof ArrayBuffer) {
|
|
371
409
|
this.bytesUsed += chunk.byteLength;
|
|
@@ -381,6 +419,7 @@ var __exports__ = (() => {
|
|
|
381
419
|
getFinalBatch(options) {
|
|
382
420
|
return this._getBatch(options);
|
|
383
421
|
}
|
|
422
|
+
// INTERNAL
|
|
384
423
|
_estimateRowMB(row) {
|
|
385
424
|
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
386
425
|
}
|
|
@@ -402,6 +441,9 @@ var __exports__ = (() => {
|
|
|
402
441
|
this.lastBatchEmittedMs = Date.now();
|
|
403
442
|
return true;
|
|
404
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
446
|
+
*/
|
|
405
447
|
_getBatch(options) {
|
|
406
448
|
if (!this.aggregator) {
|
|
407
449
|
return null;
|
|
@@ -425,15 +467,17 @@ var __exports__ = (() => {
|
|
|
425
467
|
case "columnar-table":
|
|
426
468
|
return ColumnarTableBatchAggregator;
|
|
427
469
|
case "arrow-table":
|
|
428
|
-
if (!
|
|
470
|
+
if (!_TableBatchBuilder.ArrowBatch) {
|
|
429
471
|
throw new Error(ERR_MESSAGE);
|
|
430
472
|
}
|
|
431
|
-
return
|
|
473
|
+
return _TableBatchBuilder.ArrowBatch;
|
|
432
474
|
default:
|
|
433
475
|
return BaseTableBatchAggregator;
|
|
434
476
|
}
|
|
435
477
|
}
|
|
436
478
|
};
|
|
479
|
+
var TableBatchBuilder = _TableBatchBuilder;
|
|
480
|
+
__publicField(TableBatchBuilder, "ArrowBatch");
|
|
437
481
|
|
|
438
482
|
// ../schema/src/lib/table/simple-table/table-accessors.ts
|
|
439
483
|
function getTableLength(table) {
|
|
@@ -469,7 +513,9 @@ var __exports__ = (() => {
|
|
|
469
513
|
return column[rowIndex];
|
|
470
514
|
case "arrow-table":
|
|
471
515
|
const arrowTable = table.data;
|
|
472
|
-
const arrowColumnIndex = arrowTable.schema.fields.findIndex(
|
|
516
|
+
const arrowColumnIndex = arrowTable.schema.fields.findIndex(
|
|
517
|
+
(field) => field.name === columnName
|
|
518
|
+
);
|
|
473
519
|
return arrowTable.getChildAt(arrowColumnIndex)?.get(rowIndex);
|
|
474
520
|
default:
|
|
475
521
|
throw new Error("todo");
|
|
@@ -602,22 +648,13 @@ var __exports__ = (() => {
|
|
|
602
648
|
function getDataTypeFromArray(array) {
|
|
603
649
|
let type = getDataTypeFromTypedArray(array);
|
|
604
650
|
if (type !== "null") {
|
|
605
|
-
return {
|
|
606
|
-
type,
|
|
607
|
-
nullable: false
|
|
608
|
-
};
|
|
651
|
+
return { type, nullable: false };
|
|
609
652
|
}
|
|
610
653
|
if (array.length > 0) {
|
|
611
654
|
type = getDataTypeFromValue(array[0]);
|
|
612
|
-
return {
|
|
613
|
-
type,
|
|
614
|
-
nullable: true
|
|
615
|
-
};
|
|
655
|
+
return { type, nullable: true };
|
|
616
656
|
}
|
|
617
|
-
return {
|
|
618
|
-
type: "null",
|
|
619
|
-
nullable: true
|
|
620
|
-
};
|
|
657
|
+
return { type: "null", nullable: true };
|
|
621
658
|
}
|
|
622
659
|
function getDataTypeFromTypedArray(array) {
|
|
623
660
|
switch (array.constructor) {
|
|
@@ -687,10 +724,7 @@ var __exports__ = (() => {
|
|
|
687
724
|
const field = deduceFieldFromColumn(column, columnName);
|
|
688
725
|
fields.push(field);
|
|
689
726
|
}
|
|
690
|
-
return {
|
|
691
|
-
fields,
|
|
692
|
-
metadata: {}
|
|
693
|
-
};
|
|
727
|
+
return { fields, metadata: {} };
|
|
694
728
|
}
|
|
695
729
|
function deduceSchemaFromRows(rowTable) {
|
|
696
730
|
if (!rowTable.length) {
|
|
@@ -701,10 +735,7 @@ var __exports__ = (() => {
|
|
|
701
735
|
for (const [columnName, value] of Object.entries(row0)) {
|
|
702
736
|
fields.push(deduceFieldFromValue(value, columnName));
|
|
703
737
|
}
|
|
704
|
-
return {
|
|
705
|
-
fields,
|
|
706
|
-
metadata: {}
|
|
707
|
-
};
|
|
738
|
+
return { fields, metadata: {} };
|
|
708
739
|
}
|
|
709
740
|
function deduceFieldFromColumn(column, name) {
|
|
710
741
|
if (ArrayBuffer.isView(column)) {
|
|
@@ -713,6 +744,7 @@ var __exports__ = (() => {
|
|
|
713
744
|
name,
|
|
714
745
|
type: type.type || "null",
|
|
715
746
|
nullable: type.nullable
|
|
747
|
+
// metadata: {}
|
|
716
748
|
};
|
|
717
749
|
}
|
|
718
750
|
if (Array.isArray(column) && column.length > 0) {
|
|
@@ -722,6 +754,7 @@ var __exports__ = (() => {
|
|
|
722
754
|
name,
|
|
723
755
|
type,
|
|
724
756
|
nullable: true
|
|
757
|
+
// metadata: {},
|
|
725
758
|
};
|
|
726
759
|
}
|
|
727
760
|
throw new Error("empty table");
|
|
@@ -732,6 +765,7 @@ var __exports__ = (() => {
|
|
|
732
765
|
name,
|
|
733
766
|
type,
|
|
734
767
|
nullable: true
|
|
768
|
+
// metadata: {}
|
|
735
769
|
};
|
|
736
770
|
}
|
|
737
771
|
|
|
@@ -767,10 +801,7 @@ var __exports__ = (() => {
|
|
|
767
801
|
const schema = table.schema || deduceTableSchema(table);
|
|
768
802
|
const fields = table.schema?.fields || [];
|
|
769
803
|
if (table.shape === "columnar-table") {
|
|
770
|
-
return {
|
|
771
|
-
...table,
|
|
772
|
-
schema
|
|
773
|
-
};
|
|
804
|
+
return { ...table, schema };
|
|
774
805
|
}
|
|
775
806
|
const length = getTableLength(table);
|
|
776
807
|
const columns = {};
|
|
@@ -12669,6 +12700,7 @@ return true;`);
|
|
|
12669
12700
|
|
|
12670
12701
|
// src/lib/arrow-table-batch.ts
|
|
12671
12702
|
var ArrowTableBatchAggregator = class extends ColumnarTableBatchAggregator {
|
|
12703
|
+
arrowSchema;
|
|
12672
12704
|
constructor(schema, options) {
|
|
12673
12705
|
super(schema, options);
|
|
12674
12706
|
this.arrowSchema = null;
|
|
@@ -12678,12 +12710,13 @@ return true;`);
|
|
|
12678
12710
|
if (batch) {
|
|
12679
12711
|
this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
|
|
12680
12712
|
const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
|
|
12681
|
-
const recordBatch = new RecordBatch2(
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12713
|
+
const recordBatch = new RecordBatch2(
|
|
12714
|
+
this.arrowSchema,
|
|
12715
|
+
makeData({
|
|
12716
|
+
type: new Struct(this.arrowSchema.fields),
|
|
12717
|
+
children: arrowVectors.map(({ data }) => data[0])
|
|
12718
|
+
})
|
|
12719
|
+
);
|
|
12687
12720
|
return {
|
|
12688
12721
|
shape: "arrow-table",
|
|
12689
12722
|
batchType: "data",
|
|
@@ -12749,11 +12782,11 @@ return true;`);
|
|
|
12749
12782
|
}
|
|
12750
12783
|
|
|
12751
12784
|
// src/types.ts
|
|
12752
|
-
var VECTOR_TYPES =
|
|
12785
|
+
var VECTOR_TYPES = /* @__PURE__ */ ((VECTOR_TYPES2) => {
|
|
12753
12786
|
VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
|
|
12754
12787
|
VECTOR_TYPES2[VECTOR_TYPES2["DATE"] = 1] = "DATE";
|
|
12755
12788
|
return VECTOR_TYPES2;
|
|
12756
|
-
}({});
|
|
12789
|
+
})(VECTOR_TYPES || {});
|
|
12757
12790
|
|
|
12758
12791
|
// src/tables/convert-arrow-to-columnar-table.ts
|
|
12759
12792
|
function convertArrowToColumnarTable(table) {
|
|
@@ -12779,7 +12812,10 @@ return true;`);
|
|
|
12779
12812
|
};
|
|
12780
12813
|
}
|
|
12781
12814
|
function deserializeArrowSchema(schema) {
|
|
12782
|
-
return new Schema2(
|
|
12815
|
+
return new Schema2(
|
|
12816
|
+
schema.fields.map((field) => deserializeArrowField(field)),
|
|
12817
|
+
deserializeArrowMetadata(schema.metadata)
|
|
12818
|
+
);
|
|
12783
12819
|
}
|
|
12784
12820
|
function serializeArrowMetadata(arrowMetadata) {
|
|
12785
12821
|
return Object.fromEntries(arrowMetadata);
|
|
@@ -12796,7 +12832,12 @@ return true;`);
|
|
|
12796
12832
|
};
|
|
12797
12833
|
}
|
|
12798
12834
|
function deserializeArrowField(field) {
|
|
12799
|
-
return new Field2(
|
|
12835
|
+
return new Field2(
|
|
12836
|
+
field.name,
|
|
12837
|
+
deserializeArrowType(field.type),
|
|
12838
|
+
field.nullable,
|
|
12839
|
+
deserializeArrowMetadata(field.metadata)
|
|
12840
|
+
);
|
|
12800
12841
|
}
|
|
12801
12842
|
function serializeArrowType(arrowType) {
|
|
12802
12843
|
switch (arrowType.constructor) {
|
|
@@ -13079,15 +13120,20 @@ return true;`);
|
|
|
13079
13120
|
}
|
|
13080
13121
|
|
|
13081
13122
|
// src/arrow-loader.ts
|
|
13082
|
-
var VERSION =
|
|
13123
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
13083
13124
|
var ArrowWorkerLoader = {
|
|
13084
13125
|
name: "Apache Arrow",
|
|
13085
13126
|
id: "arrow",
|
|
13086
13127
|
module: "arrow",
|
|
13087
13128
|
version: VERSION,
|
|
13129
|
+
// worker: true,
|
|
13088
13130
|
category: "table",
|
|
13089
13131
|
extensions: ["arrow", "feather"],
|
|
13090
|
-
mimeTypes: [
|
|
13132
|
+
mimeTypes: [
|
|
13133
|
+
"application/vnd.apache.arrow.file",
|
|
13134
|
+
"application/vnd.apache.arrow.stream",
|
|
13135
|
+
"application/octet-stream"
|
|
13136
|
+
],
|
|
13091
13137
|
binary: true,
|
|
13092
13138
|
tests: ["ARROW"],
|
|
13093
13139
|
options: {
|
|
@@ -13116,23 +13162,27 @@ return true;`);
|
|
|
13116
13162
|
}
|
|
13117
13163
|
function createVector(array, type) {
|
|
13118
13164
|
switch (type) {
|
|
13119
|
-
case
|
|
13165
|
+
case 1 /* DATE */:
|
|
13120
13166
|
return vectorFromArray(array);
|
|
13121
|
-
case
|
|
13167
|
+
case 0 /* FLOAT */:
|
|
13122
13168
|
default:
|
|
13123
13169
|
return vectorFromArray(array);
|
|
13124
13170
|
}
|
|
13125
13171
|
}
|
|
13126
13172
|
|
|
13127
13173
|
// src/arrow-writer.ts
|
|
13128
|
-
var VERSION2 =
|
|
13174
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
13129
13175
|
var ArrowWriter = {
|
|
13130
13176
|
name: "Apache Arrow",
|
|
13131
13177
|
id: "arrow",
|
|
13132
13178
|
module: "arrow",
|
|
13133
13179
|
version: VERSION2,
|
|
13134
13180
|
extensions: ["arrow", "feather"],
|
|
13135
|
-
mimeTypes: [
|
|
13181
|
+
mimeTypes: [
|
|
13182
|
+
"application/vnd.apache.arrow.file",
|
|
13183
|
+
"application/vnd.apache.arrow.stream",
|
|
13184
|
+
"application/octet-stream"
|
|
13185
|
+
],
|
|
13136
13186
|
binary: true,
|
|
13137
13187
|
options: {},
|
|
13138
13188
|
encode: async function encodeArrow(data, options) {
|
|
@@ -13144,7 +13194,16 @@ return true;`);
|
|
|
13144
13194
|
};
|
|
13145
13195
|
|
|
13146
13196
|
// ../gis/src/lib/geo/geoarrow-metadata.ts
|
|
13147
|
-
var GEOARROW_ENCODINGS = [
|
|
13197
|
+
var GEOARROW_ENCODINGS = [
|
|
13198
|
+
"geoarrow.multipolygon",
|
|
13199
|
+
"geoarrow.polygon",
|
|
13200
|
+
"geoarrow.multilinestring",
|
|
13201
|
+
"geoarrow.linestring",
|
|
13202
|
+
"geoarrow.multipoint",
|
|
13203
|
+
"geoarrow.point",
|
|
13204
|
+
"geoarrow.wkb",
|
|
13205
|
+
"geoarrow.wkt"
|
|
13206
|
+
];
|
|
13148
13207
|
var GEOARROW_COLUMN_METADATA_ENCODING = "ARROW:extension:name";
|
|
13149
13208
|
var GEOARROW_COLUMN_METADATA_METADATA = "ARROW:extension:metadata";
|
|
13150
13209
|
function getGeometryColumnsFromSchema(schema) {
|
|
@@ -13760,11 +13819,11 @@ return true;`);
|
|
|
13760
13819
|
}
|
|
13761
13820
|
}
|
|
13762
13821
|
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
13763
|
-
const {
|
|
13764
|
-
positions
|
|
13765
|
-
} = data;
|
|
13822
|
+
const { positions } = data;
|
|
13766
13823
|
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13767
|
-
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
|
|
13824
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
|
|
13825
|
+
(x) => x >= startIndex && x <= endIndex
|
|
13826
|
+
);
|
|
13768
13827
|
const multi = polygonIndices.length > 2;
|
|
13769
13828
|
if (!multi) {
|
|
13770
13829
|
const coordinates2 = [];
|
|
@@ -13774,62 +13833,44 @@ return true;`);
|
|
|
13774
13833
|
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
13775
13834
|
coordinates2.push(ringCoordinates);
|
|
13776
13835
|
}
|
|
13777
|
-
return {
|
|
13778
|
-
type: "Polygon",
|
|
13779
|
-
coordinates: coordinates2
|
|
13780
|
-
};
|
|
13836
|
+
return { type: "Polygon", coordinates: coordinates2 };
|
|
13781
13837
|
}
|
|
13782
13838
|
const coordinates = [];
|
|
13783
13839
|
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
13784
13840
|
const startPolygonIndex = polygonIndices[i];
|
|
13785
13841
|
const endPolygonIndex = polygonIndices[i + 1];
|
|
13786
|
-
const polygonCoordinates = polygonToGeoJson(
|
|
13842
|
+
const polygonCoordinates = polygonToGeoJson(
|
|
13843
|
+
data,
|
|
13844
|
+
startPolygonIndex,
|
|
13845
|
+
endPolygonIndex
|
|
13846
|
+
).coordinates;
|
|
13787
13847
|
coordinates.push(polygonCoordinates);
|
|
13788
13848
|
}
|
|
13789
|
-
return {
|
|
13790
|
-
type: "MultiPolygon",
|
|
13791
|
-
coordinates
|
|
13792
|
-
};
|
|
13849
|
+
return { type: "MultiPolygon", coordinates };
|
|
13793
13850
|
}
|
|
13794
13851
|
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
13795
|
-
const {
|
|
13796
|
-
positions
|
|
13797
|
-
} = data;
|
|
13852
|
+
const { positions } = data;
|
|
13798
13853
|
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13799
13854
|
const multi = pathIndices.length > 2;
|
|
13800
13855
|
if (!multi) {
|
|
13801
13856
|
const coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
13802
|
-
return {
|
|
13803
|
-
type: "LineString",
|
|
13804
|
-
coordinates: coordinates2
|
|
13805
|
-
};
|
|
13857
|
+
return { type: "LineString", coordinates: coordinates2 };
|
|
13806
13858
|
}
|
|
13807
13859
|
const coordinates = [];
|
|
13808
13860
|
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
13809
13861
|
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
13810
13862
|
coordinates.push(ringCoordinates);
|
|
13811
13863
|
}
|
|
13812
|
-
return {
|
|
13813
|
-
type: "MultiLineString",
|
|
13814
|
-
coordinates
|
|
13815
|
-
};
|
|
13864
|
+
return { type: "MultiLineString", coordinates };
|
|
13816
13865
|
}
|
|
13817
13866
|
function pointToGeoJson(data, startIndex, endIndex) {
|
|
13818
|
-
const {
|
|
13819
|
-
positions
|
|
13820
|
-
} = data;
|
|
13867
|
+
const { positions } = data;
|
|
13821
13868
|
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
13822
13869
|
const multi = coordinates.length > 1;
|
|
13823
13870
|
if (multi) {
|
|
13824
|
-
return {
|
|
13825
|
-
type: "MultiPoint",
|
|
13826
|
-
coordinates
|
|
13827
|
-
};
|
|
13871
|
+
return { type: "MultiPoint", coordinates };
|
|
13828
13872
|
}
|
|
13829
|
-
return {
|
|
13830
|
-
type: "Point",
|
|
13831
|
-
coordinates: coordinates[0]
|
|
13832
|
-
};
|
|
13873
|
+
return { type: "Point", coordinates: coordinates[0] };
|
|
13833
13874
|
}
|
|
13834
13875
|
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
13835
13876
|
startIndex = startIndex || 0;
|
|
@@ -13860,11 +13901,7 @@ return true;`);
|
|
|
13860
13901
|
const feature = parseGeometryFromArrow(arrowGeometry, encoding);
|
|
13861
13902
|
if (feature) {
|
|
13862
13903
|
const properties = propertiesTable.get(row)?.toJSON() || {};
|
|
13863
|
-
features.push({
|
|
13864
|
-
type: "Feature",
|
|
13865
|
-
geometry: feature,
|
|
13866
|
-
properties
|
|
13867
|
-
});
|
|
13904
|
+
features.push({ type: "Feature", geometry: feature, properties });
|
|
13868
13905
|
}
|
|
13869
13906
|
}
|
|
13870
13907
|
return {
|
|
@@ -13877,9 +13914,7 @@ return true;`);
|
|
|
13877
13914
|
|
|
13878
13915
|
// src/parsers/parse-geoarrow-sync.ts
|
|
13879
13916
|
function parseGeoArrowSync(arrayBuffer, options) {
|
|
13880
|
-
const table = parseArrowSync(arrayBuffer, {
|
|
13881
|
-
shape: "arrow-table"
|
|
13882
|
-
});
|
|
13917
|
+
const table = parseArrowSync(arrayBuffer, { shape: "arrow-table" });
|
|
13883
13918
|
switch (options?.shape) {
|
|
13884
13919
|
case "geojson-table":
|
|
13885
13920
|
return convertArrowToGeoJSONTable(table);
|
|
@@ -13939,28 +13974,13 @@ return true;`);
|
|
|
13939
13974
|
}
|
|
13940
13975
|
|
|
13941
13976
|
// src/geoarrow/convert-geoarrow-to-binary-geometry.ts
|
|
13942
|
-
var BinaryGeometryType = function(BinaryGeometryType2) {
|
|
13943
|
-
BinaryGeometryType2["points"] = "points";
|
|
13944
|
-
BinaryGeometryType2["lines"] = "lines";
|
|
13945
|
-
BinaryGeometryType2["polygons"] = "polygons";
|
|
13946
|
-
return BinaryGeometryType2;
|
|
13947
|
-
}(BinaryGeometryType || {});
|
|
13948
13977
|
function getBinaryGeometryTemplate() {
|
|
13949
13978
|
return {
|
|
13950
|
-
globalFeatureIds: {
|
|
13951
|
-
|
|
13952
|
-
size: 1
|
|
13953
|
-
},
|
|
13954
|
-
positions: {
|
|
13955
|
-
value: new Float32Array(0),
|
|
13956
|
-
size: 2
|
|
13957
|
-
},
|
|
13979
|
+
globalFeatureIds: { value: new Uint32Array(0), size: 1 },
|
|
13980
|
+
positions: { value: new Float32Array(0), size: 2 },
|
|
13958
13981
|
properties: [],
|
|
13959
13982
|
numericProps: {},
|
|
13960
|
-
featureIds: {
|
|
13961
|
-
value: new Uint32Array(0),
|
|
13962
|
-
size: 1
|
|
13963
|
-
}
|
|
13983
|
+
featureIds: { value: new Uint32Array(0), size: 1 }
|
|
13964
13984
|
};
|
|
13965
13985
|
}
|
|
13966
13986
|
function getBinaryGeometriesFromArrow(geoColumn, geoEncoding, options) {
|
|
@@ -13974,30 +13994,19 @@ return true;`);
|
|
|
13974
13994
|
let globalFeatureIdOffset = options?.chunkOffset || 0;
|
|
13975
13995
|
const binaryGeometries = [];
|
|
13976
13996
|
chunks.forEach((chunk) => {
|
|
13977
|
-
const {
|
|
13978
|
-
featureIds,
|
|
13979
|
-
flatCoordinateArray,
|
|
13980
|
-
nDim,
|
|
13981
|
-
geomOffset,
|
|
13982
|
-
triangles
|
|
13983
|
-
} = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
|
|
13997
|
+
const { featureIds, flatCoordinateArray, nDim, geomOffset, triangles } = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
|
|
13984
13998
|
const globalFeatureIds = new Uint32Array(featureIds.length);
|
|
13985
13999
|
for (let i = 0; i < featureIds.length; i++) {
|
|
13986
14000
|
globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
|
|
13987
14001
|
}
|
|
13988
14002
|
const binaryContent = {
|
|
13989
|
-
globalFeatureIds: {
|
|
13990
|
-
value: globalFeatureIds,
|
|
13991
|
-
size: 1
|
|
13992
|
-
},
|
|
14003
|
+
globalFeatureIds: { value: globalFeatureIds, size: 1 },
|
|
13993
14004
|
positions: {
|
|
13994
14005
|
value: flatCoordinateArray,
|
|
13995
14006
|
size: nDim
|
|
13996
14007
|
},
|
|
13997
|
-
featureIds: {
|
|
13998
|
-
|
|
13999
|
-
size: 1
|
|
14000
|
-
},
|
|
14008
|
+
featureIds: { value: featureIds, size: 1 },
|
|
14009
|
+
// eslint-disable-next-line no-loop-func
|
|
14001
14010
|
properties: [...Array(chunk.length).keys()].map((i) => ({
|
|
14002
14011
|
index: i + globalFeatureIdOffset
|
|
14003
14012
|
}))
|
|
@@ -14014,16 +14023,14 @@ return true;`);
|
|
|
14014
14023
|
type: "LineString",
|
|
14015
14024
|
...getBinaryGeometryTemplate(),
|
|
14016
14025
|
...featureTypes.line ? binaryContent : {},
|
|
14017
|
-
pathIndices: {
|
|
14018
|
-
value: featureTypes.line ? geomOffset : new Uint16Array(0),
|
|
14019
|
-
size: 1
|
|
14020
|
-
}
|
|
14026
|
+
pathIndices: { value: featureTypes.line ? geomOffset : new Uint16Array(0), size: 1 }
|
|
14021
14027
|
},
|
|
14022
14028
|
polygons: {
|
|
14023
14029
|
type: "Polygon",
|
|
14024
14030
|
...getBinaryGeometryTemplate(),
|
|
14025
14031
|
...featureTypes.polygon ? binaryContent : {},
|
|
14026
14032
|
polygonIndices: {
|
|
14033
|
+
// use geomOffset as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
|
|
14027
14034
|
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
14028
14035
|
size: 1
|
|
14029
14036
|
},
|
|
@@ -14031,12 +14038,7 @@ return true;`);
|
|
|
14031
14038
|
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
14032
14039
|
size: 1
|
|
14033
14040
|
},
|
|
14034
|
-
...triangles ? {
|
|
14035
|
-
triangles: {
|
|
14036
|
-
value: triangles,
|
|
14037
|
-
size: 1
|
|
14038
|
-
}
|
|
14039
|
-
} : {}
|
|
14041
|
+
...triangles ? { triangles: { value: triangles, size: 1 } } : {}
|
|
14040
14042
|
}
|
|
14041
14043
|
});
|
|
14042
14044
|
bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
|
|
@@ -14045,9 +14047,7 @@ return true;`);
|
|
|
14045
14047
|
binaryGeometries,
|
|
14046
14048
|
bounds,
|
|
14047
14049
|
featureTypes,
|
|
14048
|
-
...options?.calculateMeanCenters ? {
|
|
14049
|
-
meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries)
|
|
14050
|
-
} : {}
|
|
14050
|
+
...options?.calculateMeanCenters ? { meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries) } : {}
|
|
14051
14051
|
};
|
|
14052
14052
|
}
|
|
14053
14053
|
function getMeanCentersFromBinaryGeometries(binaryGeometries) {
|
|
@@ -14055,11 +14055,11 @@ return true;`);
|
|
|
14055
14055
|
binaryGeometries.forEach((binaryGeometry) => {
|
|
14056
14056
|
let binaryGeometryType = null;
|
|
14057
14057
|
if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
|
|
14058
|
-
binaryGeometryType =
|
|
14058
|
+
binaryGeometryType = "points" /* points */;
|
|
14059
14059
|
} else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
|
|
14060
|
-
binaryGeometryType =
|
|
14060
|
+
binaryGeometryType = "lines" /* lines */;
|
|
14061
14061
|
} else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
|
|
14062
|
-
binaryGeometryType =
|
|
14062
|
+
binaryGeometryType = "polygons" /* polygons */;
|
|
14063
14063
|
}
|
|
14064
14064
|
const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
|
|
14065
14065
|
if (binaryContent && binaryGeometryType !== null) {
|
|
@@ -14067,7 +14067,13 @@ return true;`);
|
|
|
14067
14067
|
const flatCoordinateArray = binaryContent.positions.value;
|
|
14068
14068
|
const nDim = binaryContent.positions.size;
|
|
14069
14069
|
const primitivePolygonIndices = binaryContent.type === "Polygon" ? binaryContent.primitivePolygonIndices?.value : void 0;
|
|
14070
|
-
const meanCenters = getMeanCentersFromGeometry(
|
|
14070
|
+
const meanCenters = getMeanCentersFromGeometry(
|
|
14071
|
+
featureIds,
|
|
14072
|
+
flatCoordinateArray,
|
|
14073
|
+
nDim,
|
|
14074
|
+
binaryGeometryType,
|
|
14075
|
+
primitivePolygonIndices
|
|
14076
|
+
);
|
|
14071
14077
|
meanCenters.forEach((center) => {
|
|
14072
14078
|
globalMeanCenters.push(center);
|
|
14073
14079
|
});
|
|
@@ -14086,7 +14092,7 @@ return true;`);
|
|
|
14086
14092
|
const center = [0, 0];
|
|
14087
14093
|
let vertexCountInFeature = 0;
|
|
14088
14094
|
while (vertexIndex < vertexCount && featureIds[coordIdx] === featureId) {
|
|
14089
|
-
if (geometryType ===
|
|
14095
|
+
if (geometryType === "polygons" /* polygons */ && primitivePolygonIndices?.[primitiveIdx] === coordIdx) {
|
|
14090
14096
|
vertexIndex += nDim;
|
|
14091
14097
|
primitiveIdx++;
|
|
14092
14098
|
} else {
|
|
@@ -14133,7 +14139,11 @@ return true;`);
|
|
|
14133
14139
|
}
|
|
14134
14140
|
primitiveIndex++;
|
|
14135
14141
|
}
|
|
14136
|
-
const triangleIndices = earcut(
|
|
14142
|
+
const triangleIndices = earcut(
|
|
14143
|
+
slicedFlatCoords,
|
|
14144
|
+
holeIndices.length > 0 ? holeIndices : void 0,
|
|
14145
|
+
nDim
|
|
14146
|
+
);
|
|
14137
14147
|
if (triangleIndices.length === 0) {
|
|
14138
14148
|
throw Error("earcut failed e.g. invalid polygon");
|
|
14139
14149
|
}
|
|
@@ -14181,9 +14191,7 @@ return true;`);
|
|
|
14181
14191
|
flatCoordinateArray,
|
|
14182
14192
|
geomOffset,
|
|
14183
14193
|
geometryIndicies,
|
|
14184
|
-
...options?.triangulate && triangles ? {
|
|
14185
|
-
triangles
|
|
14186
|
-
} : {}
|
|
14194
|
+
...options?.triangulate && triangles ? { triangles } : {}
|
|
14187
14195
|
};
|
|
14188
14196
|
}
|
|
14189
14197
|
function getBinaryLinesFromChunk(chunk, geoEncoding) {
|
|
@@ -14257,12 +14265,21 @@ return true;`);
|
|
|
14257
14265
|
}
|
|
14258
14266
|
|
|
14259
14267
|
// ../wkt/src/lib/utils/version.ts
|
|
14260
|
-
var VERSION3 =
|
|
14268
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
14261
14269
|
|
|
14262
14270
|
// ../wkt/src/lib/parse-wkt.ts
|
|
14263
14271
|
var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
|
|
14264
14272
|
var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
|
|
14265
|
-
var WKT_MAGIC_STRINGS = [
|
|
14273
|
+
var WKT_MAGIC_STRINGS = [
|
|
14274
|
+
"POINT(",
|
|
14275
|
+
"LINESTRING(",
|
|
14276
|
+
"POLYGON(",
|
|
14277
|
+
"MULTIPOINT(",
|
|
14278
|
+
"MULTILINESTRING(",
|
|
14279
|
+
"MULTIPOLYGON(",
|
|
14280
|
+
"GEOMETRYCOLLECTION("
|
|
14281
|
+
// We only support this "geojson" subset of the OGC simple features standard
|
|
14282
|
+
];
|
|
14266
14283
|
function isWKT(input) {
|
|
14267
14284
|
return WKT_MAGIC_STRINGS.some((magicString) => input.startsWith(magicString));
|
|
14268
14285
|
}
|
|
@@ -14273,11 +14290,7 @@ return true;`);
|
|
|
14273
14290
|
const parts = input.split(";");
|
|
14274
14291
|
let _ = parts.pop();
|
|
14275
14292
|
const srid = (parts.shift() || "").split("=").pop();
|
|
14276
|
-
const state = {
|
|
14277
|
-
parts,
|
|
14278
|
-
_,
|
|
14279
|
-
i: 0
|
|
14280
|
-
};
|
|
14293
|
+
const state = { parts, _, i: 0 };
|
|
14281
14294
|
const geometry = parseGeometry(state);
|
|
14282
14295
|
return options?.wkt?.crs ? addCRS(geometry, srid) : geometry;
|
|
14283
14296
|
}
|
|
@@ -14364,7 +14377,9 @@ return true;`);
|
|
|
14364
14377
|
}
|
|
14365
14378
|
white(state);
|
|
14366
14379
|
return {
|
|
14380
|
+
// @ts-ignore
|
|
14367
14381
|
type: "MultiLineString",
|
|
14382
|
+
// @ts-expect-error
|
|
14368
14383
|
coordinates: c
|
|
14369
14384
|
};
|
|
14370
14385
|
}
|
|
@@ -14378,7 +14393,9 @@ return true;`);
|
|
|
14378
14393
|
return null;
|
|
14379
14394
|
}
|
|
14380
14395
|
return {
|
|
14396
|
+
// @ts-ignore
|
|
14381
14397
|
type: "Polygon",
|
|
14398
|
+
// @ts-expect-error
|
|
14382
14399
|
coordinates: c
|
|
14383
14400
|
};
|
|
14384
14401
|
}
|
|
@@ -14393,6 +14410,7 @@ return true;`);
|
|
|
14393
14410
|
}
|
|
14394
14411
|
return {
|
|
14395
14412
|
type: "MultiPolygon",
|
|
14413
|
+
// @ts-expect-error
|
|
14396
14414
|
coordinates: c
|
|
14397
14415
|
};
|
|
14398
14416
|
}
|
|
@@ -14521,16 +14539,6 @@ return true;`);
|
|
|
14521
14539
|
var EWKB_FLAG_M = 1073741824;
|
|
14522
14540
|
var EWKB_FLAG_SRID = 536870912;
|
|
14523
14541
|
var MAX_SRID = 1e4;
|
|
14524
|
-
var WKBGeometryType = function(WKBGeometryType2) {
|
|
14525
|
-
WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
|
|
14526
|
-
WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
|
|
14527
|
-
WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
|
|
14528
|
-
WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
|
|
14529
|
-
WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
|
|
14530
|
-
WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
14531
|
-
WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
14532
|
-
return WKBGeometryType2;
|
|
14533
|
-
}({});
|
|
14534
14542
|
function isWKB(arrayBuffer) {
|
|
14535
14543
|
const dataView = new DataView(arrayBuffer);
|
|
14536
14544
|
let byteOffset = 0;
|
|
@@ -14641,31 +14649,27 @@ return true;`);
|
|
|
14641
14649
|
function parseWKBToBinary(arrayBuffer, options) {
|
|
14642
14650
|
const dataView = new DataView(arrayBuffer);
|
|
14643
14651
|
const wkbHeader = parseWKBHeader(dataView);
|
|
14644
|
-
const {
|
|
14645
|
-
geometryType,
|
|
14646
|
-
dimensions,
|
|
14647
|
-
littleEndian
|
|
14648
|
-
} = wkbHeader;
|
|
14652
|
+
const { geometryType, dimensions, littleEndian } = wkbHeader;
|
|
14649
14653
|
const offset = wkbHeader.byteOffset;
|
|
14650
14654
|
switch (geometryType) {
|
|
14651
|
-
case
|
|
14655
|
+
case 1 /* Point */:
|
|
14652
14656
|
const point = parsePoint2(dataView, offset, dimensions, littleEndian);
|
|
14653
14657
|
return point.geometry;
|
|
14654
|
-
case
|
|
14658
|
+
case 2 /* LineString */:
|
|
14655
14659
|
const line = parseLineString2(dataView, offset, dimensions, littleEndian);
|
|
14656
14660
|
return line.geometry;
|
|
14657
|
-
case
|
|
14661
|
+
case 3 /* Polygon */:
|
|
14658
14662
|
const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
|
|
14659
14663
|
return polygon.geometry;
|
|
14660
|
-
case
|
|
14664
|
+
case 4 /* MultiPoint */:
|
|
14661
14665
|
const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
|
|
14662
14666
|
multiPoint.type = "Point";
|
|
14663
14667
|
return multiPoint;
|
|
14664
|
-
case
|
|
14668
|
+
case 5 /* MultiLineString */:
|
|
14665
14669
|
const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
|
|
14666
14670
|
multiLine.type = "LineString";
|
|
14667
14671
|
return multiLine;
|
|
14668
|
-
case
|
|
14672
|
+
case 6 /* MultiPolygon */:
|
|
14669
14673
|
const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
|
|
14670
14674
|
multiPolygon.type = "Polygon";
|
|
14671
14675
|
return multiPolygon;
|
|
@@ -14680,13 +14684,7 @@ return true;`);
|
|
|
14680
14684
|
offset += 8;
|
|
14681
14685
|
}
|
|
14682
14686
|
return {
|
|
14683
|
-
geometry: {
|
|
14684
|
-
type: "Point",
|
|
14685
|
-
positions: {
|
|
14686
|
-
value: positions,
|
|
14687
|
-
size: dimension
|
|
14688
|
-
}
|
|
14689
|
-
},
|
|
14687
|
+
geometry: { type: "Point", positions: { value: positions, size: dimension } },
|
|
14690
14688
|
offset
|
|
14691
14689
|
};
|
|
14692
14690
|
}
|
|
@@ -14705,14 +14703,8 @@ return true;`);
|
|
|
14705
14703
|
return {
|
|
14706
14704
|
geometry: {
|
|
14707
14705
|
type: "LineString",
|
|
14708
|
-
positions: {
|
|
14709
|
-
|
|
14710
|
-
size: dimension
|
|
14711
|
-
},
|
|
14712
|
-
pathIndices: {
|
|
14713
|
-
value: new Uint16Array(pathIndices),
|
|
14714
|
-
size: 1
|
|
14715
|
-
}
|
|
14706
|
+
positions: { value: positions, size: dimension },
|
|
14707
|
+
pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
|
|
14716
14708
|
},
|
|
14717
14709
|
offset
|
|
14718
14710
|
};
|
|
@@ -14724,9 +14716,7 @@ return true;`);
|
|
|
14724
14716
|
const rings = [];
|
|
14725
14717
|
for (let i = 0; i < nRings; i++) {
|
|
14726
14718
|
const parsed = parseLineString2(dataView, offset, dimension, littleEndian);
|
|
14727
|
-
const {
|
|
14728
|
-
positions
|
|
14729
|
-
} = parsed.geometry;
|
|
14719
|
+
const { positions } = parsed.geometry;
|
|
14730
14720
|
offset = parsed.offset;
|
|
14731
14721
|
rings.push(positions.value);
|
|
14732
14722
|
}
|
|
@@ -14740,18 +14730,12 @@ return true;`);
|
|
|
14740
14730
|
return {
|
|
14741
14731
|
geometry: {
|
|
14742
14732
|
type: "Polygon",
|
|
14743
|
-
positions: {
|
|
14744
|
-
value: concatenatedPositions,
|
|
14745
|
-
size: dimension
|
|
14746
|
-
},
|
|
14733
|
+
positions: { value: concatenatedPositions, size: dimension },
|
|
14747
14734
|
polygonIndices: {
|
|
14748
14735
|
value: new Uint16Array(polygonIndices),
|
|
14749
14736
|
size: 1
|
|
14750
14737
|
},
|
|
14751
|
-
primitivePolygonIndices: {
|
|
14752
|
-
value: new Uint16Array(primitivePolygonIndices),
|
|
14753
|
-
size: 1
|
|
14754
|
-
}
|
|
14738
|
+
primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
|
|
14755
14739
|
},
|
|
14756
14740
|
offset
|
|
14757
14741
|
};
|
|
@@ -14812,10 +14796,7 @@ return true;`);
|
|
|
14812
14796
|
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
14813
14797
|
return {
|
|
14814
14798
|
type: "Point",
|
|
14815
|
-
positions: {
|
|
14816
|
-
value: concatenatedPositions,
|
|
14817
|
-
size: dimension
|
|
14818
|
-
}
|
|
14799
|
+
positions: { value: concatenatedPositions, size: dimension }
|
|
14819
14800
|
};
|
|
14820
14801
|
}
|
|
14821
14802
|
function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
|
|
@@ -14825,24 +14806,15 @@ return true;`);
|
|
|
14825
14806
|
pathIndices.unshift(0);
|
|
14826
14807
|
return {
|
|
14827
14808
|
type: "LineString",
|
|
14828
|
-
positions: {
|
|
14829
|
-
|
|
14830
|
-
size: dimension
|
|
14831
|
-
},
|
|
14832
|
-
pathIndices: {
|
|
14833
|
-
value: new Uint16Array(pathIndices),
|
|
14834
|
-
size: 1
|
|
14835
|
-
}
|
|
14809
|
+
positions: { value: concatenatedPositions, size: dimension },
|
|
14810
|
+
pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
|
|
14836
14811
|
};
|
|
14837
14812
|
}
|
|
14838
14813
|
function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
|
|
14839
14814
|
const polygons = [];
|
|
14840
14815
|
const primitivePolygons = [];
|
|
14841
14816
|
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
14842
|
-
const {
|
|
14843
|
-
positions,
|
|
14844
|
-
primitivePolygonIndices: primitivePolygonIndices2
|
|
14845
|
-
} = binaryPolygon;
|
|
14817
|
+
const { positions, primitivePolygonIndices: primitivePolygonIndices2 } = binaryPolygon;
|
|
14846
14818
|
polygons.push(positions.value);
|
|
14847
14819
|
primitivePolygons.push(primitivePolygonIndices2.value);
|
|
14848
14820
|
}
|
|
@@ -14851,22 +14823,15 @@ return true;`);
|
|
|
14851
14823
|
polygonIndices.unshift(0);
|
|
14852
14824
|
const primitivePolygonIndices = [0];
|
|
14853
14825
|
for (const primitivePolygon of primitivePolygons) {
|
|
14854
|
-
primitivePolygonIndices.push(
|
|
14826
|
+
primitivePolygonIndices.push(
|
|
14827
|
+
...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1])
|
|
14828
|
+
);
|
|
14855
14829
|
}
|
|
14856
14830
|
return {
|
|
14857
14831
|
type: "Polygon",
|
|
14858
|
-
positions: {
|
|
14859
|
-
|
|
14860
|
-
|
|
14861
|
-
},
|
|
14862
|
-
polygonIndices: {
|
|
14863
|
-
value: new Uint16Array(polygonIndices),
|
|
14864
|
-
size: 1
|
|
14865
|
-
},
|
|
14866
|
-
primitivePolygonIndices: {
|
|
14867
|
-
value: new Uint16Array(primitivePolygonIndices),
|
|
14868
|
-
size: 1
|
|
14869
|
-
}
|
|
14832
|
+
positions: { value: concatenatedPositions, size: dimension },
|
|
14833
|
+
polygonIndices: { value: new Uint32Array(polygonIndices), size: 1 },
|
|
14834
|
+
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
14870
14835
|
};
|
|
14871
14836
|
}
|
|
14872
14837
|
function concatTypedArrays(arrays) {
|
|
@@ -14896,10 +14861,12 @@ return true;`);
|
|
|
14896
14861
|
category: "geometry",
|
|
14897
14862
|
extensions: ["wkb"],
|
|
14898
14863
|
mimeTypes: [],
|
|
14864
|
+
// TODO can we define static, serializable tests, eg. some binary strings?
|
|
14899
14865
|
tests: [isWKB],
|
|
14900
14866
|
options: {
|
|
14901
14867
|
wkb: {
|
|
14902
14868
|
shape: "binary-geometry"
|
|
14869
|
+
// 'geojson-geometry'
|
|
14903
14870
|
}
|
|
14904
14871
|
}
|
|
14905
14872
|
};
|
|
@@ -14948,7 +14915,10 @@ return true;`);
|
|
|
14948
14915
|
return geometry;
|
|
14949
14916
|
}
|
|
14950
14917
|
function arrowWKBToFeature(arrowCellValue) {
|
|
14951
|
-
const arrayBuffer = arrowCellValue.buffer.slice(
|
|
14918
|
+
const arrayBuffer = arrowCellValue.buffer.slice(
|
|
14919
|
+
arrowCellValue.byteOffset,
|
|
14920
|
+
arrowCellValue.byteOffset + arrowCellValue.byteLength
|
|
14921
|
+
);
|
|
14952
14922
|
const binaryGeometry = WKBLoader.parseSync?.(arrayBuffer);
|
|
14953
14923
|
const geometry = binaryToGeometry(binaryGeometry);
|
|
14954
14924
|
return geometry;
|
|
@@ -15072,7 +15042,17 @@ return true;`);
|
|
|
15072
15042
|
[BufferType.VALIDITY]: cloneBuffer(data.buffers[BufferType.VALIDITY], force),
|
|
15073
15043
|
[BufferType.TYPE]: cloneBuffer(data.buffers[BufferType.TYPE], force)
|
|
15074
15044
|
};
|
|
15075
|
-
return new Data(
|
|
15045
|
+
return new Data(
|
|
15046
|
+
data.type,
|
|
15047
|
+
data.offset,
|
|
15048
|
+
data.length,
|
|
15049
|
+
// @ts-expect-error _nullCount is protected. We're using it here to mimic
|
|
15050
|
+
// `Data.clone`
|
|
15051
|
+
data._nullCount,
|
|
15052
|
+
clonedBuffers,
|
|
15053
|
+
clonedChildren,
|
|
15054
|
+
clonedDictionary
|
|
15055
|
+
);
|
|
15076
15056
|
}
|
|
15077
15057
|
function isTypedArraySliced(arr) {
|
|
15078
15058
|
return !(arr.byteOffset === 0 && arr.byteLength === arr.buffer.byteLength);
|
|
@@ -15092,11 +15072,13 @@ return true;`);
|
|
|
15092
15072
|
function getVersion() {
|
|
15093
15073
|
if (!globalThis._loadersgl_?.version) {
|
|
15094
15074
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
15095
|
-
if (
|
|
15096
|
-
console.warn(
|
|
15075
|
+
if (typeof __VERSION__ === "undefined") {
|
|
15076
|
+
console.warn(
|
|
15077
|
+
"loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
|
|
15078
|
+
);
|
|
15097
15079
|
globalThis._loadersgl_.version = NPM_TAG;
|
|
15098
15080
|
} else {
|
|
15099
|
-
globalThis._loadersgl_.version =
|
|
15081
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
15100
15082
|
}
|
|
15101
15083
|
}
|
|
15102
15084
|
return globalThis._loadersgl_.version;
|
|
@@ -15121,14 +15103,21 @@ return true;`);
|
|
|
15121
15103
|
var window_ = globals.window || globals.self || globals.global || {};
|
|
15122
15104
|
var global_ = globals.global || globals.self || globals.window || {};
|
|
15123
15105
|
var document_ = globals.document || {};
|
|
15124
|
-
var isBrowser =
|
|
15106
|
+
var isBrowser = (
|
|
15107
|
+
// @ts-ignore process.browser
|
|
15108
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
15109
|
+
);
|
|
15125
15110
|
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
15126
15111
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
15127
15112
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
15128
15113
|
|
|
15129
15114
|
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
15130
15115
|
var WorkerJob = class {
|
|
15116
|
+
name;
|
|
15117
|
+
workerThread;
|
|
15131
15118
|
isRunning = true;
|
|
15119
|
+
/** Promise that resolves when Job is done */
|
|
15120
|
+
result;
|
|
15132
15121
|
_resolve = () => {
|
|
15133
15122
|
};
|
|
15134
15123
|
_reject = () => {
|
|
@@ -15141,18 +15130,29 @@ return true;`);
|
|
|
15141
15130
|
this._reject = reject;
|
|
15142
15131
|
});
|
|
15143
15132
|
}
|
|
15133
|
+
/**
|
|
15134
|
+
* Send a message to the job's worker thread
|
|
15135
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
15136
|
+
*/
|
|
15144
15137
|
postMessage(type, payload) {
|
|
15145
15138
|
this.workerThread.postMessage({
|
|
15146
15139
|
source: "loaders.gl",
|
|
15140
|
+
// Lets worker ignore unrelated messages
|
|
15147
15141
|
type,
|
|
15148
15142
|
payload
|
|
15149
15143
|
});
|
|
15150
15144
|
}
|
|
15145
|
+
/**
|
|
15146
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
15147
|
+
*/
|
|
15151
15148
|
done(value) {
|
|
15152
15149
|
assert(this.isRunning);
|
|
15153
15150
|
this.isRunning = false;
|
|
15154
15151
|
this._resolve(value);
|
|
15155
15152
|
}
|
|
15153
|
+
/**
|
|
15154
|
+
* Call to reject the `result` Promise with the supplied error
|
|
15155
|
+
*/
|
|
15156
15156
|
error(error) {
|
|
15157
15157
|
assert(this.isRunning);
|
|
15158
15158
|
this.isRunning = false;
|
|
@@ -15192,9 +15192,7 @@ return true;`);
|
|
|
15192
15192
|
return getLoadableWorkerURLFromSource(workerSource);
|
|
15193
15193
|
}
|
|
15194
15194
|
function getLoadableWorkerURLFromSource(workerSource) {
|
|
15195
|
-
const blob = new Blob([workerSource], {
|
|
15196
|
-
type: "application/javascript"
|
|
15197
|
-
});
|
|
15195
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
15198
15196
|
return URL.createObjectURL(blob);
|
|
15199
15197
|
}
|
|
15200
15198
|
function buildScriptSource(workerUrl) {
|
|
@@ -15261,17 +15259,20 @@ return true;`);
|
|
|
15261
15259
|
var NOOP = () => {
|
|
15262
15260
|
};
|
|
15263
15261
|
var WorkerThread = class {
|
|
15262
|
+
name;
|
|
15263
|
+
source;
|
|
15264
|
+
url;
|
|
15264
15265
|
terminated = false;
|
|
15266
|
+
worker;
|
|
15267
|
+
onMessage;
|
|
15268
|
+
onError;
|
|
15265
15269
|
_loadableURL = "";
|
|
15270
|
+
/** Checks if workers are supported on this platform */
|
|
15266
15271
|
static isSupported() {
|
|
15267
15272
|
return typeof Worker !== "undefined" && isBrowser || typeof NodeWorker !== "undefined" && !isBrowser;
|
|
15268
15273
|
}
|
|
15269
15274
|
constructor(props) {
|
|
15270
|
-
const {
|
|
15271
|
-
name,
|
|
15272
|
-
source,
|
|
15273
|
-
url
|
|
15274
|
-
} = props;
|
|
15275
|
+
const { name, source, url } = props;
|
|
15275
15276
|
assert(source || url);
|
|
15276
15277
|
this.name = name;
|
|
15277
15278
|
this.source = source;
|
|
@@ -15280,6 +15281,10 @@ return true;`);
|
|
|
15280
15281
|
this.onError = (error) => console.log(error);
|
|
15281
15282
|
this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker();
|
|
15282
15283
|
}
|
|
15284
|
+
/**
|
|
15285
|
+
* Terminate this worker thread
|
|
15286
|
+
* @note Can free up significant memory
|
|
15287
|
+
*/
|
|
15283
15288
|
destroy() {
|
|
15284
15289
|
this.onMessage = NOOP;
|
|
15285
15290
|
this.onError = NOOP;
|
|
@@ -15289,10 +15294,20 @@ return true;`);
|
|
|
15289
15294
|
get isRunning() {
|
|
15290
15295
|
return Boolean(this.onMessage);
|
|
15291
15296
|
}
|
|
15297
|
+
/**
|
|
15298
|
+
* Send a message to this worker thread
|
|
15299
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
15300
|
+
* @param transferList If not supplied, calculated automatically by traversing data
|
|
15301
|
+
*/
|
|
15292
15302
|
postMessage(data, transferList) {
|
|
15293
15303
|
transferList = transferList || getTransferList(data);
|
|
15294
15304
|
this.worker.postMessage(data, transferList);
|
|
15295
15305
|
}
|
|
15306
|
+
// PRIVATE
|
|
15307
|
+
/**
|
|
15308
|
+
* Generate a standard Error from an ErrorEvent
|
|
15309
|
+
* @param event
|
|
15310
|
+
*/
|
|
15296
15311
|
_getErrorFromErrorEvent(event) {
|
|
15297
15312
|
let message = "Failed to load ";
|
|
15298
15313
|
message += `worker ${this.name} from ${this.url}. `;
|
|
@@ -15304,14 +15319,12 @@ return true;`);
|
|
|
15304
15319
|
}
|
|
15305
15320
|
return new Error(message);
|
|
15306
15321
|
}
|
|
15322
|
+
/**
|
|
15323
|
+
* Creates a worker thread on the browser
|
|
15324
|
+
*/
|
|
15307
15325
|
_createBrowserWorker() {
|
|
15308
|
-
this._loadableURL = getLoadableWorkerURL({
|
|
15309
|
-
|
|
15310
|
-
url: this.url
|
|
15311
|
-
});
|
|
15312
|
-
const worker = new Worker(this._loadableURL, {
|
|
15313
|
-
name: this.name
|
|
15314
|
-
});
|
|
15326
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
15327
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
15315
15328
|
worker.onmessage = (event) => {
|
|
15316
15329
|
if (!event.data) {
|
|
15317
15330
|
this.onError(new Error("No data received"));
|
|
@@ -15326,18 +15339,18 @@ return true;`);
|
|
|
15326
15339
|
worker.onmessageerror = (event) => console.error(event);
|
|
15327
15340
|
return worker;
|
|
15328
15341
|
}
|
|
15342
|
+
/**
|
|
15343
|
+
* Creates a worker thread in node.js
|
|
15344
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
15345
|
+
*/
|
|
15329
15346
|
_createNodeWorker() {
|
|
15330
15347
|
let worker;
|
|
15331
15348
|
if (this.url) {
|
|
15332
15349
|
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
15333
15350
|
const url = absolute ? this.url : `./${this.url}`;
|
|
15334
|
-
worker = new NodeWorker(url, {
|
|
15335
|
-
eval: false
|
|
15336
|
-
});
|
|
15351
|
+
worker = new NodeWorker(url, { eval: false });
|
|
15337
15352
|
} else if (this.source) {
|
|
15338
|
-
worker = new NodeWorker(this.source, {
|
|
15339
|
-
eval: true
|
|
15340
|
-
});
|
|
15353
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
15341
15354
|
} else {
|
|
15342
15355
|
throw new Error("no worker");
|
|
15343
15356
|
}
|
|
@@ -15356,6 +15369,9 @@ return true;`);
|
|
|
15356
15369
|
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
15357
15370
|
var WorkerPool = class {
|
|
15358
15371
|
name = "unnamed";
|
|
15372
|
+
source;
|
|
15373
|
+
// | Function;
|
|
15374
|
+
url;
|
|
15359
15375
|
maxConcurrency = 1;
|
|
15360
15376
|
maxMobileConcurrency = 1;
|
|
15361
15377
|
onDebug = () => {
|
|
@@ -15366,23 +15382,29 @@ return true;`);
|
|
|
15366
15382
|
idleQueue = [];
|
|
15367
15383
|
count = 0;
|
|
15368
15384
|
isDestroyed = false;
|
|
15385
|
+
/** Checks if workers are supported on this platform */
|
|
15369
15386
|
static isSupported() {
|
|
15370
15387
|
return WorkerThread.isSupported();
|
|
15371
15388
|
}
|
|
15389
|
+
/**
|
|
15390
|
+
* @param processor - worker function
|
|
15391
|
+
* @param maxConcurrency - max count of workers
|
|
15392
|
+
*/
|
|
15372
15393
|
constructor(props) {
|
|
15373
15394
|
this.source = props.source;
|
|
15374
15395
|
this.url = props.url;
|
|
15375
15396
|
this.setProps(props);
|
|
15376
15397
|
}
|
|
15398
|
+
/**
|
|
15399
|
+
* Terminates all workers in the pool
|
|
15400
|
+
* @note Can free up significant memory
|
|
15401
|
+
*/
|
|
15377
15402
|
destroy() {
|
|
15378
15403
|
this.idleQueue.forEach((worker) => worker.destroy());
|
|
15379
15404
|
this.isDestroyed = true;
|
|
15380
15405
|
}
|
|
15381
15406
|
setProps(props) {
|
|
15382
|
-
this.props = {
|
|
15383
|
-
...this.props,
|
|
15384
|
-
...props
|
|
15385
|
-
};
|
|
15407
|
+
this.props = { ...this.props, ...props };
|
|
15386
15408
|
if (props.name !== void 0) {
|
|
15387
15409
|
this.name = props.name;
|
|
15388
15410
|
}
|
|
@@ -15401,17 +15423,17 @@ return true;`);
|
|
|
15401
15423
|
}
|
|
15402
15424
|
async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
15403
15425
|
const startPromise = new Promise((onStart) => {
|
|
15404
|
-
this.jobQueue.push({
|
|
15405
|
-
name,
|
|
15406
|
-
onMessage: onMessage2,
|
|
15407
|
-
onError,
|
|
15408
|
-
onStart
|
|
15409
|
-
});
|
|
15426
|
+
this.jobQueue.push({ name, onMessage: onMessage2, onError, onStart });
|
|
15410
15427
|
return this;
|
|
15411
15428
|
});
|
|
15412
15429
|
this._startQueuedJob();
|
|
15413
15430
|
return await startPromise;
|
|
15414
15431
|
}
|
|
15432
|
+
// PRIVATE
|
|
15433
|
+
/**
|
|
15434
|
+
* Starts first queued job if worker is available or can be created
|
|
15435
|
+
* Called when job is started and whenever a worker returns to the idleQueue
|
|
15436
|
+
*/
|
|
15415
15437
|
async _startQueuedJob() {
|
|
15416
15438
|
if (!this.jobQueue.length) {
|
|
15417
15439
|
return;
|
|
@@ -15441,8 +15463,23 @@ return true;`);
|
|
|
15441
15463
|
}
|
|
15442
15464
|
}
|
|
15443
15465
|
}
|
|
15466
|
+
/**
|
|
15467
|
+
* Returns a worker to the idle queue
|
|
15468
|
+
* Destroys the worker if
|
|
15469
|
+
* - pool is destroyed
|
|
15470
|
+
* - if this pool doesn't reuse workers
|
|
15471
|
+
* - if maxConcurrency has been lowered
|
|
15472
|
+
* @param worker
|
|
15473
|
+
*/
|
|
15444
15474
|
returnWorkerToQueue(worker) {
|
|
15445
|
-
const shouldDestroyWorker =
|
|
15475
|
+
const shouldDestroyWorker = (
|
|
15476
|
+
// Workers on Node.js prevent the process from exiting.
|
|
15477
|
+
// Until we figure out how to close them before exit, we always destroy them
|
|
15478
|
+
!isBrowser || // If the pool is destroyed, there is no reason to keep the worker around
|
|
15479
|
+
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
15480
|
+
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
15481
|
+
this.count > this._getMaxConcurrency()
|
|
15482
|
+
);
|
|
15446
15483
|
if (shouldDestroyWorker) {
|
|
15447
15484
|
worker.destroy();
|
|
15448
15485
|
this.count--;
|
|
@@ -15453,6 +15490,9 @@ return true;`);
|
|
|
15453
15490
|
this._startQueuedJob();
|
|
15454
15491
|
}
|
|
15455
15492
|
}
|
|
15493
|
+
/**
|
|
15494
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
15495
|
+
*/
|
|
15456
15496
|
_getAvailableWorker() {
|
|
15457
15497
|
if (this.idleQueue.length > 0) {
|
|
15458
15498
|
return this.idleQueue.shift() || null;
|
|
@@ -15460,11 +15500,7 @@ return true;`);
|
|
|
15460
15500
|
if (this.count < this._getMaxConcurrency()) {
|
|
15461
15501
|
this.count++;
|
|
15462
15502
|
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
15463
|
-
return new WorkerThread({
|
|
15464
|
-
name,
|
|
15465
|
-
source: this.source,
|
|
15466
|
-
url: this.url
|
|
15467
|
-
});
|
|
15503
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
15468
15504
|
}
|
|
15469
15505
|
return null;
|
|
15470
15506
|
}
|
|
@@ -15481,44 +15517,56 @@ return true;`);
|
|
|
15481
15517
|
onDebug: () => {
|
|
15482
15518
|
}
|
|
15483
15519
|
};
|
|
15484
|
-
var
|
|
15520
|
+
var _WorkerFarm = class {
|
|
15521
|
+
props;
|
|
15485
15522
|
workerPools = /* @__PURE__ */ new Map();
|
|
15523
|
+
/** Checks if workers are supported on this platform */
|
|
15486
15524
|
static isSupported() {
|
|
15487
15525
|
return WorkerThread.isSupported();
|
|
15488
15526
|
}
|
|
15527
|
+
/** Get the singleton instance of the global worker farm */
|
|
15489
15528
|
static getWorkerFarm(props = {}) {
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
return
|
|
15529
|
+
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
15530
|
+
_WorkerFarm._workerFarm.setProps(props);
|
|
15531
|
+
return _WorkerFarm._workerFarm;
|
|
15493
15532
|
}
|
|
15533
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
15494
15534
|
constructor(props) {
|
|
15495
|
-
this.props = {
|
|
15496
|
-
...DEFAULT_PROPS
|
|
15497
|
-
};
|
|
15535
|
+
this.props = { ...DEFAULT_PROPS };
|
|
15498
15536
|
this.setProps(props);
|
|
15499
15537
|
this.workerPools = /* @__PURE__ */ new Map();
|
|
15500
15538
|
}
|
|
15539
|
+
/**
|
|
15540
|
+
* Terminate all workers in the farm
|
|
15541
|
+
* @note Can free up significant memory
|
|
15542
|
+
*/
|
|
15501
15543
|
destroy() {
|
|
15502
15544
|
for (const workerPool of this.workerPools.values()) {
|
|
15503
15545
|
workerPool.destroy();
|
|
15504
15546
|
}
|
|
15505
15547
|
this.workerPools = /* @__PURE__ */ new Map();
|
|
15506
15548
|
}
|
|
15549
|
+
/**
|
|
15550
|
+
* Set props used when initializing worker pools
|
|
15551
|
+
* @param props
|
|
15552
|
+
*/
|
|
15507
15553
|
setProps(props) {
|
|
15508
|
-
this.props = {
|
|
15509
|
-
...this.props,
|
|
15510
|
-
...props
|
|
15511
|
-
};
|
|
15554
|
+
this.props = { ...this.props, ...props };
|
|
15512
15555
|
for (const workerPool of this.workerPools.values()) {
|
|
15513
15556
|
workerPool.setProps(this._getWorkerPoolProps());
|
|
15514
15557
|
}
|
|
15515
15558
|
}
|
|
15559
|
+
/**
|
|
15560
|
+
* Returns a worker pool for the specified worker
|
|
15561
|
+
* @param options - only used first time for a specific worker name
|
|
15562
|
+
* @param options.name - the name of the worker - used to identify worker pool
|
|
15563
|
+
* @param options.url -
|
|
15564
|
+
* @param options.source -
|
|
15565
|
+
* @example
|
|
15566
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
15567
|
+
*/
|
|
15516
15568
|
getWorkerPool(options) {
|
|
15517
|
-
const {
|
|
15518
|
-
name,
|
|
15519
|
-
source,
|
|
15520
|
-
url
|
|
15521
|
-
} = options;
|
|
15569
|
+
const { name, source, url } = options;
|
|
15522
15570
|
let workerPool = this.workerPools.get(name);
|
|
15523
15571
|
if (!workerPool) {
|
|
15524
15572
|
workerPool = new WorkerPool({
|
|
@@ -15540,6 +15588,9 @@ return true;`);
|
|
|
15540
15588
|
};
|
|
15541
15589
|
}
|
|
15542
15590
|
};
|
|
15591
|
+
var WorkerFarm = _WorkerFarm;
|
|
15592
|
+
// singleton
|
|
15593
|
+
__publicField(WorkerFarm, "_workerFarm");
|
|
15543
15594
|
|
|
15544
15595
|
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
15545
15596
|
function getWorkerName(worker) {
|
|
@@ -15576,24 +15627,20 @@ return true;`);
|
|
|
15576
15627
|
async function processOnWorker(worker, data, options = {}, context = {}) {
|
|
15577
15628
|
const name = getWorkerName(worker);
|
|
15578
15629
|
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
15579
|
-
const {
|
|
15580
|
-
|
|
15581
|
-
} = options;
|
|
15582
|
-
const workerPoolProps = {
|
|
15583
|
-
name,
|
|
15584
|
-
source
|
|
15585
|
-
};
|
|
15630
|
+
const { source } = options;
|
|
15631
|
+
const workerPoolProps = { name, source };
|
|
15586
15632
|
if (!source) {
|
|
15587
15633
|
workerPoolProps.url = getWorkerURL(worker, options);
|
|
15588
15634
|
}
|
|
15589
15635
|
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
15590
15636
|
const jobName = options.jobName || worker.name;
|
|
15591
|
-
const job = await workerPool.startJob(
|
|
15637
|
+
const job = await workerPool.startJob(
|
|
15638
|
+
jobName,
|
|
15639
|
+
// eslint-disable-next-line
|
|
15640
|
+
onMessage.bind(null, context)
|
|
15641
|
+
);
|
|
15592
15642
|
const transferableOptions = getTransferListForWriter(options);
|
|
15593
|
-
job.postMessage("process", {
|
|
15594
|
-
input: data,
|
|
15595
|
-
options: transferableOptions
|
|
15596
|
-
});
|
|
15643
|
+
job.postMessage("process", { input: data, options: transferableOptions });
|
|
15597
15644
|
const result = await job.result;
|
|
15598
15645
|
return result.result;
|
|
15599
15646
|
}
|
|
@@ -15606,30 +15653,17 @@ return true;`);
|
|
|
15606
15653
|
job.error(new Error(payload.error));
|
|
15607
15654
|
break;
|
|
15608
15655
|
case "process":
|
|
15609
|
-
const {
|
|
15610
|
-
id,
|
|
15611
|
-
input,
|
|
15612
|
-
options
|
|
15613
|
-
} = payload;
|
|
15656
|
+
const { id, input, options } = payload;
|
|
15614
15657
|
try {
|
|
15615
15658
|
if (!context.process) {
|
|
15616
|
-
job.postMessage("error", {
|
|
15617
|
-
id,
|
|
15618
|
-
error: "Worker not set up to process on main thread"
|
|
15619
|
-
});
|
|
15659
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
15620
15660
|
return;
|
|
15621
15661
|
}
|
|
15622
15662
|
const result = await context.process(input, options);
|
|
15623
|
-
job.postMessage("done", {
|
|
15624
|
-
id,
|
|
15625
|
-
result
|
|
15626
|
-
});
|
|
15663
|
+
job.postMessage("done", { id, result });
|
|
15627
15664
|
} catch (error) {
|
|
15628
15665
|
const message = error instanceof Error ? error.message : "unknown error";
|
|
15629
|
-
job.postMessage("error", {
|
|
15630
|
-
id,
|
|
15631
|
-
error: message
|
|
15632
|
-
});
|
|
15666
|
+
job.postMessage("error", { id, error: message });
|
|
15633
15667
|
}
|
|
15634
15668
|
break;
|
|
15635
15669
|
default:
|
|
@@ -15638,7 +15672,7 @@ return true;`);
|
|
|
15638
15672
|
}
|
|
15639
15673
|
|
|
15640
15674
|
// src/triangulate-on-worker.ts
|
|
15641
|
-
var VERSION5 =
|
|
15675
|
+
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
15642
15676
|
var TriangulationWorker = {
|
|
15643
15677
|
id: "triangulation",
|
|
15644
15678
|
name: "Triangulate",
|
|
@@ -15647,21 +15681,15 @@ return true;`);
|
|
|
15647
15681
|
options: {}
|
|
15648
15682
|
};
|
|
15649
15683
|
function triangulateOnWorker(data, options = {}) {
|
|
15650
|
-
return processOnWorker(TriangulationWorker, {
|
|
15651
|
-
...data,
|
|
15652
|
-
operation: "triangulate"
|
|
15653
|
-
}, options);
|
|
15684
|
+
return processOnWorker(TriangulationWorker, { ...data, operation: "triangulate" }, options);
|
|
15654
15685
|
}
|
|
15655
15686
|
function parseGeoArrowOnWorker(data, options = {}) {
|
|
15656
|
-
return processOnWorker(TriangulationWorker, {
|
|
15657
|
-
...data,
|
|
15658
|
-
operation: "parse-geoarrow"
|
|
15659
|
-
}, options);
|
|
15687
|
+
return processOnWorker(TriangulationWorker, { ...data, operation: "parse-geoarrow" }, options);
|
|
15660
15688
|
}
|
|
15661
15689
|
|
|
15662
15690
|
// src/index.ts
|
|
15663
15691
|
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
15664
|
-
return __toCommonJS(
|
|
15692
|
+
return __toCommonJS(bundle_exports);
|
|
15665
15693
|
})();
|
|
15666
15694
|
return __exports__;
|
|
15667
15695
|
});
|