@electric-sql/client
Advanced tools
Comparing version
@@ -199,2 +199,4 @@ var __defProp = Object.defineProperty; | ||
var SHAPE_ID_HEADER = `electric-shape-id`; | ||
var LIVE_CACHE_BUSTER_HEADER = `electric-next-cursor`; | ||
var LIVE_CACHE_BUSTER_QUERY_PARAM = `cursor`; | ||
var CHUNK_LAST_OFFSET_HEADER = `electric-chunk-last-offset`; | ||
@@ -209,2 +211,3 @@ var CHUNK_UP_TO_DATE_HEADER = `electric-chunk-up-to-date`; | ||
// src/fetch.ts | ||
var HTTP_RETRY_STATUS_CODES = [429]; | ||
var BackoffDefaults = { | ||
@@ -238,3 +241,3 @@ initialDelay: 100, | ||
throw new FetchBackoffAbortError(); | ||
} else if (e instanceof FetchError && e.status >= 400 && e.status < 500) { | ||
} else if (e instanceof FetchError && !HTTP_RETRY_STATUS_CODES.includes(e.status) && e.status >= 400 && e.status < 500) { | ||
throw e; | ||
@@ -365,3 +368,3 @@ } else { | ||
// src/client.ts | ||
var _fetchClient2, _messageParser, _subscribers, _upToDateSubscribers, _lastOffset, _lastSyncedAt, _isUpToDate, _connected, _shapeId, _schema, _ShapeStream_instances, publish_fn, sendErrorToSubscribers_fn, notifyUpToDateSubscribers_fn, sendErrorToUpToDateSubscribers_fn, reset_fn; | ||
var _fetchClient2, _messageParser, _subscribers, _upToDateSubscribers, _lastOffset, _liveCacheBuster, _lastSyncedAt, _isUpToDate, _connected, _shapeId, _schema, _ShapeStream_instances, publish_fn, sendErrorToSubscribers_fn, notifyUpToDateSubscribers_fn, sendErrorToUpToDateSubscribers_fn, reset_fn; | ||
var ShapeStream = class { | ||
@@ -375,2 +378,4 @@ constructor(options) { | ||
__privateAdd(this, _lastOffset); | ||
__privateAdd(this, _liveCacheBuster); | ||
// Seconds since our Electric Epoch 😎 | ||
__privateAdd(this, _lastSyncedAt); | ||
@@ -386,2 +391,3 @@ // unix time | ||
__privateSet(this, _lastOffset, (_a = this.options.offset) != null ? _a : `-1`); | ||
__privateSet(this, _liveCacheBuster, ``); | ||
__privateSet(this, _shapeId, this.options.shapeId); | ||
@@ -417,2 +423,6 @@ __privateSet(this, _messageParser, new MessageParser(options.parser)); | ||
fetchUrl.searchParams.set(LIVE_QUERY_PARAM, `true`); | ||
fetchUrl.searchParams.set( | ||
LIVE_CACHE_BUSTER_QUERY_PARAM, | ||
__privateGet(this, _liveCacheBuster) | ||
); | ||
} | ||
@@ -456,2 +466,6 @@ if (__privateGet(this, _shapeId)) { | ||
} | ||
const liveCacheBuster = headers.get(LIVE_CACHE_BUSTER_HEADER); | ||
if (liveCacheBuster) { | ||
__privateSet(this, _liveCacheBuster, liveCacheBuster); | ||
} | ||
const getSchema = () => { | ||
@@ -527,2 +541,3 @@ const schemaHeader = headers.get(SHAPE_SCHEMA_HEADER); | ||
_lastOffset = new WeakMap(); | ||
_liveCacheBuster = new WeakMap(); | ||
_lastSyncedAt = new WeakMap(); | ||
@@ -568,2 +583,3 @@ _isUpToDate = new WeakMap(); | ||
__privateSet(this, _lastOffset, `-1`); | ||
__privateSet(this, _liveCacheBuster, ``); | ||
__privateSet(this, _shapeId, shapeId); | ||
@@ -570,0 +586,0 @@ __privateSet(this, _isUpToDate, false); |
{ | ||
"name": "@electric-sql/client", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Postgres everywhere - your data, in sync, wherever you need it.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -20,2 +20,4 @@ import { | ||
CHUNK_LAST_OFFSET_HEADER, | ||
LIVE_CACHE_BUSTER_HEADER, | ||
LIVE_CACHE_BUSTER_QUERY_PARAM, | ||
LIVE_QUERY_PARAM, | ||
@@ -147,2 +149,3 @@ OFFSET_QUERY_PARAM, | ||
#lastOffset: Offset | ||
#liveCacheBuster: string // Seconds since our Electric Epoch 😎 | ||
#lastSyncedAt?: number // unix time | ||
@@ -158,2 +161,3 @@ #isUpToDate: boolean = false | ||
this.#lastOffset = this.options.offset ?? `-1` | ||
this.#liveCacheBuster = `` | ||
this.#shapeId = this.options.shapeId | ||
@@ -203,2 +207,6 @@ this.#messageParser = new MessageParser<T>(options.parser) | ||
fetchUrl.searchParams.set(LIVE_QUERY_PARAM, `true`) | ||
fetchUrl.searchParams.set( | ||
LIVE_CACHE_BUSTER_QUERY_PARAM, | ||
this.#liveCacheBuster | ||
) | ||
} | ||
@@ -255,2 +263,7 @@ | ||
const liveCacheBuster = headers.get(LIVE_CACHE_BUSTER_HEADER) | ||
if (liveCacheBuster) { | ||
this.#liveCacheBuster = liveCacheBuster | ||
} | ||
const getSchema = (): Schema => { | ||
@@ -384,2 +397,3 @@ const schemaHeader = headers.get(SHAPE_SCHEMA_HEADER) | ||
this.#lastOffset = `-1` | ||
this.#liveCacheBuster = `` | ||
this.#shapeId = shapeId | ||
@@ -386,0 +400,0 @@ this.#isUpToDate = false |
export const SHAPE_ID_HEADER = `electric-shape-id` | ||
export const LIVE_CACHE_BUSTER_HEADER = `electric-next-cursor` | ||
export const LIVE_CACHE_BUSTER_QUERY_PARAM = `cursor` | ||
export const CHUNK_LAST_OFFSET_HEADER = `electric-chunk-last-offset` | ||
@@ -3,0 +5,0 @@ export const CHUNK_UP_TO_DATE_HEADER = `electric-chunk-up-to-date` |
@@ -11,2 +11,6 @@ import { | ||
// Some specific 4xx and 5xx HTTP status codes that we definitely | ||
// want to retry | ||
const HTTP_RETRY_STATUS_CODES = [429] | ||
export interface BackoffOptions { | ||
@@ -67,2 +71,3 @@ /** | ||
e instanceof FetchError && | ||
!HTTP_RETRY_STATUS_CODES.includes(e.status) && | ||
e.status >= 400 && | ||
@@ -69,0 +74,0 @@ e.status < 500 |
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
360862
2.18%3786
1.8%