Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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