@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
@@ -1,7 +1,9 @@
1
+ import { generatedExpressionMetadata, GENERATED_EXPRESSION_KEY, GENERATION_KEY, validateColumnExpressions } from "./column-expressions.js";
2
+ import { validateColumnMetadata } from "./column-metadata.js";
1
3
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
4
  // ReadOnlyCatalogInterface: derives catalog from registered functions + descriptors.
3
5
 
4
- import { type VgiSchema, schema as schema_, type VgiField, field, type VgiDataType, int64, utf8, binary, bool, nullType, list, isInt, typeSignature } from "../arrow/index.js";
6
+ import { type VgiSchema, schema as schema_, type VgiField, field, type VgiDataType, int64, utf8, binary, bool, nullType, list, isInt, isStruct, typeSignature } from "../arrow/index.js";
5
7
  import {
6
8
  CatalogInterface,
7
9
  type AttachOpaqueData,
@@ -14,7 +16,6 @@ import {
14
16
  type FunctionInfo,
15
17
  type MacroInfo,
16
18
  type IndexInfo,
17
- type IndexConstraintType,
18
19
  type CopyFromFormatInfo,
19
20
  encodeAttachCatalogInfo,
20
21
  encodeScanFunctionResult,
@@ -24,7 +25,7 @@ import { schemaDescriptorPath, type CatalogDescriptor, type SchemaDescriptor, ty
24
25
  import { serializeColumnStatistics } from "../util/statistics.js";
25
26
  import type { VgiFunction } from "../functions/types.js";
26
27
  import type { FunctionRegistry } from "../functions/registry.js";
27
- import { argumentSpecsToSchema, macroArgumentsSchema } from "../arguments/argument-spec.js";
28
+ import { argumentSpecsToSchema } from "../arguments/argument-spec.js";
28
29
  import { serializeSchema, serializeBatch, emptyBatch, batchFromColumns } from "../util/arrow/index.js";
29
30
  import { resolveMetadata } from "../metadata/resolve.js";
30
31
  import { type AttachOptionSpec, validateRequiredAttachOptions } from "./attach-option.js";
@@ -35,6 +36,9 @@ import { ForeignKeyInfoSchema } from "../generated/vgi-protocol-schemas.js";
35
36
  import { conformColumns } from "../codec/conform.js";
36
37
  import { VgiError } from "../errors.js";
37
38
  import { encodeFunctionInfoOnce, freezeCatalogItem } from "./item-encoding.js";
39
+ import { macroOverloads } from "./macro-overloads.js";
40
+ import { CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION, selectReadProfiles, validateConstraintNullability } from "./constraints.js";
41
+ import { encodeCatalogCapabilities } from "../generated/vgi-protocol-types.js";
38
42
 
39
43
  /**
40
44
  * The fixed attach id ReadOnlyCatalogInterface writes into its items (same
@@ -100,6 +104,10 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
100
104
  options: { perAttachItemIds?: boolean } = {},
101
105
  ) {
102
106
  super();
107
+ if (descriptor.defaultSchema != null &&
108
+ (descriptor.defaultSchema.length === 0 || descriptor.defaultSchema.includes("\0"))) {
109
+ throw new Error("defaultSchema must be a non-empty raw root identifier without NUL, or null");
110
+ }
103
111
  this._descriptor = descriptor;
104
112
  this._registry = registry;
105
113
  if (options.perAttachItemIds) this.perAttachItemIds = true;
@@ -178,6 +186,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
178
186
  options?: Record<string, unknown>,
179
187
  dataVersionSpec?: string | null,
180
188
  implementationVersion?: string | null,
189
+ clientCapabilities?: Uint8Array | null,
181
190
  ): CatalogAttachResult | Promise<CatalogAttachResult> {
182
191
  if (!this.catalogs().includes(name)) {
183
192
  throw new VgiError(`No worker handles catalog '${name}'`, "NOT_FOUND");
@@ -205,6 +214,10 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
205
214
  encodeAttachCatalogInfo(c)
206
215
  );
207
216
 
217
+ // Constraint records are readable only under a negotiated profile.
218
+ const available = this.catalogReadProfiles();
219
+ const read = selectReadProfiles(available, clientCapabilities);
220
+
208
221
  // Auto-derive supportsTimeTravel from table descriptors
209
222
  const hasTimeTravel = this._descriptor.schemas.some(
210
223
  (s) => s.tables?.some((t) => t.supportsTimeTravel) ?? false
@@ -217,7 +230,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
217
230
  catalog_version_frozen: true,
218
231
  catalog_version: this._version,
219
232
  attach_opaque_data_required: true,
220
- default_schema: this._descriptor.defaultSchema ?? "main",
233
+ default_schema: this._descriptor.defaultSchema === undefined ? "main" : this._descriptor.defaultSchema,
221
234
  settings,
222
235
  secret_types: secretTypes,
223
236
  attach_catalogs: attachCatalogs,
@@ -236,9 +249,27 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
236
249
  // Static, version-frozen catalog: the whole thing can be served in one
237
250
  // catalog_contents call (as vgi-python's ReadOnlyCatalogInterface does).
238
251
  supports_catalog_contents: this.supportsCatalogContents,
252
+ catalog_capabilities: available.length
253
+ ? encodeCatalogCapabilities({ read: [...available].sort(), ddl: [], write: [], transaction: [] })
254
+ : null,
255
+ selected_capabilities: available.length
256
+ ? encodeCatalogCapabilities({ read, ddl: [], write: [], transaction: [] })
257
+ : null,
239
258
  });
240
259
  }
241
260
 
261
+ /**
262
+ * Read profiles this catalog implements. Defaults to constraint records
263
+ * (with scalar CHECK expressions) when any descriptor table carries
264
+ * `constraints`; override when tables are served outside the descriptor.
265
+ */
266
+ catalogReadProfiles(): string[] {
267
+ const hasConstraints = this._descriptor.schemas.some(
268
+ (s) => s.tables?.some((t) => (t.constraints?.length ?? 0) > 0) ?? false
269
+ );
270
+ return hasConstraints ? [CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION] : [];
271
+ }
272
+
242
273
  detach(attachOpaqueData: AttachOpaqueData): void {
243
274
  // Remove attachment
244
275
  for (const [name, id] of this._attachments) {
@@ -353,11 +384,11 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
353
384
  colSchema = applyDefaults(colSchema, t.defaults);
354
385
  }
355
386
  // Apply generated-column expressions as Arrow field metadata
356
- // (`generated_expression`). DuckDB registers these columns as GENERATED
387
+ // (canonical SqlExpression IPC). DuckDB registers these columns as GENERATED
357
388
  // and evaluates the SQL expression client-side — the scan function
358
389
  // should not return values for them.
359
390
  if (t.generatedColumns) {
360
- colSchema = applyGeneratedColumns(colSchema, t.generatedColumns);
391
+ colSchema = applyGeneratedColumns(colSchema, t.generatedColumns, path);
361
392
  }
362
393
  // Apply per-column comments as Arrow field metadata (matches Python's
363
394
  // `comment` metadata key on columns).
@@ -365,41 +396,38 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
365
396
  colSchema = applyColumnComments(colSchema, t.columnComments);
366
397
  }
367
398
 
399
+ validateColumnMetadata(colSchema);
400
+ // The extension rejects the table at ATTACH when these disagree.
401
+ validateConstraintNullability(t.name, colSchema.fields, t.constraints ?? []);
402
+ validateColumnExpressions(colSchema, path);
368
403
  const columns = serializeSchema(colSchema);
369
404
 
370
- // Resolve constraint column names → indices
371
- const notNullIndices = resolveIndices(colSchema, t.notNull);
372
- const uniqueIndices = resolveIndexGroups(colSchema, t.unique);
373
- const pkIndices = resolveIndexGroups(colSchema, t.primaryKey);
374
- const fkBytes = serializeForeignKeys(t.foreignKey, path);
375
-
376
- // Validate required_filters: an AND (outer list) of OR-groups (inner
377
- // lists). Each OR-group must be non-empty, and the leading dotted segment
378
- // of each path must be a real column on this table. Struct subfield
379
- // validity is not checked here — DuckDB's binder catches typos at scan
380
- // time, and the descriptor doesn't unpack STRUCT subfields. (Mirrors
381
- // vgi-python's Table descriptor validation.)
405
+ if (t.notNull?.length || t.unique?.length || t.primaryKey?.length || t.check?.length || t.foreignKey?.length) {
406
+ throw new Error(
407
+ `Table '${t.name}': notNull/unique/primaryKey/check/foreignKey are not sent under vgi.v3; ` +
408
+ "declare canonical records with constraintRecord() in `constraints` instead"
409
+ );
410
+ }
411
+
412
+ // Validate exact raw paths against the full table schema.
382
413
  const requiredFilters = t.requiredFilters ?? [];
383
- if (requiredFilters.length > 0) {
384
- const columnNames = new Set(colSchema.fields.map((f) => f.name));
385
- for (const group of requiredFilters) {
386
- if (!group || group.length === 0) {
387
- throw new Error(
388
- `Table '${t.name}': requiredFilters must not contain empty groups`
389
- );
390
- }
391
- for (const path of group) {
392
- if (!path) {
393
- throw new Error(
394
- `Table '${t.name}': requiredFilters must not contain empty strings`
395
- );
396
- }
397
- const head = path.split(".", 1)[0];
398
- if (!columnNames.has(head)) {
399
- throw new Error(
400
- `Table '${t.name}': requiredFilters path '${path}' references ` +
401
- `unknown column '${head}'. Available columns: ${[...columnNames].sort().join(", ")}`
402
- );
414
+ for (const group of requiredFilters) {
415
+ if (!Array.isArray(group) || group.length === 0) throw new Error("requiredFilters contains an empty group");
416
+ const seen = new Set<string>();
417
+ for (const path of group) {
418
+ if (!Array.isArray(path) || path.length === 0) throw new Error("requiredFilters requires raw nonempty paths");
419
+ const key = JSON.stringify(path);
420
+ if (seen.has(key)) throw new Error("requiredFilters contains a duplicate path");
421
+ seen.add(key);
422
+ let fields = colSchema.fields;
423
+ for (let i = 0; i < path.length; ++i) {
424
+ const part = path[i];
425
+ if (typeof part !== "string" || !part || part.includes("\0")) throw new Error("invalid requiredFilters component");
426
+ const matches = fields.filter((f) => f.name === part);
427
+ if (matches.length !== 1) throw new Error(`unknown or ambiguous requiredFilters component: ${part}`);
428
+ if (i + 1 < path.length) {
429
+ if (!isStruct(matches[0].type)) throw new Error(`non-struct requiredFilters parent: ${part}`);
430
+ fields = (matches[0].type as VgiDataType & { children: readonly VgiField[] }).children;
403
431
  }
404
432
  }
405
433
  }
@@ -411,11 +439,8 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
411
439
  name: t.name,
412
440
  schema_path: normalizeSchemaPath(path),
413
441
  columns,
414
- not_null_constraints: notNullIndices,
415
- unique_constraints: uniqueIndices,
416
- check_constraints: t.check ?? [],
417
- primary_key_constraints: pkIndices,
418
- foreign_key_constraints: fkBytes,
442
+ constraints: t.constraints ?? [],
443
+ definition_revision: t.definitionRevision ?? null,
419
444
  write_result_modes: {},
420
445
  supports_column_statistics: t.statistics != null && Object.keys(t.statistics).length > 0,
421
446
  // Inline scan_function only for purely function-backed tables.
@@ -473,6 +498,8 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
473
498
  schema_path: normalizeSchemaPath(path),
474
499
  definition: v.definition,
475
500
  column_comments: v.columnComments ?? {},
501
+ aliases: [...(v.aliases ?? [])],
502
+ security: v.security ?? "regular",
476
503
  }));
477
504
  }
478
505
 
@@ -758,16 +785,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
758
785
  name: m.name,
759
786
  schema_path: normalizeSchemaPath(path),
760
787
  macro_type: (m.macroType === "scalar" ? "SCALAR" : "TABLE") as "SCALAR" | "TABLE",
761
- parameters: m.parameters,
762
- parameter_default_values: m.parameterDefaultValues ?? new Uint8Array(0),
763
- definition: m.definition,
764
- // One nullable Arrow field per parameter (in order), carrying each
765
- // documented parameter's description via the vgi_doc field-metadata key
766
- // (the same channel functions use). Type = default-value type when known
767
- // else null. Serialized as IPC bytes into the generated schema slot.
768
- arguments_schema: serializeSchema(
769
- macroArgumentsSchema(m.parameters, m.parameterDefaultValues, m.parameterDocs),
770
- ),
788
+ overloads: macroOverloads(m, normalizeSchemaPath(path)),
771
789
  }));
772
790
  }
773
791
 
@@ -778,17 +796,19 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
778
796
  ): IndexInfo[] {
779
797
  const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
780
798
  if (!schema || !schema.indexes) return [];
781
- return schema.indexes.map((idx) => ({
782
- comment: idx.comment ?? null,
783
- tags: idx.tags ?? {},
784
- name: idx.name,
785
- schema_path: normalizeSchemaPath(path),
786
- table_name: idx.tableName,
787
- index_type: idx.indexType ?? "ART",
788
- constraint_type: (idx.constraintType ?? "NONE") as IndexConstraintType,
789
- expressions: idx.expressions,
790
- options: idx.options ?? {},
791
- }));
799
+ return schema.indexes.map((idx) => {
800
+ if (!idx.definition || !idx.options) {
801
+ throw new Error("index discovery requires a canonical definition and typed option state");
802
+ }
803
+ return {
804
+ comment: idx.comment ?? null,
805
+ tags: idx.tags ?? {},
806
+ name: idx.name,
807
+ schema_path: normalizeSchemaPath(path),
808
+ definition: idx.definition,
809
+ options: idx.options,
810
+ };
811
+ });
792
812
  }
793
813
 
794
814
  override indexGet(
@@ -1001,18 +1021,20 @@ function applyDefaults(schema: VgiSchema, defaults: Record<string, DefaultValue>
1001
1021
  return result;
1002
1022
  }
1003
1023
 
1004
- function applyGeneratedColumns(schema: VgiSchema, generated: Record<string, string>): VgiSchema {
1024
+ function applyGeneratedColumns(schema: VgiSchema, generated: Record<string, string>, owner: string[]): VgiSchema {
1005
1025
  let result = schema;
1006
1026
  for (const [colName, expression] of Object.entries(generated)) {
1007
1027
  const idx = result.fields.findIndex((f) => f.name === colName);
1008
- if (idx < 0) continue;
1028
+ if (idx < 0) throw new Error(`generated expression references unknown column ${colName}`);
1009
1029
  const f = result.fields[idx];
1010
1030
  const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
1011
- existingMeta.set("generated_expression", expression);
1031
+ if (existingMeta.has(GENERATED_EXPRESSION_KEY) || existingMeta.has("generated_expression")) throw new Error("generated convenience conflicts with existing expression metadata");
1032
+ existingMeta.set(GENERATED_EXPRESSION_KEY, generatedExpressionMetadata(expression, owner));
1033
+ existingMeta.set(GENERATION_KEY, "virtual");
1012
1034
  const newField = field(f.name, f.type, f.nullable, existingMeta);
1013
1035
  const fields = [...result.fields];
1014
1036
  fields[idx] = newField;
1015
- result = schema_(fields);
1037
+ result = schema_(fields, result.metadata);
1016
1038
  }
1017
1039
  return result;
1018
1040
  }
@@ -1020,16 +1042,15 @@ function applyGeneratedColumns(schema: VgiSchema, generated: Record<string, stri
1020
1042
  function applyColumnComments(schema: VgiSchema, comments: Record<string, string>): VgiSchema {
1021
1043
  let result = schema;
1022
1044
  for (const [colName, comment] of Object.entries(comments)) {
1023
- if (!comment) continue;
1024
1045
  const idx = result.fields.findIndex((f) => f.name === colName);
1025
- if (idx < 0) continue;
1046
+ if (idx < 0) throw new Error(`column comment references unknown field ${colName}`);
1026
1047
  const f = result.fields[idx];
1027
1048
  const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
1028
1049
  existingMeta.set("comment", comment);
1029
1050
  const newField = field(f.name, f.type, f.nullable, existingMeta);
1030
1051
  const fields = [...result.fields];
1031
1052
  fields[idx] = newField;
1032
- result = schema_(fields);
1053
+ result = schema_(fields, result.metadata);
1033
1054
  }
1034
1055
  return result;
1035
1056
  }
@@ -0,0 +1,23 @@
1
+ // Copyright 2026 Query Farm LLC - https://query.farm
2
+ import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
3
+ import { deserializeSchema, isStruct, type VgiField } from "../arrow/index.js";
4
+
5
+ /** No constraint authority means every SQL user field must remain nullable. */
6
+ export function requireUnconstrainedColumns(columns: Uint8Array): void {
7
+ const visit = (field: VgiField, top: boolean, depth: number): void => {
8
+ if (depth > 64) throw new MethodNotImplementedError("catalog_table_create: column nesting exceeds supported depth");
9
+ if (top && field.metadata?.has("is_row_id")) return;
10
+ for (const key of field.metadata?.keys() ?? []) {
11
+ if (key === "ARROW:extension:name" || key.startsWith("vgi.logical_type.")) {
12
+ throw new MethodNotImplementedError("catalog_table_create: logical column types require negotiation");
13
+ }
14
+ }
15
+ if (!field.nullable) {
16
+ throw new MethodNotImplementedError("catalog_table_create: nonnullable user columns require canonical constraints");
17
+ }
18
+ if (isStruct(field.type)) {
19
+ for (const child of (field.type as VgiField["type"] & { children: readonly VgiField[] }).children) visit(child, false, depth + 1);
20
+ }
21
+ };
22
+ for (const field of deserializeSchema(columns).fields) visit(field, true, 0);
23
+ }
@@ -59,7 +59,7 @@ import { serializeAttachOptions } from "../catalog/attach-options.js";
59
59
  import { VgiClientError, wrapRpcWithErrorEnrichment } from "./errors.js";
60
60
  import { normalizeSchemaPath } from "../schema-path.js";
61
61
  import { encodeASD } from "../codec/asd.js";
62
- import { ClientCapabilitiesSchema, MacroCreateRequestSchema } from "../generated/vgi-protocol-schemas.js";
62
+ import { ClientCapabilitiesSchema, MacroCreateRequestSchema, TableCreateRequestSchema } from "../generated/vgi-protocol-schemas.js";
63
63
  import { decodeCatalogStreams } from "../catalog/contents-codec.js";
64
64
  import { decodeCatalogContentsResponse } from "../generated/vgi-protocol-types.js";
65
65
  import { deserializeInfoList, deserializeTags, toAsyncIterator } from "./helpers.js";
@@ -743,7 +743,7 @@ export class VgiClient {
743
743
  catalog_version_frozen: inner.catalog_version_frozen ?? false,
744
744
  catalog_version: Number(inner.catalog_version ?? 0),
745
745
  attach_opaque_data_required: inner.attach_opaque_data_required ?? true,
746
- default_schema: inner.default_schema ?? "main",
746
+ default_schema: inner.default_schema ?? null,
747
747
  settings: inner.settings
748
748
  ? (Array.isArray(inner.settings) ? inner.settings : [...inner.settings]).map(toUint8Array)
749
749
  : [],
@@ -1189,21 +1189,19 @@ export class VgiClient {
1189
1189
  name: string,
1190
1190
  columns: Uint8Array,
1191
1191
  onConflict: OnCreateConflict,
1192
- notNullConstraints?: number[],
1193
- uniqueConstraints?: number[][],
1194
- checkConstraints?: string[],
1192
+ constraintDefinitions: Uint8Array[] = [],
1195
1193
  transactionOpaqueData?: TransactionOpaqueData,
1196
1194
  ): Promise<void> {
1197
1195
  await this.rpc.call("catalog_table_create", {
1196
+ request: encodeASD(TableCreateRequestSchema, {
1198
1197
  attach_opaque_data: attachOpaqueData,
1199
1198
  schema_path: normalizeSchemaPath(schemaPath),
1200
1199
  name,
1201
1200
  columns,
1202
1201
  on_conflict: onConflictName(onConflict),
1203
- not_null_constraints: notNullConstraints ?? null,
1204
- unique_constraints: uniqueConstraints ?? null,
1205
- check_constraints: checkConstraints ?? null,
1202
+ constraint_definitions: constraintDefinitions,
1206
1203
  transaction_opaque_data: transactionOpaqueData ?? null,
1204
+ }),
1207
1205
  });
1208
1206
  }
1209
1207
 
@@ -1294,20 +1292,20 @@ export class VgiClient {
1294
1292
  attachOpaqueData: AttachOpaqueData,
1295
1293
  schemaPath: string[] | string,
1296
1294
  name: string,
1297
- columnName: string,
1298
- columnType: string,
1299
- defaultValue?: string | null,
1300
- ignoreNotFound?: boolean,
1295
+ columnPath: string[],
1296
+ columnDefinition: Uint8Array,
1297
+ ignoreNotFound: boolean = false,
1298
+ ifColumnNotExists: boolean = false,
1301
1299
  transactionOpaqueData?: TransactionOpaqueData,
1302
1300
  ): Promise<void> {
1303
1301
  await this.rpc.call("catalog_table_column_add", {
1304
1302
  attach_opaque_data: attachOpaqueData,
1305
1303
  schema_path: normalizeSchemaPath(schemaPath),
1306
1304
  name,
1307
- column_name: columnName,
1308
- column_type: columnType,
1309
- default_value: defaultValue ?? null,
1310
- ignore_not_found: ignoreNotFound ?? null,
1305
+ column_path: columnPath,
1306
+ column_definition: columnDefinition,
1307
+ ignore_not_found: ignoreNotFound,
1308
+ if_column_not_exists: ifColumnNotExists,
1311
1309
  transaction_opaque_data: transactionOpaqueData ?? null,
1312
1310
  });
1313
1311
  }
@@ -1317,16 +1315,20 @@ export class VgiClient {
1317
1315
  attachOpaqueData: AttachOpaqueData,
1318
1316
  schemaPath: string[] | string,
1319
1317
  name: string,
1320
- columnName: string,
1321
- ignoreNotFound?: boolean,
1318
+ columnPath: string[],
1319
+ ignoreNotFound: boolean = false,
1320
+ ifColumnExists: boolean = false,
1321
+ cascade: boolean = false,
1322
1322
  transactionOpaqueData?: TransactionOpaqueData,
1323
1323
  ): Promise<void> {
1324
1324
  await this.rpc.call("catalog_table_column_drop", {
1325
1325
  attach_opaque_data: attachOpaqueData,
1326
1326
  schema_path: normalizeSchemaPath(schemaPath),
1327
1327
  name,
1328
- column_name: columnName,
1329
- ignore_not_found: ignoreNotFound ?? null,
1328
+ column_path: columnPath,
1329
+ ignore_not_found: ignoreNotFound,
1330
+ if_column_exists: ifColumnExists,
1331
+ cascade: cascade,
1330
1332
  transaction_opaque_data: transactionOpaqueData ?? null,
1331
1333
  });
1332
1334
  }
@@ -1336,39 +1338,60 @@ export class VgiClient {
1336
1338
  attachOpaqueData: AttachOpaqueData,
1337
1339
  schemaPath: string[] | string,
1338
1340
  name: string,
1339
- columnName: string,
1340
- newName: string,
1341
- ignoreNotFound?: boolean,
1341
+ columnPath: string[],
1342
+ newColumnName: string,
1343
+ ignoreNotFound: boolean = false,
1342
1344
  transactionOpaqueData?: TransactionOpaqueData,
1343
1345
  ): Promise<void> {
1344
1346
  await this.rpc.call("catalog_table_column_rename", {
1345
1347
  attach_opaque_data: attachOpaqueData,
1346
1348
  schema_path: normalizeSchemaPath(schemaPath),
1347
1349
  name,
1348
- column_name: columnName,
1349
- new_name: newName,
1350
- ignore_not_found: ignoreNotFound ?? null,
1350
+ column_path: columnPath,
1351
+ new_column_name: newColumnName,
1352
+ ignore_not_found: ignoreNotFound,
1353
+ transaction_opaque_data: transactionOpaqueData ?? null,
1354
+ });
1355
+ }
1356
+
1357
+ /** Set or clear the comment on a column. */
1358
+ async tableColumnCommentSet(
1359
+ attachOpaqueData: AttachOpaqueData,
1360
+ schemaPath: string[] | string,
1361
+ name: string,
1362
+ columnPath: string[],
1363
+ comment: string | null,
1364
+ ignoreNotFound: boolean = false,
1365
+ transactionOpaqueData?: TransactionOpaqueData,
1366
+ ): Promise<void> {
1367
+ await this.rpc.call("catalog_table_column_comment_set", {
1368
+ attach_opaque_data: attachOpaqueData,
1369
+ schema_path: normalizeSchemaPath(schemaPath),
1370
+ name,
1371
+ column_path: columnPath,
1372
+ comment,
1373
+ ignore_not_found: ignoreNotFound,
1351
1374
  transaction_opaque_data: transactionOpaqueData ?? null,
1352
1375
  });
1353
1376
  }
1354
1377
 
1355
- /** Set the default value for a column. */
1378
+ /** Set the default using a serialized canonical SqlExpression record. */
1356
1379
  async tableColumnDefaultSet(
1357
1380
  attachOpaqueData: AttachOpaqueData,
1358
1381
  schemaPath: string[] | string,
1359
1382
  name: string,
1360
- columnName: string,
1361
- defaultValue: string,
1362
- ignoreNotFound?: boolean,
1383
+ columnPath: string[],
1384
+ expression: Uint8Array,
1385
+ ignoreNotFound: boolean = false,
1363
1386
  transactionOpaqueData?: TransactionOpaqueData,
1364
1387
  ): Promise<void> {
1365
1388
  await this.rpc.call("catalog_table_column_default_set", {
1366
1389
  attach_opaque_data: attachOpaqueData,
1367
1390
  schema_path: normalizeSchemaPath(schemaPath),
1368
1391
  name,
1369
- column_name: columnName,
1370
- default_value: defaultValue,
1371
- ignore_not_found: ignoreNotFound ?? null,
1392
+ column_path: columnPath,
1393
+ expression: expression,
1394
+ ignore_not_found: ignoreNotFound,
1372
1395
  transaction_opaque_data: transactionOpaqueData ?? null,
1373
1396
  });
1374
1397
  }
@@ -1378,16 +1401,16 @@ export class VgiClient {
1378
1401
  attachOpaqueData: AttachOpaqueData,
1379
1402
  schemaPath: string[] | string,
1380
1403
  name: string,
1381
- columnName: string,
1382
- ignoreNotFound?: boolean,
1404
+ columnPath: string[],
1405
+ ignoreNotFound: boolean = false,
1383
1406
  transactionOpaqueData?: TransactionOpaqueData,
1384
1407
  ): Promise<void> {
1385
1408
  await this.rpc.call("catalog_table_column_default_drop", {
1386
1409
  attach_opaque_data: attachOpaqueData,
1387
1410
  schema_path: normalizeSchemaPath(schemaPath),
1388
1411
  name,
1389
- column_name: columnName,
1390
- ignore_not_found: ignoreNotFound ?? null,
1412
+ column_path: columnPath,
1413
+ ignore_not_found: ignoreNotFound,
1391
1414
  transaction_opaque_data: transactionOpaqueData ?? null,
1392
1415
  });
1393
1416
  }
@@ -1397,24 +1420,27 @@ export class VgiClient {
1397
1420
  *
1398
1421
  * `columnDefinition` is a serialized Arrow Schema with a single field whose
1399
1422
  * name identifies the target column and whose type is the new column type.
1400
- * `expression` is an optional SQL expression used to convert existing values.
1423
+ * `expression` is a serialized canonical SqlExpression for USING, or null
1424
+ * when no conversion expression was supplied.
1401
1425
  */
1402
1426
  async tableColumnTypeChange(
1403
1427
  attachOpaqueData: AttachOpaqueData,
1404
1428
  schemaPath: string[] | string,
1405
1429
  name: string,
1430
+ columnPath: string[],
1406
1431
  columnDefinition: Uint8Array,
1407
- expression?: string | null,
1408
- ignoreNotFound?: boolean,
1432
+ expression: Uint8Array | null = null,
1433
+ ignoreNotFound: boolean = false,
1409
1434
  transactionOpaqueData?: TransactionOpaqueData,
1410
1435
  ): Promise<void> {
1411
1436
  await this.rpc.call("catalog_table_column_type_change", {
1412
1437
  attach_opaque_data: attachOpaqueData,
1413
1438
  schema_path: normalizeSchemaPath(schemaPath),
1414
1439
  name,
1440
+ column_path: columnPath,
1415
1441
  column_definition: columnDefinition,
1416
- expression: expression ?? null,
1417
- ignore_not_found: ignoreNotFound ?? false,
1442
+ expression: expression,
1443
+ ignore_not_found: ignoreNotFound,
1418
1444
  transaction_opaque_data: transactionOpaqueData ?? null,
1419
1445
  });
1420
1446
  }
@@ -1424,16 +1450,16 @@ export class VgiClient {
1424
1450
  attachOpaqueData: AttachOpaqueData,
1425
1451
  schemaPath: string[] | string,
1426
1452
  name: string,
1427
- columnName: string,
1428
- ignoreNotFound?: boolean,
1453
+ columnPath: string[],
1454
+ ignoreNotFound: boolean = false,
1429
1455
  transactionOpaqueData?: TransactionOpaqueData,
1430
1456
  ): Promise<void> {
1431
1457
  await this.rpc.call("catalog_table_not_null_set", {
1432
1458
  attach_opaque_data: attachOpaqueData,
1433
1459
  schema_path: normalizeSchemaPath(schemaPath),
1434
1460
  name,
1435
- column_name: columnName,
1436
- ignore_not_found: ignoreNotFound ?? null,
1461
+ column_path: columnPath,
1462
+ ignore_not_found: ignoreNotFound,
1437
1463
  transaction_opaque_data: transactionOpaqueData ?? null,
1438
1464
  });
1439
1465
  }
@@ -1443,16 +1469,16 @@ export class VgiClient {
1443
1469
  attachOpaqueData: AttachOpaqueData,
1444
1470
  schemaPath: string[] | string,
1445
1471
  name: string,
1446
- columnName: string,
1447
- ignoreNotFound?: boolean,
1472
+ columnPath: string[],
1473
+ ignoreNotFound: boolean = false,
1448
1474
  transactionOpaqueData?: TransactionOpaqueData,
1449
1475
  ): Promise<void> {
1450
1476
  await this.rpc.call("catalog_table_not_null_drop", {
1451
1477
  attach_opaque_data: attachOpaqueData,
1452
1478
  schema_path: normalizeSchemaPath(schemaPath),
1453
1479
  name,
1454
- column_name: columnName,
1455
- ignore_not_found: ignoreNotFound ?? null,
1480
+ column_path: columnPath,
1481
+ ignore_not_found: ignoreNotFound,
1456
1482
  transaction_opaque_data: transactionOpaqueData ?? null,
1457
1483
  });
1458
1484
  }
@@ -1484,12 +1510,22 @@ export class VgiClient {
1484
1510
  definition: string,
1485
1511
  onConflict: OnCreateConflict,
1486
1512
  transactionOpaqueData?: TransactionOpaqueData,
1513
+ aliases?: string[],
1514
+ security: "regular" | "barrier" = "regular",
1515
+ comment?: string | null,
1516
+ tags?: Record<string, string> | null,
1517
+ columnComments?: Record<string, string> | null,
1487
1518
  ): Promise<void> {
1488
1519
  await this.rpc.call("catalog_view_create", {
1489
1520
  attach_opaque_data: attachOpaqueData,
1490
1521
  schema_path: normalizeSchemaPath(schemaPath),
1491
1522
  name,
1492
1523
  definition,
1524
+ aliases: aliases ?? null,
1525
+ security,
1526
+ comment: comment ?? null,
1527
+ tags: tags ?? null,
1528
+ column_comments: columnComments ?? null,
1493
1529
  on_conflict: onConflictName(onConflict),
1494
1530
  transaction_opaque_data: transactionOpaqueData ?? null,
1495
1531
  });
@@ -1556,6 +1592,18 @@ export class VgiClient {
1556
1592
  // Macro Catalog API
1557
1593
  // ==========================================================================
1558
1594
 
1595
+ /** Set or clear a comment on one raw view output name. */
1596
+ async viewColumnCommentSet(
1597
+ attachOpaqueData: AttachOpaqueData, schemaPath: string[] | string, name: string, columnPath: string[],
1598
+ comment?: string | null, ignoreNotFound = false, transactionOpaqueData?: TransactionOpaqueData,
1599
+ ): Promise<void> {
1600
+ await this.rpc.call("catalog_view_column_comment_set", {
1601
+ attach_opaque_data: attachOpaqueData, schema_path: normalizeSchemaPath(schemaPath), name,
1602
+ column_path: columnPath, comment: comment ?? null, ignore_not_found: ignoreNotFound,
1603
+ transaction_opaque_data: transactionOpaqueData ?? null,
1604
+ });
1605
+ }
1606
+
1559
1607
  /** Get a macro by name, or null if not found. */
1560
1608
  async macroGet(
1561
1609
  attachOpaqueData: AttachOpaqueData,
@@ -1599,11 +1647,8 @@ export class VgiClient {
1599
1647
  schemaPath: string[] | string,
1600
1648
  name: string,
1601
1649
  macroType: MacroType,
1602
- parameters: string[],
1603
- definition: string,
1650
+ overloads: import("../generated/vgi-client.js").MacroOverload[],
1604
1651
  onConflict: OnCreateConflict,
1605
- parameterDefaultValues?: Uint8Array | null,
1606
- argumentsSchema?: Uint8Array | null,
1607
1652
  transactionOpaqueData?: TransactionOpaqueData,
1608
1653
  ): Promise<void> {
1609
1654
  const innerBatch = batchFromColumns(
@@ -1612,11 +1657,8 @@ export class VgiClient {
1612
1657
  schema_path: [normalizeSchemaPath(schemaPath)],
1613
1658
  name: [name],
1614
1659
  macro_type: [macroType],
1615
- parameters: [parameters],
1616
- definition: [definition],
1660
+ overloads: [overloads],
1617
1661
  on_conflict: [onConflictName(onConflict)],
1618
- parameter_default_values: [parameterDefaultValues ?? null],
1619
- arguments_schema: [argumentsSchema ?? null],
1620
1662
  transaction_opaque_data: [transactionOpaqueData ?? null],
1621
1663
  },
1622
1664
  MacroCreateRequestSchema,