@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
package/src/instaql.ts CHANGED
@@ -47,8 +47,8 @@ class AttrNotFoundError extends Error {
47
47
  }
48
48
  }
49
49
 
50
- function idAttr(attrsStore: s.AttrsStore, ns: string): InstantDBAttr {
51
- const attr = s.getPrimaryKeyAttr(attrsStore, ns);
50
+ function idAttr(store: s.Store, ns: string): InstantDBAttr {
51
+ const attr = s.getPrimaryKeyAttr(store, ns);
52
52
 
53
53
  if (!attr) {
54
54
  throw new AttrNotFoundError(`Could not find id attr for ${ns}`);
@@ -58,22 +58,22 @@ function idAttr(attrsStore: s.AttrsStore, ns: string): InstantDBAttr {
58
58
 
59
59
  function defaultWhere(
60
60
  makeVar: MakeVar,
61
- attrsStore: s.AttrsStore,
61
+ store: s.Store,
62
62
  etype: string,
63
63
  level: number,
64
64
  ): Pats {
65
- return [eidWhere(makeVar, attrsStore, etype, level)];
65
+ return [eidWhere(makeVar, store, etype, level)];
66
66
  }
67
67
 
68
68
  function eidWhere(
69
69
  makeVar: MakeVar,
70
- attrsStore: s.AttrsStore,
70
+ store: s.Store,
71
71
  etype: string,
72
72
  level: number,
73
73
  ): Pat {
74
74
  return [
75
75
  makeVar(etype, level),
76
- idAttr(attrsStore, etype).id,
76
+ idAttr(store, etype).id,
77
77
  makeVar(etype, level),
78
78
  makeVar('time', level),
79
79
  ];
@@ -85,13 +85,13 @@ function replaceInAttrPat(attrPat: Pat, needle: string, v: any): Pat {
85
85
 
86
86
  function refAttrPat(
87
87
  makeVar: MakeVar,
88
- attrsStore: s.AttrsStore,
88
+ store: s.Store,
89
89
  etype: string,
90
90
  level: number,
91
91
  label: string,
92
92
  ): [string, number, Pat, InstantDBAttr, boolean] {
93
- const fwdAttr = s.getAttrByFwdIdentName(attrsStore, etype, label);
94
- const revAttr = s.getAttrByReverseIdentName(attrsStore, etype, label);
93
+ const fwdAttr = s.getAttrByFwdIdentName(store, etype, label);
94
+ const revAttr = s.getAttrByReverseIdentName(store, etype, label);
95
95
  const attr = fwdAttr || revAttr;
96
96
 
97
97
  if (!attr) {
@@ -235,18 +235,14 @@ function parseValue(attr: InstantDBAttr, v: any) {
235
235
 
236
236
  function valueAttrPat(
237
237
  makeVar: MakeVar,
238
- attrsStore: s.AttrsStore,
238
+ store: s.Store,
239
239
  valueEtype: string,
240
240
  valueLevel: number,
241
241
  valueLabel: string,
242
242
  v: any,
243
243
  ): Pat {
244
- const fwdAttr = s.getAttrByFwdIdentName(attrsStore, valueEtype, valueLabel);
245
- const revAttr = s.getAttrByReverseIdentName(
246
- attrsStore,
247
- valueEtype,
248
- valueLabel,
249
- );
244
+ const fwdAttr = s.getAttrByFwdIdentName(store, valueEtype, valueLabel);
245
+ const revAttr = s.getAttrByReverseIdentName(store, valueEtype, valueLabel);
250
246
  const attr = fwdAttr || revAttr;
251
247
 
252
248
  if (!attr) {
@@ -256,7 +252,7 @@ function valueAttrPat(
256
252
  }
257
253
 
258
254
  if (v?.hasOwnProperty('$isNull')) {
259
- const idAttr = s.getAttrByFwdIdentName(attrsStore, valueEtype, 'id');
255
+ const idAttr = s.getAttrByFwdIdentName(store, valueEtype, 'id');
260
256
  if (!idAttr) {
261
257
  throw new AttrNotFoundError(
262
258
  `No attr for etype = ${valueEtype} label = id`,
@@ -284,7 +280,7 @@ function valueAttrPat(
284
280
 
285
281
  function refAttrPats(
286
282
  makeVar: MakeVar,
287
- attrsStore: s.AttrsStore,
283
+ store: s.Store,
288
284
  etype: string,
289
285
  level: number,
290
286
  refsPath: string[],
@@ -294,7 +290,7 @@ function refAttrPats(
294
290
  const [etype, level, attrPats] = acc;
295
291
  const [nextEtype, nextLevel, attrPat] = refAttrPat(
296
292
  makeVar,
297
- attrsStore,
293
+ store,
298
294
  etype,
299
295
  level,
300
296
  label,
@@ -309,7 +305,7 @@ function refAttrPats(
309
305
 
310
306
  function whereCondAttrPats(
311
307
  makeVar: MakeVar,
312
- attrsStore: s.AttrsStore,
308
+ store: s.Store,
313
309
  etype: string,
314
310
  level: number,
315
311
  path: string[],
@@ -319,14 +315,14 @@ function whereCondAttrPats(
319
315
  const valueLabel = path[path.length - 1];
320
316
  const [lastEtype, lastLevel, refPats] = refAttrPats(
321
317
  makeVar,
322
- attrsStore,
318
+ store,
323
319
  etype,
324
320
  level,
325
321
  refsPath,
326
322
  );
327
323
  const valuePat = valueAttrPat(
328
324
  makeVar,
329
- attrsStore,
325
+ store,
330
326
  lastEtype,
331
327
  lastLevel,
332
328
  valueLabel,
@@ -363,7 +359,7 @@ function genMakeVar(baseMakeVar: MakeVar, joinSym: string, orIdx: number) {
363
359
  function parseWhereClauses(
364
360
  makeVar: MakeVar,
365
361
  clauseType: 'or' | 'and' /* 'or' | 'and' */,
366
- attrsStore: s.AttrsStore,
362
+ store: s.Store,
367
363
  etype: string,
368
364
  level: number,
369
365
  whereValue: any,
@@ -371,7 +367,7 @@ function parseWhereClauses(
371
367
  const joinSym = makeVar(etype, level);
372
368
  const patterns: FullPats = whereValue.map((w, i) => {
373
369
  const makeNamespacedVar = genMakeVar(makeVar, joinSym, i);
374
- return parseWhere(makeNamespacedVar, attrsStore, etype, level, w);
370
+ return parseWhere(makeNamespacedVar, store, etype, level, w);
375
371
  });
376
372
  return { [clauseType]: { patterns, joinSym } } as AndPat | OrPat;
377
373
  }
@@ -390,31 +386,29 @@ function growPath<T>(path: T[]) {
390
386
  // to capture any intermediate nulls
391
387
  function whereCondAttrPatsForNullIsTrue(
392
388
  makeVar: MakeVar,
393
- attrsStore: s.AttrsStore,
389
+ store: s.Store,
394
390
  etype: string,
395
391
  level: number,
396
392
  path: string[],
397
393
  ): Pats[] {
398
394
  return growPath(path).map((path) =>
399
- whereCondAttrPats(makeVar, attrsStore, etype, level, path, {
400
- $isNull: true,
401
- }),
395
+ whereCondAttrPats(makeVar, store, etype, level, path, { $isNull: true }),
402
396
  );
403
397
  }
404
398
 
405
399
  function parseWhere(
406
400
  makeVar: MakeVar,
407
- attrsStore: s.AttrsStore,
401
+ store: s.Store,
408
402
  etype: string,
409
403
  level: number,
410
404
  where: Record<string, any>,
411
405
  ): FullPats {
412
406
  return Object.entries(where).flatMap(([k, v]) => {
413
407
  if (isOrClauses([k, v])) {
414
- return parseWhereClauses(makeVar, 'or', attrsStore, etype, level, v);
408
+ return parseWhereClauses(makeVar, 'or', store, etype, level, v);
415
409
  }
416
410
  if (isAndClauses([k, v])) {
417
- return parseWhereClauses(makeVar, 'and', attrsStore, etype, level, v);
411
+ return parseWhereClauses(makeVar, 'and', store, etype, level, v);
418
412
  }
419
413
 
420
414
  // Temporary hack until we have support for a uuid index on `id`
@@ -433,17 +427,10 @@ function parseWhere(
433
427
  if (v?.hasOwnProperty('$not')) {
434
428
  // `$not` won't pick up entities that are missing the attr, so we
435
429
  // add in a `$isNull` to catch those too.
436
- const notPats = whereCondAttrPats(
437
- makeVar,
438
- attrsStore,
439
- etype,
440
- level,
441
- path,
442
- v,
443
- );
430
+ const notPats = whereCondAttrPats(makeVar, store, etype, level, path, v);
444
431
  const nilPats = whereCondAttrPatsForNullIsTrue(
445
432
  makeVar,
446
- attrsStore,
433
+ store,
447
434
  etype,
448
435
  level,
449
436
  path,
@@ -466,7 +453,7 @@ function parseWhere(
466
453
  or: {
467
454
  patterns: whereCondAttrPatsForNullIsTrue(
468
455
  makeVar,
469
- attrsStore,
456
+ store,
470
457
  etype,
471
458
  level,
472
459
  path,
@@ -477,22 +464,22 @@ function parseWhere(
477
464
  ];
478
465
  }
479
466
 
480
- return whereCondAttrPats(makeVar, attrsStore, etype, level, path, v);
467
+ return whereCondAttrPats(makeVar, store, etype, level, path, v);
481
468
  });
482
469
  }
483
470
 
484
471
  function makeWhere(
485
- attrsStore: s.AttrsStore,
472
+ store: s.Store,
486
473
  etype: string,
487
474
  level: number,
488
475
  where: Record<string, any> | null,
489
476
  ): FullPats {
490
477
  const makeVar = makeVarImpl;
491
478
  if (!where) {
492
- return defaultWhere(makeVar, attrsStore, etype, level);
479
+ return defaultWhere(makeVar, store, etype, level);
493
480
  }
494
- const parsedWhere = parseWhere(makeVar, attrsStore, etype, level, where);
495
- return parsedWhere.concat(defaultWhere(makeVar, attrsStore, etype, level));
481
+ const parsedWhere = parseWhere(makeVar, store, etype, level, where);
482
+ return parsedWhere.concat(defaultWhere(makeVar, store, etype, level));
496
483
  }
497
484
 
498
485
  // Find
@@ -507,7 +494,7 @@ function makeFind(makeVar: MakeVar, etype: string, level: number) {
507
494
 
508
495
  function makeJoin(
509
496
  makeVar: MakeVar,
510
- attrsStore: s.AttrsStore,
497
+ store: s.Store,
511
498
  etype: string,
512
499
  level: number,
513
500
  label: string,
@@ -515,7 +502,7 @@ function makeJoin(
515
502
  ) {
516
503
  const [nextEtype, nextLevel, pat, attr, isForward] = refAttrPat(
517
504
  makeVar,
518
- attrsStore,
505
+ store,
519
506
  etype,
520
507
  level,
521
508
  label,
@@ -524,13 +511,7 @@ function makeJoin(
524
511
  return [nextEtype, nextLevel, actualized, attr, isForward];
525
512
  }
526
513
 
527
- function extendObjects(
528
- makeVar: MakeVar,
529
- store: s.Store,
530
- attrsStore: s.AttrsStore,
531
- { etype, level, form },
532
- objects,
533
- ) {
514
+ function extendObjects(makeVar, store, { etype, level, form }, objects) {
534
515
  const childQueries = Object.keys(form).filter((c) => c !== '$');
535
516
  if (!childQueries.length) {
536
517
  return Object.values(objects);
@@ -539,20 +520,20 @@ function extendObjects(
539
520
  const childResults = childQueries.map(function getChildResult(label) {
540
521
  const isSingular = Boolean(
541
522
  store.cardinalityInference &&
542
- attrsStore.linkIndex?.[etype]?.[label]?.isSingular,
523
+ store.linkIndex?.[etype]?.[label]?.isSingular,
543
524
  );
544
525
 
545
526
  try {
546
527
  const [nextEtype, nextLevel, join] = makeJoin(
547
528
  makeVar,
548
- attrsStore,
529
+ store,
549
530
  etype,
550
531
  level,
551
532
  label,
552
533
  eid,
553
534
  );
554
535
 
555
- const childrenArray = queryOne(store, attrsStore, {
536
+ const childrenArray = queryOne(store, {
556
537
  etype: nextEtype,
557
538
  level: nextLevel,
558
539
  form: form[label],
@@ -643,38 +624,38 @@ function isBefore(startCursor, orderAttr, direction, idVec) {
643
624
  );
644
625
  }
645
626
 
646
- function orderAttrFromCursor(attrsStore: s.AttrsStore, cursor) {
627
+ function orderAttrFromCursor(store: s.Store, cursor) {
647
628
  const cursorAttrId = cursor[1];
648
- return attrsStore.getAttr(cursorAttrId);
629
+ return store.attrs[cursorAttrId];
649
630
  }
650
631
 
651
- function orderAttrFromOrder(attrsStore: s.AttrsStore, etype, order) {
632
+ function orderAttrFromOrder(store: s.Store, etype, order) {
652
633
  const label = Object.keys(order)[0];
653
- return s.getAttrByFwdIdentName(attrsStore, etype, label);
634
+ return s.getAttrByFwdIdentName(store, etype, label);
654
635
  }
655
636
 
656
- function getOrderAttr(attrsStore: s.AttrsStore, etype, cursor, order) {
637
+ function getOrderAttr(store: s.Store, etype, cursor, order) {
657
638
  if (cursor) {
658
- return orderAttrFromCursor(attrsStore, cursor);
639
+ return orderAttrFromCursor(store, cursor);
659
640
  }
660
641
  if (order) {
661
- return orderAttrFromOrder(attrsStore, etype, order);
642
+ return orderAttrFromOrder(store, etype, order);
662
643
  }
663
644
  }
664
645
 
665
646
  function objectAttrs(
666
- attrsStore: s.AttrsStore,
647
+ store: s.Store,
667
648
  etype,
668
649
  dq,
669
650
  ): Map<string, InstantDBAttr> | undefined {
670
651
  if (!Array.isArray(dq.fields)) {
671
- return s.getBlobAttrs(attrsStore, etype);
652
+ return s.getBlobAttrs(store, etype);
672
653
  }
673
654
 
674
655
  const attrs = new Map();
675
656
 
676
657
  for (const field of dq.fields) {
677
- const attr = s.getAttrByFwdIdentName(attrsStore, etype, field);
658
+ const attr = s.getAttrByFwdIdentName(store, etype, field);
678
659
  const label = attr?.['forward-identity']?.[2];
679
660
  if (label && s.isBlob(attr)) {
680
661
  attrs.set(label, attr);
@@ -682,7 +663,7 @@ function objectAttrs(
682
663
  }
683
664
  // Ensure we add the id field to avoid empty objects
684
665
  if (!attrs.has('id')) {
685
- const attr = s.getAttrByFwdIdentName(attrsStore, etype, 'id');
666
+ const attr = s.getAttrByFwdIdentName(store, etype, 'id');
686
667
  const label = attr?.['forward-identity']?.[2];
687
668
  if (label) {
688
669
  attrs.set(label, attr);
@@ -694,7 +675,6 @@ function objectAttrs(
694
675
 
695
676
  function runDataloadAndReturnObjects(
696
677
  store: s.Store,
697
- attrsStore: s.AttrsStore,
698
678
  { etype, pageInfo, dq, form },
699
679
  ) {
700
680
  const order = form?.$?.order;
@@ -704,7 +684,7 @@ function runDataloadAndReturnObjects(
704
684
  let idVecs = datalogQuery(store, dq);
705
685
 
706
686
  const startCursor = pageInfo?.['start-cursor'];
707
- const orderAttr = getOrderAttr(attrsStore, etype, startCursor, order);
687
+ const orderAttr = getOrderAttr(store, etype, startCursor, order);
708
688
 
709
689
  if (orderAttr && orderAttr?.['forward-identity']?.[2] !== 'id') {
710
690
  const isDate = orderAttr['checked-data-type'] === 'date';
@@ -731,7 +711,7 @@ function runDataloadAndReturnObjects(
731
711
  );
732
712
 
733
713
  let objects = {};
734
- const attrs = objectAttrs(attrsStore, etype, dq);
714
+ const attrs = objectAttrs(store, etype, dq);
735
715
 
736
716
  for (const idVec of idVecs) {
737
717
  const [id] = idVec;
@@ -791,7 +771,6 @@ function isLeading(form) {
791
771
  */
792
772
  function resolveObjects(
793
773
  store: s.Store,
794
- attrsStore: s.AttrsStore,
795
774
  { etype, level, form, join, pageInfo },
796
775
  ) {
797
776
  // Wait for server to tell us where we start if we don't start from the beginning
@@ -799,14 +778,11 @@ function resolveObjects(
799
778
  return [];
800
779
  }
801
780
 
802
- const where = withJoin(
803
- makeWhere(attrsStore, etype, level, form.$?.where),
804
- join,
805
- );
781
+ const where = withJoin(makeWhere(store, etype, level, form.$?.where), join);
806
782
  const find = makeFind(makeVarImpl, etype, level);
807
783
  const fields = form.$?.fields;
808
784
 
809
- const objs = runDataloadAndReturnObjects(store, attrsStore, {
785
+ const objs = runDataloadAndReturnObjects(store, {
810
786
  etype,
811
787
  pageInfo,
812
788
  form,
@@ -840,9 +816,9 @@ function resolveObjects(
840
816
  * This swallows the missing attr error and returns
841
817
  * an empty result instead
842
818
  */
843
- function guardedResolveObjects(store: s.Store, attrsStore: s.AttrsStore, opts) {
819
+ function guardedResolveObjects(store: s.Store, opts) {
844
820
  try {
845
- return resolveObjects(store, attrsStore, opts);
821
+ return resolveObjects(store, opts);
846
822
  } catch (e) {
847
823
  if (e instanceof AttrNotFoundError) {
848
824
  return {};
@@ -863,9 +839,9 @@ function guardedResolveObjects(store: s.Store, attrsStore: s.AttrsStore, opts) {
863
839
  * `guardResolveObjects` will return the relevant `users` objects
864
840
  * `extendObjects` will then extend each `user` object with relevant `posts`.
865
841
  */
866
- function queryOne(store: s.Store, attrsStore: s.AttrsStore, opts) {
867
- const objects = guardedResolveObjects(store, attrsStore, opts);
868
- return extendObjects(makeVarImpl, store, attrsStore, opts, objects);
842
+ function queryOne(store: s.Store, opts) {
843
+ const objects = guardedResolveObjects(store, opts);
844
+ return extendObjects(makeVarImpl, store, opts, objects);
869
845
  }
870
846
 
871
847
  function formatPageInfo(
@@ -894,12 +870,10 @@ function formatPageInfo(
894
870
  export default function query(
895
871
  {
896
872
  store,
897
- attrsStore,
898
873
  pageInfo,
899
874
  aggregate,
900
875
  }: {
901
876
  store: s.Store;
902
- attrsStore: s.AttrsStore;
903
877
  pageInfo: any;
904
878
  aggregate: any;
905
879
  },
@@ -911,7 +885,7 @@ export default function query(
911
885
  // so don't bother querying further
912
886
  return res;
913
887
  }
914
- res[k] = queryOne(store, attrsStore, {
888
+ res[k] = queryOne(store, {
915
889
  etype: k,
916
890
  form: q[k],
917
891
  level: 0,