@query-farm/vgi 0.46.0 → 0.47.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 (93) hide show
  1. package/README.md +11 -5
  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/index.d.ts +1 -1
  5. package/dist/arrow/impl-flechette/iterate.d.ts +2 -0
  6. package/dist/arrow/index.d.ts +1 -1
  7. package/dist/catalog/column-expressions.d.ts +8 -0
  8. package/dist/catalog/column-metadata.d.ts +11 -0
  9. package/dist/catalog/composite.d.ts +2 -1
  10. package/dist/catalog/constraints.d.ts +74 -0
  11. package/dist/catalog/descriptors.d.ts +21 -29
  12. package/dist/catalog/interface.d.ts +15 -20
  13. package/dist/catalog/macro-overloads.d.ts +4 -0
  14. package/dist/catalog/read-only.d.ts +7 -1
  15. package/dist/catalog/unconstrained-columns.d.ts +2 -0
  16. package/dist/client/client.d.ts +18 -13
  17. package/dist/client-entry.js +753 -103
  18. package/dist/client-entry.js.map +16 -14
  19. package/dist/functions/projection.d.ts +18 -0
  20. package/dist/functions/table.d.ts +6 -1
  21. package/dist/functions/types.d.ts +1 -0
  22. package/dist/generated/vgi-client.d.ts +177 -36
  23. package/dist/generated/vgi-protocol-schemas.d.ts +51 -1
  24. package/dist/generated/vgi-protocol-types.d.ts +317 -3
  25. package/dist/generated/vgi-service.d.ts +266 -29
  26. package/dist/index.core.d.ts +3 -1
  27. package/dist/index.js +1630 -240
  28. package/dist/index.js.map +41 -34
  29. package/dist/protocol/dispatch.d.ts +9 -9
  30. package/dist/protocol/handlers/aggregate.d.ts +1 -1
  31. package/dist/protocol/handlers/catalog/index.d.ts +1 -1
  32. package/dist/protocol/handlers/catalog/metadata.d.ts +1 -0
  33. package/dist/protocol/handlers/function.d.ts +1 -1
  34. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  35. package/dist/protocol/handlers/unimplemented.d.ts +1 -1
  36. package/dist/protocol/serializers/bind.d.ts +5 -1
  37. package/dist/protocol/types.d.ts +5 -0
  38. package/dist/rpc-server.d.ts +6 -6
  39. package/dist/serve-entry.js +1613 -447
  40. package/dist/serve-entry.js.map +32 -26
  41. package/dist/util/arrow/index.d.ts +1 -1
  42. package/dist/worker-cf-entry.d.ts +2 -2
  43. package/dist/worker-cf-entry.js +1943 -572
  44. package/dist/worker-cf-entry.js.map +41 -34
  45. package/dist/worker.d.ts +1 -1
  46. package/package.json +5 -4
  47. package/src/arrow/impl-arrowjs/index.ts +1 -1
  48. package/src/arrow/impl-arrowjs/iterate.ts +9 -1
  49. package/src/arrow/impl-arrowjs/project.ts +1 -1
  50. package/src/arrow/impl-flechette/index.ts +1 -1
  51. package/src/arrow/impl-flechette/ipc.ts +12 -0
  52. package/src/arrow/impl-flechette/iterate.ts +5 -0
  53. package/src/arrow/impl-flechette/project.ts +6 -8
  54. package/src/arrow/index.ts +1 -1
  55. package/src/catalog/column-expressions.ts +224 -0
  56. package/src/catalog/column-metadata.ts +151 -0
  57. package/src/catalog/composite.ts +5 -1
  58. package/src/catalog/constraints.ts +207 -0
  59. package/src/catalog/contents-codec.ts +6 -1
  60. package/src/catalog/descriptors.ts +21 -29
  61. package/src/catalog/interface.ts +70 -55
  62. package/src/catalog/macro-overloads.ts +44 -0
  63. package/src/catalog/read-only.ts +92 -71
  64. package/src/catalog/unconstrained-columns.ts +23 -0
  65. package/src/client/client.ts +100 -58
  66. package/src/codec/asd.ts +3 -1
  67. package/src/functions/projection.ts +207 -0
  68. package/src/functions/table.ts +10 -0
  69. package/src/functions/types.ts +1 -0
  70. package/src/generated/vgi-client.ts +199 -37
  71. package/src/generated/vgi-protocol-schemas.ts +455 -41
  72. package/src/generated/vgi-protocol-types.ts +879 -5
  73. package/src/generated/vgi-service.ts +514 -42
  74. package/src/http/client-bundle.ts +1 -1
  75. package/src/http/fetch.ts +1 -1
  76. package/src/index.core.ts +5 -0
  77. package/src/protocol/dispatch.ts +9 -9
  78. package/src/protocol/handlers/aggregate.ts +1 -1
  79. package/src/protocol/handlers/catalog/admin.ts +27 -6
  80. package/src/protocol/handlers/catalog/index.ts +2 -2
  81. package/src/protocol/handlers/catalog/macro.ts +6 -5
  82. package/src/protocol/handlers/catalog/metadata.ts +16 -0
  83. package/src/protocol/handlers/catalog/table.ts +72 -26
  84. package/src/protocol/handlers/catalog/view.ts +24 -3
  85. package/src/protocol/handlers/function.ts +67 -1
  86. package/src/protocol/handlers/table-buffering.ts +1 -1
  87. package/src/protocol/handlers/unimplemented.ts +6 -6
  88. package/src/protocol/serializers/bind.ts +17 -1
  89. package/src/protocol/types.ts +6 -0
  90. package/src/rpc-server.ts +9 -9
  91. package/src/util/arrow/index.ts +1 -1
  92. package/src/worker-cf-entry.ts +6 -0
  93. package/src/worker.ts +1 -1
package/src/http/fetch.ts CHANGED
@@ -205,7 +205,7 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
205
205
  ...opts.protocol,
206
206
  });
207
207
 
208
- // The same builder every other transport uses: `vgi.v2`, the worker's
208
+ // The same builder every other transport uses: `vgi.v3`, the worker's
209
209
  // hostedProtocols(), reflection, and -- HTTP being the transport that
210
210
  // authenticates callers -- vgi_rpc.Identity.v2 when the worker opts in.
211
211
  // Built at construction, so a worker that opts into introspection without an
package/src/index.core.ts CHANGED
@@ -86,6 +86,7 @@ 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
90
  export { CompositeCatalogInterface } from "./catalog/composite.js";
90
91
  export { FunctionRegistry } from "./functions/registry.js";
91
92
 
@@ -106,6 +107,7 @@ export {
106
107
  export type {
107
108
  BindRequest,
108
109
  BindResponse,
110
+ BindRepeatability,
109
111
  CopyFromContext,
110
112
  CopyToContext,
111
113
  InitRequest,
@@ -367,3 +369,6 @@ export {
367
369
  } from "@query-farm/vgi-rpc";
368
370
  export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
369
371
  export { normalizeSchemaPath, schemaPathDisplay, schemaPathKey, schemaPathsEqual, type SchemaPath } from "./schema-path.js";
372
+
373
+ // Optional scalar projection negotiation and its explicit offer.
374
+ export { SCALAR_PROJECTION_PROFILE, type ProjectionProposal, type ProjectionAcceptance } from "./functions/projection.js";
@@ -39,7 +39,7 @@ export interface ProtocolConfig {
39
39
  * The name carries the major version, so an incompatible major is a
40
40
  * *different* protocol and therefore a 404 — an answer every proxy, WAF and
41
41
  * load balancer understands without an Arrow parser, and one that lets
42
- * `vgi.v2` and a future `vgi.v3` be served side by side while clients migrate.
42
+ * `vgi.v2` and `vgi.v3` be served side by side while clients migrate.
43
43
  * That matters for this consumer specifically: the DuckDB extension ships to
44
44
  * users and cannot be flag-dayed.
45
45
  *
@@ -61,22 +61,22 @@ export interface ProtocolConfig {
61
61
  export { VGI_PROTOCOL_NAME };
62
62
 
63
63
  /**
64
- * The `vgi.v2` protocol hash `vgi_rpc.Reflection.v1` must report for this
65
- * worker: the reference's (vgi-python 0.43.0, 72 methods). Every SDK hosts
66
- * every `vgi.v2` method with the reference's schemas, so the hash is one value
64
+ * The `vgi.v3` protocol hash `vgi_rpc.Reflection.v1` must report for this
65
+ * worker: the combined reference's 85 methods. Every SDK hosts
66
+ * every `vgi.v3` method with the reference's schemas, so the hash is one value
67
67
  * across the ports; a method this SDK does not implement is still registered
68
68
  * with the generated UNIMPLEMENTED default (src/generated/vgi-service.ts). The
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.2.0). Asserted
73
- * by src/protocol/__tests__/vgi-v2-hash.test.ts; if that test fails, the
72
+ * It changes only with vgi.v3's protocol version (currently 3.0.0). Asserted
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
  */
76
- export const VGI_V2_PROTOCOL_HASH = "774cb80090d71ea76d09aa311b9cda4ca4c33c3bf72c43242eb6dc87b6f79ce5";
76
+ export const VGI_V3_PROTOCOL_HASH = "50e9404173bee3262e96b8939eb5c425463336abca2a17916812d68b6e0f6cad";
77
77
 
78
78
  /**
79
- * This worker's `vgi.v2` implementation: the generated UNIMPLEMENTED default
79
+ * This worker's `vgi.v3` implementation: the generated UNIMPLEMENTED default
80
80
  * for every method, overridden by the handler groups for what this SDK serves.
81
81
  */
82
82
  export function buildVgiService(config: ProtocolConfig): VgiService {
@@ -93,7 +93,7 @@ export function buildVgiService(config: ProtocolConfig): VgiService {
93
93
  };
94
94
  }
95
95
 
96
- /** The `vgi.v2` protocol, registered from the generated table with {@link buildVgiService}. */
96
+ /** The `vgi.v3` protocol, registered from the generated table with {@link buildVgiService}. */
97
97
  export function buildVgiProtocol(config: ProtocolConfig): Protocol {
98
98
  return createVgiProtocol(buildVgiService(config));
99
99
  }
@@ -35,7 +35,7 @@ import { Arguments } from "../../arguments/arguments.js";
35
35
  import { validateConstConstraints } from "../../arguments/argument-spec.js";
36
36
  import { unwrapRequest, wrapResult } from "./shared.js";
37
37
 
38
- /** The aggregate lifecycle's `vgi.v2` handlers. */
38
+ /** The aggregate lifecycle's `vgi.v3` handlers. */
39
39
  export function aggregateHandlers(registry: FunctionRegistry): Partial<VgiService> {
40
40
  // `schemaPath` scopes resolution to the schema the caller named. Every
41
41
  // aggregate RPC carries it (protocol 1.2.0), so an aggregate name declared in
@@ -1,17 +1,20 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ import { encodeValidatedTableInfo } from "../../../catalog/column-metadata.js";
3
+ import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
2
4
  // Catalog admin handlers: attach/detach/create/drop, version, transactions,
3
5
  // schemas (list, get, create, drop), schema contents listings.
4
6
 
7
+ import { catalogStringMap } from "./metadata.js";
5
8
  import { schema } from "../../../arrow/index.js";
6
9
  import type { CallContext } from "@query-farm/vgi-rpc";
7
10
  import type { VgiService } from "../../../generated/vgi-service.js";
8
11
  import {
9
12
  encodeSchemaInfo,
10
- encodeTableInfo,
11
13
  encodeViewInfo,
12
14
  encodeCatalogInfo,
13
15
  } from "../../../generated/vgi-client.js";
14
- import { buildCatalogAttachResult } from "../../../generated/vgi-protocol-types.js";
16
+ import { buildCatalogAttachResult, decodeCatalogCapabilities, encodeCatalogCapabilities } from "../../../generated/vgi-protocol-types.js";
17
+ import { selectReadProfiles } from "../../../catalog/constraints.js";
15
18
  import { serveCatalogContents } from "./contents.js";
16
19
  import { encodeFunctionInfoOnce } from "../../../catalog/item-encoding.js";
17
20
  import { encodeCopyFromFormatInfo } from "../../../catalog/interface.js";
@@ -92,12 +95,28 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
92
95
  innerParams.implementation_version = restored.implementationVersion;
93
96
  optionsDict = restored.options;
94
97
  }
98
+ const clientCapabilities =
99
+ innerParams.client_capabilities == null ? null : toUint8Array(innerParams.client_capabilities);
95
100
  const result = await cat.attach(
96
101
  innerParams.name,
97
102
  optionsDict,
98
103
  innerParams.data_version_spec ?? null,
99
104
  innerParams.implementation_version ?? null,
105
+ clientCapabilities,
100
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
+ });
119
+ }
101
120
  // Seal the attach value into an AEAD envelope bound to the caller's
102
121
  // identity before it leaves the worker (HTTP transport; pass-through
103
122
  // when there is no signing key).
@@ -243,13 +262,15 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
243
262
 
244
263
  // catalog_schema_create
245
264
  const catalogSchemaCreate = catalogHandler(signingKey, async (params) => {
265
+ if (params.options != null) throw new MethodNotImplementedError("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
246
266
  const cat = getCatalog();
247
267
  await cat.schemaCreate(
248
268
  toUint8Array(params.attach_opaque_data),
249
- params.path,
269
+ Array.from(params.path),
250
270
  params.comment,
251
- null, // tags
252
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
271
+ catalogStringMap(params.tags),
272
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
273
+ decodeDictValue(params.on_conflict)
253
274
  );
254
275
  return {};
255
276
  });
@@ -276,7 +297,7 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
276
297
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
277
298
  );
278
299
  return wrapResult({
279
- items: tables.map((t) => encodeTableInfo(t)),
300
+ items: tables.map((t) => encodeValidatedTableInfo(t)),
280
301
  }, CatalogSchemaContentsTablesResultSchema);
281
302
  });
282
303
 
@@ -1,5 +1,5 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
- // Catalog handler orchestrator: every catalog_* `vgi.v2` handler.
2
+ // Catalog handler orchestrator: every catalog_* `vgi.v3` handler.
3
3
 
4
4
  import type { CatalogInterface } from "../../../catalog/interface.js";
5
5
  import type { VgiService } from "../../../generated/vgi-service.js";
@@ -10,7 +10,7 @@ import { catalogViewHandlers } from "./view.js";
10
10
  import { catalogMacroHandlers } from "./macro.js";
11
11
  import { catalogIndexHandlers } from "./index_methods.js";
12
12
 
13
- /** The catalog_* `vgi.v2` handlers, over *catalog* (or `NoCatalogError` without one). */
13
+ /** The catalog_* `vgi.v3` handlers, over *catalog* (or `NoCatalogError` without one). */
14
14
  export function catalogHandlers(
15
15
  catalog: CatalogInterface | undefined,
16
16
  signingKey?: Uint8Array,
@@ -5,11 +5,14 @@ import type { VgiService } from "../../../generated/vgi-service.js";
5
5
  import { encodeMacroInfo } from "../../../generated/vgi-client.js";
6
6
  import {
7
7
  CatalogMacroGetResultSchema,
8
+ MacroCreateRequestSchema,
8
9
  CatalogSchemaContentsMacrosResultSchema,
9
10
  } from "../../../generated/vgi-protocol-schemas.js";
10
11
  import type { MacroType } from "../../../catalog/interface.js";
11
12
  import { toUint8Array } from "../../../util/bytes.js";
12
13
  import { decodeDictValue } from "../../../util/arrow/index.js";
14
+ import { decodeASD, encodeASD } from "../../../codec/asd.js";
15
+ import type { MacroCreateRequest } from "../../../generated/vgi-client.js";
13
16
  import {
14
17
  wrapResult,
15
18
  } from "../shared.js";
@@ -37,17 +40,15 @@ export function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
37
40
  const catalogMacroCreate = catalogHandler(signingKey, async (params) => {
38
41
  const cat = getCatalog();
39
42
  // catalogHandler already flattened the wrapped request.
40
- const innerParams = params;
43
+ const innerParams = decodeASD<MacroCreateRequest>(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
44
+ if (!innerParams.overloads?.length) throw new Error("macro overload family must be nonempty");
41
45
  await cat.macroCreate(
42
46
  toUint8Array(innerParams.attach_opaque_data),
43
47
  innerParams.schema_path,
44
48
  innerParams.name,
45
49
  innerParams.macro_type as MacroType,
46
- innerParams.parameters ? (Array.isArray(innerParams.parameters) ? innerParams.parameters : [...innerParams.parameters]) : [],
47
- innerParams.definition,
50
+ innerParams.overloads,
48
51
  innerParams.on_conflict,
49
- innerParams.parameter_default_values ? toUint8Array(innerParams.parameter_default_values) : null,
50
- innerParams.arguments_schema ? toUint8Array(innerParams.arguments_schema) : null,
51
52
  innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined
52
53
  );
53
54
  return {};
@@ -0,0 +1,16 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ import { decodeMapValue } from "../../../util/arrow/index.js";
3
+
4
+ export function catalogStringMap(raw: any): Record<string, string> {
5
+ raw = decodeMapValue(raw);
6
+ const result: Record<string, string> = {};
7
+ if (raw == null) return result;
8
+ const entries = raw[Symbol.iterator] ? raw : Object.entries(raw);
9
+ for (const entry of entries) {
10
+ const [key, value] = Array.isArray(entry) ? entry : [entry.key, entry.value];
11
+ if (typeof key !== "string" || typeof value !== "string") throw new Error("catalog metadata must map strings to strings");
12
+ Object.defineProperty(result, key, { value, enumerable: true, writable: true, configurable: true });
13
+ }
14
+ return result;
15
+ }
16
+
@@ -1,15 +1,18 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ import { encodeValidatedTableInfo, validateColumnMetadataIpc } from "../../../catalog/column-metadata.js";
3
+ import { validateColumnExpressionsIpc } from "../../../catalog/column-expressions.js";
4
+ import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
2
5
  // Catalog table handlers: table_get/create/drop, scan_function_get,
3
6
  // column_statistics_get, comment_set, rename, plus all column_* mutations.
4
7
 
5
8
  import type { VgiService } from "../../../generated/vgi-service.js";
6
- import { encodeTableInfo } from "../../../generated/vgi-client.js";
7
9
  import {
8
10
  CatalogTableGetResultSchema,
9
11
  ScanBranchesResultSchema,
10
12
  ScanFunctionResultSchema,
11
13
  } from "../../../generated/vgi-protocol-schemas.js";
12
14
  import { toUint8Array } from "../../../util/bytes.js";
15
+ import { requireUnconstrainedColumns } from "../../../catalog/unconstrained-columns.js";
13
16
  import {
14
17
  wrapResult,
15
18
  } from "../shared.js";
@@ -18,6 +21,17 @@ import {
18
21
  catalogHandler,
19
22
  } from "./shared.js";
20
23
 
24
+ function requireFlatColumnPath(value: unknown, operation: string): string[] {
25
+ // The raw RPC codec returns Arrow list scalars as iterable vectors.
26
+ const path = value != null && typeof value === "object" && Symbol.iterator in value
27
+ ? Array.from(value as Iterable<unknown>) : value;
28
+ if (!Array.isArray(path) || path.length !== 1 ||
29
+ typeof path[0] !== "string" || !path[0] || path[0].includes("\0")) {
30
+ throw new MethodNotImplementedError(`${operation}: nested column paths require a negotiated capability`);
31
+ }
32
+ return path as string[];
33
+ }
34
+
21
35
  export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
22
36
  // catalog_table_get
23
37
  const catalogTableGet = catalogHandler(signingKey, async (params) => {
@@ -31,12 +45,22 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
31
45
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
32
46
  );
33
47
  return wrapResult({
34
- items: info ? [encodeTableInfo(info)] : [],
48
+ items: info ? [encodeValidatedTableInfo(info)] : [],
35
49
  }, CatalogTableGetResultSchema);
36
50
  });
37
51
 
38
52
  // catalog_table_create
39
53
  const catalogTableCreate = catalogHandler(signingKey, async (params) => {
54
+ 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
+ if (params.comment != null || params.tags != null || params.options != null || params.layout != null) {
59
+ throw new MethodNotImplementedError("catalog_table_create: table metadata/options/layout profiles are not supported");
60
+ }
61
+ validateColumnMetadataIpc(toUint8Array(params.columns));
62
+ validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
63
+ requireUnconstrainedColumns(toUint8Array(params.columns));
40
64
  const cat = getCatalog();
41
65
  await cat.tableCreate(
42
66
  toUint8Array(params.attach_opaque_data),
@@ -44,9 +68,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
44
68
  params.name,
45
69
  toUint8Array(params.columns),
46
70
  params.on_conflict,
47
- params.not_null_constraints ?? [],
48
- params.unique_constraints ?? [],
49
- params.check_constraints ?? [],
71
+ [],
50
72
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
51
73
  );
52
74
  return {};
@@ -137,122 +159,145 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
137
159
 
138
160
  // catalog_table_column_add
139
161
  const catalogTableColumnAdd = catalogHandler(signingKey, async (params) => {
162
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
163
+ validateColumnMetadataIpc(toUint8Array(params.column_definition));
164
+ validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
140
165
  const cat = getCatalog();
141
166
  await cat.tableColumnAdd(
142
167
  toUint8Array(params.attach_opaque_data),
143
168
  params.schema_path,
144
169
  params.name,
145
- params.column_name,
146
- params.column_type,
147
- params.default_value,
170
+ params.column_path,
171
+ toUint8Array(params.column_definition),
148
172
  params.ignore_not_found,
173
+ params.if_column_not_exists,
149
174
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
150
175
  );
151
176
  return {};
152
177
  });
153
-
154
178
  // catalog_table_column_drop
155
179
  const catalogTableColumnDrop = catalogHandler(signingKey, async (params) => {
180
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
156
181
  const cat = getCatalog();
157
182
  await cat.tableColumnDrop(
158
183
  toUint8Array(params.attach_opaque_data),
159
184
  params.schema_path,
160
185
  params.name,
161
- params.column_name,
186
+ params.column_path,
162
187
  params.ignore_not_found,
188
+ params.if_column_exists,
189
+ params.cascade,
163
190
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
164
191
  );
165
192
  return {};
166
193
  });
167
-
168
194
  // catalog_table_column_rename
169
195
  const catalogTableColumnRename = catalogHandler(signingKey, async (params) => {
196
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
170
197
  const cat = getCatalog();
171
198
  await cat.tableColumnRename(
172
199
  toUint8Array(params.attach_opaque_data),
173
200
  params.schema_path,
174
201
  params.name,
175
- params.column_name,
176
- params.new_name,
202
+ params.column_path,
203
+ params.new_column_name,
204
+ params.ignore_not_found,
205
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
206
+ );
207
+ return {};
208
+ });
209
+ // catalog_table_column_comment_set
210
+ const catalogTableColumnCommentSet = catalogHandler(signingKey, async (params) => {
211
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
212
+ const cat = getCatalog();
213
+ await cat.tableColumnCommentSet(
214
+ toUint8Array(params.attach_opaque_data),
215
+ params.schema_path,
216
+ params.name,
217
+ params.column_path,
218
+ params.comment,
177
219
  params.ignore_not_found,
178
220
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
179
221
  );
180
222
  return {};
181
223
  });
182
-
183
224
  // catalog_table_column_default_set
184
225
  const catalogTableColumnDefaultSet = catalogHandler(signingKey, async (params) => {
226
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
185
227
  const cat = getCatalog();
186
228
  await cat.tableColumnDefaultSet(
187
229
  toUint8Array(params.attach_opaque_data),
188
230
  params.schema_path,
189
231
  params.name,
190
- params.column_name,
191
- params.default_value,
232
+ params.column_path,
233
+ toUint8Array(params.expression),
192
234
  params.ignore_not_found,
193
235
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
194
236
  );
195
237
  return {};
196
238
  });
197
-
198
239
  // catalog_table_column_default_drop
199
240
  const catalogTableColumnDefaultDrop = catalogHandler(signingKey, async (params) => {
241
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
200
242
  const cat = getCatalog();
201
243
  await cat.tableColumnDefaultDrop(
202
244
  toUint8Array(params.attach_opaque_data),
203
245
  params.schema_path,
204
246
  params.name,
205
- params.column_name,
247
+ params.column_path,
206
248
  params.ignore_not_found,
207
249
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
208
250
  );
209
251
  return {};
210
252
  });
211
-
212
253
  // catalog_table_column_type_change
213
254
  const catalogTableColumnTypeChange = catalogHandler(signingKey, async (params) => {
255
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
214
256
  const cat = getCatalog();
215
257
  await cat.tableColumnTypeChange(
216
258
  toUint8Array(params.attach_opaque_data),
217
259
  params.schema_path,
218
260
  params.name,
219
- params.column_name,
220
- params.new_type,
261
+ params.column_path,
262
+ toUint8Array(params.column_definition),
263
+ params.expression == null ? null : toUint8Array(params.expression),
221
264
  params.ignore_not_found,
222
265
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
223
266
  );
224
267
  return {};
225
268
  });
226
-
227
269
  // catalog_table_not_null_set
228
270
  const catalogTableNotNullSet = catalogHandler(signingKey, async (params) => {
271
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
229
272
  const cat = getCatalog();
230
273
  await cat.tableNotNullSet(
231
274
  toUint8Array(params.attach_opaque_data),
232
275
  params.schema_path,
233
276
  params.name,
234
- params.column_name,
277
+ params.column_path,
235
278
  params.ignore_not_found,
236
279
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
237
280
  );
238
281
  return {};
239
282
  });
240
-
241
283
  // catalog_table_not_null_drop
242
284
  const catalogTableNotNullDrop = catalogHandler(signingKey, async (params) => {
285
+ params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
243
286
  const cat = getCatalog();
244
287
  await cat.tableNotNullDrop(
245
288
  toUint8Array(params.attach_opaque_data),
246
289
  params.schema_path,
247
290
  params.name,
248
- params.column_name,
291
+ params.column_path,
249
292
  params.ignore_not_found,
250
293
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
251
294
  );
252
295
  return {};
253
296
  });
254
-
255
297
  return {
298
+ catalogTableConstraintsApply: async () => {
299
+ throw new MethodNotImplementedError("catalog_table_constraints_apply");
300
+ },
256
301
  catalogTableGet,
257
302
  catalogTableCreate,
258
303
  catalogTableDrop,
@@ -264,6 +309,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
264
309
  catalogTableColumnAdd,
265
310
  catalogTableColumnDrop,
266
311
  catalogTableColumnRename,
312
+ catalogTableColumnCommentSet,
267
313
  catalogTableColumnDefaultSet,
268
314
  catalogTableColumnDefaultDrop,
269
315
  catalogTableColumnTypeChange,
@@ -1,11 +1,13 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
2
  // Catalog view handlers: view_get/create/drop/rename/comment_set.
3
3
 
4
+ import { catalogStringMap } from "./metadata.js";
4
5
  import type { VgiService } from "../../../generated/vgi-service.js";
5
6
  import { encodeViewInfo } from "../../../generated/vgi-client.js";
6
7
  import {
7
8
  CatalogViewGetResultSchema,
8
9
  } from "../../../generated/vgi-protocol-schemas.js";
10
+ import { decodeDictValue } from "../../../util/arrow/index.js";
9
11
  import { toUint8Array } from "../../../util/bytes.js";
10
12
  import {
11
13
  wrapResult,
@@ -32,14 +34,22 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
32
34
 
33
35
  // catalog_view_create
34
36
  const catalogViewCreate = catalogHandler(signingKey, async (params) => {
37
+ if (params.security !== "regular") throw new Error(`view security mode ${params.security} is unsupported`);
38
+ const tags = catalogStringMap(params.tags);
39
+ const columnComments = catalogStringMap(params.column_comments);
40
+ if (Object.keys(columnComments).some((key) => !key || key.includes("\0"))) throw new Error("view column comments require raw output identifiers");
35
41
  const cat = getCatalog();
36
42
  await cat.viewCreate(
37
43
  toUint8Array(params.attach_opaque_data),
38
44
  params.schema_path,
39
45
  params.name,
40
46
  params.definition,
41
- params.on_conflict,
42
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
47
+ decodeDictValue(params.on_conflict),
48
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined,
49
+ params.aliases ?? [],
50
+ params.comment,
51
+ tags,
52
+ columnComments
43
53
  );
44
54
  return {};
45
55
  });
@@ -85,5 +95,16 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
85
95
  return {};
86
96
  });
87
97
 
88
- return { catalogViewGet, catalogViewCreate, catalogViewDrop, catalogViewRename, catalogViewCommentSet };
98
+ const catalogViewColumnCommentSet = catalogHandler(signingKey, async (params) => {
99
+ const path: string[] = Array.from(params.column_path);
100
+ if (path.length !== 1 || !path[0] || path[0].includes("\0")) throw new Error("view column comments require one raw output identifier");
101
+ await getCatalog().viewColumnCommentSet(
102
+ toUint8Array(params.attach_opaque_data), params.schema_path, params.name, path,
103
+ params.comment, params.ignore_not_found,
104
+ params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
105
+ );
106
+ return {};
107
+ });
108
+
109
+ return { catalogViewColumnCommentSet, catalogViewGet, catalogViewCreate, catalogViewDrop, catalogViewRename, catalogViewCommentSet };
89
110
  }
@@ -4,6 +4,9 @@
4
4
  // implements VgiFunction.bind/globalInit/createStreamHandlers.
5
5
 
6
6
  import { type VgiSchema, schema, type VgiField, field, type VgiDataType, binary, int64 } from "../../arrow/index.js";
7
+ import { projectionRecord, validateProjectionOffer, validateProjectionProposal, validateProjectionAcceptance, type ProjectionProposal } from "../../functions/projection.js";
8
+ import { deserializeBindResponse } from "../serializers/bind.js";
9
+ import { deserializeSchema } from "../../arrow/index.js";
7
10
  import type { AuthContext } from "@query-farm/vgi-rpc";
8
11
  import { exchangeStream, type VgiService } from "../../generated/vgi-service.js";
9
12
  import type { FunctionRegistry } from "../../functions/registry.js";
@@ -23,6 +26,9 @@ import { toUint8Array } from "../../util/bytes.js";
23
26
  import { serializeColumnStatistics } from "../../util/statistics.js";
24
27
  import {
25
28
  BindResultSchema,
29
+ BindRequestSchema,
30
+ TableFunctionProjectionRequestSchema,
31
+ TableFunctionProjectionResultSchema,
26
32
  TableFunctionCardinalityResultSchema,
27
33
  TableFunctionDynamicToStringResultSchema,
28
34
  } from "../../generated/vgi-protocol-schemas.js";
@@ -185,7 +191,7 @@ async function resolveSplitPayloads(
185
191
  }
186
192
  }
187
193
 
188
- /** The per-function lifecycle's `vgi.v2` handlers. */
194
+ /** The per-function lifecycle's `vgi.v3` handlers. */
189
195
  export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService> {
190
196
  const { registry, signingKey, catalogInterface } = config;
191
197
 
@@ -240,6 +246,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
240
246
  request.attach_opaque_data = await stripAttach(request.attach_opaque_data, ctx);
241
247
  const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
242
248
  const response = await func.bind(request);
249
+ validateProjectionOffer(response);
243
250
  const serialized = serializeBindResponse(response);
244
251
  return wrapResult(serialized, BindResultSchema);
245
252
  };
@@ -599,7 +606,66 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
599
606
  return wrapResult({ keys, values }, TableFunctionDynamicToStringResultSchema);
600
607
  };
601
608
 
609
+ const tableFunctionProjection: VgiService["tableFunctionProjection"] = async (
610
+ params,
611
+ ) => {
612
+ if (toUint8Array(params.request).length > 8 * 1024 * 1024)
613
+ throw new Error("projection exceeds 8MiB");
614
+ const inner = projectionRecord(toUint8Array(params.request), TableFunctionProjectionRequestSchema);
615
+ const size =
616
+ toUint8Array(inner.bind_call).length +
617
+ toUint8Array(inner.bind_result).length +
618
+ toUint8Array(inner.result_schema).length +
619
+ Array.from(
620
+ inner.expressions as any[],
621
+ (v) => toUint8Array(v).length,
622
+ ).reduce((a, b) => a + b, 0);
623
+ if (size > 8 * 1024 * 1024) throw new Error("projection exceeds 8MiB");
624
+ const proposal: ProjectionProposal = {
625
+ bindCall: deserializeBindRequest(
626
+ projectionRecord(toUint8Array(inner.bind_call), BindRequestSchema),
627
+ ),
628
+ bindResult: deserializeBindResponse(
629
+ projectionRecord(toUint8Array(inner.bind_result), BindResultSchema),
630
+ ),
631
+ expressions: Array.from(inner.expressions as any[], toUint8Array),
632
+ resultSchema: deserializeSchema(toUint8Array(inner.result_schema)),
633
+ };
634
+ validateProjectionProposal(proposal);
635
+ const func = registry.get(
636
+ proposal.bindCall.function_name,
637
+ await strippedContext(proposal.bindCall),
638
+ );
639
+ if (func.kind !== "table")
640
+ throw new Error("projection requires an ordinary table");
641
+ const response = func.projection
642
+ ? await func.projection(proposal)
643
+ : { acceptedIndices: [], bindResult: null };
644
+ validateProjectionAcceptance(proposal, response);
645
+ const packed = wrapResult(
646
+ {
647
+ accepted_indices: response.acceptedIndices,
648
+ bind_result: response.bindResult
649
+ ? serializeBatch(
650
+ batchFromColumns(
651
+ Object.fromEntries(
652
+ Object.entries(
653
+ serializeBindResponse(response.bindResult),
654
+ ).map(([k, v]) => [k, [v]]),
655
+ ),
656
+ BindResultSchema,
657
+ ),
658
+ )
659
+ : null,
660
+ },
661
+ TableFunctionProjectionResultSchema,
662
+ );
663
+ if (packed.result.length > 8 * 1024 * 1024)
664
+ throw new Error("projection response exceeds 8MiB");
665
+ return packed;
666
+ };
602
667
  return {
668
+ tableFunctionProjection,
603
669
  bind,
604
670
  init,
605
671
  tableFunctionCardinality,
@@ -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,