Skip to content

Commit

Permalink
fix(@electric-sql/client): The table option isn't required as a team …
Browse files Browse the repository at this point in the history
…using a proxy API might set the table there (#1932)
  • Loading branch information
KyleAMathews authored Nov 6, 2024
1 parent d34cb7e commit b367c8d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-buttons-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@electric-sql/client": patch
"@core/sync-service": patch
---

Make the client table option _not_ required as a team using a proxy API might set the table there.
9 changes: 3 additions & 6 deletions packages/typescript-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export interface ShapeStreamOptions<T = never> {
databaseId?: string

/**
* The root table for the shape.
* The root table for the shape. Passed as a query parameter. Not required if you set the table in your proxy.
*/
table: string
table?: string

/**
* The where clauses for the shape.
Expand Down Expand Up @@ -246,7 +246,7 @@ export class ShapeStream<T extends Row<unknown> = Row>
this.options.subscribe
) {
const fetchUrl = new URL(url)
fetchUrl.searchParams.set(TABLE_QUERY_PARAM, table)
if (table) fetchUrl.searchParams.set(TABLE_QUERY_PARAM, table)
if (where) fetchUrl.searchParams.set(WHERE_QUERY_PARAM, where)
if (columns && columns.length > 0)
fetchUrl.searchParams.set(COLUMNS_QUERY_PARAM, columns.join(`,`))
Expand Down Expand Up @@ -465,9 +465,6 @@ function validateOptions<T>(options: Partial<ShapeStreamOptions<T>>): void {
if (!options.url) {
throw new Error(`Invalid shape options. It must provide the url`)
}
if (!options.table) {
throw new Error(`Invalid shape options. It must provide the table`)
}
if (options.signal && !(options.signal instanceof AbortSignal)) {
throw new Error(
`Invalid signal option. It must be an instance of AbortSignal.`
Expand Down
4 changes: 2 additions & 2 deletions website/docs/api/clients/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export interface ShapeStreamOptions<T = never> {
databaseId?: string

/**
* The root table for the shape.
* The root table for the shape. Passed as a query parameter. Not required if you set the table in your proxy.
*/
table: string
table?: string

/**
* The where clauses for the shape.
Expand Down

0 comments on commit b367c8d

Please sign in to comment.