@query-farm/vgi 0.47.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/dist/catalog/constraints.d.ts +74 -0
- package/dist/catalog/read-only.d.ts +6 -0
- package/dist/index.core.d.ts +1 -0
- package/dist/index.js +153 -5
- package/dist/index.js.map +7 -6
- package/dist/serve-entry.js +27 -2
- package/dist/serve-entry.js.map +5 -4
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +150 -4
- package/dist/worker-cf-entry.js.map +8 -7
- package/package.json +1 -1
- package/src/catalog/constraints.ts +207 -0
- package/src/catalog/read-only.ts +30 -1
- package/src/index.core.ts +1 -0
- package/src/protocol/handlers/catalog/admin.ts +18 -2
- package/src/worker-cf-entry.ts +6 -0
|
@@ -3,8 +3,8 @@ export type { VgiFetchOptions } from "./http/fetch.js";
|
|
|
3
3
|
export type { HostingOptions } from "./rpc-server.js";
|
|
4
4
|
export { AuthUnavailableError, GrantKeys, GrantRefusedError, IdentityUnavailableError, StatusError, } from "@query-farm/vgi-rpc";
|
|
5
5
|
export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
|
|
6
|
-
export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
|
|
7
|
-
export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, } from "./index.core.js";
|
|
6
|
+
export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, constraintRecord, readConstraintRecord, CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION, } from "./index.core.js";
|
|
7
|
+
export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, } from "./index.core.js";
|
|
8
8
|
export type { ProtocolConfig } from "./protocol/dispatch.js";
|
|
9
9
|
export type { LandingInfo } from "./http/landing.js";
|
|
10
10
|
export { createLandingRoutes } from "./http/landing.js";
|
package/dist/worker-cf-entry.js
CHANGED
|
@@ -7878,6 +7878,8 @@ function decodeASDCollection(schema, bytes) {
|
|
|
7878
7878
|
}
|
|
7879
7879
|
|
|
7880
7880
|
// src/generated/vgi-protocol-types.ts
|
|
7881
|
+
var encodeCatalogCapabilities = (v) => encodeASD(CatalogCapabilitiesSchema, v);
|
|
7882
|
+
var decodeCatalogCapabilities = (b) => decodeASD(CatalogCapabilitiesSchema, b);
|
|
7881
7883
|
var encodeSqlExpression = (v) => encodeASD(SqlExpressionSchema, v);
|
|
7882
7884
|
var decodeSqlExpression = (b) => decodeASD(SqlExpressionSchema, b);
|
|
7883
7885
|
function buildCatalogAttachResult(init) {
|
|
@@ -10746,6 +10748,128 @@ function catalogStringMap(raw) {
|
|
|
10746
10748
|
return result;
|
|
10747
10749
|
}
|
|
10748
10750
|
|
|
10751
|
+
// src/catalog/constraints.ts
|
|
10752
|
+
init_arrow();
|
|
10753
|
+
var CONSTRAINT_RECORDS_READ = "vgi.constraint.records.read.v1";
|
|
10754
|
+
var ROW_SCALAR_EXPRESSION = "vgi.expression.duckdb.scalar.v1";
|
|
10755
|
+
function objectRef(kind, schemaPath, name, ownerTable) {
|
|
10756
|
+
return encodeASD(CatalogObjectRefSchema, { kind, schema_path: schemaPath, name, owner_table: ownerTable });
|
|
10757
|
+
}
|
|
10758
|
+
function constraintRecord(spec) {
|
|
10759
|
+
if (!spec.id || spec.id.includes("\x00"))
|
|
10760
|
+
throw new Error("constraint id must be nonempty without NUL");
|
|
10761
|
+
if (spec.kind === "CHECK" !== (spec.checkSql !== undefined))
|
|
10762
|
+
throw new Error("checkSql is required for CHECK and only CHECK");
|
|
10763
|
+
if (spec.kind === "CHECK" ? spec.columns.length !== 0 : spec.columns.length === 0)
|
|
10764
|
+
throw new Error(spec.kind === "CHECK" ? "CHECK takes no column paths" : `${spec.kind} requires column paths`);
|
|
10765
|
+
if (spec.kind === "NOT_NULL" && spec.columns.length !== 1)
|
|
10766
|
+
throw new Error("NOT_NULL requires exactly one column path");
|
|
10767
|
+
if (spec.kind === "FOREIGN_KEY" !== (spec.references !== undefined))
|
|
10768
|
+
throw new Error("references is required for FOREIGN_KEY and only FOREIGN_KEY");
|
|
10769
|
+
if (spec.references && spec.references.columns.length !== spec.columns.length)
|
|
10770
|
+
throw new Error("foreign key local and referenced arity must match");
|
|
10771
|
+
const check = spec.checkSql === undefined ? null : encodeASD(SqlExpressionSchema, {
|
|
10772
|
+
sql: spec.checkSql,
|
|
10773
|
+
profile: ROW_SCALAR_EXPRESSION,
|
|
10774
|
+
schema_path: spec.schemaPath,
|
|
10775
|
+
evaluation_context: {
|
|
10776
|
+
timezone: "UTC",
|
|
10777
|
+
collation: "binary",
|
|
10778
|
+
default_order: "asc",
|
|
10779
|
+
default_null_order: "nulls_last",
|
|
10780
|
+
preserve_insertion_order: true
|
|
10781
|
+
}
|
|
10782
|
+
});
|
|
10783
|
+
const ref = spec.references;
|
|
10784
|
+
const foreign = ref === undefined ? null : encodeASD(ForeignKeyDefinitionSchema, {
|
|
10785
|
+
referenced_table: objectRef("table", ref.schemaPath, ref.table, null),
|
|
10786
|
+
referenced_column_paths: ref.columns,
|
|
10787
|
+
match: "SIMPLE",
|
|
10788
|
+
on_update: "NO_ACTION",
|
|
10789
|
+
on_delete: "NO_ACTION"
|
|
10790
|
+
});
|
|
10791
|
+
return encodeASD(ConstraintInfoSchema, {
|
|
10792
|
+
ref: objectRef("constraint", spec.schemaPath, spec.id, spec.table),
|
|
10793
|
+
definition: encodeASD(ConstraintDefinitionSchema, {
|
|
10794
|
+
kind: spec.kind,
|
|
10795
|
+
column_paths: spec.columns,
|
|
10796
|
+
declared_name: spec.declaredName ?? null,
|
|
10797
|
+
check_expression: check,
|
|
10798
|
+
foreign_key: foreign
|
|
10799
|
+
}),
|
|
10800
|
+
enforcement: spec.enforcement,
|
|
10801
|
+
validation: spec.validation,
|
|
10802
|
+
referenced_constraint: ref === undefined ? null : objectRef("constraint", ref.schemaPath, ref.constraintId, ref.table)
|
|
10803
|
+
});
|
|
10804
|
+
}
|
|
10805
|
+
function selectReadProfiles(available, clientCapabilities) {
|
|
10806
|
+
if (clientCapabilities == null || available.length === 0)
|
|
10807
|
+
return [];
|
|
10808
|
+
const client = decodeASD(ClientCapabilitiesSchema, clientCapabilities);
|
|
10809
|
+
const offered = client.catalog == null ? [] : decodeCatalogCapabilities(client.catalog).read;
|
|
10810
|
+
const selected = available.filter((p) => offered.includes(p));
|
|
10811
|
+
if (!selected.includes(CONSTRAINT_RECORDS_READ))
|
|
10812
|
+
return selected.filter((p) => p !== ROW_SCALAR_EXPRESSION).sort();
|
|
10813
|
+
return selected.sort();
|
|
10814
|
+
}
|
|
10815
|
+
function readConstraintRecord(bytes) {
|
|
10816
|
+
const info = decodeASD(ConstraintInfoSchema, bytes);
|
|
10817
|
+
const ref = decodeASD(CatalogObjectRefSchema, info.ref);
|
|
10818
|
+
const def = decodeASD(ConstraintDefinitionSchema, info.definition);
|
|
10819
|
+
const fk = def.foreign_key == null ? null : decodeASD(ForeignKeyDefinitionSchema, def.foreign_key);
|
|
10820
|
+
const target = fk == null ? null : decodeASD(CatalogObjectRefSchema, fk.referenced_table);
|
|
10821
|
+
const targetKey = info.referenced_constraint == null ? null : decodeASD(CatalogObjectRefSchema, info.referenced_constraint);
|
|
10822
|
+
return {
|
|
10823
|
+
schemaPath: [...ref.schema_path],
|
|
10824
|
+
table: ref.owner_table ?? "",
|
|
10825
|
+
id: ref.name,
|
|
10826
|
+
kind: def.kind,
|
|
10827
|
+
columns: [...def.column_paths].map((p) => [...p]),
|
|
10828
|
+
enforcement: info.enforcement,
|
|
10829
|
+
validation: info.validation,
|
|
10830
|
+
declaredName: def.declared_name ?? null,
|
|
10831
|
+
checkSql: def.check_expression == null ? null : decodeASD(SqlExpressionSchema, def.check_expression).sql,
|
|
10832
|
+
references: fk == null || target == null ? null : {
|
|
10833
|
+
schemaPath: [...target.schema_path],
|
|
10834
|
+
table: target.name,
|
|
10835
|
+
columns: [...fk.referenced_column_paths].map((p) => [...p]),
|
|
10836
|
+
constraintId: targetKey?.name ?? null
|
|
10837
|
+
}
|
|
10838
|
+
};
|
|
10839
|
+
}
|
|
10840
|
+
function ordinaryStructChildren(field) {
|
|
10841
|
+
if (!isStruct(field.type))
|
|
10842
|
+
return null;
|
|
10843
|
+
for (const key of field.metadata.keys())
|
|
10844
|
+
if (key === "ARROW:extension:name" || key.startsWith("vgi.logical_type."))
|
|
10845
|
+
return null;
|
|
10846
|
+
return field.type.children;
|
|
10847
|
+
}
|
|
10848
|
+
function validateConstraintNullability(table, fields, constraints) {
|
|
10849
|
+
const required = new Set;
|
|
10850
|
+
for (const bytes of constraints) {
|
|
10851
|
+
const record = readConstraintRecord(bytes);
|
|
10852
|
+
if (record.enforcement !== "ENFORCED" || record.validation !== "ALL_ROWS")
|
|
10853
|
+
throw new Error(`Table '${table}': constraint '${record.id}' is ${record.enforcement}/${record.validation}; ` + "DuckDB accepts only ENFORCED + ALL_ROWS records");
|
|
10854
|
+
if (record.kind === "NOT_NULL" || record.kind === "PRIMARY_KEY")
|
|
10855
|
+
for (const path of record.columns)
|
|
10856
|
+
required.add(JSON.stringify(path));
|
|
10857
|
+
}
|
|
10858
|
+
const walk = (children, prefix) => {
|
|
10859
|
+
for (const field of children) {
|
|
10860
|
+
const path = [...prefix, field.name];
|
|
10861
|
+
const key = JSON.stringify(path);
|
|
10862
|
+
if (field.nullable === required.has(key)) {
|
|
10863
|
+
throw new Error(field.nullable ? `Table '${table}': column ${path.join(".")} is in a NOT_NULL/PRIMARY_KEY record but its Arrow field is nullable` : `Table '${table}': column ${path.join(".")} is non-nullable in Arrow but no NOT_NULL/PRIMARY_KEY record names it; ` + "declare one with constraintRecord() or make the field nullable");
|
|
10864
|
+
}
|
|
10865
|
+
const nested = ordinaryStructChildren(field);
|
|
10866
|
+
if (nested)
|
|
10867
|
+
walk(nested, path);
|
|
10868
|
+
}
|
|
10869
|
+
};
|
|
10870
|
+
walk(fields, []);
|
|
10871
|
+
}
|
|
10872
|
+
|
|
10749
10873
|
// src/protocol/handlers/catalog/contents.ts
|
|
10750
10874
|
import { ExternalRef as ExternalRef2 } from "@query-farm/vgi-rpc";
|
|
10751
10875
|
|
|
@@ -12106,7 +12230,16 @@ function catalogAdminHandlers(getCatalog, signingKey) {
|
|
|
12106
12230
|
innerParams.implementation_version = restored.implementationVersion;
|
|
12107
12231
|
optionsDict = restored.options;
|
|
12108
12232
|
}
|
|
12109
|
-
const
|
|
12233
|
+
const clientCapabilities = innerParams.client_capabilities == null ? null : toUint8Array(innerParams.client_capabilities);
|
|
12234
|
+
const result = await cat.attach(innerParams.name, optionsDict, innerParams.data_version_spec ?? null, innerParams.implementation_version ?? null, clientCapabilities);
|
|
12235
|
+
if (result.catalog_capabilities != null) {
|
|
12236
|
+
const available = decodeCatalogCapabilities(toUint8Array(result.catalog_capabilities));
|
|
12237
|
+
const chosen = result.selected_capabilities == null ? { read: [], ddl: [], write: [], transaction: [] } : decodeCatalogCapabilities(toUint8Array(result.selected_capabilities));
|
|
12238
|
+
result.selected_capabilities = encodeCatalogCapabilities({
|
|
12239
|
+
...chosen,
|
|
12240
|
+
read: selectReadProfiles(available.read, clientCapabilities)
|
|
12241
|
+
});
|
|
12242
|
+
}
|
|
12110
12243
|
const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey);
|
|
12111
12244
|
return wrapResult(buildCatalogAttachResult({
|
|
12112
12245
|
...result,
|
|
@@ -14107,6 +14240,8 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
14107
14240
|
const settings = (this._descriptor.settings ?? []).map((s) => serializeSetting(s));
|
|
14108
14241
|
const secretTypes = (this._descriptor.secretTypes ?? []).map((s) => serializeSecretType(s));
|
|
14109
14242
|
const attachCatalogs = (this._descriptor.attachCatalogs ?? []).map((c) => encodeAttachCatalogInfo(c));
|
|
14243
|
+
const available = this.catalogReadProfiles();
|
|
14244
|
+
const read = selectReadProfiles(available, clientCapabilities);
|
|
14110
14245
|
const hasTimeTravel = this._descriptor.schemas.some((s) => s.tables?.some((t) => t.supportsTimeTravel) ?? false);
|
|
14111
14246
|
return buildCatalogAttachResult({
|
|
14112
14247
|
attach_opaque_data: attachOpaqueData,
|
|
@@ -14126,9 +14261,15 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
14126
14261
|
global_function_prefix: this._descriptor.globalFunctionPrefix ?? "",
|
|
14127
14262
|
resolved_data_version: null,
|
|
14128
14263
|
resolved_implementation_version: null,
|
|
14129
|
-
supports_catalog_contents: this.supportsCatalogContents
|
|
14264
|
+
supports_catalog_contents: this.supportsCatalogContents,
|
|
14265
|
+
catalog_capabilities: available.length ? encodeCatalogCapabilities({ read: [...available].sort(), ddl: [], write: [], transaction: [] }) : null,
|
|
14266
|
+
selected_capabilities: available.length ? encodeCatalogCapabilities({ read, ddl: [], write: [], transaction: [] }) : null
|
|
14130
14267
|
});
|
|
14131
14268
|
}
|
|
14269
|
+
catalogReadProfiles() {
|
|
14270
|
+
const hasConstraints = this._descriptor.schemas.some((s) => s.tables?.some((t) => (t.constraints?.length ?? 0) > 0) ?? false);
|
|
14271
|
+
return hasConstraints ? [CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION] : [];
|
|
14272
|
+
}
|
|
14132
14273
|
detach(attachOpaqueData) {
|
|
14133
14274
|
for (const [name, id] of this._attachments) {
|
|
14134
14275
|
if (bufferEquals(id, attachOpaqueData)) {
|
|
@@ -14226,10 +14367,11 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
14226
14367
|
colSchema = applyColumnComments(colSchema, t.columnComments);
|
|
14227
14368
|
}
|
|
14228
14369
|
validateColumnMetadata(colSchema);
|
|
14370
|
+
validateConstraintNullability(t.name, colSchema.fields, t.constraints ?? []);
|
|
14229
14371
|
validateColumnExpressions(colSchema, path);
|
|
14230
14372
|
const columns = serializeSchema(colSchema);
|
|
14231
14373
|
if (t.notNull?.length || t.unique?.length || t.primaryKey?.length || t.check?.length || t.foreignKey?.length) {
|
|
14232
|
-
throw new Error(
|
|
14374
|
+
throw new Error(`Table '${t.name}': notNull/unique/primaryKey/check/foreignKey are not sent under vgi.v3; ` + "declare canonical records with constraintRecord() in `constraints` instead");
|
|
14233
14375
|
}
|
|
14234
14376
|
const requiredFilters = t.requiredFilters ?? [];
|
|
14235
14377
|
for (const group of requiredFilters) {
|
|
@@ -15249,6 +15391,7 @@ export {
|
|
|
15249
15391
|
AuthContext3 as AuthContext,
|
|
15250
15392
|
AuthUnavailableError2 as AuthUnavailableError,
|
|
15251
15393
|
BindResultSchema,
|
|
15394
|
+
CONSTRAINT_RECORDS_READ,
|
|
15252
15395
|
CatalogInterface,
|
|
15253
15396
|
CompositeCatalogInterface,
|
|
15254
15397
|
DateUnit3 as DateUnit,
|
|
@@ -15261,6 +15404,7 @@ export {
|
|
|
15261
15404
|
IntervalUnit2 as IntervalUnit,
|
|
15262
15405
|
OutputCollector2 as OutputCollector,
|
|
15263
15406
|
PARENT_ROW_METADATA_KEY,
|
|
15407
|
+
ROW_SCALAR_EXPRESSION,
|
|
15264
15408
|
ReadOnlyCatalogInterface,
|
|
15265
15409
|
ScanFunctionResultSchema,
|
|
15266
15410
|
StatusError2 as StatusError,
|
|
@@ -15278,6 +15422,7 @@ export {
|
|
|
15278
15422
|
buildStatisticsBatch,
|
|
15279
15423
|
cacheControlMetadata,
|
|
15280
15424
|
columnFromArray,
|
|
15425
|
+
constraintRecord,
|
|
15281
15426
|
constraintSpecFields,
|
|
15282
15427
|
createLandingRoutes,
|
|
15283
15428
|
createVgiFetch,
|
|
@@ -15340,6 +15485,7 @@ export {
|
|
|
15340
15485
|
parentRowsMetadata,
|
|
15341
15486
|
projectBatch,
|
|
15342
15487
|
projectSchema,
|
|
15488
|
+
readConstraintRecord,
|
|
15343
15489
|
safeNumber,
|
|
15344
15490
|
schema2 as schema,
|
|
15345
15491
|
serializeAttachOptionSpec,
|
|
@@ -15363,4 +15509,4 @@ export {
|
|
|
15363
15509
|
utf82 as utf8
|
|
15364
15510
|
};
|
|
15365
15511
|
|
|
15366
|
-
//# debugId=
|
|
15512
|
+
//# debugId=FE84125A7F5CDDE564756E2164756E21
|