@query-farm/vgi 0.47.2 → 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 (105) hide show
  1. package/README.md +1 -1
  2. package/dist/arguments/argument-spec.d.ts +17 -11
  3. package/dist/catalog/descriptors.d.ts +2 -2
  4. package/dist/catalog/publication.d.ts +7 -7
  5. package/dist/client/client.d.ts +9 -3
  6. package/dist/client/errors.d.ts +2 -2
  7. package/dist/client/types.d.ts +21 -0
  8. package/dist/client-entry.d.ts +1 -1
  9. package/dist/client-entry.js +56 -7
  10. package/dist/client-entry.js.map +23 -23
  11. package/dist/filter-pushdown/deserialize.d.ts +1 -1
  12. package/dist/filter-pushdown/types.d.ts +10 -10
  13. package/dist/functions/scalar.d.ts +1 -1
  14. package/dist/functions/table-buffering.d.ts +20 -20
  15. package/dist/functions/table-in-out.d.ts +4 -4
  16. package/dist/functions/table.d.ts +7 -7
  17. package/dist/functions/types.d.ts +47 -47
  18. package/dist/generated/vgi-client.d.ts +5 -0
  19. package/dist/generated/vgi-protocol-schemas.d.ts +5 -0
  20. package/dist/generated/vgi-protocol-types.d.ts +57 -0
  21. package/dist/generated/vgi-service.d.ts +1 -1
  22. package/dist/http/fetch.d.ts +10 -10
  23. package/dist/index.core.d.ts +3 -1
  24. package/dist/index.js +289 -103
  25. package/dist/index.js.map +57 -55
  26. package/dist/protocol/dispatch.d.ts +4 -4
  27. package/dist/protocol/handlers/function.d.ts +2 -2
  28. package/dist/protocol/serializers/cardinality.d.ts +4 -1
  29. package/dist/protocol/serializers/splits.d.ts +41 -1
  30. package/dist/protocol/types.d.ts +5 -5
  31. package/dist/rpc-server.d.ts +6 -6
  32. package/dist/serve-entry.d.ts +16 -16
  33. package/dist/serve-entry.js +119 -30
  34. package/dist/serve-entry.js.map +42 -40
  35. package/dist/split-token.d.ts +6 -6
  36. package/dist/types.d.ts +9 -2
  37. package/dist/util/defined.d.ts +21 -0
  38. package/dist/worker-cf-entry.js +199 -94
  39. package/dist/worker-cf-entry.js.map +55 -53
  40. package/dist/worker.d.ts +2 -2
  41. package/package.json +6 -4
  42. package/src/arguments/argument-spec.ts +17 -11
  43. package/src/arrow/codec/registry.ts +2 -2
  44. package/src/arrow/impl-arrowjs/build.ts +1 -1
  45. package/src/arrow/impl-arrowjs/canonical.ts +23 -23
  46. package/src/arrow/impl-arrowjs/empty.ts +2 -2
  47. package/src/arrow/impl-arrowjs/ipc.ts +2 -2
  48. package/src/arrow/impl-arrowjs/iterate.ts +2 -2
  49. package/src/arrow/impl-arrowjs/project.ts +2 -2
  50. package/src/arrow/impl-flechette/build.ts +2 -1
  51. package/src/arrow/impl-flechette/canonical.ts +10 -9
  52. package/src/arrow/impl-flechette/compat.ts +3 -3
  53. package/src/arrow/impl-flechette/message-meta.ts +5 -4
  54. package/src/arrow/impl-flechette/statistics.ts +2 -2
  55. package/src/attach-ticket.ts +2 -2
  56. package/src/catalog/column-metadata.ts +1 -1
  57. package/src/catalog/composite.ts +2 -2
  58. package/src/catalog/constraints.ts +9 -9
  59. package/src/catalog/descriptors.ts +1 -1
  60. package/src/catalog/interface.ts +12 -12
  61. package/src/catalog/publication.ts +9 -8
  62. package/src/catalog/read-only.ts +9 -8
  63. package/src/catalog/sql-grammar.ts +6 -6
  64. package/src/client/client.ts +52 -15
  65. package/src/client/errors.ts +1 -1
  66. package/src/client/types.ts +23 -0
  67. package/src/client-entry.ts +2 -0
  68. package/src/codec/asd.ts +3 -3
  69. package/src/codec/conform.ts +3 -3
  70. package/src/filter-pushdown/collector.ts +1 -1
  71. package/src/filter-pushdown/deserialize.ts +13 -10
  72. package/src/filter-pushdown/evaluate.ts +3 -2
  73. package/src/filter-pushdown/history.ts +3 -2
  74. package/src/filter-pushdown/types.ts +10 -10
  75. package/src/functions/continuation.ts +1 -1
  76. package/src/functions/projection.ts +1 -1
  77. package/src/functions/registry.ts +14 -14
  78. package/src/functions/scalar.ts +3 -3
  79. package/src/functions/storage-cf-do.ts +2 -2
  80. package/src/functions/table-buffering.ts +25 -21
  81. package/src/functions/table-in-out.ts +8 -8
  82. package/src/functions/table.ts +27 -25
  83. package/src/functions/types.ts +47 -47
  84. package/src/generated/vgi-client.ts +6 -1
  85. package/src/generated/vgi-protocol-schemas.ts +36 -1
  86. package/src/generated/vgi-protocol-types.ts +130 -1
  87. package/src/generated/vgi-service.ts +7 -5
  88. package/src/http/fetch.ts +17 -12
  89. package/src/index.core.ts +34 -0
  90. package/src/protocol/carried-init-request.ts +1 -1
  91. package/src/protocol/dispatch.ts +4 -4
  92. package/src/protocol/handlers/aggregate.ts +8 -7
  93. package/src/protocol/handlers/catalog/shared.ts +1 -1
  94. package/src/protocol/handlers/function.ts +2 -2
  95. package/src/protocol/serializers/cardinality.ts +16 -3
  96. package/src/protocol/serializers/splits.ts +82 -9
  97. package/src/protocol/state-serializer.ts +1 -1
  98. package/src/protocol/types.ts +5 -5
  99. package/src/rpc-server.ts +13 -12
  100. package/src/serve-entry.ts +18 -18
  101. package/src/split-token.ts +10 -9
  102. package/src/types.ts +9 -2
  103. package/src/util/defined.ts +30 -0
  104. package/src/util/parent-rows.ts +2 -2
  105. package/src/worker.ts +15 -14
@@ -73,11 +73,11 @@ function scoreTypes(
73
73
  let varArgsSpec: ArgumentSpec | null = null;
74
74
 
75
75
  for (let i = 0; i < specs.length; i++) {
76
- const spec = specs[i];
76
+ const spec = specs[i]!;
77
77
  if (spec.isVarargs) varArgsSpec = spec;
78
78
  if (i >= actualTypes.length) break;
79
79
  if (spec.isAnyType || isNull(spec.arrowType)) continue;
80
- const actual = actualTypes[i];
80
+ const actual = actualTypes[i]!;
81
81
  if (actual === null) continue;
82
82
  if (typesIdentical(actual, spec.arrowType)) {
83
83
  score += EXACT_MATCH_SCORE;
@@ -91,7 +91,7 @@ function scoreTypes(
91
91
  // Score varargs tail beyond declared specs
92
92
  if (varArgsSpec && !varArgsSpec.isAnyType && !isNull(varArgsSpec.arrowType)) {
93
93
  for (let i = specs.length; i < actualTypes.length; i++) {
94
- const actual = actualTypes[i];
94
+ const actual = actualTypes[i]!;
95
95
  if (actual === null) continue;
96
96
  if (typesIdentical(actual, varArgsSpec.arrowType)) {
97
97
  score += EXACT_MATCH_SCORE;
@@ -141,13 +141,13 @@ function filterByArgumentTypes(
141
141
  for (const spec of colSpecs) {
142
142
  if (spec.isVarargs) varArgsColSpec = spec;
143
143
  const pos = spec.position as number;
144
- colTypes.push(pos < inputSchema.fields.length ? inputSchema.fields[pos].type : null);
144
+ colTypes.push(pos < inputSchema.fields.length ? inputSchema.fields[pos]!.type : null);
145
145
  }
146
146
  // Append varargs tail from inputSchema
147
147
  if (varArgsColSpec) {
148
148
  const start = (varArgsColSpec.position as number) + 1;
149
149
  for (let i = start; i < inputSchema.fields.length; i++) {
150
- colTypes.push(inputSchema.fields[i].type);
150
+ colTypes.push(inputSchema.fields[i]!.type);
151
151
  }
152
152
  }
153
153
  const r2 = scoreTypes(colSpecs, colTypes);
@@ -175,11 +175,11 @@ function filterByArgumentTypes(
175
175
  for (const spec of posSpecs) {
176
176
  if (spec.isVarargs) varArgsSpec = spec;
177
177
  const pos = spec.position as number;
178
- posTypes.push(pos < inputSchema.fields.length ? inputSchema.fields[pos].type : null);
178
+ posTypes.push(pos < inputSchema.fields.length ? inputSchema.fields[pos]!.type : null);
179
179
  }
180
180
  if (varArgsSpec) {
181
181
  for (let i = (varArgsSpec.position as number) + 1; i < inputSchema.fields.length; i++) {
182
- posTypes.push(inputSchema.fields[i].type);
182
+ posTypes.push(inputSchema.fields[i]!.type);
183
183
  }
184
184
  }
185
185
  }
@@ -317,16 +317,16 @@ export class FunctionRegistry {
317
317
  ): VgiFunction {
318
318
  // Fast path: single candidate
319
319
  if (candidates.length === 1) {
320
- return candidates[0];
320
+ return candidates[0]!;
321
321
  }
322
322
 
323
323
  // No context: return first (backward compat)
324
324
  if (!context?.arguments) {
325
- return candidates[0];
325
+ return candidates[0]!;
326
326
  }
327
327
 
328
328
  const args = context.arguments;
329
- const isScalar = context.isScalar ?? (candidates[0].kind === "scalar");
329
+ const isScalar = context.isScalar ?? (candidates[0]!.kind === "scalar");
330
330
 
331
331
  // Stage 1: Count-based filtering
332
332
  let matches: VgiFunction[];
@@ -391,7 +391,7 @@ export class FunctionRegistry {
391
391
  }
392
392
 
393
393
  if (matches.length === 1) {
394
- return matches[0];
394
+ return matches[0]!;
395
395
  }
396
396
 
397
397
  // Stage 2: Type-based filtering
@@ -403,14 +403,14 @@ export class FunctionRegistry {
403
403
  );
404
404
 
405
405
  if (typeFiltered.length === 1) {
406
- return typeFiltered[0];
406
+ return typeFiltered[0]!;
407
407
  }
408
408
  if (typeFiltered.length > 1) {
409
- return typeFiltered[0]; // Best score wins
409
+ return typeFiltered[0]!; // Best score wins
410
410
  }
411
411
 
412
412
  // Fallback: return first candidate
413
- return candidates[0];
413
+ return candidates[0]!;
414
414
  }
415
415
 
416
416
  has(name: string): boolean {
@@ -94,7 +94,7 @@ export interface ScalarParameterDef {
94
94
  gt?: number;
95
95
  /** Exclusive upper bound, `<` (folded into `vgi_range`). */
96
96
  lt?: number;
97
- /** Regex the value must match (surfaced as `vgi_pattern`). */
97
+ /** Regex the value must match (surfaced as `vgi_pattern`); an unanchored search — anchor with `^...$` for a full match. */
98
98
  pattern?: string;
99
99
  /** Default value (surfaced as `vgi_default`, JSON-encoded). */
100
100
  default?: unknown;
@@ -427,13 +427,13 @@ export function defineScalarFunction<
427
427
  // so complex types (Decimal, BigInt-backed Timestamp/Duration,
428
428
  // List, Map, Struct) are built via our buildColumnData. The `repr`
429
429
  // selects raw<->canonical (branded) vs rich<->canonical conversion.
430
- const fieldName = outputSchema.fields[0].name;
430
+ const fieldName = outputSchema.fields[0]!.name;
431
431
  outputBatch = batchFromColumns({ [fieldName]: result }, outputSchema, repr);
432
432
  } else {
433
433
  // User returned an Arrow Vector / typed-array-shaped column. Iterate
434
434
  // it into a JS array and re-route through batchFromColumns. Adds an
435
435
  // O(n) copy but matches both backends' contract.
436
- const fieldName = outputSchema.fields[0].name;
436
+ const fieldName = outputSchema.fields[0]!.name;
437
437
  outputBatch = batchFromColumns({ [fieldName]: [...(result as Iterable<any>)] }, outputSchema, repr);
438
438
  }
439
439
 
@@ -273,7 +273,7 @@ function newAttemptId(): string {
273
273
  const b = new Uint8Array(16);
274
274
  crypto.getRandomValues(b);
275
275
  let s = "";
276
- for (let i = 0; i < 16; i++) s += b[i].toString(16).padStart(2, "0");
276
+ for (let i = 0; i < 16; i++) s += b[i]!.toString(16).padStart(2, "0");
277
277
  return s;
278
278
  }
279
279
 
@@ -286,7 +286,7 @@ function int64FromKey(b: Uint8Array): number {
286
286
 
287
287
  function bytesToB64(buf: Uint8Array): string {
288
288
  let binary = "";
289
- for (let i = 0; i < buf.length; i++) binary += String.fromCharCode(buf[i]);
289
+ for (let i = 0; i < buf.length; i++) binary += String.fromCharCode(buf[i]!);
290
290
  return btoa(binary);
291
291
  }
292
292
 
@@ -109,16 +109,16 @@ export interface TableBufferingConfig<
109
109
  TState = any,
110
110
  > {
111
111
  name: string;
112
- description?: string;
113
- args?: Record<string, VgiDataType>;
114
- namedArgs?: Record<string, VgiDataType>;
115
- argDefaults?: Record<string, any>;
112
+ description?: string | undefined;
113
+ args?: Record<string, VgiDataType> | undefined;
114
+ namedArgs?: Record<string, VgiDataType> | undefined;
115
+ argDefaults?: Record<string, any> | undefined;
116
116
  /** Authoritative typed defaults: one row, defaulted parameters only. */
117
- parameterDefaultValues?: VgiBatch | null;
117
+ parameterDefaultValues?: VgiBatch | null | undefined;
118
118
  /** Argument descriptions keyed by argument name. */
119
- argDocs?: Record<string, string>;
119
+ argDocs?: Record<string, string> | undefined;
120
120
  /** Discovery constraints, also enforced for scalar arguments at bind. */
121
- argConstraints?: Record<string, ArgumentConstraints>;
121
+ argConstraints?: Record<string, ArgumentConstraints> | undefined;
122
122
  /** Bind: default passes through input schema. May be async. Return non-empty
123
123
  * `lookupSecret*` lists on the first pass to request DuckDB secrets; the
124
124
  * connector then re-binds with `resolvedSecretsProvided` and the resolved
@@ -164,22 +164,22 @@ export interface TableBufferingConfig<
164
164
  params: TableBufferingBindParams<TArgs>,
165
165
  ) => TableCardinality | Promise<TableCardinality>;
166
166
  // Metadata
167
- projectionPushdown?: boolean;
168
- filterPushdown?: boolean;
169
- autoApplyFilters?: boolean;
167
+ projectionPushdown?: boolean | undefined;
168
+ filterPushdown?: boolean | undefined;
169
+ autoApplyFilters?: boolean | undefined;
170
170
  /** Force ParallelSink=false in the C++ operator (single-thread ingest). */
171
- sinkOrderDependent?: boolean;
171
+ sinkOrderDependent?: boolean | undefined;
172
172
  /** Force serial Source drain in finalize_queue order. */
173
- sourceOrderDependent?: boolean;
173
+ sourceOrderDependent?: boolean | undefined;
174
174
  /** Thread DuckDB's per-chunk batch_index into every process() call. */
175
- requiresInputBatchIndex?: boolean;
176
- stability?: FunctionStability;
177
- examples?: FunctionExample[];
178
- categories?: string[];
179
- tags?: Record<string, string>;
180
- maxWorkers?: number;
181
- requiredSettings?: string[];
182
- requiredSecrets?: string[];
175
+ requiresInputBatchIndex?: boolean | undefined;
176
+ stability?: FunctionStability | undefined;
177
+ examples?: FunctionExample[] | undefined;
178
+ categories?: string[] | undefined;
179
+ tags?: Record<string, string> | undefined;
180
+ maxWorkers?: number | undefined;
181
+ requiredSettings?: string[] | undefined;
182
+ requiredSecrets?: string[] | undefined;
183
183
  }
184
184
 
185
185
  /**
@@ -479,7 +479,7 @@ function makeProjectingCollector(
479
479
  function alreadyMatches(batch: VgiBatch): boolean {
480
480
  if (batch.schema.fields.length !== targetSchema.fields.length) return false;
481
481
  for (let i = 0; i < targetSchema.fields.length; i++) {
482
- if (batch.schema.fields[i].name !== targetSchema.fields[i].name) return false;
482
+ if (batch.schema.fields[i]!.name !== targetSchema.fields[i]!.name) return false;
483
483
  }
484
484
  return true;
485
485
  }
@@ -589,6 +589,10 @@ function concatLenPrefixed(parts: Uint8Array[]): Uint8Array {
589
589
  return out;
590
590
  }
591
591
 
592
+ // Always returns exactly `count` parts (a short buffer throws a RangeError from
593
+ // the DataView), which the overloads encode as a tuple.
594
+ function splitLenPrefixed(buf: Uint8Array, count: 2): [Uint8Array, Uint8Array];
595
+ function splitLenPrefixed(buf: Uint8Array, count: 3): [Uint8Array, Uint8Array, Uint8Array];
592
596
  function splitLenPrefixed(buf: Uint8Array, count: number): Uint8Array[] {
593
597
  const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
594
598
  const parts: Uint8Array[] = [];
@@ -74,7 +74,7 @@ export interface TableInOutProcessParams<TArgs = Record<string, any>> {
74
74
  outputSchema: VgiSchema;
75
75
  settings: Record<string, any>;
76
76
  secrets: Record<string, Record<string, any>>;
77
- pushdownFilters?: PushdownFilters;
77
+ pushdownFilters?: PushdownFilters | undefined;
78
78
  /** Shared storage for cross-phase and cross-worker data (SQLite-backed). */
79
79
  storage: BoundStorage;
80
80
  /**
@@ -88,7 +88,7 @@ export interface TableInOutProcessParams<TArgs = Record<string, any>> {
88
88
  * `null`/`undefined` for a client that sent none. Mirrors vgi-python's
89
89
  * `ProcessParams.substream_id`.
90
90
  */
91
- substreamId?: Uint8Array | null;
91
+ substreamId?: Uint8Array | null | undefined;
92
92
  /**
93
93
  * Conditional-revalidation validator (exchange-mode result cache): the
94
94
  * client holds a stale cached result for THIS input unit and asks the
@@ -97,10 +97,10 @@ export interface TableInOutProcessParams<TArgs = Record<string, any>> {
97
97
  * of recomputing. Rides the input batch's custom metadata (attached by the
98
98
  * C++ WriteInputBatch). Undefined on a normal call.
99
99
  */
100
- ifNoneMatch?: string;
100
+ ifNoneMatch?: string | undefined;
101
101
  /** RFC 3339 Last-Modified validator for conditional revalidation.
102
102
  * Companion to {@link ifNoneMatch}. Undefined on a normal call. */
103
- ifModifiedSince?: string;
103
+ ifModifiedSince?: string | undefined;
104
104
  }
105
105
 
106
106
  // ============================================================================
@@ -466,7 +466,7 @@ export function defineTableInOutFunction<
466
466
  out.finish();
467
467
  return;
468
468
  }
469
- const [logId, bytes] = rows[0];
469
+ const [logId, bytes] = rows[0]!;
470
470
  out.emit(deserializeBatch(bytes) as unknown as VgiBatch);
471
471
  pState.state.cursor = logId;
472
472
  },
@@ -579,7 +579,7 @@ export function defineTableInOutFunction<
579
579
  * see a stale validator.
580
580
  */
581
581
  function applyRevalidationValidators(
582
- params: { ifNoneMatch?: string; ifModifiedSince?: string },
582
+ params: { ifNoneMatch?: string | undefined; ifModifiedSince?: string | undefined },
583
583
  input: VgiBatch,
584
584
  ): void {
585
585
  const md: Map<string, string> | undefined = (input as any)?.metadata;
@@ -594,7 +594,7 @@ function applyRevalidationValidators(
594
594
  * once per stream). See `filter-pushdown/history.ts`.
595
595
  */
596
596
  function applyDynamicFilterUpdate(
597
- eState: { processParams: { pushdownFilters?: PushdownFilters }; filterHistory: FilterDeltaHistory },
597
+ eState: { processParams: { pushdownFilters?: PushdownFilters | undefined }; filterHistory: FilterDeltaHistory },
598
598
  input: VgiBatch,
599
599
  ): void {
600
600
  const encoded = ((input as any)?.metadata as Map<string, string> | undefined)?.get("vgi_pushdown_filters");
@@ -660,7 +660,7 @@ function makeSchemaReconcilingCollector(
660
660
  const batchFields = batch.schema.fields;
661
661
  if (
662
662
  batchFields.length === targetSchema.fields.length &&
663
- targetSchema.fields.every((f, i) => batchFields[i].name === f.name)
663
+ targetSchema.fields.every((f, i) => batchFields[i]!.name === f.name)
664
664
  ) {
665
665
  return batch;
666
666
  }
@@ -75,7 +75,7 @@ function makeProjectingCollector(inner: OutputCollector, targetSchema: VgiSchema
75
75
  function alreadyMatches(batch: VgiBatch): boolean {
76
76
  if (batch.schema.fields.length !== targetSchema.fields.length) return false;
77
77
  for (let i = 0; i < targetSchema.fields.length; i++) {
78
- if (batch.schema.fields[i].name !== targetSchema.fields[i].name) return false;
78
+ if (batch.schema.fields[i]!.name !== targetSchema.fields[i]!.name) return false;
79
79
  }
80
80
  return true;
81
81
  }
@@ -140,7 +140,7 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
140
140
  outputSchema: VgiSchema;
141
141
  settings: Record<string, any>;
142
142
  secrets: Record<string, Record<string, any>>;
143
- pushdownFilters?: PushdownFilters;
143
+ pushdownFilters?: PushdownFilters | undefined;
144
144
  /**
145
145
  * The verified payloads of the splits this init claimed, in the order given,
146
146
  * or undefined when this is not a split scan.
@@ -149,8 +149,8 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
149
149
  * the client did not plan (a split-only function should fail loudly rather
150
150
  * than answer the same query differently), empty means a claim of no work.
151
151
  */
152
- splitPayloads?: Uint8Array[];
153
- storage?: BoundStorage;
152
+ splitPayloads?: Uint8Array[] | undefined;
153
+ storage?: BoundStorage | undefined;
154
154
  /**
155
155
  * AT (TIMESTAMP|VERSION) clause for this scan, or `undefined` when the scan
156
156
  * has no AT clause. Carried on the per-scan bind embedded in the init request
@@ -158,8 +158,8 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
158
158
  * read time travel at init alongside their pushdown filters. Mirrors
159
159
  * vgi-python's `ProcessParams.at_unit` / `.at_value`. See `BindRequest.at_unit`.
160
160
  */
161
- atUnit?: string;
162
- atValue?: string;
161
+ atUnit?: string | undefined;
162
+ atValue?: string | undefined;
163
163
  /**
164
164
  * Conditional-revalidation validator (the client's stored ETag). Set when the
165
165
  * client holds a stale-but-revalidatable cached result and asks the worker to
@@ -168,10 +168,10 @@ export interface TableProcessParams<TArgs = Record<string, any>> {
168
168
  * `cacheControlMetadata({ notModified: true })` instead of re-streaming.
169
169
  * Undefined on a normal call.
170
170
  */
171
- ifNoneMatch?: string;
171
+ ifNoneMatch?: string | undefined;
172
172
  /** Conditional-revalidation validator (the client's stored Last-Modified).
173
173
  * Companion to {@link ifNoneMatch}. Undefined on a normal call. */
174
- ifModifiedSince?: string;
174
+ ifModifiedSince?: string | undefined;
175
175
  }
176
176
 
177
177
  /**
@@ -449,6 +449,8 @@ export function defineTableFunction<
449
449
  return args as TArgs;
450
450
  }
451
451
 
452
+ // Optional hooks are spread in only when configured, so an unconfigured
453
+ // hook is absent rather than present-and-undefined.
452
454
  return {
453
455
  kind: "table",
454
456
  meta,
@@ -474,7 +476,7 @@ export function defineTableFunction<
474
476
  };
475
477
  },
476
478
 
477
- projection: config.projection ? (proposal) => config.projection!({args: extractArgs(proposal.bindCall), bindCall:proposal.bindCall, settings:batchToScalarDict(proposal.bindCall.settings),secrets:batchToSecretDict(proposal.bindCall.secrets),resolvedSecretsProvided:proposal.bindCall.resolved_secrets_provided},proposal) : undefined,
479
+ ...(config.projection ? { projection: (proposal) => config.projection!({args: extractArgs(proposal.bindCall), bindCall:proposal.bindCall, settings:batchToScalarDict(proposal.bindCall.settings),secrets:batchToSecretDict(proposal.bindCall.secrets),resolvedSecretsProvided:proposal.bindCall.resolved_secrets_provided},proposal) } : {}),
478
480
 
479
481
  async globalInit(request: InitRequest): Promise<GlobalInitResponse> {
480
482
  const executionId = new Uint8Array(16);
@@ -660,8 +662,8 @@ export function defineTableFunction<
660
662
  };
661
663
  },
662
664
 
663
- cardinality: config.cardinality
664
- ? (request: TableFunctionCardinalityRequest) => {
665
+ ...(config.cardinality ? {
666
+ cardinality: (request: TableFunctionCardinalityRequest) => {
665
667
  const args = extractArgs(request.bind_call);
666
668
  const settings = batchToScalarDict(request.bind_call.settings);
667
669
  const secrets = batchToSecretDict(request.bind_call.secrets);
@@ -672,8 +674,8 @@ export function defineTableFunction<
672
674
  secrets,
673
675
  resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false,
674
676
  });
675
- }
676
- : undefined,
677
+ },
678
+ } : {}),
677
679
 
678
680
  // Wired through with decoded arguments, exactly as cardinality and
679
681
  // statistics are.
@@ -683,8 +685,8 @@ export function defineTableFunction<
683
685
  // `supportsSplits` and a `plan`, advertise split capability on the wire, and
684
686
  // silently serve the framework default of one empty-payload split. Nothing
685
687
  // failed — the scan just quietly stopped being divided.
686
- plan: config.plan
687
- ? (request: TableFunctionPlanRequest) => {
688
+ ...(config.plan ? {
689
+ plan: (request: TableFunctionPlanRequest) => {
688
690
  const args = extractArgs(request.bind_call);
689
691
  const settings = batchToScalarDict(request.bind_call.settings);
690
692
  const secrets = batchToSecretDict(request.bind_call.secrets);
@@ -698,11 +700,11 @@ export function defineTableFunction<
698
700
  },
699
701
  request,
700
702
  );
701
- }
702
- : undefined,
703
+ },
704
+ } : {}),
703
705
 
704
- statistics: config.statistics
705
- ? (request: TableFunctionCardinalityRequest) => {
706
+ ...(config.statistics ? {
707
+ statistics: (request: TableFunctionCardinalityRequest) => {
706
708
  const args = extractArgs(request.bind_call);
707
709
  const settings = batchToScalarDict(request.bind_call.settings);
708
710
  const secrets = batchToSecretDict(request.bind_call.secrets);
@@ -713,11 +715,11 @@ export function defineTableFunction<
713
715
  secrets,
714
716
  resolvedSecretsProvided: request.bind_call.resolved_secrets_provided ?? false,
715
717
  });
716
- }
717
- : undefined,
718
+ },
719
+ } : {}),
718
720
 
719
- dynamicToString: config.dynamicToString
720
- ? (request) => {
721
+ ...(config.dynamicToString ? {
722
+ dynamicToString: (request) => {
721
723
  const args = extractArgs(request.bindCall);
722
724
  const settings = batchToScalarDict(request.bindCall.settings);
723
725
  const secrets = batchToSecretDict(request.bindCall.secrets);
@@ -733,7 +735,7 @@ export function defineTableFunction<
733
735
  request.globalExecutionId,
734
736
  storage,
735
737
  );
736
- }
737
- : undefined,
738
+ },
739
+ } : {}),
738
740
  };
739
741
  }
@@ -60,23 +60,23 @@ export interface EvaluationContextCapability {
60
60
 
61
61
  export interface FunctionMeta {
62
62
  name: string;
63
- description?: string;
64
- stability?: FunctionStability;
65
- nullHandling?: NullHandling;
63
+ description?: string | undefined;
64
+ stability?: FunctionStability | undefined;
65
+ nullHandling?: NullHandling | undefined;
66
66
  /** Scalar-only claims in argument declaration order. A vararg is one slot. */
67
- argumentMonotonicity?: ArgumentMonotonicity[] | null;
68
- examples?: FunctionExample[];
69
- categories?: string[];
70
- tags?: Record<string, string>;
67
+ argumentMonotonicity?: ArgumentMonotonicity[] | null | undefined;
68
+ examples?: FunctionExample[] | undefined;
69
+ categories?: string[] | undefined;
70
+ tags?: Record<string, string> | undefined;
71
71
  /**
72
72
  * Authoritative typed parameter defaults. The batch must contain one row
73
73
  * and only defaulted parameters, in signature order; a present null is an
74
74
  * explicit null default. `vgi_default` field metadata remains discovery-only.
75
75
  */
76
- parameterDefaultValues?: VgiBatch | null;
77
- projectionPushdown?: boolean;
78
- filterPushdown?: boolean;
79
- samplingPushdown?: boolean;
76
+ parameterDefaultValues?: VgiBatch | null | undefined;
77
+ projectionPushdown?: boolean | undefined;
78
+ filterPushdown?: boolean | undefined;
79
+ samplingPushdown?: boolean | undefined;
80
80
  /**
81
81
  * table (generator): opt in to DuckDB's late-materialization rewrite. A
82
82
  * TOP_N/LIMIT/SAMPLE over a rowid-bearing table is rewritten into a SEMI
@@ -85,24 +85,24 @@ export interface FunctionMeta {
85
85
  * as FunctionInfo `late_materialization`. Only honoured by the C++ extension
86
86
  * for tables whose worker also guarantees a UNIQUE, snapshot-stable rowid.
87
87
  */
88
- lateMaterialization?: boolean;
89
- filterSemanticProfiles?: string[];
90
- additionalFilterFunctions?: FilterFunctionCapability[];
91
- runtimeFilterAlgorithms?: FilterFunctionCapability[];
92
- filterEvaluationContexts?: EvaluationContextCapability[];
93
- autoApplyFilters?: boolean;
94
- preservesOrder?: OrderPreservation;
95
- maxWorkers?: number;
96
- requiredSettings?: string[];
97
- requiredSecrets?: string[];
98
- orderDependent?: OrderDependence;
99
- distinctDependent?: DistinctDependence;
88
+ lateMaterialization?: boolean | undefined;
89
+ filterSemanticProfiles?: string[] | undefined;
90
+ additionalFilterFunctions?: FilterFunctionCapability[] | undefined;
91
+ runtimeFilterAlgorithms?: FilterFunctionCapability[] | undefined;
92
+ filterEvaluationContexts?: EvaluationContextCapability[] | undefined;
93
+ autoApplyFilters?: boolean | undefined;
94
+ preservesOrder?: OrderPreservation | undefined;
95
+ maxWorkers?: number | undefined;
96
+ requiredSettings?: string[] | undefined;
97
+ requiredSecrets?: string[] | undefined;
98
+ orderDependent?: OrderDependence | undefined;
99
+ distinctDependent?: DistinctDependence | undefined;
100
100
  /**
101
101
  * For table_in_out functions: whether the user defined a finalize callback.
102
102
  * DuckDB issues a separate FINALIZE init() phase only when this is true;
103
103
  * otherwise calling FinalExecute is unsupported and crashes the C++ side.
104
104
  */
105
- hasFinalize?: boolean;
105
+ hasFinalize?: boolean | undefined;
106
106
  /**
107
107
  * Blended ("UNNEST-style") table-in-out: the function's positional args ARE
108
108
  * its per-row input columns (real typed args, no synthetic TABLE
@@ -114,36 +114,36 @@ export interface FunctionMeta {
114
114
  * single-row scan-mode. Mirrors vgi-python's RowTransformFunction /
115
115
  * ResolvedMetadata.input_from_args.
116
116
  */
117
- inputFromArgs?: boolean;
117
+ inputFromArgs?: boolean | undefined;
118
118
  /**
119
119
  * Blended only: the most input rows one worker call receives; the client
120
120
  * splits each input chunk into calls of at most this many rows. Unset sends
121
121
  * a whole chunk per call. Set by {@link defineRowTransformFunction}'s
122
122
  * `inputRowsPerCall`; surfaces as FunctionInfo.input_rows_per_call.
123
123
  */
124
- inputRowsPerCall?: number;
124
+ inputRowsPerCall?: number | undefined;
125
125
  /**
126
126
  * table_buffering: force ParallelSink=false in the C++ operator
127
127
  * (single-thread, source-ordered ingest).
128
128
  */
129
- sinkOrderDependent?: boolean;
129
+ sinkOrderDependent?: boolean | undefined;
130
130
  /**
131
131
  * table_buffering: force serial Source drain in finalize_queue order
132
132
  * (ParallelSource=false, SourceOrder=FIXED_ORDER).
133
133
  */
134
- sourceOrderDependent?: boolean;
134
+ sourceOrderDependent?: boolean | undefined;
135
135
  /**
136
136
  * table_buffering: thread DuckDB's per-chunk batch_index into every
137
137
  * process() call (RequiredPartitionInfo=BatchIndex).
138
138
  */
139
- requiresInputBatchIndex?: boolean;
139
+ requiresInputBatchIndex?: boolean | undefined;
140
140
  /**
141
141
  * table (generator): the function tags every emitted Arrow batch with a
142
142
  * per-partition `vgi_batch_index` so DuckDB's ordered sinks reassemble
143
143
  * parallel output in partition order. Surfaces as FunctionInfo
144
144
  * `supports_batch_index`.
145
145
  */
146
- supportsBatchIndex?: boolean;
146
+ supportsBatchIndex?: boolean | undefined;
147
147
  /**
148
148
  * table (generator): the scan divides into named, independently redeemable
149
149
  * splits (see the `plan` / `onSplit` hooks). Surfaces as FunctionInfo
@@ -154,19 +154,19 @@ export interface FunctionMeta {
154
154
  * same rows. Without it, the division lives behind an opaque worker-side queue
155
155
  * and a retry reads neither what it read before nor what it missed.
156
156
  */
157
- supportsSplits?: boolean;
157
+ supportsSplits?: boolean | undefined;
158
158
  /**
159
159
  * table (generator): the worker applies every pushed filter EXACTLY, so the
160
160
  * engine may drop its own copy rather than re-filtering. Wrong answers if
161
161
  * declared falsely — leave unset unless certain.
162
162
  */
163
- filtersExactlyApplied?: boolean;
163
+ filtersExactlyApplied?: boolean | undefined;
164
164
  /**
165
165
  * table (generator): addressable positions in the data, for incremental and
166
166
  * streaming reads. The engine owns the checkpoint; this declares only that
167
167
  * positions are meaningful to externalize.
168
168
  */
169
- supportsPositions?: boolean;
169
+ supportsPositions?: boolean | undefined;
170
170
  /**
171
171
  * table (generator): how long a split token stays redeemable.
172
172
  *
@@ -175,14 +175,14 @@ export interface FunctionMeta {
175
175
  * plan whose TTL is below its own planning-to-task-start horizon, which on a
176
176
  * busy cluster is hours rather than seconds.
177
177
  */
178
- splitTokenTtlSeconds?: number;
178
+ splitTokenTtlSeconds?: number | undefined;
179
179
  /**
180
180
  * table (generator): Hive-style partition-columns mode. Functions declare
181
181
  * a PartitionKind and annotate bind-schema fields; emitted batches carry
182
182
  * `vgi_partition_values#b64` metadata. Surfaces as FunctionInfo
183
183
  * `partition_kind`.
184
184
  */
185
- partitionKind?: "NOT_PARTITIONED" | "SINGLE_VALUE_PARTITIONS" | "OVERLAPPING_PARTITIONS" | "DISJOINT_PARTITIONS";
185
+ partitionKind?: "NOT_PARTITIONED" | "SINGLE_VALUE_PARTITIONS" | "OVERLAPPING_PARTITIONS" | "DISJOINT_PARTITIONS" | undefined;
186
186
  /**
187
187
  * COPY ... FROM custom format reader: the SQL `FORMAT` identifier this
188
188
  * function backs (e.g. `example_lines`). Set by {@link defineCopyFromFunction}.
@@ -191,11 +191,11 @@ export interface FunctionMeta {
191
191
  * extension registers a DuckDB CopyFunction for it. Mirrors vgi-python's
192
192
  * `CopyFromFunction.COPY_FROM_FORMAT`.
193
193
  */
194
- copyFromFormat?: string;
194
+ copyFromFormat?: string | undefined;
195
195
  /** COPY direction; only `"from"` is supported today. Default `"from"`. */
196
- copyFromDirection?: string;
196
+ copyFromDirection?: string | undefined;
197
197
  /** Optional free-text comment surfaced by `vgi_copy_formats()`. */
198
- copyFromComment?: string | null;
198
+ copyFromComment?: string | null | undefined;
199
199
  /**
200
200
  * COPY ... TO custom format writer: the SQL `FORMAT` identifier this function
201
201
  * backs (e.g. `example_lines_out`). Set by {@link defineCopyToFunction}. When
@@ -206,19 +206,19 @@ export interface FunctionMeta {
206
206
  * `table_buffering_process` / `table_buffering_combine` RPCs. Mirrors
207
207
  * vgi-python's `CopyToFunction.COPY_TO_FORMAT`.
208
208
  */
209
- copyToFormat?: string;
209
+ copyToFormat?: string | undefined;
210
210
  /** COPY direction for a TO writer; always `"to"`. Default `"to"`. */
211
- copyToDirection?: string;
211
+ copyToDirection?: string | undefined;
212
212
  /** Optional free-text comment surfaced by `vgi_copy_formats()`. */
213
- copyToComment?: string | null;
213
+ copyToComment?: string | null | undefined;
214
214
  }
215
215
 
216
216
  export interface StreamHandlers {
217
217
  // For producer streams (table functions, finalize phase)
218
- producerInit?: () => any;
219
- producerFn?: (state: any, out: OutputCollector) => void | Promise<void>;
218
+ producerInit?: (() => any) | undefined;
219
+ producerFn?: ((state: any, out: OutputCollector) => void | Promise<void>) | undefined;
220
220
  // For exchange streams (scalar, table-in-out input phase)
221
- exchangeInit?: () => any;
221
+ exchangeInit?: (() => any) | undefined;
222
222
  exchangeFn?: (
223
223
  state: any,
224
224
  input: VgiBatch,
@@ -227,7 +227,7 @@ export interface StreamHandlers {
227
227
  // Output schema for the stream
228
228
  outputSchema: VgiSchema;
229
229
  // Input schema for exchange (empty for producer)
230
- inputSchema?: VgiSchema;
230
+ inputSchema?: VgiSchema | undefined;
231
231
  /**
232
232
  * Fires once per tick batch on the producer path, before `producerFn`.
233
233
  * Receives the tick's Arrow custom metadata so the handler can pick up
@@ -241,7 +241,7 @@ export interface StreamHandlers {
241
241
  * handler state, which the dispatcher carries in the HTTP state token. Every
242
242
  * other stream's reply is refused if it says HAVE_MORE_OUTPUT.
243
243
  */
244
- continuesOutput?: boolean;
244
+ continuesOutput?: boolean | undefined;
245
245
  }
246
246
 
247
247
  /**
@@ -252,7 +252,7 @@ export interface VgiFunction {
252
252
  meta: FunctionMeta;
253
253
  argumentSpecs: ArgumentSpec[];
254
254
  /** Default output schema (for catalog registration). May be overridden at bind time. */
255
- defaultOutputSchema?: VgiSchema;
255
+ defaultOutputSchema?: VgiSchema | undefined;
256
256
  bind(request: BindRequest): BindResponse | Promise<BindResponse>;
257
257
  globalInit(request: InitRequest): GlobalInitResponse | Promise<GlobalInitResponse>;
258
258
  /**