@instantdb/core 0.22.86-experimental.split-store.20178922132.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 (45) 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 +4 -1
  9. package/dist/commonjs/Reactor.d.ts.map +1 -1
  10. package/dist/commonjs/Reactor.js +22 -12
  11. package/dist/commonjs/Reactor.js.map +1 -1
  12. package/dist/commonjs/instaml.d.ts +3 -3
  13. package/dist/commonjs/instaml.d.ts.map +1 -1
  14. package/dist/commonjs/instaml.js +2 -2
  15. package/dist/commonjs/instaml.js.map +1 -1
  16. package/dist/commonjs/instaql.d.ts +2 -2
  17. package/dist/commonjs/instaql.d.ts.map +1 -1
  18. package/dist/commonjs/instaql.js.map +1 -1
  19. package/dist/commonjs/store.d.ts +28 -9
  20. package/dist/commonjs/store.d.ts.map +1 -1
  21. package/dist/commonjs/store.js +13 -8
  22. package/dist/commonjs/store.js.map +1 -1
  23. package/dist/esm/Reactor.d.ts +4 -1
  24. package/dist/esm/Reactor.d.ts.map +1 -1
  25. package/dist/esm/Reactor.js +22 -12
  26. package/dist/esm/Reactor.js.map +1 -1
  27. package/dist/esm/instaml.d.ts +3 -3
  28. package/dist/esm/instaml.d.ts.map +1 -1
  29. package/dist/esm/instaml.js +3 -3
  30. package/dist/esm/instaml.js.map +1 -1
  31. package/dist/esm/instaql.d.ts +2 -2
  32. package/dist/esm/instaql.d.ts.map +1 -1
  33. package/dist/esm/instaql.js.map +1 -1
  34. package/dist/esm/store.d.ts +28 -9
  35. package/dist/esm/store.d.ts.map +1 -1
  36. package/dist/esm/store.js +11 -6
  37. package/dist/esm/store.js.map +1 -1
  38. package/dist/standalone/index.js +549 -533
  39. package/dist/standalone/index.umd.cjs +2 -2
  40. package/package.json +2 -2
  41. package/src/Reactor.js +44 -35
  42. package/src/instaml.ts +8 -7
  43. package/src/instaql.ts +2 -2
  44. package/src/store.ts +47 -19
  45. package/__tests__/src/instaql.bench.js +0 -29
@@ -13,11 +13,15 @@ import zenecaAttrs from './data/zeneca/attrs.json';
13
13
  import zenecaTriples from './data/zeneca/triples.json';
14
14
  import uuid from '../../src/utils/uuid';
15
15
  import { weakHash } from '../../src';
16
+ import { AttrsStoreClass } from '../../src/store';
16
17
 
17
- const zenecaIdToAttr = zenecaAttrs.reduce((res, x) => {
18
- res[x.id] = x;
19
- return res;
20
- }, {});
18
+ const zenecaAttrsStore = new AttrsStoreClass(
19
+ zenecaAttrs.reduce((res, x) => {
20
+ res[x.id] = x;
21
+ return res;
22
+ }, {}),
23
+ null,
24
+ );
21
25
 
22
26
  async function waitForLoaded(reactor) {
23
27
  await reactor.querySubs.waitForMetaToLoad();
@@ -123,12 +127,15 @@ test('rewrite mutations', () => {
123
127
  ];
124
128
 
125
129
  // create transactions without any attributes
126
- const optimisticSteps = instaml.transform({ attrs: {} }, ops);
130
+ const optimisticSteps = instaml.transform(
131
+ { attrsStore: new AttrsStoreClass({}, null) },
132
+ ops,
133
+ );
127
134
 
128
135
  const mutations = new Map([['k', { 'tx-steps': optimisticSteps }]]);
129
136
 
130
137
  const rewrittenWithoutAttrs = reactor
131
- ._rewriteMutations({}, mutations)
138
+ ._rewriteMutations(new AttrsStoreClass({}, null), mutations)
132
139
  .get('k')['tx-steps'];
133
140
 
134
141
  // Check that we didn't clobber anything in our rewrite
@@ -136,10 +143,10 @@ test('rewrite mutations', () => {
136
143
 
137
144
  // rewrite them with the new server attributes
138
145
  const rewrittenSteps = reactor
139
- ._rewriteMutations(zenecaIdToAttr, mutations)
146
+ ._rewriteMutations(zenecaAttrsStore, mutations)
140
147
  .get('k')['tx-steps'];
141
148
 
142
- const serverSteps = instaml.transform({ attrs: zenecaIdToAttr }, ops);
149
+ const serverSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
143
150
  expect(rewrittenSteps).toEqual(serverSteps);
144
151
  });
145
152
 
@@ -170,7 +177,7 @@ test('rewrite mutations works with multiple transactions', () => {
170
177
 
171
178
  for (const k of keys) {
172
179
  const attrs = reactor.optimisticAttrs();
173
- const steps = instaml.transform({ attrs }, ops);
180
+ const steps = instaml.transform({ attrsStore: attrs }, ops);
174
181
  const mut = {
175
182
  op: 'transact',
176
183
  'tx-steps': steps,
@@ -183,11 +190,11 @@ test('rewrite mutations works with multiple transactions', () => {
183
190
 
184
191
  // rewrite them with the new server attributes
185
192
  const rewrittenMutations = reactor._rewriteMutations(
186
- zenecaIdToAttr,
193
+ zenecaAttrsStore,
187
194
  reactor._pendingMutations(),
188
195
  );
189
196
 
190
- const serverSteps = instaml.transform({ attrs: zenecaIdToAttr }, ops);
197
+ const serverSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
191
198
  for (const k of keys) {
192
199
  expect(rewrittenMutations.get(k)['tx-steps']).toEqual(serverSteps);
193
200
  }
@@ -7,10 +7,22 @@ import {
7
7
  querySingle,
8
8
  queryWhere,
9
9
  } from '../../src/datalog';
10
- import { createStore } from '../../src/store';
11
- import { getAttrByFwdIdentName } from '../../src/instaml';
10
+ import {
11
+ AttrsStoreClass,
12
+ createStore,
13
+ getAttrByFwdIdentName,
14
+ } from '../../src/store';
15
+ import { InstantDBAttr } from '../../src';
16
+
17
+ const movieAttrsStore = new AttrsStoreClass(
18
+ movieAttrs as unknown as Record<string, InstantDBAttr>,
19
+ null,
20
+ );
12
21
 
13
- const store = createStore(movieAttrs, movieTriples);
22
+ const store = createStore(
23
+ movieAttrsStore,
24
+ movieTriples as [string, string, any, number][],
25
+ );
14
26
 
15
27
  test('matchPattern', () => {
16
28
  expect(
@@ -31,8 +43,8 @@ test('matchPattern', () => {
31
43
 
32
44
  function aid(friendlyName) {
33
45
  const [etype, label] = friendlyName.split('/');
34
- const attr = getAttrByFwdIdentName(store.attrs, etype, label);
35
- return attr.id;
46
+ const attr = getAttrByFwdIdentName(movieAttrsStore, etype, label);
47
+ return attr?.id;
36
48
  }
37
49
 
38
50
  function mid(movieName) {
@@ -3,27 +3,33 @@ import * as instaml from '../../src/instaml';
3
3
  import * as instatx from '../../src/instatx';
4
4
  import zenecaAttrs from './data/zeneca/attrs.json';
5
5
  import zenecaTriples from './data/zeneca/triples.json';
6
- import { createStore, transact } from '../../src/store';
6
+ import { createStore, transact, AttrsStoreClass } from '../../src/store';
7
7
  import uuid from '../../src/utils/uuid';
8
- import { i } from '../../src/index';
8
+ import { i, InstantDBAttr } from '../../src/index';
9
9
 
10
10
  const zenecaAttrToId = zenecaAttrs.reduce((res, x) => {
11
11
  res[`${x['forward-identity'][1]}/${x['forward-identity'][2]}`] = x.id;
12
12
  return res;
13
13
  }, {});
14
14
 
15
- const zenecaIdToAttr = zenecaAttrs.reduce((res, x) => {
16
- res[x.id] = x;
17
- return res;
18
- }, {});
15
+ const zenecaAttrsStore = new AttrsStoreClass(
16
+ zenecaAttrs.reduce((res, x) => {
17
+ res[x.id] = x;
18
+ return res;
19
+ }, {}),
20
+ null,
21
+ );
19
22
 
20
- const store = createStore(zenecaIdToAttr, zenecaTriples);
23
+ const store = createStore(
24
+ zenecaAttrsStore,
25
+ zenecaTriples as [string, string, any, number][],
26
+ );
21
27
 
22
28
  test('simple update transform', () => {
23
29
  const testId = uuid();
24
30
 
25
31
  const ops = instatx.tx.books[testId].update({ title: 'New Title' });
26
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
32
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
27
33
 
28
34
  const expected = [
29
35
  ['add-triple', testId, zenecaAttrToId['books/title'], 'New Title'],
@@ -43,7 +49,7 @@ test('undefined is ignored in update', () => {
43
49
  handle: 'bobby',
44
50
  fullName: undefined,
45
51
  });
46
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
52
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
47
53
 
48
54
  const expected = [
49
55
  ['add-triple', testId, zenecaAttrToId['users/id'], testId],
@@ -63,7 +69,7 @@ test('ignores id attrs', () => {
63
69
  title: 'New Title',
64
70
  id: 'ploop',
65
71
  });
66
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
72
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
67
73
 
68
74
  const expected = [
69
75
  ['add-triple', testId, zenecaAttrToId['books/title'], 'New Title'],
@@ -80,7 +86,7 @@ test("optimistically adds attrs if they don't exist", () => {
80
86
 
81
87
  const ops = instatx.tx.books[testId].update({ newAttr: 'New Title' });
82
88
 
83
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
89
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
84
90
 
85
91
  const expected = [
86
92
  [
@@ -114,7 +120,7 @@ test('lookup resolves attr ids', () => {
114
120
 
115
121
  const stopaLookup = [zenecaAttrToId['users/email'], 'stopa@instantdb.com'];
116
122
 
117
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
123
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
118
124
 
119
125
  const expected = [
120
126
  ['add-triple', stopaLookup, zenecaAttrToId['users/handle'], 'stopa'],
@@ -140,7 +146,7 @@ test('lookup creates unique attrs for custom lookups', () => {
140
146
  'newAttrValue',
141
147
  ];
142
148
 
143
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
149
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
144
150
  const expected = [
145
151
  [
146
152
  'add-attr',
@@ -170,7 +176,10 @@ test('lookup creates unique attrs for lookups in link values', () => {
170
176
  .update({})
171
177
  .link({ posts: instatx.lookup('slug', 'life-is-good') });
172
178
 
173
- const result = instaml.transform({ attrs: {} }, ops);
179
+ const result = instaml.transform(
180
+ { attrsStore: new AttrsStoreClass({}, null) },
181
+ ops,
182
+ );
174
183
 
175
184
  expect(result).toEqual([
176
185
  [
@@ -229,7 +238,10 @@ test('lookup creates unique attrs for lookups in link values with arrays', () =>
229
238
  ],
230
239
  });
231
240
 
232
- const result = instaml.transform({ attrs: {} }, ops);
241
+ const result = instaml.transform(
242
+ { attrsStore: new AttrsStoreClass({}, null) },
243
+ ops,
244
+ );
233
245
 
234
246
  const expected = [
235
247
  [
@@ -305,10 +317,10 @@ test('lookup creates unique attrs for lookups in link values when fwd-ident exis
305
317
  cardinality: 'one',
306
318
  'unique?': true,
307
319
  'index?': true,
308
- };
320
+ } as unknown as InstantDBAttr;
309
321
 
310
322
  const result = instaml.transform(
311
- { attrs: { [attrId]: existingRefAttr } },
323
+ { attrsStore: new AttrsStoreClass({ [attrId]: existingRefAttr }, null) },
312
324
  ops,
313
325
  );
314
326
 
@@ -362,10 +374,10 @@ test('lookup creates unique attrs for lookups in link values when rev-ident exis
362
374
  cardinality: 'one',
363
375
  'unique?': true,
364
376
  'index?': true,
365
- };
377
+ } as unknown as InstantDBAttr;
366
378
 
367
379
  const result = instaml.transform(
368
- { attrs: { [attrId]: existingRefAttr } },
380
+ { attrsStore: new AttrsStoreClass({ [attrId]: existingRefAttr }, null) },
369
381
  ops,
370
382
  );
371
383
 
@@ -414,35 +426,38 @@ test("lookup doesn't override attrs for lookups in link values", () => {
414
426
  const userIdAttrId = uuid();
415
427
  const postsSlugAttrId = uuid();
416
428
 
417
- const attrs = {
418
- [refAttrId]: {
419
- id: refAttrId,
420
- 'forward-identity': [uuid(), 'users', 'posts'],
421
- 'reverse-identity': [uuid(), 'posts', 'users'],
422
- 'value-type': 'ref',
423
- cardinality: 'one',
424
- 'unique?': true,
425
- 'index?': true,
426
- },
427
- [userIdAttrId]: {
428
- id: userIdAttrId,
429
- 'forward-identity': [uuid(), 'users', 'id'],
430
- 'value-type': 'blob',
431
- cardinality: 'one',
432
- 'unique?': true,
433
- 'index?': false,
434
- },
435
- [postsSlugAttrId]: {
436
- id: postsSlugAttrId,
437
- 'forward-identity': [uuid(), 'posts', 'slug'],
438
- 'value-type': 'blob',
439
- cardinality: 'one',
440
- 'unique?': true,
441
- 'index?': true,
429
+ const attrsStore = new AttrsStoreClass(
430
+ {
431
+ [refAttrId]: {
432
+ id: refAttrId,
433
+ 'forward-identity': [uuid(), 'users', 'posts'],
434
+ 'reverse-identity': [uuid(), 'posts', 'users'],
435
+ 'value-type': 'ref',
436
+ cardinality: 'one',
437
+ 'unique?': true,
438
+ 'index?': true,
439
+ } as unknown as InstantDBAttr,
440
+ [userIdAttrId]: {
441
+ id: userIdAttrId,
442
+ 'forward-identity': [uuid(), 'users', 'id'],
443
+ 'value-type': 'blob',
444
+ cardinality: 'one',
445
+ 'unique?': true,
446
+ 'index?': false,
447
+ } as unknown as InstantDBAttr,
448
+ [postsSlugAttrId]: {
449
+ id: postsSlugAttrId,
450
+ 'forward-identity': [uuid(), 'posts', 'slug'],
451
+ 'value-type': 'blob',
452
+ cardinality: 'one',
453
+ 'unique?': true,
454
+ 'index?': true,
455
+ } as unknown as InstantDBAttr,
442
456
  },
443
- };
457
+ null,
458
+ );
444
459
 
445
- const result = instaml.transform({ attrs }, ops);
460
+ const result = instaml.transform({ attrsStore }, ops);
446
461
 
447
462
  expect(result).toEqual([
448
463
  ['add-triple', uid, userIdAttrId, uid],
@@ -455,39 +470,42 @@ test("lookup doesn't override attrs for lookups in self links", () => {
455
470
  const postIdAttrId = uuid();
456
471
  const postsSlugAttrId = uuid();
457
472
 
458
- const attrs = {
459
- [postIdAttrId]: {
460
- id: postIdAttrId,
461
- 'forward-identity': [uuid(), 'posts', 'id'],
462
- 'value-type': 'blob',
463
- cardinality: 'one',
464
- 'unique?': true,
465
- 'index?': false,
466
- },
467
- [postsSlugAttrId]: {
468
- id: postsSlugAttrId,
469
- 'forward-identity': [uuid(), 'posts', 'slug'],
470
- 'value-type': 'blob',
471
- cardinality: 'one',
472
- 'unique?': true,
473
- 'index?': true,
474
- },
475
- [refAttrId]: {
476
- id: refAttrId,
477
- 'forward-identity': [uuid(), 'posts', 'parent'],
478
- 'reverse-identity': [uuid(), 'posts', 'child'],
479
- 'value-type': 'ref',
480
- cardinality: 'one',
481
- 'unique?': true,
482
- 'index?': true,
473
+ const attrsStore = new AttrsStoreClass(
474
+ {
475
+ [postIdAttrId]: {
476
+ id: postIdAttrId,
477
+ 'forward-identity': [uuid(), 'posts', 'id'],
478
+ 'value-type': 'blob',
479
+ cardinality: 'one',
480
+ 'unique?': true,
481
+ 'index?': false,
482
+ } as unknown as InstantDBAttr,
483
+ [postsSlugAttrId]: {
484
+ id: postsSlugAttrId,
485
+ 'forward-identity': [uuid(), 'posts', 'slug'],
486
+ 'value-type': 'blob',
487
+ cardinality: 'one',
488
+ 'unique?': true,
489
+ 'index?': true,
490
+ } as unknown as InstantDBAttr,
491
+ [refAttrId]: {
492
+ id: refAttrId,
493
+ 'forward-identity': [uuid(), 'posts', 'parent'],
494
+ 'reverse-identity': [uuid(), 'posts', 'child'],
495
+ 'value-type': 'ref',
496
+ cardinality: 'one',
497
+ 'unique?': true,
498
+ 'index?': true,
499
+ } as unknown as InstantDBAttr,
483
500
  },
484
- };
501
+ null,
502
+ );
485
503
 
486
504
  const ops1 = instatx.tx.posts[instatx.lookup('slug', 'life-is-good')]
487
505
  .update({})
488
506
  .link({ parent: instatx.lookup('slug', 'life-is-good') });
489
507
 
490
- const result1 = instaml.transform({ attrs }, ops1);
508
+ const result1 = instaml.transform({ attrsStore }, ops1);
491
509
 
492
510
  expect(result1.filter((x) => x[0] !== 'add-triple')).toEqual([]);
493
511
 
@@ -495,7 +513,7 @@ test("lookup doesn't override attrs for lookups in self links", () => {
495
513
  .update({})
496
514
  .link({ child: instatx.lookup('slug', 'life-is-good') });
497
515
 
498
- const result2 = instaml.transform({ attrs }, ops2);
516
+ const result2 = instaml.transform({ attrsStore }, ops2);
499
517
 
500
518
  expect(result2.filter((x) => x[0] !== 'add-triple')).toEqual([]);
501
519
  });
@@ -513,7 +531,10 @@ test('lookup creates unique ref attrs for ref lookup', () => {
513
531
  uid,
514
532
  ];
515
533
 
516
- const result = instaml.transform({ attrs: {} }, ops);
534
+ const result = instaml.transform(
535
+ { attrsStore: new AttrsStoreClass({}, null) },
536
+ ops,
537
+ );
517
538
  const expected = [
518
539
  [
519
540
  'add-attr',
@@ -576,7 +597,10 @@ test('lookup creates unique ref attrs for ref lookup in link value', () => {
576
597
  uid,
577
598
  ];
578
599
 
579
- const result = instaml.transform({ attrs: {} }, ops);
600
+ const result = instaml.transform(
601
+ { attrsStore: new AttrsStoreClass({}, null) },
602
+ ops,
603
+ );
580
604
 
581
605
  const expected = [
582
606
  [
@@ -621,7 +645,7 @@ test('lookups create entities from links', () => {
621
645
  bookshelves: bookshelfId,
622
646
  });
623
647
 
624
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
648
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
625
649
  const expectedLookup = [zenecaAttrToId['users/handle'], 'bobby_newuser'];
626
650
  const expected = [
627
651
  ['add-triple', expectedLookup, zenecaAttrToId['users/id'], expectedLookup],
@@ -648,7 +672,7 @@ test('lookups create entities from unlinks', () => {
648
672
  bookshelves: bookshelfId,
649
673
  });
650
674
 
651
- const result = instaml.transform({ attrs: zenecaAttrs }, ops);
675
+ const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
652
676
  const expectedLookup = [zenecaAttrToId['users/handle'], 'bobby_newuser'];
653
677
  const expected = [
654
678
  ['add-triple', expectedLookup, zenecaAttrToId['users/id'], expectedLookup],
@@ -670,7 +694,10 @@ test('mode: update', () => {
670
694
  // create
671
695
  var id = uuid();
672
696
  var ops = instatx.tx.users[id].update({ handle: 'test' });
673
- var result = instaml.transform({ attrs: zenecaAttrs, stores: [store] }, ops);
697
+ var result = instaml.transform(
698
+ { attrsStore: zenecaAttrsStore, stores: [store] },
699
+ ops,
700
+ );
674
701
  for (const txStep of result) {
675
702
  expect(txStep[4]).toEqual(undefined);
676
703
  }
@@ -679,7 +706,10 @@ test('mode: update', () => {
679
706
  ops = instatx.tx.users['ce942051-2d74-404a-9c7d-4aa3f2d54ae4'].update({
680
707
  handle: 'joe2',
681
708
  });
682
- result = instaml.transform({ attrs: zenecaAttrs, stores: [store] }, ops);
709
+ result = instaml.transform(
710
+ { attrsStore: zenecaAttrsStore, stores: [store] },
711
+ ops,
712
+ );
683
713
  for (const txStep of result) {
684
714
  expect(txStep[4]).toEqual({ mode: 'update' });
685
715
  }
@@ -688,14 +718,20 @@ test('mode: update', () => {
688
718
  ops = instatx.tx.users[instatx.lookup('email', 'stopa@instantdb.com')].update(
689
719
  { handle: 'stopa2' },
690
720
  );
691
- result = instaml.transform({ attrs: zenecaAttrs, stores: [store] }, ops);
721
+ result = instaml.transform(
722
+ { attrsStore: zenecaAttrsStore, stores: [store] },
723
+ ops,
724
+ );
692
725
  for (const txStep of result) {
693
726
  expect(txStep[4]).toEqual({ mode: 'update' });
694
727
  }
695
728
 
696
729
  // forced mode
697
730
  var ops = instatx.tx.users[id].update({ handle: 'test' }, { upsert: false });
698
- var result = instaml.transform({ attrs: zenecaAttrs, stores: [store] }, ops);
731
+ var result = instaml.transform(
732
+ { attrsStore: zenecaAttrsStore, stores: [store] },
733
+ ops,
734
+ );
699
735
  for (const txStep of result) {
700
736
  expect(txStep[4]).toEqual({ mode: 'update' });
701
737
  }
@@ -704,7 +740,10 @@ test('mode: update', () => {
704
740
  { handle: 'test' },
705
741
  { upsert: true },
706
742
  );
707
- var result = instaml.transform({ attrs: zenecaAttrs, stores: [store] }, ops);
743
+ var result = instaml.transform(
744
+ { attrsStore: zenecaAttrsStore, stores: [store] },
745
+ ops,
746
+ );
708
747
  for (const txStep of result) {
709
748
  expect(txStep[4]).toEqual(undefined);
710
749
  }
@@ -713,7 +752,7 @@ test('mode: update', () => {
713
752
  test('it throws if you use an invalid link attr', () => {
714
753
  expect(() =>
715
754
  instaml.transform(
716
- { attrs: {} },
755
+ { attrsStore: new AttrsStoreClass({}, null) },
717
756
  instatx.tx.users[
718
757
  instatx.lookup('user_pref.email', 'test@example.com')
719
758
  ].update({
@@ -727,36 +766,39 @@ test("it doesn't throw if you have a period in your attr", () => {
727
766
  const aid = uuid();
728
767
  const iid = uuid();
729
768
  const pid = uuid();
730
- const attrs = {
731
- [aid]: {
732
- id: aid,
733
- cardinality: 'one',
734
- 'forward-identity': [uuid(), 'users', 'attr.with.dot'],
735
- 'index?': true,
736
- 'unique?': true,
737
- 'value-type': 'blob',
738
- },
739
- [iid]: {
740
- id: iid,
741
- cardinality: 'one',
742
- 'forward-identity': [uuid(), 'users', 'id'],
743
- 'index?': true,
744
- 'unique?': false,
745
- 'value-type': 'blob',
746
- },
747
- [pid]: {
748
- id: pid,
749
- cardinality: 'one',
750
- 'forward-identity': [uuid(), 'users', 'a'],
751
- 'index?': false,
752
- 'unique?': false,
753
- 'value-type': 'blob',
769
+ const attrsStore = new AttrsStoreClass(
770
+ {
771
+ [aid]: {
772
+ id: aid,
773
+ cardinality: 'one',
774
+ 'forward-identity': [uuid(), 'users', 'attr.with.dot'],
775
+ 'index?': true,
776
+ 'unique?': true,
777
+ 'value-type': 'blob',
778
+ } as unknown as InstantDBAttr,
779
+ [iid]: {
780
+ id: iid,
781
+ cardinality: 'one',
782
+ 'forward-identity': [uuid(), 'users', 'id'],
783
+ 'index?': true,
784
+ 'unique?': false,
785
+ 'value-type': 'blob',
786
+ } as unknown as InstantDBAttr,
787
+ [pid]: {
788
+ id: pid,
789
+ cardinality: 'one',
790
+ 'forward-identity': [uuid(), 'users', 'a'],
791
+ 'index?': false,
792
+ 'unique?': false,
793
+ 'value-type': 'blob',
794
+ } as unknown as InstantDBAttr,
754
795
  },
755
- };
796
+ null,
797
+ );
756
798
 
757
799
  expect(
758
800
  instaml.transform(
759
- { attrs },
801
+ { attrsStore },
760
802
  instatx.tx.users[instatx.lookup('attr.with.dot', 'value')].update({
761
803
  a: 1,
762
804
  }),
@@ -775,7 +817,10 @@ test("it doesn't create duplicate ref attrs", () => {
775
817
  instatx.tx.nsB[bid].update({}).link({ nsA: aid }),
776
818
  ];
777
819
 
778
- const result = instaml.transform({ attrs: {} }, ops);
820
+ const result = instaml.transform(
821
+ { attrsStore: new AttrsStoreClass({}, null) },
822
+ ops,
823
+ );
779
824
 
780
825
  const expected = [
781
826
  [
@@ -863,7 +908,7 @@ test('Schema: uses info in `attrs` and `links`', () => {
863
908
 
864
909
  const result = instaml.transform(
865
910
  {
866
- attrs: zenecaAttrs,
911
+ attrsStore: zenecaAttrsStore,
867
912
  schema: schema,
868
913
  },
869
914
  ops,
@@ -947,7 +992,10 @@ test("Schema: doesn't create duplicate ref attrs", () => {
947
992
  instatx.tx.books[bookId].update({}).link({ comments: commentId }),
948
993
  ];
949
994
 
950
- const result = instaml.transform({ attrs: zenecaAttrs, schema }, ops);
995
+ const result = instaml.transform(
996
+ { attrsStore: zenecaAttrsStore, schema },
997
+ ops,
998
+ );
951
999
 
952
1000
  const expected = [
953
1001
  [
@@ -1007,7 +1055,10 @@ test('Schema: lookup creates unique attrs for custom lookups', () => {
1007
1055
  'stopanator',
1008
1056
  ];
1009
1057
 
1010
- const result = instaml.transform({ attrs: zenecaAttrs, schema }, ops);
1058
+ const result = instaml.transform(
1059
+ { attrsStore: zenecaAttrsStore, schema },
1060
+ ops,
1061
+ );
1011
1062
  const expected = [
1012
1063
  [
1013
1064
  'add-attr',
@@ -1061,7 +1112,10 @@ test('Schema: lookup creates unique attrs for lookups in link values', () => {
1061
1112
  .update({})
1062
1113
  .link({ authoredPosts: instatx.lookup('slug', 'life-is-good') });
1063
1114
 
1064
- const result = instaml.transform({ attrs: {}, schema }, ops);
1115
+ const result = instaml.transform(
1116
+ { attrsStore: new AttrsStoreClass({}, null), schema },
1117
+ ops,
1118
+ );
1065
1119
 
1066
1120
  expect(result).toEqual([
1067
1121
  [
@@ -1145,7 +1199,10 @@ test('Schema: lookup creates unique attrs for lookups in link values with arrays
1145
1199
  ],
1146
1200
  });
1147
1201
 
1148
- const result = instaml.transform({ attrs: {}, schema }, ops);
1202
+ const result = instaml.transform(
1203
+ { attrsStore: new AttrsStoreClass({}, null), schema },
1204
+ ops,
1205
+ );
1149
1206
 
1150
1207
  const expected = [
1151
1208
  [
@@ -1241,7 +1298,10 @@ test('Schema: lookup creates unique ref attrs for ref lookup', () => {
1241
1298
  uid,
1242
1299
  ];
1243
1300
 
1244
- const result = instaml.transform({ attrs: {}, schema }, ops);
1301
+ const result = instaml.transform(
1302
+ { attrsStore: new AttrsStoreClass({}, null), schema },
1303
+ ops,
1304
+ );
1245
1305
  const expected = [
1246
1306
  [
1247
1307
  'add-attr',
@@ -1324,7 +1384,10 @@ test('Schema: lookup creates unique ref attrs for ref lookup in link value', ()
1324
1384
  uid,
1325
1385
  ];
1326
1386
 
1327
- const result = instaml.transform({ attrs: {}, schema }, ops);
1387
+ const result = instaml.transform(
1388
+ { attrsStore: new AttrsStoreClass({}, null), schema },
1389
+ ops,
1390
+ );
1328
1391
 
1329
1392
  const expected = [
1330
1393
  [
@@ -1388,7 +1451,7 @@ test('Schema: populates checked-data-type', () => {
1388
1451
 
1389
1452
  const result = instaml.transform(
1390
1453
  {
1391
- attrs: zenecaAttrs,
1454
+ attrsStore: zenecaAttrsStore,
1392
1455
  schema: schema,
1393
1456
  },
1394
1457
  ops,
@@ -1501,6 +1564,7 @@ test('Schema: populates checked-data-type', () => {
1501
1564
  test('instatx should not be too permissive', () => {
1502
1565
  const ops = instatx.tx.books[uuid()].update({
1503
1566
  title: 'New Title',
1567
+ // @ts-expect-error: testing invalid states
1504
1568
  }).this_is_an_unknown_op;
1505
1569
  expect(ops).toBeUndefined();
1506
1570
  });