Skip to content

surface updateIf and deleteIf version-fenced cas methods - #59

Merged
fabracht merged 1 commit into
mainfrom
surface-updateif-deleteif
Oct 22, 2026
Merged

fabracht merged 1 commit into
mainfrom
surface-updateif-deleteif

Conversation

@fabracht

Copy link
Copy Markdown
Contributor

Summary

Fixes #57 — surfaces the version-fenced compare-and-set writes through the TS adapter. The engine CAS (stitch-rs #47) shipped in @laboverwire/stitch-wasm 0.6.0, and the 0.6.4 floor bump already raised this package to ^0.6.0, so this release only exposes the methods — no new engine floor needed.

Changes

  • src/types.ts — add updateIf / deleteIf to the Store<S> interface.
    • updateIf(entity, id, fields, expectedVersion): Promise<number> — applies fields only if the row's server version still equals expectedVersion, resolves with the new version.
    • deleteIf(entity, id, expectedVersion): Promise<void> — removes the row under the same fence.
  • src/store.ts — StitchStore.updateIf / deleteIf forward through the existing #afterReady startup gate to the wasm Store. No optimistic queueing is added, and no error-string matching: the adapter forwards the engine's rejection untouched.
  • CHANGELOG.md — ## 0.6.5.
  • tests/integration/cas.test.ts (new) — contract tests.

Contract

  • Remote-first / online-only — sent to the broker first, never optimistically queued, applied locally only on success. With no connected remote the calls reject rather than defer (verified by the new tests), preserving the upstream contract.
  • err.kind = 'preconditionFailed' — a stale-version failure surfaces as the engine's terminal error kind (distinct from the retryable conflict). The adapter forwards rejections untouched, so callers read err.kind directly; no mapping layer.

Verification (on real stitch-wasm 0.6.0)

  • npm run check — type-check + lint + format + 40/40 browser tests (was 38; +2 new).
  • npm run build clean.

Known coverage gap

The CAS success path and the preconditionFailed-on-stale-version path require a live broker round-trip, which this suite does not provide (it only uses an unroutable URL that never connects). The new tests therefore cover the online-only rejection contract; the full round-trip remains a broker-backed e2e gap.

Closes #57.

@fabracht
fabracht force-pushed the surface-updateif-deleteif branch from 6a2cf3f to d8ba514 Compare October 22, 2026 18:53
@fabracht
fabracht merged commit 7d0ee2e into main Oct 22, 2026
4 checks passed
@fabracht
fabracht deleted the surface-updateif-deleteif branch October 22, 2026 19:05
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.

surface updateIf / deleteIf (version-fenced CAS) — needs a wasm release carrying stitch-rs#47

1 participant