Skip to content

Commit 6a5e632

Browse files
committed
refactor(stack-encrypt): the query chain starts with the operator and ends on the plan
`cipher.query(op::Eq, "bob@example.com").on(&plan)` replaces `cipher.query("bob@example.com").using(&plan).op(op::Eq)`. The operator comes first, by value, and `on` names the plan, which chooses the index that answers the operator (`plan::Chooses`) and resolves the label the write used (`plan::Resolves`). An index the plan declares beside the default is named before the plan: `.via(index).on(&plan)`. An index's own term, for ORE and OPE until the ordering operators arrive, is `cipher.query_index(Ore, &40).on(&plan)`. `op::Matches` is now a value as well as a type, as `PhantomData` is, so `op::Matches::new()` is `op::Matches`; `op::Matches.case_sensitive()` is the other case. The case types are `CaseInsensitive` and `CaseSensitive`: `Sensitive` on its own read as data sensitivity. `Match` is a value the same way, so `Match::default()` is `Match`, and `Default` is implemented for every `Match<O>`. `Answers::via()` and `DefaultIndex::via()` are gone: an index is a unit type, so `Via: Default` says the same thing without a method per impl, and the three equivalent-mutant exclusions for those bodies go with them. "Needle" is gone from the prose: a match query is a filter over the query's value, where the stored term is a filter over the stored value. Claude-Session: https://claude.ai/code/session_01VYKAWbd361xDLmqBdLoUcB
1 parent 1ed1f3d commit 6a5e632

35 files changed

Lines changed: 719 additions & 540 deletions

‎.cargo/mutants.toml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ exclude_re = [
7272
'stack-encrypt/src/cipher\.rs:\d+:\d+: replace client_key_provider -> EnvKeyProvider with Default::default\(\)$',
7373
'stack-encrypt/src/target/pending\.rs:443:9: replace <impl IntoFuture for Pending<.*>>::into_future -> Self::IntoFuture with Default::default\(\)$',
7474
# stack-encrypt — equivalent.
75-
# An operator and an operator's index are unit structs, whose `Default`
76-
# is the value `clone` and `via` already return.
75+
# An operator and an index are unit structs, whose `Default` is the value
76+
# `clone` and `case_sensitive` already return.
7777
'stack-encrypt/src/op(/mod)?\.rs:\d+:\d+: replace <impl Clone for Matches<C>>::clone -> Self with Default::default\(\)$',
78-
'stack-encrypt/src/op(/mod)?\.rs:\d+:\d+: replace <impl (Answers<Eq, S> for EqualityTerm|DefaultIndex<S> for Eq|DefaultIndex<S> for Matches<<DefaultMatch as MatchCase>::Case>)>::via -> (Equality|Match) with Default::default\(\)$',
78+
'stack-encrypt/src/op(/mod)?\.rs:\d+:\d+: replace Matches::case_sensitive -> Matches<CaseSensitive> with Default::default\(\)$',
79+
'stack-encrypt/src/target/index\.rs:\d+:\d+: replace <impl Clone for Match<O>>::clone -> Self with Default::default\(\)$',
7980
'stack-encrypt/src/cipher\.rs:\d+:\d+: replace StackCipher<FromEnv>::builder -> StackCipherBuilder with Default::default\(\)$',
8081
'stack-encrypt/src/sem/mod\.rs:\d+:\d+: replace <impl MatchConfig for DefaultMatch>::options -> MatchOptions with Default::default\(\)$',
8182
# Both unit-context conversions explicitly return Self::default().

‎packages/stack-encrypt/CHANGELOG.md‎

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- **A query names an operator, not an index.** `cipher.query(v).using(&plan)`
13-
finishes with `.op(op::Eq)` or `.op(op::Matches::new())`, and the plan
14-
finds the index that answers the operator (ADR-0009). An index declares the
15-
operators it answers (`op::Supports`), a target type names the index that
16-
answers each one for it (`op::Answers`), and a plan that declares indexes
17-
uses the operator's default index (`op::DefaultIndex`). `.op_via(op, index)`
18-
names another index, such as a match index with its own configuration. What
19-
the plan's type shows is checked at compile time: a match query on an
20-
integer, an operator a target does not answer, and on a one-value plan an
21-
index it does not hold or a case-sensitive `Matches` against a
22-
case-folding index. On a field of a fields plan those are refused when the
23-
query is awaited, before any key is requested, as is a match configuration
24-
whose `op::MatchCase` disagrees with its options (`PlanError::MatchCase`).
12+
- **A query names an operator, not an index.**
13+
`cipher.query(op::Eq, "bob@example.com").on(&plan)` and
14+
`cipher.query(op::Matches, "ali").on(&plan)`: the operator comes first, as
15+
a value, and the plan named by `on` finds the index that answers it
16+
(ADR-0009). An index declares the operators it answers (`op::Supports`), a
17+
target type names the index that answers each one for it (`op::Answers`),
18+
and a plan that declares indexes uses the operator's default index
19+
(`op::DefaultIndex`); both name the index by its type, whose `Default` is
20+
the index. `.via(index)` before `.on(&plan)` names another index the plan
21+
declares, such as a match index with its own configuration.
22+
`op::Matches` is the case-insensitive operator, as a value;
23+
`op::Matches.case_sensitive()` is the other, and the case types are
24+
`op::CaseInsensitive` and `op::CaseSensitive`. What the plan's type shows
25+
is checked at compile time: a match query on an integer, an operator a
26+
target does not answer, and on a one-value plan an index it does not hold
27+
or a case-sensitive `Matches` against a case-folding index. On a field of
28+
a fields plan those are refused when the query is awaited, before any key
29+
is requested, as is a match configuration whose `op::MatchCase` disagrees
30+
with its options (`PlanError::MatchCase`).
2531
- **A match query has its own type, `sem::MatchQuery`.** It is the filter over
26-
the needle; test a stored filter against it with
32+
the query's value; test a stored filter against it with
2733
`MatchTerms::matches(&query)`. It comes only from a query chain:
2834
`op::Supports::query` takes an `op::QueryToken` that only this crate can
2935
make.
36+
- **`Match` is a value.** `.with((Equality, Match))` declares the match index
37+
under the default configuration, as `Equality` declares equality;
38+
`Match::<MyConfig>::new()` is another configuration.
3039

3140
- **Errors now expose stable codes, help text, and structured details.**
3241
All error types implement `miette::Diagnostic` with codes such as
@@ -66,10 +75,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6675

6776
### Breaking
6877

69-
- **`QueryUsing::equality()` is removed.** Write `.op(op::Eq)`. A plan that
70-
declares the equality index answers it the same way, and a target answers
71-
it through `op::Answers`. `QueryUsing::index(..)` stays until the ordering
72-
operators exist.
78+
- **The query chain starts with the operator.** `cipher.query(v)` takes the
79+
operator first: `cipher.query(op::Eq, v).on(&plan)` replaces
80+
`cipher.query(v).using(&plan).equality()`, and `on` replaces `using` for
81+
queries only (a write still runs `using` a plan). An index's own term, for
82+
an index no operator answers yet (`Ore`, `Ope`), is
83+
`cipher.query_index(Ore, v).on(&plan)`, which goes when the ordering
84+
operators arrive. `QueryUsing` is gone; the chain's types are
85+
`QueryBuilder`, `QueryVia`, `QueryIndexBuilder`, `QueryIndex` and
86+
`QueryOp`, and the plan shapes implement `plan::Chooses` and
87+
`plan::Resolves`.
88+
- **`Match::default()` is `Match`.** The match index under the default
89+
configuration is the value `Match`, and `Default` is now implemented for
90+
every `Match<O>`, so `Match::default()` no longer infers the configuration.
7391

7492
- **Update pattern matches for `dynamic::Error`.** `Context`, `Plan`,
7593
`Source`, and `Record` now carry

‎packages/stack-encrypt/CONTEXT.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ _Avoid_: query type, index (that is what answers the operator)
241241

242242
**Query term**:
243243
The value a query sends to the server. It is not the stored term: equality
244-
sends the same HMAC it stores, but a match query is a filter over the needle,
245-
where the stored term is a filter over the whole value. A query term is never
244+
sends the same HMAC it stores, but a match query is a filter over the query's
245+
value, where the stored term is a filter over the whole stored value. A query term is never
246246
stored, and a query chain never sends a stored term as a query.
247247
_Avoid_: probe, stored term (that is what a write keeps)
248248

‎packages/stack-encrypt/src/codes.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ mod tests {
150150
}),
151151
},
152152
PlanError::MatchCase { .. } => PlanError::MatchCase {
153-
declared: "Insensitive",
153+
declared: "CaseInsensitive",
154154
folds: false,
155155
},
156156
PlanError::TwoContextSources { .. } => PlanError::TwoContextSources {

‎packages/stack-encrypt/src/dynamic/record.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6799,7 +6799,7 @@ mod tests {
67996799
(P::NoContext.into(), None, Refused),
68006800
(
68016801
P::MatchCase {
6802-
declared: "Sensitive",
6802+
declared: "CaseSensitive",
68036803
folds: true,
68046804
}
68056805
.into(),

‎packages/stack-encrypt/src/dynamic/term.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ mod wire_form {
12061206
fn every_typed_index_round_trips_through_the_wire_form() {
12071207
let specs = [
12081208
Index::<String>::spec(&Equality),
1209-
Index::<String>::spec(&Match::default()),
1209+
Index::<String>::spec(&Match),
12101210
Index::<String>::spec(&Match::<Words>::new()),
12111211
Index::<String>::spec(&Ore),
12121212
Index::<String>::spec(&Ope),
@@ -1222,7 +1222,7 @@ mod wire_form {
12221222

12231223
#[test]
12241224
fn a_default_match_index_is_the_bare_match_key() {
1225-
let spec = Index::<String>::spec(&Match::default());
1225+
let spec = Index::<String>::spec(&Match);
12261226
assert!(matches!(
12271227
spec.to_value(),
12281228
FfiValue::String(key) if super::utf8(&key) == Some("match")

0 commit comments

Comments
 (0)