Skip to content

Commit b36d3ac

Browse files
committed
fix: Finalize documentation on writing events.
1 parent 9fcb351 commit b36d3ac

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,30 @@ const writtenEvents = await client.writeEvents([
5555
}
5656
]);
5757
```
58+
59+
#### Using the `isSubjectPristine` precondition
60+
61+
If you only want to write events in case a subject (such as `/books/42`) does not yet have any events, import the `isSubjectPristine` function and pass it as the second argument as an array of preconditions:
62+
63+
```typescript
64+
import { isSubjectPristine } from 'eventsourcingdb';
65+
66+
const writtenEvents = await client.writeEvents([
67+
// events
68+
], [
69+
isSubjectPristine('/books/42')
70+
]);
71+
```
72+
73+
#### Using the `isSubjectOnEventId` precondition
74+
75+
If you only want to write events in case the last event of a subject (such as `/books/42`) has a specific ID (e.g., `0`), import the `isSubjectOnEventId` function and pass it as an array of preconditions in the second argument:
76+
77+
```typescript
78+
import { isSubjectOnEventId } from 'eventsourcingdb';
79+
80+
const writtenEvents = await client.writeEvents([
81+
// events
82+
], [
83+
isSubjectOnEventId('/books/42', '0')
84+
]);

0 commit comments

Comments
 (0)