@query-farm/vgi 0.47.1 → 0.48.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 (58) hide show
  1. package/README.md +1 -1
  2. package/dist/catalog/column-expressions.d.ts +22 -1
  3. package/dist/catalog/column-metadata.d.ts +7 -0
  4. package/dist/catalog/column-types.d.ts +15 -0
  5. package/dist/catalog/composite.d.ts +2 -0
  6. package/dist/catalog/constraints.d.ts +110 -12
  7. package/dist/catalog/descriptors.d.ts +19 -1
  8. package/dist/catalog/indexes.d.ts +29 -0
  9. package/dist/catalog/interface.d.ts +41 -0
  10. package/dist/catalog/public-codecs.d.ts +6 -0
  11. package/dist/catalog/read-only.d.ts +3 -0
  12. package/dist/catalog/sql-grammar.d.ts +53 -0
  13. package/dist/catalog/unconstrained-columns.d.ts +8 -0
  14. package/dist/client/types.d.ts +5 -1
  15. package/dist/client-entry.d.ts +1 -0
  16. package/dist/client-entry.js +1435 -152
  17. package/dist/client-entry.js.map +15 -11
  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/index.core.d.ts +3 -1
  23. package/dist/index.js +1940 -545
  24. package/dist/index.js.map +26 -22
  25. package/dist/protocol/dispatch.d.ts +1 -1
  26. package/dist/protocol/serializers/splits.d.ts +41 -1
  27. package/dist/serve-entry.js +1172 -58
  28. package/dist/serve-entry.js.map +20 -17
  29. package/dist/worker-cf-entry.d.ts +2 -1
  30. package/dist/worker-cf-entry.js +1538 -191
  31. package/dist/worker-cf-entry.js.map +26 -22
  32. package/package.json +1 -1
  33. package/src/catalog/column-expressions.ts +85 -7
  34. package/src/catalog/column-metadata.ts +20 -2
  35. package/src/catalog/column-types.ts +50 -0
  36. package/src/catalog/composite.ts +10 -0
  37. package/src/catalog/constraints.ts +496 -58
  38. package/src/catalog/contents-codec.ts +3 -3
  39. package/src/catalog/descriptors.ts +19 -1
  40. package/src/catalog/indexes.ts +59 -0
  41. package/src/catalog/interface.ts +103 -1
  42. package/src/catalog/public-codecs.ts +36 -0
  43. package/src/catalog/read-only.ts +92 -36
  44. package/src/catalog/sql-grammar.ts +476 -0
  45. package/src/catalog/unconstrained-columns.ts +34 -8
  46. package/src/client/client.ts +6 -3
  47. package/src/client/types.ts +5 -1
  48. package/src/client-entry.ts +4 -0
  49. package/src/generated/vgi-client.ts +6 -1
  50. package/src/generated/vgi-protocol-schemas.ts +36 -1
  51. package/src/generated/vgi-protocol-types.ts +130 -1
  52. package/src/generated/vgi-service.ts +2 -2
  53. package/src/index.core.ts +34 -1
  54. package/src/protocol/dispatch.ts +1 -1
  55. package/src/protocol/handlers/catalog/admin.ts +14 -13
  56. package/src/protocol/handlers/catalog/table.ts +58 -11
  57. package/src/protocol/serializers/splits.ts +82 -9
  58. package/src/worker-cf-entry.ts +2 -4
@@ -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: e3a5ddf92639
5
+ // Content hash: 50667b91293f
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python python scripts/regen_generated.py
@@ -24,9 +24,11 @@ import {
24
24
  ConstraintSnapshotSchema,
25
25
  ConstraintsApplyRequestSchema,
26
26
  DependencySnapshotSchema,
27
+ FieldPathSchema,
27
28
  ForeignKeyDefinitionSchema,
28
29
  IndexDefinitionSchema,
29
30
  IndexKeySchema,
31
+ KeyGroupingSchema,
30
32
  MacroOverloadSchema,
31
33
  MacroParameterSchema,
32
34
  ObjectDependencySchema,
@@ -36,6 +38,8 @@ import {
36
38
  QueryCapabilitiesSchema,
37
39
  QueryEvaluationContextSchema,
38
40
  QueryObjectReferenceSchema,
41
+ RangeKeySchema,
42
+ RangePartitioningSchema,
39
43
  RequiredFilterPathsSchema,
40
44
  SchemaContentsSchema,
41
45
  SortKeySchema,
@@ -43,10 +47,135 @@ import {
43
47
  SqlStatementSchema,
44
48
  TableLayoutChangeSchema,
45
49
  TableLayoutSchema,
50
+ TransformSpecSchema,
46
51
  } from "./vgi-protocol-schemas.js";
47
52
  import type { CatalogAttachResult, CatalogCapabilities, CatalogContentsResponse, CatalogObjectRef, CatalogQueryPrepareRequest, CatalogQueryPrepareResult, ClientQueryCapabilities, ConstraintSnapshot, ConstraintsApplyRequest, DependencySnapshot, IndexDefinition, MacroOverload, MacroParameter, OptionDefinitions, OptionState, QueryCapabilities, QueryEvaluationContext, QueryObjectReference, SqlExpression, TableLayout } from "./vgi-client.js";
48
53
  export type { CatalogAttachResult, CatalogCapabilities, CatalogContentsResponse, CatalogObjectRef, CatalogQueryPrepareRequest, CatalogQueryPrepareResult, ClientQueryCapabilities, ConstraintSnapshot, ConstraintsApplyRequest, DependencySnapshot, IndexDefinition, MacroOverload, MacroParameter, OptionDefinitions, OptionState, QueryCapabilities, QueryEvaluationContext, QueryObjectReference, SqlExpression, TableLayout };
49
54
 
55
+ // ----------------------------------------------------------------------------
56
+ // FieldPath (schema: FieldPathSchema)
57
+ // ----------------------------------------------------------------------------
58
+
59
+ /** One raw, component-preserving field reference used by a transform. */
60
+ export interface FieldPath {
61
+ components: string[];
62
+ }
63
+
64
+ /** `FieldPath` has no defaulted fields, so its init is the record itself. */
65
+ export type FieldPathInit = FieldPath;
66
+
67
+ /** Build a complete `FieldPath`, filling the protocol defaults, in wire order. */
68
+ export function buildFieldPath(init: FieldPathInit): FieldPath {
69
+ return {
70
+ components: init.components,
71
+ };
72
+ }
73
+
74
+ export const encodeFieldPath = (v: FieldPath): Uint8Array => encodeASD(FieldPathSchema, v);
75
+ export const decodeFieldPath = (b: Uint8Array): FieldPath => decodeASD<FieldPath>(FieldPathSchema, b);
76
+
77
+ // ----------------------------------------------------------------------------
78
+ // TransformSpec (schema: TransformSpecSchema)
79
+ // ----------------------------------------------------------------------------
80
+
81
+ /** A versioned, registry-defined partition transform. `id` identifies normative semantics (for example `vgi.identity/1` or `iceberg.bucket/1`). `inputs` contains serialized :class:`FieldPath` records. `parameters` is either absent or a one-row Arrow batch, which permits any number of named, typed parameters without admitting arbitrary recursive expressions. */
82
+ export interface TransformSpec {
83
+ id: string;
84
+ inputs: Uint8Array[];
85
+ parameters?: Uint8Array | null;
86
+ }
87
+
88
+ /** Fields of `TransformSpec` that have a protocol default. */
89
+ export type TransformSpecDefaultedField =
90
+ | "inputs"
91
+ | "parameters";
92
+ /** `TransformSpec` with every field that has a protocol default optional. */
93
+ export type TransformSpecInit = Omit<TransformSpec, TransformSpecDefaultedField> & Partial<Pick<TransformSpec, TransformSpecDefaultedField>>;
94
+
95
+ /** Build a complete `TransformSpec`, filling the protocol defaults, in wire order. */
96
+ export function buildTransformSpec(init: TransformSpecInit): TransformSpec {
97
+ return {
98
+ id: init.id,
99
+ inputs: init.inputs ?? [],
100
+ parameters: init.parameters ?? null,
101
+ };
102
+ }
103
+
104
+ export const encodeTransformSpec = (v: TransformSpec): Uint8Array => encodeASD(TransformSpecSchema, v);
105
+ export const decodeTransformSpec = (b: Uint8Array): TransformSpec => decodeASD<TransformSpec>(TransformSpecSchema, b);
106
+
107
+ // ----------------------------------------------------------------------------
108
+ // KeyGrouping (schema: KeyGroupingSchema)
109
+ // ----------------------------------------------------------------------------
110
+
111
+ /** Transforms whose exact result tuple is constant within every split. */
112
+ export interface KeyGrouping {
113
+ keys: Uint8Array[];
114
+ }
115
+
116
+ /** `KeyGrouping` has no defaulted fields, so its init is the record itself. */
117
+ export type KeyGroupingInit = KeyGrouping;
118
+
119
+ /** Build a complete `KeyGrouping`, filling the protocol defaults, in wire order. */
120
+ export function buildKeyGrouping(init: KeyGroupingInit): KeyGrouping {
121
+ return {
122
+ keys: init.keys,
123
+ };
124
+ }
125
+
126
+ export const encodeKeyGrouping = (v: KeyGrouping): Uint8Array => encodeASD(KeyGroupingSchema, v);
127
+ export const decodeKeyGrouping = (b: Uint8Array): KeyGrouping => decodeASD<KeyGrouping>(KeyGroupingSchema, b);
128
+
129
+ // ----------------------------------------------------------------------------
130
+ // RangeKey (schema: RangeKeySchema)
131
+ // ----------------------------------------------------------------------------
132
+
133
+ /** One transform and comparator component of a range key. */
134
+ export interface RangeKey {
135
+ transform: Uint8Array;
136
+ direction: string;
137
+ null_order: string;
138
+ }
139
+
140
+ /** `RangeKey` has no defaulted fields, so its init is the record itself. */
141
+ export type RangeKeyInit = RangeKey;
142
+
143
+ /** Build a complete `RangeKey`, filling the protocol defaults, in wire order. */
144
+ export function buildRangeKey(init: RangeKeyInit): RangeKey {
145
+ return {
146
+ transform: init.transform,
147
+ direction: init.direction,
148
+ null_order: init.null_order,
149
+ };
150
+ }
151
+
152
+ export const encodeRangeKey = (v: RangeKey): Uint8Array => encodeASD(RangeKeySchema, v);
153
+ export const decodeRangeKey = (b: Uint8Array): RangeKey => decodeASD<RangeKey>(RangeKeySchema, b);
154
+
155
+ // ----------------------------------------------------------------------------
156
+ // RangePartitioning (schema: RangePartitioningSchema)
157
+ // ----------------------------------------------------------------------------
158
+
159
+ /** Exact half-open range distribution shared by all splits in a plan. `N` split-point rows define `N + 1` ranges. Values equal to point `i` belong to range `i + 1`. Each split names its range with :attr:`ScanSplit.range_index`. */
160
+ export interface RangePartitioning {
161
+ keys: Uint8Array[];
162
+ split_points: Uint8Array;
163
+ }
164
+
165
+ /** `RangePartitioning` has no defaulted fields, so its init is the record itself. */
166
+ export type RangePartitioningInit = RangePartitioning;
167
+
168
+ /** Build a complete `RangePartitioning`, filling the protocol defaults, in wire order. */
169
+ export function buildRangePartitioning(init: RangePartitioningInit): RangePartitioning {
170
+ return {
171
+ keys: init.keys,
172
+ split_points: init.split_points,
173
+ };
174
+ }
175
+
176
+ export const encodeRangePartitioning = (v: RangePartitioning): Uint8Array => encodeASD(RangePartitioningSchema, v);
177
+ export const decodeRangePartitioning = (b: Uint8Array): RangePartitioning => decodeASD<RangePartitioning>(RangePartitioningSchema, b);
178
+
50
179
  // ----------------------------------------------------------------------------
51
180
  // MacroParameter (schema: MacroParameterSchema)
52
181
  // ----------------------------------------------------------------------------
@@ -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: 67bb72c77d62
5
+ // Content hash: d92d651266e2
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python python scripts/regen_generated.py
@@ -38,7 +38,7 @@ import {
38
38
  export const VGI_PROTOCOL_NAME = "vgi.v3";
39
39
 
40
40
  /** The protocol's semver, stamped on every request by a client of this protocol. */
41
- export const VGI_PROTOCOL_VERSION = "3.0.0";
41
+ export const VGI_PROTOCOL_VERSION = "3.1.0";
42
42
 
43
43
  /** What a unary handler returns: the result row, now or later. */
44
44
  export type VgiReply<T> = T | ExternalRef | Promise<T | ExternalRef>;
package/src/index.core.ts CHANGED
@@ -86,7 +86,8 @@ export type { VgiFunction, FunctionMeta, StreamHandlers, FunctionExample, Handle
86
86
  export { CatalogInterface, type CatalogAttachResult, type CatalogAttachResultInit, buildCatalogAttachResult, type SchemaContentsInfo, type CatalogContentsResult, type SchemaInfo, encodeSchemaInfo, decodeSchemaInfo, type TableInfo, encodeTableInfo, decodeTableInfo, type ViewInfo, encodeViewInfo, decodeViewInfo, type CatalogInfo, encodeCatalogInfo, decodeCatalogInfo, type FunctionInfo, encodeFunctionInfo, decodeFunctionInfo, type FunctionInfoOptions, type MacroInfo, encodeMacroInfo, decodeMacroInfo, type MacroType, type CopyFromFormatInfo, encodeCopyFromFormatInfo, type AttachOpaqueData, type TransactionOpaqueData, buildScanBranchesResult, encodeFormatOptions, type ScanBranchInput } from "./catalog/interface.js";
87
87
  export type { CatalogDescriptor, SchemaDescriptor, TableDescriptor, ViewDescriptor, MacroDescriptor, SettingDescriptor, SecretTypeDescriptor, ForeignKeyDef, DefaultValue } from "./catalog/descriptors.js";
88
88
  export { ReadOnlyCatalogInterface, READ_ONLY_ITEM_ATTACH_ID } from "./catalog/read-only.js";
89
- export { constraintRecord, readConstraintRecord, validateConstraintNullability, selectReadProfiles, CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION, type ConstraintRecordSpec, type ConstraintRecordView, type ConstraintKind, type ConstraintEnforcement, type ConstraintValidation } from "./catalog/constraints.js";
89
+ // vgi.v3 records: constraints, capabilities, column expressions, indexes, macro overloads.
90
+ export * from "./catalog/public-codecs.js";
90
91
  export { CompositeCatalogInterface } from "./catalog/composite.js";
91
92
  export { FunctionRegistry } from "./functions/registry.js";
92
93
 
@@ -114,6 +115,38 @@ export type {
114
115
  GlobalInitResponse,
115
116
  TableCardinality,
116
117
  } from "./protocol/types.js";
118
+ export type {
119
+ ScanSplit,
120
+ PlanResult,
121
+ TableFunctionPlanRequest,
122
+ } from "./protocol/serializers/splits.js";
123
+ export {
124
+ type FieldPath,
125
+ type FieldPathInit,
126
+ buildFieldPath,
127
+ encodeFieldPath,
128
+ decodeFieldPath,
129
+ type TransformSpec,
130
+ type TransformSpecInit,
131
+ buildTransformSpec,
132
+ encodeTransformSpec,
133
+ decodeTransformSpec,
134
+ type KeyGrouping,
135
+ type KeyGroupingInit,
136
+ buildKeyGrouping,
137
+ encodeKeyGrouping,
138
+ decodeKeyGrouping,
139
+ type RangeKey,
140
+ type RangeKeyInit,
141
+ buildRangeKey,
142
+ encodeRangeKey,
143
+ decodeRangeKey,
144
+ type RangePartitioning,
145
+ type RangePartitioningInit,
146
+ buildRangePartitioning,
147
+ encodeRangePartitioning,
148
+ decodeRangePartitioning,
149
+ } from "./generated/vgi-protocol-types.js";
117
150
 
118
151
  // Arguments
119
152
  export { Arguments } from "./arguments/arguments.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.v3's protocol version (currently 3.0.0). Asserted
72
+ * It changes only with vgi.v3's protocol version (currently 3.1.0). Asserted
73
73
  * by src/protocol/__tests__/vgi-v3-hash.test.ts; if that test fails, the
74
74
  * surface drifted from the reference -- fix the schemas, do not bump this.
75
75
  */
@@ -14,7 +14,7 @@ import {
14
14
  encodeCatalogInfo,
15
15
  } from "../../../generated/vgi-client.js";
16
16
  import { buildCatalogAttachResult, decodeCatalogCapabilities, encodeCatalogCapabilities } from "../../../generated/vgi-protocol-types.js";
17
- import { selectReadProfiles } from "../../../catalog/constraints.js";
17
+ import { capabilitiesEmpty, catalogCapabilities, selectCatalogCapabilities } from "../../../catalog/constraints.js";
18
18
  import { serveCatalogContents } from "./contents.js";
19
19
  import { encodeFunctionInfoOnce } from "../../../catalog/item-encoding.js";
20
20
  import { encodeCopyFromFormatInfo } from "../../../catalog/interface.js";
@@ -104,18 +104,19 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
104
104
  innerParams.implementation_version ?? null,
105
105
  clientCapabilities,
106
106
  );
107
- // Select the client-offered read profiles here, from the request itself
108
- // (as vgi-python's worker does), so a catalog whose attach() override
109
- // drops the clientCapabilities argument still negotiates what it serves.
110
- if (result.catalog_capabilities != null) {
111
- const available = decodeCatalogCapabilities(toUint8Array(result.catalog_capabilities));
112
- const chosen = result.selected_capabilities == null
113
- ? { read: [], ddl: [], write: [], transaction: [] }
114
- : decodeCatalogCapabilities(toUint8Array(result.selected_capabilities));
115
- result.selected_capabilities = encodeCatalogCapabilities({
116
- ...chosen,
117
- read: selectReadProfiles(available.read, clientCapabilities),
118
- });
107
+ // Advertise and select catalog profiles here, from the request itself (as
108
+ // vgi-python's worker does), so a catalog whose attach() override drops
109
+ // the clientCapabilities argument still negotiates what it serves. A
110
+ // catalog that leaves catalog_capabilities unset advertises
111
+ // catalogCapabilities() (records, mutation, enforcement, ...).
112
+ const advertised = result.catalog_capabilities != null
113
+ ? decodeCatalogCapabilities(toUint8Array(result.catalog_capabilities))
114
+ : await cat.catalogCapabilities(toUint8Array(result.attach_opaque_data));
115
+ if (!capabilitiesEmpty(advertised)) {
116
+ result.catalog_capabilities = encodeCatalogCapabilities(catalogCapabilities(advertised!));
117
+ result.selected_capabilities = encodeCatalogCapabilities(
118
+ selectCatalogCapabilities(advertised!, clientCapabilities, result.supports_transactions ?? false),
119
+ );
119
120
  }
120
121
  // Seal the attach value into an AEAD envelope bound to the caller's
121
122
  // identity before it leaves the worker (HTTP transport; pass-through
@@ -7,12 +7,15 @@ import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
7
7
 
8
8
  import type { VgiService } from "../../../generated/vgi-service.js";
9
9
  import {
10
+ CatalogTableConstraintsApplyResultSchema,
10
11
  CatalogTableGetResultSchema,
11
12
  ScanBranchesResultSchema,
12
13
  ScanFunctionResultSchema,
13
14
  } from "../../../generated/vgi-protocol-schemas.js";
14
15
  import { toUint8Array } from "../../../util/bytes.js";
15
- import { requireUnconstrainedColumns } from "../../../catalog/unconstrained-columns.js";
16
+ import { requireCreateColumns } from "../../../catalog/unconstrained-columns.js";
17
+ import { CONSTRAINT_CREATE, CONSTRAINT_ENFORCE, CONSTRAINT_MUTATE, readConstraintRecord } from "../../../catalog/constraints.js";
18
+ import { decodeCatalogObjectRef } from "../../../generated/vgi-protocol-types.js";
16
19
  import {
17
20
  wrapResult,
18
21
  } from "../shared.js";
@@ -52,28 +55,74 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
52
55
  // catalog_table_create
53
56
  const catalogTableCreate = catalogHandler(signingKey, async (params) => {
54
57
  if (params.constraint_definitions == null) throw new Error("constraint_definitions is required");
55
- if (Array.from(params.constraint_definitions as Iterable<unknown>).length > 0) {
56
- throw new MethodNotImplementedError("catalog_table_create: canonical constraint enforcement is not supported");
57
- }
58
+ const definitions = Array.from(params.constraint_definitions as Iterable<unknown>, (d) => toUint8Array(d as Uint8Array));
58
59
  if (params.comment != null || params.tags != null || params.options != null || params.layout != null) {
59
60
  throw new MethodNotImplementedError("catalog_table_create: table metadata/options/layout profiles are not supported");
60
61
  }
62
+ const attach = toUint8Array(params.attach_opaque_data);
63
+ const cat = getCatalog();
64
+ if (definitions.length > 0) {
65
+ // DuckDB sends definitions only under a negotiated create profile; refuse
66
+ // here too when the catalog states it does not implement one.
67
+ const caps = await cat.catalogCapabilities(attach);
68
+ if (caps != null && !(caps.ddl.includes(CONSTRAINT_CREATE) && caps.write.includes(CONSTRAINT_ENFORCE))) {
69
+ throw new MethodNotImplementedError(
70
+ "catalog_table_create: this catalog does not enforce constraints (NOT NULL, PRIMARY KEY, UNIQUE, CHECK, " +
71
+ "FOREIGN KEY); it advertises neither vgi.constraint.create.v1 nor vgi.constraint.enforce.v1",
72
+ );
73
+ }
74
+ }
61
75
  validateColumnMetadataIpc(toUint8Array(params.columns));
62
76
  validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
63
- requireUnconstrainedColumns(toUint8Array(params.columns));
64
- const cat = getCatalog();
77
+ requireCreateColumns(toUint8Array(params.columns), definitions);
65
78
  await cat.tableCreate(
66
- toUint8Array(params.attach_opaque_data),
79
+ attach,
67
80
  params.schema_path,
68
81
  params.name,
69
82
  toUint8Array(params.columns),
70
83
  params.on_conflict,
71
- [],
84
+ definitions,
72
85
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
73
86
  );
74
87
  return {};
75
88
  });
76
89
 
90
+ // catalog_table_constraints_apply (ALTER TABLE ... SET/DROP NOT NULL and
91
+ // every other canonical constraint change).
92
+ const catalogTableConstraintsApply = catalogHandler(signingKey, async (params) => {
93
+ const attach = toUint8Array(params.attach_opaque_data);
94
+ const cat = getCatalog();
95
+ const caps = await cat.catalogCapabilities(attach);
96
+ if (caps != null && !caps.ddl.includes(CONSTRAINT_MUTATE)) {
97
+ throw new MethodNotImplementedError("catalog_table_constraints_apply: this catalog does not advertise vgi.constraint.mutate.v1");
98
+ }
99
+ const table = toUint8Array(params.table);
100
+ const expected = toUint8Array(params.expected_revision);
101
+ const changes = Array.from(params.changes as Iterable<unknown>, (c) => toUint8Array(c as Uint8Array));
102
+ if (expected.length === 0 || changes.length === 0) throw new Error("catalog_table_constraints_apply: empty revision or change list");
103
+ const snapshot = await cat.tableConstraintsApply({
104
+ attach_opaque_data: attach,
105
+ table,
106
+ expected_revision: expected,
107
+ changes,
108
+ transaction_opaque_data: params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : null,
109
+ });
110
+ const want = decodeCatalogObjectRef(table);
111
+ const got = decodeCatalogObjectRef(toUint8Array(snapshot.table));
112
+ if (got.name !== want.name || JSON.stringify([...got.schema_path]) !== JSON.stringify([...want.schema_path]))
113
+ throw new Error("catalog_table_constraints_apply: the catalog returned a snapshot of a different table");
114
+ const revision = toUint8Array(snapshot.definition_revision);
115
+ if (revision.length === 0 || (revision.length === expected.length && revision.every((b, i) => b === expected[i])))
116
+ throw new Error(`catalog_table_constraints_apply: table '${want.name}' must return a new, nonempty definition_revision`);
117
+ for (const record of snapshot.constraints) {
118
+ const view = readConstraintRecord(toUint8Array(record));
119
+ if (view.table !== want.name || JSON.stringify(view.schemaPath) !== JSON.stringify([...want.schema_path]))
120
+ throw new Error(`catalog_table_constraints_apply: constraint '${view.id}' belongs to another table`);
121
+ }
122
+ return wrapResult({ table, definition_revision: revision, constraints: snapshot.constraints.map((c) => toUint8Array(c)) },
123
+ CatalogTableConstraintsApplyResultSchema);
124
+ });
125
+
77
126
  // catalog_table_drop
78
127
  const catalogTableDrop = catalogHandler(signingKey, async (params) => {
79
128
  const cat = getCatalog();
@@ -295,9 +344,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
295
344
  return {};
296
345
  });
297
346
  return {
298
- catalogTableConstraintsApply: async () => {
299
- throw new MethodNotImplementedError("catalog_table_constraints_apply");
300
- },
347
+ catalogTableConstraintsApply,
301
348
  catalogTableGet,
302
349
  catalogTableCreate,
303
350
  catalogTableDrop,
@@ -10,6 +10,7 @@ import {
10
10
  TableFunctionPlanResultSchema,
11
11
  } from "../../generated/vgi-protocol-schemas.js";
12
12
  import type { BindRequest } from "../types.js";
13
+ import { OrderByDirection, OrderByNullOrder } from "../types.js";
13
14
  import { deserializeBatch, batchToScalarDict } from "../../util/arrow/index.js";
14
15
  import { toUint8Array } from "./shared.js";
15
16
  import { deserializeBindRequest } from "./bind.js";
@@ -35,7 +36,16 @@ export interface ScanSplit {
35
36
  * claiming client needs no cost model at all.
36
37
  */
37
38
  estimatedBytes?: number | bigint | null;
38
- /** 2-row (min, max) batch in the existing `vgi_partition_values` encoding. */
39
+ /** One-row exact transformed-key tuple aligned with `PlanResult.keyGrouping`. */
40
+ keyValue?: Uint8Array | null;
41
+ /** Zero-based range owned by this split under `PlanResult.rangePartitioning`. */
42
+ rangeIndex?: number | bigint | null;
43
+ /** Two-row (min, max) pruning batch; never an exact distribution claim. */
44
+ columnBounds?: Uint8Array | null;
45
+ /**
46
+ * Two-row (min, max) batch in the legacy `vgi_partition_values` encoding.
47
+ * @deprecated Protocol 3 producers should use `columnBounds`.
48
+ */
39
49
  partitionBounds?: Uint8Array | null;
40
50
  columnStatistics?: Uint8Array | null;
41
51
  locationIds?: number[] | null;
@@ -76,7 +86,21 @@ export interface PlanResult {
76
86
  * cacheable and is not redeemable after commit or rollback.
77
87
  */
78
88
  scope?: "catalog" | "transaction";
89
+ /** Hoisted host list indexed by each split's `locationIds`. */
90
+ locations?: string[] | null;
91
+ /** Serialized `KeyGrouping` shared by every page of this plan. */
92
+ keyGrouping?: Uint8Array | null;
93
+ /** Serialized `RangePartitioning` shared by every page of this plan. */
94
+ rangePartitioning?: Uint8Array | null;
95
+ /** @deprecated Protocol 3 producers should use `keyGrouping` or `rangePartitioning`. */
96
+ partitioning?: Uint8Array[] | null;
97
+ /** Serialized `SortField` records describing order within each split. */
98
+ sortOrder?: Uint8Array[] | null;
79
99
  cacheMaxAgeSeconds?: number | null;
100
+ /** Actual exclusive lower data position selected by the worker. */
101
+ startPosition?: Uint8Array | null;
102
+ /** Data frontier resolved by the worker for this plan. */
103
+ endPosition?: Uint8Array | null;
80
104
  }
81
105
 
82
106
  /** The request a client sends to divide a scan. */
@@ -85,6 +109,8 @@ export interface TableFunctionPlanRequest {
85
109
  bind_opaque_data: Uint8Array | null;
86
110
  projection_ids: number[] | null;
87
111
  pushdown_filters: Uint8Array | null;
112
+ join_keys: Uint8Array[] | null;
113
+ row_limit: bigint | null;
88
114
  /** The primary sizing lever: every engine is byte-driven. */
89
115
  target_split_bytes: bigint | null;
90
116
  /**
@@ -92,12 +118,26 @@ export interface TableFunctionPlanRequest {
92
118
  * per thread, which a byte target alone would not give it.
93
119
  */
94
120
  min_splits: bigint | null;
121
+ /** Maximum number of splits to enumerate on this response page. */
122
+ max_splits_per_response: bigint | null;
95
123
  /**
96
124
  * A place in the ENUMERATION of splits — NOT a place in the data. A cursor
97
125
  * lives for one plan call; a position is checkpointed and must survive
98
126
  * restarts, upgrades and key rotation.
99
127
  */
100
128
  cursor: Uint8Array | null;
129
+ /** Narrower filters supplied on a continuation request. */
130
+ refined_filters: Uint8Array | null;
131
+ /** False while the client may still send further filter refinement. */
132
+ filters_complete: boolean;
133
+ start_position: Uint8Array | null;
134
+ end_position: Uint8Array | null;
135
+ order_by_column_name: string | null;
136
+ order_by_direction: OrderByDirection | null;
137
+ order_by_null_order: OrderByNullOrder | null;
138
+ order_by_limit: bigint | null;
139
+ tablesample_percentage: number | null;
140
+ tablesample_seed: bigint | null;
101
141
  }
102
142
 
103
143
  /**
@@ -136,15 +176,43 @@ export function deserializePlanRequest(params: Record<string, any>): TableFuncti
136
176
 
137
177
  const asBigInt = (v: unknown): bigint | null =>
138
178
  v == null ? null : typeof v === "bigint" ? v : BigInt(Number(v));
179
+ const asBytes = (v: unknown): Uint8Array | null => v == null ? null : toUint8Array(v);
180
+ const asBytesList = (v: unknown): Uint8Array[] | null => {
181
+ if (v == null) return null;
182
+ const values = Array.isArray(v)
183
+ ? v
184
+ : v && typeof (v as any)[Symbol.iterator] === "function"
185
+ ? [...(v as Iterable<unknown>)]
186
+ : [];
187
+ return values.filter((entry) => entry != null).map(toUint8Array);
188
+ };
189
+ const enumValue = <T extends string>(v: unknown, values: readonly T[]): T | null => {
190
+ if (v == null) return null;
191
+ const text = String(v) as T;
192
+ return values.includes(text) ? text : null;
193
+ };
139
194
 
140
195
  return {
141
196
  bind_call: bindCall,
142
- bind_opaque_data: params.bind_opaque_data ? toUint8Array(params.bind_opaque_data) : null,
197
+ bind_opaque_data: asBytes(params.bind_opaque_data),
143
198
  projection_ids: projectionIds,
144
- pushdown_filters: params.pushdown_filters ? toUint8Array(params.pushdown_filters) : null,
199
+ pushdown_filters: asBytes(params.pushdown_filters),
200
+ join_keys: asBytesList(params.join_keys),
201
+ row_limit: asBigInt(params.row_limit),
145
202
  target_split_bytes: asBigInt(params.target_split_bytes),
146
203
  min_splits: asBigInt(params.min_splits),
147
- cursor: params.cursor ? toUint8Array(params.cursor) : null,
204
+ max_splits_per_response: asBigInt(params.max_splits_per_response),
205
+ cursor: asBytes(params.cursor),
206
+ refined_filters: asBytes(params.refined_filters),
207
+ filters_complete: params.filters_complete == null ? true : Boolean(params.filters_complete),
208
+ start_position: asBytes(params.start_position),
209
+ end_position: asBytes(params.end_position),
210
+ order_by_column_name: params.order_by_column_name == null ? null : String(params.order_by_column_name),
211
+ order_by_direction: enumValue(params.order_by_direction, Object.values(OrderByDirection)),
212
+ order_by_null_order: enumValue(params.order_by_null_order, Object.values(OrderByNullOrder)),
213
+ order_by_limit: asBigInt(params.order_by_limit),
214
+ tablesample_percentage: params.tablesample_percentage == null ? null : Number(params.tablesample_percentage),
215
+ tablesample_seed: asBigInt(params.tablesample_seed),
148
216
  };
149
217
  }
150
218
 
@@ -188,6 +256,9 @@ export function scanSplitRow(split: ScanSplit, token: Uint8Array): Record<string
188
256
  estimated_rows: asBigInt(split.estimatedRows),
189
257
  rows_exact: split.rowsExact === true,
190
258
  estimated_bytes: asBigInt(split.estimatedBytes),
259
+ key_value: split.keyValue ?? null,
260
+ range_index: asBigInt(split.rangeIndex),
261
+ column_bounds: split.columnBounds ?? null,
191
262
  partition_bounds: split.partitionBounds ?? null,
192
263
  column_statistics: split.columnStatistics ?? null,
193
264
  location_ids: split.locationIds ?? null,
@@ -211,11 +282,13 @@ export function planResponseRow(result: PlanResult, splitBlobs: Uint8Array[]): R
211
282
  estimated_total_bytes: asBigInt(result.estimatedTotalBytes),
212
283
  catalog_version: asBigInt(result.catalogVersion),
213
284
  scope: result.scope ?? "catalog",
214
- locations: null,
215
- partitioning: [],
216
- sort_order: [],
285
+ locations: result.locations ?? null,
286
+ key_grouping: result.keyGrouping ?? null,
287
+ range_partitioning: result.rangePartitioning ?? null,
288
+ partitioning: result.partitioning ?? null,
289
+ sort_order: result.sortOrder ?? null,
217
290
  cache_max_age_seconds: asBigInt(result.cacheMaxAgeSeconds),
218
- start_position: new Uint8Array(0),
219
- end_position: new Uint8Array(0),
291
+ start_position: result.startPosition ?? null,
292
+ end_position: result.endPosition ?? null,
220
293
  };
221
294
  }
@@ -65,11 +65,9 @@ export {
65
65
  serializeColumnStatistics,
66
66
  BindResultSchema,
67
67
  ScanFunctionResultSchema,
68
- constraintRecord,
69
- readConstraintRecord,
70
- CONSTRAINT_RECORDS_READ,
71
- ROW_SCALAR_EXPRESSION,
72
68
  } from "./index.core.js";
69
+ // vgi.v3 records: constraints, capabilities, column expressions, indexes, macro overloads.
70
+ export * from "./catalog/public-codecs.js";
73
71
 
74
72
  export type {
75
73
  CacheControl,