Skip to content

Commit a629897

Browse files
authored
fix(eql-bindings): give v4 inventory entries v4 schema ids, and pin the version boundary
The inventory boxes PhantomData<T> handles, and their DomainType impl did not forward schema_id, so every v4 entry reported an /eql/v3/ $id. A type-level schema_id_base_static() now carries each type's base through the handle, and the generated v4 types override it. That surfaced in a new v4 parity test, the counterpart of catalog_parity.rs: v4::all() is the scalar catalog under eql_v4 names in catalog order, each query twin lives in eql_v4, term keys match the catalog, and each generation's TextEq refuses the other's version, both directly and through the inventory. The encryption suite refuses a real v4 payload whose version alone was set back to 3. types:generate snapshots and restores src/v4 as well as src/v3, types:check diffs it, and the pre-commit hook triggers on it. The v4 module doc no longer links a feature-gated module, and the Go READMEs name the eql_v4 column and query operand the guest now writes.
1 parent f8e525f commit a629897

20 files changed

Lines changed: 466 additions & 12 deletions

File tree

‎languages/golang/cmd/stashgen/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Your program calls those functions, and it never builds or names a plan.
4444
```
4545

4646
6. Store the encrypted type.
47-
Each `encrypt_into` field is one EQL column: `eql.TextEq` implements `driver.Valuer` and `sql.Scanner`, so a database library binds and scans it as the JSON a `public.eql_v3_text_eq` column holds.
47+
Each `encrypt_into` field is one EQL column: `eql.TextEq` implements `driver.Valuer` and `sql.Scanner`, so a database library binds and scans it as the JSON a `public.eql_v4_text_eq` column holds. Stack Encrypt writes EQL v4; see the `encrypt` package README.
4848

4949
7. Run the generator again after each change to the struct or to a tag.
5050
A change to the fields of the struct stops the build until you do.

‎languages/golang/encrypt/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,14 @@ package documentation for the full account.
276276
## EQL columns
277277

278278
A field tagged `encrypt_into=TextEq` is stored as one EQL value, the JSON
279-
PostgreSQL holds in a `public.eql_v3_text_eq` column, as an `eql.TextEq`
280-
from package `encrypt/eql`. The guest builds the value: the generated code
279+
PostgreSQL holds in a `public.eql_v4_text_eq` column, as an `eql.TextEq`
280+
from package `encrypt/eql`. Stack Encrypt writes EQL v4, the `eql_v4` install
281+
of EQL's SQL; the `eql_v3` columns the TypeScript SDK writes hold
282+
cipherstash-client's terms, which these never match. The guest builds the value: the generated code
281283
imports `encrypt/eql`, which embeds the build of the engine that holds the
282284
EQL types and registers it on import, so the program runs that build and
283285
stores what it returns. `Fields.Email.Query` returns the `eql.TextEqQuery`
284-
the column's `eql_v3.query_text_eq` operand takes. `mise run
286+
the column's `eql_v4.query_text_eq` operand takes. `mise run
285287
wasm:guest:build:eql` builds that guest beside the other. A cipher extended
286288
with a tenant part refuses a struct with an `encrypt_into` field: an EQL
287289
value is stored under a table and a column, and the extended label has no

‎packages/eql/crates/eql-bindings/src/v3/domain_type.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ pub trait DomainType {
7070
format!("{SCHEMA_ID_BASE}{}.json", self.domain())
7171
}
7272

73+
/// The base [`Self::schema_id`] is built on: [`SCHEMA_ID_BASE`] for v3,
74+
/// overridden by the generated v4 types. The type-level form, so the
75+
/// `PhantomData` handles [`all`](super::all) boxes can reach a type's own
76+
/// base; without it they fell back to the v3 default.
77+
///
78+
/// `where Self: Sized` keeps the trait object-safe.
79+
fn schema_id_base_static() -> &'static str
80+
where
81+
Self: Sized,
82+
{
83+
SCHEMA_ID_BASE
84+
}
85+
7386
/// Required term JSON keys of this domain beyond the envelope
7487
/// (`hm`/`ob`/`bf`/`op`), in catalog (wire) order. `Some(&[])` for a
7588
/// storage-only scalar; `None` for the SteVec (jsonb) shapes, whose index
@@ -132,6 +145,14 @@ where
132145
T::term_json_keys_static()
133146
}
134147

148+
fn schema_id_base_static() -> &'static str {
149+
T::schema_id_base_static()
150+
}
151+
152+
fn schema_id(&self) -> String {
153+
format!("{}{}.json", T::schema_id_base_static(), self.domain())
154+
}
155+
135156
fn parse_value(&self, value: &serde_json::Value) -> Result<(), serde_json::Error> {
136157
T::deserialize(value).map(|_| ())
137158
}

‎packages/eql/crates/eql-bindings/src/v4/bigint.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ impl DomainType for Bigint {
4040
fn schema(&self) -> Schema {
4141
schema_for!(Bigint)
4242
}
43+
fn schema_id_base_static() -> &'static str {
44+
super::SCHEMA_ID_BASE
45+
}
4346
fn schema_id(&self) -> String {
4447
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
4548
}
@@ -79,6 +82,9 @@ impl DomainType for BigintEq {
7982
fn schema(&self) -> Schema {
8083
schema_for!(BigintEq)
8184
}
85+
fn schema_id_base_static() -> &'static str {
86+
super::SCHEMA_ID_BASE
87+
}
8288
fn schema_id(&self) -> String {
8389
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
8490
}
@@ -118,6 +124,9 @@ impl DomainType for BigintOrdOre {
118124
fn schema(&self) -> Schema {
119125
schema_for!(BigintOrdOre)
120126
}
127+
fn schema_id_base_static() -> &'static str {
128+
super::SCHEMA_ID_BASE
129+
}
121130
fn schema_id(&self) -> String {
122131
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
123132
}
@@ -157,6 +166,9 @@ impl DomainType for BigintOrd {
157166
fn schema(&self) -> Schema {
158167
schema_for!(BigintOrd)
159168
}
169+
fn schema_id_base_static() -> &'static str {
170+
super::SCHEMA_ID_BASE
171+
}
160172
fn schema_id(&self) -> String {
161173
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
162174
}
@@ -196,6 +208,9 @@ impl DomainType for BigintOrdOpe {
196208
fn schema(&self) -> Schema {
197209
schema_for!(BigintOrdOpe)
198210
}
211+
fn schema_id_base_static() -> &'static str {
212+
super::SCHEMA_ID_BASE
213+
}
199214
fn schema_id(&self) -> String {
200215
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
201216
}
@@ -234,6 +249,9 @@ impl DomainType for BigintEqQuery {
234249
fn schema(&self) -> Schema {
235250
schema_for!(BigintEqQuery)
236251
}
252+
fn schema_id_base_static() -> &'static str {
253+
super::SCHEMA_ID_BASE
254+
}
237255
fn schema_id(&self) -> String {
238256
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
239257
}
@@ -272,6 +290,9 @@ impl DomainType for BigintOrdOreQuery {
272290
fn schema(&self) -> Schema {
273291
schema_for!(BigintOrdOreQuery)
274292
}
293+
fn schema_id_base_static() -> &'static str {
294+
super::SCHEMA_ID_BASE
295+
}
275296
fn schema_id(&self) -> String {
276297
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
277298
}
@@ -310,6 +331,9 @@ impl DomainType for BigintOrdQuery {
310331
fn schema(&self) -> Schema {
311332
schema_for!(BigintOrdQuery)
312333
}
334+
fn schema_id_base_static() -> &'static str {
335+
super::SCHEMA_ID_BASE
336+
}
313337
fn schema_id(&self) -> String {
314338
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
315339
}
@@ -348,6 +372,9 @@ impl DomainType for BigintOrdOpeQuery {
348372
fn schema(&self) -> Schema {
349373
schema_for!(BigintOrdOpeQuery)
350374
}
375+
fn schema_id_base_static() -> &'static str {
376+
super::SCHEMA_ID_BASE
377+
}
351378
fn schema_id(&self) -> String {
352379
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
353380
}

‎packages/eql/crates/eql-bindings/src/v4/boolean.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ impl DomainType for Boolean {
4040
fn schema(&self) -> Schema {
4141
schema_for!(Boolean)
4242
}
43+
fn schema_id_base_static() -> &'static str {
44+
super::SCHEMA_ID_BASE
45+
}
4346
fn schema_id(&self) -> String {
4447
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
4548
}

‎packages/eql/crates/eql-bindings/src/v4/date.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ impl DomainType for Date {
4040
fn schema(&self) -> Schema {
4141
schema_for!(Date)
4242
}
43+
fn schema_id_base_static() -> &'static str {
44+
super::SCHEMA_ID_BASE
45+
}
4346
fn schema_id(&self) -> String {
4447
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
4548
}
@@ -79,6 +82,9 @@ impl DomainType for DateEq {
7982
fn schema(&self) -> Schema {
8083
schema_for!(DateEq)
8184
}
85+
fn schema_id_base_static() -> &'static str {
86+
super::SCHEMA_ID_BASE
87+
}
8288
fn schema_id(&self) -> String {
8389
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
8490
}
@@ -118,6 +124,9 @@ impl DomainType for DateOrdOre {
118124
fn schema(&self) -> Schema {
119125
schema_for!(DateOrdOre)
120126
}
127+
fn schema_id_base_static() -> &'static str {
128+
super::SCHEMA_ID_BASE
129+
}
121130
fn schema_id(&self) -> String {
122131
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
123132
}
@@ -157,6 +166,9 @@ impl DomainType for DateOrd {
157166
fn schema(&self) -> Schema {
158167
schema_for!(DateOrd)
159168
}
169+
fn schema_id_base_static() -> &'static str {
170+
super::SCHEMA_ID_BASE
171+
}
160172
fn schema_id(&self) -> String {
161173
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
162174
}
@@ -196,6 +208,9 @@ impl DomainType for DateOrdOpe {
196208
fn schema(&self) -> Schema {
197209
schema_for!(DateOrdOpe)
198210
}
211+
fn schema_id_base_static() -> &'static str {
212+
super::SCHEMA_ID_BASE
213+
}
199214
fn schema_id(&self) -> String {
200215
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
201216
}
@@ -234,6 +249,9 @@ impl DomainType for DateEqQuery {
234249
fn schema(&self) -> Schema {
235250
schema_for!(DateEqQuery)
236251
}
252+
fn schema_id_base_static() -> &'static str {
253+
super::SCHEMA_ID_BASE
254+
}
237255
fn schema_id(&self) -> String {
238256
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
239257
}
@@ -272,6 +290,9 @@ impl DomainType for DateOrdOreQuery {
272290
fn schema(&self) -> Schema {
273291
schema_for!(DateOrdOreQuery)
274292
}
293+
fn schema_id_base_static() -> &'static str {
294+
super::SCHEMA_ID_BASE
295+
}
275296
fn schema_id(&self) -> String {
276297
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
277298
}
@@ -310,6 +331,9 @@ impl DomainType for DateOrdQuery {
310331
fn schema(&self) -> Schema {
311332
schema_for!(DateOrdQuery)
312333
}
334+
fn schema_id_base_static() -> &'static str {
335+
super::SCHEMA_ID_BASE
336+
}
313337
fn schema_id(&self) -> String {
314338
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
315339
}
@@ -348,6 +372,9 @@ impl DomainType for DateOrdOpeQuery {
348372
fn schema(&self) -> Schema {
349373
schema_for!(DateOrdOpeQuery)
350374
}
375+
fn schema_id_base_static() -> &'static str {
376+
super::SCHEMA_ID_BASE
377+
}
351378
fn schema_id(&self) -> String {
352379
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
353380
}

‎packages/eql/crates/eql-bindings/src/v4/double.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ impl DomainType for Double {
4040
fn schema(&self) -> Schema {
4141
schema_for!(Double)
4242
}
43+
fn schema_id_base_static() -> &'static str {
44+
super::SCHEMA_ID_BASE
45+
}
4346
fn schema_id(&self) -> String {
4447
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
4548
}
@@ -79,6 +82,9 @@ impl DomainType for DoubleEq {
7982
fn schema(&self) -> Schema {
8083
schema_for!(DoubleEq)
8184
}
85+
fn schema_id_base_static() -> &'static str {
86+
super::SCHEMA_ID_BASE
87+
}
8288
fn schema_id(&self) -> String {
8389
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
8490
}
@@ -118,6 +124,9 @@ impl DomainType for DoubleOrdOre {
118124
fn schema(&self) -> Schema {
119125
schema_for!(DoubleOrdOre)
120126
}
127+
fn schema_id_base_static() -> &'static str {
128+
super::SCHEMA_ID_BASE
129+
}
121130
fn schema_id(&self) -> String {
122131
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
123132
}
@@ -157,6 +166,9 @@ impl DomainType for DoubleOrd {
157166
fn schema(&self) -> Schema {
158167
schema_for!(DoubleOrd)
159168
}
169+
fn schema_id_base_static() -> &'static str {
170+
super::SCHEMA_ID_BASE
171+
}
160172
fn schema_id(&self) -> String {
161173
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
162174
}
@@ -196,6 +208,9 @@ impl DomainType for DoubleOrdOpe {
196208
fn schema(&self) -> Schema {
197209
schema_for!(DoubleOrdOpe)
198210
}
211+
fn schema_id_base_static() -> &'static str {
212+
super::SCHEMA_ID_BASE
213+
}
199214
fn schema_id(&self) -> String {
200215
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
201216
}
@@ -234,6 +249,9 @@ impl DomainType for DoubleEqQuery {
234249
fn schema(&self) -> Schema {
235250
schema_for!(DoubleEqQuery)
236251
}
252+
fn schema_id_base_static() -> &'static str {
253+
super::SCHEMA_ID_BASE
254+
}
237255
fn schema_id(&self) -> String {
238256
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
239257
}
@@ -272,6 +290,9 @@ impl DomainType for DoubleOrdOreQuery {
272290
fn schema(&self) -> Schema {
273291
schema_for!(DoubleOrdOreQuery)
274292
}
293+
fn schema_id_base_static() -> &'static str {
294+
super::SCHEMA_ID_BASE
295+
}
275296
fn schema_id(&self) -> String {
276297
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
277298
}
@@ -310,6 +331,9 @@ impl DomainType for DoubleOrdQuery {
310331
fn schema(&self) -> Schema {
311332
schema_for!(DoubleOrdQuery)
312333
}
334+
fn schema_id_base_static() -> &'static str {
335+
super::SCHEMA_ID_BASE
336+
}
313337
fn schema_id(&self) -> String {
314338
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
315339
}
@@ -348,6 +372,9 @@ impl DomainType for DoubleOrdOpeQuery {
348372
fn schema(&self) -> Schema {
349373
schema_for!(DoubleOrdOpeQuery)
350374
}
375+
fn schema_id_base_static() -> &'static str {
376+
super::SCHEMA_ID_BASE
377+
}
351378
fn schema_id(&self) -> String {
352379
format!("{}{}.json", super::SCHEMA_ID_BASE, self.domain())
353380
}

0 commit comments

Comments
 (0)