@mtkruto/browser 0.128.0 → 0.130.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 (151) hide show
  1. package/esm/0_deps.d.ts +4 -3
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +4 -3
  4. package/esm/3_types.d.ts +4 -0
  5. package/esm/3_types.d.ts.map +1 -1
  6. package/esm/3_types.js +4 -0
  7. package/esm/client/0_params.d.ts +26 -0
  8. package/esm/client/0_params.d.ts.map +1 -1
  9. package/esm/client/1_client_generic.d.ts +41 -2
  10. package/esm/client/1_client_generic.d.ts.map +1 -1
  11. package/esm/client/1_types.d.ts +1 -0
  12. package/esm/client/1_types.d.ts.map +1 -1
  13. package/esm/client/2_account_manager.d.ts +3 -0
  14. package/esm/client/2_account_manager.d.ts.map +1 -1
  15. package/esm/client/2_account_manager.js +16 -1
  16. package/esm/client/2_takeout_manager.d.ts +29 -0
  17. package/esm/client/2_takeout_manager.d.ts.map +1 -0
  18. package/esm/client/2_takeout_manager.js +41 -0
  19. package/esm/client/3_message_manager.js +1 -1
  20. package/esm/client/6_client.d.ts +41 -2
  21. package/esm/client/6_client.d.ts.map +1 -1
  22. package/esm/client/6_client.js +64 -3
  23. package/esm/client/6_client_dispatcher.d.ts +41 -2
  24. package/esm/client/6_client_dispatcher.d.ts.map +1 -1
  25. package/esm/client/6_client_dispatcher.js +54 -0
  26. package/esm/types/0_calling_code.d.ts +31 -0
  27. package/esm/types/0_calling_code.d.ts.map +1 -0
  28. package/esm/types/0_calling_code.js +26 -0
  29. package/esm/types/0_chat_action_type.d.ts +13 -0
  30. package/esm/types/0_chat_action_type.d.ts.map +1 -1
  31. package/esm/types/0_timezone.d.ts +31 -0
  32. package/esm/types/0_timezone.d.ts.map +1 -0
  33. package/esm/types/0_timezone.js +26 -0
  34. package/esm/types/1_available_reactions.d.ts +1 -0
  35. package/esm/types/1_available_reactions.d.ts.map +1 -1
  36. package/esm/types/1_chat_p.d.ts +1 -1
  37. package/esm/types/1_chat_p.d.ts.map +1 -1
  38. package/esm/types/1_chat_p.js +1 -1
  39. package/esm/types/1_country.d.ts +36 -0
  40. package/esm/types/1_country.d.ts.map +1 -0
  41. package/esm/types/1_country.js +30 -0
  42. package/esm/types/2_left_channel_list.d.ts +30 -0
  43. package/esm/types/2_left_channel_list.d.ts.map +1 -0
  44. package/esm/types/2_left_channel_list.js +25 -0
  45. package/esm/types/2_story_album_icon.d.ts +1 -0
  46. package/esm/types/2_story_album_icon.d.ts.map +1 -1
  47. package/esm/types/2_user.d.ts +1 -1
  48. package/esm/types/2_user.d.ts.map +1 -1
  49. package/esm/types/2_user.js +2 -2
  50. package/esm/types/3_app_support.d.ts +3 -0
  51. package/esm/types/3_app_support.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/script/0_deps.d.ts +4 -3
  54. package/script/0_deps.d.ts.map +1 -1
  55. package/script/0_deps.js +13 -12
  56. package/script/3_types.d.ts +4 -0
  57. package/script/3_types.d.ts.map +1 -1
  58. package/script/3_types.js +4 -0
  59. package/script/client/0_params.d.ts +26 -0
  60. package/script/client/0_params.d.ts.map +1 -1
  61. package/script/client/1_client_generic.d.ts +41 -2
  62. package/script/client/1_client_generic.d.ts.map +1 -1
  63. package/script/client/1_types.d.ts +1 -0
  64. package/script/client/1_types.d.ts.map +1 -1
  65. package/script/client/2_account_manager.d.ts +3 -0
  66. package/script/client/2_account_manager.d.ts.map +1 -1
  67. package/script/client/2_account_manager.js +15 -0
  68. package/script/client/2_takeout_manager.d.ts +29 -0
  69. package/script/client/2_takeout_manager.d.ts.map +1 -0
  70. package/script/client/2_takeout_manager.js +45 -0
  71. package/script/client/3_message_manager.js +1 -1
  72. package/script/client/6_client.d.ts +41 -2
  73. package/script/client/6_client.d.ts.map +1 -1
  74. package/script/client/6_client.js +64 -3
  75. package/script/client/6_client_dispatcher.d.ts +41 -2
  76. package/script/client/6_client_dispatcher.d.ts.map +1 -1
  77. package/script/client/6_client_dispatcher.js +54 -0
  78. package/script/types/0_calling_code.d.ts +31 -0
  79. package/script/types/0_calling_code.d.ts.map +1 -0
  80. package/script/types/0_calling_code.js +29 -0
  81. package/script/types/0_chat_action_type.d.ts +13 -0
  82. package/script/types/0_chat_action_type.d.ts.map +1 -1
  83. package/script/types/0_timezone.d.ts +31 -0
  84. package/script/types/0_timezone.d.ts.map +1 -0
  85. package/script/types/0_timezone.js +29 -0
  86. package/script/types/1_available_reactions.d.ts +1 -0
  87. package/script/types/1_available_reactions.d.ts.map +1 -1
  88. package/script/types/1_chat_p.d.ts +1 -1
  89. package/script/types/1_chat_p.d.ts.map +1 -1
  90. package/script/types/1_chat_p.js +1 -1
  91. package/script/types/1_country.d.ts +36 -0
  92. package/script/types/1_country.d.ts.map +1 -0
  93. package/script/types/1_country.js +33 -0
  94. package/script/types/2_left_channel_list.d.ts +30 -0
  95. package/script/types/2_left_channel_list.d.ts.map +1 -0
  96. package/script/types/2_left_channel_list.js +28 -0
  97. package/script/types/2_story_album_icon.d.ts +1 -0
  98. package/script/types/2_story_album_icon.d.ts.map +1 -1
  99. package/script/types/2_user.d.ts +1 -1
  100. package/script/types/2_user.d.ts.map +1 -1
  101. package/script/types/2_user.js +2 -2
  102. package/script/types/3_app_support.d.ts +3 -0
  103. package/script/types/3_app_support.d.ts.map +1 -1
  104. package/esm/deps/jsr.io/@std/async/1.2.0/_util.d.ts +0 -2
  105. package/esm/deps/jsr.io/@std/async/1.2.0/_util.d.ts.map +0 -1
  106. package/esm/deps/jsr.io/@std/async/1.2.0/_util.js +0 -6
  107. package/esm/deps/jsr.io/@std/async/1.2.0/abortable.d.ts +0 -107
  108. package/esm/deps/jsr.io/@std/async/1.2.0/abortable.d.ts.map +0 -1
  109. package/esm/deps/jsr.io/@std/async/1.2.0/abortable.js +0 -46
  110. package/esm/deps/jsr.io/@std/async/1.2.0/deadline.d.ts +0 -37
  111. package/esm/deps/jsr.io/@std/async/1.2.0/deadline.d.ts.map +0 -1
  112. package/esm/deps/jsr.io/@std/async/1.2.0/deadline.js +0 -41
  113. package/esm/deps/jsr.io/@std/async/1.2.0/debounce.d.ts +0 -44
  114. package/esm/deps/jsr.io/@std/async/1.2.0/debounce.d.ts.map +0 -1
  115. package/esm/deps/jsr.io/@std/async/1.2.0/debounce.js +0 -57
  116. package/esm/deps/jsr.io/@std/async/1.2.0/mod.d.ts +0 -22
  117. package/esm/deps/jsr.io/@std/async/1.2.0/mod.d.ts.map +0 -1
  118. package/esm/deps/jsr.io/@std/async/1.2.0/mod.js +0 -23
  119. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts +0 -111
  120. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts.map +0 -1
  121. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +0 -154
  122. package/esm/deps/jsr.io/@std/async/1.2.0/retry.d.ts +0 -155
  123. package/esm/deps/jsr.io/@std/async/1.2.0/retry.d.ts.map +0 -1
  124. package/esm/deps/jsr.io/@std/async/1.2.0/retry.js +0 -147
  125. package/esm/deps/jsr.io/@std/async/1.2.0/tee.d.ts +0 -43
  126. package/esm/deps/jsr.io/@std/async/1.2.0/tee.d.ts.map +0 -1
  127. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +0 -79
  128. package/script/deps/jsr.io/@std/async/1.2.0/_util.d.ts +0 -2
  129. package/script/deps/jsr.io/@std/async/1.2.0/_util.d.ts.map +0 -1
  130. package/script/deps/jsr.io/@std/async/1.2.0/_util.js +0 -9
  131. package/script/deps/jsr.io/@std/async/1.2.0/abortable.d.ts +0 -107
  132. package/script/deps/jsr.io/@std/async/1.2.0/abortable.d.ts.map +0 -1
  133. package/script/deps/jsr.io/@std/async/1.2.0/abortable.js +0 -49
  134. package/script/deps/jsr.io/@std/async/1.2.0/deadline.d.ts +0 -37
  135. package/script/deps/jsr.io/@std/async/1.2.0/deadline.d.ts.map +0 -1
  136. package/script/deps/jsr.io/@std/async/1.2.0/deadline.js +0 -44
  137. package/script/deps/jsr.io/@std/async/1.2.0/debounce.d.ts +0 -44
  138. package/script/deps/jsr.io/@std/async/1.2.0/debounce.d.ts.map +0 -1
  139. package/script/deps/jsr.io/@std/async/1.2.0/debounce.js +0 -60
  140. package/script/deps/jsr.io/@std/async/1.2.0/mod.d.ts +0 -22
  141. package/script/deps/jsr.io/@std/async/1.2.0/mod.d.ts.map +0 -1
  142. package/script/deps/jsr.io/@std/async/1.2.0/mod.js +0 -39
  143. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts +0 -111
  144. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts.map +0 -1
  145. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +0 -158
  146. package/script/deps/jsr.io/@std/async/1.2.0/retry.d.ts +0 -155
  147. package/script/deps/jsr.io/@std/async/1.2.0/retry.d.ts.map +0 -1
  148. package/script/deps/jsr.io/@std/async/1.2.0/retry.js +0 -152
  149. package/script/deps/jsr.io/@std/async/1.2.0/tee.d.ts +0 -43
  150. package/script/deps/jsr.io/@std/async/1.2.0/tee.d.ts.map +0 -1
  151. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +0 -82
@@ -1,155 +0,0 @@
1
- /**
2
- * Error thrown in {@linkcode retry} once the maximum number of failed attempts
3
- * has been reached.
4
- *
5
- * @example Usage
6
- * ```ts no-assert ignore
7
- * import { RetryError } from "@std/async/retry";
8
- *
9
- * throw new RetryError({ foo: "bar" }, 3);
10
- * ```
11
- */
12
- export declare class RetryError extends Error {
13
- /**
14
- * Constructs a new {@linkcode RetryError} instance.
15
- *
16
- * @param cause the cause for this error.
17
- * @param attempts the number of retry attempts made.
18
- */
19
- constructor(cause: unknown, attempts: number);
20
- }
21
- /** Options for {@linkcode retry}. */
22
- export interface RetryOptions {
23
- /**
24
- * How much to backoff after each retry.
25
- *
26
- * @default {2}
27
- */
28
- multiplier?: number;
29
- /**
30
- * The maximum milliseconds between attempts.
31
- *
32
- * @default {60000}
33
- */
34
- maxTimeout?: number;
35
- /**
36
- * The maximum amount of attempts until failure.
37
- *
38
- * @default {5}
39
- */
40
- maxAttempts?: number;
41
- /**
42
- * The initial and minimum amount of milliseconds between attempts.
43
- *
44
- * @default {1000}
45
- */
46
- minTimeout?: number;
47
- /**
48
- * Amount of jitter to introduce to the time between attempts. This is `1`
49
- * for full jitter by default.
50
- *
51
- * @default {1}
52
- */
53
- jitter?: number;
54
- /**
55
- * Callback to determine if an error or other thrown value is retriable.
56
- *
57
- * @default {() => true}
58
- *
59
- * @param err The thrown error or other value.
60
- * @returns `true` if the error is retriable, `false` otherwise.
61
- */
62
- isRetriable?: (err: unknown) => boolean;
63
- /**
64
- * An AbortSignal to cancel the retry operation.
65
- *
66
- * If the signal is aborted, the retry will stop and reject with the signal's
67
- * reason. The signal is checked before each attempt and during the delay
68
- * between attempts.
69
- *
70
- * @default {undefined}
71
- */
72
- signal?: AbortSignal;
73
- }
74
- /**
75
- * Calls the given (possibly asynchronous) function up to `maxAttempts` times.
76
- * Retries as long as the given function throws. If the attempts are exhausted,
77
- * throws a {@linkcode RetryError} with `cause` set to the inner exception.
78
- *
79
- * The backoff is calculated by multiplying `minTimeout` with `multiplier` to the power of the current attempt counter (starting at 0 up to `maxAttempts - 1`). It is capped at `maxTimeout` however.
80
- * How long the actual delay is, depends on `jitter`.
81
- *
82
- * When `jitter` is the default value of `1`, waits between two attempts for a
83
- * randomized amount between 0 and the backoff time. With the default options
84
- * the maximal delay will be `15s = 1s + 2s + 4s + 8s`. If all five attempts
85
- * are exhausted the mean delay will be `9.5s = ½(4s + 15s)`.
86
- *
87
- * When `jitter` is `0`, waits the full backoff time.
88
- *
89
- * @example Example configuration 1
90
- * ```ts no-assert
91
- * import { retry } from "@std/async/retry";
92
- * const req = async () => {
93
- * // some function that throws sometimes
94
- * };
95
- *
96
- * // Below resolves to the first non-error result of `req`
97
- * const retryPromise = await retry(req, {
98
- * multiplier: 2,
99
- * maxTimeout: 60000,
100
- * maxAttempts: 5,
101
- * minTimeout: 100,
102
- * jitter: 1,
103
- * });
104
- * ```
105
- *
106
- * @example Example configuration 2
107
- * ```ts no-assert
108
- * import { retry } from "@std/async/retry";
109
- * const req = async () => {
110
- * // some function that throws sometimes
111
- * };
112
- *
113
- * // Make sure we wait at least 1 minute, but at most 2 minutes
114
- * const retryPromise = await retry(req, {
115
- * multiplier: 2.34,
116
- * maxTimeout: 80000,
117
- * maxAttempts: 7,
118
- * minTimeout: 1000,
119
- * jitter: 0.5,
120
- * });
121
- * ```
122
- *
123
- * @example Only retry on specific error types
124
- * ```ts no-assert
125
- * import { retry } from "@std/async/retry";
126
- *
127
- * class HttpError extends Error {
128
- * status: number;
129
- * constructor(status: number) {
130
- * super(`HTTP ${status}`);
131
- * this.status = status;
132
- * }
133
- * }
134
- *
135
- * const req = async () => {
136
- * // some function that throws HttpError
137
- * };
138
- *
139
- * // Only retry on 429 (rate limit) or 5xx (server) errors
140
- * const retryPromise = await retry(req, {
141
- * isRetriable: (err) =>
142
- * err instanceof HttpError && (err.status === 429 || err.status >= 500),
143
- * });
144
- * ```
145
- *
146
- * @typeParam T The return type of the function to retry and returned promise.
147
- * @param fn The function to retry.
148
- * @param options Additional options.
149
- * @returns The promise that resolves with the value returned by the function to retry.
150
- * @throws {RetryError} If the function fails after `maxAttempts` attempts.
151
- * @throws If the `signal` is aborted, throws the signal's reason.
152
- * @throws If `isRetriable` returns `false` for an error, throws that error immediately.
153
- */
154
- export declare function retry<T>(fn: (() => Promise<T>) | (() => T), options?: RetryOptions): Promise<T>;
155
- //# sourceMappingURL=retry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/retry.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC;;;;;OAKG;gBACS,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;CAK7C;AAED,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;IACxC;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,EAAE,EAAE,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAClC,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,CAAC,CAAC,CAoEZ"}
@@ -1,147 +0,0 @@
1
- // Copyright 2018-2026 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- import { delay } from "./delay.js";
4
- import { exponentialBackoffWithJitter } from "./_util.js";
5
- /**
6
- * Error thrown in {@linkcode retry} once the maximum number of failed attempts
7
- * has been reached.
8
- *
9
- * @example Usage
10
- * ```ts no-assert ignore
11
- * import { RetryError } from "@std/async/retry";
12
- *
13
- * throw new RetryError({ foo: "bar" }, 3);
14
- * ```
15
- */
16
- export class RetryError extends Error {
17
- /**
18
- * Constructs a new {@linkcode RetryError} instance.
19
- *
20
- * @param cause the cause for this error.
21
- * @param attempts the number of retry attempts made.
22
- */
23
- constructor(cause, attempts) {
24
- super(`Retrying exceeded the maxAttempts (${attempts}).`);
25
- this.name = "RetryError";
26
- this.cause = cause;
27
- }
28
- }
29
- /**
30
- * Calls the given (possibly asynchronous) function up to `maxAttempts` times.
31
- * Retries as long as the given function throws. If the attempts are exhausted,
32
- * throws a {@linkcode RetryError} with `cause` set to the inner exception.
33
- *
34
- * The backoff is calculated by multiplying `minTimeout` with `multiplier` to the power of the current attempt counter (starting at 0 up to `maxAttempts - 1`). It is capped at `maxTimeout` however.
35
- * How long the actual delay is, depends on `jitter`.
36
- *
37
- * When `jitter` is the default value of `1`, waits between two attempts for a
38
- * randomized amount between 0 and the backoff time. With the default options
39
- * the maximal delay will be `15s = 1s + 2s + 4s + 8s`. If all five attempts
40
- * are exhausted the mean delay will be `9.5s = ½(4s + 15s)`.
41
- *
42
- * When `jitter` is `0`, waits the full backoff time.
43
- *
44
- * @example Example configuration 1
45
- * ```ts no-assert
46
- * import { retry } from "@std/async/retry";
47
- * const req = async () => {
48
- * // some function that throws sometimes
49
- * };
50
- *
51
- * // Below resolves to the first non-error result of `req`
52
- * const retryPromise = await retry(req, {
53
- * multiplier: 2,
54
- * maxTimeout: 60000,
55
- * maxAttempts: 5,
56
- * minTimeout: 100,
57
- * jitter: 1,
58
- * });
59
- * ```
60
- *
61
- * @example Example configuration 2
62
- * ```ts no-assert
63
- * import { retry } from "@std/async/retry";
64
- * const req = async () => {
65
- * // some function that throws sometimes
66
- * };
67
- *
68
- * // Make sure we wait at least 1 minute, but at most 2 minutes
69
- * const retryPromise = await retry(req, {
70
- * multiplier: 2.34,
71
- * maxTimeout: 80000,
72
- * maxAttempts: 7,
73
- * minTimeout: 1000,
74
- * jitter: 0.5,
75
- * });
76
- * ```
77
- *
78
- * @example Only retry on specific error types
79
- * ```ts no-assert
80
- * import { retry } from "@std/async/retry";
81
- *
82
- * class HttpError extends Error {
83
- * status: number;
84
- * constructor(status: number) {
85
- * super(`HTTP ${status}`);
86
- * this.status = status;
87
- * }
88
- * }
89
- *
90
- * const req = async () => {
91
- * // some function that throws HttpError
92
- * };
93
- *
94
- * // Only retry on 429 (rate limit) or 5xx (server) errors
95
- * const retryPromise = await retry(req, {
96
- * isRetriable: (err) =>
97
- * err instanceof HttpError && (err.status === 429 || err.status >= 500),
98
- * });
99
- * ```
100
- *
101
- * @typeParam T The return type of the function to retry and returned promise.
102
- * @param fn The function to retry.
103
- * @param options Additional options.
104
- * @returns The promise that resolves with the value returned by the function to retry.
105
- * @throws {RetryError} If the function fails after `maxAttempts` attempts.
106
- * @throws If the `signal` is aborted, throws the signal's reason.
107
- * @throws If `isRetriable` returns `false` for an error, throws that error immediately.
108
- */
109
- export async function retry(fn, options) {
110
- const { multiplier = 2, maxTimeout = 60000, maxAttempts = 5, minTimeout = 1000, jitter = 1, isRetriable = () => true, signal, } = options ?? {};
111
- if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {
112
- throw new RangeError(`Cannot retry as 'maxAttempts' must be a positive integer: current value is ${maxAttempts}`);
113
- }
114
- if (!Number.isFinite(multiplier) || multiplier < 1) {
115
- throw new RangeError(`Cannot retry as 'multiplier' must be a finite number >= 1: current value is ${multiplier}`);
116
- }
117
- if (Number.isNaN(maxTimeout) || maxTimeout <= 0) {
118
- throw new RangeError(`Cannot retry as 'maxTimeout' must be a positive number: current value is ${maxTimeout}`);
119
- }
120
- if (Number.isNaN(minTimeout) || minTimeout < 0) {
121
- throw new RangeError(`Cannot retry as 'minTimeout' must be >= 0: current value is ${minTimeout}`);
122
- }
123
- if (minTimeout > maxTimeout) {
124
- throw new RangeError(`Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=${minTimeout}', 'maxTimeout=${maxTimeout}'`);
125
- }
126
- if (Number.isNaN(jitter) || jitter < 0 || jitter > 1) {
127
- throw new RangeError(`Cannot retry as 'jitter' must be between 0 and 1: current value is ${jitter}`);
128
- }
129
- let attempt = 0;
130
- while (true) {
131
- signal?.throwIfAborted();
132
- try {
133
- return await fn();
134
- }
135
- catch (error) {
136
- if (!isRetriable(error)) {
137
- throw error;
138
- }
139
- if (attempt + 1 >= maxAttempts) {
140
- throw new RetryError(error, maxAttempts);
141
- }
142
- const timeout = exponentialBackoffWithJitter(maxTimeout, minTimeout, attempt, multiplier, jitter);
143
- await delay(timeout, signal ? { signal } : undefined);
144
- }
145
- attempt++;
146
- }
147
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * Utility for representing n-tuple. Used in {@linkcode tee}.
3
- *
4
- * @internal
5
- */
6
- export type Tuple<T, N extends number> = N extends N ? number extends N ? T[] : TupleOf<T, N, []> : never;
7
- /**
8
- * Utility for representing n-tuple of. Used in {@linkcode Tuple}.
9
- *
10
- * @internal
11
- */
12
- export type TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : TupleOf<T, N, [T, ...R]>;
13
- /**
14
- * Branches the given async iterable into the `n` branches.
15
- *
16
- * @example Usage
17
- * ```ts
18
- * import { tee } from "@std/async/tee";
19
- * import { assertEquals } from "@std/assert";
20
- *
21
- * const gen = async function* gen() {
22
- * yield 1;
23
- * yield 2;
24
- * yield 3;
25
- * };
26
- *
27
- * const [branch1, branch2] = tee(gen());
28
- *
29
- * const result1 = await Array.fromAsync(branch1);
30
- * assertEquals(result1, [1, 2, 3]);
31
- *
32
- * const result2 = await Array.fromAsync(branch2);
33
- * assertEquals(result2, [1, 2, 3]);
34
- * ```
35
- *
36
- * @typeParam T The type of the provided async iterable and the returned async iterables.
37
- * @typeParam N The amount of branches to tee into.
38
- * @param iterable The iterable to tee.
39
- * @param n The amount of branches to tee into.
40
- * @returns The tuple where each element is an async iterable.
41
- */
42
- export declare function tee<T, N extends number = 2>(iterable: AsyncIterable<T>, n?: N): Tuple<AsyncIterable<T>, N>;
43
- //# sourceMappingURL=tee.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tee.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/tee.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,GAChD,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAC1C,KAAK,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAAE,IAC1D,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,GACrB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAuC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,CAAC,EACzC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,CAAC,GAAE,CAAU,GACZ,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAuB5B"}
@@ -1,79 +0,0 @@
1
- // Copyright 2018-2026 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- class Queue {
4
- #source;
5
- #queue;
6
- head;
7
- done;
8
- constructor(iterable) {
9
- this.#source = iterable[Symbol.asyncIterator]();
10
- this.#queue = {
11
- value: undefined,
12
- next: undefined,
13
- };
14
- this.head = this.#queue;
15
- this.done = false;
16
- }
17
- async next() {
18
- const result = await this.#source.next();
19
- if (!result.done) {
20
- const nextNode = {
21
- value: result.value,
22
- next: undefined,
23
- };
24
- this.#queue.next = nextNode;
25
- this.#queue = nextNode;
26
- }
27
- else {
28
- this.done = true;
29
- }
30
- }
31
- }
32
- /**
33
- * Branches the given async iterable into the `n` branches.
34
- *
35
- * @example Usage
36
- * ```ts
37
- * import { tee } from "@std/async/tee";
38
- * import { assertEquals } from "@std/assert";
39
- *
40
- * const gen = async function* gen() {
41
- * yield 1;
42
- * yield 2;
43
- * yield 3;
44
- * };
45
- *
46
- * const [branch1, branch2] = tee(gen());
47
- *
48
- * const result1 = await Array.fromAsync(branch1);
49
- * assertEquals(result1, [1, 2, 3]);
50
- *
51
- * const result2 = await Array.fromAsync(branch2);
52
- * assertEquals(result2, [1, 2, 3]);
53
- * ```
54
- *
55
- * @typeParam T The type of the provided async iterable and the returned async iterables.
56
- * @typeParam N The amount of branches to tee into.
57
- * @param iterable The iterable to tee.
58
- * @param n The amount of branches to tee into.
59
- * @returns The tuple where each element is an async iterable.
60
- */
61
- export function tee(iterable, n = 2) {
62
- const queue = new Queue(iterable);
63
- async function* generator() {
64
- let buffer = queue.head;
65
- while (true) {
66
- if (buffer.next) {
67
- buffer = buffer.next;
68
- yield buffer.value;
69
- }
70
- else if (queue.done) {
71
- return;
72
- }
73
- else {
74
- await queue.next();
75
- }
76
- }
77
- }
78
- return Array.from({ length: n }).map(() => generator());
79
- }
@@ -1,2 +0,0 @@
1
- export declare function exponentialBackoffWithJitter(cap: number, base: number, attempt: number, multiplier: number, jitter: number): number;
2
- //# sourceMappingURL=_util.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_util.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/_util.ts"],"names":[],"mappings":"AAGA,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,UAIf"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2026 the Deno authors. MIT license.
3
- // This module is browser compatible.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.exponentialBackoffWithJitter = exponentialBackoffWithJitter;
6
- function exponentialBackoffWithJitter(cap, base, attempt, multiplier, jitter) {
7
- const exp = Math.min(cap, base * multiplier ** attempt);
8
- return (1 - jitter * Math.random()) * exp;
9
- }
@@ -1,107 +0,0 @@
1
- /**
2
- * Make a {@linkcode Promise} abortable with the given signal.
3
- *
4
- * @throws {DOMException} If the signal is already aborted and `signal.reason`
5
- * is undefined. Otherwise, throws `signal.reason`.
6
- * @typeParam T The type of the provided and returned promise.
7
- * @param p The promise to make abortable.
8
- * @param signal The signal to abort the promise with.
9
- * @returns A promise that can be aborted.
10
- *
11
- * @example Error-handling a timeout
12
- * ```ts ignore
13
- * import { abortable, delay } from "@std/async";
14
- * import { assertRejects, assertEquals } from "@std/assert";
15
- *
16
- * const promise = delay(1_000);
17
- *
18
- * // Rejects with `DOMException` after 100 ms
19
- * await assertRejects(
20
- * () => abortable(promise, AbortSignal.timeout(100)),
21
- * DOMException,
22
- * "Signal timed out."
23
- * );
24
- * ```
25
- *
26
- * @example Error-handling an abort
27
- * ```ts ignore
28
- * import { abortable, delay } from "@std/async";
29
- * import { assertRejects, assertEquals } from "@std/assert";
30
- *
31
- * const promise = delay(1_000);
32
- * const controller = new AbortController();
33
- * controller.abort(new Error("This is my reason"));
34
- *
35
- * // Rejects with `DOMException` immediately
36
- * await assertRejects(
37
- * () => abortable(promise, controller.signal),
38
- * Error,
39
- * "This is my reason"
40
- * );
41
- * ```
42
- */
43
- export declare function abortable<T>(p: Promise<T>, signal: AbortSignal): Promise<T>;
44
- /**
45
- * Make an {@linkcode AsyncIterable} abortable with the given signal.
46
- *
47
- * @throws {DOMException} If the signal is already aborted and `signal.reason`
48
- * is undefined. Otherwise, throws `signal.reason`.
49
- * @typeParam T The type of the provided and returned async iterable.
50
- * @param p The async iterable to make abortable.
51
- * @param signal The signal to abort the promise with.
52
- * @returns An async iterable that can be aborted.
53
- *
54
- * @example Error-handling a timeout
55
- * ```ts
56
- * import { abortable, delay } from "@std/async";
57
- * import { assertRejects, assertEquals } from "@std/assert";
58
- *
59
- * const asyncIter = async function* () {
60
- * yield "Hello";
61
- * await delay(1_000);
62
- * yield "World";
63
- * };
64
- *
65
- * const items: string[] = [];
66
- * // Below throws `DOMException` after 100 ms and items become `["Hello"]`
67
- * await assertRejects(
68
- * async () => {
69
- * for await (const item of abortable(asyncIter(), AbortSignal.timeout(100))) {
70
- * items.push(item);
71
- * }
72
- * },
73
- * DOMException,
74
- * "Signal timed out."
75
- * );
76
- * assertEquals(items, ["Hello"]);
77
- * ```
78
- *
79
- * @example Error-handling an abort
80
- * ```ts
81
- * import { abortable, delay } from "@std/async";
82
- * import { assertRejects, assertEquals } from "@std/assert";
83
- *
84
- * const asyncIter = async function* () {
85
- * yield "Hello";
86
- * await delay(1_000);
87
- * yield "World";
88
- * };
89
- * const controller = new AbortController();
90
- * controller.abort(new Error("This is my reason"));
91
- *
92
- * const items: string[] = [];
93
- * // Below throws `DOMException` immediately
94
- * await assertRejects(
95
- * async () => {
96
- * for await (const item of abortable(asyncIter(), controller.signal)) {
97
- * items.push(item);
98
- * }
99
- * },
100
- * Error,
101
- * "This is my reason"
102
- * );
103
- * assertEquals(items, []);
104
- * ```
105
- */
106
- export declare function abortable<T>(p: AsyncIterable<T>, signal: AbortSignal): AsyncGenerator<T>;
107
- //# sourceMappingURL=abortable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/abortable.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EACzB,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,GAClB,cAAc,CAAC,CAAC,CAAC,CAAC"}
@@ -1,49 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2026 the Deno authors. MIT license.
3
- // This module is browser compatible.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.abortable = abortable;
6
- function abortable(p, signal) {
7
- if (p instanceof Promise) {
8
- return abortablePromise(p, signal);
9
- }
10
- else {
11
- return abortableAsyncIterable(p, signal);
12
- }
13
- }
14
- function abortablePromise(p, signal) {
15
- const { promise, reject } = Promise.withResolvers();
16
- const abort = () => reject(signal.reason);
17
- if (signal.aborted)
18
- abort();
19
- signal.addEventListener("abort", abort, { once: true });
20
- return Promise.race([promise, p]).finally(() => {
21
- signal.removeEventListener("abort", abort);
22
- });
23
- }
24
- async function* abortableAsyncIterable(p, signal) {
25
- signal.throwIfAborted();
26
- const { promise, reject } = Promise.withResolvers();
27
- const abort = () => reject(signal.reason);
28
- signal.addEventListener("abort", abort, { once: true });
29
- const it = p[Symbol.asyncIterator]();
30
- try {
31
- while (true) {
32
- const race = Promise.race([promise, it.next()]);
33
- race.catch(() => {
34
- signal.removeEventListener("abort", abort);
35
- });
36
- const { done, value } = await race;
37
- if (done) {
38
- signal.removeEventListener("abort", abort);
39
- const result = await it.return?.(value);
40
- return result?.value;
41
- }
42
- yield value;
43
- }
44
- }
45
- catch (e) {
46
- await it.return?.();
47
- throw e;
48
- }
49
- }
@@ -1,37 +0,0 @@
1
- /** Options for {@linkcode deadline}. */
2
- export interface DeadlineOptions {
3
- /** Signal used to abort the deadline. */
4
- signal?: AbortSignal;
5
- }
6
- /**
7
- * Create a promise which will be rejected with {@linkcode DOMException} when
8
- * a given delay is exceeded.
9
- *
10
- * Note: Prefer to use {@linkcode AbortSignal.timeout} instead for the APIs
11
- * that accept {@linkcode AbortSignal}.
12
- *
13
- * @throws {DOMException & { name: "TimeoutError" }} If the provided duration
14
- * runs out before resolving.
15
- * @throws {DOMException & { name: "AbortError" }} If the optional signal is
16
- * aborted with the default `reason` before resolving or timing out.
17
- * @throws {AbortSignal["reason"]} If the optional signal is aborted with a
18
- * custom `reason` before resolving or timing out.
19
- * @typeParam T The type of the provided and returned promise.
20
- * @param p The promise to make rejectable.
21
- * @param ms Duration in milliseconds for when the promise should time out. If
22
- * greater than `Number.MAX_SAFE_INTEGER`, the deadline will never expire.
23
- * @param options Additional options.
24
- * @returns A promise that will reject if the provided duration runs out before resolving.
25
- *
26
- * @example Usage
27
- * ```ts ignore
28
- * import { deadline } from "@std/async/deadline";
29
- * import { delay } from "@std/async/delay";
30
- *
31
- * const delayedPromise = delay(1_000);
32
- * // Below throws `DOMException` after 10 ms
33
- * const result = await deadline(delayedPromise, 10);
34
- * ```
35
- */
36
- export declare function deadline<T>(p: Promise<T>, ms: number, options?: DeadlineOptions): Promise<T>;
37
- //# sourceMappingURL=deadline.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deadline.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/deadline.ts"],"names":[],"mappings":"AAKA,wCAAwC;AACxC,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,CAAC,CAAC,CAKZ"}