S
Store

Change Events

Subscribe to record-store changes for local logging, monitoring, and UI updates.

Record subscriptions

import { createStore } from "@cuitty/store/client";

const store = await createStore({
  module: "my-app",
  schema: {
    users: { class: "record" },
  },
});

const users = store.record("users");

const unsubscribe = users.subscribe({}, (change) => {
  console.log(`${change.type}: ${change.key}`);
});

await users.put("user:1", { name: "Alice" });
unsubscribe();

Record events

EventPayloadFired when
put{ key, value, receipt }A record is written
patch{ key, value, receipt }A record is patched
delete{ key, receipt }A record is deleted

Event stream events

Event streams do not expose a subscription handle yet. Query the stream after appending events:

const audit = store.event("audit");
await audit.append({ action: "login", userId: "user:1" });

const recent = await audit.query({ limit: 10 });

Sync status

Sync progress is observable through the sync controller:

const before = await store.sync.status();
await store.sync.flush();
const after = await store.sync.status();

console.log({ before: before.pending, after: after.pending });

Operation log

For audit-style UI, read the local operation log. Every write receipt has a matching operation entry.

const latest = store.operationLog().slice(-10);
for (const operation of latest) {
  console.log(operation.action, operation.store, operation.createdAt);
}