@rebasepro/client 0.30.1 → 0.31.0-canary.g59cd6fd

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,29 +1,31 @@
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-B7F5mimt.js";
2
- import { EntityReference, EntityRelation, GeoPoint, Vector, hasFieldOperation, isUnsupported, parseCaseFoldedFieldPath, parseRelationAggregateSort, toCanonicalOp } from "@rebasepro/types";
1
+ import { a as byIdRead, c as invalidBulkBody, d as RebaseApiError$1, f as buildQueryString, l as SDKQueryBuilder, n as MemoryOfflineStore, r as createMutationId, s as etagOf, t as IndexedDBOfflineStore, u as RebaseClientError$1 } from "./offline-store-DtmBwmKE.js";
2
+ import { hasFieldOperation, isUnsupported, parseCaseFoldedFieldPath, parseRelationAggregateSort, toCanonicalOp } from "@rebasepro/types";
3
3
  import { collectAllPages, normalizeOrderBy, paginateFind, resolveFindWindow, withETag } from "@rebasepro/common";
4
4
  import { splitSearchTerms, unref } from "@rebasepro/utils";
5
5
  //#region src/offline-codec.ts
6
6
  /**
7
- * Lossless round-tripping of rows through the offline store.
7
+ * Rows and queued writes through the offline store.
8
8
  *
9
- * Both persistence backends move values by structured clone, which keeps
10
- * `Date` but flattens every class instance to a plain object. For
11
- * `EntityReference`/`EntityRelation` that is harmless — they carry their own
12
- * `__type` discriminator, so the JSON reviver can rebuild them — but
13
- * `GeoPoint` and `Vector` do not, and would come back out of the cache as
14
- * anonymous `{ latitude, longitude }` / `{ value }` bags. A row read from the
15
- * cache must be indistinguishable from the same row read from the network, so
16
- * those two are tagged on the way in and revived on the way out.
9
+ * Both persistence backends move values by structured clone. What goes in is
10
+ * wire values — the row a Rebase server serves, and the values a write sends
11
+ * (the admin converts its view model before it hands a write to the client) —
12
+ * so a clone gives back exactly what went in, `Date` included. The one thing
13
+ * a structured clone gets wrong is a key named `__proto__`, so rows are
14
+ * copied key by key on both sides ({@link setOwn}).
17
15
  *
18
- * Type tests here are structural rather than `instanceof`, because a structured
19
- * clone can arrive from another realm — an iframe, a worker, or the polyfill
20
- * the tests run against — where the constructor identity differs but the value
21
- * is the real thing. Only *plain* objects are walked; anything else is passed
22
- * through whole, so a class instance is never quietly reduced to `{}`.
16
+ * A queued write from before layout 2 (`QUEUE_SCHEMA_VERSION`) is the exception:
17
+ * the admin handed the client its view model then, and the store kept those
18
+ * values as plain objects tagged with their class (`{ __type: "relation",
19
+ * id, … }`, `{ __type: "GeoPoint", … }`, `{ __type: "Vector", value }`,
20
+ * `{ __type: "reference", id, … }`). Such an entry is a user's unsynced write,
21
+ * so it is converted to the wire values the server stored for it — a relation
22
+ * as its key, a point as `{ latitude, longitude }`, a vector as its numbers,
23
+ * a reference as its id — rather than dropped or replayed in a shape the
24
+ * server no longer accepts ({@link hydrateMutation}).
25
+ *
26
+ * Only *plain* objects are walked (tested structurally: a clone may come from
27
+ * another realm); anything else is passed through whole.
23
28
  */
24
- function isDate(value) {
25
- return Object.prototype.toString.call(value) === "[object Date]";
26
- }
27
29
  /** An object literal — not a Date, RegExp, Map, or any class instance. */
28
30
  function isPlainObject$1(value) {
29
31
  if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
@@ -45,53 +47,56 @@ function setOwn(out, key, value) {
45
47
  configurable: true
46
48
  });
47
49
  }
48
- function dehydrateValue(value) {
49
- if (value === null || value === void 0) return value;
50
- if (value instanceof GeoPoint) return {
51
- __type: "GeoPoint",
52
- latitude: value.latitude,
53
- longitude: value.longitude
54
- };
55
- if (value instanceof Vector) return {
56
- __type: "Vector",
57
- value: [...value.value]
58
- };
59
- if (value instanceof EntityReference || value instanceof EntityRelation) return value;
60
- if (Array.isArray(value)) return value.map(dehydrateValue);
50
+ /** A copy of a value, walked so that every key — `__proto__` too — stays an own property. */
51
+ function copyValue(value) {
52
+ if (Array.isArray(value)) return value.map(copyValue);
61
53
  if (isPlainObject$1(value)) {
62
54
  const out = {};
63
- for (const [key, inner] of Object.entries(value)) setOwn(out, key, dehydrateValue(inner));
55
+ for (const [key, inner] of Object.entries(value)) setOwn(out, key, copyValue(inner));
64
56
  return out;
65
57
  }
66
58
  return value;
67
59
  }
68
- function hydrateValue(value) {
69
- if (value === null || value === void 0 || isDate(value)) return value;
70
- if (Array.isArray(value)) return value.map(hydrateValue);
71
- if (typeof value === "object") {
72
- const revived = rebaseReviver("", value);
73
- if (revived !== value) return revived;
74
- if (!isPlainObject$1(value)) return value;
60
+ /**
61
+ * The wire value a tagged view-model value of a queue entry from before
62
+ * layout 2 stands for (see the module comment), or the value itself.
63
+ */
64
+ function wireOfTagged(value) {
65
+ switch (value.__type) {
66
+ case "relation":
67
+ case "reference": return typeof value.id === "string" || typeof value.id === "number" ? value.id : value;
68
+ case "GeoPoint": return typeof value.latitude === "number" && typeof value.longitude === "number" ? {
69
+ latitude: value.latitude,
70
+ longitude: value.longitude
71
+ } : value;
72
+ case "Vector": return Array.isArray(value.value) ? value.value.map(Number) : value;
73
+ default: return value;
74
+ }
75
+ }
76
+ /** {@link copyValue}, with each tagged view-model value as its wire value. */
77
+ function wireOfLegacyValue(value) {
78
+ if (Array.isArray(value)) return value.map(wireOfLegacyValue);
79
+ if (isPlainObject$1(value)) {
80
+ const converted = wireOfTagged(value);
81
+ if (converted !== value) return converted;
75
82
  const out = {};
76
- for (const [key, inner] of Object.entries(value)) setOwn(out, key, hydrateValue(inner));
83
+ for (const [key, inner] of Object.entries(value)) setOwn(out, key, wireOfLegacyValue(inner));
77
84
  return out;
78
85
  }
79
86
  return value;
80
87
  }
81
88
  /** Prepare a row for the store. */
82
89
  function dehydrateRow(row) {
83
- return dehydrateValue(row);
90
+ return copyValue(row);
84
91
  }
85
92
  /** Restore a row read back from the store. */
86
93
  function hydrateRow(row) {
87
- return hydrateValue(row);
94
+ return copyValue(row);
88
95
  }
89
96
  /**
90
- * A queued write as the store keeps it, and back. Its payloads are rows, and
91
- * a row read back from the queue has to be the row that was queued: stored
92
- * raw, a pending `GeoPoint` came back after a reload as a bare
93
- * `{ latitude, longitude }`, was overlaid onto the server's rows, and was
94
- * written back to the cache that way.
97
+ * A queued write as the store keeps it, and back: its payloads are rows, each
98
+ * copied by {@link copyValue} — or, for an entry of an older layout, turned
99
+ * into wire values.
95
100
  */
96
101
  function mapMutation(op, map) {
97
102
  const rows = (value) => value === void 0 ? value : map(value);
@@ -112,11 +117,21 @@ function mapMutation(op, map) {
112
117
  }
113
118
  /** Prepare a queued write for the store. */
114
119
  function dehydrateMutation(op) {
115
- return mapMutation(op, dehydrateValue);
120
+ return mapMutation(op, copyValue);
116
121
  }
117
- /** Restore a queued write read back from the store. */
122
+ /**
123
+ * Restore a queued write read back from the store. An entry of layout 1 —
124
+ * written before the client held wire values only — has its view-model values
125
+ * converted to wire values and is stamped with the current layout, so it
126
+ * replays as the server stored such a write and is persisted that way the
127
+ * next time the entry is written back.
128
+ */
118
129
  function hydrateMutation(op) {
119
- return mapMutation(op, hydrateValue);
130
+ if ((op.schemaVersion ?? 1) >= 2) return mapMutation(op, copyValue);
131
+ return {
132
+ ...mapMutation(op, wireOfLegacyValue),
133
+ schemaVersion: 2
134
+ };
120
135
  }
121
136
  //#endregion
122
137
  //#region src/offline-connectivity.ts
@@ -369,8 +384,8 @@ var ConnectivityMonitor = class {
369
384
  * Two things it deliberately approximates, both flagged by
370
385
  * {@link isExactlyEvaluable}: `searchString` becomes a case-insensitive
371
386
  * substring scan over the row's string fields (the server runs real full-text
372
- * search over the collection's configured columns), and `include` cannot be
373
- * evaluated at all, because the related rows live in collections this query
387
+ * search over the table's configured columns), and `include` cannot be
388
+ * evaluated at all, because the related rows live in tables this query
374
389
  * knows nothing about.
375
390
  */
376
391
  var collator = typeof Intl !== "undefined" && typeof Intl.Collator === "function" ? new Intl.Collator(void 0, {
@@ -381,17 +396,11 @@ function isNullish(value) {
381
396
  return value === null || value === void 0;
382
397
  }
383
398
  /**
384
- * Reduce a value to something comparable. Relations compare by the id they
385
- * point at — the column holds a foreign key, so that is what the server
386
- * compares too.
399
+ * Reduce a value to something comparable: a date by its instant. A relation
400
+ * is its key on a row and in a filter alike — the wire carries nothing else.
387
401
  */
388
402
  function toComparable(value) {
389
403
  if (value instanceof Date) return value.getTime();
390
- if (value instanceof EntityRelation) return value.id;
391
- if (value && typeof value === "object") {
392
- const record = value;
393
- if (typeof record.__type === "string" && "id" in record) return record.id;
394
- }
395
404
  return value;
396
405
  }
397
406
  /**
@@ -731,9 +740,9 @@ function logicalOrders(condition, depth = 0) {
731
740
  }
732
741
  /**
733
742
  * Can a locally evaluated answer to `params` be trusted to match the server's,
734
- * assuming the cache holds every row of the collection?
743
+ * assuming the cache holds every row of the table?
735
744
  *
736
- * `include` pulls in rows from other collections that this evaluator never
745
+ * `include` pulls in rows from other tables that this evaluator never
737
746
  * sees, and `searchString` is only approximated — both make the local answer a
738
747
  * best effort rather than an equivalent one.
739
748
  *
@@ -863,7 +872,7 @@ function dependencyRejected(refused, error) {
863
872
  });
864
873
  }
865
874
  /**
866
- * A refusal about what a write contains — a field the collection no longer
875
+ * A refusal about what a write contains — a field the table no longer
867
876
  * has, one the caller may not write, a value a constraint refuses — rather
868
877
  * than about the row or the caller as a whole.
869
878
  */
@@ -924,7 +933,7 @@ function replaceMintedId(value, from, to) {
924
933
  /**
925
934
  * A plain object from any realm — a queued payload read back from the store is
926
935
  * a structured clone, whose `Object.prototype` need not be this one. A class
927
- * instance (a `GeoPoint`, a `Date`) is not walked.
936
+ * instance (a `Date`) is not walked.
928
937
  */
929
938
  function isPlainObject(value) {
930
939
  if (value === null || typeof value !== "object") return false;
@@ -993,12 +1002,12 @@ function generateOfflineStringId() {
993
1002
  */
994
1003
  var lastOfflineNumericId = 0;
995
1004
  /**
996
- * A temporary id for a collection whose ids are numbers.
1005
+ * A temporary id for a table whose ids are numbers.
997
1006
  *
998
1007
  * **Negative**, which is the convention every local-first engine settles on for
999
1008
  * the same reason: a real key is a positive integer or an identity sequence, so
1000
1009
  * the sign alone says "this one is not the server's yet" — and it stays a
1001
- * number, which is what matters. A UUID string was minted for every collection,
1010
+ * number, which is what matters. A UUID string was minted for every table,
1002
1011
  * so a `create` while offline handed back `{ id: "526e2faf-…" }` on a row the
1003
1012
  * generated types declare `id: number`. Anything that put that in a URL, a
1004
1013
  * foreign key or an `id.toFixed()` was wrong or threw until the replay
@@ -1051,7 +1060,7 @@ function optimisticRow(fields, id) {
1051
1060
  * Whether a query answers with something narrower than whole rows: `fields`
1052
1061
  * returns only the columns it names (and the key), and `distinct` collapses
1053
1062
  * rows into their distinct projections. Either way what comes back is not a
1054
- * row of the collection, and must not be stored as one.
1063
+ * row of the table, and must not be stored as one.
1055
1064
  */
1056
1065
  function isProjection(params) {
1057
1066
  return (params?.fields?.length ?? 0) > 0 || params?.distinct === true;
@@ -1132,7 +1141,7 @@ var OfflineManager = class {
1132
1141
  * touches nothing that belongs to the new user.
1133
1142
  */
1134
1143
  scopeEpoch = 0;
1135
- /** The local database: normalized rows and query snapshots per collection. */
1144
+ /** The local database: normalized rows and query snapshots per table. */
1136
1145
  collections = /* @__PURE__ */ new Map();
1137
1146
  /** In-memory mirror of the current scope's queue, in replay order. */
1138
1147
  queueEntries = [];
@@ -1144,7 +1153,7 @@ var OfflineManager = class {
1144
1153
  this.pendingIndex = void 0;
1145
1154
  }
1146
1155
  /**
1147
- * Per collection, the row ids the queue writes to and the ones it creates
1156
+ * Per table, the row ids the queue writes to and the ones it creates
1148
1157
  * — {@link hasPending} and {@link isLocallyCreated}, which answering a
1149
1158
  * page asks once or twice per row. Each used to scan the whole queue: a
1150
1159
  * 500-row page against 200 queued writes read 80,000 queue entries, on
@@ -1194,8 +1203,8 @@ var OfflineManager = class {
1194
1203
  api;
1195
1204
  constructor(config, createInner) {
1196
1205
  this.store = config.store ?? (typeof indexedDB !== "undefined" ? new IndexedDBOfflineStore() : new MemoryOfflineStore());
1197
- this.maxCachedQueries = config.maxCachedQueriesPerCollection ?? 50;
1198
- this.maxCachedRows = config.maxCachedRowsPerCollection ?? 5e3;
1206
+ this.maxCachedQueries = config.maxCachedQueriesPerTable ?? 50;
1207
+ this.maxCachedRows = config.maxCachedRowsPerTable ?? 5e3;
1199
1208
  this.maxRetries = config.maxRetries ?? 5;
1200
1209
  this.onSyncError = config.onSyncError;
1201
1210
  this.onConflict = config.onConflict;
@@ -1400,13 +1409,13 @@ var OfflineManager = class {
1400
1409
  */
1401
1410
  /**
1402
1411
  * A filtered write runs on the server or not at all: refused while writes
1403
- * are being queued, and while this collection has queued writes the
1412
+ * are being queued, and while this table has queued writes the
1404
1413
  * server has not seen — the filter would be judged against rows they are
1405
1414
  * about to change.
1406
1415
  */
1407
1416
  assertOnlineForFilteredWrite(slug, method) {
1408
1417
  if (this.sendsWrites() && !this.hasPendingIn(slug)) return;
1409
- throw new RebaseClientError$1(`${method}() on "${slug}" needs the server: which rows a filter matches is the server's answer, so a filtered write is not queued offline, nor sent ahead of writes this collection still has queued.`, { code: "OFFLINE_FILTERED_WRITE_UNSUPPORTED" });
1418
+ throw new RebaseClientError$1(`${method}() on "${slug}" needs the server: which rows a filter matches is the server's answer, so a filtered write is not queued offline, nor sent ahead of writes this table still has queued.`, { code: "OFFLINE_FILTERED_WRITE_UNSUPPORTED" });
1410
1419
  }
1411
1420
  sendsWrites() {
1412
1421
  return this.connectivity.shouldAttempt() && !this.unverified;
@@ -1471,7 +1480,7 @@ var OfflineManager = class {
1471
1480
  * on. A page the server never answered here is evaluated over whatever
1472
1481
  * rows happen to be cached, and its `hasMore` is about those rows — so
1473
1482
  * offline, `findAll()` stopped at the first such page and returned a
1474
- * fraction of the collection as the whole of it, with nothing to tell
1483
+ * fraction of the table as the whole of it, with nothing to tell
1475
1484
  * the two apart. A walk refuses that page instead.
1476
1485
  */
1477
1486
  const findPage = async (params, walk) => {
@@ -1514,7 +1523,7 @@ var OfflineManager = class {
1514
1523
  meta: answer.meta
1515
1524
  };
1516
1525
  };
1517
- const unwalkable = () => offlineError(`Offline: a page of "${slug}" the server has not answered on this device is needed to read the collection to the end, and the local database cannot say what is on it.`);
1526
+ const unwalkable = () => offlineError(`Offline: a page of "${slug}" the server has not answered on this device is needed to read the table to the end, and the local database cannot say what is on it.`);
1518
1527
  const wrapped = {
1519
1528
  find: (params) => findPage(params, false),
1520
1529
  iterate: (params) => paginateFind((p) => findPage(p, true), params, slug),
@@ -1721,7 +1730,7 @@ var OfflineManager = class {
1721
1730
  * Online only. Which rows a filter matches is the server's answer —
1722
1731
  * the local store holds a subset of them — so a filtered write is
1723
1732
  * never applied locally or queued. The rows it updated are folded
1724
- * into the store; a filtered delete refreshes the collection.
1733
+ * into the store; a filtered delete refreshes the table.
1725
1734
  */
1726
1735
  updateWhere: async (query, data, options) => {
1727
1736
  const ticket = this.ticket() ?? await this.nextTicket();
@@ -2393,17 +2402,17 @@ var OfflineManager = class {
2393
2402
  };
2394
2403
  }
2395
2404
  /**
2396
- * A temporary id of the type this collection's ids actually have.
2405
+ * A temporary id of the type this table's ids actually have.
2397
2406
  *
2398
2407
  * There is no schema here to read it off — the generated `Database` types
2399
2408
  * are erased at compile time, and the whole point of this path is that the
2400
2409
  * server is unreachable. So it is read off the rows the local database
2401
- * already holds: a collection whose cached ids are numbers gets a negative
2410
+ * already holds: a table whose cached ids are numbers gets a negative
2402
2411
  * number, and everything else gets a UUID.
2403
2412
  *
2404
- * A collection with nothing cached falls back to a UUID, which is the same
2413
+ * A table with nothing cached falls back to a UUID, which is the same
2405
2414
  * guess as before — but that is a first write on a device that has never
2406
- * read the collection, which is also the case where nothing local can tell
2415
+ * read the table, which is also the case where nothing local can tell
2407
2416
  * the difference. Reading one row first is enough to fix it.
2408
2417
  */
2409
2418
  mintOfflineId(slug) {
@@ -2610,7 +2619,7 @@ var OfflineManager = class {
2610
2619
  /**
2611
2620
  * A write changed which rows belong in a list, and only the server can say
2612
2621
  * how — a row it generated is in no cached page, and the totals moved.
2613
- * Re-run every live query on the collection; queries nobody is watching
2622
+ * Re-run every live query on the table; queries nobody is watching
2614
2623
  * are corrected by their next `find`.
2615
2624
  *
2616
2625
  * Coalesced per microtask so a burst of writes costs one round trip, and
@@ -2686,14 +2695,14 @@ var OfflineManager = class {
2686
2695
  ...mutation,
2687
2696
  mutationId: createMutationId(),
2688
2697
  queuedAt: Date.now(),
2689
- schemaVersion: 1
2698
+ schemaVersion: 2
2690
2699
  };
2691
2700
  await this.persistMutation(`${ticket.scope}|${orphan.mutationId}`, orphan);
2692
2701
  return;
2693
2702
  }
2694
2703
  if (mutation.type === "update") {
2695
2704
  const tail = this.queue[this.queue.length - 1];
2696
- if (tail && !this.inFlight.has(tail.mutationId) && tail.sent === void 0 && (tail.schemaVersion ?? 1) <= 1 && tail.collection === mutation.collection && (tail.type === "create" || tail.type === "update") && tail.id === mutation.id && (mutation.ifMatch === void 0 || mutation.ifMatch === tail.ifMatch)) {
2705
+ if (tail && !this.inFlight.has(tail.mutationId) && tail.sent === void 0 && (tail.schemaVersion ?? 1) <= 2 && tail.collection === mutation.collection && (tail.type === "create" || tail.type === "update") && tail.id === mutation.id && (mutation.ifMatch === void 0 || mutation.ifMatch === tail.ifMatch)) {
2697
2706
  if (tail.type === "update") tail.parts = [...tail.parts ?? [{ ...tail.data }], { ...mutation.data }];
2698
2707
  tail.data = {
2699
2708
  ...tail.data,
@@ -2717,7 +2726,7 @@ var OfflineManager = class {
2717
2726
  ...mutation,
2718
2727
  mutationId: createMutationId(),
2719
2728
  queuedAt: Date.now(),
2720
- schemaVersion: 1
2729
+ schemaVersion: 2
2721
2730
  };
2722
2731
  await this.persistMutation(this.queueKey(full), full);
2723
2732
  this.queue.push(full);
@@ -2741,7 +2750,7 @@ var OfflineManager = class {
2741
2750
  if (typeof storage?.persist !== "function") return;
2742
2751
  storage.persist().then((persisted) => this.patchStatus({ persisted }), () => void 0);
2743
2752
  }
2744
- /** The queue's row ids for one collection — see {@link pendingIndex}. */
2753
+ /** The queue's row ids for one table — see {@link pendingIndex}. */
2745
2754
  pendingIds(slug) {
2746
2755
  if (!this.pendingIndex) {
2747
2756
  const index = /* @__PURE__ */ new Map();
@@ -2788,7 +2797,7 @@ var OfflineManager = class {
2788
2797
  hasPending(slug, id) {
2789
2798
  return this.pendingIds(slug)?.writes.has(String(id)) ?? false;
2790
2799
  }
2791
- /** Does this collection have any write the server has not seen? */
2800
+ /** Does this table have any write the server has not seen? */
2792
2801
  hasPendingIn(slug) {
2793
2802
  return (this.pendingIds(slug)?.writes.size ?? 0) > 0;
2794
2803
  }
@@ -2853,7 +2862,7 @@ var OfflineManager = class {
2853
2862
  try {
2854
2863
  while (this.queue.length > 0 && !this.disposed && this.isCurrent(ticket)) {
2855
2864
  const op = this.queue[0];
2856
- if ((op.schemaVersion ?? 1) > 1) {
2865
+ if ((op.schemaVersion ?? 1) > 2) {
2857
2866
  this.patchStatus({ lastError: `A queued write was saved by a newer version of the SDK (layout ${String(op.schemaVersion)}); it is kept, and replays once this page runs that version.` });
2858
2867
  break;
2859
2868
  }
@@ -2938,8 +2947,8 @@ var OfflineManager = class {
2938
2947
  * see {@link OfflineConfig.replayBatchSize}. Fewer than two means the head
2939
2948
  * replays on its own.
2940
2949
  *
2941
- * Consecutive, so the queue's order holds; one collection, since a bulk
2942
- * write is one collection's. Each is a create never sent (so its request
2950
+ * Consecutive, so the queue's order holds; one table, since a bulk
2951
+ * write is one table's. Each is a create never sent (so its request
2943
2952
  * is still its own to choose) with an id the SDK minted as a string — a
2944
2953
  * lost answer then cannot duplicate it, because the server refuses that
2945
2954
  * id the second time and the single replay recognises the row as its
@@ -2951,7 +2960,7 @@ var OfflineManager = class {
2951
2960
  if (this.replayBatchSize < 2) return [];
2952
2961
  const head = this.queue[0];
2953
2962
  const resent = head?.sent?.run;
2954
- const foldable = (op, collection) => op !== void 0 && op.type === "create" && op.generatedId === true && typeof op.id === "string" && (resent === void 0 ? op.sent === void 0 : op.sent?.run === resent) && !op.upsert && (op.schemaVersion ?? 1) <= 1 && !unbatched.has(op.mutationId) && (collection === void 0 || op.collection === collection);
2963
+ const foldable = (op, collection) => op !== void 0 && op.type === "create" && op.generatedId === true && typeof op.id === "string" && (resent === void 0 ? op.sent === void 0 : op.sent?.run === resent) && !op.upsert && (op.schemaVersion ?? 1) <= 2 && !unbatched.has(op.mutationId) && (collection === void 0 || op.collection === collection);
2955
2964
  if (!foldable(head)) return [];
2956
2965
  const run = [head];
2957
2966
  for (let i = 1; i < this.queue.length && (resent !== void 0 || run.length < this.replayBatchSize); i++) {
@@ -3382,7 +3391,7 @@ var OfflineManager = class {
3382
3391
  if (msg.type === "rows") for (const slug of msg.slugs ?? []) this.reloadCollection(slug);
3383
3392
  else if (msg.type === "queue") this.reloadQueue();
3384
3393
  }
3385
- /** Re-read one collection from the store, replacing what is in memory. */
3394
+ /** Re-read one table from the store, replacing what is in memory. */
3386
3395
  async reloadCollection(slug) {
3387
3396
  const state = this.collections.get(slug);
3388
3397
  if (!state?.loaded || this.scopeHold) return;
@@ -3487,4 +3496,4 @@ var OfflineManager = class {
3487
3496
  //#endregion
3488
3497
  export { OfflineManager };
3489
3498
 
3490
- //# sourceMappingURL=offline-B6J1YUWF.js.map
3499
+ //# sourceMappingURL=offline-D_wKJcO3.js.map