@rebasepro/client 0.27.0 → 0.28.0

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.
@@ -1,4 +1,4 @@
1
- import { a as byIdRead, c as invalidBulkBody, d as RebaseApiError$1, f as buildQueryString, g as rebaseReviver, l as SDKQueryBuilder, n as MemoryOfflineStore, r as createMutationId, s as etagOf, t as IndexedDBOfflineStore, u as RebaseClientError$1 } from "./offline-store-BhYXViha.js";
1
+ import { a as byIdRead, c as invalidBulkBody, d as RebaseApiError$1, f as buildQueryString, g as rebaseReviver, l as SDKQueryBuilder, n as MemoryOfflineStore, r as createMutationId, s as etagOf, t as IndexedDBOfflineStore, u as RebaseClientError$1 } from "./offline-store-Cxhh99Q-.js";
2
2
  import { EntityReference, EntityRelation, GeoPoint, Vector, hasFieldOperation, isUnsupported, parseRelationAggregateSort, toCanonicalOp } from "@rebasepro/types";
3
3
  import { collectAllPages, normalizeOrderBy, paginateFind, resolveFindWindow, withETag } from "@rebasepro/common";
4
4
  import { splitSearchTerms, unref } from "@rebasepro/utils";
@@ -960,6 +960,8 @@ function generateOfflineStringId() {
960
960
  *
961
961
  * Module-scoped and strictly decreasing: two temporary ids in the same session
962
962
  * must not collide, and neither must one minted a millisecond after another.
963
+ * Another tab has a module of its own, which the random part of
964
+ * {@link nextOfflineNumericId} covers.
963
965
  */
964
966
  var lastOfflineNumericId = 0;
965
967
  /**
@@ -975,11 +977,24 @@ var lastOfflineNumericId = 0;
975
977
  * reconciled it — and the SDK's own types said it could not happen.
976
978
  */
977
979
  function generateOfflineNumericId() {
978
- const candidate = -Date.now();
979
- lastOfflineNumericId = lastOfflineNumericId === 0 ? candidate : Math.min(candidate, lastOfflineNumericId - 1);
980
+ lastOfflineNumericId = nextOfflineNumericId(lastOfflineNumericId, Date.now(), Math.random());
980
981
  return lastOfflineNumericId;
981
982
  }
982
983
  /**
984
+ * The temporary numeric id after `last` (0 for none yet), at `now` with the
985
+ * random draw `random` in [0, 1).
986
+ *
987
+ * The millisecond, scaled by 1000, with three random digits under it. Tabs of
988
+ * one origin share the offline database but not the module that remembers
989
+ * `last`, so two that create in the same millisecond minted the same id from
990
+ * the millisecond alone, and one row took the other's place in the store.
991
+ * Scaled, the value stays a safe integer for another two centuries.
992
+ */
993
+ function nextOfflineNumericId(last, now, random) {
994
+ const candidate = -(now * 1e3 + Math.floor(random * 1e3));
995
+ return last === 0 ? candidate : Math.min(candidate, last - 1);
996
+ }
997
+ /**
983
998
  * The row an optimistic write puts in the cache before the server has seen it.
984
999
  *
985
1000
  * It is NOT an `M`, and saying so is the point of collecting this in one place.
@@ -3063,6 +3078,19 @@ var OfflineManager = class {
3063
3078
  if (queued.data && !Array.isArray(queued.data)) queued.data.id = serverId;
3064
3079
  dirty = true;
3065
3080
  }
3081
+ if (queued.updates?.some((u) => String(u.id) === oldKey)) {
3082
+ queued.updates = queued.updates.map((u) => String(u.id) === oldKey ? {
3083
+ id: serverId,
3084
+ data: u.data
3085
+ } : u);
3086
+ this.queueChangedInPlace();
3087
+ dirty = true;
3088
+ }
3089
+ if (queued.ids?.some((id) => String(id) === oldKey)) {
3090
+ queued.ids = queued.ids.map((id) => String(id) === oldKey ? serverId : id);
3091
+ this.queueChangedInPlace();
3092
+ dirty = true;
3093
+ }
3066
3094
  const rollbackRows = queued.rollback?.rows;
3067
3095
  if (rollbackRows && oldKey in rollbackRows) {
3068
3096
  rollbackRows[String(serverId)] = rollbackRows[oldKey];
@@ -3390,4 +3418,4 @@ var OfflineManager = class {
3390
3418
  //#endregion
3391
3419
  export { OfflineManager };
3392
3420
 
3393
- //# sourceMappingURL=offline-AvuEcg7u.js.map
3421
+ //# sourceMappingURL=offline-BjJdcVBb.js.map