viem 2.48.11 → 2.49.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/CHANGELOG.md +21 -0
- package/_cjs/actions/public/call.js +26 -6
- package/_cjs/actions/public/call.js.map +1 -1
- package/_cjs/clients/transports/http.js +19 -2
- package/_cjs/clients/transports/http.js.map +1 -1
- package/_cjs/errors/utils.js +17 -0
- package/_cjs/errors/utils.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/errors/version.js.map +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/actions/wallet.js.map +1 -1
- package/_cjs/utils/buildRequest.js +12 -2
- package/_cjs/utils/buildRequest.js.map +1 -1
- package/_cjs/utils/ccip.js +17 -4
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/promise/withRetry.js +23 -3
- package/_cjs/utils/promise/withRetry.js.map +1 -1
- package/_cjs/utils/promise/withTimeout.js +5 -2
- package/_cjs/utils/promise/withTimeout.js.map +1 -1
- package/_cjs/utils/rpc/http.js +5 -0
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/wait.js +19 -2
- package/_cjs/utils/wait.js.map +1 -1
- package/_esm/actions/public/call.js +26 -6
- package/_esm/actions/public/call.js.map +1 -1
- package/_esm/clients/transports/http.js +19 -2
- package/_esm/clients/transports/http.js.map +1 -1
- package/_esm/errors/utils.js +15 -0
- package/_esm/errors/utils.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/errors/version.js.map +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/actions/wallet.js +1 -1
- package/_esm/tempo/actions/wallet.js.map +1 -1
- package/_esm/utils/buildRequest.js +12 -2
- package/_esm/utils/buildRequest.js.map +1 -1
- package/_esm/utils/ccip.js +17 -4
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/promise/withRetry.js +23 -3
- package/_esm/utils/promise/withRetry.js.map +1 -1
- package/_esm/utils/promise/withTimeout.js +5 -2
- package/_esm/utils/promise/withTimeout.js.map +1 -1
- package/_esm/utils/rpc/http.js +5 -0
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/wait.js +19 -2
- package/_esm/utils/wait.js.map +1 -1
- package/_types/actions/public/call.d.ts +4 -1
- package/_types/actions/public/call.d.ts.map +1 -1
- package/_types/clients/transports/http.d.ts.map +1 -1
- package/_types/errors/utils.d.ts +3 -0
- package/_types/errors/utils.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/errors/version.d.ts.map +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/actions/wallet.d.ts +15 -5
- package/_types/tempo/actions/wallet.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +2 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/utils/buildRequest.d.ts +5 -3
- package/_types/utils/buildRequest.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +5 -3
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/promise/withRetry.d.ts +3 -2
- package/_types/utils/promise/withRetry.d.ts.map +1 -1
- package/_types/utils/promise/withTimeout.d.ts +1 -1
- package/_types/utils/promise/withTimeout.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/wait.d.ts +3 -1
- package/_types/utils/wait.d.ts.map +1 -1
- package/actions/public/call.ts +59 -23
- package/clients/transports/http.ts +18 -2
- package/errors/utils.ts +19 -0
- package/errors/version.ts +1 -1
- package/index.ts +1 -0
- package/package.json +1 -1
- package/tempo/actions/wallet.ts +15 -5
- package/types/eip1193.ts +2 -0
- package/utils/buildRequest.ts +22 -6
- package/utils/ccip.ts +22 -4
- package/utils/promise/withRetry.ts +29 -2
- package/utils/promise/withTimeout.ts +6 -3
- package/utils/rpc/http.ts +7 -1
- package/utils/wait.ts +24 -2
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type ErrorType,
|
|
3
|
+
getAbortError,
|
|
4
|
+
isAbortError,
|
|
5
|
+
} from '../../errors/utils.js'
|
|
2
6
|
import { wait } from '../wait.js'
|
|
3
7
|
|
|
4
8
|
export type WithRetryParameters = {
|
|
@@ -19,6 +23,8 @@ export type WithRetryParameters = {
|
|
|
19
23
|
error: Error
|
|
20
24
|
}) => Promise<boolean> | boolean)
|
|
21
25
|
| undefined
|
|
26
|
+
// AbortSignal to cancel retries.
|
|
27
|
+
signal?: AbortSignal | undefined
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export type WithRetryErrorType = ErrorType
|
|
@@ -29,14 +35,27 @@ export function withRetry<data>(
|
|
|
29
35
|
delay: delay_ = 100,
|
|
30
36
|
retryCount = 2,
|
|
31
37
|
shouldRetry = () => true,
|
|
38
|
+
signal,
|
|
32
39
|
}: WithRetryParameters = {},
|
|
33
40
|
) {
|
|
34
41
|
return new Promise<data>((resolve, reject) => {
|
|
35
42
|
const attemptRetry = async ({ count = 0 } = {}) => {
|
|
43
|
+
if (signal?.aborted) {
|
|
44
|
+
reject(getAbortError(signal))
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
const retry = async ({ error }: { error: Error }) => {
|
|
37
49
|
const delay =
|
|
38
50
|
typeof delay_ === 'function' ? delay_({ count, error }) : delay_
|
|
39
|
-
if (delay)
|
|
51
|
+
if (delay) {
|
|
52
|
+
try {
|
|
53
|
+
await wait(delay, { signal })
|
|
54
|
+
} catch (err) {
|
|
55
|
+
reject(err)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
}
|
|
40
59
|
attemptRetry({ count: count + 1 })
|
|
41
60
|
}
|
|
42
61
|
|
|
@@ -44,6 +63,14 @@ export function withRetry<data>(
|
|
|
44
63
|
const data = await fn()
|
|
45
64
|
resolve(data)
|
|
46
65
|
} catch (err) {
|
|
66
|
+
if (signal?.aborted) {
|
|
67
|
+
reject(getAbortError(signal))
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
if (isAbortError(err)) {
|
|
71
|
+
reject(err)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
47
74
|
if (
|
|
48
75
|
count < retryCount &&
|
|
49
76
|
(await shouldRetry({ count, error: err as Error }))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ErrorType, isAbortError } from '../../errors/utils.js'
|
|
2
2
|
|
|
3
3
|
export type WithTimeoutErrorType = ErrorType
|
|
4
4
|
|
|
@@ -24,8 +24,8 @@ export function withTimeout<data>(
|
|
|
24
24
|
return new Promise((resolve, reject) => {
|
|
25
25
|
;(async () => {
|
|
26
26
|
let timeoutId!: NodeJS.Timeout
|
|
27
|
+
const controller = new AbortController()
|
|
27
28
|
try {
|
|
28
|
-
const controller = new AbortController()
|
|
29
29
|
if (timeout > 0) {
|
|
30
30
|
timeoutId = setTimeout(() => {
|
|
31
31
|
if (signal) {
|
|
@@ -37,7 +37,10 @@ export function withTimeout<data>(
|
|
|
37
37
|
}
|
|
38
38
|
resolve(await fn({ signal: controller?.signal || null }))
|
|
39
39
|
} catch (err) {
|
|
40
|
-
if (
|
|
40
|
+
if (controller?.signal.aborted && isAbortError(err)) {
|
|
41
|
+
reject(errorInstance)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
41
44
|
reject(err)
|
|
42
45
|
} finally {
|
|
43
46
|
clearTimeout(timeoutId)
|
package/utils/rpc/http.ts
CHANGED
|
@@ -4,7 +4,11 @@ import {
|
|
|
4
4
|
TimeoutError,
|
|
5
5
|
type TimeoutErrorType,
|
|
6
6
|
} from '../../errors/request.js'
|
|
7
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
type ErrorType,
|
|
9
|
+
getAbortError,
|
|
10
|
+
isAbortError,
|
|
11
|
+
} from '../../errors/utils.js'
|
|
8
12
|
import type { RpcRequest, RpcResponse } from '../../types/rpc.js'
|
|
9
13
|
import type { MaybePromise } from '../../types/utils.js'
|
|
10
14
|
import {
|
|
@@ -174,6 +178,8 @@ export function getHttpRpcClient(
|
|
|
174
178
|
|
|
175
179
|
return data
|
|
176
180
|
} catch (err) {
|
|
181
|
+
if (signal_?.aborted) throw getAbortError(signal_)
|
|
182
|
+
if (isAbortError(err)) throw err
|
|
177
183
|
if (err instanceof HttpRequestError) throw err
|
|
178
184
|
if (err instanceof TimeoutError) throw err
|
|
179
185
|
throw new HttpRequestError({
|
package/utils/wait.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { getAbortError } from '../errors/utils.js'
|
|
2
|
+
|
|
3
|
+
export async function wait(
|
|
4
|
+
time: number,
|
|
5
|
+
{ signal }: { signal?: AbortSignal | undefined } = {},
|
|
6
|
+
) {
|
|
7
|
+
return new Promise<void>((resolve, reject) => {
|
|
8
|
+
if (signal?.aborted) {
|
|
9
|
+
reject(getAbortError(signal))
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const cleanup = () => signal?.removeEventListener('abort', onAbort)
|
|
14
|
+
const timeout = setTimeout(() => {
|
|
15
|
+
cleanup()
|
|
16
|
+
resolve()
|
|
17
|
+
}, time)
|
|
18
|
+
const onAbort = () => {
|
|
19
|
+
clearTimeout(timeout)
|
|
20
|
+
cleanup()
|
|
21
|
+
reject(getAbortError(signal))
|
|
22
|
+
}
|
|
23
|
+
signal?.addEventListener('abort', onAbort, { once: true })
|
|
24
|
+
})
|
|
3
25
|
}
|