Integration guide

Everything an iWac app needs to join a device to the sync mesh.

Opening a channel

A client opens one long-lived channel to the nearest relay. The handshake carries the device token; everything after it is incremental.

const ch = Mirage.connect({
  endpoint: "https://mirage.iwacapp.com",
  device:   deviceToken,
  onDelta:  apply,
});

Applying deltas

Each delta is a compact, ordered patch. Apply them in sequence; Mirage guarantees ordering per collection and dedupes on reconnect.

function apply(delta){
  store.patch(delta.collection, delta.ops);
  ch.ack(delta.seq);
}

Conflict handling

Writes are last-writer-wins at the field level, with a vector clock kept per device so a stale edit never clobbers a newer one. Hooks let you override the merge for a specific collection.

Rate & limits

A single device may keep one channel open. Payloads are capped at 8 MiB per delta; larger attachments stream through the attachment store and arrive as references.