@tanstack/db 0.0.23 → 0.0.24

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 (44) hide show
  1. package/dist/cjs/proxy.cjs +21 -0
  2. package/dist/cjs/proxy.cjs.map +1 -1
  3. package/dist/cjs/query/builder/index.cjs +72 -0
  4. package/dist/cjs/query/builder/index.cjs.map +1 -1
  5. package/dist/cjs/query/builder/index.d.cts +64 -0
  6. package/dist/cjs/query/compiler/index.cjs +44 -8
  7. package/dist/cjs/query/compiler/index.cjs.map +1 -1
  8. package/dist/cjs/query/compiler/index.d.cts +4 -7
  9. package/dist/cjs/query/compiler/joins.cjs +14 -6
  10. package/dist/cjs/query/compiler/joins.cjs.map +1 -1
  11. package/dist/cjs/query/compiler/joins.d.cts +4 -8
  12. package/dist/cjs/query/compiler/types.d.cts +10 -0
  13. package/dist/cjs/query/optimizer.cjs +283 -0
  14. package/dist/cjs/query/optimizer.cjs.map +1 -0
  15. package/dist/cjs/query/optimizer.d.cts +42 -0
  16. package/dist/cjs/utils.cjs +42 -0
  17. package/dist/cjs/utils.cjs.map +1 -0
  18. package/dist/cjs/utils.d.cts +18 -0
  19. package/dist/esm/proxy.js +21 -0
  20. package/dist/esm/proxy.js.map +1 -1
  21. package/dist/esm/query/builder/index.d.ts +64 -0
  22. package/dist/esm/query/builder/index.js +72 -0
  23. package/dist/esm/query/builder/index.js.map +1 -1
  24. package/dist/esm/query/compiler/index.d.ts +4 -7
  25. package/dist/esm/query/compiler/index.js +44 -8
  26. package/dist/esm/query/compiler/index.js.map +1 -1
  27. package/dist/esm/query/compiler/joins.d.ts +4 -8
  28. package/dist/esm/query/compiler/joins.js +14 -6
  29. package/dist/esm/query/compiler/joins.js.map +1 -1
  30. package/dist/esm/query/compiler/types.d.ts +10 -0
  31. package/dist/esm/query/optimizer.d.ts +42 -0
  32. package/dist/esm/query/optimizer.js +283 -0
  33. package/dist/esm/query/optimizer.js.map +1 -0
  34. package/dist/esm/utils.d.ts +18 -0
  35. package/dist/esm/utils.js +42 -0
  36. package/dist/esm/utils.js.map +1 -0
  37. package/package.json +1 -1
  38. package/src/proxy.ts +24 -0
  39. package/src/query/builder/index.ts +104 -0
  40. package/src/query/compiler/index.ts +85 -18
  41. package/src/query/compiler/joins.ts +21 -13
  42. package/src/query/compiler/types.ts +12 -0
  43. package/src/query/optimizer.ts +738 -0
  44. package/src/utils.ts +86 -0
package/src/utils.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Generic utility functions
3
+ */
4
+
5
+ /**
6
+ * Deep equality function that compares two values recursively
7
+ *
8
+ * @param a - First value to compare
9
+ * @param b - Second value to compare
10
+ * @returns True if the values are deeply equal, false otherwise
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * deepEquals({ a: 1, b: 2 }, { b: 2, a: 1 }) // true (property order doesn't matter)
15
+ * deepEquals([1, { x: 2 }], [1, { x: 2 }]) // true
16
+ * deepEquals({ a: 1 }, { a: 2 }) // false
17
+ * ```
18
+ */
19
+ export function deepEquals(a: any, b: any): boolean {
20
+ return deepEqualsInternal(a, b, new Map())
21
+ }
22
+
23
+ /**
24
+ * Internal implementation with cycle detection to prevent infinite recursion
25
+ */
26
+ function deepEqualsInternal(
27
+ a: any,
28
+ b: any,
29
+ visited: Map<object, object>
30
+ ): boolean {
31
+ // Handle strict equality (primitives, same reference)
32
+ if (a === b) return true
33
+
34
+ // Handle null/undefined
35
+ if (a == null || b == null) return false
36
+
37
+ // Handle different types
38
+ if (typeof a !== typeof b) return false
39
+
40
+ // Handle arrays
41
+ if (Array.isArray(a)) {
42
+ if (!Array.isArray(b) || a.length !== b.length) return false
43
+
44
+ // Check for circular references
45
+ if (visited.has(a)) {
46
+ return visited.get(a) === b
47
+ }
48
+ visited.set(a, b)
49
+
50
+ const result = a.every((item, index) =>
51
+ deepEqualsInternal(item, b[index], visited)
52
+ )
53
+ visited.delete(a)
54
+ return result
55
+ }
56
+
57
+ // Handle objects
58
+ if (typeof a === `object`) {
59
+ // Check for circular references
60
+ if (visited.has(a)) {
61
+ return visited.get(a) === b
62
+ }
63
+ visited.set(a, b)
64
+
65
+ // Get all keys from both objects
66
+ const keysA = Object.keys(a)
67
+ const keysB = Object.keys(b)
68
+
69
+ // Check if they have the same number of keys
70
+ if (keysA.length !== keysB.length) {
71
+ visited.delete(a)
72
+ return false
73
+ }
74
+
75
+ // Check if all keys exist in both objects and their values are equal
76
+ const result = keysA.every(
77
+ (key) => key in b && deepEqualsInternal(a[key], b[key], visited)
78
+ )
79
+
80
+ visited.delete(a)
81
+ return result
82
+ }
83
+
84
+ // For primitives that aren't strictly equal
85
+ return false
86
+ }