@konstit/csv 0.5.0 → 0.6.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 +36 -3
- package/THIRD_PARTY_NOTICES.md +99 -0
- package/dist/api.d.ts +3 -0
- package/dist/api.js +34 -108
- package/dist/batches.d.ts +3 -4
- package/dist/batches.js +103 -29
- package/dist/cli-command.js +145 -75
- package/dist/cli-schema.d.ts +25 -5
- package/dist/cli-schema.js +48 -23
- package/dist/file-stream.d.ts +10 -3
- package/dist/file-stream.js +22 -17
- package/dist/files.js +32 -76
- package/dist/filter.d.ts +2 -3
- package/dist/filter.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/inspect-file.d.ts +16 -6
- package/dist/inspect-file.js +67 -17
- package/dist/latin1-rows.d.ts +3 -3
- package/dist/latin1-rows.js +65 -15
- package/dist/materialize-field.d.ts +1 -0
- package/dist/materialize-field.js +10 -1
- package/dist/native.d.ts +47 -71
- package/dist/native.js +28 -86
- package/dist/normalize.d.ts +1 -40
- package/dist/normalize.js +25 -62
- package/dist/options-snapshot.d.ts +2 -2
- package/dist/options-snapshot.js +2 -0
- package/dist/parser.d.ts +17 -202
- package/dist/parser.js +152 -230
- package/dist/strict-schema.d.ts +1 -1
- package/dist/strict-schema.js +4 -3
- package/dist/transforms.d.ts +11 -0
- package/dist/transforms.js +192 -0
- package/dist/types.d.ts +77 -9
- package/dist/zip-reader.d.ts +2 -0
- package/dist/zip-reader.js +31 -21
- package/package.json +3 -2
- 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 +14 -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/native.d.ts
CHANGED
|
@@ -13,7 +13,23 @@ export declare const EMPTY_BUFFER: Uint8Array<ArrayBuffer>;
|
|
|
13
13
|
export declare const EMPTY_U32: Uint32Array<ArrayBuffer>;
|
|
14
14
|
export declare const DEFAULT_CHUNK_SIZE: number;
|
|
15
15
|
export declare const native: import("bun:ffi").Library<{
|
|
16
|
-
readonly
|
|
16
|
+
readonly csv_parser_add_transform: {
|
|
17
|
+
readonly args: readonly ["ptr", "u32", "u32"];
|
|
18
|
+
readonly returns: "bool";
|
|
19
|
+
};
|
|
20
|
+
readonly csv_parser_add_transform_with_default: {
|
|
21
|
+
readonly args: readonly ["ptr", "u32", "u32", "buffer", "buffer_length"];
|
|
22
|
+
readonly returns: "bool";
|
|
23
|
+
};
|
|
24
|
+
readonly csv_parser_transform_pair: {
|
|
25
|
+
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length", "buffer", "buffer_length"];
|
|
26
|
+
readonly returns: "bool";
|
|
27
|
+
};
|
|
28
|
+
readonly csv_parser_transform_validated_batch: {
|
|
29
|
+
readonly args: readonly ["ptr", "ptr"];
|
|
30
|
+
readonly returns: "ptr";
|
|
31
|
+
};
|
|
32
|
+
readonly csv_probe_format_v2: {
|
|
17
33
|
readonly args: readonly ["buffer", "u32", "bool", "bool", "ptr"];
|
|
18
34
|
readonly returns: "u32";
|
|
19
35
|
};
|
|
@@ -25,11 +41,31 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
25
41
|
readonly args: readonly ["int", "u8"];
|
|
26
42
|
readonly returns: "ptr";
|
|
27
43
|
};
|
|
44
|
+
readonly csv_parser_create_prepared: {
|
|
45
|
+
readonly args: readonly ["int", "u8", "u32"];
|
|
46
|
+
readonly returns: "ptr";
|
|
47
|
+
};
|
|
48
|
+
readonly csv_parser_enable_transformed_quoted_spans: {
|
|
49
|
+
readonly args: readonly ["ptr"];
|
|
50
|
+
readonly returns: "void";
|
|
51
|
+
};
|
|
52
|
+
readonly csv_parser_set_row_selection: {
|
|
53
|
+
readonly args: readonly ["ptr", "u64", "u64", "bool"];
|
|
54
|
+
readonly returns: "void";
|
|
55
|
+
};
|
|
56
|
+
readonly csv_parser_take_skipped_header: {
|
|
57
|
+
readonly args: readonly ["ptr"];
|
|
58
|
+
readonly returns: "ptr";
|
|
59
|
+
};
|
|
60
|
+
readonly csv_parser_skipped_rows: {
|
|
61
|
+
readonly args: readonly ["ptr"];
|
|
62
|
+
readonly returns: "u64";
|
|
63
|
+
};
|
|
28
64
|
readonly csv_parser_destroy: {
|
|
29
65
|
readonly args: readonly ["ptr"];
|
|
30
66
|
readonly returns: "void";
|
|
31
67
|
};
|
|
32
|
-
readonly
|
|
68
|
+
readonly csv_parser_reset_stream: {
|
|
33
69
|
readonly args: readonly ["ptr"];
|
|
34
70
|
readonly returns: "void";
|
|
35
71
|
};
|
|
@@ -37,50 +73,18 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
37
73
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
38
74
|
readonly returns: "ptr";
|
|
39
75
|
};
|
|
40
|
-
readonly csv_parser_finish_batch: {
|
|
41
|
-
readonly args: readonly ["ptr"];
|
|
42
|
-
readonly returns: "ptr";
|
|
43
|
-
};
|
|
44
76
|
readonly csv_parser_write_strict_batch: {
|
|
45
77
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
46
78
|
readonly returns: "ptr";
|
|
47
79
|
};
|
|
48
|
-
readonly csv_parser_finish_strict_batch: {
|
|
49
|
-
readonly args: readonly ["ptr"];
|
|
50
|
-
readonly returns: "ptr";
|
|
51
|
-
};
|
|
52
80
|
readonly csv_parser_write_fixed_batch: {
|
|
53
81
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32"];
|
|
54
82
|
readonly returns: "ptr";
|
|
55
83
|
};
|
|
56
|
-
readonly csv_parser_finish_fixed_batch: {
|
|
57
|
-
readonly args: readonly ["ptr", "u32"];
|
|
58
|
-
readonly returns: "ptr";
|
|
59
|
-
};
|
|
60
84
|
readonly csv_parser_write_strict_fixed_batch: {
|
|
61
85
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32"];
|
|
62
86
|
readonly returns: "ptr";
|
|
63
87
|
};
|
|
64
|
-
readonly csv_parser_finish_strict_fixed_batch: {
|
|
65
|
-
readonly args: readonly ["ptr", "u32"];
|
|
66
|
-
readonly returns: "ptr";
|
|
67
|
-
};
|
|
68
|
-
readonly csv_parser_write_projected_batch: {
|
|
69
|
-
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"];
|
|
70
|
-
readonly returns: "ptr";
|
|
71
|
-
};
|
|
72
|
-
readonly csv_parser_finish_projected_batch: {
|
|
73
|
-
readonly args: readonly ["ptr", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"];
|
|
74
|
-
readonly returns: "ptr";
|
|
75
|
-
};
|
|
76
|
-
readonly csv_parser_write_projected_batch_where_all: {
|
|
77
|
-
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
78
|
-
readonly returns: "ptr";
|
|
79
|
-
};
|
|
80
|
-
readonly csv_parser_finish_projected_batch_where_all: {
|
|
81
|
-
readonly args: readonly ["ptr", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
82
|
-
readonly returns: "ptr";
|
|
83
|
-
};
|
|
84
88
|
readonly csv_batch_destroy: {
|
|
85
89
|
readonly args: readonly ["ptr"];
|
|
86
90
|
readonly returns: "void";
|
|
@@ -141,42 +145,6 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
141
145
|
readonly args: readonly ["ptr"];
|
|
142
146
|
readonly returns: "ptr";
|
|
143
147
|
};
|
|
144
|
-
readonly csv_parser_finish_count: {
|
|
145
|
-
readonly args: readonly ["ptr"];
|
|
146
|
-
readonly returns: "u64";
|
|
147
|
-
};
|
|
148
|
-
readonly csv_parser_write_count_where_all: {
|
|
149
|
-
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
150
|
-
readonly returns: "u64";
|
|
151
|
-
};
|
|
152
|
-
readonly csv_parser_finish_count_where_all: {
|
|
153
|
-
readonly args: readonly ["ptr", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
154
|
-
readonly returns: "u64";
|
|
155
|
-
};
|
|
156
|
-
readonly csv_parser_write_count_where_equals: {
|
|
157
|
-
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"];
|
|
158
|
-
readonly returns: "u64";
|
|
159
|
-
};
|
|
160
|
-
readonly csv_parser_finish_count_where_equals: {
|
|
161
|
-
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length"];
|
|
162
|
-
readonly returns: "u64";
|
|
163
|
-
};
|
|
164
|
-
readonly csv_parser_write_count_where_in: {
|
|
165
|
-
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length", "buffer", "u64"];
|
|
166
|
-
readonly returns: "u64";
|
|
167
|
-
};
|
|
168
|
-
readonly csv_parser_finish_count_where_in: {
|
|
169
|
-
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length", "buffer", "u64"];
|
|
170
|
-
readonly returns: "u64";
|
|
171
|
-
};
|
|
172
|
-
readonly csv_parser_write_count_where_starts_with: {
|
|
173
|
-
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"];
|
|
174
|
-
readonly returns: "u64";
|
|
175
|
-
};
|
|
176
|
-
readonly csv_parser_finish_count_where_starts_with: {
|
|
177
|
-
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length"];
|
|
178
|
-
readonly returns: "u64";
|
|
179
|
-
};
|
|
180
148
|
readonly csv_zip_reader_create: {
|
|
181
149
|
readonly args: readonly ["cstring", "buffer", "buffer_length", "u64", "u32"];
|
|
182
150
|
readonly returns: "ptr";
|
|
@@ -185,6 +153,10 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
185
153
|
readonly args: readonly ["ptr"];
|
|
186
154
|
readonly returns: "void";
|
|
187
155
|
};
|
|
156
|
+
readonly csv_zip_reader_entry_name: {
|
|
157
|
+
readonly args: readonly ["ptr", "buffer"];
|
|
158
|
+
readonly returns: "ptr";
|
|
159
|
+
};
|
|
188
160
|
readonly csv_zip_reader_enable_read_ahead: {
|
|
189
161
|
readonly args: readonly ["ptr", "u32"];
|
|
190
162
|
readonly returns: "void";
|
|
@@ -229,6 +201,10 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
229
201
|
readonly args: readonly ["u8", "u32"];
|
|
230
202
|
readonly returns: "ptr";
|
|
231
203
|
};
|
|
204
|
+
readonly csv_parser_create_latin1_cleanup_rows: {
|
|
205
|
+
readonly args: readonly ["u8", "u32"];
|
|
206
|
+
readonly returns: "ptr";
|
|
207
|
+
};
|
|
232
208
|
readonly csv_batch_quoted_rows_ptr: {
|
|
233
209
|
readonly args: readonly ["ptr"];
|
|
234
210
|
readonly returns: "ptr";
|
|
@@ -238,7 +214,7 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
238
214
|
readonly returns: "ptr";
|
|
239
215
|
};
|
|
240
216
|
}>;
|
|
241
|
-
export declare function latin1RowsParser(fixedColumns: number | undefined): (delimiter: number) => NativePointer | null;
|
|
217
|
+
export declare function latin1RowsParser(fixedColumns: number | undefined, cleanup?: boolean): (delimiter: number) => NativePointer | null;
|
|
242
218
|
export declare function resolveNativeLibraryPath(configuredPath: string | undefined): string;
|
|
243
219
|
export declare function requireConfiguredNativeLibraryPath(configuredPath: string): string;
|
|
244
220
|
export declare function nativeLibraryCandidates(root: string, target: string, librarySuffix: string): readonly string[];
|
package/dist/native.js
CHANGED
|
@@ -19,7 +19,20 @@ export const EMPTY_BUFFER = EMPTY_BUFFER_STORAGE.subarray(0, 0);
|
|
|
19
19
|
export const EMPTY_U32 = new Uint32Array(1);
|
|
20
20
|
export const DEFAULT_CHUNK_SIZE = 1048576;
|
|
21
21
|
const CSV_SYMBOLS = {
|
|
22
|
-
|
|
22
|
+
csv_parser_add_transform: { args: ["ptr", "u32", "u32"], returns: "bool" },
|
|
23
|
+
csv_parser_add_transform_with_default: {
|
|
24
|
+
args: [
|
|
25
|
+
"ptr",
|
|
26
|
+
"u32",
|
|
27
|
+
"u32",
|
|
28
|
+
"buffer",
|
|
29
|
+
"buffer_length"
|
|
30
|
+
],
|
|
31
|
+
returns: "bool"
|
|
32
|
+
},
|
|
33
|
+
csv_parser_transform_pair: { args: ["ptr", "u32", "buffer", "buffer_length", "buffer", "buffer_length"], returns: "bool" },
|
|
34
|
+
csv_parser_transform_validated_batch: { args: ["ptr", "ptr"], returns: "ptr" },
|
|
35
|
+
csv_probe_format_v2: {
|
|
23
36
|
args: [
|
|
24
37
|
"buffer",
|
|
25
38
|
"u32",
|
|
@@ -37,11 +50,16 @@ const CSV_SYMBOLS = {
|
|
|
37
50
|
args: ["int", "u8"],
|
|
38
51
|
returns: "ptr"
|
|
39
52
|
},
|
|
53
|
+
csv_parser_create_prepared: { args: ["int", "u8", "u32"], returns: "ptr" },
|
|
54
|
+
csv_parser_enable_transformed_quoted_spans: { args: ["ptr"], returns: "void" },
|
|
55
|
+
csv_parser_set_row_selection: { args: ["ptr", "u64", "u64", "bool"], returns: "void" },
|
|
56
|
+
csv_parser_take_skipped_header: { args: ["ptr"], returns: "ptr" },
|
|
57
|
+
csv_parser_skipped_rows: { args: ["ptr"], returns: "u64" },
|
|
40
58
|
csv_parser_destroy: {
|
|
41
59
|
args: ["ptr"],
|
|
42
60
|
returns: "void"
|
|
43
61
|
},
|
|
44
|
-
|
|
62
|
+
csv_parser_reset_stream: {
|
|
45
63
|
args: ["ptr"],
|
|
46
64
|
returns: "void"
|
|
47
65
|
},
|
|
@@ -49,64 +67,18 @@ const CSV_SYMBOLS = {
|
|
|
49
67
|
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
50
68
|
returns: "ptr"
|
|
51
69
|
},
|
|
52
|
-
csv_parser_finish_batch: {
|
|
53
|
-
args: ["ptr"],
|
|
54
|
-
returns: "ptr"
|
|
55
|
-
},
|
|
56
70
|
csv_parser_write_strict_batch: {
|
|
57
71
|
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
58
72
|
returns: "ptr"
|
|
59
73
|
},
|
|
60
|
-
csv_parser_finish_strict_batch: {
|
|
61
|
-
args: ["ptr"],
|
|
62
|
-
returns: "ptr"
|
|
63
|
-
},
|
|
64
74
|
csv_parser_write_fixed_batch: {
|
|
65
75
|
args: ["ptr", "buffer", "buffer_length", "bool", "u32"],
|
|
66
76
|
returns: "ptr"
|
|
67
77
|
},
|
|
68
|
-
csv_parser_finish_fixed_batch: {
|
|
69
|
-
args: ["ptr", "u32"],
|
|
70
|
-
returns: "ptr"
|
|
71
|
-
},
|
|
72
78
|
csv_parser_write_strict_fixed_batch: {
|
|
73
79
|
args: ["ptr", "buffer", "buffer_length", "bool", "u32"],
|
|
74
80
|
returns: "ptr"
|
|
75
81
|
},
|
|
76
|
-
csv_parser_finish_strict_fixed_batch: {
|
|
77
|
-
args: ["ptr", "u32"],
|
|
78
|
-
returns: "ptr"
|
|
79
|
-
},
|
|
80
|
-
csv_parser_write_projected_batch: {
|
|
81
|
-
args: ["ptr", "buffer", "buffer_length", "bool", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"],
|
|
82
|
-
returns: "ptr"
|
|
83
|
-
},
|
|
84
|
-
csv_parser_finish_projected_batch: {
|
|
85
|
-
args: ["ptr", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"],
|
|
86
|
-
returns: "ptr"
|
|
87
|
-
},
|
|
88
|
-
csv_parser_write_projected_batch_where_all: {
|
|
89
|
-
args: [
|
|
90
|
-
"ptr",
|
|
91
|
-
"buffer",
|
|
92
|
-
"buffer_length",
|
|
93
|
-
"bool",
|
|
94
|
-
"bool",
|
|
95
|
-
"buffer",
|
|
96
|
-
"u64",
|
|
97
|
-
"buffer",
|
|
98
|
-
"u64",
|
|
99
|
-
"buffer",
|
|
100
|
-
"buffer_length",
|
|
101
|
-
"buffer",
|
|
102
|
-
"u64"
|
|
103
|
-
],
|
|
104
|
-
returns: "ptr"
|
|
105
|
-
},
|
|
106
|
-
csv_parser_finish_projected_batch_where_all: {
|
|
107
|
-
args: ["ptr", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
108
|
-
returns: "ptr"
|
|
109
|
-
},
|
|
110
82
|
csv_batch_destroy: {
|
|
111
83
|
args: ["ptr"],
|
|
112
84
|
returns: "void"
|
|
@@ -167,42 +139,6 @@ const CSV_SYMBOLS = {
|
|
|
167
139
|
args: ["ptr"],
|
|
168
140
|
returns: "ptr"
|
|
169
141
|
},
|
|
170
|
-
csv_parser_finish_count: {
|
|
171
|
-
args: ["ptr"],
|
|
172
|
-
returns: "u64"
|
|
173
|
-
},
|
|
174
|
-
csv_parser_write_count_where_all: {
|
|
175
|
-
args: ["ptr", "buffer", "buffer_length", "bool", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
176
|
-
returns: "u64"
|
|
177
|
-
},
|
|
178
|
-
csv_parser_finish_count_where_all: {
|
|
179
|
-
args: ["ptr", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
180
|
-
returns: "u64"
|
|
181
|
-
},
|
|
182
|
-
csv_parser_write_count_where_equals: {
|
|
183
|
-
args: ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"],
|
|
184
|
-
returns: "u64"
|
|
185
|
-
},
|
|
186
|
-
csv_parser_finish_count_where_equals: {
|
|
187
|
-
args: ["ptr", "u32", "buffer", "buffer_length"],
|
|
188
|
-
returns: "u64"
|
|
189
|
-
},
|
|
190
|
-
csv_parser_write_count_where_in: {
|
|
191
|
-
args: ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length", "buffer", "u64"],
|
|
192
|
-
returns: "u64"
|
|
193
|
-
},
|
|
194
|
-
csv_parser_finish_count_where_in: {
|
|
195
|
-
args: ["ptr", "u32", "buffer", "buffer_length", "buffer", "u64"],
|
|
196
|
-
returns: "u64"
|
|
197
|
-
},
|
|
198
|
-
csv_parser_write_count_where_starts_with: {
|
|
199
|
-
args: ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"],
|
|
200
|
-
returns: "u64"
|
|
201
|
-
},
|
|
202
|
-
csv_parser_finish_count_where_starts_with: {
|
|
203
|
-
args: ["ptr", "u32", "buffer", "buffer_length"],
|
|
204
|
-
returns: "u64"
|
|
205
|
-
},
|
|
206
142
|
csv_zip_reader_create: {
|
|
207
143
|
args: ["cstring", "buffer", "buffer_length", "u64", "u32"],
|
|
208
144
|
returns: "ptr"
|
|
@@ -211,6 +147,10 @@ const CSV_SYMBOLS = {
|
|
|
211
147
|
args: ["ptr"],
|
|
212
148
|
returns: "void"
|
|
213
149
|
},
|
|
150
|
+
csv_zip_reader_entry_name: {
|
|
151
|
+
args: ["ptr", "buffer"],
|
|
152
|
+
returns: "ptr"
|
|
153
|
+
},
|
|
214
154
|
csv_zip_reader_enable_read_ahead: {
|
|
215
155
|
args: ["ptr", "u32"],
|
|
216
156
|
returns: "void"
|
|
@@ -249,6 +189,7 @@ const CSV_SYMBOLS = {
|
|
|
249
189
|
},
|
|
250
190
|
csv_parser_create_latin1_rows_with_quoted_spans: { args: ["u8"], returns: "ptr" },
|
|
251
191
|
csv_parser_create_latin1_quoted_rows: { args: ["u8", "u32"], returns: "ptr" },
|
|
192
|
+
csv_parser_create_latin1_cleanup_rows: { args: ["u8", "u32"], returns: "ptr" },
|
|
252
193
|
csv_batch_quoted_rows_ptr: { args: ["ptr"], returns: "ptr" },
|
|
253
194
|
csv_parser_create_latin1_rows_with_fixed_columns: {
|
|
254
195
|
args: ["u8", "u32"],
|
|
@@ -256,8 +197,9 @@ const CSV_SYMBOLS = {
|
|
|
256
197
|
}
|
|
257
198
|
};
|
|
258
199
|
export const native = dlopen(resolveNativeLibraryPath(process.env.CSV_NATIVE_LIBRARY_PATH), CSV_SYMBOLS);
|
|
259
|
-
export function latin1RowsParser(fixedColumns) {
|
|
260
|
-
|
|
200
|
+
export function latin1RowsParser(fixedColumns, cleanup = !1) {
|
|
201
|
+
const create = cleanup ? native.symbols.csv_parser_create_latin1_cleanup_rows : native.symbols.csv_parser_create_latin1_quoted_rows;
|
|
202
|
+
return (delimiter) => create(delimiter, fixedColumns ?? 0);
|
|
261
203
|
}
|
|
262
204
|
export function resolveNativeLibraryPath(configuredPath) {
|
|
263
205
|
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
package/dist/normalize.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CsvColumns, CsvEncoding,
|
|
1
|
+
import type { CsvColumns, CsvEncoding, CsvFieldValue, CsvNativeEncoding, CsvNativeFilter, CsvNativeFilterProgramEntry, CsvNativeProjectionOptions, CsvRegex } from './types.js';
|
|
2
2
|
interface PreparedCsvBufferInput {
|
|
3
3
|
readonly bytes: NodeJS.TypedArray | DataView;
|
|
4
4
|
readonly parserEncoding: 'utf8' | 'latin1';
|
|
@@ -8,27 +8,6 @@ export declare const MAX_PROJECTION_LENGTH = 2024;
|
|
|
8
8
|
export declare const MAX_FILTER_COUNT = 2024;
|
|
9
9
|
export declare const MAX_REGEX_FILTER_COUNT = 32;
|
|
10
10
|
export declare const MAX_FILTER_PROGRAM_LENGTH = 4096;
|
|
11
|
-
/**
|
|
12
|
-
* Boolean operation in a postfix filter program accepted by `NativeCsvParser`.
|
|
13
|
-
*
|
|
14
|
-
* Predicates push results onto a stack. An operator consumes the most recent
|
|
15
|
-
* results and pushes one combined result. Missing columns produce an unknown
|
|
16
|
-
* result, which remains unknown under `not` and does not select a row by itself.
|
|
17
|
-
*/
|
|
18
|
-
export interface CsvNativeFilterOperator {
|
|
19
|
-
/** Number of preceding stack results to consume; positive, and exactly one for `not`. */
|
|
20
|
-
readonly operandCount: number;
|
|
21
|
-
/** Combine operands with AND, OR, or unary negation. */
|
|
22
|
-
readonly operator: 'all' | 'any' | 'not';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Predicate or boolean operator in a low-level postfix filter program.
|
|
26
|
-
*
|
|
27
|
-
* Place predicates before the operators that consume them. A complete program
|
|
28
|
-
* must leave exactly one result on the stack and contain at most 4096 entries.
|
|
29
|
-
* Most applications can use `csv.column()` and its boolean combinators instead.
|
|
30
|
-
*/
|
|
31
|
-
export type CsvNativeFilterProgramEntry = CsvNativeFilter | CsvNativeFilterOperator;
|
|
32
11
|
export declare function projectionFilterProgram(options: CsvNativeProjectionOptions): readonly CsvNativeFilterProgramEntry[] | undefined;
|
|
33
12
|
export declare function encodingCode(encoding?: CsvNativeEncoding): number;
|
|
34
13
|
/**
|
|
@@ -44,29 +23,11 @@ export declare function normalizeFixedColumnsCount(value: number | undefined, la
|
|
|
44
23
|
export declare function rejectSelectedColumns(options: object): void;
|
|
45
24
|
export declare function normalizeColumns(columns: CsvColumns | undefined): Uint32Array;
|
|
46
25
|
export declare function normalizeColumnIndex(column: number, label: string): number;
|
|
47
|
-
export declare function normalizeEqualsFilter(filter: CsvEqualsFilter | undefined): {
|
|
48
|
-
enabled: boolean;
|
|
49
|
-
column: number;
|
|
50
|
-
value: Uint8Array;
|
|
51
|
-
valueLength: number;
|
|
52
|
-
};
|
|
53
26
|
export declare function normalizeFilterColumn(column: number): number;
|
|
54
27
|
export declare function normalizeFilterValue(value: CsvFieldValue): Uint8Array;
|
|
55
28
|
type CsvRegexInput = Pick<CsvRegex, 'flags' | 'source'>;
|
|
56
29
|
export declare function normalizeRegex(regex: CsvRegexInput): Uint8Array;
|
|
57
30
|
export declare function validateRegex(regex: CsvRegexInput): void;
|
|
58
|
-
export declare function normalizeInFilter(filter: CsvInFilter): {
|
|
59
|
-
column: number;
|
|
60
|
-
valuesData: Uint8Array;
|
|
61
|
-
valuesDataLength: number;
|
|
62
|
-
offsets: Uint32Array;
|
|
63
|
-
valueCount: number;
|
|
64
|
-
};
|
|
65
|
-
export declare function normalizeStartsWithFilter(filter: CsvStartsWithFilter): {
|
|
66
|
-
column: number;
|
|
67
|
-
value: Uint8Array;
|
|
68
|
-
valueLength: number;
|
|
69
|
-
};
|
|
70
31
|
export declare function normalizeNativeFilters(filters: readonly CsvNativeFilter[] | undefined): {
|
|
71
32
|
descriptors: Uint32Array;
|
|
72
33
|
filterCount: number;
|
package/dist/normalize.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
native
|
|
5
5
|
} from "./native.js";
|
|
6
6
|
const LATIN1_ENCODINGS = new Set(["latin1", "iso88591", "iso-8859-1"]);
|
|
7
|
+
const EMPTY_COLUMNS = EMPTY_U32.subarray(0, 0);
|
|
7
8
|
export const MAX_COLUMN_INDEX = 2024;
|
|
8
9
|
export const MAX_PROJECTION_LENGTH = 2024;
|
|
9
10
|
export const MAX_FILTER_COUNT = MAX_PROJECTION_LENGTH;
|
|
@@ -27,8 +28,14 @@ export function projectionFilterProgram(options) {
|
|
|
27
28
|
if (options.equalsFilter !== void 0)
|
|
28
29
|
return [options.equalsFilter];
|
|
29
30
|
const filters = options.filters;
|
|
30
|
-
if (filters === void 0
|
|
31
|
+
if (filters === void 0)
|
|
32
|
+
return;
|
|
33
|
+
if (!Array.isArray(filters))
|
|
34
|
+
throw TypeError("filters must be an array of predicates");
|
|
35
|
+
if (filters.length === 0)
|
|
31
36
|
return;
|
|
37
|
+
if (filters.length > MAX_FILTER_COUNT)
|
|
38
|
+
throw RangeError(`filter count out of range: ${filters.length}`);
|
|
32
39
|
return filters.length === 1 ? filters : [...filters, { operator: "all", operandCount: filters.length }];
|
|
33
40
|
}
|
|
34
41
|
export function encodingCode(encoding = "utf8") {
|
|
@@ -89,12 +96,15 @@ export function rejectSelectedColumns(options) {
|
|
|
89
96
|
}
|
|
90
97
|
export function normalizeColumns(columns) {
|
|
91
98
|
if (columns === void 0)
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
return EMPTY_COLUMNS;
|
|
100
|
+
const count = columns.length;
|
|
101
|
+
if (count === 0)
|
|
102
|
+
return EMPTY_COLUMNS;
|
|
103
|
+
if (count > MAX_PROJECTION_LENGTH)
|
|
104
|
+
throw RangeError(`selected column count out of range: ${count}`);
|
|
105
|
+
const normalized = new Uint32Array(count);
|
|
96
106
|
const seen = new Set;
|
|
97
|
-
for (let index = 0;index <
|
|
107
|
+
for (let index = 0;index < count; ++index) {
|
|
98
108
|
const column = columns[index] ?? NaN;
|
|
99
109
|
normalizeColumnIndex(column, "selected column");
|
|
100
110
|
if (seen.has(column))
|
|
@@ -102,34 +112,19 @@ export function normalizeColumns(columns) {
|
|
|
102
112
|
seen.add(column);
|
|
103
113
|
normalized[index] = column;
|
|
104
114
|
}
|
|
105
|
-
return normalized
|
|
115
|
+
return normalized;
|
|
106
116
|
}
|
|
107
117
|
export function normalizeColumnIndex(column, label) {
|
|
108
118
|
if (!Number.isInteger(column) || column < 0 || column > MAX_COLUMN_INDEX)
|
|
109
119
|
throw RangeError(`${label} out of range: ${column}`);
|
|
110
120
|
return column;
|
|
111
121
|
}
|
|
112
|
-
export function normalizeEqualsFilter(filter) {
|
|
113
|
-
if (filter === void 0)
|
|
114
|
-
return {
|
|
115
|
-
enabled: !1,
|
|
116
|
-
column: 0,
|
|
117
|
-
value: EMPTY_BUFFER,
|
|
118
|
-
valueLength: 0
|
|
119
|
-
};
|
|
120
|
-
normalizeColumnIndex(filter.column, "filter column");
|
|
121
|
-
const value = typeof filter.value === "string" ? Buffer.from(filter.value) : filter.value;
|
|
122
|
-
return {
|
|
123
|
-
enabled: !0,
|
|
124
|
-
column: filter.column,
|
|
125
|
-
value: value.byteLength === 0 ? EMPTY_BUFFER : value,
|
|
126
|
-
valueLength: value.byteLength
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
122
|
export function normalizeFilterColumn(column) {
|
|
130
123
|
return normalizeColumnIndex(column, "filter column");
|
|
131
124
|
}
|
|
132
125
|
export function normalizeFilterValue(value) {
|
|
126
|
+
if (typeof value !== "string" && !(value instanceof Uint8Array))
|
|
127
|
+
throw TypeError("filter value must be a string, Buffer, or Uint8Array");
|
|
133
128
|
return typeof value === "string" ? Buffer.from(value) : value;
|
|
134
129
|
}
|
|
135
130
|
export function normalizeRegex(regex) {
|
|
@@ -225,44 +220,6 @@ function convertJavaScriptRegexSource(source, unicode) {
|
|
|
225
220
|
function isSurrogate(codePoint) {
|
|
226
221
|
return codePoint >= 55296 && codePoint <= 57343;
|
|
227
222
|
}
|
|
228
|
-
export function normalizeInFilter(filter) {
|
|
229
|
-
const column = normalizeFilterColumn(filter.column);
|
|
230
|
-
if (filter.values.length === 0)
|
|
231
|
-
throw RangeError("filter values must not be empty");
|
|
232
|
-
const values = filter.values.map((value) => normalizeFilterValue(value));
|
|
233
|
-
let valuesDataLength = 0;
|
|
234
|
-
for (const value of values) {
|
|
235
|
-
valuesDataLength += value.byteLength;
|
|
236
|
-
if (valuesDataLength > 4294967295)
|
|
237
|
-
throw RangeError("filter values exceed native offset range");
|
|
238
|
-
}
|
|
239
|
-
const valuesData = valuesDataLength === 0 ? EMPTY_BUFFER : new Uint8Array(valuesDataLength);
|
|
240
|
-
const offsets = new Uint32Array(values.length + 1);
|
|
241
|
-
let offset = 0;
|
|
242
|
-
for (let index = 0;index < values.length; ++index) {
|
|
243
|
-
const value = values[index] ?? EMPTY_BUFFER;
|
|
244
|
-
offsets[index] = offset;
|
|
245
|
-
valuesData.set(value, offset);
|
|
246
|
-
offset += value.byteLength;
|
|
247
|
-
}
|
|
248
|
-
offsets[values.length] = offset;
|
|
249
|
-
return {
|
|
250
|
-
column,
|
|
251
|
-
valuesData,
|
|
252
|
-
valuesDataLength,
|
|
253
|
-
offsets,
|
|
254
|
-
valueCount: values.length
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
export function normalizeStartsWithFilter(filter) {
|
|
258
|
-
const column = normalizeFilterColumn(filter.column);
|
|
259
|
-
const value = normalizeFilterValue(filter.prefix);
|
|
260
|
-
return {
|
|
261
|
-
column,
|
|
262
|
-
value: value.byteLength === 0 ? EMPTY_BUFFER : value,
|
|
263
|
-
valueLength: value.byteLength
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
223
|
export function normalizeNativeFilters(filters) {
|
|
267
224
|
if (filters === void 0 || filters.length === 0)
|
|
268
225
|
return {
|
|
@@ -350,6 +307,8 @@ export function normalizeNativeFilters(filters) {
|
|
|
350
307
|
};
|
|
351
308
|
}
|
|
352
309
|
export function normalizeNativeFilterProgram(program) {
|
|
310
|
+
if (!Array.isArray(program))
|
|
311
|
+
throw TypeError("filterProgram must be an array");
|
|
353
312
|
if (program.length === 0)
|
|
354
313
|
throw RangeError("filter program must contain at least one predicate");
|
|
355
314
|
if (program.length > MAX_FILTER_PROGRAM_LENGTH)
|
|
@@ -360,6 +319,8 @@ export function normalizeNativeFilterProgram(program) {
|
|
|
360
319
|
const entry = program[index];
|
|
361
320
|
if (entry === void 0)
|
|
362
321
|
throw TypeError(`filter program entry missing at index ${index}`);
|
|
322
|
+
if (typeof entry !== "object" || entry === null)
|
|
323
|
+
throw TypeError(`invalid filter program entry at index ${index}`);
|
|
363
324
|
if (!isNativeFilterOperator(entry)) {
|
|
364
325
|
predicates.push(entry);
|
|
365
326
|
++stackDepth;
|
|
@@ -410,5 +371,7 @@ function nativeFilterOperatorCode(operator) {
|
|
|
410
371
|
return NATIVE_FILTER_ANY;
|
|
411
372
|
case "not":
|
|
412
373
|
return NATIVE_FILTER_NOT;
|
|
374
|
+
default:
|
|
375
|
+
throw TypeError(`unknown filter operator: ${String(operator)}`);
|
|
413
376
|
}
|
|
414
377
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CsvApiFileOptions, CsvNativeProjectionOptions } from './types.js';
|
|
1
|
+
import type { CsvApiFileOptions, CsvNativeProjectionOptions, CsvTransformOptions } from './types.js';
|
|
2
2
|
/** Own the mutable option values while retaining opaque immutable filter handles. */
|
|
3
|
-
export declare function snapshotCsvOptions<TOptions extends CsvApiFileOptions & CsvNativeProjectionOptions>(options: TOptions): TOptions;
|
|
3
|
+
export declare function snapshotCsvOptions<TOptions extends CsvApiFileOptions & CsvNativeProjectionOptions & CsvTransformOptions>(options: TOptions): TOptions;
|
package/dist/options-snapshot.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
MAX_PROJECTION_LENGTH,
|
|
4
4
|
rejectSelectedColumns
|
|
5
5
|
} from "./normalize.js";
|
|
6
|
+
import { snapshotTransforms } from "./transforms.js";
|
|
6
7
|
const snapshots = new WeakSet;
|
|
7
8
|
export function snapshotCsvOptions(options) {
|
|
8
9
|
if (snapshots.has(options))
|
|
@@ -13,6 +14,7 @@ export function snapshotCsvOptions(options) {
|
|
|
13
14
|
throw RangeError(`filter count out of range: ${captured.filters.length}`);
|
|
14
15
|
const snapshot = Object.freeze({
|
|
15
16
|
...captured,
|
|
17
|
+
transform: snapshotTransforms(captured.transform),
|
|
16
18
|
columns: snapshotColumns(captured.columns),
|
|
17
19
|
expectedHeaders: captured.expectedHeaders === void 0 ? void 0 : Object.freeze([...captured.expectedHeaders]),
|
|
18
20
|
compression: typeof captured.compression === "object" && captured.compression !== null ? Object.freeze({ ...captured.compression }) : captured.compression,
|