@konstit/csv 0.4.1
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/LICENSE +21 -0
- package/README.md +554 -0
- package/THIRD_PARTY_NOTICES.md +365 -0
- package/dist/api.d.ts +81 -0
- package/dist/api.js +515 -0
- package/dist/batches.d.ts +47 -0
- package/dist/batches.js +348 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +605 -0
- package/dist/file-stream.d.ts +11 -0
- package/dist/file-stream.js +290 -0
- package/dist/files.d.ts +8 -0
- package/dist/files.js +150 -0
- package/dist/filter.d.ts +8 -0
- package/dist/filter.js +82 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/native.d.ts +199 -0
- package/dist/native.js +275 -0
- package/dist/normalize.d.ts +56 -0
- package/dist/normalize.js +365 -0
- package/dist/options.d.ts +17 -0
- package/dist/options.js +12 -0
- package/dist/parser.d.ts +32 -0
- package/dist/parser.js +254 -0
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.js +12 -0
- package/dist/strict-schema.d.ts +12 -0
- package/dist/strict-schema.js +90 -0
- package/dist/types.d.ts +181 -0
- package/dist/types.js +0 -0
- package/dist/worker-count.d.ts +2 -0
- package/dist/worker-count.js +96 -0
- package/dist/worker-factory.d.ts +3 -0
- package/dist/worker-factory.js +9 -0
- package/dist/worker-filter.d.ts +29 -0
- package/dist/worker-filter.js +46 -0
- package/dist/worker-module.d.ts +1 -0
- package/dist/worker-module.js +4 -0
- package/dist/worker-pool.d.ts +17 -0
- package/dist/worker-pool.js +290 -0
- package/dist/worker-rows.d.ts +8 -0
- package/dist/worker-rows.js +118 -0
- package/dist/workers/count.worker.d.ts +1 -0
- package/dist/workers/count.worker.js +49 -0
- package/dist/workers/rows.worker.d.ts +1 -0
- package/dist/workers/rows.worker.js +85 -0
- package/dist/zip-reader.d.ts +2 -0
- package/dist/zip-reader.js +89 -0
- package/package.json +122 -0
- 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 +48 -0
- package/prebuilds/provenance/darwin-arm64.json +1 -0
- package/prebuilds/provenance/darwin-x64.json +1 -0
- package/prebuilds/provenance/linux-x64.json +1 -0
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { type Library, type Pointer } from 'bun:ffi';
|
|
2
|
+
export type { Pointer } from 'bun:ffi';
|
|
3
|
+
export { toArrayBuffer } from 'bun:ffi';
|
|
4
|
+
export type NativePointer = Pointer | bigint;
|
|
5
|
+
export declare const EMPTY_BUFFER: Uint8Array<ArrayBuffer>;
|
|
6
|
+
export declare const EMPTY_U32: Uint32Array<ArrayBuffer>;
|
|
7
|
+
export declare const DEFAULT_CHUNK_SIZE: number;
|
|
8
|
+
export declare const native: Library<{
|
|
9
|
+
readonly csv_runtime_supports_avx2: {
|
|
10
|
+
readonly args: readonly [];
|
|
11
|
+
readonly returns: "int";
|
|
12
|
+
};
|
|
13
|
+
readonly csv_parser_create: {
|
|
14
|
+
readonly args: readonly ["int", "u8"];
|
|
15
|
+
readonly returns: "ptr";
|
|
16
|
+
};
|
|
17
|
+
readonly csv_parser_destroy: {
|
|
18
|
+
readonly args: readonly ["ptr"];
|
|
19
|
+
readonly returns: "void";
|
|
20
|
+
};
|
|
21
|
+
readonly csv_parser_reset: {
|
|
22
|
+
readonly args: readonly ["ptr"];
|
|
23
|
+
readonly returns: "void";
|
|
24
|
+
};
|
|
25
|
+
readonly csv_parser_write_batch: {
|
|
26
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
27
|
+
readonly returns: "ptr";
|
|
28
|
+
};
|
|
29
|
+
readonly csv_parser_finish_batch: {
|
|
30
|
+
readonly args: readonly ["ptr"];
|
|
31
|
+
readonly returns: "ptr";
|
|
32
|
+
};
|
|
33
|
+
readonly csv_parser_write_strict_batch: {
|
|
34
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
35
|
+
readonly returns: "ptr";
|
|
36
|
+
};
|
|
37
|
+
readonly csv_parser_finish_strict_batch: {
|
|
38
|
+
readonly args: readonly ["ptr"];
|
|
39
|
+
readonly returns: "ptr";
|
|
40
|
+
};
|
|
41
|
+
readonly csv_parser_write_fixed_batch: {
|
|
42
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32"];
|
|
43
|
+
readonly returns: "ptr";
|
|
44
|
+
};
|
|
45
|
+
readonly csv_parser_finish_fixed_batch: {
|
|
46
|
+
readonly args: readonly ["ptr", "u32"];
|
|
47
|
+
readonly returns: "ptr";
|
|
48
|
+
};
|
|
49
|
+
readonly csv_parser_write_strict_fixed_batch: {
|
|
50
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32"];
|
|
51
|
+
readonly returns: "ptr";
|
|
52
|
+
};
|
|
53
|
+
readonly csv_parser_finish_strict_fixed_batch: {
|
|
54
|
+
readonly args: readonly ["ptr", "u32"];
|
|
55
|
+
readonly returns: "ptr";
|
|
56
|
+
};
|
|
57
|
+
readonly csv_parser_write_projected_batch: {
|
|
58
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"];
|
|
59
|
+
readonly returns: "ptr";
|
|
60
|
+
};
|
|
61
|
+
readonly csv_parser_finish_projected_batch: {
|
|
62
|
+
readonly args: readonly ["ptr", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"];
|
|
63
|
+
readonly returns: "ptr";
|
|
64
|
+
};
|
|
65
|
+
readonly csv_parser_write_projected_batch_where_all: {
|
|
66
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
67
|
+
readonly returns: "ptr";
|
|
68
|
+
};
|
|
69
|
+
readonly csv_parser_finish_projected_batch_where_all: {
|
|
70
|
+
readonly args: readonly ["ptr", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
71
|
+
readonly returns: "ptr";
|
|
72
|
+
};
|
|
73
|
+
readonly csv_batch_destroy: {
|
|
74
|
+
readonly args: readonly ["ptr"];
|
|
75
|
+
readonly returns: "void";
|
|
76
|
+
};
|
|
77
|
+
readonly csv_batch_row_count: {
|
|
78
|
+
readonly args: readonly ["ptr"];
|
|
79
|
+
readonly returns: "u64";
|
|
80
|
+
};
|
|
81
|
+
readonly csv_batch_total_fields: {
|
|
82
|
+
readonly args: readonly ["ptr"];
|
|
83
|
+
readonly returns: "u64";
|
|
84
|
+
};
|
|
85
|
+
readonly csv_batch_data_len: {
|
|
86
|
+
readonly args: readonly ["ptr"];
|
|
87
|
+
readonly returns: "u64";
|
|
88
|
+
};
|
|
89
|
+
readonly csv_batch_data_ptr: {
|
|
90
|
+
readonly args: readonly ["ptr"];
|
|
91
|
+
readonly returns: "ptr";
|
|
92
|
+
};
|
|
93
|
+
readonly csv_batch_row_offsets_ptr: {
|
|
94
|
+
readonly args: readonly ["ptr"];
|
|
95
|
+
readonly returns: "ptr";
|
|
96
|
+
};
|
|
97
|
+
readonly csv_batch_field_offsets_ptr: {
|
|
98
|
+
readonly args: readonly ["ptr"];
|
|
99
|
+
readonly returns: "ptr";
|
|
100
|
+
};
|
|
101
|
+
readonly csv_batch_count_where_equals: {
|
|
102
|
+
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length"];
|
|
103
|
+
readonly returns: "u64";
|
|
104
|
+
};
|
|
105
|
+
readonly csv_parser_write_count: {
|
|
106
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
107
|
+
readonly returns: "u64";
|
|
108
|
+
};
|
|
109
|
+
readonly csv_parser_count_trusted_newlines: {
|
|
110
|
+
readonly args: readonly ["buffer", "buffer_length"];
|
|
111
|
+
readonly returns: "u64";
|
|
112
|
+
};
|
|
113
|
+
readonly csv_regex_validate: {
|
|
114
|
+
readonly args: readonly ["buffer", "buffer_length"];
|
|
115
|
+
readonly returns: "cstring";
|
|
116
|
+
};
|
|
117
|
+
readonly csv_parser_find_split_offsets: {
|
|
118
|
+
readonly args: readonly ["cstring", "u64", "u8"];
|
|
119
|
+
readonly returns: "ptr";
|
|
120
|
+
};
|
|
121
|
+
readonly csv_split_offsets_batch_destroy: {
|
|
122
|
+
readonly args: readonly ["ptr"];
|
|
123
|
+
readonly returns: "void";
|
|
124
|
+
};
|
|
125
|
+
readonly csv_split_offsets_batch_count: {
|
|
126
|
+
readonly args: readonly ["ptr"];
|
|
127
|
+
readonly returns: "u64";
|
|
128
|
+
};
|
|
129
|
+
readonly csv_split_offsets_batch_ptr: {
|
|
130
|
+
readonly args: readonly ["ptr"];
|
|
131
|
+
readonly returns: "ptr";
|
|
132
|
+
};
|
|
133
|
+
readonly csv_parser_finish_count: {
|
|
134
|
+
readonly args: readonly ["ptr"];
|
|
135
|
+
readonly returns: "u64";
|
|
136
|
+
};
|
|
137
|
+
readonly csv_parser_write_count_where_all: {
|
|
138
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
139
|
+
readonly returns: "u64";
|
|
140
|
+
};
|
|
141
|
+
readonly csv_parser_finish_count_where_all: {
|
|
142
|
+
readonly args: readonly ["ptr", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"];
|
|
143
|
+
readonly returns: "u64";
|
|
144
|
+
};
|
|
145
|
+
readonly csv_parser_write_count_where_equals: {
|
|
146
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"];
|
|
147
|
+
readonly returns: "u64";
|
|
148
|
+
};
|
|
149
|
+
readonly csv_parser_finish_count_where_equals: {
|
|
150
|
+
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length"];
|
|
151
|
+
readonly returns: "u64";
|
|
152
|
+
};
|
|
153
|
+
readonly csv_parser_write_count_where_in: {
|
|
154
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length", "buffer", "u64"];
|
|
155
|
+
readonly returns: "u64";
|
|
156
|
+
};
|
|
157
|
+
readonly csv_parser_finish_count_where_in: {
|
|
158
|
+
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length", "buffer", "u64"];
|
|
159
|
+
readonly returns: "u64";
|
|
160
|
+
};
|
|
161
|
+
readonly csv_parser_write_count_where_starts_with: {
|
|
162
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"];
|
|
163
|
+
readonly returns: "u64";
|
|
164
|
+
};
|
|
165
|
+
readonly csv_parser_finish_count_where_starts_with: {
|
|
166
|
+
readonly args: readonly ["ptr", "u32", "buffer", "buffer_length"];
|
|
167
|
+
readonly returns: "u64";
|
|
168
|
+
};
|
|
169
|
+
readonly csv_zip_reader_create: {
|
|
170
|
+
readonly args: readonly ["cstring", "buffer", "buffer_length", "u64", "u32"];
|
|
171
|
+
readonly returns: "ptr";
|
|
172
|
+
};
|
|
173
|
+
readonly csv_zip_reader_destroy: {
|
|
174
|
+
readonly args: readonly ["ptr"];
|
|
175
|
+
readonly returns: "void";
|
|
176
|
+
};
|
|
177
|
+
readonly csv_zip_reader_read: {
|
|
178
|
+
readonly args: readonly ["ptr", "buffer", "buffer_length"];
|
|
179
|
+
readonly returns: "u64";
|
|
180
|
+
};
|
|
181
|
+
readonly csv_zip_reader_status: {
|
|
182
|
+
readonly args: readonly ["ptr"];
|
|
183
|
+
readonly returns: "int";
|
|
184
|
+
};
|
|
185
|
+
readonly csv_zip_reader_last_error: {
|
|
186
|
+
readonly args: readonly ["ptr"];
|
|
187
|
+
readonly returns: "cstring";
|
|
188
|
+
};
|
|
189
|
+
readonly csv_parser_last_error: {
|
|
190
|
+
readonly args: readonly ["ptr"];
|
|
191
|
+
readonly returns: "cstring";
|
|
192
|
+
};
|
|
193
|
+
}>;
|
|
194
|
+
export declare function requireConfiguredNativeLibraryPath(configuredPath: string): string;
|
|
195
|
+
export declare function nativeLibraryCandidates(root: string, target: string, librarySuffix: string): readonly string[];
|
|
196
|
+
export declare function findNativeLibraryPath(candidates: readonly string[]): string | undefined;
|
|
197
|
+
export declare function requireNativeLibraryPath(candidates: readonly string[]): string;
|
|
198
|
+
export declare function requirePtr(ptr: NativePointer | null): NativePointer;
|
|
199
|
+
export declare function u64ToSafeNumber(value: bigint | number, label: string): number;
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dlopen,
|
|
3
|
+
suffix
|
|
4
|
+
} from "bun:ffi";
|
|
5
|
+
import {
|
|
6
|
+
existsSync,
|
|
7
|
+
statSync
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import {
|
|
10
|
+
dirname,
|
|
11
|
+
isAbsolute,
|
|
12
|
+
join,
|
|
13
|
+
resolve
|
|
14
|
+
} from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
export { toArrayBuffer } from "bun:ffi";
|
|
17
|
+
const EMPTY_BUFFER_STORAGE = new Uint8Array(1);
|
|
18
|
+
export const EMPTY_BUFFER = EMPTY_BUFFER_STORAGE.subarray(0, 0);
|
|
19
|
+
export const EMPTY_U32 = new Uint32Array(1);
|
|
20
|
+
export const DEFAULT_CHUNK_SIZE = 1048576;
|
|
21
|
+
const CSV_SYMBOLS = {
|
|
22
|
+
csv_runtime_supports_avx2: {
|
|
23
|
+
args: [],
|
|
24
|
+
returns: "int"
|
|
25
|
+
},
|
|
26
|
+
csv_parser_create: {
|
|
27
|
+
args: ["int", "u8"],
|
|
28
|
+
returns: "ptr"
|
|
29
|
+
},
|
|
30
|
+
csv_parser_destroy: {
|
|
31
|
+
args: ["ptr"],
|
|
32
|
+
returns: "void"
|
|
33
|
+
},
|
|
34
|
+
csv_parser_reset: {
|
|
35
|
+
args: ["ptr"],
|
|
36
|
+
returns: "void"
|
|
37
|
+
},
|
|
38
|
+
csv_parser_write_batch: {
|
|
39
|
+
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
40
|
+
returns: "ptr"
|
|
41
|
+
},
|
|
42
|
+
csv_parser_finish_batch: {
|
|
43
|
+
args: ["ptr"],
|
|
44
|
+
returns: "ptr"
|
|
45
|
+
},
|
|
46
|
+
csv_parser_write_strict_batch: {
|
|
47
|
+
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
48
|
+
returns: "ptr"
|
|
49
|
+
},
|
|
50
|
+
csv_parser_finish_strict_batch: {
|
|
51
|
+
args: ["ptr"],
|
|
52
|
+
returns: "ptr"
|
|
53
|
+
},
|
|
54
|
+
csv_parser_write_fixed_batch: {
|
|
55
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "u32"],
|
|
56
|
+
returns: "ptr"
|
|
57
|
+
},
|
|
58
|
+
csv_parser_finish_fixed_batch: {
|
|
59
|
+
args: ["ptr", "u32"],
|
|
60
|
+
returns: "ptr"
|
|
61
|
+
},
|
|
62
|
+
csv_parser_write_strict_fixed_batch: {
|
|
63
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "u32"],
|
|
64
|
+
returns: "ptr"
|
|
65
|
+
},
|
|
66
|
+
csv_parser_finish_strict_fixed_batch: {
|
|
67
|
+
args: ["ptr", "u32"],
|
|
68
|
+
returns: "ptr"
|
|
69
|
+
},
|
|
70
|
+
csv_parser_write_projected_batch: {
|
|
71
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"],
|
|
72
|
+
returns: "ptr"
|
|
73
|
+
},
|
|
74
|
+
csv_parser_finish_projected_batch: {
|
|
75
|
+
args: ["ptr", "bool", "buffer", "u64", "bool", "u32", "buffer", "buffer_length"],
|
|
76
|
+
returns: "ptr"
|
|
77
|
+
},
|
|
78
|
+
csv_parser_write_projected_batch_where_all: {
|
|
79
|
+
args: [
|
|
80
|
+
"ptr",
|
|
81
|
+
"buffer",
|
|
82
|
+
"buffer_length",
|
|
83
|
+
"bool",
|
|
84
|
+
"bool",
|
|
85
|
+
"buffer",
|
|
86
|
+
"u64",
|
|
87
|
+
"buffer",
|
|
88
|
+
"u64",
|
|
89
|
+
"buffer",
|
|
90
|
+
"buffer_length",
|
|
91
|
+
"buffer",
|
|
92
|
+
"u64"
|
|
93
|
+
],
|
|
94
|
+
returns: "ptr"
|
|
95
|
+
},
|
|
96
|
+
csv_parser_finish_projected_batch_where_all: {
|
|
97
|
+
args: ["ptr", "bool", "buffer", "u64", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
98
|
+
returns: "ptr"
|
|
99
|
+
},
|
|
100
|
+
csv_batch_destroy: {
|
|
101
|
+
args: ["ptr"],
|
|
102
|
+
returns: "void"
|
|
103
|
+
},
|
|
104
|
+
csv_batch_row_count: {
|
|
105
|
+
args: ["ptr"],
|
|
106
|
+
returns: "u64"
|
|
107
|
+
},
|
|
108
|
+
csv_batch_total_fields: {
|
|
109
|
+
args: ["ptr"],
|
|
110
|
+
returns: "u64"
|
|
111
|
+
},
|
|
112
|
+
csv_batch_data_len: {
|
|
113
|
+
args: ["ptr"],
|
|
114
|
+
returns: "u64"
|
|
115
|
+
},
|
|
116
|
+
csv_batch_data_ptr: {
|
|
117
|
+
args: ["ptr"],
|
|
118
|
+
returns: "ptr"
|
|
119
|
+
},
|
|
120
|
+
csv_batch_row_offsets_ptr: {
|
|
121
|
+
args: ["ptr"],
|
|
122
|
+
returns: "ptr"
|
|
123
|
+
},
|
|
124
|
+
csv_batch_field_offsets_ptr: {
|
|
125
|
+
args: ["ptr"],
|
|
126
|
+
returns: "ptr"
|
|
127
|
+
},
|
|
128
|
+
csv_batch_count_where_equals: {
|
|
129
|
+
args: ["ptr", "u32", "buffer", "buffer_length"],
|
|
130
|
+
returns: "u64"
|
|
131
|
+
},
|
|
132
|
+
csv_parser_write_count: {
|
|
133
|
+
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
134
|
+
returns: "u64"
|
|
135
|
+
},
|
|
136
|
+
csv_parser_count_trusted_newlines: {
|
|
137
|
+
args: ["buffer", "buffer_length"],
|
|
138
|
+
returns: "u64"
|
|
139
|
+
},
|
|
140
|
+
csv_regex_validate: {
|
|
141
|
+
args: ["buffer", "buffer_length"],
|
|
142
|
+
returns: "cstring"
|
|
143
|
+
},
|
|
144
|
+
csv_parser_find_split_offsets: {
|
|
145
|
+
args: ["cstring", "u64", "u8"],
|
|
146
|
+
returns: "ptr"
|
|
147
|
+
},
|
|
148
|
+
csv_split_offsets_batch_destroy: {
|
|
149
|
+
args: ["ptr"],
|
|
150
|
+
returns: "void"
|
|
151
|
+
},
|
|
152
|
+
csv_split_offsets_batch_count: {
|
|
153
|
+
args: ["ptr"],
|
|
154
|
+
returns: "u64"
|
|
155
|
+
},
|
|
156
|
+
csv_split_offsets_batch_ptr: {
|
|
157
|
+
args: ["ptr"],
|
|
158
|
+
returns: "ptr"
|
|
159
|
+
},
|
|
160
|
+
csv_parser_finish_count: {
|
|
161
|
+
args: ["ptr"],
|
|
162
|
+
returns: "u64"
|
|
163
|
+
},
|
|
164
|
+
csv_parser_write_count_where_all: {
|
|
165
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
166
|
+
returns: "u64"
|
|
167
|
+
},
|
|
168
|
+
csv_parser_finish_count_where_all: {
|
|
169
|
+
args: ["ptr", "buffer", "u64", "buffer", "buffer_length", "buffer", "u64"],
|
|
170
|
+
returns: "u64"
|
|
171
|
+
},
|
|
172
|
+
csv_parser_write_count_where_equals: {
|
|
173
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"],
|
|
174
|
+
returns: "u64"
|
|
175
|
+
},
|
|
176
|
+
csv_parser_finish_count_where_equals: {
|
|
177
|
+
args: ["ptr", "u32", "buffer", "buffer_length"],
|
|
178
|
+
returns: "u64"
|
|
179
|
+
},
|
|
180
|
+
csv_parser_write_count_where_in: {
|
|
181
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length", "buffer", "u64"],
|
|
182
|
+
returns: "u64"
|
|
183
|
+
},
|
|
184
|
+
csv_parser_finish_count_where_in: {
|
|
185
|
+
args: ["ptr", "u32", "buffer", "buffer_length", "buffer", "u64"],
|
|
186
|
+
returns: "u64"
|
|
187
|
+
},
|
|
188
|
+
csv_parser_write_count_where_starts_with: {
|
|
189
|
+
args: ["ptr", "buffer", "buffer_length", "bool", "u32", "buffer", "buffer_length"],
|
|
190
|
+
returns: "u64"
|
|
191
|
+
},
|
|
192
|
+
csv_parser_finish_count_where_starts_with: {
|
|
193
|
+
args: ["ptr", "u32", "buffer", "buffer_length"],
|
|
194
|
+
returns: "u64"
|
|
195
|
+
},
|
|
196
|
+
csv_zip_reader_create: {
|
|
197
|
+
args: ["cstring", "buffer", "buffer_length", "u64", "u32"],
|
|
198
|
+
returns: "ptr"
|
|
199
|
+
},
|
|
200
|
+
csv_zip_reader_destroy: {
|
|
201
|
+
args: ["ptr"],
|
|
202
|
+
returns: "void"
|
|
203
|
+
},
|
|
204
|
+
csv_zip_reader_read: {
|
|
205
|
+
args: ["ptr", "buffer", "buffer_length"],
|
|
206
|
+
returns: "u64"
|
|
207
|
+
},
|
|
208
|
+
csv_zip_reader_status: {
|
|
209
|
+
args: ["ptr"],
|
|
210
|
+
returns: "int"
|
|
211
|
+
},
|
|
212
|
+
csv_zip_reader_last_error: {
|
|
213
|
+
args: ["ptr"],
|
|
214
|
+
returns: "cstring"
|
|
215
|
+
},
|
|
216
|
+
csv_parser_last_error: {
|
|
217
|
+
args: ["ptr"],
|
|
218
|
+
returns: "cstring"
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
export const native = loadNative();
|
|
222
|
+
function loadNative() {
|
|
223
|
+
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
224
|
+
const target = `${process.platform}-${process.arch}`;
|
|
225
|
+
const configuredPath = process.env.CSV_NATIVE_LIBRARY_PATH;
|
|
226
|
+
const libraryPath = configuredPath === void 0 ? requireNativeLibraryPath(nativeLibraryCandidates(root, target, suffix)) : requireConfiguredNativeLibraryPath(configuredPath);
|
|
227
|
+
return dlopen(resolve(libraryPath), CSV_SYMBOLS);
|
|
228
|
+
}
|
|
229
|
+
export function requireConfiguredNativeLibraryPath(configuredPath) {
|
|
230
|
+
if (configuredPath.length === 0)
|
|
231
|
+
throw Error("CSV_NATIVE_LIBRARY_PATH must not be empty");
|
|
232
|
+
if (!isAbsolute(configuredPath))
|
|
233
|
+
throw Error("CSV_NATIVE_LIBRARY_PATH must be an absolute path");
|
|
234
|
+
let isFile = !1;
|
|
235
|
+
try {
|
|
236
|
+
isFile = statSync(configuredPath).isFile();
|
|
237
|
+
} catch {}
|
|
238
|
+
if (!isFile)
|
|
239
|
+
throw Error(`CSV_NATIVE_LIBRARY_PATH is not a file: ${configuredPath}`);
|
|
240
|
+
return configuredPath;
|
|
241
|
+
}
|
|
242
|
+
export function nativeLibraryCandidates(root, target, librarySuffix) {
|
|
243
|
+
return [
|
|
244
|
+
join(root, "prebuilds", target, `libcsv_native.${librarySuffix}`),
|
|
245
|
+
join(root, "build", target, `libcsv_native.${librarySuffix}`),
|
|
246
|
+
join(root, "build", target, "Release", `libcsv_native.${librarySuffix}`),
|
|
247
|
+
join(root, "build", `libcsv_native.${librarySuffix}`),
|
|
248
|
+
join(root, "build", "Release", `libcsv_native.${librarySuffix}`),
|
|
249
|
+
join(root, `libcsv_native.${librarySuffix}`)
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
export function findNativeLibraryPath(candidates) {
|
|
253
|
+
return candidates.find((candidate) => existsSync(candidate));
|
|
254
|
+
}
|
|
255
|
+
export function requireNativeLibraryPath(candidates) {
|
|
256
|
+
const libraryPath = findNativeLibraryPath(candidates);
|
|
257
|
+
if (libraryPath === void 0)
|
|
258
|
+
throw Error("native library not found. Run: bun run build:native");
|
|
259
|
+
return libraryPath;
|
|
260
|
+
}
|
|
261
|
+
export function requirePtr(ptr) {
|
|
262
|
+
if (ptr === null)
|
|
263
|
+
throw Error("native CSV pointer is null");
|
|
264
|
+
return ptr;
|
|
265
|
+
}
|
|
266
|
+
export function u64ToSafeNumber(value, label) {
|
|
267
|
+
if (typeof value === "number") {
|
|
268
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
269
|
+
throw RangeError(`${label} exceeds the JavaScript safe integer range: ${value}`);
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER))
|
|
273
|
+
throw RangeError(`${label} exceeds Number.MAX_SAFE_INTEGER: ${value}`);
|
|
274
|
+
return Number(value);
|
|
275
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { CsvColumns, CsvEncoding, CsvEqualsFilter, CsvFieldValue, CsvInFilter, CsvNativeFilter, CsvRegex, CsvStartsWithFilter } from './types.js';
|
|
2
|
+
export declare const MAX_COLUMN_INDEX = 2024;
|
|
3
|
+
export declare const MAX_PROJECTION_LENGTH = 2024;
|
|
4
|
+
export declare const MAX_FILTER_COUNT = 2024;
|
|
5
|
+
export declare const MAX_REGEX_FILTER_COUNT = 32;
|
|
6
|
+
export declare const MAX_FILTER_PROGRAM_LENGTH = 4096;
|
|
7
|
+
export interface CsvNativeFilterOperator {
|
|
8
|
+
readonly operandCount: number;
|
|
9
|
+
readonly operator: 'all' | 'any' | 'not';
|
|
10
|
+
}
|
|
11
|
+
export type CsvNativeFilterProgramEntry = CsvNativeFilter | CsvNativeFilterOperator;
|
|
12
|
+
export declare function encodingCode(encoding?: CsvEncoding): number;
|
|
13
|
+
export declare function normalizeChunk(chunk: NodeJS.TypedArray | DataView): NodeJS.TypedArray | DataView;
|
|
14
|
+
export declare function normalizeFixedColumnsCount(value: number | undefined, label: string): number | undefined;
|
|
15
|
+
export declare function normalizeColumns(columns: CsvColumns | undefined): Uint32Array;
|
|
16
|
+
export declare function normalizeColumnIndex(column: number, label: string): number;
|
|
17
|
+
export declare function normalizeEqualsFilter(filter: CsvEqualsFilter | undefined): {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
column: number;
|
|
20
|
+
value: Uint8Array;
|
|
21
|
+
valueLength: number;
|
|
22
|
+
};
|
|
23
|
+
export declare function normalizeFilterColumn(column: number): number;
|
|
24
|
+
export declare function normalizeFilterValue(value: CsvFieldValue): Uint8Array;
|
|
25
|
+
type CsvRegexInput = Pick<CsvRegex, 'flags' | 'source'>;
|
|
26
|
+
export declare function normalizeRegex(regex: CsvRegexInput): Uint8Array;
|
|
27
|
+
export declare function validateRegex(regex: CsvRegexInput): void;
|
|
28
|
+
export declare function normalizeInFilter(filter: CsvInFilter): {
|
|
29
|
+
column: number;
|
|
30
|
+
valuesData: Uint8Array;
|
|
31
|
+
valuesDataLength: number;
|
|
32
|
+
offsets: Uint32Array;
|
|
33
|
+
valueCount: number;
|
|
34
|
+
};
|
|
35
|
+
export declare function normalizeStartsWithFilter(filter: CsvStartsWithFilter): {
|
|
36
|
+
column: number;
|
|
37
|
+
value: Uint8Array;
|
|
38
|
+
valueLength: number;
|
|
39
|
+
};
|
|
40
|
+
export declare function normalizeNativeFilters(filters: readonly CsvNativeFilter[] | undefined): {
|
|
41
|
+
descriptors: Uint32Array;
|
|
42
|
+
filterCount: number;
|
|
43
|
+
valuesData: Uint8Array;
|
|
44
|
+
valuesDataLength: number;
|
|
45
|
+
valueOffsets: Uint32Array;
|
|
46
|
+
valueCount: number;
|
|
47
|
+
};
|
|
48
|
+
export declare function normalizeNativeFilterProgram(program: readonly CsvNativeFilterProgramEntry[]): {
|
|
49
|
+
descriptors: Uint32Array;
|
|
50
|
+
filterCount: number;
|
|
51
|
+
valuesData: Uint8Array;
|
|
52
|
+
valuesDataLength: number;
|
|
53
|
+
valueOffsets: Uint32Array;
|
|
54
|
+
valueCount: number;
|
|
55
|
+
};
|
|
56
|
+
export {};
|