diff --git a/.changeset/young-bikes-battle.md b/.changeset/young-bikes-battle.md new file mode 100644 index 00000000..d0924df9 --- /dev/null +++ b/.changeset/young-bikes-battle.md @@ -0,0 +1,5 @@ +--- +'@electric-sql/pglite-sync': patch +--- + +Bump the version of the Electric sync client diff --git a/docs/docs/sync.md b/docs/docs/sync.md index b6ed0a6f..3462fe62 100644 --- a/docs/docs/sync.md +++ b/docs/docs/sync.md @@ -38,7 +38,12 @@ You can then use the `syncShapeToTable` method to sync a table from Electric: ```ts const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { + table: 'todo', + }, + }, table: 'todo', primaryKey: ['id'], }) @@ -69,7 +74,7 @@ The `syncShapeToTable` is a relatively thin wrapper around the Electric [ShapeSt It takes the following options as an object: - `shape: ShapeStreamOptions`
- The shape stream specification to sync, described by [`ShapeStreamOptions`](#shapestreamoptions). + The shape stream specification to sync, described by the Electric [ShapeStream API](https://electric-sql.com/docs/api/clients/typescript#shapestream) options, see the [ShapeStream API](https://electric-sql.com/docs/api/clients/typescript#options) for more details. - `table: string`
The name of the table to sync into. @@ -100,40 +105,11 @@ The returned `shape` object from the `syncShapeToTable` call has the following m - `subscribe(cb: () => void, error: (err: FetchError | Error) => void)`
A callback to indicate that the shape caught up to the main Postgres. -- `subscribeMustRefresh(cb: () => void)`
- A callback that is called when the stream emits a `must-refresh` message. - -- `unsubscribeMustRefresh(cb: () => void)`
- Unsubscribe from the `mustRefresh` notification. - - `unsubscribe()`
Unsubscribe from the shape. Note that this does not clear the state that has been synced into the table. -### `ShapeStreamOptions` - -- `url: string`
- The full URL to where the Shape is hosted. This can either be the Electric server directly, or a proxy. E.g. for a local Electric instance, you might set `http://localhost:3000/v1/shape` - -- `table: string`
- The name of the table in the remote database to sync from - -- `where?: string`
- Where clauses for the shape. - -- `offset?: Offset`
- The "offset" on the shape log. This is typically not set as the ShapeStream will handle this automatically. A common scenario where you might pass an offset is if you're maintaining a local cache of the log. If you've gone offline and are re-starting a ShapeStream to catch-up to the latest state of the Shape, you'd pass in the last offset and shapeId you'd seen from the Electric server so it knows at what point in the shape to catch you up from. - -- `shapeId?: string`
- The server side `shapeId`, similar to `offset`, this isn't typically used unless you're maintaining a cache of the shape log. - -- `backoffOptions`
- Options to configure the backoff rules on failure - -- `subscribe?: boolean`
- Automatically fetch updates to the Shape. If you just want to sync the current shape and stop, pass false. - -- `signal?: AbortSignal`
- A `AbortSignal` instance to use to abort the sync. +- `stream: ShapeStream`
+ The underlying `ShapeStream` instance, see the [ShapeStream API](https://electric-sql.com/docs/api/clients/typescript#shapestream) for more details. ## Limitations diff --git a/packages/pglite-sync/package.json b/packages/pglite-sync/package.json index af232ca9..3af9beaf 100644 --- a/packages/pglite-sync/package.json +++ b/packages/pglite-sync/package.json @@ -45,7 +45,7 @@ "dist" ], "dependencies": { - "@electric-sql/client": "~0.8.0" + "@electric-sql/client": "~0.9.0" }, "devDependencies": { "@electric-sql/pglite": "workspace:*", diff --git a/packages/pglite-sync/test/sync.test.ts b/packages/pglite-sync/test/sync.test.ts index 32d8f3f7..2f03baa5 100644 --- a/packages/pglite-sync/test/sync.test.ts +++ b/packages/pglite-sync/test/sync.test.ts @@ -52,7 +52,10 @@ describe('pglite-sync', () => { })) const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], }) @@ -121,7 +124,10 @@ describe('pglite-sync', () => { })) const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], }) @@ -201,7 +207,10 @@ describe('pglite-sync', () => { const numResumes = 3 for (let i = 0; i < numResumes; i++) { const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], shapeKey: 'foo', @@ -270,7 +279,10 @@ describe('pglite-sync', () => { const numInserts = 100 const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], shapeKey: 'foo', @@ -334,7 +346,10 @@ describe('pglite-sync', () => { // resuming should const resumedShape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], shapeKey: 'foo', @@ -375,7 +390,10 @@ describe('pglite-sync', () => { const altTable = 'bar' const shape1 = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: table, primaryKey: ['id'], }) @@ -384,7 +402,10 @@ describe('pglite-sync', () => { await expect( async () => await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo_alt' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo_alt' }, + }, table: table, primaryKey: ['id'], }), @@ -392,7 +413,10 @@ describe('pglite-sync', () => { // should be able to sync shape into other table const altShape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'bar' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'bar' }, + }, table: altTable, primaryKey: ['id'], }) @@ -403,7 +427,10 @@ describe('pglite-sync', () => { shape1.unsubscribe() const shape2 = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo_alt' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo_alt' }, + }, table: table, primaryKey: ['id'], }) @@ -420,7 +447,10 @@ describe('pglite-sync', () => { })) const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], }) @@ -506,7 +536,10 @@ describe('pglite-sync', () => { expect(result0.rows[0]).toEqual({ current_setting: 'false' }) const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'test_syncing' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'test_syncing' }, + }, table: 'test_syncing', primaryKey: ['id'], }) @@ -548,7 +581,10 @@ describe('pglite-sync', () => { })) const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], useCopy: true, @@ -624,7 +660,10 @@ describe('pglite-sync', () => { })) const shape = await pg.electric.syncShapeToTable({ - shape: { url: 'http://localhost:3000/v1/shape', table: 'todo' }, + shape: { + url: 'http://localhost:3000/v1/shape', + params: { table: 'todo' }, + }, table: 'todo', primaryKey: ['id'], useCopy: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d4003370..8fe4984d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -249,8 +249,8 @@ importers: packages/pglite-sync: dependencies: '@electric-sql/client': - specifier: ~0.8.0 - version: 0.8.0 + specifier: ~0.9.0 + version: 0.9.0 devDependencies: '@electric-sql/pglite': specifier: workspace:* @@ -636,8 +636,8 @@ packages: search-insights: optional: true - '@electric-sql/client@0.8.0': - resolution: {integrity: sha512-M4VnuL2q2i1yhsjc9DEQtf4GEkXoaMjlfm0Lq7KqLDjj2nqPhbUTo8IeWhf3OJSZ7j+GyFd/YlLg4rlBDrE/6Q==} + '@electric-sql/client@0.9.0': + resolution: {integrity: sha512-UL2Gep9wPdGMTE0oEWVi0HA8R293R2OzFfHeAsN2LABYYl/boXss7nseNEiIV5+RjHPH7Tm8NsjH9iJW2rZkrQ==} '@embedded-postgres/darwin-arm64@15.5.1-beta.11': resolution: {integrity: sha512-5m96qe7TFR/wzL05fyl1TRKfm+I73gIdDea+vXh60MQzUUfX9FXSiR8id6TI4aRhomUrd/l8hLTq8E2ymTCIFw==} @@ -1886,6 +1886,7 @@ packages: bun@1.1.30: resolution: {integrity: sha512-ysRL1pq10Xba0jqVLPrKU3YIv0ohfp3cTajCPtpjCyppbn3lfiAVNpGoHfyaxS17OlPmWmR67UZRPw/EueQuug==} + cpu: [arm64, x64] os: [darwin, linux, win32] hasBin: true @@ -4783,7 +4784,7 @@ snapshots: transitivePeerDependencies: - '@algolia/client-search' - '@electric-sql/client@0.8.0': + '@electric-sql/client@0.9.0': optionalDependencies: '@rollup/rollup-darwin-arm64': 4.24.0