@instantdb/core 0.22.86-experimental.separate-attrs.20122276424.1 → 0.22.86-experimental.split-store.20183617880.1

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.
Files changed (65) hide show
  1. package/__tests__/src/Reactor.test.js +18 -11
  2. package/__tests__/src/{datalog.test.js → datalog.test.ts} +17 -5
  3. package/__tests__/src/{instaml.test.js → instaml.test.ts} +183 -119
  4. package/__tests__/src/instaql.bench.ts +34 -0
  5. package/__tests__/src/{instaql.test.js → instaql.test.ts} +342 -455
  6. package/__tests__/src/instaqlInference.test.js +13 -9
  7. package/__tests__/src/{store.test.js → store.test.ts} +188 -210
  8. package/dist/commonjs/Reactor.d.ts +23 -6
  9. package/dist/commonjs/Reactor.d.ts.map +1 -1
  10. package/dist/commonjs/Reactor.js +110 -45
  11. package/dist/commonjs/Reactor.js.map +1 -1
  12. package/dist/commonjs/SyncTable.d.ts +4 -1
  13. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  14. package/dist/commonjs/SyncTable.js +35 -37
  15. package/dist/commonjs/SyncTable.js.map +1 -1
  16. package/dist/commonjs/instaml.d.ts +17 -4
  17. package/dist/commonjs/instaml.d.ts.map +1 -1
  18. package/dist/commonjs/instaml.js +105 -76
  19. package/dist/commonjs/instaml.js.map +1 -1
  20. package/dist/commonjs/instaql.d.ts +4 -3
  21. package/dist/commonjs/instaql.d.ts.map +1 -1
  22. package/dist/commonjs/instaql.js +65 -63
  23. package/dist/commonjs/instaql.js.map +1 -1
  24. package/dist/commonjs/reactorTypes.d.ts +29 -0
  25. package/dist/commonjs/reactorTypes.d.ts.map +1 -0
  26. package/dist/commonjs/reactorTypes.js +3 -0
  27. package/dist/commonjs/reactorTypes.js.map +1 -0
  28. package/dist/commonjs/store.d.ts +67 -25
  29. package/dist/commonjs/store.d.ts.map +1 -1
  30. package/dist/commonjs/store.js +170 -70
  31. package/dist/commonjs/store.js.map +1 -1
  32. package/dist/esm/Reactor.d.ts +23 -6
  33. package/dist/esm/Reactor.d.ts.map +1 -1
  34. package/dist/esm/Reactor.js +111 -46
  35. package/dist/esm/Reactor.js.map +1 -1
  36. package/dist/esm/SyncTable.d.ts +4 -1
  37. package/dist/esm/SyncTable.d.ts.map +1 -1
  38. package/dist/esm/SyncTable.js +35 -37
  39. package/dist/esm/SyncTable.js.map +1 -1
  40. package/dist/esm/instaml.d.ts +17 -4
  41. package/dist/esm/instaml.d.ts.map +1 -1
  42. package/dist/esm/instaml.js +102 -71
  43. package/dist/esm/instaml.js.map +1 -1
  44. package/dist/esm/instaql.d.ts +4 -3
  45. package/dist/esm/instaql.d.ts.map +1 -1
  46. package/dist/esm/instaql.js +65 -63
  47. package/dist/esm/instaql.js.map +1 -1
  48. package/dist/esm/reactorTypes.d.ts +29 -0
  49. package/dist/esm/reactorTypes.d.ts.map +1 -0
  50. package/dist/esm/reactorTypes.js +2 -0
  51. package/dist/esm/reactorTypes.js.map +1 -0
  52. package/dist/esm/store.d.ts +67 -25
  53. package/dist/esm/store.d.ts.map +1 -1
  54. package/dist/esm/store.js +167 -70
  55. package/dist/esm/store.js.map +1 -1
  56. package/dist/standalone/index.js +1580 -1392
  57. package/dist/standalone/index.umd.cjs +3 -3
  58. package/package.json +2 -2
  59. package/src/Reactor.js +154 -77
  60. package/src/SyncTable.ts +85 -45
  61. package/src/{instaml.js → instaml.ts} +196 -95
  62. package/src/instaql.ts +88 -62
  63. package/src/reactorTypes.ts +32 -0
  64. package/src/store.ts +248 -90
  65. package/__tests__/src/instaql.bench.js +0 -29
@@ -3,12 +3,13 @@
3
3
  */
4
4
  export default class Reactor<RoomSchema extends import("./presence.ts").RoomSchemaShape = {}> {
5
5
  constructor(config: any, Storage: typeof IndexedDBStorage | undefined, NetworkListener: typeof WindowNetworkListener | undefined, versions: any, EventSourceConstructor: any);
6
- attrs: any;
6
+ /** @type {sts.AttrsStore | undefined} */
7
+ attrs: sts.AttrsStore | undefined;
7
8
  _isOnline: boolean;
8
9
  _isShutdown: boolean;
9
10
  status: string;
10
- /** @type {PersistedObject} */
11
- querySubs: PersistedObject<any, any, any>;
11
+ /** @type {PersistedObject<string, QuerySub, QuerySubInStorage>} */
12
+ querySubs: PersistedObject<string, QuerySub, QuerySubInStorage>;
12
13
  /** @type {PersistedObject} */
13
14
  kv: PersistedObject<any, any, any>;
14
15
  /** @type {SyncTable} */
@@ -78,6 +79,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
78
79
  queryCacheLimit: any;
79
80
  versions: any;
80
81
  _beforeUnload(): void;
82
+ ensureAttrs(): sts.AttrsStore;
81
83
  updateSchema(schema: any): void;
82
84
  _reactorStats(): {
83
85
  inFlightMutationCount: number;
@@ -139,12 +141,24 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
139
141
  _unsubQuery(q: any, hash: any, cb: any): void;
140
142
  _hasQueryListeners(hash: any): boolean;
141
143
  _cleanupQuery(q: any, hash: any): void;
142
- _rewriteMutations(attrs: any, muts: any, processedTxId: any): any;
144
+ /**
145
+ *
146
+ * @param {sts.AttrsStore} attrs
147
+ * @param {any} muts
148
+ * @param {number} [processedTxId]
149
+ */
150
+ _rewriteMutations(attrs: sts.AttrsStore, muts: any, processedTxId?: number): any;
143
151
  _rewriteMutationsSorted(attrs: any, muts: any): any[];
144
- optimisticAttrs(): any;
152
+ /**
153
+ * @returns {sts.AttrsStore}
154
+ */
155
+ optimisticAttrs(): sts.AttrsStore;
145
156
  /** Runs instaql on a query and a store */
146
157
  dataForQuery(hash: any): any;
147
- _applyOptimisticUpdates(store: any, mutations: any, processedTxId: any): any;
158
+ _applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any): {
159
+ store: any;
160
+ attrsStore: any;
161
+ };
148
162
  /** Re-run instaql and call all callbacks with new data */
149
163
  notifyOne: (hash: any) => void;
150
164
  notifyOneQueryOnce: (hash: any) => void;
@@ -338,6 +352,9 @@ export type Logger = import("./utils/log.ts").Logger;
338
352
  export type Connection = import("./Connection.ts").Connection<any>;
339
353
  export type TransportType = import("./Connection.ts").TransportType;
340
354
  export type EventSourceConstructor = import("./Connection.ts").EventSourceConstructor;
355
+ export type QuerySub = import("./reactorTypes.ts").QuerySub;
356
+ export type QuerySubInStorage = import("./reactorTypes.ts").QuerySubInStorage;
357
+ import * as sts from './store.ts';
341
358
  import { PersistedObject } from './utils/PersistedObject.ts';
342
359
  import { SyncTable } from './SyncTable.ts';
343
360
  import { Deferred } from './utils/Deferred.js';
@@ -1 +1 @@
1
- {"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"AA8KA;;GAEG;AACH,6BAFwD,UAAU,SAArD,OAAQ,eAAe,EAAE,eAAgB;IAkEpD,8KAgHC;IA/KD,WAAM;IACN,mBAAiB;IACjB,qBAAoB;IACpB,eAA2B;IAE3B,8BAA8B;IAC9B,0CAAU;IAEV,8BAA8B;IAC9B,mCAAG;IAEH,wBAAwB;IACxB,YADW,SAAS,CACT;IAEX,wEAAwE;IACxE,UADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;KAAE,CAAC,CAAC,CACtD;IACd,gFAAgF;IAChF,eADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,CACzD;IACnB,eAAa;IACb,gBAAc;IACd,wBAAsB;IACtB,2BAAyB;IACzB,YAAO;IACP,qCAAkC;IAClC,0BAA2B;IAC3B,4BAAwB;IACxB,yBAAyB;IACzB,YADW,UAAU,CACV;IACX,4BAA4B;IAC5B,gBADW,aAAa,CACF;IAEtB,qCAAqC;IACrC,cADW,sBAAsB,CACpB;IACb,6BAA6B;IAC7B,OADW,OAAO,GAAG,I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0BAmBlC,gBAAgB;yBApBjB,qBAAqB;yBAJrB,cAAc;4BACX,iBAAiB;6BAHhB,uBAAuB;kCAClB,4BAA4B"}
@@ -60,7 +60,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
60
60
  const weakHash_ts_1 = __importDefault(require("./utils/weakHash.js"));
61
61
  const instaql_ts_1 = __importDefault(require("./instaql.js"));
62
62
  const instaml = __importStar(require("./instaml.js"));
63
- const s = __importStar(require("./store.js"));
63
+ const sts = __importStar(require("./store.js"));
64
64
  const uuid_ts_1 = __importDefault(require("./utils/uuid.js"));
65
65
  const IndexedDBStorage_ts_1 = __importDefault(require("./IndexedDBStorage.js"));
66
66
  const WindowNetworkListener_js_1 = __importDefault(require("./WindowNetworkListener.js"));
@@ -87,6 +87,8 @@ const SyncTable_ts_1 = require("./SyncTable.js");
87
87
  /** @typedef {import('./Connection.ts').Connection} Connection */
88
88
  /** @typedef {import('./Connection.ts').TransportType} TransportType */
89
89
  /** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
90
+ /** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
91
+ /** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
90
92
  const STATUS = {
91
93
  CONNECTING: 'connecting',
92
94
  OPENED: 'opened',
@@ -139,20 +141,37 @@ const ignoreLogging = {
139
141
  'refresh-presence': true,
140
142
  'patch-presence': true,
141
143
  };
144
+ /**
145
+ * @param {QuerySubInStorage} x
146
+ * @param {boolean | null} useDateObjects
147
+ * @returns {QuerySub}
148
+ */
142
149
  function querySubFromStorage(x, useDateObjects) {
143
150
  var _a;
144
151
  const v = typeof x === 'string' ? JSON.parse(x) : x;
145
152
  if ((_a = v === null || v === void 0 ? void 0 : v.result) === null || _a === void 0 ? void 0 : _a.store) {
146
- const storeJSON = v.result.store;
147
- v.result.store = s.fromJSON(Object.assign(Object.assign({}, storeJSON), { useDateObjects: useDateObjects }));
153
+ const attrsStore = sts.attrsStoreFromJSON(v.result.attrsStore, v.result.store);
154
+ if (attrsStore) {
155
+ const storeJSON = v.result.store;
156
+ v.result.store = sts.fromJSON(attrsStore, Object.assign(Object.assign({}, storeJSON), { useDateObjects: useDateObjects }));
157
+ v.result.attrsStore = attrsStore;
158
+ }
148
159
  }
149
160
  return v;
150
161
  }
162
+ /**
163
+ *
164
+ * @param {string} _key
165
+ * @param {QuerySub} sub
166
+ * @returns QuerySubInStorage
167
+ */
151
168
  function querySubToStorage(_key, sub) {
152
- var _a;
153
- const jsonSub = Object.assign({}, sub);
154
- if ((_a = sub.result) === null || _a === void 0 ? void 0 : _a.store) {
155
- jsonSub.result = Object.assign(Object.assign({}, sub.result), { store: s.toJSON(sub.result.store) });
169
+ const { result } = sub, rest = __rest(sub, ["result"]);
170
+ const jsonSub = /** @type {import('./reactorTypes.ts').QuerySubInStorage} */ (rest);
171
+ if (result) {
172
+ /** @type {import('./reactorTypes.ts').QuerySubResultInStorage} */
173
+ const jsonResult = Object.assign(Object.assign({}, result), { store: sts.toJSON(result.store), attrsStore: result.attrsStore.toJSON() });
174
+ jsonSub.result = jsonResult;
156
175
  }
157
176
  return jsonSub;
158
177
  }
@@ -297,7 +316,7 @@ class Reactor {
297
316
  }
298
317
  try {
299
318
  const txSteps = instaml.transform({
300
- attrs: this.optimisticAttrs(),
319
+ attrsStore: this.optimisticAttrs(),
301
320
  schema: this.config.schema,
302
321
  stores: Object.values(this.querySubs.currentValue).map((sub) => { var _a; return (_a = sub === null || sub === void 0 ? void 0 : sub.result) === null || _a === void 0 ? void 0 : _a.store; }),
303
322
  useDateObjects: this.config.useDateObjects,
@@ -463,7 +482,9 @@ class Reactor {
463
482
  this._initStorage(Storage);
464
483
  this._syncTable = new SyncTable_ts_1.SyncTable(this._trySendAuthed.bind(this), new Storage(this.config.appId, 'syncSubs'), {
465
484
  useDateObjects: this.config.useDateObjects,
466
- }, this._log, (triples) => s.createStore(this.attrs, triples, this.config.enableCardinalityInference, this._linkIndex, this.config.useDateObjects));
485
+ }, this._log, (triples) => {
486
+ return sts.createStore(this.ensureAttrs(), triples, this.config.enableCardinalityInference, this.config.useDateObjects);
487
+ }, () => this.ensureAttrs());
467
488
  this._oauthCallbackResponse = this._oauthLoginInit();
468
489
  // kick off a request to cache it
469
490
  this.getCurrentUser();
@@ -493,6 +514,12 @@ class Reactor {
493
514
  addEventListener('beforeunload', this._beforeUnload);
494
515
  }
495
516
  }
517
+ ensureAttrs() {
518
+ if (!this.attrs) {
519
+ throw new Error('attrs have not loaded.');
520
+ }
521
+ return this.attrs;
522
+ }
496
523
  updateSchema(schema) {
497
524
  this.config = Object.assign(Object.assign({}, this.config), { schema: schema, cardinalityInference: Boolean(schema) });
498
525
  this._linkIndex = schema ? (0, linkIndex_ts_1.createLinkIndex)(this.config.schema) : null;
@@ -516,7 +543,7 @@ class Reactor {
516
543
  serialize: querySubToStorage,
517
544
  parse: (_key, x) => querySubFromStorage(x, this.config.useDateObjects),
518
545
  // objectSize
519
- objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
546
+ objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x === null || x === void 0 ? void 0 : x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
520
547
  logger: this._log,
521
548
  preloadEntryCount: 10,
522
549
  gc: {
@@ -650,7 +677,7 @@ class Reactor {
650
677
  const pageInfo = (_d = (_c = result === null || result === void 0 ? void 0 : result[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d['page-info'];
651
678
  const aggregate = (_f = (_e = result === null || result === void 0 ? void 0 : result[0]) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f['aggregate'];
652
679
  const triples = (0, instaqlResult_js_1.extractTriples)(result);
653
- const store = s.createStore(this.attrs, triples, enableCardinalityInference, this._linkIndex, this.config.useDateObjects);
680
+ const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
654
681
  this.querySubs.updateInPlace((prev) => {
655
682
  if (!prev[hash]) {
656
683
  this._log.info('Missing value in querySubs', { hash, q });
@@ -658,6 +685,7 @@ class Reactor {
658
685
  }
659
686
  prev[hash].result = {
660
687
  store,
688
+ attrsStore: this.ensureAttrs(),
661
689
  pageInfo,
662
690
  aggregate,
663
691
  processedTxId: msg['processed-tx-id'],
@@ -692,7 +720,7 @@ class Reactor {
692
720
  this._setAttrs(attrs);
693
721
  }
694
722
  this._cleanupPendingMutationsTimeout();
695
- const rewrittenMutations = this._rewriteMutations(this.attrs, this._pendingMutations(), processedTxId);
723
+ const rewrittenMutations = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations(), processedTxId);
696
724
  if (rewrittenMutations !== this._pendingMutations()) {
697
725
  // We know we've changed the mutations to fix the attr ids and removed
698
726
  // processed attrs, so we'll persist those changes to prevent optimisticAttrs
@@ -708,19 +736,33 @@ class Reactor {
708
736
  const result = x['instaql-result'];
709
737
  const hash = (0, weakHash_ts_1.default)(q);
710
738
  const triples = (0, instaqlResult_js_1.extractTriples)(result);
711
- const store = s.createStore(this.attrs, triples, enableCardinalityInference, this._linkIndex, this.config.useDateObjects);
712
- const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
739
+ const attrsStore = this.ensureAttrs();
740
+ const store = sts.createStore(attrsStore, triples, enableCardinalityInference, this.config.useDateObjects);
741
+ const { store: newStore, attrsStore: newAttrsStore } = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
713
742
  const pageInfo = (_b = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b['page-info'];
714
743
  const aggregate = (_d = (_c = result === null || result === void 0 ? void 0 : result[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d['aggregate'];
715
- return { q, hash, store: newStore, pageInfo, aggregate };
744
+ return {
745
+ q,
746
+ hash,
747
+ store: newStore,
748
+ attrsStore: newAttrsStore,
749
+ pageInfo,
750
+ aggregate,
751
+ };
716
752
  });
717
- updates.forEach(({ hash, q, store, pageInfo, aggregate }) => {
753
+ updates.forEach(({ hash, q, store, attrsStore, pageInfo, aggregate }) => {
718
754
  this.querySubs.updateInPlace((prev) => {
719
755
  if (!prev[hash]) {
720
756
  this._log.error('Missing value in querySubs', { hash, q });
721
757
  return;
722
758
  }
723
- prev[hash].result = { store, pageInfo, aggregate, processedTxId };
759
+ prev[hash].result = {
760
+ store,
761
+ attrsStore,
762
+ pageInfo,
763
+ aggregate,
764
+ processedTxId,
765
+ };
724
766
  });
725
767
  });
726
768
  this._cleanupPendingMutationsQueries();
@@ -732,7 +774,7 @@ class Reactor {
732
774
  case 'transact-ok': {
733
775
  const { 'client-event-id': eventId, 'tx-id': txId } = msg;
734
776
  this._inFlightMutationEventIds.delete(eventId);
735
- const muts = this._rewriteMutations(this.attrs, this._pendingMutations());
777
+ const muts = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations());
736
778
  const prevMutation = muts.get(eventId);
737
779
  if (!prevMutation) {
738
780
  break;
@@ -741,11 +783,18 @@ class Reactor {
741
783
  this._updatePendingMutations((prev) => {
742
784
  prev.set(eventId, Object.assign(Object.assign({}, prev.get(eventId)), { 'tx-id': txId, confirmed: Date.now() }));
743
785
  });
744
- const newAttrs = prevMutation['tx-steps']
745
- .filter(([action, ..._args]) => action === 'add-attr')
746
- .map(([_action, attr]) => attr)
747
- .concat(Object.values(this.attrs));
748
- this._setAttrs(newAttrs);
786
+ const newAttrs = [];
787
+ for (const step of prevMutation['tx-steps']) {
788
+ if (step[0] === 'add-attr') {
789
+ const attr = step[1];
790
+ newAttrs.push(attr);
791
+ }
792
+ }
793
+ if (newAttrs.length) {
794
+ const existingAttrs = Object.values(this.ensureAttrs());
795
+ this._setAttrs([...existingAttrs, ...newAttrs]);
796
+ this._setAttrs(newAttrs);
797
+ }
749
798
  this._finishTransaction('synced', eventId);
750
799
  this._cleanupPendingMutationsTimeout();
751
800
  break;
@@ -906,10 +955,10 @@ class Reactor {
906
955
  this._completeQueryOnce(q, hash, r.dfd);
907
956
  }
908
957
  _setAttrs(attrs) {
909
- this.attrs = attrs.reduce((acc, attr) => {
958
+ this.attrs = new sts.AttrsStoreClass(attrs.reduce((acc, attr) => {
910
959
  acc[attr.id] = attr;
911
960
  return acc;
912
- }, {});
961
+ }, {}), this._linkIndex);
913
962
  this.notifyAttrsSubs();
914
963
  }
915
964
  _startQuerySub(q, hash) {
@@ -1015,6 +1064,12 @@ class Reactor {
1015
1064
  // We remove `add-attr` commands for attrs that already exist.
1016
1065
  // We update `add-triple` and `retract-triple` commands to use the
1017
1066
  // server attr-ids.
1067
+ /**
1068
+ *
1069
+ * @param {sts.AttrsStore} attrs
1070
+ * @param {any} muts
1071
+ * @param {number} [processedTxId]
1072
+ */
1018
1073
  _rewriteMutations(attrs, muts, processedTxId) {
1019
1074
  if (!attrs)
1020
1075
  return muts;
@@ -1022,12 +1077,12 @@ class Reactor {
1022
1077
  return new Map();
1023
1078
  const findExistingAttr = (attr) => {
1024
1079
  const [_, etype, label] = attr['forward-identity'];
1025
- const existing = instaml.getAttrByFwdIdentName(attrs, etype, label);
1080
+ const existing = sts.getAttrByFwdIdentName(attrs, etype, label);
1026
1081
  return existing;
1027
1082
  };
1028
1083
  const findReverseAttr = (attr) => {
1029
1084
  const [_, etype, label] = attr['forward-identity'];
1030
- const revAttr = instaml.getAttrByReverseIdentName(attrs, etype, label);
1085
+ const revAttr = sts.getAttrByReverseIdentName(attrs, etype, label);
1031
1086
  return revAttr;
1032
1087
  };
1033
1088
  const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
@@ -1090,8 +1145,11 @@ class Reactor {
1090
1145
  }
1091
1146
  // ---------------------------
1092
1147
  // Transact
1148
+ /**
1149
+ * @returns {sts.AttrsStore}
1150
+ */
1093
1151
  optimisticAttrs() {
1094
- var _a;
1152
+ var _a, _b;
1095
1153
  const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
1096
1154
  .flatMap((x) => x['tx-steps']);
1097
1155
  const deletedAttrIds = new Set(pendingMutationSteps
@@ -1104,17 +1162,22 @@ class Reactor {
1104
1162
  }
1105
1163
  else if (_action === 'update-attr' &&
1106
1164
  attr.id &&
1107
- ((_a = this.attrs) === null || _a === void 0 ? void 0 : _a[attr.id])) {
1108
- const fullAttr = Object.assign(Object.assign({}, this.attrs[attr.id]), attr);
1165
+ ((_a = this.attrs) === null || _a === void 0 ? void 0 : _a.getAttr(attr.id))) {
1166
+ const fullAttr = Object.assign(Object.assign({}, this.attrs.getAttr(attr.id)), attr);
1109
1167
  pendingAttrs.push(fullAttr);
1110
1168
  }
1111
1169
  }
1112
- const attrsWithoutDeleted = [
1113
- ...Object.values(this.attrs || {}),
1114
- ...pendingAttrs,
1115
- ].filter((a) => !deletedAttrIds.has(a.id));
1116
- const attrsRecord = Object.fromEntries(attrsWithoutDeleted.map((a) => [a.id, a]));
1117
- return attrsRecord;
1170
+ if (!deletedAttrIds.size && !pendingAttrs.length) {
1171
+ return this.attrs || new sts.AttrsStoreClass({}, this._linkIndex);
1172
+ }
1173
+ const attrs = Object.assign({}, (((_b = this.attrs) === null || _b === void 0 ? void 0 : _b.attrs) || {}));
1174
+ for (const attr of pendingAttrs) {
1175
+ attrs[attr.id] = attr;
1176
+ }
1177
+ for (const id of deletedAttrIds) {
1178
+ delete attrs[id];
1179
+ }
1180
+ return new sts.AttrsStoreClass(attrs, this._linkIndex);
1118
1181
  }
1119
1182
  /** Runs instaql on a query and a store */
1120
1183
  dataForQuery(hash) {
@@ -1139,19 +1202,21 @@ class Reactor {
1139
1202
  pendingMutationsVersion === cached.pendingMutationsVersion) {
1140
1203
  return cached;
1141
1204
  }
1142
- const { store, pageInfo, aggregate, processedTxId } = result;
1143
- const mutations = this._rewriteMutationsSorted(store.attrs, pendingMutations);
1144
- const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
1145
- const resp = (0, instaql_ts_1.default)({ store: newStore, pageInfo, aggregate }, q);
1205
+ const { store, attrsStore, pageInfo, aggregate, processedTxId } = result;
1206
+ const mutations = this._rewriteMutationsSorted(attrsStore, pendingMutations);
1207
+ const { store: newStore, attrsStore: newAttrsStore } = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
1208
+ const resp = (0, instaql_ts_1.default)({ store: newStore, attrsStore: newAttrsStore, pageInfo, aggregate }, q);
1146
1209
  return { data: resp, querySubVersion, pendingMutationsVersion };
1147
1210
  }
1148
- _applyOptimisticUpdates(store, mutations, processedTxId) {
1211
+ _applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
1149
1212
  for (const [_, mut] of mutations) {
1150
1213
  if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
1151
- store = s.transact(store, mut['tx-steps']);
1214
+ const result = sts.transact(store, attrsStore, mut['tx-steps']);
1215
+ store = result.store;
1216
+ attrsStore = result.attrsStore;
1152
1217
  }
1153
1218
  }
1154
- return store;
1219
+ return { store, attrsStore };
1155
1220
  }
1156
1221
  /** Re-compute all subscriptions */
1157
1222
  notifyAll() {
@@ -1231,7 +1296,7 @@ class Reactor {
1231
1296
  .forEach(({ eventId, q }) => {
1232
1297
  this._trySendAuthed(eventId, { op: 'add-query', q });
1233
1298
  });
1234
- const muts = this._rewriteMutationsSorted(this.attrs, this._pendingMutations());
1299
+ const muts = this._rewriteMutationsSorted(this.ensureAttrs(), this._pendingMutations());
1235
1300
  muts.forEach(([eventId, mut]) => {
1236
1301
  if (!mut['tx-id']) {
1237
1302
  this._sendMutation(eventId, mut);
@@ -1518,7 +1583,7 @@ class Reactor {
1518
1583
  subscribeAttrs(cb) {
1519
1584
  this.attrsCbs.push(cb);
1520
1585
  if (this.attrs) {
1521
- cb(this.attrs);
1586
+ cb(this.attrs.attrs);
1522
1587
  }
1523
1588
  return () => {
1524
1589
  this.attrsCbs = this.attrsCbs.filter((x) => x !== cb);