Skip to content

feat(eql-bindings): answer order queries from a field reference - #1752

Merged
coderdan merged 4 commits into
nextfrom
feat/eql-bindings-order-queries
Nov 23, 2026
Merged

coderdan merged 4 commits into
nextfrom
feat/eql-bindings-order-queries

Conversation

@coderdan

Copy link
Copy Markdown
Contributor

Summary

A Rust record field typed with an ordered EQL type (IntegerOrd, DateOrdOre, TextOrd and the others) can now be range-queried from its field reference: EncryptedMember::AGE.gt(30).encrypt(&keyset) returns the type's query twin (IntegerOrdQuery, …). Before this, those types answered no operator from a field reference, so a Rust program could range-query them only through a data plan. Each query is the same bytes the data plan (the Go SDK's path) derives for the same value, and finds the same rows. No EQL SQL and no stored form changes.

Changes

  • eql-codegen (targets.rs): the rule for which operators a type answers now covers order indexes. eq goes through the equality index, lt/lte/gt/gte through the OPE or block ORE index, and matches through the match index, in the data path's operator order. The old typed_gap is removed.

  • Generated v4/answers.rs:

    • all 24 non-text ordered types (…Ord, …OrdOpe, …OrdOre) answer the four orderings;
    • TextOrd, TextOrdOpe and TextOrdOre answer eq and the orderings;
    • TextSearch and TextSearchOre answer eq, the orderings and matches.

    The ANSWERS table lists them all.

  • eql-bindings encryption/query.rs: TwinIndex<I, Q, D = I> gains a third parameter: the indexes whose terms the twin carries (D). New Supports impls cover the orderings on one-term twins, and Eq plus the orderings on (Equality, O) twins.

  • Tests:

    • typed_queries.rs covers all 39 answering types. Each type's operators must equal the data path's, with no gap allowed, and every query's bytes must equal the data path's. A block ORE ob term carries a random nonce, so it is checked with ore-rs's comparator instead.
    • New typed_order_queries.rs stores rows through a record and checks that the field reference's query and the data path's each find exactly the expected rows, in Rust and, as an #[ignore] PostgreSQL test, through the SQL operators.
  • packages/eql/mise.toml: typed_order_queries is added to the test:encryption:postgres suite list.

  • Docs:

    • eql-bindings README: the table and twin paragraph are updated, and a record example gains a doctest for AGE.gt(30).
    • query.rs module docs: updated, with a compile_fail doctest showing that IntegerOrd has no eq or between.
    • eql-bindings CHANGELOG: an Unreleased entry.
    • The plan doc's "EQL types as fields" section is updated.

Verification

Run in the packages/eql workspace:

  • Regenerated with cargo run -p eql-codegen -- bindings and -- go-eql. answers.rs changed. v4/targets.rs and the Go eql_gen.go are unchanged, and regenerating again after cargo fmt gives identical output.
  • cargo test -p eql-bindings --all-features passes, and the TS and JSON Schema exports are identical to the committed ones.
  • cargo test -p eql-codegen: the unit, parity and CLI suites pass.
  • cargo test -p eql-encryption-tests: all pass, including the README doctests and the new tests.
  • cargo clippy with -D warnings, on all targets and features: clean, also with --features stack-encrypt.
  • cargo fmt --all --check: clean.
  • cargo check --locked for wasm32-wasip1 passes with --features stack-encrypt and with --features targets.
  • PostgreSQL: the bundle was built with tasks/build.sh into a throwaway PG 17. Every suite in the test:encryption:postgres list was run with --ignored, and all pass: text_eq, v4_types, v4_order, v4_date_time_numeric, v4_range, v4_text_search, v4_ore_block, typed_order_queries and json_tree.
  • cargo doc -D warnings fails for eql-bindings and eql-codegen with the same pre-existing errors as next, in files this PR doesn't touch. There is one fewer, because the stale typed_gap link is gone.
  • Not run: stack-encrypt's tests and the Go tests. Neither stack-encrypt nor the engine changes, and eql_gen.go is unchanged.

Related

Closes #1668. Stacked on #1751.

Review notes

  • Design choice: the twin is built from more than one term. The issue offered two options: this, or a single-term twin form that the SQL accepts. The second would need SQL changes for text, because eql_v4.query_text_ord, _ope and _ore require both hm and op/ob. Every non-text ordered twin already has a single term, so those use the one-index path. This matches the data path's rule.
  • Text search types are included. They had the same gap (their twin carries an order term). Including them lets the test require that a field reference's operators equal the data path's for every type.
  • between is not answered. The issue lists Between, but the data path answers between on no EQL type, and the issue asks for the data path's rule. Adding it means changing both paths, using the existing query_*_range_* twins. It's left out on purpose, and a compile_fail doctest pins that.
  • TextOrd eq runs only the equality index's prepare check, as the data path does.
  • The API changes are to unreleased items only, so there is no Breaking entry.

@coderdan
coderdan requested a review from a team as a code owner November 22, 2026 14:32
@coderdan
coderdan requested a balanced review from Copilot November 22, 2026 14:32
@changeset-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a914822

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@cipherstash/eql Minor
stash Patch
@cipherstash/stack-prisma Patch
@cipherstash/basic-example Patch
@cipherstash/e2e Patch
@cipherstash/prisma-example Patch
@cipherstash/stack-drizzle Patch
@cipherstash/stack-supabase Patch
@cipherstash/stack Patch
@cipherstash/wizard Patch
@cipherstash/bench Patch
@cipherstash/test-kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d34444b5-7389-46d9-b092-b71c2b266bfe

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new ordering paths lack field-reference/data-path parity tests for trailing-NUL and oversized text in both TextOrdOre and TextSearchOre, leaving rejection before key requests unverified.

1 open issue
What changed in this PR

Adds ordered EQL v4 queries through Rust record field references, closing the gap described in #1668. Queries follow the existing data-plan behavior without changing SQL or stored formats.

Changes:

  • Generates ordering support for numeric, date/time, ordered-text and text-search fields.
  • Extends query-twin assembly to carry one or multiple index terms as required.
  • Adds parity and PostgreSQL tests, updates suite registration, and documents the API.
File Description
packages/​eql/​tests/​encryption/​tests/​typed_queries.rs Expands operator and term parity coverage to all 39 answering types.
packages/​eql/​tests/​encryption/​tests/​typed_order_queries.rs Adds row-selection checks for field-reference and data-plan queries.
packages/​eql/​tests/​encryption/​tests/​common/​mod.rs Adds a shared block ORE comparison helper.
packages/​eql/​mise.toml Registers the new PostgreSQL test suite.
packages/​eql/​crates/​eql-codegen/​src/​targets.rs Generates ordering answers and multi-term twin assembly.
packages/​eql/​crates/​eql-bindings/​src/​v4/​answers.rs Adds generated operator implementations for ordered and search types.
packages/​eql/​crates/​eql-bindings/​src/​encryption/​query.rs Extends TwinIndex and documents supported operations.
packages/​eql/​crates/​eql-bindings/​README.md Updates the operator table and adds an order-query example.
packages/​eql/​crates/​eql-bindings/​CHANGELOG.md Records the new query support and API changes.
docs/​plans/​2026-10-24-stack-encrypt-api-plan.md Updates the plan’s EQL field-query coverage.

Review effort: Balanced

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed 4c028752 · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review (standards and spec agents) · claude-opus-5-5; rust-security agent · claude-opus-5-5 (no new findings)
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check, company-skills:review-post

Findings (7): 3 minor, 4 nit — 5 inline, 1 below, 1 in reply.

  • .changeset/ minor Adds to #1752 (comment): this PR adds public eql-bindings surface (lt/lte/gt/gte from field references, TwinIndex's third parameter), and the crate releases in lockstep with @cipherstash/eql. Pending changesets already bump the version, but without an '@cipherstash/eql': minor changeset (like eql-json-tree-open-one-child.md) the feature gets no entry in packages/eql/packages/eql/CHANGELOG.md.

Source: code-review · claude-opus-5-5

Verified at head and dropped: 8 refuted (duplicate answers in answers_for_indexes, the two optional_terms checks, Answer::index's nameless panic, hand-edited crate CHANGELOG, TwinIndex upgrade note, duplicated impl bodies, the 6-type row tests, eq/matches scope). 1 already covered by #1752 (comment) (refusal tests).


Generated by Claude Code

@coderdan

Copy link
Copy Markdown
Contributor Author

Review round 1, addressed in 5b83b21. It was pushed as a fast-forward; the restack onto #1751's fixes comes next.

  • Missing @cipherstash/eql changeset (review body): added .changeset/eql-bindings-order-queries.md ('@cipherstash/eql': minor).
  • CI, "WASI check, guests and Go (Linux)": the unused IndexSpec import comes from refactor(stack-encrypt)!: remove the seven PlanError variants nothing raises #1749, which fixes it. It reaches this branch with the restack.
  • Release order: eql-bindings now calls the new TargetDescriptor::with_query_carrying_every_term, so the stack-encrypt release has to go out before the eql-bindings one. The lower PRs in this stack already require that order.
  • The inline findings are answered on their threads.

Checks at 5b83b21:

  • Root workspace:
    • fmt passes.
    • clippy and cargo test -p stack-encrypt --all-features pass.
    • rustdoc with -D warnings passes.
  • EQL workspace: every test:encryption and test:crates step passes. One eql-codegen CLI test (select_subcommand…) failed once and passed on rerun; it touches nothing this commit changes.
  • PostgreSQL 15: all nine test:encryption:postgres suites pass (63 tests).
  • Go: guests were rebuilt. go test ./... passes, and go generate produces no drift.
  • cargo-mutants on the stack-encrypt diff: 8 mutants, 4 caught, 4 unviable, 0 missed.

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth + stack-encrypt + stack-encrypt-jsonpath)

caught missed unviable timeout
4 0 4 0

Every mutant in the changed lines was caught by a test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The added changelog paragraph contradicts the preceding entry and advertises an unsupported JsonTreeChild decryption type, so the stale duplicate should be removed.

1 open issue
1 resolved since last review

Review effort: Balanced

A field reference of an ordered EQL v4 type (IntegerOrd, DateOrdOre,
TextOrd and the rest) had no op::Answers impls, so a Rust program could
range-query such a field only through a data plan. eql-codegen now
generates the impls for every producible type with a query twin, by the
rule the data path answers a field that names the type: eq through the
equality index, lt, lte, gt and gte through the type's order index (OPE
or block ORE), matches through the match index. Every ordered type
answers the orderings, TextOrd* answer eq too, and TextSearch and
TextSearchOre answer eq, the orderings and matches.

The twins differ in the terms they need, and no SQL or stored form
changes. An ordered type other than text has a one-term twin (op or
ob). eql_v4.query_text_ord requires hm and op together, so TwinIndex
takes a third type parameter, the indexes whose terms the twin carries
(defaulting to the answering index), and a TextOrd query derives the
terms of (Equality, Ope) for its one value through stack-encrypt's
Indexes, as the data path's run of the twin's own plan does. A text
search twin's terms are optional, so QueryTwin is implemented once per
term and its query carries the answering index's term alone, as the
data path's projection does. No type answers between, which the data
path answers on no EQL type.

typed_queries.rs now holds every type's operators to the data path's
with no gap, and every query's bytes to the data path's (a block ORE
term, which carries a random nonce, compares equal instead).
typed_order_queries.rs stores rows through a record and checks that a
field reference's query and the data path's each find exactly the rows
the plaintexts say, in Rust and, against an EQL v4 database, through the
SQL operators; it joins the test:encryption:postgres suites.

Closes #1668
…er index refuses

A TextOrd* query twin carries its hm and its order term whatever the
operator, so an eq query derives a block ORE (or OPE) term too. Both
paths checked the equality index alone for eq: the pair Eq impl's
prepare in eql-bindings, and stack-encrypt's prepare_input in
check_query and query_term. So TextOrdOre eq of text that ends in NUL,
or is too long for block ORE, passed a binding's boundary and was
refused only while its term was derived, after the keyset's index key
was loaded. An ordering of the same text was refused before any key.

The typed twin now prepares every index whose term it derives: the
equality index, then the order index, for eq and the orderings alike.
The data path does the same for a type whose twin carries every term:
TargetDescriptor gains query_carries_every_term (not on the wire, set
with with_query_carrying_every_term), which eql-bindings' EqlTargets
sets for every type with a twin except the text search types, whose
twin carries the answering index's term alone. A text search eq of the
same text is still answered by both paths, as before.

typed_queries.rs now holds both paths to the same refusal, before any
key request, for block ORE text ending in NUL or over the limit and for
text no index normalizes, on every ordered text type and operator, and
checks each type's descriptor against the terms its query carries. The
39 answering types are listed once, in one macro that writes the
record, the row and the dispatch from it; typed_order_queries.rs does
the same for its six columns, and ob_order picks the plaintext from the
type's family.

eql-codegen keys its typed-query rules on an IndexKey enum, so each
rule is an exhaustive match and a new index is a compile error rather
than a missed arm or a dropped import. The generated files do not
change.

The README and module docs are rewrapped; the API plan names the
follow-up for between and the state of #1658 and #1659. A changeset
records the feature for @cipherstash/eql.
The restack of the order-query change onto the child-read review fix
merged the old wording of the child entry under its new wording. The old
text said a child opens as DecryptSource<JsonPlaintext>, which is no
longer true.
…tween plainly

Searchable-encryption indexes belong to Stack Encrypt. EQL is one consumer
of them, so the doc of `target_indexes` no longer calls them the indexes
an EQL type answers through.

The note that a field reference has no `between` now says why: a range
query sends both bounds in one operand, and no SDK builds that operand
yet. The eql-bindings CHANGELOG points at the issue that tracks it.
@coderdan
coderdan force-pushed the feat/eql-bindings-order-queries branch from eaf369a to a914822 Compare November 23, 2026 00:15
Base automatically changed from feat/json-open-one-child to next November 23, 2026 01:01
@coderdan
coderdan merged commit a1680d2 into next Nov 23, 2026
57 checks passed
@coderdan
coderdan deleted the feat/eql-bindings-order-queries branch November 23, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stack-encrypt: a field marker cannot query an ordered EQL type such as IntegerOrd — add order queries

3 participants