@konstit/csv 0.5.0 → 0.5.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/README.md +9 -3
- package/dist/api.js +20 -94
- package/dist/batches.d.ts +3 -4
- package/dist/batches.js +12 -10
- package/dist/cli-command.js +42 -77
- package/dist/cli-schema.d.ts +21 -5
- package/dist/cli-schema.js +37 -22
- package/dist/file-stream.d.ts +7 -3
- package/dist/file-stream.js +13 -12
- package/dist/files.js +33 -76
- package/dist/filter.d.ts +1 -2
- 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 +2 -3
- package/dist/latin1-rows.js +13 -3
- package/dist/native.d.ts +21 -69
- package/dist/native.js +9 -83
- package/dist/normalize.d.ts +1 -40
- package/dist/normalize.js +25 -62
- package/dist/parser.d.ts +17 -202
- package/dist/parser.js +131 -230
- package/dist/strict-schema.d.ts +1 -1
- package/dist/strict-schema.js +4 -3
- package/dist/types.d.ts +37 -5
- 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 +8 -8
- package/prebuilds/provenance/darwin-arm64.json +1 -1
- package/prebuilds/provenance/darwin-x64.json +1 -1
- package/prebuilds/provenance/linux-x64.json +1 -1
package/dist/native.d.ts
CHANGED
|
@@ -25,11 +25,27 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
25
25
|
readonly args: readonly ["int", "u8"];
|
|
26
26
|
readonly returns: "ptr";
|
|
27
27
|
};
|
|
28
|
+
readonly csv_parser_create_prepared: {
|
|
29
|
+
readonly args: readonly ["int", "u8", "u32"];
|
|
30
|
+
readonly returns: "ptr";
|
|
31
|
+
};
|
|
32
|
+
readonly csv_parser_set_row_selection: {
|
|
33
|
+
readonly args: readonly ["ptr", "u64", "u64", "bool"];
|
|
34
|
+
readonly returns: "void";
|
|
35
|
+
};
|
|
36
|
+
readonly csv_parser_take_skipped_header: {
|
|
37
|
+
readonly args: readonly ["ptr"];
|
|
38
|
+
readonly returns: "ptr";
|
|
39
|
+
};
|
|
40
|
+
readonly csv_parser_skipped_rows: {
|
|
41
|
+
readonly args: readonly ["ptr"];
|
|
42
|
+
readonly returns: "u64";
|
|
43
|
+
};
|
|
28
44
|
readonly csv_parser_destroy: {
|
|
29
45
|
readonly args: readonly ["ptr"];
|
|
30
46
|
readonly returns: "void";
|
|
31
47
|
};
|
|
32
|
-
readonly
|
|
48
|
+
readonly csv_parser_reset_stream: {
|
|
33
49
|
readonly args: readonly ["ptr"];
|
|
34
50
|
readonly returns: "void";
|
|
35
51
|
};
|
|
@@ -37,50 +53,18 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
37
53
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
38
54
|
readonly returns: "ptr";
|
|
39
55
|
};
|
|
40
|
-
readonly csv_parser_finish_batch: {
|
|
41
|
-
readonly args: readonly ["ptr"];
|
|
42
|
-
readonly returns: "ptr";
|
|
43
|
-
};
|
|
44
56
|
readonly csv_parser_write_strict_batch: {
|
|
45
57
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool"];
|
|
46
58
|
readonly returns: "ptr";
|
|
47
59
|
};
|
|
48
|
-
readonly csv_parser_finish_strict_batch: {
|
|
49
|
-
readonly args: readonly ["ptr"];
|
|
50
|
-
readonly returns: "ptr";
|
|
51
|
-
};
|
|
52
60
|
readonly csv_parser_write_fixed_batch: {
|
|
53
61
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32"];
|
|
54
62
|
readonly returns: "ptr";
|
|
55
63
|
};
|
|
56
|
-
readonly csv_parser_finish_fixed_batch: {
|
|
57
|
-
readonly args: readonly ["ptr", "u32"];
|
|
58
|
-
readonly returns: "ptr";
|
|
59
|
-
};
|
|
60
64
|
readonly csv_parser_write_strict_fixed_batch: {
|
|
61
65
|
readonly args: readonly ["ptr", "buffer", "buffer_length", "bool", "u32"];
|
|
62
66
|
readonly returns: "ptr";
|
|
63
67
|
};
|
|
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
68
|
readonly csv_batch_destroy: {
|
|
85
69
|
readonly args: readonly ["ptr"];
|
|
86
70
|
readonly returns: "void";
|
|
@@ -141,42 +125,6 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
141
125
|
readonly args: readonly ["ptr"];
|
|
142
126
|
readonly returns: "ptr";
|
|
143
127
|
};
|
|
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
128
|
readonly csv_zip_reader_create: {
|
|
181
129
|
readonly args: readonly ["cstring", "buffer", "buffer_length", "u64", "u32"];
|
|
182
130
|
readonly returns: "ptr";
|
|
@@ -185,6 +133,10 @@ export declare const native: import("bun:ffi").Library<{
|
|
|
185
133
|
readonly args: readonly ["ptr"];
|
|
186
134
|
readonly returns: "void";
|
|
187
135
|
};
|
|
136
|
+
readonly csv_zip_reader_entry_name: {
|
|
137
|
+
readonly args: readonly ["ptr", "buffer"];
|
|
138
|
+
readonly returns: "ptr";
|
|
139
|
+
};
|
|
188
140
|
readonly csv_zip_reader_enable_read_ahead: {
|
|
189
141
|
readonly args: readonly ["ptr", "u32"];
|
|
190
142
|
readonly returns: "void";
|
package/dist/native.js
CHANGED
|
@@ -37,11 +37,15 @@ const CSV_SYMBOLS = {
|
|
|
37
37
|
args: ["int", "u8"],
|
|
38
38
|
returns: "ptr"
|
|
39
39
|
},
|
|
40
|
+
csv_parser_create_prepared: { args: ["int", "u8", "u32"], returns: "ptr" },
|
|
41
|
+
csv_parser_set_row_selection: { args: ["ptr", "u64", "u64", "bool"], returns: "void" },
|
|
42
|
+
csv_parser_take_skipped_header: { args: ["ptr"], returns: "ptr" },
|
|
43
|
+
csv_parser_skipped_rows: { args: ["ptr"], returns: "u64" },
|
|
40
44
|
csv_parser_destroy: {
|
|
41
45
|
args: ["ptr"],
|
|
42
46
|
returns: "void"
|
|
43
47
|
},
|
|
44
|
-
|
|
48
|
+
csv_parser_reset_stream: {
|
|
45
49
|
args: ["ptr"],
|
|
46
50
|
returns: "void"
|
|
47
51
|
},
|
|
@@ -49,64 +53,18 @@ const CSV_SYMBOLS = {
|
|
|
49
53
|
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
50
54
|
returns: "ptr"
|
|
51
55
|
},
|
|
52
|
-
csv_parser_finish_batch: {
|
|
53
|
-
args: ["ptr"],
|
|
54
|
-
returns: "ptr"
|
|
55
|
-
},
|
|
56
56
|
csv_parser_write_strict_batch: {
|
|
57
57
|
args: ["ptr", "buffer", "buffer_length", "bool"],
|
|
58
58
|
returns: "ptr"
|
|
59
59
|
},
|
|
60
|
-
csv_parser_finish_strict_batch: {
|
|
61
|
-
args: ["ptr"],
|
|
62
|
-
returns: "ptr"
|
|
63
|
-
},
|
|
64
60
|
csv_parser_write_fixed_batch: {
|
|
65
61
|
args: ["ptr", "buffer", "buffer_length", "bool", "u32"],
|
|
66
62
|
returns: "ptr"
|
|
67
63
|
},
|
|
68
|
-
csv_parser_finish_fixed_batch: {
|
|
69
|
-
args: ["ptr", "u32"],
|
|
70
|
-
returns: "ptr"
|
|
71
|
-
},
|
|
72
64
|
csv_parser_write_strict_fixed_batch: {
|
|
73
65
|
args: ["ptr", "buffer", "buffer_length", "bool", "u32"],
|
|
74
66
|
returns: "ptr"
|
|
75
67
|
},
|
|
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
68
|
csv_batch_destroy: {
|
|
111
69
|
args: ["ptr"],
|
|
112
70
|
returns: "void"
|
|
@@ -167,42 +125,6 @@ const CSV_SYMBOLS = {
|
|
|
167
125
|
args: ["ptr"],
|
|
168
126
|
returns: "ptr"
|
|
169
127
|
},
|
|
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
128
|
csv_zip_reader_create: {
|
|
207
129
|
args: ["cstring", "buffer", "buffer_length", "u64", "u32"],
|
|
208
130
|
returns: "ptr"
|
|
@@ -211,6 +133,10 @@ const CSV_SYMBOLS = {
|
|
|
211
133
|
args: ["ptr"],
|
|
212
134
|
returns: "void"
|
|
213
135
|
},
|
|
136
|
+
csv_zip_reader_entry_name: {
|
|
137
|
+
args: ["ptr", "buffer"],
|
|
138
|
+
returns: "ptr"
|
|
139
|
+
},
|
|
214
140
|
csv_zip_reader_enable_read_ahead: {
|
|
215
141
|
args: ["ptr", "u32"],
|
|
216
142
|
returns: "void"
|
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
|
}
|