Snapshot
@rotorsoft/act-root / act/src / Snapshot
Type Alias: Snapshot<TState, TEvents>
Snapshot<
TState,TEvents> =object
Defined in: libs/act/src/types/action.ts:221
Snapshot of state at a specific point in time.
Snapshots represent the current state after applying events. They include metadata about how many events have been applied (patches) and how many snapshots have been taken for optimization.
Examples
const snapshot = await app.load(Counter, "counter-1");
console.log(snapshot.state); // { count: 42 }
console.log(snapshot.patches); // 8 (events since last snapshot)
console.log(snapshot.snaps); // 1 (1 snapshot taken)
console.log(snapshot.event); // Last event that created this snapshot
.on({ increment: z.object({ by: z.number() }) })
.emit((action, snapshot) => {
console.log("Current count:", snapshot.state.count);
console.log("Events applied:", snapshot.patches);
return ["Incremented", { amount: action.by }];
})
Type Parameters
TState
TState extends Schema
State schema
TEvents
TEvents extends Schemas
Event schemas
Properties
event?
readonlyoptionalevent?:Committed<TEvents, keyofTEvents>
Defined in: libs/act/src/types/action.ts:225
Event that created this snapshot (undefined for initial state)
patch?
readonlyoptionalpatch?:Readonly<Patch<TState>>
Defined in: libs/act/src/types/action.ts:231
Domain patch applied by this event (undefined for initial/loaded state)
patches
readonlypatches:number
Defined in: libs/act/src/types/action.ts:227
Number of patches applied since last snapshot
snaps
readonlysnaps:number
Defined in: libs/act/src/types/action.ts:229
Number of snapshots taken for this stream
state
readonlystate:TState
Defined in: libs/act/src/types/action.ts:223
Current state data