Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ exclude_globs = ["packages/stack-encrypt-derive/**"]
# same reason. The future that a native `into_future` returns has no
# `Default`, so the native mutant does not compile.
exclude_re = [
# stack-encrypt — equivalent. `predicate!`'s finders return the type of a
# path's values as a `PhantomData`, a zero-sized type with one value, so
# `PhantomData::from(Default::default())` is the same value. (Nothing calls
# them at run time either: the macro's checks are type-checked, never run.)
'stack-encrypt/src/field_reference/json/predicate_checks\.rs:\d+:\d+: replace .* -> PhantomData<[^>]*> with PhantomData::from\(Default::default\(\)\)$',
# stack-auth — unreachable under the native test build.
'stack-auth/src/transport\.rs:\d+:\d+: replace <impl std::fmt::Display for NoTransport>::fmt ',
'stack-auth/src/transport\.rs:\d+:\d+: replace <impl DynTransport for T>::send_dyn -> std::pin::Pin<Box<dyn Future<Output = Result<HttpResponse, RequestError>>\+\x27a>> ',
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Every npm package except EQL lives under `languages/typescript/`: packages in `l
EQL issues in this repository, never in the historical
`cipherstash/encrypt-query-language` repository. Old upstream issue and PR
links are provenance only.
- `packages/stack-auth`, `packages/stack-profile`, `packages/stack-kms`, `packages/stack-encrypt`, `packages/stack-encrypt-derive`, `packages/stack-encrypt-jsonpath`, `packages/stack-guest-abi`: The Rust crates imported from `cipherstash/cipherstash-suite` with their history, and one added here — `stack-auth` and `stack-profile` (published to crates.io, one version group), `stack-kms` (published to crates.io from 0.1.0, its own version group, re-exported by `stack-encrypt` as `stack_encrypt::kms`), `stack-encrypt` and `stack-encrypt-derive` (published to crates.io from 0.1.0, one version group; `eql-bindings`' `stack-encrypt` feature depends on them from the registry), `stack-encrypt-jsonpath` (the JSONPath grammar of the JSON index, moved out of `stack-encrypt` so the derive can check a field's declared paths at compile time; in the `stack-encrypt` version group, re-exported at `stack_encrypt::json`; its first version is published by hand, as the others' were, before Trusted Publishing can take it), and `stack-guest-abi` (`publish = false`). They are the members of the **root Cargo workspace**, with the three node binding crates below. See "Working on the Rust crates".
- `packages/stack-auth`, `packages/stack-profile`, `packages/stack-kms`, `packages/stack-encrypt`, `packages/stack-encrypt-derive`, `packages/stack-encrypt-jsonpath`, `packages/stack-guest-abi`: The Rust crates imported from `cipherstash/cipherstash-suite` with their history, and one added here — `stack-auth` and `stack-profile` (published to crates.io, one version group), `stack-kms` (published to crates.io from 0.1.0, its own version group, re-exported by `stack-encrypt` as `stack_encrypt::kms`), `stack-encrypt` and `stack-encrypt-derive` (published to crates.io from 0.1.0, one version group; `eql-bindings`' `stack-encrypt` feature depends on them from the registry), `stack-encrypt-jsonpath` (the JSONPath grammar of the JSON index and the SQL/JSON path predicate grammar its `match` operator reads, moved out of `stack-encrypt` so the derive can check a field's declared paths, and `predicate!` a predicate's text, at compile time; in the `stack-encrypt` version group, re-exported at `stack_encrypt::json`; its first version is published by hand, as the others' were, before Trusted Publishing can take it), and `stack-guest-abi` (`publish = false`). They are the members of the **root Cargo workspace**, with the three node binding crates below. See "Working on the Rust crates".
- `languages/typescript/packages/auth`, `languages/typescript/packages/profile`, `languages/typescript/packages/stack-auth-wasm`: The node bindings of those crates. `@cipherstash/auth` (napi-rs v2) and its six `platforms/*` packages are published to npm from this repository by `release.yml` (`auth-artifacts`, `publish-auth`); a change to what it ships, the `stack-auth` crate included, needs an `@cipherstash/auth` changeset (`require-auth-npm-changeset.yml`). `@cipherstash/profile` and its platforms are private and never published; `@cipherstash/stack-auth-wasm` is private and builds the wasm that `@cipherstash/auth` ships. Their `build` and `test` scripts never invoke cargo; `build:native`, `build:debug` and `test:cargo` do. `@cipherstash/auth` also ships two pure-JS framework adapters over the wasm `OidcFederationStrategy`: `./next` (Next.js App Router, hands the token to the render on a request header) and `./start` (TanStack Start: `csFederateCurrent` is called inside a function middleware the app declares itself, which hands the token to the server function through `next({ context })`; `@tanstack/react-start` is an optional peer loaded only by that entry).
- `languages/golang`: The Go module — the SDK `encrypt` with its generated-code support `encrypt/gensupport`, its test package `encrypt/encrypttest` (context assertions, and `NewClient`: an offline client over the deterministic test builds, for an application's tests; a **nested Go module** of its own, so only a program that imports it downloads those builds, requiring the SDK at the zero pseudo-version with `replace ../..` in the tree, and `NewClient` fails when the two are at different versions) and the policy packages `encrypt/policy` and `encrypt/policy/protosource`; the credential package `auth`; the generator `stashgen` and its command `cmd/stashgen`; and `internal` (the shared guest plumbing and the `record` wire model). A wazero host with no cgo. Its two WASI guests (`encrypt/guest`, `auth/guest`) are detached Cargo workspaces built by `mise run wasm:guest:build` and `mise run wasm:auth-guest:build`; `mise run wasm:guest:build:deterministic` and `wasm:guest:build:eql:deterministic` build the seeded TEST builds into `encrypt/encrypttest/wasm`, which `encrypttest` embeds and the hermetic Go tests read; the `.wasm` files are gitignored. The stack-encrypt guest has a second build with the EQL types (`mise run wasm:guest:build:eql`, cargo feature `eql`, linking `eql-bindings` by path; `wasm:guest:build:eql:deterministic` is its test build), embedded by `encrypt/eql` and registered on import, so a program whose generated code names an EQL type runs it (ADR-0007, amended). `encrypt/eql`'s types and `Types` table are generated from the EQL catalog by `eql-codegen` (`eql_gen.go`, written by `mise run types:generate` in `packages/eql` and drift-gated by `types:check` and `cargo test -p eql-codegen`). Generated `*_stash.go` files are committed and CI fails when `go generate ./...` changes one. Releases are cut by hand with `.github/workflows/release-golang.yml` (`gh workflow run release-golang.yml -f version=X.Y.Z[-pre] --ref <branch>`): because the guests are gitignored on main and Go fetches a version as the files committed at its tag, the workflow builds them, commits them on a release-only commit no branch points at, with `encrypt/encrypttest/go.mod` pinned to the SDK version by `scripts/go-release-pin-encrypttest.sh` (run in `build` and in `publish`), tags it `languages/golang/vX.Y.Z` and `languages/golang/encrypt/encrypttest/vX.Y.Z` (the workflow's `MODULES`) and pushes the tags alone, then attaches the EQL v4 SQL bundle to the GitHub release. The ref must carry the EQL v4 bundle, or the build stops at "Build the EQL SQL bundles". `scripts/go-release-version.mjs` refuses, before anything is built, every version Go would refuse (non-canonical semver, `+build` metadata, a v2+ major on a module path with no `/vN` suffix, a version shaped like a pseudo-version), a final version dispatched from anywhere but `main`, and a final version while `languages/golang/go.mod` pins a `github.com/cipherstash/vitaminc/…` module at a pseudo-version (vitaminc's Go bindings have no tags, and a TEMPORARY pin on an unreleased commit must be gone before the module is tagged); a pre-release may come from a branch and may carry such a pin. The build job also refuses a version the Go proxy already lists in `@v/list`, which catches a tag deleted after the proxy fetched it; it never asks the proxy for the version itself before the tag exists, because the proxy would cache "not found" for up to 30 minutes and `verify` would fail after the push. The build checks the `Cargo.lock` of the EQL workspace and both guest workspaces with `--locked` first, since none of those builds passes it. It runs in a job with no write token and hands the guests to a `publish` job that holds `contents: write` and runs only git and gh. `publish` fetches the commit with plain unauthenticated git rather than `actions/checkout`, whose `token` input defaults to the job's writable token, and refuses a release commit whose tree is not the one the build tested. `publish` takes the paths it commits from the workflow's fixed `GUESTS` list, never from the artifact, and refuses a `guests.sha256` that is not exactly one SHA-256 line for each of those five guests (the three production guests and the two test builds `encrypttest` embeds): the build job runs third-party code after writing that manifest, so a path read from it could put any file on the tag (`scripts/__tests__/go-release-artifact.test.mjs`). A version is immutable once the Go proxy has fetched it, so a tag is never moved or deleted: if `publish` or `verify` fails after the tag is pushed, use "Re-run failed jobs" on the same run, which keeps a tag that run pushed and creates or completes the release; a new dispatch of the same version is refused. Never tag a main commit by hand: `go get` would fetch a module with no guests. `encrypt/example` is a third nested module, never tagged: it requires both modules as an application does. `./...` stops at a nested module, so `scripts/go-binding-test.sh`, `go:lint` and the generated-code check find each `go.mod` and run in its directory.
- `e2e/*`: Cross-package end-to-end tests (package managers, supply chain, Prisma example README)
Expand Down
30 changes: 20 additions & 10 deletions docs/plans/2026-10-24-stack-encrypt-api-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ The kinds of JSON query, the field reference method for each, and what each find
| Comparison at a path | `at().age().gt(v)`, `.lt(v)`, `.between(a, b)`, and the rest | Rows where the value at an ordered path orders against, or lies between, the given values | `JsonTreeLeafQuery`; two for `between`, low then high |
| A path's selector | `at().age().selector()` | The selector `->` and `ORDER BY eql_v4.ord_term(col -> $1)` take | `JsonTreeSelector` |
| Element match | `elements().visits().place().eq(v).and().at().gt(v)` | Rows where one element of an array meets several conditions together | `JsonTreeElementsQuery` |
| Jsonpath predicate | `predicate(text)`, with `.var(name, v)` for each variable | Rows where a SQL/JSON path predicate is true | `JsonTreePredicateQuery` |
| Jsonpath predicate | `predicate!(FIELD, "text", name = v, ..)`, checked when the program compiles, and `predicate(text)`, with `.var(name, v)` for each variable, for text built at run time | Rows where a SQL/JSON path predicate is true | `JsonTreePredicateQuery` |
| Children and child count | `children(path)` | The entries directly below one node, or how many there are | `JsonTreeToken` |

Paths are typed, from the attribute. Decided by Dan on 21 November 2026:
Expand Down Expand Up @@ -547,8 +547,14 @@ Paths are typed, from the attribute. Decided by Dan on 21 November 2026:
path and value. A field that declares no paths has only these.
- A predicate's variables are given one at a time: `.var(name, v)`, with
`v` a scalar, and `.var_null(name)`. A repeated name, a NaN and an
infinity are refused before any key is fetched. The predicate text is
checked when the query is encrypted.
infinity are refused before any key is fetched. The text of
`predicate(text)` is checked when the query is encrypted.
- `predicate!(FIELD, "text", name = v, ..)` checks a predicate written in
the program when the program compiles: that the text parses, that the
index can answer it, that each variable is given once and used, that the
field declares each path and member, and that each value, a variable's or
a literal's, is of the path's type. It sends the same text, so its
operand is the one `predicate(text)` derives.

Two limits of the SQL stay, from the reference page's sections on
comparing a value at a path and on what the SQL cannot do. Sorting rows by a path through an array
Expand Down Expand Up @@ -1627,13 +1633,17 @@ Base64.
form's operand and to the data plan's, the compile-fail cases under
`packages/stack-encrypt/tests/ui` hold the refusals, and the [JSON query
example](#query-a-json-document) runs.
- **Not done.** Checking a predicate's text at compile time (a
`predicate!` macro built on the typed paths), which a following pull
request adds. Until then the predicate text is checked when the query is
encrypted.
- **Tracked in.** Issue #1459 is open until the predicate pull request
merges; #1687 refers to it. Issue #1677 is open for opening one child.
Issue #1486 is closed.
- **Done** too: `predicate!(FIELD, "text", name = value, ..)` checks a
predicate's text at compile time, in the pull request stacked on #1687
(22 November 2026). It reads the text with the engine's parser, which
moved into `stack-encrypt-jsonpath`; refuses what the parser and the
index refuse whatever the variables hold; matches the variables with
the text's `$name`s; and checks each path, member and value through the
accessors the derive generated, found by the path's text. When the
program runs it is `predicate(text).var(..)`, so the operand is the text
form's and the data plan's `match` operand.
- **Tracked in.** Issue #1459 closes with the `predicate!` pull request.
Issue #1677 is open for opening one child. Issue #1486 is closed.
- **Finished when** these are all true:
- the [JSON query example](#query-a-json-document) compiles;
- a path, a member or a value type the field does not declare does not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,55 @@ async fn a_path_declared_for_equality_is_the_data_plans_operand() {
"{refused:?}"
);
}

/// `predicate!` on a `JsonTreeDocument` field: the macro's query is the
/// text form's for the same text and variables, as the EQL predicate type,
/// and it checks an ordered path, a path declared for equality alone and an
/// array's members alike.
#[tokio::test]
async fn the_predicate_macro_is_the_text_form() {
let (cipher, _) = common::cipher().await;
let keyset = cipher.default_keyset();
let min: u32 = 30;
let from_macro: JsonTreePredicateQuery = stack_encrypt::predicate!(
NamedCustomer::PROFILE,
r#"$.age >= $min && $.name == "Ada" && exists($.visits[*] ? (@.place == $p && @.at > 10))"#,
min,
p = "home",
)
.encrypt(&keyset)
.await
.unwrap();
let from_text: JsonTreePredicateQuery = NamedCustomer::PROFILE
.predicate(
r#"$.age >= $min && $.name == "Ada" && exists($.visits[*] ? (@.place == $p && @.at > 10))"#,
)
.var("min", min)
.var("p", "home")
.encrypt(&keyset)
.await
.unwrap();
// The equality leaf is a containment needle, whose selectors each
// derivation sends in a random order of its own: compare the trees
// with each selector set sorted.
let sorted = |query: &JsonTreePredicateQuery| {
fn sort(value: &mut Value) {
match value {
Value::Object(map) => {
for (key, inner) in map.iter_mut() {
if let (true, Value::Array(items)) = (key == "sv", &mut *inner) {
items.sort_by_key(|item| item.to_string());
}
sort(inner);
}
}
Value::Array(items) => items.iter_mut().for_each(sort),
_ => {}
}
}
let mut value = serde_json::to_value(query).unwrap();
sort(&mut value);
value
};
assert_eq!(sorted(&from_macro), sorted(&from_text));
}
5 changes: 3 additions & 2 deletions packages/stack-encrypt-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ syn = { version = "3", features = ["full", "extra-traits"] }
# built into the compiler's process.
stack-encrypt-jsonpath = { path = "../stack-encrypt-jsonpath", version = "0.3.0" }

# The dev-dependencies below are used only by the crate-level doctests.
# `tokio` and `zeroize` are used only by the crate-level doctests.
# `cargo-udeps` cannot see into rustdoc, so it reports them as unused.
# (`stack-encrypt` is used by a unit test too, which `cargo-udeps` sees.)
[package.metadata.cargo-udeps.ignore]
development = ["stack-encrypt", "tokio", "zeroize"]
development = ["tokio", "zeroize"]

[dev-dependencies]
# The plain-segment rule is copied from stack-encrypt (a proc-macro crate cannot
Expand Down
Loading
Loading