@instantdb/core 0.22.162 → 0.22.163

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/core",
3
- "version": "0.22.162",
3
+ "version": "0.22.163",
4
4
  "description": "Instant's core local abstraction",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
6
6
  "repository": {
@@ -56,7 +56,7 @@
56
56
  "dependencies": {
57
57
  "mutative": "^1.0.10",
58
58
  "uuid": "^11.1.0",
59
- "@instantdb/version": "0.22.162"
59
+ "@instantdb/version": "0.22.163"
60
60
  },
61
61
  "scripts": {
62
62
  "test": "vitest",
package/src/Reactor.js CHANGED
@@ -2169,6 +2169,22 @@ export default class Reactor {
2169
2169
  delete prev[k].result;
2170
2170
  });
2171
2171
  });
2172
+ this.querySubs.clearUnloadedKeys();
2173
+ this._updatePendingMutations((prev) => {
2174
+ // Mark all pending mutations with an error, since we won't be able to
2175
+ // deliver the result
2176
+ for (const [eventId, _v] of prev.entries()) {
2177
+ if (this.mutationDeferredStore.get(eventId)) {
2178
+ this._finishTransaction('error', eventId, {
2179
+ message: 'User changed while transaction was in progress.',
2180
+ type: 'user-changed',
2181
+ });
2182
+ }
2183
+ }
2184
+
2185
+ prev.clear();
2186
+ });
2187
+
2172
2188
  this._reconnectTimeoutMs = 0;
2173
2189
  this._transport.close();
2174
2190
  this._oauthCallbackResponse = null;
@@ -550,4 +550,21 @@ export class PersistedObject<K extends string, T, SerializedT> {
550
550
  this._subs = this._subs.filter((x) => x !== cb);
551
551
  };
552
552
  }
553
+
554
+ // Removes any keys that we haven't loaded--used when
555
+ // changing users to make sure we clean out all user data
556
+ public async clearUnloadedKeys(): Promise<void> {
557
+ let needsPersist = false;
558
+ for (const key of await this._persister.getAllKeys()) {
559
+ if (key === META_KEY || key in this.currentValue) {
560
+ continue;
561
+ }
562
+
563
+ this._pendingSaveKeys.add(key as K);
564
+ needsPersist = true;
565
+ }
566
+ if (needsPersist) {
567
+ await this._enqueuePersist();
568
+ }
569
+ }
553
570
  }