@konstit/csv 0.4.1 → 0.4.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.
- package/README.md +136 -463
- package/dist/api.d.ts +356 -21
- package/dist/api.js +64 -93
- package/dist/batches.d.ts +291 -0
- package/dist/batches.js +72 -43
- package/dist/file-stream.d.ts +2 -2
- package/dist/file-stream.js +5 -2
- package/dist/files.d.ts +148 -2
- package/dist/files.js +30 -24
- package/dist/filter.d.ts +82 -0
- package/dist/latin1-rows.d.ts +3 -0
- package/dist/latin1-rows.js +84 -0
- package/dist/materialize-field.d.ts +1 -0
- package/dist/materialize-field.js +26 -0
- package/dist/native.d.ts +29 -0
- package/dist/native.js +44 -3
- package/dist/normalize.d.ts +18 -1
- package/dist/normalize.js +10 -0
- package/dist/options-snapshot.d.ts +3 -0
- package/dist/options-snapshot.js +50 -0
- package/dist/options.d.ts +44 -3
- package/dist/parser.d.ts +307 -1
- package/dist/parser.js +121 -8
- package/dist/strict-schema.d.ts +1 -1
- package/dist/strict-schema.js +4 -1
- package/dist/types.d.ts +435 -67
- package/dist/worker-count.d.ts +33 -1
- package/dist/worker-count.js +6 -1
- package/dist/worker-pool.d.ts +77 -1
- package/dist/worker-pool.js +11 -3
- package/dist/worker-rows.d.ts +31 -3
- package/dist/worker-rows.js +11 -2
- package/dist/workers/count.worker.js +13 -26
- package/dist/workers/rows.worker.js +23 -52
- package/package.json +23 -10
- 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 +8 -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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { decodeMaterializedField } from "./materialize-field.js";
|
|
2
|
+
import {
|
|
3
|
+
EMPTY_BUFFER,
|
|
4
|
+
native,
|
|
5
|
+
optionalLatin1RowsNative,
|
|
6
|
+
requirePtr,
|
|
7
|
+
toArrayBuffer,
|
|
8
|
+
u64ToSafeNumber
|
|
9
|
+
} from "./native.js";
|
|
10
|
+
import { normalizeChunk } from "./normalize.js";
|
|
11
|
+
import { prepareNativeParser } from "./parser.js";
|
|
12
|
+
const latin1RowsParserFinalizer = new FinalizationRegistry((parser) => {
|
|
13
|
+
native.symbols.csv_parser_destroy(parser);
|
|
14
|
+
});
|
|
15
|
+
export async function* latin1Rows(chunks, delimiter, columns, filters) {
|
|
16
|
+
if (delimiter === "auto")
|
|
17
|
+
throw Error("automatic delimiter detection is only supported by file APIs");
|
|
18
|
+
if (delimiter.length !== 1)
|
|
19
|
+
throw Error("delimiter must be one character");
|
|
20
|
+
const parser = optionalLatin1RowsNative()?.symbols.csv_parser_create_latin1_rows(delimiter.charCodeAt(0));
|
|
21
|
+
if (parser === null || parser === void 0)
|
|
22
|
+
throw Error("failed to create native CSV parser");
|
|
23
|
+
const lifetime = {};
|
|
24
|
+
latin1RowsParserFinalizer.register(lifetime, parser, lifetime);
|
|
25
|
+
try {
|
|
26
|
+
const prepared = prepareNativeParser(parser, columns, filters);
|
|
27
|
+
for await (const chunk of chunks) {
|
|
28
|
+
const input = normalizeChunk(chunk);
|
|
29
|
+
const batch = prepared.writeBatch(input, !1);
|
|
30
|
+
const rows = consumeLatin1Batch(parser, batch);
|
|
31
|
+
if (rows.length > 0)
|
|
32
|
+
yield rows;
|
|
33
|
+
}
|
|
34
|
+
const batch = prepared.writeBatch(EMPTY_BUFFER, !0);
|
|
35
|
+
const rows = consumeLatin1Batch(parser, batch);
|
|
36
|
+
if (rows.length > 0)
|
|
37
|
+
yield rows;
|
|
38
|
+
} finally {
|
|
39
|
+
latin1RowsParserFinalizer.unregister(lifetime);
|
|
40
|
+
native.symbols.csv_parser_destroy(parser);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function consumeLatin1Batch(parser, batch) {
|
|
44
|
+
if (batch === null)
|
|
45
|
+
throw Error(`native CSV parser failed: ${native.symbols.csv_parser_last_error(parser) ?? "native parser error unavailable"}`);
|
|
46
|
+
try {
|
|
47
|
+
const rowCount = u64ToSafeNumber(native.symbols.csv_batch_row_count(batch), "CSV batch row count");
|
|
48
|
+
if (rowCount === 0)
|
|
49
|
+
return [];
|
|
50
|
+
const totalFields = u64ToSafeNumber(native.symbols.csv_batch_total_fields(batch), "CSV batch field count");
|
|
51
|
+
const dataLength = u64ToSafeNumber(native.symbols.csv_batch_data_len(batch), "CSV batch data length");
|
|
52
|
+
const data = dataLength === 0 ? EMPTY_BUFFER : new Uint8Array(toArrayBuffer(requirePtr(native.symbols.csv_batch_data_ptr(batch)), 0, dataLength));
|
|
53
|
+
const bytes = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
54
|
+
const rowOffsets = new Uint32Array(toArrayBuffer(requirePtr(native.symbols.csv_batch_row_offsets_ptr(batch)), 0, (rowCount + 1) * 8));
|
|
55
|
+
const fieldOffsets = new Uint32Array(toArrayBuffer(requirePtr(native.symbols.csv_batch_field_offsets_ptr(batch)), 0, (totalFields + 1) * 8));
|
|
56
|
+
const rows = [];
|
|
57
|
+
rows.length = rowCount;
|
|
58
|
+
for (let rowIndex = 0;rowIndex < rowCount; ++rowIndex) {
|
|
59
|
+
const fieldStart = checkedOffset(rowOffsets, rowIndex, totalFields);
|
|
60
|
+
const fieldEnd = checkedOffset(rowOffsets, rowIndex + 1, totalFields);
|
|
61
|
+
const row = [];
|
|
62
|
+
row.length = fieldEnd - fieldStart;
|
|
63
|
+
for (let fieldIndex = fieldStart;fieldIndex < fieldEnd; ++fieldIndex) {
|
|
64
|
+
const start = checkedOffset(fieldOffsets, fieldIndex, dataLength);
|
|
65
|
+
const end = checkedOffset(fieldOffsets, fieldIndex + 1, dataLength);
|
|
66
|
+
row[fieldIndex - fieldStart] = decodeMaterializedField(bytes, start, end, "latin1");
|
|
67
|
+
}
|
|
68
|
+
rows[rowIndex] = row;
|
|
69
|
+
}
|
|
70
|
+
return rows;
|
|
71
|
+
} finally {
|
|
72
|
+
native.symbols.csv_batch_destroy(batch);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function checkedOffset(words, index, upperBound) {
|
|
76
|
+
const low = words[index * 2];
|
|
77
|
+
const high = words[index * 2 + 1];
|
|
78
|
+
if (low === void 0 || high === void 0 || high > 2097151)
|
|
79
|
+
throw RangeError("CSV batch offset out of range");
|
|
80
|
+
const offset = low + high * 4294967296;
|
|
81
|
+
if (offset > upperBound)
|
|
82
|
+
throw RangeError("CSV batch offset exceeds backing storage");
|
|
83
|
+
return offset;
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function decodeMaterializedField(data: Buffer, start: number, end: number, encoding: 'utf8' | 'latin1'): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const ASCII_SINGLE = Array.from({ length: 128 }, (_, byte) => String.fromCharCode(byte));
|
|
2
|
+
const ASCII_PAIRS = Array.from({ length: 16384 });
|
|
3
|
+
export function decodeMaterializedField(data, start, end, encoding) {
|
|
4
|
+
const length = end - start;
|
|
5
|
+
if (length === 0)
|
|
6
|
+
return "";
|
|
7
|
+
if (length === 1) {
|
|
8
|
+
const first = data[start] ?? 128;
|
|
9
|
+
if (first < 128)
|
|
10
|
+
return ASCII_SINGLE[first] ?? "";
|
|
11
|
+
}
|
|
12
|
+
if (length === 2) {
|
|
13
|
+
const first = data[start] ?? 128;
|
|
14
|
+
const second = data[start + 1] ?? 128;
|
|
15
|
+
if (first < 128 && second < 128) {
|
|
16
|
+
const key = first << 7 | second;
|
|
17
|
+
const cached = ASCII_PAIRS[key];
|
|
18
|
+
if (cached !== void 0)
|
|
19
|
+
return cached;
|
|
20
|
+
const decoded = String.fromCharCode(first, second);
|
|
21
|
+
ASCII_PAIRS[key] = decoded;
|
|
22
|
+
return decoded;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return data.toString(encoding, start, end);
|
|
26
|
+
}
|
package/dist/native.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { type Library, type Pointer } from 'bun:ffi';
|
|
2
2
|
export type { Pointer } from 'bun:ffi';
|
|
3
3
|
export { toArrayBuffer } from 'bun:ffi';
|
|
4
|
+
/**
|
|
5
|
+
* Address of a native CSV resource, represented by Bun FFI as a pointer or bigint.
|
|
6
|
+
*
|
|
7
|
+
* A handle must originate from the matching native CSV ABI and remain valid for
|
|
8
|
+
* the operation using it. Wrapping a batch handle in `NativeCsvBatch` transfers
|
|
9
|
+
* responsibility for releasing that resource to the batch.
|
|
10
|
+
*/
|
|
4
11
|
export type NativePointer = Pointer | bigint;
|
|
5
12
|
export declare const EMPTY_BUFFER: Uint8Array<ArrayBuffer>;
|
|
6
13
|
export declare const EMPTY_U32: Uint32Array<ArrayBuffer>;
|
|
@@ -191,6 +198,28 @@ export declare const native: Library<{
|
|
|
191
198
|
readonly returns: "cstring";
|
|
192
199
|
};
|
|
193
200
|
}>;
|
|
201
|
+
declare const PREPARED_PARSER_SYMBOLS: {
|
|
202
|
+
readonly csv_parser_prepare: {
|
|
203
|
+
readonly args: readonly ["ptr", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
204
|
+
readonly returns: "bool";
|
|
205
|
+
};
|
|
206
|
+
readonly csv_parser_write_prepared_batch: {
|
|
207
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
208
|
+
readonly returns: "ptr";
|
|
209
|
+
};
|
|
210
|
+
readonly csv_parser_write_prepared_count: {
|
|
211
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
212
|
+
readonly returns: "u64";
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
export declare function optionalPreparedParserNative(): Library<typeof PREPARED_PARSER_SYMBOLS> | null;
|
|
216
|
+
declare const LATIN1_ROWS_SYMBOLS: {
|
|
217
|
+
readonly csv_parser_create_latin1_rows: {
|
|
218
|
+
readonly args: readonly ["u8"];
|
|
219
|
+
readonly returns: "ptr";
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
export declare function optionalLatin1RowsNative(): Library<typeof LATIN1_ROWS_SYMBOLS> | null;
|
|
194
223
|
export declare function requireConfiguredNativeLibraryPath(configuredPath: string): string;
|
|
195
224
|
export declare function nativeLibraryCandidates(root: string, target: string, librarySuffix: string): readonly string[];
|
|
196
225
|
export declare function findNativeLibraryPath(candidates: readonly string[]): string | undefined;
|
package/dist/native.js
CHANGED
|
@@ -218,13 +218,54 @@ const CSV_SYMBOLS = {
|
|
|
218
218
|
returns: "cstring"
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
const nativeLibraryPath = resolveNativeLibraryPath();
|
|
222
|
+
export const native = dlopen(nativeLibraryPath, CSV_SYMBOLS);
|
|
223
|
+
const PREPARED_PARSER_SYMBOLS = {
|
|
224
|
+
csv_parser_prepare: {
|
|
225
|
+
args: ["ptr", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
226
|
+
returns: "bool"
|
|
227
|
+
},
|
|
228
|
+
csv_parser_write_prepared_batch: {
|
|
229
|
+
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
230
|
+
returns: "ptr"
|
|
231
|
+
},
|
|
232
|
+
csv_parser_write_prepared_count: {
|
|
233
|
+
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
234
|
+
returns: "u64"
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
let preparedParserNative;
|
|
238
|
+
export function optionalPreparedParserNative() {
|
|
239
|
+
if (preparedParserNative === void 0)
|
|
240
|
+
try {
|
|
241
|
+
preparedParserNative = dlopen(nativeLibraryPath, PREPARED_PARSER_SYMBOLS);
|
|
242
|
+
} catch {
|
|
243
|
+
preparedParserNative = null;
|
|
244
|
+
}
|
|
245
|
+
return preparedParserNative;
|
|
246
|
+
}
|
|
247
|
+
const LATIN1_ROWS_SYMBOLS = {
|
|
248
|
+
csv_parser_create_latin1_rows: {
|
|
249
|
+
args: ["u8"],
|
|
250
|
+
returns: "ptr"
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
let latin1RowsNative;
|
|
254
|
+
export function optionalLatin1RowsNative() {
|
|
255
|
+
if (latin1RowsNative === void 0)
|
|
256
|
+
try {
|
|
257
|
+
latin1RowsNative = dlopen(nativeLibraryPath, LATIN1_ROWS_SYMBOLS);
|
|
258
|
+
} catch {
|
|
259
|
+
latin1RowsNative = null;
|
|
260
|
+
}
|
|
261
|
+
return latin1RowsNative;
|
|
262
|
+
}
|
|
263
|
+
function resolveNativeLibraryPath() {
|
|
223
264
|
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
224
265
|
const target = `${process.platform}-${process.arch}`;
|
|
225
266
|
const configuredPath = process.env.CSV_NATIVE_LIBRARY_PATH;
|
|
226
267
|
const libraryPath = configuredPath === void 0 ? requireNativeLibraryPath(nativeLibraryCandidates(root, target, suffix)) : requireConfiguredNativeLibraryPath(configuredPath);
|
|
227
|
-
return
|
|
268
|
+
return resolve(libraryPath);
|
|
228
269
|
}
|
|
229
270
|
export function requireConfiguredNativeLibraryPath(configuredPath) {
|
|
230
271
|
if (configuredPath.length === 0)
|
package/dist/normalize.d.ts
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
import type { CsvColumns, CsvEncoding, CsvEqualsFilter, CsvFieldValue, CsvInFilter, CsvNativeFilter, CsvRegex, CsvStartsWithFilter } from './types.js';
|
|
1
|
+
import type { CsvColumns, CsvEncoding, CsvEqualsFilter, CsvFieldValue, CsvInFilter, CsvNativeFilter, CsvNativeProjectionOptions, CsvRegex, CsvStartsWithFilter } from './types.js';
|
|
2
2
|
export declare const MAX_COLUMN_INDEX = 2024;
|
|
3
3
|
export declare const MAX_PROJECTION_LENGTH = 2024;
|
|
4
4
|
export declare const MAX_FILTER_COUNT = 2024;
|
|
5
5
|
export declare const MAX_REGEX_FILTER_COUNT = 32;
|
|
6
6
|
export declare const MAX_FILTER_PROGRAM_LENGTH = 4096;
|
|
7
|
+
/**
|
|
8
|
+
* Boolean operation in a postfix filter program accepted by `NativeCsvParser`.
|
|
9
|
+
*
|
|
10
|
+
* Predicates push results onto a stack. An operator consumes the most recent
|
|
11
|
+
* results and pushes one combined result. Missing columns produce an unknown
|
|
12
|
+
* result, which remains unknown under `not` and does not select a row by itself.
|
|
13
|
+
*/
|
|
7
14
|
export interface CsvNativeFilterOperator {
|
|
15
|
+
/** Number of preceding stack results to consume; positive, and exactly one for `not`. */
|
|
8
16
|
readonly operandCount: number;
|
|
17
|
+
/** Combine operands with AND, OR, or unary negation. */
|
|
9
18
|
readonly operator: 'all' | 'any' | 'not';
|
|
10
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Predicate or boolean operator in a low-level postfix filter program.
|
|
22
|
+
*
|
|
23
|
+
* Place predicates before the operators that consume them. A complete program
|
|
24
|
+
* must leave exactly one result on the stack and contain at most 4096 entries.
|
|
25
|
+
* Most applications can use `csv.column()` and its boolean combinators instead.
|
|
26
|
+
*/
|
|
11
27
|
export type CsvNativeFilterProgramEntry = CsvNativeFilter | CsvNativeFilterOperator;
|
|
28
|
+
export declare function projectionFilterProgram(options: CsvNativeProjectionOptions): readonly CsvNativeFilterProgramEntry[] | undefined;
|
|
12
29
|
export declare function encodingCode(encoding?: CsvEncoding): number;
|
|
13
30
|
export declare function normalizeChunk(chunk: NodeJS.TypedArray | DataView): NodeJS.TypedArray | DataView;
|
|
14
31
|
export declare function normalizeFixedColumnsCount(value: number | undefined, label: string): number | undefined;
|
package/dist/normalize.js
CHANGED
|
@@ -20,6 +20,16 @@ const NATIVE_FILTER_NOT = 9;
|
|
|
20
20
|
export const MAX_REGEX_FILTER_COUNT = 32;
|
|
21
21
|
export const MAX_FILTER_PROGRAM_LENGTH = 4096;
|
|
22
22
|
const MAX_REGEX_PATTERN_BYTES = 4096;
|
|
23
|
+
export function projectionFilterProgram(options) {
|
|
24
|
+
if (options.equalsFilter !== void 0 && options.filters !== void 0)
|
|
25
|
+
throw Error("use equalsFilter or filters, not both");
|
|
26
|
+
if (options.equalsFilter !== void 0)
|
|
27
|
+
return [options.equalsFilter];
|
|
28
|
+
const filters = options.filters;
|
|
29
|
+
if (filters === void 0 || filters.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
return filters.length === 1 ? filters : [...filters, { operator: "all", operandCount: filters.length }];
|
|
32
|
+
}
|
|
23
33
|
export function encodingCode(encoding = "utf8") {
|
|
24
34
|
const normalized = encoding.toLowerCase();
|
|
25
35
|
if (normalized === "utf8")
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CsvApiFileOptions, CsvNativeProjectionOptions } from './types.js';
|
|
2
|
+
/** Own the mutable option values while retaining opaque immutable filter handles. */
|
|
3
|
+
export declare function snapshotCsvOptions<TOptions extends CsvApiFileOptions & CsvNativeProjectionOptions>(options: TOptions): TOptions;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_FILTER_COUNT,
|
|
3
|
+
MAX_PROJECTION_LENGTH
|
|
4
|
+
} from "./normalize.js";
|
|
5
|
+
const snapshots = new WeakSet;
|
|
6
|
+
export function snapshotCsvOptions(options) {
|
|
7
|
+
if (snapshots.has(options))
|
|
8
|
+
return options;
|
|
9
|
+
const captured = { ...options };
|
|
10
|
+
if (captured.filters !== void 0 && captured.filters.length > MAX_FILTER_COUNT)
|
|
11
|
+
throw RangeError(`filter count out of range: ${captured.filters.length}`);
|
|
12
|
+
const snapshot = Object.freeze({
|
|
13
|
+
...captured,
|
|
14
|
+
columns: snapshotColumns(captured.columns),
|
|
15
|
+
selectedColumns: snapshotColumns(captured.selectedColumns),
|
|
16
|
+
expectedHeaders: captured.expectedHeaders === void 0 ? void 0 : Object.freeze([...captured.expectedHeaders]),
|
|
17
|
+
compression: typeof captured.compression === "object" && captured.compression !== null ? Object.freeze({ ...captured.compression }) : captured.compression,
|
|
18
|
+
equalsFilter: captured.equalsFilter === void 0 ? void 0 : Object.freeze({ ...captured.equalsFilter, value: copyFieldValue(captured.equalsFilter.value) }),
|
|
19
|
+
filters: captured.filters === void 0 ? void 0 : Object.freeze(captured.filters.map(snapshotNativeFilter))
|
|
20
|
+
});
|
|
21
|
+
snapshots.add(snapshot);
|
|
22
|
+
return snapshot;
|
|
23
|
+
}
|
|
24
|
+
function snapshotColumns(columns) {
|
|
25
|
+
if (columns === void 0)
|
|
26
|
+
return;
|
|
27
|
+
if (columns.length > MAX_PROJECTION_LENGTH)
|
|
28
|
+
throw RangeError(`selected column count out of range: ${columns.length}`);
|
|
29
|
+
return Object.freeze([...columns]);
|
|
30
|
+
}
|
|
31
|
+
function snapshotNativeFilter(filter) {
|
|
32
|
+
if ("value" in filter)
|
|
33
|
+
return Object.freeze({ ...filter, value: copyFieldValue(filter.value) });
|
|
34
|
+
if ("values" in filter)
|
|
35
|
+
return Object.freeze({ ...filter, values: Object.freeze(filter.values.map(copyFieldValue)) });
|
|
36
|
+
if ("notEquals" in filter)
|
|
37
|
+
return Object.freeze({ ...filter, notEquals: copyFieldValue(filter.notEquals) });
|
|
38
|
+
if ("notIn" in filter)
|
|
39
|
+
return Object.freeze({ ...filter, notIn: Object.freeze(filter.notIn.map(copyFieldValue)) });
|
|
40
|
+
if ("prefix" in filter)
|
|
41
|
+
return Object.freeze({ ...filter, prefix: copyFieldValue(filter.prefix) });
|
|
42
|
+
return Object.freeze({ ...filter, regex: Object.freeze({ ...filter.regex }) });
|
|
43
|
+
}
|
|
44
|
+
function copyFieldValue(value) {
|
|
45
|
+
if (typeof value === "string")
|
|
46
|
+
return value;
|
|
47
|
+
if (!(value instanceof Uint8Array))
|
|
48
|
+
throw TypeError("filter value must be a string, Buffer, or Uint8Array");
|
|
49
|
+
return new Uint8Array(value);
|
|
50
|
+
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,17 +1,58 @@
|
|
|
1
1
|
import type { CsvColumnarBatchOptions, CsvColumns, CsvCountOptions, CsvRowsOptions, CsvRowViewsOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Preserve literal inference for `csv.rows()` options.
|
|
3
|
+
* Preserve literal column inference for `csv.rows()` options.
|
|
4
|
+
*
|
|
5
|
+
* This identity helper is useful when options are declared separately from the call site. It
|
|
6
|
+
* checks the selected-column/strict/worker union while retaining tuple literals for projected row
|
|
7
|
+
* types; it does not clone or freeze the object. Each operation snapshots caller-owned option
|
|
8
|
+
* values when invoked.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam TColumns - Literal selected column indexes, when supplied.
|
|
11
|
+
* @typeParam TOptions - The complete rows option object to preserve.
|
|
12
|
+
* @param options - Type-checked rows options.
|
|
13
|
+
* @returns The same options object, with its literal type preserved.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const options = defineRowsOptions({ columns: [0, 2] as const });
|
|
18
|
+
* for await (const rows of csv.rows('data.csv', options)) {
|
|
19
|
+
* const firstField = rows[0]?.[0];
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
4
22
|
*/
|
|
5
23
|
export declare function defineRowsOptions<const TColumns extends CsvColumns | undefined, const TOptions extends CsvRowsOptions<TColumns>>(options: TOptions): TOptions;
|
|
6
24
|
/**
|
|
7
25
|
* Preserve literal inference for `csv.count()` options.
|
|
26
|
+
*
|
|
27
|
+
* The helper validates the count option union, including the restrictions that apply to strict
|
|
28
|
+
* and parallel counting, while returning the original object unchanged.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam TOptions - The complete count option object to preserve.
|
|
31
|
+
* @param options - Type-checked count options.
|
|
32
|
+
* @returns The same options object, with its literal type preserved.
|
|
8
33
|
*/
|
|
9
34
|
export declare function defineCountOptions<const TOptions extends CsvCountOptions>(options: TOptions): TOptions;
|
|
10
35
|
/**
|
|
11
|
-
* Preserve literal inference for `csv.withColumnarBatches()` options.
|
|
36
|
+
* Preserve literal column inference for `csv.withColumnarBatches()` options.
|
|
37
|
+
*
|
|
38
|
+
* This identity helper retains projected column tuples for columnar batch callbacks and checks
|
|
39
|
+
* the callback API's option restrictions, including its non-strict projected mode.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam TColumns - Literal selected column indexes, when supplied.
|
|
42
|
+
* @typeParam TOptions - The complete columnar batch option object to preserve.
|
|
43
|
+
* @param options - Type-checked columnar batch options.
|
|
44
|
+
* @returns The same options object, with its literal type preserved.
|
|
12
45
|
*/
|
|
13
46
|
export declare function defineColumnarOptions<const TColumns extends CsvColumns | undefined, const TOptions extends CsvColumnarBatchOptions<TColumns>>(options: TOptions): TOptions;
|
|
14
47
|
/**
|
|
15
|
-
* Preserve literal inference for `csv.withRowViews()` options.
|
|
48
|
+
* Preserve literal column inference for `csv.withRowViews()` options.
|
|
49
|
+
*
|
|
50
|
+
* The helper checks the serial row-view option union and keeps a selected-column tuple visible to
|
|
51
|
+
* the callback's `CsvRowView` type. It is an identity function at runtime.
|
|
52
|
+
*
|
|
53
|
+
* @typeParam TColumns - Literal selected column indexes, when supplied.
|
|
54
|
+
* @typeParam TOptions - The complete row-view option object to preserve.
|
|
55
|
+
* @param options - Type-checked row-view options.
|
|
56
|
+
* @returns The same options object, with its literal type preserved.
|
|
16
57
|
*/
|
|
17
58
|
export declare function defineRowViewOptions<const TColumns extends CsvColumns | undefined, const TOptions extends CsvRowViewsOptions<TColumns>>(options: TOptions): TOptions;
|