@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
@@ -399,7 +399,7 @@ export class ClientDispatcher extends Composer {
399
399
  return await this.#dispatch("updateProfile", params);
400
400
  }
401
401
  /**
402
- * Update the profile photo of the current user.
402
+ * Update the profile photo of the current user or a bot managed by the current user.
403
403
  *
404
404
  * @method ac
405
405
  * @param photo The photo to set as profile photo.
@@ -408,7 +408,7 @@ export class ClientDispatcher extends Composer {
408
408
  return await this.#dispatch("updateProfilePhoto", photo, params);
409
409
  }
410
410
  /**
411
- * Update the profile video of the current user.
411
+ * Update the profile video of the current user or a bot managed by the current user.
412
412
  *
413
413
  * @method ac
414
414
  * @param video The video to set as profile video.
@@ -416,6 +416,14 @@ export class ClientDispatcher extends Composer {
416
416
  async updateProfileVideo(video, params) {
417
417
  return await this.#dispatch("updateProfileVideo", video, params);
418
418
  }
419
+ /**
420
+ * Remove the profile video of the current user or a bot managed by the current user.
421
+ *
422
+ * @method ac
423
+ */
424
+ async removeProfilePhoto(params) {
425
+ return await this.#dispatch("removeProfilePhoto", params);
426
+ }
419
427
  /**
420
428
  * Set the birthday of the current user. User-only.
421
429
  *
@@ -666,6 +674,18 @@ export class ClientDispatcher extends Composer {
666
674
  async sendPhoto(chatId, photo, params) {
667
675
  return await this.#dispatch("sendPhoto", chatId, photo, params);
668
676
  }
677
+ /**
678
+ * Send a live photo.
679
+ *
680
+ * @method ms
681
+ * @param chatId The identifier of a chat to send the photo to.
682
+ * @param photo The photo to send.
683
+ * @param photo The video version of the photo.
684
+ * @returns The sent live photo.
685
+ */
686
+ async sendLivePhoto(chatId, photo, video, params) {
687
+ return await this.#dispatch("sendLivePhoto", chatId, photo, video, params);
688
+ }
669
689
  /**
670
690
  * Send a document.
671
691
  *
@@ -2351,6 +2371,27 @@ export class ClientDispatcher extends Composer {
2351
2371
  async removeReaction(chatId, messageId, reaction) {
2352
2372
  return await this.#dispatch("removeReaction", chatId, messageId, reaction);
2353
2373
  }
2374
+ /**
2375
+ * Undo a reaction by another user.
2376
+ *
2377
+ * @method re
2378
+ * @param chatId The identifier of the chat which the message belongs to.
2379
+ * @param messageId The identifier of the message which the reaction was made to.
2380
+ * @param userId The identifier of the user who made the reaction.
2381
+ */
2382
+ async removeUserReaction(chatId, messageId, userId) {
2383
+ return await this.#dispatch("removeUserReaction", chatId, messageId, userId);
2384
+ }
2385
+ /**
2386
+ * Undo recent reactions to messages made by another user.
2387
+ *
2388
+ * @method re
2389
+ * @param chatId The identifier of the chat which the messages belongs to.
2390
+ * @param userId The identifier of the user who made the reactions.
2391
+ */
2392
+ async removeUserReactions(chatId, userId) {
2393
+ return await this.#dispatch("removeUserReactions", chatId, userId);
2394
+ }
2354
2395
  /**
2355
2396
  * Clear recent reactions. User-only.
2356
2397
  *
@@ -3096,4 +3137,36 @@ export class ClientDispatcher extends Composer {
3096
3137
  async revokeManagedBotToken(userId) {
3097
3138
  return await this.#dispatch("revokeManagedBotToken", userId);
3098
3139
  }
3140
+ /**
3141
+ * Set the access settings of a managed bot. Bot-only.
3142
+ *
3143
+ * @method mb
3144
+ * @param userId The identifier of the bot user.
3145
+ * @param isAccessRestricted Whether access is restricted to specific users.
3146
+ */
3147
+ async setManagedBotAccessSettings(userId, isAccessRestricted, params) {
3148
+ return await this.#dispatch("setManagedBotAccessSettings", userId, isAccessRestricted, params);
3149
+ }
3150
+ /**
3151
+ * Set the access settings of a managed bot. Bot-only.
3152
+ *
3153
+ * @method mb
3154
+ * @param userId The identifier of the bot user.
3155
+ */
3156
+ async getManagedBotAccessSettings(userId) {
3157
+ return await this.#dispatch("getManagedBotAccessSettings", userId);
3158
+ }
3159
+ //
3160
+ // ========================= GUEST QUERIES ========================= //
3161
+ //
3162
+ /**
3163
+ * Answer a guest query. Bot-only.
3164
+ *
3165
+ * @method gq
3166
+ * @param id The identifier of the guest query to answer.
3167
+ * @returns The identifier of the sent message.
3168
+ */
3169
+ async answerGuestQuery(id, result) {
3170
+ return await this.#dispatch("answerGuestQuery", id, result);
3171
+ }
3099
3172
  }
@@ -25,7 +25,7 @@ export declare class ConnectionWebSocket implements Connection {
25
25
  get isConnected(): boolean;
26
26
  open(): Promise<void>;
27
27
  read(p: Uint8Array): Promise<void>;
28
- write(p: Uint8Array): Promise<void>;
28
+ write(p: Uint8Array<ArrayBuffer>): Promise<void>;
29
29
  close(): void;
30
30
  }
31
31
  //# sourceMappingURL=1_connection_web_socket.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"1_connection_web_socket.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_web_socket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,mBAAoB,YAAW,UAAU;;IAOpD,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,GAAG,EAAE,MAAM;IA8CvB,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGK,IAAI;IAmBJ,IAAI,CAAC,CAAC,EAAE,UAAU;IAgBlB,KAAK,CAAC,CAAC,EAAE,UAAU;IAkBzB,KAAK;CAMN"}
1
+ {"version":3,"file":"1_connection_web_socket.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_web_socket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,mBAAoB,YAAW,UAAU;;IAOpD,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,GAAG,EAAE,MAAM;IA8CvB,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGK,IAAI;IAmBJ,IAAI,CAAC,CAAC,EAAE,UAAU;IAgBlB,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC;IAkBtC,KAAK;CAMN"}
@@ -1 +1 @@
1
- {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/delay.ts"],"names":[],"mappings":"AAGA,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B3E"}
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.3.0/delay.ts"],"names":[],"mappings":"AAGA,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B3E"}
@@ -25,9 +25,11 @@
25
25
  * @typeParam T the input type.
26
26
  * @typeParam R the output type.
27
27
  * @param poolLimit The maximum count of items being processed concurrently.
28
+ * Must be a positive integer.
28
29
  * @param array The input array for mapping.
29
30
  * @param iteratorFn The function to call for every item of the array.
30
31
  * @returns The async iterator with the transformed values.
32
+ * @throws {RangeError} If `poolLimit` is not a positive integer.
31
33
  */
32
34
  export declare function pooledMap<T, R>(poolLimit: number, array: Iterable<T> | AsyncIterable<T>, iteratorFn: (data: T) => Promise<R>): AsyncIterableIterator<R>;
33
35
  //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.3.0/pool.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EACrC,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,qBAAqB,CAAC,CAAC,CAAC,CAwE1B"}
@@ -29,12 +29,16 @@ const ERROR_WHILE_MAPPING_MESSAGE = "Cannot complete the mapping as an error was
29
29
  * @typeParam T the input type.
30
30
  * @typeParam R the output type.
31
31
  * @param poolLimit The maximum count of items being processed concurrently.
32
+ * Must be a positive integer.
32
33
  * @param array The input array for mapping.
33
34
  * @param iteratorFn The function to call for every item of the array.
34
35
  * @returns The async iterator with the transformed values.
36
+ * @throws {RangeError} If `poolLimit` is not a positive integer.
35
37
  */
36
38
  export function pooledMap(poolLimit, array, iteratorFn) {
37
- // Create the async iterable that is returned from this function.
39
+ if (!Number.isInteger(poolLimit) || poolLimit < 1) {
40
+ throw new RangeError("'poolLimit' must be a positive integer");
41
+ }
38
42
  const res = new TransformStream({
39
43
  async transform(p, controller) {
40
44
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"_serialize_arg_list.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cache/0.2.2/_serialize_arg_list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;;GAQG;AAEH,wBAAgB,iBAAiB,CAAC,MAAM,EACtC,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACvC,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAmE/C"}
1
+ {"version":3,"file":"_serialize_arg_list.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cache/0.2.3/_serialize_arg_list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EACtC,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACvC,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAgF/C"}
@@ -8,9 +8,17 @@
8
8
  * @returns `getKey`, the function for getting cache keys.
9
9
  */
10
10
  export function _serializeArgList(cache) {
11
+ // Three cooperating data structures track weak (reference-type) arguments:
12
+ // 1. weakKeyToKeySegmentCache: WeakMap from object/symbol → segment id
13
+ // (e.g. `"{0}"`) so the same reference always maps to the same segment.
14
+ // 2. weakKeySegmentToKeyCache: Map from segment id → set of composite cache
15
+ // keys that contain that segment, used by the finalization callback.
16
+ // 3. registry (FinalizationRegistry): when a weak key is garbage-collected,
17
+ // looks up its segment in (2) and deletes all associated entries from the
18
+ // caller-provided cache.
11
19
  const weakKeyToKeySegmentCache = new WeakMap();
12
20
  const weakKeySegmentToKeyCache = new Map();
13
- let i = 0;
21
+ let nextWeakKeyId = 0;
14
22
  const registry = new FinalizationRegistry((keySegment) => {
15
23
  for (const key of weakKeySegmentToKeyCache.get(keySegment) ?? []) {
16
24
  cache.delete(key);
@@ -35,35 +43,38 @@ export function _serializeArgList(cache) {
35
43
  // e.g. https://github.com/tc39/proposal-record-tuple
36
44
  return JSON.stringify(arg);
37
45
  }
46
+ if (typeof arg === "symbol") {
47
+ try {
48
+ new WeakRef(arg);
49
+ }
50
+ catch {
51
+ return `Symbol.for(${JSON.stringify(arg.description)})`;
52
+ }
53
+ }
38
54
  try {
39
- assertWeakKey(arg);
55
+ new WeakRef(arg);
40
56
  }
41
57
  catch {
42
- if (typeof arg === "symbol") {
43
- return `Symbol.for(${JSON.stringify(arg.description)})`;
44
- }
45
- // Non-weak keys other than `Symbol.for(...)` are handled by the branches above.
46
58
  throw new Error("Should be unreachable: please open an issue at https://github.com/denoland/std/issues/new");
47
59
  }
48
- if (!weakKeyToKeySegmentCache.has(arg)) {
49
- const keySegment = `{${i++}}`;
50
- weakKeySegments.push(keySegment);
60
+ let keySegment = weakKeyToKeySegmentCache.get(arg);
61
+ if (keySegment === undefined) {
62
+ keySegment = `{${nextWeakKeyId++}}`;
51
63
  registry.register(arg, keySegment);
52
64
  weakKeyToKeySegmentCache.set(arg, keySegment);
53
65
  }
54
- const keySegment = weakKeyToKeySegmentCache.get(arg);
55
66
  weakKeySegments.push(keySegment);
56
67
  return keySegment;
57
68
  });
58
69
  const key = keySegments.join(",");
59
70
  for (const keySegment of weakKeySegments) {
60
- const keys = weakKeySegmentToKeyCache.get(keySegment) ?? [];
61
- keys.push(key);
62
- weakKeySegmentToKeyCache.set(keySegment, keys);
71
+ let keys = weakKeySegmentToKeyCache.get(keySegment);
72
+ if (keys === undefined) {
73
+ keys = new Set();
74
+ weakKeySegmentToKeyCache.set(keySegment, keys);
75
+ }
76
+ keys.add(key);
63
77
  }
64
78
  return key;
65
79
  };
66
80
  }
67
- function assertWeakKey(arg) {
68
- new WeakRef(arg);
69
- }
@@ -1,5 +1,38 @@
1
1
  import type { MemoizationCache } from "./memoize.js";
2
2
  export type { MemoizationCache };
3
+ /**
4
+ * The reason an entry was removed from the cache.
5
+ *
6
+ * @experimental **UNSTABLE**: New API, yet to be vetted.
7
+ *
8
+ * - `"evicted"` — removed automatically because the cache exceeded
9
+ * {@linkcode LruCache.prototype.maxSize | maxSize}.
10
+ * - `"deleted"` — removed by an explicit
11
+ * {@linkcode LruCache.prototype.delete | delete()} call.
12
+ * - `"cleared"` — removed by
13
+ * {@linkcode LruCache.prototype.clear | clear()}.
14
+ */
15
+ export type LruCacheEjectionReason = "evicted" | "deleted" | "cleared";
16
+ /**
17
+ * Options for the {@linkcode LruCache} constructor.
18
+ *
19
+ * @experimental **UNSTABLE**: New API, yet to be vetted.
20
+ */
21
+ export interface LruCacheOptions<K, V> {
22
+ /**
23
+ * Callback invoked when an entry is removed, whether by eviction,
24
+ * manual deletion, or clearing the cache. The entry is already removed
25
+ * from the cache when this callback fires. Overwriting an existing key
26
+ * via {@linkcode LruCache.prototype.set | set()} does **not** trigger
27
+ * this callback. The cache is not re-entrant during this callback:
28
+ * calling `set`, `delete`, or `clear` will throw.
29
+ *
30
+ * @param ejectedKey The key of the removed entry.
31
+ * @param ejectedValue The value of the removed entry.
32
+ * @param reason Why the entry was removed.
33
+ */
34
+ onEject?: (ejectedKey: K, ejectedValue: V, reason: LruCacheEjectionReason) => void;
35
+ }
3
36
  /**
4
37
  * Least-recently-used cache.
5
38
  *
@@ -8,7 +41,7 @@ export type { MemoizationCache };
8
41
  * @see {@link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU | Least-recently-used cache}
9
42
  *
10
43
  * Automatically removes entries above the max size based on when they were
11
- * last accessed with `get`, `set`, or `has`.
44
+ * last accessed with `get` or `set`.
12
45
  *
13
46
  * @typeParam K The type of the cache keys.
14
47
  * @typeParam V The type of the cache values.
@@ -35,32 +68,42 @@ export type { MemoizationCache };
35
68
  * assert(!cache.has("a"));
36
69
  * ```
37
70
  *
38
- * @example Adding a onEject function.
71
+ * @example Adding an onEject callback
39
72
  * ```ts
40
73
  * import { LruCache } from "@std/cache";
41
74
  * import { assertEquals } from "@std/assert";
42
75
  *
43
- * const cache = new LruCache<string, string>(3, { onEject: (key, value) => {
44
- * console.log("Revoking: ", key)
45
- * URL.revokeObjectURL(value)
46
- * }});
76
+ * const ejected: [string, number, string][] = [];
77
+ * const cache = new LruCache<string, number>(2, {
78
+ * onEject: (key, value, reason) => ejected.push([key, value, reason]),
79
+ * });
47
80
  *
48
- * cache.set(
49
- * "fast-url",
50
- * URL.createObjectURL(new Blob(["Hello, World"], { type: "text/plain" }))
51
- * );
81
+ * cache.set("a", 1);
82
+ * cache.set("b", 2);
83
+ * cache.set("c", 3);
52
84
  *
53
- * cache.delete("fast-url") // "Revoking: fast-url"
54
- * assertEquals(cache.get("fast-url"), undefined)
85
+ * assertEquals(ejected, [["a", 1, "evicted"]]);
55
86
  * ```
56
87
  */
57
88
  export declare class LruCache<K, V> extends Map<K, V> implements MemoizationCache<K, V> {
58
89
  #private;
90
+ /**
91
+ * Constructs a new `LruCache`.
92
+ *
93
+ * @experimental **UNSTABLE**: New API, yet to be vetted.
94
+ *
95
+ * @param maxSize The maximum number of entries to store in the cache. Must
96
+ * be a positive integer.
97
+ * @param options Additional options.
98
+ */
99
+ constructor(maxSize: number, options?: LruCacheOptions<K, V>);
59
100
  /**
60
101
  * The maximum number of entries to store in the cache.
61
102
  *
103
+ * @returns The maximum number of entries in the cache.
104
+ *
62
105
  * @example Max size
63
- * ```ts no-assert
106
+ * ```ts
64
107
  * import { LruCache } from "@std/cache";
65
108
  * import { assertEquals } from "@std/assert";
66
109
  *
@@ -68,18 +111,10 @@ export declare class LruCache<K, V> extends Map<K, V> implements MemoizationCach
68
111
  * assertEquals(cache.maxSize, 100);
69
112
  * ```
70
113
  */
71
- maxSize: number;
114
+ get maxSize(): number;
72
115
  /**
73
- * Constructs a new `LruCache`.
74
- *
75
- * @param maxSize The maximum number of entries to store in the cache.
76
- * @param options Additional options.
77
- */
78
- constructor(maxSize: number, options?: {
79
- onEject: (ejectedKey: K, ejectedValue: V) => void;
80
- });
81
- /**
82
- * Checks whether an element with the specified key exists or not.
116
+ * Checks whether an element with the specified key exists or not. Does
117
+ * **not** update the entry's position in the eviction order.
83
118
  *
84
119
  * @param key The key to check.
85
120
  * @returns `true` if the cache contains the specified key, otherwise `false`.
@@ -100,7 +135,8 @@ export declare class LruCache<K, V> extends Map<K, V> implements MemoizationCach
100
135
  * Gets the element with the specified key.
101
136
  *
102
137
  * @param key The key to get the value for.
103
- * @returns The value associated with the specified key, or `undefined` if the key is not present in the cache.
138
+ * @returns The value associated with the specified key, or `undefined` if
139
+ * the key is not present in the cache.
104
140
  *
105
141
  * @example Getting a value from the cache
106
142
  * ```ts
@@ -114,6 +150,35 @@ export declare class LruCache<K, V> extends Map<K, V> implements MemoizationCach
114
150
  * ```
115
151
  */
116
152
  get(key: K): V | undefined;
153
+ /**
154
+ * Returns the value associated with the given key, or `undefined` if the
155
+ * key is not present, **without** updating its position in the eviction
156
+ * order.
157
+ *
158
+ * @experimental **UNSTABLE**: New API, yet to be vetted.
159
+ *
160
+ * @param key The key to look up.
161
+ * @returns The value, or `undefined` if not present.
162
+ *
163
+ * @example Peeking at a value without promoting it
164
+ * ```ts
165
+ * import { LruCache } from "@std/cache";
166
+ * import { assertEquals } from "@std/assert";
167
+ *
168
+ * const cache = new LruCache<string, number>(3);
169
+ * cache.set("a", 1);
170
+ * cache.set("b", 2);
171
+ * cache.set("c", 3);
172
+ *
173
+ * // peek does not promote "a"
174
+ * assertEquals(cache.peek("a"), 1);
175
+ *
176
+ * // "a" is still the least recently used and gets evicted
177
+ * cache.set("d", 4);
178
+ * assertEquals(cache.peek("a"), undefined);
179
+ * ```
180
+ */
181
+ peek(key: K): V | undefined;
117
182
  /**
118
183
  * Sets the specified key to the specified value.
119
184
  *
@@ -151,5 +216,24 @@ export declare class LruCache<K, V> extends Map<K, V> implements MemoizationCach
151
216
  * ```
152
217
  */
153
218
  delete(key: K): boolean;
219
+ /**
220
+ * Clears the cache.
221
+ *
222
+ * @experimental **UNSTABLE**: New API, yet to be vetted.
223
+ *
224
+ * @example Usage
225
+ * ```ts
226
+ * import { LruCache } from "@std/cache";
227
+ * import { assertEquals } from "@std/assert/equals";
228
+ *
229
+ * const cache = new LruCache<string, number>(100);
230
+ *
231
+ * cache.set("a", 1);
232
+ * cache.set("b", 2);
233
+ * cache.clear();
234
+ * assertEquals(cache.size, 0);
235
+ * ```
236
+ */
237
+ clear(): void;
154
238
  }
155
239
  //# sourceMappingURL=lru_cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru_cache.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cache/0.2.3/lru_cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC;IACnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,CACR,UAAU,EAAE,CAAC,EACb,YAAY,EAAE,CAAC,EACf,MAAM,EAAE,sBAAsB,KAC3B,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAC1C,YAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;;IAOjC;;;;;;;;OAQG;gBAED,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;IAYjC;;;;;;;;;;;;;OAaG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAsBD;;;;;;;;;;;;;;;;;OAiBG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAI7B;;;;;;;;;;;;;;;;;OAiBG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAUnC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAI3B;;;;;;;;;;;;;;OAcG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAYpC;;;;;;;;;;;;;;;;;;;OAmBG;IACM,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAqBhC;;;;;;;;;;;;;;;;;OAiBG;IACM,KAAK,IAAI,IAAI;CA2BvB"}