Skip to Content
Jumentix DocsPackages@jumentix/canaUsage guideAPI reference

API reference

Compact map of the public Cana surface used by the guide.

Client lifecycle

APIPurpose
createClient(options)Create a browser database client.
client.open()Open or upgrade the database.
client.close()Close the open connection.
client.backendRead the active storage backend after open() for diagnostics.
client.storageState()Inspect storage availability and quota signal.
client.durabilityAssessment()Inspect persistence confidence.

Tables

APIPurpose
client.table<TRecord>(name)Create a typed table handle.
table.get(key)Read one record by primary key.
table.add(record, key)Insert only when the key is unused.
table.put(record, key)Insert or replace.
table.update(key, changes)Merge fields into an existing record.
table.delete(key)Delete one record.
table.clear()Delete all records from the store.
table.bulkAdd(records)Insert a batch in one transaction.
table.bulkPut(records)Upsert a batch in one transaction.
table.bulkDelete(keys)Delete a batch in one transaction.
table.query(query)Read records with optional index, direction, offset and limit.
table.count(query)Count records without materializing them in JavaScript.
table.explain(query)Return records plus the query plan Cana used.

Transactions and events

APIPurpose
client.transaction(mode, stores, body)Run a multi-store commit boundary.
client.subscribe(listener)Listen to committed CanaChangeEvent entries.
client.subscribe(listener, { sinceCursor })Replay retained events newer than the cursor.
client.resolveWrite(correlationId, attemptedAt)Resolve a write with unknown outcome when operationLedger is enabled.

Worker APIs

APIPurpose
createWorkerHost(options)Serve a real Cana client behind a Worker or MessagePort.
createRouter(options)Correlate requests and responses on the page side.
createWorkerClient(router)Typed facade for request/response operations across the boundary.

Factory adapter

Use the factory adapter when the rest of a Jumentix application expects repository-like store handles instead of calling client.table() directly.

Factory adapter

Use createCanaDatabaseClient with Category and Task stores.

const adapter = cana.createCanaDatabaseClient({
  name: dbName,
  schema: {
  version: 1,
  stores: [
    { name: 'categories', keyPath: 'id', indexes: [{ name: 'byName', keyPath: 'name', unique: true }] },
    {
      name: 'tasks',
      keyPath: 'id',
      indexes: [
        { name: 'byCategory', keyPath: 'categoryId' },
        { name: 'byCompleted', keyPath: 'completed' },
        { name: 'byUpdatedAt', keyPath: 'updatedAt' }
      ]
    }
  ]
}
});
await adapter.connect();
await adapter.stores.categories.add({ id: 'docs', name: 'Docs', color: '#0f766e' });
await adapter.stores.tasks.add({
  id: 'docs-1',
  title: 'Created through the adapter',
  categoryId: 'docs',
  completed: false,
  priority: 'medium',
  createdAt: 1,
  updatedAt: 1
});
const task = await adapter.stores.tasks.get('docs-1');
await adapter.disconnect();
return {
  backend: adapter.cana.backend,
  stores: Object.keys(adapter.stores),
  task
};

Glossary

TermMeaning
BackendThe active storage implementation behind the client.
CursorMonotonic number attached to committed change events.
Durable source of truthThe data layer that survives reloads. Cana plays this role for browser offline data.
Event replayDelivering retained events after a subscriber reconnects with sinceCursor.
Operation ledgerOptional store that lets Cana resolve an uncertain write outcome.
Query planDescription of whether Cana used an index, key range, count request or scan.
Structured cloneBrowser serialization used by Worker messages; it rejects functions and class instances with private state.