@instantdb/core 0.22.86-experimental.split-store.20178922132.1 → 0.22.87-experimental.drewh-explorer-component.20180358679.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 (57) hide show
  1. package/dist/commonjs/Reactor.d.ts +6 -20
  2. package/dist/commonjs/Reactor.d.ts.map +1 -1
  3. package/dist/commonjs/Reactor.js +42 -97
  4. package/dist/commonjs/Reactor.js.map +1 -1
  5. package/dist/commonjs/SyncTable.d.ts +1 -4
  6. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  7. package/dist/commonjs/SyncTable.js +37 -35
  8. package/dist/commonjs/SyncTable.js.map +1 -1
  9. package/dist/commonjs/instaml.d.ts +4 -17
  10. package/dist/commonjs/instaml.d.ts.map +1 -1
  11. package/dist/commonjs/instaml.js +76 -105
  12. package/dist/commonjs/instaml.js.map +1 -1
  13. package/dist/commonjs/instaql.d.ts +1 -2
  14. package/dist/commonjs/instaql.d.ts.map +1 -1
  15. package/dist/commonjs/instaql.js +63 -65
  16. package/dist/commonjs/instaql.js.map +1 -1
  17. package/dist/commonjs/store.d.ts +21 -44
  18. package/dist/commonjs/store.d.ts.map +1 -1
  19. package/dist/commonjs/store.js +69 -164
  20. package/dist/commonjs/store.js.map +1 -1
  21. package/dist/esm/Reactor.d.ts +6 -20
  22. package/dist/esm/Reactor.d.ts.map +1 -1
  23. package/dist/esm/Reactor.js +43 -98
  24. package/dist/esm/Reactor.js.map +1 -1
  25. package/dist/esm/SyncTable.d.ts +1 -4
  26. package/dist/esm/SyncTable.d.ts.map +1 -1
  27. package/dist/esm/SyncTable.js +37 -35
  28. package/dist/esm/SyncTable.js.map +1 -1
  29. package/dist/esm/instaml.d.ts +4 -17
  30. package/dist/esm/instaml.d.ts.map +1 -1
  31. package/dist/esm/instaml.js +71 -102
  32. package/dist/esm/instaml.js.map +1 -1
  33. package/dist/esm/instaql.d.ts +1 -2
  34. package/dist/esm/instaql.d.ts.map +1 -1
  35. package/dist/esm/instaql.js +63 -65
  36. package/dist/esm/instaql.js.map +1 -1
  37. package/dist/esm/store.d.ts +21 -44
  38. package/dist/esm/store.d.ts.map +1 -1
  39. package/dist/esm/store.js +69 -161
  40. package/dist/esm/store.js.map +1 -1
  41. package/dist/standalone/index.js +1364 -1536
  42. package/dist/standalone/index.umd.cjs +3 -3
  43. package/package.json +2 -2
  44. package/src/Reactor.js +58 -126
  45. package/src/SyncTable.ts +45 -85
  46. package/src/{instaml.ts → instaml.js} +95 -195
  47. package/src/instaql.ts +60 -86
  48. package/src/store.ts +79 -209
  49. package/dist/commonjs/reactorTypes.d.ts +0 -29
  50. package/dist/commonjs/reactorTypes.d.ts.map +0 -1
  51. package/dist/commonjs/reactorTypes.js +0 -3
  52. package/dist/commonjs/reactorTypes.js.map +0 -1
  53. package/dist/esm/reactorTypes.d.ts +0 -29
  54. package/dist/esm/reactorTypes.d.ts.map +0 -1
  55. package/dist/esm/reactorTypes.js +0 -2
  56. package/dist/esm/reactorTypes.js.map +0 -1
  57. package/src/reactorTypes.ts +0 -32
@@ -2,14 +2,24 @@ import { InstantDBAttr } from './attrTypes.ts';
2
2
  import { LinkIndex } from './utils/linkIndex.ts';
3
3
  type Triple = [string, string, any, number];
4
4
  type Attrs = Record<string, InstantDBAttr>;
5
+ type AttrIndexes = {
6
+ blobAttrs: Map<string, Map<string, InstantDBAttr>>;
7
+ primaryKeys: Map<string, InstantDBAttr>;
8
+ forwardIdents: Map<string, Map<string, InstantDBAttr>>;
9
+ revIdents: Map<string, Map<string, InstantDBAttr>>;
10
+ };
5
11
  export type Store = {
6
12
  eav: Map<string, Map<string, Map<any, Triple>>>;
7
13
  aev: Map<string, Map<string, Map<any, Triple>>>;
8
14
  vae: Map<any, Map<string, Map<string, Triple>>>;
9
15
  useDateObjects: boolean | null;
16
+ attrs: Attrs;
17
+ attrIndexes: AttrIndexes;
10
18
  cardinalityInference: boolean | null;
19
+ linkIndex: LinkIndex | null;
20
+ __type: 'store';
11
21
  };
12
- type StoreJsonVersion0 = {
22
+ export type StoreJson = {
13
23
  __type: 'store';
14
24
  attrs: Attrs;
15
25
  triples: Triple[];
@@ -17,55 +27,22 @@ type StoreJsonVersion0 = {
17
27
  linkIndex: LinkIndex | null;
18
28
  useDateObjects: boolean | null;
19
29
  };
20
- type StoreJsonVersion1 = {
21
- triples: Triple[];
22
- cardinalityInference: boolean | null;
23
- useDateObjects: boolean | null;
24
- version: 1;
25
- };
26
- export type StoreJson = StoreJsonVersion0 | StoreJsonVersion1;
27
- export type AttrsStoreJson = {
28
- attrs: Attrs;
29
- linkIndex: LinkIndex | null;
30
- };
31
- export declare class AttrsStore {
32
- attrs: Attrs;
33
- linkIndex: LinkIndex | null;
34
- private _blobAttrs;
35
- private _primaryKeys;
36
- private _forwardIdents;
37
- private _revIdents;
38
- constructor(attrs: Attrs, linkIndex: LinkIndex | null);
39
- resetAttrIndexes(): void;
40
- addAttr(attr: InstantDBAttr): void;
41
- deleteAttr(attrId: string): void;
42
- updateAttr(partialAttr: Partial<InstantDBAttr> & {
43
- id: string;
44
- }): void;
45
- getAttr(id: string): InstantDBAttr | undefined;
46
- get blobAttrs(): Map<string, Map<string, InstantDBAttr>>;
47
- get primaryKeys(): Map<string, InstantDBAttr>;
48
- get forwardIdents(): Map<string, Map<string, InstantDBAttr>>;
49
- get revIdents(): Map<string, Map<string, InstantDBAttr>>;
50
- toJSON(): AttrsStoreJson;
51
- }
52
30
  export declare function isBlob(attr: InstantDBAttr): boolean;
53
31
  export declare function getInMap(obj: any, path: any): any;
54
- export declare function toJSON(store: Store): StoreJsonVersion1;
55
- export declare function fromJSON(attrsStore: AttrsStore, storeJSON: StoreJson): Store;
56
- export declare function attrsStoreFromJSON(attrsStoreJSON: AttrsStoreJson | null, storeJSON: StoreJson | null): AttrsStore | undefined;
32
+ export declare function toJSON(store: Store): StoreJson;
33
+ export declare function fromJSON(storeJSON: StoreJson): Store;
57
34
  export declare function hasTriple(store: Store, [e, a, v]: [string, string, any]): boolean;
58
35
  export declare function hasEntity(store: Store, e: string): boolean;
59
- export declare function createStore(attrsStore: AttrsStore, triples: Triple[], enableCardinalityInference: boolean | null, useDateObjects: boolean | null): Store;
60
- export declare function retractTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple): void;
61
- export declare function addTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple): void;
36
+ export declare function createStore(attrs: Record<string, InstantDBAttr>, triples: Triple[], enableCardinalityInference: boolean | null, linkIndex: LinkIndex | null, useDateObjects: boolean | null): Store;
37
+ export declare function retractTriple(store: Store, rawTriple: Triple): void;
38
+ export declare function addTriple(store: Store, rawTriple: Triple): void;
62
39
  export declare function allMapValues(m: any, level: any, res?: any[]): any[];
63
40
  export declare function getTriples(store: any, [e, a, v]: [any, any, any]): any[];
64
41
  export declare function getAsObject(store: Store, attrs: Map<string, InstantDBAttr> | undefined, e: string): {};
65
- export declare function getAttrByFwdIdentName(attrsStore: AttrsStore, inputEtype: string, inputLabel: string): InstantDBAttr | undefined;
66
- export declare function getAttrByReverseIdentName(attrsStore: AttrsStore, inputEtype: string, inputLabel: string): InstantDBAttr | undefined;
67
- export declare function getBlobAttrs(attrsStore: AttrsStore, etype: string): Map<string, InstantDBAttr> | undefined;
68
- export declare function getPrimaryKeyAttr(attrsStore: AttrsStore, etype: string): InstantDBAttr | undefined;
69
- export declare function transact(store: Store, attrsStore: AttrsStore, txSteps: any): Store;
42
+ export declare function getAttrByFwdIdentName(store: Store, inputEtype: string, inputLabel: string): InstantDBAttr | undefined;
43
+ export declare function getAttrByReverseIdentName(store: Store, inputEtype: string, inputLabel: string): InstantDBAttr | undefined;
44
+ export declare function getBlobAttrs(store: Store, etype: string): Map<string, InstantDBAttr> | undefined;
45
+ export declare function getPrimaryKeyAttr(store: Store, etype: string): InstantDBAttr | undefined;
46
+ export declare function transact(store: Store, txSteps: any): Store;
70
47
  export {};
71
48
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file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
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttrsStore = void 0;
4
3
  exports.isBlob = isBlob;
5
4
  exports.getInMap = getInMap;
6
5
  exports.toJSON = toJSON;
7
6
  exports.fromJSON = fromJSON;
8
- exports.attrsStoreFromJSON = attrsStoreFromJSON;
9
7
  exports.hasTriple = hasTriple;
10
8
  exports.hasEntity = hasEntity;
11
9
  exports.createStore = createStore;
@@ -22,103 +20,6 @@ exports.transact = transact;
22
20
  const mutative_1 = require("mutative");
23
21
  const object_js_1 = require("./utils/object.js");
24
22
  const dates_ts_1 = require("./utils/dates.js");
25
- class AttrsStore {
26
- constructor(attrs, linkIndex) {
27
- this._blobAttrs = null;
28
- this._primaryKeys = null;
29
- this._forwardIdents = null;
30
- this._revIdents = null;
31
- console.log('attrs init', new Error('trace'));
32
- this.attrs = attrs;
33
- this.linkIndex = linkIndex;
34
- }
35
- resetAttrIndexes() {
36
- this._blobAttrs = null;
37
- this._primaryKeys = null;
38
- this._forwardIdents = null;
39
- this._revIdents = null;
40
- }
41
- addAttr(attr) {
42
- this.attrs[attr.id] = attr;
43
- this.resetAttrIndexes();
44
- }
45
- deleteAttr(attrId) {
46
- delete this.attrs[attrId];
47
- this.resetAttrIndexes();
48
- }
49
- updateAttr(partialAttr) {
50
- const attr = this.attrs[partialAttr.id];
51
- if (!attr)
52
- return;
53
- this.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
54
- this.resetAttrIndexes();
55
- }
56
- getAttr(id) {
57
- return this.attrs[id];
58
- }
59
- // XXX: Might be better to create all of the indexes at once as soon as someone
60
- // requests one index
61
- get blobAttrs() {
62
- if (this._blobAttrs) {
63
- return this._blobAttrs;
64
- }
65
- console.log('blobAttrs');
66
- this._blobAttrs = new Map();
67
- for (const attr of Object.values(this.attrs)) {
68
- if (isBlob(attr)) {
69
- const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
70
- setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
71
- }
72
- }
73
- return this._blobAttrs;
74
- }
75
- get primaryKeys() {
76
- if (this._primaryKeys) {
77
- return this._primaryKeys;
78
- }
79
- console.log('primayKeys');
80
- this._primaryKeys = new Map();
81
- for (const attr of Object.values(this.attrs)) {
82
- if (attr['primary?']) {
83
- const [_, fwdEtype] = attr['forward-identity'];
84
- setInMap(this._primaryKeys, [fwdEtype], attr);
85
- }
86
- }
87
- return this._primaryKeys;
88
- }
89
- get forwardIdents() {
90
- if (this._forwardIdents) {
91
- return this._forwardIdents;
92
- }
93
- console.log('fwdIdents');
94
- this._forwardIdents = new Map();
95
- for (const attr of Object.values(this.attrs)) {
96
- const fwdIdent = attr['forward-identity'];
97
- const [_, fwdEtype, fwdLabel] = fwdIdent;
98
- setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
99
- }
100
- return this._forwardIdents;
101
- }
102
- get revIdents() {
103
- if (this._revIdents) {
104
- return this._revIdents;
105
- }
106
- console.log('revIdents');
107
- this._revIdents = new Map();
108
- for (const attr of Object.values(this.attrs)) {
109
- const revIdent = attr['reverse-identity'];
110
- if (revIdent) {
111
- const [_, revEtype, revLabel] = revIdent;
112
- setInMap(this._revIdents, [revEtype, revLabel], attr);
113
- }
114
- }
115
- return this._revIdents;
116
- }
117
- toJSON() {
118
- return { attrs: this.attrs, linkIndex: this.linkIndex };
119
- }
120
- }
121
- exports.AttrsStore = AttrsStore;
122
23
  function hasEA(attr) {
123
24
  return attr['cardinality'] === 'one';
124
25
  }
@@ -164,15 +65,15 @@ function setInMap(m, path, value) {
164
65
  function isDateAttr(attr) {
165
66
  return attr['checked-data-type'] === 'date';
166
67
  }
167
- function createTripleIndexes(attrsStore, triples, useDateObjects) {
68
+ function createTripleIndexes(attrs, triples, useDateObjects) {
168
69
  const eav = new Map();
169
70
  const aev = new Map();
170
71
  const vae = new Map();
171
72
  for (const triple of triples) {
172
- let [eid, aid, v] = triple;
173
- const attr = attrsStore.getAttr(aid);
73
+ let [eid, aid, v, t] = triple;
74
+ const attr = getAttr(attrs, aid);
174
75
  if (!attr) {
175
- console.warn('no such attr', aid, eid);
76
+ console.warn('no such attr', eid, attrs);
176
77
  continue;
177
78
  }
178
79
  if (attr['checked-data-type'] === 'date' && useDateObjects) {
@@ -212,22 +113,16 @@ function createAttrIndexes(attrs) {
212
113
  }
213
114
  function toJSON(store) {
214
115
  return {
116
+ __type: store.__type,
117
+ attrs: store.attrs,
215
118
  triples: allMapValues(store.eav, 3),
216
119
  cardinalityInference: store.cardinalityInference,
120
+ linkIndex: store.linkIndex,
217
121
  useDateObjects: store.useDateObjects,
218
- version: 1,
219
122
  };
220
123
  }
221
- function fromJSON(attrsStore, storeJSON) {
222
- return createStore(attrsStore, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.useDateObjects);
223
- }
224
- function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
225
- if (attrsStoreJSON) {
226
- return new AttrsStore(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
227
- }
228
- if (storeJSON && '__type' in storeJSON) {
229
- return new AttrsStore(storeJSON.attrs, storeJSON.linkIndex);
230
- }
124
+ function fromJSON(storeJSON) {
125
+ return createStore(storeJSON.attrs, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.linkIndex, storeJSON.useDateObjects);
231
126
  }
232
127
  function hasTriple(store, [e, a, v]) {
233
128
  return getInMap(store.eav, [e, a, v]) !== undefined;
@@ -235,10 +130,17 @@ function hasTriple(store, [e, a, v]) {
235
130
  function hasEntity(store, e) {
236
131
  return getInMap(store.eav, [e]) !== undefined;
237
132
  }
238
- function createStore(attrsStore, triples, enableCardinalityInference, useDateObjects) {
239
- const store = createTripleIndexes(attrsStore, triples, useDateObjects);
240
- store.cardinalityInference = enableCardinalityInference;
133
+ function resetAttrIndexes(store) {
134
+ store.attrIndexes = createAttrIndexes(store.attrs);
135
+ }
136
+ function createStore(attrs, triples, enableCardinalityInference, linkIndex, useDateObjects) {
137
+ const store = createTripleIndexes(attrs, triples, useDateObjects);
241
138
  store.useDateObjects = useDateObjects;
139
+ store.attrs = attrs;
140
+ store.attrIndexes = createAttrIndexes(attrs);
141
+ store.cardinalityInference = enableCardinalityInference;
142
+ store.linkIndex = linkIndex;
143
+ store.__type = 'store';
242
144
  return store;
243
145
  }
244
146
  // We may have local triples with lookup refs in them,
@@ -295,13 +197,13 @@ function resolveLookupRefs(store, triple) {
295
197
  return [eid, ...rest];
296
198
  }
297
199
  }
298
- function retractTriple(store, attrsStore, rawTriple) {
200
+ function retractTriple(store, rawTriple) {
299
201
  const triple = resolveLookupRefs(store, rawTriple);
300
202
  if (!triple) {
301
203
  return;
302
204
  }
303
205
  const [eid, aid, v] = triple;
304
- const attr = attrsStore.getAttr(aid);
206
+ const attr = getAttr(store.attrs, aid);
305
207
  if (!attr) {
306
208
  return;
307
209
  }
@@ -342,14 +244,14 @@ function getCreatedAt(store, attr, triple) {
342
244
  */
343
245
  return createdAt || Date.now() * 10 + _seed++;
344
246
  }
345
- function addTriple(store, attrsStore, rawTriple) {
247
+ function addTriple(store, rawTriple) {
346
248
  var _a;
347
249
  const triple = resolveLookupRefs(store, rawTriple);
348
250
  if (!triple) {
349
251
  return;
350
252
  }
351
253
  let [eid, aid, v] = triple;
352
- const attr = attrsStore.getAttr(aid);
254
+ const attr = getAttr(store.attrs, aid);
353
255
  if (!attr) {
354
256
  // (XXX): Due to the way we're handling attrs, it's
355
257
  // possible to enter a state where we receive a triple without an attr.
@@ -378,14 +280,14 @@ function addTriple(store, attrsStore, rawTriple) {
378
280
  setInMap(store.vae, [v, aid, eid], enhancedTriple);
379
281
  }
380
282
  }
381
- function mergeTriple(store, attrsStore, rawTriple) {
283
+ function mergeTriple(store, rawTriple) {
382
284
  var _a;
383
285
  const triple = resolveLookupRefs(store, rawTriple);
384
286
  if (!triple) {
385
287
  return;
386
288
  }
387
289
  const [eid, aid, update] = triple;
388
- const attr = attrsStore.getAttr(aid);
290
+ const attr = getAttr(store.attrs, aid);
389
291
  if (!attr)
390
292
  return;
391
293
  if (!isBlob(attr))
@@ -406,7 +308,7 @@ function mergeTriple(store, attrsStore, rawTriple) {
406
308
  ];
407
309
  setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
408
310
  }
409
- function deleteEntity(store, attrsStore, args) {
311
+ function deleteEntity(store, args) {
410
312
  var _a, _b;
411
313
  const [lookup, etype] = args;
412
314
  const triple = resolveLookupRefs(store, [lookup]);
@@ -418,10 +320,10 @@ function deleteEntity(store, attrsStore, args) {
418
320
  const eMap = store.eav.get(id);
419
321
  if (eMap) {
420
322
  for (const a of eMap.keys()) {
421
- const attr = attrsStore.getAttr(a);
323
+ const attr = store.attrs[a];
422
324
  // delete cascade refs
423
325
  if (attr && attr['on-delete-reverse'] === 'cascade') {
424
- allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => { var _a; return deleteEntity(store, attrsStore, [v, (_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]]); });
326
+ allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => { var _a; return deleteEntity(store, [v, (_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]]); });
425
327
  }
426
328
  if (
427
329
  // Fall back to deleting everything if we've rehydrated tx-steps from
@@ -446,7 +348,7 @@ function deleteEntity(store, attrsStore, args) {
446
348
  vaeTriples.forEach((triple) => {
447
349
  var _a, _b, _c;
448
350
  const [e, a, v] = triple;
449
- const attr = attrsStore.getAttr(a);
351
+ const attr = store.attrs[a];
450
352
  if (!etype || !attr || ((_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
451
353
  deleteInMap(store.eav, [e, a, v]);
452
354
  deleteInMap(store.aev, [a, e, v]);
@@ -455,7 +357,7 @@ function deleteEntity(store, attrsStore, args) {
455
357
  if (attr &&
456
358
  attr['on-delete'] === 'cascade' &&
457
359
  ((_b = attr['reverse-identity']) === null || _b === void 0 ? void 0 : _b[1]) === etype) {
458
- deleteEntity(store, attrsStore, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
360
+ deleteEntity(store, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
459
361
  }
460
362
  });
461
363
  }
@@ -471,55 +373,58 @@ function deleteEntity(store, attrsStore, args) {
471
373
  // * We could batch this reset at the end
472
374
  // * We could add an ave index for all triples, so removing the
473
375
  // right triples is easy and fast.
474
- function resetIndexMap(store, attrsStore, newTriples) {
475
- const newIndexMap = createTripleIndexes(attrsStore, newTriples, store.useDateObjects);
376
+ function resetIndexMap(store, newTriples) {
377
+ const newIndexMap = createTripleIndexes(store.attrs, newTriples, store.useDateObjects);
476
378
  Object.keys(newIndexMap).forEach((key) => {
477
379
  store[key] = newIndexMap[key];
478
380
  });
479
381
  }
480
- function addAttr(attrsStore, [attr]) {
481
- attrsStore.addAttr(attr);
382
+ function addAttr(store, [attr]) {
383
+ store.attrs[attr.id] = attr;
384
+ resetAttrIndexes(store);
482
385
  }
483
386
  function getAllTriples(store) {
484
387
  return allMapValues(store.eav, 3);
485
388
  }
486
- function deleteAttr(store, attrsStore, [id]) {
487
- if (!attrsStore.getAttr(id))
389
+ function deleteAttr(store, [id]) {
390
+ if (!store.attrs[id])
488
391
  return;
489
392
  const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
490
- attrsStore.deleteAttr(id);
491
- resetIndexMap(store, attrsStore, newTriples);
393
+ delete store.attrs[id];
394
+ resetAttrIndexes(store);
395
+ resetIndexMap(store, newTriples);
492
396
  }
493
- function updateAttr(store, attrsStore, [partialAttr]) {
494
- const attr = attrsStore.getAttr(partialAttr.id);
397
+ function updateAttr(store, [partialAttr]) {
398
+ const attr = store.attrs[partialAttr.id];
495
399
  if (!attr)
496
400
  return;
497
- attrsStore.updateAttr(partialAttr);
498
- resetIndexMap(store, attrsStore, getAllTriples(store));
401
+ store.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
402
+ resetAttrIndexes(store);
403
+ resetIndexMap(store, getAllTriples(store));
499
404
  }
500
- function applyTxStep(store, attrsStore, txStep) {
405
+ function applyTxStep(store, txStep) {
501
406
  const [action, ...args] = txStep;
502
407
  switch (action) {
503
408
  case 'add-triple':
504
- addTriple(store, attrsStore, args);
409
+ addTriple(store, args);
505
410
  break;
506
411
  case 'deep-merge-triple':
507
- mergeTriple(store, attrsStore, args);
412
+ mergeTriple(store, args);
508
413
  break;
509
414
  case 'retract-triple':
510
- retractTriple(store, attrsStore, args);
415
+ retractTriple(store, args);
511
416
  break;
512
417
  case 'delete-entity':
513
- deleteEntity(store, attrsStore, args);
418
+ deleteEntity(store, args);
514
419
  break;
515
420
  case 'add-attr':
516
- addAttr(attrsStore, args);
421
+ addAttr(store, args);
517
422
  break;
518
423
  case 'delete-attr':
519
- deleteAttr(store, attrsStore, args);
424
+ deleteAttr(store, args);
520
425
  break;
521
426
  case 'update-attr':
522
- updateAttr(store, attrsStore, args);
427
+ updateAttr(store, args);
523
428
  break;
524
429
  case 'restore-attr':
525
430
  break;
@@ -682,32 +587,32 @@ function getAsObject(store, attrs, e) {
682
587
  }
683
588
  return obj;
684
589
  }
685
- function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
590
+ function getAttrByFwdIdentName(store, inputEtype, inputLabel) {
686
591
  var _a;
687
- return (_a = attrsStore.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
592
+ return (_a = store.attrIndexes.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
688
593
  }
689
- function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
594
+ function getAttrByReverseIdentName(store, inputEtype, inputLabel) {
690
595
  var _a;
691
- return (_a = attrsStore.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
596
+ return (_a = store.attrIndexes.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
692
597
  }
693
- function getBlobAttrs(attrsStore, etype) {
694
- return attrsStore.blobAttrs.get(etype);
598
+ function getBlobAttrs(store, etype) {
599
+ return store.attrIndexes.blobAttrs.get(etype);
695
600
  }
696
- function getPrimaryKeyAttr(attrsStore, etype) {
601
+ function getPrimaryKeyAttr(store, etype) {
697
602
  var _a;
698
- const fromPrimary = attrsStore.primaryKeys.get(etype);
603
+ const fromPrimary = store.attrIndexes.primaryKeys.get(etype);
699
604
  if (fromPrimary) {
700
605
  return fromPrimary;
701
606
  }
702
- return (_a = attrsStore.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
607
+ return (_a = store.attrIndexes.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
703
608
  }
704
- function findTriple(store, attrsStore, rawTriple) {
609
+ function findTriple(store, rawTriple) {
705
610
  const triple = resolveLookupRefs(store, rawTriple);
706
611
  if (!triple) {
707
612
  return;
708
613
  }
709
614
  const [eid, aid, v] = triple;
710
- const attr = attrsStore.getAttr(aid);
615
+ const attr = getAttr(store.attrs, aid);
711
616
  if (!attr) {
712
617
  // (XXX): Due to the way we're handling attrs, it's
713
618
  // possible to enter a state where we receive a triple without an attr.
@@ -717,7 +622,7 @@ function findTriple(store, attrsStore, rawTriple) {
717
622
  }
718
623
  return getInMap(store.eav, [eid, aid]);
719
624
  }
720
- function transact(store, attrsStore, txSteps) {
625
+ function transact(store, txSteps) {
721
626
  const txStepsFiltered = txSteps.filter(([action, eid, attrId, value, opts]) => {
722
627
  if (action !== 'add-triple' && action !== 'deep-merge-triple') {
723
628
  return true;
@@ -727,10 +632,10 @@ function transact(store, attrsStore, txSteps) {
727
632
  return true;
728
633
  }
729
634
  let exists = false;
730
- const attr = attrsStore.getAttr(attrId);
635
+ const attr = getAttr(store.attrs, attrId);
731
636
  if (attr) {
732
- const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
733
- exists = !!findTriple(store, attrsStore, [
637
+ const idAttr = getPrimaryKeyAttr(store, attr['forward-identity'][1]);
638
+ exists = !!findTriple(store, [
734
639
  eid,
735
640
  idAttr === null || idAttr === void 0 ? void 0 : idAttr.id,
736
641
  eid,
@@ -746,7 +651,7 @@ function transact(store, attrsStore, txSteps) {
746
651
  });
747
652
  return (0, mutative_1.create)(store, (draft) => {
748
653
  txStepsFiltered.forEach((txStep) => {
749
- applyTxStep(draft, attrsStore, txStep);
654
+ applyTxStep(draft, txStep);
750
655
  });
751
656
  });
752
657
  }