@mtkruto/browser 0.142.0 → 0.144.0
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/esm/0_deps.d.ts +4 -4
- package/esm/0_deps.d.ts.map +1 -1
- package/esm/0_deps.js +4 -4
- package/esm/3_types.d.ts +2 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +2 -0
- package/esm/client/0_params.d.ts +21 -3
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities.d.ts.map +1 -1
- package/esm/client/1_client_generic.d.ts +60 -4
- package/esm/client/1_client_generic.d.ts.map +1 -1
- package/esm/client/2_managed_bot_manager.d.ts +4 -1
- package/esm/client/2_managed_bot_manager.d.ts.map +1 -1
- package/esm/client/2_managed_bot_manager.js +13 -0
- package/esm/client/3_account_manager.d.ts +2 -1
- package/esm/client/3_account_manager.d.ts.map +1 -1
- package/esm/client/3_account_manager.js +17 -2
- package/esm/client/3_filters.d.ts +6 -1
- package/esm/client/3_filters.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +10 -6
- package/esm/client/3_message_manager.d.ts.map +1 -1
- package/esm/client/3_message_manager.js +67 -13
- package/esm/client/3_sticker_set_manager.d.ts +1 -2
- package/esm/client/3_sticker_set_manager.d.ts.map +1 -1
- package/esm/client/4_context.d.ts +8 -1
- package/esm/client/4_context.d.ts.map +1 -1
- package/esm/client/4_context.js +21 -1
- package/esm/client/4_story_manager.d.ts +1 -2
- package/esm/client/4_story_manager.d.ts.map +1 -1
- package/esm/client/6_client.d.ts +60 -5
- package/esm/client/6_client.d.ts.map +1 -1
- package/esm/client/6_client.js +75 -2
- package/esm/client/6_client_dispatcher.d.ts +60 -5
- package/esm/client/6_client_dispatcher.d.ts.map +1 -1
- package/esm/client/6_client_dispatcher.js +75 -2
- package/esm/connection/1_connection_web_socket.d.ts +1 -1
- package/esm/connection/1_connection_web_socket.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/async/1.2.0 → esm/deps/jsr.io/@std/async/1.3.0}/delay.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/async/1.2.0 → esm/deps/jsr.io/@std/async/1.3.0}/pool.d.ts +2 -0
- package/esm/deps/jsr.io/@std/async/1.3.0/pool.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/pool.js +5 -1
- package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.js +27 -16
- package/{script/deps/jsr.io/@std/cache/0.2.2 → esm/deps/jsr.io/@std/cache/0.2.3}/lru_cache.d.ts +109 -25
- package/esm/deps/jsr.io/@std/cache/0.2.3/lru_cache.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/cache/0.2.3/lru_cache.js +299 -0
- package/{script/deps/jsr.io/@std/cache/0.2.2 → esm/deps/jsr.io/@std/cache/0.2.3}/memoize.d.ts +18 -10
- package/esm/deps/jsr.io/@std/cache/0.2.3/memoize.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/memoize.js +11 -7
- package/esm/deps/jsr.io/@std/streams/1.1.0/to_array_buffer.d.ts.map +1 -0
- package/esm/tl/1_telegram_api.d.ts +251 -5
- package/esm/tl/1_telegram_api.d.ts.map +1 -1
- package/esm/tl/1_telegram_api.js +271 -11
- package/esm/types/1_chat_p.d.ts +2 -0
- package/esm/types/1_chat_p.d.ts.map +1 -1
- package/esm/types/1_chat_p.js +1 -0
- package/esm/types/1_video.d.ts.map +1 -1
- package/esm/types/1_video.js +3 -2
- package/esm/types/2_user.d.ts +2 -0
- package/esm/types/2_user.d.ts.map +1 -1
- package/esm/types/2_user.js +1 -0
- package/esm/types/3_bot_access_settings.d.ts +27 -0
- package/esm/types/3_bot_access_settings.d.ts.map +1 -0
- package/esm/types/3_bot_access_settings.js +27 -0
- package/esm/types/4_poll.d.ts +2 -0
- package/esm/types/4_poll.d.ts.map +1 -1
- package/esm/types/4_poll.js +1 -0
- package/esm/types/6_message.d.ts +12 -1
- package/esm/types/6_message.d.ts.map +1 -1
- package/esm/types/6_message.js +20 -2
- package/esm/types/7_guest_query.d.ts +28 -0
- package/esm/types/7_guest_query.d.ts.map +1 -0
- package/esm/types/7_guest_query.js +20 -0
- package/esm/types/8_update.d.ts +19 -1
- package/esm/types/8_update.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/0_deps.d.ts +4 -4
- package/script/0_deps.d.ts.map +1 -1
- package/script/0_deps.js +4 -4
- package/script/3_types.d.ts +2 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +2 -0
- package/script/client/0_params.d.ts +21 -3
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities.d.ts.map +1 -1
- package/script/client/1_client_generic.d.ts +60 -4
- package/script/client/1_client_generic.d.ts.map +1 -1
- package/script/client/2_managed_bot_manager.d.ts +4 -1
- package/script/client/2_managed_bot_manager.d.ts.map +1 -1
- package/script/client/2_managed_bot_manager.js +13 -0
- package/script/client/3_account_manager.d.ts +2 -1
- package/script/client/3_account_manager.d.ts.map +1 -1
- package/script/client/3_account_manager.js +17 -2
- package/script/client/3_filters.d.ts +6 -1
- package/script/client/3_filters.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +10 -6
- package/script/client/3_message_manager.d.ts.map +1 -1
- package/script/client/3_message_manager.js +65 -11
- package/script/client/3_sticker_set_manager.d.ts +1 -2
- package/script/client/3_sticker_set_manager.d.ts.map +1 -1
- package/script/client/4_context.d.ts +8 -1
- package/script/client/4_context.d.ts.map +1 -1
- package/script/client/4_context.js +21 -1
- package/script/client/4_story_manager.d.ts +1 -2
- package/script/client/4_story_manager.d.ts.map +1 -1
- package/script/client/6_client.d.ts +60 -5
- package/script/client/6_client.d.ts.map +1 -1
- package/script/client/6_client.js +75 -2
- package/script/client/6_client_dispatcher.d.ts +60 -5
- package/script/client/6_client_dispatcher.d.ts.map +1 -1
- package/script/client/6_client_dispatcher.js +75 -2
- package/script/connection/1_connection_web_socket.d.ts +1 -1
- package/script/connection/1_connection_web_socket.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/async/1.2.0 → script/deps/jsr.io/@std/async/1.3.0}/delay.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/async/1.2.0 → script/deps/jsr.io/@std/async/1.3.0}/pool.d.ts +2 -0
- package/script/deps/jsr.io/@std/async/1.3.0/pool.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/pool.js +5 -1
- package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.js +27 -16
- package/{esm/deps/jsr.io/@std/cache/0.2.2 → script/deps/jsr.io/@std/cache/0.2.3}/lru_cache.d.ts +109 -25
- package/script/deps/jsr.io/@std/cache/0.2.3/lru_cache.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/lru_cache.js +149 -38
- package/{esm/deps/jsr.io/@std/cache/0.2.2 → script/deps/jsr.io/@std/cache/0.2.3}/memoize.d.ts +18 -10
- package/script/deps/jsr.io/@std/cache/0.2.3/memoize.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/memoize.js +11 -7
- package/script/deps/jsr.io/@std/streams/1.1.0/to_array_buffer.d.ts.map +1 -0
- package/script/tl/1_telegram_api.d.ts +251 -5
- package/script/tl/1_telegram_api.d.ts.map +1 -1
- package/script/tl/1_telegram_api.js +271 -11
- package/script/types/1_chat_p.d.ts +2 -0
- package/script/types/1_chat_p.d.ts.map +1 -1
- package/script/types/1_chat_p.js +1 -0
- package/script/types/1_video.d.ts.map +1 -1
- package/script/types/1_video.js +3 -2
- package/script/types/2_user.d.ts +2 -0
- package/script/types/2_user.d.ts.map +1 -1
- package/script/types/2_user.js +1 -0
- package/script/types/3_bot_access_settings.d.ts +27 -0
- package/script/types/3_bot_access_settings.d.ts.map +1 -0
- package/script/types/3_bot_access_settings.js +30 -0
- package/script/types/4_poll.d.ts +2 -0
- package/script/types/4_poll.d.ts.map +1 -1
- package/script/types/4_poll.js +1 -0
- package/script/types/6_message.d.ts +12 -1
- package/script/types/6_message.d.ts.map +1 -1
- package/script/types/6_message.js +20 -2
- package/script/types/7_guest_query.d.ts +28 -0
- package/script/types/7_guest_query.d.ts.map +1 -0
- package/script/types/7_guest_query.js +21 -0
- package/script/types/8_update.d.ts +19 -1
- package/script/types/8_update.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/pool.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +0 -188
- package/esm/deps/jsr.io/@std/cache/0.2.2/memoize.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/streams/1.0.17/to_array_buffer.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/pool.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/cache/0.2.2/memoize.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/streams/1.0.17/to_array_buffer.d.ts.map +0 -1
- /package/esm/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.js +0 -0
- /package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.js +0 -0
- /package/script/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.d.ts +0 -0
- /package/script/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.js +0 -0
- /package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts +0 -0
- /package/script/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.d.ts +0 -0
- /package/script/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.js +0 -0
|
@@ -11,7 +11,7 @@ exports.LruCache = void 0;
|
|
|
11
11
|
* @see {@link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU | Least-recently-used cache}
|
|
12
12
|
*
|
|
13
13
|
* Automatically removes entries above the max size based on when they were
|
|
14
|
-
* last accessed with `get
|
|
14
|
+
* last accessed with `get` or `set`.
|
|
15
15
|
*
|
|
16
16
|
* @typeParam K The type of the cache keys.
|
|
17
17
|
* @typeParam V The type of the cache values.
|
|
@@ -38,31 +38,51 @@ exports.LruCache = void 0;
|
|
|
38
38
|
* assert(!cache.has("a"));
|
|
39
39
|
* ```
|
|
40
40
|
*
|
|
41
|
-
* @example Adding
|
|
41
|
+
* @example Adding an onEject callback
|
|
42
42
|
* ```ts
|
|
43
43
|
* import { LruCache } from "@std/cache";
|
|
44
44
|
* import { assertEquals } from "@std/assert";
|
|
45
45
|
*
|
|
46
|
-
* const
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* }
|
|
46
|
+
* const ejected: [string, number, string][] = [];
|
|
47
|
+
* const cache = new LruCache<string, number>(2, {
|
|
48
|
+
* onEject: (key, value, reason) => ejected.push([key, value, reason]),
|
|
49
|
+
* });
|
|
50
50
|
*
|
|
51
|
-
* cache.set(
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* );
|
|
51
|
+
* cache.set("a", 1);
|
|
52
|
+
* cache.set("b", 2);
|
|
53
|
+
* cache.set("c", 3);
|
|
55
54
|
*
|
|
56
|
-
*
|
|
57
|
-
* assertEquals(cache.get("fast-url"), undefined)
|
|
55
|
+
* assertEquals(ejected, [["a", 1, "evicted"]]);
|
|
58
56
|
* ```
|
|
59
57
|
*/
|
|
60
58
|
class LruCache extends Map {
|
|
59
|
+
#maxSize;
|
|
60
|
+
#ejecting = false;
|
|
61
|
+
#eject;
|
|
62
|
+
/**
|
|
63
|
+
* Constructs a new `LruCache`.
|
|
64
|
+
*
|
|
65
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
66
|
+
*
|
|
67
|
+
* @param maxSize The maximum number of entries to store in the cache. Must
|
|
68
|
+
* be a positive integer.
|
|
69
|
+
* @param options Additional options.
|
|
70
|
+
*/
|
|
71
|
+
constructor(maxSize, options) {
|
|
72
|
+
super();
|
|
73
|
+
if (!Number.isInteger(maxSize) || maxSize < 1) {
|
|
74
|
+
throw new RangeError(`Cannot create LruCache: maxSize must be a positive integer: received ${maxSize}`);
|
|
75
|
+
}
|
|
76
|
+
this.#maxSize = maxSize;
|
|
77
|
+
this.#eject = options?.onEject;
|
|
78
|
+
}
|
|
61
79
|
/**
|
|
62
80
|
* The maximum number of entries to store in the cache.
|
|
63
81
|
*
|
|
82
|
+
* @returns The maximum number of entries in the cache.
|
|
83
|
+
*
|
|
64
84
|
* @example Max size
|
|
65
|
-
* ```ts
|
|
85
|
+
* ```ts
|
|
66
86
|
* import { LruCache } from "@std/cache";
|
|
67
87
|
* import { assertEquals } from "@std/assert";
|
|
68
88
|
*
|
|
@@ -70,31 +90,32 @@ class LruCache extends Map {
|
|
|
70
90
|
* assertEquals(cache.maxSize, 100);
|
|
71
91
|
* ```
|
|
72
92
|
*/
|
|
73
|
-
maxSize
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Constructs a new `LruCache`.
|
|
77
|
-
*
|
|
78
|
-
* @param maxSize The maximum number of entries to store in the cache.
|
|
79
|
-
* @param options Additional options.
|
|
80
|
-
*/
|
|
81
|
-
constructor(maxSize, options) {
|
|
82
|
-
super();
|
|
83
|
-
this.maxSize = maxSize;
|
|
84
|
-
this.#eject = options?.onEject ?? (() => { });
|
|
93
|
+
get maxSize() {
|
|
94
|
+
return this.#maxSize;
|
|
85
95
|
}
|
|
86
96
|
#setMostRecentlyUsed(key, value) {
|
|
87
|
-
// delete then re-add to ensure most recently accessed elements are last
|
|
88
97
|
super.delete(key);
|
|
89
98
|
super.set(key, value);
|
|
90
99
|
}
|
|
91
100
|
#pruneToMaxSize() {
|
|
92
|
-
if (this.size
|
|
93
|
-
|
|
101
|
+
if (this.size <= this.#maxSize)
|
|
102
|
+
return;
|
|
103
|
+
const key = this.keys().next().value;
|
|
104
|
+
const value = super.get(key);
|
|
105
|
+
super.delete(key);
|
|
106
|
+
if (this.#eject) {
|
|
107
|
+
this.#ejecting = true;
|
|
108
|
+
try {
|
|
109
|
+
this.#eject(key, value, "evicted");
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
this.#ejecting = false;
|
|
113
|
+
}
|
|
94
114
|
}
|
|
95
115
|
}
|
|
96
116
|
/**
|
|
97
|
-
* Checks whether an element with the specified key exists or not.
|
|
117
|
+
* Checks whether an element with the specified key exists or not. Does
|
|
118
|
+
* **not** update the entry's position in the eviction order.
|
|
98
119
|
*
|
|
99
120
|
* @param key The key to check.
|
|
100
121
|
* @returns `true` if the cache contains the specified key, otherwise `false`.
|
|
@@ -111,17 +132,14 @@ class LruCache extends Map {
|
|
|
111
132
|
* ```
|
|
112
133
|
*/
|
|
113
134
|
has(key) {
|
|
114
|
-
|
|
115
|
-
if (exists) {
|
|
116
|
-
this.#setMostRecentlyUsed(key, super.get(key));
|
|
117
|
-
}
|
|
118
|
-
return exists;
|
|
135
|
+
return super.has(key);
|
|
119
136
|
}
|
|
120
137
|
/**
|
|
121
138
|
* Gets the element with the specified key.
|
|
122
139
|
*
|
|
123
140
|
* @param key The key to get the value for.
|
|
124
|
-
* @returns The value associated with the specified key, or `undefined` if
|
|
141
|
+
* @returns The value associated with the specified key, or `undefined` if
|
|
142
|
+
* the key is not present in the cache.
|
|
125
143
|
*
|
|
126
144
|
* @example Getting a value from the cache
|
|
127
145
|
* ```ts
|
|
@@ -142,6 +160,37 @@ class LruCache extends Map {
|
|
|
142
160
|
}
|
|
143
161
|
return undefined;
|
|
144
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the value associated with the given key, or `undefined` if the
|
|
165
|
+
* key is not present, **without** updating its position in the eviction
|
|
166
|
+
* order.
|
|
167
|
+
*
|
|
168
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
169
|
+
*
|
|
170
|
+
* @param key The key to look up.
|
|
171
|
+
* @returns The value, or `undefined` if not present.
|
|
172
|
+
*
|
|
173
|
+
* @example Peeking at a value without promoting it
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { LruCache } from "@std/cache";
|
|
176
|
+
* import { assertEquals } from "@std/assert";
|
|
177
|
+
*
|
|
178
|
+
* const cache = new LruCache<string, number>(3);
|
|
179
|
+
* cache.set("a", 1);
|
|
180
|
+
* cache.set("b", 2);
|
|
181
|
+
* cache.set("c", 3);
|
|
182
|
+
*
|
|
183
|
+
* // peek does not promote "a"
|
|
184
|
+
* assertEquals(cache.peek("a"), 1);
|
|
185
|
+
*
|
|
186
|
+
* // "a" is still the least recently used and gets evicted
|
|
187
|
+
* cache.set("d", 4);
|
|
188
|
+
* assertEquals(cache.peek("a"), undefined);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
peek(key) {
|
|
192
|
+
return super.get(key);
|
|
193
|
+
}
|
|
145
194
|
/**
|
|
146
195
|
* Sets the specified key to the specified value.
|
|
147
196
|
*
|
|
@@ -158,6 +207,9 @@ class LruCache extends Map {
|
|
|
158
207
|
* ```
|
|
159
208
|
*/
|
|
160
209
|
set(key, value) {
|
|
210
|
+
if (this.#ejecting) {
|
|
211
|
+
throw new TypeError("Cannot set entry in LruCache: cache is not re-entrant during onEject callbacks");
|
|
212
|
+
}
|
|
161
213
|
this.#setMostRecentlyUsed(key, value);
|
|
162
214
|
this.#pruneToMaxSize();
|
|
163
215
|
return this;
|
|
@@ -183,10 +235,69 @@ class LruCache extends Map {
|
|
|
183
235
|
* ```
|
|
184
236
|
*/
|
|
185
237
|
delete(key) {
|
|
186
|
-
if (
|
|
187
|
-
|
|
238
|
+
if (this.#ejecting) {
|
|
239
|
+
throw new TypeError("Cannot delete entry in LruCache: cache is not re-entrant during onEject callbacks");
|
|
240
|
+
}
|
|
241
|
+
const value = super.get(key);
|
|
242
|
+
const existed = super.delete(key);
|
|
243
|
+
if (!existed)
|
|
244
|
+
return false;
|
|
245
|
+
if (this.#eject) {
|
|
246
|
+
this.#ejecting = true;
|
|
247
|
+
try {
|
|
248
|
+
this.#eject(key, value, "deleted");
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
this.#ejecting = false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Clears the cache.
|
|
258
|
+
*
|
|
259
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
260
|
+
*
|
|
261
|
+
* @example Usage
|
|
262
|
+
* ```ts
|
|
263
|
+
* import { LruCache } from "@std/cache";
|
|
264
|
+
* import { assertEquals } from "@std/assert/equals";
|
|
265
|
+
*
|
|
266
|
+
* const cache = new LruCache<string, number>(100);
|
|
267
|
+
*
|
|
268
|
+
* cache.set("a", 1);
|
|
269
|
+
* cache.set("b", 2);
|
|
270
|
+
* cache.clear();
|
|
271
|
+
* assertEquals(cache.size, 0);
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
clear() {
|
|
275
|
+
if (this.#ejecting) {
|
|
276
|
+
throw new TypeError("Cannot clear LruCache: cache is not re-entrant during onEject callbacks");
|
|
277
|
+
}
|
|
278
|
+
if (!this.#eject) {
|
|
279
|
+
super.clear();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const entries = [...super.entries()];
|
|
283
|
+
super.clear();
|
|
284
|
+
this.#ejecting = true;
|
|
285
|
+
let error;
|
|
286
|
+
try {
|
|
287
|
+
for (const [key, value] of entries) {
|
|
288
|
+
try {
|
|
289
|
+
this.#eject(key, value, "cleared");
|
|
290
|
+
}
|
|
291
|
+
catch (e) {
|
|
292
|
+
error ??= e;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
this.#ejecting = false;
|
|
188
298
|
}
|
|
189
|
-
|
|
299
|
+
if (error !== undefined)
|
|
300
|
+
throw error;
|
|
190
301
|
}
|
|
191
302
|
}
|
|
192
303
|
exports.LruCache = LruCache;
|
package/{esm/deps/jsr.io/@std/cache/0.2.2 → script/deps/jsr.io/@std/cache/0.2.3}/memoize.d.ts
RENAMED
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export interface MemoizationCache<K, V> {
|
|
7
|
+
/** Checks whether a value for the given key exists in the cache. */
|
|
8
|
+
has(key: K): boolean;
|
|
9
|
+
/** Returns the cached value associated with the given key, if present. */
|
|
10
|
+
get(key: K): V | undefined;
|
|
11
|
+
/** Stores a value in the cache under the given key. */
|
|
12
|
+
set(key: K, val: V): unknown;
|
|
13
|
+
/** Removes the value associated with the given key from the cache. */
|
|
14
|
+
delete(key: K): unknown;
|
|
15
|
+
}
|
|
12
16
|
/**
|
|
13
17
|
* The result of a memoized function, as stored in its cache.
|
|
14
18
|
*
|
|
@@ -39,8 +43,9 @@ export type MemoizeOptions<Fn extends (...args: never[]) => unknown, Key, Cache
|
|
|
39
43
|
* {@linkcode Map} object is instantiated upon memoization and used as a cache, with no
|
|
40
44
|
* limit on the number of results to be cached.
|
|
41
45
|
*
|
|
42
|
-
* Alternatively, you can supply
|
|
43
|
-
*
|
|
46
|
+
* Alternatively, you can supply an
|
|
47
|
+
* {@link https://jsr.io/@std/cache/doc/lru-cache/~/LruCache | LruCache}
|
|
48
|
+
* with a specified max size to limit memory usage.
|
|
44
49
|
*/
|
|
45
50
|
cache?: Cache;
|
|
46
51
|
/**
|
|
@@ -84,7 +89,8 @@ export type MemoizeOptions<Fn extends (...args: never[]) => unknown, Key, Cache
|
|
|
84
89
|
* @param fn The function to memoize
|
|
85
90
|
* @param options Options for memoization
|
|
86
91
|
*
|
|
87
|
-
* @returns The memoized function
|
|
92
|
+
* @returns The memoized function, with a `cache` property exposing the
|
|
93
|
+
* underlying cache for inspection or manual invalidation.
|
|
88
94
|
*
|
|
89
95
|
* @example Basic usage
|
|
90
96
|
* ```ts
|
|
@@ -107,5 +113,7 @@ export type MemoizeOptions<Fn extends (...args: never[]) => unknown, Key, Cache
|
|
|
107
113
|
* > avoid this, you can pass a custom `getKey` option or use the memoized
|
|
108
114
|
* > function inside an anonymous callback like `arr.map((x) => func(x))`.
|
|
109
115
|
*/
|
|
110
|
-
export declare function memoize<Fn extends (...args: never[]) => unknown, Key = string, Cache extends MemoizationCache<Key, MemoizationCacheResult<ReturnType<Fn>>> = Map<Key, MemoizationCacheResult<ReturnType<Fn>>>>(fn: Fn, options?: MemoizeOptions<Fn, Key, Cache>): Fn
|
|
116
|
+
export declare function memoize<Fn extends (...args: never[]) => unknown, Key = string, Cache extends MemoizationCache<Key, MemoizationCacheResult<ReturnType<Fn>>> = Map<Key, MemoizationCacheResult<ReturnType<Fn>>>>(fn: Fn, options?: MemoizeOptions<Fn, Key, Cache>): Fn & {
|
|
117
|
+
cache: Cache;
|
|
118
|
+
};
|
|
111
119
|
//# sourceMappingURL=memoize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cache/0.2.3/memoize.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACpC,oEAAoE;IACpE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IACrB,0EAA0E;IAC1E,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,uDAAuD;IACvD,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IAC7B,sEAAsE;IACtE,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAChC;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACjC,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG,KAAK,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CACxB,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EACxC,GAAG,EACH,KAAK,SAAS,gBAAgB,CAAC,GAAG,EAAE,sBAAsB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,IACzE;IACF;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,iBAAiB,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC;IACvE;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;CAC9C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,OAAO,CACrB,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EACxC,GAAG,GAAG,MAAM,EACZ,KAAK,SAAS,gBAAgB,CAAC,GAAG,EAAE,sBAAsB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,GACzE,GAAG,CACD,GAAG,EACH,sBAAsB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CACvC,EAEH,EAAE,EAAE,EAAE,EACN,OAAO,CAAC,EAAE,cAAc,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GACvC,EAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAkEvB"}
|
|
@@ -15,7 +15,8 @@ const _serialize_arg_list_js_1 = require("./_serialize_arg_list.js");
|
|
|
15
15
|
* @param fn The function to memoize
|
|
16
16
|
* @param options Options for memoization
|
|
17
17
|
*
|
|
18
|
-
* @returns The memoized function
|
|
18
|
+
* @returns The memoized function, with a `cache` property exposing the
|
|
19
|
+
* underlying cache for inspection or manual invalidation.
|
|
19
20
|
*
|
|
20
21
|
* @example Basic usage
|
|
21
22
|
* ```ts
|
|
@@ -39,20 +40,22 @@ const _serialize_arg_list_js_1 = require("./_serialize_arg_list.js");
|
|
|
39
40
|
* > function inside an anonymous callback like `arr.map((x) => func(x))`.
|
|
40
41
|
*/
|
|
41
42
|
function memoize(fn, options) {
|
|
42
|
-
const cache = options?.cache ?? new Map();
|
|
43
|
+
const cache = (options?.cache ?? new Map());
|
|
43
44
|
const getKey = options?.getKey ??
|
|
44
45
|
(0, _serialize_arg_list_js_1._serializeArgList)(cache);
|
|
45
46
|
const errorIsCacheable = options?.errorIsCacheable ?? (() => false);
|
|
46
47
|
const memoized = function (...args) {
|
|
47
48
|
const key = getKey.apply(this, args);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const cached = cache.get(key);
|
|
50
|
+
// `MemoizationCacheResult` is always a truthy object, so `undefined`
|
|
51
|
+
// reliably indicates a cache miss here.
|
|
52
|
+
if (cached !== undefined) {
|
|
53
|
+
switch (cached.kind) {
|
|
51
54
|
case "ok":
|
|
52
55
|
case "promise":
|
|
53
|
-
return
|
|
56
|
+
return cached.value;
|
|
54
57
|
case "error":
|
|
55
|
-
throw
|
|
58
|
+
throw cached.error;
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
try {
|
|
@@ -81,5 +84,6 @@ function memoize(fn, options) {
|
|
|
81
84
|
return Object.defineProperties(memoized, {
|
|
82
85
|
length: { value: fn.length },
|
|
83
86
|
name: { value: fn.name },
|
|
87
|
+
cache: { value: cache },
|
|
84
88
|
});
|
|
85
89
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to_array_buffer.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/streams/1.1.0/to_array_buffer.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,aAAa,CACjC,cAAc,EAAE,cAAc,CAAC,UAAU,CAAC,GACzC,OAAO,CAAC,WAAW,CAAC,CAetB"}
|