@nika-js/onlymap 0.1.0
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/.vscode/onlymap.code-snippets +173 -0
- package/LICENSE.md +133 -0
- package/README.md +188 -0
- package/bin/onlymapjs.mjs +182 -0
- package/dist/Arrow.dom-7AXne1TU.js +5233 -0
- package/dist/actions.d.ts +30 -0
- package/dist/attribute-resolution.d.ts +73 -0
- package/dist/basemap-D95W0IIA.js +25203 -0
- package/dist/basemap.d.ts +72 -0
- package/dist/convert-arrow-schema-CvZ3cT5m.js +94 -0
- package/dist/csp-sandbox.d.ts +20 -0
- package/dist/ctx.d.ts +49 -0
- package/dist/d3-bundle.d.ts +218 -0
- package/dist/data-emit.d.ts +10 -0
- package/dist/data-layer.d.ts +150 -0
- package/dist/declarative-filter.d.ts +12 -0
- package/dist/dev-error-panel.d.ts +15 -0
- package/dist/draw-controller.d.ts +51 -0
- package/dist/draw.d.ts +102 -0
- package/dist/effects.d.ts +39 -0
- package/dist/elements/om-behavior.d.ts +13 -0
- package/dist/elements/om-layer.d.ts +11 -0
- package/dist/elements/om-map.d.ts +168 -0
- package/dist/elements/om-overlay.d.ts +82 -0
- package/dist/elements/om-step.d.ts +12 -0
- package/dist/elements/om-story.d.ts +67 -0
- package/dist/elements/om-widget.d.ts +29 -0
- package/dist/env.d.ts +41 -0
- package/dist/expr/cache.d.ts +28 -0
- package/dist/expr/compile.d.ts +27 -0
- package/dist/expr/errors.d.ts +10 -0
- package/dist/expr/full-js-block.d.ts +17 -0
- package/dist/expr/index.d.ts +12 -0
- package/dist/expr/output-type.d.ts +12 -0
- package/dist/expr/scale.d.ts +13 -0
- package/dist/expr/script-block.d.ts +16 -0
- package/dist/expr/whitelist.d.ts +28 -0
- package/dist/field-access.d.ts +24 -0
- package/dist/html-data.d.ts +25 -0
- package/dist/index-2v2NXF_n.js +435 -0
- package/dist/index-BFjXVHly.js +605 -0
- package/dist/index-C9w78NS9.js +4883 -0
- package/dist/index-CU-iOTdr.js +75292 -0
- package/dist/index-D74olQ9w.js +3907 -0
- package/dist/index-Do7hmHwi.js +1457 -0
- package/dist/index.d.ts +76 -0
- package/dist/ir-snapshot.d.ts +54 -0
- package/dist/ir.d.ts +66 -0
- package/dist/layer-registry.d.ts +27 -0
- package/dist/layers/popup-layer.d.ts +65 -0
- package/dist/onlymapjs.css +1 -0
- package/dist/onlymapjs.js +30 -0
- package/dist/onlymapjs.umd.cjs +8618 -0
- package/dist/parse-manifest.d.ts +19 -0
- package/dist/recordbatch-HRu0SMKp.js +4742 -0
- package/dist/runtime-core.d.ts +170 -0
- package/dist/selection.d.ts +31 -0
- package/dist/stats.d.ts +29 -0
- package/dist/table-accessors-DBjWgN0C.js +204 -0
- package/dist/template-interpolation.d.ts +6 -0
- package/dist/testing.d.ts +90 -0
- package/dist/timeline.d.ts +37 -0
- package/dist/validation.d.ts +22 -0
- package/dist/vega-loader.d.ts +22 -0
- package/dist/viewport-filter.d.ts +25 -0
- package/dist/widget-registry.d.ts +23 -0
- package/dist/widget-script.d.ts +1 -0
- package/dist/widgets/built-in.d.ts +1 -0
- package/dist/widgets/dom-utils.d.ts +4 -0
- package/llms.txt +43 -0
- package/onlymapjs.html-data.json +1688 -0
- package/package.json +111 -0
- package/skills/onlymapjs/SKILL.md +61 -0
- package/skills/onlymapjs/agents/openai.yaml +4 -0
- package/skills/onlymapjs/references/patterns.md +213 -0
- package/skills/onlymapjs/references/syntax.md +342 -0
- package/skills/onlymapjs/references/testing.md +126 -0
|
@@ -0,0 +1,1457 @@
|
|
|
1
|
+
var Oe = Object.defineProperty;
|
|
2
|
+
var ke = (r, e, t) => e in r ? Oe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var l = (r, e, t) => ke(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { g as ve, a as ce, b as he, i as Fe, t as je, l as xe } from "./index-CU-iOTdr.js";
|
|
5
|
+
import { ai as Ie, h as ue, au as X, a2 as W, af as fe, Y as Ne, F as Le, aR as Ue, S as Me, bP as qe } from "./recordbatch-HRu0SMKp.js";
|
|
6
|
+
import { g as $, a as de, b as Ve, c as $e, d as Pe, e as He, m as ze } from "./table-accessors-DBjWgN0C.js";
|
|
7
|
+
import { c as Qe } from "./convert-arrow-schema-CvZ3cT5m.js";
|
|
8
|
+
function me(r) {
|
|
9
|
+
switch (r.shape) {
|
|
10
|
+
case "array-row-table":
|
|
11
|
+
case "object-row-table":
|
|
12
|
+
return We(r.data);
|
|
13
|
+
case "geojson-table":
|
|
14
|
+
return Ze(r.features);
|
|
15
|
+
case "columnar-table":
|
|
16
|
+
return Je(r.data);
|
|
17
|
+
case "arrow-table":
|
|
18
|
+
default:
|
|
19
|
+
throw new Error("Deduce schema");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function Je(r) {
|
|
23
|
+
const e = [];
|
|
24
|
+
for (const [t, s] of Object.entries(r)) {
|
|
25
|
+
const i = Ye(s, t);
|
|
26
|
+
e.push(i);
|
|
27
|
+
}
|
|
28
|
+
return { fields: e, metadata: {} };
|
|
29
|
+
}
|
|
30
|
+
function We(r) {
|
|
31
|
+
if (!r.length)
|
|
32
|
+
throw new Error("deduce from empty table");
|
|
33
|
+
const e = [], t = r[0];
|
|
34
|
+
for (const [s, i] of Object.entries(t))
|
|
35
|
+
e.push(ge(i, s));
|
|
36
|
+
return { fields: e, metadata: {} };
|
|
37
|
+
}
|
|
38
|
+
function Ze(r) {
|
|
39
|
+
if (!r.length)
|
|
40
|
+
throw new Error("deduce from empty table");
|
|
41
|
+
const e = [], t = r[0].properties || {};
|
|
42
|
+
for (const [s, i] of Object.entries(t))
|
|
43
|
+
e.push(ge(i, s));
|
|
44
|
+
return { fields: e, metadata: {} };
|
|
45
|
+
}
|
|
46
|
+
function Ye(r, e) {
|
|
47
|
+
if (ArrayBuffer.isView(r)) {
|
|
48
|
+
const t = ve(r);
|
|
49
|
+
return {
|
|
50
|
+
name: e,
|
|
51
|
+
type: t.type || "null",
|
|
52
|
+
nullable: t.nullable
|
|
53
|
+
// metadata: {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(r) && r.length > 0) {
|
|
57
|
+
const t = r[0], s = ce(t);
|
|
58
|
+
return {
|
|
59
|
+
name: e,
|
|
60
|
+
type: s,
|
|
61
|
+
nullable: !0
|
|
62
|
+
// metadata: {},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
throw new Error("empty table");
|
|
66
|
+
}
|
|
67
|
+
function ge(r, e) {
|
|
68
|
+
const t = ce(r);
|
|
69
|
+
return {
|
|
70
|
+
name: e,
|
|
71
|
+
type: t,
|
|
72
|
+
nullable: !0
|
|
73
|
+
// metadata: {}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function Ke(r, e) {
|
|
77
|
+
const t = he(r.type, r.nullable);
|
|
78
|
+
return new t(e);
|
|
79
|
+
}
|
|
80
|
+
function* Ge(r, e) {
|
|
81
|
+
const t = Qe(r.schema), s = $(r), i = de(r), a = s, h = t == null ? void 0 : t.fields.map((o) => Ie(o)), f = new ue(t.fields);
|
|
82
|
+
let m = 0;
|
|
83
|
+
for (let o = 0; o < s; o++)
|
|
84
|
+
for (let d = 0; d < i; ++d) {
|
|
85
|
+
const n = Ve(r, o, d);
|
|
86
|
+
if (h[d].append(n), m++, m >= a) {
|
|
87
|
+
const _ = h.map((c) => c.flush()), p = new X(f, 0, m, 0, void 0, _);
|
|
88
|
+
yield new W(t, p), m = 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (m > 0) {
|
|
92
|
+
const o = h.map((n) => n.flush()), d = new X(f, 0, m, 0, void 0, o);
|
|
93
|
+
yield new W(t, d), m = 0;
|
|
94
|
+
}
|
|
95
|
+
h.map((o) => o.finish());
|
|
96
|
+
}
|
|
97
|
+
function Xe(r, e) {
|
|
98
|
+
switch (r.shape) {
|
|
99
|
+
case "arrow-table":
|
|
100
|
+
return r.data;
|
|
101
|
+
case "columnar-table":
|
|
102
|
+
// TODO - optimized implementation is possible
|
|
103
|
+
// return convertColumnarTableToArrow(table, options);
|
|
104
|
+
// fall through
|
|
105
|
+
default:
|
|
106
|
+
const t = Ge(r);
|
|
107
|
+
return new fe(t);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function U(r, e) {
|
|
111
|
+
switch (e) {
|
|
112
|
+
case "object-row-table":
|
|
113
|
+
return rt(r);
|
|
114
|
+
case "array-row-table":
|
|
115
|
+
return tt(r);
|
|
116
|
+
case "columnar-table":
|
|
117
|
+
return et(r);
|
|
118
|
+
case "arrow-table":
|
|
119
|
+
return st(r);
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(e);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function et(r) {
|
|
125
|
+
var a;
|
|
126
|
+
const e = r.schema || me(r), t = ((a = r.schema) == null ? void 0 : a.fields) || [];
|
|
127
|
+
if (r.shape === "columnar-table")
|
|
128
|
+
return { ...r, schema: e };
|
|
129
|
+
const s = $(r), i = {};
|
|
130
|
+
for (const h of t) {
|
|
131
|
+
const f = Ke(h, s);
|
|
132
|
+
i[h.name] = f;
|
|
133
|
+
for (let m = 0; m < s; m++)
|
|
134
|
+
f[m] = $e(r, m, h.name);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
shape: "columnar-table",
|
|
138
|
+
schema: e,
|
|
139
|
+
data: i
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function tt(r) {
|
|
143
|
+
if (r.shape === "array-row-table")
|
|
144
|
+
return r;
|
|
145
|
+
const e = $(r), t = new Array(e);
|
|
146
|
+
for (let s = 0; s < e; s++)
|
|
147
|
+
t[s] = Pe(r, s);
|
|
148
|
+
return {
|
|
149
|
+
shape: "array-row-table",
|
|
150
|
+
schema: r.schema,
|
|
151
|
+
data: t
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function rt(r) {
|
|
155
|
+
if (r.shape === "object-row-table")
|
|
156
|
+
return r;
|
|
157
|
+
const e = $(r), t = new Array(e);
|
|
158
|
+
for (let s = 0; s < e; s++)
|
|
159
|
+
t[s] = He(r, s);
|
|
160
|
+
return {
|
|
161
|
+
shape: "object-row-table",
|
|
162
|
+
schema: r.schema,
|
|
163
|
+
data: t
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function st(r) {
|
|
167
|
+
const e = Xe(r);
|
|
168
|
+
return {
|
|
169
|
+
shape: "arrow-table",
|
|
170
|
+
schema: r.schema,
|
|
171
|
+
data: e
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function pe(r, e) {
|
|
175
|
+
if (!r)
|
|
176
|
+
throw new Error("null row");
|
|
177
|
+
const t = {};
|
|
178
|
+
if (e)
|
|
179
|
+
for (let s = 0; s < e.length; s++)
|
|
180
|
+
t[e[s]] = r[s];
|
|
181
|
+
else
|
|
182
|
+
for (let s = 0; s < r.length; s++) {
|
|
183
|
+
const i = `column-${s}`;
|
|
184
|
+
t[i] = r[s];
|
|
185
|
+
}
|
|
186
|
+
return t;
|
|
187
|
+
}
|
|
188
|
+
function we(r, e) {
|
|
189
|
+
if (!r)
|
|
190
|
+
throw new Error("null row");
|
|
191
|
+
if (e) {
|
|
192
|
+
const t = new Array(e.length);
|
|
193
|
+
for (let s = 0; s < e.length; s++)
|
|
194
|
+
t[s] = r[e[s]];
|
|
195
|
+
return t;
|
|
196
|
+
}
|
|
197
|
+
return Object.values(r);
|
|
198
|
+
}
|
|
199
|
+
function nt(r) {
|
|
200
|
+
const e = [];
|
|
201
|
+
for (let t = 0; t < r.length; t++) {
|
|
202
|
+
const s = `column-${t}`;
|
|
203
|
+
e.push(s);
|
|
204
|
+
}
|
|
205
|
+
return e;
|
|
206
|
+
}
|
|
207
|
+
function it(r) {
|
|
208
|
+
return Object.keys(r);
|
|
209
|
+
}
|
|
210
|
+
function q(r, e) {
|
|
211
|
+
switch (e) {
|
|
212
|
+
case "object-row-table":
|
|
213
|
+
return { ...r, ...U(r, "object-row-table") };
|
|
214
|
+
case "array-row-table":
|
|
215
|
+
return { ...r, ...U(r, "array-row-table") };
|
|
216
|
+
case "columnar-table":
|
|
217
|
+
return { ...r, ...U(r, "columnar-table") };
|
|
218
|
+
case "arrow-table":
|
|
219
|
+
return { ...r, ...U(r, "arrow-table") };
|
|
220
|
+
default:
|
|
221
|
+
throw new Error(e);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function* at(r, e) {
|
|
225
|
+
for await (const t of r)
|
|
226
|
+
switch (e) {
|
|
227
|
+
case "object-row-table":
|
|
228
|
+
yield q(t, "object-row-table");
|
|
229
|
+
break;
|
|
230
|
+
case "array-row-table":
|
|
231
|
+
yield q(t, "array-row-table");
|
|
232
|
+
break;
|
|
233
|
+
case "columnar-table":
|
|
234
|
+
yield q(t, "columnar-table");
|
|
235
|
+
break;
|
|
236
|
+
case "arrow-table":
|
|
237
|
+
yield q(t, "arrow-table");
|
|
238
|
+
break;
|
|
239
|
+
default:
|
|
240
|
+
throw new Error(e);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const ee = 100;
|
|
244
|
+
class ot {
|
|
245
|
+
constructor(e, t) {
|
|
246
|
+
l(this, "schema");
|
|
247
|
+
l(this, "options");
|
|
248
|
+
l(this, "shape");
|
|
249
|
+
l(this, "length", 0);
|
|
250
|
+
l(this, "rows", null);
|
|
251
|
+
l(this, "cursor", 0);
|
|
252
|
+
l(this, "_headers", []);
|
|
253
|
+
if (this.options = t, this.schema = e, !Array.isArray(e)) {
|
|
254
|
+
this._headers = [];
|
|
255
|
+
for (const s in e)
|
|
256
|
+
this._headers[e[s].index] = e[s].name;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
rowCount() {
|
|
260
|
+
return this.length;
|
|
261
|
+
}
|
|
262
|
+
addArrayRow(e, t) {
|
|
263
|
+
Number.isFinite(t) && (this.cursor = t), this.shape = "array-row-table", this.rows = this.rows || new Array(ee), this.rows[this.length] = e, this.length++;
|
|
264
|
+
}
|
|
265
|
+
addObjectRow(e, t) {
|
|
266
|
+
Number.isFinite(t) && (this.cursor = t), this.shape = "object-row-table", this.rows = this.rows || new Array(ee), this.rows[this.length] = e, this.length++;
|
|
267
|
+
}
|
|
268
|
+
getBatch() {
|
|
269
|
+
let e = this.rows;
|
|
270
|
+
return e ? (e = e.slice(0, this.length), this.rows = null, {
|
|
271
|
+
shape: this.shape || "array-row-table",
|
|
272
|
+
batchType: "data",
|
|
273
|
+
data: e,
|
|
274
|
+
length: this.length,
|
|
275
|
+
schema: this.schema,
|
|
276
|
+
cursor: this.cursor
|
|
277
|
+
}) : null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const te = 100;
|
|
281
|
+
class lt {
|
|
282
|
+
constructor(e, t) {
|
|
283
|
+
l(this, "schema");
|
|
284
|
+
l(this, "options");
|
|
285
|
+
l(this, "length", 0);
|
|
286
|
+
l(this, "objectRows", null);
|
|
287
|
+
l(this, "arrayRows", null);
|
|
288
|
+
l(this, "cursor", 0);
|
|
289
|
+
l(this, "_headers", null);
|
|
290
|
+
if (this.options = t, this.schema = e, e) {
|
|
291
|
+
this._headers = [];
|
|
292
|
+
for (let s = 0; s < e.fields.length; s++)
|
|
293
|
+
this._headers[s] = e.fields[s].name;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
rowCount() {
|
|
297
|
+
return this.length;
|
|
298
|
+
}
|
|
299
|
+
addArrayRow(e, t) {
|
|
300
|
+
switch (Number.isFinite(t) && (this.cursor = t), this._headers || (this._headers = nt(e)), this.options.shape) {
|
|
301
|
+
case "object-row-table":
|
|
302
|
+
const s = pe(e, this._headers);
|
|
303
|
+
this.addObjectRow(s, t);
|
|
304
|
+
break;
|
|
305
|
+
case "array-row-table":
|
|
306
|
+
this.arrayRows = this.arrayRows || new Array(te), this.arrayRows[this.length] = e, this.length++;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
addObjectRow(e, t) {
|
|
311
|
+
switch (Number.isFinite(t) && (this.cursor = t), this._headers || (this._headers = it(e)), this.options.shape) {
|
|
312
|
+
case "array-row-table":
|
|
313
|
+
const s = we(e, this._headers);
|
|
314
|
+
this.addArrayRow(s, t);
|
|
315
|
+
break;
|
|
316
|
+
case "object-row-table":
|
|
317
|
+
this.objectRows = this.objectRows || new Array(te), this.objectRows[this.length] = e, this.length++;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
getBatch() {
|
|
322
|
+
let e = this.arrayRows || this.objectRows;
|
|
323
|
+
return e ? (e = e.slice(0, this.length), this.arrayRows = null, this.objectRows = null, {
|
|
324
|
+
shape: this.options.shape,
|
|
325
|
+
batchType: "data",
|
|
326
|
+
data: e,
|
|
327
|
+
length: this.length,
|
|
328
|
+
// @ts-expect-error we should infer a schema
|
|
329
|
+
schema: this.schema,
|
|
330
|
+
cursor: this.cursor
|
|
331
|
+
}) : null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const ct = 100;
|
|
335
|
+
class ye {
|
|
336
|
+
constructor(e, t) {
|
|
337
|
+
l(this, "schema");
|
|
338
|
+
l(this, "length", 0);
|
|
339
|
+
l(this, "allocated", 0);
|
|
340
|
+
l(this, "columns", {});
|
|
341
|
+
this.schema = e, this._reallocateColumns();
|
|
342
|
+
}
|
|
343
|
+
rowCount() {
|
|
344
|
+
return this.length;
|
|
345
|
+
}
|
|
346
|
+
addArrayRow(e) {
|
|
347
|
+
this._reallocateColumns();
|
|
348
|
+
let t = 0;
|
|
349
|
+
for (const s in this.columns)
|
|
350
|
+
this.columns[s][this.length] = e[t++];
|
|
351
|
+
this.length++;
|
|
352
|
+
}
|
|
353
|
+
addObjectRow(e) {
|
|
354
|
+
this._reallocateColumns();
|
|
355
|
+
for (const t in e)
|
|
356
|
+
this.columns[t][this.length] = e[t];
|
|
357
|
+
this.length++;
|
|
358
|
+
}
|
|
359
|
+
getBatch() {
|
|
360
|
+
return this._pruneColumns(), {
|
|
361
|
+
shape: "columnar-table",
|
|
362
|
+
batchType: "data",
|
|
363
|
+
data: this.columns,
|
|
364
|
+
schema: this.schema,
|
|
365
|
+
length: this.length
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
// HELPERS
|
|
369
|
+
_reallocateColumns() {
|
|
370
|
+
if (!(this.length < this.allocated)) {
|
|
371
|
+
this.allocated = this.allocated > 0 ? this.allocated *= 2 : ct, this.columns = {};
|
|
372
|
+
for (const e of this.schema.fields) {
|
|
373
|
+
const t = he(e.type, e.nullable), s = this.columns[e.name];
|
|
374
|
+
if (!s)
|
|
375
|
+
this.columns[e.name] = new t(this.allocated);
|
|
376
|
+
else if (Array.isArray(s))
|
|
377
|
+
s.length = this.allocated;
|
|
378
|
+
else if (Fe(s)) {
|
|
379
|
+
const i = new t(this.allocated);
|
|
380
|
+
i.set(s), this.columns[e.name] = i;
|
|
381
|
+
} else
|
|
382
|
+
throw new Error("Invalid column type");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
_pruneColumns() {
|
|
387
|
+
for (const [e, t] of Object.entries(this.columns))
|
|
388
|
+
this.columns[e] = t.slice(0, this.length);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
class ht extends ye {
|
|
392
|
+
constructor(t, s) {
|
|
393
|
+
super(t, s);
|
|
394
|
+
l(this, "arrowSchema");
|
|
395
|
+
this.arrowSchema = null;
|
|
396
|
+
}
|
|
397
|
+
getBatch() {
|
|
398
|
+
const t = super.getBatch();
|
|
399
|
+
if (t) {
|
|
400
|
+
this.arrowSchema = this.arrowSchema || ut(t.schema);
|
|
401
|
+
const s = ft(this.arrowSchema, t.data), i = new W(this.arrowSchema, Ne({
|
|
402
|
+
type: new ue(this.arrowSchema.fields),
|
|
403
|
+
children: s.map(({ data: a }) => a[0])
|
|
404
|
+
}));
|
|
405
|
+
return {
|
|
406
|
+
shape: "arrow-table",
|
|
407
|
+
batchType: "data",
|
|
408
|
+
data: new fe([i]),
|
|
409
|
+
length: t.length
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function ut(r) {
|
|
416
|
+
const e = [];
|
|
417
|
+
for (const t in r) {
|
|
418
|
+
const s = r[t];
|
|
419
|
+
if (s.type === Float32Array) {
|
|
420
|
+
const i = /* @__PURE__ */ new Map(), a = new Le(s.name, new Ue(), s.nullable, i);
|
|
421
|
+
e.push(a);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (e.length === 0)
|
|
425
|
+
throw new Error("No arrow convertible fields");
|
|
426
|
+
return new Me(e);
|
|
427
|
+
}
|
|
428
|
+
function ft(r, e) {
|
|
429
|
+
const t = [];
|
|
430
|
+
for (const s of r.fields) {
|
|
431
|
+
const i = e[s.name];
|
|
432
|
+
if (i instanceof Float32Array) {
|
|
433
|
+
const a = qe(i);
|
|
434
|
+
t.push(a);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (r.fields.length !== t.length)
|
|
438
|
+
throw new Error("Some columns not arrow convertible");
|
|
439
|
+
return t;
|
|
440
|
+
}
|
|
441
|
+
const dt = {
|
|
442
|
+
shape: void 0,
|
|
443
|
+
batchSize: "auto",
|
|
444
|
+
batchDebounceMs: 0,
|
|
445
|
+
limit: 0,
|
|
446
|
+
_limitMB: 0
|
|
447
|
+
};
|
|
448
|
+
class be {
|
|
449
|
+
constructor(e, t) {
|
|
450
|
+
l(this, "schema");
|
|
451
|
+
l(this, "options");
|
|
452
|
+
l(this, "aggregator", null);
|
|
453
|
+
l(this, "batchCount", 0);
|
|
454
|
+
l(this, "bytesUsed", 0);
|
|
455
|
+
l(this, "isChunkComplete", !1);
|
|
456
|
+
l(this, "lastBatchEmittedMs", Date.now());
|
|
457
|
+
l(this, "totalLength", 0);
|
|
458
|
+
l(this, "totalBytes", 0);
|
|
459
|
+
l(this, "rowBytes", 0);
|
|
460
|
+
this.schema = e, this.options = { ...dt, ...t };
|
|
461
|
+
}
|
|
462
|
+
limitReached() {
|
|
463
|
+
var e, t;
|
|
464
|
+
return !!((e = this.options) != null && e.limit && this.totalLength >= this.options.limit || (t = this.options) != null && t._limitMB && this.totalBytes / 1e6 >= this.options._limitMB);
|
|
465
|
+
}
|
|
466
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
467
|
+
addRow(e) {
|
|
468
|
+
this.limitReached() || (this.totalLength++, this.rowBytes = this.rowBytes || this._estimateRowMB(e), this.totalBytes += this.rowBytes, Array.isArray(e) ? this.addArrayRow(e) : this.addObjectRow(e));
|
|
469
|
+
}
|
|
470
|
+
/** Add one row to the batch */
|
|
471
|
+
addArrayRow(e) {
|
|
472
|
+
if (!this.aggregator) {
|
|
473
|
+
const t = this._getTableBatchType();
|
|
474
|
+
this.aggregator = new t(this.schema, this.options);
|
|
475
|
+
}
|
|
476
|
+
this.aggregator.addArrayRow(e);
|
|
477
|
+
}
|
|
478
|
+
/** Add one row to the batch */
|
|
479
|
+
addObjectRow(e) {
|
|
480
|
+
if (!this.aggregator) {
|
|
481
|
+
const t = this._getTableBatchType();
|
|
482
|
+
this.aggregator = new t(this.schema, this.options);
|
|
483
|
+
}
|
|
484
|
+
this.aggregator.addObjectRow(e);
|
|
485
|
+
}
|
|
486
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
487
|
+
chunkComplete(e) {
|
|
488
|
+
e instanceof ArrayBuffer && (this.bytesUsed += e.byteLength), typeof e == "string" && (this.bytesUsed += e.length), this.isChunkComplete = !0;
|
|
489
|
+
}
|
|
490
|
+
getFullBatch(e) {
|
|
491
|
+
return this._isFull() ? this._getBatch(e) : null;
|
|
492
|
+
}
|
|
493
|
+
getFinalBatch(e) {
|
|
494
|
+
return this._getBatch(e);
|
|
495
|
+
}
|
|
496
|
+
// INTERNAL
|
|
497
|
+
_estimateRowMB(e) {
|
|
498
|
+
return Array.isArray(e) ? e.length * 8 : Object.keys(e).length * 8;
|
|
499
|
+
}
|
|
500
|
+
_isFull() {
|
|
501
|
+
if (!this.aggregator || this.aggregator.rowCount() === 0)
|
|
502
|
+
return !1;
|
|
503
|
+
if (this.options.batchSize === "auto") {
|
|
504
|
+
if (!this.isChunkComplete)
|
|
505
|
+
return !1;
|
|
506
|
+
} else if (this.options.batchSize > this.aggregator.rowCount())
|
|
507
|
+
return !1;
|
|
508
|
+
return this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs ? !1 : (this.isChunkComplete = !1, this.lastBatchEmittedMs = Date.now(), !0);
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
512
|
+
*/
|
|
513
|
+
_getBatch(e) {
|
|
514
|
+
if (!this.aggregator)
|
|
515
|
+
return null;
|
|
516
|
+
e != null && e.bytesUsed && (this.bytesUsed = e.bytesUsed);
|
|
517
|
+
const t = this.aggregator.getBatch();
|
|
518
|
+
return t.count = this.batchCount, t.bytesUsed = this.bytesUsed, Object.assign(t, e), this.batchCount++, this.aggregator = null, t;
|
|
519
|
+
}
|
|
520
|
+
_getTableBatchType() {
|
|
521
|
+
switch (this.options.shape) {
|
|
522
|
+
case "array-row-table":
|
|
523
|
+
case "object-row-table":
|
|
524
|
+
return lt;
|
|
525
|
+
case "columnar-table":
|
|
526
|
+
return ye;
|
|
527
|
+
case "arrow-table":
|
|
528
|
+
return ht;
|
|
529
|
+
default:
|
|
530
|
+
return ot;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
l(be, "ArrowBatch");
|
|
535
|
+
class re extends Array {
|
|
536
|
+
enqueue(e) {
|
|
537
|
+
return this.push(e);
|
|
538
|
+
}
|
|
539
|
+
dequeue() {
|
|
540
|
+
return this.shift();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
class mt {
|
|
544
|
+
constructor() {
|
|
545
|
+
l(this, "_values");
|
|
546
|
+
l(this, "_settlers");
|
|
547
|
+
l(this, "_closed");
|
|
548
|
+
this._values = new re(), this._settlers = new re(), this._closed = !1;
|
|
549
|
+
}
|
|
550
|
+
close() {
|
|
551
|
+
for (; this._settlers.length > 0; )
|
|
552
|
+
this._settlers.dequeue().resolve({ done: !0 });
|
|
553
|
+
this._closed = !0;
|
|
554
|
+
}
|
|
555
|
+
[Symbol.asyncIterator]() {
|
|
556
|
+
return this;
|
|
557
|
+
}
|
|
558
|
+
enqueue(e) {
|
|
559
|
+
if (this._closed)
|
|
560
|
+
throw new Error("Closed");
|
|
561
|
+
if (this._settlers.length > 0) {
|
|
562
|
+
if (this._values.length > 0)
|
|
563
|
+
throw new Error("Illegal internal state");
|
|
564
|
+
const t = this._settlers.dequeue();
|
|
565
|
+
e instanceof Error ? t.reject(e) : t.resolve({ value: e });
|
|
566
|
+
} else
|
|
567
|
+
this._values.enqueue(e);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* @returns a Promise for an IteratorResult
|
|
571
|
+
*/
|
|
572
|
+
next() {
|
|
573
|
+
if (this._values.length > 0) {
|
|
574
|
+
const e = this._values.dequeue();
|
|
575
|
+
return e instanceof Error ? Promise.reject(e) : Promise.resolve({ value: e });
|
|
576
|
+
}
|
|
577
|
+
if (this._closed) {
|
|
578
|
+
if (this._settlers.length > 0)
|
|
579
|
+
throw new Error("Illegal internal state");
|
|
580
|
+
return Promise.resolve({ done: !0 });
|
|
581
|
+
}
|
|
582
|
+
return new Promise((e, t) => {
|
|
583
|
+
this._settlers.enqueue({ resolve: e, reject: t });
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const se = "\uFEFF", j = {
|
|
588
|
+
RECORD_SEP: "",
|
|
589
|
+
UNIT_SEP: "",
|
|
590
|
+
BYTE_ORDER_MARK: se,
|
|
591
|
+
BAD_DELIMITERS: ["\r", `
|
|
592
|
+
`, '"', se],
|
|
593
|
+
WORKERS_SUPPORTED: !1,
|
|
594
|
+
// !IS_WORKER && !!globalThis.Worker
|
|
595
|
+
NODE_STREAM_INPUT: 1,
|
|
596
|
+
// Configurable chunk sizes for local and remote files, respectively
|
|
597
|
+
LocalChunkSize: 1024 * 1024 * 10,
|
|
598
|
+
// 10 M,
|
|
599
|
+
RemoteChunkSize: 1024 * 1024 * 5,
|
|
600
|
+
// 5 M,
|
|
601
|
+
DefaultDelimiter: ","
|
|
602
|
+
// Used if not specified and detection fail,
|
|
603
|
+
};
|
|
604
|
+
function gt(r, e = {}, t = pt) {
|
|
605
|
+
return new t(e).stream(r);
|
|
606
|
+
}
|
|
607
|
+
let _e = class {
|
|
608
|
+
constructor(e) {
|
|
609
|
+
l(this, "_handle");
|
|
610
|
+
l(this, "_config");
|
|
611
|
+
l(this, "_finished", !1);
|
|
612
|
+
l(this, "_completed", !1);
|
|
613
|
+
l(this, "_input", null);
|
|
614
|
+
l(this, "_baseIndex", 0);
|
|
615
|
+
l(this, "_partialLine", "");
|
|
616
|
+
l(this, "_rowCount", 0);
|
|
617
|
+
l(this, "_start", 0);
|
|
618
|
+
l(this, "isFirstChunk", !0);
|
|
619
|
+
l(this, "_completeResults", {
|
|
620
|
+
data: [],
|
|
621
|
+
errors: [],
|
|
622
|
+
meta: {}
|
|
623
|
+
});
|
|
624
|
+
const t = { ...e };
|
|
625
|
+
t.dynamicTypingFunction && (t.dynamicTyping = {}), t.chunkSize = parseInt(t.chunkSize), !e.step && !e.chunk && (t.chunkSize = null), this._handle = new Ce(t), this._handle.streamer = this, this._config = t;
|
|
626
|
+
}
|
|
627
|
+
// eslint-disable-next-line complexity, max-statements
|
|
628
|
+
parseChunk(e, t) {
|
|
629
|
+
if (this.isFirstChunk && x(this._config.beforeFirstChunk)) {
|
|
630
|
+
const f = this._config.beforeFirstChunk(e);
|
|
631
|
+
f !== void 0 && (e = f);
|
|
632
|
+
}
|
|
633
|
+
this.isFirstChunk = !1;
|
|
634
|
+
const s = this._partialLine + e;
|
|
635
|
+
this._partialLine = "";
|
|
636
|
+
let i = this._handle.parse(s, this._baseIndex, !this._finished);
|
|
637
|
+
if (this._handle.paused() || this._handle.aborted())
|
|
638
|
+
return;
|
|
639
|
+
const a = i.meta.cursor;
|
|
640
|
+
this._finished || (this._partialLine = s.substring(a - this._baseIndex), this._baseIndex = a), i && i.data && (this._rowCount += i.data.length);
|
|
641
|
+
const h = this._finished || this._config.preview && this._rowCount >= this._config.preview;
|
|
642
|
+
if (x(this._config.chunk) && !t) {
|
|
643
|
+
if (this._config.chunk(i, this._handle), this._handle.paused() || this._handle.aborted())
|
|
644
|
+
return;
|
|
645
|
+
i = void 0, this._completeResults = void 0;
|
|
646
|
+
}
|
|
647
|
+
return !this._config.step && !this._config.chunk && (this._completeResults.data = this._completeResults.data.concat(i.data), this._completeResults.errors = this._completeResults.errors.concat(i.errors), this._completeResults.meta = i.meta), !this._completed && h && x(this._config.complete) && (!i || !i.meta.aborted) && (this._config.complete(this._completeResults, this._input), this._completed = !0), i;
|
|
648
|
+
}
|
|
649
|
+
_sendError(e) {
|
|
650
|
+
x(this._config.error) && this._config.error(e);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
class pt extends _e {
|
|
654
|
+
constructor(t = {}) {
|
|
655
|
+
super(t);
|
|
656
|
+
l(this, "remaining");
|
|
657
|
+
}
|
|
658
|
+
stream(t) {
|
|
659
|
+
return this.remaining = t, this._nextChunk();
|
|
660
|
+
}
|
|
661
|
+
_nextChunk() {
|
|
662
|
+
if (this._finished)
|
|
663
|
+
return;
|
|
664
|
+
const t = this._config.chunkSize, s = t ? this.remaining.substr(0, t) : this.remaining;
|
|
665
|
+
return this.remaining = t ? this.remaining.substr(t) : "", this._finished = !this.remaining, this.parseChunk(s);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const wt = /^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i, yt = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/;
|
|
669
|
+
class Ce {
|
|
670
|
+
constructor(e) {
|
|
671
|
+
l(this, "_config");
|
|
672
|
+
/** Number of times step was called (number of rows parsed) */
|
|
673
|
+
l(this, "_stepCounter", 0);
|
|
674
|
+
/** Number of rows that have been parsed so far */
|
|
675
|
+
l(this, "_rowCounter", 0);
|
|
676
|
+
/** The input being parsed */
|
|
677
|
+
l(this, "_input");
|
|
678
|
+
/** The core parser being used */
|
|
679
|
+
l(this, "_parser");
|
|
680
|
+
/** Whether we are paused or not */
|
|
681
|
+
l(this, "_paused", !1);
|
|
682
|
+
/** Whether the parser has aborted or not */
|
|
683
|
+
l(this, "_aborted", !1);
|
|
684
|
+
/** Temporary state between delimiter detection and processing results */
|
|
685
|
+
l(this, "_delimiterError", !1);
|
|
686
|
+
/** Fields are from the header row of the input, if there is one */
|
|
687
|
+
l(this, "_fields", []);
|
|
688
|
+
/** The last results returned from the parser */
|
|
689
|
+
l(this, "_results", {
|
|
690
|
+
data: [],
|
|
691
|
+
errors: [],
|
|
692
|
+
meta: {}
|
|
693
|
+
});
|
|
694
|
+
if (x(e.step)) {
|
|
695
|
+
const t = e.step;
|
|
696
|
+
e.step = (s) => {
|
|
697
|
+
if (this._results = s, this.needsHeaderRow())
|
|
698
|
+
this.processResults();
|
|
699
|
+
else {
|
|
700
|
+
if (this.processResults(), !this._results.data || this._results.data.length === 0)
|
|
701
|
+
return;
|
|
702
|
+
this._stepCounter += s.data.length, e.preview && this._stepCounter > e.preview ? this._parser.abort() : t(this._results, this);
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
this._config = e;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Parses input. Most users won't need, and shouldn't mess with, the baseIndex
|
|
710
|
+
* and ignoreLastRow parameters. They are used by streamers (wrapper functions)
|
|
711
|
+
* when an input comes in multiple chunks, like from a file.
|
|
712
|
+
*/
|
|
713
|
+
parse(e, t, s) {
|
|
714
|
+
const i = this._config.quoteChar || '"';
|
|
715
|
+
if (this._config.newline || (this._config.newline = bt(e, i)), this._delimiterError = !1, this._config.delimiter)
|
|
716
|
+
x(this._config.delimiter) && (this._config.delimiter = this._config.delimiter(e), this._results.meta.delimiter = this._config.delimiter);
|
|
717
|
+
else {
|
|
718
|
+
const h = this.guessDelimiter(e, this._config.newline, this._config.skipEmptyLines, this._config.comments, this._config.delimitersToGuess);
|
|
719
|
+
h.successful ? this._config.delimiter = h.bestDelimiter : (this._delimiterError = !0, this._config.delimiter = j.DefaultDelimiter), this._results.meta.delimiter = this._config.delimiter;
|
|
720
|
+
}
|
|
721
|
+
const a = Ae(this._config);
|
|
722
|
+
return this._config.preview && this._config.header && a.preview++, this._input = e, this._parser = new Z(a), this._results = this._parser.parse(this._input, t, s), this.processResults(), this._paused ? { meta: { paused: !0 } } : this._results || { meta: { paused: !1 } };
|
|
723
|
+
}
|
|
724
|
+
paused() {
|
|
725
|
+
return this._paused;
|
|
726
|
+
}
|
|
727
|
+
pause() {
|
|
728
|
+
this._paused = !0, this._parser.abort(), this._input = this._input.substr(this._parser.getCharIndex());
|
|
729
|
+
}
|
|
730
|
+
resume() {
|
|
731
|
+
this._paused = !1, this.streamer.parseChunk(this._input, !0);
|
|
732
|
+
}
|
|
733
|
+
aborted() {
|
|
734
|
+
return this._aborted;
|
|
735
|
+
}
|
|
736
|
+
abort() {
|
|
737
|
+
this._aborted = !0, this._parser.abort(), this._results.meta.aborted = !0, x(this._config.complete) && this._config.complete(this._results), this._input = "";
|
|
738
|
+
}
|
|
739
|
+
testEmptyLine(e) {
|
|
740
|
+
return this._config.skipEmptyLines === "greedy" ? e.join("").trim() === "" : e.length === 1 && e[0].length === 0;
|
|
741
|
+
}
|
|
742
|
+
processResults() {
|
|
743
|
+
if (this._results && this._delimiterError && (this.addError("Delimiter", "UndetectableDelimiter", `Unable to auto-detect delimiting character; defaulted to '${j.DefaultDelimiter}'`), this._delimiterError = !1), this._config.skipEmptyLines)
|
|
744
|
+
for (let e = 0; e < this._results.data.length; e++)
|
|
745
|
+
this.testEmptyLine(this._results.data[e]) && this._results.data.splice(e--, 1);
|
|
746
|
+
return this.needsHeaderRow() && this.fillHeaderFields(), this.applyHeaderAndDynamicTypingAndTransformation();
|
|
747
|
+
}
|
|
748
|
+
needsHeaderRow() {
|
|
749
|
+
return this._config.header && this._fields.length === 0;
|
|
750
|
+
}
|
|
751
|
+
fillHeaderFields() {
|
|
752
|
+
if (!this._results)
|
|
753
|
+
return;
|
|
754
|
+
const e = (t) => {
|
|
755
|
+
x(this._config.transformHeader) && (t = this._config.transformHeader(t)), this._fields.push(t);
|
|
756
|
+
};
|
|
757
|
+
if (Array.isArray(this._results.data[0])) {
|
|
758
|
+
for (let t = 0; this.needsHeaderRow() && t < this._results.data.length; t++)
|
|
759
|
+
this._results.data[t].forEach(e);
|
|
760
|
+
this._results.data.splice(0, 1);
|
|
761
|
+
} else
|
|
762
|
+
this._results.data.forEach(e);
|
|
763
|
+
}
|
|
764
|
+
shouldApplyDynamicTyping(e) {
|
|
765
|
+
var t, s;
|
|
766
|
+
return this._config.dynamicTypingFunction && ((t = this._config.dynamicTyping) == null ? void 0 : t[e]) === void 0 && (this._config.dynamicTyping[e] = this._config.dynamicTypingFunction(e)), (((s = this._config.dynamicTyping) == null ? void 0 : s[e]) || this._config.dynamicTyping) === !0;
|
|
767
|
+
}
|
|
768
|
+
parseDynamic(e, t) {
|
|
769
|
+
return this.shouldApplyDynamicTyping(e) ? t === "true" || t === "TRUE" ? !0 : t === "false" || t === "FALSE" ? !1 : wt.test(t) ? parseFloat(t) : yt.test(t) ? new Date(t) : t === "" ? null : t : t;
|
|
770
|
+
}
|
|
771
|
+
applyHeaderAndDynamicTypingAndTransformation() {
|
|
772
|
+
if (!this._results || !this._results.data || !this._config.header && !this._config.dynamicTyping && !this._config.transform)
|
|
773
|
+
return this._results;
|
|
774
|
+
let e = 1;
|
|
775
|
+
return !this._results.data[0] || Array.isArray(this._results.data[0]) ? (this._results.data = this._results.data.map(this.processRow.bind(this)), e = this._results.data.length) : this._results.data = this.processRow(this._results.data, 0), this._config.header && this._results.meta && (this._results.meta.fields = this._fields), this._rowCounter += e, this._results;
|
|
776
|
+
}
|
|
777
|
+
processRow(e, t) {
|
|
778
|
+
const s = this._config.header ? {} : [];
|
|
779
|
+
let i;
|
|
780
|
+
for (i = 0; i < e.length; i++) {
|
|
781
|
+
let a = i, h = e[i];
|
|
782
|
+
this._config.header && (a = i >= this._fields.length ? "__parsed_extra" : this._fields[i]), this._config.transform && (h = this._config.transform(h, a)), h = this.parseDynamic(a, h), a === "__parsed_extra" ? (s[a] = s[a] || [], s[a].push(h)) : s[a] = h;
|
|
783
|
+
}
|
|
784
|
+
return this._config.header && (i > this._fields.length ? this.addError("FieldMismatch", "TooManyFields", `Too many fields: expected ${this._fields.length} fields but parsed ${i}`, this._rowCounter + t) : i < this._fields.length && this.addError("FieldMismatch", "TooFewFields", `Too few fields: expected ${this._fields.length} fields but parsed ${i}`, this._rowCounter + t)), s;
|
|
785
|
+
}
|
|
786
|
+
// eslint-disable-next-line complexity, max-statements
|
|
787
|
+
guessDelimiter(e, t, s, i, a) {
|
|
788
|
+
let h, f, m;
|
|
789
|
+
a = a || [",", " ", "|", ";", j.RECORD_SEP, j.UNIT_SEP];
|
|
790
|
+
for (let o = 0; o < a.length; o++) {
|
|
791
|
+
const d = a[o];
|
|
792
|
+
let n = 0, u = 0, _ = 0;
|
|
793
|
+
m = void 0;
|
|
794
|
+
const p = new Z({
|
|
795
|
+
comments: i,
|
|
796
|
+
delimiter: d,
|
|
797
|
+
newline: t,
|
|
798
|
+
preview: 10
|
|
799
|
+
}).parse(e);
|
|
800
|
+
for (let c = 0; c < p.data.length; c++) {
|
|
801
|
+
if (s && this.testEmptyLine(p.data[c])) {
|
|
802
|
+
_++;
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
const g = p.data[c].length;
|
|
806
|
+
if (n += g, typeof m > "u") {
|
|
807
|
+
m = 0;
|
|
808
|
+
continue;
|
|
809
|
+
} else g > 1 && (u += Math.abs(g - m), m = g);
|
|
810
|
+
}
|
|
811
|
+
p.data.length > 0 && (n /= p.data.length - _), (typeof f > "u" || u > f) && n > 1.99 && (f = u, h = d);
|
|
812
|
+
}
|
|
813
|
+
return this._config.delimiter = h, {
|
|
814
|
+
successful: !!h,
|
|
815
|
+
bestDelimiter: h
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
addError(e, t, s, i) {
|
|
819
|
+
this._results.errors.push({
|
|
820
|
+
type: e,
|
|
821
|
+
code: t,
|
|
822
|
+
message: s,
|
|
823
|
+
row: i
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function bt(r, e) {
|
|
828
|
+
r = r.substr(0, 1024 * 1024);
|
|
829
|
+
const t = new RegExp(`${V(e)}([^]*?)${V(e)}`, "gm");
|
|
830
|
+
r = r.replace(t, "");
|
|
831
|
+
const s = r.split("\r"), i = r.split(`
|
|
832
|
+
`), a = i.length > 1 && i[0].length < s[0].length;
|
|
833
|
+
if (s.length === 1 || a)
|
|
834
|
+
return `
|
|
835
|
+
`;
|
|
836
|
+
let h = 0;
|
|
837
|
+
for (let f = 0; f < s.length; f++)
|
|
838
|
+
s[f][0] === `
|
|
839
|
+
` && h++;
|
|
840
|
+
return h >= s.length / 2 ? `\r
|
|
841
|
+
` : "\r";
|
|
842
|
+
}
|
|
843
|
+
function V(r) {
|
|
844
|
+
return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
845
|
+
}
|
|
846
|
+
function Z(r = {}) {
|
|
847
|
+
let e = r.delimiter, t = r.newline, s = r.comments;
|
|
848
|
+
const i = r.step, a = r.preview, h = r.fastMode;
|
|
849
|
+
let f;
|
|
850
|
+
r.quoteChar === void 0 ? f = '"' : f = r.quoteChar;
|
|
851
|
+
let m = f;
|
|
852
|
+
if (r.escapeChar !== void 0 && (m = r.escapeChar), (typeof e != "string" || j.BAD_DELIMITERS.indexOf(e) > -1) && (e = ","), s === e)
|
|
853
|
+
throw new Error("Comment character same as delimiter");
|
|
854
|
+
s === !0 ? s = "#" : (typeof s != "string" || j.BAD_DELIMITERS.indexOf(s) > -1) && (s = !1), t !== `
|
|
855
|
+
` && t !== "\r" && t !== `\r
|
|
856
|
+
` && (t = `
|
|
857
|
+
`);
|
|
858
|
+
let o = 0, d = !1;
|
|
859
|
+
this.parse = function(n, u, _) {
|
|
860
|
+
if (typeof n != "string")
|
|
861
|
+
throw new Error("Input must be a string");
|
|
862
|
+
const p = n.length, c = e.length, g = t.length, A = s.length, R = x(i);
|
|
863
|
+
o = 0;
|
|
864
|
+
let y = [], F = [], w = [], v = 0;
|
|
865
|
+
if (!n)
|
|
866
|
+
return E();
|
|
867
|
+
if (h || h !== !1 && n.indexOf(f) === -1) {
|
|
868
|
+
const S = n.split(t);
|
|
869
|
+
for (let O = 0; O < S.length; O++) {
|
|
870
|
+
const k = S[O];
|
|
871
|
+
if (o += k.length, O !== S.length - 1)
|
|
872
|
+
o += t.length;
|
|
873
|
+
else if (_)
|
|
874
|
+
return E();
|
|
875
|
+
if (!(s && k.substr(0, A) === s)) {
|
|
876
|
+
if (R) {
|
|
877
|
+
if (y = [], I(k.split(e)), N(), d)
|
|
878
|
+
return E();
|
|
879
|
+
} else
|
|
880
|
+
I(k.split(e));
|
|
881
|
+
if (a && O >= a)
|
|
882
|
+
return y = y.slice(0, a), E(!0);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return E();
|
|
886
|
+
}
|
|
887
|
+
let T = n.indexOf(e, o), C = n.indexOf(t, o);
|
|
888
|
+
const D = new RegExp(V(m) + V(f), "g");
|
|
889
|
+
let b;
|
|
890
|
+
for (; ; ) {
|
|
891
|
+
if (n[o] === f) {
|
|
892
|
+
for (b = o, o++; ; ) {
|
|
893
|
+
if (b = n.indexOf(f, b + 1), b === -1)
|
|
894
|
+
return _ || F.push({
|
|
895
|
+
type: "Quotes",
|
|
896
|
+
code: "MissingQuotes",
|
|
897
|
+
message: "Quoted field unterminated",
|
|
898
|
+
row: y.length,
|
|
899
|
+
// row has yet to be inserted
|
|
900
|
+
index: o
|
|
901
|
+
}), H();
|
|
902
|
+
if (b === p - 1) {
|
|
903
|
+
const De = n.substring(o, b).replace(D, f);
|
|
904
|
+
return H(De);
|
|
905
|
+
}
|
|
906
|
+
if (f === m && n[b + 1] === m) {
|
|
907
|
+
b++;
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (f !== m && b !== 0 && n[b - 1] === m)
|
|
911
|
+
continue;
|
|
912
|
+
const S = C === -1 ? T : Math.min(T, C), O = K(S);
|
|
913
|
+
if (n[b + 1 + O] === e) {
|
|
914
|
+
if (w.push(n.substring(o, b).replace(D, f)), o = b + 1 + O + c, T = n.indexOf(e, o), C = n.indexOf(t, o), R && (N(), d))
|
|
915
|
+
return E();
|
|
916
|
+
if (a && y.length >= a)
|
|
917
|
+
return E(!0);
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
const k = K(C);
|
|
921
|
+
if (n.substr(b + 1 + k, g) === t) {
|
|
922
|
+
if (w.push(n.substring(o, b).replace(D, f)), G(b + 1 + k + g), T = n.indexOf(e, o), R && (N(), d))
|
|
923
|
+
return E();
|
|
924
|
+
if (a && y.length >= a)
|
|
925
|
+
return E(!0);
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
F.push({
|
|
929
|
+
type: "Quotes",
|
|
930
|
+
code: "InvalidQuotes",
|
|
931
|
+
message: "Trailing quote on quoted field is malformed",
|
|
932
|
+
row: y.length,
|
|
933
|
+
// row has yet to be inserted
|
|
934
|
+
index: o
|
|
935
|
+
}), b++;
|
|
936
|
+
}
|
|
937
|
+
if (R && (N(), d))
|
|
938
|
+
return E();
|
|
939
|
+
if (a && y.length >= a)
|
|
940
|
+
return E(!0);
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
if (s && w.length === 0 && n.substr(o, A) === s) {
|
|
944
|
+
if (C === -1)
|
|
945
|
+
return E();
|
|
946
|
+
o = C + g, C = n.indexOf(t, o), T = n.indexOf(e, o);
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
if (T !== -1 && (T < C || C === -1)) {
|
|
950
|
+
w.push(n.substring(o, T)), o = T + c, T = n.indexOf(e, o);
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
if (C !== -1) {
|
|
954
|
+
if (w.push(n.substring(o, C)), G(C + g), R && (N(), d))
|
|
955
|
+
return E();
|
|
956
|
+
if (a && y.length >= a)
|
|
957
|
+
return E(!0);
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
return H();
|
|
963
|
+
function I(S) {
|
|
964
|
+
y.push(S), v = o;
|
|
965
|
+
}
|
|
966
|
+
function K(S) {
|
|
967
|
+
let O = 0;
|
|
968
|
+
if (S !== -1) {
|
|
969
|
+
const k = n.substring(b + 1, S);
|
|
970
|
+
k && k.trim() === "" && (O = k.length);
|
|
971
|
+
}
|
|
972
|
+
return O;
|
|
973
|
+
}
|
|
974
|
+
function H(S) {
|
|
975
|
+
return _ || (typeof S > "u" && (S = n.substr(o)), w.push(S), o = p, I(w), R && N()), E();
|
|
976
|
+
}
|
|
977
|
+
function G(S) {
|
|
978
|
+
o = S, I(w), w = [], C = n.indexOf(t, o);
|
|
979
|
+
}
|
|
980
|
+
function E(S, O) {
|
|
981
|
+
return {
|
|
982
|
+
data: O || !1 ? y[0] : y,
|
|
983
|
+
errors: F,
|
|
984
|
+
meta: {
|
|
985
|
+
delimiter: e,
|
|
986
|
+
linebreak: t,
|
|
987
|
+
aborted: d,
|
|
988
|
+
truncated: !!S,
|
|
989
|
+
cursor: v + (u || 0)
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
function N() {
|
|
994
|
+
i(E(void 0, !0)), y = [], F = [];
|
|
995
|
+
}
|
|
996
|
+
}, this.abort = function() {
|
|
997
|
+
d = !0;
|
|
998
|
+
}, this.getCharIndex = function() {
|
|
999
|
+
return o;
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
function Ae(r) {
|
|
1003
|
+
if (typeof r != "object" || r === null)
|
|
1004
|
+
return r;
|
|
1005
|
+
const e = Array.isArray(r) ? [] : {};
|
|
1006
|
+
for (const t in r)
|
|
1007
|
+
e[t] = Ae(r[t]);
|
|
1008
|
+
return e;
|
|
1009
|
+
}
|
|
1010
|
+
function x(r) {
|
|
1011
|
+
return typeof r == "function";
|
|
1012
|
+
}
|
|
1013
|
+
function _t(r, e = {}) {
|
|
1014
|
+
let t = !1, s = !0, i = ",", a = `\r
|
|
1015
|
+
`, h = '"', f = h + h, m = !1, o = null;
|
|
1016
|
+
n();
|
|
1017
|
+
const d = new RegExp(Ct(h), "g");
|
|
1018
|
+
if (typeof r == "string" && (r = JSON.parse(r)), Array.isArray(r)) {
|
|
1019
|
+
if (!r.length || Array.isArray(r[0]))
|
|
1020
|
+
return u(null, r, m);
|
|
1021
|
+
if (typeof r[0] == "object")
|
|
1022
|
+
return u(o || Object.keys(r[0]), r, m);
|
|
1023
|
+
} else if (typeof r == "object")
|
|
1024
|
+
return typeof r.data == "string" && (r.data = JSON.parse(r.data)), Array.isArray(r.data) && (r.fields || (r.fields = r.meta && r.meta.fields), r.fields || (r.fields = Array.isArray(r.data[0]) ? r.fields : Object.keys(r.data[0])), !Array.isArray(r.data[0]) && typeof r.data[0] != "object" && (r.data = [r.data])), u(r.fields || [], r.data || [], m);
|
|
1025
|
+
throw new Error("Unable to serialize unrecognized input");
|
|
1026
|
+
function n() {
|
|
1027
|
+
if (typeof e == "object") {
|
|
1028
|
+
if (typeof e.delimiter == "string" && !j.BAD_DELIMITERS.filter(function(c) {
|
|
1029
|
+
var g;
|
|
1030
|
+
return ((g = e.delimiter) == null ? void 0 : g.indexOf(c)) !== -1;
|
|
1031
|
+
}).length && (i = e.delimiter), (typeof e.quotes == "boolean" || Array.isArray(e.quotes)) && (t = e.quotes), (typeof e.skipEmptyLines == "boolean" || e.skipEmptyLines === "greedy") && (m = e.skipEmptyLines), typeof e.newline == "string" && (a = e.newline), typeof e.quoteChar == "string" && (h = e.quoteChar), typeof e.header == "boolean" && (s = e.header), Array.isArray(e.columns)) {
|
|
1032
|
+
if (e.columns.length === 0)
|
|
1033
|
+
throw new Error("Option columns is empty");
|
|
1034
|
+
o = e.columns;
|
|
1035
|
+
}
|
|
1036
|
+
e.escapeChar !== void 0 && (f = e.escapeChar + h);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
function u(c, g, A) {
|
|
1040
|
+
let R = "";
|
|
1041
|
+
typeof c == "string" && (c = JSON.parse(c)), typeof g == "string" && (g = JSON.parse(g));
|
|
1042
|
+
const y = Array.isArray(c) && c.length > 0, F = !Array.isArray(g[0]);
|
|
1043
|
+
if (y && s) {
|
|
1044
|
+
for (let w = 0; w < c.length; w++)
|
|
1045
|
+
w > 0 && (R += i), R += _(c[w], w);
|
|
1046
|
+
g.length > 0 && (R += a);
|
|
1047
|
+
}
|
|
1048
|
+
for (let w = 0; w < g.length; w++) {
|
|
1049
|
+
const v = y ? c.length : g[w].length;
|
|
1050
|
+
let T = !1;
|
|
1051
|
+
const C = y ? Object.keys(g[w]).length === 0 : g[w].length === 0;
|
|
1052
|
+
if (A && !y && (T = A === "greedy" ? g[w].join("").trim() === "" : g[w].length === 1 && g[w][0].length === 0), A === "greedy" && y) {
|
|
1053
|
+
const D = [];
|
|
1054
|
+
for (let b = 0; b < v; b++) {
|
|
1055
|
+
const I = F ? c[b] : b;
|
|
1056
|
+
D.push(g[w][I]);
|
|
1057
|
+
}
|
|
1058
|
+
T = D.join("").trim() === "";
|
|
1059
|
+
}
|
|
1060
|
+
if (!T) {
|
|
1061
|
+
for (let D = 0; D < v; D++) {
|
|
1062
|
+
D > 0 && !C && (R += i);
|
|
1063
|
+
const b = y && F ? c[D] : D;
|
|
1064
|
+
R += _(g[w][b], D);
|
|
1065
|
+
}
|
|
1066
|
+
w < g.length - 1 && (!A || v > 0 && !C) && (R += a);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return R;
|
|
1070
|
+
}
|
|
1071
|
+
function _(c, g) {
|
|
1072
|
+
return typeof c > "u" || c === null ? "" : c.constructor === Date ? JSON.stringify(c).slice(1, 25) : (c = c.toString().replace(d, f), typeof t == "boolean" && t || Array.isArray(t) && t[g] || p(c, j.BAD_DELIMITERS) || c.indexOf(i) > -1 || c.charAt(0) === " " || c.charAt(c.length - 1) === " " ? h + c + h : c);
|
|
1073
|
+
}
|
|
1074
|
+
function p(c, g) {
|
|
1075
|
+
for (let A = 0; A < g.length; A++)
|
|
1076
|
+
if (c.indexOf(g[A]) > -1)
|
|
1077
|
+
return !0;
|
|
1078
|
+
return !1;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
function Ct(r) {
|
|
1082
|
+
return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1083
|
+
}
|
|
1084
|
+
const P = {
|
|
1085
|
+
...j,
|
|
1086
|
+
parse: gt,
|
|
1087
|
+
unparse: _t,
|
|
1088
|
+
ChunkStreamer: _e,
|
|
1089
|
+
// Exposed for testing and development only
|
|
1090
|
+
Parser: Z,
|
|
1091
|
+
ParserHandle: Ce
|
|
1092
|
+
}, { ChunkStreamer: At } = P;
|
|
1093
|
+
class Tt extends At {
|
|
1094
|
+
constructor(t = {}) {
|
|
1095
|
+
super(t);
|
|
1096
|
+
l(this, "textDecoder", new TextDecoder(this._config.encoding));
|
|
1097
|
+
}
|
|
1098
|
+
// Implement ChunkStreamer base class methods
|
|
1099
|
+
// this.pause = function() {
|
|
1100
|
+
// ChunkStreamer.prototype.pause.apply(this, arguments);
|
|
1101
|
+
// };
|
|
1102
|
+
// this.resume = function() {
|
|
1103
|
+
// ChunkStreamer.prototype.resume.apply(this, arguments);
|
|
1104
|
+
// this._input.resume();
|
|
1105
|
+
// };
|
|
1106
|
+
async stream(t) {
|
|
1107
|
+
this._input = t;
|
|
1108
|
+
try {
|
|
1109
|
+
for await (const s of t)
|
|
1110
|
+
this.parseChunk(this.getStringChunk(s));
|
|
1111
|
+
this._finished = !0, this.parseChunk("");
|
|
1112
|
+
} catch (s) {
|
|
1113
|
+
this._sendError(s);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
_nextChunk() {
|
|
1117
|
+
}
|
|
1118
|
+
// HELPER METHODS
|
|
1119
|
+
getStringChunk(t) {
|
|
1120
|
+
return typeof t == "string" ? t : this.textDecoder.decode(t, { stream: !0 });
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
const Te = {
|
|
1124
|
+
id: "csv",
|
|
1125
|
+
module: "csv",
|
|
1126
|
+
name: "CSV",
|
|
1127
|
+
extensions: ["csv", "tsv", "dsv"],
|
|
1128
|
+
mimeTypes: ["text/csv", "text/tab-separated-values", "text/dsv"],
|
|
1129
|
+
category: "table"
|
|
1130
|
+
}, Rt = "4.4.3", Y = "object-row-table", M = {
|
|
1131
|
+
...Te,
|
|
1132
|
+
dataType: null,
|
|
1133
|
+
batchType: null,
|
|
1134
|
+
version: Rt,
|
|
1135
|
+
parse: async (r, e) => ne(new TextDecoder().decode(r), e),
|
|
1136
|
+
parseText: (r, e) => ne(r, e),
|
|
1137
|
+
parseInBatches: St,
|
|
1138
|
+
// @ts-ignore
|
|
1139
|
+
// testText: null,
|
|
1140
|
+
options: {
|
|
1141
|
+
csv: {
|
|
1142
|
+
shape: Y,
|
|
1143
|
+
// 'object-row-table'
|
|
1144
|
+
optimizeMemoryUsage: !1,
|
|
1145
|
+
// CSV options
|
|
1146
|
+
header: "auto",
|
|
1147
|
+
columnPrefix: "column",
|
|
1148
|
+
// delimiter: auto
|
|
1149
|
+
// newline: auto
|
|
1150
|
+
quoteChar: '"',
|
|
1151
|
+
escapeChar: '"',
|
|
1152
|
+
dynamicTyping: !0,
|
|
1153
|
+
comments: !1,
|
|
1154
|
+
skipEmptyLines: !0,
|
|
1155
|
+
// transform: null?
|
|
1156
|
+
delimitersToGuess: [",", " ", "|", ";"]
|
|
1157
|
+
// fastMode: auto
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
async function ne(r, e) {
|
|
1162
|
+
const t = { ...M.options.csv, ...e == null ? void 0 : e.csv }, s = Et(r), a = t.header === "auto" ? Re(s) : !!t.header, h = {
|
|
1163
|
+
// dynamicTyping: true,
|
|
1164
|
+
...t,
|
|
1165
|
+
header: a,
|
|
1166
|
+
download: !1,
|
|
1167
|
+
// We handle loading, no need for papaparse to do it for us
|
|
1168
|
+
transformHeader: a ? Se() : void 0,
|
|
1169
|
+
error: (u) => {
|
|
1170
|
+
throw new Error(u);
|
|
1171
|
+
}
|
|
1172
|
+
}, f = P.parse(r, h), m = f.data, o = f.meta.fields || Ee(t.columnPrefix, s.length), d = t.shape || Y;
|
|
1173
|
+
let n;
|
|
1174
|
+
switch (d) {
|
|
1175
|
+
case "object-row-table":
|
|
1176
|
+
n = {
|
|
1177
|
+
shape: "object-row-table",
|
|
1178
|
+
data: m.map((u) => Array.isArray(u) ? pe(u, o) : u)
|
|
1179
|
+
};
|
|
1180
|
+
break;
|
|
1181
|
+
case "array-row-table":
|
|
1182
|
+
n = {
|
|
1183
|
+
shape: "array-row-table",
|
|
1184
|
+
data: m.map((u) => Array.isArray(u) ? u : we(u, o))
|
|
1185
|
+
};
|
|
1186
|
+
break;
|
|
1187
|
+
default:
|
|
1188
|
+
throw new Error(d);
|
|
1189
|
+
}
|
|
1190
|
+
return n.schema = me(n), n;
|
|
1191
|
+
}
|
|
1192
|
+
function St(r, e) {
|
|
1193
|
+
var o;
|
|
1194
|
+
e = { ...e }, ((o = e == null ? void 0 : e.core) == null ? void 0 : o.batchSize) === "auto" && (e.core.batchSize = 4e3);
|
|
1195
|
+
const t = { ...M.options.csv, ...e == null ? void 0 : e.csv }, s = new mt();
|
|
1196
|
+
let i = !0, a = null, h = null, f = null;
|
|
1197
|
+
const m = {
|
|
1198
|
+
// dynamicTyping: true, // Convert numbers and boolean values in rows from strings,
|
|
1199
|
+
...t,
|
|
1200
|
+
header: !1,
|
|
1201
|
+
// Unfortunately, header detection is not automatic and does not infer shapes
|
|
1202
|
+
download: !1,
|
|
1203
|
+
// We handle loading, no need for papaparse to do it for us
|
|
1204
|
+
// chunkSize is set to 5MB explicitly (same as Papaparse default) due to a bug where the
|
|
1205
|
+
// streaming parser gets stuck if skipEmptyLines and a step callback are both supplied.
|
|
1206
|
+
// See https://github.com/mholt/PapaParse/issues/465
|
|
1207
|
+
chunkSize: 1024 * 1024 * 5,
|
|
1208
|
+
// skipEmptyLines is set to a boolean value if supplied. Greedy is set to true
|
|
1209
|
+
// skipEmptyLines is handled manually given two bugs where the streaming parser gets stuck if
|
|
1210
|
+
// both of the skipEmptyLines and step callback options are provided:
|
|
1211
|
+
// - true doesn't work unless chunkSize is set: https://github.com/mholt/PapaParse/issues/465
|
|
1212
|
+
// - greedy doesn't work: https://github.com/mholt/PapaParse/issues/825
|
|
1213
|
+
skipEmptyLines: !1,
|
|
1214
|
+
// step is called on every row
|
|
1215
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1216
|
+
step(d) {
|
|
1217
|
+
let n = d.data;
|
|
1218
|
+
if (t.skipEmptyLines && n.flat().join("").trim() === "")
|
|
1219
|
+
return;
|
|
1220
|
+
const u = d.meta.cursor;
|
|
1221
|
+
if (i && !a && (t.header === "auto" ? Re(n) : !!t.header)) {
|
|
1222
|
+
a = n.map(Se());
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
i && (i = !1, a || (a = Ee(t.columnPrefix, n.length)), f = Bt(n, a)), t.optimizeMemoryUsage && (n = JSON.parse(JSON.stringify(n)));
|
|
1226
|
+
const _ = (e == null ? void 0 : e.shape) || t.shape || Y;
|
|
1227
|
+
h = h || new be(
|
|
1228
|
+
// @ts-expect-error TODO this is not a proper schema
|
|
1229
|
+
f,
|
|
1230
|
+
{
|
|
1231
|
+
shape: _,
|
|
1232
|
+
...(e == null ? void 0 : e.core) || {}
|
|
1233
|
+
}
|
|
1234
|
+
);
|
|
1235
|
+
try {
|
|
1236
|
+
h.addRow(n);
|
|
1237
|
+
const p = h && h.getFullBatch({ bytesUsed: u });
|
|
1238
|
+
p && s.enqueue(p);
|
|
1239
|
+
} catch (p) {
|
|
1240
|
+
s.enqueue(p);
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
// complete is called when all rows have been read
|
|
1244
|
+
complete(d) {
|
|
1245
|
+
try {
|
|
1246
|
+
const n = d.meta.cursor, u = h && h.getFinalBatch({ bytesUsed: n });
|
|
1247
|
+
u && s.enqueue(u);
|
|
1248
|
+
} catch (n) {
|
|
1249
|
+
s.enqueue(n);
|
|
1250
|
+
}
|
|
1251
|
+
s.close();
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
return P.parse(je(r), m, Tt), s;
|
|
1255
|
+
}
|
|
1256
|
+
function Re(r) {
|
|
1257
|
+
return r && r.every((e) => typeof e == "string");
|
|
1258
|
+
}
|
|
1259
|
+
function Et(r) {
|
|
1260
|
+
return P.parse(r, {
|
|
1261
|
+
dynamicTyping: !0,
|
|
1262
|
+
preview: 1
|
|
1263
|
+
}).data[0];
|
|
1264
|
+
}
|
|
1265
|
+
function Se() {
|
|
1266
|
+
const r = /* @__PURE__ */ new Set();
|
|
1267
|
+
return (e) => {
|
|
1268
|
+
let t = e, s = 1;
|
|
1269
|
+
for (; r.has(t); )
|
|
1270
|
+
t = `${e}.${s}`, s++;
|
|
1271
|
+
return r.add(t), t;
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
function Ee(r, e = 0) {
|
|
1275
|
+
const t = [];
|
|
1276
|
+
for (let s = 0; s < e; s++)
|
|
1277
|
+
t.push(`${r}${s + 1}`);
|
|
1278
|
+
return t;
|
|
1279
|
+
}
|
|
1280
|
+
function Bt(r, e) {
|
|
1281
|
+
const t = [];
|
|
1282
|
+
for (let s = 0; s < r.length; s++) {
|
|
1283
|
+
const i = e && e[s] || s, a = r[s];
|
|
1284
|
+
switch (typeof a) {
|
|
1285
|
+
case "number":
|
|
1286
|
+
t.push({ name: String(i), type: "float64", nullable: !0 });
|
|
1287
|
+
break;
|
|
1288
|
+
case "boolean":
|
|
1289
|
+
t.push({ name: String(i), type: "bool", nullable: !0 });
|
|
1290
|
+
break;
|
|
1291
|
+
case "string":
|
|
1292
|
+
t.push({ name: String(i), type: "utf8", nullable: !0 });
|
|
1293
|
+
break;
|
|
1294
|
+
default:
|
|
1295
|
+
xe.warn(`CSV: Unknown column type: ${typeof a}`)(), t.push({ name: String(i), type: "utf8", nullable: !0 });
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return {
|
|
1299
|
+
fields: t,
|
|
1300
|
+
metadata: {
|
|
1301
|
+
"loaders.gl#format": "csv",
|
|
1302
|
+
"loaders.gl#loader": "CSVLoader"
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
var ie = {}, z = {}, Q = 34, L = 10, J = 13;
|
|
1307
|
+
function Be(r) {
|
|
1308
|
+
return new Function("d", "return {" + r.map(function(e, t) {
|
|
1309
|
+
return JSON.stringify(e) + ": d[" + t + '] || ""';
|
|
1310
|
+
}).join(",") + "}");
|
|
1311
|
+
}
|
|
1312
|
+
function Dt(r, e) {
|
|
1313
|
+
var t = Be(r);
|
|
1314
|
+
return function(s, i) {
|
|
1315
|
+
return e(t(s), i, r);
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
function ae(r) {
|
|
1319
|
+
var e = /* @__PURE__ */ Object.create(null), t = [];
|
|
1320
|
+
return r.forEach(function(s) {
|
|
1321
|
+
for (var i in s)
|
|
1322
|
+
i in e || t.push(e[i] = i);
|
|
1323
|
+
}), t;
|
|
1324
|
+
}
|
|
1325
|
+
function B(r, e) {
|
|
1326
|
+
var t = r + "", s = t.length;
|
|
1327
|
+
return s < e ? new Array(e - s + 1).join(0) + t : t;
|
|
1328
|
+
}
|
|
1329
|
+
function Ot(r) {
|
|
1330
|
+
return r < 0 ? "-" + B(-r, 6) : r > 9999 ? "+" + B(r, 6) : B(r, 4);
|
|
1331
|
+
}
|
|
1332
|
+
function kt(r) {
|
|
1333
|
+
var e = r.getUTCHours(), t = r.getUTCMinutes(), s = r.getUTCSeconds(), i = r.getUTCMilliseconds();
|
|
1334
|
+
return isNaN(r) ? "Invalid Date" : Ot(r.getUTCFullYear()) + "-" + B(r.getUTCMonth() + 1, 2) + "-" + B(r.getUTCDate(), 2) + (i ? "T" + B(e, 2) + ":" + B(t, 2) + ":" + B(s, 2) + "." + B(i, 3) + "Z" : s ? "T" + B(e, 2) + ":" + B(t, 2) + ":" + B(s, 2) + "Z" : t || e ? "T" + B(e, 2) + ":" + B(t, 2) + "Z" : "");
|
|
1335
|
+
}
|
|
1336
|
+
function vt(r) {
|
|
1337
|
+
var e = new RegExp('["' + r + `
|
|
1338
|
+
\r]`), t = r.charCodeAt(0);
|
|
1339
|
+
function s(n, u) {
|
|
1340
|
+
var _, p, c = i(n, function(g, A) {
|
|
1341
|
+
if (_) return _(g, A - 1);
|
|
1342
|
+
p = g, _ = u ? Dt(g, u) : Be(g);
|
|
1343
|
+
});
|
|
1344
|
+
return c.columns = p || [], c;
|
|
1345
|
+
}
|
|
1346
|
+
function i(n, u) {
|
|
1347
|
+
var _ = [], p = n.length, c = 0, g = 0, A, R = p <= 0, y = !1;
|
|
1348
|
+
n.charCodeAt(p - 1) === L && --p, n.charCodeAt(p - 1) === J && --p;
|
|
1349
|
+
function F() {
|
|
1350
|
+
if (R) return z;
|
|
1351
|
+
if (y) return y = !1, ie;
|
|
1352
|
+
var v, T = c, C;
|
|
1353
|
+
if (n.charCodeAt(T) === Q) {
|
|
1354
|
+
for (; c++ < p && n.charCodeAt(c) !== Q || n.charCodeAt(++c) === Q; ) ;
|
|
1355
|
+
return (v = c) >= p ? R = !0 : (C = n.charCodeAt(c++)) === L ? y = !0 : C === J && (y = !0, n.charCodeAt(c) === L && ++c), n.slice(T + 1, v - 1).replace(/""/g, '"');
|
|
1356
|
+
}
|
|
1357
|
+
for (; c < p; ) {
|
|
1358
|
+
if ((C = n.charCodeAt(v = c++)) === L) y = !0;
|
|
1359
|
+
else if (C === J)
|
|
1360
|
+
y = !0, n.charCodeAt(c) === L && ++c;
|
|
1361
|
+
else if (C !== t) continue;
|
|
1362
|
+
return n.slice(T, v);
|
|
1363
|
+
}
|
|
1364
|
+
return R = !0, n.slice(T, p);
|
|
1365
|
+
}
|
|
1366
|
+
for (; (A = F()) !== z; ) {
|
|
1367
|
+
for (var w = []; A !== ie && A !== z; ) w.push(A), A = F();
|
|
1368
|
+
u && (w = u(w, g++)) == null || _.push(w);
|
|
1369
|
+
}
|
|
1370
|
+
return _;
|
|
1371
|
+
}
|
|
1372
|
+
function a(n, u) {
|
|
1373
|
+
return n.map(function(_) {
|
|
1374
|
+
return u.map(function(p) {
|
|
1375
|
+
return d(_[p]);
|
|
1376
|
+
}).join(r);
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
function h(n, u) {
|
|
1380
|
+
return u == null && (u = ae(n)), [u.map(d).join(r)].concat(a(n, u)).join(`
|
|
1381
|
+
`);
|
|
1382
|
+
}
|
|
1383
|
+
function f(n, u) {
|
|
1384
|
+
return u == null && (u = ae(n)), a(n, u).join(`
|
|
1385
|
+
`);
|
|
1386
|
+
}
|
|
1387
|
+
function m(n) {
|
|
1388
|
+
return n.map(o).join(`
|
|
1389
|
+
`);
|
|
1390
|
+
}
|
|
1391
|
+
function o(n) {
|
|
1392
|
+
return n.map(d).join(r);
|
|
1393
|
+
}
|
|
1394
|
+
function d(n) {
|
|
1395
|
+
return n == null ? "" : n instanceof Date ? kt(n) : e.test(n += "") ? '"' + n.replace(/"/g, '""') + '"' : n;
|
|
1396
|
+
}
|
|
1397
|
+
return {
|
|
1398
|
+
parse: s,
|
|
1399
|
+
parseRows: i,
|
|
1400
|
+
format: h,
|
|
1401
|
+
formatBody: f,
|
|
1402
|
+
formatRows: m,
|
|
1403
|
+
formatRow: o,
|
|
1404
|
+
formatValue: d
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
var Ft = vt(","), jt = Ft.formatRows;
|
|
1408
|
+
function oe(r, e = { csv: { useDisplayNames: !0 } }) {
|
|
1409
|
+
var f, m;
|
|
1410
|
+
const t = e.useDisplayNames || ((f = e.csv) == null ? void 0 : f.useDisplayNames), a = [(((m = r.schema) == null ? void 0 : m.fields) || []).map((o) => {
|
|
1411
|
+
var n;
|
|
1412
|
+
const d = (n = o.metadata) == null ? void 0 : n.displayName;
|
|
1413
|
+
return t && typeof d == "string" ? d : o.name;
|
|
1414
|
+
})];
|
|
1415
|
+
for (const o of ze(r)) {
|
|
1416
|
+
const d = [];
|
|
1417
|
+
for (let n = 0; n < de(r); ++n) {
|
|
1418
|
+
const u = o[n];
|
|
1419
|
+
d[n] = xt(u);
|
|
1420
|
+
}
|
|
1421
|
+
a.push(d);
|
|
1422
|
+
}
|
|
1423
|
+
const h = a.map((o) => o.map((d) => d === null ? "" : d));
|
|
1424
|
+
return jt(h);
|
|
1425
|
+
}
|
|
1426
|
+
const xt = (r) => r == null ? null : r instanceof Date ? r.toISOString() : typeof r == "object" ? JSON.stringify(r) : String(r), $t = {
|
|
1427
|
+
...Te,
|
|
1428
|
+
version: "latest",
|
|
1429
|
+
options: {
|
|
1430
|
+
csv: {
|
|
1431
|
+
useDisplayNames: !1
|
|
1432
|
+
}
|
|
1433
|
+
},
|
|
1434
|
+
text: !0,
|
|
1435
|
+
encode: async (r, e) => new TextEncoder().encode(oe(r, e)).buffer,
|
|
1436
|
+
encodeTextSync: (r, e) => oe(r, e)
|
|
1437
|
+
}, Pt = {
|
|
1438
|
+
...M,
|
|
1439
|
+
dataType: null,
|
|
1440
|
+
batchType: null,
|
|
1441
|
+
parse: async (r, e) => le(new TextDecoder().decode(r), e),
|
|
1442
|
+
parseText: (r, e) => le(r, e),
|
|
1443
|
+
parseInBatches: It
|
|
1444
|
+
};
|
|
1445
|
+
async function le(r, e) {
|
|
1446
|
+
const t = await M.parseText(r, e);
|
|
1447
|
+
return U(t, "arrow-table");
|
|
1448
|
+
}
|
|
1449
|
+
function It(r, e) {
|
|
1450
|
+
const t = M.parseInBatches(r, e);
|
|
1451
|
+
return at(t, "arrow-table");
|
|
1452
|
+
}
|
|
1453
|
+
export {
|
|
1454
|
+
Pt as CSVArrowLoader,
|
|
1455
|
+
M as CSVLoader,
|
|
1456
|
+
$t as CSVWriter
|
|
1457
|
+
};
|