@noormdev/sdk 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (46) hide show
  1. package/dist/chunk-5AYPF5D5.js +943 -0
  2. package/dist/chunk-5AYPF5D5.js.map +1 -0
  3. package/dist/chunk-D2XW2UOP.js +42 -0
  4. package/dist/chunk-D2XW2UOP.js.map +1 -0
  5. package/dist/chunk-DE3NJ22A.js +308 -0
  6. package/dist/chunk-DE3NJ22A.js.map +1 -0
  7. package/dist/chunk-DLQES4PM.js +3136 -0
  8. package/dist/chunk-DLQES4PM.js.map +1 -0
  9. package/dist/chunk-TBRUDUBQ.js +1099 -0
  10. package/dist/chunk-TBRUDUBQ.js.map +1 -0
  11. package/dist/chunk-UOFJT5PY.js +1499 -0
  12. package/dist/chunk-UOFJT5PY.js.map +1 -0
  13. package/dist/chunk-YJBKNUTP.js +7233 -0
  14. package/dist/chunk-YJBKNUTP.js.map +1 -0
  15. package/dist/csv-T5P3IN4K.js +7 -0
  16. package/dist/csv-T5P3IN4K.js.map +1 -0
  17. package/dist/engine-GMQXUPNB.js +11 -0
  18. package/dist/{engine-B4JH5RQJ.js.map → engine-GMQXUPNB.js.map} +1 -1
  19. package/dist/index.d.ts +3316 -1006
  20. package/dist/index.js +26662 -6922
  21. package/dist/index.js.map +1 -1
  22. package/dist/json5-LNT3RGJ7.js +7 -0
  23. package/dist/json5-LNT3RGJ7.js.map +1 -0
  24. package/dist/mssql-3NNVV77C.js +121 -0
  25. package/dist/mssql-3NNVV77C.js.map +1 -0
  26. package/dist/{mysql-C2DR4TF7.js → mysql-UPMQUBLE.js} +5 -3
  27. package/dist/mysql-UPMQUBLE.js.map +1 -0
  28. package/dist/{postgres-SIDJBSIT.js → postgres-CPVTCR7W.js} +5 -3
  29. package/dist/postgres-CPVTCR7W.js.map +1 -0
  30. package/dist/{sqlite-5VZTBN5J.js → sqlite-F3ZSSDUM.js} +5 -3
  31. package/dist/sqlite-F3ZSSDUM.js.map +1 -0
  32. package/dist/sqlite-bun-LMHUMGQI.js +60 -0
  33. package/dist/sqlite-bun-LMHUMGQI.js.map +1 -0
  34. package/dist/storage-WQURRPCA.js +8 -0
  35. package/dist/storage-WQURRPCA.js.map +1 -0
  36. package/dist/yaml-XI7RQ2D5.js +7 -0
  37. package/dist/yaml-XI7RQ2D5.js.map +1 -0
  38. package/package.json +8 -4
  39. package/dist/chunk-MERTHCAJ.js +0 -299
  40. package/dist/chunk-MERTHCAJ.js.map +0 -1
  41. package/dist/engine-B4JH5RQJ.js +0 -3
  42. package/dist/mssql-T4M7OGEC.js +0 -46
  43. package/dist/mssql-T4M7OGEC.js.map +0 -1
  44. package/dist/mysql-C2DR4TF7.js.map +0 -1
  45. package/dist/postgres-SIDJBSIT.js.map +0 -1
  46. package/dist/sqlite-5VZTBN5J.js.map +0 -1
@@ -0,0 +1,1499 @@
1
+ import { createRequire } from 'module';
2
+ import { readFile } from 'fs/promises';
3
+
4
+ createRequire(import.meta.url);
5
+
6
+ // node_modules/csv-parse/lib/api/CsvError.js
7
+ var CsvError = class _CsvError extends Error {
8
+ constructor(code, message, options, ...contexts) {
9
+ if (Array.isArray(message)) message = message.join(" ").trim();
10
+ super(message);
11
+ if (Error.captureStackTrace !== void 0) {
12
+ Error.captureStackTrace(this, _CsvError);
13
+ }
14
+ this.code = code;
15
+ for (const context of contexts) {
16
+ for (const key in context) {
17
+ const value = context[key];
18
+ this[key] = Buffer.isBuffer(value) ? value.toString(options.encoding) : value == null ? value : JSON.parse(JSON.stringify(value));
19
+ }
20
+ }
21
+ }
22
+ };
23
+
24
+ // node_modules/csv-parse/lib/utils/is_object.js
25
+ var is_object = function(obj) {
26
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj);
27
+ };
28
+
29
+ // node_modules/csv-parse/lib/api/normalize_columns_array.js
30
+ var normalize_columns_array = function(columns) {
31
+ const normalizedColumns = [];
32
+ for (let i = 0, l = columns.length; i < l; i++) {
33
+ const column = columns[i];
34
+ if (column === void 0 || column === null || column === false) {
35
+ normalizedColumns[i] = { disabled: true };
36
+ } else if (typeof column === "string") {
37
+ normalizedColumns[i] = { name: column };
38
+ } else if (is_object(column)) {
39
+ if (typeof column.name !== "string") {
40
+ throw new CsvError("CSV_OPTION_COLUMNS_MISSING_NAME", [
41
+ "Option columns missing name:",
42
+ `property "name" is required at position ${i}`,
43
+ "when column is an object literal"
44
+ ]);
45
+ }
46
+ normalizedColumns[i] = column;
47
+ } else {
48
+ throw new CsvError("CSV_INVALID_COLUMN_DEFINITION", [
49
+ "Invalid column definition:",
50
+ "expect a string or a literal object,",
51
+ `got ${JSON.stringify(column)} at position ${i}`
52
+ ]);
53
+ }
54
+ }
55
+ return normalizedColumns;
56
+ };
57
+
58
+ // node_modules/csv-parse/lib/utils/ResizeableBuffer.js
59
+ var ResizeableBuffer = class {
60
+ constructor(size = 100) {
61
+ this.size = size;
62
+ this.length = 0;
63
+ this.buf = Buffer.allocUnsafe(size);
64
+ }
65
+ prepend(val) {
66
+ if (Buffer.isBuffer(val)) {
67
+ const length = this.length + val.length;
68
+ if (length >= this.size) {
69
+ this.resize();
70
+ if (length >= this.size) {
71
+ throw Error("INVALID_BUFFER_STATE");
72
+ }
73
+ }
74
+ const buf = this.buf;
75
+ this.buf = Buffer.allocUnsafe(this.size);
76
+ val.copy(this.buf, 0);
77
+ buf.copy(this.buf, val.length);
78
+ this.length += val.length;
79
+ } else {
80
+ const length = this.length++;
81
+ if (length === this.size) {
82
+ this.resize();
83
+ }
84
+ const buf = this.clone();
85
+ this.buf[0] = val;
86
+ buf.copy(this.buf, 1, 0, length);
87
+ }
88
+ }
89
+ append(val) {
90
+ const length = this.length++;
91
+ if (length === this.size) {
92
+ this.resize();
93
+ }
94
+ this.buf[length] = val;
95
+ }
96
+ clone() {
97
+ return Buffer.from(this.buf.slice(0, this.length));
98
+ }
99
+ resize() {
100
+ const length = this.length;
101
+ this.size = this.size * 2;
102
+ const buf = Buffer.allocUnsafe(this.size);
103
+ this.buf.copy(buf, 0, 0, length);
104
+ this.buf = buf;
105
+ }
106
+ toString(encoding) {
107
+ if (encoding) {
108
+ return this.buf.slice(0, this.length).toString(encoding);
109
+ } else {
110
+ return Uint8Array.prototype.slice.call(this.buf.slice(0, this.length));
111
+ }
112
+ }
113
+ toJSON() {
114
+ return this.toString("utf8");
115
+ }
116
+ reset() {
117
+ this.length = 0;
118
+ }
119
+ };
120
+ var ResizeableBuffer_default = ResizeableBuffer;
121
+
122
+ // node_modules/csv-parse/lib/api/init_state.js
123
+ var np = 12;
124
+ var cr = 13;
125
+ var nl = 10;
126
+ var space = 32;
127
+ var tab = 9;
128
+ var init_state = function(options) {
129
+ return {
130
+ bomSkipped: false,
131
+ bufBytesStart: 0,
132
+ castField: options.cast_function,
133
+ commenting: false,
134
+ // Current error encountered by a record
135
+ error: void 0,
136
+ enabled: options.from_line === 1,
137
+ escaping: false,
138
+ escapeIsQuote: Buffer.isBuffer(options.escape) && Buffer.isBuffer(options.quote) && Buffer.compare(options.escape, options.quote) === 0,
139
+ // columns can be `false`, `true`, `Array`
140
+ expectedRecordLength: Array.isArray(options.columns) ? options.columns.length : void 0,
141
+ field: new ResizeableBuffer_default(20),
142
+ firstLineToHeaders: options.cast_first_line_to_header,
143
+ needMoreDataSize: Math.max(
144
+ // Skip if the remaining buffer smaller than comment
145
+ options.comment !== null ? options.comment.length : 0,
146
+ ...options.delimiter.map((delimiter) => delimiter.length),
147
+ // Skip if the remaining buffer can be escape sequence
148
+ options.quote !== null ? options.quote.length : 0
149
+ ),
150
+ previousBuf: void 0,
151
+ quoting: false,
152
+ stop: false,
153
+ rawBuffer: new ResizeableBuffer_default(100),
154
+ record: [],
155
+ recordHasError: false,
156
+ record_length: 0,
157
+ recordDelimiterMaxLength: options.record_delimiter.length === 0 ? 0 : Math.max(...options.record_delimiter.map((v) => v.length)),
158
+ trimChars: [
159
+ Buffer.from(" ", options.encoding)[0],
160
+ Buffer.from(" ", options.encoding)[0]
161
+ ],
162
+ wasQuoting: false,
163
+ wasRowDelimiter: false,
164
+ timchars: [
165
+ Buffer.from(Buffer.from([cr], "utf8").toString(), options.encoding),
166
+ Buffer.from(Buffer.from([nl], "utf8").toString(), options.encoding),
167
+ Buffer.from(Buffer.from([np], "utf8").toString(), options.encoding),
168
+ Buffer.from(Buffer.from([space], "utf8").toString(), options.encoding),
169
+ Buffer.from(Buffer.from([tab], "utf8").toString(), options.encoding)
170
+ ]
171
+ };
172
+ };
173
+
174
+ // node_modules/csv-parse/lib/utils/underscore.js
175
+ var underscore = function(str) {
176
+ return str.replace(/([A-Z])/g, function(_, match) {
177
+ return "_" + match.toLowerCase();
178
+ });
179
+ };
180
+
181
+ // node_modules/csv-parse/lib/api/normalize_options.js
182
+ var normalize_options = function(opts) {
183
+ const options = {};
184
+ for (const opt in opts) {
185
+ options[underscore(opt)] = opts[opt];
186
+ }
187
+ if (options.encoding === void 0 || options.encoding === true) {
188
+ options.encoding = "utf8";
189
+ } else if (options.encoding === null || options.encoding === false) {
190
+ options.encoding = null;
191
+ } else if (typeof options.encoding !== "string" && options.encoding !== null) {
192
+ throw new CsvError(
193
+ "CSV_INVALID_OPTION_ENCODING",
194
+ [
195
+ "Invalid option encoding:",
196
+ "encoding must be a string or null to return a buffer,",
197
+ `got ${JSON.stringify(options.encoding)}`
198
+ ],
199
+ options
200
+ );
201
+ }
202
+ if (options.bom === void 0 || options.bom === null || options.bom === false) {
203
+ options.bom = false;
204
+ } else if (options.bom !== true) {
205
+ throw new CsvError(
206
+ "CSV_INVALID_OPTION_BOM",
207
+ [
208
+ "Invalid option bom:",
209
+ "bom must be true,",
210
+ `got ${JSON.stringify(options.bom)}`
211
+ ],
212
+ options
213
+ );
214
+ }
215
+ options.cast_function = null;
216
+ if (options.cast === void 0 || options.cast === null || options.cast === false || options.cast === "") {
217
+ options.cast = void 0;
218
+ } else if (typeof options.cast === "function") {
219
+ options.cast_function = options.cast;
220
+ options.cast = true;
221
+ } else if (options.cast !== true) {
222
+ throw new CsvError(
223
+ "CSV_INVALID_OPTION_CAST",
224
+ [
225
+ "Invalid option cast:",
226
+ "cast must be true or a function,",
227
+ `got ${JSON.stringify(options.cast)}`
228
+ ],
229
+ options
230
+ );
231
+ }
232
+ if (options.cast_date === void 0 || options.cast_date === null || options.cast_date === false || options.cast_date === "") {
233
+ options.cast_date = false;
234
+ } else if (options.cast_date === true) {
235
+ options.cast_date = function(value) {
236
+ const date = Date.parse(value);
237
+ return !isNaN(date) ? new Date(date) : value;
238
+ };
239
+ } else if (typeof options.cast_date !== "function") {
240
+ throw new CsvError(
241
+ "CSV_INVALID_OPTION_CAST_DATE",
242
+ [
243
+ "Invalid option cast_date:",
244
+ "cast_date must be true or a function,",
245
+ `got ${JSON.stringify(options.cast_date)}`
246
+ ],
247
+ options
248
+ );
249
+ }
250
+ options.cast_first_line_to_header = void 0;
251
+ if (options.columns === true) {
252
+ options.cast_first_line_to_header = void 0;
253
+ } else if (typeof options.columns === "function") {
254
+ options.cast_first_line_to_header = options.columns;
255
+ options.columns = true;
256
+ } else if (Array.isArray(options.columns)) {
257
+ options.columns = normalize_columns_array(options.columns);
258
+ } else if (options.columns === void 0 || options.columns === null || options.columns === false) {
259
+ options.columns = false;
260
+ } else {
261
+ throw new CsvError(
262
+ "CSV_INVALID_OPTION_COLUMNS",
263
+ [
264
+ "Invalid option columns:",
265
+ "expect an array, a function or true,",
266
+ `got ${JSON.stringify(options.columns)}`
267
+ ],
268
+ options
269
+ );
270
+ }
271
+ if (options.group_columns_by_name === void 0 || options.group_columns_by_name === null || options.group_columns_by_name === false) {
272
+ options.group_columns_by_name = false;
273
+ } else if (options.group_columns_by_name !== true) {
274
+ throw new CsvError(
275
+ "CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
276
+ [
277
+ "Invalid option group_columns_by_name:",
278
+ "expect an boolean,",
279
+ `got ${JSON.stringify(options.group_columns_by_name)}`
280
+ ],
281
+ options
282
+ );
283
+ } else if (options.columns === false) {
284
+ throw new CsvError(
285
+ "CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
286
+ [
287
+ "Invalid option group_columns_by_name:",
288
+ "the `columns` mode must be activated."
289
+ ],
290
+ options
291
+ );
292
+ }
293
+ if (options.comment === void 0 || options.comment === null || options.comment === false || options.comment === "") {
294
+ options.comment = null;
295
+ } else {
296
+ if (typeof options.comment === "string") {
297
+ options.comment = Buffer.from(options.comment, options.encoding);
298
+ }
299
+ if (!Buffer.isBuffer(options.comment)) {
300
+ throw new CsvError(
301
+ "CSV_INVALID_OPTION_COMMENT",
302
+ [
303
+ "Invalid option comment:",
304
+ "comment must be a buffer or a string,",
305
+ `got ${JSON.stringify(options.comment)}`
306
+ ],
307
+ options
308
+ );
309
+ }
310
+ }
311
+ if (options.comment_no_infix === void 0 || options.comment_no_infix === null || options.comment_no_infix === false) {
312
+ options.comment_no_infix = false;
313
+ } else if (options.comment_no_infix !== true) {
314
+ throw new CsvError(
315
+ "CSV_INVALID_OPTION_COMMENT",
316
+ [
317
+ "Invalid option comment_no_infix:",
318
+ "value must be a boolean,",
319
+ `got ${JSON.stringify(options.comment_no_infix)}`
320
+ ],
321
+ options
322
+ );
323
+ }
324
+ const delimiter_json = JSON.stringify(options.delimiter);
325
+ if (!Array.isArray(options.delimiter))
326
+ options.delimiter = [options.delimiter];
327
+ if (options.delimiter.length === 0) {
328
+ throw new CsvError(
329
+ "CSV_INVALID_OPTION_DELIMITER",
330
+ [
331
+ "Invalid option delimiter:",
332
+ "delimiter must be a non empty string or buffer or array of string|buffer,",
333
+ `got ${delimiter_json}`
334
+ ],
335
+ options
336
+ );
337
+ }
338
+ options.delimiter = options.delimiter.map(function(delimiter) {
339
+ if (delimiter === void 0 || delimiter === null || delimiter === false) {
340
+ return Buffer.from(",", options.encoding);
341
+ }
342
+ if (typeof delimiter === "string") {
343
+ delimiter = Buffer.from(delimiter, options.encoding);
344
+ }
345
+ if (!Buffer.isBuffer(delimiter) || delimiter.length === 0) {
346
+ throw new CsvError(
347
+ "CSV_INVALID_OPTION_DELIMITER",
348
+ [
349
+ "Invalid option delimiter:",
350
+ "delimiter must be a non empty string or buffer or array of string|buffer,",
351
+ `got ${delimiter_json}`
352
+ ],
353
+ options
354
+ );
355
+ }
356
+ return delimiter;
357
+ });
358
+ if (options.escape === void 0 || options.escape === true) {
359
+ options.escape = Buffer.from('"', options.encoding);
360
+ } else if (typeof options.escape === "string") {
361
+ options.escape = Buffer.from(options.escape, options.encoding);
362
+ } else if (options.escape === null || options.escape === false) {
363
+ options.escape = null;
364
+ }
365
+ if (options.escape !== null) {
366
+ if (!Buffer.isBuffer(options.escape)) {
367
+ throw new Error(
368
+ `Invalid Option: escape must be a buffer, a string or a boolean, got ${JSON.stringify(options.escape)}`
369
+ );
370
+ }
371
+ }
372
+ if (options.from === void 0 || options.from === null) {
373
+ options.from = 1;
374
+ } else {
375
+ if (typeof options.from === "string" && /\d+/.test(options.from)) {
376
+ options.from = parseInt(options.from);
377
+ }
378
+ if (Number.isInteger(options.from)) {
379
+ if (options.from < 0) {
380
+ throw new Error(
381
+ `Invalid Option: from must be a positive integer, got ${JSON.stringify(opts.from)}`
382
+ );
383
+ }
384
+ } else {
385
+ throw new Error(
386
+ `Invalid Option: from must be an integer, got ${JSON.stringify(options.from)}`
387
+ );
388
+ }
389
+ }
390
+ if (options.from_line === void 0 || options.from_line === null) {
391
+ options.from_line = 1;
392
+ } else {
393
+ if (typeof options.from_line === "string" && /\d+/.test(options.from_line)) {
394
+ options.from_line = parseInt(options.from_line);
395
+ }
396
+ if (Number.isInteger(options.from_line)) {
397
+ if (options.from_line <= 0) {
398
+ throw new Error(
399
+ `Invalid Option: from_line must be a positive integer greater than 0, got ${JSON.stringify(opts.from_line)}`
400
+ );
401
+ }
402
+ } else {
403
+ throw new Error(
404
+ `Invalid Option: from_line must be an integer, got ${JSON.stringify(opts.from_line)}`
405
+ );
406
+ }
407
+ }
408
+ if (options.ignore_last_delimiters === void 0 || options.ignore_last_delimiters === null) {
409
+ options.ignore_last_delimiters = false;
410
+ } else if (typeof options.ignore_last_delimiters === "number") {
411
+ options.ignore_last_delimiters = Math.floor(options.ignore_last_delimiters);
412
+ if (options.ignore_last_delimiters === 0) {
413
+ options.ignore_last_delimiters = false;
414
+ }
415
+ } else if (typeof options.ignore_last_delimiters !== "boolean") {
416
+ throw new CsvError(
417
+ "CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS",
418
+ [
419
+ "Invalid option `ignore_last_delimiters`:",
420
+ "the value must be a boolean value or an integer,",
421
+ `got ${JSON.stringify(options.ignore_last_delimiters)}`
422
+ ],
423
+ options
424
+ );
425
+ }
426
+ if (options.ignore_last_delimiters === true && options.columns === false) {
427
+ throw new CsvError(
428
+ "CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS",
429
+ [
430
+ "The option `ignore_last_delimiters`",
431
+ "requires the activation of the `columns` option"
432
+ ],
433
+ options
434
+ );
435
+ }
436
+ if (options.info === void 0 || options.info === null || options.info === false) {
437
+ options.info = false;
438
+ } else if (options.info !== true) {
439
+ throw new Error(
440
+ `Invalid Option: info must be true, got ${JSON.stringify(options.info)}`
441
+ );
442
+ }
443
+ if (options.max_record_size === void 0 || options.max_record_size === null || options.max_record_size === false) {
444
+ options.max_record_size = 0;
445
+ } else if (Number.isInteger(options.max_record_size) && options.max_record_size >= 0) ; else if (typeof options.max_record_size === "string" && /\d+/.test(options.max_record_size)) {
446
+ options.max_record_size = parseInt(options.max_record_size);
447
+ } else {
448
+ throw new Error(
449
+ `Invalid Option: max_record_size must be a positive integer, got ${JSON.stringify(options.max_record_size)}`
450
+ );
451
+ }
452
+ if (options.objname === void 0 || options.objname === null || options.objname === false) {
453
+ options.objname = void 0;
454
+ } else if (Buffer.isBuffer(options.objname)) {
455
+ if (options.objname.length === 0) {
456
+ throw new Error(`Invalid Option: objname must be a non empty buffer`);
457
+ }
458
+ if (options.encoding === null) ; else {
459
+ options.objname = options.objname.toString(options.encoding);
460
+ }
461
+ } else if (typeof options.objname === "string") {
462
+ if (options.objname.length === 0) {
463
+ throw new Error(`Invalid Option: objname must be a non empty string`);
464
+ }
465
+ } else if (typeof options.objname === "number") ; else {
466
+ throw new Error(
467
+ `Invalid Option: objname must be a string or a buffer, got ${options.objname}`
468
+ );
469
+ }
470
+ if (options.objname !== void 0) {
471
+ if (typeof options.objname === "number") {
472
+ if (options.columns !== false) {
473
+ throw Error(
474
+ "Invalid Option: objname index cannot be combined with columns or be defined as a field"
475
+ );
476
+ }
477
+ } else {
478
+ if (options.columns === false) {
479
+ throw Error(
480
+ "Invalid Option: objname field must be combined with columns or be defined as an index"
481
+ );
482
+ }
483
+ }
484
+ }
485
+ if (options.on_record === void 0 || options.on_record === null) {
486
+ options.on_record = void 0;
487
+ } else if (typeof options.on_record !== "function") {
488
+ throw new CsvError(
489
+ "CSV_INVALID_OPTION_ON_RECORD",
490
+ [
491
+ "Invalid option `on_record`:",
492
+ "expect a function,",
493
+ `got ${JSON.stringify(options.on_record)}`
494
+ ],
495
+ options
496
+ );
497
+ }
498
+ if (options.on_skip !== void 0 && options.on_skip !== null && typeof options.on_skip !== "function") {
499
+ throw new Error(
500
+ `Invalid Option: on_skip must be a function, got ${JSON.stringify(options.on_skip)}`
501
+ );
502
+ }
503
+ if (options.quote === null || options.quote === false || options.quote === "") {
504
+ options.quote = null;
505
+ } else {
506
+ if (options.quote === void 0 || options.quote === true) {
507
+ options.quote = Buffer.from('"', options.encoding);
508
+ } else if (typeof options.quote === "string") {
509
+ options.quote = Buffer.from(options.quote, options.encoding);
510
+ }
511
+ if (!Buffer.isBuffer(options.quote)) {
512
+ throw new Error(
513
+ `Invalid Option: quote must be a buffer or a string, got ${JSON.stringify(options.quote)}`
514
+ );
515
+ }
516
+ }
517
+ if (options.raw === void 0 || options.raw === null || options.raw === false) {
518
+ options.raw = false;
519
+ } else if (options.raw !== true) {
520
+ throw new Error(
521
+ `Invalid Option: raw must be true, got ${JSON.stringify(options.raw)}`
522
+ );
523
+ }
524
+ if (options.record_delimiter === void 0) {
525
+ options.record_delimiter = [];
526
+ } else if (typeof options.record_delimiter === "string" || Buffer.isBuffer(options.record_delimiter)) {
527
+ if (options.record_delimiter.length === 0) {
528
+ throw new CsvError(
529
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
530
+ [
531
+ "Invalid option `record_delimiter`:",
532
+ "value must be a non empty string or buffer,",
533
+ `got ${JSON.stringify(options.record_delimiter)}`
534
+ ],
535
+ options
536
+ );
537
+ }
538
+ options.record_delimiter = [options.record_delimiter];
539
+ } else if (!Array.isArray(options.record_delimiter)) {
540
+ throw new CsvError(
541
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
542
+ [
543
+ "Invalid option `record_delimiter`:",
544
+ "value must be a string, a buffer or array of string|buffer,",
545
+ `got ${JSON.stringify(options.record_delimiter)}`
546
+ ],
547
+ options
548
+ );
549
+ }
550
+ options.record_delimiter = options.record_delimiter.map(function(rd, i) {
551
+ if (typeof rd !== "string" && !Buffer.isBuffer(rd)) {
552
+ throw new CsvError(
553
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
554
+ [
555
+ "Invalid option `record_delimiter`:",
556
+ "value must be a string, a buffer or array of string|buffer",
557
+ `at index ${i},`,
558
+ `got ${JSON.stringify(rd)}`
559
+ ],
560
+ options
561
+ );
562
+ } else if (rd.length === 0) {
563
+ throw new CsvError(
564
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
565
+ [
566
+ "Invalid option `record_delimiter`:",
567
+ "value must be a non empty string or buffer",
568
+ `at index ${i},`,
569
+ `got ${JSON.stringify(rd)}`
570
+ ],
571
+ options
572
+ );
573
+ }
574
+ if (typeof rd === "string") {
575
+ rd = Buffer.from(rd, options.encoding);
576
+ }
577
+ return rd;
578
+ });
579
+ if (typeof options.relax_column_count === "boolean") ; else if (options.relax_column_count === void 0 || options.relax_column_count === null) {
580
+ options.relax_column_count = false;
581
+ } else {
582
+ throw new Error(
583
+ `Invalid Option: relax_column_count must be a boolean, got ${JSON.stringify(options.relax_column_count)}`
584
+ );
585
+ }
586
+ if (typeof options.relax_column_count_less === "boolean") ; else if (options.relax_column_count_less === void 0 || options.relax_column_count_less === null) {
587
+ options.relax_column_count_less = false;
588
+ } else {
589
+ throw new Error(
590
+ `Invalid Option: relax_column_count_less must be a boolean, got ${JSON.stringify(options.relax_column_count_less)}`
591
+ );
592
+ }
593
+ if (typeof options.relax_column_count_more === "boolean") ; else if (options.relax_column_count_more === void 0 || options.relax_column_count_more === null) {
594
+ options.relax_column_count_more = false;
595
+ } else {
596
+ throw new Error(
597
+ `Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`
598
+ );
599
+ }
600
+ if (typeof options.relax_quotes === "boolean") ; else if (options.relax_quotes === void 0 || options.relax_quotes === null) {
601
+ options.relax_quotes = false;
602
+ } else {
603
+ throw new Error(
604
+ `Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`
605
+ );
606
+ }
607
+ if (typeof options.skip_empty_lines === "boolean") ; else if (options.skip_empty_lines === void 0 || options.skip_empty_lines === null) {
608
+ options.skip_empty_lines = false;
609
+ } else {
610
+ throw new Error(
611
+ `Invalid Option: skip_empty_lines must be a boolean, got ${JSON.stringify(options.skip_empty_lines)}`
612
+ );
613
+ }
614
+ if (typeof options.skip_records_with_empty_values === "boolean") ; else if (options.skip_records_with_empty_values === void 0 || options.skip_records_with_empty_values === null) {
615
+ options.skip_records_with_empty_values = false;
616
+ } else {
617
+ throw new Error(
618
+ `Invalid Option: skip_records_with_empty_values must be a boolean, got ${JSON.stringify(options.skip_records_with_empty_values)}`
619
+ );
620
+ }
621
+ if (typeof options.skip_records_with_error === "boolean") ; else if (options.skip_records_with_error === void 0 || options.skip_records_with_error === null) {
622
+ options.skip_records_with_error = false;
623
+ } else {
624
+ throw new Error(
625
+ `Invalid Option: skip_records_with_error must be a boolean, got ${JSON.stringify(options.skip_records_with_error)}`
626
+ );
627
+ }
628
+ if (options.rtrim === void 0 || options.rtrim === null || options.rtrim === false) {
629
+ options.rtrim = false;
630
+ } else if (options.rtrim !== true) {
631
+ throw new Error(
632
+ `Invalid Option: rtrim must be a boolean, got ${JSON.stringify(options.rtrim)}`
633
+ );
634
+ }
635
+ if (options.ltrim === void 0 || options.ltrim === null || options.ltrim === false) {
636
+ options.ltrim = false;
637
+ } else if (options.ltrim !== true) {
638
+ throw new Error(
639
+ `Invalid Option: ltrim must be a boolean, got ${JSON.stringify(options.ltrim)}`
640
+ );
641
+ }
642
+ if (options.trim === void 0 || options.trim === null || options.trim === false) {
643
+ options.trim = false;
644
+ } else if (options.trim !== true) {
645
+ throw new Error(
646
+ `Invalid Option: trim must be a boolean, got ${JSON.stringify(options.trim)}`
647
+ );
648
+ }
649
+ if (options.trim === true && opts.ltrim !== false) {
650
+ options.ltrim = true;
651
+ } else if (options.ltrim !== true) {
652
+ options.ltrim = false;
653
+ }
654
+ if (options.trim === true && opts.rtrim !== false) {
655
+ options.rtrim = true;
656
+ } else if (options.rtrim !== true) {
657
+ options.rtrim = false;
658
+ }
659
+ if (options.to === void 0 || options.to === null) {
660
+ options.to = -1;
661
+ } else if (options.to !== -1) {
662
+ if (typeof options.to === "string" && /\d+/.test(options.to)) {
663
+ options.to = parseInt(options.to);
664
+ }
665
+ if (Number.isInteger(options.to)) {
666
+ if (options.to <= 0) {
667
+ throw new Error(
668
+ `Invalid Option: to must be a positive integer greater than 0, got ${JSON.stringify(opts.to)}`
669
+ );
670
+ }
671
+ } else {
672
+ throw new Error(
673
+ `Invalid Option: to must be an integer, got ${JSON.stringify(opts.to)}`
674
+ );
675
+ }
676
+ }
677
+ if (options.to_line === void 0 || options.to_line === null) {
678
+ options.to_line = -1;
679
+ } else if (options.to_line !== -1) {
680
+ if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
681
+ options.to_line = parseInt(options.to_line);
682
+ }
683
+ if (Number.isInteger(options.to_line)) {
684
+ if (options.to_line <= 0) {
685
+ throw new Error(
686
+ `Invalid Option: to_line must be a positive integer greater than 0, got ${JSON.stringify(opts.to_line)}`
687
+ );
688
+ }
689
+ } else {
690
+ throw new Error(
691
+ `Invalid Option: to_line must be an integer, got ${JSON.stringify(opts.to_line)}`
692
+ );
693
+ }
694
+ }
695
+ return options;
696
+ };
697
+
698
+ // node_modules/csv-parse/lib/api/index.js
699
+ var isRecordEmpty = function(record) {
700
+ return record.every(
701
+ (field) => field == null || field.toString && field.toString().trim() === ""
702
+ );
703
+ };
704
+ var cr2 = 13;
705
+ var nl2 = 10;
706
+ var boms = {
707
+ // Note, the following are equals:
708
+ // Buffer.from("\ufeff")
709
+ // Buffer.from([239, 187, 191])
710
+ // Buffer.from('EFBBBF', 'hex')
711
+ utf8: Buffer.from([239, 187, 191]),
712
+ // Note, the following are equals:
713
+ // Buffer.from "\ufeff", 'utf16le
714
+ // Buffer.from([255, 254])
715
+ utf16le: Buffer.from([255, 254])
716
+ };
717
+ var transform = function(original_options = {}) {
718
+ const info = {
719
+ bytes: 0,
720
+ comment_lines: 0,
721
+ empty_lines: 0,
722
+ invalid_field_length: 0,
723
+ lines: 1,
724
+ records: 0
725
+ };
726
+ const options = normalize_options(original_options);
727
+ return {
728
+ info,
729
+ original_options,
730
+ options,
731
+ state: init_state(options),
732
+ __needMoreData: function(i, bufLen, end) {
733
+ if (end) return false;
734
+ const { encoding, escape, quote } = this.options;
735
+ const { quoting, needMoreDataSize, recordDelimiterMaxLength } = this.state;
736
+ const numOfCharLeft = bufLen - i - 1;
737
+ const requiredLength = Math.max(
738
+ needMoreDataSize,
739
+ // Skip if the remaining buffer smaller than record delimiter
740
+ // If "record_delimiter" is yet to be discovered:
741
+ // 1. It is equals to `[]` and "recordDelimiterMaxLength" equals `0`
742
+ // 2. We set the length to windows line ending in the current encoding
743
+ // Note, that encoding is known from user or bom discovery at that point
744
+ // recordDelimiterMaxLength,
745
+ recordDelimiterMaxLength === 0 ? Buffer.from("\r\n", encoding).length : recordDelimiterMaxLength,
746
+ // Skip if remaining buffer can be an escaped quote
747
+ quoting ? (escape === null ? 0 : escape.length) + quote.length : 0,
748
+ // Skip if remaining buffer can be record delimiter following the closing quote
749
+ quoting ? quote.length + recordDelimiterMaxLength : 0
750
+ );
751
+ return numOfCharLeft < requiredLength;
752
+ },
753
+ // Central parser implementation
754
+ parse: function(nextBuf, end, push, close) {
755
+ const {
756
+ bom,
757
+ comment_no_infix,
758
+ encoding,
759
+ from_line,
760
+ ltrim,
761
+ max_record_size,
762
+ raw,
763
+ relax_quotes,
764
+ rtrim,
765
+ skip_empty_lines,
766
+ to,
767
+ to_line
768
+ } = this.options;
769
+ let { comment, escape, quote, record_delimiter } = this.options;
770
+ const { bomSkipped, previousBuf, rawBuffer, escapeIsQuote } = this.state;
771
+ let buf;
772
+ if (previousBuf === void 0) {
773
+ if (nextBuf === void 0) {
774
+ close();
775
+ return;
776
+ } else {
777
+ buf = nextBuf;
778
+ }
779
+ } else if (previousBuf !== void 0 && nextBuf === void 0) {
780
+ buf = previousBuf;
781
+ } else {
782
+ buf = Buffer.concat([previousBuf, nextBuf]);
783
+ }
784
+ if (bomSkipped === false) {
785
+ if (bom === false) {
786
+ this.state.bomSkipped = true;
787
+ } else if (buf.length < 3) {
788
+ if (end === false) {
789
+ this.state.previousBuf = buf;
790
+ return;
791
+ }
792
+ } else {
793
+ for (const encoding2 in boms) {
794
+ if (boms[encoding2].compare(buf, 0, boms[encoding2].length) === 0) {
795
+ const bomLength = boms[encoding2].length;
796
+ this.state.bufBytesStart += bomLength;
797
+ buf = buf.slice(bomLength);
798
+ const options2 = normalize_options({
799
+ ...this.original_options,
800
+ encoding: encoding2
801
+ });
802
+ for (const key in options2) {
803
+ this.options[key] = options2[key];
804
+ }
805
+ ({ comment, escape, quote } = this.options);
806
+ break;
807
+ }
808
+ }
809
+ this.state.bomSkipped = true;
810
+ }
811
+ }
812
+ const bufLen = buf.length;
813
+ let pos;
814
+ for (pos = 0; pos < bufLen; pos++) {
815
+ if (this.__needMoreData(pos, bufLen, end)) {
816
+ break;
817
+ }
818
+ if (this.state.wasRowDelimiter === true) {
819
+ this.info.lines++;
820
+ this.state.wasRowDelimiter = false;
821
+ }
822
+ if (to_line !== -1 && this.info.lines > to_line) {
823
+ this.state.stop = true;
824
+ close();
825
+ return;
826
+ }
827
+ if (this.state.quoting === false && record_delimiter.length === 0) {
828
+ const record_delimiterCount = this.__autoDiscoverRecordDelimiter(
829
+ buf,
830
+ pos
831
+ );
832
+ if (record_delimiterCount) {
833
+ record_delimiter = this.options.record_delimiter;
834
+ }
835
+ }
836
+ const chr = buf[pos];
837
+ if (raw === true) {
838
+ rawBuffer.append(chr);
839
+ }
840
+ if ((chr === cr2 || chr === nl2) && this.state.wasRowDelimiter === false) {
841
+ this.state.wasRowDelimiter = true;
842
+ }
843
+ if (this.state.escaping === true) {
844
+ this.state.escaping = false;
845
+ } else {
846
+ if (escape !== null && this.state.quoting === true && this.__isEscape(buf, pos, chr) && pos + escape.length < bufLen) {
847
+ if (escapeIsQuote) {
848
+ if (this.__isQuote(buf, pos + escape.length)) {
849
+ this.state.escaping = true;
850
+ pos += escape.length - 1;
851
+ continue;
852
+ }
853
+ } else {
854
+ this.state.escaping = true;
855
+ pos += escape.length - 1;
856
+ continue;
857
+ }
858
+ }
859
+ if (this.state.commenting === false && this.__isQuote(buf, pos)) {
860
+ if (this.state.quoting === true) {
861
+ const nextChr = buf[pos + quote.length];
862
+ const isNextChrTrimable = rtrim && this.__isCharTrimable(buf, pos + quote.length);
863
+ const isNextChrComment = comment !== null && this.__compareBytes(comment, buf, pos + quote.length, nextChr);
864
+ const isNextChrDelimiter = this.__isDelimiter(
865
+ buf,
866
+ pos + quote.length,
867
+ nextChr
868
+ );
869
+ const isNextChrRecordDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRecordDelimiter(buf, pos + quote.length) : this.__isRecordDelimiter(nextChr, buf, pos + quote.length);
870
+ if (escape !== null && this.__isEscape(buf, pos, chr) && this.__isQuote(buf, pos + escape.length)) {
871
+ pos += escape.length - 1;
872
+ } else if (!nextChr || isNextChrDelimiter || isNextChrRecordDelimiter || isNextChrComment || isNextChrTrimable) {
873
+ this.state.quoting = false;
874
+ this.state.wasQuoting = true;
875
+ pos += quote.length - 1;
876
+ continue;
877
+ } else if (relax_quotes === false) {
878
+ const err = this.__error(
879
+ new CsvError(
880
+ "CSV_INVALID_CLOSING_QUOTE",
881
+ [
882
+ "Invalid Closing Quote:",
883
+ `got "${String.fromCharCode(nextChr)}"`,
884
+ `at line ${this.info.lines}`,
885
+ "instead of delimiter, record delimiter, trimable character",
886
+ "(if activated) or comment"
887
+ ],
888
+ this.options,
889
+ this.__infoField()
890
+ )
891
+ );
892
+ if (err !== void 0) return err;
893
+ } else {
894
+ this.state.quoting = false;
895
+ this.state.wasQuoting = true;
896
+ this.state.field.prepend(quote);
897
+ pos += quote.length - 1;
898
+ }
899
+ } else {
900
+ if (this.state.field.length !== 0) {
901
+ if (relax_quotes === false) {
902
+ const info2 = this.__infoField();
903
+ const bom2 = Object.keys(boms).map(
904
+ (b) => boms[b].equals(this.state.field.toString()) ? b : false
905
+ ).filter(Boolean)[0];
906
+ const err = this.__error(
907
+ new CsvError(
908
+ "INVALID_OPENING_QUOTE",
909
+ [
910
+ "Invalid Opening Quote:",
911
+ `a quote is found on field ${JSON.stringify(info2.column)} at line ${info2.lines}, value is ${JSON.stringify(this.state.field.toString(encoding))}`,
912
+ bom2 ? `(${bom2} bom)` : void 0
913
+ ],
914
+ this.options,
915
+ info2,
916
+ {
917
+ field: this.state.field
918
+ }
919
+ )
920
+ );
921
+ if (err !== void 0) return err;
922
+ }
923
+ } else {
924
+ this.state.quoting = true;
925
+ pos += quote.length - 1;
926
+ continue;
927
+ }
928
+ }
929
+ }
930
+ if (this.state.quoting === false) {
931
+ const recordDelimiterLength = this.__isRecordDelimiter(
932
+ chr,
933
+ buf,
934
+ pos
935
+ );
936
+ if (recordDelimiterLength !== 0) {
937
+ const skipCommentLine = this.state.commenting && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0;
938
+ if (skipCommentLine) {
939
+ this.info.comment_lines++;
940
+ } else {
941
+ if (this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1 : 0) >= from_line) {
942
+ this.state.enabled = true;
943
+ this.__resetField();
944
+ this.__resetRecord();
945
+ pos += recordDelimiterLength - 1;
946
+ continue;
947
+ }
948
+ if (skip_empty_lines === true && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0) {
949
+ this.info.empty_lines++;
950
+ pos += recordDelimiterLength - 1;
951
+ continue;
952
+ }
953
+ this.info.bytes = this.state.bufBytesStart + pos;
954
+ const errField = this.__onField();
955
+ if (errField !== void 0) return errField;
956
+ this.info.bytes = this.state.bufBytesStart + pos + recordDelimiterLength;
957
+ const errRecord = this.__onRecord(push);
958
+ if (errRecord !== void 0) return errRecord;
959
+ if (to !== -1 && this.info.records >= to) {
960
+ this.state.stop = true;
961
+ close();
962
+ return;
963
+ }
964
+ }
965
+ this.state.commenting = false;
966
+ pos += recordDelimiterLength - 1;
967
+ continue;
968
+ }
969
+ if (this.state.commenting) {
970
+ continue;
971
+ }
972
+ if (comment !== null && (comment_no_infix === false || this.state.record.length === 0 && this.state.field.length === 0)) {
973
+ const commentCount = this.__compareBytes(comment, buf, pos, chr);
974
+ if (commentCount !== 0) {
975
+ this.state.commenting = true;
976
+ continue;
977
+ }
978
+ }
979
+ const delimiterLength = this.__isDelimiter(buf, pos, chr);
980
+ if (delimiterLength !== 0) {
981
+ this.info.bytes = this.state.bufBytesStart + pos;
982
+ const errField = this.__onField();
983
+ if (errField !== void 0) return errField;
984
+ pos += delimiterLength - 1;
985
+ continue;
986
+ }
987
+ }
988
+ }
989
+ if (this.state.commenting === false) {
990
+ if (max_record_size !== 0 && this.state.record_length + this.state.field.length > max_record_size) {
991
+ return this.__error(
992
+ new CsvError(
993
+ "CSV_MAX_RECORD_SIZE",
994
+ [
995
+ "Max Record Size:",
996
+ "record exceed the maximum number of tolerated bytes",
997
+ `of ${max_record_size}`,
998
+ `at line ${this.info.lines}`
999
+ ],
1000
+ this.options,
1001
+ this.__infoField()
1002
+ )
1003
+ );
1004
+ }
1005
+ }
1006
+ const lappend = ltrim === false || this.state.quoting === true || this.state.field.length !== 0 || !this.__isCharTrimable(buf, pos);
1007
+ const rappend = rtrim === false || this.state.wasQuoting === false;
1008
+ if (lappend === true && rappend === true) {
1009
+ this.state.field.append(chr);
1010
+ } else if (rtrim === true && !this.__isCharTrimable(buf, pos)) {
1011
+ return this.__error(
1012
+ new CsvError(
1013
+ "CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",
1014
+ [
1015
+ "Invalid Closing Quote:",
1016
+ "found non trimable byte after quote",
1017
+ `at line ${this.info.lines}`
1018
+ ],
1019
+ this.options,
1020
+ this.__infoField()
1021
+ )
1022
+ );
1023
+ } else {
1024
+ if (lappend === false) {
1025
+ pos += this.__isCharTrimable(buf, pos) - 1;
1026
+ }
1027
+ continue;
1028
+ }
1029
+ }
1030
+ if (end === true) {
1031
+ if (this.state.quoting === true) {
1032
+ const err = this.__error(
1033
+ new CsvError(
1034
+ "CSV_QUOTE_NOT_CLOSED",
1035
+ [
1036
+ "Quote Not Closed:",
1037
+ `the parsing is finished with an opening quote at line ${this.info.lines}`
1038
+ ],
1039
+ this.options,
1040
+ this.__infoField()
1041
+ )
1042
+ );
1043
+ if (err !== void 0) return err;
1044
+ } else {
1045
+ if (this.state.wasQuoting === true || this.state.record.length !== 0 || this.state.field.length !== 0) {
1046
+ this.info.bytes = this.state.bufBytesStart + pos;
1047
+ const errField = this.__onField();
1048
+ if (errField !== void 0) return errField;
1049
+ const errRecord = this.__onRecord(push);
1050
+ if (errRecord !== void 0) return errRecord;
1051
+ } else if (this.state.wasRowDelimiter === true) {
1052
+ this.info.empty_lines++;
1053
+ } else if (this.state.commenting === true) {
1054
+ this.info.comment_lines++;
1055
+ }
1056
+ }
1057
+ } else {
1058
+ this.state.bufBytesStart += pos;
1059
+ this.state.previousBuf = buf.slice(pos);
1060
+ }
1061
+ if (this.state.wasRowDelimiter === true) {
1062
+ this.info.lines++;
1063
+ this.state.wasRowDelimiter = false;
1064
+ }
1065
+ },
1066
+ __onRecord: function(push) {
1067
+ const {
1068
+ columns,
1069
+ group_columns_by_name,
1070
+ encoding,
1071
+ info: info2,
1072
+ from,
1073
+ relax_column_count,
1074
+ relax_column_count_less,
1075
+ relax_column_count_more,
1076
+ raw,
1077
+ skip_records_with_empty_values
1078
+ } = this.options;
1079
+ const { enabled, record } = this.state;
1080
+ if (enabled === false) {
1081
+ return this.__resetRecord();
1082
+ }
1083
+ const recordLength = record.length;
1084
+ if (columns === true) {
1085
+ if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
1086
+ this.__resetRecord();
1087
+ return;
1088
+ }
1089
+ return this.__firstLineToColumns(record);
1090
+ }
1091
+ if (columns === false && this.info.records === 0) {
1092
+ this.state.expectedRecordLength = recordLength;
1093
+ }
1094
+ if (recordLength !== this.state.expectedRecordLength) {
1095
+ const err = columns === false ? new CsvError(
1096
+ "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH",
1097
+ [
1098
+ "Invalid Record Length:",
1099
+ `expect ${this.state.expectedRecordLength},`,
1100
+ `got ${recordLength} on line ${this.info.lines}`
1101
+ ],
1102
+ this.options,
1103
+ this.__infoField(),
1104
+ {
1105
+ record
1106
+ }
1107
+ ) : new CsvError(
1108
+ "CSV_RECORD_INCONSISTENT_COLUMNS",
1109
+ [
1110
+ "Invalid Record Length:",
1111
+ `columns length is ${columns.length},`,
1112
+ // rename columns
1113
+ `got ${recordLength} on line ${this.info.lines}`
1114
+ ],
1115
+ this.options,
1116
+ this.__infoField(),
1117
+ {
1118
+ record
1119
+ }
1120
+ );
1121
+ if (relax_column_count === true || relax_column_count_less === true && recordLength < this.state.expectedRecordLength || relax_column_count_more === true && recordLength > this.state.expectedRecordLength) {
1122
+ this.info.invalid_field_length++;
1123
+ this.state.error = err;
1124
+ } else {
1125
+ const finalErr = this.__error(err);
1126
+ if (finalErr) return finalErr;
1127
+ }
1128
+ }
1129
+ if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
1130
+ this.__resetRecord();
1131
+ return;
1132
+ }
1133
+ if (this.state.recordHasError === true) {
1134
+ this.__resetRecord();
1135
+ this.state.recordHasError = false;
1136
+ return;
1137
+ }
1138
+ this.info.records++;
1139
+ if (from === 1 || this.info.records >= from) {
1140
+ const { objname } = this.options;
1141
+ if (columns !== false) {
1142
+ const obj = {};
1143
+ for (let i = 0, l = record.length; i < l; i++) {
1144
+ if (columns[i] === void 0 || columns[i].disabled) continue;
1145
+ if (group_columns_by_name === true && obj[columns[i].name] !== void 0) {
1146
+ if (Array.isArray(obj[columns[i].name])) {
1147
+ obj[columns[i].name] = obj[columns[i].name].concat(record[i]);
1148
+ } else {
1149
+ obj[columns[i].name] = [obj[columns[i].name], record[i]];
1150
+ }
1151
+ } else {
1152
+ obj[columns[i].name] = record[i];
1153
+ }
1154
+ }
1155
+ if (raw === true || info2 === true) {
1156
+ const extRecord = Object.assign(
1157
+ { record: obj },
1158
+ raw === true ? { raw: this.state.rawBuffer.toString(encoding) } : {},
1159
+ info2 === true ? { info: this.__infoRecord() } : {}
1160
+ );
1161
+ const err = this.__push(
1162
+ objname === void 0 ? extRecord : [obj[objname], extRecord],
1163
+ push
1164
+ );
1165
+ if (err) {
1166
+ return err;
1167
+ }
1168
+ } else {
1169
+ const err = this.__push(
1170
+ objname === void 0 ? obj : [obj[objname], obj],
1171
+ push
1172
+ );
1173
+ if (err) {
1174
+ return err;
1175
+ }
1176
+ }
1177
+ } else {
1178
+ if (raw === true || info2 === true) {
1179
+ const extRecord = Object.assign(
1180
+ { record },
1181
+ raw === true ? { raw: this.state.rawBuffer.toString(encoding) } : {},
1182
+ info2 === true ? { info: this.__infoRecord() } : {}
1183
+ );
1184
+ const err = this.__push(
1185
+ objname === void 0 ? extRecord : [record[objname], extRecord],
1186
+ push
1187
+ );
1188
+ if (err) {
1189
+ return err;
1190
+ }
1191
+ } else {
1192
+ const err = this.__push(
1193
+ objname === void 0 ? record : [record[objname], record],
1194
+ push
1195
+ );
1196
+ if (err) {
1197
+ return err;
1198
+ }
1199
+ }
1200
+ }
1201
+ }
1202
+ this.__resetRecord();
1203
+ },
1204
+ __firstLineToColumns: function(record) {
1205
+ const { firstLineToHeaders } = this.state;
1206
+ try {
1207
+ const headers = firstLineToHeaders === void 0 ? record : firstLineToHeaders.call(null, record);
1208
+ if (!Array.isArray(headers)) {
1209
+ return this.__error(
1210
+ new CsvError(
1211
+ "CSV_INVALID_COLUMN_MAPPING",
1212
+ [
1213
+ "Invalid Column Mapping:",
1214
+ "expect an array from column function,",
1215
+ `got ${JSON.stringify(headers)}`
1216
+ ],
1217
+ this.options,
1218
+ this.__infoField(),
1219
+ {
1220
+ headers
1221
+ }
1222
+ )
1223
+ );
1224
+ }
1225
+ const normalizedHeaders = normalize_columns_array(headers);
1226
+ this.state.expectedRecordLength = normalizedHeaders.length;
1227
+ this.options.columns = normalizedHeaders;
1228
+ this.__resetRecord();
1229
+ return;
1230
+ } catch (err) {
1231
+ return err;
1232
+ }
1233
+ },
1234
+ __resetRecord: function() {
1235
+ if (this.options.raw === true) {
1236
+ this.state.rawBuffer.reset();
1237
+ }
1238
+ this.state.error = void 0;
1239
+ this.state.record = [];
1240
+ this.state.record_length = 0;
1241
+ },
1242
+ __onField: function() {
1243
+ const { cast, encoding, rtrim, max_record_size } = this.options;
1244
+ const { enabled, wasQuoting } = this.state;
1245
+ if (enabled === false) {
1246
+ return this.__resetField();
1247
+ }
1248
+ let field = this.state.field.toString(encoding);
1249
+ if (rtrim === true && wasQuoting === false) {
1250
+ field = field.trimRight();
1251
+ }
1252
+ if (cast === true) {
1253
+ const [err, f] = this.__cast(field);
1254
+ if (err !== void 0) return err;
1255
+ field = f;
1256
+ }
1257
+ this.state.record.push(field);
1258
+ if (max_record_size !== 0 && typeof field === "string") {
1259
+ this.state.record_length += field.length;
1260
+ }
1261
+ this.__resetField();
1262
+ },
1263
+ __resetField: function() {
1264
+ this.state.field.reset();
1265
+ this.state.wasQuoting = false;
1266
+ },
1267
+ __push: function(record, push) {
1268
+ const { on_record } = this.options;
1269
+ if (on_record !== void 0) {
1270
+ const info2 = this.__infoRecord();
1271
+ try {
1272
+ record = on_record.call(null, record, info2);
1273
+ } catch (err) {
1274
+ return err;
1275
+ }
1276
+ if (record === void 0 || record === null) {
1277
+ return;
1278
+ }
1279
+ }
1280
+ push(record);
1281
+ },
1282
+ // Return a tuple with the error and the casted value
1283
+ __cast: function(field) {
1284
+ const { columns, relax_column_count } = this.options;
1285
+ const isColumns = Array.isArray(columns);
1286
+ if (isColumns === true && relax_column_count && this.options.columns.length <= this.state.record.length) {
1287
+ return [void 0, void 0];
1288
+ }
1289
+ if (this.state.castField !== null) {
1290
+ try {
1291
+ const info2 = this.__infoField();
1292
+ return [void 0, this.state.castField.call(null, field, info2)];
1293
+ } catch (err) {
1294
+ return [err];
1295
+ }
1296
+ }
1297
+ if (this.__isFloat(field)) {
1298
+ return [void 0, parseFloat(field)];
1299
+ } else if (this.options.cast_date !== false) {
1300
+ const info2 = this.__infoField();
1301
+ return [void 0, this.options.cast_date.call(null, field, info2)];
1302
+ }
1303
+ return [void 0, field];
1304
+ },
1305
+ // Helper to test if a character is a space or a line delimiter
1306
+ __isCharTrimable: function(buf, pos) {
1307
+ const isTrim = (buf2, pos2) => {
1308
+ const { timchars } = this.state;
1309
+ loop1: for (let i = 0; i < timchars.length; i++) {
1310
+ const timchar = timchars[i];
1311
+ for (let j = 0; j < timchar.length; j++) {
1312
+ if (timchar[j] !== buf2[pos2 + j]) continue loop1;
1313
+ }
1314
+ return timchar.length;
1315
+ }
1316
+ return 0;
1317
+ };
1318
+ return isTrim(buf, pos);
1319
+ },
1320
+ // Keep it in case we implement the `cast_int` option
1321
+ // __isInt(value){
1322
+ // // return Number.isInteger(parseInt(value))
1323
+ // // return !isNaN( parseInt( obj ) );
1324
+ // return /^(\-|\+)?[1-9][0-9]*$/.test(value)
1325
+ // }
1326
+ __isFloat: function(value) {
1327
+ return value - parseFloat(value) + 1 >= 0;
1328
+ },
1329
+ __compareBytes: function(sourceBuf, targetBuf, targetPos, firstByte) {
1330
+ if (sourceBuf[0] !== firstByte) return 0;
1331
+ const sourceLength = sourceBuf.length;
1332
+ for (let i = 1; i < sourceLength; i++) {
1333
+ if (sourceBuf[i] !== targetBuf[targetPos + i]) return 0;
1334
+ }
1335
+ return sourceLength;
1336
+ },
1337
+ __isDelimiter: function(buf, pos, chr) {
1338
+ const { delimiter, ignore_last_delimiters } = this.options;
1339
+ if (ignore_last_delimiters === true && this.state.record.length === this.options.columns.length - 1) {
1340
+ return 0;
1341
+ } else if (ignore_last_delimiters !== false && typeof ignore_last_delimiters === "number" && this.state.record.length === ignore_last_delimiters - 1) {
1342
+ return 0;
1343
+ }
1344
+ loop1: for (let i = 0; i < delimiter.length; i++) {
1345
+ const del = delimiter[i];
1346
+ if (del[0] === chr) {
1347
+ for (let j = 1; j < del.length; j++) {
1348
+ if (del[j] !== buf[pos + j]) continue loop1;
1349
+ }
1350
+ return del.length;
1351
+ }
1352
+ }
1353
+ return 0;
1354
+ },
1355
+ __isRecordDelimiter: function(chr, buf, pos) {
1356
+ const { record_delimiter } = this.options;
1357
+ const recordDelimiterLength = record_delimiter.length;
1358
+ loop1: for (let i = 0; i < recordDelimiterLength; i++) {
1359
+ const rd = record_delimiter[i];
1360
+ const rdLength = rd.length;
1361
+ if (rd[0] !== chr) {
1362
+ continue;
1363
+ }
1364
+ for (let j = 1; j < rdLength; j++) {
1365
+ if (rd[j] !== buf[pos + j]) {
1366
+ continue loop1;
1367
+ }
1368
+ }
1369
+ return rd.length;
1370
+ }
1371
+ return 0;
1372
+ },
1373
+ __isEscape: function(buf, pos, chr) {
1374
+ const { escape } = this.options;
1375
+ if (escape === null) return false;
1376
+ const l = escape.length;
1377
+ if (escape[0] === chr) {
1378
+ for (let i = 0; i < l; i++) {
1379
+ if (escape[i] !== buf[pos + i]) {
1380
+ return false;
1381
+ }
1382
+ }
1383
+ return true;
1384
+ }
1385
+ return false;
1386
+ },
1387
+ __isQuote: function(buf, pos) {
1388
+ const { quote } = this.options;
1389
+ if (quote === null) return false;
1390
+ const l = quote.length;
1391
+ for (let i = 0; i < l; i++) {
1392
+ if (quote[i] !== buf[pos + i]) {
1393
+ return false;
1394
+ }
1395
+ }
1396
+ return true;
1397
+ },
1398
+ __autoDiscoverRecordDelimiter: function(buf, pos) {
1399
+ const { encoding } = this.options;
1400
+ const rds = [
1401
+ // Important, the windows line ending must be before mac os 9
1402
+ Buffer.from("\r\n", encoding),
1403
+ Buffer.from("\n", encoding),
1404
+ Buffer.from("\r", encoding)
1405
+ ];
1406
+ loop: for (let i = 0; i < rds.length; i++) {
1407
+ const l = rds[i].length;
1408
+ for (let j = 0; j < l; j++) {
1409
+ if (rds[i][j] !== buf[pos + j]) {
1410
+ continue loop;
1411
+ }
1412
+ }
1413
+ this.options.record_delimiter.push(rds[i]);
1414
+ this.state.recordDelimiterMaxLength = rds[i].length;
1415
+ return rds[i].length;
1416
+ }
1417
+ return 0;
1418
+ },
1419
+ __error: function(msg) {
1420
+ const { encoding, raw, skip_records_with_error } = this.options;
1421
+ const err = typeof msg === "string" ? new Error(msg) : msg;
1422
+ if (skip_records_with_error) {
1423
+ this.state.recordHasError = true;
1424
+ if (this.options.on_skip !== void 0) {
1425
+ try {
1426
+ this.options.on_skip(
1427
+ err,
1428
+ raw ? this.state.rawBuffer.toString(encoding) : void 0
1429
+ );
1430
+ } catch (err2) {
1431
+ return err2;
1432
+ }
1433
+ }
1434
+ return void 0;
1435
+ } else {
1436
+ return err;
1437
+ }
1438
+ },
1439
+ __infoDataSet: function() {
1440
+ return {
1441
+ ...this.info,
1442
+ columns: this.options.columns
1443
+ };
1444
+ },
1445
+ __infoRecord: function() {
1446
+ const { columns, raw, encoding } = this.options;
1447
+ return {
1448
+ ...this.__infoDataSet(),
1449
+ error: this.state.error,
1450
+ header: columns === true,
1451
+ index: this.state.record.length,
1452
+ raw: raw ? this.state.rawBuffer.toString(encoding) : void 0
1453
+ };
1454
+ },
1455
+ __infoField: function() {
1456
+ const { columns } = this.options;
1457
+ const isColumns = Array.isArray(columns);
1458
+ return {
1459
+ ...this.__infoRecord(),
1460
+ column: isColumns === true ? columns.length > this.state.record.length ? columns[this.state.record.length].name : null : this.state.record.length,
1461
+ quoting: this.state.wasQuoting
1462
+ };
1463
+ }
1464
+ };
1465
+ };
1466
+
1467
+ // node_modules/csv-parse/lib/sync.js
1468
+ var parse = function(data, opts = {}) {
1469
+ if (typeof data === "string") {
1470
+ data = Buffer.from(data);
1471
+ }
1472
+ const records = opts && opts.objname ? {} : [];
1473
+ const parser = transform(opts);
1474
+ const push = (record) => {
1475
+ if (parser.options.objname === void 0) records.push(record);
1476
+ else {
1477
+ records[record[0]] = record[1];
1478
+ }
1479
+ };
1480
+ const close = () => {
1481
+ };
1482
+ const error = parser.parse(data, true, push, close);
1483
+ if (error !== void 0) throw error;
1484
+ return records;
1485
+ };
1486
+
1487
+ // src/core/template/loaders/csv.ts
1488
+ async function loadCsv(filepath) {
1489
+ const content = await readFile(filepath, "utf-8");
1490
+ return parse(content, {
1491
+ columns: true,
1492
+ skip_empty_lines: true,
1493
+ trim: true
1494
+ });
1495
+ }
1496
+
1497
+ export { loadCsv };
1498
+ //# sourceMappingURL=chunk-UOFJT5PY.js.map
1499
+ //# sourceMappingURL=chunk-UOFJT5PY.js.map