@dvina/sdk 4.0.248 → 4.0.251

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.
@@ -8406,15 +8406,19 @@ function createSseTransport(options) {
8406
8406
  }
8407
8407
  return;
8408
8408
  }
8409
- if (!eventId) {
8410
- return;
8411
- }
8412
- currentLastSyncId = eventId;
8413
8409
  if (eventType === "cursor") {
8410
+ if (!eventId) {
8411
+ return;
8412
+ }
8413
+ currentLastSyncId = eventId;
8414
8414
  options.onCursor?.(eventId);
8415
8415
  return;
8416
8416
  }
8417
8417
  if (eventType === "sync" && eventData) {
8418
+ if (!eventId) {
8419
+ return;
8420
+ }
8421
+ currentLastSyncId = eventId;
8418
8422
  try {
8419
8423
  const parsed = JSON.parse(eventData);
8420
8424
  options.onEvent({
@@ -9096,13 +9100,35 @@ var CacheManager = class {
9096
9100
  const freshness = await this._db._sync.get(getQueryFreshnessKey(queryKey));
9097
9101
  return typeof freshness?.value === "number" ? freshness.value : fallback?.fetchedAt;
9098
9102
  }
9103
+ async getQuerySyncId(queryKey) {
9104
+ const entry = await this._db._queryResults.get(queryKey);
9105
+ return entry?.querySyncId;
9106
+ }
9107
+ async setQuerySyncId(queryKey, querySyncId) {
9108
+ const entry = await this._db._queryResults.get(queryKey);
9109
+ if (!entry || entry.querySyncId === querySyncId) {
9110
+ return;
9111
+ }
9112
+ entry.querySyncId = querySyncId;
9113
+ await this._db._queryResults.put(entry);
9114
+ }
9099
9115
  /**
9100
9116
  * Write connection metadata to the `_queryResults` table.
9101
9117
  */
9102
- async writeQueryResult(queryKey, connection) {
9118
+ async writeQueryResult(queryKey, connection, options) {
9103
9119
  const fetchedAt = Date.now();
9104
9120
  const existing = await this._db._queryResults.get(queryKey);
9121
+ const nextQuerySyncId = options?.querySyncId ?? existing?.querySyncId;
9105
9122
  if (existing && hasSameQueryResultContents(existing, connection)) {
9123
+ if (existing.querySyncId !== nextQuerySyncId) {
9124
+ existing.querySyncId = nextQuerySyncId;
9125
+ existing.fetchedAt = fetchedAt;
9126
+ await this._db.transaction("rw", [this._db._queryResults, this._db._sync], async () => {
9127
+ await this._db._queryResults.put(existing);
9128
+ await this._touchQueryFreshness(queryKey, fetchedAt);
9129
+ });
9130
+ return;
9131
+ }
9106
9132
  await this._touchQueryFreshness(queryKey, fetchedAt);
9107
9133
  return;
9108
9134
  }
@@ -9112,6 +9138,7 @@ var CacheManager = class {
9112
9138
  entityIds: connection.entityIds,
9113
9139
  pageInfo: connection.pageInfo,
9114
9140
  totalCount: connection.totalCount,
9141
+ querySyncId: nextQuerySyncId,
9115
9142
  fetchedAt
9116
9143
  };
9117
9144
  await this._db.transaction("rw", [this._db._queryResults, this._db._sync], async () => {
@@ -9480,7 +9507,11 @@ var QueryExecutor = class {
9480
9507
  }
9481
9508
  }
9482
9509
  }
9510
+ const querySyncId = await this._db.getLastSyncId();
9483
9511
  const networkResult = await this.query(document2, variables, operationName);
9512
+ if (querySyncId !== "0") {
9513
+ await this._cache.setQuerySyncId(queryKey, querySyncId).catch(() => void 0);
9514
+ }
9484
9515
  try {
9485
9516
  const result = await buildResult(this._db);
9486
9517
  ref._markInitialized(result);
@@ -9991,7 +10022,7 @@ var SyncEngine = class {
9991
10022
  });
9992
10023
  if (this._sse) {
9993
10024
  this._subscriptionToQueryKey.set(subscriptionDescriptor.id, queryKey);
9994
- this._sse.subscribe(subscriptionDescriptor);
10025
+ void this._subscribeWithQuerySyncId(subscriptionDescriptor, queryKey);
9995
10026
  }
9996
10027
  void this._revalidateSubscriptionIfStale(subscriptionDescriptor.id);
9997
10028
  const originalDispose = ref.dispose.bind(ref);
@@ -10013,6 +10044,16 @@ var SyncEngine = class {
10013
10044
  }
10014
10045
  return ref;
10015
10046
  }
10047
+ async _subscribeWithQuerySyncId(subscriptionDescriptor, queryKey) {
10048
+ const cachedQuerySyncId = await this._cache.getQuerySyncId(queryKey).catch(() => void 0);
10049
+ if (!this._subscriptionToQueryKey.has(subscriptionDescriptor.id)) {
10050
+ return;
10051
+ }
10052
+ if (cachedQuerySyncId) {
10053
+ subscriptionDescriptor.querySyncId = cachedQuerySyncId;
10054
+ }
10055
+ this._sse?.subscribe(subscriptionDescriptor);
10056
+ }
10016
10057
  // ─── Mutate ────────────────────────────────────────────────────────────
10017
10058
  /**
10018
10059
  * Execute a mutation with optional optimistic update and automatic cache rule.
@@ -10198,7 +10239,11 @@ var SyncEngine = class {
10198
10239
  const startedAt = Date.now();
10199
10240
  this._lastRevalidatedAt.set(subscription.queryKey, startedAt);
10200
10241
  try {
10242
+ const querySyncId = await this._db.getLastSyncId();
10201
10243
  await this.query(subscription.document, subscription.variables, subscription.operationName);
10244
+ if (querySyncId !== "0") {
10245
+ await this._cache.setQuerySyncId(subscription.queryKey, querySyncId).catch(() => void 0);
10246
+ }
10202
10247
  this._clearRevalidationRetry(subscription.queryKey);
10203
10248
  } catch {
10204
10249
  this._lastRevalidatedAt.delete(subscription.queryKey);
@@ -23552,5 +23597,5 @@ exports.getOrCreateDatabase = getOrCreateDatabase;
23552
23597
  exports.reconstructConnectionNodes = reconstructConnectionNodes;
23553
23598
  exports.reconstructEntity = reconstructEntity;
23554
23599
  exports.uploadFile = uploadFile;
23555
- //# sourceMappingURL=chunk-FAENNJ6Q.cjs.map
23556
- //# sourceMappingURL=chunk-FAENNJ6Q.cjs.map
23600
+ //# sourceMappingURL=chunk-YLVE4CQ3.cjs.map
23601
+ //# sourceMappingURL=chunk-YLVE4CQ3.cjs.map