Commit 6616b81
authored
feat(experimental): MultiShapeStream and TransactionalMultiShapeStream APIs (#2356)
This adds two new APIs to the @electric-sql/experimental package:
## `MultiShapeStream`
A multi-shape stream is a stream that can subscribe to multiple shapes.
It ensures that all shapes will receive at least an `up-to-date` message
from Electric within the `checkForUpdatesAfter` interval.
The emitted messages have an additional `shape` prop that is the name of
the shape provided in the shapes object when constructing the
`MultiShapeStream`.
```ts
const multiShapeStream = new MultiShapeStream({
shapes: {
shape1: {
url: 'http://localhost:3000/v1/shape1',
},
shape2: {
url: 'http://localhost:3000/v1/shape2',
},
},
})
multiShapeStream.subscribe((msgs) => {
console.log(msgs)
})
// or with ShapeStream instances
const multiShapeStream = new MultiShapeStream({
shapes: {
shape1: new ShapeStream({ url: 'http://localhost:3000/v1/shape1' }),
shape2: new ShapeStream({ url: 'http://localhost:3000/v1/shape2' }),
},
})
```
## `TransactionalMultiShapeStream`
A transactional multi-shape stream is a multi-shape stream that emits
the messages in transactional batches.
It uses the `lsn` metadata to infer transaction boundaries, and the
`op_position` metadata to sort the messages within a transaction.
Note that you will only receive change massages on the main subscription
(in transactional batches), and not any control massages.
```ts
const transactionalMultiShapeStream = new TransactionalMultiShapeStream({
shapes: {
shape1: {
url: 'http://localhost:3000/v1/shape1',
},
shape2: {
url: 'http://localhost:3000/v1/shape2',
},
},
})
transactionalMultiShapeStream.subscribe((msgs) => {
console.log(msgs)
})
// or with ShapeStream instances
const transactionalMultiShapeStream = new TransactionalMultiShapeStream({
shapes: {
shape1: new ShapeStream({ url: 'http://localhost:3000/v1/shape1' }),
shape2: new ShapeStream({ url: 'http://localhost:3000/v1/shape2' }),
},
})
```1 parent 5da8f25 commit 6616b81
File tree
10 files changed
+1094
-24
lines changed- .changeset
- packages
- experimental
- src
- test
- support
- typescript-client/src
10 files changed
+1094
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 9 | | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
0 commit comments