Skip to content

Commit

Permalink
doc: export return type for syncShapeToTable (#452)
Browse files Browse the repository at this point in the history
* doc: export return type for syncShapeToTable

* feat: expose stream object as of for useShape hook

* Changeset

---------

Co-authored-by: Sam Willis <[email protected]>
  • Loading branch information
yacineb and samwillis authored Dec 8, 2024
1 parent bfddaaa commit c3d98d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/poor-cheetahs-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite-sync': patch
---

Export return type of `syncShapeToTable`
14 changes: 13 additions & 1 deletion packages/pglite-sync/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ShapeStream,
isChangeMessage,
isControlMessage,
ShapeStreamInterface,
} from '@electric-sql/client'
import type {
Extension,
Expand All @@ -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
Expand All @@ -52,7 +61,9 @@ async function createPlugin(
const shapePerTableLock = new Map<string, void>()

const namespaceObj = {
syncShapeToTable: async (options: SyncShapeToTableOptions) => {
syncShapeToTable: async (
options: SyncShapeToTableOptions,
): Promise<SyncShapeToTableResult> => {
if (shapePerTableLock.has(options.table)) {
throw new Error('Already syncing shape for table ' + options.table)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c3d98d5

Please sign in to comment.