@mtkruto/browser 0.142.0 → 0.143.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 +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/client/0_params.d.ts +10 -0
- 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 +34 -3
- package/esm/client/1_client_generic.d.ts.map +1 -1
- 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 +8 -5
- package/esm/client/3_message_manager.d.ts.map +1 -1
- package/esm/client/3_message_manager.js +39 -10
- package/esm/client/4_context.d.ts +8 -0
- package/esm/client/4_context.d.ts.map +1 -1
- package/esm/client/4_context.js +21 -1
- package/esm/client/6_client.d.ts +34 -3
- package/esm/client/6_client.d.ts.map +1 -1
- package/esm/client/6_client.js +44 -2
- package/esm/client/6_client_dispatcher.d.ts +34 -3
- package/esm/client/6_client_dispatcher.d.ts.map +1 -1
- package/esm/client/6_client_dispatcher.js +44 -2
- 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/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/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/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 +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/client/0_params.d.ts +10 -0
- 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 +34 -3
- package/script/client/1_client_generic.d.ts.map +1 -1
- 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 +8 -5
- package/script/client/3_message_manager.d.ts.map +1 -1
- package/script/client/3_message_manager.js +37 -8
- package/script/client/4_context.d.ts +8 -0
- package/script/client/4_context.d.ts.map +1 -1
- package/script/client/4_context.js +21 -1
- package/script/client/6_client.d.ts +34 -3
- package/script/client/6_client.d.ts.map +1 -1
- package/script/client/6_client.js +44 -2
- package/script/client/6_client_dispatcher.d.ts +34 -3
- package/script/client/6_client_dispatcher.d.ts.map +1 -1
- package/script/client/6_client_dispatcher.js +44 -2
- 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/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/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/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
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* Least-recently-used cache.
|
|
5
|
+
*
|
|
6
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU | Least-recently-used cache}
|
|
9
|
+
*
|
|
10
|
+
* Automatically removes entries above the max size based on when they were
|
|
11
|
+
* last accessed with `get` or `set`.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam K The type of the cache keys.
|
|
14
|
+
* @typeParam V The type of the cache values.
|
|
15
|
+
*
|
|
16
|
+
* @example Basic usage
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { LruCache } from "@std/cache";
|
|
19
|
+
* import { assert, assertEquals } from "@std/assert";
|
|
20
|
+
*
|
|
21
|
+
* const MAX_SIZE = 3;
|
|
22
|
+
* const cache = new LruCache<string, number>(MAX_SIZE);
|
|
23
|
+
*
|
|
24
|
+
* cache.set("a", 1);
|
|
25
|
+
* cache.set("b", 2);
|
|
26
|
+
* cache.set("c", 3);
|
|
27
|
+
* cache.set("d", 4);
|
|
28
|
+
*
|
|
29
|
+
* // most recent values are stored up to `MAX_SIZE`
|
|
30
|
+
* assertEquals(cache.get("b"), 2);
|
|
31
|
+
* assertEquals(cache.get("c"), 3);
|
|
32
|
+
* assertEquals(cache.get("d"), 4);
|
|
33
|
+
*
|
|
34
|
+
* // less recent values are removed
|
|
35
|
+
* assert(!cache.has("a"));
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Adding an onEject callback
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { LruCache } from "@std/cache";
|
|
41
|
+
* import { assertEquals } from "@std/assert";
|
|
42
|
+
*
|
|
43
|
+
* const ejected: [string, number, string][] = [];
|
|
44
|
+
* const cache = new LruCache<string, number>(2, {
|
|
45
|
+
* onEject: (key, value, reason) => ejected.push([key, value, reason]),
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* cache.set("a", 1);
|
|
49
|
+
* cache.set("b", 2);
|
|
50
|
+
* cache.set("c", 3);
|
|
51
|
+
*
|
|
52
|
+
* assertEquals(ejected, [["a", 1, "evicted"]]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export class LruCache extends Map {
|
|
56
|
+
#maxSize;
|
|
57
|
+
#ejecting = false;
|
|
58
|
+
#eject;
|
|
59
|
+
/**
|
|
60
|
+
* Constructs a new `LruCache`.
|
|
61
|
+
*
|
|
62
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
63
|
+
*
|
|
64
|
+
* @param maxSize The maximum number of entries to store in the cache. Must
|
|
65
|
+
* be a positive integer.
|
|
66
|
+
* @param options Additional options.
|
|
67
|
+
*/
|
|
68
|
+
constructor(maxSize, options) {
|
|
69
|
+
super();
|
|
70
|
+
if (!Number.isInteger(maxSize) || maxSize < 1) {
|
|
71
|
+
throw new RangeError(`Cannot create LruCache: maxSize must be a positive integer: received ${maxSize}`);
|
|
72
|
+
}
|
|
73
|
+
this.#maxSize = maxSize;
|
|
74
|
+
this.#eject = options?.onEject;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The maximum number of entries to store in the cache.
|
|
78
|
+
*
|
|
79
|
+
* @returns The maximum number of entries in the cache.
|
|
80
|
+
*
|
|
81
|
+
* @example Max size
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { LruCache } from "@std/cache";
|
|
84
|
+
* import { assertEquals } from "@std/assert";
|
|
85
|
+
*
|
|
86
|
+
* const cache = new LruCache<string, number>(100);
|
|
87
|
+
* assertEquals(cache.maxSize, 100);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
get maxSize() {
|
|
91
|
+
return this.#maxSize;
|
|
92
|
+
}
|
|
93
|
+
#setMostRecentlyUsed(key, value) {
|
|
94
|
+
super.delete(key);
|
|
95
|
+
super.set(key, value);
|
|
96
|
+
}
|
|
97
|
+
#pruneToMaxSize() {
|
|
98
|
+
if (this.size <= this.#maxSize)
|
|
99
|
+
return;
|
|
100
|
+
const key = this.keys().next().value;
|
|
101
|
+
const value = super.get(key);
|
|
102
|
+
super.delete(key);
|
|
103
|
+
if (this.#eject) {
|
|
104
|
+
this.#ejecting = true;
|
|
105
|
+
try {
|
|
106
|
+
this.#eject(key, value, "evicted");
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
this.#ejecting = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks whether an element with the specified key exists or not. Does
|
|
115
|
+
* **not** update the entry's position in the eviction order.
|
|
116
|
+
*
|
|
117
|
+
* @param key The key to check.
|
|
118
|
+
* @returns `true` if the cache contains the specified key, otherwise `false`.
|
|
119
|
+
*
|
|
120
|
+
* @example Checking for the existence of a key
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { LruCache } from "@std/cache";
|
|
123
|
+
* import { assert } from "@std/assert";
|
|
124
|
+
*
|
|
125
|
+
* const cache = new LruCache<string, number>(100);
|
|
126
|
+
*
|
|
127
|
+
* cache.set("a", 1);
|
|
128
|
+
* assert(cache.has("a"));
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
has(key) {
|
|
132
|
+
return super.has(key);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets the element with the specified key.
|
|
136
|
+
*
|
|
137
|
+
* @param key The key to get the value for.
|
|
138
|
+
* @returns The value associated with the specified key, or `undefined` if
|
|
139
|
+
* the key is not present in the cache.
|
|
140
|
+
*
|
|
141
|
+
* @example Getting a value from the cache
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { LruCache } from "@std/cache";
|
|
144
|
+
* import { assertEquals } from "@std/assert";
|
|
145
|
+
*
|
|
146
|
+
* const cache = new LruCache<string, number>(100);
|
|
147
|
+
*
|
|
148
|
+
* cache.set("a", 1);
|
|
149
|
+
* assertEquals(cache.get("a"), 1);
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
get(key) {
|
|
153
|
+
if (super.has(key)) {
|
|
154
|
+
const value = super.get(key);
|
|
155
|
+
this.#setMostRecentlyUsed(key, value);
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the value associated with the given key, or `undefined` if the
|
|
162
|
+
* key is not present, **without** updating its position in the eviction
|
|
163
|
+
* order.
|
|
164
|
+
*
|
|
165
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
166
|
+
*
|
|
167
|
+
* @param key The key to look up.
|
|
168
|
+
* @returns The value, or `undefined` if not present.
|
|
169
|
+
*
|
|
170
|
+
* @example Peeking at a value without promoting it
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { LruCache } from "@std/cache";
|
|
173
|
+
* import { assertEquals } from "@std/assert";
|
|
174
|
+
*
|
|
175
|
+
* const cache = new LruCache<string, number>(3);
|
|
176
|
+
* cache.set("a", 1);
|
|
177
|
+
* cache.set("b", 2);
|
|
178
|
+
* cache.set("c", 3);
|
|
179
|
+
*
|
|
180
|
+
* // peek does not promote "a"
|
|
181
|
+
* assertEquals(cache.peek("a"), 1);
|
|
182
|
+
*
|
|
183
|
+
* // "a" is still the least recently used and gets evicted
|
|
184
|
+
* cache.set("d", 4);
|
|
185
|
+
* assertEquals(cache.peek("a"), undefined);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
peek(key) {
|
|
189
|
+
return super.get(key);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Sets the specified key to the specified value.
|
|
193
|
+
*
|
|
194
|
+
* @param key The key to set the value for.
|
|
195
|
+
* @param value The value to set.
|
|
196
|
+
* @returns `this` for chaining.
|
|
197
|
+
*
|
|
198
|
+
* @example Setting a value in the cache
|
|
199
|
+
* ```ts no-assert
|
|
200
|
+
* import { LruCache } from "@std/cache";
|
|
201
|
+
*
|
|
202
|
+
* const cache = new LruCache<string, number>(100);
|
|
203
|
+
* cache.set("a", 1);
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
set(key, value) {
|
|
207
|
+
if (this.#ejecting) {
|
|
208
|
+
throw new TypeError("Cannot set entry in LruCache: cache is not re-entrant during onEject callbacks");
|
|
209
|
+
}
|
|
210
|
+
this.#setMostRecentlyUsed(key, value);
|
|
211
|
+
this.#pruneToMaxSize();
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Deletes the value associated with the given key.
|
|
216
|
+
*
|
|
217
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
218
|
+
*
|
|
219
|
+
* @param key The key to delete.
|
|
220
|
+
* @returns `true` if the key was deleted, `false` otherwise.
|
|
221
|
+
*
|
|
222
|
+
* @example Deleting a key from the cache
|
|
223
|
+
* ```ts
|
|
224
|
+
* import { LruCache } from "@std/cache";
|
|
225
|
+
* import { assertEquals } from "@std/assert/equals";
|
|
226
|
+
*
|
|
227
|
+
* const cache = new LruCache<string, number>(1);
|
|
228
|
+
*
|
|
229
|
+
* cache.set("a", 1);
|
|
230
|
+
* cache.delete("a");
|
|
231
|
+
* assertEquals(cache.has("a"), false);
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
delete(key) {
|
|
235
|
+
if (this.#ejecting) {
|
|
236
|
+
throw new TypeError("Cannot delete entry in LruCache: cache is not re-entrant during onEject callbacks");
|
|
237
|
+
}
|
|
238
|
+
const value = super.get(key);
|
|
239
|
+
const existed = super.delete(key);
|
|
240
|
+
if (!existed)
|
|
241
|
+
return false;
|
|
242
|
+
if (this.#eject) {
|
|
243
|
+
this.#ejecting = true;
|
|
244
|
+
try {
|
|
245
|
+
this.#eject(key, value, "deleted");
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
this.#ejecting = false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Clears the cache.
|
|
255
|
+
*
|
|
256
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
257
|
+
*
|
|
258
|
+
* @example Usage
|
|
259
|
+
* ```ts
|
|
260
|
+
* import { LruCache } from "@std/cache";
|
|
261
|
+
* import { assertEquals } from "@std/assert/equals";
|
|
262
|
+
*
|
|
263
|
+
* const cache = new LruCache<string, number>(100);
|
|
264
|
+
*
|
|
265
|
+
* cache.set("a", 1);
|
|
266
|
+
* cache.set("b", 2);
|
|
267
|
+
* cache.clear();
|
|
268
|
+
* assertEquals(cache.size, 0);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
clear() {
|
|
272
|
+
if (this.#ejecting) {
|
|
273
|
+
throw new TypeError("Cannot clear LruCache: cache is not re-entrant during onEject callbacks");
|
|
274
|
+
}
|
|
275
|
+
if (!this.#eject) {
|
|
276
|
+
super.clear();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const entries = [...super.entries()];
|
|
280
|
+
super.clear();
|
|
281
|
+
this.#ejecting = true;
|
|
282
|
+
let error;
|
|
283
|
+
try {
|
|
284
|
+
for (const [key, value] of entries) {
|
|
285
|
+
try {
|
|
286
|
+
this.#eject(key, value, "cleared");
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
error ??= e;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
this.#ejecting = false;
|
|
295
|
+
}
|
|
296
|
+
if (error !== undefined)
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
package/{script/deps/jsr.io/@std/cache/0.2.2 → esm/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"}
|
|
@@ -12,7 +12,8 @@ import { _serializeArgList } from "./_serialize_arg_list.js";
|
|
|
12
12
|
* @param fn The function to memoize
|
|
13
13
|
* @param options Options for memoization
|
|
14
14
|
*
|
|
15
|
-
* @returns The memoized function
|
|
15
|
+
* @returns The memoized function, with a `cache` property exposing the
|
|
16
|
+
* underlying cache for inspection or manual invalidation.
|
|
16
17
|
*
|
|
17
18
|
* @example Basic usage
|
|
18
19
|
* ```ts
|
|
@@ -36,20 +37,22 @@ import { _serializeArgList } from "./_serialize_arg_list.js";
|
|
|
36
37
|
* > function inside an anonymous callback like `arr.map((x) => func(x))`.
|
|
37
38
|
*/
|
|
38
39
|
export function memoize(fn, options) {
|
|
39
|
-
const cache = options?.cache ?? new Map();
|
|
40
|
+
const cache = (options?.cache ?? new Map());
|
|
40
41
|
const getKey = options?.getKey ??
|
|
41
42
|
_serializeArgList(cache);
|
|
42
43
|
const errorIsCacheable = options?.errorIsCacheable ?? (() => false);
|
|
43
44
|
const memoized = function (...args) {
|
|
44
45
|
const key = getKey.apply(this, args);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const cached = cache.get(key);
|
|
47
|
+
// `MemoizationCacheResult` is always a truthy object, so `undefined`
|
|
48
|
+
// reliably indicates a cache miss here.
|
|
49
|
+
if (cached !== undefined) {
|
|
50
|
+
switch (cached.kind) {
|
|
48
51
|
case "ok":
|
|
49
52
|
case "promise":
|
|
50
|
-
return
|
|
53
|
+
return cached.value;
|
|
51
54
|
case "error":
|
|
52
|
-
throw
|
|
55
|
+
throw cached.error;
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
try {
|
|
@@ -78,5 +81,6 @@ export function memoize(fn, options) {
|
|
|
78
81
|
return Object.defineProperties(memoized, {
|
|
79
82
|
length: { value: fn.length },
|
|
80
83
|
name: { value: fn.name },
|
|
84
|
+
cache: { value: cache },
|
|
81
85
|
});
|
|
82
86
|
}
|
|
@@ -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"}
|