# Checkpoints

Remembers how far each view model has read.

A checkpoint has to live as long as the view model it tracks: pair an in-memory view model with [layerMemory](https://effect-cqrs.dambox.ch/reference/api/checkpoints/#layermemory) so it rebuilds from the event store on restart, and a durable one with a durable checkpoint store.

## Classes

### Checkpoints

Defined in: [src/Checkpoints.ts:13](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Checkpoints.ts#L13)

#### Extends

* `Shape`<`"effect-cqrs/Checkpoints"`, { `advance?`: (`viewModel`, `from`, `to`) => `Effect`<`boolean`, [`EventStoreError`](https://effect-cqrs.dambox.ch/reference/api/eventstore/#eventstoreerror)>; `get`(`viewModel`): `Effect`<`number`, [`EventStoreError`](https://effect-cqrs.dambox.ch/reference/api/eventstore/#eventstoreerror)>; `set`(`viewModel`, `position`): `Effect`<`void`, [`EventStoreError`](https://effect-cqrs.dambox.ch/reference/api/eventstore/#eventstoreerror)>; }, `this`>

#### Constructors

##### Constructor

> **new Checkpoints**(`_`): [`Checkpoints`](https://effect-cqrs.dambox.ch/reference/api/checkpoints/#checkpoints)

Defined in: node_modules/.pnpm/effect\@4.0.6/node_modules/effect/dist/Context.d.ts:121

###### Parameters

###### \_

`never`

###### Returns

[`Checkpoints`](https://effect-cqrs.dambox.ch/reference/api/checkpoints/#checkpoints)

###### Inherited from

Context.Service\<Checkpoints, { /\*\* The last processed position, \`0\` when the view model never ran. \*/ get(viewModel: string): Effect.Effect\<number, EventStoreError> set(viewModel: string, position: number): Effect.Effect\<void, EventStoreError> /\*\* \* Moves a checkpoint to \`to\` only if it is still at \`from\`, and returns whether it \* moved. View models use it to notice that another process moved their checkpoint, \* which can happen for a moment while a lease changes hands: in a \`transaction\` \* the batch then rolls back instead of being committed twice. Stores without it \* fall back to \`set\`, which can’t notice. \*/ readonly advance?: | ((viewModel: string, from: number, to: number) => Effect.Effect\<boolean, EventStoreError>) | undefined }>()(“effect-cqrs/Checkpoints”).constructor

## Variables

### layerMemory

> `const` **layerMemory**: `Layer.Layer`<[`Checkpoints`](https://effect-cqrs.dambox.ch/reference/api/checkpoints/#checkpoints)>

Defined in: [src/Checkpoints.ts:29](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Checkpoints.ts#L29)
