@instantdb/core 0.22.164 → 0.22.165

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 (60) hide show
  1. package/__tests__/src/infiniteQuery.e2e.test.ts +384 -0
  2. package/__tests__/src/simple.e2e.test.ts +0 -1
  3. package/__tests__/src/utils/e2e.ts +1 -1
  4. package/dist/commonjs/Reactor.d.ts +1 -1
  5. package/dist/commonjs/Reactor.js +3 -3
  6. package/dist/commonjs/Reactor.js.map +1 -1
  7. package/dist/commonjs/index.d.ts +23 -2
  8. package/dist/commonjs/index.d.ts.map +1 -1
  9. package/dist/commonjs/index.js +25 -1
  10. package/dist/commonjs/index.js.map +1 -1
  11. package/dist/commonjs/infiniteQuery.d.ts +26 -0
  12. package/dist/commonjs/infiniteQuery.d.ts.map +1 -0
  13. package/dist/commonjs/infiniteQuery.js +422 -0
  14. package/dist/commonjs/infiniteQuery.js.map +1 -0
  15. package/dist/commonjs/instaql.d.ts.map +1 -1
  16. package/dist/commonjs/instaql.js +18 -5
  17. package/dist/commonjs/instaql.js.map +1 -1
  18. package/dist/commonjs/queryTypes.d.ts +2 -2
  19. package/dist/commonjs/queryTypes.d.ts.map +1 -1
  20. package/dist/commonjs/queryTypes.js.map +1 -1
  21. package/dist/commonjs/utils/Deferred.d.ts +5 -4
  22. package/dist/commonjs/utils/Deferred.d.ts.map +1 -1
  23. package/dist/commonjs/utils/Deferred.js.map +1 -1
  24. package/dist/commonjs/utils/weakHash.d.ts.map +1 -1
  25. package/dist/commonjs/utils/weakHash.js +4 -0
  26. package/dist/commonjs/utils/weakHash.js.map +1 -1
  27. package/dist/esm/Reactor.d.ts +1 -1
  28. package/dist/esm/Reactor.js +1 -1
  29. package/dist/esm/Reactor.js.map +1 -1
  30. package/dist/esm/index.d.ts +23 -2
  31. package/dist/esm/index.d.ts.map +1 -1
  32. package/dist/esm/index.js +25 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/infiniteQuery.d.ts +26 -0
  35. package/dist/esm/infiniteQuery.d.ts.map +1 -0
  36. package/dist/esm/infiniteQuery.js +417 -0
  37. package/dist/esm/infiniteQuery.js.map +1 -0
  38. package/dist/esm/instaql.d.ts.map +1 -1
  39. package/dist/esm/instaql.js +18 -5
  40. package/dist/esm/instaql.js.map +1 -1
  41. package/dist/esm/queryTypes.d.ts +2 -2
  42. package/dist/esm/queryTypes.d.ts.map +1 -1
  43. package/dist/esm/queryTypes.js.map +1 -1
  44. package/dist/esm/utils/Deferred.d.ts +5 -4
  45. package/dist/esm/utils/Deferred.d.ts.map +1 -1
  46. package/dist/esm/utils/Deferred.js.map +1 -1
  47. package/dist/esm/utils/weakHash.d.ts.map +1 -1
  48. package/dist/esm/utils/weakHash.js +4 -0
  49. package/dist/esm/utils/weakHash.js.map +1 -1
  50. package/dist/standalone/index.js +1731 -1432
  51. package/dist/standalone/index.umd.cjs +3 -3
  52. package/package.json +2 -2
  53. package/src/Reactor.js +1 -1
  54. package/src/index.ts +49 -0
  55. package/src/infiniteQuery.ts +573 -0
  56. package/src/instaql.ts +25 -7
  57. package/src/queryTypes.ts +1 -2
  58. package/src/utils/{Deferred.js → Deferred.ts} +4 -4
  59. package/src/utils/weakHash.ts +4 -0
  60. package/vitest.config.ts +6 -0
package/src/instaql.ts CHANGED
@@ -628,20 +628,29 @@ function comparableDate(x) {
628
628
  return new Date(x).getTime();
629
629
  }
630
630
 
631
- function isBefore(startCursor, orderAttr, direction, idVec) {
632
- const [c_e, _c_a, c_v, c_t] = startCursor;
633
- const compareVal = direction === 'desc' ? 1 : -1;
631
+ function compareToCursor(cursor, orderAttr, idVec) {
632
+ const [c_e, _c_a, c_v, c_t] = cursor;
633
+
634
634
  if (orderAttr['forward-identity']?.[2] === 'id') {
635
- return compareOrderTriples(idVec, [c_e, c_t], null) === compareVal;
635
+ return compareOrderTriples(idVec, [c_e, c_t], null);
636
636
  }
637
+
637
638
  const [e, v] = idVec;
638
639
  const dataType = orderAttr['checked-data-type'];
639
640
  const v_new = dataType === 'date' ? comparableDate(v) : v;
640
641
  const c_v_new = dataType === 'date' ? comparableDate(c_v) : c_v;
641
642
 
642
- return (
643
- compareOrderTriples([e, v_new], [c_e, c_v_new], dataType) === compareVal
644
- );
643
+ return compareOrderTriples([e, v_new], [c_e, c_v_new], dataType);
644
+ }
645
+
646
+ function isBefore(startCursor, orderAttr, direction, idVec) {
647
+ const cmp = compareToCursor(startCursor, orderAttr, idVec);
648
+ return direction === 'desc' ? cmp > 0 : cmp < 0;
649
+ }
650
+
651
+ function isAfter(endCursor, orderAttr, direction, idVec) {
652
+ const cmp = compareToCursor(endCursor, orderAttr, idVec);
653
+ return direction === 'desc' ? cmp < 0 : cmp > 0;
645
654
  }
646
655
 
647
656
  function orderAttrFromCursor(attrsStore: s.AttrsStore, cursor) {
@@ -705,6 +714,7 @@ function runDataloadAndReturnObjects(
705
714
  let idVecs = datalogQuery(store, dq);
706
715
 
707
716
  const startCursor = pageInfo?.['start-cursor'];
717
+ const endCursor = pageInfo?.['end-cursor'];
708
718
  const orderAttr = getOrderAttr(attrsStore, etype, startCursor, order);
709
719
 
710
720
  if (orderAttr && orderAttr?.['forward-identity']?.[2] !== 'id') {
@@ -748,6 +758,14 @@ function runDataloadAndReturnObjects(
748
758
  continue;
749
759
  }
750
760
 
761
+ if (
762
+ endCursor &&
763
+ orderAttr &&
764
+ isAfter(endCursor, orderAttr, direction, idVec)
765
+ ) {
766
+ continue;
767
+ }
768
+
751
769
  const obj = s.getAsObject(store, attrs, id);
752
770
  if (obj) {
753
771
  objects[id] = obj;
package/src/queryTypes.ts CHANGED
@@ -378,7 +378,7 @@ type InstaQLEntity<
378
378
  InstaQLEntitySubqueryResult<Schema, EntityName, Subquery, UseDates>
379
379
  >;
380
380
 
381
- type InstaQLQueryEntityResult<
381
+ export type InstaQLQueryEntityResult<
382
382
  Entities extends EntitiesDef,
383
383
  EntityName extends keyof Entities,
384
384
  Query extends {
@@ -712,7 +712,6 @@ export {
712
712
  InstaQLQueryResult,
713
713
  InstaQLParams,
714
714
  InstaQLOptions,
715
- InstaQLQueryEntityResult,
716
715
  InstaQLEntitySubquery,
717
716
  InstaQLEntity,
718
717
  InstaQLResult,
@@ -1,7 +1,7 @@
1
- export class Deferred {
2
- promise;
3
- _resolve;
4
- _reject;
1
+ export class Deferred<T = any> {
2
+ promise: Promise<T>;
3
+ _resolve: (value: T) => void;
4
+ _reject: (...reason: any) => void;
5
5
 
6
6
  constructor() {
7
7
  this.promise = new Promise((resolve, reject) => {
@@ -57,6 +57,10 @@ export default function weakHash(input: any): string {
57
57
 
58
58
  for (let i = 0; i < keys.length; i++) {
59
59
  const key = keys[i];
60
+ if (input[key] === undefined) {
61
+ // Ignore undefined keys in the hash
62
+ continue;
63
+ }
60
64
  // Hash the key using string hash
61
65
  const keyHash = weakHash(key);
62
66
  hash ^= parseInt(keyHash, 16);
package/vitest.config.ts CHANGED
@@ -9,9 +9,15 @@ export default defineConfig({
9
9
  test: {
10
10
  name: 'e2e',
11
11
  include: ['**/**.e2e.test.ts'],
12
+ expect: {
13
+ poll: {
14
+ timeout: 10_000,
15
+ },
16
+ },
12
17
  browser: {
13
18
  enabled: true,
14
19
  provider: playwright(),
20
+ screenshotFailures: false,
15
21
  headless: true,
16
22
  instances: [{ browser: 'chromium' }],
17
23
  },