@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.
Files changed (172) hide show
  1. package/esm/0_deps.d.ts +4 -4
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +4 -4
  4. package/esm/3_types.d.ts +2 -0
  5. package/esm/3_types.d.ts.map +1 -1
  6. package/esm/3_types.js +2 -0
  7. package/esm/client/0_params.d.ts +21 -3
  8. package/esm/client/0_params.d.ts.map +1 -1
  9. package/esm/client/0_utilities.d.ts +1 -1
  10. package/esm/client/0_utilities.d.ts.map +1 -1
  11. package/esm/client/1_client_generic.d.ts +60 -4
  12. package/esm/client/1_client_generic.d.ts.map +1 -1
  13. package/esm/client/2_managed_bot_manager.d.ts +4 -1
  14. package/esm/client/2_managed_bot_manager.d.ts.map +1 -1
  15. package/esm/client/2_managed_bot_manager.js +13 -0
  16. package/esm/client/3_account_manager.d.ts +2 -1
  17. package/esm/client/3_account_manager.d.ts.map +1 -1
  18. package/esm/client/3_account_manager.js +17 -2
  19. package/esm/client/3_filters.d.ts +6 -1
  20. package/esm/client/3_filters.d.ts.map +1 -1
  21. package/esm/client/3_message_manager.d.ts +10 -6
  22. package/esm/client/3_message_manager.d.ts.map +1 -1
  23. package/esm/client/3_message_manager.js +67 -13
  24. package/esm/client/3_sticker_set_manager.d.ts +1 -2
  25. package/esm/client/3_sticker_set_manager.d.ts.map +1 -1
  26. package/esm/client/4_context.d.ts +8 -1
  27. package/esm/client/4_context.d.ts.map +1 -1
  28. package/esm/client/4_context.js +21 -1
  29. package/esm/client/4_story_manager.d.ts +1 -2
  30. package/esm/client/4_story_manager.d.ts.map +1 -1
  31. package/esm/client/6_client.d.ts +60 -5
  32. package/esm/client/6_client.d.ts.map +1 -1
  33. package/esm/client/6_client.js +75 -2
  34. package/esm/client/6_client_dispatcher.d.ts +60 -5
  35. package/esm/client/6_client_dispatcher.d.ts.map +1 -1
  36. package/esm/client/6_client_dispatcher.js +75 -2
  37. package/esm/connection/1_connection_web_socket.d.ts +1 -1
  38. package/esm/connection/1_connection_web_socket.d.ts.map +1 -1
  39. 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
  40. package/{script/deps/jsr.io/@std/async/1.2.0 → esm/deps/jsr.io/@std/async/1.3.0}/pool.d.ts +2 -0
  41. package/esm/deps/jsr.io/@std/async/1.3.0/pool.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/pool.js +5 -1
  43. package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts.map +1 -1
  44. package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.js +27 -16
  45. 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
  46. package/esm/deps/jsr.io/@std/cache/0.2.3/lru_cache.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@std/cache/0.2.3/lru_cache.js +299 -0
  48. package/{script/deps/jsr.io/@std/cache/0.2.2 → esm/deps/jsr.io/@std/cache/0.2.3}/memoize.d.ts +18 -10
  49. package/esm/deps/jsr.io/@std/cache/0.2.3/memoize.d.ts.map +1 -0
  50. package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/memoize.js +11 -7
  51. package/esm/deps/jsr.io/@std/streams/1.1.0/to_array_buffer.d.ts.map +1 -0
  52. package/esm/tl/1_telegram_api.d.ts +251 -5
  53. package/esm/tl/1_telegram_api.d.ts.map +1 -1
  54. package/esm/tl/1_telegram_api.js +271 -11
  55. package/esm/types/1_chat_p.d.ts +2 -0
  56. package/esm/types/1_chat_p.d.ts.map +1 -1
  57. package/esm/types/1_chat_p.js +1 -0
  58. package/esm/types/1_video.d.ts.map +1 -1
  59. package/esm/types/1_video.js +3 -2
  60. package/esm/types/2_user.d.ts +2 -0
  61. package/esm/types/2_user.d.ts.map +1 -1
  62. package/esm/types/2_user.js +1 -0
  63. package/esm/types/3_bot_access_settings.d.ts +27 -0
  64. package/esm/types/3_bot_access_settings.d.ts.map +1 -0
  65. package/esm/types/3_bot_access_settings.js +27 -0
  66. package/esm/types/4_poll.d.ts +2 -0
  67. package/esm/types/4_poll.d.ts.map +1 -1
  68. package/esm/types/4_poll.js +1 -0
  69. package/esm/types/6_message.d.ts +12 -1
  70. package/esm/types/6_message.d.ts.map +1 -1
  71. package/esm/types/6_message.js +20 -2
  72. package/esm/types/7_guest_query.d.ts +28 -0
  73. package/esm/types/7_guest_query.d.ts.map +1 -0
  74. package/esm/types/7_guest_query.js +20 -0
  75. package/esm/types/8_update.d.ts +19 -1
  76. package/esm/types/8_update.d.ts.map +1 -1
  77. package/package.json +1 -1
  78. package/script/0_deps.d.ts +4 -4
  79. package/script/0_deps.d.ts.map +1 -1
  80. package/script/0_deps.js +4 -4
  81. package/script/3_types.d.ts +2 -0
  82. package/script/3_types.d.ts.map +1 -1
  83. package/script/3_types.js +2 -0
  84. package/script/client/0_params.d.ts +21 -3
  85. package/script/client/0_params.d.ts.map +1 -1
  86. package/script/client/0_utilities.d.ts +1 -1
  87. package/script/client/0_utilities.d.ts.map +1 -1
  88. package/script/client/1_client_generic.d.ts +60 -4
  89. package/script/client/1_client_generic.d.ts.map +1 -1
  90. package/script/client/2_managed_bot_manager.d.ts +4 -1
  91. package/script/client/2_managed_bot_manager.d.ts.map +1 -1
  92. package/script/client/2_managed_bot_manager.js +13 -0
  93. package/script/client/3_account_manager.d.ts +2 -1
  94. package/script/client/3_account_manager.d.ts.map +1 -1
  95. package/script/client/3_account_manager.js +17 -2
  96. package/script/client/3_filters.d.ts +6 -1
  97. package/script/client/3_filters.d.ts.map +1 -1
  98. package/script/client/3_message_manager.d.ts +10 -6
  99. package/script/client/3_message_manager.d.ts.map +1 -1
  100. package/script/client/3_message_manager.js +65 -11
  101. package/script/client/3_sticker_set_manager.d.ts +1 -2
  102. package/script/client/3_sticker_set_manager.d.ts.map +1 -1
  103. package/script/client/4_context.d.ts +8 -1
  104. package/script/client/4_context.d.ts.map +1 -1
  105. package/script/client/4_context.js +21 -1
  106. package/script/client/4_story_manager.d.ts +1 -2
  107. package/script/client/4_story_manager.d.ts.map +1 -1
  108. package/script/client/6_client.d.ts +60 -5
  109. package/script/client/6_client.d.ts.map +1 -1
  110. package/script/client/6_client.js +75 -2
  111. package/script/client/6_client_dispatcher.d.ts +60 -5
  112. package/script/client/6_client_dispatcher.d.ts.map +1 -1
  113. package/script/client/6_client_dispatcher.js +75 -2
  114. package/script/connection/1_connection_web_socket.d.ts +1 -1
  115. package/script/connection/1_connection_web_socket.d.ts.map +1 -1
  116. 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
  117. package/{esm/deps/jsr.io/@std/async/1.2.0 → script/deps/jsr.io/@std/async/1.3.0}/pool.d.ts +2 -0
  118. package/script/deps/jsr.io/@std/async/1.3.0/pool.d.ts.map +1 -0
  119. package/script/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/pool.js +5 -1
  120. package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts.map +1 -1
  121. package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.js +27 -16
  122. 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
  123. package/script/deps/jsr.io/@std/cache/0.2.3/lru_cache.d.ts.map +1 -0
  124. package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/lru_cache.js +149 -38
  125. package/{esm/deps/jsr.io/@std/cache/0.2.2 → script/deps/jsr.io/@std/cache/0.2.3}/memoize.d.ts +18 -10
  126. package/script/deps/jsr.io/@std/cache/0.2.3/memoize.d.ts.map +1 -0
  127. package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/memoize.js +11 -7
  128. package/script/deps/jsr.io/@std/streams/1.1.0/to_array_buffer.d.ts.map +1 -0
  129. package/script/tl/1_telegram_api.d.ts +251 -5
  130. package/script/tl/1_telegram_api.d.ts.map +1 -1
  131. package/script/tl/1_telegram_api.js +271 -11
  132. package/script/types/1_chat_p.d.ts +2 -0
  133. package/script/types/1_chat_p.d.ts.map +1 -1
  134. package/script/types/1_chat_p.js +1 -0
  135. package/script/types/1_video.d.ts.map +1 -1
  136. package/script/types/1_video.js +3 -2
  137. package/script/types/2_user.d.ts +2 -0
  138. package/script/types/2_user.d.ts.map +1 -1
  139. package/script/types/2_user.js +1 -0
  140. package/script/types/3_bot_access_settings.d.ts +27 -0
  141. package/script/types/3_bot_access_settings.d.ts.map +1 -0
  142. package/script/types/3_bot_access_settings.js +30 -0
  143. package/script/types/4_poll.d.ts +2 -0
  144. package/script/types/4_poll.d.ts.map +1 -1
  145. package/script/types/4_poll.js +1 -0
  146. package/script/types/6_message.d.ts +12 -1
  147. package/script/types/6_message.d.ts.map +1 -1
  148. package/script/types/6_message.js +20 -2
  149. package/script/types/7_guest_query.d.ts +28 -0
  150. package/script/types/7_guest_query.d.ts.map +1 -0
  151. package/script/types/7_guest_query.js +21 -0
  152. package/script/types/8_update.d.ts +19 -1
  153. package/script/types/8_update.d.ts.map +1 -1
  154. package/esm/deps/jsr.io/@std/async/1.2.0/pool.d.ts.map +0 -1
  155. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.d.ts.map +0 -1
  156. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +0 -188
  157. package/esm/deps/jsr.io/@std/cache/0.2.2/memoize.d.ts.map +0 -1
  158. package/esm/deps/jsr.io/@std/streams/1.0.17/to_array_buffer.d.ts.map +0 -1
  159. package/script/deps/jsr.io/@std/async/1.2.0/pool.d.ts.map +0 -1
  160. package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.d.ts.map +0 -1
  161. package/script/deps/jsr.io/@std/cache/0.2.2/memoize.d.ts.map +0 -1
  162. package/script/deps/jsr.io/@std/streams/1.0.17/to_array_buffer.d.ts.map +0 -1
  163. /package/esm/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.d.ts +0 -0
  164. /package/esm/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.js +0 -0
  165. /package/esm/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts +0 -0
  166. /package/esm/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.d.ts +0 -0
  167. /package/esm/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.js +0 -0
  168. /package/script/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.d.ts +0 -0
  169. /package/script/deps/jsr.io/@std/async/{1.2.0 → 1.3.0}/delay.js +0 -0
  170. /package/script/deps/jsr.io/@std/cache/{0.2.2 → 0.2.3}/_serialize_arg_list.d.ts +0 -0
  171. /package/script/deps/jsr.io/@std/streams/{1.0.17 → 1.1.0}/to_array_buffer.d.ts +0 -0
  172. /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`, `set`, or `has`.
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 a onEject function.
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 cache = new LruCache<string, string>(3, { onEject: (key, value) => {
47
- * console.log("Revoking: ", key)
48
- * URL.revokeObjectURL(value)
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
- * "fast-url",
53
- * URL.createObjectURL(new Blob(["Hello, World"], { type: "text/plain" }))
54
- * );
51
+ * cache.set("a", 1);
52
+ * cache.set("b", 2);
53
+ * cache.set("c", 3);
55
54
  *
56
- * cache.delete("fast-url") // "Revoking: fast-url"
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 no-assert
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
- #eject;
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 > this.maxSize) {
93
- this.delete(this.keys().next().value);
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
- const exists = super.has(key);
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 the key is not present in the cache.
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 (super.has(key)) {
187
- this.#eject(key, super.get(key));
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
- return super.delete(key);
299
+ if (error !== undefined)
300
+ throw error;
190
301
  }
191
302
  }
192
303
  exports.LruCache = LruCache;
@@ -3,12 +3,16 @@
3
3
  *
4
4
  * @experimental **UNSTABLE**: New API, yet to be vetted.
5
5
  */
6
- export type MemoizationCache<K, V> = {
7
- has: (key: K) => boolean;
8
- get: (key: K) => V | undefined;
9
- set: (key: K, val: V) => unknown;
10
- delete: (key: K) => unknown;
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 a {@linkcode LruCache} with a specified max
43
- * size to limit memory usage.
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
- if (cache.has(key)) {
49
- const result = cache.get(key);
50
- switch (result.kind) {
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 result.value;
56
+ return cached.value;
54
57
  case "error":
55
- throw result.error;
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"}