Repository navigation
feat(zero-rust): typed define_query and define_mutator - #208
Merged
Merged
Conversation
… feature JS's defineQuery and defineMutator, shaped like the Swift client's: a definition has its name in the TS registry and a serde argument type, and `with(args)` makes a QueryRequest or a MutateRequest. The client sends the name and the arguments as JSON (struct fields in declaration order, as a JS object literal keeps them), and a mutator reads them back as its type before its body runs; arguments that don't read fail it as an app error. A definition of `()` (or any type without fields) sends no arguments, as JS's `undefined` does. The context comes from the Zero: materialize, run, and preload now take any `ZeroQuery<C>` (an AnyQuery, a typed Query, or a QueryRequest built with the client's context), so existing `&AnyQuery` calls still compile. `Zero::mutate_request` takes a MutateRequest, next to `mutate(name, args)`, which keeps working. NamedQuery and NamedMutator erase the types, for an app's list of definitions and its drift tests. The `serde` feature adds only serde: json::to_value and json::from_value read and write `json::Value` natively, and Value and Object are serde types. The default build keeps no dependencies. Amp-Thread-ID: https://ampcode.com/threads/T-db04f816-97ed-4bc9-b19e-9ee68611a0ab Co-authored-by: tmm <tmm@tmm.dev>
…ator zbugs-model's queries and mutators are now define_query and define_mutator definitions, and its own NamedQuery, MutatorDef, MutateRequest, and serde_json bridge are gone. Rune and GPUI pass QueryRequests to materialize and preload, which build them with the client's context, and run mutations with Zero::mutate_request. QueryRequest is Send, so Rune can make one on the UI thread for the client on its sync thread, and materialize, run, and preload take an unsized ZeroQuery, for a list of preloads of different types. Amp-Thread-ID: https://ampcode.com/threads/T-db04f816-97ed-4bc9-b19e-9ee68611a0ab Co-authored-by: tmm <tmm@tmm.dev>
Amp-Thread-ID: https://ampcode.com/threads/T-db04f816-97ed-4bc9-b19e-9ee68611a0ab Co-authored-by: tmm <tmm@tmm.dev>
tmm
force-pushed
the
feat/zero-rust-define
branch
from
November 14, 2026 12:36
43688aa to
7c2887f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Typed named queries and mutators for the Rust client, as tmm decided (option A):
define_queryanddefine_mutatorbehind a new optionalserdefeature, shaped like the Swift client'sdefineQueryanddefineMutator. The context comes from theZeroinstance. Stacked on #206; it rides with 0.2.0 (minor changeset).zero_client::define:define_query→QueryDefinition,.with(args)→QueryRequest(Send, cloneable,read(view));define_mutator→MutatorDefinition,.with(args)→MutateRequest,.mutator()to register.NamedQuery<C>andNamedMutator<C>erase the types for lists of definitions (registration, drift tests). An argument type with no fields, such as(), sends no arguments, as JS'sundefineddoes.query::ZeroQuery<C>:materialize,run, andpreloadtake anAnyQuery, a typedQuery, or aQueryRequest(unsized too, so&dyn ZeroQuery<C>works). Existing calls compile unchanged.client::MutateRequest { name, args }andZero::mutate_request(request). Naming: JS and Swift both call thiszero.mutate(request). Rust has no overloading andmutate(name, args)already exists, somutatekeeps its signature and the request form ismutate_request, matching Swift'sMutateRequesttype name.json::ValueandObjectimplement serde;json::to_valueandjson::from_value.cargo tree -p zero-client -e normallists only zero-client); serde isdefault-features = false, features = ["std"].NamedQuery,MutatorDef,MutateRequest,AnyNamedQuery,AnyMutator, and serde_json bridge are gone. PARITY.md'sdefineQueryanddefineMutatorrows are updated.No change to the wire protocol, query or mutator names and arguments, or storage: zbugs-model's drift test (the same vectors zbugs-swift checks) passes unchanged in content, and I checked that it still fails when a query or mutator is renamed.
Checked locally:
cargo clippy --workspace --all-targets --all-features -D warnings,cargo test --workspace --all-features,cargo doc -D warnings; zbugs-modelcargo clippy -D warningsandcargo test(drift); zbugs-rune and zbugs-gpui (and--features e2e)cargo clippy -D warningsandcargo teston Linux.