@konstit/csv 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -463
- package/THIRD_PARTY_NOTICES.md +7 -1
- package/dist/api.d.ts +169 -44
- package/dist/api.js +75 -368
- package/dist/batches.d.ts +250 -7
- package/dist/batches.js +135 -83
- package/dist/cli-command.d.ts +7 -0
- package/dist/cli-command.js +350 -0
- package/dist/cli-schema.d.ts +111 -0
- package/dist/cli-schema.js +219 -0
- package/dist/cli.js +2 -604
- package/dist/file-stream.d.ts +57 -2
- package/dist/file-stream.js +244 -36
- package/dist/files.d.ts +149 -3
- package/dist/files.js +37 -29
- package/dist/filter.d.ts +80 -0
- package/dist/format-bytes.d.ts +1 -0
- package/dist/format-bytes.js +11 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -14
- package/dist/inspect-file.d.ts +12 -0
- package/dist/inspect-file.js +88 -0
- package/dist/latin1-rows.d.ts +5 -0
- package/dist/latin1-rows.js +122 -0
- package/dist/materialize-field.d.ts +3 -0
- package/dist/materialize-field.js +31 -0
- package/dist/native.d.ts +51 -2
- package/dist/native.js +43 -4
- package/dist/normalize.d.ts +32 -2
- package/dist/normalize.js +51 -2
- package/dist/options-snapshot.d.ts +3 -0
- package/dist/options-snapshot.js +51 -0
- package/dist/options.d.ts +25 -10
- package/dist/options.js +0 -6
- package/dist/parser.d.ts +309 -4
- package/dist/parser.js +128 -31
- package/dist/strict-schema.d.ts +5 -3
- package/dist/strict-schema.js +4 -1
- package/dist/types.d.ts +355 -121
- package/dist/zip-reader.d.ts +11 -1
- package/dist/zip-reader.js +12 -3
- package/package.json +44 -29
- package/prebuilds/darwin-arm64/libcsv_native.dylib +0 -0
- package/prebuilds/darwin-x64/libcsv_native.dylib +0 -0
- package/prebuilds/linux-x64/libcsv_native.so +0 -0
- package/prebuilds/manifest.json +9 -8
- package/prebuilds/provenance/darwin-arm64.json +1 -1
- package/prebuilds/provenance/darwin-x64.json +1 -1
- package/prebuilds/provenance/linux-x64.json +1 -1
- package/dist/worker-count.d.ts +0 -2
- package/dist/worker-count.js +0 -96
- package/dist/worker-factory.d.ts +0 -3
- package/dist/worker-factory.js +0 -9
- package/dist/worker-filter.d.ts +0 -29
- package/dist/worker-filter.js +0 -46
- package/dist/worker-module.d.ts +0 -1
- package/dist/worker-module.js +0 -4
- package/dist/worker-pool.d.ts +0 -17
- package/dist/worker-pool.js +0 -290
- package/dist/worker-rows.d.ts +0 -8
- package/dist/worker-rows.js +0 -118
- package/dist/workers/count.worker.d.ts +0 -1
- package/dist/workers/count.worker.js +0 -49
- package/dist/workers/rows.worker.d.ts +0 -1
- package/dist/workers/rows.worker.js +0 -85
package/dist/batches.d.ts
CHANGED
|
@@ -1,47 +1,290 @@
|
|
|
1
1
|
import { type NativePointer } from './native.js';
|
|
2
2
|
import type { CsvColumnBytesCallback, CsvColumnRangeCallback, CsvColumns, CsvFieldRange, CsvRow, CsvScanColumnsCallback, NativeCsvRowCallback } from './types.js';
|
|
3
|
+
declare const visitBatchRows: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A reusable, low-allocation view over one row in a {@link NativeCsvBatch}.
|
|
6
|
+
*
|
|
7
|
+
* `NativeCsvBatch.forEachRow()` moves one instance across the batch instead of
|
|
8
|
+
* allocating a new view for every row. Read the row during the callback; the
|
|
9
|
+
* same object is moved before the next callback. Byte and buffer results are
|
|
10
|
+
* views over the batch's backing storage and must not be retained after the
|
|
11
|
+
* batch is closed.
|
|
12
|
+
*/
|
|
3
13
|
export declare class NativeCsvRowView {
|
|
4
14
|
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a row view over packed batch storage.
|
|
17
|
+
*
|
|
18
|
+
* Most callers should obtain a view from `NativeCsvBatch.forEachRow()`.
|
|
19
|
+
* Direct construction is useful when integrating with a compatible native
|
|
20
|
+
* batch representation.
|
|
21
|
+
*
|
|
22
|
+
* @param data Concatenated field bytes for the batch.
|
|
23
|
+
* @param rowOffsets Row boundaries expressed as indexes into `fieldOffsets`.
|
|
24
|
+
* The array must contain one entry per row plus a final end offset.
|
|
25
|
+
* @param fieldOffsets Field boundaries expressed as byte offsets into `data`.
|
|
26
|
+
* The array must contain one entry per field plus a final end offset.
|
|
27
|
+
* @param rowIndex Initial zero-based row index. The index is checked when a
|
|
28
|
+
* row property or accessor is first read.
|
|
29
|
+
*/
|
|
5
30
|
constructor(data: Buffer, rowOffsets: BigUint64Array, fieldOffsets: BigUint64Array, rowIndex?: number);
|
|
31
|
+
/** Zero-based index of the row currently selected by this view. */
|
|
6
32
|
get rowIndex(): number;
|
|
33
|
+
/** Number of fields in the currently selected row. */
|
|
7
34
|
get fieldCount(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Moves this view to another row in the same batch.
|
|
37
|
+
*
|
|
38
|
+
* @param rowIndex Zero-based row index.
|
|
39
|
+
* @returns This view, so callers can chain the move with a read.
|
|
40
|
+
* @throws {RangeError} If `rowIndex` is outside the row-offset table.
|
|
41
|
+
*/
|
|
8
42
|
moveTo(rowIndex: number): this;
|
|
9
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Returns the byte range for a field in the current row.
|
|
45
|
+
*
|
|
46
|
+
* Column indexes are zero-based and relative to the fields stored in the
|
|
47
|
+
* row. The returned offsets address `data` directly.
|
|
48
|
+
*
|
|
49
|
+
* @param columnIndex Zero-based field index.
|
|
50
|
+
* @returns A half-open byte range, or `null` when the row has no such field.
|
|
51
|
+
* @throws {RangeError} If the row or offset table is malformed.
|
|
52
|
+
*/
|
|
10
53
|
range(columnIndex: number): CsvFieldRange | null;
|
|
11
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Returns a borrowed byte view for a field in the current row.
|
|
56
|
+
*
|
|
57
|
+
* The returned view shares the batch backing storage; consume it before the
|
|
58
|
+
* originating batch is closed.
|
|
59
|
+
*
|
|
60
|
+
* @param columnIndex Zero-based field index.
|
|
61
|
+
* @returns A borrowed byte view, or `null` when the field is absent.
|
|
62
|
+
*/
|
|
12
63
|
bytes(columnIndex: number): Uint8Array | null;
|
|
13
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Returns a borrowed `Buffer` view for a field in the current row.
|
|
66
|
+
*
|
|
67
|
+
* The returned buffer shares the batch backing storage and is invalid once
|
|
68
|
+
* the originating batch is closed.
|
|
69
|
+
*
|
|
70
|
+
* @param columnIndex Zero-based field index.
|
|
71
|
+
* @returns A borrowed buffer, or `null` when the field is absent.
|
|
72
|
+
*/
|
|
14
73
|
buffer(columnIndex: number): Buffer | null;
|
|
15
|
-
|
|
16
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Decodes a field as UTF-8 text.
|
|
76
|
+
*
|
|
77
|
+
* @param columnIndex Zero-based field index.
|
|
78
|
+
* @returns The decoded field, or `null` when the field is absent.
|
|
79
|
+
*/
|
|
17
80
|
get(columnIndex: number): string | null;
|
|
18
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Materializes selected fields from the current row in the requested order.
|
|
83
|
+
*
|
|
84
|
+
* Missing fields are represented by empty strings, matching `rowsInto()`.
|
|
85
|
+
*
|
|
86
|
+
* @param columns Zero-based field indexes. Duplicate indexes are allowed for
|
|
87
|
+
* this low-level accessor.
|
|
88
|
+
* @returns A newly allocated array of decoded UTF-8 strings.
|
|
89
|
+
*/
|
|
19
90
|
pick(columns: CsvColumns): string[];
|
|
91
|
+
static [visitBatchRows](batch: NativeCsvBatch, callback: NativeCsvRowCallback): void;
|
|
20
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Owns one native parser output batch and exposes low-allocation field views.
|
|
95
|
+
*
|
|
96
|
+
* Batches returned by `NativeCsvParser` own native memory until `close()` or
|
|
97
|
+
* disposal. `dataView()`, offset arrays, and field byte views borrow that
|
|
98
|
+
* memory; release or consume them before closing the batch. Use `using` when
|
|
99
|
+
* iterating batches to make this lifetime explicit.
|
|
100
|
+
*
|
|
101
|
+
* A batch contains the fields emitted by the parser for that operation. When a
|
|
102
|
+
* projected operation was used, column indexes refer to the projected fields
|
|
103
|
+
* in their emitted order.
|
|
104
|
+
*/
|
|
21
105
|
export declare class NativeCsvBatch {
|
|
22
106
|
#private;
|
|
107
|
+
/**
|
|
108
|
+
* Wraps a native batch handle.
|
|
109
|
+
*
|
|
110
|
+
* Callers normally receive instances from `NativeCsvParser`; this constructor
|
|
111
|
+
* is exposed for integrations that already own a compatible native handle.
|
|
112
|
+
*
|
|
113
|
+
* @param handle Native batch pointer returned by the parser ABI. Ownership of
|
|
114
|
+
* the handle transfers to this wrapper; do not wrap the same handle in a
|
|
115
|
+
* second `NativeCsvBatch` instance.
|
|
116
|
+
*/
|
|
23
117
|
constructor(handle: NativePointer);
|
|
118
|
+
/** Whether this batch has released its native handle. */
|
|
24
119
|
get closed(): boolean;
|
|
120
|
+
/** Number of complete rows stored in this batch. */
|
|
25
121
|
get rowCount(): number;
|
|
122
|
+
/** Total number of fields across all rows in this batch. */
|
|
26
123
|
get totalFields(): number;
|
|
124
|
+
/** Number of bytes in the concatenated field-data buffer. */
|
|
27
125
|
get dataLength(): number;
|
|
126
|
+
/**
|
|
127
|
+
* Materializes every field as a UTF-8 string.
|
|
128
|
+
*
|
|
129
|
+
* @returns A newly allocated array containing one string array per row.
|
|
130
|
+
* Missing fields are not padded because this overload returns all stored fields.
|
|
131
|
+
*/
|
|
28
132
|
rows(): CsvRow[];
|
|
133
|
+
/**
|
|
134
|
+
* Visits each row through one reusable {@link NativeCsvRowView}.
|
|
135
|
+
*
|
|
136
|
+
* The callback must be synchronous. Row access is valid only during its call.
|
|
137
|
+
* Copy borrowed bytes before closing the batch.
|
|
138
|
+
*
|
|
139
|
+
* @param callback Function invoked with the reusable row view and its row index.
|
|
140
|
+
*/
|
|
29
141
|
forEachRow(callback: NativeCsvRowCallback): void;
|
|
142
|
+
/**
|
|
143
|
+
* Materializes rows into a caller-owned reusable result array.
|
|
144
|
+
*
|
|
145
|
+
* `target` and its existing row arrays are resized and overwritten in place;
|
|
146
|
+
* this avoids allocating a new outer or inner array for every batch. If
|
|
147
|
+
* `columns` is supplied, each row is emitted in that requested order and a
|
|
148
|
+
* missing field is represented by `''`.
|
|
149
|
+
*
|
|
150
|
+
* @param target Array to fill. It is truncated or extended to `rowCount`.
|
|
151
|
+
* @param columns Optional zero-based field indexes relative to this batch.
|
|
152
|
+
* Duplicate indexes are rejected.
|
|
153
|
+
* @returns The same `target` array passed by the caller.
|
|
154
|
+
* @throws {RangeError} If a column index is invalid, repeated, or an offset
|
|
155
|
+
* exceeds the batch backing storage.
|
|
156
|
+
*/
|
|
30
157
|
rowsInto(target: CsvRow[], columns?: CsvColumns): CsvRow[];
|
|
158
|
+
/**
|
|
159
|
+
* Returns the concatenated field bytes as a borrowed `Buffer`.
|
|
160
|
+
*
|
|
161
|
+
* The buffer is backed by native batch storage and must not be used after
|
|
162
|
+
* `close()`.
|
|
163
|
+
*/
|
|
31
164
|
data(): Buffer;
|
|
165
|
+
/**
|
|
166
|
+
* Returns the concatenated field bytes as a borrowed `Uint8Array`.
|
|
167
|
+
*
|
|
168
|
+
* This view shares storage with `data()` and remains valid only while the
|
|
169
|
+
* batch is open.
|
|
170
|
+
*/
|
|
32
171
|
dataView(): Uint8Array;
|
|
172
|
+
/**
|
|
173
|
+
* Returns borrowed row boundaries as a `BigUint64Array`.
|
|
174
|
+
*
|
|
175
|
+
* Each value is a field index into `fieldOffsets`; the array has
|
|
176
|
+
* `rowCount + 1` entries. Offsets may exceed `Number.MAX_SAFE_INTEGER`, so
|
|
177
|
+
* keep them as `bigint` unless a checked conversion is appropriate.
|
|
178
|
+
*/
|
|
33
179
|
rowOffsets(): BigUint64Array;
|
|
180
|
+
/**
|
|
181
|
+
* Returns borrowed field byte boundaries as a `BigUint64Array`.
|
|
182
|
+
*
|
|
183
|
+
* Each value is a byte offset into `data()`; the array has
|
|
184
|
+
* `totalFields + 1` entries. Offsets may exceed `Number.MAX_SAFE_INTEGER`,
|
|
185
|
+
* so keep them as `bigint` unless a checked conversion is appropriate.
|
|
186
|
+
*/
|
|
34
187
|
fieldOffsets(): BigUint64Array;
|
|
188
|
+
/**
|
|
189
|
+
* Returns the number of fields in one row.
|
|
190
|
+
*
|
|
191
|
+
* @param rowIndex Zero-based row index.
|
|
192
|
+
* @throws {RangeError} If `rowIndex` is outside the batch.
|
|
193
|
+
*/
|
|
35
194
|
rowFieldCount(rowIndex: number): number;
|
|
195
|
+
/**
|
|
196
|
+
* Returns a field's byte range within the concatenated batch data.
|
|
197
|
+
*
|
|
198
|
+
* @param rowIndex Zero-based row index.
|
|
199
|
+
* @param columnIndex Zero-based field index relative to that row.
|
|
200
|
+
* @returns A half-open byte range, or `null` when the row has no such field.
|
|
201
|
+
* @throws {RangeError} If the row or offset tables are invalid.
|
|
202
|
+
*/
|
|
36
203
|
fieldRange(rowIndex: number, columnIndex: number): CsvFieldRange | null;
|
|
204
|
+
/**
|
|
205
|
+
* Returns a borrowed `Buffer` view for one field.
|
|
206
|
+
*
|
|
207
|
+
* @param rowIndex Zero-based row index.
|
|
208
|
+
* @param columnIndex Zero-based field index relative to that row.
|
|
209
|
+
* @returns A view backed by the batch data, or `null` when the field is absent.
|
|
210
|
+
*/
|
|
37
211
|
fieldBuffer(rowIndex: number, columnIndex: number): Buffer | null;
|
|
212
|
+
/**
|
|
213
|
+
* Returns a borrowed `Uint8Array` view for one field.
|
|
214
|
+
*
|
|
215
|
+
* @param rowIndex Zero-based row index.
|
|
216
|
+
* @param columnIndex Zero-based field index relative to that row.
|
|
217
|
+
* @returns A view backed by the batch data, or `null` when the field is absent.
|
|
218
|
+
*/
|
|
38
219
|
fieldBytes(rowIndex: number, columnIndex: number): Uint8Array | null;
|
|
220
|
+
/**
|
|
221
|
+
* Decodes one field as UTF-8 text.
|
|
222
|
+
*
|
|
223
|
+
* @param rowIndex Zero-based row index.
|
|
224
|
+
* @param columnIndex Zero-based field index relative to that row.
|
|
225
|
+
* @returns The decoded text, or `null` when the field is absent.
|
|
226
|
+
*/
|
|
39
227
|
fieldString(rowIndex: number, columnIndex: number): string | null;
|
|
228
|
+
/**
|
|
229
|
+
* Visits the byte range of one column for a contiguous row interval.
|
|
230
|
+
*
|
|
231
|
+
* Rows that do not contain `columnIndex` are skipped. The callback receives
|
|
232
|
+
* offsets into `data()` and is invoked synchronously.
|
|
233
|
+
*
|
|
234
|
+
* @param columnIndex Zero-based field index relative to each row.
|
|
235
|
+
* @param callback Receives `(rowIndex, start, end)` for each present field.
|
|
236
|
+
* @param startRow Inclusive first row; defaults to `0`.
|
|
237
|
+
* @param endRow Exclusive end row; defaults to `rowCount`.
|
|
238
|
+
* @throws {RangeError} If the row interval is invalid or an offset exceeds
|
|
239
|
+
* the batch backing storage.
|
|
240
|
+
*/
|
|
40
241
|
forEachColumnRange(columnIndex: number, callback: CsvColumnRangeCallback, startRow?: number, endRow?: number): void;
|
|
242
|
+
/**
|
|
243
|
+
* Visits one column's borrowed bytes for a contiguous row interval.
|
|
244
|
+
*
|
|
245
|
+
* Missing fields are skipped. Each `Uint8Array` shares the batch backing
|
|
246
|
+
* storage and must be consumed during the callback.
|
|
247
|
+
*
|
|
248
|
+
* @param columnIndex Zero-based field index relative to each row.
|
|
249
|
+
* @param callback Receives `(rowIndex, bytes)` for each present field.
|
|
250
|
+
* @param startRow Inclusive first row; defaults to `0`.
|
|
251
|
+
* @param endRow Exclusive end row; defaults to `rowCount`.
|
|
252
|
+
*/
|
|
41
253
|
forEachColumnBytes(columnIndex: number, callback: CsvColumnBytesCallback, startRow?: number, endRow?: number): void;
|
|
254
|
+
/**
|
|
255
|
+
* Scans several columns while reusing one range array per row.
|
|
256
|
+
*
|
|
257
|
+
* `ranges` contains two numeric offsets per requested column in the same
|
|
258
|
+
* order as `columns`: `[start0, end0, start1, end1, ...]`. A missing field is
|
|
259
|
+
* reported as `[-1, -1]`. Both `ranges` and `data` are reused/borrowed and
|
|
260
|
+
* must be consumed synchronously by the callback.
|
|
261
|
+
*
|
|
262
|
+
* @param columns Zero-based field indexes relative to each row.
|
|
263
|
+
* @param callback Receives `(rowIndex, ranges, data)` for each row.
|
|
264
|
+
* @param startRow Inclusive first row; defaults to `0`.
|
|
265
|
+
* @param endRow Exclusive end row; defaults to `rowCount`.
|
|
266
|
+
* @throws {RangeError} If the row interval or an offset is invalid.
|
|
267
|
+
*/
|
|
42
268
|
scanColumns(columns: CsvColumns, callback: CsvScanColumnsCallback, startRow?: number, endRow?: number): void;
|
|
269
|
+
/**
|
|
270
|
+
* Counts rows whose field equals a supplied byte value.
|
|
271
|
+
*
|
|
272
|
+
* A string value is encoded as UTF-8; `Buffer` and `Uint8Array` values are
|
|
273
|
+
* compared as supplied.
|
|
274
|
+
*
|
|
275
|
+
* @param columnIndex Zero-based field index relative to each row.
|
|
276
|
+
* @param value String or bytes to compare.
|
|
277
|
+
* @returns The number of matching rows.
|
|
278
|
+
* @throws {RangeError} If `columnIndex` is invalid.
|
|
279
|
+
*/
|
|
43
280
|
countWhereEquals(columnIndex: number, value: string | Buffer | Uint8Array): number;
|
|
281
|
+
/**
|
|
282
|
+
* Releases the native batch and invalidates borrowed data and offset views.
|
|
283
|
+
*
|
|
284
|
+
* Calling `close()` more than once is safe.
|
|
285
|
+
*/
|
|
44
286
|
close(): void;
|
|
45
|
-
|
|
287
|
+
/** Implements `using` / explicit resource management. */
|
|
46
288
|
[Symbol.dispose](): void;
|
|
47
289
|
}
|
|
290
|
+
export {};
|