@query-farm/vgi 0.47.1 → 0.48.0
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 +1 -1
- 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 +110 -12
- 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 +3 -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 +1435 -152
- package/dist/client-entry.js.map +15 -11
- package/dist/generated/vgi-client.d.ts +5 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +5 -0
- package/dist/generated/vgi-protocol-types.d.ts +57 -0
- package/dist/generated/vgi-service.d.ts +1 -1
- package/dist/index.core.d.ts +3 -1
- package/dist/index.js +1940 -545
- package/dist/index.js.map +26 -22
- package/dist/protocol/dispatch.d.ts +1 -1
- package/dist/protocol/serializers/splits.d.ts +41 -1
- package/dist/serve-entry.js +1172 -58
- package/dist/serve-entry.js.map +20 -17
- package/dist/worker-cf-entry.d.ts +2 -1
- package/dist/worker-cf-entry.js +1538 -191
- package/dist/worker-cf-entry.js.map +26 -22
- 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 +496 -58
- 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 +92 -36
- 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/generated/vgi-client.ts +6 -1
- package/src/generated/vgi-protocol-schemas.ts +36 -1
- package/src/generated/vgi-protocol-types.ts +130 -1
- package/src/generated/vgi-service.ts +2 -2
- package/src/index.core.ts +34 -1
- package/src/protocol/dispatch.ts +1 -1
- package/src/protocol/handlers/catalog/admin.ts +14 -13
- package/src/protocol/handlers/catalog/table.ts +58 -11
- package/src/protocol/serializers/splits.ts +82 -9
- package/src/worker-cf-entry.ts +2 -4
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ npm install @query-farm/vgi
|
|
|
40
40
|
|
|
41
41
|
Requires **Node.js ≥ 22.15** or **Bun**.
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
This branch uses **`vgi.v3` / `3.1.0`** and requires a matching VGI
|
|
44
44
|
extension. Existing `vgi.v2` extensions need SDK 0.46.x; upgrade the engine-side
|
|
45
45
|
extension and workers together. This release prepares the shared protocol for
|
|
46
46
|
DuckDB 2.0; it does not require upgrading DuckDB itself. See
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import { type VgiSchema } from "../arrow/index.js";
|
|
2
|
+
import type { SqlExpression } from "../generated/vgi-client.js";
|
|
2
3
|
export declare const GENERATED_EXPRESSION_KEY = "vgi.column.generated.v1";
|
|
3
4
|
export declare const GENERATION_KEY = "vgi.column.generation.v1";
|
|
4
|
-
|
|
5
|
+
/** Canonical DEFAULT: base64 of one `SqlExpression` IPC record. */
|
|
6
|
+
export declare const DEFAULT_EXPRESSION_KEY = "vgi.column.default.v1";
|
|
7
|
+
/** Validate one canonical base64 `SqlExpression` and return its SQL. */
|
|
8
|
+
export declare function validateEncoded(encoded: string, owner: string[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Encode `sql` as canonical `vgi.column.generated.v1` metadata (base64 of a
|
|
11
|
+
* `SqlExpression` owned by schema `owner`). Pair it with
|
|
12
|
+
* `vgi.column.generation.v1 = "virtual"` on a nullable field.
|
|
13
|
+
*/
|
|
5
14
|
export declare function generatedExpressionMetadata(sql: string, owner: string[]): string;
|
|
15
|
+
/**
|
|
16
|
+
* Encode `sql` as canonical `vgi.column.default.v1` metadata. DuckDB reads it
|
|
17
|
+
* for boolean, signed-integer, float, decimal128 and utf8 columns; the SQL is a
|
|
18
|
+
* constant expression (no column references).
|
|
19
|
+
*/
|
|
20
|
+
export declare function defaultExpressionMetadata(sql: string, owner: string[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* A DuckDB scalar `SqlExpression` owned by `schemaPath`, in the default
|
|
23
|
+
* evaluation context (UTC, binary collation, ASC NULLS LAST) — the only one the
|
|
24
|
+
* extension's native adapter accepts. Encode with `encodeSqlExpression`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sqlExpression(sql: string, schemaPath: readonly string[]): SqlExpression;
|
|
6
27
|
/** Validate canonical VIRTUAL metadata without evaluating or rewriting SQL. */
|
|
7
28
|
export declare function validateColumnExpressions(schema: VgiSchema, owner: string[], allowGenerated?: boolean): void;
|
|
8
29
|
export declare function validateColumnExpressionsIpc(bytes: Uint8Array, owner: string[], allowGenerated?: boolean): void;
|
|
@@ -8,4 +8,11 @@ export declare function validateColumnMetadata(schema: VgiSchema): void;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function validateColumnMetadataIpc(bytes: Uint8Array): void;
|
|
10
10
|
export declare function validateTableInfoColumns(info: TableInfo): void;
|
|
11
|
+
/**
|
|
12
|
+
* The TableInfo a worker sends: raw column metadata checked on the original
|
|
13
|
+
* bytes, then the served schema (see `servedTableInfo`: constraint records
|
|
14
|
+
* checked as DuckDB checks them, nullability derived from them, legacy
|
|
15
|
+
* generated metadata translated), whose column expressions are checked last.
|
|
16
|
+
*/
|
|
17
|
+
export declare function servedValidatedTableInfo(info: TableInfo): TableInfo;
|
|
11
18
|
export declare function encodeValidatedTableInfo(info: TableInfo): Uint8Array;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type VgiField } from "../arrow/index.js";
|
|
2
|
+
/** The top-level column carrying `is_row_id` metadata (DuckDB's rowid, never a user column). */
|
|
3
|
+
export declare function isRowIdField(field: VgiField): boolean;
|
|
4
|
+
/** Whether the field carries an Arrow extension type or a VGI logical type. */
|
|
5
|
+
export declare function hasLogicalType(field: VgiField): boolean;
|
|
6
|
+
/** A field's children when it is an ordinary STRUCT (not an extension or logical type), else null. */
|
|
7
|
+
export declare function ordinaryStructChildren(field: VgiField): readonly VgiField[] | null;
|
|
8
|
+
/** Whether the field is a generated column (canonical or legacy metadata). */
|
|
9
|
+
export declare function isGeneratedField(field: VgiField): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The DuckDB primitive a field maps to for the bounded expression and CHECK
|
|
12
|
+
* profiles, or null for every other type (unsigned, large/dictionary strings,
|
|
13
|
+
* temporal, nested, extension and logical types).
|
|
14
|
+
*/
|
|
15
|
+
export declare function duckdbPrimitive(field: VgiField): string | null;
|
|
@@ -42,6 +42,8 @@ export declare class CompositeCatalogInterface extends CatalogInterface {
|
|
|
42
42
|
tableColumnTypeChange(...args: Parameters<CatalogInterface["tableColumnTypeChange"]>): Promise<void>;
|
|
43
43
|
tableNotNullSet(...args: Parameters<CatalogInterface["tableNotNullSet"]>): Promise<void>;
|
|
44
44
|
tableNotNullDrop(...args: Parameters<CatalogInterface["tableNotNullDrop"]>): Promise<void>;
|
|
45
|
+
tableConstraintsApply(request: Parameters<CatalogInterface["tableConstraintsApply"]>[0]): ReturnType<CatalogInterface["tableConstraintsApply"]>;
|
|
46
|
+
catalogCapabilities(attachOpaqueData: AttachOpaqueData): Promise<Awaited<ReturnType<CatalogInterface["catalogCapabilities"]>>>;
|
|
45
47
|
viewCreate(...args: Parameters<CatalogInterface["viewCreate"]>): Promise<void>;
|
|
46
48
|
viewDrop(...args: Parameters<CatalogInterface["viewDrop"]>): Promise<void>;
|
|
47
49
|
viewRename(...args: Parameters<CatalogInterface["viewRename"]>): Promise<void>;
|
|
@@ -1,35 +1,52 @@
|
|
|
1
|
-
import { type VgiField } from "../arrow/index.js";
|
|
1
|
+
import { type VgiField, type VgiSchema } from "../arrow/index.js";
|
|
2
|
+
import { type CatalogCapabilities } from "../generated/vgi-protocol-types.js";
|
|
3
|
+
import type { ClientCapabilities, TableInfo } from "../generated/vgi-client.js";
|
|
2
4
|
/** Read profile: the catalog serves canonical ConstraintInfo records. */
|
|
3
5
|
export declare const CONSTRAINT_RECORDS_READ = "vgi.constraint.records.read.v1";
|
|
4
6
|
/** Read profile: CHECK constraints carry DuckDB scalar SQL expressions. */
|
|
5
7
|
export declare const ROW_SCALAR_EXPRESSION = "vgi.expression.duckdb.scalar.v1";
|
|
8
|
+
/** DDL profile: CREATE TABLE may carry canonical constraint definitions. */
|
|
9
|
+
export declare const CONSTRAINT_CREATE = "vgi.constraint.create.v1";
|
|
10
|
+
/** DDL profile: `catalog_table_constraints_apply` (e.g. ALTER ... SET/DROP NOT NULL). */
|
|
11
|
+
export declare const CONSTRAINT_MUTATE = "vgi.constraint.mutate.v1";
|
|
12
|
+
/** Write profile: the provider enforces its ENFORCED records on every write. */
|
|
13
|
+
export declare const CONSTRAINT_ENFORCE = "vgi.constraint.enforce.v1";
|
|
14
|
+
/** Transaction profile: constraint DDL may run inside a catalog transaction. */
|
|
15
|
+
export declare const TRANSACTION_DDL = "vgi.transaction.ddl.v1";
|
|
6
16
|
export type ConstraintKind = "NOT_NULL" | "PRIMARY_KEY" | "UNIQUE" | "CHECK" | "FOREIGN_KEY";
|
|
7
17
|
/** Whether the authority enforces the constraint on every write path. */
|
|
8
18
|
export type ConstraintEnforcement = "ENFORCED" | "METADATA_ONLY";
|
|
9
19
|
/** Coverage of existing rows; only ALL_ROWS justifies engine facts. */
|
|
10
20
|
export type ConstraintValidation = "ALL_ROWS" | "FUTURE_WRITES" | "UNVALIDATED";
|
|
11
21
|
export interface ConstraintRecordSpec {
|
|
12
|
-
/** Schema path of the owning table. */
|
|
22
|
+
/** Schema path of the owning table (one component: DuckDB reads no other). */
|
|
13
23
|
schemaPath: readonly string[];
|
|
14
24
|
/** Owning table name. */
|
|
15
25
|
table: string;
|
|
16
26
|
/** Stable provider-owned identity, unique within the table. Never derived by the SDK. */
|
|
17
27
|
id: string;
|
|
18
28
|
kind: ConstraintKind;
|
|
19
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Raw component paths, e.g. `[["id"]]`; empty for CHECK. Only NOT_NULL may
|
|
31
|
+
* name a nested STRUCT field (`[["bbox", "xmin"]]`).
|
|
32
|
+
*/
|
|
20
33
|
columns: readonly (readonly string[])[];
|
|
21
34
|
/**
|
|
22
35
|
* The provider's attestation. The DuckDB extension reads only
|
|
23
36
|
* ENFORCED + ALL_ROWS records, so state that only when every row the table
|
|
24
|
-
* can ever return satisfies the constraint.
|
|
37
|
+
* can ever return satisfies the constraint; the builder refuses anything else.
|
|
25
38
|
*/
|
|
26
39
|
enforcement: ConstraintEnforcement;
|
|
27
40
|
validation: ConstraintValidation;
|
|
28
|
-
/** Optional SQL label (CONSTRAINT <name>). */
|
|
41
|
+
/** Optional SQL label (CONSTRAINT <name>); unique per table, case-insensitively. */
|
|
29
42
|
declaredName?: string;
|
|
30
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* CHECK only: one numeric comparison, e.g. `price >= 0` or `lo < hi`. Each
|
|
45
|
+
* operand is a numeric literal or a signed-integer/float column; DuckDB reads
|
|
46
|
+
* nothing else.
|
|
47
|
+
*/
|
|
31
48
|
checkSql?: string;
|
|
32
|
-
/** FOREIGN_KEY only: the referenced key and its constraint identity. */
|
|
49
|
+
/** FOREIGN_KEY only: the referenced key (same schema) and its constraint identity. */
|
|
33
50
|
references?: {
|
|
34
51
|
schemaPath: readonly string[];
|
|
35
52
|
table: string;
|
|
@@ -41,10 +58,39 @@ export interface ConstraintRecordSpec {
|
|
|
41
58
|
/** Encode one canonical `ConstraintInfo` record for `TableDescriptor.constraints`. */
|
|
42
59
|
export declare function constraintRecord(spec: ConstraintRecordSpec): Uint8Array;
|
|
43
60
|
/**
|
|
44
|
-
*
|
|
61
|
+
* Build a catalog's profile advertisement (`CatalogAttachResult.catalog_capabilities`).
|
|
62
|
+
* Returned by `CatalogInterface.catalogCapabilities()`; the attach handler
|
|
63
|
+
* selects from it against the client's offer.
|
|
64
|
+
*/
|
|
65
|
+
export declare function catalogCapabilities(init?: Partial<CatalogCapabilities>): CatalogCapabilities;
|
|
66
|
+
/** What a catalog that serves (and enforces/mutates) canonical constraint records advertises. */
|
|
67
|
+
export declare function constraintCapabilities(options?: {
|
|
68
|
+
create?: boolean;
|
|
69
|
+
mutate?: boolean;
|
|
70
|
+
enforce?: boolean;
|
|
71
|
+
transactionDdl?: boolean;
|
|
72
|
+
}): CatalogCapabilities;
|
|
73
|
+
/**
|
|
74
|
+
* Select the client-offered subset of `available`, canonically sorted, keeping
|
|
75
|
+
* a profile only when its prerequisites were selected too (CONSTRAINT_CREATE
|
|
76
|
+
* needs records read + enforcement; the scalar expression read needs records
|
|
77
|
+
* read). The DDL transaction profile requires `supportsTransactions`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function selectCatalogCapabilities(available: CatalogCapabilities, clientCapabilities: Uint8Array | ClientCapabilities | null | undefined, supportsTransactions?: boolean): CatalogCapabilities;
|
|
80
|
+
/**
|
|
81
|
+
* The client-offered read profiles from `available`, in canonical (sorted) order.
|
|
45
82
|
* A scalar-expression read is selected only alongside constraint records.
|
|
46
83
|
*/
|
|
47
84
|
export declare function selectReadProfiles(available: readonly string[], clientCapabilities: Uint8Array | null | undefined): string[];
|
|
85
|
+
/**
|
|
86
|
+
* The ClientCapabilities a client sends when the caller supplies none: it can
|
|
87
|
+
* read canonical constraint records (decode them with `readConstraintRecord`)
|
|
88
|
+
* and their CHECK expressions. It offers no DDL or enforcement; pass an
|
|
89
|
+
* explicit offer to negotiate those.
|
|
90
|
+
*/
|
|
91
|
+
export declare function defaultClientCapabilities(engine?: string): ClientCapabilities;
|
|
92
|
+
/** True when every category of `caps` is empty. */
|
|
93
|
+
export declare function capabilitiesEmpty(caps: CatalogCapabilities | null | undefined): boolean;
|
|
48
94
|
/** A decoded `ConstraintInfo` record, in `constraintRecord()`'s vocabulary. */
|
|
49
95
|
export interface ConstraintRecordView {
|
|
50
96
|
schemaPath: string[];
|
|
@@ -61,14 +107,66 @@ export interface ConstraintRecordView {
|
|
|
61
107
|
table: string;
|
|
62
108
|
columns: string[][];
|
|
63
109
|
constraintId: string | null;
|
|
110
|
+
/** The referenced constraint's owner table (should equal `table`). */
|
|
111
|
+
constraintTable?: string | null;
|
|
112
|
+
constraintSchemaPath?: string[] | null;
|
|
113
|
+
match?: string;
|
|
114
|
+
onUpdate?: string;
|
|
115
|
+
onDelete?: string;
|
|
64
116
|
} | null;
|
|
65
117
|
}
|
|
66
118
|
/** Decode a `TableInfo.constraints` entry (the inverse of `constraintRecord`). */
|
|
67
119
|
export declare function readConstraintRecord(bytes: Uint8Array): ConstraintRecordView;
|
|
120
|
+
export interface ValidatedConstraints {
|
|
121
|
+
records: ConstraintRecordView[];
|
|
122
|
+
/** JSON-encoded column paths a NOT_NULL or PRIMARY_KEY record makes non-nullable. */
|
|
123
|
+
required: Set<string>;
|
|
124
|
+
}
|
|
68
125
|
/**
|
|
69
|
-
* Check a table's records
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
126
|
+
* Check a table's canonical records exactly as the DuckDB extension does at
|
|
127
|
+
* ATTACH, so a worker's own tests fail with the table, constraint id and path
|
|
128
|
+
* instead of an opaque ATTACH error: identity (owner table and one-component
|
|
129
|
+
* schema), unique ids and declared names, ENFORCED + ALL_ROWS only, at most one
|
|
130
|
+
* PRIMARY KEY, resolvable column paths (nested only for NOT_NULL, never the
|
|
131
|
+
* row-id column), the native CHECK grammar and its operand types, and foreign
|
|
132
|
+
* keys DuckDB can represent (same schema, MATCH SIMPLE, NO ACTION/RESTRICT).
|
|
133
|
+
* Foreign-key targets are checked across tables by `validateForeignKeyTargets`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function validateTableConstraints(table: string, schemaPath: readonly string[], fields: readonly VgiField[], constraints: readonly Uint8Array[]): ValidatedConstraints;
|
|
136
|
+
/** A table's identity and records, for `validateForeignKeyTargets`. */
|
|
137
|
+
export interface ConstraintTableRef {
|
|
138
|
+
schemaPath: readonly string[];
|
|
139
|
+
name: string;
|
|
140
|
+
constraints: readonly Uint8Array[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check every FOREIGN_KEY among `tables` against its target: the referenced
|
|
144
|
+
* table is among `tables`, and the referenced constraint id is that table's
|
|
145
|
+
* PRIMARY_KEY or UNIQUE record over the referenced columns.
|
|
146
|
+
*/
|
|
147
|
+
export declare function validateForeignKeyTargets(tables: readonly ConstraintTableRef[]): void;
|
|
148
|
+
/**
|
|
149
|
+
* The served Arrow fields for a table's records: nullability is exactly the
|
|
150
|
+
* records' (a field, descending through ordinary STRUCTs, is non-nullable iff
|
|
151
|
+
* a NOT_NULL or PRIMARY_KEY record names its path; the top-level row-id column
|
|
152
|
+
* is untouched). Returns `fields` itself when nothing changes.
|
|
153
|
+
*/
|
|
154
|
+
export declare function servedConstraintFields(fields: readonly VgiField[], required: ReadonlySet<string>): readonly VgiField[];
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated Since 0.48: tables are served with nullability derived from their
|
|
157
|
+
* records automatically, so a non-nullable field no record names is no longer
|
|
158
|
+
* an error. Use `validateTableConstraints` for the remaining ATTACH checks.
|
|
73
159
|
*/
|
|
74
160
|
export declare function validateConstraintNullability(table: string, fields: readonly VgiField[], constraints: readonly Uint8Array[]): void;
|
|
161
|
+
/**
|
|
162
|
+
* The served form of a table's Arrow schema: legacy generated metadata
|
|
163
|
+
* translated, records validated as DuckDB validates them at ATTACH, and
|
|
164
|
+
* nullability made exactly the records' (see `servedConstraintFields`).
|
|
165
|
+
* Returns the input schema itself when nothing changes.
|
|
166
|
+
*/
|
|
167
|
+
export declare function servedTableSchema(table: string, schemaPath: readonly string[], schema: VgiSchema, constraints: readonly Uint8Array[]): VgiSchema;
|
|
168
|
+
/**
|
|
169
|
+
* Apply `servedTableSchema` to a TableInfo about to be sent. The original
|
|
170
|
+
* column bytes are kept when nothing changes.
|
|
171
|
+
*/
|
|
172
|
+
export declare function servedTableInfo(info: TableInfo): TableInfo;
|
|
@@ -18,18 +18,36 @@ export interface ForeignKeyDef {
|
|
|
18
18
|
}
|
|
19
19
|
export type DefaultValue = string | number | boolean | null;
|
|
20
20
|
export interface TableDescriptor {
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Canonical ConstraintInfo IPC records with provider-owned stable identities
|
|
23
|
+
* (build them with `constraintRecord`). They also set the served Arrow
|
|
24
|
+
* nullability: a column is served non-nullable exactly when a NOT_NULL or
|
|
25
|
+
* PRIMARY_KEY record names it, so a non-nullable field nobody names is
|
|
26
|
+
* served nullable.
|
|
27
|
+
*/
|
|
22
28
|
constraints?: Uint8Array[];
|
|
29
|
+
/** Opaque token that changes whenever `constraints` change. */
|
|
23
30
|
definitionRevision?: Uint8Array | null;
|
|
24
31
|
name: string;
|
|
25
32
|
columns?: VgiSchema;
|
|
26
33
|
function?: VgiFunction;
|
|
27
34
|
arguments?: Arguments;
|
|
35
|
+
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "NOT_NULL", ... })]`. */
|
|
28
36
|
notNull?: string[];
|
|
37
|
+
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "UNIQUE", ... })]`. */
|
|
29
38
|
unique?: string[][];
|
|
39
|
+
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "CHECK", ... })]`. */
|
|
30
40
|
check?: string[];
|
|
41
|
+
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "PRIMARY_KEY", ... })]`. */
|
|
31
42
|
primaryKey?: string[][];
|
|
43
|
+
/** @deprecated Not sent under vgi.v3 (serving throws). Use `constraints: [constraintRecord({ kind: "FOREIGN_KEY", ... })]`. */
|
|
32
44
|
foreignKey?: ForeignKeyDef[];
|
|
45
|
+
/**
|
|
46
|
+
* Column defaults as literals. Served as canonical `vgi.column.default.v1`
|
|
47
|
+
* when a string literal meets a utf8 column or a boolean a boolean column,
|
|
48
|
+
* and as the legacy `default` SQL key otherwise (numeric defaults included:
|
|
49
|
+
* their canonical form would show in duckdb_columns() as a folded cast).
|
|
50
|
+
*/
|
|
33
51
|
defaults?: Record<string, DefaultValue>;
|
|
34
52
|
/** Per-column comment strings, applied as field metadata `comment`. */
|
|
35
53
|
columnComments?: Record<string, string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IndexConstraintType } from "../generated/vgi-client.js";
|
|
2
|
+
/** The typed-value batch for an index with no options. */
|
|
3
|
+
export declare function emptyIndexOptions(): Uint8Array;
|
|
4
|
+
export interface CanonicalIndexSpec {
|
|
5
|
+
/** Schema path of the indexed table. */
|
|
6
|
+
schemaPath: readonly string[];
|
|
7
|
+
/** Indexed table. */
|
|
8
|
+
table: string;
|
|
9
|
+
/** Raw column paths, one per key, in key order. */
|
|
10
|
+
columns: readonly (readonly string[])[];
|
|
11
|
+
/** Provider algorithm name, e.g. "art" or "btree". */
|
|
12
|
+
algorithm: string;
|
|
13
|
+
/** What the index claims; DuckDB reads NONE without a constraint. Default NONE. */
|
|
14
|
+
constraintType?: IndexConstraintType;
|
|
15
|
+
/** The id of the PRIMARY_KEY/UNIQUE constraint record the index implements, if any. */
|
|
16
|
+
associatedConstraintId?: string;
|
|
17
|
+
/** Typed option values (a one-row IPC batch); default: no options. */
|
|
18
|
+
options?: Uint8Array;
|
|
19
|
+
/** Options the user set explicitly (names in `options`). */
|
|
20
|
+
explicitOptionNames?: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Encode an index's `IndexInfo.definition` (`IndexDefinition`) and
|
|
24
|
+
* `IndexInfo.options` (`OptionState`) records.
|
|
25
|
+
*/
|
|
26
|
+
export declare function canonicalIndex(spec: CanonicalIndexSpec): {
|
|
27
|
+
definition: Uint8Array;
|
|
28
|
+
options: Uint8Array;
|
|
29
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CatalogSnapshotPolicy } from "./publication.js";
|
|
2
|
+
import type { CatalogCapabilities, ConstraintSnapshot, ConstraintsApplyRequest } from "../generated/vgi-protocol-types.js";
|
|
2
3
|
export type AttachOpaqueData = Uint8Array;
|
|
3
4
|
export type TransactionOpaqueData = Uint8Array;
|
|
4
5
|
import type { MacroType } from "../generated/vgi-client.js";
|
|
@@ -363,7 +364,45 @@ export declare abstract class CatalogInterface {
|
|
|
363
364
|
schemaContentsViews(attachOpaqueData: AttachOpaqueData, path: string[], transactionOpaqueData?: TransactionOpaqueData): Awaitable<ViewInfo[]>;
|
|
364
365
|
schemaContentsFunctions(attachOpaqueData: AttachOpaqueData, path: string[], type: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<FunctionInfo[]>;
|
|
365
366
|
tableGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<TableInfo | null>;
|
|
367
|
+
/**
|
|
368
|
+
* CREATE TABLE. `constraintDefinitions` carries one canonical
|
|
369
|
+
* `ConstraintDefinition` record per declared constraint (decode with
|
|
370
|
+
* `decodeConstraintDefinition`); `columns` marks exactly the NOT NULL and
|
|
371
|
+
* PRIMARY KEY columns non-nullable. DuckDB sends definitions only when the
|
|
372
|
+
* attach negotiated `vgi.constraint.create.v1` (advertise it from
|
|
373
|
+
* `catalogCapabilities()`), and the catalog must then enforce every one on
|
|
374
|
+
* every write and serve each back as an ENFORCED + ALL_ROWS `ConstraintInfo`
|
|
375
|
+
* record (see `constraintRecord`). Refuse any it cannot enforce.
|
|
376
|
+
*/
|
|
366
377
|
tableCreate(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columns: Uint8Array, onConflict: string, constraintDefinitions?: Uint8Array[], transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
378
|
+
/**
|
|
379
|
+
* The profiles this catalog implements for an attachment (advertised as
|
|
380
|
+
* `CatalogAttachResult.catalog_capabilities` when `attach()` leaves it
|
|
381
|
+
* unset; the worker selects against the client's offer). Override to serve
|
|
382
|
+
* canonical constraint records from a custom catalog, e.g.
|
|
383
|
+
* `return constraintCapabilities({ enforce: true })`. The default advertises
|
|
384
|
+
* nothing, unless the catalog implements `tableConstraintsApply` or the
|
|
385
|
+
* deprecated not-null hooks, in which case it advertises records read,
|
|
386
|
+
* mutation and enforcement. Return null for "unknown" (no SDK-side gating).
|
|
387
|
+
*/
|
|
388
|
+
catalogCapabilities(_attachOpaqueData: AttachOpaqueData): Awaitable<CatalogCapabilities | null>;
|
|
389
|
+
/** Whether a subclass overrides either deprecated not-null hook. */
|
|
390
|
+
private _implementsLegacyNotNull;
|
|
391
|
+
/**
|
|
392
|
+
* Apply canonical constraint changes atomically (`catalog_table_constraints_apply`;
|
|
393
|
+
* DuckDB sends ALTER TABLE ... SET/DROP NOT NULL this way). Attach and
|
|
394
|
+
* transaction values arrive unwrapped. Reject the request when the table's
|
|
395
|
+
* current `definition_revision` differs from `request.expected_revision`;
|
|
396
|
+
* on success return the table's new records under a NEW definition revision.
|
|
397
|
+
* Requires `vgi.constraint.mutate.v1` (see `catalogCapabilities`).
|
|
398
|
+
*
|
|
399
|
+
* The default routes NOT NULL changes to the deprecated `tableNotNullSet` /
|
|
400
|
+
* `tableNotNullDrop` hooks when a catalog implements them (re-reading the
|
|
401
|
+
* table with `tableGet` for the snapshot, so that catalog must serve the
|
|
402
|
+
* NOT_NULL records and rotate `definition_revision` itself); otherwise it is
|
|
403
|
+
* unimplemented.
|
|
404
|
+
*/
|
|
405
|
+
tableConstraintsApply(request: ConstraintsApplyRequest): Promise<ConstraintSnapshot>;
|
|
367
406
|
tableDrop(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
368
407
|
tableScanFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<any>;
|
|
369
408
|
/**
|
|
@@ -394,7 +433,9 @@ export declare abstract class CatalogInterface {
|
|
|
394
433
|
tableColumnDefaultSet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columnPath: string[], expression: Uint8Array, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
395
434
|
tableColumnDefaultDrop(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columnPath: string[], ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
396
435
|
tableColumnTypeChange(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columnPath: string[], columnDefinition: Uint8Array, expression?: Uint8Array | null, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
436
|
+
/** @deprecated DuckDB sends SET NOT NULL through `tableConstraintsApply`; the default routes it here. */
|
|
397
437
|
tableNotNullSet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columnPath: string[], ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
438
|
+
/** @deprecated DuckDB sends DROP NOT NULL through `tableConstraintsApply`; the default routes it here. */
|
|
398
439
|
tableNotNullDrop(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, columnPath: string[], ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData): Awaitable<void>;
|
|
399
440
|
viewGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<ViewInfo | null>;
|
|
400
441
|
viewCreate(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, definition: string, onConflict: string, transactionOpaqueData?: TransactionOpaqueData, aliases?: string[], comment?: string | null, tags?: Record<string, string> | null, columnComments?: Record<string, string> | null): Awaitable<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { constraintRecord, readConstraintRecord, validateTableConstraints, validateForeignKeyTargets, servedTableSchema, servedTableInfo, servedConstraintFields, validateConstraintNullability, selectReadProfiles, selectCatalogCapabilities, catalogCapabilities, constraintCapabilities, defaultClientCapabilities, CONSTRAINT_RECORDS_READ, ROW_SCALAR_EXPRESSION, CONSTRAINT_CREATE, CONSTRAINT_MUTATE, CONSTRAINT_ENFORCE, TRANSACTION_DDL, type ConstraintRecordSpec, type ConstraintRecordView, type ConstraintKind, type ConstraintEnforcement, type ConstraintValidation, type ConstraintTableRef, type ValidatedConstraints, } from "./constraints.js";
|
|
2
|
+
export { sqlExpression, generatedExpressionMetadata, defaultExpressionMetadata, GENERATED_EXPRESSION_KEY, GENERATION_KEY, DEFAULT_EXPRESSION_KEY, } from "./column-expressions.js";
|
|
3
|
+
export { validateColumnExpressionSql, validateNumericCheckSql } from "./sql-grammar.js";
|
|
4
|
+
export { canonicalIndex, emptyIndexOptions, type CanonicalIndexSpec } from "./indexes.js";
|
|
5
|
+
export { encodeCatalogCapabilities, decodeCatalogCapabilities, buildCatalogCapabilities, encodeSqlExpression, decodeSqlExpression, encodeCatalogObjectRef, decodeCatalogObjectRef, encodeConstraintInfo, decodeConstraintInfo, encodeConstraintDefinition, decodeConstraintDefinition, buildConstraintDefinition, encodeForeignKeyDefinition, decodeForeignKeyDefinition, encodeConstraintChange, decodeConstraintChange, buildConstraintChange, encodeConstraintSnapshot, decodeConstraintSnapshot, encodeConstraintsApplyRequest, decodeConstraintsApplyRequest, encodeIndexDefinition, decodeIndexDefinition, encodeMacroOverload, decodeMacroOverload, buildMacroOverload, type CatalogCapabilities, type SqlExpression, type CatalogObjectRef, type ConstraintInfo, type ConstraintDefinition, type ForeignKeyDefinition, type ConstraintChange, type ConstraintSnapshot, type ConstraintsApplyRequest, type IndexDefinition, type MacroOverload, type MacroParameter, } from "../generated/vgi-protocol-types.js";
|
|
6
|
+
export type { ClientCapabilities } from "../generated/vgi-client.js";
|
|
@@ -2,6 +2,7 @@ import { CatalogInterface, type AttachOpaqueData, type TransactionOpaqueData, ty
|
|
|
2
2
|
import { type CatalogDescriptor } from "./descriptors.js";
|
|
3
3
|
import type { FunctionRegistry } from "../functions/registry.js";
|
|
4
4
|
import { type AttachOptionSpec } from "./attach-option.js";
|
|
5
|
+
import type { CatalogCapabilities } from "../generated/vgi-protocol-types.js";
|
|
5
6
|
/**
|
|
6
7
|
* The fixed attach id ReadOnlyCatalogInterface writes into its items (same
|
|
7
8
|
* bytes as vgi-python's `ReadOnlyCatalogInterface._FIXED_ATTACH_ID`). Shared:
|
|
@@ -93,6 +94,8 @@ export declare class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
93
94
|
* `constraints`; override when tables are served outside the descriptor.
|
|
94
95
|
*/
|
|
95
96
|
catalogReadProfiles(): string[];
|
|
97
|
+
/** The descriptor's read profiles (records are served, never mutated here). */
|
|
98
|
+
catalogCapabilities(_attachOpaqueData: AttachOpaqueData): CatalogCapabilities | null;
|
|
96
99
|
detach(attachOpaqueData: AttachOpaqueData): void;
|
|
97
100
|
version(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): number | Promise<number>;
|
|
98
101
|
/**
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type LiteralType = "NULL" | "BOOLEAN" | "INTEGER" | "BIGINT" | "HUGEINT" | "DECIMAL" | "DOUBLE" | "VARCHAR";
|
|
2
|
+
export type ScalarNode = {
|
|
3
|
+
kind: "constant";
|
|
4
|
+
type: LiteralType;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "column";
|
|
7
|
+
names: string[];
|
|
8
|
+
} | {
|
|
9
|
+
kind: "cast";
|
|
10
|
+
type: string | null;
|
|
11
|
+
qualified: boolean;
|
|
12
|
+
child: ScalarNode;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "comparison";
|
|
15
|
+
op: string;
|
|
16
|
+
left: ScalarNode;
|
|
17
|
+
right: ScalarNode;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "conjunction";
|
|
20
|
+
op: "AND" | "OR";
|
|
21
|
+
children: ScalarNode[];
|
|
22
|
+
} | {
|
|
23
|
+
kind: "operator";
|
|
24
|
+
op: "NOT" | "IS_NULL" | "IS_NOT_NULL" | "COALESCE";
|
|
25
|
+
children: ScalarNode[];
|
|
26
|
+
} | {
|
|
27
|
+
kind: "function";
|
|
28
|
+
name: string;
|
|
29
|
+
qualified: boolean;
|
|
30
|
+
children: ScalarNode[];
|
|
31
|
+
};
|
|
32
|
+
/** Parse one DuckDB scalar expression in the bounded grammar's syntax. */
|
|
33
|
+
export declare function parseScalarSql(sql: string): ScalarNode;
|
|
34
|
+
/**
|
|
35
|
+
* Check `sql` against the extension's column-expression grammar
|
|
36
|
+
* (vgi_column_expression.cpp `Parse`): a DEFAULT (`usingColumns` false: no
|
|
37
|
+
* column references), a USING expression (`usingColumns` true: `/` allowed) or
|
|
38
|
+
* a VIRTUAL generated column (`generated`: column references, `||`, no
|
|
39
|
+
* DECIMAL/floating literals or casts). Returns the referenced column names.
|
|
40
|
+
* Throws an Error naming the rule broken.
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateColumnExpressionSql(sql: string, options: {
|
|
43
|
+
usingColumns: boolean;
|
|
44
|
+
generated: boolean;
|
|
45
|
+
}): string[];
|
|
46
|
+
/**
|
|
47
|
+
* The extension's native CHECK read grammar (`ParseNumericCheck`): exactly one
|
|
48
|
+
* comparison (=, <>, <, >, <=, >=) whose operands are each a non-NULL numeric
|
|
49
|
+
* literal or an unqualified column reference. `resolveColumn` checks a
|
|
50
|
+
* referenced column (by case-insensitive name) and throws when it is not an
|
|
51
|
+
* acceptable operand.
|
|
52
|
+
*/
|
|
53
|
+
export declare function validateNumericCheckSql(sql: string, resolveColumn: (name: string) => void): void;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check CREATE TABLE columns against the canonical constraint definitions sent
|
|
3
|
+
* with them: a column may be non-nullable only when a NOT_NULL or PRIMARY_KEY
|
|
4
|
+
* definition names it (DuckDB marks exactly those), nested fields stay
|
|
5
|
+
* nullable, and logical column types are refused (they need negotiation).
|
|
6
|
+
* With no definitions every user column must be nullable.
|
|
7
|
+
*/
|
|
8
|
+
export declare function requireCreateColumns(columns: Uint8Array, constraintDefinitions?: readonly Uint8Array[]): void;
|
|
1
9
|
/** No constraint authority means every SQL user field must remain nullable. */
|
|
2
10
|
export declare function requireUnconstrainedColumns(columns: Uint8Array): void;
|
package/dist/client/types.d.ts
CHANGED
|
@@ -41,7 +41,11 @@ export interface CatalogAttachOptions {
|
|
|
41
41
|
optionsBytes?: Uint8Array;
|
|
42
42
|
dataVersionSpec?: string | null;
|
|
43
43
|
implementationVersion?: string | null;
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Engine capabilities serialized into the protocol's named inner record.
|
|
46
|
+
* Omitted: `defaultClientCapabilities()` (reads canonical constraint records
|
|
47
|
+
* and their CHECK expressions). `null`: send no offer.
|
|
48
|
+
*/
|
|
45
49
|
clientCapabilities?: import("../generated/vgi-client.js").ClientCapabilities | null;
|
|
46
50
|
}
|
|
47
51
|
/** Conflict resolution strategy for create operations. */
|
package/dist/client-entry.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { type ArgumentSpec, argumentSpecsToSchema, schemaToArgumentSpecs, } from
|
|
|
5
5
|
export { FunctionType, FunctionStability, NullHandling, ArgumentMonotonicity, OrderPreservation, OrderDependence, DistinctDependence, TableInOutPhase, } from "./types.js";
|
|
6
6
|
export type { BindRequest, BindResponse, InitRequest, GlobalInitResponse, TableCardinality, } from "./protocol/types.js";
|
|
7
7
|
export { type SchemaInfo, encodeSchemaInfo, decodeSchemaInfo, type TableInfo, encodeTableInfo, decodeTableInfo, type ViewInfo, encodeViewInfo, decodeViewInfo, type FunctionInfo, encodeFunctionInfo, decodeFunctionInfo, type MacroInfo, encodeMacroInfo, decodeMacroInfo, type CatalogAttachResult, type AttachOpaqueData, type TransactionOpaqueData, } from "./catalog/interface.js";
|
|
8
|
+
export * from "./catalog/public-codecs.js";
|
|
8
9
|
export { VgiError, RowCountMismatchError, FunctionNotFoundError, CatalogReadOnlyError, CatalogNotFoundError, CatalogAlreadyExistsError, ArgumentValidationError, NoCatalogError, } from "./errors.js";
|
|
9
10
|
export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, safeNumber, serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, } from "./util/arrow/index.js";
|
|
10
11
|
export { TypeId, typeSignature } from "./arrow/predicates.js";
|