eventsourcingdb 0.10.5 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -170,7 +170,7 @@ for await (const event of client.readEvents('/books/42', {
|
|
|
170
170
|
|
|
171
171
|
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.
|
|
172
172
|
|
|
173
|
-
To abort reading independently of that, hand over an abort signal as third
|
|
173
|
+
To abort reading independently of that, hand over an abort signal as third argument when calling `readEvents`, and abort the appropriate `AbortController`:
|
|
174
174
|
|
|
175
175
|
```typescript
|
|
176
176
|
const controller = new AbortController();
|
|
@@ -254,7 +254,7 @@ for await (const event of client.observeEvents('/books/42', {
|
|
|
254
254
|
|
|
255
255
|
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.
|
|
256
256
|
|
|
257
|
-
To abort observing independently of that, hand over an abort signal as third
|
|
257
|
+
To abort observing independently of that, hand over an abort signal as third argument when calling `observeEvents`, and abort the appropriate `AbortController`:
|
|
258
258
|
|
|
259
259
|
```typescript
|
|
260
260
|
const controller = new AbortController();
|
|
@@ -269,3 +269,90 @@ for await (const event of client.observeEvents('/books/42', {
|
|
|
269
269
|
// observing to end.
|
|
270
270
|
controller.abort();
|
|
271
271
|
```
|
|
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
|
+
```
|