@query-farm/vgi 0.44.0 → 0.46.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 (73) hide show
  1. package/README.md +8 -1
  2. package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
  3. package/dist/arrow/impl-arrowjs/ipc.d.ts +6 -0
  4. package/dist/arrow/impl-flechette/build.d.ts +2 -2
  5. package/dist/arrow/impl-flechette/canonical.d.ts +2 -2
  6. package/dist/arrow/impl-flechette/index.d.ts +1 -1
  7. package/dist/arrow/impl-flechette/ipc.d.ts +6 -0
  8. package/dist/arrow/impl-flechette/schema.d.ts +19 -5
  9. package/dist/arrow/index.d.ts +1 -1
  10. package/dist/catalog/contents-codec.d.ts +7 -0
  11. package/dist/catalog/contents-digest.d.ts +2 -1
  12. package/dist/catalog/interface.d.ts +3 -0
  13. package/dist/catalog/publication-envelope.d.ts +1 -0
  14. package/dist/catalog/publication.d.ts +142 -0
  15. package/dist/catalog/s3-publication.d.ts +38 -0
  16. package/dist/client/client.d.ts +20 -1
  17. package/dist/client-entry.js +189 -37
  18. package/dist/client-entry.js.map +15 -12
  19. package/dist/codec/asd.d.ts +4 -0
  20. package/dist/functions/continuation.d.ts +69 -0
  21. package/dist/functions/table-in-out.d.ts +51 -7
  22. package/dist/functions/types.d.ts +20 -0
  23. package/dist/generated/vgi-client.d.ts +7 -14
  24. package/dist/generated/vgi-protocol-schemas.d.ts +2 -0
  25. package/dist/generated/vgi-protocol-types.d.ts +26 -3
  26. package/dist/generated/vgi-service.d.ts +3 -3
  27. package/dist/index.core.d.ts +1 -0
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.js +981 -138
  30. package/dist/index.js.map +31 -25
  31. package/dist/protocol/dispatch.d.ts +1 -1
  32. package/dist/protocol/handlers/catalog/contents.d.ts +4 -4
  33. package/dist/serve-entry.js +643 -81
  34. package/dist/serve-entry.js.map +22 -18
  35. package/dist/util/parent-rows.d.ts +8 -0
  36. package/dist/worker-cf-entry.d.ts +1 -1
  37. package/dist/worker-cf-entry.js +821 -131
  38. package/dist/worker-cf-entry.js.map +29 -24
  39. package/package.json +4 -4
  40. package/src/arrow/impl-arrowjs/index.ts +1 -0
  41. package/src/arrow/impl-arrowjs/ipc.ts +23 -0
  42. package/src/arrow/impl-flechette/build.ts +4 -2
  43. package/src/arrow/impl-flechette/canonical.ts +14 -7
  44. package/src/arrow/impl-flechette/index.ts +1 -0
  45. package/src/arrow/impl-flechette/ipc.ts +19 -0
  46. package/src/arrow/index.ts +1 -1
  47. package/src/catalog/contents-codec.ts +77 -0
  48. package/src/catalog/contents-digest.ts +20 -17
  49. package/src/catalog/interface.ts +3 -0
  50. package/src/catalog/publication-envelope.ts +62 -0
  51. package/src/catalog/publication.ts +290 -0
  52. package/src/catalog/read-only.ts +6 -2
  53. package/src/catalog/s3-publication.ts +81 -0
  54. package/src/client/client.ts +82 -30
  55. package/src/codec/asd.ts +40 -1
  56. package/src/codec/conform.ts +2 -1
  57. package/src/filter-pushdown/collector.ts +17 -1
  58. package/src/functions/continuation.ts +202 -0
  59. package/src/functions/table-in-out.ts +131 -56
  60. package/src/functions/types.ts +20 -0
  61. package/src/generated/vgi-client.ts +8 -16
  62. package/src/generated/vgi-protocol-schemas.ts +14 -6
  63. package/src/generated/vgi-protocol-types.ts +39 -5
  64. package/src/generated/vgi-service.ts +4 -3
  65. package/src/index.core.ts +6 -0
  66. package/src/index.ts +5 -0
  67. package/src/protocol/dispatch.ts +1 -1
  68. package/src/protocol/handlers/catalog/admin.ts +7 -4
  69. package/src/protocol/handlers/catalog/contents.ts +50 -35
  70. package/src/protocol/handlers/function.ts +12 -0
  71. package/src/protocol/state-serializer.ts +7 -1
  72. package/src/util/parent-rows.ts +41 -0
  73. package/src/worker-cf-entry.ts +3 -0
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_schemas. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: vgi-gen-ts-schemas v2
5
- // Content hash: 36a9087555c9
5
+ // Content hash: 31082ec470b8
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python vgi-gen-ts-schemas \
@@ -29,6 +29,9 @@ import {
29
29
  utf8,
30
30
  } from "../arrow/index.js";
31
31
 
32
+ /** Canonical fingerprint of the nested catalog wire schemas. */
33
+ export const VGI_CATALOG_CONTRACT_HASH = "0aa39285365f5f4326ce85c4d41d2705ea992dee41cf98d07640a2767b6ac3fb";
34
+
32
35
  // Origin: CatalogInfo
33
36
  export const CatalogInfoSchema = schema([
34
37
  field("name", utf8(), false),
@@ -43,7 +46,6 @@ export const CatalogInfoSchema = schema([
43
46
  export const SchemaInfoSchema = schema([
44
47
  field("comment", utf8(), true),
45
48
  field("tags", map(field("key", utf8(), false), field("value", utf8(), true), false), false),
46
- field("attach_opaque_data", binary(), false),
47
49
  field("path", list(field("item", utf8(), true)), false),
48
50
  field("estimated_object_count", map(field("key", utf8(), false), field("value", int64(), true), false), true),
49
51
  ]);
@@ -90,9 +92,9 @@ export const FunctionInfoSchema = schema([
90
92
  field("name", utf8(), false),
91
93
  field("schema_path", list(field("item", utf8(), true)), false),
92
94
  field("function_type", dictionary(utf8(), int16()), false),
93
- field("arguments", binary(), false),
94
- field("output_schema", binary(), false),
95
- field("parameter_default_values", binary(), true),
95
+ field("arguments", dictionary(binary(), int32()), false),
96
+ field("output_schema", dictionary(binary(), int32()), false),
97
+ field("parameter_default_values", dictionary(binary(), int32()), true),
96
98
  field("stability", dictionary(utf8(), int16()), true),
97
99
  field("null_handling", dictionary(utf8(), int16()), true),
98
100
  field("argument_monotonicity", list(field("item", utf8(), true)), true),
@@ -124,6 +126,7 @@ export const FunctionInfoSchema = schema([
124
126
  field("sink_order_dependent", bool(), false),
125
127
  field("requires_input_batch_index", bool(), false),
126
128
  field("input_from_args", bool(), false),
129
+ field("input_rows_per_call", int64(), true),
127
130
  field("required_settings", list(field("item", utf8(), true)), false),
128
131
  field("required_secrets", list(field("item", struct([field("secret_type", utf8(), false), field("scope", utf8(), true), field("secret_name", utf8(), true)]), true)), false),
129
132
  ]);
@@ -665,7 +668,12 @@ export const CatalogContentsResultSchema = schema([
665
668
  field("catalog_version", int64(), false),
666
669
  field("etag", utf8(), true),
667
670
  field("not_modified", bool(), false),
668
- field("schemas", list(field("item", struct([field("path", list(field("item", utf8(), true)), false), field("schema", binary(), false), field("tables", list(field("item", binary(), true)), false), field("views", list(field("item", binary(), true)), false), field("scalar_functions", list(field("item", binary(), true)), false), field("aggregate_functions", list(field("item", binary(), true)), false), field("table_functions", list(field("item", binary(), true)), false), field("scalar_macros", list(field("item", binary(), true)), false), field("table_macros", list(field("item", binary(), true)), false), field("indexes", list(field("item", binary(), true)), false)]), true)), false),
671
+ field("schemas", binary(), true),
672
+ field("tables", binary(), true),
673
+ field("views", binary(), true),
674
+ field("functions", binary(), true),
675
+ field("macros", binary(), true),
676
+ field("indexes", binary(), true),
669
677
  ]);
670
678
 
671
679
  // Origin: method 'catalog_copy_from_formats' result
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_types. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: python -m vgi.codegen.ts_types v1
5
- // Content hash: d240510f013b
5
+ // Content hash: 65401a7ca1e1
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python python scripts/regen_generated.py
@@ -14,8 +14,8 @@ import {
14
14
  CatalogContentsResultSchema,
15
15
  SchemaContentsSchema,
16
16
  } from "./vgi-protocol-schemas.js";
17
- import type { CatalogAttachResult, CatalogContentsResponse, SchemaContents } from "./vgi-client.js";
18
- export type { CatalogAttachResult, CatalogContentsResponse, SchemaContents };
17
+ import type { CatalogAttachResult, CatalogContentsResponse } from "./vgi-client.js";
18
+ export type { CatalogAttachResult, CatalogContentsResponse };
19
19
 
20
20
  // ----------------------------------------------------------------------------
21
21
  // CatalogAttachResult (schema: CatalogAttachResultSchema)
@@ -68,6 +68,30 @@ export const decodeCatalogAttachResult = (b: Uint8Array): CatalogAttachResult =>
68
68
  // SchemaContents (schema: SchemaContentsSchema)
69
69
  // ----------------------------------------------------------------------------
70
70
 
71
+ /** One schema and everything in it: one struct row of `CatalogContentsResponse.schemas`. Every item is byte-for-byte what the matching per-schema RPC returns in its `items` list, so a client decodes them with the decoders it already has. Each kind is complete: an empty list means the schema has none of that kind. */
72
+ export interface SchemaContents {
73
+ /** The schema path. Equals `SchemaInfo.path` inside `schema`, so a client can name the schema without decoding it. */
74
+ path: string[];
75
+ /** The schema's `SchemaInfo` item (a `catalog_schemas` entry). */
76
+ schema: Uint8Array;
77
+ /** `TableInfo` items (`catalog_schema_contents_tables`). */
78
+ tables: Uint8Array[];
79
+ /** `ViewInfo` items (`catalog_schema_contents_views`). */
80
+ views: Uint8Array[];
81
+ /** `FunctionInfo` items, `SCALAR_FUNCTION`. */
82
+ scalar_functions: Uint8Array[];
83
+ /** `FunctionInfo` items, `AGGREGATE_FUNCTION`. */
84
+ aggregate_functions: Uint8Array[];
85
+ /** `FunctionInfo` items, `TABLE_FUNCTION`. */
86
+ table_functions: Uint8Array[];
87
+ /** `MacroInfo` items, `SCALAR_MACRO`. */
88
+ scalar_macros: Uint8Array[];
89
+ /** `MacroInfo` items, `TABLE_MACRO`. */
90
+ table_macros: Uint8Array[];
91
+ /** `IndexInfo` items (`catalog_schema_contents_indexes`). */
92
+ indexes: Uint8Array[];
93
+ }
94
+
71
95
  /** Fields of `SchemaContents` that have a protocol default. */
72
96
  export type SchemaContentsDefaultedField =
73
97
  | "tables"
@@ -108,7 +132,12 @@ export const decodeSchemaContents = (b: Uint8Array): SchemaContents => decodeASD
108
132
  export type CatalogContentsResponseDefaultedField =
109
133
  | "etag"
110
134
  | "not_modified"
111
- | "schemas";
135
+ | "schemas"
136
+ | "tables"
137
+ | "views"
138
+ | "functions"
139
+ | "macros"
140
+ | "indexes";
112
141
  /** `CatalogContentsResponse` with every field that has a protocol default optional. */
113
142
  export type CatalogContentsResponseInit = Omit<CatalogContentsResponse, CatalogContentsResponseDefaultedField> & Partial<Pick<CatalogContentsResponse, CatalogContentsResponseDefaultedField>>;
114
143
 
@@ -118,7 +147,12 @@ export function buildCatalogContentsResponse(init: CatalogContentsResponseInit):
118
147
  catalog_version: init.catalog_version,
119
148
  etag: init.etag ?? null,
120
149
  not_modified: init.not_modified ?? false,
121
- schemas: init.schemas ?? [],
150
+ schemas: init.schemas ?? null,
151
+ tables: init.tables ?? null,
152
+ views: init.views ?? null,
153
+ functions: init.functions ?? null,
154
+ macros: init.macros ?? null,
155
+ indexes: init.indexes ?? null,
122
156
  };
123
157
  }
124
158
 
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_registry. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: python -m vgi.codegen.ts_registry v1
5
- // Content hash: 4cb38be76170
5
+ // Content hash: 56897005f0e2
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python python scripts/regen_generated.py
@@ -10,6 +10,7 @@
10
10
  import {
11
11
  type CallContext,
12
12
  type ExchangeFn,
13
+ type ExternalRef,
13
14
  type ExchangeInit,
14
15
  type HeaderInit,
15
16
  MethodNotImplementedError,
@@ -37,10 +38,10 @@ import {
37
38
  export const VGI_PROTOCOL_NAME = "vgi.v2";
38
39
 
39
40
  /** The protocol's semver, stamped on every request by a client of this protocol. */
40
- export const VGI_PROTOCOL_VERSION = "2.1.0";
41
+ export const VGI_PROTOCOL_VERSION = "2.2.0";
41
42
 
42
43
  /** What a unary handler returns: the result row, now or later. */
43
- export type VgiReply<T> = T | Promise<T>;
44
+ export type VgiReply<T> = T | ExternalRef | Promise<T | ExternalRef>;
44
45
 
45
46
  /** The result of a unary method with no `result` column. */
46
47
  export type NoResult = Record<string, never>;
package/src/index.core.ts CHANGED
@@ -52,6 +52,12 @@ export {
52
52
  type RowTransformConfig,
53
53
  type RowTransformProcessParams,
54
54
  } from "./functions/table-in-out.js";
55
+ export {
56
+ moreOutputMetadata,
57
+ STATUS_KEY,
58
+ HAVE_MORE_OUTPUT,
59
+ CONTINUE,
60
+ } from "./functions/continuation.js";
55
61
  export {
56
62
  defineTableBufferingFunction,
57
63
  type TableBufferingConfig,
package/src/index.ts CHANGED
@@ -9,3 +9,8 @@ export * from "./index.core.js";
9
9
 
10
10
  // Worker (node/bun only — stdio + AF_UNIX launcher transport)
11
11
  export { Worker, type WorkerConfig } from "./worker.js";
12
+
13
+ export { CatalogSnapshotManager, MemoryCatalogPublicationRepository, S3CatalogPublicationRepository } from "./catalog/publication.js";
14
+ export type { CatalogSnapshotPolicy, SnapshotIdentity, SnapshotRequest, CatalogPublicationManifest, CatalogPublicationRepository, CatalogManifestObjectStore } from "./catalog/publication.js";
15
+ export { S3CatalogObjectStorage } from "./catalog/s3-publication.js";
16
+ export type { CatalogS3Signer } from "./catalog/s3-publication.js";
@@ -69,7 +69,7 @@ export { VGI_PROTOCOL_NAME };
69
69
  * hash covers method names, types and the params/result/header schemas only
70
70
  * (WIRE_PROTOCOL.md §14).
71
71
  *
72
- * It changes only with vgi.v2's protocol version (currently 2.1.0). Asserted
72
+ * It changes only with vgi.v2's protocol version (currently 2.2.0). Asserted
73
73
  * by src/protocol/__tests__/vgi-v2-hash.test.ts; if that test fails, the
74
74
  * surface drifted from the reference -- fix the schemas, do not bump this.
75
75
  */
@@ -207,10 +207,13 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
207
207
  // the committed catalog at catalog_version. `if_none_match` revalidates a
208
208
  // snapshot the client holds (etag / not_modified); see ./contents.ts for the
209
209
  // rules, the content-hash etag and the frozen-catalog cache.
210
- const catalogContents = catalogHandler(signingKey, async (params) => {
211
- const ifNoneMatch = params.if_none_match == null ? null : String(params.if_none_match);
212
- return serveCatalogContents(getCatalog(), toUint8Array(params.attach_opaque_data), ifNoneMatch);
213
- });
210
+ const catalogContents: VgiService["catalogContents"] = async (params, ctx) => {
211
+ const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
212
+ return catalogHandler(signingKey, async (opened, context) => {
213
+ const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
214
+ return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
215
+ })(params, ctx);
216
+ };
214
217
 
215
218
  // catalog_copy_from_formats — catalog-level (not schema-scoped). Lists the
216
219
  // custom COPY ... FROM formats this catalog advertises; empty list when none.
@@ -1,31 +1,24 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
2
  // SPDX-License-Identifier: LicenseRef-QueryFarm-Source-Available-1.0
3
3
 
4
- // catalog_contents: the worker side of the protocol 2.1.0 bulk enumeration,
4
+ // catalog_contents: the worker side of the wire 2.2 bulk enumeration,
5
5
  // with etag revalidation and the frozen-catalog response cache. Mirrors
6
6
  // vgi-python's Worker.catalog_contents / _catalog_contents_response.
7
7
 
8
- import {
9
- encodeSchemaInfo,
10
- encodeTableInfo,
11
- encodeViewInfo,
12
- encodeMacroInfo,
13
- encodeIndexInfo,
14
- } from "../../../generated/vgi-client.js";
15
8
  import {
16
9
  buildCatalogContentsResponse,
17
- buildSchemaContents,
18
10
  type CatalogContentsResponse,
19
- type SchemaContents,
20
11
  } from "../../../generated/vgi-protocol-types.js";
12
+ import { ExternalRef, type CallContext } from "@query-farm/vgi-rpc";
13
+ import { CatalogSnapshotManager, type CatalogSnapshotPolicy } from "../../../catalog/publication.js";
21
14
  import { CatalogContentsResultSchema } from "../../../generated/vgi-protocol-schemas.js";
22
- import { encodeFunctionInfoOnce } from "../../../catalog/item-encoding.js";
15
+ import { encodeCatalogStreams, decodeCatalogStreams } from "../../../catalog/contents-codec.js";
23
16
  import type { AttachOpaqueData, CatalogInterface } from "../../../catalog/interface.js";
24
17
  import { catalogContentsDigest } from "../../../catalog/contents-digest.js";
25
- import { schemaPathKey } from "../../../schema-path.js";
26
18
  import { wrapResult } from "../shared.js";
27
19
 
28
20
  type Wire = { result: Uint8Array };
21
+ const schemaPathKey = (path: readonly string[]) => JSON.stringify(path.map((part) => part.toLowerCase()));
29
22
 
30
23
  /** One cached answer per catalog instance, valid for one catalog version. */
31
24
  interface ContentsSnapshot {
@@ -39,6 +32,8 @@ interface ContentsSnapshot {
39
32
  * (weak, so a dropped catalog takes its snapshot with it). Holds the build
40
33
  * promise, so concurrent first calls build once.
41
34
  */
35
+ const PUBLICATIONS = new WeakMap<CatalogSnapshotPolicy, CatalogSnapshotManager>();
36
+
42
37
  const CACHE = new WeakMap<CatalogInterface, Promise<ContentsSnapshot>>();
43
38
 
44
39
  /**
@@ -47,9 +42,8 @@ const CACHE = new WeakMap<CatalogInterface, Promise<ContentsSnapshot>>();
47
42
  * Enforces the revalidation rules: `not_modified` needs an etag equal to
48
43
  * `ifNoneMatch` and no schemas; a catalog with no etag never yields
49
44
  * `not_modified` (and so ignores `ifNoneMatch`). Validates the schema paths
50
- * (unique, parent present) and orders them parent-first. Every item is
51
- * encoded with the SAME encoder its per-schema RPC uses, so items are
52
- * byte-identical to catalog_schemas / catalog_schema_contents_* items.
45
+ * (unique, parent present) and orders them parent-first. The six collection
46
+ * streams retain the fields used by the existing per-schema RPC metadata.
53
47
  */
54
48
  export async function buildCatalogContents(
55
49
  cat: CatalogInterface,
@@ -83,31 +77,17 @@ export async function buildCatalogContents(
83
77
  }
84
78
  }
85
79
 
86
- // Same parent-before-child order catalog_schemas guarantees (stable sort).
87
- const schemas: SchemaContents[] = infos
88
- .sort((a, b) => a.schema.path.length - b.schema.path.length)
89
- .map((c) =>
90
- buildSchemaContents({
91
- path: [...c.schema.path],
92
- schema: encodeSchemaInfo(c.schema),
93
- tables: c.tables.map((t) => encodeTableInfo(t)),
94
- views: c.views.map((v) => encodeViewInfo(v)),
95
- scalar_functions: c.scalar_functions.map((f) => encodeFunctionInfoOnce(f)),
96
- aggregate_functions: c.aggregate_functions.map((f) => encodeFunctionInfoOnce(f)),
97
- table_functions: c.table_functions.map((f) => encodeFunctionInfoOnce(f)),
98
- scalar_macros: c.scalar_macros.map((m) => encodeMacroInfo(m)),
99
- table_macros: c.table_macros.map((m) => encodeMacroInfo(m)),
100
- indexes: c.indexes.map((i) => encodeIndexInfo(i)),
101
- }),
102
- );
80
+ const streams = encodeCatalogStreams(infos.sort((a, b) => a.schema.path.length - b.schema.path.length));
103
81
  let etag = etag0;
104
82
  if (etag === null && owner.catalogContentsEtag === "content-hash") {
105
- etag = await catalogContentsDigest(schemas);
83
+ etag = await catalogContentsDigest(streams, version);
106
84
  }
107
85
  if (etag !== null && ifNoneMatch !== null && etag === ifNoneMatch) {
108
86
  return buildCatalogContentsResponse({ catalog_version: version, etag, not_modified: true });
109
87
  }
110
- return buildCatalogContentsResponse({ catalog_version: version, etag, schemas });
88
+ const response = buildCatalogContentsResponse({ catalog_version: version, etag, ...streams });
89
+ decodeCatalogStreams(response);
90
+ return response;
111
91
  }
112
92
 
113
93
  /**
@@ -123,9 +103,44 @@ export async function serveCatalogContents(
123
103
  cat: CatalogInterface,
124
104
  attach: AttachOpaqueData,
125
105
  ifNoneMatch: string | null,
126
- ): Promise<Wire> {
106
+ callContext?: CallContext,
107
+ sealedAttach: Uint8Array = attach,
108
+ ): Promise<Wire | ExternalRef> {
127
109
  const owner = cat.catalogContentsOwner(attach);
128
110
  const version = Number(await cat.version(attach));
111
+ const policy = owner.catalogSnapshotPolicy;
112
+ if (policy?.delivery === "published") {
113
+ const request = { catalog: cat, attachOpaqueData: attach, callContext, catalogVersion: version };
114
+ const inline = (etag: string) => wrapResult(buildCatalogContentsResponse({ catalog_version: version, etag, not_modified: true }), CatalogContentsResultSchema);
115
+ const cheapEtag = await policy.etag?.(request);
116
+ if (cheapEtag != null && cheapEtag === ifNoneMatch) return inline(cheapEtag);
117
+ let manager = PUBLICATIONS.get(policy);
118
+ if (!manager) { manager = new CatalogSnapshotManager(policy); PUBLICATIONS.set(policy, manager); }
119
+ const scopeBytes = new Uint8Array(await crypto.subtle.digest("SHA-256", sealedAttach as BufferSource));
120
+ const attachmentScope = "attachment:" + Array.from(scopeBytes, (b) => b.toString(16).padStart(2, "0")).join("");
121
+ const identify = async (input: typeof request) => { const id = await policy.identity(input); return { ...id, visibilityScope: id.visibilityScope ?? attachmentScope }; };
122
+ const identity = await identify(request);
123
+ if (identity.catalogVersion !== version) throw new Error("snapshot identity version differs from the attached catalog");
124
+ const assertCurrentIdentity = async () => {
125
+ const currentVersion = Number(await cat.version(attach));
126
+ const current = await identify({ ...request, catalogVersion: currentVersion });
127
+ if (currentVersion !== version || await manager!.key(identity) !== await manager!.key(current)) throw new Error("catalog changed while resolving its publication");
128
+ };
129
+ const buildSnapshot = async (validator: string | null) => {
130
+ const response = await buildCatalogContents(cat, owner, attach, version, validator);
131
+ await assertCurrentIdentity();
132
+ return response;
133
+ };
134
+ try {
135
+ const manifest = await manager.warm(identity, () => buildSnapshot(null));
136
+ await assertCurrentIdentity();
137
+ if (manifest.etag === ifNoneMatch) return inline(manifest.etag);
138
+ return new ExternalRef(manifest.url, manifest.sha256);
139
+ } catch (error) {
140
+ if (policy.onPublicationFailure !== "ordinary") throw error;
141
+ return wrapResult(await buildSnapshot(ifNoneMatch), CatalogContentsResultSchema);
142
+ }
143
+ }
129
144
  if (owner.catalogContentsCacheable()) {
130
145
  let pending = CACHE.get(owner);
131
146
  let snapshot = pending ? await pending.catch(() => null) : null;
@@ -8,6 +8,7 @@ import type { AuthContext } from "@query-farm/vgi-rpc";
8
8
  import { exchangeStream, type VgiService } from "../../generated/vgi-service.js";
9
9
  import type { FunctionRegistry } from "../../functions/registry.js";
10
10
  import type { StreamHandlers, HandlerState } from "../../functions/types.js";
11
+ import { refuseMoreOutput } from "../../functions/continuation.js";
11
12
  import {
12
13
  deserializeBindRequest,
13
14
  serializeBindResponse,
@@ -410,6 +411,11 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
410
411
  if (state.userState != null && handlerState?.state !== undefined) {
411
412
  handlerState!.state = state.userState;
412
413
  }
414
+ // Whether the last reply said more, so only a continuation tick is
415
+ // valid now (functions/continuation.ts).
416
+ if (handlers.continuesOutput) {
417
+ handlerState!.morePending = state.morePending === true;
418
+ }
413
419
  }
414
420
 
415
421
  if (state.isProducer && handlers.producerFn) {
@@ -427,6 +433,11 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
427
433
  } else if (handlers.exchangeFn) {
428
434
  await handlers.exchangeFn(handlerState, input, out);
429
435
  }
436
+ // Only a table-in-out exchange can continue its output; anywhere else
437
+ // the client would never send the tick.
438
+ if (!handlers.continuesOutput) {
439
+ refuseMoreOutput(state.functionName, out);
440
+ }
430
441
 
431
442
  // Save mutated user state for the next exchange round
432
443
  if (handlerState?.state !== undefined) {
@@ -435,6 +446,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
435
446
  // And the dynamic-filter history this turn left (compacted: bounded by
436
447
  // the number of predicate ids, not the number of turns).
437
448
  state.filterHistory = handlerState?.filterHistory ?? null;
449
+ state.morePending = handlerState?.morePending === true;
438
450
  },
439
451
  headerInit: (params: any, state: any, ctx: any) => {
440
452
  // During init, _initResponse is still in memory.
@@ -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
  };
@@ -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.