@tanstack/db 0.0.12 → 0.0.14

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 (49) hide show
  1. package/dist/cjs/SortedMap.cjs +38 -11
  2. package/dist/cjs/SortedMap.cjs.map +1 -1
  3. package/dist/cjs/SortedMap.d.cts +10 -0
  4. package/dist/cjs/collection.cjs +467 -95
  5. package/dist/cjs/collection.cjs.map +1 -1
  6. package/dist/cjs/collection.d.cts +81 -5
  7. package/dist/cjs/index.cjs +2 -0
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/index.d.cts +1 -0
  10. package/dist/cjs/optimistic-action.cjs +21 -0
  11. package/dist/cjs/optimistic-action.cjs.map +1 -0
  12. package/dist/cjs/optimistic-action.d.cts +39 -0
  13. package/dist/cjs/query/compiled-query.cjs +21 -11
  14. package/dist/cjs/query/compiled-query.cjs.map +1 -1
  15. package/dist/cjs/query/query-builder.cjs +2 -2
  16. package/dist/cjs/query/query-builder.cjs.map +1 -1
  17. package/dist/cjs/transactions.cjs +3 -1
  18. package/dist/cjs/transactions.cjs.map +1 -1
  19. package/dist/cjs/transactions.d.cts +4 -4
  20. package/dist/cjs/types.d.cts +45 -1
  21. package/dist/esm/SortedMap.d.ts +10 -0
  22. package/dist/esm/SortedMap.js +38 -11
  23. package/dist/esm/SortedMap.js.map +1 -1
  24. package/dist/esm/collection.d.ts +81 -5
  25. package/dist/esm/collection.js +467 -95
  26. package/dist/esm/collection.js.map +1 -1
  27. package/dist/esm/index.d.ts +1 -0
  28. package/dist/esm/index.js +2 -0
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/optimistic-action.d.ts +39 -0
  31. package/dist/esm/optimistic-action.js +21 -0
  32. package/dist/esm/optimistic-action.js.map +1 -0
  33. package/dist/esm/query/compiled-query.js +21 -11
  34. package/dist/esm/query/compiled-query.js.map +1 -1
  35. package/dist/esm/query/query-builder.js +2 -2
  36. package/dist/esm/query/query-builder.js.map +1 -1
  37. package/dist/esm/transactions.d.ts +4 -4
  38. package/dist/esm/transactions.js +3 -1
  39. package/dist/esm/transactions.js.map +1 -1
  40. package/dist/esm/types.d.ts +45 -1
  41. package/package.json +1 -1
  42. package/src/SortedMap.ts +46 -13
  43. package/src/collection.ts +624 -119
  44. package/src/index.ts +1 -0
  45. package/src/optimistic-action.ts +65 -0
  46. package/src/query/compiled-query.ts +36 -14
  47. package/src/query/query-builder.ts +2 -2
  48. package/src/transactions.ts +14 -5
  49. package/src/types.ts +48 -1
@@ -23,6 +23,33 @@ class SortedMap {
23
23
  if (a > b) return 1;
24
24
  return 0;
25
25
  }
26
+ /**
27
+ * Finds the index where a key-value pair should be inserted to maintain sort order.
28
+ * Uses binary search to find the correct position based on the value.
29
+ * Hence, it is in O(log n) time.
30
+ *
31
+ * @param key - The key to find position for
32
+ * @param value - The value to compare against
33
+ * @returns The index where the key should be inserted
34
+ */
35
+ indexOf(value) {
36
+ let left = 0;
37
+ let right = this.sortedKeys.length;
38
+ while (left < right) {
39
+ const mid = Math.floor((left + right) / 2);
40
+ const midKey = this.sortedKeys[mid];
41
+ const midValue = this.map.get(midKey);
42
+ const comparison = this.comparator(value, midValue);
43
+ if (comparison < 0) {
44
+ right = mid;
45
+ } else if (comparison > 0) {
46
+ left = mid + 1;
47
+ } else {
48
+ return mid;
49
+ }
50
+ }
51
+ return left;
52
+ }
26
53
  /**
27
54
  * Sets a key-value pair in the map and maintains sort order
28
55
  *
@@ -31,15 +58,14 @@ class SortedMap {
31
58
  * @returns This SortedMap instance for chaining
32
59
  */
33
60
  set(key, value) {
34
- this.map.set(key, value);
35
- if (!this.sortedKeys.includes(key)) {
36
- this.sortedKeys.push(key);
61
+ if (this.map.has(key)) {
62
+ const oldValue = this.map.get(key);
63
+ const oldIndex = this.indexOf(oldValue);
64
+ this.sortedKeys.splice(oldIndex, 1);
37
65
  }
38
- this.sortedKeys.sort((a, b) => {
39
- const valueA = this.map.get(a);
40
- const valueB = this.map.get(b);
41
- return this.comparator(valueA, valueB);
42
- });
66
+ const index = this.indexOf(value);
67
+ this.sortedKeys.splice(index, 0, key);
68
+ this.map.set(key, value);
43
69
  return this;
44
70
  }
45
71
  /**
@@ -58,10 +84,11 @@ class SortedMap {
58
84
  * @returns True if the key was found and removed, false otherwise
59
85
  */
60
86
  delete(key) {
61
- if (this.map.delete(key)) {
62
- const index = this.sortedKeys.indexOf(key);
87
+ if (this.map.has(key)) {
88
+ const oldValue = this.map.get(key);
89
+ const index = this.indexOf(oldValue);
63
90
  this.sortedKeys.splice(index, 1);
64
- return true;
91
+ return this.map.delete(key);
65
92
  }
66
93
  return false;
67
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SortedMap.cjs","sources":["../../src/SortedMap.ts"],"sourcesContent":["/**\n * A Map implementation that keeps its entries sorted based on a comparator function\n * @template TKey - The type of keys in the map\n * @template TValue - The type of values in the map\n */\nexport class SortedMap<TKey, TValue> {\n private map: Map<TKey, TValue>\n private sortedKeys: Array<TKey>\n private comparator: (a: TValue, b: TValue) => number\n\n /**\n * Creates a new SortedMap instance\n *\n * @param comparator - Optional function to compare values for sorting\n */\n constructor(comparator?: (a: TValue, b: TValue) => number) {\n this.map = new Map<TKey, TValue>()\n this.sortedKeys = []\n this.comparator = comparator || this.defaultComparator\n }\n\n /**\n * Default comparator function used when none is provided\n *\n * @param a - First value to compare\n * @param b - Second value to compare\n * @returns -1 if a < b, 1 if a > b, 0 if equal\n */\n private defaultComparator(a: TValue, b: TValue): number {\n if (a < b) return -1\n if (a > b) return 1\n return 0\n }\n\n /**\n * Sets a key-value pair in the map and maintains sort order\n *\n * @param key - The key to set\n * @param value - The value to associate with the key\n * @returns This SortedMap instance for chaining\n */\n set(key: TKey, value: TValue): this {\n this.map.set(key, value)\n\n if (!this.sortedKeys.includes(key)) {\n this.sortedKeys.push(key)\n }\n\n // Re-sort keys based on values\n this.sortedKeys.sort((a, b) => {\n const valueA = this.map.get(a)!\n const valueB = this.map.get(b)!\n return this.comparator(valueA, valueB)\n })\n\n return this\n }\n\n /**\n * Gets a value by its key\n *\n * @param key - The key to look up\n * @returns The value associated with the key, or undefined if not found\n */\n get(key: TKey): TValue | undefined {\n return this.map.get(key)\n }\n\n /**\n * Removes a key-value pair from the map\n *\n * @param key - The key to remove\n * @returns True if the key was found and removed, false otherwise\n */\n delete(key: TKey): boolean {\n if (this.map.delete(key)) {\n const index = this.sortedKeys.indexOf(key)\n this.sortedKeys.splice(index, 1)\n return true\n }\n return false\n }\n\n /**\n * Checks if a key exists in the map\n *\n * @param key - The key to check\n * @returns True if the key exists, false otherwise\n */\n has(key: TKey): boolean {\n return this.map.has(key)\n }\n\n /**\n * Removes all key-value pairs from the map\n */\n clear(): void {\n this.map.clear()\n this.sortedKeys = []\n }\n\n /**\n * Gets the number of key-value pairs in the map\n */\n get size(): number {\n return this.map.size\n }\n\n /**\n * Default iterator that returns entries in sorted order\n *\n * @returns An iterator for the map's entries\n */\n *[Symbol.iterator](): IterableIterator<[TKey, TValue]> {\n for (const key of this.sortedKeys) {\n yield [key, this.map.get(key)!] as [TKey, TValue]\n }\n }\n\n /**\n * Returns an iterator for the map's entries in sorted order\n *\n * @returns An iterator for the map's entries\n */\n entries(): IterableIterator<[TKey, TValue]> {\n return this[Symbol.iterator]()\n }\n\n /**\n * Returns an iterator for the map's keys in sorted order\n *\n * @returns An iterator for the map's keys\n */\n keys(): IterableIterator<TKey> {\n return this.sortedKeys[Symbol.iterator]()\n }\n\n /**\n * Returns an iterator for the map's values in sorted order\n *\n * @returns An iterator for the map's values\n */\n values(): IterableIterator<TValue> {\n return function* (this: SortedMap<TKey, TValue>) {\n for (const key of this.sortedKeys) {\n yield this.map.get(key)!\n }\n }.call(this)\n }\n\n /**\n * Executes a callback function for each key-value pair in the map in sorted order\n *\n * @param callbackfn - Function to execute for each entry\n */\n forEach(\n callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void\n ): void {\n for (const key of this.sortedKeys) {\n callbackfn(this.map.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AAAA;AAAA;AAAA;AAAA,EAMzB,QAAc;AACZ,SAAK,IAAI,MAAM;AACf,SAAK,aAAa,CAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMrB,IAAI,OAAe;AACjB,WAAO,KAAK,IAAI;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlB,EAAE,OAAO,QAAQ,IAAsC;AAC1C,eAAA,OAAO,KAAK,YAAY;AACjC,YAAM,CAAC,KAAK,KAAK,IAAI,IAAI,GAAG,CAAE;AAAA,IAAA;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF,UAA4C;AACnC,WAAA,KAAK,OAAO,QAAQ,EAAE;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/B,OAA+B;AAC7B,WAAO,KAAK,WAAW,OAAO,QAAQ,EAAE;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1C,SAAmC;AACjC,YAAO,aAA0C;AACpC,iBAAA,OAAO,KAAK,YAAY;AAC3B,cAAA,KAAK,IAAI,IAAI,GAAG;AAAA,MAAA;AAAA,IACxB,GACA,KAAK,IAAI;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQb,QACE,YACM;AACK,eAAA,OAAO,KAAK,YAAY;AACjC,iBAAW,KAAK,IAAI,IAAI,GAAG,GAAI,KAAK,KAAK,GAAG;AAAA,IAAA;AAAA,EAC9C;AAEJ;;"}
1
+ {"version":3,"file":"SortedMap.cjs","sources":["../../src/SortedMap.ts"],"sourcesContent":["/**\n * A Map implementation that keeps its entries sorted based on a comparator function\n * @template TKey - The type of keys in the map\n * @template TValue - The type of values in the map\n */\nexport class SortedMap<TKey, TValue> {\n private map: Map<TKey, TValue>\n private sortedKeys: Array<TKey>\n private comparator: (a: TValue, b: TValue) => number\n\n /**\n * Creates a new SortedMap instance\n *\n * @param comparator - Optional function to compare values for sorting\n */\n constructor(comparator?: (a: TValue, b: TValue) => number) {\n this.map = new Map<TKey, TValue>()\n this.sortedKeys = []\n this.comparator = comparator || this.defaultComparator\n }\n\n /**\n * Default comparator function used when none is provided\n *\n * @param a - First value to compare\n * @param b - Second value to compare\n * @returns -1 if a < b, 1 if a > b, 0 if equal\n */\n private defaultComparator(a: TValue, b: TValue): number {\n if (a < b) return -1\n if (a > b) return 1\n return 0\n }\n\n /**\n * Finds the index where a key-value pair should be inserted to maintain sort order.\n * Uses binary search to find the correct position based on the value.\n * Hence, it is in O(log n) time.\n *\n * @param key - The key to find position for\n * @param value - The value to compare against\n * @returns The index where the key should be inserted\n */\n private indexOf(value: TValue): number {\n let left = 0\n let right = this.sortedKeys.length\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2)\n const midKey = this.sortedKeys[mid]!\n const midValue = this.map.get(midKey)!\n const comparison = this.comparator(value, midValue)\n\n if (comparison < 0) {\n right = mid\n } else if (comparison > 0) {\n left = mid + 1\n } else {\n return mid\n }\n }\n\n return left\n }\n\n /**\n * Sets a key-value pair in the map and maintains sort order\n *\n * @param key - The key to set\n * @param value - The value to associate with the key\n * @returns This SortedMap instance for chaining\n */\n set(key: TKey, value: TValue): this {\n if (this.map.has(key)) {\n // Need to remove the old key from the sorted keys array\n const oldValue = this.map.get(key)!\n const oldIndex = this.indexOf(oldValue)\n this.sortedKeys.splice(oldIndex, 1)\n }\n\n // Insert the new key at the correct position\n const index = this.indexOf(value)\n this.sortedKeys.splice(index, 0, key)\n\n this.map.set(key, value)\n\n return this\n }\n\n /**\n * Gets a value by its key\n *\n * @param key - The key to look up\n * @returns The value associated with the key, or undefined if not found\n */\n get(key: TKey): TValue | undefined {\n return this.map.get(key)\n }\n\n /**\n * Removes a key-value pair from the map\n *\n * @param key - The key to remove\n * @returns True if the key was found and removed, false otherwise\n */\n delete(key: TKey): boolean {\n if (this.map.has(key)) {\n const oldValue = this.map.get(key)\n const index = this.indexOf(oldValue!)\n this.sortedKeys.splice(index, 1)\n return this.map.delete(key)\n }\n\n return false\n }\n\n /**\n * Checks if a key exists in the map\n *\n * @param key - The key to check\n * @returns True if the key exists, false otherwise\n */\n has(key: TKey): boolean {\n return this.map.has(key)\n }\n\n /**\n * Removes all key-value pairs from the map\n */\n clear(): void {\n this.map.clear()\n this.sortedKeys = []\n }\n\n /**\n * Gets the number of key-value pairs in the map\n */\n get size(): number {\n return this.map.size\n }\n\n /**\n * Default iterator that returns entries in sorted order\n *\n * @returns An iterator for the map's entries\n */\n *[Symbol.iterator](): IterableIterator<[TKey, TValue]> {\n for (const key of this.sortedKeys) {\n yield [key, this.map.get(key)!] as [TKey, TValue]\n }\n }\n\n /**\n * Returns an iterator for the map's entries in sorted order\n *\n * @returns An iterator for the map's entries\n */\n entries(): IterableIterator<[TKey, TValue]> {\n return this[Symbol.iterator]()\n }\n\n /**\n * Returns an iterator for the map's keys in sorted order\n *\n * @returns An iterator for the map's keys\n */\n keys(): IterableIterator<TKey> {\n return this.sortedKeys[Symbol.iterator]()\n }\n\n /**\n * Returns an iterator for the map's values in sorted order\n *\n * @returns An iterator for the map's values\n */\n values(): IterableIterator<TValue> {\n return function* (this: SortedMap<TKey, TValue>) {\n for (const key of this.sortedKeys) {\n yield this.map.get(key)!\n }\n }.call(this)\n }\n\n /**\n * Executes a callback function for each key-value pair in the map in sorted order\n *\n * @param callbackfn - Function to execute for each entry\n */\n forEach(\n callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void\n ): void {\n for (const key of this.sortedKeys) {\n callbackfn(this.map.get(key)!, key, this.map)\n }\n }\n}\n"],"names":[],"mappings":";;AAKO,MAAM,UAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUnC,YAAY,YAA+C;AACpD,SAAA,0BAAU,IAAkB;AACjC,SAAK,aAAa,CAAC;AACd,SAAA,aAAa,cAAc,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU/B,kBAAkB,GAAW,GAAmB;AAClD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> b, 0 if equal
22
22
  */
23
23
  private defaultComparator;
24
+ /**
25
+ * Finds the index where a key-value pair should be inserted to maintain sort order.
26
+ * Uses binary search to find the correct position based on the value.
27
+ * Hence, it is in O(log n) time.
28
+ *
29
+ * @param key - The key to find position for
30
+ * @param value - The value to compare against
31
+ * @returns The index where the key should be inserted
32
+ */
33
+ private indexOf;
24
34
  /**
25
35
  * Sets a key-value pair in the map and maintains sort order
26
36
  *