@query-farm/vgi 0.47.0 → 0.47.2
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/column-expressions.d.ts +22 -1
- package/dist/catalog/column-metadata.d.ts +7 -0
- package/dist/catalog/column-types.d.ts +15 -0
- package/dist/catalog/composite.d.ts +2 -0
- package/dist/catalog/constraints.d.ts +172 -0
- package/dist/catalog/descriptors.d.ts +19 -1
- package/dist/catalog/indexes.d.ts +29 -0
- package/dist/catalog/interface.d.ts +41 -0
- package/dist/catalog/public-codecs.d.ts +6 -0
- package/dist/catalog/read-only.d.ts +9 -0
- package/dist/catalog/sql-grammar.d.ts +53 -0
- package/dist/catalog/unconstrained-columns.d.ts +8 -0
- package/dist/client/types.d.ts +5 -1
- package/dist/client-entry.d.ts +1 -0
- package/dist/client-entry.js +1410 -152
- package/dist/client-entry.js.map +12 -8
- package/dist/index.core.d.ts +1 -0
- package/dist/index.js +1644 -226
- package/dist/index.js.map +19 -15
- package/dist/serve-entry.js +1100 -29
- package/dist/serve-entry.js.map +13 -10
- package/dist/worker-cf-entry.d.ts +2 -1
- package/dist/worker-cf-entry.js +1477 -54
- package/dist/worker-cf-entry.js.map +19 -15
- package/package.json +1 -1
- package/src/catalog/column-expressions.ts +85 -7
- package/src/catalog/column-metadata.ts +20 -2
- package/src/catalog/column-types.ts +50 -0
- package/src/catalog/composite.ts +10 -0
- package/src/catalog/constraints.ts +645 -0
- package/src/catalog/contents-codec.ts +3 -3
- package/src/catalog/descriptors.ts +19 -1
- package/src/catalog/indexes.ts +59 -0
- package/src/catalog/interface.ts +103 -1
- package/src/catalog/public-codecs.ts +36 -0
- package/src/catalog/read-only.ts +115 -30
- package/src/catalog/sql-grammar.ts +476 -0
- package/src/catalog/unconstrained-columns.ts +34 -8
- package/src/client/client.ts +6 -3
- package/src/client/types.ts +5 -1
- package/src/client-entry.ts +4 -0
- package/src/index.core.ts +2 -0
- package/src/protocol/handlers/catalog/admin.ts +19 -2
- package/src/protocol/handlers/catalog/table.ts +58 -11
- package/src/worker-cf-entry.ts +4 -0
|
@@ -7,12 +7,15 @@ import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
|
|
|
7
7
|
|
|
8
8
|
import type { VgiService } from "../../../generated/vgi-service.js";
|
|
9
9
|
import {
|
|
10
|
+
CatalogTableConstraintsApplyResultSchema,
|
|
10
11
|
CatalogTableGetResultSchema,
|
|
11
12
|
ScanBranchesResultSchema,
|
|
12
13
|
ScanFunctionResultSchema,
|
|
13
14
|
} from "../../../generated/vgi-protocol-schemas.js";
|
|
14
15
|
import { toUint8Array } from "../../../util/bytes.js";
|
|
15
|
-
import {
|
|
16
|
+
import { requireCreateColumns } from "../../../catalog/unconstrained-columns.js";
|
|
17
|
+
import { CONSTRAINT_CREATE, CONSTRAINT_ENFORCE, CONSTRAINT_MUTATE, readConstraintRecord } from "../../../catalog/constraints.js";
|
|
18
|
+
import { decodeCatalogObjectRef } from "../../../generated/vgi-protocol-types.js";
|
|
16
19
|
import {
|
|
17
20
|
wrapResult,
|
|
18
21
|
} from "../shared.js";
|
|
@@ -52,28 +55,74 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
52
55
|
// catalog_table_create
|
|
53
56
|
const catalogTableCreate = catalogHandler(signingKey, async (params) => {
|
|
54
57
|
if (params.constraint_definitions == null) throw new Error("constraint_definitions is required");
|
|
55
|
-
|
|
56
|
-
throw new MethodNotImplementedError("catalog_table_create: canonical constraint enforcement is not supported");
|
|
57
|
-
}
|
|
58
|
+
const definitions = Array.from(params.constraint_definitions as Iterable<unknown>, (d) => toUint8Array(d as Uint8Array));
|
|
58
59
|
if (params.comment != null || params.tags != null || params.options != null || params.layout != null) {
|
|
59
60
|
throw new MethodNotImplementedError("catalog_table_create: table metadata/options/layout profiles are not supported");
|
|
60
61
|
}
|
|
62
|
+
const attach = toUint8Array(params.attach_opaque_data);
|
|
63
|
+
const cat = getCatalog();
|
|
64
|
+
if (definitions.length > 0) {
|
|
65
|
+
// DuckDB sends definitions only under a negotiated create profile; refuse
|
|
66
|
+
// here too when the catalog states it does not implement one.
|
|
67
|
+
const caps = await cat.catalogCapabilities(attach);
|
|
68
|
+
if (caps != null && !(caps.ddl.includes(CONSTRAINT_CREATE) && caps.write.includes(CONSTRAINT_ENFORCE))) {
|
|
69
|
+
throw new MethodNotImplementedError(
|
|
70
|
+
"catalog_table_create: this catalog does not enforce constraints (NOT NULL, PRIMARY KEY, UNIQUE, CHECK, " +
|
|
71
|
+
"FOREIGN KEY); it advertises neither vgi.constraint.create.v1 nor vgi.constraint.enforce.v1",
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
validateColumnMetadataIpc(toUint8Array(params.columns));
|
|
62
76
|
validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
|
|
63
|
-
|
|
64
|
-
const cat = getCatalog();
|
|
77
|
+
requireCreateColumns(toUint8Array(params.columns), definitions);
|
|
65
78
|
await cat.tableCreate(
|
|
66
|
-
|
|
79
|
+
attach,
|
|
67
80
|
params.schema_path,
|
|
68
81
|
params.name,
|
|
69
82
|
toUint8Array(params.columns),
|
|
70
83
|
params.on_conflict,
|
|
71
|
-
|
|
84
|
+
definitions,
|
|
72
85
|
params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
|
|
73
86
|
);
|
|
74
87
|
return {};
|
|
75
88
|
});
|
|
76
89
|
|
|
90
|
+
// catalog_table_constraints_apply (ALTER TABLE ... SET/DROP NOT NULL and
|
|
91
|
+
// every other canonical constraint change).
|
|
92
|
+
const catalogTableConstraintsApply = catalogHandler(signingKey, async (params) => {
|
|
93
|
+
const attach = toUint8Array(params.attach_opaque_data);
|
|
94
|
+
const cat = getCatalog();
|
|
95
|
+
const caps = await cat.catalogCapabilities(attach);
|
|
96
|
+
if (caps != null && !caps.ddl.includes(CONSTRAINT_MUTATE)) {
|
|
97
|
+
throw new MethodNotImplementedError("catalog_table_constraints_apply: this catalog does not advertise vgi.constraint.mutate.v1");
|
|
98
|
+
}
|
|
99
|
+
const table = toUint8Array(params.table);
|
|
100
|
+
const expected = toUint8Array(params.expected_revision);
|
|
101
|
+
const changes = Array.from(params.changes as Iterable<unknown>, (c) => toUint8Array(c as Uint8Array));
|
|
102
|
+
if (expected.length === 0 || changes.length === 0) throw new Error("catalog_table_constraints_apply: empty revision or change list");
|
|
103
|
+
const snapshot = await cat.tableConstraintsApply({
|
|
104
|
+
attach_opaque_data: attach,
|
|
105
|
+
table,
|
|
106
|
+
expected_revision: expected,
|
|
107
|
+
changes,
|
|
108
|
+
transaction_opaque_data: params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : null,
|
|
109
|
+
});
|
|
110
|
+
const want = decodeCatalogObjectRef(table);
|
|
111
|
+
const got = decodeCatalogObjectRef(toUint8Array(snapshot.table));
|
|
112
|
+
if (got.name !== want.name || JSON.stringify([...got.schema_path]) !== JSON.stringify([...want.schema_path]))
|
|
113
|
+
throw new Error("catalog_table_constraints_apply: the catalog returned a snapshot of a different table");
|
|
114
|
+
const revision = toUint8Array(snapshot.definition_revision);
|
|
115
|
+
if (revision.length === 0 || (revision.length === expected.length && revision.every((b, i) => b === expected[i])))
|
|
116
|
+
throw new Error(`catalog_table_constraints_apply: table '${want.name}' must return a new, nonempty definition_revision`);
|
|
117
|
+
for (const record of snapshot.constraints) {
|
|
118
|
+
const view = readConstraintRecord(toUint8Array(record));
|
|
119
|
+
if (view.table !== want.name || JSON.stringify(view.schemaPath) !== JSON.stringify([...want.schema_path]))
|
|
120
|
+
throw new Error(`catalog_table_constraints_apply: constraint '${view.id}' belongs to another table`);
|
|
121
|
+
}
|
|
122
|
+
return wrapResult({ table, definition_revision: revision, constraints: snapshot.constraints.map((c) => toUint8Array(c)) },
|
|
123
|
+
CatalogTableConstraintsApplyResultSchema);
|
|
124
|
+
});
|
|
125
|
+
|
|
77
126
|
// catalog_table_drop
|
|
78
127
|
const catalogTableDrop = catalogHandler(signingKey, async (params) => {
|
|
79
128
|
const cat = getCatalog();
|
|
@@ -295,9 +344,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
295
344
|
return {};
|
|
296
345
|
});
|
|
297
346
|
return {
|
|
298
|
-
catalogTableConstraintsApply
|
|
299
|
-
throw new MethodNotImplementedError("catalog_table_constraints_apply");
|
|
300
|
-
},
|
|
347
|
+
catalogTableConstraintsApply,
|
|
301
348
|
catalogTableGet,
|
|
302
349
|
catalogTableCreate,
|
|
303
350
|
catalogTableDrop,
|
package/src/worker-cf-entry.ts
CHANGED
|
@@ -66,6 +66,8 @@ export {
|
|
|
66
66
|
BindResultSchema,
|
|
67
67
|
ScanFunctionResultSchema,
|
|
68
68
|
} from "./index.core.js";
|
|
69
|
+
// vgi.v3 records: constraints, capabilities, column expressions, indexes, macro overloads.
|
|
70
|
+
export * from "./catalog/public-codecs.js";
|
|
69
71
|
|
|
70
72
|
export type {
|
|
71
73
|
CacheControl,
|
|
@@ -86,6 +88,8 @@ export type {
|
|
|
86
88
|
RowTransformConfig,
|
|
87
89
|
RowTransformProcessParams,
|
|
88
90
|
TableInOutBindParams,
|
|
91
|
+
ConstraintRecordSpec,
|
|
92
|
+
ConstraintRecordView,
|
|
89
93
|
} from "./index.core.js";
|
|
90
94
|
|
|
91
95
|
export type { ProtocolConfig } from "./protocol/dispatch.js";
|