Skip to content

Commit d8fe3e1

Browse files
committed
fix: Add missing documentation.
1 parent f2d2a89 commit d8fe3e1

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

README.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ for await (const event of client.readEvents('/books/42', {
170170

171171
If you need to abort reading use `break` or `return` within the `await for` loop. However, this only works if there is currently an iteration going on.
172172

173-
To abort reading independently of that, hand over an abort signal as third parameter when calling `readEvents`, and abort the appropriate `AbortController`:
173+
To abort reading independently of that, hand over an abort signal as third argument when calling `readEvents`, and abort the appropriate `AbortController`:
174174

175175
```typescript
176176
const controller = new AbortController();
@@ -254,7 +254,7 @@ for await (const event of client.observeEvents('/books/42', {
254254

255255
If you need to abort observing use `break` or `return` within the `await for` loop. However, this only works if there is currently an iteration going on.
256256

257-
To abort observing independently of that, hand over an abort signal as third parameter when calling `observeEvents`, and abort the appropriate `AbortController`:
257+
To abort observing independently of that, hand over an abort signal as third argument when calling `observeEvents`, and abort the appropriate `AbortController`:
258258

259259
```typescript
260260
const controller = new AbortController();
@@ -269,3 +269,90 @@ for await (const event of client.observeEvents('/books/42', {
269269
// observing to end.
270270
controller.abort();
271271
```
272+
273+
### Registering an Event Schema
274+
275+
To register an event schema, call the `registerEventSchema` function and hand over an event type and the desired schema:
276+
277+
```typescript
278+
await client.registerEventSchema('io.eventsourcingdb.library.book-acquired', {
279+
type: 'object',
280+
properties: {
281+
title: { type: 'string' },
282+
author: { type: 'string' },
283+
isbn: { type: 'string' }
284+
},
285+
required: [
286+
'title',
287+
'author',
288+
'isbn'
289+
],
290+
additionalProperties: false
291+
});
292+
```
293+
294+
### Listing Subjects
295+
296+
To list all subjects, call the `readSubjects` function with `/` as the base subject. The function returns an asynchronous iterator, which you can use e.g. inside a `for await` loop:
297+
298+
```typescript
299+
for await (const subject of client.readSubjects('/')) {
300+
// ...
301+
}
302+
```
303+
304+
If you only want to list subjects within a specific branch, provide the desired base subject instead:
305+
306+
```typescript
307+
for await (const subject of client.readSubjects('/books')) {
308+
// ...
309+
}
310+
```
311+
312+
#### Aborting Listing
313+
314+
If you need to abort listing use `break` or `return` within the `await for` loop. However, this only works if there is currently an iteration going on.
315+
316+
To abort listing independently of that, hand over an abort signal as second argument when calling `readSubjects`, and abort the appropriate `AbortController`:
317+
318+
```typescript
319+
const controller = new AbortController();
320+
321+
for await (const subject of client.readSubjects(
322+
'/', controller.signal)
323+
) {
324+
// ...
325+
}
326+
327+
// Somewhere else, abort the controller, which will cause
328+
// reading to end.
329+
controller.abort();
330+
```
331+
332+
### Listing Event Types
333+
334+
To list all event types, call the `readEventTypes` function. The function returns an asynchronous iterator, which you can use e.g. inside a `for await` loop:
335+
336+
```typescript
337+
for await (const eventType of client.readEventTypes()) {
338+
// ...
339+
}
340+
```
341+
342+
#### Aborting Listing
343+
344+
If you need to abort listing use `break` or `return` within the `await for` loop. However, this only works if there is currently an iteration going on.
345+
346+
To abort listing independently of that, hand over an abort signal as argument when calling `readEventTypes`, and abort the appropriate `AbortController`:
347+
348+
```typescript
349+
const controller = new AbortController();
350+
351+
for await (const eventType of client.readEventTypes()) {
352+
// ...
353+
}
354+
355+
// Somewhere else, abort the controller, which will cause
356+
// reading to end.
357+
controller.abort();
358+
```

0 commit comments

Comments
 (0)