@query-farm/vgi 0.48.0 → 0.48.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.
Files changed (95) hide show
  1. package/dist/arguments/argument-spec.d.ts +17 -11
  2. package/dist/catalog/descriptors.d.ts +2 -2
  3. package/dist/catalog/publication.d.ts +7 -7
  4. package/dist/client/client.d.ts +9 -3
  5. package/dist/client/errors.d.ts +2 -2
  6. package/dist/client/types.d.ts +21 -0
  7. package/dist/client-entry.d.ts +1 -1
  8. package/dist/client-entry.js +31 -7
  9. package/dist/client-entry.js.map +20 -20
  10. package/dist/filter-pushdown/deserialize.d.ts +1 -1
  11. package/dist/filter-pushdown/types.d.ts +10 -10
  12. package/dist/functions/scalar.d.ts +1 -1
  13. package/dist/functions/table-buffering.d.ts +20 -20
  14. package/dist/functions/table-in-out.d.ts +4 -4
  15. package/dist/functions/table.d.ts +7 -7
  16. package/dist/functions/types.d.ts +47 -47
  17. package/dist/http/fetch.d.ts +10 -10
  18. package/dist/index.core.d.ts +1 -1
  19. package/dist/index.js +155 -94
  20. package/dist/index.js.map +53 -52
  21. package/dist/protocol/dispatch.d.ts +3 -3
  22. package/dist/protocol/handlers/function.d.ts +2 -2
  23. package/dist/protocol/serializers/cardinality.d.ts +4 -1
  24. package/dist/protocol/types.d.ts +5 -5
  25. package/dist/rpc-server.d.ts +6 -6
  26. package/dist/serve-entry.d.ts +16 -16
  27. package/dist/serve-entry.js +42 -21
  28. package/dist/serve-entry.js.map +38 -37
  29. package/dist/split-token.d.ts +6 -6
  30. package/dist/types.d.ts +9 -2
  31. package/dist/util/defined.d.ts +21 -0
  32. package/dist/worker-cf-entry.js +120 -85
  33. package/dist/worker-cf-entry.js.map +51 -50
  34. package/dist/worker.d.ts +2 -2
  35. package/package.json +6 -4
  36. package/src/arguments/argument-spec.ts +17 -11
  37. package/src/arrow/codec/registry.ts +2 -2
  38. package/src/arrow/impl-arrowjs/build.ts +1 -1
  39. package/src/arrow/impl-arrowjs/canonical.ts +23 -23
  40. package/src/arrow/impl-arrowjs/empty.ts +2 -2
  41. package/src/arrow/impl-arrowjs/ipc.ts +2 -2
  42. package/src/arrow/impl-arrowjs/iterate.ts +2 -2
  43. package/src/arrow/impl-arrowjs/project.ts +2 -2
  44. package/src/arrow/impl-flechette/build.ts +2 -1
  45. package/src/arrow/impl-flechette/canonical.ts +10 -9
  46. package/src/arrow/impl-flechette/compat.ts +3 -3
  47. package/src/arrow/impl-flechette/message-meta.ts +5 -4
  48. package/src/arrow/impl-flechette/statistics.ts +2 -2
  49. package/src/attach-ticket.ts +2 -2
  50. package/src/catalog/column-metadata.ts +1 -1
  51. package/src/catalog/composite.ts +2 -2
  52. package/src/catalog/constraints.ts +9 -9
  53. package/src/catalog/descriptors.ts +1 -1
  54. package/src/catalog/interface.ts +12 -12
  55. package/src/catalog/publication.ts +9 -8
  56. package/src/catalog/read-only.ts +9 -8
  57. package/src/catalog/sql-grammar.ts +6 -6
  58. package/src/client/client.ts +52 -15
  59. package/src/client/errors.ts +1 -1
  60. package/src/client/types.ts +23 -0
  61. package/src/client-entry.ts +2 -0
  62. package/src/codec/asd.ts +3 -3
  63. package/src/codec/conform.ts +3 -3
  64. package/src/filter-pushdown/collector.ts +1 -1
  65. package/src/filter-pushdown/deserialize.ts +13 -10
  66. package/src/filter-pushdown/evaluate.ts +3 -2
  67. package/src/filter-pushdown/history.ts +3 -2
  68. package/src/filter-pushdown/types.ts +10 -10
  69. package/src/functions/continuation.ts +1 -1
  70. package/src/functions/projection.ts +1 -1
  71. package/src/functions/registry.ts +14 -14
  72. package/src/functions/scalar.ts +3 -3
  73. package/src/functions/storage-cf-do.ts +2 -2
  74. package/src/functions/table-buffering.ts +25 -21
  75. package/src/functions/table-in-out.ts +8 -8
  76. package/src/functions/table.ts +27 -25
  77. package/src/functions/types.ts +47 -47
  78. package/src/generated/vgi-service.ts +5 -3
  79. package/src/http/fetch.ts +17 -12
  80. package/src/index.core.ts +2 -0
  81. package/src/protocol/carried-init-request.ts +1 -1
  82. package/src/protocol/dispatch.ts +3 -3
  83. package/src/protocol/handlers/aggregate.ts +8 -7
  84. package/src/protocol/handlers/catalog/shared.ts +1 -1
  85. package/src/protocol/handlers/function.ts +2 -2
  86. package/src/protocol/serializers/cardinality.ts +16 -3
  87. package/src/protocol/state-serializer.ts +1 -1
  88. package/src/protocol/types.ts +5 -5
  89. package/src/rpc-server.ts +13 -12
  90. package/src/serve-entry.ts +18 -18
  91. package/src/split-token.ts +10 -9
  92. package/src/types.ts +9 -2
  93. package/src/util/defined.ts +30 -0
  94. package/src/util/parent-rows.ts +2 -2
  95. package/src/worker.ts +15 -14
@@ -338,15 +338,15 @@ export function singleBranchResult(
338
338
  function encodeScanBranch(cols: {
339
339
  function_name: string;
340
340
  arguments: Uint8Array;
341
- branch_filter?: string | null;
342
- writable?: boolean;
343
- source_catalog?: string | null;
344
- source_schema_path?: string[] | null;
345
- source_table?: string | null;
346
- format_name?: string | null;
347
- format_locations?: string[] | null;
348
- format_options?: Uint8Array | null;
349
- schema_path?: string[] | null;
341
+ branch_filter?: string | null | undefined;
342
+ writable?: boolean | undefined;
343
+ source_catalog?: string | null | undefined;
344
+ source_schema_path?: string[] | null | undefined;
345
+ source_table?: string | null | undefined;
346
+ format_name?: string | null | undefined;
347
+ format_locations?: string[] | null | undefined;
348
+ format_options?: Uint8Array | null | undefined;
349
+ schema_path?: string[] | null | undefined;
350
350
  }): Uint8Array {
351
351
  return serializeBatch(
352
352
  batchFromColumns(
@@ -613,7 +613,7 @@ export abstract class CatalogInterface {
613
613
  */
614
614
  catalogNameForAttach(_attachOpaqueData: Uint8Array): string | null {
615
615
  const names = this.catalogs();
616
- return names.length === 1 ? names[0] : null;
616
+ return names.length === 1 ? names[0]! : null;
617
617
  }
618
618
 
619
619
  // Required overrides
@@ -794,8 +794,8 @@ export abstract class CatalogInterface {
794
794
  const change = decodeConstraintChange(bytes);
795
795
  if (change.operation === "ADD" && change.definition != null) {
796
796
  const def = decodeConstraintDefinition(change.definition);
797
- if (def.kind === "NOT_NULL" && def.column_paths.length === 1 && def.column_paths[0].length === 1) {
798
- await this.tableNotNullSet(attach, schemaPath, target.name, [...def.column_paths[0]], false, tx);
797
+ if (def.kind === "NOT_NULL" && def.column_paths.length === 1 && def.column_paths[0]!.length === 1) {
798
+ await this.tableNotNullSet(attach, schemaPath, target.name, [...def.column_paths[0]!], false, tx);
799
799
  continue;
800
800
  }
801
801
  } else if (change.operation === "DROP" && change.ref != null) {
@@ -21,7 +21,7 @@ export interface SnapshotIdentity {
21
21
  export interface SnapshotRequest {
22
22
  catalog: CatalogInterface;
23
23
  attachOpaqueData: AttachOpaqueData;
24
- callContext?: CallContext;
24
+ callContext?: CallContext | undefined;
25
25
  catalogVersion: number;
26
26
  }
27
27
  export interface CatalogPublicationManifest {
@@ -39,9 +39,9 @@ export interface CatalogPublicationManifest {
39
39
  rawSize: number;
40
40
  storedSize: number;
41
41
  url: string;
42
- objectId?: string;
43
- expiresAt?: number;
44
- retainUntil?: number;
42
+ objectId?: string | undefined;
43
+ expiresAt?: number | undefined;
44
+ retainUntil?: number | undefined;
45
45
  stable: boolean;
46
46
  validated: true;
47
47
  }
@@ -199,13 +199,14 @@ export class CatalogSnapshotManager {
199
199
  validateCatalogPublicationEnvelope(bytes);
200
200
  },
201
201
  });
202
- if (resolved.numRows !== 1 || resolved.schema.fields.length !== 1 || resolved.schema.fields[0].name !== "result"
203
- || typeSignature(resolved.schema.fields[0].type) !== typeSignature(binary()) || resolved.schema.fields[0].nullable) throw new Error("invalid published RPC envelope");
202
+ const resultField = resolved.schema.fields.length === 1 ? resolved.schema.fields[0] : undefined;
203
+ if (resolved.numRows !== 1 || !resultField || resultField.name !== "result"
204
+ || typeSignature(resultField.type) !== typeSignature(binary()) || resultField.nullable) throw new Error("invalid published RPC envelope");
204
205
  const bytes = resolved.getChild("result")?.get(0);
205
206
  if (!(bytes instanceof Uint8Array)) throw new Error("published catalog has no result bytes");
206
207
  const decoded = decodeASDCollection<CatalogContentsResponse>(CatalogContentsResultSchema, bytes);
207
- if (decoded.length !== 1) throw new Error("published catalog must contain exactly one response row");
208
- const response = decoded[0];
208
+ const response = decoded.length === 1 ? decoded[0] : undefined;
209
+ if (!response) throw new Error("published catalog must contain exactly one response row");
209
210
  if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion || response.etag !== m.etag) throw new Error("published catalog version or ETag mismatch");
210
211
  decodeCatalogStreams(response);
211
212
  if (expected) for (const kind of CATALOG_STREAM_KINDS) {
@@ -450,10 +450,11 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
450
450
  const part = path[i];
451
451
  if (typeof part !== "string" || !part || part.includes("\0")) throw new Error("invalid requiredFilters component");
452
452
  const matches = fields.filter((f) => f.name === part);
453
- if (matches.length !== 1) throw new Error(`unknown or ambiguous requiredFilters component: ${part}`);
453
+ const match = matches.length === 1 ? matches[0] : undefined;
454
+ if (!match) throw new Error(`unknown or ambiguous requiredFilters component: ${part}`);
454
455
  if (i + 1 < path.length) {
455
- if (!isStruct(matches[0].type)) throw new Error(`non-struct requiredFilters parent: ${part}`);
456
- fields = (matches[0].type as VgiDataType & { children: readonly VgiField[] }).children;
456
+ if (!isStruct(match.type)) throw new Error(`non-struct requiredFilters parent: ${part}`);
457
+ fields = (match.type as VgiDataType & { children: readonly VgiField[] }).children;
457
458
  }
458
459
  }
459
460
  }
@@ -610,13 +611,13 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
610
611
  }
611
612
  let argumentIndex = 0;
612
613
  for (const defaultField of defaults.schema.fields) {
613
- while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
614
+ while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex]!.name !== defaultField.name) {
614
615
  argumentIndex++;
615
616
  }
616
617
  if (argumentIndex === argSchema.fields.length) {
617
618
  throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
618
619
  }
619
- const argumentField = argSchema.fields[argumentIndex];
620
+ const argumentField = argSchema.fields[argumentIndex]!;
620
621
  if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
621
622
  throw new Error(
622
623
  `parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` +
@@ -1054,7 +1055,7 @@ function applyDefaults(schema: VgiSchema, defaults: Record<string, DefaultValue>
1054
1055
  for (const [colName, value] of Object.entries(defaults)) {
1055
1056
  const idx = result.fields.findIndex((f) => f.name === colName);
1056
1057
  if (idx < 0) continue;
1057
- const f = result.fields[idx];
1058
+ const f = result.fields[idx]!;
1058
1059
  const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
1059
1060
  const sql = defaultToSql(value);
1060
1061
  // Canonical where it is exact (see canonicalDefault); the legacy "default"
@@ -1077,7 +1078,7 @@ function applyGeneratedColumns(schema: VgiSchema, generated: Record<string, stri
1077
1078
  for (const [colName, expression] of Object.entries(generated)) {
1078
1079
  const idx = result.fields.findIndex((f) => f.name === colName);
1079
1080
  if (idx < 0) throw new Error(`Table '${table}': generatedColumns names unknown column ${colName}`);
1080
- const f = result.fields[idx];
1081
+ const f = result.fields[idx]!;
1081
1082
  const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
1082
1083
  if (existingMeta.has(GENERATED_EXPRESSION_KEY) || existingMeta.has("generated_expression"))
1083
1084
  throw new Error(`Table '${table}': generatedColumns for ${colName} conflicts with existing expression metadata`);
@@ -1100,7 +1101,7 @@ function applyColumnComments(schema: VgiSchema, comments: Record<string, string>
1100
1101
  for (const [colName, comment] of Object.entries(comments)) {
1101
1102
  const idx = result.fields.findIndex((f) => f.name === colName);
1102
1103
  if (idx < 0) throw new Error(`Table '${table}': columnComments names unknown column ${colName}`);
1103
- const f = result.fields[idx];
1104
+ const f = result.fields[idx]!;
1104
1105
  const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
1105
1106
  existingMeta.set("comment", comment);
1106
1107
  const newField = field(f.name, f.type, f.nullable, existingMeta);
@@ -45,7 +45,7 @@ function tokenize(sql: string): Token[] {
45
45
  const out: Token[] = [];
46
46
  let i = 0;
47
47
  while (i < sql.length) {
48
- const c = sql[i];
48
+ const c = sql[i]!;
49
49
  if (/\s/.test(c)) { i++; continue; }
50
50
  if (sql.startsWith("--", i)) {
51
51
  while (i < sql.length && sql[i] !== "\n") i++;
@@ -126,8 +126,8 @@ class Parser {
126
126
  private pos = 0;
127
127
  constructor(private readonly tokens: Token[]) {}
128
128
 
129
- private peek(offset = 0): Token { return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)]; }
130
- private next(): Token { return this.tokens[this.pos++]; }
129
+ private peek(offset = 0): Token { return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)]!; }
130
+ private next(): Token { return this.tokens[this.pos++]!; }
131
131
  private isOp(v: string, offset = 0): boolean {
132
132
  const t = this.peek(offset);
133
133
  return t.t === "op" && t.v === v;
@@ -375,7 +375,7 @@ class Parser {
375
375
  this.expectOp(")");
376
376
  if (this.isWord("filter") || this.isWord("over")) fail("aggregate and window functions are unsupported");
377
377
  if (names.length === 1 && !t.quoted && word === "coalesce") return { kind: "operator", op: "COALESCE", children };
378
- return { kind: "function", name: names[names.length - 1], qualified: names.length > 1, children };
378
+ return { kind: "function", name: names[names.length - 1]!, qualified: names.length > 1, children };
379
379
  }
380
380
  if (this.peek().t === "str") fail("typed literals are unsupported");
381
381
  return { kind: "column", names };
@@ -417,7 +417,7 @@ export function validateColumnExpressionSql(
417
417
  return;
418
418
  case "column":
419
419
  if (!usingColumns || node.names.length !== 1) fail("column references are unsupported in this scope");
420
- columns.push(node.names[0]);
420
+ columns.push(node.names[0]!);
421
421
  return;
422
422
  case "cast":
423
423
  if (node.qualified) fail("qualified scalar cast types are unsupported");
@@ -471,6 +471,6 @@ export function validateNumericCheckSql(sql: string, resolveColumn: (name: strin
471
471
  if (operand.kind !== "column") fail("native CHECK read supports only numeric column/constant comparisons");
472
472
  const column = operand as Extract<ScalarNode, { kind: "column" }>;
473
473
  if (column.names.length !== 1) fail("CHECK requires unqualified column references");
474
- resolveColumn(column.names[0]);
474
+ resolveColumn(column.names[0]!);
475
475
  }
476
476
  }
@@ -2,7 +2,7 @@
2
2
  // VgiClient — high-level client for calling VGI worker functions and catalog API.
3
3
  // Works with any RpcClient (subprocess or HTTP transport).
4
4
 
5
- import { type VgiSchema, schema as schema_, type VgiField, field, type VgiBatch, type VgiDataType, utf8, binary, list } from "../arrow/index.js";
5
+ import { type VgiSchema, schema as schema_, type VgiField, field, type VgiBatch, type VgiDataType, utf8, binary, list, isInt } from "../arrow/index.js";
6
6
  // `import type`, not `import { type … }`: the latter keeps the statement and
7
7
  // emits `import {} from "@query-farm/vgi-rpc"`, a side-effect import of the
8
8
  // package root — which re-exports the whole framework, server included, into
@@ -66,9 +66,37 @@ import { decodeCatalogContentsResponse } from "../generated/vgi-protocol-types.j
66
66
  import { deserializeInfoList, deserializeTags, toAsyncIterator } from "./helpers.js";
67
67
 
68
68
  export { VgiClientError };
69
+
70
+ /** Names of the top-level 64-bit integer (int64/uint64) fields of `s`. */
71
+ function int64ColumnNames(s: VgiSchema | null | undefined): string[] {
72
+ if (!s) return [];
73
+ return s.fields
74
+ .filter((f) => isInt(f.type) && (f.type as { bitWidth?: number }).bitWidth === 64)
75
+ .map((f) => f.name);
76
+ }
77
+
78
+ const MIN_SAFE_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
79
+ const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
80
+
81
+ /** Normalise the int64 columns of `rows` in place to `mode`. Lossless: the
82
+ * RPC layer only ever narrows a bigint to number when it is a safe integer. */
83
+ function applyInt64Mode(rows: Record<string, any>[], columns: string[], mode: Int64Mode): void {
84
+ for (const row of rows) {
85
+ for (const name of columns) {
86
+ const v = row[name];
87
+ if (mode === "bigint") {
88
+ if (typeof v === "number" && Number.isInteger(v)) row[name] = BigInt(v);
89
+ } else if (typeof v === "bigint" && v >= MIN_SAFE_BIGINT && v <= MAX_SAFE_BIGINT) {
90
+ row[name] = Number(v);
91
+ }
92
+ }
93
+ }
94
+ }
69
95
  import type {
70
96
  VgiClientOptions,
71
97
  TableFunctionOptions,
98
+ TableFunctionRowsOptions,
99
+ Int64Mode,
72
100
  ScalarFunctionOptions,
73
101
  TableInOutFunctionOptions,
74
102
  OnCreateConflict,
@@ -262,13 +290,13 @@ export class VgiClient {
262
290
  bindRequest: BindRequest,
263
291
  bindResponse: BindResponse,
264
292
  opts?: {
265
- projectionIds?: number[] | null;
266
- pushdownFilters?: VgiBatch | null;
267
- phase?: TableInOutPhase | null;
268
- executionId?: Uint8Array | null;
269
- orderBy?: OrderByPushdown | null;
270
- tablesample?: TablesamplePushdown | null;
271
- joinKeys?: VgiBatch[] | null;
293
+ projectionIds?: number[] | null | undefined;
294
+ pushdownFilters?: VgiBatch | null | undefined;
295
+ phase?: TableInOutPhase | null | undefined;
296
+ executionId?: Uint8Array | null | undefined;
297
+ orderBy?: OrderByPushdown | null | undefined;
298
+ tablesample?: TablesamplePushdown | null | undefined;
299
+ joinKeys?: VgiBatch[] | null | undefined;
272
300
  },
273
301
  ): Promise<{ session: StreamSession; initResponse: GlobalInitResponse }> {
274
302
  const ob = opts?.orderBy ?? null;
@@ -617,9 +645,15 @@ export class VgiClient {
617
645
  // Row convenience for table function
618
646
  // ==========================================================================
619
647
 
620
- /** Call a table function, yielding output as row objects. */
648
+ /**
649
+ * Call a table function, yielding output as row objects.
650
+ *
651
+ * int64/uint64 columns follow `opts.int64` (see {@link Int64Mode}); pass
652
+ * `int64: "bigint"` to get a `bigint` for every value instead of a
653
+ * magnitude-dependent mix of `number` and `bigint`.
654
+ */
621
655
  async *tableFunctionRows(
622
- opts: TableFunctionOptions,
656
+ opts: TableFunctionRowsOptions,
623
657
  ): AsyncGenerator<Record<string, any>[]> {
624
658
  const args = opts.arguments ?? new Arguments();
625
659
  const { request: bindReq, response: bindResp } = await this._doBind(
@@ -640,9 +674,12 @@ export class VgiClient {
640
674
  tablesample: opts.tablesample,
641
675
  joinKeys: opts.joinKeys,
642
676
  });
677
+ const int64Columns = opts.int64 === undefined ? [] : int64ColumnNames(bindResp.output_schema);
643
678
  try {
644
679
  for await (const rows of session) {
645
- if (rows.length > 0) yield rows;
680
+ if (rows.length === 0) continue;
681
+ if (int64Columns.length > 0) applyInt64Mode(rows, int64Columns, opts.int64!);
682
+ yield rows;
646
683
  }
647
684
  } finally {
648
685
  session.close();
@@ -1056,7 +1093,7 @@ export class VgiClient {
1056
1093
  if (!result) return null;
1057
1094
  const inner = unwrapResult(result);
1058
1095
  const items = deserializeInfoList(inner.items, decodeSchemaInfo);
1059
- return items.length > 0 ? items[0] : null;
1096
+ return items[0] ?? null;
1060
1097
  }
1061
1098
 
1062
1099
  /** Create a new schema. */
@@ -1182,7 +1219,7 @@ export class VgiClient {
1182
1219
  if (!result) return null;
1183
1220
  const inner = unwrapResult(result);
1184
1221
  const items = deserializeInfoList(inner.items, decodeTableInfo);
1185
- return items.length > 0 ? items[0] : null;
1222
+ return items[0] ?? null;
1186
1223
  }
1187
1224
 
1188
1225
  /** Create a new table. */
@@ -1502,7 +1539,7 @@ export class VgiClient {
1502
1539
  if (!result) return null;
1503
1540
  const inner = unwrapResult(result);
1504
1541
  const items = deserializeInfoList(inner.items, decodeViewInfo);
1505
- return items.length > 0 ? items[0] : null;
1542
+ return items[0] ?? null;
1506
1543
  }
1507
1544
 
1508
1545
  /** Create a new view. */
@@ -1623,7 +1660,7 @@ export class VgiClient {
1623
1660
  if (!result) return null;
1624
1661
  const inner = unwrapResult(result);
1625
1662
  const items = deserializeInfoList(inner.items, decodeMacroInfo);
1626
- return items.length > 0 ? items[0] : null;
1663
+ return items[0] ?? null;
1627
1664
  }
1628
1665
 
1629
1666
  /** List macros in a schema, filtered by type. */
@@ -22,7 +22,7 @@ export class VgiClientError extends Error {
22
22
 
23
23
  constructor(
24
24
  message: string,
25
- options?: { remoteTraceback?: string; errorType?: string; cause?: unknown },
25
+ options?: { remoteTraceback?: string | undefined; errorType?: string | undefined; cause?: unknown },
26
26
  ) {
27
27
  super(message, options?.cause != null ? { cause: options.cause } : undefined);
28
28
  this.name = "VgiClientError";
@@ -98,6 +98,29 @@ export interface TableFunctionOptions {
98
98
  onBind?: BindResultCallback;
99
99
  }
100
100
 
101
+ /**
102
+ * How {@link VgiClient.tableFunctionRows} surfaces int64/uint64 column
103
+ * values. Same vocabulary as `@query-farm/vgi-rpc`'s client `int64` option.
104
+ *
105
+ * - `"number-if-safe"`: values within `Number.MAX_SAFE_INTEGER` become
106
+ * `number`, larger ones stay `bigint` (one column can hold both).
107
+ * - `"bigint"`: every value stays a `bigint` — one JS type per column.
108
+ */
109
+ export type Int64Mode = "number-if-safe" | "bigint";
110
+
111
+ /** Options for {@link VgiClient.tableFunctionRows}. */
112
+ export interface TableFunctionRowsOptions extends TableFunctionOptions {
113
+ /**
114
+ * Surfacing of top-level int64/uint64 output columns (see {@link Int64Mode}).
115
+ * When omitted, rows are returned as the underlying `RpcClient` produced
116
+ * them — `"number-if-safe"` unless that client was created with
117
+ * `int64: "bigint"` (`@query-farm/vgi-rpc` >= 0.29.6). Setting it here
118
+ * overrides the client either way. The omitted-default may become
119
+ * `"bigint"` in a future minor release; pass it explicitly to pin it.
120
+ */
121
+ int64?: Int64Mode;
122
+ }
123
+
101
124
  /** Options for calling a scalar function. */
102
125
  export interface ScalarFunctionOptions {
103
126
  /** Name of the function to call. */
@@ -18,6 +18,8 @@ export { VgiClient, VgiClientError } from "./client/client.js";
18
18
  export type {
19
19
  VgiClientOptions,
20
20
  TableFunctionOptions,
21
+ TableFunctionRowsOptions,
22
+ Int64Mode,
21
23
  ScalarFunctionOptions,
22
24
  TableInOutFunctionOptions,
23
25
  OnCreateConflict,
package/src/codec/asd.ts CHANGED
@@ -111,7 +111,7 @@ function sortMapsForType(type: VgiDataType, value: any): any {
111
111
  if (value == null || !typeHasMap(type)) return value;
112
112
  if (isMap(type)) {
113
113
  const entries = (type as any).children[0].type as VgiDataType;
114
- const valueType = ((entries as any).children as VgiField[])[1].type;
114
+ const valueType = ((entries as any).children as VgiField[])[1]!.type;
115
115
  return mapPairs(value)
116
116
  .map(([k, v]): [unknown, unknown] => [k, sortMapsForType(valueType, v)])
117
117
  .sort((x, y) => compareKeys(x[0], y[0]));
@@ -186,7 +186,7 @@ function normalizeValue(raw: any, type: VgiDataType): any {
186
186
  // and struct children: a map<utf8, int64> yields numbers (bigint beyond
187
187
  // the safe range), not strings, and a null value stays null.
188
188
  const entries = (type as any).children[0].type as VgiDataType;
189
- const valueType = ((entries as any).children as VgiField[])[1].type;
189
+ const valueType = ((entries as any).children as VgiField[])[1]!.type;
190
190
  const out: Record<string, any> = {};
191
191
  const put = (k: unknown, v: unknown): void => {
192
192
  Object.defineProperty(out, String(k), {
@@ -267,7 +267,7 @@ export function decodeASDCollection<T>(schema: VgiSchema, bytes: Uint8Array | nu
267
267
  const batches = deserializeBatches(bytes);
268
268
  const validateSchema = (actualSchema: VgiSchema) => {
269
269
  if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
270
- const actual = actualSchema.fields[i];
270
+ const actual = actualSchema.fields[i]!;
271
271
  return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
272
272
  })) throw new Error("catalog collection has an incompatible metadata schema");
273
273
  };
@@ -61,8 +61,8 @@ function children(type: VgiDataType): VgiField[] {
61
61
  }
62
62
 
63
63
  function mapValueType(type: VgiDataType): VgiDataType {
64
- const entries = children(type)[0].type;
65
- return children(entries)[1].type;
64
+ const entries = children(type)[0]!.type;
65
+ return children(entries)[1]!.type;
66
66
  }
67
67
 
68
68
  function mapPairs(raw: any): Array<[unknown, unknown]> {
@@ -114,7 +114,7 @@ function conformValue(type: VgiDataType, value: any, nullable: boolean, name: st
114
114
  if (!hasContainer(type)) return value;
115
115
 
116
116
  if (isList(type)) {
117
- const itemType = children(type)[0].type;
117
+ const itemType = children(type)[0]!.type;
118
118
  const itemsNullable = OPTIONAL_ITEM_FIELDS.has(name);
119
119
  const items = Array.isArray(value) ? value : Array.from(value as Iterable<unknown>);
120
120
  let changed = !Array.isArray(value);
@@ -117,7 +117,7 @@ export class FilteringOutputCollector {
117
117
  const mask = this.filters.evaluate(batch as any);
118
118
  const parents = decodeParentRows(encoded);
119
119
  const kept: number[] = [];
120
- for (let i = 0; i < parents.length; i++) if (mask[i]) kept.push(parents[i]);
120
+ for (let i = 0; i < parents.length; i++) if (mask[i]) kept.push(parents[i]!);
121
121
  const md = new Map(metadata);
122
122
  if (kept.length > 0) md.set(PARENT_ROW_METADATA_KEY, encodeParentRows(kept));
123
123
  else md.delete(PARENT_ROW_METADATA_KEY);
@@ -71,7 +71,7 @@ export class FilterV2Error extends Error {
71
71
  export interface DeserializeFilterOptions extends FilterCapabilities {
72
72
  /** The authoritative, unprojected bind output schema. */
73
73
  outputSchema: VgiSchema;
74
- joinKeyBatches?: VgiBatch[];
74
+ joinKeyBatches?: VgiBatch[] | undefined;
75
75
  }
76
76
 
77
77
  function utf8Length(value: string): number {
@@ -180,7 +180,7 @@ class StrictJsonParser {
180
180
  const start = this.offset++;
181
181
  let escaped = false;
182
182
  while (this.offset < this.text.length) {
183
- const ch = this.text[this.offset++];
183
+ const ch = this.text[this.offset++]!;
184
184
  if (!escaped && ch === '"') {
185
185
  try {
186
186
  return JSON.parse(this.text.slice(start, this.offset));
@@ -303,9 +303,10 @@ class FilterParser {
303
303
  const names = batch.schema.fields.map((field) => field.name);
304
304
  if (new Set(names).size !== names.length) throw new FilterV2Error("filter payload names must be unique");
305
305
  for (let i = 1; i < names.length; i++) {
306
- if (!PAYLOAD_NAME.test(names[i])) throw new FilterV2Error(`noncanonical payload name ${names[i]}`);
307
- if (names[i].startsWith("type_") && this.valueAt(i) !== null) {
308
- throw new FilterV2Error(`${names[i]} must contain NULL`);
306
+ const name = names[i]!;
307
+ if (!PAYLOAD_NAME.test(name)) throw new FilterV2Error(`noncanonical payload name ${name}`);
308
+ if (name.startsWith("type_") && this.valueAt(i) !== null) {
309
+ throw new FilterV2Error(`${name} must contain NULL`);
309
310
  }
310
311
  }
311
312
  this.context = parseContext(batch.schema);
@@ -319,8 +320,9 @@ class FilterParser {
319
320
 
320
321
  private valueAt(index: number): unknown {
321
322
  const column = this.batch.getChildAt(index);
322
- if (!column) throw new FilterV2Error(`missing payload column ${index}`);
323
- return readCanonicalValue(this.batch.schema.fields[index].type, column, 0);
323
+ const field = this.batch.schema.fields[index];
324
+ if (!column || !field) throw new FilterV2Error(`missing payload column ${index}`);
325
+ return readCanonicalValue(field.type, column, 0);
324
326
  }
325
327
 
326
328
  private validateContextCapability(): void {
@@ -363,7 +365,7 @@ class FilterParser {
363
365
  const entries = this.header("delta", "updates");
364
366
  const live = new Map(prior.predicates.map((predicate) => [predicate.id, predicate]));
365
367
  const revisions = new Map(prior.revisions);
366
- const parsed: Array<{ id: string; revision: number; predicate?: FilterPredicate }> = [];
368
+ const parsed: Array<{ id: string; revision: number; predicate?: FilterPredicate | undefined }> = [];
367
369
  const seen = new Set<string>();
368
370
  for (let index = 0; index < entries.length; index++) {
369
371
  const where = `updates[${index}]`;
@@ -436,8 +438,9 @@ class FilterParser {
436
438
  const ref = expectUint(rawRef, `${prefix}_ref`);
437
439
  const name = `${prefix}_${ref}`;
438
440
  const indexes = this.batch.schema.fields.flatMap((field, index) => field.name === name ? [index] : []);
439
- if (indexes.length !== 1) throw new FilterV2Error(`missing or duplicate payload ${name}`);
440
- return { ref, field: this.batch.schema.fields[indexes[0]], value: this.valueAt(indexes[0]) };
441
+ const index = indexes.length === 1 ? indexes[0] : undefined;
442
+ if (index === undefined) throw new FilterV2Error(`missing or duplicate payload ${name}`);
443
+ return { ref, field: this.batch.schema.fields[index]!, value: this.valueAt(index) };
441
444
  }
442
445
 
443
446
  private identity(raw: unknown, where: string): FunctionIdentity {
@@ -45,7 +45,8 @@ function resolveColumn(batch: VgiBatch, columnName: string): { type: VgiDataType
45
45
  throw new FilterV2Error(`filter column ${columnName} is unavailable in emitted batch`);
46
46
  }
47
47
  const column = batch.getChildAt(index);
48
- resolved = column ? { type: batch.schema.fields[index].type, column } : null;
48
+ const field = batch.schema.fields[index];
49
+ resolved = column && field ? { type: field.type, column } : null;
49
50
  byName.set(columnName, resolved);
50
51
  }
51
52
  return resolved;
@@ -510,7 +511,7 @@ export class PushdownFilters {
510
511
  if (predicate.mode === "advisory") continue;
511
512
  throw error;
512
513
  }
513
- for (let row = 0; row < batch.numRows; row++) mask[row] &= values[row] === true ? 1 : 0;
514
+ for (let row = 0; row < batch.numRows; row++) mask[row]! &= values[row] === true ? 1 : 0;
514
515
  }
515
516
  return mask;
516
517
  }
@@ -98,8 +98,9 @@ export function decodeFilterDelta(bytes: Uint8Array): VgiBatch {
98
98
  */
99
99
  function deltaRevisionKeys(batch: VgiBatch): string[] {
100
100
  const column = batch.getChildAt(0);
101
- if (!column) throw new FilterV2Error("delta document has no filter_spec column");
102
- const raw = readCanonicalValue(batch.schema.fields[0].type, column, 0);
101
+ const field = batch.schema.fields[0];
102
+ if (!column || !field) throw new FilterV2Error("delta document has no filter_spec column");
103
+ const raw = readCanonicalValue(field.type, column, 0);
103
104
  const document = JSON.parse(String(raw)) as { updates?: Array<{ id: string; revision: number }> };
104
105
  return (document.updates ?? []).map((update) => revisionKey(update.id, update.revision));
105
106
  }
@@ -32,12 +32,12 @@ export interface FunctionIdentity {
32
32
 
33
33
  export interface EvaluationContext {
34
34
  profile: string;
35
- timeZone?: string;
36
- calendar?: string;
37
- defaultCollation?: string;
38
- ieeeFloatingPointOps?: boolean;
39
- integerDivision?: boolean;
40
- providerFingerprint?: string;
35
+ timeZone?: string | undefined;
36
+ calendar?: string | undefined;
37
+ defaultCollation?: string | undefined;
38
+ ieeeFloatingPointOps?: boolean | undefined;
39
+ integerDivision?: boolean | undefined;
40
+ providerFingerprint?: string | undefined;
41
41
  }
42
42
 
43
43
  export type FilterExpression =
@@ -56,7 +56,7 @@ export type FilterExpression =
56
56
  node: "call";
57
57
  function: StandardFilterFunction | FunctionIdentity;
58
58
  arguments: FilterExpression[];
59
- options?: Record<string, unknown>;
59
+ options?: Record<string, unknown> | undefined;
60
60
  }
61
61
  | {
62
62
  node: "runtime_filter";
@@ -89,9 +89,9 @@ export interface FilterPredicate {
89
89
  }
90
90
 
91
91
  export interface FilterCapabilities {
92
- extensionFunctions?: ReadonlyArray<FunctionIdentity>;
93
- runtimeAlgorithms?: ReadonlyArray<FunctionIdentity>;
94
- evaluationContexts?: ReadonlyArray<{ profile: string; providerFingerprint?: string | null }>;
92
+ extensionFunctions?: ReadonlyArray<FunctionIdentity> | undefined;
93
+ runtimeAlgorithms?: ReadonlyArray<FunctionIdentity> | undefined;
94
+ evaluationContexts?: ReadonlyArray<{ profile: string; providerFingerprint?: string | null }> | undefined;
95
95
  }
96
96
 
97
97
  // Source aliases ease the protocol-2.0 transition for applications that imported
@@ -56,7 +56,7 @@ export function moreOutputMetadata(more: boolean, extra?: Map<string, string>):
56
56
  function replyMetadata(out: OutputCollector): Map<string, string> | null {
57
57
  const idx = out.dataBatchIdx;
58
58
  if (idx == null) return null;
59
- const emitted = out.batches[idx];
59
+ const emitted = out.batches[idx]!;
60
60
  const md = new Map<string, string>((emitted.batch as any).metadata ?? []);
61
61
  for (const [k, v] of emitted.metadata ?? []) md.set(k, v);
62
62
  return md;
@@ -196,7 +196,7 @@ export function validateProjectionAcceptance(
196
196
  const expected = schema(
197
197
  [
198
198
  ...p.bindResult.output_schema.fields,
199
- ...r.acceptedIndices.map((i) => p.resultSchema.fields[i]),
199
+ ...r.acceptedIndices.map((i) => p.resultSchema.fields[i]!),
200
200
  ],
201
201
  p.bindResult.output_schema.metadata,
202
202
  );