@loaders.gl/json 4.0.0-beta.2 → 4.0.0-beta.3

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 (119) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +1603 -1561
  2. package/dist/{esm/geojson-loader.js → geojson-loader.js} +2 -2
  3. package/dist/geojson-loader.js.map +1 -0
  4. package/dist/geojson-worker.js +345 -179
  5. package/dist/{esm/geojson-writer.js → geojson-writer.js} +1 -1
  6. package/dist/geojson-writer.js.map +1 -0
  7. package/dist/index.cjs +1259 -0
  8. package/dist/index.js +9 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/{esm/json-loader.js → json-loader.js} +3 -3
  11. package/dist/json-loader.js.map +1 -0
  12. package/dist/{esm/json-writer.js → json-writer.js} +1 -1
  13. package/dist/json-writer.js.map +1 -0
  14. package/dist/{esm/lib → lib}/clarinet/clarinet.js +33 -34
  15. package/dist/lib/clarinet/clarinet.js.map +1 -0
  16. package/dist/{esm/lib → lib}/encoder-utils/encode-table-row.js +1 -1
  17. package/dist/lib/encoder-utils/encode-table-row.js.map +1 -0
  18. package/dist/lib/encoder-utils/encode-utils.js.map +1 -0
  19. package/dist/{esm/lib → lib}/encoder-utils/utf8-encoder.js +4 -5
  20. package/dist/lib/encoder-utils/utf8-encoder.js.map +1 -0
  21. package/dist/{esm/lib → lib}/encoders/geojson-encoder.js +3 -3
  22. package/dist/lib/encoders/geojson-encoder.js.map +1 -0
  23. package/dist/{esm/lib → lib}/encoders/json-encoder.js +1 -1
  24. package/dist/lib/encoders/json-encoder.js.map +1 -0
  25. package/dist/{esm/lib → lib}/json-parser/json-parser.js +8 -9
  26. package/dist/lib/json-parser/json-parser.js.map +1 -0
  27. package/dist/{esm/lib → lib}/json-parser/streaming-json-parser.js +6 -7
  28. package/dist/lib/json-parser/streaming-json-parser.js.map +1 -0
  29. package/dist/{esm/lib → lib}/jsonpath/jsonpath.js +1 -2
  30. package/dist/lib/jsonpath/jsonpath.js.map +1 -0
  31. package/dist/{esm/lib → lib}/parsers/parse-json-in-batches.js +2 -2
  32. package/dist/lib/parsers/parse-json-in-batches.js.map +1 -0
  33. package/dist/lib/parsers/parse-json.js.map +1 -0
  34. package/dist/{esm/lib → lib}/parsers/parse-ndjson-in-batches.js +1 -1
  35. package/dist/lib/parsers/parse-ndjson-in-batches.js.map +1 -0
  36. package/dist/{esm/lib → lib}/parsers/parse-ndjson.js +1 -1
  37. package/dist/lib/parsers/parse-ndjson.js.map +1 -0
  38. package/dist/{esm/ndgeoson-loader.js → ndgeoson-loader.js} +3 -3
  39. package/dist/ndgeoson-loader.js.map +1 -0
  40. package/dist/{esm/ndjson-loader.js → ndjson-loader.js} +3 -3
  41. package/dist/ndjson-loader.js.map +1 -0
  42. package/dist/{esm/workers → workers}/geojson-worker.js +1 -1
  43. package/dist/workers/geojson-worker.js.map +1 -0
  44. package/package.json +17 -9
  45. package/dist/bundle.d.ts +0 -2
  46. package/dist/bundle.d.ts.map +0 -1
  47. package/dist/es5/bundle.js +0 -6
  48. package/dist/es5/bundle.js.map +0 -1
  49. package/dist/es5/geojson-loader.js +0 -166
  50. package/dist/es5/geojson-loader.js.map +0 -1
  51. package/dist/es5/geojson-writer.js +0 -27
  52. package/dist/es5/geojson-writer.js.map +0 -1
  53. package/dist/es5/index.js +0 -69
  54. package/dist/es5/index.js.map +0 -1
  55. package/dist/es5/json-loader.js +0 -67
  56. package/dist/es5/json-loader.js.map +0 -1
  57. package/dist/es5/json-writer.js +0 -42
  58. package/dist/es5/json-writer.js.map +0 -1
  59. package/dist/es5/lib/clarinet/clarinet.js +0 -446
  60. package/dist/es5/lib/clarinet/clarinet.js.map +0 -1
  61. package/dist/es5/lib/encoder-utils/encode-table-row.js +0 -54
  62. package/dist/es5/lib/encoder-utils/encode-table-row.js.map +0 -1
  63. package/dist/es5/lib/encoder-utils/encode-utils.js +0 -42
  64. package/dist/es5/lib/encoder-utils/encode-utils.js.map +0 -1
  65. package/dist/es5/lib/encoder-utils/utf8-encoder.js +0 -54
  66. package/dist/es5/lib/encoder-utils/utf8-encoder.js.map +0 -1
  67. package/dist/es5/lib/encoders/geojson-encoder.js +0 -141
  68. package/dist/es5/lib/encoders/geojson-encoder.js.map +0 -1
  69. package/dist/es5/lib/encoders/json-encoder.js +0 -30
  70. package/dist/es5/lib/encoders/json-encoder.js.map +0 -1
  71. package/dist/es5/lib/json-parser/json-parser.js +0 -140
  72. package/dist/es5/lib/json-parser/json-parser.js.map +0 -1
  73. package/dist/es5/lib/json-parser/streaming-json-parser.js +0 -123
  74. package/dist/es5/lib/json-parser/streaming-json-parser.js.map +0 -1
  75. package/dist/es5/lib/jsonpath/jsonpath.js +0 -119
  76. package/dist/es5/lib/jsonpath/jsonpath.js.map +0 -1
  77. package/dist/es5/lib/parsers/parse-json-in-batches.js +0 -206
  78. package/dist/es5/lib/parsers/parse-json-in-batches.js.map +0 -1
  79. package/dist/es5/lib/parsers/parse-json.js +0 -38
  80. package/dist/es5/lib/parsers/parse-json.js.map +0 -1
  81. package/dist/es5/lib/parsers/parse-ndjson-in-batches.js +0 -114
  82. package/dist/es5/lib/parsers/parse-ndjson-in-batches.js.map +0 -1
  83. package/dist/es5/lib/parsers/parse-ndjson.js +0 -19
  84. package/dist/es5/lib/parsers/parse-ndjson.js.map +0 -1
  85. package/dist/es5/ndgeoson-loader.js +0 -51
  86. package/dist/es5/ndgeoson-loader.js.map +0 -1
  87. package/dist/es5/ndjson-loader.js +0 -44
  88. package/dist/es5/ndjson-loader.js.map +0 -1
  89. package/dist/es5/workers/geojson-worker.js +0 -6
  90. package/dist/es5/workers/geojson-worker.js.map +0 -1
  91. package/dist/esm/bundle.js +0 -4
  92. package/dist/esm/bundle.js.map +0 -1
  93. package/dist/esm/geojson-loader.js.map +0 -1
  94. package/dist/esm/geojson-writer.js.map +0 -1
  95. package/dist/esm/index.js +0 -9
  96. package/dist/esm/index.js.map +0 -1
  97. package/dist/esm/json-loader.js.map +0 -1
  98. package/dist/esm/json-writer.js.map +0 -1
  99. package/dist/esm/lib/clarinet/LICENSE +0 -28
  100. package/dist/esm/lib/clarinet/clarinet.js.map +0 -1
  101. package/dist/esm/lib/encoder-utils/encode-table-row.js.map +0 -1
  102. package/dist/esm/lib/encoder-utils/encode-utils.js.map +0 -1
  103. package/dist/esm/lib/encoder-utils/utf8-encoder.js.map +0 -1
  104. package/dist/esm/lib/encoders/geojson-encoder.js.map +0 -1
  105. package/dist/esm/lib/encoders/json-encoder.js.map +0 -1
  106. package/dist/esm/lib/json-parser/json-parser.js.map +0 -1
  107. package/dist/esm/lib/json-parser/streaming-json-parser.js.map +0 -1
  108. package/dist/esm/lib/jsonpath/jsonpath.js.map +0 -1
  109. package/dist/esm/lib/parsers/parse-json-in-batches.js.map +0 -1
  110. package/dist/esm/lib/parsers/parse-json.js.map +0 -1
  111. package/dist/esm/lib/parsers/parse-ndjson-in-batches.js.map +0 -1
  112. package/dist/esm/lib/parsers/parse-ndjson.js.map +0 -1
  113. package/dist/esm/ndgeoson-loader.js.map +0 -1
  114. package/dist/esm/ndjson-loader.js.map +0 -1
  115. package/dist/esm/workers/geojson-worker.js.map +0 -1
  116. package/src/bundle.ts +0 -4
  117. /package/dist/{es5/lib → lib}/clarinet/LICENSE +0 -0
  118. /package/dist/{esm/lib → lib}/encoder-utils/encode-utils.js +0 -0
  119. /package/dist/{esm/lib → lib}/parsers/parse-json.js +0 -0
@@ -1,77 +1,97 @@
1
- (() => {
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['loader'] = factory();
6
+ else root['loader'] = factory();})(globalThis, function () {
7
+ "use strict";
8
+ var __exports__ = (() => {
2
9
  var __defProp = Object.defineProperty;
3
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
- };
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
13
  var __export = (target, all) => {
11
- __markAsModule(target);
12
14
  for (var name in all)
13
15
  __defProp(target, name, { get: all[name], enumerable: true });
14
16
  };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+
27
+ // src/index.ts
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ JSONLoader: () => JSONLoader,
31
+ JSONWriter: () => JSONWriter,
32
+ NDJSONLoader: () => NDJSONLoader,
33
+ _ClarinetParser: () => ClarinetParser,
34
+ _GeoJSONLoader: () => GeoJSONLoader,
35
+ _GeoJSONWorkerLoader: () => GeoJSONWorkerLoader,
36
+ _GeoJSONWriter: () => GeoJSONWriter,
37
+ _JSONPath: () => JSONPath,
38
+ _rebuildJsonObject: () => rebuildJsonObject
39
+ });
15
40
 
16
41
  // ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
17
- var DEFAULT_ROW_COUNT, BaseTableBatchAggregator;
18
- var init_base_table_batch_aggregator = __esm({
19
- "../schema/src/lib/table/batches/base-table-batch-aggregator.ts"() {
20
- DEFAULT_ROW_COUNT = 100;
21
- BaseTableBatchAggregator = class {
22
- constructor(schema, options) {
23
- this.length = 0;
24
- this.rows = null;
25
- this.cursor = 0;
26
- this._headers = [];
27
- this.options = options;
28
- this.schema = schema;
29
- if (!Array.isArray(schema)) {
30
- this._headers = [];
31
- for (const key in schema) {
32
- this._headers[schema[key].index] = schema[key].name;
33
- }
34
- }
35
- }
36
- rowCount() {
37
- return this.length;
38
- }
39
- addArrayRow(row, cursor) {
40
- if (Number.isFinite(cursor)) {
41
- this.cursor = cursor;
42
- }
43
- this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
44
- this.rows[this.length] = row;
45
- this.length++;
46
- }
47
- addObjectRow(row, cursor) {
48
- if (Number.isFinite(cursor)) {
49
- this.cursor = cursor;
50
- }
51
- this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
52
- this.rows[this.length] = row;
53
- this.length++;
54
- }
55
- getBatch() {
56
- let rows = this.rows;
57
- if (!rows) {
58
- return null;
59
- }
60
- rows = rows.slice(0, this.length);
61
- this.rows = null;
62
- const batch = {
63
- shape: this.options.shape,
64
- batchType: "data",
65
- data: rows,
66
- length: this.length,
67
- schema: this.schema,
68
- cursor: this.cursor
69
- };
70
- return batch;
42
+ var DEFAULT_ROW_COUNT = 100;
43
+ var BaseTableBatchAggregator = class {
44
+ length = 0;
45
+ rows = null;
46
+ cursor = 0;
47
+ _headers = [];
48
+ constructor(schema, options) {
49
+ this.options = options;
50
+ this.schema = schema;
51
+ if (!Array.isArray(schema)) {
52
+ this._headers = [];
53
+ for (const key in schema) {
54
+ this._headers[schema[key].index] = schema[key].name;
71
55
  }
56
+ }
57
+ }
58
+ rowCount() {
59
+ return this.length;
60
+ }
61
+ addArrayRow(row, cursor) {
62
+ if (Number.isFinite(cursor)) {
63
+ this.cursor = cursor;
64
+ }
65
+ this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
66
+ this.rows[this.length] = row;
67
+ this.length++;
68
+ }
69
+ addObjectRow(row, cursor) {
70
+ if (Number.isFinite(cursor)) {
71
+ this.cursor = cursor;
72
+ }
73
+ this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
74
+ this.rows[this.length] = row;
75
+ this.length++;
76
+ }
77
+ getBatch() {
78
+ let rows = this.rows;
79
+ if (!rows) {
80
+ return null;
81
+ }
82
+ rows = rows.slice(0, this.length);
83
+ this.rows = null;
84
+ const batch = {
85
+ shape: this.options.shape,
86
+ batchType: "data",
87
+ data: rows,
88
+ length: this.length,
89
+ schema: this.schema,
90
+ cursor: this.cursor
72
91
  };
92
+ return batch;
73
93
  }
74
- });
94
+ };
75
95
 
76
96
  // ../schema/src/lib/table/simple-table/row-utils.ts
77
97
  function convertToObjectRow(arrayRow, headers) {
@@ -100,306 +120,295 @@
100
120
  }
101
121
  return arrayRow;
102
122
  }
103
- var init_row_utils = __esm({
104
- "../schema/src/lib/table/simple-table/row-utils.ts"() {
105
- }
106
- });
107
123
 
108
124
  // ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
109
- var DEFAULT_ROW_COUNT2, RowTableBatchAggregator;
110
- var init_row_table_batch_aggregator = __esm({
111
- "../schema/src/lib/table/batches/row-table-batch-aggregator.ts"() {
112
- init_row_utils();
113
- DEFAULT_ROW_COUNT2 = 100;
114
- RowTableBatchAggregator = class {
115
- constructor(schema, options) {
116
- this.length = 0;
117
- this.objectRows = null;
118
- this.arrayRows = null;
119
- this.cursor = 0;
120
- this._headers = [];
121
- this.options = options;
122
- this.schema = schema;
123
- if (!Array.isArray(schema)) {
124
- this._headers = [];
125
- for (const key in schema) {
126
- this._headers[schema[key].index] = schema[key].name;
127
- }
128
- }
129
- }
130
- rowCount() {
131
- return this.length;
132
- }
133
- addArrayRow(row, cursor) {
134
- if (Number.isFinite(cursor)) {
135
- this.cursor = cursor;
136
- }
137
- switch (this.options.shape) {
138
- case "object-row-table":
139
- const rowObject = convertToObjectRow(row, this._headers);
140
- this.addObjectRow(rowObject, cursor);
141
- break;
142
- case "array-row-table":
143
- this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
144
- this.arrayRows[this.length] = row;
145
- this.length++;
146
- break;
147
- }
148
- }
149
- addObjectRow(row, cursor) {
150
- if (Number.isFinite(cursor)) {
151
- this.cursor = cursor;
152
- }
153
- switch (this.options.shape) {
154
- case "array-row-table":
155
- const rowArray = convertToArrayRow(row, this._headers);
156
- this.addArrayRow(rowArray, cursor);
157
- break;
158
- case "object-row-table":
159
- this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
160
- this.objectRows[this.length] = row;
161
- this.length++;
162
- break;
163
- }
164
- }
165
- getBatch() {
166
- let rows = this.arrayRows || this.objectRows;
167
- if (!rows) {
168
- return null;
169
- }
170
- rows = rows.slice(0, this.length);
171
- this.arrayRows = null;
172
- this.objectRows = null;
173
- return {
174
- shape: this.options.shape,
175
- batchType: "data",
176
- data: rows,
177
- length: this.length,
178
- schema: this.schema,
179
- cursor: this.cursor
180
- };
125
+ var DEFAULT_ROW_COUNT2 = 100;
126
+ var RowTableBatchAggregator = class {
127
+ length = 0;
128
+ objectRows = null;
129
+ arrayRows = null;
130
+ cursor = 0;
131
+ _headers = [];
132
+ constructor(schema, options) {
133
+ this.options = options;
134
+ this.schema = schema;
135
+ if (!Array.isArray(schema)) {
136
+ this._headers = [];
137
+ for (const key in schema) {
138
+ this._headers[schema[key].index] = schema[key].name;
181
139
  }
140
+ }
141
+ }
142
+ rowCount() {
143
+ return this.length;
144
+ }
145
+ addArrayRow(row, cursor) {
146
+ if (Number.isFinite(cursor)) {
147
+ this.cursor = cursor;
148
+ }
149
+ switch (this.options.shape) {
150
+ case "object-row-table":
151
+ const rowObject = convertToObjectRow(row, this._headers);
152
+ this.addObjectRow(rowObject, cursor);
153
+ break;
154
+ case "array-row-table":
155
+ this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
156
+ this.arrayRows[this.length] = row;
157
+ this.length++;
158
+ break;
159
+ }
160
+ }
161
+ addObjectRow(row, cursor) {
162
+ if (Number.isFinite(cursor)) {
163
+ this.cursor = cursor;
164
+ }
165
+ switch (this.options.shape) {
166
+ case "array-row-table":
167
+ const rowArray = convertToArrayRow(row, this._headers);
168
+ this.addArrayRow(rowArray, cursor);
169
+ break;
170
+ case "object-row-table":
171
+ this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
172
+ this.objectRows[this.length] = row;
173
+ this.length++;
174
+ break;
175
+ }
176
+ }
177
+ getBatch() {
178
+ let rows = this.arrayRows || this.objectRows;
179
+ if (!rows) {
180
+ return null;
181
+ }
182
+ rows = rows.slice(0, this.length);
183
+ this.arrayRows = null;
184
+ this.objectRows = null;
185
+ return {
186
+ shape: this.options.shape,
187
+ batchType: "data",
188
+ data: rows,
189
+ length: this.length,
190
+ schema: this.schema,
191
+ cursor: this.cursor
182
192
  };
183
193
  }
184
- });
194
+ };
185
195
 
186
196
  // ../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts
187
- var DEFAULT_ROW_COUNT3, ColumnarTableBatchAggregator;
188
- var init_columnar_table_batch_aggregator = __esm({
189
- "../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts"() {
190
- DEFAULT_ROW_COUNT3 = 100;
191
- ColumnarTableBatchAggregator = class {
192
- constructor(schema, options) {
193
- this.length = 0;
194
- this.allocated = 0;
195
- this.columns = {};
196
- this.schema = schema;
197
- this._reallocateColumns();
198
- }
199
- rowCount() {
200
- return this.length;
201
- }
202
- addArrayRow(row) {
203
- this._reallocateColumns();
204
- let i = 0;
205
- for (const fieldName in this.columns) {
206
- this.columns[fieldName][this.length] = row[i++];
207
- }
208
- this.length++;
209
- }
210
- addObjectRow(row) {
211
- this._reallocateColumns();
212
- for (const fieldName in row) {
213
- this.columns[fieldName][this.length] = row[fieldName];
214
- }
215
- this.length++;
216
- }
217
- getBatch() {
218
- this._pruneColumns();
219
- const columns = Array.isArray(this.schema) ? this.columns : {};
220
- if (!Array.isArray(this.schema)) {
221
- for (const fieldName in this.schema) {
222
- const field = this.schema[fieldName];
223
- columns[field.name] = this.columns[field.index];
224
- }
225
- }
226
- this.columns = {};
227
- const batch = {
228
- shape: "columnar-table",
229
- batchType: "data",
230
- data: columns,
231
- schema: this.schema,
232
- length: this.length
233
- };
234
- return batch;
235
- }
236
- _reallocateColumns() {
237
- if (this.length < this.allocated) {
238
- return;
239
- }
240
- this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
241
- this.columns = {};
242
- for (const fieldName in this.schema) {
243
- const field = this.schema[fieldName];
244
- const ArrayType = field.type || Float32Array;
245
- const oldColumn = this.columns[field.index];
246
- if (oldColumn && ArrayBuffer.isView(oldColumn)) {
247
- const typedArray = new ArrayType(this.allocated);
248
- typedArray.set(oldColumn);
249
- this.columns[field.index] = typedArray;
250
- } else if (oldColumn) {
251
- oldColumn.length = this.allocated;
252
- this.columns[field.index] = oldColumn;
253
- } else {
254
- this.columns[field.index] = new ArrayType(this.allocated);
255
- }
256
- }
257
- }
258
- _pruneColumns() {
259
- for (const [columnName, column] of Object.entries(this.columns)) {
260
- this.columns[columnName] = column.slice(0, this.length);
261
- }
197
+ var DEFAULT_ROW_COUNT3 = 100;
198
+ var ColumnarTableBatchAggregator = class {
199
+ length = 0;
200
+ allocated = 0;
201
+ columns = {};
202
+ constructor(schema, options) {
203
+ this.schema = schema;
204
+ this._reallocateColumns();
205
+ }
206
+ rowCount() {
207
+ return this.length;
208
+ }
209
+ addArrayRow(row) {
210
+ this._reallocateColumns();
211
+ let i = 0;
212
+ for (const fieldName in this.columns) {
213
+ this.columns[fieldName][this.length] = row[i++];
214
+ }
215
+ this.length++;
216
+ }
217
+ addObjectRow(row) {
218
+ this._reallocateColumns();
219
+ for (const fieldName in row) {
220
+ this.columns[fieldName][this.length] = row[fieldName];
221
+ }
222
+ this.length++;
223
+ }
224
+ getBatch() {
225
+ this._pruneColumns();
226
+ const columns = Array.isArray(this.schema) ? this.columns : {};
227
+ if (!Array.isArray(this.schema)) {
228
+ for (const fieldName in this.schema) {
229
+ const field = this.schema[fieldName];
230
+ columns[field.name] = this.columns[field.index];
262
231
  }
232
+ }
233
+ this.columns = {};
234
+ const batch = {
235
+ shape: "columnar-table",
236
+ batchType: "data",
237
+ data: columns,
238
+ schema: this.schema,
239
+ length: this.length
263
240
  };
241
+ return batch;
264
242
  }
265
- });
243
+ // HELPERS
244
+ _reallocateColumns() {
245
+ if (this.length < this.allocated) {
246
+ return;
247
+ }
248
+ this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
249
+ this.columns = {};
250
+ for (const fieldName in this.schema) {
251
+ const field = this.schema[fieldName];
252
+ const ArrayType = field.type || Float32Array;
253
+ const oldColumn = this.columns[field.index];
254
+ if (oldColumn && ArrayBuffer.isView(oldColumn)) {
255
+ const typedArray = new ArrayType(this.allocated);
256
+ typedArray.set(oldColumn);
257
+ this.columns[field.index] = typedArray;
258
+ } else if (oldColumn) {
259
+ oldColumn.length = this.allocated;
260
+ this.columns[field.index] = oldColumn;
261
+ } else {
262
+ this.columns[field.index] = new ArrayType(this.allocated);
263
+ }
264
+ }
265
+ }
266
+ _pruneColumns() {
267
+ for (const [columnName, column] of Object.entries(this.columns)) {
268
+ this.columns[columnName] = column.slice(0, this.length);
269
+ }
270
+ }
271
+ };
266
272
 
267
273
  // ../schema/src/lib/table/batches/table-batch-builder.ts
268
- var DEFAULT_OPTIONS, ERR_MESSAGE, TableBatchBuilder;
269
- var init_table_batch_builder = __esm({
270
- "../schema/src/lib/table/batches/table-batch-builder.ts"() {
271
- init_base_table_batch_aggregator();
272
- init_row_table_batch_aggregator();
273
- init_columnar_table_batch_aggregator();
274
- DEFAULT_OPTIONS = {
275
- shape: "array-row-table",
276
- batchSize: "auto",
277
- batchDebounceMs: 0,
278
- limit: 0,
279
- _limitMB: 0
274
+ var DEFAULT_OPTIONS = {
275
+ shape: "array-row-table",
276
+ batchSize: "auto",
277
+ batchDebounceMs: 0,
278
+ limit: 0,
279
+ _limitMB: 0
280
+ };
281
+ var ERR_MESSAGE = "TableBatchBuilder";
282
+ var TableBatchBuilder = class {
283
+ aggregator = null;
284
+ batchCount = 0;
285
+ bytesUsed = 0;
286
+ isChunkComplete = false;
287
+ lastBatchEmittedMs = Date.now();
288
+ totalLength = 0;
289
+ totalBytes = 0;
290
+ rowBytes = 0;
291
+ constructor(schema, options) {
292
+ this.schema = schema;
293
+ this.options = {
294
+ ...DEFAULT_OPTIONS,
295
+ ...options
280
296
  };
281
- ERR_MESSAGE = "TableBatchBuilder";
282
- TableBatchBuilder = class {
283
- constructor(schema, options) {
284
- this.aggregator = null;
285
- this.batchCount = 0;
286
- this.bytesUsed = 0;
287
- this.isChunkComplete = false;
288
- this.lastBatchEmittedMs = Date.now();
289
- this.totalLength = 0;
290
- this.totalBytes = 0;
291
- this.rowBytes = 0;
292
- this.schema = schema;
293
- this.options = { ...DEFAULT_OPTIONS, ...options };
294
- }
295
- limitReached() {
296
- if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
297
- return true;
298
- }
299
- if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
300
- return true;
301
- }
297
+ }
298
+ limitReached() {
299
+ if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
300
+ return true;
301
+ }
302
+ if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
303
+ return true;
304
+ }
305
+ return false;
306
+ }
307
+ /** @deprecated Use addArrayRow or addObjectRow */
308
+ addRow(row) {
309
+ if (this.limitReached()) {
310
+ return;
311
+ }
312
+ this.totalLength++;
313
+ this.rowBytes = this.rowBytes || this._estimateRowMB(row);
314
+ this.totalBytes += this.rowBytes;
315
+ if (Array.isArray(row)) {
316
+ this.addArrayRow(row);
317
+ } else {
318
+ this.addObjectRow(row);
319
+ }
320
+ }
321
+ /** Add one row to the batch */
322
+ addArrayRow(row) {
323
+ if (!this.aggregator) {
324
+ const TableBatchType = this._getTableBatchType();
325
+ this.aggregator = new TableBatchType(this.schema, this.options);
326
+ }
327
+ this.aggregator.addArrayRow(row);
328
+ }
329
+ /** Add one row to the batch */
330
+ addObjectRow(row) {
331
+ if (!this.aggregator) {
332
+ const TableBatchType = this._getTableBatchType();
333
+ this.aggregator = new TableBatchType(this.schema, this.options);
334
+ }
335
+ this.aggregator.addObjectRow(row);
336
+ }
337
+ /** Mark an incoming raw memory chunk has completed */
338
+ chunkComplete(chunk) {
339
+ if (chunk instanceof ArrayBuffer) {
340
+ this.bytesUsed += chunk.byteLength;
341
+ }
342
+ if (typeof chunk === "string") {
343
+ this.bytesUsed += chunk.length;
344
+ }
345
+ this.isChunkComplete = true;
346
+ }
347
+ getFullBatch(options) {
348
+ return this._isFull() ? this._getBatch(options) : null;
349
+ }
350
+ getFinalBatch(options) {
351
+ return this._getBatch(options);
352
+ }
353
+ // INTERNAL
354
+ _estimateRowMB(row) {
355
+ return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
356
+ }
357
+ _isFull() {
358
+ if (!this.aggregator || this.aggregator.rowCount() === 0) {
359
+ return false;
360
+ }
361
+ if (this.options.batchSize === "auto") {
362
+ if (!this.isChunkComplete) {
302
363
  return false;
303
364
  }
304
- addRow(row) {
305
- if (this.limitReached()) {
306
- return;
307
- }
308
- this.totalLength++;
309
- this.rowBytes = this.rowBytes || this._estimateRowMB(row);
310
- this.totalBytes += this.rowBytes;
311
- if (Array.isArray(row)) {
312
- this.addArrayRow(row);
313
- } else {
314
- this.addObjectRow(row);
315
- }
316
- }
317
- addArrayRow(row) {
318
- if (!this.aggregator) {
319
- const TableBatchType = this._getTableBatchType();
320
- this.aggregator = new TableBatchType(this.schema, this.options);
321
- }
322
- this.aggregator.addArrayRow(row);
323
- }
324
- addObjectRow(row) {
325
- if (!this.aggregator) {
326
- const TableBatchType = this._getTableBatchType();
327
- this.aggregator = new TableBatchType(this.schema, this.options);
328
- }
329
- this.aggregator.addObjectRow(row);
330
- }
331
- chunkComplete(chunk) {
332
- if (chunk instanceof ArrayBuffer) {
333
- this.bytesUsed += chunk.byteLength;
334
- }
335
- if (typeof chunk === "string") {
336
- this.bytesUsed += chunk.length;
337
- }
338
- this.isChunkComplete = true;
339
- }
340
- getFullBatch(options) {
341
- return this._isFull() ? this._getBatch(options) : null;
342
- }
343
- getFinalBatch(options) {
344
- return this._getBatch(options);
345
- }
346
- _estimateRowMB(row) {
347
- return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
348
- }
349
- _isFull() {
350
- if (!this.aggregator || this.aggregator.rowCount() === 0) {
351
- return false;
352
- }
353
- if (this.options.batchSize === "auto") {
354
- if (!this.isChunkComplete) {
355
- return false;
356
- }
357
- } else if (this.options.batchSize > this.aggregator.rowCount()) {
358
- return false;
359
- }
360
- if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
361
- return false;
362
- }
363
- this.isChunkComplete = false;
364
- this.lastBatchEmittedMs = Date.now();
365
- return true;
366
- }
367
- _getBatch(options) {
368
- if (!this.aggregator) {
369
- return null;
370
- }
371
- if (options?.bytesUsed) {
372
- this.bytesUsed = options.bytesUsed;
373
- }
374
- const normalizedBatch = this.aggregator.getBatch();
375
- normalizedBatch.count = this.batchCount;
376
- normalizedBatch.bytesUsed = this.bytesUsed;
377
- Object.assign(normalizedBatch, options);
378
- this.batchCount++;
379
- this.aggregator = null;
380
- return normalizedBatch;
381
- }
382
- _getTableBatchType() {
383
- switch (this.options.shape) {
384
- case "row-table":
385
- return BaseTableBatchAggregator;
386
- case "array-row-table":
387
- case "object-row-table":
388
- return RowTableBatchAggregator;
389
- case "columnar-table":
390
- return ColumnarTableBatchAggregator;
391
- case "arrow-table":
392
- if (!TableBatchBuilder.ArrowBatch) {
393
- throw new Error(ERR_MESSAGE);
394
- }
395
- return TableBatchBuilder.ArrowBatch;
396
- default:
397
- throw new Error(ERR_MESSAGE);
398
- }
399
- }
400
- };
365
+ } else if (this.options.batchSize > this.aggregator.rowCount()) {
366
+ return false;
367
+ }
368
+ if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
369
+ return false;
370
+ }
371
+ this.isChunkComplete = false;
372
+ this.lastBatchEmittedMs = Date.now();
373
+ return true;
401
374
  }
402
- });
375
+ /**
376
+ * bytesUsed can be set via chunkComplete or via getBatch*
377
+ */
378
+ _getBatch(options) {
379
+ if (!this.aggregator) {
380
+ return null;
381
+ }
382
+ if (options?.bytesUsed) {
383
+ this.bytesUsed = options.bytesUsed;
384
+ }
385
+ const normalizedBatch = this.aggregator.getBatch();
386
+ normalizedBatch.count = this.batchCount;
387
+ normalizedBatch.bytesUsed = this.bytesUsed;
388
+ Object.assign(normalizedBatch, options);
389
+ this.batchCount++;
390
+ this.aggregator = null;
391
+ return normalizedBatch;
392
+ }
393
+ _getTableBatchType() {
394
+ switch (this.options.shape) {
395
+ case "row-table":
396
+ return BaseTableBatchAggregator;
397
+ case "array-row-table":
398
+ case "object-row-table":
399
+ return RowTableBatchAggregator;
400
+ case "columnar-table":
401
+ return ColumnarTableBatchAggregator;
402
+ case "arrow-table":
403
+ if (!TableBatchBuilder.ArrowBatch) {
404
+ throw new Error(ERR_MESSAGE);
405
+ }
406
+ return TableBatchBuilder.ArrowBatch;
407
+ default:
408
+ throw new Error(ERR_MESSAGE);
409
+ }
410
+ }
411
+ };
403
412
 
404
413
  // ../schema/src/lib/table/simple-table/table-accessors.ts
405
414
  function getTableLength(table) {
@@ -568,10 +577,6 @@
568
577
  yield getTableRowAsObject(table, rowIndex, target);
569
578
  }
570
579
  }
571
- var init_table_accessors = __esm({
572
- "../schema/src/lib/table/simple-table/table-accessors.ts"() {
573
- }
574
- });
575
580
 
576
581
  // ../schema/src/lib/table/simple-table/data-type.ts
577
582
  function getDataTypeFromValue(value, defaultNumberType = "float32") {
@@ -592,13 +597,22 @@
592
597
  function getDataTypeFromArray(array) {
593
598
  let type = getDataTypeFromTypedArray(array);
594
599
  if (type !== "null") {
595
- return { type, nullable: false };
600
+ return {
601
+ type,
602
+ nullable: false
603
+ };
596
604
  }
597
605
  if (array.length > 0) {
598
606
  type = getDataTypeFromValue(array[0]);
599
- return { type, nullable: true };
607
+ return {
608
+ type,
609
+ nullable: true
610
+ };
600
611
  }
601
- return { type: "null", nullable: true };
612
+ return {
613
+ type: "null",
614
+ nullable: true
615
+ };
602
616
  }
603
617
  function getDataTypeFromTypedArray(array) {
604
618
  switch (array.constructor) {
@@ -623,10 +637,6 @@
623
637
  return "null";
624
638
  }
625
639
  }
626
- var init_data_type = __esm({
627
- "../schema/src/lib/table/simple-table/data-type.ts"() {
628
- }
629
- });
630
640
 
631
641
  // ../schema/src/lib/table/simple-table/table-schema.ts
632
642
  function deduceTableSchema(table) {
@@ -647,7 +657,10 @@
647
657
  const field = deduceFieldFromColumn(column, columnName);
648
658
  fields.push(field);
649
659
  }
650
- return { fields, metadata: {} };
660
+ return {
661
+ fields,
662
+ metadata: {}
663
+ };
651
664
  }
652
665
  function deduceSchemaFromRows(rowTable) {
653
666
  if (!rowTable.length) {
@@ -658,7 +671,10 @@
658
671
  for (const [columnName, value] of Object.entries(row0)) {
659
672
  fields.push(deduceFieldFromValue(value, columnName));
660
673
  }
661
- return { fields, metadata: {} };
674
+ return {
675
+ fields,
676
+ metadata: {}
677
+ };
662
678
  }
663
679
  function deduceFieldFromColumn(column, name) {
664
680
  if (ArrayBuffer.isView(column)) {
@@ -667,6 +683,7 @@
667
683
  name,
668
684
  type: type.type || "null",
669
685
  nullable: type.nullable
686
+ // metadata: {}
670
687
  };
671
688
  }
672
689
  if (Array.isArray(column) && column.length > 0) {
@@ -676,6 +693,7 @@
676
693
  name,
677
694
  type,
678
695
  nullable: true
696
+ // metadata: {},
679
697
  };
680
698
  }
681
699
  throw new Error("empty table");
@@ -686,32 +704,40 @@
686
704
  name,
687
705
  type,
688
706
  nullable: true
707
+ // metadata: {}
689
708
  };
690
709
  }
691
- var init_table_schema = __esm({
692
- "../schema/src/lib/table/simple-table/table-schema.ts"() {
693
- init_data_type();
694
- }
695
- });
696
710
 
697
711
  // ../schema/src/lib/table/simple-table/make-table.ts
698
712
  function makeTableFromData(data) {
699
713
  let table;
700
714
  switch (getTableShapeFromData(data)) {
701
715
  case "array-row-table":
702
- table = { shape: "array-row-table", data };
716
+ table = {
717
+ shape: "array-row-table",
718
+ data
719
+ };
703
720
  break;
704
721
  case "object-row-table":
705
- table = { shape: "object-row-table", data };
722
+ table = {
723
+ shape: "object-row-table",
724
+ data
725
+ };
706
726
  break;
707
727
  case "columnar-table":
708
- table = { shape: "columnar-table", data };
728
+ table = {
729
+ shape: "columnar-table",
730
+ data
731
+ };
709
732
  break;
710
733
  default:
711
734
  throw new Error("table");
712
735
  }
713
736
  const schema = deduceTableSchema(table);
714
- return { ...table, schema };
737
+ return {
738
+ ...table,
739
+ schema
740
+ };
715
741
  }
716
742
  function getTableShapeFromData(data) {
717
743
  if (Array.isArray(data)) {
@@ -731,20 +757,6 @@
731
757
  }
732
758
  throw new Error("invalid table");
733
759
  }
734
- var init_make_table = __esm({
735
- "../schema/src/lib/table/simple-table/make-table.ts"() {
736
- init_table_schema();
737
- }
738
- });
739
-
740
- // ../schema/src/index.ts
741
- var init_src = __esm({
742
- "../schema/src/index.ts"() {
743
- init_table_batch_builder();
744
- init_table_accessors();
745
- init_make_table();
746
- }
747
- });
748
760
 
749
761
  // src/lib/parsers/parse-json.ts
750
762
  function parseJSONSync(jsonText, options) {
@@ -773,11 +785,6 @@
773
785
  }
774
786
  return null;
775
787
  }
776
- var init_parse_json = __esm({
777
- "src/lib/parsers/parse-json.ts"() {
778
- init_src();
779
- }
780
- });
781
788
 
782
789
  // ../loader-utils/src/lib/env-utils/assert.ts
783
790
  function assert(condition, message) {
@@ -785,16 +792,14 @@
785
792
  throw new Error(message || "loader assertion failed.");
786
793
  }
787
794
  }
788
- var init_assert = __esm({
789
- "../loader-utils/src/lib/env-utils/assert.ts"() {
790
- }
791
- });
792
795
 
793
796
  // ../loader-utils/src/lib/iterators/text-iterators.ts
794
797
  async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
795
798
  const textDecoder = new TextDecoder(void 0, options);
796
799
  for await (const arrayBuffer of arrayBufferIterator) {
797
- yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
800
+ yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, {
801
+ stream: true
802
+ });
798
803
  }
799
804
  }
800
805
  async function* makeLineIterator(textIterator) {
@@ -815,791 +820,863 @@
815
820
  async function* makeNumberedLineIterator(lineIterator) {
816
821
  let counter = 1;
817
822
  for await (const line of lineIterator) {
818
- yield { counter, line };
823
+ yield {
824
+ counter,
825
+ line
826
+ };
819
827
  counter++;
820
828
  }
821
829
  }
822
- var init_text_iterators = __esm({
823
- "../loader-utils/src/lib/iterators/text-iterators.ts"() {
824
- }
825
- });
826
830
 
827
831
  // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
828
- var init_typeof = __esm({
829
- "../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
830
- }
831
- });
832
+ function _typeof(obj) {
833
+ "@babel/helpers - typeof";
834
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
835
+ return typeof obj2;
836
+ } : function(obj2) {
837
+ return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
838
+ }, _typeof(obj);
839
+ }
832
840
 
833
841
  // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
834
- var init_toPrimitive = __esm({
835
- "../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() {
836
- init_typeof();
837
- }
838
- });
842
+ function _toPrimitive(input, hint) {
843
+ if (_typeof(input) !== "object" || input === null)
844
+ return input;
845
+ var prim = input[Symbol.toPrimitive];
846
+ if (prim !== void 0) {
847
+ var res = prim.call(input, hint || "default");
848
+ if (_typeof(res) !== "object")
849
+ return res;
850
+ throw new TypeError("@@toPrimitive must return a primitive value.");
851
+ }
852
+ return (hint === "string" ? String : Number)(input);
853
+ }
839
854
 
840
855
  // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
841
- var init_toPropertyKey = __esm({
842
- "../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() {
843
- init_typeof();
844
- init_toPrimitive();
845
- }
846
- });
856
+ function _toPropertyKey(arg) {
857
+ var key = _toPrimitive(arg, "string");
858
+ return _typeof(key) === "symbol" ? key : String(key);
859
+ }
847
860
 
848
861
  // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
849
- var init_defineProperty = __esm({
850
- "../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
851
- init_toPropertyKey();
852
- }
853
- });
854
-
855
- // ../loader-utils/src/index.ts
856
- var init_src2 = __esm({
857
- "../loader-utils/src/index.ts"() {
858
- init_assert();
859
- init_text_iterators();
862
+ function _defineProperty(obj, key, value) {
863
+ key = _toPropertyKey(key);
864
+ if (key in obj) {
865
+ Object.defineProperty(obj, key, {
866
+ value,
867
+ enumerable: true,
868
+ configurable: true,
869
+ writable: true
870
+ });
871
+ } else {
872
+ obj[key] = value;
860
873
  }
861
- });
874
+ return obj;
875
+ }
862
876
 
863
877
  // src/lib/clarinet/clarinet.ts
864
- function isWhitespace(c) {
865
- return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
866
- }
867
- function checkBufferLength(parser) {
868
- const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
869
- let maxActual = 0;
870
- for (const buffer of ["textNode", "numberNode"]) {
871
- const len = parser[buffer] === void 0 ? 0 : parser[buffer].length;
872
- if (len > maxAllowed) {
873
- switch (buffer) {
874
- case "text":
875
- break;
876
- default:
877
- parser._error(`Max buffer length exceeded: ${buffer}`);
878
- }
879
- }
880
- maxActual = Math.max(maxActual, len);
878
+ var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
879
+ var STATE = /* @__PURE__ */ function(STATE2) {
880
+ STATE2[STATE2["BEGIN"] = 0] = "BEGIN";
881
+ STATE2[STATE2["VALUE"] = 1] = "VALUE";
882
+ STATE2[STATE2["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
883
+ STATE2[STATE2["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
884
+ STATE2[STATE2["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
885
+ STATE2[STATE2["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
886
+ STATE2[STATE2["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
887
+ STATE2[STATE2["STRING"] = 7] = "STRING";
888
+ STATE2[STATE2["BACKSLASH"] = 8] = "BACKSLASH";
889
+ STATE2[STATE2["END"] = 9] = "END";
890
+ STATE2[STATE2["OPEN_KEY"] = 10] = "OPEN_KEY";
891
+ STATE2[STATE2["CLOSE_KEY"] = 11] = "CLOSE_KEY";
892
+ STATE2[STATE2["TRUE"] = 12] = "TRUE";
893
+ STATE2[STATE2["TRUE2"] = 13] = "TRUE2";
894
+ STATE2[STATE2["TRUE3"] = 14] = "TRUE3";
895
+ STATE2[STATE2["FALSE"] = 15] = "FALSE";
896
+ STATE2[STATE2["FALSE2"] = 16] = "FALSE2";
897
+ STATE2[STATE2["FALSE3"] = 17] = "FALSE3";
898
+ STATE2[STATE2["FALSE4"] = 18] = "FALSE4";
899
+ STATE2[STATE2["NULL"] = 19] = "NULL";
900
+ STATE2[STATE2["NULL2"] = 20] = "NULL2";
901
+ STATE2[STATE2["NULL3"] = 21] = "NULL3";
902
+ STATE2[STATE2["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
903
+ STATE2[STATE2["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
904
+ return STATE2;
905
+ }(STATE || {});
906
+ var Char = {
907
+ tab: 9,
908
+ // \t
909
+ lineFeed: 10,
910
+ // \n
911
+ carriageReturn: 13,
912
+ // \r
913
+ space: 32,
914
+ // " "
915
+ doubleQuote: 34,
916
+ // "
917
+ plus: 43,
918
+ // +
919
+ comma: 44,
920
+ // ,
921
+ minus: 45,
922
+ // -
923
+ period: 46,
924
+ // .
925
+ _0: 48,
926
+ // 0
927
+ _9: 57,
928
+ // 9
929
+ colon: 58,
930
+ // :
931
+ E: 69,
932
+ // E
933
+ openBracket: 91,
934
+ // [
935
+ backslash: 92,
936
+ // \
937
+ closeBracket: 93,
938
+ // ]
939
+ a: 97,
940
+ // a
941
+ b: 98,
942
+ // b
943
+ e: 101,
944
+ // e
945
+ f: 102,
946
+ // f
947
+ l: 108,
948
+ // l
949
+ n: 110,
950
+ // n
951
+ r: 114,
952
+ // r
953
+ s: 115,
954
+ // s
955
+ t: 116,
956
+ // t
957
+ u: 117,
958
+ // u
959
+ openBrace: 123,
960
+ // {
961
+ closeBrace: 125
962
+ // }
963
+ };
964
+ var stringTokenPattern = /[\\"\n]/g;
965
+ var DEFAULT_OPTIONS2 = {
966
+ onready: () => {
967
+ },
968
+ onopenobject: () => {
969
+ },
970
+ onkey: () => {
971
+ },
972
+ oncloseobject: () => {
973
+ },
974
+ onopenarray: () => {
975
+ },
976
+ onclosearray: () => {
977
+ },
978
+ onvalue: () => {
979
+ },
980
+ onerror: () => {
981
+ },
982
+ onend: () => {
983
+ },
984
+ onchunkparsed: () => {
881
985
  }
882
- parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;
883
- }
884
- var MAX_BUFFER_LENGTH, STATE, Char, stringTokenPattern, DEFAULT_OPTIONS2, ClarinetParser;
885
- var init_clarinet = __esm({
886
- "src/lib/clarinet/clarinet.ts"() {
887
- MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
888
- (function(STATE2) {
889
- STATE2[STATE2["BEGIN"] = 0] = "BEGIN";
890
- STATE2[STATE2["VALUE"] = 1] = "VALUE";
891
- STATE2[STATE2["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
892
- STATE2[STATE2["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
893
- STATE2[STATE2["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
894
- STATE2[STATE2["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
895
- STATE2[STATE2["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
896
- STATE2[STATE2["STRING"] = 7] = "STRING";
897
- STATE2[STATE2["BACKSLASH"] = 8] = "BACKSLASH";
898
- STATE2[STATE2["END"] = 9] = "END";
899
- STATE2[STATE2["OPEN_KEY"] = 10] = "OPEN_KEY";
900
- STATE2[STATE2["CLOSE_KEY"] = 11] = "CLOSE_KEY";
901
- STATE2[STATE2["TRUE"] = 12] = "TRUE";
902
- STATE2[STATE2["TRUE2"] = 13] = "TRUE2";
903
- STATE2[STATE2["TRUE3"] = 14] = "TRUE3";
904
- STATE2[STATE2["FALSE"] = 15] = "FALSE";
905
- STATE2[STATE2["FALSE2"] = 16] = "FALSE2";
906
- STATE2[STATE2["FALSE3"] = 17] = "FALSE3";
907
- STATE2[STATE2["FALSE4"] = 18] = "FALSE4";
908
- STATE2[STATE2["NULL"] = 19] = "NULL";
909
- STATE2[STATE2["NULL2"] = 20] = "NULL2";
910
- STATE2[STATE2["NULL3"] = 21] = "NULL3";
911
- STATE2[STATE2["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
912
- STATE2[STATE2["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
913
- })(STATE || (STATE = {}));
914
- Char = {
915
- tab: 9,
916
- lineFeed: 10,
917
- carriageReturn: 13,
918
- space: 32,
919
- doubleQuote: 34,
920
- plus: 43,
921
- comma: 44,
922
- minus: 45,
923
- period: 46,
924
- _0: 48,
925
- _9: 57,
926
- colon: 58,
927
- E: 69,
928
- openBracket: 91,
929
- backslash: 92,
930
- closeBracket: 93,
931
- a: 97,
932
- b: 98,
933
- e: 101,
934
- f: 102,
935
- l: 108,
936
- n: 110,
937
- r: 114,
938
- s: 115,
939
- t: 116,
940
- u: 117,
941
- openBrace: 123,
942
- closeBrace: 125
986
+ };
987
+ var ClarinetParser = class {
988
+ options = DEFAULT_OPTIONS2;
989
+ bufferCheckPosition = MAX_BUFFER_LENGTH;
990
+ q = "";
991
+ c = "";
992
+ p = "";
993
+ closed = false;
994
+ closedRoot = false;
995
+ sawRoot = false;
996
+ // tag = null;
997
+ error = null;
998
+ state = STATE.BEGIN;
999
+ stack = [];
1000
+ // mostly just for error reporting
1001
+ position = 0;
1002
+ column = 0;
1003
+ line = 1;
1004
+ slashed = false;
1005
+ unicodeI = 0;
1006
+ unicodeS = null;
1007
+ depth = 0;
1008
+ constructor(options = {}) {
1009
+ this.options = {
1010
+ ...DEFAULT_OPTIONS2,
1011
+ ...options
943
1012
  };
944
- stringTokenPattern = /[\\"\n]/g;
945
- DEFAULT_OPTIONS2 = {
946
- onready: () => {
947
- },
948
- onopenobject: () => {
949
- },
950
- onkey: () => {
951
- },
952
- oncloseobject: () => {
953
- },
954
- onopenarray: () => {
955
- },
956
- onclosearray: () => {
957
- },
958
- onvalue: () => {
959
- },
960
- onerror: () => {
961
- },
962
- onend: () => {
963
- },
964
- onchunkparsed: () => {
1013
+ this.textNode = void 0;
1014
+ this.numberNode = "";
1015
+ this.emit("onready");
1016
+ }
1017
+ end() {
1018
+ if (this.state !== STATE.VALUE || this.depth !== 0)
1019
+ this._error("Unexpected end");
1020
+ this._closeValue();
1021
+ this.c = "";
1022
+ this.closed = true;
1023
+ this.emit("onend");
1024
+ return this;
1025
+ }
1026
+ resume() {
1027
+ this.error = null;
1028
+ return this;
1029
+ }
1030
+ close() {
1031
+ return this.write(null);
1032
+ }
1033
+ // protected
1034
+ emit(event, data) {
1035
+ this.options[event]?.(data, this);
1036
+ }
1037
+ emitNode(event, data) {
1038
+ this._closeValue();
1039
+ this.emit(event, data);
1040
+ }
1041
+ /* eslint-disable no-continue */
1042
+ // eslint-disable-next-line complexity, max-statements
1043
+ write(chunk) {
1044
+ if (this.error) {
1045
+ throw this.error;
1046
+ }
1047
+ if (this.closed) {
1048
+ return this._error("Cannot write after close. Assign an onready handler.");
1049
+ }
1050
+ if (chunk === null) {
1051
+ return this.end();
1052
+ }
1053
+ let i = 0;
1054
+ let c = chunk.charCodeAt(0);
1055
+ let p = this.p;
1056
+ while (c) {
1057
+ p = c;
1058
+ this.c = c = chunk.charCodeAt(i++);
1059
+ if (p !== c) {
1060
+ this.p = p;
1061
+ } else {
1062
+ p = this.p;
965
1063
  }
966
- };
967
- ClarinetParser = class {
968
- constructor(options = {}) {
969
- this.options = DEFAULT_OPTIONS2;
970
- this.bufferCheckPosition = MAX_BUFFER_LENGTH;
971
- this.q = "";
972
- this.c = "";
973
- this.p = "";
974
- this.closed = false;
975
- this.closedRoot = false;
976
- this.sawRoot = false;
977
- this.error = null;
978
- this.state = 0;
979
- this.stack = [];
980
- this.position = 0;
1064
+ if (!c)
1065
+ break;
1066
+ this.position++;
1067
+ if (c === Char.lineFeed) {
1068
+ this.line++;
981
1069
  this.column = 0;
982
- this.line = 1;
983
- this.slashed = false;
984
- this.unicodeI = 0;
985
- this.unicodeS = null;
986
- this.depth = 0;
987
- this.options = { ...DEFAULT_OPTIONS2, ...options };
988
- this.textNode = void 0;
989
- this.numberNode = "";
990
- this.emit("onready");
991
- }
992
- end() {
993
- if (this.state !== 1 || this.depth !== 0)
994
- this._error("Unexpected end");
995
- this._closeValue();
996
- this.c = "";
997
- this.closed = true;
998
- this.emit("onend");
999
- return this;
1000
- }
1001
- resume() {
1002
- this.error = null;
1003
- return this;
1004
- }
1005
- close() {
1006
- return this.write(null);
1007
- }
1008
- emit(event, data) {
1009
- this.options[event]?.(data, this);
1010
- }
1011
- emitNode(event, data) {
1012
- this._closeValue();
1013
- this.emit(event, data);
1014
- }
1015
- write(chunk) {
1016
- if (this.error) {
1017
- throw this.error;
1018
- }
1019
- if (this.closed) {
1020
- return this._error("Cannot write after close. Assign an onready handler.");
1021
- }
1022
- if (chunk === null) {
1023
- return this.end();
1024
- }
1025
- let i = 0;
1026
- let c = chunk.charCodeAt(0);
1027
- let p = this.p;
1028
- while (c) {
1029
- p = c;
1030
- this.c = c = chunk.charCodeAt(i++);
1031
- if (p !== c) {
1032
- this.p = p;
1033
- } else {
1034
- p = this.p;
1070
+ } else
1071
+ this.column++;
1072
+ switch (this.state) {
1073
+ case STATE.BEGIN:
1074
+ if (c === Char.openBrace)
1075
+ this.state = STATE.OPEN_OBJECT;
1076
+ else if (c === Char.openBracket)
1077
+ this.state = STATE.OPEN_ARRAY;
1078
+ else if (!isWhitespace(c)) {
1079
+ this._error("Non-whitespace before {[.");
1035
1080
  }
1036
- if (!c)
1037
- break;
1038
- this.position++;
1039
- if (c === Char.lineFeed) {
1040
- this.line++;
1041
- this.column = 0;
1081
+ continue;
1082
+ case STATE.OPEN_KEY:
1083
+ case STATE.OPEN_OBJECT:
1084
+ if (isWhitespace(c))
1085
+ continue;
1086
+ if (this.state === STATE.OPEN_KEY)
1087
+ this.stack.push(STATE.CLOSE_KEY);
1088
+ else if (c === Char.closeBrace) {
1089
+ this.emit("onopenobject");
1090
+ this.depth++;
1091
+ this.emit("oncloseobject");
1092
+ this.depth--;
1093
+ this.state = this.stack.pop() || STATE.VALUE;
1094
+ continue;
1042
1095
  } else
1043
- this.column++;
1044
- switch (this.state) {
1045
- case 0:
1046
- if (c === Char.openBrace)
1047
- this.state = 2;
1048
- else if (c === Char.openBracket)
1049
- this.state = 4;
1050
- else if (!isWhitespace(c)) {
1051
- this._error("Non-whitespace before {[.");
1052
- }
1053
- continue;
1054
- case 10:
1055
- case 2:
1056
- if (isWhitespace(c))
1057
- continue;
1058
- if (this.state === 10)
1059
- this.stack.push(11);
1060
- else if (c === Char.closeBrace) {
1061
- this.emit("onopenobject");
1062
- this.depth++;
1063
- this.emit("oncloseobject");
1064
- this.depth--;
1065
- this.state = this.stack.pop() || 1;
1066
- continue;
1067
- } else
1068
- this.stack.push(3);
1069
- if (c === Char.doubleQuote)
1070
- this.state = 7;
1071
- else
1072
- this._error('Malformed object key should start with "');
1073
- continue;
1074
- case 11:
1075
- case 3:
1076
- if (isWhitespace(c))
1077
- continue;
1078
- if (c === Char.colon) {
1079
- if (this.state === 3) {
1080
- this.stack.push(3);
1081
- this._closeValue("onopenobject");
1082
- this.depth++;
1083
- } else
1084
- this._closeValue("onkey");
1085
- this.state = 1;
1086
- } else if (c === Char.closeBrace) {
1087
- this.emitNode("oncloseobject");
1088
- this.depth--;
1089
- this.state = this.stack.pop() || 1;
1090
- } else if (c === Char.comma) {
1091
- if (this.state === 3)
1092
- this.stack.push(3);
1093
- this._closeValue();
1094
- this.state = 10;
1095
- } else
1096
- this._error("Bad object");
1096
+ this.stack.push(STATE.CLOSE_OBJECT);
1097
+ if (c === Char.doubleQuote)
1098
+ this.state = STATE.STRING;
1099
+ else
1100
+ this._error('Malformed object key should start with "');
1101
+ continue;
1102
+ case STATE.CLOSE_KEY:
1103
+ case STATE.CLOSE_OBJECT:
1104
+ if (isWhitespace(c))
1105
+ continue;
1106
+ if (c === Char.colon) {
1107
+ if (this.state === STATE.CLOSE_OBJECT) {
1108
+ this.stack.push(STATE.CLOSE_OBJECT);
1109
+ this._closeValue("onopenobject");
1110
+ this.depth++;
1111
+ } else
1112
+ this._closeValue("onkey");
1113
+ this.state = STATE.VALUE;
1114
+ } else if (c === Char.closeBrace) {
1115
+ this.emitNode("oncloseobject");
1116
+ this.depth--;
1117
+ this.state = this.stack.pop() || STATE.VALUE;
1118
+ } else if (c === Char.comma) {
1119
+ if (this.state === STATE.CLOSE_OBJECT)
1120
+ this.stack.push(STATE.CLOSE_OBJECT);
1121
+ this._closeValue();
1122
+ this.state = STATE.OPEN_KEY;
1123
+ } else
1124
+ this._error("Bad object");
1125
+ continue;
1126
+ case STATE.OPEN_ARRAY:
1127
+ case STATE.VALUE:
1128
+ if (isWhitespace(c))
1129
+ continue;
1130
+ if (this.state === STATE.OPEN_ARRAY) {
1131
+ this.emit("onopenarray");
1132
+ this.depth++;
1133
+ this.state = STATE.VALUE;
1134
+ if (c === Char.closeBracket) {
1135
+ this.emit("onclosearray");
1136
+ this.depth--;
1137
+ this.state = this.stack.pop() || STATE.VALUE;
1097
1138
  continue;
1098
- case 4:
1099
- case 1:
1100
- if (isWhitespace(c))
1101
- continue;
1102
- if (this.state === 4) {
1103
- this.emit("onopenarray");
1104
- this.depth++;
1105
- this.state = 1;
1106
- if (c === Char.closeBracket) {
1107
- this.emit("onclosearray");
1108
- this.depth--;
1109
- this.state = this.stack.pop() || 1;
1110
- continue;
1139
+ } else {
1140
+ this.stack.push(STATE.CLOSE_ARRAY);
1141
+ }
1142
+ }
1143
+ if (c === Char.doubleQuote)
1144
+ this.state = STATE.STRING;
1145
+ else if (c === Char.openBrace)
1146
+ this.state = STATE.OPEN_OBJECT;
1147
+ else if (c === Char.openBracket)
1148
+ this.state = STATE.OPEN_ARRAY;
1149
+ else if (c === Char.t)
1150
+ this.state = STATE.TRUE;
1151
+ else if (c === Char.f)
1152
+ this.state = STATE.FALSE;
1153
+ else if (c === Char.n)
1154
+ this.state = STATE.NULL;
1155
+ else if (c === Char.minus) {
1156
+ this.numberNode += "-";
1157
+ } else if (Char._0 <= c && c <= Char._9) {
1158
+ this.numberNode += String.fromCharCode(c);
1159
+ this.state = STATE.NUMBER_DIGIT;
1160
+ } else
1161
+ this._error("Bad value");
1162
+ continue;
1163
+ case STATE.CLOSE_ARRAY:
1164
+ if (c === Char.comma) {
1165
+ this.stack.push(STATE.CLOSE_ARRAY);
1166
+ this._closeValue("onvalue");
1167
+ this.state = STATE.VALUE;
1168
+ } else if (c === Char.closeBracket) {
1169
+ this.emitNode("onclosearray");
1170
+ this.depth--;
1171
+ this.state = this.stack.pop() || STATE.VALUE;
1172
+ } else if (isWhitespace(c))
1173
+ continue;
1174
+ else
1175
+ this._error("Bad array");
1176
+ continue;
1177
+ case STATE.STRING:
1178
+ if (this.textNode === void 0) {
1179
+ this.textNode = "";
1180
+ }
1181
+ let starti = i - 1;
1182
+ let slashed = this.slashed;
1183
+ let unicodeI = this.unicodeI;
1184
+ STRING_BIGLOOP:
1185
+ while (true) {
1186
+ while (unicodeI > 0) {
1187
+ this.unicodeS += String.fromCharCode(c);
1188
+ c = chunk.charCodeAt(i++);
1189
+ this.position++;
1190
+ if (unicodeI === 4) {
1191
+ this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
1192
+ unicodeI = 0;
1193
+ starti = i - 1;
1111
1194
  } else {
1112
- this.stack.push(5);
1195
+ unicodeI++;
1113
1196
  }
1197
+ if (!c)
1198
+ break STRING_BIGLOOP;
1114
1199
  }
1115
- if (c === Char.doubleQuote)
1116
- this.state = 7;
1117
- else if (c === Char.openBrace)
1118
- this.state = 2;
1119
- else if (c === Char.openBracket)
1120
- this.state = 4;
1121
- else if (c === Char.t)
1122
- this.state = 12;
1123
- else if (c === Char.f)
1124
- this.state = 15;
1125
- else if (c === Char.n)
1126
- this.state = 19;
1127
- else if (c === Char.minus) {
1128
- this.numberNode += "-";
1129
- } else if (Char._0 <= c && c <= Char._9) {
1130
- this.numberNode += String.fromCharCode(c);
1131
- this.state = 23;
1132
- } else
1133
- this._error("Bad value");
1134
- continue;
1135
- case 5:
1136
- if (c === Char.comma) {
1137
- this.stack.push(5);
1138
- this._closeValue("onvalue");
1139
- this.state = 1;
1140
- } else if (c === Char.closeBracket) {
1141
- this.emitNode("onclosearray");
1142
- this.depth--;
1143
- this.state = this.stack.pop() || 1;
1144
- } else if (isWhitespace(c))
1145
- continue;
1146
- else
1147
- this._error("Bad array");
1148
- continue;
1149
- case 7:
1150
- if (this.textNode === void 0) {
1151
- this.textNode = "";
1200
+ if (c === Char.doubleQuote && !slashed) {
1201
+ this.state = this.stack.pop() || STATE.VALUE;
1202
+ this.textNode += chunk.substring(starti, i - 1);
1203
+ this.position += i - 1 - starti;
1204
+ break;
1152
1205
  }
1153
- let starti = i - 1;
1154
- let slashed = this.slashed;
1155
- let unicodeI = this.unicodeI;
1156
- STRING_BIGLOOP:
1157
- while (true) {
1158
- while (unicodeI > 0) {
1159
- this.unicodeS += String.fromCharCode(c);
1160
- c = chunk.charCodeAt(i++);
1161
- this.position++;
1162
- if (unicodeI === 4) {
1163
- this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
1164
- unicodeI = 0;
1165
- starti = i - 1;
1166
- } else {
1167
- unicodeI++;
1168
- }
1169
- if (!c)
1170
- break STRING_BIGLOOP;
1171
- }
1172
- if (c === Char.doubleQuote && !slashed) {
1173
- this.state = this.stack.pop() || 1;
1174
- this.textNode += chunk.substring(starti, i - 1);
1175
- this.position += i - 1 - starti;
1176
- break;
1177
- }
1178
- if (c === Char.backslash && !slashed) {
1179
- slashed = true;
1180
- this.textNode += chunk.substring(starti, i - 1);
1181
- this.position += i - 1 - starti;
1182
- c = chunk.charCodeAt(i++);
1183
- this.position++;
1184
- if (!c)
1185
- break;
1186
- }
1187
- if (slashed) {
1188
- slashed = false;
1189
- if (c === Char.n) {
1190
- this.textNode += "\n";
1191
- } else if (c === Char.r) {
1192
- this.textNode += "\r";
1193
- } else if (c === Char.t) {
1194
- this.textNode += " ";
1195
- } else if (c === Char.f) {
1196
- this.textNode += "\f";
1197
- } else if (c === Char.b) {
1198
- this.textNode += "\b";
1199
- } else if (c === Char.u) {
1200
- unicodeI = 1;
1201
- this.unicodeS = "";
1202
- } else {
1203
- this.textNode += String.fromCharCode(c);
1204
- }
1205
- c = chunk.charCodeAt(i++);
1206
- this.position++;
1207
- starti = i - 1;
1208
- if (!c)
1209
- break;
1210
- else
1211
- continue;
1212
- }
1213
- stringTokenPattern.lastIndex = i;
1214
- const reResult = stringTokenPattern.exec(chunk);
1215
- if (reResult === null) {
1216
- i = chunk.length + 1;
1217
- this.textNode += chunk.substring(starti, i - 1);
1218
- this.position += i - 1 - starti;
1219
- break;
1220
- }
1221
- i = reResult.index + 1;
1222
- c = chunk.charCodeAt(reResult.index);
1223
- if (!c) {
1224
- this.textNode += chunk.substring(starti, i - 1);
1225
- this.position += i - 1 - starti;
1226
- break;
1227
- }
1206
+ if (c === Char.backslash && !slashed) {
1207
+ slashed = true;
1208
+ this.textNode += chunk.substring(starti, i - 1);
1209
+ this.position += i - 1 - starti;
1210
+ c = chunk.charCodeAt(i++);
1211
+ this.position++;
1212
+ if (!c)
1213
+ break;
1214
+ }
1215
+ if (slashed) {
1216
+ slashed = false;
1217
+ if (c === Char.n) {
1218
+ this.textNode += "\n";
1219
+ } else if (c === Char.r) {
1220
+ this.textNode += "\r";
1221
+ } else if (c === Char.t) {
1222
+ this.textNode += " ";
1223
+ } else if (c === Char.f) {
1224
+ this.textNode += "\f";
1225
+ } else if (c === Char.b) {
1226
+ this.textNode += "\b";
1227
+ } else if (c === Char.u) {
1228
+ unicodeI = 1;
1229
+ this.unicodeS = "";
1230
+ } else {
1231
+ this.textNode += String.fromCharCode(c);
1228
1232
  }
1229
- this.slashed = slashed;
1230
- this.unicodeI = unicodeI;
1231
- continue;
1232
- case 12:
1233
- if (c === Char.r)
1234
- this.state = 13;
1235
- else
1236
- this._error(`Invalid true started with t${c}`);
1237
- continue;
1238
- case 13:
1239
- if (c === Char.u)
1240
- this.state = 14;
1241
- else
1242
- this._error(`Invalid true started with tr${c}`);
1243
- continue;
1244
- case 14:
1245
- if (c === Char.e) {
1246
- this.emit("onvalue", true);
1247
- this.state = this.stack.pop() || 1;
1248
- } else
1249
- this._error(`Invalid true started with tru${c}`);
1250
- continue;
1251
- case 15:
1252
- if (c === Char.a)
1253
- this.state = 16;
1254
- else
1255
- this._error(`Invalid false started with f${c}`);
1256
- continue;
1257
- case 16:
1258
- if (c === Char.l)
1259
- this.state = 17;
1260
- else
1261
- this._error(`Invalid false started with fa${c}`);
1262
- continue;
1263
- case 17:
1264
- if (c === Char.s)
1265
- this.state = 18;
1266
- else
1267
- this._error(`Invalid false started with fal${c}`);
1268
- continue;
1269
- case 18:
1270
- if (c === Char.e) {
1271
- this.emit("onvalue", false);
1272
- this.state = this.stack.pop() || 1;
1273
- } else
1274
- this._error(`Invalid false started with fals${c}`);
1275
- continue;
1276
- case 19:
1277
- if (c === Char.u)
1278
- this.state = 20;
1279
- else
1280
- this._error(`Invalid null started with n${c}`);
1281
- continue;
1282
- case 20:
1283
- if (c === Char.l)
1284
- this.state = 21;
1285
- else
1286
- this._error(`Invalid null started with nu${c}`);
1287
- continue;
1288
- case 21:
1289
- if (c === Char.l) {
1290
- this.emit("onvalue", null);
1291
- this.state = this.stack.pop() || 1;
1292
- } else
1293
- this._error(`Invalid null started with nul${c}`);
1294
- continue;
1295
- case 22:
1296
- if (c === Char.period) {
1297
- this.numberNode += ".";
1298
- this.state = 23;
1299
- } else
1300
- this._error("Leading zero not followed by .");
1301
- continue;
1302
- case 23:
1303
- if (Char._0 <= c && c <= Char._9)
1304
- this.numberNode += String.fromCharCode(c);
1305
- else if (c === Char.period) {
1306
- if (this.numberNode.indexOf(".") !== -1)
1307
- this._error("Invalid number has two dots");
1308
- this.numberNode += ".";
1309
- } else if (c === Char.e || c === Char.E) {
1310
- if (this.numberNode.indexOf("e") !== -1 || this.numberNode.indexOf("E") !== -1)
1311
- this._error("Invalid number has two exponential");
1312
- this.numberNode += "e";
1313
- } else if (c === Char.plus || c === Char.minus) {
1314
- if (!(p === Char.e || p === Char.E))
1315
- this._error("Invalid symbol in number");
1316
- this.numberNode += String.fromCharCode(c);
1317
- } else {
1318
- this._closeNumber();
1319
- i--;
1320
- this.state = this.stack.pop() || 1;
1233
+ c = chunk.charCodeAt(i++);
1234
+ this.position++;
1235
+ starti = i - 1;
1236
+ if (!c)
1237
+ break;
1238
+ else
1239
+ continue;
1321
1240
  }
1322
- continue;
1323
- default:
1324
- this._error(`Unknown state: ${this.state}`);
1241
+ stringTokenPattern.lastIndex = i;
1242
+ const reResult = stringTokenPattern.exec(chunk);
1243
+ if (reResult === null) {
1244
+ i = chunk.length + 1;
1245
+ this.textNode += chunk.substring(starti, i - 1);
1246
+ this.position += i - 1 - starti;
1247
+ break;
1248
+ }
1249
+ i = reResult.index + 1;
1250
+ c = chunk.charCodeAt(reResult.index);
1251
+ if (!c) {
1252
+ this.textNode += chunk.substring(starti, i - 1);
1253
+ this.position += i - 1 - starti;
1254
+ break;
1255
+ }
1256
+ }
1257
+ this.slashed = slashed;
1258
+ this.unicodeI = unicodeI;
1259
+ continue;
1260
+ case STATE.TRUE:
1261
+ if (c === Char.r)
1262
+ this.state = STATE.TRUE2;
1263
+ else
1264
+ this._error(`Invalid true started with t${c}`);
1265
+ continue;
1266
+ case STATE.TRUE2:
1267
+ if (c === Char.u)
1268
+ this.state = STATE.TRUE3;
1269
+ else
1270
+ this._error(`Invalid true started with tr${c}`);
1271
+ continue;
1272
+ case STATE.TRUE3:
1273
+ if (c === Char.e) {
1274
+ this.emit("onvalue", true);
1275
+ this.state = this.stack.pop() || STATE.VALUE;
1276
+ } else
1277
+ this._error(`Invalid true started with tru${c}`);
1278
+ continue;
1279
+ case STATE.FALSE:
1280
+ if (c === Char.a)
1281
+ this.state = STATE.FALSE2;
1282
+ else
1283
+ this._error(`Invalid false started with f${c}`);
1284
+ continue;
1285
+ case STATE.FALSE2:
1286
+ if (c === Char.l)
1287
+ this.state = STATE.FALSE3;
1288
+ else
1289
+ this._error(`Invalid false started with fa${c}`);
1290
+ continue;
1291
+ case STATE.FALSE3:
1292
+ if (c === Char.s)
1293
+ this.state = STATE.FALSE4;
1294
+ else
1295
+ this._error(`Invalid false started with fal${c}`);
1296
+ continue;
1297
+ case STATE.FALSE4:
1298
+ if (c === Char.e) {
1299
+ this.emit("onvalue", false);
1300
+ this.state = this.stack.pop() || STATE.VALUE;
1301
+ } else
1302
+ this._error(`Invalid false started with fals${c}`);
1303
+ continue;
1304
+ case STATE.NULL:
1305
+ if (c === Char.u)
1306
+ this.state = STATE.NULL2;
1307
+ else
1308
+ this._error(`Invalid null started with n${c}`);
1309
+ continue;
1310
+ case STATE.NULL2:
1311
+ if (c === Char.l)
1312
+ this.state = STATE.NULL3;
1313
+ else
1314
+ this._error(`Invalid null started with nu${c}`);
1315
+ continue;
1316
+ case STATE.NULL3:
1317
+ if (c === Char.l) {
1318
+ this.emit("onvalue", null);
1319
+ this.state = this.stack.pop() || STATE.VALUE;
1320
+ } else
1321
+ this._error(`Invalid null started with nul${c}`);
1322
+ continue;
1323
+ case STATE.NUMBER_DECIMAL_POINT:
1324
+ if (c === Char.period) {
1325
+ this.numberNode += ".";
1326
+ this.state = STATE.NUMBER_DIGIT;
1327
+ } else
1328
+ this._error("Leading zero not followed by .");
1329
+ continue;
1330
+ case STATE.NUMBER_DIGIT:
1331
+ if (Char._0 <= c && c <= Char._9)
1332
+ this.numberNode += String.fromCharCode(c);
1333
+ else if (c === Char.period) {
1334
+ if (this.numberNode.indexOf(".") !== -1)
1335
+ this._error("Invalid number has two dots");
1336
+ this.numberNode += ".";
1337
+ } else if (c === Char.e || c === Char.E) {
1338
+ if (this.numberNode.indexOf("e") !== -1 || this.numberNode.indexOf("E") !== -1)
1339
+ this._error("Invalid number has two exponential");
1340
+ this.numberNode += "e";
1341
+ } else if (c === Char.plus || c === Char.minus) {
1342
+ if (!(p === Char.e || p === Char.E))
1343
+ this._error("Invalid symbol in number");
1344
+ this.numberNode += String.fromCharCode(c);
1345
+ } else {
1346
+ this._closeNumber();
1347
+ i--;
1348
+ this.state = this.stack.pop() || STATE.VALUE;
1325
1349
  }
1326
- }
1327
- if (this.position >= this.bufferCheckPosition) {
1328
- checkBufferLength(this);
1329
- }
1330
- this.emit("onchunkparsed");
1331
- return this;
1332
- }
1333
- _closeValue(event = "onvalue") {
1334
- if (this.textNode !== void 0) {
1335
- this.emit(event, this.textNode);
1336
- }
1337
- this.textNode = void 0;
1338
- }
1339
- _closeNumber() {
1340
- if (this.numberNode)
1341
- this.emit("onvalue", parseFloat(this.numberNode));
1342
- this.numberNode = "";
1350
+ continue;
1351
+ default:
1352
+ this._error(`Unknown state: ${this.state}`);
1343
1353
  }
1344
- _error(message = "") {
1345
- this._closeValue();
1346
- message += `
1354
+ }
1355
+ if (this.position >= this.bufferCheckPosition) {
1356
+ checkBufferLength(this);
1357
+ }
1358
+ this.emit("onchunkparsed");
1359
+ return this;
1360
+ }
1361
+ _closeValue(event = "onvalue") {
1362
+ if (this.textNode !== void 0) {
1363
+ this.emit(event, this.textNode);
1364
+ }
1365
+ this.textNode = void 0;
1366
+ }
1367
+ _closeNumber() {
1368
+ if (this.numberNode)
1369
+ this.emit("onvalue", parseFloat(this.numberNode));
1370
+ this.numberNode = "";
1371
+ }
1372
+ _error(message = "") {
1373
+ this._closeValue();
1374
+ message += `
1347
1375
  Line: ${this.line}
1348
1376
  Column: ${this.column}
1349
1377
  Char: ${this.c}`;
1350
- const error = new Error(message);
1351
- this.error = error;
1352
- this.emit("onerror", error);
1378
+ const error = new Error(message);
1379
+ this.error = error;
1380
+ this.emit("onerror", error);
1381
+ }
1382
+ };
1383
+ function isWhitespace(c) {
1384
+ return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
1385
+ }
1386
+ function checkBufferLength(parser) {
1387
+ const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
1388
+ let maxActual = 0;
1389
+ for (const buffer of ["textNode", "numberNode"]) {
1390
+ const len = parser[buffer] === void 0 ? 0 : parser[buffer].length;
1391
+ if (len > maxAllowed) {
1392
+ switch (buffer) {
1393
+ case "text":
1394
+ break;
1395
+ default:
1396
+ parser._error(`Max buffer length exceeded: ${buffer}`);
1353
1397
  }
1354
- };
1398
+ }
1399
+ maxActual = Math.max(maxActual, len);
1355
1400
  }
1356
- });
1401
+ parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;
1402
+ }
1357
1403
 
1358
- // src/lib/jsonpath/jsonpath.ts
1359
- var JSONPath;
1360
- var init_jsonpath = __esm({
1361
- "src/lib/jsonpath/jsonpath.ts"() {
1362
- JSONPath = class {
1363
- constructor(path = null) {
1364
- this.path = ["$"];
1365
- if (path instanceof JSONPath) {
1366
- this.path = [...path.path];
1367
- return;
1368
- }
1369
- if (Array.isArray(path)) {
1370
- this.path.push(...path);
1371
- return;
1372
- }
1373
- if (typeof path === "string") {
1374
- this.path = path.split(".");
1375
- if (this.path[0] !== "$") {
1376
- throw new Error("JSONPaths must start with $");
1377
- }
1378
- }
1379
- }
1380
- clone() {
1381
- return new JSONPath(this);
1382
- }
1383
- toString() {
1384
- return this.path.join(".");
1385
- }
1386
- push(name) {
1387
- this.path.push(name);
1388
- }
1389
- pop() {
1390
- return this.path.pop();
1391
- }
1392
- set(name) {
1393
- this.path[this.path.length - 1] = name;
1394
- }
1395
- equals(other) {
1396
- if (!this || !other || this.path.length !== other.path.length) {
1397
- return false;
1398
- }
1399
- for (let i = 0; i < this.path.length; ++i) {
1400
- if (this.path[i] !== other.path[i]) {
1401
- return false;
1402
- }
1403
- }
1404
- return true;
1405
- }
1406
- setFieldAtPath(object, value) {
1407
- const path = [...this.path];
1408
- path.shift();
1409
- const field = path.pop();
1410
- for (const component of path) {
1411
- object = object[component];
1412
- }
1413
- object[field] = value;
1404
+ // src/lib/jsonpath/jsonpath.ts
1405
+ var JSONPath = class {
1406
+ constructor(path = null) {
1407
+ this.path = ["$"];
1408
+ if (path instanceof JSONPath) {
1409
+ this.path = [...path.path];
1410
+ return;
1411
+ }
1412
+ if (Array.isArray(path)) {
1413
+ this.path.push(...path);
1414
+ return;
1415
+ }
1416
+ if (typeof path === "string") {
1417
+ this.path = path.split(".");
1418
+ if (this.path[0] !== "$") {
1419
+ throw new Error("JSONPaths must start with $");
1414
1420
  }
1415
- getFieldAtPath(object) {
1416
- const path = [...this.path];
1417
- path.shift();
1418
- const field = path.pop();
1419
- for (const component of path) {
1420
- object = object[component];
1421
- }
1422
- return object[field];
1421
+ }
1422
+ }
1423
+ clone() {
1424
+ return new JSONPath(this);
1425
+ }
1426
+ toString() {
1427
+ return this.path.join(".");
1428
+ }
1429
+ push(name) {
1430
+ this.path.push(name);
1431
+ }
1432
+ pop() {
1433
+ return this.path.pop();
1434
+ }
1435
+ set(name) {
1436
+ this.path[this.path.length - 1] = name;
1437
+ }
1438
+ equals(other) {
1439
+ if (!this || !other || this.path.length !== other.path.length) {
1440
+ return false;
1441
+ }
1442
+ for (let i = 0; i < this.path.length; ++i) {
1443
+ if (this.path[i] !== other.path[i]) {
1444
+ return false;
1423
1445
  }
1424
- };
1446
+ }
1447
+ return true;
1425
1448
  }
1426
- });
1449
+ /**
1450
+ * Sets the value pointed at by path
1451
+ * TODO - handle root path
1452
+ * @param object
1453
+ * @param value
1454
+ */
1455
+ setFieldAtPath(object, value) {
1456
+ const path = [...this.path];
1457
+ path.shift();
1458
+ const field = path.pop();
1459
+ for (const component of path) {
1460
+ object = object[component];
1461
+ }
1462
+ object[field] = value;
1463
+ }
1464
+ /**
1465
+ * Gets the value pointed at by path
1466
+ * TODO - handle root path
1467
+ * @param object
1468
+ */
1469
+ getFieldAtPath(object) {
1470
+ const path = [...this.path];
1471
+ path.shift();
1472
+ const field = path.pop();
1473
+ for (const component of path) {
1474
+ object = object[component];
1475
+ }
1476
+ return object[field];
1477
+ }
1478
+ };
1427
1479
 
1428
1480
  // src/lib/json-parser/json-parser.ts
1429
- var JSONParser;
1430
- var init_json_parser = __esm({
1431
- "src/lib/json-parser/json-parser.ts"() {
1432
- init_clarinet();
1433
- init_jsonpath();
1434
- JSONParser = class {
1435
- constructor(options) {
1436
- this.result = void 0;
1437
- this.previousStates = [];
1438
- this.currentState = Object.freeze({ container: [], key: null });
1439
- this.jsonpath = new JSONPath();
1440
- this.reset();
1441
- this.parser = new ClarinetParser({
1442
- onready: () => {
1443
- this.jsonpath = new JSONPath();
1444
- this.previousStates.length = 0;
1445
- this.currentState.container.length = 0;
1446
- },
1447
- onopenobject: (name) => {
1448
- this._openObject({});
1449
- if (typeof name !== "undefined") {
1450
- this.parser.emit("onkey", name);
1451
- }
1452
- },
1453
- onkey: (name) => {
1454
- this.jsonpath.set(name);
1455
- this.currentState.key = name;
1456
- },
1457
- oncloseobject: () => {
1458
- this._closeObject();
1459
- },
1460
- onopenarray: () => {
1461
- this._openArray();
1462
- },
1463
- onclosearray: () => {
1464
- this._closeArray();
1465
- },
1466
- onvalue: (value) => {
1467
- this._pushOrSet(value);
1468
- },
1469
- onerror: (error) => {
1470
- throw error;
1471
- },
1472
- onend: () => {
1473
- this.result = this.currentState.container.pop();
1474
- },
1475
- ...options
1476
- });
1477
- }
1478
- reset() {
1479
- this.result = void 0;
1480
- this.previousStates = [];
1481
- this.currentState = Object.freeze({ container: [], key: null });
1481
+ var JSONParser = class {
1482
+ result = void 0;
1483
+ previousStates = [];
1484
+ currentState = Object.freeze({
1485
+ container: [],
1486
+ key: null
1487
+ });
1488
+ jsonpath = new JSONPath();
1489
+ constructor(options) {
1490
+ this.reset();
1491
+ this.parser = new ClarinetParser({
1492
+ onready: () => {
1482
1493
  this.jsonpath = new JSONPath();
1483
- }
1484
- write(chunk) {
1485
- this.parser.write(chunk);
1486
- }
1487
- close() {
1488
- this.parser.close();
1489
- }
1490
- _pushOrSet(value) {
1491
- const { container, key } = this.currentState;
1492
- if (key !== null) {
1493
- container[key] = value;
1494
- this.currentState.key = null;
1495
- } else {
1496
- container.push(value);
1494
+ this.previousStates.length = 0;
1495
+ this.currentState.container.length = 0;
1496
+ },
1497
+ onopenobject: (name) => {
1498
+ this._openObject({});
1499
+ if (typeof name !== "undefined") {
1500
+ this.parser.emit("onkey", name);
1497
1501
  }
1498
- }
1499
- _openArray(newContainer = []) {
1500
- this.jsonpath.push(null);
1501
- this._pushOrSet(newContainer);
1502
- this.previousStates.push(this.currentState);
1503
- this.currentState = { container: newContainer, isArray: true, key: null };
1504
- }
1505
- _closeArray() {
1506
- this.jsonpath.pop();
1507
- this.currentState = this.previousStates.pop();
1508
- }
1509
- _openObject(newContainer = {}) {
1510
- this.jsonpath.push(null);
1511
- this._pushOrSet(newContainer);
1512
- this.previousStates.push(this.currentState);
1513
- this.currentState = { container: newContainer, isArray: false, key: null };
1514
- }
1515
- _closeObject() {
1516
- this.jsonpath.pop();
1517
- this.currentState = this.previousStates.pop();
1518
- }
1502
+ },
1503
+ onkey: (name) => {
1504
+ this.jsonpath.set(name);
1505
+ this.currentState.key = name;
1506
+ },
1507
+ oncloseobject: () => {
1508
+ this._closeObject();
1509
+ },
1510
+ onopenarray: () => {
1511
+ this._openArray();
1512
+ },
1513
+ onclosearray: () => {
1514
+ this._closeArray();
1515
+ },
1516
+ onvalue: (value) => {
1517
+ this._pushOrSet(value);
1518
+ },
1519
+ onerror: (error) => {
1520
+ throw error;
1521
+ },
1522
+ onend: () => {
1523
+ this.result = this.currentState.container.pop();
1524
+ },
1525
+ ...options
1526
+ });
1527
+ }
1528
+ reset() {
1529
+ this.result = void 0;
1530
+ this.previousStates = [];
1531
+ this.currentState = Object.freeze({
1532
+ container: [],
1533
+ key: null
1534
+ });
1535
+ this.jsonpath = new JSONPath();
1536
+ }
1537
+ write(chunk) {
1538
+ this.parser.write(chunk);
1539
+ }
1540
+ close() {
1541
+ this.parser.close();
1542
+ }
1543
+ // PRIVATE METHODS
1544
+ _pushOrSet(value) {
1545
+ const {
1546
+ container,
1547
+ key
1548
+ } = this.currentState;
1549
+ if (key !== null) {
1550
+ container[key] = value;
1551
+ this.currentState.key = null;
1552
+ } else {
1553
+ container.push(value);
1554
+ }
1555
+ }
1556
+ _openArray(newContainer = []) {
1557
+ this.jsonpath.push(null);
1558
+ this._pushOrSet(newContainer);
1559
+ this.previousStates.push(this.currentState);
1560
+ this.currentState = {
1561
+ container: newContainer,
1562
+ isArray: true,
1563
+ key: null
1519
1564
  };
1520
1565
  }
1521
- });
1566
+ _closeArray() {
1567
+ this.jsonpath.pop();
1568
+ this.currentState = this.previousStates.pop();
1569
+ }
1570
+ _openObject(newContainer = {}) {
1571
+ this.jsonpath.push(null);
1572
+ this._pushOrSet(newContainer);
1573
+ this.previousStates.push(this.currentState);
1574
+ this.currentState = {
1575
+ container: newContainer,
1576
+ isArray: false,
1577
+ key: null
1578
+ };
1579
+ }
1580
+ _closeObject() {
1581
+ this.jsonpath.pop();
1582
+ this.currentState = this.previousStates.pop();
1583
+ }
1584
+ };
1522
1585
 
1523
1586
  // src/lib/json-parser/streaming-json-parser.ts
1524
- var StreamingJSONParser;
1525
- var init_streaming_json_parser = __esm({
1526
- "src/lib/json-parser/streaming-json-parser.ts"() {
1527
- init_json_parser();
1528
- init_jsonpath();
1529
- StreamingJSONParser = class extends JSONParser {
1530
- constructor(options = {}) {
1531
- super({
1532
- onopenarray: () => {
1533
- if (!this.streamingArray) {
1534
- if (this._matchJSONPath()) {
1535
- this.streamingJsonPath = this.getJsonPath().clone();
1536
- this.streamingArray = [];
1537
- this._openArray(this.streamingArray);
1538
- return;
1539
- }
1540
- }
1541
- this._openArray();
1542
- },
1543
- onopenobject: (name) => {
1544
- if (!this.topLevelObject) {
1545
- this.topLevelObject = {};
1546
- this._openObject(this.topLevelObject);
1547
- } else {
1548
- this._openObject({});
1549
- }
1550
- if (typeof name !== "undefined") {
1551
- this.parser.emit("onkey", name);
1552
- }
1587
+ var StreamingJSONParser = class extends JSONParser {
1588
+ streamingJsonPath = null;
1589
+ streamingArray = null;
1590
+ topLevelObject = null;
1591
+ constructor(options = {}) {
1592
+ super({
1593
+ onopenarray: () => {
1594
+ if (!this.streamingArray) {
1595
+ if (this._matchJSONPath()) {
1596
+ this.streamingJsonPath = this.getJsonPath().clone();
1597
+ this.streamingArray = [];
1598
+ this._openArray(this.streamingArray);
1599
+ return;
1553
1600
  }
1554
- });
1555
- this.streamingJsonPath = null;
1556
- this.streamingArray = null;
1557
- this.topLevelObject = null;
1558
- const jsonpaths = options.jsonpaths || [];
1559
- this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
1560
- }
1561
- write(chunk) {
1562
- super.write(chunk);
1563
- let array = [];
1564
- if (this.streamingArray) {
1565
- array = [...this.streamingArray];
1566
- this.streamingArray.length = 0;
1567
1601
  }
1568
- return array;
1569
- }
1570
- getPartialResult() {
1571
- return this.topLevelObject;
1572
- }
1573
- getStreamingJsonPath() {
1574
- return this.streamingJsonPath;
1575
- }
1576
- getStreamingJsonPathAsString() {
1577
- return this.streamingJsonPath && this.streamingJsonPath.toString();
1578
- }
1579
- getJsonPath() {
1580
- return this.jsonpath;
1581
- }
1582
- _matchJSONPath() {
1583
- const currentPath = this.getJsonPath();
1584
- if (this.jsonPaths.length === 0) {
1585
- return true;
1602
+ this._openArray();
1603
+ },
1604
+ // Redefine onopenarray to inject value for top-level object
1605
+ onopenobject: (name) => {
1606
+ if (!this.topLevelObject) {
1607
+ this.topLevelObject = {};
1608
+ this._openObject(this.topLevelObject);
1609
+ } else {
1610
+ this._openObject({});
1586
1611
  }
1587
- for (const jsonPath of this.jsonPaths) {
1588
- if (jsonPath.equals(currentPath)) {
1589
- return true;
1590
- }
1612
+ if (typeof name !== "undefined") {
1613
+ this.parser.emit("onkey", name);
1591
1614
  }
1592
- return false;
1593
1615
  }
1594
- };
1616
+ });
1617
+ const jsonpaths = options.jsonpaths || [];
1618
+ this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
1619
+ }
1620
+ /**
1621
+ * write REDEFINITION
1622
+ * - super.write() chunk to parser
1623
+ * - get the contents (so far) of "topmost-level" array as batch of rows
1624
+ * - clear top-level array
1625
+ * - return the batch of rows\
1626
+ */
1627
+ write(chunk) {
1628
+ super.write(chunk);
1629
+ let array = [];
1630
+ if (this.streamingArray) {
1631
+ array = [...this.streamingArray];
1632
+ this.streamingArray.length = 0;
1633
+ }
1634
+ return array;
1635
+ }
1636
+ /**
1637
+ * Returns a partially formed result object
1638
+ * Useful for returning the "wrapper" object when array is not top level
1639
+ * e.g. GeoJSON
1640
+ */
1641
+ getPartialResult() {
1642
+ return this.topLevelObject;
1643
+ }
1644
+ getStreamingJsonPath() {
1645
+ return this.streamingJsonPath;
1646
+ }
1647
+ getStreamingJsonPathAsString() {
1648
+ return this.streamingJsonPath && this.streamingJsonPath.toString();
1649
+ }
1650
+ getJsonPath() {
1651
+ return this.jsonpath;
1652
+ }
1653
+ // PRIVATE METHODS
1654
+ /**
1655
+ * Checks is this.getJsonPath matches the jsonpaths provided in options
1656
+ */
1657
+ _matchJSONPath() {
1658
+ const currentPath = this.getJsonPath();
1659
+ if (this.jsonPaths.length === 0) {
1660
+ return true;
1661
+ }
1662
+ for (const jsonPath of this.jsonPaths) {
1663
+ if (jsonPath.equals(currentPath)) {
1664
+ return true;
1665
+ }
1666
+ }
1667
+ return false;
1595
1668
  }
1596
- });
1669
+ };
1597
1670
 
1598
1671
  // src/lib/parsers/parse-json-in-batches.ts
1599
1672
  async function* parseJSONInBatches(binaryAsyncIterator, options) {
1600
1673
  const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
1601
- const { metadata } = options;
1602
- const { jsonpaths } = options.json || {};
1674
+ const {
1675
+ metadata
1676
+ } = options;
1677
+ const {
1678
+ jsonpaths
1679
+ } = options.json || {};
1603
1680
  let isFirstChunk = true;
1604
1681
  const schema = null;
1605
1682
  const shape = options?.json?.shape || "object-row-table";
@@ -1607,18 +1684,22 @@ Char: ${this.c}`;
1607
1684
  ...options,
1608
1685
  shape
1609
1686
  });
1610
- const parser = new StreamingJSONParser({ jsonpaths });
1687
+ const parser = new StreamingJSONParser({
1688
+ jsonpaths
1689
+ });
1611
1690
  for await (const chunk of asyncIterator) {
1612
1691
  const rows = parser.write(chunk);
1613
1692
  const jsonpath2 = rows.length > 0 && parser.getStreamingJsonPathAsString();
1614
1693
  if (rows.length > 0 && isFirstChunk) {
1615
1694
  if (metadata) {
1616
1695
  const initialBatch = {
1696
+ // Common fields
1617
1697
  shape,
1618
1698
  batchType: "partial-result",
1619
1699
  data: [],
1620
1700
  length: 0,
1621
1701
  bytesUsed: 0,
1702
+ // JSON additions
1622
1703
  container: parser.getPartialResult(),
1623
1704
  jsonpath: jsonpath2
1624
1705
  };
@@ -1628,19 +1709,25 @@ Char: ${this.c}`;
1628
1709
  }
1629
1710
  for (const row of rows) {
1630
1711
  tableBatchBuilder.addRow(row);
1631
- const batch3 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
1712
+ const batch3 = tableBatchBuilder.getFullBatch({
1713
+ jsonpath: jsonpath2
1714
+ });
1632
1715
  if (batch3) {
1633
1716
  yield batch3;
1634
1717
  }
1635
1718
  }
1636
1719
  tableBatchBuilder.chunkComplete(chunk);
1637
- const batch2 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
1720
+ const batch2 = tableBatchBuilder.getFullBatch({
1721
+ jsonpath: jsonpath2
1722
+ });
1638
1723
  if (batch2) {
1639
1724
  yield batch2;
1640
1725
  }
1641
1726
  }
1642
1727
  const jsonpath = parser.getStreamingJsonPathAsString();
1643
- const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
1728
+ const batch = tableBatchBuilder.getFinalBatch({
1729
+ jsonpath
1730
+ });
1644
1731
  if (batch) {
1645
1732
  yield batch;
1646
1733
  }
@@ -1652,6 +1739,7 @@ Char: ${this.c}`;
1652
1739
  jsonpath: parser.getStreamingJsonPathAsString(),
1653
1740
  data: [],
1654
1741
  length: 0
1742
+ // schema: null
1655
1743
  };
1656
1744
  yield finalBatch;
1657
1745
  }
@@ -1669,56 +1757,54 @@ Char: ${this.c}`;
1669
1757
  }
1670
1758
  return batch.container;
1671
1759
  }
1672
- var init_parse_json_in_batches = __esm({
1673
- "src/lib/parsers/parse-json-in-batches.ts"() {
1674
- init_src();
1675
- init_src2();
1676
- init_streaming_json_parser();
1677
- init_jsonpath();
1678
- }
1679
- });
1680
1760
 
1681
1761
  // src/json-loader.ts
1762
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1763
+ var DEFAULT_JSON_LOADER_OPTIONS = {
1764
+ json: {
1765
+ shape: "object-row-table",
1766
+ table: false,
1767
+ jsonpaths: []
1768
+ // batchSize: 'auto'
1769
+ }
1770
+ };
1771
+ var JSONLoader = {
1772
+ name: "JSON",
1773
+ id: "json",
1774
+ module: "json",
1775
+ version: VERSION,
1776
+ extensions: ["json", "geojson"],
1777
+ mimeTypes: ["application/json"],
1778
+ category: "table",
1779
+ text: true,
1780
+ parse,
1781
+ parseTextSync,
1782
+ parseInBatches,
1783
+ options: DEFAULT_JSON_LOADER_OPTIONS
1784
+ };
1682
1785
  async function parse(arrayBuffer, options) {
1683
1786
  return parseTextSync(new TextDecoder().decode(arrayBuffer), options);
1684
1787
  }
1685
1788
  function parseTextSync(text, options) {
1686
- const jsonOptions = { ...options, json: { ...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json } };
1789
+ const jsonOptions = {
1790
+ ...options,
1791
+ json: {
1792
+ ...DEFAULT_JSON_LOADER_OPTIONS.json,
1793
+ ...options?.json
1794
+ }
1795
+ };
1687
1796
  return parseJSONSync(text, jsonOptions);
1688
1797
  }
1689
1798
  function parseInBatches(asyncIterator, options) {
1690
- const jsonOptions = { ...options, json: { ...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json } };
1799
+ const jsonOptions = {
1800
+ ...options,
1801
+ json: {
1802
+ ...DEFAULT_JSON_LOADER_OPTIONS.json,
1803
+ ...options?.json
1804
+ }
1805
+ };
1691
1806
  return parseJSONInBatches(asyncIterator, jsonOptions);
1692
1807
  }
1693
- var VERSION, DEFAULT_JSON_LOADER_OPTIONS, JSONLoader;
1694
- var init_json_loader = __esm({
1695
- "src/json-loader.ts"() {
1696
- init_parse_json();
1697
- init_parse_json_in_batches();
1698
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1699
- DEFAULT_JSON_LOADER_OPTIONS = {
1700
- json: {
1701
- shape: "object-row-table",
1702
- table: false,
1703
- jsonpaths: []
1704
- }
1705
- };
1706
- JSONLoader = {
1707
- name: "JSON",
1708
- id: "json",
1709
- module: "json",
1710
- version: VERSION,
1711
- extensions: ["json", "geojson"],
1712
- mimeTypes: ["application/json"],
1713
- category: "table",
1714
- text: true,
1715
- parse,
1716
- parseTextSync,
1717
- parseInBatches,
1718
- options: DEFAULT_JSON_LOADER_OPTIONS
1719
- };
1720
- }
1721
- });
1722
1808
 
1723
1809
  // src/lib/parsers/parse-ndjson.ts
1724
1810
  function parseNDJSONSync(ndjsonText) {
@@ -1732,11 +1818,6 @@ Char: ${this.c}`;
1732
1818
  });
1733
1819
  return makeTableFromData(parsedLines);
1734
1820
  }
1735
- var init_parse_ndjson = __esm({
1736
- "src/lib/parsers/parse-ndjson.ts"() {
1737
- init_src();
1738
- }
1739
- });
1740
1821
 
1741
1822
  // src/lib/parsers/parse-ndjson-in-batches.ts
1742
1823
  async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
@@ -1749,7 +1830,10 @@ Char: ${this.c}`;
1749
1830
  ...options,
1750
1831
  shape
1751
1832
  });
1752
- for await (const { counter, line } of numberedLineIterator) {
1833
+ for await (const {
1834
+ counter,
1835
+ line
1836
+ } of numberedLineIterator) {
1753
1837
  try {
1754
1838
  const row = JSON.parse(line);
1755
1839
  tableBatchBuilder.addRow(row);
@@ -1767,40 +1851,28 @@ Char: ${this.c}`;
1767
1851
  yield batch;
1768
1852
  }
1769
1853
  }
1770
- var init_parse_ndjson_in_batches = __esm({
1771
- "src/lib/parsers/parse-ndjson-in-batches.ts"() {
1772
- init_src();
1773
- init_src2();
1774
- }
1775
- });
1776
1854
 
1777
1855
  // src/ndjson-loader.ts
1778
- var VERSION2, NDJSONLoader;
1779
- var init_ndjson_loader = __esm({
1780
- "src/ndjson-loader.ts"() {
1781
- init_parse_ndjson();
1782
- init_parse_ndjson_in_batches();
1783
- VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1784
- NDJSONLoader = {
1785
- name: "NDJSON",
1786
- id: "ndjson",
1787
- module: "json",
1788
- version: VERSION2,
1789
- extensions: ["ndjson", "jsonl"],
1790
- mimeTypes: [
1791
- "application/x-ndjson",
1792
- "application/jsonlines",
1793
- "application/json-seq"
1794
- ],
1795
- category: "table",
1796
- text: true,
1797
- parse: async (arrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),
1798
- parseTextSync: parseNDJSONSync,
1799
- parseInBatches: parseNDJSONInBatches,
1800
- options: {}
1801
- };
1802
- }
1803
- });
1856
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1857
+ var NDJSONLoader = {
1858
+ name: "NDJSON",
1859
+ id: "ndjson",
1860
+ module: "json",
1861
+ version: VERSION2,
1862
+ extensions: ["ndjson", "jsonl"],
1863
+ mimeTypes: [
1864
+ "application/x-ndjson",
1865
+ "application/jsonlines",
1866
+ // https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#cm-batch
1867
+ "application/json-seq"
1868
+ ],
1869
+ category: "table",
1870
+ text: true,
1871
+ parse: async (arrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),
1872
+ parseTextSync: parseNDJSONSync,
1873
+ parseInBatches: parseNDJSONInBatches,
1874
+ options: {}
1875
+ };
1804
1876
 
1805
1877
  // src/lib/encoders/json-encoder.ts
1806
1878
  function encodeTableAsJSON(table, options) {
@@ -1812,64 +1884,49 @@ Char: ${this.c}`;
1812
1884
  }
1813
1885
  return `[${strings.join(",")}]`;
1814
1886
  }
1815
- var init_json_encoder = __esm({
1816
- "src/lib/encoders/json-encoder.ts"() {
1817
- init_src();
1818
- }
1819
- });
1820
1887
 
1821
1888
  // src/json-writer.ts
1822
- var JSONWriter;
1823
- var init_json_writer = __esm({
1824
- "src/json-writer.ts"() {
1825
- init_json_encoder();
1826
- JSONWriter = {
1827
- id: "json",
1828
- version: "latest",
1829
- module: "json",
1830
- name: "JSON",
1831
- extensions: ["json"],
1832
- mimeTypes: ["application/json"],
1833
- options: {},
1834
- text: true,
1835
- encode: async (table, options) => new TextEncoder().encode(encodeTableAsJSON(table, options)).buffer,
1836
- encodeTextSync: (table, options) => encodeTableAsJSON(table, options)
1837
- };
1838
- }
1839
- });
1889
+ var JSONWriter = {
1890
+ id: "json",
1891
+ version: "latest",
1892
+ module: "json",
1893
+ name: "JSON",
1894
+ extensions: ["json"],
1895
+ mimeTypes: ["application/json"],
1896
+ options: {},
1897
+ text: true,
1898
+ encode: async (table, options) => new TextEncoder().encode(encodeTableAsJSON(table, options)).buffer,
1899
+ encodeTextSync: (table, options) => encodeTableAsJSON(table, options)
1900
+ };
1840
1901
 
1841
- // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
1902
+ // ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
1903
+ var DimIndex = {
1904
+ x: 0,
1905
+ y: 1,
1906
+ z: 2
1907
+ };
1842
1908
  function getPolygonSignedArea(points, options = {}) {
1843
1909
  const {
1844
1910
  start = 0,
1845
- end = points.length
1911
+ end = points.length,
1912
+ plane = "xy"
1846
1913
  } = options;
1847
1914
  const dim = options.size || 2;
1848
1915
  let area2 = 0;
1916
+ const i0 = DimIndex[plane[0]];
1917
+ const i1 = DimIndex[plane[1]];
1849
1918
  for (let i = start, j = end - dim; i < end; i += dim) {
1850
- area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
1919
+ area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
1851
1920
  j = i;
1852
1921
  }
1853
1922
  return area2 / 2;
1854
1923
  }
1855
- var init_polygon_utils = __esm({
1856
- "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
1857
- }
1858
- });
1859
1924
 
1860
- // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
1861
- var init_polygon = __esm({
1862
- "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
1863
- init_defineProperty();
1864
- init_polygon_utils();
1865
- }
1866
- });
1867
-
1868
- // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
1869
- function earcut(positions, holeIndices, dim = 2, areas) {
1925
+ // ../../node_modules/@math.gl/polygon/dist/earcut.js
1926
+ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
1870
1927
  const hasHoles = holeIndices && holeIndices.length;
1871
1928
  const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
1872
- let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
1929
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
1873
1930
  const triangles = [];
1874
1931
  if (!outerNode || outerNode.next === outerNode.prev)
1875
1932
  return triangles;
@@ -1881,7 +1938,7 @@ Char: ${this.c}`;
1881
1938
  let x;
1882
1939
  let y;
1883
1940
  if (hasHoles)
1884
- outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
1941
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
1885
1942
  if (positions.length > 80 * dim) {
1886
1943
  minX = maxX = positions[0];
1887
1944
  minY = maxY = positions[1];
@@ -1898,27 +1955,30 @@ Char: ${this.c}`;
1898
1955
  maxY = y;
1899
1956
  }
1900
1957
  invSize = Math.max(maxX - minX, maxY - minY);
1901
- invSize = invSize !== 0 ? 1 / invSize : 0;
1958
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
1902
1959
  }
1903
- earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
1960
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
1904
1961
  return triangles;
1905
1962
  }
1906
- function linkedList(data, start, end, dim, clockwise, area2) {
1963
+ function linkedList(data, start, end, dim, clockwise, area2, plane) {
1907
1964
  let i;
1908
1965
  let last;
1909
1966
  if (area2 === void 0) {
1910
1967
  area2 = getPolygonSignedArea(data, {
1911
1968
  start,
1912
1969
  end,
1913
- size: dim
1970
+ size: dim,
1971
+ plane
1914
1972
  });
1915
1973
  }
1974
+ let i0 = DimIndex[plane[0]];
1975
+ let i1 = DimIndex[plane[1]];
1916
1976
  if (clockwise === area2 < 0) {
1917
1977
  for (i = start; i < end; i += dim)
1918
- last = insertNode(i, data[i], data[i + 1], last);
1978
+ last = insertNode(i, data[i + i0], data[i + i1], last);
1919
1979
  } else {
1920
1980
  for (i = end - dim; i >= start; i -= dim)
1921
- last = insertNode(i, data[i], data[i + 1], last);
1981
+ last = insertNode(i, data[i + i0], data[i + i1], last);
1922
1982
  }
1923
1983
  if (last && equals(last, last.next)) {
1924
1984
  removeNode(last);
@@ -1959,9 +2019,9 @@ Char: ${this.c}`;
1959
2019
  prev = ear.prev;
1960
2020
  next = ear.next;
1961
2021
  if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
1962
- triangles.push(prev.i / dim);
1963
- triangles.push(ear.i / dim);
1964
- triangles.push(next.i / dim);
2022
+ triangles.push(prev.i / dim | 0);
2023
+ triangles.push(ear.i / dim | 0);
2024
+ triangles.push(next.i / dim | 0);
1965
2025
  removeNode(ear);
1966
2026
  ear = next.next;
1967
2027
  stop = next.next;
@@ -1987,9 +2047,19 @@ Char: ${this.c}`;
1987
2047
  const c = ear.next;
1988
2048
  if (area(a, b, c) >= 0)
1989
2049
  return false;
1990
- let p = ear.next.next;
1991
- while (p !== ear.prev) {
1992
- if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2050
+ const ax = a.x;
2051
+ const bx = b.x;
2052
+ const cx = c.x;
2053
+ const ay = a.y;
2054
+ const by = b.y;
2055
+ const cy = c.y;
2056
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
2057
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
2058
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
2059
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
2060
+ let p = c.next;
2061
+ while (p !== a) {
2062
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
1993
2063
  return false;
1994
2064
  p = p.next;
1995
2065
  }
@@ -2001,29 +2071,35 @@ Char: ${this.c}`;
2001
2071
  const c = ear.next;
2002
2072
  if (area(a, b, c) >= 0)
2003
2073
  return false;
2004
- const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
2005
- const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
2006
- const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
2007
- const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
2008
- const minZ = zOrder(minTX, minTY, minX, minY, invSize);
2009
- const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
2074
+ const ax = a.x;
2075
+ const bx = b.x;
2076
+ const cx = c.x;
2077
+ const ay = a.y;
2078
+ const by = b.y;
2079
+ const cy = c.y;
2080
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
2081
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
2082
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
2083
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
2084
+ const minZ = zOrder(x0, y0, minX, minY, invSize);
2085
+ const maxZ = zOrder(x1, y1, minX, minY, invSize);
2010
2086
  let p = ear.prevZ;
2011
2087
  let n = ear.nextZ;
2012
2088
  while (p && p.z >= minZ && n && n.z <= maxZ) {
2013
- if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2089
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2014
2090
  return false;
2015
2091
  p = p.prevZ;
2016
- if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
2092
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
2017
2093
  return false;
2018
2094
  n = n.nextZ;
2019
2095
  }
2020
2096
  while (p && p.z >= minZ) {
2021
- if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2097
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2022
2098
  return false;
2023
2099
  p = p.prevZ;
2024
2100
  }
2025
2101
  while (n && n.z <= maxZ) {
2026
- if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
2102
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
2027
2103
  return false;
2028
2104
  n = n.nextZ;
2029
2105
  }
@@ -2035,9 +2111,9 @@ Char: ${this.c}`;
2035
2111
  const a = p.prev;
2036
2112
  const b = p.next.next;
2037
2113
  if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
2038
- triangles.push(a.i / dim);
2039
- triangles.push(p.i / dim);
2040
- triangles.push(b.i / dim);
2114
+ triangles.push(a.i / dim | 0);
2115
+ triangles.push(p.i / dim | 0);
2116
+ triangles.push(b.i / dim | 0);
2041
2117
  removeNode(p);
2042
2118
  removeNode(p.next);
2043
2119
  p = start = b;
@@ -2055,8 +2131,8 @@ Char: ${this.c}`;
2055
2131
  let c = splitPolygon(a, b);
2056
2132
  a = filterPoints(a, a.next);
2057
2133
  c = filterPoints(c, c.next);
2058
- earcutLinked(a, triangles, dim, minX, minY, invSize);
2059
- earcutLinked(c, triangles, dim, minX, minY, invSize);
2134
+ earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
2135
+ earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
2060
2136
  return;
2061
2137
  }
2062
2138
  b = b.next;
@@ -2064,7 +2140,7 @@ Char: ${this.c}`;
2064
2140
  a = a.next;
2065
2141
  } while (a !== start);
2066
2142
  }
2067
- function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
2143
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2068
2144
  const queue = [];
2069
2145
  let i;
2070
2146
  let len;
@@ -2074,15 +2150,14 @@ Char: ${this.c}`;
2074
2150
  for (i = 0, len = holeIndices.length; i < len; i++) {
2075
2151
  start = holeIndices[i] * dim;
2076
2152
  end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
2077
- list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
2153
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
2078
2154
  if (list === list.next)
2079
2155
  list.steiner = true;
2080
2156
  queue.push(getLeftmost(list));
2081
2157
  }
2082
2158
  queue.sort(compareX);
2083
2159
  for (i = 0; i < queue.length; i++) {
2084
- eliminateHole(queue[i], outerNode);
2085
- outerNode = filterPoints(outerNode, outerNode.next);
2160
+ outerNode = eliminateHole(queue[i], outerNode);
2086
2161
  }
2087
2162
  return outerNode;
2088
2163
  }
@@ -2090,12 +2165,13 @@ Char: ${this.c}`;
2090
2165
  return a.x - b.x;
2091
2166
  }
2092
2167
  function eliminateHole(hole, outerNode) {
2093
- outerNode = findHoleBridge(hole, outerNode);
2094
- if (outerNode) {
2095
- const b = splitPolygon(outerNode, hole);
2096
- filterPoints(outerNode, outerNode.next);
2097
- filterPoints(b, b.next);
2168
+ const bridge = findHoleBridge(hole, outerNode);
2169
+ if (!bridge) {
2170
+ return outerNode;
2098
2171
  }
2172
+ const bridgeReverse = splitPolygon(bridge, hole);
2173
+ filterPoints(bridgeReverse, bridgeReverse.next);
2174
+ return filterPoints(bridge, bridge.next);
2099
2175
  }
2100
2176
  function findHoleBridge(hole, outerNode) {
2101
2177
  let p = outerNode;
@@ -2108,21 +2184,15 @@ Char: ${this.c}`;
2108
2184
  const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
2109
2185
  if (x <= hx && x > qx) {
2110
2186
  qx = x;
2111
- if (x === hx) {
2112
- if (hy === p.y)
2113
- return p;
2114
- if (hy === p.next.y)
2115
- return p.next;
2116
- }
2117
2187
  m = p.x < p.next.x ? p : p.next;
2188
+ if (x === hx)
2189
+ return m;
2118
2190
  }
2119
2191
  }
2120
2192
  p = p.next;
2121
2193
  } while (p !== outerNode);
2122
2194
  if (!m)
2123
2195
  return null;
2124
- if (hx === qx)
2125
- return m;
2126
2196
  const stop = m;
2127
2197
  const mx = m.x;
2128
2198
  const my = m.y;
@@ -2147,7 +2217,7 @@ Char: ${this.c}`;
2147
2217
  function indexCurve(start, minX, minY, invSize) {
2148
2218
  let p = start;
2149
2219
  do {
2150
- if (p.z === null)
2220
+ if (p.z === 0)
2151
2221
  p.z = zOrder(p.x, p.y, minX, minY, invSize);
2152
2222
  p.prevZ = p.prev;
2153
2223
  p.nextZ = p.next;
@@ -2208,8 +2278,8 @@ Char: ${this.c}`;
2208
2278
  return list;
2209
2279
  }
2210
2280
  function zOrder(x, y, minX, minY, invSize) {
2211
- x = 32767 * (x - minX) * invSize;
2212
- y = 32767 * (y - minY) * invSize;
2281
+ x = (x - minX) * invSize | 0;
2282
+ y = (y - minY) * invSize | 0;
2213
2283
  x = (x | x << 8) & 16711935;
2214
2284
  x = (x | x << 4) & 252645135;
2215
2285
  x = (x | x << 2) & 858993459;
@@ -2231,7 +2301,7 @@ Char: ${this.c}`;
2231
2301
  return leftmost;
2232
2302
  }
2233
2303
  function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
2234
- return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
2304
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
2235
2305
  }
2236
2306
  function isValidDiagonal(a, b) {
2237
2307
  return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
@@ -2290,8 +2360,8 @@ Char: ${this.c}`;
2290
2360
  return inside;
2291
2361
  }
2292
2362
  function splitPolygon(a, b) {
2293
- const a2 = new Node(a.i, a.x, a.y);
2294
- const b2 = new Node(b.i, b.x, b.y);
2363
+ const a2 = new Vertex(a.i, a.x, a.y);
2364
+ const b2 = new Vertex(b.i, b.x, b.y);
2295
2365
  const an = a.next;
2296
2366
  const bp = b.prev;
2297
2367
  a.next = b;
@@ -2305,7 +2375,7 @@ Char: ${this.c}`;
2305
2375
  return b2;
2306
2376
  }
2307
2377
  function insertNode(i, x, y, last) {
2308
- const p = new Node(i, x, y);
2378
+ const p = new Vertex(i, x, y);
2309
2379
  if (!last) {
2310
2380
  p.prev = p;
2311
2381
  p.next = p;
@@ -2325,64 +2395,22 @@ Char: ${this.c}`;
2325
2395
  if (p.nextZ)
2326
2396
  p.nextZ.prevZ = p.prevZ;
2327
2397
  }
2328
- function Node(i, x, y) {
2329
- this.i = i;
2330
- this.x = x;
2331
- this.y = y;
2332
- this.prev = null;
2333
- this.next = null;
2334
- this.z = null;
2335
- this.prevZ = null;
2336
- this.nextZ = null;
2337
- this.steiner = false;
2338
- }
2339
- var init_earcut = __esm({
2340
- "../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
2341
- init_polygon_utils();
2342
- }
2343
- });
2344
-
2345
- // ../../node_modules/@math.gl/polygon/dist/esm/utils.js
2346
- var init_utils = __esm({
2347
- "../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
2348
- }
2349
- });
2350
-
2351
- // ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
2352
- var init_lineclip = __esm({
2353
- "../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
2354
- init_utils();
2355
- }
2356
- });
2357
-
2358
- // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
2359
- var init_cut_by_grid = __esm({
2360
- "../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
2361
- init_lineclip();
2362
- init_utils();
2363
- }
2364
- });
2365
-
2366
- // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
2367
- var init_cut_by_mercator_bounds = __esm({
2368
- "../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
2369
- init_cut_by_grid();
2370
- init_utils();
2398
+ var Vertex = class {
2399
+ constructor(i, x, y) {
2400
+ _defineProperty(this, "i", void 0);
2401
+ _defineProperty(this, "x", void 0);
2402
+ _defineProperty(this, "y", void 0);
2403
+ _defineProperty(this, "prev", null);
2404
+ _defineProperty(this, "next", null);
2405
+ _defineProperty(this, "z", 0);
2406
+ _defineProperty(this, "prevZ", null);
2407
+ _defineProperty(this, "nextZ", null);
2408
+ _defineProperty(this, "steiner", false);
2409
+ this.i = i;
2410
+ this.x = x;
2411
+ this.y = y;
2371
2412
  }
2372
- });
2373
-
2374
- // ../../node_modules/@math.gl/polygon/dist/esm/index.js
2375
- var init_esm = __esm({
2376
- "../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
2377
- init_polygon();
2378
- init_polygon_utils();
2379
- init_earcut();
2380
- init_lineclip();
2381
- init_cut_by_grid();
2382
- init_cut_by_mercator_bounds();
2383
- init_polygon();
2384
- }
2385
- });
2413
+ };
2386
2414
 
2387
2415
  // ../gis/src/lib/flat-geojson-to-binary.ts
2388
2416
  function flatGeojsonToBinary(features, geometryInfo, options) {
@@ -2423,7 +2451,11 @@ Char: ${this.c}`;
2423
2451
  propArrayTypes,
2424
2452
  coordLength
2425
2453
  } = geometryInfo;
2426
- const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
2454
+ const {
2455
+ numericPropKeys = [],
2456
+ PositionDataType = Float32Array,
2457
+ triangulate = true
2458
+ } = options;
2427
2459
  const hasGlobalId = features[0] && "id" in features[0];
2428
2460
  const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
2429
2461
  const points = {
@@ -2488,7 +2520,9 @@ Char: ${this.c}`;
2488
2520
  handlePoint(geometry, points, indexMap, coordLength, properties);
2489
2521
  points.properties.push(keepStringProperties(properties, numericPropKeys));
2490
2522
  if (hasGlobalId) {
2491
- points.fields.push({ id: feature.id });
2523
+ points.fields.push({
2524
+ id: feature.id
2525
+ });
2492
2526
  }
2493
2527
  indexMap.pointFeature++;
2494
2528
  break;
@@ -2496,7 +2530,9 @@ Char: ${this.c}`;
2496
2530
  handleLineString(geometry, lines, indexMap, coordLength, properties);
2497
2531
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
2498
2532
  if (hasGlobalId) {
2499
- lines.fields.push({ id: feature.id });
2533
+ lines.fields.push({
2534
+ id: feature.id
2535
+ });
2500
2536
  }
2501
2537
  indexMap.lineFeature++;
2502
2538
  break;
@@ -2504,7 +2540,9 @@ Char: ${this.c}`;
2504
2540
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
2505
2541
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
2506
2542
  if (hasGlobalId) {
2507
- polygons.fields.push({ id: feature.id });
2543
+ polygons.fields.push({
2544
+ id: feature.id
2545
+ });
2508
2546
  }
2509
2547
  indexMap.polygonFeature++;
2510
2548
  break;
@@ -2550,12 +2588,19 @@ Char: ${this.c}`;
2550
2588
  const nextIndices = geometry.indices[l + 1];
2551
2589
  for (let i = 0, il = indices.length; i < il; ++i) {
2552
2590
  const start = indices[i];
2553
- const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
2591
+ const end = i === il - 1 ? (
2592
+ // last line, so either read to:
2593
+ nextIndices === void 0 ? geometry.data.length : nextIndices[0]
2594
+ ) : indices[i + 1];
2554
2595
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
2555
2596
  indexMap.polygonPosition += (end - start) / coordLength;
2556
2597
  }
2557
2598
  const endPosition = indexMap.polygonPosition;
2558
- triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
2599
+ triangulatePolygon(polygons, areas, indices, {
2600
+ startPosition,
2601
+ endPosition,
2602
+ coordLength
2603
+ });
2559
2604
  }
2560
2605
  }
2561
2606
  function triangulatePolygon(polygons, areas, indices, {
@@ -2579,7 +2624,10 @@ Char: ${this.c}`;
2579
2624
  function wrapProps(obj, size) {
2580
2625
  const returnObj = {};
2581
2626
  for (const key in obj) {
2582
- returnObj[key] = { value: obj[key], size };
2627
+ returnObj[key] = {
2628
+ value: obj[key],
2629
+ size
2630
+ };
2583
2631
  }
2584
2632
  return returnObj;
2585
2633
  }
@@ -2587,31 +2635,71 @@ Char: ${this.c}`;
2587
2635
  const binaryFeatures = {
2588
2636
  points: {
2589
2637
  ...points,
2590
- positions: { value: points.positions, size: coordLength },
2591
- globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
2592
- featureIds: { value: points.featureIds, size: 1 },
2638
+ positions: {
2639
+ value: points.positions,
2640
+ size: coordLength
2641
+ },
2642
+ globalFeatureIds: {
2643
+ value: points.globalFeatureIds,
2644
+ size: 1
2645
+ },
2646
+ featureIds: {
2647
+ value: points.featureIds,
2648
+ size: 1
2649
+ },
2593
2650
  numericProps: wrapProps(points.numericProps, 1)
2594
2651
  },
2595
2652
  lines: {
2596
2653
  ...lines,
2597
- positions: { value: lines.positions, size: coordLength },
2598
- pathIndices: { value: lines.pathIndices, size: 1 },
2599
- globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
2600
- featureIds: { value: lines.featureIds, size: 1 },
2654
+ positions: {
2655
+ value: lines.positions,
2656
+ size: coordLength
2657
+ },
2658
+ pathIndices: {
2659
+ value: lines.pathIndices,
2660
+ size: 1
2661
+ },
2662
+ globalFeatureIds: {
2663
+ value: lines.globalFeatureIds,
2664
+ size: 1
2665
+ },
2666
+ featureIds: {
2667
+ value: lines.featureIds,
2668
+ size: 1
2669
+ },
2601
2670
  numericProps: wrapProps(lines.numericProps, 1)
2602
2671
  },
2603
2672
  polygons: {
2604
2673
  ...polygons,
2605
- positions: { value: polygons.positions, size: coordLength },
2606
- polygonIndices: { value: polygons.polygonIndices, size: 1 },
2607
- primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
2608
- globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
2609
- featureIds: { value: polygons.featureIds, size: 1 },
2674
+ positions: {
2675
+ value: polygons.positions,
2676
+ size: coordLength
2677
+ },
2678
+ polygonIndices: {
2679
+ value: polygons.polygonIndices,
2680
+ size: 1
2681
+ },
2682
+ primitivePolygonIndices: {
2683
+ value: polygons.primitivePolygonIndices,
2684
+ size: 1
2685
+ },
2686
+ globalFeatureIds: {
2687
+ value: polygons.globalFeatureIds,
2688
+ size: 1
2689
+ },
2690
+ featureIds: {
2691
+ value: polygons.featureIds,
2692
+ size: 1
2693
+ },
2610
2694
  numericProps: wrapProps(polygons.numericProps, 1)
2611
2695
  }
2696
+ // triangles not expected
2612
2697
  };
2613
2698
  if (binaryFeatures.polygons && polygons.triangles) {
2614
- binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
2699
+ binaryFeatures.polygons.triangles = {
2700
+ value: new Uint32Array(polygons.triangles),
2701
+ size: 1
2702
+ };
2615
2703
  }
2616
2704
  return binaryFeatures;
2617
2705
  }
@@ -2638,11 +2726,6 @@ Char: ${this.c}`;
2638
2726
  }
2639
2727
  return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
2640
2728
  }
2641
- var init_flat_geojson_to_binary = __esm({
2642
- "../gis/src/lib/flat-geojson-to-binary.ts"() {
2643
- init_esm();
2644
- }
2645
- });
2646
2729
 
2647
2730
  // ../gis/src/lib/extract-geometry-info.ts
2648
2731
  function extractGeometryInfo(features) {
@@ -2655,7 +2738,7 @@ Char: ${this.c}`;
2655
2738
  let polygonObjectsCount = 0;
2656
2739
  let polygonRingsCount = 0;
2657
2740
  let polygonFeaturesCount = 0;
2658
- const coordLengths = new Set();
2741
+ const coordLengths = /* @__PURE__ */ new Set();
2659
2742
  for (const feature of features) {
2660
2743
  const geometry = feature.geometry;
2661
2744
  switch (geometry.type) {
@@ -2728,13 +2811,12 @@ Char: ${this.c}`;
2728
2811
  polygonFeaturesCount
2729
2812
  };
2730
2813
  }
2731
- var init_extract_geometry_info = __esm({
2732
- "../gis/src/lib/extract-geometry-info.ts"() {
2733
- }
2734
- });
2735
2814
 
2736
2815
  // ../gis/src/lib/geojson-to-flat-geojson.ts
2737
- function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
2816
+ function geojsonToFlatGeojson(features, options = {
2817
+ coordLength: 2,
2818
+ fixRingWinding: true
2819
+ }) {
2738
2820
  return features.map((feature) => flattenFeature(feature, options));
2739
2821
  }
2740
2822
  function flattenPoint(coordinates, data, indices, options) {
@@ -2775,7 +2857,9 @@ Char: ${this.c}`;
2775
2857
  }
2776
2858
  }
2777
2859
  function flattenFeature(feature, options) {
2778
- const { geometry } = feature;
2860
+ const {
2861
+ geometry
2862
+ } = feature;
2779
2863
  if (geometry.type === "GeometryCollection") {
2780
2864
  throw new Error("GeometryCollection type not supported");
2781
2865
  }
@@ -2813,48 +2897,83 @@ Char: ${this.c}`;
2813
2897
  default:
2814
2898
  throw new Error(`Unknown type: ${type}`);
2815
2899
  }
2816
- return { ...feature, geometry: { type, indices, data, areas } };
2900
+ return {
2901
+ ...feature,
2902
+ geometry: {
2903
+ type,
2904
+ indices,
2905
+ data,
2906
+ areas
2907
+ }
2908
+ };
2817
2909
  }
2818
- var init_geojson_to_flat_geojson = __esm({
2819
- "../gis/src/lib/geojson-to-flat-geojson.ts"() {
2820
- init_esm();
2821
- }
2822
- });
2823
2910
 
2824
2911
  // ../gis/src/lib/geojson-to-binary.ts
2825
- function geojsonToBinary(features, options = { fixRingWinding: true, triangulate: true }) {
2912
+ function geojsonToBinary(features, options = {
2913
+ fixRingWinding: true,
2914
+ triangulate: true
2915
+ }) {
2826
2916
  const geometryInfo = extractGeometryInfo(features);
2827
2917
  const coordLength = geometryInfo.coordLength;
2828
- const { fixRingWinding } = options;
2829
- const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
2918
+ const {
2919
+ fixRingWinding
2920
+ } = options;
2921
+ const flatFeatures = geojsonToFlatGeojson(features, {
2922
+ coordLength,
2923
+ fixRingWinding
2924
+ });
2830
2925
  return flatGeojsonToBinary(flatFeatures, geometryInfo, {
2831
2926
  numericPropKeys: options.numericPropKeys,
2832
2927
  PositionDataType: options.PositionDataType || Float32Array,
2833
2928
  triangulate: options.triangulate
2834
2929
  });
2835
2930
  }
2836
- var init_geojson_to_binary = __esm({
2837
- "../gis/src/lib/geojson-to-binary.ts"() {
2838
- init_extract_geometry_info();
2839
- init_geojson_to_flat_geojson();
2840
- init_flat_geojson_to_binary();
2841
- }
2842
- });
2843
-
2844
- // ../gis/src/index.ts
2845
- var init_src3 = __esm({
2846
- "../gis/src/index.ts"() {
2847
- init_geojson_to_binary();
2848
- }
2849
- });
2850
2931
 
2851
2932
  // src/geojson-loader.ts
2933
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2934
+ var GeoJSONWorkerLoader = {
2935
+ name: "GeoJSON",
2936
+ id: "geojson",
2937
+ module: "geojson",
2938
+ version: VERSION3,
2939
+ worker: true,
2940
+ extensions: ["geojson"],
2941
+ mimeTypes: ["application/geo+json"],
2942
+ category: "geometry",
2943
+ text: true,
2944
+ options: {
2945
+ geojson: {
2946
+ shape: "object-row-table"
2947
+ },
2948
+ json: {
2949
+ shape: "object-row-table",
2950
+ jsonpaths: ["$", "$.features"]
2951
+ },
2952
+ gis: {
2953
+ format: "geojson"
2954
+ }
2955
+ }
2956
+ };
2957
+ var GeoJSONLoader = {
2958
+ ...GeoJSONWorkerLoader,
2959
+ // @ts-expect-error
2960
+ parse: parse2,
2961
+ // @ts-expect-error
2962
+ parseTextSync: parseTextSync2,
2963
+ parseInBatches: parseInBatches2
2964
+ };
2852
2965
  async function parse2(arrayBuffer, options) {
2853
2966
  return parseTextSync2(new TextDecoder().decode(arrayBuffer), options);
2854
2967
  }
2855
2968
  function parseTextSync2(text, options) {
2856
- options = { ...GeoJSONLoader.options, ...options };
2857
- options.geojson = { ...GeoJSONLoader.options.geojson, ...options.geojson };
2969
+ options = {
2970
+ ...GeoJSONLoader.options,
2971
+ ...options
2972
+ };
2973
+ options.geojson = {
2974
+ ...GeoJSONLoader.options.geojson,
2975
+ ...options.geojson
2976
+ };
2858
2977
  options.gis = options.gis || {};
2859
2978
  let geojson;
2860
2979
  try {
@@ -2864,6 +2983,8 @@ Char: ${this.c}`;
2864
2983
  }
2865
2984
  const table = {
2866
2985
  shape: "geojson-table",
2986
+ // TODO - deduce schema from geojson
2987
+ // TODO check that parsed data is of type FeatureCollection
2867
2988
  type: "FeatureCollection",
2868
2989
  features: geojson?.features || []
2869
2990
  };
@@ -2875,8 +2996,14 @@ Char: ${this.c}`;
2875
2996
  }
2876
2997
  }
2877
2998
  function parseInBatches2(asyncIterator, options) {
2878
- options = { ...GeoJSONLoader.options, ...options };
2879
- options.json = { ...GeoJSONLoader.options.geojson, ...options.geojson };
2999
+ options = {
3000
+ ...GeoJSONLoader.options,
3001
+ ...options
3002
+ };
3003
+ options.json = {
3004
+ ...GeoJSONLoader.options.geojson,
3005
+ ...options.geojson
3006
+ };
2880
3007
  const geojsonIterator = parseJSONInBatches(asyncIterator, options);
2881
3008
  switch (options.gis.format) {
2882
3009
  case "binary":
@@ -2891,43 +3018,6 @@ Char: ${this.c}`;
2891
3018
  yield batch;
2892
3019
  }
2893
3020
  }
2894
- var VERSION3, GeoJSONWorkerLoader, GeoJSONLoader;
2895
- var init_geojson_loader = __esm({
2896
- "src/geojson-loader.ts"() {
2897
- init_src3();
2898
- init_parse_json_in_batches();
2899
- VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2900
- GeoJSONWorkerLoader = {
2901
- name: "GeoJSON",
2902
- id: "geojson",
2903
- module: "geojson",
2904
- version: VERSION3,
2905
- worker: true,
2906
- extensions: ["geojson"],
2907
- mimeTypes: ["application/geo+json"],
2908
- category: "geometry",
2909
- text: true,
2910
- options: {
2911
- geojson: {
2912
- shape: "object-row-table"
2913
- },
2914
- json: {
2915
- shape: "object-row-table",
2916
- jsonpaths: ["$", "$.features"]
2917
- },
2918
- gis: {
2919
- format: "geojson"
2920
- }
2921
- }
2922
- };
2923
- GeoJSONLoader = {
2924
- ...GeoJSONWorkerLoader,
2925
- parse: parse2,
2926
- parseTextSync: parseTextSync2,
2927
- parseInBatches: parseInBatches2
2928
- };
2929
- }
2930
- });
2931
3021
 
2932
3022
  // src/lib/encoder-utils/encode-utils.ts
2933
3023
  function detectGeometryColumnIndex(table) {
@@ -2956,11 +3046,6 @@ Char: ${this.c}`;
2956
3046
  }
2957
3047
  return properties;
2958
3048
  }
2959
- var init_encode_utils = __esm({
2960
- "src/lib/encoder-utils/encode-utils.ts"() {
2961
- init_src();
2962
- }
2963
- });
2964
3049
 
2965
3050
  // src/lib/encoder-utils/encode-table-row.ts
2966
3051
  function encodeTableRow(table, rowIndex, geometryColumnIndex, utf8Encoder) {
@@ -2976,7 +3061,11 @@ Char: ${this.c}`;
2976
3061
  const columnName = table.schema?.fields[geometryColumnIndex].name;
2977
3062
  let featureOrGeometry = columnName && row[columnName];
2978
3063
  if (!featureOrGeometry) {
2979
- return { type: "Feature", geometry: null, properties };
3064
+ return {
3065
+ type: "Feature",
3066
+ geometry: null,
3067
+ properties
3068
+ };
2980
3069
  }
2981
3070
  if (typeof featureOrGeometry === "string") {
2982
3071
  try {
@@ -2989,53 +3078,53 @@ Char: ${this.c}`;
2989
3078
  throw new Error("invalid geometry column value");
2990
3079
  }
2991
3080
  if (featureOrGeometry?.type === "Feature") {
2992
- return { ...featureOrGeometry, properties };
3081
+ return {
3082
+ ...featureOrGeometry,
3083
+ properties
3084
+ };
2993
3085
  }
2994
- return { type: "Feature", geometry: featureOrGeometry, properties };
3086
+ return {
3087
+ type: "Feature",
3088
+ geometry: featureOrGeometry,
3089
+ properties
3090
+ };
2995
3091
  }
2996
- var init_encode_table_row = __esm({
2997
- "src/lib/encoder-utils/encode-table-row.ts"() {
2998
- init_src();
2999
- init_encode_utils();
3000
- }
3001
- });
3002
3092
 
3003
3093
  // src/lib/encoder-utils/utf8-encoder.ts
3004
- var Utf8ArrayBufferEncoder;
3005
- var init_utf8_encoder = __esm({
3006
- "src/lib/encoder-utils/utf8-encoder.ts"() {
3007
- Utf8ArrayBufferEncoder = class {
3008
- constructor(chunkSize) {
3009
- this.strings = [];
3010
- this.totalLength = 0;
3011
- this.textEncoder = new TextEncoder();
3012
- this.chunkSize = chunkSize;
3013
- }
3014
- push(...strings) {
3015
- for (const string of strings) {
3016
- this.strings.push(string);
3017
- this.totalLength += string.length;
3018
- }
3019
- }
3020
- isFull() {
3021
- return this.totalLength >= this.chunkSize;
3022
- }
3023
- getArrayBufferBatch() {
3024
- return this.textEncoder.encode(this.getStringBatch()).buffer;
3025
- }
3026
- getStringBatch() {
3027
- const stringChunk = this.strings.join("");
3028
- this.strings = [];
3029
- this.totalLength = 0;
3030
- return stringChunk;
3031
- }
3032
- };
3094
+ var Utf8ArrayBufferEncoder = class {
3095
+ strings = [];
3096
+ totalLength = 0;
3097
+ textEncoder = new TextEncoder();
3098
+ constructor(chunkSize) {
3099
+ this.chunkSize = chunkSize;
3100
+ }
3101
+ push(...strings) {
3102
+ for (const string of strings) {
3103
+ this.strings.push(string);
3104
+ this.totalLength += string.length;
3105
+ }
3033
3106
  }
3034
- });
3107
+ isFull() {
3108
+ return this.totalLength >= this.chunkSize;
3109
+ }
3110
+ getArrayBufferBatch() {
3111
+ return this.textEncoder.encode(this.getStringBatch()).buffer;
3112
+ }
3113
+ getStringBatch() {
3114
+ const stringChunk = this.strings.join("");
3115
+ this.strings = [];
3116
+ this.totalLength = 0;
3117
+ return stringChunk;
3118
+ }
3119
+ };
3035
3120
 
3036
3121
  // src/lib/encoders/geojson-encoder.ts
3037
3122
  async function* encodeTableAsGeojsonInBatches(batchIterator, inputOpts = {}) {
3038
- const options = { geojson: {}, chunkSize: 1e4, ...inputOpts };
3123
+ const options = {
3124
+ geojson: {},
3125
+ chunkSize: 1e4,
3126
+ ...inputOpts
3127
+ };
3039
3128
  const utf8Encoder = new Utf8ArrayBufferEncoder(options.chunkSize);
3040
3129
  if (!options.geojson.featureArray) {
3041
3130
  utf8Encoder.push("{\n", '"type": "FeatureCollection",\n', '"features":\n');
@@ -3073,72 +3162,25 @@ Char: ${this.c}`;
3073
3162
  }
3074
3163
  yield utf8Encoder.getArrayBufferBatch();
3075
3164
  }
3076
- var init_geojson_encoder = __esm({
3077
- "src/lib/encoders/geojson-encoder.ts"() {
3078
- init_src();
3079
- init_encode_utils();
3080
- init_encode_table_row();
3081
- init_utf8_encoder();
3082
- }
3083
- });
3084
3165
 
3085
3166
  // src/geojson-writer.ts
3086
- var GeoJSONWriter;
3087
- var init_geojson_writer = __esm({
3088
- "src/geojson-writer.ts"() {
3089
- init_geojson_encoder();
3090
- GeoJSONWriter = {
3091
- id: "geojson",
3092
- version: "latest",
3093
- module: "geojson",
3094
- name: "GeoJSON",
3095
- extensions: ["geojson"],
3096
- mimeTypes: ["application/geo+json"],
3097
- options: {
3098
- geojson: {
3099
- featureArray: false,
3100
- geometryColumn: null
3101
- }
3102
- },
3103
- text: true,
3104
- encodeInBatches: (tableIterator, options) => encodeTableAsGeojsonInBatches(tableIterator, options)
3105
- };
3106
- }
3107
- });
3108
-
3109
- // src/index.ts
3110
- var src_exports = {};
3111
- __export(src_exports, {
3112
- JSONLoader: () => JSONLoader,
3113
- JSONWriter: () => JSONWriter,
3114
- NDJSONLoader: () => NDJSONLoader,
3115
- _ClarinetParser: () => ClarinetParser,
3116
- _GeoJSONLoader: () => GeoJSONLoader,
3117
- _GeoJSONWorkerLoader: () => GeoJSONWorkerLoader,
3118
- _GeoJSONWriter: () => GeoJSONWriter,
3119
- _JSONPath: () => JSONPath,
3120
- _rebuildJsonObject: () => rebuildJsonObject
3121
- });
3122
- var init_src4 = __esm({
3123
- "src/index.ts"() {
3124
- init_json_loader();
3125
- init_ndjson_loader();
3126
- init_json_writer();
3127
- init_geojson_loader();
3128
- init_geojson_writer();
3129
- init_jsonpath();
3130
- init_clarinet();
3131
- init_parse_json_in_batches();
3132
- }
3133
- });
3134
-
3135
- // src/bundle.ts
3136
- var require_bundle = __commonJS({
3137
- "src/bundle.ts"(exports, module) {
3138
- var moduleExports = (init_src4(), src_exports);
3139
- globalThis.loaders = globalThis.loaders || {};
3140
- module.exports = Object.assign(globalThis.loaders, moduleExports);
3141
- }
3142
- });
3143
- require_bundle();
3167
+ var GeoJSONWriter = {
3168
+ id: "geojson",
3169
+ version: "latest",
3170
+ module: "geojson",
3171
+ name: "GeoJSON",
3172
+ extensions: ["geojson"],
3173
+ mimeTypes: ["application/geo+json"],
3174
+ options: {
3175
+ geojson: {
3176
+ featureArray: false,
3177
+ geometryColumn: null
3178
+ }
3179
+ },
3180
+ text: true,
3181
+ encodeInBatches: (tableIterator, options) => encodeTableAsGeojsonInBatches(tableIterator, options)
3182
+ };
3183
+ return __toCommonJS(src_exports);
3144
3184
  })();
3185
+ return __exports__;
3186
+ });