@instantdb/core 0.22.83 → 0.22.84

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 (47) hide show
  1. package/__tests__/src/utils/PersistedObject.test.ts +1 -1
  2. package/dist/commonjs/Reactor.d.ts.map +1 -1
  3. package/dist/commonjs/Reactor.js.map +1 -1
  4. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  5. package/dist/commonjs/SyncTable.js +1 -0
  6. package/dist/commonjs/SyncTable.js.map +1 -1
  7. package/dist/commonjs/attrTypes.d.ts +1 -1
  8. package/dist/commonjs/attrTypes.d.ts.map +1 -1
  9. package/dist/commonjs/attrTypes.js.map +1 -1
  10. package/dist/commonjs/datalog.js +2 -2
  11. package/dist/commonjs/datalog.js.map +1 -1
  12. package/dist/commonjs/instaml.js +2 -2
  13. package/dist/commonjs/instaml.js.map +1 -1
  14. package/dist/commonjs/instaql.js.map +1 -1
  15. package/dist/commonjs/store.d.ts +44 -29
  16. package/dist/commonjs/store.d.ts.map +1 -1
  17. package/dist/commonjs/store.js +9 -5
  18. package/dist/commonjs/store.js.map +1 -1
  19. package/dist/esm/Reactor.d.ts.map +1 -1
  20. package/dist/esm/Reactor.js +1 -1
  21. package/dist/esm/Reactor.js.map +1 -1
  22. package/dist/esm/SyncTable.d.ts.map +1 -1
  23. package/dist/esm/SyncTable.js +2 -1
  24. package/dist/esm/SyncTable.js.map +1 -1
  25. package/dist/esm/attrTypes.d.ts +1 -1
  26. package/dist/esm/attrTypes.d.ts.map +1 -1
  27. package/dist/esm/attrTypes.js.map +1 -1
  28. package/dist/esm/datalog.js +1 -1
  29. package/dist/esm/datalog.js.map +1 -1
  30. package/dist/esm/instaml.js +1 -1
  31. package/dist/esm/instaml.js.map +1 -1
  32. package/dist/esm/instaql.js +1 -1
  33. package/dist/esm/instaql.js.map +1 -1
  34. package/dist/esm/store.d.ts +44 -29
  35. package/dist/esm/store.d.ts.map +1 -1
  36. package/dist/esm/store.js +9 -5
  37. package/dist/esm/store.js.map +1 -1
  38. package/dist/standalone/index.js +95 -87
  39. package/dist/standalone/index.umd.cjs +3 -3
  40. package/package.json +2 -2
  41. package/src/Reactor.js +1 -1
  42. package/src/SyncTable.ts +4 -3
  43. package/src/attrTypes.ts +1 -6
  44. package/src/datalog.js +1 -1
  45. package/src/instaml.js +1 -1
  46. package/src/instaql.js +1 -1
  47. package/src/{store.js → store.ts} +127 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/core",
3
- "version": "0.22.83",
3
+ "version": "0.22.84",
4
4
  "description": "Instant's core local abstraction",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "dependencies": {
54
54
  "mutative": "^1.0.10",
55
55
  "uuid": "^11.1.0",
56
- "@instantdb/version": "0.22.83"
56
+ "@instantdb/version": "0.22.84"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "vitest",
package/src/Reactor.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import weakHash from './utils/weakHash.ts';
3
3
  import instaql from './instaql.js';
4
4
  import * as instaml from './instaml.js';
5
- import * as s from './store.js';
5
+ import * as s from './store.ts';
6
6
  import uuid from './utils/uuid.ts';
7
7
  import IndexedDBStorage from './IndexedDBStorage.ts';
8
8
  import WindowNetworkListener from './WindowNetworkListener.js';
package/src/SyncTable.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PersistedObject } from './utils/PersistedObject.ts';
2
- import * as s from './store.js';
2
+ import * as s from './store.ts';
3
3
  import weakHash from './utils/weakHash.ts';
4
4
  import uuid from './utils/uuid.ts';
5
5
  import { Logger } from './Reactor.js';
@@ -31,7 +31,7 @@ type Sub = {
31
31
  table: string;
32
32
  orderField: string;
33
33
  orderDirection: 'asc' | 'desc';
34
- orderFieldType?: 'string' | 'number' | 'date' | 'boolean';
34
+ orderFieldType?: 'string' | 'number' | 'date' | 'boolean' | null;
35
35
  state?: SubState;
36
36
  values?: SubValues;
37
37
  createdAt: number;
@@ -113,6 +113,7 @@ function syncSubToStorage(_k: string, sub: Sub): SubInStorage {
113
113
  const store = s.toJSON(e.store);
114
114
  // We'll store the attrs once on values, and put the
115
115
  // attrs back into the store on hydration
116
+ // @ts-ignore: ts doesn't want us to delete a non-optional
116
117
  delete store['attrs'];
117
118
  entities.push({ ...e, store });
118
119
  }
@@ -790,7 +791,7 @@ export class SyncTable {
790
791
 
791
792
  const orderFieldType = orderFieldTypeMutative(sub, this.createStore);
792
793
 
793
- sortEntitiesInPlace(sub, orderFieldType, entities);
794
+ sortEntitiesInPlace(sub, orderFieldType!, entities);
794
795
  this.notifyCbs(hash, {
795
796
  type: CallbackEventType.SyncTransaction,
796
797
  data: subData(sub, sub.values?.entities),
package/src/attrTypes.ts CHANGED
@@ -6,12 +6,7 @@ export type InstantDBIdent = [id, etype, label];
6
6
 
7
7
  export type InstantDBInferredType = 'number' | 'string' | 'boolean' | 'json';
8
8
 
9
- export type InstantDBCheckedDataType =
10
- | 'number'
11
- | 'string'
12
- | 'boolean'
13
- | 'date'
14
- | 'json';
9
+ export type InstantDBCheckedDataType = 'number' | 'string' | 'boolean' | 'date';
15
10
 
16
11
  export type InstantDBAttrOnDelete = 'cascade';
17
12
 
package/src/datalog.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // 1. patternMatch
2
- import { getTriples } from './store.js';
2
+ import { getTriples } from './store.ts';
3
3
 
4
4
  function isVariable(x) {
5
5
  return typeof x === 'string' && x.startsWith('?');
package/src/instaml.js CHANGED
@@ -1,4 +1,4 @@
1
- import { allMapValues } from './store.js';
1
+ import { allMapValues } from './store.ts';
2
2
  import { getOps, isLookup, parseLookup } from './instatx.ts';
3
3
  import { immutableRemoveUndefined } from './utils/object.js';
4
4
  import { coerceToDate } from './utils/dates.ts';
package/src/instaql.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { query as datalogQuery } from './datalog.js';
2
2
  import { uuidCompare } from './utils/uuid.ts';
3
3
  import { stringCompare } from './utils/strings.ts';
4
- import * as s from './store.js';
4
+ import * as s from './store.ts';
5
5
 
6
6
  // Pattern variables
7
7
  // -----------------
@@ -1,20 +1,53 @@
1
1
  import { create } from 'mutative';
2
2
  import { immutableDeepMerge } from './utils/object.js';
3
3
  import { coerceToDate } from './utils/dates.ts';
4
-
5
- function hasEA(attr) {
4
+ import { InstantDBAttr } from './attrTypes.ts';
5
+ import { LinkIndex } from './utils/linkIndex.ts';
6
+
7
+ type Triple = [string, string, any, number];
8
+ type Attrs = Record<string, InstantDBAttr>;
9
+
10
+ type AttrIndexes = {
11
+ blobAttrs: Map<string, Map<string, InstantDBAttr>>;
12
+ primaryKeys: Map<string, InstantDBAttr>;
13
+ forwardIdents: Map<string, Map<string, InstantDBAttr>>;
14
+ revIdents: Map<string, Map<string, InstantDBAttr>>;
15
+ };
16
+
17
+ export type Store = {
18
+ eav: Map<string, Map<string, Map<any, Triple>>>;
19
+ aev: Map<string, Map<string, Map<any, Triple>>>;
20
+ vae: Map<any, Map<string, Map<string, Triple>>>;
21
+ useDateObjects: boolean | null;
22
+ attrs: Attrs;
23
+ attrIndexes: AttrIndexes;
24
+ cardinalityInference: boolean | null;
25
+ linkIndex: LinkIndex | null;
26
+ __type: 'store';
27
+ };
28
+
29
+ export type StoreJson = {
30
+ __type: 'store';
31
+ attrs: Attrs;
32
+ triples: Triple[];
33
+ cardinalityInference: boolean | null;
34
+ linkIndex: LinkIndex | null;
35
+ useDateObjects: boolean | null;
36
+ };
37
+
38
+ function hasEA(attr: InstantDBAttr) {
6
39
  return attr['cardinality'] === 'one';
7
40
  }
8
41
 
9
- function isRef(attr) {
42
+ function isRef(attr: InstantDBAttr) {
10
43
  return attr['value-type'] === 'ref';
11
44
  }
12
45
 
13
- export function isBlob(attr) {
46
+ export function isBlob(attr: InstantDBAttr) {
14
47
  return attr['value-type'] === 'blob';
15
48
  }
16
49
 
17
- function getAttr(attrs, attrId) {
50
+ function getAttr(attrs: Attrs, attrId: string): InstantDBAttr | undefined {
18
51
  return attrs[attrId];
19
52
  }
20
53
 
@@ -48,11 +81,15 @@ function setInMap(m, path, value) {
48
81
  setInMap(nextM, tail, value);
49
82
  }
50
83
 
51
- function isDateAttr(attr) {
84
+ function isDateAttr(attr: InstantDBAttr) {
52
85
  return attr['checked-data-type'] === 'date';
53
86
  }
54
87
 
55
- function createTripleIndexes(attrs, triples, useDateObjects) {
88
+ function createTripleIndexes(
89
+ attrs: Record<string, InstantDBAttr>,
90
+ triples: Triple[],
91
+ useDateObjects: boolean | null,
92
+ ): Pick<Store, 'eav' | 'aev' | 'vae'> {
56
93
  const eav = new Map();
57
94
  const aev = new Map();
58
95
  const vae = new Map();
@@ -79,7 +116,7 @@ function createTripleIndexes(attrs, triples, useDateObjects) {
79
116
  return { eav, aev, vae };
80
117
  }
81
118
 
82
- function createAttrIndexes(attrs) {
119
+ function createAttrIndexes(attrs: Record<string, InstantDBAttr>): AttrIndexes {
83
120
  const blobAttrs = new Map();
84
121
  const primaryKeys = new Map();
85
122
  const forwardIdents = new Map();
@@ -105,7 +142,7 @@ function createAttrIndexes(attrs) {
105
142
  return { blobAttrs, primaryKeys, forwardIdents, revIdents };
106
143
  }
107
144
 
108
- export function toJSON(store) {
145
+ export function toJSON(store: Store): StoreJson {
109
146
  return {
110
147
  __type: store.__type,
111
148
  attrs: store.attrs,
@@ -116,7 +153,7 @@ export function toJSON(store) {
116
153
  };
117
154
  }
118
155
 
119
- export function fromJSON(storeJSON) {
156
+ export function fromJSON(storeJSON: StoreJson): Store {
120
157
  return createStore(
121
158
  storeJSON.attrs,
122
159
  storeJSON.triples,
@@ -126,26 +163,30 @@ export function fromJSON(storeJSON) {
126
163
  );
127
164
  }
128
165
 
129
- export function hasTriple(store, [e, a, v]) {
166
+ export function hasTriple(store: Store, [e, a, v]: [string, string, any]) {
130
167
  return getInMap(store.eav, [e, a, v]) !== undefined;
131
168
  }
132
169
 
133
- export function hasEntity(store, e) {
170
+ export function hasEntity(store: Store, e: string) {
134
171
  return getInMap(store.eav, [e]) !== undefined;
135
172
  }
136
173
 
137
- function resetAttrIndexes(store) {
174
+ function resetAttrIndexes(store: Store) {
138
175
  store.attrIndexes = createAttrIndexes(store.attrs);
139
176
  }
140
177
 
141
178
  export function createStore(
142
- attrs,
143
- triples,
144
- enableCardinalityInference,
145
- linkIndex,
146
- useDateObjects,
147
- ) {
148
- const store = createTripleIndexes(attrs, triples, useDateObjects);
179
+ attrs: Record<string, InstantDBAttr>,
180
+ triples: Triple[],
181
+ enableCardinalityInference: boolean | null,
182
+ linkIndex: LinkIndex | null,
183
+ useDateObjects: boolean | null,
184
+ ): Store {
185
+ const store = createTripleIndexes(
186
+ attrs,
187
+ triples,
188
+ useDateObjects,
189
+ ) as unknown as Store;
149
190
  store.useDateObjects = useDateObjects;
150
191
  store.attrs = attrs;
151
192
  store.attrIndexes = createAttrIndexes(attrs);
@@ -161,7 +202,7 @@ export function createStore(
161
202
  // into the store. If we can't find the lookup ref locally,
162
203
  // then we drop the triple and have to wait for the server response
163
204
  // to see the optimistic updates.
164
- function resolveLookupRefs(store, triple) {
205
+ function resolveLookupRefs(store: Store, triple: Triple): Triple | null {
165
206
  let eid;
166
207
 
167
208
  // Check if `e` is a lookup ref
@@ -213,7 +254,7 @@ function resolveLookupRefs(store, triple) {
213
254
  }
214
255
  }
215
256
 
216
- export function retractTriple(store, rawTriple) {
257
+ export function retractTriple(store: Store, rawTriple: Triple): void {
217
258
  const triple = resolveLookupRefs(store, rawTriple);
218
259
  if (!triple) {
219
260
  return;
@@ -232,10 +273,15 @@ export function retractTriple(store, rawTriple) {
232
273
  }
233
274
 
234
275
  let _seed = 0;
235
- function getCreatedAt(store, attr, triple) {
276
+ function getCreatedAt(
277
+ store: Store,
278
+ attr: InstantDBAttr,
279
+ triple: Triple,
280
+ ): Number {
236
281
  const [eid, aid, v] = triple;
237
282
  let createdAt;
238
- const t = getInMap(store.ea, [eid, aid, v]);
283
+
284
+ const t = getInMap(store.eav, [eid, aid, v]);
239
285
  if (t) {
240
286
  createdAt = t[3];
241
287
  }
@@ -264,7 +310,7 @@ function getCreatedAt(store, attr, triple) {
264
310
  return createdAt || Date.now() * 10 + _seed++;
265
311
  }
266
312
 
267
- export function addTriple(store, rawTriple) {
313
+ export function addTriple(store: Store, rawTriple: Triple) {
268
314
  const triple = resolveLookupRefs(store, rawTriple);
269
315
  if (!triple) {
270
316
  return;
@@ -303,7 +349,7 @@ export function addTriple(store, rawTriple) {
303
349
  }
304
350
  }
305
351
 
306
- function mergeTriple(store, rawTriple) {
352
+ function mergeTriple(store: Store, rawTriple: Triple) {
307
353
  const triple = resolveLookupRefs(store, rawTriple);
308
354
  if (!triple) {
309
355
  return;
@@ -336,9 +382,9 @@ function mergeTriple(store, rawTriple) {
336
382
  setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
337
383
  }
338
384
 
339
- function deleteEntity(store, args) {
385
+ function deleteEntity(store: Store, args: any[]) {
340
386
  const [lookup, etype] = args;
341
- const triple = resolveLookupRefs(store, [lookup]);
387
+ const triple = resolveLookupRefs(store, [lookup] as unknown as Triple);
342
388
 
343
389
  if (!triple) {
344
390
  return;
@@ -353,8 +399,9 @@ function deleteEntity(store, args) {
353
399
 
354
400
  // delete cascade refs
355
401
  if (attr && attr['on-delete-reverse'] === 'cascade') {
356
- allMapValues(eMap.get(a), 1).forEach(([e, a, v]) =>
357
- deleteEntity(store, [v, attr['reverse-identity']?.[1]]),
402
+ allMapValues(eMap.get(a), 1).forEach(
403
+ ([e, a, v]: [string, string, any]) =>
404
+ deleteEntity(store, [v, attr['reverse-identity']?.[1]]),
358
405
  );
359
406
  }
360
407
 
@@ -381,7 +428,7 @@ function deleteEntity(store, args) {
381
428
  const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);
382
429
 
383
430
  if (vaeTriples) {
384
- vaeTriples.forEach((triple) => {
431
+ vaeTriples.forEach((triple: Triple) => {
385
432
  const [e, a, v] = triple;
386
433
  const attr = store.attrs[a];
387
434
  if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {
@@ -411,7 +458,7 @@ function deleteEntity(store, args) {
411
458
  // * We could batch this reset at the end
412
459
  // * We could add an ave index for all triples, so removing the
413
460
  // right triples is easy and fast.
414
- function resetIndexMap(store, newTriples) {
461
+ function resetIndexMap(store: Store, newTriples: Triple[]) {
415
462
  const newIndexMap = createTripleIndexes(
416
463
  store.attrs,
417
464
  newTriples,
@@ -422,16 +469,16 @@ function resetIndexMap(store, newTriples) {
422
469
  });
423
470
  }
424
471
 
425
- function addAttr(store, [attr]) {
472
+ function addAttr(store: Store, [attr]: [InstantDBAttr]) {
426
473
  store.attrs[attr.id] = attr;
427
474
  resetAttrIndexes(store);
428
475
  }
429
476
 
430
- function getAllTriples(store) {
477
+ function getAllTriples(store: Store): Triple[] {
431
478
  return allMapValues(store.eav, 3);
432
479
  }
433
480
 
434
- function deleteAttr(store, [id]) {
481
+ function deleteAttr(store: Store, [id]: [string]) {
435
482
  if (!store.attrs[id]) return;
436
483
  const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
437
484
  delete store.attrs[id];
@@ -439,7 +486,10 @@ function deleteAttr(store, [id]) {
439
486
  resetIndexMap(store, newTriples);
440
487
  }
441
488
 
442
- function updateAttr(store, [partialAttr]) {
489
+ function updateAttr(
490
+ store: Store,
491
+ [partialAttr]: [Partial<InstantDBAttr> & { id: string }],
492
+ ) {
443
493
  const attr = store.attrs[partialAttr.id];
444
494
  if (!attr) return;
445
495
  store.attrs[partialAttr.id] = { ...attr, ...partialAttr };
@@ -447,7 +497,7 @@ function updateAttr(store, [partialAttr]) {
447
497
  resetIndexMap(store, getAllTriples(store));
448
498
  }
449
499
 
450
- function applyTxStep(store, txStep) {
500
+ function applyTxStep(store: Store, txStep) {
451
501
  const [action, ...args] = txStep;
452
502
  switch (action) {
453
503
  case 'add-triple':
@@ -480,7 +530,7 @@ function applyTxStep(store, txStep) {
480
530
  }
481
531
  }
482
532
 
483
- export function allMapValues(m, level, res = []) {
533
+ export function allMapValues(m, level, res: any[] = []) {
484
534
  if (!m) {
485
535
  return res;
486
536
  }
@@ -500,12 +550,12 @@ export function allMapValues(m, level, res = []) {
500
550
  return res;
501
551
  }
502
552
 
503
- function triplesByValue(store, m, v) {
504
- const res = [];
553
+ function triplesByValue(store: Store, m: Map<any, Triple>, v: any) {
554
+ const res: Triple[] = [];
505
555
  if (v?.hasOwnProperty('$not')) {
506
556
  for (const candidate of m.keys()) {
507
557
  if (v.$not !== candidate) {
508
- res.push(m.get(candidate));
558
+ res.push(m.get(candidate) as Triple);
509
559
  }
510
560
  }
511
561
  return res;
@@ -517,10 +567,9 @@ function triplesByValue(store, m, v) {
517
567
  if (reverse) {
518
568
  for (const candidate of m.keys()) {
519
569
  const vMap = store.vae.get(candidate);
520
- const isValNull =
521
- !vMap || vMap.get(attrId)?.get(null) || !vMap.get(attrId);
570
+ const isValNull = !vMap || !vMap.get(attrId);
522
571
  if (isNull ? isValNull : !isValNull) {
523
- res.push(m.get(candidate));
572
+ res.push(m.get(candidate) as Triple);
524
573
  }
525
574
  }
526
575
  } else {
@@ -529,7 +578,7 @@ function triplesByValue(store, m, v) {
529
578
  const isValNull =
530
579
  !aMap || aMap.get(candidate)?.get(null) || !aMap.get(candidate);
531
580
  if (isNull ? isValNull : !isValNull) {
532
- res.push(m.get(candidate));
581
+ res.push(m.get(candidate) as Triple);
533
582
  }
534
583
  }
535
584
  }
@@ -555,7 +604,7 @@ function triplesByValue(store, m, v) {
555
604
 
556
605
  // A poor man's pattern matching
557
606
  // Returns either eav, ea, ev, av, v, or ''
558
- function whichIdx(e, a, v) {
607
+ function whichIdx(e, a, v): 'eav' | 'ea' | 'ev' | 'av' | 'e' | 'a' | 'v' | '' {
559
608
  let res = '';
560
609
  if (e !== undefined) {
561
610
  res += 'e';
@@ -566,7 +615,7 @@ function whichIdx(e, a, v) {
566
615
  if (v !== undefined) {
567
616
  res += 'v';
568
617
  }
569
- return res;
618
+ return res as 'eav' | 'ea' | 'ev' | 'av' | 'e' | 'a' | 'v' | '';
570
619
  }
571
620
 
572
621
  export function getTriples(store, [e, a, v]) {
@@ -592,7 +641,7 @@ export function getTriples(store, [e, a, v]) {
592
641
  if (!eMap) {
593
642
  return [];
594
643
  }
595
- const res = [];
644
+ const res: Triple[] = [];
596
645
  for (const aMap of eMap.values()) {
597
646
  res.push(...triplesByValue(store, aMap, v));
598
647
  }
@@ -607,14 +656,14 @@ export function getTriples(store, [e, a, v]) {
607
656
  if (!aMap) {
608
657
  return [];
609
658
  }
610
- const res = [];
659
+ const res: Triple[] = [];
611
660
  for (const eMap of aMap.values()) {
612
661
  res.push(...triplesByValue(store, eMap, v));
613
662
  }
614
663
  return res;
615
664
  }
616
665
  case 'v': {
617
- const res = [];
666
+ const res: Triple[] = [];
618
667
  for (const eMap of store.eav.values()) {
619
668
  for (const aMap of eMap.values()) {
620
669
  res.push(...triplesByValue(store, aMap, v));
@@ -628,7 +677,11 @@ export function getTriples(store, [e, a, v]) {
628
677
  }
629
678
  }
630
679
 
631
- export function getAsObject(store, attrs, e) {
680
+ export function getAsObject(
681
+ store: Store,
682
+ attrs: Map<string, InstantDBAttr>,
683
+ e: string,
684
+ ) {
632
685
  const obj = {};
633
686
 
634
687
  for (const [label, attr] of attrs.entries()) {
@@ -642,19 +695,27 @@ export function getAsObject(store, attrs, e) {
642
695
  return obj;
643
696
  }
644
697
 
645
- export function getAttrByFwdIdentName(store, inputEtype, inputLabel) {
698
+ export function getAttrByFwdIdentName(
699
+ store: Store,
700
+ inputEtype: string,
701
+ inputLabel: string,
702
+ ) {
646
703
  return store.attrIndexes.forwardIdents.get(inputEtype)?.get(inputLabel);
647
704
  }
648
705
 
649
- export function getAttrByReverseIdentName(store, inputEtype, inputLabel) {
706
+ export function getAttrByReverseIdentName(
707
+ store: Store,
708
+ inputEtype: string,
709
+ inputLabel: string,
710
+ ) {
650
711
  return store.attrIndexes.revIdents.get(inputEtype)?.get(inputLabel);
651
712
  }
652
713
 
653
- export function getBlobAttrs(store, etype) {
714
+ export function getBlobAttrs(store: Store, etype: string) {
654
715
  return store.attrIndexes.blobAttrs.get(etype);
655
716
  }
656
717
 
657
- export function getPrimaryKeyAttr(store, etype) {
718
+ export function getPrimaryKeyAttr(store: Store, etype: string) {
658
719
  const fromPrimary = store.attrIndexes.primaryKeys.get(etype);
659
720
  if (fromPrimary) {
660
721
  return fromPrimary;
@@ -662,8 +723,11 @@ export function getPrimaryKeyAttr(store, etype) {
662
723
  return store.attrIndexes.forwardIdents.get(etype)?.get('id');
663
724
  }
664
725
 
665
- function findTriple(store, rawTriple) {
666
- const triple = resolveLookupRefs(store, rawTriple);
726
+ function findTriple(
727
+ store: Store,
728
+ rawTriple: [string, string, any] | Triple,
729
+ ): Triple | undefined {
730
+ const triple = resolveLookupRefs(store, rawTriple as Triple);
667
731
  if (!triple) {
668
732
  return;
669
733
  }
@@ -681,7 +745,7 @@ function findTriple(store, rawTriple) {
681
745
  return getInMap(store.eav, [eid, aid]);
682
746
  }
683
747
 
684
- export function transact(store, txSteps) {
748
+ export function transact(store: Store, txSteps) {
685
749
  const txStepsFiltered = txSteps.filter(
686
750
  ([action, eid, attrId, value, opts]) => {
687
751
  if (action !== 'add-triple' && action !== 'deep-merge-triple') {
@@ -698,7 +762,11 @@ export function transact(store, txSteps) {
698
762
  const attr = getAttr(store.attrs, attrId);
699
763
  if (attr) {
700
764
  const idAttr = getPrimaryKeyAttr(store, attr['forward-identity'][1]);
701
- exists = !!findTriple(store, [eid, idAttr.id, eid]);
765
+ exists = !!findTriple(store, [
766
+ eid as string,
767
+ idAttr?.id as string,
768
+ eid,
769
+ ]);
702
770
  }
703
771
 
704
772
  if (mode === 'create' && exists) {