lampamazaza-new-internal-utils 0.24.3
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/LICENSE +21 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.js +18 -0
- package/dist/config.cjs +82 -0
- package/dist/config.d.cts +42 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.js +72 -0
- package/dist/errors/assert.cjs +11 -0
- package/dist/errors/assert.d.cts +11 -0
- package/dist/errors/assert.d.ts +11 -0
- package/dist/errors/assert.js +11 -0
- package/dist/errors/base.cjs +34 -0
- package/dist/errors/base.d.cts +21 -0
- package/dist/errors/base.d.ts +21 -0
- package/dist/errors/base.js +33 -0
- package/dist/errors/index.cjs +23 -0
- package/dist/errors/index.d.cts +11 -0
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/request.cjs +48 -0
- package/dist/errors/request.d.cts +61 -0
- package/dist/errors/request.d.ts +61 -0
- package/dist/errors/request.js +46 -0
- package/dist/errors/utils/isNetworkError.cjs +23 -0
- package/dist/errors/utils/isNetworkError.js +22 -0
- package/dist/errors/utils/toError.cjs +8 -0
- package/dist/errors/utils/toError.d.cts +4 -0
- package/dist/errors/utils/toError.d.ts +4 -0
- package/dist/errors/utils/toError.js +7 -0
- package/dist/index.cjs +125 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +30 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.ts +11 -0
- package/dist/nearClient.cjs +18 -0
- package/dist/nearClient.d.cts +8 -0
- package/dist/nearClient.d.ts +8 -0
- package/dist/nearClient.js +18 -0
- package/dist/poaBridge/constants/blockchains.cjs +57 -0
- package/dist/poaBridge/constants/blockchains.d.cts +86 -0
- package/dist/poaBridge/constants/blockchains.d.ts +86 -0
- package/dist/poaBridge/constants/blockchains.js +54 -0
- package/dist/poaBridge/errors/withdrawal.cjs +52 -0
- package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
- package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
- package/dist/poaBridge/errors/withdrawal.js +50 -0
- package/dist/poaBridge/getPendingDeposits.cjs +9 -0
- package/dist/poaBridge/getPendingDeposits.d.cts +12 -0
- package/dist/poaBridge/getPendingDeposits.d.ts +13 -0
- package/dist/poaBridge/getPendingDeposits.js +9 -0
- package/dist/poaBridge/index.cjs +23 -0
- package/dist/poaBridge/index.d.cts +11 -0
- package/dist/poaBridge/index.d.ts +11 -0
- package/dist/poaBridge/index.js +18 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
- package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
- package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
- package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +161 -0
- package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +161 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
- package/dist/services/blockchainBalanceService.cjs +40 -0
- package/dist/services/blockchainBalanceService.d.cts +21 -0
- package/dist/services/blockchainBalanceService.d.ts +21 -0
- package/dist/services/blockchainBalanceService.js +37 -0
- package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
- package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
- package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
- package/dist/solverRelay/errors/intentSettlement.js +20 -0
- package/dist/solverRelay/errors/quote.cjs +18 -0
- package/dist/solverRelay/errors/quote.d.cts +21 -0
- package/dist/solverRelay/errors/quote.d.ts +22 -0
- package/dist/solverRelay/errors/quote.js +18 -0
- package/dist/solverRelay/getQuote.cjs +49 -0
- package/dist/solverRelay/getQuote.d.cts +14 -0
- package/dist/solverRelay/getQuote.d.ts +14 -0
- package/dist/solverRelay/getQuote.js +49 -0
- package/dist/solverRelay/getStatus.cjs +26 -0
- package/dist/solverRelay/getStatus.d.cts +17 -0
- package/dist/solverRelay/getStatus.d.ts +18 -0
- package/dist/solverRelay/getStatus.js +26 -0
- package/dist/solverRelay/index.cjs +27 -0
- package/dist/solverRelay/index.d.cts +16 -0
- package/dist/solverRelay/index.d.ts +16 -0
- package/dist/solverRelay/index.js +22 -0
- package/dist/solverRelay/publishIntent.cjs +20 -0
- package/dist/solverRelay/publishIntent.d.cts +15 -0
- package/dist/solverRelay/publishIntent.d.ts +16 -0
- package/dist/solverRelay/publishIntent.js +20 -0
- package/dist/solverRelay/publishIntents.cjs +43 -0
- package/dist/solverRelay/publishIntents.d.cts +10 -0
- package/dist/solverRelay/publishIntents.d.ts +11 -0
- package/dist/solverRelay/publishIntents.js +42 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
- package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
- package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
- package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
- package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
- package/dist/solverRelay/solverRelayHttpClient/types.d.cts +109 -0
- package/dist/solverRelay/solverRelayHttpClient/types.d.ts +109 -0
- package/dist/solverRelay/utils/parseFailedPublishError.cjs +40 -0
- package/dist/solverRelay/utils/parseFailedPublishError.d.cts +25 -0
- package/dist/solverRelay/utils/parseFailedPublishError.d.ts +26 -0
- package/dist/solverRelay/utils/parseFailedPublishError.js +39 -0
- package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
- package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
- package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
- package/dist/solverRelay/utils/quoteWithLog.js +21 -0
- package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
- package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
- package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
- package/dist/solverRelay/waitForIntentSettlement.js +52 -0
- package/dist/types/authHandle.cjs +22 -0
- package/dist/types/authHandle.d.cts +25 -0
- package/dist/types/authHandle.d.ts +25 -0
- package/dist/types/authHandle.js +16 -0
- package/dist/types/base.d.cts +45 -0
- package/dist/types/base.d.ts +45 -0
- package/dist/types/intentsUserId.d.cts +10 -0
- package/dist/types/intentsUserId.d.ts +10 -0
- package/dist/types/walletMessage.cjs +11 -0
- package/dist/types/walletMessage.d.cts +106 -0
- package/dist/types/walletMessage.d.ts +106 -0
- package/dist/types/walletMessage.js +5 -0
- package/dist/utils/abortSignal.cjs +19 -0
- package/dist/utils/abortSignal.js +18 -0
- package/dist/utils/appFee.cjs +20 -0
- package/dist/utils/appFee.d.cts +9 -0
- package/dist/utils/appFee.d.ts +9 -0
- package/dist/utils/appFee.js +15 -0
- package/dist/utils/assert.cjs +9 -0
- package/dist/utils/assert.d.cts +7 -0
- package/dist/utils/assert.d.ts +7 -0
- package/dist/utils/assert.js +9 -0
- package/dist/utils/authIdentity.cjs +56 -0
- package/dist/utils/authIdentity.d.cts +34 -0
- package/dist/utils/authIdentity.d.ts +34 -0
- package/dist/utils/authIdentity.js +50 -0
- package/dist/utils/failover.cjs +22 -0
- package/dist/utils/failover.d.cts +16 -0
- package/dist/utils/failover.d.ts +16 -0
- package/dist/utils/failover.js +20 -0
- package/dist/utils/handleRPCResponse.cjs +30 -0
- package/dist/utils/handleRPCResponse.js +28 -0
- package/dist/utils/index.cjs +55 -0
- package/dist/utils/index.d.cts +13 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +50 -0
- package/dist/utils/messageFactory.cjs +137 -0
- package/dist/utils/messageFactory.d.cts +70 -0
- package/dist/utils/messageFactory.d.ts +70 -0
- package/dist/utils/messageFactory.js +132 -0
- package/dist/utils/multiPayload/webauthn.cjs +27 -0
- package/dist/utils/multiPayload/webauthn.js +26 -0
- package/dist/utils/near.cjs +58 -0
- package/dist/utils/near.d.cts +35 -0
- package/dist/utils/near.d.ts +35 -0
- package/dist/utils/near.js +53 -0
- package/dist/utils/poll.cjs +87 -0
- package/dist/utils/poll.d.cts +54 -0
- package/dist/utils/poll.d.ts +54 -0
- package/dist/utils/poll.js +85 -0
- package/dist/utils/prepareBroadcastRequest.cjs +98 -0
- package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
- package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
- package/dist/utils/prepareBroadcastRequest.js +90 -0
- package/dist/utils/promise/withTimeout.cjs +34 -0
- package/dist/utils/promise/withTimeout.d.cts +16 -0
- package/dist/utils/promise/withTimeout.d.ts +16 -0
- package/dist/utils/promise/withTimeout.js +34 -0
- package/dist/utils/request.cjs +100 -0
- package/dist/utils/request.d.cts +27 -0
- package/dist/utils/request.d.ts +27 -0
- package/dist/utils/request.js +99 -0
- package/dist/utils/requestShouldRetry.cjs +20 -0
- package/dist/utils/requestShouldRetry.js +20 -0
- package/dist/utils/retry.cjs +66 -0
- package/dist/utils/retry.d.cts +56 -0
- package/dist/utils/retry.d.ts +56 -0
- package/dist/utils/retry.js +64 -0
- package/dist/utils/serialize.cjs +82 -0
- package/dist/utils/serialize.d.cts +17 -0
- package/dist/utils/serialize.d.ts +17 -0
- package/dist/utils/serialize.js +81 -0
- package/dist/utils/stellarAddressToBytes.cjs +295 -0
- package/dist/utils/stellarAddressToBytes.js +294 -0
- package/dist/utils/token.cjs +8 -0
- package/dist/utils/token.js +7 -0
- package/dist/utils/tokenUtils.cjs +263 -0
- package/dist/utils/tokenUtils.d.cts +88 -0
- package/dist/utils/tokenUtils.d.ts +88 -0
- package/dist/utils/tokenUtils.js +238 -0
- package/dist/utils/tronAddressToHex.cjs +18 -0
- package/dist/utils/tronAddressToHex.js +17 -0
- package/dist/utils/uint8Array.cjs +15 -0
- package/dist/utils/uint8Array.d.cts +4 -0
- package/dist/utils/uint8Array.d.ts +4 -0
- package/dist/utils/uint8Array.js +14 -0
- package/dist/utils/webAuthn.cjs +91 -0
- package/dist/utils/webAuthn.js +89 -0
- package/package.json +56 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { HttpRequestError, TimeoutError } from "../errors/request.js";
|
|
2
|
+
import { isNetworkError } from "../errors/utils/isNetworkError.js";
|
|
3
|
+
import { toError } from "../errors/utils/toError.js";
|
|
4
|
+
import { mergeAbortSignals } from "./abortSignal.js";
|
|
5
|
+
import { withTimeout } from "./promise/withTimeout.js";
|
|
6
|
+
import { requestShouldRetry } from "./requestShouldRetry.js";
|
|
7
|
+
import { retry } from "@lifeomic/attempt";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/request.ts
|
|
10
|
+
async function request({ retryOptions = { maxAttempts: 1 }, logger, ...params }) {
|
|
11
|
+
const overallStartTime = performance.now();
|
|
12
|
+
let totalNetworkTime = 0;
|
|
13
|
+
let attemptCount = 0;
|
|
14
|
+
const response = await retry(async (ctx) => {
|
|
15
|
+
attemptCount = ctx.attemptNum + 1;
|
|
16
|
+
const attemptStartTime = performance.now();
|
|
17
|
+
logger?.debug("Sending HTTP request", {
|
|
18
|
+
url: params.url.toString(),
|
|
19
|
+
method: params.fetchOptions?.method || "GET",
|
|
20
|
+
body: JSON.stringify(params.body),
|
|
21
|
+
attempt: ctx.attemptNum
|
|
22
|
+
});
|
|
23
|
+
const response$1 = await request_(params);
|
|
24
|
+
const attemptDuration = performance.now() - attemptStartTime;
|
|
25
|
+
totalNetworkTime += attemptDuration;
|
|
26
|
+
logger?.debug("HTTP request attempt completed", {
|
|
27
|
+
attempt: ctx.attemptNum,
|
|
28
|
+
attemptDuration: Math.floor(attemptDuration),
|
|
29
|
+
statusCode: response$1.status,
|
|
30
|
+
success: response$1.ok,
|
|
31
|
+
responseSize: response$1.headers.get("content-length")
|
|
32
|
+
});
|
|
33
|
+
return response$1;
|
|
34
|
+
}, {
|
|
35
|
+
...retryOptions,
|
|
36
|
+
handleError: (err, context) => {
|
|
37
|
+
logger?.error("HTTP request attempt failed", {
|
|
38
|
+
attempt: context.attemptNum,
|
|
39
|
+
errorMessage: toError(err).message
|
|
40
|
+
});
|
|
41
|
+
if (!requestShouldRetry(err) || params.fetchOptions?.signal?.reason === err) context.abort();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const overallDuration = performance.now() - overallStartTime;
|
|
45
|
+
const retryOverhead = overallDuration - totalNetworkTime;
|
|
46
|
+
logger?.[attemptCount > 1 ? "info" : "debug"]("HTTP request completed", {
|
|
47
|
+
statusCode: response.status,
|
|
48
|
+
success: response.ok,
|
|
49
|
+
totalDuration: Math.floor(overallDuration),
|
|
50
|
+
networkTime: Math.floor(totalNetworkTime),
|
|
51
|
+
retryOverhead: Math.floor(retryOverhead),
|
|
52
|
+
attempts: attemptCount,
|
|
53
|
+
responseSize: response.headers.get("content-length")
|
|
54
|
+
});
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
async function request_({ url, body, timeout = 1e4, fetchOptions }) {
|
|
58
|
+
const { headers: customHeaders, method, signal: signal_ } = fetchOptions ?? {};
|
|
59
|
+
try {
|
|
60
|
+
const headers = new Headers(customHeaders);
|
|
61
|
+
headers.set("Content-Type", "application/json");
|
|
62
|
+
const response = await withTimeout(({ signal }) => {
|
|
63
|
+
return fetch(url, {
|
|
64
|
+
...fetchOptions,
|
|
65
|
+
method,
|
|
66
|
+
headers,
|
|
67
|
+
body: JSON.stringify(body),
|
|
68
|
+
signal: mergeAbortSignals([signal_, timeout > 0 ? signal : null].filter(Boolean))
|
|
69
|
+
});
|
|
70
|
+
}, {
|
|
71
|
+
errorInstance: new TimeoutError({
|
|
72
|
+
body,
|
|
73
|
+
url: url.toString()
|
|
74
|
+
}),
|
|
75
|
+
timeout,
|
|
76
|
+
signal: true
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) throw new HttpRequestError({
|
|
79
|
+
body,
|
|
80
|
+
details: response.statusText,
|
|
81
|
+
headers: response.headers,
|
|
82
|
+
status: response.status,
|
|
83
|
+
url: url.toString()
|
|
84
|
+
});
|
|
85
|
+
return response;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
if (err instanceof HttpRequestError) throw err;
|
|
88
|
+
if (err instanceof TimeoutError) throw err;
|
|
89
|
+
if (isNetworkError(err)) throw new HttpRequestError({
|
|
90
|
+
body,
|
|
91
|
+
cause: err,
|
|
92
|
+
url: url.toString()
|
|
93
|
+
});
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { request };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_request = require('../errors/request.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/requestShouldRetry.ts
|
|
4
|
+
function requestShouldRetry(error) {
|
|
5
|
+
if (error instanceof require_request.HttpRequestError && error.status != null) {
|
|
6
|
+
if (error.status === 403) return true;
|
|
7
|
+
if (error.status === 408) return true;
|
|
8
|
+
if (error.status === 413) return true;
|
|
9
|
+
if (error.status === 429) return true;
|
|
10
|
+
if (error.status === 500) return true;
|
|
11
|
+
if (error.status === 502) return true;
|
|
12
|
+
if (error.status === 503) return true;
|
|
13
|
+
if (error.status === 504) return true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.requestShouldRetry = requestShouldRetry;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HttpRequestError } from "../errors/request.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/requestShouldRetry.ts
|
|
4
|
+
function requestShouldRetry(error) {
|
|
5
|
+
if (error instanceof HttpRequestError && error.status != null) {
|
|
6
|
+
if (error.status === 403) return true;
|
|
7
|
+
if (error.status === 408) return true;
|
|
8
|
+
if (error.status === 413) return true;
|
|
9
|
+
if (error.status === 429) return true;
|
|
10
|
+
if (error.status === 500) return true;
|
|
11
|
+
if (error.status === 502) return true;
|
|
12
|
+
if (error.status === 503) return true;
|
|
13
|
+
if (error.status === 504) return true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { requestShouldRetry };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/retry.ts
|
|
3
|
+
const RETRY_CONFIGS = {
|
|
4
|
+
THIRTY_SECS_AGGRESSIVE: {
|
|
5
|
+
delay: 500,
|
|
6
|
+
minDelay: 500,
|
|
7
|
+
factor: 2,
|
|
8
|
+
maxAttempts: 6,
|
|
9
|
+
jitter: true
|
|
10
|
+
},
|
|
11
|
+
ONE_MIN_MODERATE: {
|
|
12
|
+
delay: 1e3,
|
|
13
|
+
minDelay: 1e3,
|
|
14
|
+
factor: 1.5,
|
|
15
|
+
maxAttempts: 8,
|
|
16
|
+
jitter: true
|
|
17
|
+
},
|
|
18
|
+
TWO_MINS_GRADUAL: {
|
|
19
|
+
delay: 500,
|
|
20
|
+
minDelay: 500,
|
|
21
|
+
factor: 1.5,
|
|
22
|
+
maxAttempts: 12,
|
|
23
|
+
jitter: true
|
|
24
|
+
},
|
|
25
|
+
FIVE_MINS_STEADY: {
|
|
26
|
+
delay: 2e3,
|
|
27
|
+
minDelay: 2e3,
|
|
28
|
+
factor: 1.4,
|
|
29
|
+
maxAttempts: 12,
|
|
30
|
+
jitter: true
|
|
31
|
+
},
|
|
32
|
+
THIRTY_MINS_PATIENT: {
|
|
33
|
+
delay: 5e3,
|
|
34
|
+
minDelay: 5e3,
|
|
35
|
+
factor: 1.3,
|
|
36
|
+
maxAttempts: 18,
|
|
37
|
+
jitter: true
|
|
38
|
+
},
|
|
39
|
+
TWO_HOURS_PERSISTENT: {
|
|
40
|
+
delay: 1e4,
|
|
41
|
+
minDelay: 1e4,
|
|
42
|
+
factor: 1.2,
|
|
43
|
+
maxAttempts: 27,
|
|
44
|
+
jitter: true
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Calculates how many attempts fit within a timeout budget.
|
|
49
|
+
*
|
|
50
|
+
* @returns number of attempts that fit within the timeout
|
|
51
|
+
*/
|
|
52
|
+
function calculateMaxAttempts(timeout, delay, factor) {
|
|
53
|
+
let totalDelay = 0;
|
|
54
|
+
let currentDelay = delay;
|
|
55
|
+
let attempts = 1;
|
|
56
|
+
while (totalDelay + currentDelay <= timeout) {
|
|
57
|
+
totalDelay += currentDelay;
|
|
58
|
+
attempts++;
|
|
59
|
+
currentDelay *= factor;
|
|
60
|
+
}
|
|
61
|
+
return Math.max(1, attempts);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.RETRY_CONFIGS = RETRY_CONFIGS;
|
|
66
|
+
exports.calculateMaxAttempts = calculateMaxAttempts;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AttemptOptions } from "@lifeomic/attempt";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/retry.d.ts
|
|
4
|
+
type RetryOptions = Partial<Pick<AttemptOptions<unknown>, "delay" | "initialDelay" | "minDelay" | "maxDelay" | "factor" | "maxAttempts" | "timeout" | "jitter" | "initialJitter">>;
|
|
5
|
+
declare const RETRY_CONFIGS: {
|
|
6
|
+
THIRTY_SECS_AGGRESSIVE: {
|
|
7
|
+
delay: number;
|
|
8
|
+
minDelay: number;
|
|
9
|
+
factor: number;
|
|
10
|
+
maxAttempts: number;
|
|
11
|
+
jitter: boolean;
|
|
12
|
+
};
|
|
13
|
+
ONE_MIN_MODERATE: {
|
|
14
|
+
delay: number;
|
|
15
|
+
minDelay: number;
|
|
16
|
+
factor: number;
|
|
17
|
+
maxAttempts: number;
|
|
18
|
+
jitter: boolean;
|
|
19
|
+
};
|
|
20
|
+
TWO_MINS_GRADUAL: {
|
|
21
|
+
delay: number;
|
|
22
|
+
minDelay: number;
|
|
23
|
+
factor: number;
|
|
24
|
+
maxAttempts: number;
|
|
25
|
+
jitter: boolean;
|
|
26
|
+
};
|
|
27
|
+
FIVE_MINS_STEADY: {
|
|
28
|
+
delay: number;
|
|
29
|
+
minDelay: number;
|
|
30
|
+
factor: number;
|
|
31
|
+
maxAttempts: number;
|
|
32
|
+
jitter: boolean;
|
|
33
|
+
};
|
|
34
|
+
THIRTY_MINS_PATIENT: {
|
|
35
|
+
delay: number;
|
|
36
|
+
minDelay: number;
|
|
37
|
+
factor: number;
|
|
38
|
+
maxAttempts: number;
|
|
39
|
+
jitter: boolean;
|
|
40
|
+
};
|
|
41
|
+
TWO_HOURS_PERSISTENT: {
|
|
42
|
+
delay: number;
|
|
43
|
+
minDelay: number;
|
|
44
|
+
factor: number;
|
|
45
|
+
maxAttempts: number;
|
|
46
|
+
jitter: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Calculates how many attempts fit within a timeout budget.
|
|
51
|
+
*
|
|
52
|
+
* @returns number of attempts that fit within the timeout
|
|
53
|
+
*/
|
|
54
|
+
declare function calculateMaxAttempts(timeout: number, delay: number, factor: number): number;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { RETRY_CONFIGS, RetryOptions, calculateMaxAttempts };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AttemptOptions } from "@lifeomic/attempt";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/retry.d.ts
|
|
4
|
+
type RetryOptions = Partial<Pick<AttemptOptions<unknown>, "delay" | "initialDelay" | "minDelay" | "maxDelay" | "factor" | "maxAttempts" | "timeout" | "jitter" | "initialJitter">>;
|
|
5
|
+
declare const RETRY_CONFIGS: {
|
|
6
|
+
THIRTY_SECS_AGGRESSIVE: {
|
|
7
|
+
delay: number;
|
|
8
|
+
minDelay: number;
|
|
9
|
+
factor: number;
|
|
10
|
+
maxAttempts: number;
|
|
11
|
+
jitter: boolean;
|
|
12
|
+
};
|
|
13
|
+
ONE_MIN_MODERATE: {
|
|
14
|
+
delay: number;
|
|
15
|
+
minDelay: number;
|
|
16
|
+
factor: number;
|
|
17
|
+
maxAttempts: number;
|
|
18
|
+
jitter: boolean;
|
|
19
|
+
};
|
|
20
|
+
TWO_MINS_GRADUAL: {
|
|
21
|
+
delay: number;
|
|
22
|
+
minDelay: number;
|
|
23
|
+
factor: number;
|
|
24
|
+
maxAttempts: number;
|
|
25
|
+
jitter: boolean;
|
|
26
|
+
};
|
|
27
|
+
FIVE_MINS_STEADY: {
|
|
28
|
+
delay: number;
|
|
29
|
+
minDelay: number;
|
|
30
|
+
factor: number;
|
|
31
|
+
maxAttempts: number;
|
|
32
|
+
jitter: boolean;
|
|
33
|
+
};
|
|
34
|
+
THIRTY_MINS_PATIENT: {
|
|
35
|
+
delay: number;
|
|
36
|
+
minDelay: number;
|
|
37
|
+
factor: number;
|
|
38
|
+
maxAttempts: number;
|
|
39
|
+
jitter: boolean;
|
|
40
|
+
};
|
|
41
|
+
TWO_HOURS_PERSISTENT: {
|
|
42
|
+
delay: number;
|
|
43
|
+
minDelay: number;
|
|
44
|
+
factor: number;
|
|
45
|
+
maxAttempts: number;
|
|
46
|
+
jitter: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Calculates how many attempts fit within a timeout budget.
|
|
51
|
+
*
|
|
52
|
+
* @returns number of attempts that fit within the timeout
|
|
53
|
+
*/
|
|
54
|
+
declare function calculateMaxAttempts(timeout: number, delay: number, factor: number): number;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { RETRY_CONFIGS, RetryOptions, calculateMaxAttempts };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/utils/retry.ts
|
|
2
|
+
const RETRY_CONFIGS = {
|
|
3
|
+
THIRTY_SECS_AGGRESSIVE: {
|
|
4
|
+
delay: 500,
|
|
5
|
+
minDelay: 500,
|
|
6
|
+
factor: 2,
|
|
7
|
+
maxAttempts: 6,
|
|
8
|
+
jitter: true
|
|
9
|
+
},
|
|
10
|
+
ONE_MIN_MODERATE: {
|
|
11
|
+
delay: 1e3,
|
|
12
|
+
minDelay: 1e3,
|
|
13
|
+
factor: 1.5,
|
|
14
|
+
maxAttempts: 8,
|
|
15
|
+
jitter: true
|
|
16
|
+
},
|
|
17
|
+
TWO_MINS_GRADUAL: {
|
|
18
|
+
delay: 500,
|
|
19
|
+
minDelay: 500,
|
|
20
|
+
factor: 1.5,
|
|
21
|
+
maxAttempts: 12,
|
|
22
|
+
jitter: true
|
|
23
|
+
},
|
|
24
|
+
FIVE_MINS_STEADY: {
|
|
25
|
+
delay: 2e3,
|
|
26
|
+
minDelay: 2e3,
|
|
27
|
+
factor: 1.4,
|
|
28
|
+
maxAttempts: 12,
|
|
29
|
+
jitter: true
|
|
30
|
+
},
|
|
31
|
+
THIRTY_MINS_PATIENT: {
|
|
32
|
+
delay: 5e3,
|
|
33
|
+
minDelay: 5e3,
|
|
34
|
+
factor: 1.3,
|
|
35
|
+
maxAttempts: 18,
|
|
36
|
+
jitter: true
|
|
37
|
+
},
|
|
38
|
+
TWO_HOURS_PERSISTENT: {
|
|
39
|
+
delay: 1e4,
|
|
40
|
+
minDelay: 1e4,
|
|
41
|
+
factor: 1.2,
|
|
42
|
+
maxAttempts: 27,
|
|
43
|
+
jitter: true
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Calculates how many attempts fit within a timeout budget.
|
|
48
|
+
*
|
|
49
|
+
* @returns number of attempts that fit within the timeout
|
|
50
|
+
*/
|
|
51
|
+
function calculateMaxAttempts(timeout, delay, factor) {
|
|
52
|
+
let totalDelay = 0;
|
|
53
|
+
let currentDelay = delay;
|
|
54
|
+
let attempts = 1;
|
|
55
|
+
while (totalDelay + currentDelay <= timeout) {
|
|
56
|
+
totalDelay += currentDelay;
|
|
57
|
+
attempts++;
|
|
58
|
+
currentDelay *= factor;
|
|
59
|
+
}
|
|
60
|
+
return Math.max(1, attempts);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { RETRY_CONFIGS, calculateMaxAttempts };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/serialize.ts
|
|
3
|
+
/**
|
|
4
|
+
* Get the reference key for the circular value
|
|
5
|
+
*
|
|
6
|
+
* @param keys the keys to build the reference key from
|
|
7
|
+
* @param cutoff the maximum number of keys to include
|
|
8
|
+
* @returns the reference key
|
|
9
|
+
*/
|
|
10
|
+
function getReferenceKey(keys, cutoff) {
|
|
11
|
+
return keys.slice(0, cutoff).join(".") || ".";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Faster `Array.prototype.indexOf` implementation build for slicing / splicing
|
|
15
|
+
*
|
|
16
|
+
* @param array the array to match the value in
|
|
17
|
+
* @param value the value to match
|
|
18
|
+
* @returns the matching index, or -1
|
|
19
|
+
*/
|
|
20
|
+
function getCutoff(array, value) {
|
|
21
|
+
const { length } = array;
|
|
22
|
+
for (let index = 0; index < length; ++index) if (array[index] === value) return index + 1;
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a replacer method that handles circular values
|
|
27
|
+
*
|
|
28
|
+
* @param [replacer] a custom replacer to use for non-circular values
|
|
29
|
+
* @param [circularReplacer] a custom replacer to use for circular methods
|
|
30
|
+
* @returns the value to stringify
|
|
31
|
+
*/
|
|
32
|
+
function createReplacer(replacer, circularReplacer) {
|
|
33
|
+
const hasReplacer = typeof replacer === "function";
|
|
34
|
+
const hasCircularReplacer = typeof circularReplacer === "function";
|
|
35
|
+
const cache = [];
|
|
36
|
+
const keys = [];
|
|
37
|
+
return function replace(key, value) {
|
|
38
|
+
if (typeof value === "object") if (cache.length) {
|
|
39
|
+
const thisCutoff = getCutoff(cache, this);
|
|
40
|
+
if (thisCutoff === 0) cache[cache.length] = this;
|
|
41
|
+
else {
|
|
42
|
+
cache.splice(thisCutoff);
|
|
43
|
+
keys.splice(thisCutoff);
|
|
44
|
+
}
|
|
45
|
+
keys[keys.length] = key;
|
|
46
|
+
const valueCutoff = getCutoff(cache, value);
|
|
47
|
+
if (valueCutoff !== 0) return hasCircularReplacer ? circularReplacer.call(this, key, value, getReferenceKey(keys, valueCutoff)) : `[ref=${getReferenceKey(keys, valueCutoff)}]`;
|
|
48
|
+
} else {
|
|
49
|
+
cache[0] = value;
|
|
50
|
+
keys[0] = key;
|
|
51
|
+
}
|
|
52
|
+
return hasReplacer ? replacer.call(this, key, value) : value;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Stringifier that handles circular values
|
|
57
|
+
*
|
|
58
|
+
* Forked from https://github.com/planttheidea/fast-stringify
|
|
59
|
+
*
|
|
60
|
+
* @param value to stringify
|
|
61
|
+
* @param [replacer] a custom replacer function for handling standard values
|
|
62
|
+
* @param [indent] the number of spaces to indent the output by
|
|
63
|
+
* @param [circularReplacer] a custom replacer function for handling circular values
|
|
64
|
+
* @returns the stringified output
|
|
65
|
+
*/
|
|
66
|
+
function serialize(value, replacer, indent, circularReplacer) {
|
|
67
|
+
return JSON.stringify(value, createReplacer((key, value_) => {
|
|
68
|
+
let value$1 = value_;
|
|
69
|
+
if (typeof value$1 === "bigint") value$1 = {
|
|
70
|
+
__type: "bigint",
|
|
71
|
+
value: value_.toString()
|
|
72
|
+
};
|
|
73
|
+
if (value$1 instanceof Map) value$1 = {
|
|
74
|
+
__type: "Map",
|
|
75
|
+
value: Array.from(value_.entries())
|
|
76
|
+
};
|
|
77
|
+
return replacer?.(key, value$1) ?? value$1;
|
|
78
|
+
}, circularReplacer), indent ?? void 0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.serialize = serialize;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/utils/serialize.d.ts
|
|
2
|
+
type StandardReplacer = (key: string, value: any) => any;
|
|
3
|
+
type CircularReplacer = (key: string, value: any, referenceKey: string) => any;
|
|
4
|
+
/**
|
|
5
|
+
* Stringifier that handles circular values
|
|
6
|
+
*
|
|
7
|
+
* Forked from https://github.com/planttheidea/fast-stringify
|
|
8
|
+
*
|
|
9
|
+
* @param value to stringify
|
|
10
|
+
* @param [replacer] a custom replacer function for handling standard values
|
|
11
|
+
* @param [indent] the number of spaces to indent the output by
|
|
12
|
+
* @param [circularReplacer] a custom replacer function for handling circular values
|
|
13
|
+
* @returns the stringified output
|
|
14
|
+
*/
|
|
15
|
+
declare function serialize(value: any, replacer?: StandardReplacer | null | undefined, indent?: number | null | undefined, circularReplacer?: CircularReplacer | null | undefined): string;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { serialize };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/utils/serialize.d.ts
|
|
2
|
+
type StandardReplacer = (key: string, value: any) => any;
|
|
3
|
+
type CircularReplacer = (key: string, value: any, referenceKey: string) => any;
|
|
4
|
+
/**
|
|
5
|
+
* Stringifier that handles circular values
|
|
6
|
+
*
|
|
7
|
+
* Forked from https://github.com/planttheidea/fast-stringify
|
|
8
|
+
*
|
|
9
|
+
* @param value to stringify
|
|
10
|
+
* @param [replacer] a custom replacer function for handling standard values
|
|
11
|
+
* @param [indent] the number of spaces to indent the output by
|
|
12
|
+
* @param [circularReplacer] a custom replacer function for handling circular values
|
|
13
|
+
* @returns the stringified output
|
|
14
|
+
*/
|
|
15
|
+
declare function serialize(value: any, replacer?: StandardReplacer | null | undefined, indent?: number | null | undefined, circularReplacer?: CircularReplacer | null | undefined): string;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { serialize };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//#region src/utils/serialize.ts
|
|
2
|
+
/**
|
|
3
|
+
* Get the reference key for the circular value
|
|
4
|
+
*
|
|
5
|
+
* @param keys the keys to build the reference key from
|
|
6
|
+
* @param cutoff the maximum number of keys to include
|
|
7
|
+
* @returns the reference key
|
|
8
|
+
*/
|
|
9
|
+
function getReferenceKey(keys, cutoff) {
|
|
10
|
+
return keys.slice(0, cutoff).join(".") || ".";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Faster `Array.prototype.indexOf` implementation build for slicing / splicing
|
|
14
|
+
*
|
|
15
|
+
* @param array the array to match the value in
|
|
16
|
+
* @param value the value to match
|
|
17
|
+
* @returns the matching index, or -1
|
|
18
|
+
*/
|
|
19
|
+
function getCutoff(array, value) {
|
|
20
|
+
const { length } = array;
|
|
21
|
+
for (let index = 0; index < length; ++index) if (array[index] === value) return index + 1;
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a replacer method that handles circular values
|
|
26
|
+
*
|
|
27
|
+
* @param [replacer] a custom replacer to use for non-circular values
|
|
28
|
+
* @param [circularReplacer] a custom replacer to use for circular methods
|
|
29
|
+
* @returns the value to stringify
|
|
30
|
+
*/
|
|
31
|
+
function createReplacer(replacer, circularReplacer) {
|
|
32
|
+
const hasReplacer = typeof replacer === "function";
|
|
33
|
+
const hasCircularReplacer = typeof circularReplacer === "function";
|
|
34
|
+
const cache = [];
|
|
35
|
+
const keys = [];
|
|
36
|
+
return function replace(key, value) {
|
|
37
|
+
if (typeof value === "object") if (cache.length) {
|
|
38
|
+
const thisCutoff = getCutoff(cache, this);
|
|
39
|
+
if (thisCutoff === 0) cache[cache.length] = this;
|
|
40
|
+
else {
|
|
41
|
+
cache.splice(thisCutoff);
|
|
42
|
+
keys.splice(thisCutoff);
|
|
43
|
+
}
|
|
44
|
+
keys[keys.length] = key;
|
|
45
|
+
const valueCutoff = getCutoff(cache, value);
|
|
46
|
+
if (valueCutoff !== 0) return hasCircularReplacer ? circularReplacer.call(this, key, value, getReferenceKey(keys, valueCutoff)) : `[ref=${getReferenceKey(keys, valueCutoff)}]`;
|
|
47
|
+
} else {
|
|
48
|
+
cache[0] = value;
|
|
49
|
+
keys[0] = key;
|
|
50
|
+
}
|
|
51
|
+
return hasReplacer ? replacer.call(this, key, value) : value;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Stringifier that handles circular values
|
|
56
|
+
*
|
|
57
|
+
* Forked from https://github.com/planttheidea/fast-stringify
|
|
58
|
+
*
|
|
59
|
+
* @param value to stringify
|
|
60
|
+
* @param [replacer] a custom replacer function for handling standard values
|
|
61
|
+
* @param [indent] the number of spaces to indent the output by
|
|
62
|
+
* @param [circularReplacer] a custom replacer function for handling circular values
|
|
63
|
+
* @returns the stringified output
|
|
64
|
+
*/
|
|
65
|
+
function serialize(value, replacer, indent, circularReplacer) {
|
|
66
|
+
return JSON.stringify(value, createReplacer((key, value_) => {
|
|
67
|
+
let value$1 = value_;
|
|
68
|
+
if (typeof value$1 === "bigint") value$1 = {
|
|
69
|
+
__type: "bigint",
|
|
70
|
+
value: value_.toString()
|
|
71
|
+
};
|
|
72
|
+
if (value$1 instanceof Map) value$1 = {
|
|
73
|
+
__type: "Map",
|
|
74
|
+
value: Array.from(value_.entries())
|
|
75
|
+
};
|
|
76
|
+
return replacer?.(key, value$1) ?? value$1;
|
|
77
|
+
}, circularReplacer), indent ?? void 0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { serialize };
|