@electric-sql/client
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -180,2 +180,7 @@ /** | ||
/** | ||
* Additional request parameters to attach to the URL. | ||
* These will be merged with Electric's standard parameters. | ||
*/ | ||
params?: Record<string, string>; | ||
/** | ||
* Automatically fetch updates to the Shape. If you just want to sync the current | ||
@@ -182,0 +187,0 @@ * shape and stop, pass false. |
@@ -372,2 +372,13 @@ var __defProp = Object.defineProperty; | ||
// src/client.ts | ||
var RESERVED_PARAMS = /* @__PURE__ */ new Set([ | ||
DATABASE_ID_QUERY_PARAM, | ||
COLUMNS_QUERY_PARAM, | ||
LIVE_CACHE_BUSTER_QUERY_PARAM, | ||
SHAPE_HANDLE_QUERY_PARAM, | ||
LIVE_QUERY_PARAM, | ||
OFFSET_QUERY_PARAM, | ||
TABLE_QUERY_PARAM, | ||
WHERE_QUERY_PARAM, | ||
REPLICA_PARAM | ||
]); | ||
var _fetchClient2, _messageParser, _subscribers, _upToDateSubscribers, _lastOffset, _liveCacheBuster, _lastSyncedAt, _isUpToDate, _connected, _shapeHandle, _databaseId, _schema, _error, _replica, _ShapeStream_instances, publish_fn, sendErrorToSubscribers_fn, notifyUpToDateSubscribers_fn, sendErrorToUpToDateSubscribers_fn, reset_fn; | ||
@@ -429,2 +440,15 @@ var _ShapeStream = class _ShapeStream { | ||
const fetchUrl = new URL(url); | ||
if (this.options.params) { | ||
const reservedParams = Object.keys(this.options.params).filter( | ||
(key) => RESERVED_PARAMS.has(key) | ||
); | ||
if (reservedParams.length > 0) { | ||
throw new Error( | ||
`Cannot use reserved Electric parameter names in custom params: ${reservedParams.join(`, `)}` | ||
); | ||
} | ||
for (const [key, value] of Object.entries(this.options.params)) { | ||
fetchUrl.searchParams.set(key, value); | ||
} | ||
} | ||
if (table) fetchUrl.searchParams.set(TABLE_QUERY_PARAM, table); | ||
@@ -431,0 +455,0 @@ if (where) fetchUrl.searchParams.set(WHERE_QUERY_PARAM, where); |
{ | ||
"name": "@electric-sql/client", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "Postgres everywhere - your data, in sync, wherever you need it.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -57,2 +57,14 @@ <p align="center"> | ||
// You can also add custom headers and URL parameters | ||
const streamWithParams = new ShapeStream({ | ||
url: `${BASE_URL}/v1/shape`, | ||
table: `foo`, | ||
headers: { | ||
'Authorization': 'Bearer token' | ||
}, | ||
params: { | ||
'custom-param': 'value' | ||
} | ||
}) | ||
stream.subscribe(messages => { | ||
@@ -59,0 +71,0 @@ // messages is an array with one or more row updates |
@@ -34,2 +34,14 @@ import { | ||
const RESERVED_PARAMS = new Set([ | ||
DATABASE_ID_QUERY_PARAM, | ||
COLUMNS_QUERY_PARAM, | ||
LIVE_CACHE_BUSTER_QUERY_PARAM, | ||
SHAPE_HANDLE_QUERY_PARAM, | ||
LIVE_QUERY_PARAM, | ||
OFFSET_QUERY_PARAM, | ||
TABLE_QUERY_PARAM, | ||
WHERE_QUERY_PARAM, | ||
REPLICA_PARAM, | ||
]) | ||
type Replica = `full` | `default` | ||
@@ -103,2 +115,8 @@ | ||
/** | ||
* Additional request parameters to attach to the URL. | ||
* These will be merged with Electric's standard parameters. | ||
*/ | ||
params?: Record<string, string> | ||
/** | ||
* Automatically fetch updates to the Shape. If you just want to sync the current | ||
@@ -251,2 +269,21 @@ * shape and stop, pass false. | ||
const fetchUrl = new URL(url) | ||
// Add any custom parameters first | ||
if (this.options.params) { | ||
// Check for reserved parameter names | ||
const reservedParams = Object.keys(this.options.params).filter( | ||
(key) => RESERVED_PARAMS.has(key) | ||
) | ||
if (reservedParams.length > 0) { | ||
throw new Error( | ||
`Cannot use reserved Electric parameter names in custom params: ${reservedParams.join(`, `)}` | ||
) | ||
} | ||
for (const [key, value] of Object.entries(this.options.params)) { | ||
fetchUrl.searchParams.set(key, value) | ||
} | ||
} | ||
// Add Electric's internal parameters | ||
if (table) fetchUrl.searchParams.set(TABLE_QUERY_PARAM, table) | ||
@@ -253,0 +290,0 @@ if (where) fetchUrl.searchParams.set(WHERE_QUERY_PARAM, where) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
393332
4127
97