@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/normalize.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
EMPTY_U32,
|
|
4
4
|
native
|
|
5
5
|
} from "./native.js";
|
|
6
|
+
const LATIN1_ENCODINGS = new Set(["latin1", "iso88591", "iso-8859-1"]);
|
|
6
7
|
export const MAX_COLUMN_INDEX = 2024;
|
|
7
8
|
export const MAX_PROJECTION_LENGTH = 2024;
|
|
8
9
|
export const MAX_FILTER_COUNT = MAX_PROJECTION_LENGTH;
|
|
@@ -20,14 +21,58 @@ const NATIVE_FILTER_NOT = 9;
|
|
|
20
21
|
export const MAX_REGEX_FILTER_COUNT = 32;
|
|
21
22
|
export const MAX_FILTER_PROGRAM_LENGTH = 4096;
|
|
22
23
|
const MAX_REGEX_PATTERN_BYTES = 4096;
|
|
24
|
+
export function projectionFilterProgram(options) {
|
|
25
|
+
if (options.equalsFilter !== void 0 && options.filters !== void 0)
|
|
26
|
+
throw Error("use equalsFilter or filters, not both");
|
|
27
|
+
if (options.equalsFilter !== void 0)
|
|
28
|
+
return [options.equalsFilter];
|
|
29
|
+
const filters = options.filters;
|
|
30
|
+
if (filters === void 0 || filters.length === 0)
|
|
31
|
+
return;
|
|
32
|
+
return filters.length === 1 ? filters : [...filters, { operator: "all", operandCount: filters.length }];
|
|
33
|
+
}
|
|
23
34
|
export function encodingCode(encoding = "utf8") {
|
|
24
|
-
const normalized = encoding
|
|
35
|
+
const normalized = resolveInputEncoding(encoding);
|
|
25
36
|
if (normalized === "utf8")
|
|
26
37
|
return 0;
|
|
27
|
-
if (normalized === "latin1"
|
|
38
|
+
if (normalized === "latin1")
|
|
28
39
|
return 1;
|
|
29
40
|
throw Error(`unsupported encoding: ${encoding}`);
|
|
30
41
|
}
|
|
42
|
+
export function resolveInputEncoding(encoding = "utf8", delimiter) {
|
|
43
|
+
if (encoding === "auto")
|
|
44
|
+
throw Error("automatic encoding detection is only supported by file parsing APIs; specify encoding explicitly");
|
|
45
|
+
if (encoding === "utf8" || encoding === "utf-8")
|
|
46
|
+
return "utf8";
|
|
47
|
+
if (LATIN1_ENCODINGS.has(encoding))
|
|
48
|
+
return "latin1";
|
|
49
|
+
if (typeof encoding !== "string")
|
|
50
|
+
throw TypeError("encoding must be a string");
|
|
51
|
+
let decoder;
|
|
52
|
+
try {
|
|
53
|
+
decoder = new TextDecoder(encoding);
|
|
54
|
+
} catch (cause) {
|
|
55
|
+
if (cause instanceof RangeError)
|
|
56
|
+
throw Error(`unsupported encoding: ${encoding}`, { cause });
|
|
57
|
+
throw cause;
|
|
58
|
+
}
|
|
59
|
+
if (decoder.encoding === "utf-8")
|
|
60
|
+
return "utf8";
|
|
61
|
+
if (decoder.encoding === "windows-1252" && LATIN1_ENCODINGS.has(encoding.trim().toLowerCase()))
|
|
62
|
+
return "latin1";
|
|
63
|
+
if (delimiter !== void 0 && delimiter.charCodeAt(0) > 127)
|
|
64
|
+
throw Error(`encoding ${decoder.encoding} requires an ASCII delimiter`);
|
|
65
|
+
return decoder;
|
|
66
|
+
}
|
|
67
|
+
export function prepareCsvBufferInput(buffer, encoding, delimiter) {
|
|
68
|
+
const resolved = resolveInputEncoding(encoding, delimiter);
|
|
69
|
+
if (typeof resolved === "string")
|
|
70
|
+
return { bytes: buffer, parserEncoding: resolved };
|
|
71
|
+
return {
|
|
72
|
+
bytes: new TextEncoder().encode(resolved.decode(buffer)),
|
|
73
|
+
parserEncoding: "utf8"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
31
76
|
export function normalizeChunk(chunk) {
|
|
32
77
|
return chunk.byteLength === 0 ? EMPTY_BUFFER : chunk;
|
|
33
78
|
}
|
|
@@ -38,6 +83,10 @@ export function normalizeFixedColumnsCount(value, label) {
|
|
|
38
83
|
throw RangeError(`${label} out of range: ${value}`);
|
|
39
84
|
return value;
|
|
40
85
|
}
|
|
86
|
+
export function rejectSelectedColumns(options) {
|
|
87
|
+
if ("selectedColumns" in options)
|
|
88
|
+
throw TypeError("selectedColumns is unsupported; use columns");
|
|
89
|
+
}
|
|
41
90
|
export function normalizeColumns(columns) {
|
|
42
91
|
if (columns === void 0)
|
|
43
92
|
return EMPTY_U32;
|
|
@@ -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,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_FILTER_COUNT,
|
|
3
|
+
MAX_PROJECTION_LENGTH,
|
|
4
|
+
rejectSelectedColumns
|
|
5
|
+
} from "./normalize.js";
|
|
6
|
+
const snapshots = new WeakSet;
|
|
7
|
+
export function snapshotCsvOptions(options) {
|
|
8
|
+
if (snapshots.has(options))
|
|
9
|
+
return options;
|
|
10
|
+
rejectSelectedColumns(options);
|
|
11
|
+
const captured = { ...options };
|
|
12
|
+
if (captured.filters !== void 0 && captured.filters.length > MAX_FILTER_COUNT)
|
|
13
|
+
throw RangeError(`filter count out of range: ${captured.filters.length}`);
|
|
14
|
+
const snapshot = Object.freeze({
|
|
15
|
+
...captured,
|
|
16
|
+
columns: snapshotColumns(captured.columns),
|
|
17
|
+
expectedHeaders: captured.expectedHeaders === void 0 ? void 0 : Object.freeze([...captured.expectedHeaders]),
|
|
18
|
+
compression: typeof captured.compression === "object" && captured.compression !== null ? Object.freeze({ ...captured.compression }) : captured.compression,
|
|
19
|
+
equalsFilter: captured.equalsFilter === void 0 ? void 0 : Object.freeze({ ...captured.equalsFilter, value: copyFieldValue(captured.equalsFilter.value) }),
|
|
20
|
+
filters: captured.filters === void 0 ? void 0 : Object.freeze(captured.filters.map(snapshotNativeFilter))
|
|
21
|
+
});
|
|
22
|
+
snapshots.add(snapshot);
|
|
23
|
+
return snapshot;
|
|
24
|
+
}
|
|
25
|
+
function snapshotColumns(columns) {
|
|
26
|
+
if (columns === void 0)
|
|
27
|
+
return;
|
|
28
|
+
if (columns.length > MAX_PROJECTION_LENGTH)
|
|
29
|
+
throw RangeError(`selected column count out of range: ${columns.length}`);
|
|
30
|
+
return Object.freeze([...columns]);
|
|
31
|
+
}
|
|
32
|
+
function snapshotNativeFilter(filter) {
|
|
33
|
+
if ("value" in filter)
|
|
34
|
+
return Object.freeze({ ...filter, value: copyFieldValue(filter.value) });
|
|
35
|
+
if ("values" in filter)
|
|
36
|
+
return Object.freeze({ ...filter, values: Object.freeze(filter.values.map(copyFieldValue)) });
|
|
37
|
+
if ("notEquals" in filter)
|
|
38
|
+
return Object.freeze({ ...filter, notEquals: copyFieldValue(filter.notEquals) });
|
|
39
|
+
if ("notIn" in filter)
|
|
40
|
+
return Object.freeze({ ...filter, notIn: Object.freeze(filter.notIn.map(copyFieldValue)) });
|
|
41
|
+
if ("prefix" in filter)
|
|
42
|
+
return Object.freeze({ ...filter, prefix: copyFieldValue(filter.prefix) });
|
|
43
|
+
return Object.freeze({ ...filter, regex: Object.freeze({ ...filter.regex }) });
|
|
44
|
+
}
|
|
45
|
+
function copyFieldValue(value) {
|
|
46
|
+
if (typeof value === "string")
|
|
47
|
+
return value;
|
|
48
|
+
if (!(value instanceof Uint8Array))
|
|
49
|
+
throw TypeError("filter value must be a string, Buffer, or Uint8Array");
|
|
50
|
+
return new Uint8Array(value);
|
|
51
|
+
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CsvColumns, CsvCountOptions, CsvRowsOptions } 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 projection and strict validation options while retaining tuple literals for projected row
|
|
7
|
+
* types. Each operation snapshots caller-owned option values when invoked.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam TColumns - Literal selected column indexes, when supplied.
|
|
10
|
+
* @typeParam TOptions - The complete rows option object to preserve.
|
|
11
|
+
* @param options - Type-checked rows options.
|
|
12
|
+
* @returns The same options object, with its literal type preserved.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const options = defineRowsOptions({ columns: [0, 2] as const });
|
|
17
|
+
* for await (const rows of csv.rows('data.csv', options)) {
|
|
18
|
+
* const firstField = rows[0]?.[0];
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
4
21
|
*/
|
|
5
22
|
export declare function defineRowsOptions<const TColumns extends CsvColumns | undefined, const TOptions extends CsvRowsOptions<TColumns>>(options: TOptions): TOptions;
|
|
6
23
|
/**
|
|
7
24
|
* Preserve literal inference for `csv.count()` options.
|
|
25
|
+
*
|
|
26
|
+
* The helper checks that strict counts use unfiltered input and returns the original object.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TOptions - The complete count option object to preserve.
|
|
29
|
+
* @param options - Type-checked count options.
|
|
30
|
+
* @returns The same options object, with its literal type preserved.
|
|
8
31
|
*/
|
|
9
32
|
export declare function defineCountOptions<const TOptions extends CsvCountOptions>(options: TOptions): TOptions;
|
|
10
|
-
/**
|
|
11
|
-
* Preserve literal inference for `csv.withColumnarBatches()` options.
|
|
12
|
-
*/
|
|
13
|
-
export declare function defineColumnarOptions<const TColumns extends CsvColumns | undefined, const TOptions extends CsvColumnarBatchOptions<TColumns>>(options: TOptions): TOptions;
|
|
14
|
-
/**
|
|
15
|
-
* Preserve literal inference for `csv.withRowViews()` options.
|
|
16
|
-
*/
|
|
17
|
-
export declare function defineRowViewOptions<const TColumns extends CsvColumns | undefined, const TOptions extends CsvRowViewsOptions<TColumns>>(options: TOptions): TOptions;
|
package/dist/options.js
CHANGED
package/dist/parser.d.ts
CHANGED
|
@@ -1,32 +1,337 @@
|
|
|
1
1
|
import { NativeCsvBatch } from './batches.js';
|
|
2
|
+
import { type NativePointer } from './native.js';
|
|
2
3
|
import type { CsvNativeFilterProgramEntry } from './normalize.js';
|
|
3
|
-
import type { CsvEqualsFilter, CsvInFilter, CsvNativeFilter, CsvNativeProjectionOptions, CsvParserOptions, CsvRow, CsvStartsWithFilter } from './types.js';
|
|
4
|
+
import type { CsvColumns, CsvEqualsFilter, CsvInFilter, CsvNativeFilter, CsvNativeProjectionOptions, CsvParserOptions, CsvRow, CsvStartsWithFilter } from './types.js';
|
|
5
|
+
export declare const nativeCsvParserFinalizer: FinalizationRegistry<NativePointer>;
|
|
6
|
+
/**
|
|
7
|
+
* The fixed-configuration parser surface used by high-level streaming APIs.
|
|
8
|
+
*
|
|
9
|
+
* A prepared parser captures projection and filter state once, so each chunk
|
|
10
|
+
* is processed with the same configuration. The parser owns its native handle
|
|
11
|
+
* and must be closed or disposed after use.
|
|
12
|
+
*/
|
|
13
|
+
export type PreparedCsvParser = Pick<NativeCsvParser, 'writeBatch' | 'endBatch' | 'writeCount' | 'endCount' | 'close' | typeof Symbol.dispose>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a parser with projection and filter configuration prepared once.
|
|
16
|
+
*
|
|
17
|
+
* This helper is used by the high-level APIs; direct callers that need to
|
|
18
|
+
* change projection or filters between writes should use `NativeCsvParser`
|
|
19
|
+
* and its explicit per-write methods instead.
|
|
20
|
+
*
|
|
21
|
+
* @param options Base parser settings such as encoding, delimiter, strictness,
|
|
22
|
+
* and fixed column count.
|
|
23
|
+
* @param columns Optional zero-based columns to emit in each batch.
|
|
24
|
+
* @param program Optional postfix sequence of filter predicates and boolean
|
|
25
|
+
* operators. The parser validates and normalizes it before preparation.
|
|
26
|
+
* @param projected Whether the caller is explicitly requesting a projected
|
|
27
|
+
* path. This is an internal distinction used by the high-level API.
|
|
28
|
+
* @returns A parser with `writeBatch`/`writeCount` operations bound to the
|
|
29
|
+
* supplied configuration.
|
|
30
|
+
* @throws {Error} If strict validation is requested for a projected or
|
|
31
|
+
* filtered operation, or native parser setup fails.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createPreparedParser(options: CsvParserOptions, columns?: CsvColumns, program?: readonly CsvNativeFilterProgramEntry[], projected?: boolean): PreparedCsvParser;
|
|
34
|
+
interface PreparedNativeWriter {
|
|
35
|
+
writeBatch(input: NodeJS.TypedArray | DataView, final: boolean): NativePointer | null;
|
|
36
|
+
writeCount(input: NodeJS.TypedArray | DataView, final: boolean): bigint | number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Prepares native projection and filter buffers for an existing parser handle.
|
|
40
|
+
*
|
|
41
|
+
* This low-level helper is intended for the parser implementation. The native
|
|
42
|
+
* parser owns a copy of the normalized configuration, and the caller remains
|
|
43
|
+
* responsible for closing the handle.
|
|
44
|
+
*
|
|
45
|
+
* @param handle Open native parser handle.
|
|
46
|
+
* @param columns Optional zero-based output columns.
|
|
47
|
+
* @param program Optional postfix sequence of filter predicates and boolean
|
|
48
|
+
* operators. It is validated and normalized before preparation.
|
|
49
|
+
* @returns Prepared write functions for batches and counts.
|
|
50
|
+
* @throws {Error} If the native library rejects the configuration.
|
|
51
|
+
*/
|
|
52
|
+
export declare function prepareNativeParser(handle: NativePointer, columns: CsvColumns | undefined, program: readonly CsvNativeFilterProgramEntry[] | undefined): PreparedNativeWriter;
|
|
53
|
+
/**
|
|
54
|
+
* Incrementally parses caller-owned CSV chunks through the native parser.
|
|
55
|
+
*
|
|
56
|
+
* Use this class when the application controls buffering. A write may return a
|
|
57
|
+
* `NativeCsvBatch` containing complete rows while retaining an incomplete row
|
|
58
|
+
* for the next write. Every returned batch owns native memory and must be
|
|
59
|
+
* closed or disposed. `write()` and `end()` are convenience methods that
|
|
60
|
+
* materialize rows and close their temporary batches automatically.
|
|
61
|
+
*
|
|
62
|
+
* Projection and filter options passed to the explicit projected/count methods
|
|
63
|
+
* apply to the current stream position. Keep them consistent while a row is
|
|
64
|
+
* split across chunks; complete that row or call `reset()` before changing them.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* using parser = new NativeCsvParser({ delimiter: ';' });
|
|
69
|
+
* using first = parser.writeBatch(Buffer.from('1;Ada\n2;Bob'), false);
|
|
70
|
+
* console.log(first.rows()); // [['1', 'Ada']]
|
|
71
|
+
* using final = parser.endBatch();
|
|
72
|
+
* console.log(final.rows()); // [['2', 'Bob']]
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
4
75
|
export declare class NativeCsvParser {
|
|
5
76
|
#private;
|
|
77
|
+
/**
|
|
78
|
+
* Creates an open parser.
|
|
79
|
+
*
|
|
80
|
+
* @param options Base parser settings. `encoding`, `delimiter`, `strict`, and
|
|
81
|
+
* `fixedColumns` are captured by this parser; the delimiter defaults to `,`.
|
|
82
|
+
* Automatic delimiter detection (`"auto"`) is available through file APIs,
|
|
83
|
+
* not this manual parser. `columns` is validated for compatibility
|
|
84
|
+
* but does not configure `writeBatch()`; apply projection with one of the
|
|
85
|
+
* explicit projected methods instead. `expectedHeaders`, `requireHeader`,
|
|
86
|
+
* and `minDataRows` are schema metadata for higher-level APIs and have no
|
|
87
|
+
* effect on this low-level parser.
|
|
88
|
+
* @throws {Error} If the delimiter is not one character or native parser
|
|
89
|
+
* creation fails.
|
|
90
|
+
* @throws {RangeError} If selected or fixed column settings are out of range.
|
|
91
|
+
*/
|
|
6
92
|
constructor(options?: CsvParserOptions);
|
|
93
|
+
/** Whether the native parser handle has been released. */
|
|
7
94
|
get closed(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Parses a chunk and materializes all complete rows emitted by that call.
|
|
97
|
+
*
|
|
98
|
+
* The temporary native batch is closed before this method returns. Use
|
|
99
|
+
* `writeBatch()` when byte views or low-allocation access are required.
|
|
100
|
+
*
|
|
101
|
+
* @param chunk Input bytes. The parser may retain an incomplete final row for
|
|
102
|
+
* a later call.
|
|
103
|
+
* @param final Set to `true` when this is the last input chunk; buffered row
|
|
104
|
+
* state is flushed before returning.
|
|
105
|
+
* @returns Materialized UTF-8 rows emitted by this call.
|
|
106
|
+
* @throws {Error} If the parser is closed or native parsing fails.
|
|
107
|
+
*/
|
|
8
108
|
write(chunk: NodeJS.TypedArray | DataView, final?: boolean): CsvRow[];
|
|
109
|
+
/**
|
|
110
|
+
* Parses a chunk and returns an owned batch of complete rows.
|
|
111
|
+
*
|
|
112
|
+
* Call `batch.close()` or use `using` for the returned batch. The parser may
|
|
113
|
+
* retain an incomplete row between calls. `final: true` marks the input end
|
|
114
|
+
* and flushes that row.
|
|
115
|
+
*
|
|
116
|
+
* @param chunk Input bytes.
|
|
117
|
+
* @param final Whether this is the final input chunk.
|
|
118
|
+
* @returns A native batch that the caller owns.
|
|
119
|
+
* @throws {Error} If the parser is closed or native parsing fails.
|
|
120
|
+
*/
|
|
9
121
|
writeBatch(chunk: NodeJS.TypedArray | DataView, final?: boolean): NativeCsvBatch;
|
|
122
|
+
/**
|
|
123
|
+
* Parses a chunk with explicit projection and optional native filters.
|
|
124
|
+
*
|
|
125
|
+
* Returned fields follow `columns` order. `equalsFilter` and
|
|
126
|
+
* `filters` are mutually exclusive. Keep the same projection and filter
|
|
127
|
+
* configuration for chunks that may belong to one logical row.
|
|
128
|
+
*
|
|
129
|
+
* @param chunk Input bytes.
|
|
130
|
+
* @param options Projection and filter settings for this stream position.
|
|
131
|
+
* @param final Whether this is the final input chunk.
|
|
132
|
+
* @returns An owned projected batch; close or dispose it after use.
|
|
133
|
+
* @throws {Error} If strict mode is enabled, both filter forms are supplied,
|
|
134
|
+
* the parser is closed, or native parsing fails.
|
|
135
|
+
* @throws {RangeError} If projection or filter values are invalid.
|
|
136
|
+
*/
|
|
10
137
|
writeProjectedBatch(chunk: NodeJS.TypedArray | DataView, options?: CsvNativeProjectionOptions, final?: boolean): NativeCsvBatch;
|
|
138
|
+
/**
|
|
139
|
+
* Flushes the parser and materializes its final rows.
|
|
140
|
+
*
|
|
141
|
+
* The temporary final batch is closed before this method returns. Use
|
|
142
|
+
* `endBatch()` when the native batch representation is needed.
|
|
143
|
+
*
|
|
144
|
+
* @returns Materialized UTF-8 rows pending at end of input.
|
|
145
|
+
* @throws {Error} If the parser is closed or the final row is invalid.
|
|
146
|
+
*/
|
|
11
147
|
end(): CsvRow[];
|
|
148
|
+
/**
|
|
149
|
+
* Flushes buffered parser state and returns the final owned batch.
|
|
150
|
+
*
|
|
151
|
+
* @returns A native batch that the caller owns and must close.
|
|
152
|
+
* @throws {Error} If the parser is closed or the final row is invalid.
|
|
153
|
+
*/
|
|
12
154
|
endBatch(): NativeCsvBatch;
|
|
155
|
+
/**
|
|
156
|
+
* Flushes buffered state using explicit projection and filter settings.
|
|
157
|
+
*
|
|
158
|
+
* The options must match the configuration used for chunks contributing to
|
|
159
|
+
* the final logical row. `equalsFilter` and `filters` cannot be combined.
|
|
160
|
+
*
|
|
161
|
+
* @param options Projection and filter settings.
|
|
162
|
+
* @returns An owned projected batch; close or dispose it after use.
|
|
163
|
+
* @throws {Error} If strict mode is enabled, filter forms conflict, the
|
|
164
|
+
* parser is closed, or the final row is invalid.
|
|
165
|
+
*/
|
|
13
166
|
endProjectedBatch(options?: CsvNativeProjectionOptions): NativeCsvBatch;
|
|
14
|
-
|
|
15
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Parses a chunk with a postfix native filter program.
|
|
169
|
+
*
|
|
170
|
+
* This is the lower-level counterpart to `writeProjectedBatch()` for callers
|
|
171
|
+
* that want to provide predicate and boolean-operator entries directly.
|
|
172
|
+
*
|
|
173
|
+
* @param chunk Input bytes.
|
|
174
|
+
* @param columns Optional zero-based output columns.
|
|
175
|
+
* @param program Filter predicates and boolean operators in postfix order.
|
|
176
|
+
* The method validates and normalizes the entries before the native call.
|
|
177
|
+
* @param final Whether this is the final input chunk.
|
|
178
|
+
* @returns An owned projected batch; close or dispose it after use.
|
|
179
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
180
|
+
* parsing rejects the program or input.
|
|
181
|
+
*/
|
|
182
|
+
writeProjectedBatchWhere(chunk: NodeJS.TypedArray | DataView, columns: readonly number[] | undefined, program: readonly CsvNativeFilterProgramEntry[], final?: boolean): NativeCsvBatch;
|
|
183
|
+
/**
|
|
184
|
+
* Flushes buffered state with a postfix native filter program.
|
|
185
|
+
*
|
|
186
|
+
* @param columns Optional zero-based output columns.
|
|
187
|
+
* @param program Filter predicates and boolean operators in postfix order.
|
|
188
|
+
* The method validates and normalizes the entries before the native call.
|
|
189
|
+
* @returns An owned projected batch; close or dispose it after use.
|
|
190
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
191
|
+
* parsing rejects the program or final row.
|
|
192
|
+
*/
|
|
193
|
+
endProjectedBatchWhere(columns: readonly number[] | undefined, program: readonly CsvNativeFilterProgramEntry[]): NativeCsvBatch;
|
|
194
|
+
/**
|
|
195
|
+
* Counts complete rows emitted by a chunk without materializing fields.
|
|
196
|
+
*
|
|
197
|
+
* Sum the results from each write and call `endCount()` for the final
|
|
198
|
+
* buffered row when processing split input.
|
|
199
|
+
*
|
|
200
|
+
* @param chunk Input bytes.
|
|
201
|
+
* @param final Whether this is the final input chunk.
|
|
202
|
+
* @returns The number of rows emitted by this call.
|
|
203
|
+
* @throws {Error} In strict mode, because count mode has no strict validator,
|
|
204
|
+
* or if the parser is closed/native parsing fails.
|
|
205
|
+
*/
|
|
16
206
|
writeCount(chunk: NodeJS.TypedArray | DataView, final?: boolean): number;
|
|
207
|
+
/**
|
|
208
|
+
* Flushes buffered state and returns the final unfiltered row count.
|
|
209
|
+
*
|
|
210
|
+
* @returns The number of rows emitted while finishing the stream.
|
|
211
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
212
|
+
* parsing fails.
|
|
213
|
+
*/
|
|
17
214
|
endCount(): number;
|
|
215
|
+
/**
|
|
216
|
+
* Counts rows matching an equality filter while parsing a chunk.
|
|
217
|
+
*
|
|
218
|
+
* @param chunk Input bytes.
|
|
219
|
+
* @param filter Column and value to compare.
|
|
220
|
+
* @param final Whether this is the final input chunk.
|
|
221
|
+
* @returns Matching rows emitted by this call.
|
|
222
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
223
|
+
* parsing fails.
|
|
224
|
+
* @throws {RangeError} If the filter column or value is invalid.
|
|
225
|
+
*/
|
|
18
226
|
writeCountWhereEquals(chunk: NodeJS.TypedArray | DataView, filter: CsvEqualsFilter, final?: boolean): number;
|
|
227
|
+
/**
|
|
228
|
+
* Flushes buffered state and counts rows matching an equality filter.
|
|
229
|
+
*
|
|
230
|
+
* @param filter Column and value to compare.
|
|
231
|
+
* @returns Matching rows emitted while finishing the stream.
|
|
232
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
233
|
+
* parsing fails.
|
|
234
|
+
*/
|
|
19
235
|
endCountWhereEquals(filter: CsvEqualsFilter): number;
|
|
236
|
+
/**
|
|
237
|
+
* Counts rows whose field belongs to an inclusion set while parsing a chunk.
|
|
238
|
+
*
|
|
239
|
+
* @param chunk Input bytes.
|
|
240
|
+
* @param filter Column and accepted values.
|
|
241
|
+
* @param final Whether this is the final input chunk.
|
|
242
|
+
* @returns Matching rows emitted by this call.
|
|
243
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
244
|
+
* parsing fails.
|
|
245
|
+
*/
|
|
20
246
|
writeCountWhereIn(chunk: NodeJS.TypedArray | DataView, filter: CsvInFilter, final?: boolean): number;
|
|
247
|
+
/**
|
|
248
|
+
* Flushes buffered state and counts rows matching an inclusion set.
|
|
249
|
+
*
|
|
250
|
+
* @param filter Column and accepted values.
|
|
251
|
+
* @returns Matching rows emitted while finishing the stream.
|
|
252
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
253
|
+
* parsing fails.
|
|
254
|
+
*/
|
|
21
255
|
endCountWhereIn(filter: CsvInFilter): number;
|
|
256
|
+
/**
|
|
257
|
+
* Counts rows whose field starts with a prefix while parsing a chunk.
|
|
258
|
+
*
|
|
259
|
+
* @param chunk Input bytes.
|
|
260
|
+
* @param filter Column and prefix to compare.
|
|
261
|
+
* @param final Whether this is the final input chunk.
|
|
262
|
+
* @returns Matching rows emitted by this call.
|
|
263
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
264
|
+
* parsing fails.
|
|
265
|
+
*/
|
|
22
266
|
writeCountWhereStartsWith(chunk: NodeJS.TypedArray | DataView, filter: CsvStartsWithFilter, final?: boolean): number;
|
|
267
|
+
/**
|
|
268
|
+
* Flushes buffered state and counts rows matching a prefix.
|
|
269
|
+
*
|
|
270
|
+
* @param filter Column and prefix to compare.
|
|
271
|
+
* @returns Matching rows emitted while finishing the stream.
|
|
272
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
273
|
+
* parsing fails.
|
|
274
|
+
*/
|
|
23
275
|
endCountWhereStartsWith(filter: CsvStartsWithFilter): number;
|
|
276
|
+
/**
|
|
277
|
+
* Counts rows satisfying all filters while parsing a chunk.
|
|
278
|
+
*
|
|
279
|
+
* @param chunk Input bytes.
|
|
280
|
+
* @param filters Native filter predicates combined with logical AND.
|
|
281
|
+
* @param final Whether this is the final input chunk.
|
|
282
|
+
* @returns Matching rows emitted by this call.
|
|
283
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
284
|
+
* parsing fails.
|
|
285
|
+
*/
|
|
24
286
|
writeCountWhereAll(chunk: NodeJS.TypedArray | DataView, filters: readonly CsvNativeFilter[], final?: boolean): number;
|
|
287
|
+
/**
|
|
288
|
+
* Flushes buffered state and counts rows satisfying all filters.
|
|
289
|
+
*
|
|
290
|
+
* @param filters Native filter predicates combined with logical AND.
|
|
291
|
+
* @returns Matching rows emitted while finishing the stream.
|
|
292
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
293
|
+
* parsing fails.
|
|
294
|
+
*/
|
|
25
295
|
endCountWhereAll(filters: readonly CsvNativeFilter[]): number;
|
|
296
|
+
/**
|
|
297
|
+
* Counts rows using a postfix native filter program while parsing a chunk.
|
|
298
|
+
*
|
|
299
|
+
* @param chunk Input bytes.
|
|
300
|
+
* @param program Filter predicates and boolean operators in postfix order.
|
|
301
|
+
* The method validates and normalizes the entries before the native call.
|
|
302
|
+
* @param final Whether this is the final input chunk.
|
|
303
|
+
* @returns Matching rows emitted by this call.
|
|
304
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
305
|
+
* parsing rejects the program or input.
|
|
306
|
+
*/
|
|
26
307
|
writeCountWhere(chunk: NodeJS.TypedArray | DataView, program: readonly CsvNativeFilterProgramEntry[], final?: boolean): number;
|
|
308
|
+
/**
|
|
309
|
+
* Flushes buffered state and counts rows using a postfix filter program.
|
|
310
|
+
*
|
|
311
|
+
* @param program Filter predicates and boolean operators in postfix order.
|
|
312
|
+
* The method validates and normalizes the entries before the native call.
|
|
313
|
+
* @returns Matching rows emitted while finishing the stream.
|
|
314
|
+
* @throws {Error} If strict mode is enabled, the parser is closed, or native
|
|
315
|
+
* parsing rejects the program or final row.
|
|
316
|
+
*/
|
|
27
317
|
endCountWhere(program: readonly CsvNativeFilterProgramEntry[]): number;
|
|
318
|
+
/**
|
|
319
|
+
* Discards buffered row state and parser errors while keeping this parser open.
|
|
320
|
+
*
|
|
321
|
+
* Callers must supply projection or filter settings again after a reset.
|
|
322
|
+
*
|
|
323
|
+
* @throws {Error} If the parser is already closed.
|
|
324
|
+
*/
|
|
28
325
|
reset(): void;
|
|
326
|
+
/**
|
|
327
|
+
* Releases the native parser handle.
|
|
328
|
+
*
|
|
329
|
+
* Closing is idempotent. Subsequent parsing calls throw; batches already
|
|
330
|
+
* returned by the parser retain their own lifetime and must be closed
|
|
331
|
+
* separately.
|
|
332
|
+
*/
|
|
29
333
|
close(): void;
|
|
30
|
-
|
|
334
|
+
/** Implements `using` / explicit resource management. */
|
|
31
335
|
[Symbol.dispose](): void;
|
|
32
336
|
}
|
|
337
|
+
export {};
|