@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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ED
@@ -1,102 +1,6 @@
1
1
  import { create } from 'mutative';
2
2
  import { immutableDeepMerge } from './utils/object.js';
3
3
  import { coerceToDate } from "./utils/dates.js";
4
- export class AttrsStore {
5
- constructor(attrs, linkIndex) {
6
- this._blobAttrs = null;
7
- this._primaryKeys = null;
8
- this._forwardIdents = null;
9
- this._revIdents = null;
10
- console.log('attrs init', new Error('trace'));
11
- this.attrs = attrs;
12
- this.linkIndex = linkIndex;
13
- }
14
- resetAttrIndexes() {
15
- this._blobAttrs = null;
16
- this._primaryKeys = null;
17
- this._forwardIdents = null;
18
- this._revIdents = null;
19
- }
20
- addAttr(attr) {
21
- this.attrs[attr.id] = attr;
22
- this.resetAttrIndexes();
23
- }
24
- deleteAttr(attrId) {
25
- delete this.attrs[attrId];
26
- this.resetAttrIndexes();
27
- }
28
- updateAttr(partialAttr) {
29
- const attr = this.attrs[partialAttr.id];
30
- if (!attr)
31
- return;
32
- this.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
33
- this.resetAttrIndexes();
34
- }
35
- getAttr(id) {
36
- return this.attrs[id];
37
- }
38
- // XXX: Might be better to create all of the indexes at once as soon as someone
39
- // requests one index
40
- get blobAttrs() {
41
- if (this._blobAttrs) {
42
- return this._blobAttrs;
43
- }
44
- console.log('blobAttrs');
45
- this._blobAttrs = new Map();
46
- for (const attr of Object.values(this.attrs)) {
47
- if (isBlob(attr)) {
48
- const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
49
- setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
50
- }
51
- }
52
- return this._blobAttrs;
53
- }
54
- get primaryKeys() {
55
- if (this._primaryKeys) {
56
- return this._primaryKeys;
57
- }
58
- console.log('primayKeys');
59
- this._primaryKeys = new Map();
60
- for (const attr of Object.values(this.attrs)) {
61
- if (attr['primary?']) {
62
- const [_, fwdEtype] = attr['forward-identity'];
63
- setInMap(this._primaryKeys, [fwdEtype], attr);
64
- }
65
- }
66
- return this._primaryKeys;
67
- }
68
- get forwardIdents() {
69
- if (this._forwardIdents) {
70
- return this._forwardIdents;
71
- }
72
- console.log('fwdIdents');
73
- this._forwardIdents = new Map();
74
- for (const attr of Object.values(this.attrs)) {
75
- const fwdIdent = attr['forward-identity'];
76
- const [_, fwdEtype, fwdLabel] = fwdIdent;
77
- setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
78
- }
79
- return this._forwardIdents;
80
- }
81
- get revIdents() {
82
- if (this._revIdents) {
83
- return this._revIdents;
84
- }
85
- console.log('revIdents');
86
- this._revIdents = new Map();
87
- for (const attr of Object.values(this.attrs)) {
88
- const revIdent = attr['reverse-identity'];
89
- if (revIdent) {
90
- const [_, revEtype, revLabel] = revIdent;
91
- setInMap(this._revIdents, [revEtype, revLabel], attr);
92
- }
93
- }
94
- return this._revIdents;
95
- }
96
- toJSON() {
97
- return { attrs: this.attrs, linkIndex: this.linkIndex };
98
- }
99
- }
100
4
  function hasEA(attr) {
101
5
  return attr['cardinality'] === 'one';
102
6
  }
@@ -142,15 +46,15 @@ function setInMap(m, path, value) {
142
46
  function isDateAttr(attr) {
143
47
  return attr['checked-data-type'] === 'date';
144
48
  }
145
- function createTripleIndexes(attrsStore, triples, useDateObjects) {
49
+ function createTripleIndexes(attrs, triples, useDateObjects) {
146
50
  const eav = new Map();
147
51
  const aev = new Map();
148
52
  const vae = new Map();
149
53
  for (const triple of triples) {
150
- let [eid, aid, v] = triple;
151
- const attr = attrsStore.getAttr(aid);
54
+ let [eid, aid, v, t] = triple;
55
+ const attr = getAttr(attrs, aid);
152
56
  if (!attr) {
153
- console.warn('no such attr', aid, eid);
57
+ console.warn('no such attr', eid, attrs);
154
58
  continue;
155
59
  }
156
60
  if (attr['checked-data-type'] === 'date' && useDateObjects) {
@@ -190,22 +94,16 @@ function createAttrIndexes(attrs) {
190
94
  }
191
95
  export function toJSON(store) {
192
96
  return {
97
+ __type: store.__type,
98
+ attrs: store.attrs,
193
99
  triples: allMapValues(store.eav, 3),
194
100
  cardinalityInference: store.cardinalityInference,
101
+ linkIndex: store.linkIndex,
195
102
  useDateObjects: store.useDateObjects,
196
- version: 1,
197
103
  };
198
104
  }
199
- export function fromJSON(attrsStore, storeJSON) {
200
- return createStore(attrsStore, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.useDateObjects);
201
- }
202
- export function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
203
- if (attrsStoreJSON) {
204
- return new AttrsStore(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
205
- }
206
- if (storeJSON && '__type' in storeJSON) {
207
- return new AttrsStore(storeJSON.attrs, storeJSON.linkIndex);
208
- }
105
+ export function fromJSON(storeJSON) {
106
+ return createStore(storeJSON.attrs, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.linkIndex, storeJSON.useDateObjects);
209
107
  }
210
108
  export function hasTriple(store, [e, a, v]) {
211
109
  return getInMap(store.eav, [e, a, v]) !== undefined;
@@ -213,10 +111,17 @@ export function hasTriple(store, [e, a, v]) {
213
111
  export function hasEntity(store, e) {
214
112
  return getInMap(store.eav, [e]) !== undefined;
215
113
  }
216
- export function createStore(attrsStore, triples, enableCardinalityInference, useDateObjects) {
217
- const store = createTripleIndexes(attrsStore, triples, useDateObjects);
218
- store.cardinalityInference = enableCardinalityInference;
114
+ function resetAttrIndexes(store) {
115
+ store.attrIndexes = createAttrIndexes(store.attrs);
116
+ }
117
+ export function createStore(attrs, triples, enableCardinalityInference, linkIndex, useDateObjects) {
118
+ const store = createTripleIndexes(attrs, triples, useDateObjects);
219
119
  store.useDateObjects = useDateObjects;
120
+ store.attrs = attrs;
121
+ store.attrIndexes = createAttrIndexes(attrs);
122
+ store.cardinalityInference = enableCardinalityInference;
123
+ store.linkIndex = linkIndex;
124
+ store.__type = 'store';
220
125
  return store;
221
126
  }
222
127
  // We may have local triples with lookup refs in them,
@@ -273,13 +178,13 @@ function resolveLookupRefs(store, triple) {
273
178
  return [eid, ...rest];
274
179
  }
275
180
  }
276
- export function retractTriple(store, attrsStore, rawTriple) {
181
+ export function retractTriple(store, rawTriple) {
277
182
  const triple = resolveLookupRefs(store, rawTriple);
278
183
  if (!triple) {
279
184
  return;
280
185
  }
281
186
  const [eid, aid, v] = triple;
282
- const attr = attrsStore.getAttr(aid);
187
+ const attr = getAttr(store.attrs, aid);
283
188
  if (!attr) {
284
189
  return;
285
190
  }
@@ -320,14 +225,14 @@ function getCreatedAt(store, attr, triple) {
320
225
  */
321
226
  return createdAt || Date.now() * 10 + _seed++;
322
227
  }
323
- export function addTriple(store, attrsStore, rawTriple) {
228
+ export function addTriple(store, rawTriple) {
324
229
  var _a;
325
230
  const triple = resolveLookupRefs(store, rawTriple);
326
231
  if (!triple) {
327
232
  return;
328
233
  }
329
234
  let [eid, aid, v] = triple;
330
- const attr = attrsStore.getAttr(aid);
235
+ const attr = getAttr(store.attrs, aid);
331
236
  if (!attr) {
332
237
  // (XXX): Due to the way we're handling attrs, it's
333
238
  // possible to enter a state where we receive a triple without an attr.
@@ -356,14 +261,14 @@ export function addTriple(store, attrsStore, rawTriple) {
356
261
  setInMap(store.vae, [v, aid, eid], enhancedTriple);
357
262
  }
358
263
  }
359
- function mergeTriple(store, attrsStore, rawTriple) {
264
+ function mergeTriple(store, rawTriple) {
360
265
  var _a;
361
266
  const triple = resolveLookupRefs(store, rawTriple);
362
267
  if (!triple) {
363
268
  return;
364
269
  }
365
270
  const [eid, aid, update] = triple;
366
- const attr = attrsStore.getAttr(aid);
271
+ const attr = getAttr(store.attrs, aid);
367
272
  if (!attr)
368
273
  return;
369
274
  if (!isBlob(attr))
@@ -384,7 +289,7 @@ function mergeTriple(store, attrsStore, rawTriple) {
384
289
  ];
385
290
  setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
386
291
  }
387
- function deleteEntity(store, attrsStore, args) {
292
+ function deleteEntity(store, args) {
388
293
  var _a, _b;
389
294
  const [lookup, etype] = args;
390
295
  const triple = resolveLookupRefs(store, [lookup]);
@@ -396,10 +301,10 @@ function deleteEntity(store, attrsStore, args) {
396
301
  const eMap = store.eav.get(id);
397
302
  if (eMap) {
398
303
  for (const a of eMap.keys()) {
399
- const attr = attrsStore.getAttr(a);
304
+ const attr = store.attrs[a];
400
305
  // delete cascade refs
401
306
  if (attr && attr['on-delete-reverse'] === 'cascade') {
402
- 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]]); });
307
+ 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]]); });
403
308
  }
404
309
  if (
405
310
  // Fall back to deleting everything if we've rehydrated tx-steps from
@@ -424,7 +329,7 @@ function deleteEntity(store, attrsStore, args) {
424
329
  vaeTriples.forEach((triple) => {
425
330
  var _a, _b, _c;
426
331
  const [e, a, v] = triple;
427
- const attr = attrsStore.getAttr(a);
332
+ const attr = store.attrs[a];
428
333
  if (!etype || !attr || ((_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
429
334
  deleteInMap(store.eav, [e, a, v]);
430
335
  deleteInMap(store.aev, [a, e, v]);
@@ -433,7 +338,7 @@ function deleteEntity(store, attrsStore, args) {
433
338
  if (attr &&
434
339
  attr['on-delete'] === 'cascade' &&
435
340
  ((_b = attr['reverse-identity']) === null || _b === void 0 ? void 0 : _b[1]) === etype) {
436
- deleteEntity(store, attrsStore, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
341
+ deleteEntity(store, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
437
342
  }
438
343
  });
439
344
  }
@@ -449,55 +354,58 @@ function deleteEntity(store, attrsStore, args) {
449
354
  // * We could batch this reset at the end
450
355
  // * We could add an ave index for all triples, so removing the
451
356
  // right triples is easy and fast.
452
- function resetIndexMap(store, attrsStore, newTriples) {
453
- const newIndexMap = createTripleIndexes(attrsStore, newTriples, store.useDateObjects);
357
+ function resetIndexMap(store, newTriples) {
358
+ const newIndexMap = createTripleIndexes(store.attrs, newTriples, store.useDateObjects);
454
359
  Object.keys(newIndexMap).forEach((key) => {
455
360
  store[key] = newIndexMap[key];
456
361
  });
457
362
  }
458
- function addAttr(attrsStore, [attr]) {
459
- attrsStore.addAttr(attr);
363
+ function addAttr(store, [attr]) {
364
+ store.attrs[attr.id] = attr;
365
+ resetAttrIndexes(store);
460
366
  }
461
367
  function getAllTriples(store) {
462
368
  return allMapValues(store.eav, 3);
463
369
  }
464
- function deleteAttr(store, attrsStore, [id]) {
465
- if (!attrsStore.getAttr(id))
370
+ function deleteAttr(store, [id]) {
371
+ if (!store.attrs[id])
466
372
  return;
467
373
  const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
468
- attrsStore.deleteAttr(id);
469
- resetIndexMap(store, attrsStore, newTriples);
374
+ delete store.attrs[id];
375
+ resetAttrIndexes(store);
376
+ resetIndexMap(store, newTriples);
470
377
  }
471
- function updateAttr(store, attrsStore, [partialAttr]) {
472
- const attr = attrsStore.getAttr(partialAttr.id);
378
+ function updateAttr(store, [partialAttr]) {
379
+ const attr = store.attrs[partialAttr.id];
473
380
  if (!attr)
474
381
  return;
475
- attrsStore.updateAttr(partialAttr);
476
- resetIndexMap(store, attrsStore, getAllTriples(store));
382
+ store.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
383
+ resetAttrIndexes(store);
384
+ resetIndexMap(store, getAllTriples(store));
477
385
  }
478
- function applyTxStep(store, attrsStore, txStep) {
386
+ function applyTxStep(store, txStep) {
479
387
  const [action, ...args] = txStep;
480
388
  switch (action) {
481
389
  case 'add-triple':
482
- addTriple(store, attrsStore, args);
390
+ addTriple(store, args);
483
391
  break;
484
392
  case 'deep-merge-triple':
485
- mergeTriple(store, attrsStore, args);
393
+ mergeTriple(store, args);
486
394
  break;
487
395
  case 'retract-triple':
488
- retractTriple(store, attrsStore, args);
396
+ retractTriple(store, args);
489
397
  break;
490
398
  case 'delete-entity':
491
- deleteEntity(store, attrsStore, args);
399
+ deleteEntity(store, args);
492
400
  break;
493
401
  case 'add-attr':
494
- addAttr(attrsStore, args);
402
+ addAttr(store, args);
495
403
  break;
496
404
  case 'delete-attr':
497
- deleteAttr(store, attrsStore, args);
405
+ deleteAttr(store, args);
498
406
  break;
499
407
  case 'update-attr':
500
- updateAttr(store, attrsStore, args);
408
+ updateAttr(store, args);
501
409
  break;
502
410
  case 'restore-attr':
503
411
  break;
@@ -660,32 +568,32 @@ export function getAsObject(store, attrs, e) {
660
568
  }
661
569
  return obj;
662
570
  }
663
- export function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
571
+ export function getAttrByFwdIdentName(store, inputEtype, inputLabel) {
664
572
  var _a;
665
- return (_a = attrsStore.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
573
+ return (_a = store.attrIndexes.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
666
574
  }
667
- export function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
575
+ export function getAttrByReverseIdentName(store, inputEtype, inputLabel) {
668
576
  var _a;
669
- return (_a = attrsStore.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
577
+ return (_a = store.attrIndexes.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
670
578
  }
671
- export function getBlobAttrs(attrsStore, etype) {
672
- return attrsStore.blobAttrs.get(etype);
579
+ export function getBlobAttrs(store, etype) {
580
+ return store.attrIndexes.blobAttrs.get(etype);
673
581
  }
674
- export function getPrimaryKeyAttr(attrsStore, etype) {
582
+ export function getPrimaryKeyAttr(store, etype) {
675
583
  var _a;
676
- const fromPrimary = attrsStore.primaryKeys.get(etype);
584
+ const fromPrimary = store.attrIndexes.primaryKeys.get(etype);
677
585
  if (fromPrimary) {
678
586
  return fromPrimary;
679
587
  }
680
- return (_a = attrsStore.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
588
+ return (_a = store.attrIndexes.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
681
589
  }
682
- function findTriple(store, attrsStore, rawTriple) {
590
+ function findTriple(store, rawTriple) {
683
591
  const triple = resolveLookupRefs(store, rawTriple);
684
592
  if (!triple) {
685
593
  return;
686
594
  }
687
595
  const [eid, aid, v] = triple;
688
- const attr = attrsStore.getAttr(aid);
596
+ const attr = getAttr(store.attrs, aid);
689
597
  if (!attr) {
690
598
  // (XXX): Due to the way we're handling attrs, it's
691
599
  // possible to enter a state where we receive a triple without an attr.
@@ -695,7 +603,7 @@ function findTriple(store, attrsStore, rawTriple) {
695
603
  }
696
604
  return getInMap(store.eav, [eid, aid]);
697
605
  }
698
- export function transact(store, attrsStore, txSteps) {
606
+ export function transact(store, txSteps) {
699
607
  const txStepsFiltered = txSteps.filter(([action, eid, attrId, value, opts]) => {
700
608
  if (action !== 'add-triple' && action !== 'deep-merge-triple') {
701
609
  return true;
@@ -705,10 +613,10 @@ export function transact(store, attrsStore, txSteps) {
705
613
  return true;
706
614
  }
707
615
  let exists = false;
708
- const attr = attrsStore.getAttr(attrId);
616
+ const attr = getAttr(store.attrs, attrId);
709
617
  if (attr) {
710
- const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
711
- exists = !!findTriple(store, attrsStore, [
618
+ const idAttr = getPrimaryKeyAttr(store, attr['forward-identity'][1]);
619
+ exists = !!findTriple(store, [
712
620
  eid,
713
621
  idAttr === null || idAttr === void 0 ? void 0 : idAttr.id,
714
622
  eid,
@@ -724,7 +632,7 @@ export function transact(store, attrsStore, txSteps) {
724
632
  });
725
633
  return create(store, (draft) => {
726
634
  txStepsFiltered.forEach((txStep) => {
727
- applyTxStep(draft, attrsStore, txStep);
635
+ applyTxStep(draft, txStep);
728
636
  });
729
637
  });
730
638
  }