@tanstack/db 0.0.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.
- package/README.md +37 -0
- package/dist/cjs/SortedMap.cjs +140 -0
- package/dist/cjs/SortedMap.cjs.map +1 -0
- package/dist/cjs/SortedMap.d.cts +91 -0
- package/dist/cjs/collection.cjs +597 -0
- package/dist/cjs/collection.cjs.map +1 -0
- package/dist/cjs/collection.d.cts +176 -0
- package/dist/cjs/deferred.cjs +25 -0
- package/dist/cjs/deferred.cjs.map +1 -0
- package/dist/cjs/deferred.d.cts +20 -0
- package/dist/cjs/errors.cjs +10 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/errors.d.cts +3 -0
- package/dist/cjs/index.cjs +33 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +9 -0
- package/dist/cjs/proxy.cjs +654 -0
- package/dist/cjs/proxy.cjs.map +1 -0
- package/dist/cjs/proxy.d.cts +59 -0
- package/dist/cjs/query/compiled-query.cjs +162 -0
- package/dist/cjs/query/compiled-query.cjs.map +1 -0
- package/dist/cjs/query/compiled-query.d.cts +22 -0
- package/dist/cjs/query/evaluators.cjs +146 -0
- package/dist/cjs/query/evaluators.cjs.map +1 -0
- package/dist/cjs/query/evaluators.d.cts +9 -0
- package/dist/cjs/query/extractors.cjs +122 -0
- package/dist/cjs/query/extractors.cjs.map +1 -0
- package/dist/cjs/query/extractors.d.cts +22 -0
- package/dist/cjs/query/functions.cjs +152 -0
- package/dist/cjs/query/functions.cjs.map +1 -0
- package/dist/cjs/query/functions.d.cts +21 -0
- package/dist/cjs/query/group-by.cjs +91 -0
- package/dist/cjs/query/group-by.cjs.map +1 -0
- package/dist/cjs/query/group-by.d.cts +40 -0
- package/dist/cjs/query/index.d.cts +5 -0
- package/dist/cjs/query/joins.cjs +155 -0
- package/dist/cjs/query/joins.cjs.map +1 -0
- package/dist/cjs/query/joins.d.cts +14 -0
- package/dist/cjs/query/key-by.cjs +43 -0
- package/dist/cjs/query/key-by.cjs.map +1 -0
- package/dist/cjs/query/key-by.d.cts +3 -0
- package/dist/cjs/query/order-by.cjs +229 -0
- package/dist/cjs/query/order-by.cjs.map +1 -0
- package/dist/cjs/query/order-by.d.cts +3 -0
- package/dist/cjs/query/pipeline-compiler.cjs +94 -0
- package/dist/cjs/query/pipeline-compiler.cjs.map +1 -0
- package/dist/cjs/query/pipeline-compiler.d.cts +9 -0
- package/dist/cjs/query/query-builder.cjs +314 -0
- package/dist/cjs/query/query-builder.cjs.map +1 -0
- package/dist/cjs/query/query-builder.d.cts +219 -0
- package/dist/cjs/query/schema.d.cts +98 -0
- package/dist/cjs/query/select.cjs +107 -0
- package/dist/cjs/query/select.cjs.map +1 -0
- package/dist/cjs/query/select.d.cts +3 -0
- package/dist/cjs/query/types.d.cts +188 -0
- package/dist/cjs/query/utils.cjs +154 -0
- package/dist/cjs/query/utils.cjs.map +1 -0
- package/dist/cjs/query/utils.d.cts +37 -0
- package/dist/cjs/transactions.cjs +137 -0
- package/dist/cjs/transactions.cjs.map +1 -0
- package/dist/cjs/transactions.d.cts +27 -0
- package/dist/cjs/types.d.cts +94 -0
- package/dist/cjs/utils.cjs +17 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +3 -0
- package/dist/esm/SortedMap.d.ts +91 -0
- package/dist/esm/SortedMap.js +140 -0
- package/dist/esm/SortedMap.js.map +1 -0
- package/dist/esm/collection.d.ts +176 -0
- package/dist/esm/collection.js +597 -0
- package/dist/esm/collection.js.map +1 -0
- package/dist/esm/deferred.d.ts +20 -0
- package/dist/esm/deferred.js +25 -0
- package/dist/esm/deferred.js.map +1 -0
- package/dist/esm/errors.d.ts +3 -0
- package/dist/esm/errors.js +10 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/proxy.d.ts +59 -0
- package/dist/esm/proxy.js +654 -0
- package/dist/esm/proxy.js.map +1 -0
- package/dist/esm/query/compiled-query.d.ts +22 -0
- package/dist/esm/query/compiled-query.js +162 -0
- package/dist/esm/query/compiled-query.js.map +1 -0
- package/dist/esm/query/evaluators.d.ts +9 -0
- package/dist/esm/query/evaluators.js +146 -0
- package/dist/esm/query/evaluators.js.map +1 -0
- package/dist/esm/query/extractors.d.ts +22 -0
- package/dist/esm/query/extractors.js +122 -0
- package/dist/esm/query/extractors.js.map +1 -0
- package/dist/esm/query/functions.d.ts +21 -0
- package/dist/esm/query/functions.js +152 -0
- package/dist/esm/query/functions.js.map +1 -0
- package/dist/esm/query/group-by.d.ts +40 -0
- package/dist/esm/query/group-by.js +91 -0
- package/dist/esm/query/group-by.js.map +1 -0
- package/dist/esm/query/index.d.ts +5 -0
- package/dist/esm/query/joins.d.ts +14 -0
- package/dist/esm/query/joins.js +155 -0
- package/dist/esm/query/joins.js.map +1 -0
- package/dist/esm/query/key-by.d.ts +3 -0
- package/dist/esm/query/key-by.js +43 -0
- package/dist/esm/query/key-by.js.map +1 -0
- package/dist/esm/query/order-by.d.ts +3 -0
- package/dist/esm/query/order-by.js +229 -0
- package/dist/esm/query/order-by.js.map +1 -0
- package/dist/esm/query/pipeline-compiler.d.ts +9 -0
- package/dist/esm/query/pipeline-compiler.js +94 -0
- package/dist/esm/query/pipeline-compiler.js.map +1 -0
- package/dist/esm/query/query-builder.d.ts +219 -0
- package/dist/esm/query/query-builder.js +314 -0
- package/dist/esm/query/query-builder.js.map +1 -0
- package/dist/esm/query/schema.d.ts +98 -0
- package/dist/esm/query/select.d.ts +3 -0
- package/dist/esm/query/select.js +107 -0
- package/dist/esm/query/select.js.map +1 -0
- package/dist/esm/query/types.d.ts +188 -0
- package/dist/esm/query/utils.d.ts +37 -0
- package/dist/esm/query/utils.js +154 -0
- package/dist/esm/query/utils.js.map +1 -0
- package/dist/esm/transactions.d.ts +27 -0
- package/dist/esm/transactions.js +137 -0
- package/dist/esm/transactions.js.map +1 -0
- package/dist/esm/types.d.ts +94 -0
- package/dist/esm/utils.d.ts +3 -0
- package/dist/esm/utils.js +17 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +57 -0
- package/src/SortedMap.ts +163 -0
- package/src/collection.ts +919 -0
- package/src/deferred.ts +47 -0
- package/src/errors.ts +6 -0
- package/src/index.ts +12 -0
- package/src/proxy.ts +1104 -0
- package/src/query/compiled-query.ts +193 -0
- package/src/query/evaluators.ts +222 -0
- package/src/query/extractors.ts +211 -0
- package/src/query/functions.ts +297 -0
- package/src/query/group-by.ts +137 -0
- package/src/query/index.ts +5 -0
- package/src/query/joins.ts +247 -0
- package/src/query/key-by.ts +61 -0
- package/src/query/order-by.ts +312 -0
- package/src/query/pipeline-compiler.ts +152 -0
- package/src/query/query-builder.ts +898 -0
- package/src/query/schema.ts +255 -0
- package/src/query/select.ts +173 -0
- package/src/query/types.ts +417 -0
- package/src/query/utils.ts +245 -0
- package/src/transactions.ts +198 -0
- package/src/types.ts +125 -0
- package/src/utils.ts +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @tanstack/db
|
|
2
|
+
|
|
3
|
+
**A reactive client store for building super fast apps on sync**
|
|
4
|
+
|
|
5
|
+
TanStack DB extends TanStack Query with collections, live queries and transactional mutations that keep your UI reactive, consistent and blazing fast 🔥
|
|
6
|
+
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://x.com/intent/post?text=TanStack%20DB&url=https://tanstack.com/db">
|
|
9
|
+
<img alt="#TanStack" src="https://img.shields.io/twitter/url?color=%2308a0e9&label=%23TanStack&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Fbutton_hashtag%3DTanStack" /></a>
|
|
10
|
+
<a href="#status">
|
|
11
|
+
<img src="https://img.shields.io/badge/status-alpha-orange" alt="Status - Alpha"></a>
|
|
12
|
+
<a href="https://npmjs.com/package/@tanstack/db">
|
|
13
|
+
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/db.svg" /></a>
|
|
14
|
+
<a href="https://discord.gg/yjUNbvbraC">
|
|
15
|
+
<img alt="" src="https://img.shields.io/badge/Discord-TanStack-%235865F2" /></a>
|
|
16
|
+
<a href="https://github.com/tanstack/db/discussions">
|
|
17
|
+
<img alt="Join the discussion on Github" src="https://img.shields.io/badge/Discussions-Chat%20now!-green" /></a>
|
|
18
|
+
<a href="https://x.com/tan_stack">
|
|
19
|
+
<img alt="" src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social&label=Follow @TanStack" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
## 💥 Visit the [TanStack/db](https://github.com/TanStack/db) repo for docs and details!
|
|
23
|
+
|
|
24
|
+
- 🔥 **blazing fast query engine**<br />
|
|
25
|
+
for sub-millisecond live queries — even for complex queries with joins and aggregates
|
|
26
|
+
- 🎯 **fine-grained reactivity**<br />
|
|
27
|
+
to minimize component re-rendering
|
|
28
|
+
- 💪 **robust transaction primitives**<br />
|
|
29
|
+
for easy optimistic mutations with sync and lifecycle support
|
|
30
|
+
- 🌟 **normalized data**<br />
|
|
31
|
+
to keep your backend simple
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
|
|
36
|
+
|
|
37
|
+
Enjoy this library? Try the entire [TanStack](https://tanstack.com), including [TanStack Query](https://tanstack.com/query), [TanStack Store](https://tanstack.com/store), etc.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
class SortedMap {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new SortedMap instance
|
|
6
|
+
*
|
|
7
|
+
* @param comparator - Optional function to compare values for sorting
|
|
8
|
+
*/
|
|
9
|
+
constructor(comparator) {
|
|
10
|
+
this.map = /* @__PURE__ */ new Map();
|
|
11
|
+
this.sortedKeys = [];
|
|
12
|
+
this.comparator = comparator || this.defaultComparator;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Default comparator function used when none is provided
|
|
16
|
+
*
|
|
17
|
+
* @param a - First value to compare
|
|
18
|
+
* @param b - Second value to compare
|
|
19
|
+
* @returns -1 if a < b, 1 if a > b, 0 if equal
|
|
20
|
+
*/
|
|
21
|
+
defaultComparator(a, b) {
|
|
22
|
+
if (a < b) return -1;
|
|
23
|
+
if (a > b) return 1;
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets a key-value pair in the map and maintains sort order
|
|
28
|
+
*
|
|
29
|
+
* @param key - The key to set
|
|
30
|
+
* @param value - The value to associate with the key
|
|
31
|
+
* @returns This SortedMap instance for chaining
|
|
32
|
+
*/
|
|
33
|
+
set(key, value) {
|
|
34
|
+
this.map.set(key, value);
|
|
35
|
+
if (!this.sortedKeys.includes(key)) {
|
|
36
|
+
this.sortedKeys.push(key);
|
|
37
|
+
}
|
|
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
|
+
});
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets a value by its key
|
|
47
|
+
*
|
|
48
|
+
* @param key - The key to look up
|
|
49
|
+
* @returns The value associated with the key, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
get(key) {
|
|
52
|
+
return this.map.get(key);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Removes a key-value pair from the map
|
|
56
|
+
*
|
|
57
|
+
* @param key - The key to remove
|
|
58
|
+
* @returns True if the key was found and removed, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
delete(key) {
|
|
61
|
+
if (this.map.delete(key)) {
|
|
62
|
+
const index = this.sortedKeys.indexOf(key);
|
|
63
|
+
this.sortedKeys.splice(index, 1);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a key exists in the map
|
|
70
|
+
*
|
|
71
|
+
* @param key - The key to check
|
|
72
|
+
* @returns True if the key exists, false otherwise
|
|
73
|
+
*/
|
|
74
|
+
has(key) {
|
|
75
|
+
return this.map.has(key);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Removes all key-value pairs from the map
|
|
79
|
+
*/
|
|
80
|
+
clear() {
|
|
81
|
+
this.map.clear();
|
|
82
|
+
this.sortedKeys = [];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Gets the number of key-value pairs in the map
|
|
86
|
+
*/
|
|
87
|
+
get size() {
|
|
88
|
+
return this.map.size;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Default iterator that returns entries in sorted order
|
|
92
|
+
*
|
|
93
|
+
* @returns An iterator for the map's entries
|
|
94
|
+
*/
|
|
95
|
+
*[Symbol.iterator]() {
|
|
96
|
+
for (const key of this.sortedKeys) {
|
|
97
|
+
yield [key, this.map.get(key)];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns an iterator for the map's entries in sorted order
|
|
102
|
+
*
|
|
103
|
+
* @returns An iterator for the map's entries
|
|
104
|
+
*/
|
|
105
|
+
entries() {
|
|
106
|
+
return this[Symbol.iterator]();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns an iterator for the map's keys in sorted order
|
|
110
|
+
*
|
|
111
|
+
* @returns An iterator for the map's keys
|
|
112
|
+
*/
|
|
113
|
+
keys() {
|
|
114
|
+
return this.sortedKeys[Symbol.iterator]();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns an iterator for the map's values in sorted order
|
|
118
|
+
*
|
|
119
|
+
* @returns An iterator for the map's values
|
|
120
|
+
*/
|
|
121
|
+
values() {
|
|
122
|
+
return (function* () {
|
|
123
|
+
for (const key of this.sortedKeys) {
|
|
124
|
+
yield this.map.get(key);
|
|
125
|
+
}
|
|
126
|
+
}).call(this);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Executes a callback function for each key-value pair in the map in sorted order
|
|
130
|
+
*
|
|
131
|
+
* @param callbackfn - Function to execute for each entry
|
|
132
|
+
*/
|
|
133
|
+
forEach(callbackfn) {
|
|
134
|
+
for (const key of this.sortedKeys) {
|
|
135
|
+
callbackfn(this.map.get(key), key, this.map);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.SortedMap = SortedMap;
|
|
140
|
+
//# sourceMappingURL=SortedMap.cjs.map
|
|
@@ -0,0 +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.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,QAAA,IAAI,EAAU,QAAA;AACd,QAAA,IAAI,EAAU,QAAA;AACX,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUT,IAAI,KAAW,OAAqB;AAC7B,SAAA,IAAI,IAAI,KAAK,KAAK;AAEvB,QAAI,CAAC,KAAK,WAAW,SAAS,GAAG,GAAG;AAC7B,WAAA,WAAW,KAAK,GAAG;AAAA,IAAA;AAI1B,SAAK,WAAW,KAAK,CAAC,GAAG,MAAM;AAC7B,YAAM,SAAS,KAAK,IAAI,IAAI,CAAC;AAC7B,YAAM,SAAS,KAAK,IAAI,IAAI,CAAC;AACtB,aAAA,KAAK,WAAW,QAAQ,MAAM;AAAA,IAAA,CACtC;AAEM,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAST,IAAI,KAA+B;AAC1B,WAAA,KAAK,IAAI,IAAI,GAAG;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzB,OAAO,KAAoB;AACzB,QAAI,KAAK,IAAI,OAAO,GAAG,GAAG;AACxB,YAAM,QAAQ,KAAK,WAAW,QAAQ,GAAG;AACpC,WAAA,WAAW,OAAO,OAAO,CAAC;AACxB,aAAA;AAAA,IAAA;AAEF,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAST,IAAI,KAAoB;AACf,WAAA,KAAK,IAAI,IAAI,GAAG;AAAA,EAAA;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;;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Map implementation that keeps its entries sorted based on a comparator function
|
|
3
|
+
* @template TKey - The type of keys in the map
|
|
4
|
+
* @template TValue - The type of values in the map
|
|
5
|
+
*/
|
|
6
|
+
export declare class SortedMap<TKey, TValue> {
|
|
7
|
+
private map;
|
|
8
|
+
private sortedKeys;
|
|
9
|
+
private comparator;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new SortedMap instance
|
|
12
|
+
*
|
|
13
|
+
* @param comparator - Optional function to compare values for sorting
|
|
14
|
+
*/
|
|
15
|
+
constructor(comparator?: (a: TValue, b: TValue) => number);
|
|
16
|
+
/**
|
|
17
|
+
* Default comparator function used when none is provided
|
|
18
|
+
*
|
|
19
|
+
* @param a - First value to compare
|
|
20
|
+
* @param b - Second value to compare
|
|
21
|
+
* @returns -1 if a < b, 1 if a > b, 0 if equal
|
|
22
|
+
*/
|
|
23
|
+
private defaultComparator;
|
|
24
|
+
/**
|
|
25
|
+
* Sets a key-value pair in the map and maintains sort order
|
|
26
|
+
*
|
|
27
|
+
* @param key - The key to set
|
|
28
|
+
* @param value - The value to associate with the key
|
|
29
|
+
* @returns This SortedMap instance for chaining
|
|
30
|
+
*/
|
|
31
|
+
set(key: TKey, value: TValue): this;
|
|
32
|
+
/**
|
|
33
|
+
* Gets a value by its key
|
|
34
|
+
*
|
|
35
|
+
* @param key - The key to look up
|
|
36
|
+
* @returns The value associated with the key, or undefined if not found
|
|
37
|
+
*/
|
|
38
|
+
get(key: TKey): TValue | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Removes a key-value pair from the map
|
|
41
|
+
*
|
|
42
|
+
* @param key - The key to remove
|
|
43
|
+
* @returns True if the key was found and removed, false otherwise
|
|
44
|
+
*/
|
|
45
|
+
delete(key: TKey): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a key exists in the map
|
|
48
|
+
*
|
|
49
|
+
* @param key - The key to check
|
|
50
|
+
* @returns True if the key exists, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
has(key: TKey): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Removes all key-value pairs from the map
|
|
55
|
+
*/
|
|
56
|
+
clear(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the number of key-value pairs in the map
|
|
59
|
+
*/
|
|
60
|
+
get size(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Default iterator that returns entries in sorted order
|
|
63
|
+
*
|
|
64
|
+
* @returns An iterator for the map's entries
|
|
65
|
+
*/
|
|
66
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
67
|
+
/**
|
|
68
|
+
* Returns an iterator for the map's entries in sorted order
|
|
69
|
+
*
|
|
70
|
+
* @returns An iterator for the map's entries
|
|
71
|
+
*/
|
|
72
|
+
entries(): IterableIterator<[TKey, TValue]>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns an iterator for the map's keys in sorted order
|
|
75
|
+
*
|
|
76
|
+
* @returns An iterator for the map's keys
|
|
77
|
+
*/
|
|
78
|
+
keys(): IterableIterator<TKey>;
|
|
79
|
+
/**
|
|
80
|
+
* Returns an iterator for the map's values in sorted order
|
|
81
|
+
*
|
|
82
|
+
* @returns An iterator for the map's values
|
|
83
|
+
*/
|
|
84
|
+
values(): IterableIterator<TValue>;
|
|
85
|
+
/**
|
|
86
|
+
* Executes a callback function for each key-value pair in the map in sorted order
|
|
87
|
+
*
|
|
88
|
+
* @param callbackfn - Function to execute for each entry
|
|
89
|
+
*/
|
|
90
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void): void;
|
|
91
|
+
}
|