@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
@@ -0,0 +1,207 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ // Canonical constraint records for catalogs that state their own facts.
3
+
4
+ import { encodeASD, decodeASD } from "../codec/asd.js";
5
+ import { isStruct, type VgiDataType, type VgiField } from "../arrow/index.js";
6
+ import {
7
+ CatalogObjectRefSchema,
8
+ ClientCapabilitiesSchema,
9
+ ConstraintDefinitionSchema,
10
+ ConstraintInfoSchema,
11
+ ForeignKeyDefinitionSchema,
12
+ SqlExpressionSchema,
13
+ } from "../generated/vgi-protocol-schemas.js";
14
+ import { decodeCatalogCapabilities, type CatalogCapabilities } from "../generated/vgi-protocol-types.js";
15
+
16
+ /** Read profile: the catalog serves canonical ConstraintInfo records. */
17
+ export const CONSTRAINT_RECORDS_READ = "vgi.constraint.records.read.v1";
18
+ /** Read profile: CHECK constraints carry DuckDB scalar SQL expressions. */
19
+ export const ROW_SCALAR_EXPRESSION = "vgi.expression.duckdb.scalar.v1";
20
+
21
+ export type ConstraintKind = "NOT_NULL" | "PRIMARY_KEY" | "UNIQUE" | "CHECK" | "FOREIGN_KEY";
22
+ /** Whether the authority enforces the constraint on every write path. */
23
+ export type ConstraintEnforcement = "ENFORCED" | "METADATA_ONLY";
24
+ /** Coverage of existing rows; only ALL_ROWS justifies engine facts. */
25
+ export type ConstraintValidation = "ALL_ROWS" | "FUTURE_WRITES" | "UNVALIDATED";
26
+
27
+ export interface ConstraintRecordSpec {
28
+ /** Schema path of the owning table. */
29
+ schemaPath: readonly string[];
30
+ /** Owning table name. */
31
+ table: string;
32
+ /** Stable provider-owned identity, unique within the table. Never derived by the SDK. */
33
+ id: string;
34
+ kind: ConstraintKind;
35
+ /** Raw component paths, e.g. `[["id"]]` or `[["bbox", "xmin"]]`; empty for CHECK. */
36
+ columns: readonly (readonly string[])[];
37
+ /**
38
+ * The provider's attestation. The DuckDB extension reads only
39
+ * ENFORCED + ALL_ROWS records, so state that only when every row the table
40
+ * can ever return satisfies the constraint.
41
+ */
42
+ enforcement: ConstraintEnforcement;
43
+ validation: ConstraintValidation;
44
+ /** Optional SQL label (CONSTRAINT <name>). */
45
+ declaredName?: string;
46
+ /** CHECK only: a DuckDB scalar expression over the table's columns. */
47
+ checkSql?: string;
48
+ /** FOREIGN_KEY only: the referenced key and its constraint identity. */
49
+ references?: {
50
+ schemaPath: readonly string[];
51
+ table: string;
52
+ columns: readonly (readonly string[])[];
53
+ /** `id` of the referenced table's PRIMARY_KEY or UNIQUE record. */
54
+ constraintId: string;
55
+ };
56
+ }
57
+
58
+ function objectRef(kind: "table" | "constraint", schemaPath: readonly string[], name: string, ownerTable: string | null): Uint8Array {
59
+ return encodeASD(CatalogObjectRefSchema, { kind, schema_path: schemaPath, name, owner_table: ownerTable });
60
+ }
61
+
62
+ /** Encode one canonical `ConstraintInfo` record for `TableDescriptor.constraints`. */
63
+ export function constraintRecord(spec: ConstraintRecordSpec): Uint8Array {
64
+ if (!spec.id || spec.id.includes("\0")) throw new Error("constraint id must be nonempty without NUL");
65
+ if ((spec.kind === "CHECK") !== (spec.checkSql !== undefined))
66
+ throw new Error("checkSql is required for CHECK and only CHECK");
67
+ if (spec.kind === "CHECK" ? spec.columns.length !== 0 : spec.columns.length === 0)
68
+ throw new Error(spec.kind === "CHECK" ? "CHECK takes no column paths" : `${spec.kind} requires column paths`);
69
+ if (spec.kind === "NOT_NULL" && spec.columns.length !== 1) throw new Error("NOT_NULL requires exactly one column path");
70
+ if ((spec.kind === "FOREIGN_KEY") !== (spec.references !== undefined))
71
+ throw new Error("references is required for FOREIGN_KEY and only FOREIGN_KEY");
72
+ if (spec.references && spec.references.columns.length !== spec.columns.length)
73
+ throw new Error("foreign key local and referenced arity must match");
74
+ const check = spec.checkSql === undefined ? null : encodeASD(SqlExpressionSchema, {
75
+ sql: spec.checkSql,
76
+ profile: ROW_SCALAR_EXPRESSION,
77
+ schema_path: spec.schemaPath,
78
+ evaluation_context: {
79
+ timezone: "UTC", collation: "binary", default_order: "asc",
80
+ default_null_order: "nulls_last", preserve_insertion_order: true,
81
+ },
82
+ });
83
+ const ref = spec.references;
84
+ const foreign = ref === undefined ? null : encodeASD(ForeignKeyDefinitionSchema, {
85
+ referenced_table: objectRef("table", ref.schemaPath, ref.table, null),
86
+ referenced_column_paths: ref.columns,
87
+ match: "SIMPLE", on_update: "NO_ACTION", on_delete: "NO_ACTION",
88
+ });
89
+ return encodeASD(ConstraintInfoSchema, {
90
+ ref: objectRef("constraint", spec.schemaPath, spec.id, spec.table),
91
+ definition: encodeASD(ConstraintDefinitionSchema, {
92
+ kind: spec.kind,
93
+ column_paths: spec.columns,
94
+ declared_name: spec.declaredName ?? null,
95
+ check_expression: check,
96
+ foreign_key: foreign,
97
+ }),
98
+ enforcement: spec.enforcement,
99
+ validation: spec.validation,
100
+ referenced_constraint: ref === undefined ? null : objectRef("constraint", ref.schemaPath, ref.constraintId, ref.table),
101
+ });
102
+ }
103
+
104
+ /**
105
+ * The client-offered profiles from `available`, in canonical (sorted) order.
106
+ * A scalar-expression read is selected only alongside constraint records.
107
+ */
108
+ export function selectReadProfiles(available: readonly string[], clientCapabilities: Uint8Array | null | undefined): string[] {
109
+ if (clientCapabilities == null || available.length === 0) return [];
110
+ const client = decodeASD<{ catalog?: Uint8Array | null }>(ClientCapabilitiesSchema, clientCapabilities);
111
+ const offered: CatalogCapabilities["read"] = client.catalog == null ? [] : decodeCatalogCapabilities(client.catalog).read;
112
+ const selected = available.filter((p) => offered.includes(p));
113
+ if (!selected.includes(CONSTRAINT_RECORDS_READ)) return selected.filter((p) => p !== ROW_SCALAR_EXPRESSION).sort();
114
+ return selected.sort();
115
+ }
116
+
117
+ /** A decoded `ConstraintInfo` record, in `constraintRecord()`'s vocabulary. */
118
+ export interface ConstraintRecordView {
119
+ schemaPath: string[];
120
+ table: string;
121
+ id: string;
122
+ kind: ConstraintKind;
123
+ columns: string[][];
124
+ enforcement: ConstraintEnforcement;
125
+ validation: ConstraintValidation;
126
+ declaredName: string | null;
127
+ checkSql: string | null;
128
+ references: { schemaPath: string[]; table: string; columns: string[][]; constraintId: string | null } | null;
129
+ }
130
+
131
+ type RefRow = { kind: string; schema_path: string[]; name: string; owner_table: string | null };
132
+
133
+ /** Decode a `TableInfo.constraints` entry (the inverse of `constraintRecord`). */
134
+ export function readConstraintRecord(bytes: Uint8Array): ConstraintRecordView {
135
+ const info = decodeASD<any>(ConstraintInfoSchema, bytes);
136
+ const ref = decodeASD<RefRow>(CatalogObjectRefSchema, info.ref);
137
+ const def = decodeASD<any>(ConstraintDefinitionSchema, info.definition);
138
+ const fk = def.foreign_key == null ? null : decodeASD<any>(ForeignKeyDefinitionSchema, def.foreign_key);
139
+ const target = fk == null ? null : decodeASD<RefRow>(CatalogObjectRefSchema, fk.referenced_table);
140
+ const targetKey = info.referenced_constraint == null ? null : decodeASD<RefRow>(CatalogObjectRefSchema, info.referenced_constraint);
141
+ return {
142
+ schemaPath: [...ref.schema_path],
143
+ table: ref.owner_table ?? "",
144
+ id: ref.name,
145
+ kind: def.kind,
146
+ columns: [...def.column_paths].map((p: Iterable<string>) => [...p]),
147
+ enforcement: info.enforcement,
148
+ validation: info.validation,
149
+ declaredName: def.declared_name ?? null,
150
+ checkSql: def.check_expression == null ? null : decodeASD<any>(SqlExpressionSchema, def.check_expression).sql,
151
+ references: fk == null || target == null ? null : {
152
+ schemaPath: [...target.schema_path],
153
+ table: target.name,
154
+ columns: [...fk.referenced_column_paths].map((p: Iterable<string>) => [...p]),
155
+ constraintId: targetKey?.name ?? null,
156
+ },
157
+ };
158
+ }
159
+
160
+ function ordinaryStructChildren(field: VgiField): readonly VgiField[] | null {
161
+ if (!isStruct(field.type)) return null;
162
+ for (const key of field.metadata.keys())
163
+ if (key === "ARROW:extension:name" || key.startsWith("vgi.logical_type.")) return null;
164
+ return (field.type as VgiDataType & { children: readonly VgiField[] }).children;
165
+ }
166
+
167
+ /**
168
+ * Check a table's records the way the DuckDB extension does at ATTACH: every
169
+ * record is ENFORCED + ALL_ROWS, and Arrow nullability agrees with the
170
+ * NOT_NULL/PRIMARY_KEY records (a field, descending through ordinary STRUCTs,
171
+ * is non-nullable exactly when a record names its path).
172
+ */
173
+ export function validateConstraintNullability(
174
+ table: string,
175
+ fields: readonly VgiField[],
176
+ constraints: readonly Uint8Array[],
177
+ ): void {
178
+ const required = new Set<string>();
179
+ for (const bytes of constraints) {
180
+ const record = readConstraintRecord(bytes);
181
+ // DuckDB reads only facts that hold for every row; anything else fails ATTACH.
182
+ if (record.enforcement !== "ENFORCED" || record.validation !== "ALL_ROWS")
183
+ throw new Error(
184
+ `Table '${table}': constraint '${record.id}' is ${record.enforcement}/${record.validation}; ` +
185
+ "DuckDB accepts only ENFORCED + ALL_ROWS records"
186
+ );
187
+ if (record.kind === "NOT_NULL" || record.kind === "PRIMARY_KEY")
188
+ for (const path of record.columns) required.add(JSON.stringify(path));
189
+ }
190
+ const walk = (children: readonly VgiField[], prefix: string[]) => {
191
+ for (const field of children) {
192
+ const path = [...prefix, field.name];
193
+ const key = JSON.stringify(path);
194
+ if (field.nullable === required.has(key)) {
195
+ throw new Error(
196
+ field.nullable
197
+ ? `Table '${table}': column ${path.join(".")} is in a NOT_NULL/PRIMARY_KEY record but its Arrow field is nullable`
198
+ : `Table '${table}': column ${path.join(".")} is non-nullable in Arrow but no NOT_NULL/PRIMARY_KEY record names it; ` +
199
+ "declare one with constraintRecord() or make the field nullable"
200
+ );
201
+ }
202
+ const nested = ordinaryStructChildren(field);
203
+ if (nested) walk(nested, path);
204
+ }
205
+ };
206
+ walk(fields, []);
207
+ }
@@ -1,5 +1,6 @@
1
1
  // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
2
  // Catalog-wide collection streams, independent of delivery and attachment state.
3
+ import { validateTableInfoColumns } from "./column-metadata.js";
3
4
  import { encodeASDCollection, decodeASDCollection } from "../codec/asd.js";
4
5
  import {
5
6
  SchemaInfoSchema, TableInfoSchema, ViewInfoSchema, FunctionInfoSchema, MacroInfoSchema, IndexInfoSchema,
@@ -14,6 +15,7 @@ export const CATALOG_STREAM_KINDS = ["schemas", "tables", "views", "functions",
14
15
  export type CatalogStreams = Pick<CatalogContentsResponse, typeof CATALOG_STREAM_KINDS[number]>;
15
16
 
16
17
  export function encodeCatalogStreams(inventory: readonly SchemaContentsInfo[]): CatalogStreams {
18
+ for (const schema of inventory) for (const table of schema.tables) validateTableInfoColumns(table);
17
19
  const streams = {
18
20
  schemas: encodeASDCollection(SchemaInfoSchema, inventory.map((s) => s.schema)),
19
21
  tables: encodeASDCollection(TableInfoSchema, inventory.flatMap((s) => s.tables)),
@@ -53,7 +55,10 @@ export function decodeCatalogStreams(response: CatalogContentsResponse, ifNoneMa
53
55
  if (!entry) throw new Error("catalog object references an absent schema");
54
56
  return entry;
55
57
  };
56
- for (const item of decodeASDCollection<TableInfo>(TableInfoSchema, response.tables)) owner(item).tables.push(item);
58
+ for (const item of decodeASDCollection<TableInfo>(TableInfoSchema, response.tables)) {
59
+ validateTableInfoColumns(item);
60
+ owner(item).tables.push(item);
61
+ }
57
62
  for (const item of decodeASDCollection<ViewInfo>(ViewInfoSchema, response.views)) owner(item).views.push(item);
58
63
  for (const item of decodeASDCollection<FunctionInfo>(FunctionInfoSchema, response.functions)) {
59
64
  const entry = owner(item);
@@ -25,6 +25,9 @@ export interface ForeignKeyDef {
25
25
  export type DefaultValue = string | number | boolean | null;
26
26
 
27
27
  export interface TableDescriptor {
28
+ /** Canonical ConstraintInfo IPC records with provider-owned stable identities. */
29
+ constraints?: Uint8Array[];
30
+ definitionRevision?: Uint8Array | null;
28
31
  name: string;
29
32
  columns?: VgiSchema;
30
33
  function?: VgiFunction;
@@ -40,7 +43,7 @@ export interface TableDescriptor {
40
43
  /**
41
44
  * Generated (virtual) columns: map of column name → SQL expression computed
42
45
  * from other physical columns. Applied as Arrow field metadata
43
- * `generated_expression`, which the DuckDB VGI extension reads at table
46
+ * canonical SqlExpression IPC with explicit owner/context, which DuckDB reads at table
44
47
  * registration. The backing scan function should not return these columns —
45
48
  * DuckDB evaluates the expressions client-side.
46
49
  */
@@ -59,25 +62,10 @@ export interface TableDescriptor {
59
62
  * (always re-fetch).
60
63
  */
61
64
  statisticsCacheMaxAgeSeconds?: number | null;
62
- /**
63
- * Required WHERE-filter groups in conjunctive normal form — an AND (outer
64
- * list) of OR-groups (inner lists) of dotted-path column references that MUST
65
- * appear in a WHERE expression for any scan of this table. A group is
66
- * satisfied when any one of its paths has a filter; every group must be
67
- * satisfied. So `[["accession_number"], ["ticker", "cik"]]` means
68
- * "accession_number AND one of (ticker, cik)"; a single-path group
69
- * `[["country"]]` is a plain mandatory filter. Paths are top-level names
70
- * (`"country"`) or struct subfields (`"bbox.xmin"`, `"nested.outer.inner"`).
71
- * Empty/undefined (default) means no enforcement — the zero-cost fast path
72
- * for every existing table.
73
- *
74
- * Satisfaction is prefix-based: a present filter on a shorter path satisfies
75
- * any required path it is a prefix of. So a whole-struct filter on `bbox`
76
- * satisfies all of `bbox.xmin` / `.xmax` / `.ymin` / `.ymax`. The VGI DuckDB
77
- * extension's optimizer pass consults this at bind time and throws a
78
- * `BinderException` listing any unsatisfied groups.
79
- */
80
- requiredFilters?: string[][];
65
+ /** AND-of-OR groups of raw component paths, e.g. `[[["bbox", "xmin"]], [["ticker"], ["cik"]]]`.
66
+ * Dots and quotes are literal. A present component prefix satisfies a path;
67
+ * a child does not satisfy its parent. Empty/undefined means no requirements. */
68
+ requiredFilters?: string[][][];
81
69
  supportsTimeTravel?: boolean;
82
70
  /**
83
71
  * Inline cardinality estimate/max surfaced through TableInfo. When set,
@@ -92,6 +80,10 @@ export interface TableDescriptor {
92
80
 
93
81
  export interface ViewDescriptor {
94
82
  name: string;
83
+ /** Ordered raw output identifiers; empty uses query names. */
84
+ aliases?: string[];
85
+ /** Optimization barrier mode; readers must enforce or reject it. */
86
+ security?: "regular" | "barrier";
95
87
  definition: string;
96
88
  comment?: string;
97
89
  /**
@@ -111,11 +103,12 @@ export interface MacroDescriptor {
111
103
  macroType: "scalar" | "table";
112
104
  parameters: string[];
113
105
  parameterDefaultValues?: Uint8Array | null;
106
+ /** Complete canonical family; simple-definition fields must be empty when supplied. */
107
+ overloads?: import("../generated/vgi-client.js").MacroOverload[];
114
108
  /**
115
109
  * Optional mapping of parameter name to a human/agent-facing description.
116
110
  * Keys must appear in `parameters`. Descriptions flow over the wire via the
117
- * macro `arguments_schema`'s `vgi_doc` field metadata (the same channel
118
- * functions use for per-argument docs), so the DuckDB extension's
111
+ * canonical parameter's `documentation` field, so the DuckDB extension's
119
112
  * `vgi_function_arguments()` can surface them. Empty/omitted = no docs.
120
113
  */
121
114
  parameterDocs?: Record<string, string>;
@@ -126,12 +119,10 @@ export interface MacroDescriptor {
126
119
 
127
120
  export interface IndexDescriptor {
128
121
  name: string;
129
- tableName: string;
130
- expressions: string[];
131
- /** UNIQUE / PRIMARY / NONE; defaults to NONE. */
132
- constraintType?: "NONE" | "UNIQUE" | "PRIMARY";
133
- indexType?: string;
134
- options?: Record<string, string>;
122
+ /** Complete provider-authored definition; no expression strings or options are inferred. */
123
+ definition: Uint8Array;
124
+ /** Effective values and persisted override names, including explicit NULL. */
125
+ options: Uint8Array;
135
126
  comment?: string;
136
127
  tags?: Record<string, string>;
137
128
  }
@@ -164,7 +155,8 @@ export interface SecretTypeDescriptor {
164
155
 
165
156
  export interface CatalogDescriptor {
166
157
  name: string;
167
- defaultSchema?: string;
158
+ /** One raw root identifier; null means no implicit default, omitted means main. */
159
+ defaultSchema?: string | null;
168
160
  schemas: SchemaDescriptor[];
169
161
  settings?: SettingDescriptor[];
170
162
  secretTypes?: SecretTypeDescriptor[];
@@ -68,8 +68,8 @@ export type { MacroInfo };
68
68
  export { encodeMacroInfo, decodeMacroInfo } from "../generated/vgi-client.js";
69
69
 
70
70
  // IndexInfo wire shape — declarative indexes a worker advertises and DuckDB
71
- // surfaces under duckdb_indexes(). Constraint type maps to is_unique /
72
- // is_primary on the DuckDB side.
71
+ // surfaces under duckdb_indexes(). Definitions preserve raw paths, contextual
72
+ // expressions, typed options and explicit logical-constraint associations.
73
73
  import type { IndexInfo, IndexConstraintType } from "../generated/vgi-client.js";
74
74
  export type { IndexInfo, IndexConstraintType };
75
75
  export { encodeIndexInfo, decodeIndexInfo } from "../generated/vgi-client.js";
@@ -627,6 +627,7 @@ export abstract class CatalogInterface {
627
627
  options?: Record<string, unknown>,
628
628
  dataVersionSpec?: string | null,
629
629
  implementationVersion?: string | null,
630
+ clientCapabilities?: Uint8Array | null,
630
631
  ): Awaitable<CatalogAttachResult>;
631
632
  /**
632
633
  * List the catalogs this worker exposes with their version metadata. The
@@ -668,8 +669,9 @@ export abstract class CatalogInterface {
668
669
  attachOpaqueData: AttachOpaqueData,
669
670
  path: string[],
670
671
  comment?: string | null,
671
- tags?: any,
672
- transactionOpaqueData?: TransactionOpaqueData
672
+ tags?: Record<string, string> | null,
673
+ transactionOpaqueData?: TransactionOpaqueData,
674
+ onConflict?: string
673
675
  ): Awaitable<void> {
674
676
  throw new CatalogReadOnlyError("schema_create");
675
677
  }
@@ -720,9 +722,7 @@ export abstract class CatalogInterface {
720
722
  name: string,
721
723
  columns: Uint8Array,
722
724
  onConflict: string,
723
- notNullConstraints?: number[],
724
- uniqueConstraints?: number[][],
725
- checkConstraints?: string[],
725
+ constraintDefinitions?: Uint8Array[],
726
726
  transactionOpaqueData?: TransactionOpaqueData
727
727
  ): Awaitable<void> {
728
728
  throw new CatalogReadOnlyError("table_create");
@@ -807,86 +807,100 @@ export abstract class CatalogInterface {
807
807
  attachOpaqueData: AttachOpaqueData,
808
808
  schemaPath: string[],
809
809
  name: string,
810
- columnName: string,
811
- columnType: string,
812
- defaultValue?: string,
813
- ignoreNotFound?: boolean,
814
- transactionOpaqueData?: TransactionOpaqueData
810
+ columnPath: string[],
811
+ columnDefinition: Uint8Array,
812
+ ignoreNotFound: boolean = false,
813
+ ifColumnNotExists: boolean = false,
814
+ transactionOpaqueData?: TransactionOpaqueData,
815
815
  ): Awaitable<void> {
816
- throw new CatalogReadOnlyError("table_column_add");
816
+ throw new CatalogReadOnlyError("catalog_table_column_add");
817
817
  }
818
818
  tableColumnDrop(
819
819
  attachOpaqueData: AttachOpaqueData,
820
820
  schemaPath: string[],
821
821
  name: string,
822
- columnName: string,
823
- ignoreNotFound?: boolean,
824
- transactionOpaqueData?: TransactionOpaqueData
822
+ columnPath: string[],
823
+ ignoreNotFound: boolean = false,
824
+ ifColumnExists: boolean = false,
825
+ cascade: boolean = false,
826
+ transactionOpaqueData?: TransactionOpaqueData,
825
827
  ): Awaitable<void> {
826
- throw new CatalogReadOnlyError("table_column_drop");
828
+ throw new CatalogReadOnlyError("catalog_table_column_drop");
827
829
  }
828
830
  tableColumnRename(
829
831
  attachOpaqueData: AttachOpaqueData,
830
832
  schemaPath: string[],
831
833
  name: string,
832
- columnName: string,
833
- newName: string,
834
- ignoreNotFound?: boolean,
835
- transactionOpaqueData?: TransactionOpaqueData
834
+ columnPath: string[],
835
+ newColumnName: string,
836
+ ignoreNotFound: boolean = false,
837
+ transactionOpaqueData?: TransactionOpaqueData,
838
+ ): Awaitable<void> {
839
+ throw new CatalogReadOnlyError("catalog_table_column_rename");
840
+ }
841
+ tableColumnCommentSet(
842
+ attachOpaqueData: AttachOpaqueData,
843
+ schemaPath: string[],
844
+ name: string,
845
+ columnPath: string[],
846
+ comment: string | null,
847
+ ignoreNotFound: boolean = false,
848
+ transactionOpaqueData?: TransactionOpaqueData,
836
849
  ): Awaitable<void> {
837
- throw new CatalogReadOnlyError("table_column_rename");
850
+ throw new CatalogReadOnlyError("catalog_table_column_comment_set");
838
851
  }
839
852
  tableColumnDefaultSet(
840
853
  attachOpaqueData: AttachOpaqueData,
841
854
  schemaPath: string[],
842
855
  name: string,
843
- columnName: string,
844
- defaultValue: string,
845
- ignoreNotFound?: boolean,
846
- transactionOpaqueData?: TransactionOpaqueData
856
+ columnPath: string[],
857
+ expression: Uint8Array,
858
+ ignoreNotFound: boolean = false,
859
+ transactionOpaqueData?: TransactionOpaqueData,
847
860
  ): Awaitable<void> {
848
- throw new CatalogReadOnlyError("table_column_default_set");
861
+ throw new CatalogReadOnlyError("catalog_table_column_default_set");
849
862
  }
850
863
  tableColumnDefaultDrop(
851
864
  attachOpaqueData: AttachOpaqueData,
852
865
  schemaPath: string[],
853
866
  name: string,
854
- columnName: string,
855
- ignoreNotFound?: boolean,
856
- transactionOpaqueData?: TransactionOpaqueData
867
+ columnPath: string[],
868
+ ignoreNotFound: boolean = false,
869
+ transactionOpaqueData?: TransactionOpaqueData,
857
870
  ): Awaitable<void> {
858
- throw new CatalogReadOnlyError("table_column_default_drop");
871
+ throw new CatalogReadOnlyError("catalog_table_column_default_drop");
859
872
  }
860
873
  tableColumnTypeChange(
861
874
  attachOpaqueData: AttachOpaqueData,
862
875
  schemaPath: string[],
863
876
  name: string,
864
- columnName: string,
865
- newType: string,
866
- ignoreNotFound?: boolean,
867
- transactionOpaqueData?: TransactionOpaqueData
877
+ columnPath: string[],
878
+ columnDefinition: Uint8Array,
879
+ expression: Uint8Array | null = null,
880
+ ignoreNotFound: boolean = false,
881
+ transactionOpaqueData?: TransactionOpaqueData,
868
882
  ): Awaitable<void> {
869
- throw new CatalogReadOnlyError("table_column_type_change");
883
+ throw new CatalogReadOnlyError("catalog_table_column_type_change");
870
884
  }
871
885
  tableNotNullSet(
872
886
  attachOpaqueData: AttachOpaqueData,
873
887
  schemaPath: string[],
874
888
  name: string,
875
- columnName: string,
876
- ignoreNotFound?: boolean,
877
- transactionOpaqueData?: TransactionOpaqueData
889
+ columnPath: string[],
890
+ ignoreNotFound: boolean = false,
891
+ transactionOpaqueData?: TransactionOpaqueData,
878
892
  ): Awaitable<void> {
879
- throw new CatalogReadOnlyError("table_not_null_set");
893
+ throw new CatalogReadOnlyError("catalog_table_not_null_set");
880
894
  }
881
895
  tableNotNullDrop(
882
896
  attachOpaqueData: AttachOpaqueData,
883
897
  schemaPath: string[],
884
898
  name: string,
885
- columnName: string,
886
- ignoreNotFound?: boolean,
887
- transactionOpaqueData?: TransactionOpaqueData
899
+ columnPath: string[],
900
+ ignoreNotFound: boolean = false,
901
+ transactionOpaqueData?: TransactionOpaqueData,
888
902
  ): Awaitable<void> {
889
- throw new CatalogReadOnlyError("table_not_null_drop");
903
+ throw new CatalogReadOnlyError("catalog_table_not_null_drop");
890
904
  }
891
905
  viewGet(
892
906
  attachOpaqueData: AttachOpaqueData,
@@ -902,7 +916,11 @@ export abstract class CatalogInterface {
902
916
  name: string,
903
917
  definition: string,
904
918
  onConflict: string,
905
- transactionOpaqueData?: TransactionOpaqueData
919
+ transactionOpaqueData?: TransactionOpaqueData,
920
+ aliases?: string[],
921
+ comment?: string | null,
922
+ tags?: Record<string, string> | null,
923
+ columnComments?: Record<string, string> | null
906
924
  ): Awaitable<void> {
907
925
  throw new CatalogReadOnlyError("view_create");
908
926
  }
@@ -935,6 +953,12 @@ export abstract class CatalogInterface {
935
953
  ): Awaitable<void> {
936
954
  throw new CatalogReadOnlyError("view_comment_set");
937
955
  }
956
+ viewColumnCommentSet(
957
+ attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columnPath: string[],
958
+ comment?: string | null, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData
959
+ ): Awaitable<void> {
960
+ throw new CatalogReadOnlyError("view_column_comment_set");
961
+ }
938
962
  macroGet(
939
963
  attachOpaqueData: AttachOpaqueData,
940
964
  schemaPath: string[],
@@ -948,17 +972,8 @@ export abstract class CatalogInterface {
948
972
  schemaPath: string[],
949
973
  name: string,
950
974
  macroType: MacroType,
951
- parameters: string[],
952
- definition: string,
975
+ overloads: import("../generated/vgi-client.js").MacroOverload[],
953
976
  onConflict: string,
954
- parameterDefaultValues?: Uint8Array | null,
955
- /**
956
- * Optional Arrow schema (one nullable field per parameter, in `parameters`
957
- * order) serialized as IPC bytes, carrying per-parameter descriptions via the
958
- * `vgi_doc` field metadata key. `null`/omitted when no per-parameter docs are
959
- * supplied. Build with `macroArgumentsSchema` + `serializeSchema`.
960
- */
961
- argumentsSchema?: Uint8Array | null,
962
977
  transactionOpaqueData?: TransactionOpaqueData
963
978
  ): Awaitable<void> {
964
979
  throw new CatalogReadOnlyError("macro_create");
@@ -0,0 +1,44 @@
1
+ // Copyright 2025, 2026 Query Farm LLC - https://query.farm
2
+ import type { MacroDescriptor } from "./descriptors.js";
3
+ import type { MacroOverload } from "../generated/vgi-client.js";
4
+ import { deserializeBatch, projectBatch, serializeBatch } from "../arrow/index.js";
5
+
6
+ /** Convert a simple descriptor without treating default-value types as declarations. */
7
+ export function macroOverloads(macro: MacroDescriptor, owner: string[]): MacroOverload[] {
8
+ if (macro.overloads != null) {
9
+ if (macro.parameters.length || macro.definition || macro.parameterDefaultValues ||
10
+ Object.keys(macro.parameterDocs ?? {}).length) throw new Error("macro family conflicts with single-definition descriptor");
11
+ if (!macro.overloads.length) throw new Error("macro overload family must be nonempty");
12
+ for (const overload of macro.overloads) {
13
+ if (overload.parameters.some(p => p.default_expression != null)) throw new Error("discovery macro defaults must be resolved values");
14
+ if (overload.macro_type !== macro.macroType || JSON.stringify(overload.schema_path) !== JSON.stringify(owner)) {
15
+ throw new Error("macro overload owner and kind must equal the parent macro");
16
+ }
17
+ }
18
+ return macro.overloads;
19
+ }
20
+ if (!macro.definition.trim() || macro.definition.includes("\0")) throw new Error("macro definition must be nonempty SQL without NUL");
21
+ const defaults = macro.parameterDefaultValues?.length ? deserializeBatch(macro.parameterDefaultValues) : null;
22
+ if (defaults && defaults.numRows !== 1) throw new Error("macro defaults require exactly one row");
23
+ for (const name of [...(defaults?.schema.fields.map(f => f.name) ?? []), ...Object.keys(macro.parameterDocs ?? {})]) {
24
+ if (!macro.parameters.includes(name)) throw new Error(`unknown macro parameter '${name}'`);
25
+ }
26
+ const defaultNames = defaults?.schema.fields.map(f => f.name) ?? [];
27
+ if (new Set(defaultNames).size !== defaultNames.length) throw new Error("duplicate macro default");
28
+ const seen = new Set<string>();
29
+ let hasDefault = false;
30
+ const parameters = macro.parameters.map(name => {
31
+ if (!name || name.includes("\0") || seen.has(name.toLowerCase())) throw new Error("invalid or duplicate macro parameter");
32
+ seen.add(name.toLowerCase());
33
+ const index = defaults?.schema.fields.findIndex(f => f.name === name) ?? -1;
34
+ if (index < 0 && hasDefault) throw new Error("required macro parameter cannot follow a default");
35
+ hasDefault ||= index >= 0;
36
+ return { name, declared_type: null, default_expression: null,
37
+ default_value: index < 0 ? null : serializeBatch(projectBatch([index], defaults!)),
38
+ documentation: macro.parameterDocs?.[name] ?? null };
39
+ });
40
+ return [{ parameters, definition: macro.definition, profile: "duckdb.macro.v1",
41
+ schema_path: [...owner], macro_type: macro.macroType,
42
+ evaluation_context: { timezone: "UTC", collation: "binary", default_order: "asc",
43
+ default_null_order: "nulls_last", preserve_insertion_order: true } }];
44
+ }