Skip to content

StateCollectionProxy

Proxy handle for a shared state collection, accessed via a SharedStateHandle returned by ctx.mkdb() or await ctx.observe(db(...)). Mutations are routed through auto-generated CRUD actions. Reads delegate to the underlying TanStack DB collection.

Note: StateCollectionProxy applies to shared state handles only. Entity state uses ctx.db.actions.<coll>_insert/update/delete for writes and ctx.db.collections.<coll>?.get/toArray for reads. See EntityDefinition for details.

Source: @durable-streams/darix-runtime

ts
interface StateCollectionProxy<T extends object = Record<string, unknown>> {
  insert(row: T): unknown
  update(key: string, updater: (draft: T) => void): unknown
  delete(key: string): unknown
  get(key: string): T | undefined
  toArray: T[]
}

Members

MemberParametersReturn TypeDescription
insert(row)row: TTransactionInsert a new row into the collection.
update(key, updater)key: string, updater: (draft: T) => voidTransactionUpdate a row by key. The updater receives an Immer-style mutable draft.
delete(key)key: stringTransactionDelete a row by key.
get(key)key: stringT | undefinedRead a single row by key. Returns undefined if not found.
toArray-T[]All rows as an array. This is a getter property, not a method.

Notes

  • Mutating methods (insert, update, delete) return a Transaction. These are fire-and-forget -- the write is persisted to the entity's durable stream asynchronously.
  • The update method uses Immer-style drafts. Mutate the draft directly rather than returning a new object.
  • toArray is a property, not a method call. Access it without parentheses: shared.items.toArray.