@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.
- package/README.md +11 -5
- package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
- package/dist/arrow/impl-arrowjs/iterate.d.ts +2 -0
- package/dist/arrow/impl-flechette/index.d.ts +1 -1
- package/dist/arrow/impl-flechette/iterate.d.ts +2 -0
- package/dist/arrow/index.d.ts +1 -1
- package/dist/catalog/column-expressions.d.ts +8 -0
- package/dist/catalog/column-metadata.d.ts +11 -0
- package/dist/catalog/composite.d.ts +2 -1
- package/dist/catalog/constraints.d.ts +74 -0
- package/dist/catalog/descriptors.d.ts +21 -29
- package/dist/catalog/interface.d.ts +15 -20
- package/dist/catalog/macro-overloads.d.ts +4 -0
- package/dist/catalog/read-only.d.ts +7 -1
- package/dist/catalog/unconstrained-columns.d.ts +2 -0
- package/dist/client/client.d.ts +18 -13
- package/dist/client-entry.js +753 -103
- package/dist/client-entry.js.map +16 -14
- package/dist/functions/projection.d.ts +18 -0
- package/dist/functions/table.d.ts +6 -1
- package/dist/functions/types.d.ts +1 -0
- package/dist/generated/vgi-client.d.ts +177 -36
- package/dist/generated/vgi-protocol-schemas.d.ts +51 -1
- package/dist/generated/vgi-protocol-types.d.ts +317 -3
- package/dist/generated/vgi-service.d.ts +266 -29
- package/dist/index.core.d.ts +3 -1
- package/dist/index.js +1630 -240
- package/dist/index.js.map +41 -34
- package/dist/protocol/dispatch.d.ts +9 -9
- package/dist/protocol/handlers/aggregate.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index.d.ts +1 -1
- package/dist/protocol/handlers/catalog/metadata.d.ts +1 -0
- package/dist/protocol/handlers/function.d.ts +1 -1
- package/dist/protocol/handlers/table-buffering.d.ts +1 -1
- package/dist/protocol/handlers/unimplemented.d.ts +1 -1
- package/dist/protocol/serializers/bind.d.ts +5 -1
- package/dist/protocol/types.d.ts +5 -0
- package/dist/rpc-server.d.ts +6 -6
- package/dist/serve-entry.js +1613 -447
- package/dist/serve-entry.js.map +32 -26
- package/dist/util/arrow/index.d.ts +1 -1
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +1943 -572
- package/dist/worker-cf-entry.js.map +41 -34
- package/dist/worker.d.ts +1 -1
- package/package.json +5 -4
- package/src/arrow/impl-arrowjs/index.ts +1 -1
- package/src/arrow/impl-arrowjs/iterate.ts +9 -1
- package/src/arrow/impl-arrowjs/project.ts +1 -1
- package/src/arrow/impl-flechette/index.ts +1 -1
- package/src/arrow/impl-flechette/ipc.ts +12 -0
- package/src/arrow/impl-flechette/iterate.ts +5 -0
- package/src/arrow/impl-flechette/project.ts +6 -8
- package/src/arrow/index.ts +1 -1
- package/src/catalog/column-expressions.ts +224 -0
- package/src/catalog/column-metadata.ts +151 -0
- package/src/catalog/composite.ts +5 -1
- package/src/catalog/constraints.ts +207 -0
- package/src/catalog/contents-codec.ts +6 -1
- package/src/catalog/descriptors.ts +21 -29
- package/src/catalog/interface.ts +70 -55
- package/src/catalog/macro-overloads.ts +44 -0
- package/src/catalog/read-only.ts +92 -71
- package/src/catalog/unconstrained-columns.ts +23 -0
- package/src/client/client.ts +100 -58
- package/src/codec/asd.ts +3 -1
- package/src/functions/projection.ts +207 -0
- package/src/functions/table.ts +10 -0
- package/src/functions/types.ts +1 -0
- package/src/generated/vgi-client.ts +199 -37
- package/src/generated/vgi-protocol-schemas.ts +455 -41
- package/src/generated/vgi-protocol-types.ts +879 -5
- package/src/generated/vgi-service.ts +514 -42
- package/src/http/client-bundle.ts +1 -1
- package/src/http/fetch.ts +1 -1
- package/src/index.core.ts +5 -0
- package/src/protocol/dispatch.ts +9 -9
- package/src/protocol/handlers/aggregate.ts +1 -1
- package/src/protocol/handlers/catalog/admin.ts +27 -6
- package/src/protocol/handlers/catalog/index.ts +2 -2
- package/src/protocol/handlers/catalog/macro.ts +6 -5
- package/src/protocol/handlers/catalog/metadata.ts +16 -0
- package/src/protocol/handlers/catalog/table.ts +72 -26
- package/src/protocol/handlers/catalog/view.ts +24 -3
- package/src/protocol/handlers/function.ts +67 -1
- package/src/protocol/handlers/table-buffering.ts +1 -1
- package/src/protocol/handlers/unimplemented.ts +6 -6
- package/src/protocol/serializers/bind.ts +17 -1
- package/src/protocol/types.ts +6 -0
- package/src/rpc-server.ts +9 -9
- package/src/util/arrow/index.ts +1 -1
- package/src/worker-cf-entry.ts +6 -0
- package/src/worker.ts +1 -1
package/src/catalog/read-only.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
// (
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
//
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
415
|
-
|
|
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
|
-
|
|
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
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
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
|
|
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)
|
|
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.
|
|
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)
|
|
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
|
+
}
|
package/src/client/client.ts
CHANGED
|
@@ -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 ??
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
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
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
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
|
-
|
|
1321
|
-
ignoreNotFound
|
|
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
|
-
|
|
1329
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
-
|
|
1340
|
-
|
|
1341
|
-
ignoreNotFound
|
|
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
|
-
|
|
1349
|
-
|
|
1350
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
|
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
|
-
|
|
1361
|
-
|
|
1362
|
-
ignoreNotFound
|
|
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
|
-
|
|
1370
|
-
|
|
1371
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
-
|
|
1382
|
-
ignoreNotFound
|
|
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
|
-
|
|
1390
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
|
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
|
|
1408
|
-
ignoreNotFound
|
|
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
|
|
1417
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
-
|
|
1428
|
-
ignoreNotFound
|
|
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
|
-
|
|
1436
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
-
|
|
1447
|
-
ignoreNotFound
|
|
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
|
-
|
|
1455
|
-
ignore_not_found: ignoreNotFound
|
|
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
|
-
|
|
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
|
-
|
|
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,
|