@loaders.gl/excel 4.4.5 → 5.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +14 -3
  2. package/dist/bundled.d.ts +3 -0
  3. package/dist/bundled.d.ts.map +1 -0
  4. package/dist/bundled.js +5 -0
  5. package/dist/bundled.js.map +1 -0
  6. package/dist/dist.dev.js +36143 -21760
  7. package/dist/dist.min.js +54 -37
  8. package/dist/excel-format.d.ts +2 -0
  9. package/dist/excel-format.d.ts.map +1 -1
  10. package/dist/excel-format.js +2 -0
  11. package/dist/excel-format.js.map +1 -1
  12. package/dist/excel-loader-with-parser.d.ts +60 -0
  13. package/dist/excel-loader-with-parser.d.ts.map +1 -0
  14. package/dist/excel-loader-with-parser.js +29 -0
  15. package/dist/excel-loader-with-parser.js.map +1 -0
  16. package/dist/excel-loader.d.ts +40 -14
  17. package/dist/excel-loader.d.ts.map +1 -1
  18. package/dist/excel-loader.js +11 -13
  19. package/dist/excel-loader.js.map +1 -1
  20. package/dist/excel-worker.js +37702 -23157
  21. package/dist/index.cjs +892 -43
  22. package/dist/index.cjs.map +3 -4
  23. package/dist/index.d.ts +3 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +4 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/convert-excel-rows-to-arrow.d.ts +11 -0
  28. package/dist/lib/convert-excel-rows-to-arrow.d.ts.map +1 -0
  29. package/dist/lib/convert-excel-rows-to-arrow.js +72 -0
  30. package/dist/lib/convert-excel-rows-to-arrow.js.map +1 -0
  31. package/dist/lib/encode-excel.d.ts.map +1 -1
  32. package/dist/lib/encode-excel.js +3 -0
  33. package/dist/lib/encode-excel.js.map +1 -1
  34. package/dist/unbundled.d.ts +3 -0
  35. package/dist/unbundled.d.ts.map +1 -0
  36. package/dist/unbundled.js +5 -0
  37. package/dist/unbundled.js.map +1 -0
  38. package/dist/workers/excel-worker.js +5 -2
  39. package/dist/workers/excel-worker.js.map +1 -1
  40. package/package.json +15 -5
  41. package/src/bundled.ts +9 -0
  42. package/src/excel-format.ts +2 -0
  43. package/src/excel-loader-with-parser.ts +51 -0
  44. package/src/excel-loader.ts +21 -21
  45. package/src/index.ts +5 -1
  46. package/src/lib/convert-excel-rows-to-arrow.ts +83 -0
  47. package/src/lib/encode-excel.ts +4 -0
  48. package/src/unbundled.ts +6 -0
  49. package/src/workers/excel-worker.ts +6 -2
package/dist/index.cjs CHANGED
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
15
+ };
6
16
  var __export = (target, all) => {
7
17
  for (var name in all)
8
18
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,34 +25,39 @@ var __copyProps = (to, from, except, desc) => {
15
25
  }
16
26
  return to;
17
27
  };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
18
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
37
 
20
- // dist/index.js
21
- var dist_exports = {};
22
- __export(dist_exports, {
23
- ExcelFormat: () => ExcelFormat,
24
- ExcelLoader: () => ExcelLoader,
25
- ExcelWorkerLoader: () => ExcelWorkerLoader
26
- });
27
- module.exports = __toCommonJS(dist_exports);
28
-
29
38
  // dist/excel-format.js
30
- var ExcelFormat = {
31
- name: "Excel",
32
- id: "excel",
33
- module: "excel",
34
- extensions: ["xls", "xlsb", "xlsm", "xlsx"],
35
- mimeTypes: [
36
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
37
- "application/vnd.ms-excel"
38
- ],
39
- category: "table",
40
- binary: true
41
- };
39
+ var ExcelFormat;
40
+ var init_excel_format = __esm({
41
+ "dist/excel-format.js"() {
42
+ "use strict";
43
+ ExcelFormat = {
44
+ name: "Excel",
45
+ id: "excel",
46
+ module: "excel",
47
+ encoding: "zip",
48
+ format: "excel",
49
+ extensions: ["xls", "xlsb", "xlsm", "xlsx"],
50
+ mimeTypes: [
51
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
52
+ "application/vnd.ms-excel"
53
+ ],
54
+ category: "table",
55
+ binary: true
56
+ };
57
+ }
58
+ });
42
59
 
43
60
  // dist/lib/parse-excel.js
44
- var import_xlsx = require("xlsx");
45
- var dataTableNamesMap = {};
46
61
  function parseExcel(arrayBuffer, options) {
47
62
  var _a, _b, _c;
48
63
  const dataUrl = "dummy";
@@ -65,28 +80,862 @@ function parseExcel(arrayBuffer, options) {
65
80
  }
66
81
  return dataRows;
67
82
  }
83
+ var import_xlsx, dataTableNamesMap;
84
+ var init_parse_excel = __esm({
85
+ "dist/lib/parse-excel.js"() {
86
+ "use strict";
87
+ import_xlsx = require("xlsx");
88
+ dataTableNamesMap = {};
89
+ }
90
+ });
68
91
 
69
- // dist/excel-loader.js
70
- var VERSION = true ? "4.4.5" : "latest";
71
- var ExcelWorkerLoader = {
72
- ...ExcelFormat,
73
- dataType: null,
74
- batchType: null,
75
- version: VERSION,
76
- worker: true,
77
- options: {
78
- excel: {
79
- shape: "object-row-table",
80
- sheet: void 0
81
- // Load default Sheet
92
+ // ../schema-utils/src/lib/schema/data-type.ts
93
+ function getDataTypeFromValue(value, defaultNumberType = "float32") {
94
+ if (value instanceof Date) {
95
+ return "date-millisecond";
96
+ }
97
+ if (typeof value === "number") {
98
+ return defaultNumberType;
99
+ }
100
+ if (typeof value === "boolean") {
101
+ return "bool";
102
+ }
103
+ if (typeof value === "string") {
104
+ return "utf8";
105
+ }
106
+ if (value === null || value === "undefined") {
107
+ return "null";
108
+ }
109
+ return "null";
110
+ }
111
+ function getDataTypeFromArray(array) {
112
+ let type = getDataTypeFromTypedArray(array);
113
+ if (type !== "null") {
114
+ return { type, nullable: false };
115
+ }
116
+ if (array.length > 0) {
117
+ type = getDataTypeFromValue(array[0]);
118
+ return { type, nullable: true };
119
+ }
120
+ return { type: "null", nullable: true };
121
+ }
122
+ function getDataTypeFromTypedArray(array) {
123
+ switch (array.constructor) {
124
+ case Int8Array:
125
+ return "int8";
126
+ case Uint8Array:
127
+ case Uint8ClampedArray:
128
+ return "uint8";
129
+ case Int16Array:
130
+ return "int16";
131
+ case Uint16Array:
132
+ return "uint16";
133
+ case Int32Array:
134
+ return "int32";
135
+ case Uint32Array:
136
+ return "uint32";
137
+ case Float32Array:
138
+ return "float32";
139
+ case Float64Array:
140
+ return "float64";
141
+ default:
142
+ return "null";
143
+ }
144
+ }
145
+ var init_data_type = __esm({
146
+ "../schema-utils/src/lib/schema/data-type.ts"() {
147
+ "use strict";
148
+ }
149
+ });
150
+
151
+ // ../schema-utils/src/lib/schema/convert-arrow-schema.ts
152
+ function convertArrowToSchema(arrowSchema) {
153
+ return serializeArrowSchema(arrowSchema);
154
+ }
155
+ function convertSchemaToArrow(schema, options) {
156
+ return deserializeArrowSchema(schema, options);
157
+ }
158
+ function serializeArrowSchema(arrowSchema) {
159
+ return {
160
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
161
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
162
+ };
163
+ }
164
+ function deserializeArrowSchema(schema, options) {
165
+ return new arrow.Schema(
166
+ schema.fields.map((field) => deserializeArrowField(field, options)),
167
+ deserializeArrowMetadata(schema.metadata)
168
+ );
169
+ }
170
+ function serializeArrowMetadata(arrowMetadata) {
171
+ return Object.fromEntries(arrowMetadata);
172
+ }
173
+ function deserializeArrowMetadata(metadata) {
174
+ return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
175
+ }
176
+ function serializeArrowField(field) {
177
+ return {
178
+ name: field.name,
179
+ type: serializeArrowType(field.type),
180
+ nullable: field.nullable,
181
+ metadata: serializeArrowMetadata(field.metadata)
182
+ };
183
+ }
184
+ function deserializeArrowField(field, options) {
185
+ return new arrow.Field(
186
+ field.name,
187
+ deserializeArrowType(field.type, options),
188
+ field.nullable,
189
+ deserializeArrowMetadata(field.metadata)
190
+ );
191
+ }
192
+ function serializeArrowType(arrowType) {
193
+ if (isArrowViewType(arrowType, "BinaryView")) {
194
+ return "binary-view";
195
+ }
196
+ if (isArrowViewType(arrowType, "Utf8View")) {
197
+ return "utf8-view";
198
+ }
199
+ switch (arrowType.constructor) {
200
+ case arrow.Null:
201
+ return "null";
202
+ case arrow.Binary:
203
+ return "binary";
204
+ case arrow.FixedSizeBinary:
205
+ return {
206
+ type: "fixed-size-binary",
207
+ byteWidth: arrowType.byteWidth
208
+ };
209
+ case arrow.Bool:
210
+ return "bool";
211
+ case arrow.Int:
212
+ const intType = arrowType;
213
+ return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
214
+ case arrow.Int8:
215
+ return "int8";
216
+ case arrow.Int16:
217
+ return "int16";
218
+ case arrow.Int32:
219
+ return "int32";
220
+ case arrow.Int64:
221
+ return "int64";
222
+ case arrow.Uint8:
223
+ return "uint8";
224
+ case arrow.Uint16:
225
+ return "uint16";
226
+ case arrow.Uint32:
227
+ return "uint32";
228
+ case arrow.Uint64:
229
+ return "uint64";
230
+ case arrow.Float:
231
+ const precision = arrowType.precision;
232
+ switch (precision) {
233
+ case arrow.Precision.HALF:
234
+ return "float16";
235
+ case arrow.Precision.SINGLE:
236
+ return "float32";
237
+ case arrow.Precision.DOUBLE:
238
+ return "float64";
239
+ default:
240
+ return "float16";
241
+ }
242
+ case arrow.Float16:
243
+ return "float16";
244
+ case arrow.Float32:
245
+ return "float32";
246
+ case arrow.Float64:
247
+ return "float64";
248
+ case arrow.Utf8:
249
+ return "utf8";
250
+ case arrow.Decimal:
251
+ const decimal = arrowType;
252
+ return {
253
+ type: "decimal",
254
+ bitWidth: decimal.bitWidth,
255
+ precision: decimal.precision,
256
+ scale: decimal.scale
257
+ };
258
+ case arrow.Date_:
259
+ const dateUnit = arrowType.unit;
260
+ return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
261
+ case arrow.DateDay:
262
+ return "date-day";
263
+ case arrow.DateMillisecond:
264
+ return "date-millisecond";
265
+ case arrow.Time:
266
+ const timeUnit = arrowType.unit;
267
+ switch (timeUnit) {
268
+ case arrow.TimeUnit.SECOND:
269
+ return "time-second";
270
+ case arrow.TimeUnit.MILLISECOND:
271
+ return "time-millisecond";
272
+ case arrow.TimeUnit.MICROSECOND:
273
+ return "time-microsecond";
274
+ case arrow.TimeUnit.NANOSECOND:
275
+ return "time-nanosecond";
276
+ default:
277
+ return "time-second";
278
+ }
279
+ case arrow.TimeMillisecond:
280
+ return "time-millisecond";
281
+ case arrow.TimeSecond:
282
+ return "time-second";
283
+ case arrow.TimeMicrosecond:
284
+ return "time-microsecond";
285
+ case arrow.TimeNanosecond:
286
+ return "time-nanosecond";
287
+ case arrow.Timestamp:
288
+ const timeStampUnit = arrowType.unit;
289
+ switch (timeStampUnit) {
290
+ case arrow.TimeUnit.SECOND:
291
+ return "timestamp-second";
292
+ case arrow.TimeUnit.MILLISECOND:
293
+ return "timestamp-millisecond";
294
+ case arrow.TimeUnit.MICROSECOND:
295
+ return "timestamp-microsecond";
296
+ case arrow.TimeUnit.NANOSECOND:
297
+ return "timestamp-nanosecond";
298
+ default:
299
+ return "timestamp-second";
300
+ }
301
+ case arrow.TimestampSecond:
302
+ return "timestamp-second";
303
+ case arrow.TimestampMillisecond:
304
+ return "timestamp-millisecond";
305
+ case arrow.TimestampMicrosecond:
306
+ return "timestamp-microsecond";
307
+ case arrow.TimestampNanosecond:
308
+ return "timestamp-nanosecond";
309
+ case arrow.Interval:
310
+ const intervalUnit = arrowType.unit;
311
+ switch (intervalUnit) {
312
+ case arrow.IntervalUnit.DAY_TIME:
313
+ return "interval-daytime";
314
+ case arrow.IntervalUnit.YEAR_MONTH:
315
+ return "interval-yearmonth";
316
+ default:
317
+ return "interval-daytime";
318
+ }
319
+ case arrow.IntervalDayTime:
320
+ return "interval-daytime";
321
+ case arrow.IntervalYearMonth:
322
+ return "interval-yearmonth";
323
+ case arrow.Map_:
324
+ const mapType = arrowType;
325
+ return {
326
+ type: "map",
327
+ keysSorted: mapType.keysSorted,
328
+ children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
329
+ };
330
+ case arrow.List:
331
+ const listType = arrowType;
332
+ const listField = listType.valueField;
333
+ return {
334
+ type: "list",
335
+ children: [serializeArrowField(listField)]
336
+ };
337
+ case arrow.FixedSizeList:
338
+ const fixedSizeList = arrowType;
339
+ return {
340
+ type: "fixed-size-list",
341
+ listSize: fixedSizeList.listSize,
342
+ children: [serializeArrowField(fixedSizeList.children[0])]
343
+ };
344
+ case arrow.Struct:
345
+ const structType = arrowType;
346
+ return {
347
+ type: "struct",
348
+ children: structType.children.map((arrowField) => serializeArrowField(arrowField))
349
+ };
350
+ case arrow.Dictionary:
351
+ const dictionaryType = arrowType;
352
+ return {
353
+ type: "dictionary",
354
+ id: dictionaryType.id,
355
+ indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
356
+ dictionary: serializeArrowType(dictionaryType.dictionary),
357
+ isOrdered: dictionaryType.isOrdered
358
+ };
359
+ default:
360
+ throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
361
+ }
362
+ }
363
+ function deserializeArrowType(dataType, options) {
364
+ if (typeof dataType === "object") {
365
+ switch (dataType.type) {
366
+ case "decimal":
367
+ return new arrow.Decimal(dataType.scale, dataType.precision, dataType.bitWidth);
368
+ case "map": {
369
+ const children = dataType.children.map(
370
+ (arrowField) => deserializeArrowField(arrowField, options)
371
+ );
372
+ return new arrow.Map_(children, dataType.keysSorted);
373
+ }
374
+ case "list": {
375
+ const field = deserializeArrowField(dataType.children[0], options);
376
+ return new arrow.List(field);
377
+ }
378
+ case "fixed-size-list": {
379
+ const child = deserializeArrowField(dataType.children[0], options);
380
+ return new arrow.FixedSizeList(dataType.listSize, child);
381
+ }
382
+ case "fixed-size-binary":
383
+ return new arrow.FixedSizeBinary(dataType.byteWidth);
384
+ case "struct": {
385
+ const children = dataType.children.map(
386
+ (arrowField) => deserializeArrowField(arrowField, options)
387
+ );
388
+ return new arrow.Struct(children);
389
+ }
390
+ case "dictionary": {
391
+ return new arrow.Dictionary(
392
+ deserializeArrowType(dataType.dictionary, options),
393
+ deserializeArrowDictionaryKeyType(dataType.indices),
394
+ dataType.id,
395
+ dataType.isOrdered
396
+ );
397
+ }
398
+ default:
399
+ throw new Error("array type not supported");
82
400
  }
83
401
  }
84
- };
85
- var ExcelLoader = {
86
- ...ExcelWorkerLoader,
87
- async parse(arrayBuffer, options) {
88
- const data = parseExcel(arrayBuffer, options);
89
- return { shape: "object-row-table", data };
402
+ switch (dataType) {
403
+ case "null":
404
+ return new arrow.Null();
405
+ case "binary":
406
+ return makeVariableWidthArrowType("BinaryView", new arrow.Binary(), options);
407
+ case "binary-view":
408
+ return makeRequiredArrowViewType("BinaryView");
409
+ case "bool":
410
+ return new arrow.Bool();
411
+ case "int8":
412
+ return new arrow.Int8();
413
+ case "int16":
414
+ return new arrow.Int16();
415
+ case "int32":
416
+ return new arrow.Int32();
417
+ case "int64":
418
+ return new arrow.Int64();
419
+ case "uint8":
420
+ return new arrow.Uint8();
421
+ case "uint16":
422
+ return new arrow.Uint16();
423
+ case "uint32":
424
+ return new arrow.Uint32();
425
+ case "uint64":
426
+ return new arrow.Uint64();
427
+ case "float16":
428
+ return new arrow.Float16();
429
+ case "float32":
430
+ return new arrow.Float32();
431
+ case "float64":
432
+ return new arrow.Float64();
433
+ case "utf8":
434
+ return makeVariableWidthArrowType("Utf8View", new arrow.Utf8(), options);
435
+ case "utf8-view":
436
+ return makeRequiredArrowViewType("Utf8View");
437
+ case "date-day":
438
+ return new arrow.DateDay();
439
+ case "date-millisecond":
440
+ return new arrow.DateMillisecond();
441
+ case "time-second":
442
+ return new arrow.TimeSecond();
443
+ case "time-millisecond":
444
+ return new arrow.TimeMillisecond();
445
+ case "time-microsecond":
446
+ return new arrow.TimeMicrosecond();
447
+ case "time-nanosecond":
448
+ return new arrow.TimeNanosecond();
449
+ case "timestamp-second":
450
+ return new arrow.TimestampSecond();
451
+ case "timestamp-millisecond":
452
+ return new arrow.TimestampMillisecond();
453
+ case "timestamp-microsecond":
454
+ return new arrow.TimestampMicrosecond();
455
+ case "timestamp-nanosecond":
456
+ return new arrow.TimestampNanosecond();
457
+ case "interval-daytime":
458
+ return new arrow.IntervalDayTime();
459
+ case "interval-yearmonth":
460
+ return new arrow.IntervalYearMonth();
461
+ default:
462
+ throw new Error("array type not supported");
90
463
  }
91
- };
464
+ }
465
+ function getArrowViewConstructors() {
466
+ return arrow;
467
+ }
468
+ function isArrowViewType(arrowType, viewTypeName) {
469
+ const constructor = getArrowViewConstructors()[viewTypeName];
470
+ if (constructor && arrowType instanceof constructor) {
471
+ return true;
472
+ }
473
+ const guards = arrow.DataType;
474
+ const guard = viewTypeName === "BinaryView" ? guards.isBinaryView : guards.isUtf8View;
475
+ return Boolean(guard == null ? void 0 : guard(arrowType));
476
+ }
477
+ function makeVariableWidthArrowType(viewTypeName, fallbackType, options) {
478
+ const viewTypeMode = (options == null ? void 0 : options.viewTypes) || "never";
479
+ if (viewTypeMode === "never") {
480
+ return fallbackType;
481
+ }
482
+ const constructor = getArrowViewConstructors()[viewTypeName];
483
+ if (constructor) {
484
+ return new constructor();
485
+ }
486
+ if (viewTypeMode === "require") {
487
+ throw new Error(
488
+ `${viewTypeName} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`
489
+ );
490
+ }
491
+ return fallbackType;
492
+ }
493
+ function makeRequiredArrowViewType(viewTypeName) {
494
+ const constructor = getArrowViewConstructors()[viewTypeName];
495
+ if (!constructor) {
496
+ throw new Error(
497
+ `${viewTypeName} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`
498
+ );
499
+ }
500
+ return new constructor();
501
+ }
502
+ function serializeArrowDictionaryKeyType(arrowType) {
503
+ if (arrowType instanceof arrow.Int) {
504
+ const prefix = arrowType.isSigned ? "int" : "uint";
505
+ const keyType = `${prefix}${arrowType.bitWidth}`;
506
+ if (isSchemaDictionaryKeyType(keyType)) {
507
+ return keyType;
508
+ }
509
+ }
510
+ switch (arrowType.constructor) {
511
+ case arrow.Int8:
512
+ return "int8";
513
+ case arrow.Int16:
514
+ return "int16";
515
+ case arrow.Int32:
516
+ return "int32";
517
+ case arrow.Uint8:
518
+ return "uint8";
519
+ case arrow.Uint16:
520
+ return "uint16";
521
+ case arrow.Uint32:
522
+ return "uint32";
523
+ default:
524
+ throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
525
+ }
526
+ }
527
+ function isSchemaDictionaryKeyType(keyType) {
528
+ return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
529
+ }
530
+ function deserializeArrowDictionaryKeyType(keyType) {
531
+ switch (keyType) {
532
+ case "int8":
533
+ return new arrow.Int8();
534
+ case "int16":
535
+ return new arrow.Int16();
536
+ case "int32":
537
+ return new arrow.Int32();
538
+ case "uint8":
539
+ return new arrow.Uint8();
540
+ case "uint16":
541
+ return new arrow.Uint16();
542
+ case "uint32":
543
+ return new arrow.Uint32();
544
+ default:
545
+ throw new Error(`schema dictionary index type not supported: ${keyType}`);
546
+ }
547
+ }
548
+ var arrow;
549
+ var init_convert_arrow_schema = __esm({
550
+ "../schema-utils/src/lib/schema/convert-arrow-schema.ts"() {
551
+ "use strict";
552
+ arrow = __toESM(require("apache-arrow"), 1);
553
+ }
554
+ });
555
+
556
+ // ../schema-utils/src/lib/schema/deduce-table-schema.ts
557
+ function deduceTableSchema(table) {
558
+ switch (table.shape) {
559
+ case "array-row-table":
560
+ case "object-row-table":
561
+ return deduceSchemaFromRows(table.data);
562
+ case "geojson-table":
563
+ return deduceSchemaFromGeoJSON(table.features);
564
+ case "columnar-table":
565
+ return deduceSchemaFromColumns(table.data);
566
+ case "arrow-table":
567
+ default:
568
+ throw new Error("Deduce schema");
569
+ }
570
+ }
571
+ function deduceSchemaFromColumns(columnarTable) {
572
+ const fields = [];
573
+ for (const [columnName, column] of Object.entries(columnarTable)) {
574
+ const field = deduceFieldFromColumn(column, columnName);
575
+ fields.push(field);
576
+ }
577
+ return { fields, metadata: {} };
578
+ }
579
+ function deduceSchemaFromRows(rowTable) {
580
+ if (!rowTable.length) {
581
+ throw new Error("deduce from empty table");
582
+ }
583
+ const fields = [];
584
+ const row0 = rowTable[0];
585
+ for (const [columnName, value] of Object.entries(row0)) {
586
+ fields.push(deduceFieldFromValue(value, columnName));
587
+ }
588
+ return { fields, metadata: {} };
589
+ }
590
+ function deduceSchemaFromGeoJSON(features) {
591
+ if (!features.length) {
592
+ throw new Error("deduce from empty table");
593
+ }
594
+ const fields = [];
595
+ const row0 = features[0].properties || {};
596
+ for (const [columnName, value] of Object.entries(row0)) {
597
+ fields.push(deduceFieldFromValue(value, columnName));
598
+ }
599
+ return { fields, metadata: {} };
600
+ }
601
+ function deduceFieldFromColumn(column, name) {
602
+ if (ArrayBuffer.isView(column)) {
603
+ const type = getDataTypeFromArray(column);
604
+ return {
605
+ name,
606
+ type: type.type || "null",
607
+ nullable: type.nullable
608
+ // metadata: {}
609
+ };
610
+ }
611
+ if (Array.isArray(column) && column.length > 0) {
612
+ const value = column[0];
613
+ const type = getDataTypeFromValue(value);
614
+ return {
615
+ name,
616
+ type,
617
+ nullable: true
618
+ // metadata: {},
619
+ };
620
+ }
621
+ throw new Error("empty table");
622
+ }
623
+ function deduceFieldFromValue(value, name) {
624
+ const type = getDataTypeFromValue(value);
625
+ return {
626
+ name,
627
+ type,
628
+ nullable: true
629
+ // metadata: {}
630
+ };
631
+ }
632
+ var init_deduce_table_schema = __esm({
633
+ "../schema-utils/src/lib/schema/deduce-table-schema.ts"() {
634
+ "use strict";
635
+ init_data_type();
636
+ }
637
+ });
638
+
639
+ // ../schema-utils/src/lib/table/tables/make-table.ts
640
+ function makeTableFromData(data) {
641
+ let table;
642
+ switch (getTableShapeFromData(data)) {
643
+ case "array-row-table":
644
+ table = { shape: "array-row-table", data };
645
+ break;
646
+ case "object-row-table":
647
+ table = { shape: "object-row-table", data };
648
+ break;
649
+ case "columnar-table":
650
+ table = { shape: "columnar-table", data };
651
+ break;
652
+ case "arrow-table":
653
+ table = { shape: "arrow-table", data };
654
+ break;
655
+ default:
656
+ throw new Error("table");
657
+ }
658
+ const schema = deduceTableSchema(table);
659
+ return { ...table, schema };
660
+ }
661
+ function getTableShapeFromData(data) {
662
+ if (data instanceof arrow2.Table) {
663
+ return "arrow-table";
664
+ }
665
+ if (Array.isArray(data)) {
666
+ if (data.length === 0) {
667
+ throw new Error("cannot deduce type of empty table");
668
+ }
669
+ const firstRow = data[0];
670
+ if (Array.isArray(firstRow)) {
671
+ return "array-row-table";
672
+ }
673
+ if (firstRow && typeof firstRow === "object") {
674
+ return "object-row-table";
675
+ }
676
+ }
677
+ if (data && typeof data === "object") {
678
+ return "columnar-table";
679
+ }
680
+ throw new Error("invalid table");
681
+ }
682
+ var arrow2;
683
+ var init_make_table = __esm({
684
+ "../schema-utils/src/lib/table/tables/make-table.ts"() {
685
+ "use strict";
686
+ arrow2 = __toESM(require("apache-arrow"), 1);
687
+ init_deduce_table_schema();
688
+ }
689
+ });
690
+
691
+ // ../schema-utils/src/lib/table/batch-builder/arrow-table-builder.ts
692
+ var arrow3, ArrowTableBuilder;
693
+ var init_arrow_table_builder = __esm({
694
+ "../schema-utils/src/lib/table/batch-builder/arrow-table-builder.ts"() {
695
+ "use strict";
696
+ arrow3 = __toESM(require("apache-arrow"), 1);
697
+ init_src();
698
+ ArrowTableBuilder = class {
699
+ schema;
700
+ arrowSchema;
701
+ arrowBuilders;
702
+ length;
703
+ constructor(schema, options) {
704
+ this.arrowSchema = convertSchemaToArrow(schema, options);
705
+ this.schema = (options == null ? void 0 : options.viewTypes) && options.viewTypes !== "never" ? convertArrowToSchema(this.arrowSchema) : schema;
706
+ this.arrowBuilders = this.arrowSchema.fields.map(
707
+ (field) => arrow3.makeBuilder({ type: field.type, nullValues: [null] })
708
+ );
709
+ this.length = 0;
710
+ }
711
+ addObjectRow(row) {
712
+ for (let i = 0; i < this.arrowBuilders.length; i++) {
713
+ const columnName = this.schema.fields[i].name;
714
+ const value = row[columnName];
715
+ this.arrowBuilders[i].append(value);
716
+ }
717
+ this.length++;
718
+ }
719
+ addArrayRow(row) {
720
+ for (let i = 0; i < this.arrowBuilders.length; i++) {
721
+ this.arrowBuilders[i].append(row[i]);
722
+ }
723
+ this.length++;
724
+ }
725
+ /** Makes sure that a first batch with schema is sent even if no rows */
726
+ firstBatch() {
727
+ const arrowRecordBatch = this._getArrowRecordBatch();
728
+ if (arrowRecordBatch.numCols !== 0) {
729
+ return null;
730
+ }
731
+ return {
732
+ shape: "arrow-table",
733
+ batchType: "data",
734
+ length: arrowRecordBatch.numRows,
735
+ schema: this.schema,
736
+ data: new arrow3.Table(arrowRecordBatch)
737
+ };
738
+ }
739
+ /** Flush the current batch if conditions are right */
740
+ flushBatch() {
741
+ const arrowRecordBatch = this._getArrowRecordBatch();
742
+ if (arrowRecordBatch.numCols === 0) {
743
+ return null;
744
+ }
745
+ return {
746
+ shape: "arrow-table",
747
+ batchType: "data",
748
+ length: arrowRecordBatch.numRows,
749
+ schema: this.schema,
750
+ data: new arrow3.Table(arrowRecordBatch)
751
+ };
752
+ }
753
+ /** Get a last batch if any data is left */
754
+ finishBatch() {
755
+ const arrowRecordBatch = this._getArrowRecordBatch();
756
+ this.arrowBuilders.forEach((builder) => builder.finish());
757
+ if (arrowRecordBatch.numCols === 0) {
758
+ return null;
759
+ }
760
+ return {
761
+ shape: "arrow-table",
762
+ batchType: "data",
763
+ length: arrowRecordBatch.numRows,
764
+ schema: this.schema,
765
+ data: new arrow3.Table(arrowRecordBatch)
766
+ };
767
+ }
768
+ /** Return a table with all the accumulated data */
769
+ finishTable() {
770
+ const arrowRecordBatch = this._getArrowRecordBatch();
771
+ this.arrowBuilders.forEach((builder) => builder.finish());
772
+ return {
773
+ shape: "arrow-table",
774
+ schema: this.schema,
775
+ data: new arrow3.Table(arrowRecordBatch)
776
+ };
777
+ }
778
+ /** Extract a record batch flushing the currently accumulated data in the builders */
779
+ _getArrowRecordBatch() {
780
+ var _a;
781
+ const { arrowBuilders, arrowSchema } = this;
782
+ const arrowDatas = arrowBuilders.map((builder) => builder.flush());
783
+ const length = ((_a = arrowDatas[0]) == null ? void 0 : _a.length) || this.length;
784
+ this.length = 0;
785
+ const structField = new arrow3.Struct(arrowSchema.fields);
786
+ const arrowStructData = new arrow3.Data(structField, 0, length, 0, void 0, arrowDatas);
787
+ const arrowRecordBatch = new arrow3.RecordBatch(arrowSchema, arrowStructData);
788
+ return arrowRecordBatch;
789
+ }
790
+ };
791
+ }
792
+ });
793
+
794
+ // ../schema-utils/src/index.ts
795
+ var init_src = __esm({
796
+ "../schema-utils/src/index.ts"() {
797
+ "use strict";
798
+ init_convert_arrow_schema();
799
+ init_make_table();
800
+ init_arrow_table_builder();
801
+ }
802
+ });
803
+
804
+ // dist/lib/convert-excel-rows-to-arrow.js
805
+ function convertExcelRowsToArrowTable(rows) {
806
+ const table = rows.length > 0 ? makeTableFromData(rows) : { shape: "object-row-table", schema: { fields: [], metadata: {} }, data: rows };
807
+ const schema = deducePrimitiveAwareSchema(table);
808
+ if (table.data.length === 0 || schema.fields.length === 0) {
809
+ return {
810
+ shape: "arrow-table",
811
+ schema,
812
+ data: new arrow4.Table(new arrow4.Schema([]))
813
+ };
814
+ }
815
+ const arrowTableBuilder = new ArrowTableBuilder(schema);
816
+ for (const row of table.data) {
817
+ arrowTableBuilder.addObjectRow(row);
818
+ }
819
+ return arrowTableBuilder.finishTable();
820
+ }
821
+ function deducePrimitiveAwareSchema(table) {
822
+ const fields = table.schema.fields.map((field) => {
823
+ if (field.type === "float32") {
824
+ return { ...field, type: "float64" };
825
+ }
826
+ if (field.type !== "null") {
827
+ return field;
828
+ }
829
+ for (const row of table.data) {
830
+ const type = getDataTypeFromPrimitive(row[field.name]);
831
+ if (type !== "null") {
832
+ return { ...field, type };
833
+ }
834
+ }
835
+ return field;
836
+ });
837
+ return { ...table.schema, fields };
838
+ }
839
+ function getDataTypeFromPrimitive(value) {
840
+ switch (typeof value) {
841
+ case "number":
842
+ return "float64";
843
+ case "boolean":
844
+ return "bool";
845
+ case "string":
846
+ return "utf8";
847
+ default:
848
+ return value instanceof Date ? "date-millisecond" : "null";
849
+ }
850
+ }
851
+ var arrow4;
852
+ var init_convert_excel_rows_to_arrow = __esm({
853
+ "dist/lib/convert-excel-rows-to-arrow.js"() {
854
+ "use strict";
855
+ init_src();
856
+ arrow4 = __toESM(require("apache-arrow"), 1);
857
+ }
858
+ });
859
+
860
+ // dist/excel-loader-with-parser.js
861
+ var excel_loader_with_parser_exports = {};
862
+ __export(excel_loader_with_parser_exports, {
863
+ ExcelLoaderWithParser: () => ExcelLoaderWithParser,
864
+ ExcelWorkerLoaderWithParser: () => ExcelWorkerLoaderWithParser
865
+ });
866
+ var _ExcelWorkerLoaderPreload, ExcelWorkerLoaderMetadataWithoutPreload, _ExcelLoaderPreload, ExcelLoaderMetadataWithoutPreload, ExcelWorkerLoaderWithParser, ExcelLoaderWithParser;
867
+ var init_excel_loader_with_parser = __esm({
868
+ "dist/excel-loader-with-parser.js"() {
869
+ "use strict";
870
+ init_parse_excel();
871
+ init_convert_excel_rows_to_arrow();
872
+ init_excel_loader();
873
+ init_excel_loader();
874
+ ({ preload: _ExcelWorkerLoaderPreload, ...ExcelWorkerLoaderMetadataWithoutPreload } = ExcelWorkerLoader);
875
+ ({ preload: _ExcelLoaderPreload, ...ExcelLoaderMetadataWithoutPreload } = ExcelLoader);
876
+ ExcelWorkerLoaderWithParser = {
877
+ ...ExcelWorkerLoaderMetadataWithoutPreload
878
+ };
879
+ ExcelLoaderWithParser = {
880
+ ...ExcelLoaderMetadataWithoutPreload,
881
+ async parse(arrayBuffer, options) {
882
+ var _a;
883
+ const excelOptions = {
884
+ ...options,
885
+ excel: { ...ExcelLoaderWithParser.options.excel, ...options == null ? void 0 : options.excel }
886
+ };
887
+ const rows = parseExcel(arrayBuffer, excelOptions);
888
+ if (((_a = excelOptions.excel) == null ? void 0 : _a.shape) === "arrow-table") {
889
+ return convertExcelRowsToArrowTable(rows);
890
+ }
891
+ return { shape: "object-row-table", data: rows };
892
+ }
893
+ };
894
+ }
895
+ });
896
+
897
+ // dist/excel-loader.js
898
+ async function preload() {
899
+ const { ExcelLoaderWithParser: ExcelLoaderWithParser2 } = await Promise.resolve().then(() => (init_excel_loader_with_parser(), excel_loader_with_parser_exports));
900
+ return ExcelLoaderWithParser2;
901
+ }
902
+ var VERSION, ExcelWorkerLoader, ExcelLoader;
903
+ var init_excel_loader = __esm({
904
+ "dist/excel-loader.js"() {
905
+ "use strict";
906
+ init_excel_format();
907
+ VERSION = true ? "5.0.0-alpha.2" : "latest";
908
+ ExcelWorkerLoader = {
909
+ ...ExcelFormat,
910
+ dataType: null,
911
+ batchType: null,
912
+ version: VERSION,
913
+ worker: true,
914
+ options: {
915
+ excel: {
916
+ shape: "object-row-table",
917
+ sheet: void 0
918
+ // Load default Sheet
919
+ }
920
+ },
921
+ preload
922
+ };
923
+ ExcelLoader = {
924
+ ...ExcelWorkerLoader,
925
+ preload
926
+ };
927
+ }
928
+ });
929
+
930
+ // dist/index.js
931
+ var index_exports = {};
932
+ __export(index_exports, {
933
+ ExcelFormat: () => ExcelFormat,
934
+ ExcelLoader: () => ExcelLoader,
935
+ ExcelWorkerLoader: () => ExcelWorkerLoader
936
+ });
937
+ module.exports = __toCommonJS(index_exports);
938
+ init_excel_format();
939
+ init_excel_loader();
940
+ init_excel_loader();
92
941
  //# sourceMappingURL=index.cjs.map