Skip to content

feat(durable object): expose SyncKvStorage#978

Open
chise0713 wants to merge 9 commits intocloudflare:mainfrom
chise0713:sync_kv
Open

feat(durable object): expose SyncKvStorage#978
chise0713 wants to merge 9 commits intocloudflare:mainfrom
chise0713:sync_kv

Conversation

@chise0713
Copy link
Copy Markdown

  • add wasm bindings for SyncKvStorage, reference
  • expose kv() on DurableObjectStorage
  • add missing startAfter to ListOptions (present in workerd, both async kv and sync kv)

Related: #967

…ions

Address review feedback on the SyncKvStorage bindings and bring them
in line with the patterns used elsewhere in worker-sys.

worker-sys:
- SyncKvStorage methods now have both non-throwing and `try_*`
  (`catch`) variants, matching the convention used for other
  Durable Object bindings
- `extends = Object` with `#[derive(Debug, Clone, PartialEq, Eq)]`
- `put(value: &JsValue)` takes by reference; `list()` returns
  `JsValue` since `Iterable<[string, T]>` has no wasm-bindgen mapping
- New `SyncKvListOptions` extern type with getters/setters for every
  field, exposing the JS object directly rather than serialising a
  Rust struct

worker:
- High-level `SyncKvStorage` calls the `try_*` sys variants so JS
  exceptions surface as `Error` instead of aborting
- `delete` now returns `Result<bool>` to match the fallible JS call
- `SyncKvListOptions` is re-exported from `worker-sys` directly;
  construction is via `SyncKvListOptionsBuilder::new()` which mutates
  the underlying JS object in place \u2014 no Rust-owned intermediate
  representation
- Reverted `startAfter` from `durable::ListOptions`; that field
  belongs to the async storage API and should land separately
- Tightened `SyncKvIterator::next` to use `dyn_into::<Array>`
  instead of dual checks; alphabetised `mod` ordering in lib.rs

example:
- Renamed wrangler worker name from `worker-rs-test` to
  `sync-kv-example` to avoid colliding with the test crate's
  deployed worker name
- Aligned `compatibility_date` with the test crate's (`2025-09-23`)
- Renamed `Test` durable object to `SyncKvDurableObject` for clarity

tests:
- Added `/list_options` exercising `start`, `start_after`, `end`,
  `reverse`, and `limit` against real workerd behaviour
- Updated existing assertions for the new `Result<bool>` shape of
  `delete`
- Use `collect::<Result<Vec<_>>>()?` instead of `.unwrap()` so test
  failures surface useful errors
- Moved `KEYS_LEN` const into the arms that use it
- Added missing trailing newlines on new files
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 2 untouched benchmarks


Comparing chise0713:sync_kv (1937aef) with main (fd18681)

Open in CodSpeed

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.

3 participants