Skip to content

replace backend with stitch-wasm - #21

Merged
fabracht merged 3 commits into
mainfrom
replace-backend-with-stitch-wasm
Jul 19, 2026
Merged

replace backend with stitch-wasm#21
fabracht merged 3 commits into
mainfrom
replace-backend-with-stitch-wasm

Conversation

@fabracht

Copy link
Copy Markdown
Contributor

Replaces the TypeScript store backend with the Rust-backed @laboverwire/stitch-wasm. The TS package becomes a thin, framework-agnostic binding layer; all store/sync/persistence/queue logic now lives in stitch-rs (wasm).

Backend swap

  • src/store.ts is now a thin adapter (StitchStore + MemoryView) over @laboverwire/stitch-wasm@0.2.1 — presents the exact Store interface the React/Vue bindings expect (property getters, config, version-cached memory shim, connection-status normalization, setReconnectValidator + getTicket-aware reconnect).
  • Deleted relocated backend modules: memory-store, persistence-layer, remote-sync-layer, sync-engine, offline-queue, internal-utils, internal-wasm-error.
  • types.ts/index.ts trimmed to the public surface; dropped create* internal factories, OwnershipError, MqdbError.
  • Removed direct deps mqdb-wasm and mqtt5-wasm (now bundled inside the wasm).
  • React/Vue bindings unchanged.

Pre-init tolerance

The wasm store throws not initialized before initialize() completes. React fires child effects before parent effects, and Vue's async init races the same way, so hooks/composables that subscribe or read on mount crashed. Fixed in the shared TS wrapper (not the Rust core — native async consumers can't hit this):

  • sync reads gate on ready() and return empties ([]/{}/null/0/offline) instead of throwing;
  • subscribe* defer wiring until a #readyPromise resolves, then poke the callback so useSyncExternalStore re-reads; deferred subs return a working unsubscribe;
  • async methods route through #afterReady (run now if ready, else await init).

Tests

  • Deleted obsolete backend tests (offline-queue-flush, response-topic-parse, wasm-error).
  • Adapted integration tests to the wasm's async event delivery (vi.waitFor) and its subscribe-after-init contract.
  • Added React (react-hook-init.test.tsx) and Vue (vue-composable-init.test.ts) coverage proving pre-init mounts don't throw and that a subscription established before init reactively receives data after init + scope load.
  • vitest.config.ts gains vite-plugin-wasm + vite-plugin-top-level-await to load the wasm ESM.

Full suite: 30 passed. tsc, eslint, prettier clean.

Consumer note

Apps consuming this package will need vite-plugin-wasm (+ vite-plugin-top-level-await) in their Vite config to load the wasm ESM.

@fabracht
fabracht merged commit 8ea5d1d into main Jul 19, 2026
4 checks passed
@fabracht
fabracht deleted the replace-backend-with-stitch-wasm branch July 19, 2026 14:45
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.

1 participant