@electric-sql/client 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/client.ts CHANGED
@@ -31,6 +31,18 @@ import {
31
31
  REPLICA_PARAM,
32
32
  } from './constants'
33
33
 
34
+ const RESERVED_PARAMS = new Set([
35
+ DATABASE_ID_QUERY_PARAM,
36
+ COLUMNS_QUERY_PARAM,
37
+ LIVE_CACHE_BUSTER_QUERY_PARAM,
38
+ SHAPE_HANDLE_QUERY_PARAM,
39
+ LIVE_QUERY_PARAM,
40
+ OFFSET_QUERY_PARAM,
41
+ TABLE_QUERY_PARAM,
42
+ WHERE_QUERY_PARAM,
43
+ REPLICA_PARAM,
44
+ ])
45
+
34
46
  type Replica = `full` | `default`
35
47
 
36
48
  /**
@@ -98,6 +110,12 @@ export interface ShapeStreamOptions<T = never> {
98
110
  */
99
111
  headers?: Record<string, string>
100
112
 
113
+ /**
114
+ * Additional request parameters to attach to the URL.
115
+ * These will be merged with Electric's standard parameters.
116
+ */
117
+ params?: Record<string, string>
118
+
101
119
  /**
102
120
  * Automatically fetch updates to the Shape. If you just want to sync the current
103
121
  * shape and stop, pass false.
@@ -246,6 +264,25 @@ export class ShapeStream<T extends Row<unknown> = Row>
246
264
  this.options.subscribe
247
265
  ) {
248
266
  const fetchUrl = new URL(url)
267
+
268
+ // Add any custom parameters first
269
+ if (this.options.params) {
270
+ // Check for reserved parameter names
271
+ const reservedParams = Object.keys(this.options.params).filter(
272
+ (key) => RESERVED_PARAMS.has(key)
273
+ )
274
+ if (reservedParams.length > 0) {
275
+ throw new Error(
276
+ `Cannot use reserved Electric parameter names in custom params: ${reservedParams.join(`, `)}`
277
+ )
278
+ }
279
+
280
+ for (const [key, value] of Object.entries(this.options.params)) {
281
+ fetchUrl.searchParams.set(key, value)
282
+ }
283
+ }
284
+
285
+ // Add Electric's internal parameters
249
286
  if (table) fetchUrl.searchParams.set(TABLE_QUERY_PARAM, table)
250
287
  if (where) fetchUrl.searchParams.set(WHERE_QUERY_PARAM, where)
251
288
  if (columns && columns.length > 0)