@loaders.gl/excel 5.0.0-alpha.1 → 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.
- package/LICENSE +14 -3
- package/dist/dist.dev.js +7427 -6709
- package/dist/dist.min.js +39 -29
- package/dist/excel-loader.js +1 -1
- package/dist/excel-worker.js +7423 -6709
- package/dist/index.cjs +729 -12
- package/dist/index.cjs.map +3 -4
- package/dist/lib/encode-excel.d.ts.map +1 -1
- package/dist/lib/encode-excel.js +3 -0
- package/dist/lib/encode-excel.js.map +1 -1
- package/dist/workers/excel-worker.js +3 -0
- package/dist/workers/excel-worker.js.map +1 -1
- package/package.json +5 -5
- package/src/lib/encode-excel.ts +4 -0
- package/src/workers/excel-worker.ts +4 -0
package/dist/index.cjs
CHANGED
|
@@ -5,8 +5,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
|
|
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
|
+
}
|
|
10
15
|
};
|
|
11
16
|
var __export = (target, all) => {
|
|
12
17
|
for (var name in all)
|
|
@@ -84,18 +89,730 @@ var init_parse_excel = __esm({
|
|
|
84
89
|
}
|
|
85
90
|
});
|
|
86
91
|
|
|
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");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
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");
|
|
463
|
+
}
|
|
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
|
+
|
|
87
804
|
// dist/lib/convert-excel-rows-to-arrow.js
|
|
88
805
|
function convertExcelRowsToArrowTable(rows) {
|
|
89
|
-
const table = rows.length > 0 ?
|
|
806
|
+
const table = rows.length > 0 ? makeTableFromData(rows) : { shape: "object-row-table", schema: { fields: [], metadata: {} }, data: rows };
|
|
90
807
|
const schema = deducePrimitiveAwareSchema(table);
|
|
91
808
|
if (table.data.length === 0 || schema.fields.length === 0) {
|
|
92
809
|
return {
|
|
93
810
|
shape: "arrow-table",
|
|
94
811
|
schema,
|
|
95
|
-
data: new
|
|
812
|
+
data: new arrow4.Table(new arrow4.Schema([]))
|
|
96
813
|
};
|
|
97
814
|
}
|
|
98
|
-
const arrowTableBuilder = new
|
|
815
|
+
const arrowTableBuilder = new ArrowTableBuilder(schema);
|
|
99
816
|
for (const row of table.data) {
|
|
100
817
|
arrowTableBuilder.addObjectRow(row);
|
|
101
818
|
}
|
|
@@ -131,12 +848,12 @@ function getDataTypeFromPrimitive(value) {
|
|
|
131
848
|
return value instanceof Date ? "date-millisecond" : "null";
|
|
132
849
|
}
|
|
133
850
|
}
|
|
134
|
-
var
|
|
851
|
+
var arrow4;
|
|
135
852
|
var init_convert_excel_rows_to_arrow = __esm({
|
|
136
853
|
"dist/lib/convert-excel-rows-to-arrow.js"() {
|
|
137
854
|
"use strict";
|
|
138
|
-
|
|
139
|
-
|
|
855
|
+
init_src();
|
|
856
|
+
arrow4 = __toESM(require("apache-arrow"), 1);
|
|
140
857
|
}
|
|
141
858
|
});
|
|
142
859
|
|
|
@@ -187,7 +904,7 @@ var init_excel_loader = __esm({
|
|
|
187
904
|
"dist/excel-loader.js"() {
|
|
188
905
|
"use strict";
|
|
189
906
|
init_excel_format();
|
|
190
|
-
VERSION = true ? "5.0.0-alpha.
|
|
907
|
+
VERSION = true ? "5.0.0-alpha.2" : "latest";
|
|
191
908
|
ExcelWorkerLoader = {
|
|
192
909
|
...ExcelFormat,
|
|
193
910
|
dataType: null,
|
|
@@ -211,13 +928,13 @@ var init_excel_loader = __esm({
|
|
|
211
928
|
});
|
|
212
929
|
|
|
213
930
|
// dist/index.js
|
|
214
|
-
var
|
|
215
|
-
__export(
|
|
931
|
+
var index_exports = {};
|
|
932
|
+
__export(index_exports, {
|
|
216
933
|
ExcelFormat: () => ExcelFormat,
|
|
217
934
|
ExcelLoader: () => ExcelLoader,
|
|
218
935
|
ExcelWorkerLoader: () => ExcelWorkerLoader
|
|
219
936
|
});
|
|
220
|
-
module.exports = __toCommonJS(
|
|
937
|
+
module.exports = __toCommonJS(index_exports);
|
|
221
938
|
init_excel_format();
|
|
222
939
|
init_excel_loader();
|
|
223
940
|
init_excel_loader();
|