Skip to content

Commit 6616b81

Browse files
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

10 files changed

+1094
-24
lines changed

.changeset/old-tigers-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@electric-sql/client": patch
3+
---
4+
5+
Correctly set the cache busting url param when using `forceDisconnectAndRefresh`

.changeset/serious-clouds-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@electric-sql/experimental": patch
3+
---
4+
5+
New experimental MultiShapeStream and TransactionalMultiShapeStream APIs that combine multiple shapes streams into a single stream. Note: these two APIs are experimental and are likely to change in a future version of the package.

packages/experimental/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
"bugs": {
77
"url": "https://github.com/electric-sql/electric/issues"
88
},
9-
"dependencies": {
10-
"@electric-sql/client": "workspace:*"
11-
},
129
"devDependencies": {
10+
"@electric-sql/client": "workspace:*",
1311
"@types/pg": "^8.11.6",
1412
"@types/uuid": "^10.0.0",
1513
"@typescript-eslint/eslint-plugin": "^7.14.1",
@@ -27,6 +25,14 @@
2725
"uuid": "^10.0.0",
2826
"vitest": "^2.0.2"
2927
},
28+
"peerDependencies": {
29+
"@electric-sql/client": "workspace:*"
30+
},
31+
"peerDependenciesMeta": {
32+
"@electric-sql/client": {
33+
"optional": false
34+
}
35+
},
3036
"exports": {
3137
"./package.json": "./package.json",
3238
".": {

packages/experimental/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './match'
2+
export * from './multi-shape-stream'

0 commit comments

Comments
 (0)