@query-farm/vgi 0.45.0 → 0.47.0

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 (102) hide show
  1. package/README.md +19 -6
  2. package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
  3. package/dist/arrow/impl-arrowjs/iterate.d.ts +2 -0
  4. package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
  5. package/dist/arrow/impl-flechette/index.d.ts +1 -1
  6. package/dist/arrow/impl-flechette/iterate.d.ts +2 -0
  7. package/dist/arrow/impl-flechette/schema.d.ts +19 -5
  8. package/dist/arrow/index.d.ts +1 -1
  9. package/dist/catalog/column-expressions.d.ts +8 -0
  10. package/dist/catalog/column-metadata.d.ts +11 -0
  11. package/dist/catalog/composite.d.ts +2 -1
  12. package/dist/catalog/descriptors.d.ts +21 -29
  13. package/dist/catalog/interface.d.ts +15 -20
  14. package/dist/catalog/macro-overloads.d.ts +4 -0
  15. package/dist/catalog/read-only.d.ts +1 -1
  16. package/dist/catalog/unconstrained-columns.d.ts +2 -0
  17. package/dist/client/client.d.ts +38 -14
  18. package/dist/client-entry.js +806 -115
  19. package/dist/client-entry.js.map +18 -14
  20. package/dist/functions/continuation.d.ts +69 -0
  21. package/dist/functions/projection.d.ts +18 -0
  22. package/dist/functions/table-in-out.d.ts +51 -7
  23. package/dist/functions/table.d.ts +6 -1
  24. package/dist/functions/types.d.ts +21 -0
  25. package/dist/generated/vgi-client.d.ts +178 -36
  26. package/dist/generated/vgi-protocol-schemas.d.ts +51 -1
  27. package/dist/generated/vgi-protocol-types.d.ts +317 -3
  28. package/dist/generated/vgi-service.d.ts +266 -29
  29. package/dist/index.core.d.ts +3 -1
  30. package/dist/index.js +1747 -320
  31. package/dist/index.js.map +45 -37
  32. package/dist/protocol/dispatch.d.ts +9 -9
  33. package/dist/protocol/handlers/aggregate.d.ts +1 -1
  34. package/dist/protocol/handlers/catalog/index.d.ts +1 -1
  35. package/dist/protocol/handlers/catalog/metadata.d.ts +1 -0
  36. package/dist/protocol/handlers/function.d.ts +1 -1
  37. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  38. package/dist/protocol/handlers/unimplemented.d.ts +1 -1
  39. package/dist/protocol/serializers/bind.d.ts +5 -1
  40. package/dist/protocol/types.d.ts +5 -0
  41. package/dist/rpc-server.d.ts +6 -6
  42. package/dist/serve-entry.js +1607 -436
  43. package/dist/serve-entry.js.map +33 -27
  44. package/dist/util/arrow/index.d.ts +1 -1
  45. package/dist/util/parent-rows.d.ts +8 -0
  46. package/dist/worker-cf-entry.d.ts +1 -1
  47. package/dist/worker-cf-entry.js +1901 -526
  48. package/dist/worker-cf-entry.js.map +45 -37
  49. package/dist/worker.d.ts +1 -1
  50. package/package.json +8 -7
  51. package/src/arrow/impl-arrowjs/index.ts +1 -1
  52. package/src/arrow/impl-arrowjs/iterate.ts +9 -1
  53. package/src/arrow/impl-arrowjs/project.ts +1 -1
  54. package/src/arrow/impl-flechette/canonical.ts +7 -5
  55. package/src/arrow/impl-flechette/index.ts +1 -1
  56. package/src/arrow/impl-flechette/ipc.ts +12 -0
  57. package/src/arrow/impl-flechette/iterate.ts +5 -0
  58. package/src/arrow/impl-flechette/project.ts +6 -8
  59. package/src/arrow/index.ts +1 -1
  60. package/src/catalog/column-expressions.ts +224 -0
  61. package/src/catalog/column-metadata.ts +151 -0
  62. package/src/catalog/composite.ts +5 -1
  63. package/src/catalog/contents-codec.ts +6 -1
  64. package/src/catalog/descriptors.ts +21 -29
  65. package/src/catalog/interface.ts +70 -55
  66. package/src/catalog/macro-overloads.ts +44 -0
  67. package/src/catalog/read-only.ts +69 -71
  68. package/src/catalog/unconstrained-columns.ts +23 -0
  69. package/src/client/client.ts +180 -69
  70. package/src/codec/asd.ts +3 -1
  71. package/src/filter-pushdown/collector.ts +17 -1
  72. package/src/functions/continuation.ts +202 -0
  73. package/src/functions/projection.ts +207 -0
  74. package/src/functions/table-in-out.ts +131 -56
  75. package/src/functions/table.ts +10 -0
  76. package/src/functions/types.ts +21 -0
  77. package/src/generated/vgi-client.ts +200 -37
  78. package/src/generated/vgi-protocol-schemas.ts +456 -41
  79. package/src/generated/vgi-protocol-types.ts +879 -5
  80. package/src/generated/vgi-service.ts +514 -42
  81. package/src/http/client-bundle.ts +1 -1
  82. package/src/http/fetch.ts +1 -1
  83. package/src/index.core.ts +10 -0
  84. package/src/protocol/dispatch.ts +9 -9
  85. package/src/protocol/handlers/aggregate.ts +1 -1
  86. package/src/protocol/handlers/catalog/admin.ts +10 -5
  87. package/src/protocol/handlers/catalog/index.ts +2 -2
  88. package/src/protocol/handlers/catalog/macro.ts +6 -5
  89. package/src/protocol/handlers/catalog/metadata.ts +16 -0
  90. package/src/protocol/handlers/catalog/table.ts +72 -26
  91. package/src/protocol/handlers/catalog/view.ts +24 -3
  92. package/src/protocol/handlers/function.ts +79 -1
  93. package/src/protocol/handlers/table-buffering.ts +1 -1
  94. package/src/protocol/handlers/unimplemented.ts +6 -6
  95. package/src/protocol/serializers/bind.ts +17 -1
  96. package/src/protocol/state-serializer.ts +7 -1
  97. package/src/protocol/types.ts +6 -0
  98. package/src/rpc-server.ts +9 -9
  99. package/src/util/arrow/index.ts +1 -1
  100. package/src/util/parent-rows.ts +41 -0
  101. package/src/worker-cf-entry.ts +3 -0
  102. package/src/worker.ts +1 -1
@@ -33,7 +33,7 @@ import {
33
33
  } from "../../functions/table-buffering.js";
34
34
  import { Arguments } from "../../arguments/arguments.js";
35
35
 
36
- /** The table_buffering lifecycle's `vgi.v2` handlers. */
36
+ /** The table_buffering lifecycle's `vgi.v3` handlers. */
37
37
  export function tableBufferingHandlers(
38
38
  registry: FunctionRegistry,
39
39
  signingKey?: Uint8Array,
@@ -1,9 +1,9 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
- // vgi.v2 methods this SDK registers but does not implement.
2
+ // vgi.v3 methods this SDK registers but does not implement.
3
3
  //
4
- // "The protocol is the unit of optionality": every SDK hosts EVERY vgi.v2
4
+ // "The protocol is the unit of optionality": every SDK hosts EVERY vgi.v3
5
5
  // method with exactly the reference's schemas, so vgi_rpc.Reflection.v1
6
- // reports one vgi.v2 protocol hash everywhere (see VGI_V2_PROTOCOL_HASH in
6
+ // reports one vgi.v3 protocol hash everywhere (see VGI_V3_PROTOCOL_HASH in
7
7
  // ../dispatch.ts). The registration and the UNIMPLEMENTED default for every
8
8
  // method are generated (src/generated/vgi-service.ts); this module only names
9
9
  // the methods whose generated default this worker leaves in place, so a test
@@ -15,7 +15,7 @@
15
15
  import { FunctionRegistry } from "../../functions/registry.js";
16
16
  import {
17
17
  UNIMPLEMENTED_VGI_SERVICE,
18
- VGI_V2_METHODS,
18
+ VGI_V3_METHODS,
19
19
  type VgiMethodSpec,
20
20
  } from "../../generated/vgi-service.js";
21
21
  import { buildVgiService } from "../dispatch.js";
@@ -24,7 +24,7 @@ export { unimplementedMessage } from "../../generated/vgi-service.js";
24
24
 
25
25
  const service = buildVgiService({ registry: new FunctionRegistry() });
26
26
 
27
- /** The vgi.v2 methods (of the reference's 72) this SDK leaves at the generated default. */
28
- export const UNIMPLEMENTED_METHODS: readonly VgiMethodSpec[] = VGI_V2_METHODS.filter(
27
+ /** The vgi.v3 methods (of the reference's 72) this SDK leaves at the generated default. */
28
+ export const UNIMPLEMENTED_METHODS: readonly VgiMethodSpec[] = VGI_V3_METHODS.filter(
29
29
  (m) => service[m.key] === UNIMPLEMENTED_VGI_SERVICE[m.key],
30
30
  );
@@ -6,7 +6,7 @@
6
6
  import { type VgiSchema, schema, field, type VgiBatch, type VgiDataType, utf8, binary, bool, struct, dictionary, int16, list } from "../../arrow/index.js";
7
7
  import { Arguments } from "../../arguments/arguments.js";
8
8
  import { FunctionType } from "../../types.js";
9
- import type { BindRequest, BindResponse, CopyFromContext, CopyToContext } from "../types.js";
9
+ import type { BindRequest, BindResponse, BindRepeatability, CopyFromContext, CopyToContext } from "../types.js";
10
10
  import {
11
11
  serializeSchema,
12
12
  deserializeSchema,
@@ -184,15 +184,29 @@ export function deserializeBindRequest(
184
184
  };
185
185
  }
186
186
 
187
+ /** Validate required wire enum values, including rejecting NULL and absent values. */
188
+ export function parseBindRepeatability(value: unknown): BindRepeatability {
189
+ if (value !== "UNKNOWN" && value !== "STABLE_WITHIN_QUERY")
190
+ throw new Error("invalid bind repeatability");
191
+ return value;
192
+ }
193
+
194
+ /** Only omitted provider declarations default; explicit NULL remains invalid. */
195
+ export function normalizeBindRepeatability(value: unknown): BindRepeatability {
196
+ return parseBindRepeatability(value === undefined ? "UNKNOWN" : value);
197
+ }
198
+
187
199
  export function serializeBindResponse(
188
200
  resp: BindResponse
189
201
  ): Record<string, any> {
190
202
  return {
191
203
  output_schema: serializeSchema(resp.output_schema),
192
204
  opaque_data: resp.opaque_data ?? null,
205
+ projection_expression_profiles: resp.projection_expression_profiles ?? [],
193
206
  lookup_secret_types: resp.lookup_secret_types ?? [],
194
207
  lookup_scopes: resp.lookup_scopes ?? [],
195
208
  lookup_names: resp.lookup_names ?? [],
209
+ repeatability: normalizeBindRepeatability(resp.repeatability),
196
210
  };
197
211
  }
198
212
 
@@ -206,10 +220,12 @@ export function deserializeBindResponse(
206
220
  };
207
221
  return {
208
222
  output_schema: deserializeSchema(toUint8Array(params.output_schema)),
223
+ projection_expression_profiles: toStrArray(params.projection_expression_profiles),
209
224
  opaque_data: params.opaque_data ? toUint8Array(params.opaque_data) : null,
210
225
  lookup_secret_types: toStrArray(params.lookup_secret_types),
211
226
  lookup_scopes: toStrArray(params.lookup_scopes),
212
227
  lookup_names: toStrArray(params.lookup_names),
228
+ repeatability: parseBindRepeatability(params.repeatability),
213
229
  };
214
230
  }
215
231
 
@@ -50,6 +50,9 @@ export const EXCHANGE_STATE_SCHEMA = makeSchema([
50
50
  // null when no delta has been applied. Bounded by the number of predicate
51
51
  // ids, so the token stays flat-sized however many turns the scan takes.
52
52
  field("filter_history", binary(), true),
53
+ // A table-in-out exchange's last reply said HAVE_MORE_OUTPUT, so the next
54
+ // input must be a continuation tick (functions/continuation.ts). A flag bit.
55
+ field("more_pending", bool(), false),
53
56
  ]);
54
57
 
55
58
  const TEXT_ENCODER = new TextEncoder();
@@ -61,6 +64,7 @@ const FLAG_PRODUCER = 1;
61
64
  const FLAG_OPAQUE_DATA = 2;
62
65
  const FLAG_USER_STATE = 4;
63
66
  const FLAG_FILTER_HISTORY = 8;
67
+ const FLAG_MORE_PENDING = 16;
64
68
 
65
69
  /**
66
70
  * Child field name for an inferred list. Arrow matches list children by
@@ -243,7 +247,8 @@ export const arrowStateSerializer: StateSerializer = {
243
247
  (state.isProducer ? FLAG_PRODUCER : 0) |
244
248
  (opaqueData ? FLAG_OPAQUE_DATA : 0) |
245
249
  (userState ? FLAG_USER_STATE : 0) |
246
- (filterHistory ? FLAG_FILTER_HISTORY : 0);
250
+ (filterHistory ? FLAG_FILTER_HISTORY : 0) |
251
+ (state.morePending ? FLAG_MORE_PENDING : 0);
247
252
  const chunks = [functionName, initRequest, executionId];
248
253
  if (opaqueData) chunks.push(opaqueData);
249
254
  if (userState) chunks.push(userState);
@@ -302,6 +307,7 @@ export const arrowStateSerializer: StateSerializer = {
302
307
  __isProducer: isProducer,
303
308
  userState: deserializeUserState(userStateBytes),
304
309
  filterHistory: decodeFilterHistory(filterHistoryBytes),
310
+ morePending: (flags & FLAG_MORE_PENDING) !== 0,
305
311
  };
306
312
  },
307
313
  };
@@ -104,7 +104,13 @@ export interface BindRequest {
104
104
  argument_names?: (string | null)[] | null;
105
105
  }
106
106
 
107
+ /** Equivalent scans of one bound state within a query; independent binds may differ. */
108
+ export type BindRepeatability = "UNKNOWN" | "STABLE_WITHIN_QUERY";
109
+
107
110
  export interface BindResponse {
111
+ /** Omitted provider values serialize as UNKNOWN. Wire values are required. */
112
+ repeatability?: BindRepeatability;
113
+ projection_expression_profiles?: string[];
108
114
  output_schema: VgiSchema;
109
115
  opaque_data: Uint8Array | null;
110
116
  lookup_secret_types?: string[];
package/src/rpc-server.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  //
10
10
  // What a server hosts, in reflection order:
11
11
  //
12
- // 1. The worker's own protocol, `vgi.v2`.
12
+ // 1. The worker's own protocol, `vgi.v3`.
13
13
  // 2. The worker's `hostedProtocols()`, in the order returned -- on EVERY
14
14
  // transport.
15
15
  // 3. `vgi_rpc.Reflection.v1` -- on every transport.
@@ -19,9 +19,9 @@
19
19
  // configured explicitly (never a generated one) *and* the worker can
20
20
  // issue grants. See `attach-ticket.ts`.
21
21
  //
22
- // Extra protocols cannot change `vgi.v2` behaviour: vgi-rpc routes every
22
+ // Extra protocols cannot change `vgi.v3` behaviour: vgi-rpc routes every
23
23
  // request on its `vgi_rpc.protocol` key with no fallback to the primary, so a
24
- // client that only ever names `vgi.v2` (the DuckDB extension) dispatches
24
+ // client that only ever names `vgi.v3` (the DuckDB extension) dispatches
25
25
  // exactly as it would against a single-protocol server.
26
26
 
27
27
  import {
@@ -55,7 +55,7 @@ const RESERVED_PREFIX = "vgi_rpc.";
55
55
  export const INTROSPECT_PRINCIPALS_ENV = "VGI_INTROSPECT_PRINCIPALS";
56
56
 
57
57
  /**
58
- * What a worker hosts beyond `vgi.v2`, and whether it opts into identity.
58
+ * What a worker hosts beyond `vgi.v3`, and whether it opts into identity.
59
59
  *
60
60
  * Accepted by `new Worker({...})`, `serveVgiWorker`, `createVgiWorkerFetch`
61
61
  * and `createVgiFetch` (Cloudflare Workers) alike, so one worker definition
@@ -63,20 +63,20 @@ export const INTROSPECT_PRINCIPALS_ENV = "VGI_INTROSPECT_PRINCIPALS";
63
63
  */
64
64
  export interface HostingOptions {
65
65
  /**
66
- * Additional vgi-rpc protocols to host beside `vgi.v2`, on the **same**
66
+ * Additional vgi-rpc protocols to host beside `vgi.v3`, on the **same**
67
67
  * listener, whatever the transport.
68
68
  *
69
69
  * A vgi-rpc `Protocol` carries its handlers, so each entry is a whole
70
70
  * `(protocol, implementation)` pair. Called **once**, when the server is
71
71
  * built; it may consult configuration or the environment, but the answer is
72
72
  * fixed for the life of the process, so reflection output and protocol
73
- * hashes stay stable. Hosted after `vgi.v2`, in the order returned.
73
+ * hashes stay stable. Hosted after `vgi.v3`, in the order returned.
74
74
  *
75
75
  * The protocol is the unit of optionality: there is no way to host a subset
76
76
  * of a protocol's methods. A capability that is optional is its own
77
77
  * protocol, returned here or not.
78
78
  *
79
- * Each needs a distinct wire name, which may not be `vgi.v2` and may not
79
+ * Each needs a distinct wire name, which may not be `vgi.v3` and may not
80
80
  * use the reserved `vgi_rpc.` prefix: reflection is hosted automatically and
81
81
  * `vgi_rpc.Identity.v2` is enabled through {@link resolveToken} /
82
82
  * {@link mintGrant}. Violations are a startup error naming this hook.
@@ -164,14 +164,14 @@ export interface BuildRpcServerOptions {
164
164
  }
165
165
 
166
166
  /**
167
- * Build the vgi-rpc server for a worker's `vgi.v2` protocol on `transport`.
167
+ * Build the vgi-rpc server for a worker's `vgi.v3` protocol on `transport`.
168
168
  *
169
169
  * Calls `hosting.hostedProtocols()` exactly once and hosts the result beside
170
170
  * `primary`; see the module comment for the full hosted set.
171
171
  *
172
172
  * @throws TypeError `hostedProtocols()` returned something other than an
173
173
  * iterable of vgi-rpc `Protocol`s.
174
- * @throws Error A hosted protocol's name is invalid, reserved, `vgi.v2`'s, or
174
+ * @throws Error A hosted protocol's name is invalid, reserved, `vgi.v3`'s, or
175
175
  * repeated; the transport is unknown; or the worker supplies `resolveToken`
176
176
  * on HTTP with no introspector allowlist.
177
177
  */
@@ -12,7 +12,7 @@ export {
12
12
  batchToScalarDict,
13
13
  batchToSecretDict,
14
14
  safeNumber,
15
- decodeDictValue,
15
+ decodeDictValue, decodeMapValue,
16
16
  filterBatch,
17
17
  projectSchema,
18
18
  projectBatch,
@@ -0,0 +1,41 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // Per-output-row provenance wire encoding (batched correlated LATERAL): base64
3
+ // of a raw little-endian int32[] under `vgi_rpc.parent_row#b64`. Shared by the
4
+ // emit helper (functions/table-in-out.ts) and the auto-apply filter
5
+ // (filter-pushdown/collector.ts), which must drop the same rows from both.
6
+
7
+ /** Metadata key carrying per-output-row provenance: base64 of a raw
8
+ * little-endian int32[] mapping each output row to the input row that
9
+ * produced it. Shared by string with the C++ extension and vgi-python. */
10
+ export const PARENT_ROW_METADATA_KEY = "vgi_rpc.parent_row#b64";
11
+
12
+ /** Encode parent-row indices as the wire's base64 little-endian int32[]. */
13
+ export function encodeParentRows(parentRows: ArrayLike<number>): string {
14
+ const raw = new Uint8Array(parentRows.length * 4);
15
+ const dv = new DataView(raw.buffer);
16
+ for (let i = 0; i < parentRows.length; i++) {
17
+ dv.setInt32(i * 4, parentRows[i], true);
18
+ }
19
+ if (typeof (globalThis as any).Buffer !== "undefined") {
20
+ return (globalThis as any).Buffer.from(raw).toString("base64");
21
+ }
22
+ let bin = "";
23
+ for (let i = 0; i < raw.length; i++) bin += String.fromCharCode(raw[i]);
24
+ return (globalThis as any).btoa(bin);
25
+ }
26
+
27
+ /** Decode the wire's base64 little-endian int32[] back into parent-row indices. */
28
+ export function decodeParentRows(encoded: string): Int32Array {
29
+ let raw: Uint8Array;
30
+ if (typeof (globalThis as any).Buffer !== "undefined") {
31
+ raw = new Uint8Array((globalThis as any).Buffer.from(encoded, "base64"));
32
+ } else {
33
+ const bin = (globalThis as any).atob(encoded) as string;
34
+ raw = new Uint8Array(bin.length);
35
+ for (let i = 0; i < bin.length; i++) raw[i] = bin.charCodeAt(i);
36
+ }
37
+ const dv = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
38
+ const out = new Int32Array(raw.byteLength >> 2);
39
+ for (let i = 0; i < out.length; i++) out[i] = dv.getInt32(i * 4, true);
40
+ return out;
41
+ }
@@ -42,6 +42,9 @@ export {
42
42
  defineRowTransformFunction,
43
43
  parentRowsMetadata,
44
44
  PARENT_ROW_METADATA_KEY,
45
+ // Continued output: a table-in-out reply that says more follow, answered
46
+ // through the function's resume(). Composes with parentRowsMetadata.
47
+ moreOutputMetadata,
45
48
  // Encodes ArgumentConstraints into the discovery-facing ArgumentSpec fields.
46
49
  // The blended config has no `argConstraints` of its own, so a worker that
47
50
  // wants ge/le/choices/pattern on a row-transform's args applies them itself.
package/src/worker.ts CHANGED
@@ -282,7 +282,7 @@ export class Worker {
282
282
  }
283
283
 
284
284
  /**
285
- * Build the vgi-rpc server for one transport: `vgi.v2`, the worker's
285
+ * Build the vgi-rpc server for one transport: `vgi.v3`, the worker's
286
286
  * `hostedProtocols()` and reflection everywhere; identity on HTTP only. The
287
287
  * one construction path every transport uses (see `rpc-server.ts`).
288
288
  */