@query-farm/vgi 0.48.0 → 0.48.2
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 +24 -1
- package/dist/arguments/argument-spec.d.ts +17 -11
- package/dist/catalog/descriptors.d.ts +16 -2
- package/dist/catalog/publication.d.ts +7 -7
- package/dist/catalog/read-only.d.ts +4 -5
- package/dist/client/client.d.ts +9 -3
- package/dist/client/errors.d.ts +2 -2
- package/dist/client/types.d.ts +21 -0
- package/dist/client-entry.d.ts +1 -1
- package/dist/client-entry.js +31 -7
- package/dist/client-entry.js.map +20 -20
- package/dist/filter-pushdown/deserialize.d.ts +1 -1
- package/dist/filter-pushdown/types.d.ts +10 -10
- package/dist/functions/registry.d.ts +1 -0
- package/dist/functions/scalar.d.ts +17 -6
- package/dist/functions/table-buffering.d.ts +20 -20
- package/dist/functions/table-in-out.d.ts +4 -4
- package/dist/functions/table.d.ts +7 -7
- package/dist/functions/types.d.ts +51 -47
- package/dist/http/fetch.d.ts +10 -10
- package/dist/index.core.d.ts +2 -2
- package/dist/index.js +201 -116
- package/dist/index.js.map +53 -52
- package/dist/protocol/dispatch.d.ts +3 -3
- package/dist/protocol/handlers/function.d.ts +2 -2
- package/dist/protocol/serializers/cardinality.d.ts +4 -1
- package/dist/protocol/types.d.ts +5 -5
- package/dist/rpc-server.d.ts +6 -6
- package/dist/serve-entry.d.ts +16 -16
- package/dist/serve-entry.js +47 -24
- package/dist/serve-entry.js.map +38 -37
- package/dist/split-token.d.ts +6 -6
- package/dist/types.d.ts +9 -2
- package/dist/util/defined.d.ts +21 -0
- package/dist/worker-cf-entry.js +164 -106
- package/dist/worker-cf-entry.js.map +51 -50
- package/dist/worker.d.ts +2 -2
- package/package.json +6 -4
- package/src/arguments/argument-spec.ts +17 -11
- package/src/arrow/codec/registry.ts +2 -2
- package/src/arrow/impl-arrowjs/build.ts +1 -1
- package/src/arrow/impl-arrowjs/canonical.ts +23 -23
- package/src/arrow/impl-arrowjs/empty.ts +2 -2
- package/src/arrow/impl-arrowjs/ipc.ts +2 -2
- package/src/arrow/impl-arrowjs/iterate.ts +2 -2
- package/src/arrow/impl-arrowjs/project.ts +2 -2
- package/src/arrow/impl-flechette/build.ts +2 -1
- package/src/arrow/impl-flechette/canonical.ts +10 -9
- package/src/arrow/impl-flechette/compat.ts +3 -3
- package/src/arrow/impl-flechette/message-meta.ts +5 -4
- package/src/arrow/impl-flechette/statistics.ts +2 -2
- package/src/attach-ticket.ts +2 -2
- package/src/catalog/column-metadata.ts +1 -1
- package/src/catalog/composite.ts +2 -2
- package/src/catalog/constraints.ts +9 -9
- package/src/catalog/descriptors.ts +15 -1
- package/src/catalog/interface.ts +12 -12
- package/src/catalog/publication.ts +9 -8
- package/src/catalog/read-only.ts +27 -21
- package/src/catalog/sql-grammar.ts +6 -6
- package/src/client/client.ts +52 -15
- package/src/client/errors.ts +1 -1
- package/src/client/types.ts +23 -0
- package/src/client-entry.ts +2 -0
- package/src/codec/asd.ts +3 -3
- package/src/codec/conform.ts +3 -3
- package/src/filter-pushdown/collector.ts +1 -1
- package/src/filter-pushdown/deserialize.ts +13 -10
- package/src/filter-pushdown/evaluate.ts +3 -2
- package/src/filter-pushdown/history.ts +3 -2
- package/src/filter-pushdown/types.ts +10 -10
- package/src/functions/continuation.ts +1 -1
- package/src/functions/projection.ts +1 -1
- package/src/functions/registry.ts +20 -17
- package/src/functions/scalar.ts +33 -11
- package/src/functions/storage-cf-do.ts +2 -2
- package/src/functions/table-buffering.ts +28 -21
- package/src/functions/table-in-out.ts +37 -17
- package/src/functions/table.ts +36 -31
- package/src/functions/types.ts +58 -48
- package/src/generated/vgi-service.ts +5 -3
- package/src/http/fetch.ts +17 -12
- package/src/index.core.ts +3 -1
- package/src/protocol/carried-init-request.ts +1 -1
- package/src/protocol/dispatch.ts +3 -3
- package/src/protocol/handlers/aggregate.ts +8 -7
- package/src/protocol/handlers/catalog/shared.ts +1 -1
- package/src/protocol/handlers/function.ts +18 -5
- package/src/protocol/serializers/cardinality.ts +16 -3
- package/src/protocol/state-serializer.ts +1 -1
- package/src/protocol/types.ts +5 -5
- package/src/rpc-server.ts +13 -12
- package/src/serve-entry.ts +18 -18
- package/src/split-token.ts +10 -9
- package/src/types.ts +9 -2
- package/src/util/defined.ts +30 -0
- package/src/util/parent-rows.ts +2 -2
- package/src/worker.ts +15 -14
package/dist/worker.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export interface WorkerConfig extends HostingOptions {
|
|
|
23
23
|
export declare class Worker {
|
|
24
24
|
private _registry;
|
|
25
25
|
private _hosting;
|
|
26
|
-
private _catalogInterface
|
|
27
|
-
private _catalogName
|
|
26
|
+
private _catalogInterface;
|
|
27
|
+
private _catalogName;
|
|
28
28
|
constructor(config: WorkerConfig);
|
|
29
29
|
run(argv?: readonly string[]): void;
|
|
30
30
|
private _serve;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@query-farm/vgi",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.2",
|
|
4
4
|
"description": "TypeScript framework for extending DuckDB with user-defined functions via the Vector Gateway Interface (VGI) over Arrow IPC.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Query Farm LLC (https://query.farm)",
|
|
@@ -75,9 +75,11 @@
|
|
|
75
75
|
"!src/**/*.test.ts",
|
|
76
76
|
"!src/**/*.spec.ts"
|
|
77
77
|
],
|
|
78
|
-
"//imports": "`browser` maps to arrow-js DELIBERATELY, not flechette. Measured on the client surface (VgiClient + Arguments + batch helpers), a minified browser bundle is 84 KB gzip via arrow-js vs 116 KB via flechette \u2014 arrow-js tree-shakes to the subset the client touches, while flechette links as a unit. Flechette still wins for `worker-cf`, which exercises far more of the Arrow API and cannot take a peer dep. Keep `browser` AFTER `workerd`/`worker`: conditions match in key order, so a workerd build (which sets both) must hit flechette first.",
|
|
78
|
+
"//imports": "`browser` maps to arrow-js DELIBERATELY, not flechette. Measured on the client surface (VgiClient + Arguments + batch helpers), a minified browser bundle is 84 KB gzip via arrow-js vs 116 KB via flechette \u2014 arrow-js tree-shakes to the subset the client touches, while flechette links as a unit. Flechette still wins for `worker-cf`, which exercises far more of the Arrow API and cannot take a peer dep. Keep `browser` AFTER `workerd`/`worker`: conditions match in key order, so a workerd build (which sets both) must hit flechette first. `vgi-source` comes first and is set only by the SDK's own tsconfig (customConditions) so in-repo type-checking resolves to source; `types` comes next so consumers' tsc resolves the shipped declaration file instead of SDK source (which would otherwise be type-checked under the consumer's compiler flags, e.g. noUncheckedIndexedAccess; skipLibCheck does not cover .ts files). Runtimes and bundlers match neither condition.",
|
|
79
79
|
"imports": {
|
|
80
80
|
"#arrow-impl": {
|
|
81
|
+
"vgi-source": "./src/arrow/impl-arrowjs/index.ts",
|
|
82
|
+
"types": "./dist/arrow/impl-arrowjs/index.d.ts",
|
|
81
83
|
"flechette": "./src/arrow/impl-flechette/index.ts",
|
|
82
84
|
"workerd": "./src/arrow/impl-flechette/index.ts",
|
|
83
85
|
"worker": "./src/arrow/impl-flechette/index.ts",
|
|
@@ -91,12 +93,12 @@
|
|
|
91
93
|
},
|
|
92
94
|
"peerDependencies": {
|
|
93
95
|
"@query-farm/apache-arrow": "^21.1.1",
|
|
94
|
-
"@query-farm/vgi-rpc": "^0.29.
|
|
96
|
+
"@query-farm/vgi-rpc": "^0.29.6"
|
|
95
97
|
},
|
|
96
98
|
"devDependencies": {
|
|
97
99
|
"@duckdb/node-api": "^1.5.5-r.4",
|
|
98
100
|
"@query-farm/apache-arrow": "^21.1.1",
|
|
99
|
-
"@query-farm/vgi-rpc": "^0.29.
|
|
101
|
+
"@query-farm/vgi-rpc": "^0.29.6",
|
|
100
102
|
"@types/bun": "latest",
|
|
101
103
|
"typescript": "^7.0.2"
|
|
102
104
|
},
|
|
@@ -25,11 +25,11 @@ export interface ArgumentSpec {
|
|
|
25
25
|
name: string;
|
|
26
26
|
position: number | string;
|
|
27
27
|
arrowType: VgiDataType;
|
|
28
|
-
isTableInput?: boolean;
|
|
29
|
-
isAnyType?: boolean;
|
|
30
|
-
isVarargs?: boolean;
|
|
31
|
-
isConst?: boolean;
|
|
32
|
-
doc?: string;
|
|
28
|
+
isTableInput?: boolean | undefined;
|
|
29
|
+
isAnyType?: boolean | undefined;
|
|
30
|
+
isVarargs?: boolean | undefined;
|
|
31
|
+
isConst?: boolean | undefined;
|
|
32
|
+
doc?: string | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* Discovery-facing constraint metadata, pre-encoded to their surfaced UTF-8
|
|
35
35
|
* forms (presence-only — `undefined` means the constraint is absent and the
|
|
@@ -37,10 +37,10 @@ export interface ArgumentSpec {
|
|
|
37
37
|
* `ArgumentSpec.default_json` / `choices_json` / `range_notation` / `pattern`
|
|
38
38
|
* so `argumentSpecsToSchema`/`schemaToArgumentSpecs` round-trip symmetrically.
|
|
39
39
|
*/
|
|
40
|
-
defaultJson?: string;
|
|
41
|
-
choicesJson?: string;
|
|
42
|
-
rangeNotation?: string;
|
|
43
|
-
pattern?: string;
|
|
40
|
+
defaultJson?: string | undefined;
|
|
41
|
+
choicesJson?: string | undefined;
|
|
42
|
+
rangeNotation?: string | undefined;
|
|
43
|
+
pattern?: string | undefined;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -59,7 +59,11 @@ export interface ArgumentConstraints {
|
|
|
59
59
|
gt?: number;
|
|
60
60
|
/** Exclusive upper bound (`<`). */
|
|
61
61
|
lt?: number;
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Regex the value must match (surfaced as `vgi_pattern`, as-is). Matching is
|
|
64
|
+
* an UNANCHORED search (JSON Schema / ECMA-262 semantics, same across SDKs):
|
|
65
|
+
* `"\\d"` accepts `"ab1"`. Anchor with `^...$` to require a full match.
|
|
66
|
+
*/
|
|
63
67
|
pattern?: string;
|
|
64
68
|
/** Default value (JSON-encoded into `vgi_default`); optional args only. */
|
|
65
69
|
default?: unknown;
|
|
@@ -260,7 +264,9 @@ export function assertArrowTypes(
|
|
|
260
264
|
* Enforce a bind-time const value against its declared {@link ArgumentConstraints},
|
|
261
265
|
* throwing {@link ArgumentValidationError} on violation. Mirrors the Python SDK's
|
|
262
266
|
* `Arg._validate`: numeric range (`ge`/`le`/`gt`/`lt`), closed choice set, and
|
|
263
|
-
* regex `pattern
|
|
267
|
+
* regex `pattern` (an unanchored search — `RegExp.prototype.test`, matching the
|
|
268
|
+
* JSON Schema `pattern` keyword). A `null`/`undefined` value skips its value
|
|
269
|
+
* constraints.
|
|
264
270
|
*/
|
|
265
271
|
export function validateConstConstraints(
|
|
266
272
|
name: string,
|
|
@@ -340,8 +340,8 @@ function bigIntUnitCodec(label: string): Codec {
|
|
|
340
340
|
function decimalViewToBigInt(view: ArrayBufferView): bigint {
|
|
341
341
|
const u8 = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
342
342
|
let bi = 0n;
|
|
343
|
-
for (let i = u8.length - 1; i >= 0; i--) bi = (bi << 8n) | BigInt(u8[i]);
|
|
344
|
-
if (u8.length > 0 && (u8[u8.length - 1] & 0x80)) bi -= 1n << BigInt(u8.length * 8);
|
|
343
|
+
for (let i = u8.length - 1; i >= 0; i--) bi = (bi << 8n) | BigInt(u8[i]!);
|
|
344
|
+
if (u8.length > 0 && (u8[u8.length - 1]! & 0x80)) bi -= 1n << BigInt(u8.length * 8);
|
|
345
345
|
return bi;
|
|
346
346
|
}
|
|
347
347
|
|
|
@@ -97,7 +97,7 @@ function buildInt32Data(values: unknown[], type: DataType): any {
|
|
|
97
97
|
for (let i = 0; i < length; i++) {
|
|
98
98
|
const v = values[i];
|
|
99
99
|
if (v === null || v === undefined) { nullCount++; continue; }
|
|
100
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
100
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
101
101
|
buf[i] = typeof v === "bigint" ? Number(v) : (v as number);
|
|
102
102
|
}
|
|
103
103
|
return makeData({
|
|
@@ -115,7 +115,7 @@ function buildBigIntData(values: unknown[], type: DataType): any {
|
|
|
115
115
|
for (let i = 0; i < length; i++) {
|
|
116
116
|
const v = values[i];
|
|
117
117
|
if (v === null || v === undefined) { nullCount++; continue; }
|
|
118
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
118
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
119
119
|
bigBuf[i] = typeof v === "bigint" ? v : BigInt(v as number);
|
|
120
120
|
}
|
|
121
121
|
const data = new Int32Array(bigBuf.buffer);
|
|
@@ -135,7 +135,7 @@ function buildDecimalData(values: unknown[], type: DataType): any {
|
|
|
135
135
|
for (let i = 0; i < length; i++) {
|
|
136
136
|
const val = values[i];
|
|
137
137
|
if (val === null || val === undefined) { nullCount++; continue; }
|
|
138
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
138
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
139
139
|
let bytes: Uint8Array;
|
|
140
140
|
if (val instanceof Uint8Array) {
|
|
141
141
|
bytes = val;
|
|
@@ -172,7 +172,7 @@ function bigIntToDecimalBytes(value: bigint, byteWidth: number): Uint8Array {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
function buildListData(values: unknown[], listType: List): any {
|
|
175
|
-
const childField = listType.children[0]
|
|
175
|
+
const childField = listType.children[0]!;
|
|
176
176
|
const numRows = values.length;
|
|
177
177
|
const offsets = new Int32Array(numRows + 1);
|
|
178
178
|
const allItems: unknown[] = [];
|
|
@@ -184,7 +184,7 @@ function buildListData(values: unknown[], listType: List): any {
|
|
|
184
184
|
if (row == null) {
|
|
185
185
|
nullCount++;
|
|
186
186
|
} else {
|
|
187
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
187
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
188
188
|
const items = Array.isArray(row) ? row
|
|
189
189
|
: (typeof (row as any)[Symbol.iterator] === "function") ? Array.from(row as Iterable<unknown>)
|
|
190
190
|
: null;
|
|
@@ -211,7 +211,7 @@ function buildListData(values: unknown[], listType: List): any {
|
|
|
211
211
|
* decimal threw.
|
|
212
212
|
*/
|
|
213
213
|
function buildFixedSizeListData(values: unknown[], type: FixedSizeList): any {
|
|
214
|
-
const childField = type.children[0]
|
|
214
|
+
const childField = type.children[0]!;
|
|
215
215
|
const listSize = type.listSize;
|
|
216
216
|
const numRows = values.length;
|
|
217
217
|
const allItems: unknown[] = [];
|
|
@@ -225,7 +225,7 @@ function buildFixedSizeListData(values: unknown[], type: FixedSizeList): any {
|
|
|
225
225
|
for (let j = 0; j < listSize; j++) allItems.push(null);
|
|
226
226
|
continue;
|
|
227
227
|
}
|
|
228
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
228
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
229
229
|
const items = Array.isArray(row) ? row : Array.from(row as Iterable<unknown>);
|
|
230
230
|
if (items.length !== listSize) {
|
|
231
231
|
throw new TypeError(
|
|
@@ -246,7 +246,7 @@ function buildFixedSizeListData(values: unknown[], type: FixedSizeList): any {
|
|
|
246
246
|
|
|
247
247
|
function buildMapData(values: unknown[], mapType: Map_): any {
|
|
248
248
|
const numRows = values.length;
|
|
249
|
-
const entriesField = mapType.children[0]
|
|
249
|
+
const entriesField = mapType.children[0]!;
|
|
250
250
|
const keyField = (entriesField.type as any).children[0] as Field;
|
|
251
251
|
const valueField = (entriesField.type as any).children[1] as Field;
|
|
252
252
|
const offsets = new Int32Array(numRows + 1);
|
|
@@ -260,7 +260,7 @@ function buildMapData(values: unknown[], mapType: Map_): any {
|
|
|
260
260
|
if (row == null) {
|
|
261
261
|
nullCount++;
|
|
262
262
|
} else {
|
|
263
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
263
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
264
264
|
// Canonical map is Array<[k, v]>, but tolerate Map / iterable / object.
|
|
265
265
|
const pairs: Array<[unknown, unknown]> = Array.isArray(row) ? row as any
|
|
266
266
|
: row instanceof Map ? Array.from(row.entries())
|
|
@@ -298,16 +298,16 @@ function buildStructData(values: unknown[], structType: Struct): any {
|
|
|
298
298
|
const row = values[i] as any;
|
|
299
299
|
if (row == null) {
|
|
300
300
|
nullCount++;
|
|
301
|
-
for (let c = 0; c < childFields.length; c++) childArrays[c]
|
|
301
|
+
for (let c = 0; c < childFields.length; c++) childArrays[c]!.push(null);
|
|
302
302
|
} else {
|
|
303
|
-
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
303
|
+
nullBitmap[i >> 3]! |= 1 << (i & 7);
|
|
304
304
|
for (let c = 0; c < childFields.length; c++) {
|
|
305
|
-
const name = childFields[c]
|
|
306
|
-
childArrays[c]
|
|
305
|
+
const name = childFields[c]!.name;
|
|
306
|
+
childArrays[c]!.push(row[name] ?? row[c] ?? null);
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
|
-
const children = childFields.map((cf, idx) => buildColumnData(childArrays[idx]
|
|
310
|
+
const children = childFields.map((cf, idx) => buildColumnData(childArrays[idx]!, cf.type));
|
|
311
311
|
return makeData({
|
|
312
312
|
type: structType, length: numRows, nullCount,
|
|
313
313
|
nullBitmap: nullCount > 0 ? nullBitmap : undefined, children,
|
|
@@ -318,21 +318,21 @@ function emptyDataForType(type: DataType): any {
|
|
|
318
318
|
if (DataType.isList(type)) {
|
|
319
319
|
return makeData({
|
|
320
320
|
type, length: 0, nullCount: 0,
|
|
321
|
-
child: emptyDataForType((type as List).children[0]
|
|
321
|
+
child: emptyDataForType((type as List).children[0]!.type),
|
|
322
322
|
valueOffsets: new Int32Array([0]),
|
|
323
323
|
});
|
|
324
324
|
}
|
|
325
325
|
if (DataType.isMap(type)) {
|
|
326
326
|
return makeData({
|
|
327
327
|
type, length: 0, nullCount: 0,
|
|
328
|
-
child: emptyDataForType((type as Map_).children[0]
|
|
328
|
+
child: emptyDataForType((type as Map_).children[0]!.type),
|
|
329
329
|
valueOffsets: new Int32Array([0]),
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
if (DataType.isFixedSizeList(type)) {
|
|
333
333
|
return makeData({
|
|
334
334
|
type, length: 0, nullCount: 0,
|
|
335
|
-
child: emptyDataForType((type as FixedSizeList).children[0]
|
|
335
|
+
child: emptyDataForType((type as FixedSizeList).children[0]!.type),
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
338
|
if (DataType.isStruct(type)) {
|
|
@@ -451,7 +451,7 @@ function decimalToBigInt(type: DataType, data: any, index: number): bigint {
|
|
|
451
451
|
const start = index * wordsPerElem;
|
|
452
452
|
const u8 = new Uint8Array(byteWidth);
|
|
453
453
|
for (let w = 0; w < wordsPerElem; w++) {
|
|
454
|
-
const word = u32[start + w] >>> 0;
|
|
454
|
+
const word = u32[start + w]! >>> 0;
|
|
455
455
|
u8[w * 4] = word & 0xff;
|
|
456
456
|
u8[w * 4 + 1] = (word >>> 8) & 0xff;
|
|
457
457
|
u8[w * 4 + 2] = (word >>> 16) & 0xff;
|
|
@@ -463,8 +463,8 @@ function decimalToBigInt(type: DataType, data: any, index: number): bigint {
|
|
|
463
463
|
/** Little-endian two's-complement bytes -> signed bigint. */
|
|
464
464
|
function decimalBytesToBigInt(u8: Uint8Array): bigint {
|
|
465
465
|
let bi = 0n;
|
|
466
|
-
for (let i = u8.length - 1; i >= 0; i--) bi = (bi << 8n) | BigInt(u8[i]);
|
|
467
|
-
if (u8[u8.length - 1] & 0x80) bi -= 1n << BigInt(u8.length * 8);
|
|
466
|
+
for (let i = u8.length - 1; i >= 0; i--) bi = (bi << 8n) | BigInt(u8[i]!);
|
|
467
|
+
if (u8[u8.length - 1]! & 0x80) bi -= 1n << BigInt(u8.length * 8);
|
|
468
468
|
return bi;
|
|
469
469
|
}
|
|
470
470
|
|
|
@@ -472,7 +472,7 @@ function readStruct(type: DataType, col: any, index: number): Record<string, unk
|
|
|
472
472
|
const children = (type as any).children as Field[];
|
|
473
473
|
const out: Record<string, unknown> = {};
|
|
474
474
|
for (let c = 0; c < children.length; c++) {
|
|
475
|
-
const cf = children[c]
|
|
475
|
+
const cf = children[c]!;
|
|
476
476
|
const childVec = typeof col.getChildAt === "function"
|
|
477
477
|
? col.getChildAt(c)
|
|
478
478
|
: (col.children?.[c]);
|
|
@@ -487,7 +487,7 @@ function readUnion(type: DataType, col: any, data: any, index: number): TaggedUn
|
|
|
487
487
|
// Per-row type code -> child index. DuckDB emits SPARSE unions, where every
|
|
488
488
|
// child is full-length and aligned with the parent row.
|
|
489
489
|
const typeIds: ArrayLike<number> | undefined = data?.typeIds;
|
|
490
|
-
const tcode = typeIds ? typeIds[index] : children.length > 0 ? 0 : -1;
|
|
490
|
+
const tcode = typeIds ? typeIds[index]! : children.length > 0 ? 0 : -1;
|
|
491
491
|
const map = (type as any).typeIdToChildIndex as Record<number, number> | undefined;
|
|
492
492
|
const childIdx = map && map[tcode] !== undefined ? map[tcode] : tcode;
|
|
493
493
|
const childField = children[childIdx];
|
|
@@ -495,7 +495,7 @@ function readUnion(type: DataType, col: any, data: any, index: number): TaggedUn
|
|
|
495
495
|
// Dense unions carry an offsets buffer remapping the parent row into the
|
|
496
496
|
// child; sparse unions read the child at the same row.
|
|
497
497
|
const offsets: ArrayLike<number> | undefined = data?.valueOffsets;
|
|
498
|
-
const childRow = offsets ? offsets[index] : index;
|
|
498
|
+
const childRow = offsets ? offsets[index]! : index;
|
|
499
499
|
const childVec = typeof col.getChildAt === "function"
|
|
500
500
|
? col.getChildAt(childIdx)
|
|
501
501
|
: col.children?.[childIdx];
|
|
@@ -21,7 +21,7 @@ function emptyData(field: Field): any {
|
|
|
21
21
|
const type = field.type;
|
|
22
22
|
|
|
23
23
|
if (DataType.isList(type)) {
|
|
24
|
-
const childField = (type as List).children[0]
|
|
24
|
+
const childField = (type as List).children[0]!;
|
|
25
25
|
return makeData({
|
|
26
26
|
type,
|
|
27
27
|
length: 0,
|
|
@@ -32,7 +32,7 @@ function emptyData(field: Field): any {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (DataType.isMap(type)) {
|
|
35
|
-
const entriesField = (type as Map_).children[0]
|
|
35
|
+
const entriesField = (type as Map_).children[0]!;
|
|
36
36
|
return makeData({
|
|
37
37
|
type,
|
|
38
38
|
length: 0,
|
|
@@ -33,7 +33,7 @@ export function deserializeSchema(bytes: Uint8Array): Schema {
|
|
|
33
33
|
const reader = RecordBatchReader.from(bytes);
|
|
34
34
|
const batches = [...reader];
|
|
35
35
|
if (batches.length > 0) {
|
|
36
|
-
return batches[0]
|
|
36
|
+
return batches[0]!.schema;
|
|
37
37
|
}
|
|
38
38
|
if (reader.schema) return reader.schema;
|
|
39
39
|
throw new Error("Cannot deserialize schema from empty IPC stream");
|
|
@@ -64,7 +64,7 @@ export function deserializeBatch(bytes: Uint8Array): RecordBatch {
|
|
|
64
64
|
const sch = reader.schema ?? new Schema([]);
|
|
65
65
|
return emptyBatch(sch);
|
|
66
66
|
}
|
|
67
|
-
return batches[0]
|
|
67
|
+
return batches[0]!;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/** Decode every data batch of a collection stream (including dictionary replacements). */
|
|
@@ -22,11 +22,11 @@ export function* iterRows(
|
|
|
22
22
|
for (let i = 0; i < a.numRows; i++) {
|
|
23
23
|
const row: Record<string, any> = {};
|
|
24
24
|
for (let fi = 0; fi < a.schema.fields.length; fi++) {
|
|
25
|
-
const field = a.schema.fields[fi]
|
|
25
|
+
const field = a.schema.fields[fi]!;
|
|
26
26
|
const col = a.getChild(field.name);
|
|
27
27
|
if (!col) { row[field.name] = null; continue; }
|
|
28
28
|
const canonical = readCanonicalValue(field.type as unknown as VgiDataType, col, i);
|
|
29
|
-
const codec = codecs[fi]
|
|
29
|
+
const codec = codecs[fi]!;
|
|
30
30
|
row[field.name] = repr === "raw"
|
|
31
31
|
? codec.canonicalToRaw(canonical)
|
|
32
32
|
: codec.canonicalToRich(canonical);
|
|
@@ -41,7 +41,7 @@ export function projectSchema(
|
|
|
41
41
|
if (!projectionIds) return a;
|
|
42
42
|
const validIds = validateProjectionIds("projectSchema", projectionIds, a.fields.length);
|
|
43
43
|
if (validIds.length === 0) return a;
|
|
44
|
-
return new Schema(validIds.map((i) => a.fields[i]), a.metadata);
|
|
44
|
+
return new Schema(validIds.map((i) => a.fields[i]!), a.metadata);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -58,7 +58,7 @@ export function projectBatch(
|
|
|
58
58
|
const projectedSchema = projectSchema(projectionIds, a.schema);
|
|
59
59
|
const children = validIds.map((i) => {
|
|
60
60
|
const col = a.getChildAt(i);
|
|
61
|
-
return col!.data[0]
|
|
61
|
+
return col!.data[0]!;
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
const structType = new Struct(projectedSchema.fields);
|
|
@@ -53,7 +53,8 @@ export function batchFromColumns(
|
|
|
53
53
|
): VgiBatch {
|
|
54
54
|
let numRows = 0;
|
|
55
55
|
for (const f of schema.fields) {
|
|
56
|
-
|
|
56
|
+
const col = columns[f.name];
|
|
57
|
+
if (col) { numRows = col.length; break; }
|
|
57
58
|
}
|
|
58
59
|
const canonicalColumns: Record<string, unknown[]> = {};
|
|
59
60
|
for (const f of schema.fields) {
|
|
@@ -71,8 +71,8 @@ export function writeCanonicalBatch(
|
|
|
71
71
|
const ftype = toFlechetteType(f.type);
|
|
72
72
|
const values = columns[f.name];
|
|
73
73
|
const col: Column<any> = values
|
|
74
|
-
? f_columnFromArray(prepareForFlechette(f.type, values), ftype, { ...COLUMN_OPTS, maxBatchRows })
|
|
75
|
-
: f_columnFromArray(new Array(numRows).fill(null), ftype, { ...COLUMN_OPTS, maxBatchRows });
|
|
74
|
+
? f_columnFromArray(prepareForFlechette(f.type, values), ftype, { ...COLUMN_OPTS, ...(maxBatchRows !== undefined ? { maxBatchRows } : {}) })
|
|
75
|
+
: f_columnFromArray(new Array(numRows).fill(null), ftype, { ...COLUMN_OPTS, ...(maxBatchRows !== undefined ? { maxBatchRows } : {}) });
|
|
76
76
|
childCols.push(col);
|
|
77
77
|
const nullable = (f as any).nullable ?? true;
|
|
78
78
|
const metadata = (f as any).metadata ?? null;
|
|
@@ -118,9 +118,9 @@ export function prepareForFlechette(type: VgiDataType, values: unknown[]): unkno
|
|
|
118
118
|
if (v == null) return null;
|
|
119
119
|
const w = v as ArrayLike<number>;
|
|
120
120
|
if (typeof (w as any).length !== "number" || w.length < 4) return v;
|
|
121
|
-
const lo = BigInt(w[2] >>> 0);
|
|
122
|
-
const hi = BigInt(w[3] | 0);
|
|
123
|
-
return [w[0] | 0, w[1] | 0, BigInt.asIntN(64, (hi << 32n) | lo)];
|
|
121
|
+
const lo = BigInt(w[2]! >>> 0);
|
|
122
|
+
const hi = BigInt(w[3]! | 0);
|
|
123
|
+
return [w[0]! | 0, w[1]! | 0, BigInt.asIntN(64, (hi << 32n) | lo)];
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
if (tid === 17) {
|
|
@@ -222,7 +222,7 @@ function isNullAt(data: any, index: number): boolean {
|
|
|
222
222
|
if ((data?.nullCount ?? 0) === 0) return false;
|
|
223
223
|
const validity: Uint8Array | undefined = data?.validity;
|
|
224
224
|
if (!validity || validity.length === 0) return false;
|
|
225
|
-
return ((validity[index >> 3] >> (index & 7)) & 1) === 0;
|
|
225
|
+
return ((validity[index >> 3]! >> (index & 7)) & 1) === 0;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/** Read a struct column-based so nested union children keep their tags. */
|
|
@@ -242,7 +242,8 @@ function readStructColumn(
|
|
|
242
242
|
const children = (type as any).children as Array<{ name: string; type: VgiDataType }>;
|
|
243
243
|
const out: Record<string, unknown> = {};
|
|
244
244
|
for (let c = 0; c < children.length; c++) {
|
|
245
|
-
|
|
245
|
+
const child = children[c]!;
|
|
246
|
+
out[child.name] = readCanonicalValue(child.type, data.children[c], index);
|
|
246
247
|
}
|
|
247
248
|
return out;
|
|
248
249
|
}
|
|
@@ -259,7 +260,7 @@ function readUnionColumn(
|
|
|
259
260
|
// Per-row type code -> child index. DuckDB emits SPARSE unions: each child is
|
|
260
261
|
// full-length and aligned with the parent row.
|
|
261
262
|
const typeIds: ArrayLike<number> | undefined = data?.typeIds;
|
|
262
|
-
const tcode = typeIds ? typeIds[index] : children.length > 0 ? 0 : -1;
|
|
263
|
+
const tcode = typeIds ? typeIds[index]! : children.length > 0 ? 0 : -1;
|
|
263
264
|
const map = (type as any).typeMap as Record<number, number> | undefined;
|
|
264
265
|
const childIdx = map && map[tcode] !== undefined ? map[tcode] : tcode;
|
|
265
266
|
const childField = children[childIdx];
|
|
@@ -267,7 +268,7 @@ function readUnionColumn(
|
|
|
267
268
|
// Dense unions remap the row via offsets; sparse unions share the row index.
|
|
268
269
|
const offsets: ArrayLike<number> | undefined = data?.offsets;
|
|
269
270
|
const isDense = (type as any).mode === 1;
|
|
270
|
-
const childRow = isDense && offsets ? offsets[index] : index;
|
|
271
|
+
const childRow = isDense && offsets ? offsets[index]! : index;
|
|
271
272
|
const value = readCanonicalValue(childField.type, data.children[childIdx], childRow);
|
|
272
273
|
return { tag: childField.name, value };
|
|
273
274
|
}
|
|
@@ -64,10 +64,10 @@ function columnIsValid(this: any, index: number): boolean {
|
|
|
64
64
|
let hi = data.length;
|
|
65
65
|
while (lo < hi) {
|
|
66
66
|
const mid = (lo + hi) >>> 1;
|
|
67
|
-
if (offsets[mid + 1] <= index) lo = mid + 1;
|
|
67
|
+
if (offsets[mid + 1]! <= index) lo = mid + 1;
|
|
68
68
|
else hi = mid;
|
|
69
69
|
}
|
|
70
|
-
return batchIsValid(data[lo], index - offsets[lo]);
|
|
70
|
+
return batchIsValid(data[lo], index - offsets[lo]!);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
@@ -160,7 +160,7 @@ function intervalMonthDayNanoValue(this: any, index: number): Int32Array {
|
|
|
160
160
|
for (let w = 0; w < 4; w++) {
|
|
161
161
|
const p = base + (w << 2);
|
|
162
162
|
out[w] =
|
|
163
|
-
bytes[p] | (bytes[p + 1] << 8) | (bytes[p + 2] << 16) | (bytes[p + 3] << 24);
|
|
163
|
+
bytes[p]! | (bytes[p + 1]! << 8) | (bytes[p + 2]! << 16) | (bytes[p + 3]! << 24);
|
|
164
164
|
}
|
|
165
165
|
return out;
|
|
166
166
|
}
|
|
@@ -20,13 +20,14 @@ const TYPE_SCHEMA = 1;
|
|
|
20
20
|
const TYPE_RECORD_BATCH = 3;
|
|
21
21
|
|
|
22
22
|
function readU32LE(b: Uint8Array, p: number): number {
|
|
23
|
-
|
|
23
|
+
// Out-of-range bytes read as `undefined`, which the bitwise ops coerce to 0.
|
|
24
|
+
return ((b[p]! | (b[p + 1]! << 8) | (b[p + 2]! << 16) | (b[p + 3]! << 24)) >>> 0);
|
|
24
25
|
}
|
|
25
26
|
function readI32LE(b: Uint8Array, p: number): number {
|
|
26
27
|
return readU32LE(b, p) | 0;
|
|
27
28
|
}
|
|
28
29
|
function readI16LE(b: Uint8Array, p: number): number {
|
|
29
|
-
const v = b[p] | (b[p + 1] << 8);
|
|
30
|
+
const v = b[p]! | (b[p + 1]! << 8);
|
|
30
31
|
return v < 0x8000 ? v : v - 0x10000;
|
|
31
32
|
}
|
|
32
33
|
function readI64LE(b: Uint8Array, p: number): bigint {
|
|
@@ -61,7 +62,7 @@ function readTable(buf: Uint8Array, tablePos: number): FbTable {
|
|
|
61
62
|
/** Position of a field in the table buffer, or null if absent (offset 0). */
|
|
62
63
|
function fieldAt(t: FbTable, fieldIndex: number): number | null {
|
|
63
64
|
if (fieldIndex >= t.fields.length) return null;
|
|
64
|
-
const off = t.fields[fieldIndex]
|
|
65
|
+
const off = t.fields[fieldIndex]!;
|
|
65
66
|
return off === 0 ? null : t.pos + off;
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -97,7 +98,7 @@ function readMessageEnvelope(head: Uint8Array): ParsedMessage {
|
|
|
97
98
|
// 3: bodyLength (int64) vtable offset 10
|
|
98
99
|
// 4: custom_metadata ([KeyVal]) vtable offset 12
|
|
99
100
|
const headerTypePos = fieldAt(msg, 1);
|
|
100
|
-
const headerType = headerTypePos === null ? 0 : head[headerTypePos]
|
|
101
|
+
const headerType = headerTypePos === null ? 0 : head[headerTypePos]!;
|
|
101
102
|
|
|
102
103
|
const bodyLengthPos = fieldAt(msg, 3);
|
|
103
104
|
const bodyLengthBig = bodyLengthPos === null ? 0n : readI64LE(head, bodyLengthPos);
|
|
@@ -120,7 +120,7 @@ function buildUnionColumn(
|
|
|
120
120
|
// children get null from the SparseUnionBuilder).
|
|
121
121
|
const prepared = values.map((v, i) => {
|
|
122
122
|
if (v == null) return null;
|
|
123
|
-
const type = typeOrder[rowTypeCodes[i]]
|
|
123
|
+
const type = typeOrder[rowTypeCodes[i]!]!;
|
|
124
124
|
const codec = codecFor(type);
|
|
125
125
|
return prepareForFlechette(type, [codec.richToCanonical(v)])[0];
|
|
126
126
|
});
|
|
@@ -128,7 +128,7 @@ function buildUnionColumn(
|
|
|
128
128
|
UnionMode.Sparse,
|
|
129
129
|
children as any,
|
|
130
130
|
typeIds,
|
|
131
|
-
(_value: any, index: number) => rowTypeCodes[index]
|
|
131
|
+
(_value: any, index: number) => rowTypeCodes[index]!,
|
|
132
132
|
);
|
|
133
133
|
return f_columnFromArray(prepared, unionType as any, COLUMN_OPTS);
|
|
134
134
|
}
|
package/src/attach-ticket.ts
CHANGED
|
@@ -255,7 +255,7 @@ function decodePayload(payload: Uint8Array): AttachTicketClaims {
|
|
|
255
255
|
|
|
256
256
|
function b64url(data: Uint8Array): string {
|
|
257
257
|
let bin = "";
|
|
258
|
-
for (let i = 0; i < data.length; i++) bin += String.fromCharCode(data[i]);
|
|
258
|
+
for (let i = 0; i < data.length; i++) bin += String.fromCharCode(data[i]!);
|
|
259
259
|
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -422,7 +422,7 @@ export async function redeemAttachTicket(
|
|
|
422
422
|
others.map((k) => [`options.${k}`, `not allowed alongside ${ATTACH_TICKET_OPTION}`] as const),
|
|
423
423
|
);
|
|
424
424
|
}
|
|
425
|
-
const token = options[ticketKeys[0]];
|
|
425
|
+
const token = options[ticketKeys[0]!];
|
|
426
426
|
if (typeof token !== "string") throw new AttachTicketInvalidError(`${ATTACH_TICKET_OPTION} must be a string`);
|
|
427
427
|
if (!signingKey) throw new AttachTicketInvalidError("this worker does not redeem attach tickets");
|
|
428
428
|
const claims = await openAttachTicket(signingKey, token, callerPrincipal(auth), now);
|
|
@@ -18,7 +18,7 @@ function scalarText(value: string): void {
|
|
|
18
18
|
function tags(value: string): void {
|
|
19
19
|
let i = 0;
|
|
20
20
|
const ws = () => {
|
|
21
|
-
while (i < value.length && /[ \t\r\n]/.test(value[i])) i++;
|
|
21
|
+
while (i < value.length && /[ \t\r\n]/.test(value[i]!)) i++;
|
|
22
22
|
};
|
|
23
23
|
const str = (): string => {
|
|
24
24
|
ws();
|
package/src/catalog/composite.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class CompositeCatalogInterface extends CatalogInterface {
|
|
|
52
52
|
|
|
53
53
|
private _route(attachOpaqueData: AttachOpaqueData): CatalogInterface {
|
|
54
54
|
const idx = attachOpaqueData[ROUTE_BYTE];
|
|
55
|
-
const route = this._backends[idx];
|
|
55
|
+
const route = idx === undefined ? undefined : this._backends[idx];
|
|
56
56
|
if (!route) {
|
|
57
57
|
// Routing is a check too (vgi-opaque-data-sealing.md rule 4): an
|
|
58
58
|
// unroutable value gets the uniform refusal, never a description of
|
|
@@ -99,7 +99,7 @@ export class CompositeCatalogInterface extends CatalogInterface {
|
|
|
99
99
|
clientCapabilities?: Uint8Array | null,
|
|
100
100
|
): Promise<CatalogAttachResult> {
|
|
101
101
|
for (let i = 0; i < this._backends.length; i++) {
|
|
102
|
-
const b = this._backends[i]
|
|
102
|
+
const b = this._backends[i]!;
|
|
103
103
|
if (b.catalogs().includes(name)) {
|
|
104
104
|
const result = await b.attach(name, options, dataVersionSpec, implementationVersion, clientCapabilities);
|
|
105
105
|
// Stamp the route-byte so other workers in the pool can decode the
|
|
@@ -416,10 +416,10 @@ export function validateTableConstraints(
|
|
|
416
416
|
fail((error as Error).message);
|
|
417
417
|
}
|
|
418
418
|
const resolveTop = (path: string[]): number => {
|
|
419
|
-
const matches = fieldsByExactName(fields, path[0]);
|
|
419
|
+
const matches = fieldsByExactName(fields, path[0]!);
|
|
420
420
|
if (matches.length !== 1 || matches[0] === rowId)
|
|
421
421
|
fail(`column path ${path.join(".")} names a missing, ambiguous or row-id column`);
|
|
422
|
-
return matches[0]
|
|
422
|
+
return matches[0]!;
|
|
423
423
|
};
|
|
424
424
|
switch (record.kind) {
|
|
425
425
|
case "CHECK": {
|
|
@@ -429,14 +429,14 @@ export function validateTableConstraints(
|
|
|
429
429
|
}
|
|
430
430
|
case "NOT_NULL": {
|
|
431
431
|
if (record.columns.length !== 1) fail("NOT_NULL requires exactly one column path");
|
|
432
|
-
const path = record.columns[0]
|
|
433
|
-
let field = fields[resolveTop(path)]
|
|
432
|
+
const path = record.columns[0]!;
|
|
433
|
+
let field = fields[resolveTop(path)]!;
|
|
434
434
|
for (let depth = 1; depth < path.length; depth++) {
|
|
435
435
|
const children = ordinaryStructChildren(field);
|
|
436
436
|
if (!children) fail(`column path ${path.join(".")} must traverse ordinary STRUCT fields`);
|
|
437
|
-
const matches = fieldsByExactName(children!, path[depth]);
|
|
437
|
+
const matches = fieldsByExactName(children!, path[depth]!);
|
|
438
438
|
if (matches.length !== 1) fail(`column path ${path.join(".")} names a missing or ambiguous nested field`);
|
|
439
|
-
field = children![matches[0]]
|
|
439
|
+
field = children![matches[0]!]!;
|
|
440
440
|
}
|
|
441
441
|
if (path.length === 1 && isGeneratedField(field))
|
|
442
442
|
fail(`column ${path[0]} is a generated column, which DuckDB requires to be nullable`);
|
|
@@ -447,7 +447,7 @@ export function validateTableConstraints(
|
|
|
447
447
|
case "UNIQUE": {
|
|
448
448
|
for (const path of record.columns) {
|
|
449
449
|
const index = resolveTop(path);
|
|
450
|
-
if (record.kind === "PRIMARY_KEY" && isGeneratedField(fields[index]))
|
|
450
|
+
if (record.kind === "PRIMARY_KEY" && isGeneratedField(fields[index]!))
|
|
451
451
|
fail(`PRIMARY KEY column ${path[0]} is a generated column, which DuckDB requires to be nullable`);
|
|
452
452
|
}
|
|
453
453
|
if (record.kind === "PRIMARY_KEY") {
|
|
@@ -505,7 +505,7 @@ function validateCheckRecord(
|
|
|
505
505
|
const matches = fields.map((f, i) => (f.name.toLowerCase() === lower ? i : -1)).filter((i) => i >= 0);
|
|
506
506
|
if (matches.length > 1) throw new Error(`ambiguous CHECK column reference ${name}`);
|
|
507
507
|
if (matches.length === 0 || matches[0] === rowId) throw new Error(`CHECK references a missing or row-id column ${name}`);
|
|
508
|
-
const column = fields[matches[0]]
|
|
508
|
+
const column = fields[matches[0]!]!;
|
|
509
509
|
if (column.metadata.has("ARROW:extension:name")) throw new Error(`CHECK operand ${name} has an extension type`);
|
|
510
510
|
if (isGeneratedField(column)) throw new Error(`CHECK operand ${name} is a generated column`);
|
|
511
511
|
const type = duckdbPrimitive(column);
|
|
@@ -585,7 +585,7 @@ export function validateConstraintNullability(
|
|
|
585
585
|
fields: readonly VgiField[],
|
|
586
586
|
constraints: readonly Uint8Array[],
|
|
587
587
|
): void {
|
|
588
|
-
const schemaPath = constraints.length ? readConstraintRecord(constraints[0]).schemaPath : ["main"];
|
|
588
|
+
const schemaPath = constraints.length ? readConstraintRecord(constraints[0]!).schemaPath : ["main"];
|
|
589
589
|
validateTableConstraints(table, schemaPath, fields, constraints);
|
|
590
590
|
}
|
|
591
591
|
|