@konstit/csv 0.6.0 → 0.7.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 +113 -101
- package/THIRD_PARTY_NOTICES.md +27 -0
- package/dist/api.d.ts +84 -57
- package/dist/api.js +211 -40
- package/dist/batch-pipeline.d.ts +10 -0
- package/dist/batch-pipeline.js +83 -0
- package/dist/batches.d.ts +36 -1
- package/dist/batches.js +241 -5
- package/dist/cli-command.d.ts +7 -7
- package/dist/cli-command.js +325 -164
- package/dist/cli-schema.d.ts +51 -21
- package/dist/cli-schema.js +126 -65
- package/dist/cli.js +1 -1
- package/dist/file-stream.d.ts +66 -18
- package/dist/file-stream.js +534 -199
- package/dist/files.d.ts +17 -37
- package/dist/files.js +50 -21
- package/dist/gzip-reader.d.ts +2 -0
- package/dist/gzip-reader.js +37 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/inspect-file.d.ts +26 -3
- package/dist/inspect-file.js +169 -74
- package/dist/inspect-zip.d.ts +26 -0
- package/dist/inspect-zip.js +59 -0
- package/dist/latin1-rows.d.ts +11 -3
- package/dist/latin1-rows.js +276 -75
- package/dist/materialize-field.d.ts +6 -0
- package/dist/materialize-field.js +9 -0
- package/dist/native.d.ts +118 -20
- package/dist/native.js +53 -23
- package/dist/normalize.d.ts +7 -1
- package/dist/normalize.js +49 -9
- package/dist/options.d.ts +27 -12
- package/dist/parser.d.ts +34 -14
- package/dist/parser.js +296 -102
- package/dist/strict-schema.d.ts +7 -8
- package/dist/strict-schema.js +45 -83
- package/dist/transforms.d.ts +1 -3
- package/dist/transforms.js +17 -16
- package/dist/types.d.ts +192 -75
- package/dist/zip-entry.d.ts +14 -0
- package/dist/zip-entry.js +155 -0
- package/dist/zip-reader.d.ts +14 -3
- package/dist/zip-reader.js +65 -23
- package/package.json +34 -23
- 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 +18 -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/parser.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { NativeCsvBatch } from './batches.js';
|
|
2
|
-
import type
|
|
1
|
+
import { NativeCsvBatch, NativeCsvRawRecordBatch } from './batches.js';
|
|
2
|
+
import { type CsvFileInput } from './file-stream.js';
|
|
3
3
|
import { type NativePointer } from './native.js';
|
|
4
4
|
import type { CsvColumns, CsvNativeFilterProgramEntry, CsvParserOptions, CsvRow, CsvTransform, NativeCsvParserOptions } from './types.js';
|
|
5
5
|
export declare const nativeCsvParserFinalizer: FinalizationRegistry<NativePointer>;
|
|
6
|
-
|
|
6
|
+
/** Read the header with the same dialect and limits used for data records. */
|
|
7
|
+
export declare function readCsvHeader(nextChunk: () => Promise<IteratorResult<Uint8Array, void>>, options: CsvParserOptions): Promise<{
|
|
8
|
+
readonly value: {
|
|
9
|
+
readonly names: CsvRow;
|
|
10
|
+
readonly record: number;
|
|
11
|
+
};
|
|
12
|
+
readonly replay: Generator<Uint8Array, void>;
|
|
13
|
+
}>;
|
|
14
|
+
type OpenParseAhead<TBatch> = (chunks: AsyncIterator<Uint8Array, void>, first: Uint8Array, limit: number | undefined) => AsyncGenerator<TBatch, void> | undefined;
|
|
15
|
+
export declare function parseFileChunks<TBatch extends NativeCsvBatch | NativeCsvRawRecordBatch>(input: CsvFileInput, parser: {
|
|
16
|
+
writeBatch(chunk: Uint8Array, final?: boolean): TBatch;
|
|
17
|
+
}, limit: number | undefined, openParseAhead?: OpenParseAhead<TBatch>): AsyncGenerator<TBatch, void>;
|
|
18
|
+
export declare function parseUtf8RowBatches(input: CsvFileInput, parser: NativeCsvParser, limit: number | undefined): AsyncGenerator<NativeCsvBatch, void>;
|
|
19
|
+
export declare function parseRawRecordChunks(input: CsvFileInput, options: CsvParserOptions, program: readonly CsvNativeFilterProgramEntry[] | undefined): AsyncGenerator<NativeCsvRawRecordBatch, void>;
|
|
7
20
|
export declare function countFileChunks(input: CsvFileInput, options: CsvParserOptions, filters?: readonly CsvNativeFilterProgramEntry[]): Promise<number>;
|
|
8
|
-
export declare function createPreparedParser(options: CsvParserOptions, columns?: CsvColumns, program?: readonly CsvNativeFilterProgramEntry[], transform?: readonly CsvTransform[], output?: 'batches' | 'rows'): NativeCsvParser;
|
|
21
|
+
export declare function createPreparedParser(options: CsvParserOptions, columns?: CsvColumns, program?: readonly CsvNativeFilterProgramEntry[], transform?: readonly CsvTransform[], output?: 'batches' | 'rows' | 'pipelined-rows'): NativeCsvParser;
|
|
9
22
|
interface PreparedNativeWriter {
|
|
10
23
|
writeBatch(input: NodeJS.TypedArray | DataView, final: boolean): NativePointer | null;
|
|
11
24
|
writeCount(input: NodeJS.TypedArray | DataView, final: boolean): bigint | number;
|
|
@@ -25,9 +38,12 @@ interface PreparedNativeWriter {
|
|
|
25
38
|
* @throws {Error} If the native library rejects the configuration.
|
|
26
39
|
*/
|
|
27
40
|
export declare function prepareNativeParser(handle: NativePointer, columns: CsvColumns | undefined, program: readonly CsvNativeFilterProgramEntry[] | undefined): PreparedNativeWriter;
|
|
28
|
-
export declare function validateRowSelection({ skipRows, limit }: Pick<CsvParserOptions, 'skipRows' | 'limit'>): void;
|
|
29
|
-
export declare function setRowSelection(handle: NativePointer, options: CsvParserOptions
|
|
41
|
+
export declare function validateRowSelection({ skipRows, skipEmptyLines, limit }: Pick<CsvParserOptions, 'skipRows' | 'skipEmptyLines' | 'limit'>): void;
|
|
42
|
+
export declare function setRowSelection(handle: NativePointer, options: CsvParserOptions): void;
|
|
43
|
+
export declare function prepareNativeValidation({ strict, expectedHeaders, maxRecordBytes }: Pick<CsvParserOptions, 'strict' | 'expectedHeaders' | 'maxRecordBytes'>): ((handle: NativePointer) => void) | undefined;
|
|
30
44
|
declare const createSchemaParser: unique symbol;
|
|
45
|
+
declare const physicalRows: unique symbol;
|
|
46
|
+
declare const openPipeline: unique symbol;
|
|
31
47
|
/**
|
|
32
48
|
* Incrementally parses caller-owned CSV chunks through the native parser.
|
|
33
49
|
*
|
|
@@ -36,6 +52,8 @@ declare const createSchemaParser: unique symbol;
|
|
|
36
52
|
* for the next write. Every returned batch owns native memory and must be
|
|
37
53
|
* closed or disposed. `write()` and `end()` are convenience methods that
|
|
38
54
|
* materialize rows and close their temporary batches automatically.
|
|
55
|
+
* With automatic delimiter detection, writes emit no rows until the input
|
|
56
|
+
* exceeds 64 KiB or ends. Supply a delimiter to parse each chunk as it arrives.
|
|
39
57
|
*
|
|
40
58
|
* The constructor captures the projection and filters for the lifetime of the parser.
|
|
41
59
|
* Filters use physical column indexes. Batches emit fields in projection order.
|
|
@@ -51,18 +69,17 @@ declare const createSchemaParser: unique symbol;
|
|
|
51
69
|
*/
|
|
52
70
|
export declare class NativeCsvParser {
|
|
53
71
|
#private;
|
|
54
|
-
static [createSchemaParser](options: NativeCsvParserOptions, output: 'batches' | 'rows'): NativeCsvParser;
|
|
72
|
+
static [createSchemaParser](options: NativeCsvParserOptions, output: 'batches' | 'rows' | 'pipelined-rows'): NativeCsvParser;
|
|
55
73
|
/**
|
|
56
74
|
* Creates an open parser.
|
|
57
75
|
*
|
|
58
76
|
* @param options Parser settings, output columns and predicates. The delimiter defaults
|
|
59
|
-
* to
|
|
60
|
-
* APIs handle schema metadata such as `expectedHeaders`.
|
|
77
|
+
* to automatic detection. Strict validation checks physical records before projection and filtering.
|
|
61
78
|
* @throws {Error} If the delimiter is not one character or native parser
|
|
62
79
|
* creation fails.
|
|
63
80
|
* @throws {RangeError} If selected or fixed column settings are out of range.
|
|
64
81
|
*/
|
|
65
|
-
constructor(
|
|
82
|
+
constructor(supplied?: NativeCsvParserOptions);
|
|
66
83
|
/** Whether the native parser handle has been released. */
|
|
67
84
|
get closed(): boolean;
|
|
68
85
|
/**
|
|
@@ -85,6 +102,8 @@ export declare class NativeCsvParser {
|
|
|
85
102
|
* Call `batch.close()` or use `using` for the returned batch. The parser may
|
|
86
103
|
* retain an incomplete row between calls. `final: true` marks the input end
|
|
87
104
|
* and flushes that row.
|
|
105
|
+
* Switch between count and materialized writes at record boundaries after any
|
|
106
|
+
* delimiter probe bytes have been parsed.
|
|
88
107
|
*
|
|
89
108
|
* @param chunk Input bytes.
|
|
90
109
|
* @param final Whether this is the final input chunk.
|
|
@@ -92,6 +111,7 @@ export declare class NativeCsvParser {
|
|
|
92
111
|
* @throws {Error} If the parser is closed or native parsing fails.
|
|
93
112
|
*/
|
|
94
113
|
writeBatch(chunk: NodeJS.TypedArray | DataView, final?: boolean): NativeCsvBatch;
|
|
114
|
+
[openPipeline](chunks: AsyncIterator<Uint8Array, void>, first: Uint8Array, limit: number | undefined): AsyncGenerator<NativeCsvBatch, void> | undefined;
|
|
95
115
|
/**
|
|
96
116
|
* Flushes the parser and materializes its final rows.
|
|
97
117
|
*
|
|
@@ -118,22 +138,21 @@ export declare class NativeCsvParser {
|
|
|
118
138
|
* @param chunk Input bytes.
|
|
119
139
|
* @param final Whether this is the final input chunk.
|
|
120
140
|
* @returns The number of rows emitted by this call.
|
|
121
|
-
* @throws {Error}
|
|
122
|
-
* or if the parser is closed/native parsing fails.
|
|
141
|
+
* @throws {Error} If the parser is closed or a consumed record fails validation.
|
|
123
142
|
*/
|
|
124
143
|
writeCount(chunk: NodeJS.TypedArray | DataView, final?: boolean): number;
|
|
125
144
|
/**
|
|
126
145
|
* Flushes buffered state and returns the number of matching final records.
|
|
127
146
|
*
|
|
128
147
|
* @returns The number of rows emitted while finishing the stream.
|
|
129
|
-
* @throws {Error} If
|
|
130
|
-
* parsing fails.
|
|
148
|
+
* @throws {Error} If the parser is closed or the final record fails validation.
|
|
131
149
|
*/
|
|
132
150
|
endCount(): number;
|
|
133
151
|
/**
|
|
134
152
|
* Discards buffered row state and parser errors while keeping this parser open.
|
|
135
153
|
*
|
|
136
154
|
* Row skipping and limiting restart with the constructor's values. Projection and filters stay active.
|
|
155
|
+
* Automatic delimiter detection runs again on the next input.
|
|
137
156
|
*
|
|
138
157
|
* @throws {Error} If the parser is already closed.
|
|
139
158
|
*/
|
|
@@ -148,5 +167,6 @@ export declare class NativeCsvParser {
|
|
|
148
167
|
close(): void;
|
|
149
168
|
/** Implements `using` / explicit resource management. */
|
|
150
169
|
[Symbol.dispose](): void;
|
|
170
|
+
[physicalRows](): number;
|
|
151
171
|
}
|
|
152
172
|
export {};
|