From c3d98d5bdf68e52ffdeba31e994580ae677a6879 Mon Sep 17 00:00:00 2001 From: Yacine Date: Sun, 8 Dec 2024 15:53:50 +0100 Subject: [PATCH] doc: export return type for syncShapeToTable (#452) * doc: export return type for syncShapeToTable * feat: expose stream object as of for useShape hook * Changeset --------- Co-authored-by: Sam Willis --- .changeset/poor-cheetahs-beg.md | 5 +++++ packages/pglite-sync/src/index.ts | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/poor-cheetahs-beg.md diff --git a/.changeset/poor-cheetahs-beg.md b/.changeset/poor-cheetahs-beg.md new file mode 100644 index 000000000..bc59a5f3e --- /dev/null +++ b/.changeset/poor-cheetahs-beg.md @@ -0,0 +1,5 @@ +--- +'@electric-sql/pglite-sync': patch +--- + +Export return type of `syncShapeToTable` diff --git a/packages/pglite-sync/src/index.ts b/packages/pglite-sync/src/index.ts index 8c9b27d49..8d88fe7f5 100644 --- a/packages/pglite-sync/src/index.ts +++ b/packages/pglite-sync/src/index.ts @@ -4,6 +4,7 @@ import { ShapeStream, isChangeMessage, isControlMessage, + ShapeStreamInterface, } from '@electric-sql/client' import type { Extension, @@ -30,6 +31,14 @@ export interface SyncShapeToTableOptions { useCopy?: boolean } +export interface SyncShapeToTableResult { + unsubscribe: () => void + readonly isUpToDate: boolean + readonly shapeId: string + subscribe: (cb: () => void, error: (err: Error) => void) => () => void + stream: ShapeStreamInterface +} + export interface ElectricSyncOptions { debug?: boolean metadataSchema?: string @@ -52,7 +61,9 @@ async function createPlugin( const shapePerTableLock = new Map() const namespaceObj = { - syncShapeToTable: async (options: SyncShapeToTableOptions) => { + syncShapeToTable: async ( + options: SyncShapeToTableOptions, + ): Promise => { if (shapePerTableLock.has(options.table)) { throw new Error('Already syncing shape for table ' + options.table) } @@ -240,6 +251,7 @@ async function createPlugin( get shapeId() { return stream.shapeHandle }, + stream, subscribe: (cb: () => void, error: (err: Error) => void) => { return stream.subscribe(() => { if (stream.isUpToDate) {