diff --git a/docs/plans/2026-10-24-stack-encrypt-api-plan.md b/docs/plans/2026-10-24-stack-encrypt-api-plan.md index 444703be4..140ca414f 100644 --- a/docs/plans/2026-10-24-stack-encrypt-api-plan.md +++ b/docs/plans/2026-10-24-stack-encrypt-api-plan.md @@ -2312,7 +2312,7 @@ review. The rules are the query artifact's. `.via`. The `MatchConfig` documentation says a field and its query agree "by construction". That is true only for one-value plans today. Both are amended, not contradicted in silence. -- **Tracked in.** Steps 1 and 2 are done: #1279, #1318, #1317 and #1233 are closed. They brought `prepare`, the `sem::query` rules and `Op`, and dropped `Matches`'s case parameter. The analyzer of "Match configuration: one analyzer" is its own work (#1673). Step 3 is done apart from its clean-up: the field references and `Planned` (#1486, closed), and the removal of `DefaultIndex` and `.via` (#1666). Issue #1671 is open to remove `PlanError::IndexOptions` and the other variants nothing raises, and to amend ADR-0009 and the `MatchConfig` documentation. Step 4 is issue #1672, open. +- **Tracked in.** Steps 1 and 2 are done: #1279, #1318, #1317 and #1233 are closed. They brought `prepare`, the `sem::query` rules and `Op`, and dropped `Matches`'s case parameter. The analyzer of "Match configuration: one analyzer" is its own work (#1673). Step 3 is done apart from its clean-up: the field references and `Planned` (#1486, closed), and the removal of `DefaultIndex` and `.via` (#1666). #1671 removes `PlanError::IndexOptions` and the six other variants nothing raised, and amends ADR-0009 and the `MatchConfig` documentation. Step 4 is issue #1672, open. - **Finished when** these are all true: - every index's operators appear in one declaration, and a test shows the typed and dynamic lookups agree on every index; @@ -2465,4 +2465,4 @@ renames. | `scope(..)`, `bind(..)`, `bind(claim = ..)`, `keyset(name(field = ..))` | The declaration attributes. Confirmed | | `stack-kms` to `stack-zerokms` | Not decided. The crate rename is part of the crate layout question, which stays open | | `scope = ".."`, Go `scope=` | The record's name is its first scope, so the attribute and the Go tag both say `scope`. Today they say `context = ".."` and `context=`. The builder's `Plan::scope(..)` was part of this decision and goes with the builder. Decided by Dan on 8 November 2026 | -| `plan.query(field, op)`, `plan.field(name)`, `IndexNotDeclared`, `FieldIndexes`, `StageSpec`, `Match`, `NotPortable` | The dynamic interface names. Confirmed | +| `plan.query(field, op)`, `plan.field(name)`, `FieldIndexes`, `StageSpec`, `Match`, `NotPortable` | The dynamic interface names. Confirmed. `IndexNotDeclared` was on this list and is removed (#1671): no query takes an index from the caller | diff --git a/languages/golang/encrypt/guest/src/status.rs b/languages/golang/encrypt/guest/src/status.rs index 9445a2a0a..570dd9e5b 100644 --- a/languages/golang/encrypt/guest/src/status.rs +++ b/languages/golang/encrypt/guest/src/status.rs @@ -420,7 +420,7 @@ mod tests { fn a_plan_refusal_is_the_callers_input() { assert_eq!( status_for_error(&stack_encrypt::Error::Plan( - stack_encrypt::PlanError::NoContext + stack_encrypt::PlanError::BindInQuery )), STATUS_ENCODING ); diff --git a/packages/stack-encrypt/CHANGELOG.md b/packages/stack-encrypt/CHANGELOG.md index 6642d4680..6c3290cf3 100644 --- a/packages/stack-encrypt/CHANGELOG.md +++ b/packages/stack-encrypt/CHANGELOG.md @@ -438,6 +438,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking +- **Seven `PlanError` variants that nothing raised are removed** (#1671). + Only the plan builder and `plan::all` raised them, and both are gone, + so no call returned them: `IdentityWithoutField`, `IndexNotDeclared`, + `IndexOptions`, `MixedCiphers`, `NoContext`, `PassthroughIndexed` and + `TargetWithVerbs`. `plan::all` raised `MixedCiphers`; the builder raised + the other six. + Their error codes go with them (`stack_encrypt::plan_identity_without_field`, + `plan_index_not_declared`, `plan_index_options`, `plan_mixed_ciphers`, + `plan_no_context`, `plan_passthrough_indexed` and + `plan_target_with_verbs`). The other variants keep their codes. No + `dynamic::Reason` is removed: a data plan with a passthrough beside + another output, or with both outputs and a target, is still refused as + `passthrough_with_outputs` or `outputs_with_target`. To upgrade, delete + match arms that name a removed variant; `PlanError` is + `#[non_exhaustive]`, so a wildcard arm already covers the rest. No + stored byte changes. + - **A cipher no longer reads credentials you did not name** (#1722). `StackCipher::new()` and `init()` on the bare builder read `CS_CLIENT_ID`, `CS_CLIENT_KEY`, `CS_CLIENT_ACCESS_KEY`, @@ -1297,6 +1314,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 still comes back before the pending exists, as a `dynamic::Error`. `decrypt_with`'s `expected` context is checked inside the `Planned` lowering. No stored byte changes. +- **The `MatchConfig` and `Match` documentation says how a field and its + query agree** (#1671), where it said they agree "by construction". A + query made from the field's reference answers through the field's own + `Match`, and a data plan's query reads the field's one match index. A + filter derived directly with `match_terms` matches a stored one only + under the field's configuration. - **The context parameter of the cipher-directed methods is named `context`, not `aad`** (#1568): `KeysetCipher::encrypt_tree`, `KeysetCipher::decrypt_tree`, `StackCipher::decrypt`, diff --git a/packages/stack-encrypt/docs/adr/0009-operators-select-the-index-and-a-query-term-is-not-the-stored-term.md b/packages/stack-encrypt/docs/adr/0009-operators-select-the-index-and-a-query-term-is-not-the-stored-term.md index 969c3b8e7..c55b00824 100644 --- a/packages/stack-encrypt/docs/adr/0009-operators-select-the-index-and-a-query-term-is-not-the-stored-term.md +++ b/packages/stack-encrypt/docs/adr/0009-operators-select-the-index-and-a-query-term-is-not-the-stored-term.md @@ -1,7 +1,7 @@ --- status: proposed date: 2026-10-13 -amended: 2026-11-10 +amended: 2026-11-23 supersedes: ADR-0004 (decision 5) extends: ADR-0003, ADR-0007 --- @@ -249,6 +249,10 @@ pub trait DefaultIndex: Operator { } ``` +*Amended 2026-11-23:* `DefaultIndex` and `.via` are removed. A field's +target type answers through `Answers`, and a plan that is data through +`dynamic::Op::answered_by`. See [Amended 2026-11-23](#amended-2026-11-23-1671). + ### 4. A query term is one of three things, and the trait it implements is its fidelity ```rust @@ -1282,3 +1286,42 @@ vitaminc-ore's `Orderable`, which `stack_encrypt::Orderable` re-exports. That trait covers the integers of 16 bits and wider, the floats, text, dates, timestamps, and decimals. It does not cover bytes or an 8-bit integer. Where this ADR names `op::Ordered`, read `Orderable`. + +## Amended 2026-11-23 (#1671) + +`DefaultIndex` and `.via(index)` are removed (#1666, with the plan builder +they belonged to). Nothing replaced them with a new choice: each field +declares at most one index per operator (amended 2026-11-10), so a query +has nothing to choose. + +- **A typed field answers through its target type.** A query starts from + the field's reference, which carries the field's target type. That type + implements `Answers`, whose `Via` is the index that answers `Op`: + `EqualityTerm` answers `Eq` through `Equality`, `MatchTerms` answers + `Matches` through `Match`, and a tuple of terms answers through the + one term that answers the operator. So a field declared with a match + index under configuration `O` is queried under `O`: the query cannot + name another index or other options. A field whose type has no + `Answers` impl for an operator has no method for it, and the query does + not compile. +- **A plan that is data answers through `dynamic::Op::answered_by`.** A + field of a data plan lists its indexes as `IndexSpec` values. + `dynamic::Op::answered_by(kind, indexes)` returns the one that answers + the operator for the field's kind, from each index's own declaration of + its operators (`IndexSpec::answers`). The query derives its term under + that index's options, which are the options the stored term was derived + under. `Plan::query` refuses an operator no index answers before any key + is requested. + +Neither path takes an index from the caller, so the refusals that guarded a +caller's choice are removed with it: `PlanError::IndexNotDeclared` (an index +the field does not declare) and `PlanError::IndexOptions` (a match index +under other options). Five more variants that only removed code raised go +with them: `IdentityWithoutField`, `NoContext`, `PassthroughIndexed` and +`TargetWithVerbs`, which the plan builder raised, and `MixedCiphers`, which +`plan::all` raised. A data plan that declares a passthrough field with +outputs, or a field with both outputs and a target, is still refused, by +the parser, as `passthrough_with_outputs` and `outputs_with_target`. + +Where decision 1 and decision 7 write `.via(Ore)` and `.via(Ope)`, read: the +index the field declares for the operator. diff --git a/packages/stack-encrypt/src/codes.rs b/packages/stack-encrypt/src/codes.rs index fc31c56b0..c6740c3b4 100644 --- a/packages/stack-encrypt/src/codes.rs +++ b/packages/stack-encrypt/src/codes.rs @@ -9,8 +9,7 @@ mod tests { use uuid::Uuid; use crate::diagnostic::is_code_of; - use crate::sem::{MatchOptions, TermBytesError, TermError}; - use crate::target::IndexSpec; + use crate::sem::{TermBytesError, TermError}; use crate::{BlobError, Descriptor, Error, LabelError, LeafBytesError, PlanError}; /// One row per variant of an enum, written `pattern => value`. The @@ -89,7 +88,7 @@ mod tests { }, Error::NoKeyset => Error::NoKeyset, Error::NotOpened => Error::NotOpened, - Error::Plan(_) => Error::Plan(PlanError::NoContext), + Error::Plan(_) => Error::Plan(PlanError::BindInQuery), Error::Blob(_) => Error::Blob(BlobError::NotABlob), ])); errors.extend(boxed(variants![ @@ -165,16 +164,12 @@ mod tests { field: field(), source: LabelError::Empty, }, - PlanError::IdentityWithoutField => PlanError::IdentityWithoutField, PlanError::DuplicateField { .. } => PlanError::DuplicateField { field: field() }, PlanError::SharedIdentity { .. } => PlanError::SharedIdentity { identity: "age".into(), first: "age".into(), second: "years".into(), }, - PlanError::PassthroughIndexed { .. } => { - PlanError::PassthroughIndexed { field: field() } - }, PlanError::DuplicateIndex { .. } => PlanError::DuplicateIndex { at: field(), index: "eq", @@ -191,19 +186,6 @@ mod tests { expected: "int64", }, PlanError::NoSuchField { .. } => PlanError::NoSuchField { field: field() }, - PlanError::MixedCiphers => PlanError::MixedCiphers, - PlanError::IndexNotDeclared { .. } => PlanError::IndexNotDeclared { - field: field(), - index: "ore", - }, - PlanError::IndexOptions { .. } => PlanError::IndexOptions { - field: field(), - declared: IndexSpec::Match(MatchOptions::default()), - asked: IndexSpec::Match(MatchOptions { - downcase: false, - ..MatchOptions::default() - }), - }, PlanError::IndexOverlap { .. } => PlanError::IndexOverlap { at: field(), first: "ore", @@ -214,9 +196,7 @@ mod tests { first: "the plan", second: "the call", }, - PlanError::NoContext => PlanError::NoContext, PlanError::BindInQuery => PlanError::BindInQuery, - PlanError::TargetWithVerbs { .. } => PlanError::TargetWithVerbs { field: field() }, ])); #[cfg(feature = "dynamic")] errors.extend(dynamic_variants()); @@ -226,6 +206,7 @@ mod tests { #[cfg(feature = "dynamic")] fn dynamic_variants() -> Vec { use crate::dynamic::{Error, Reason, TargetError, ValueKind}; + use crate::target::IndexSpec; let name = || "email".to_string(); let target = || "TextEq".to_string(); let mut errors = Vec::new(); @@ -384,11 +365,6 @@ mod tests { fn every_payload() -> Vec<(Box, serde_json::Value)> { use serde_json::json; let (a, b) = (Uuid::from_u128(1), Uuid::from_u128(2)); - let declared = IndexSpec::Match(MatchOptions::default()); - let asked = IndexSpec::Match(MatchOptions { - downcase: false, - ..MatchOptions::default() - }); let payloads: Vec<(Box, serde_json::Value)> = vec![ ( Box::new(Error::Kms(crate::kms::Error::GenerateKey( @@ -548,26 +524,6 @@ mod tests { }), json!({ "field": "age", "expected": "int64" }), ), - ( - Box::new(PlanError::IndexNotDeclared { - field: "age".into(), - index: "ore", - }), - json!({ "field": "age", "index": "ore" }), - ), - ( - Box::new(PlanError::IndexOptions { - field: "age".into(), - declared: declared.clone(), - asked: asked.clone(), - }), - json!({ - "field": "age", - "index": "match", - "declared": { "match": { "tokenizer": { "ngram": 3 }, "downcase": true, "k": 3, "m": 256 } }, - "asked": { "match": { "tokenizer": { "ngram": 3 }, "downcase": false, "k": 3, "m": 256 } }, - }), - ), ( Box::new(PlanError::TwoContextSources { first: "the plan", @@ -575,7 +531,7 @@ mod tests { }), json!({ "first": "the plan", "second": "the call" }), ), - (Box::new(PlanError::NoContext), json!({})), + (Box::new(PlanError::BindInQuery), json!({})), ]; // The builder error's fields come through the box. #[cfg(feature = "http")] @@ -600,6 +556,7 @@ mod tests { #[cfg(feature = "dynamic")] fn dynamic_payloads() -> Vec<(Box, serde_json::Value)> { use crate::dynamic::{Error, Reason, TargetError, ValueKind}; + use crate::target::IndexSpec; use serde_json::json; let name = || "email".to_string(); let target = || "TextEq".to_string(); diff --git a/packages/stack-encrypt/src/dynamic/record.rs b/packages/stack-encrypt/src/dynamic/record.rs index 58dc25d27..ee13cf764 100644 --- a/packages/stack-encrypt/src/dynamic/record.rs +++ b/packages/stack-encrypt/src/dynamic/record.rs @@ -662,7 +662,6 @@ fn refusal(error: crate::Error) -> (Option, Reason) { P::FieldLabel { field, .. } => (Some(field), Reason::ContextNotLabel), P::DuplicateField { field } => (Some(field), Reason::DuplicateField), P::SharedIdentity { second, .. } => (Some(second), Reason::SharedIdentity), - P::PassthroughIndexed { field } => (Some(field), Reason::PassthroughWithOutputs), P::DuplicateIndex { at, .. } => (Some(at), Reason::DuplicateOutput), P::IndexOverlap { at, .. } => (Some(at), Reason::OverlappingOutputs), P::EmptyIndexes => (None, Reason::NoOutputs), @@ -670,17 +669,9 @@ fn refusal(error: crate::Error) -> (Option, Reason) { P::NotInValue { field } => (Some(field), Reason::FieldMissing), P::FieldType { field, .. } => (Some(field), Reason::FieldType), P::NoSuchField { field } => (Some(field), Reason::NoSuchField), - P::TargetWithVerbs { field } => (Some(field), Reason::OutputsWithTarget), - P::IndexNotDeclared { field, .. } | P::IndexOptions { field, .. } => { - (Some(field), Reason::Refused) - } P::BindInQuery => (None, Reason::BindInQuery), P::EmptyPart => (None, Reason::EmptyBinding), - P::IdentityWithoutField - | P::MixedCiphers - | P::TwoContextSources { .. } - | P::NoContext - | P::ContextNotStorable { .. } => (None, Reason::Refused), + P::TwoContextSources { .. } | P::ContextNotStorable { .. } => (None, Reason::Refused), } } @@ -8388,11 +8379,6 @@ mod tests { some("years"), SharedIdentity, ), - ( - P::PassthroughIndexed { field: field() }.into(), - some("age"), - PassthroughWithOutputs, - ), ( P::DuplicateIndex { at: field(), @@ -8427,32 +8413,6 @@ mod tests { some("age"), NoSuchField, ), - ( - P::TargetWithVerbs { field: field() }.into(), - some("age"), - OutputsWithTarget, - ), - ( - P::IndexNotDeclared { - field: field(), - index: "ore", - } - .into(), - some("age"), - Refused, - ), - ( - P::IndexOptions { - field: field(), - declared: IndexSpec::Equality, - asked: IndexSpec::Equality, - } - .into(), - some("age"), - Refused, - ), - (P::IdentityWithoutField.into(), None, Refused), - (P::MixedCiphers.into(), None, Refused), ( P::TwoContextSources { first: "the plan", @@ -8462,7 +8422,6 @@ mod tests { None, Refused, ), - (P::NoContext.into(), None, Refused), (P::BindInQuery.into(), None, BindInQuery), ( P::IndexOverlap { diff --git a/packages/stack-encrypt/src/plan/error.rs b/packages/stack-encrypt/src/plan/error.rs index eaf214254..df4bcea1f 100644 --- a/packages/stack-encrypt/src/plan/error.rs +++ b/packages/stack-encrypt/src/plan/error.rs @@ -1,6 +1,5 @@ //! Why a plan was refused. use crate::op::Op; -use crate::target::IndexSpec; use crate::LabelError; /// Why a plan was refused: when it was parsed, or when it was run against a @@ -9,19 +8,6 @@ use crate::LabelError; /// Every refusal of a plan is raised before any key is requested: a plan /// that does not hold up never reaches ZeroKMS. Carried in [`Error::Plan`]. /// -/// Some variants were raised only by the Rust plan builder, which is -/// removed, so nothing raises them now: [`IdentityWithoutField`], -/// [`MixedCiphers`], [`IndexNotDeclared`], [`IndexOptions`], [`NoContext`] -/// and [`TargetWithVerbs`]. They stay because each has an error code that a -/// binding's status table lists. Each one's documentation says so. -/// -/// [`IdentityWithoutField`]: Self::IdentityWithoutField -/// [`MixedCiphers`]: Self::MixedCiphers -/// [`IndexNotDeclared`]: Self::IndexNotDeclared -/// [`IndexOptions`]: Self::IndexOptions -/// [`NoContext`]: Self::NoContext -/// [`TargetWithVerbs`]: Self::TargetWithVerbs -/// /// [`Error::Plan`]: crate::Error::Plan /// /// Every variant has a `stack_encrypt::` miette code, and names the field @@ -57,14 +43,6 @@ pub enum PlanError { #[diagnostic_source] source: LabelError, }, - /// `identity` was called before any field was declared, so there was no - /// field for it to pin. - /// - /// Not raised any more: only the removed plan builder raised it. Kept - /// for its error code. - #[error("identity was set before any field was declared")] - #[diagnostic(code(stack_encrypt::plan_identity_without_field))] - IdentityWithoutField, /// A field was named twice. #[error("field {field:?} is named twice")] #[diagnostic(code(stack_encrypt::plan_duplicate_field))] @@ -89,18 +67,6 @@ pub enum PlanError { /// The field declared second. second: String, }, - /// A field was declared both passthrough and indexed. A passthrough - /// field is carried unsealed and unauthenticated; one that must be - /// searchable is sealed, with its indexes beside it. - #[error("field {field:?} is declared both passthrough and indexed")] - #[diagnostic( - code(stack_encrypt::plan_passthrough_indexed), - help("A passthrough field is stored unsealed. Seal the field to index it.") - )] - PassthroughIndexed { - /// The field. - field: String, - }, /// A field, or a record of one value, names the same index twice. #[error("{at:?} names the {index} index twice")] #[diagnostic(code(stack_encrypt::plan_duplicate_index))] @@ -155,57 +121,6 @@ pub enum PlanError { /// The field asked for. field: String, }, - /// The operations given to one batch were started on different - /// ciphers. The removed `plan::all` refused such a batch. - /// - /// Not raised any more. [`Pending::zip`](crate::Pending::zip) and - /// [`Pending::all`](crate::Pending::all) accept operations started on - /// different ciphers, because they check the keyset, not the cipher. - /// Kept for its error code. - #[error("the operations in one batch were started on different ciphers")] - #[diagnostic( - code(stack_encrypt::plan_mixed_ciphers), - help("Start every operation in one batch on the same cipher.") - )] - MixedCiphers, - /// A query asked a field for an index the field never declared, so it - /// would have matched nothing. - /// - /// Not raised any more: only the removed plan builder raised it. Kept - /// for its error code. - #[error("field {field:?} declares no {index} index")] - #[diagnostic( - code(stack_encrypt::plan_index_not_declared), - help("Query the field through an index it declares, or declare the index on the field.") - )] - IndexNotDeclared { - /// The field, or `the value` for a one-value plan. - field: String, - /// The index asked for, as its key. - index: &'static str, - }, - /// A query asked a field for an index the field declares with other - /// options (a match index under another tokenizer or filter size), so - /// its terms would never have matched. - /// - /// Not raised any more: only the removed plan builder raised it. Kept - /// for its error code. - #[error( - "field {field:?} declares a {} index with other options: declared {declared:?}, asked {asked:?}", - declared.key() - )] - #[diagnostic( - code(stack_encrypt::plan_index_options), - help("Query with the options the field declares: terms derived under other options never match.") - )] - IndexOptions { - /// The field, or `the value` for a one-value plan. - field: String, - /// The index as the field declares it. - declared: IndexSpec, - /// The index as the query asked for it. - asked: IndexSpec, - }, /// A field declares two indexes that answer one operator, so a query /// for it would have two terms to choose from and the plan has to /// guess. A field declares at most one index per operator: @@ -246,16 +161,6 @@ pub enum PlanError { /// Who gave it again. second: &'static str, }, - /// The plan was run with no context: it was built without one and has - /// no context field, and the call named none. - /// - /// Not raised any more: only the removed plan builder raised it. Kept - /// for its error code. - #[error( - "the plan has no context: build it with one, name one in the call, or use a context field" - )] - #[diagnostic(code(stack_encrypt::plan_no_context))] - NoContext, /// A query was extended by a binding. A binding is in the stored /// context alone, so a query cannot carry one: the row is found by its /// scopes, and the binding is checked when the row is opened. @@ -295,18 +200,6 @@ pub enum PlanError { /// context that the type was given. field: String, }, - /// A field was declared both as a typed target (`encrypt_into`) and with - /// a data verb. A field is one or the other: the target's type decides - /// its layout and its queries. - /// - /// Not raised any more: only the removed plan builder raised it. Kept - /// for its error code. - #[error("field {field:?} is declared both as a typed target and with data verbs")] - #[diagnostic(code(stack_encrypt::plan_target_with_verbs))] - TargetWithVerbs { - /// The field. - field: String, - }, } impl crate::ErrorPayload for PlanError { @@ -320,11 +213,9 @@ impl crate::ErrorPayload for PlanError { fields } Self::DuplicateField { field } - | Self::PassthroughIndexed { field } | Self::NotInPlan { field } | Self::NotInValue { field } | Self::NoSuchField { field } - | Self::TargetWithVerbs { field } | Self::ContextNotStorable { field } => payload([("field", field.as_str().into())]), Self::SharedIdentity { identity, @@ -342,19 +233,6 @@ impl crate::ErrorPayload for PlanError { ("field", field.as_str().into()), ("expected", (*expected).into()), ]), - Self::IndexNotDeclared { field, index } => { - payload([("field", field.as_str().into()), ("index", (*index).into())]) - } - Self::IndexOptions { - field, - declared, - asked, - } => payload([ - ("field", field.as_str().into()), - ("index", declared.key().into()), - ("declared", index_value(declared)), - ("asked", index_value(asked)), - ]), Self::IndexOverlap { at, first, @@ -369,51 +247,7 @@ impl crate::ErrorPayload for PlanError { Self::TwoContextSources { first, second } => { payload([("first", (*first).into()), ("second", (*second).into())]) } - Self::IdentityWithoutField - | Self::EmptyIndexes - | Self::MixedCiphers - | Self::NoContext - | Self::BindInQuery - | Self::EmptyPart => serde_json::Map::new(), - } - } -} - -/// An index as a plan writes it: its key, or for a match index the object of -/// its options (`{"match": {"tokenizer": "standard", "downcase": true, -/// "k": 3, "m": 256}}`, an n-gram tokenizer as `{"ngram": 3}`, and -/// `"short_words": true` only when that option is on), and for a -/// JSON index the object of its options (`{"json": {"sealed_root": -/// true, "ordered": ["$.age"]}}`). A caller in another language can read -/// it, and it does not move when a field is added to the Rust type, as -/// `Debug` text would. -fn index_value(index: &IndexSpec) -> serde_json::Value { - use crate::sem::Tokenizer; - match index { - IndexSpec::Match(options) => { - let tokenizer = match options.tokenizer { - Tokenizer::Standard => serde_json::Value::from("standard"), - Tokenizer::Ngram { length } => serde_json::json!({ "ngram": length }), - }; - let mut value = serde_json::json!({ - "tokenizer": tokenizer, - "downcase": options.downcase, - "k": options.k, - "m": options.m, - }); - if options.short_words { - value["short_words"] = true.into(); - } - serde_json::json!({ "match": value }) - } - IndexSpec::Json(options) => serde_json::json!({ - "json": { - "sealed_root": options.sealed_root, - "ordered": options.ordered, - } - }), - IndexSpec::Equality | IndexSpec::Ore | IndexSpec::Ope | IndexSpec::OreBlock => { - index.key().into() + Self::EmptyIndexes | Self::BindInQuery | Self::EmptyPart => serde_json::Map::new(), } } } diff --git a/packages/stack-encrypt/src/sem/mod.rs b/packages/stack-encrypt/src/sem/mod.rs index 9427b5527..9c2f15588 100644 --- a/packages/stack-encrypt/src/sem/mod.rs +++ b/packages/stack-encrypt/src/sem/mod.rs @@ -800,9 +800,18 @@ impl MatchOptions { } /// Type-level match configuration: the [`MatchOptions`] a [`MatchTerms`] -/// is generated with. Putting the configuration on the *type* means a record -/// field and the query probing it agree on tokenizer and filter parameters by -/// construction. Define your own by implementing this on a marker type. +/// is generated with. Define your own by implementing this on a marker type. +/// +/// A field stored as `MatchTerms` and a query made from that field's +/// reference use one configuration: the field's type names its match index, +/// [`Match`](struct@crate::target::Match), through +/// [`Answers`](crate::op::Answers), and the query derives its filter through +/// that index. A filter derived directly, with +/// [`match_terms`](crate::KeysetCipher::match_terms) or a `Match` the +/// caller names, is cut under whatever configuration it is given, and +/// matches a stored filter only when that configuration is the field's. A +/// plan that is data has one match index per field, and its stored filter +/// and its query both read that index's options. pub trait MatchConfig: Send + Sync + 'static { fn options() -> MatchOptions; @@ -2059,12 +2068,15 @@ impl KeysetCipher<'_, K> { /// `descriptor` and the type-level config `O`: tokenize locally, PRF each /// token, fold the outputs into Bloom-filter bit positions. /// - /// The config is a *type* parameter (not runtime options) so write-time - /// and query-time terms agree by construction — a term generated under - /// one config cannot be compared against a term generated under another, - /// which would otherwise silently return false negatives. Byte-identical - /// to the target-directed path for the same `O`. For custom options, - /// define a marker type implementing [`MatchConfig`]. + /// The config is a *type* parameter (not runtime options), so the + /// filter's type says which configuration cut it. A filter cut under + /// one config is not comparable with one cut under another: a query + /// would miss rows it should match, with no error. So a filter derived + /// here matches a stored one only when `O` is the field's own. A query + /// made from the field's reference takes the field's `O` ([`MatchConfig`] + /// says how). Byte-identical to the target-directed path for the same + /// `O`. For custom options, define a marker type implementing + /// [`MatchConfig`]. /// /// This derives the *stored* filter. Text that yields no tokens (empty /// or separator-only text, or text shorter than the n-gram length; see diff --git a/packages/stack-encrypt/src/target/index.rs b/packages/stack-encrypt/src/target/index.rs index d35c9a456..34dd77493 100644 --- a/packages/stack-encrypt/src/target/index.rs +++ b/packages/stack-encrypt/src/target/index.rs @@ -342,8 +342,9 @@ impl Json { /// The value [`Match`](constant@Match) is the index under the default /// configuration ([`DefaultMatch`]), as `PhantomData` is a value of its /// type; `Match::::new()` is another. The configuration is on the -/// type so that a stored field and the query probing it agree on it by -/// construction. +/// type, so a field's type fixes the one its stored filter and its queries +/// are cut under: a query made from the field's reference answers through +/// the field's own `Match` ([`Answers`](crate::op::Answers)). pub struct Match { config: PhantomData O>, }