@metamask-previews/controller-utils 11.4.5-preview-183f0b5a → 11.4.5-preview-9df90b5
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 +2 -1
- package/dist/create-service-policy.cjs +13 -3
- package/dist/create-service-policy.cjs.map +1 -1
- package/dist/create-service-policy.d.cts +14 -2
- package/dist/create-service-policy.d.cts.map +1 -1
- package/dist/create-service-policy.d.mts +14 -2
- package/dist/create-service-policy.d.mts.map +1 -1
- package/dist/create-service-policy.mjs +13 -3
- package/dist/create-service-policy.mjs.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
9
9
|
|
10
10
|
### Added
|
11
11
|
|
12
|
-
- Add `createServicePolicy` function to assist with reducing boilerplate for service classes ([#5154](https://github.com/MetaMask/core/pull/5154), [#5143](https://github.com/MetaMask/core/pull/5143))
|
12
|
+
- Add `createServicePolicy` function to assist with reducing boilerplate for service classes ([#5154](https://github.com/MetaMask/core/pull/5154), [#5143](https://github.com/MetaMask/core/pull/5143), [#5149](https://github.com/MetaMask/core/pull/5149))
|
13
|
+
- Also add `DEFAULT_CIRCUIT_BREAK_DURATION`, `DEFAULT_DEGRADED_THRESHOLD`, `DEFAULT_MAX_CONSECUTIVE_FAILURES`, and `DEFAULT_MAX_RETRIES` constants and `IServicePolicy` type
|
13
14
|
|
14
15
|
## [11.4.5]
|
15
16
|
|
@@ -38,6 +38,12 @@ exports.DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
38
38
|
* there for more.
|
39
39
|
*
|
40
40
|
* @param options - The options to this function.
|
41
|
+
* @param options.maxRetries - The maximum number of times that a failing
|
42
|
+
* service should be re-invoked before giving up. Defaults to 3.
|
43
|
+
* @param options.retryFilterPolicy - The policy used to control when the
|
44
|
+
* service should be retried based on either the result of the servce or an
|
45
|
+
* error that it throws. For instance, you could use this to retry only certain
|
46
|
+
* errors. See `handleWhen` and friends from Cockatiel for more.
|
41
47
|
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
42
48
|
* service is allowed to fail before pausing further retries. Defaults to 12.
|
43
49
|
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
@@ -62,6 +68,10 @@ exports.DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
62
68
|
* class Service {
|
63
69
|
* constructor() {
|
64
70
|
* this.#policy = createServicePolicy({
|
71
|
+
* maxRetries: 3,
|
72
|
+
* retryFilterPolicy: handleWhen((error) => {
|
73
|
+
* return error.message.includes('oops');
|
74
|
+
* }),
|
65
75
|
* maxConsecutiveFailures: 3,
|
66
76
|
* circuitBreakDuration: 5000,
|
67
77
|
* degradedThreshold: 2000,
|
@@ -83,17 +93,17 @@ exports.DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
83
93
|
* }
|
84
94
|
* ```
|
85
95
|
*/
|
86
|
-
function createServicePolicy({ maxConsecutiveFailures = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = exports.DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = exports.DEFAULT_DEGRADED_THRESHOLD, onBreak = () => {
|
96
|
+
function createServicePolicy({ maxRetries = exports.DEFAULT_MAX_RETRIES, retryFilterPolicy = cockatiel_1.handleAll, maxConsecutiveFailures = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = exports.DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = exports.DEFAULT_DEGRADED_THRESHOLD, onBreak = () => {
|
87
97
|
// do nothing
|
88
98
|
}, onDegraded = () => {
|
89
99
|
// do nothing
|
90
100
|
}, onRetry = () => {
|
91
101
|
// do nothing
|
92
102
|
}, } = {}) {
|
93
|
-
const retryPolicy = (0, cockatiel_1.retry)(
|
103
|
+
const retryPolicy = (0, cockatiel_1.retry)(retryFilterPolicy, {
|
94
104
|
// Note that although the option here is called "max attempts", it's really
|
95
105
|
// maximum number of *retries* (attempts past the initial attempt).
|
96
|
-
maxAttempts:
|
106
|
+
maxAttempts: maxRetries,
|
97
107
|
// Retries of the service will be executed following ever increasing delays,
|
98
108
|
// determined by a backoff formula.
|
99
109
|
backoff: new cockatiel_1.ExponentialBackoff(),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAQmB;AAKnB;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACU,QAAA,gCAAgC,GAAG,CAAC,CAAC,GAAG,2BAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACU,QAAA,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACU,QAAA,0BAA0B,GAAG,IAAK,CAAC;AAEhD
|
1
|
+
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAQmB;AAKnB;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACU,QAAA,gCAAgC,GAAG,CAAC,CAAC,GAAG,2BAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACU,QAAA,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACU,QAAA,0BAA0B,GAAG,IAAK,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,SAAgB,mBAAmB,CAAC,EAClC,UAAU,GAAG,2BAAmB,EAChC,iBAAiB,GAAG,qBAAS,EAC7B,sBAAsB,GAAG,wCAAgC,EACzD,oBAAoB,GAAG,sCAA8B,EACrD,iBAAiB,GAAG,kCAA0B,EAC9C,OAAO,GAAG,GAAG,EAAE;IACb,aAAa;AACf,CAAC,EACD,UAAU,GAAG,GAAG,EAAE;IAChB,aAAa;AACf,CAAC,EACD,OAAO,GAAG,GAAG,EAAE;IACb,aAAa;AACf,CAAC,MAUC,EAAE;IACJ,MAAM,WAAW,GAAG,IAAA,iBAAK,EAAC,iBAAiB,EAAE;QAC3C,2EAA2E;QAC3E,mEAAmE;QACnE,WAAW,EAAE,UAAU;QACvB,4EAA4E;QAC5E,mCAAmC;QACnC,OAAO,EAAE,IAAI,8BAAkB,EAAE;KAClC,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,IAAA,0BAAc,EAAC,qBAAS,EAAE;QACrD,uEAAuE;QACvE,oEAAoE;QACpE,wEAAwE;QACxE,4EAA4E;QAC5E,qEAAqE;QACrE,qDAAqD;QACrD,aAAa,EAAE,oBAAoB;QACnC,OAAO,EAAE,IAAI,8BAAkB,CAAC,sBAAsB,CAAC;KACxD,CAAC,CAAC;IAEH,2EAA2E;IAC3E,2EAA2E;IAC3E,sDAAsD;IACtD,6EAA6E;IAC7E,gBAAgB;IAChB,8EAA8E;IAC9E,8EAA8E;IAC9E,6BAA6B;IAC7B,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtC,uEAAuE;IACvE,+BAA+B;IAC/B,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7B,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE;QACxB,IAAI,oBAAoB,CAAC,KAAK,KAAK,wBAAY,CAAC,MAAM,EAAE;YACtD,uEAAuE;YACvE,uEAAuE;YACvE,qEAAqE;YACrE,UAAU,EAAE,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IACH,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;QACrC,IACE,oBAAoB,CAAC,KAAK,KAAK,wBAAY,CAAC,MAAM;YAClD,QAAQ,GAAG,iBAAiB,EAC5B;YACA,wEAAwE;YACxE,kEAAkE;YAClE,uBAAuB;YACvB,UAAU,EAAE,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IAEH,4EAA4E;IAC5E,eAAe;IACf,OAAO,IAAA,gBAAI,EAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;AACjD,CAAC;AAlFD,kDAkFC","sourcesContent":["import {\n circuitBreaker,\n ConsecutiveBreaker,\n ExponentialBackoff,\n handleAll,\n retry,\n wrap,\n CircuitState,\n} from 'cockatiel';\nimport type { IPolicy, Policy } from 'cockatiel';\n\nexport type { IPolicy as IServicePolicy };\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function.\n * @param options.maxRetries - The maximum number of times that a failing\n * service should be re-invoked before giving up. Defaults to 3.\n * @param options.retryFilterPolicy - The policy used to control when the\n * service should be retried based on either the result of the servce or an\n * error that it throws. For instance, you could use this to retry only certain\n * errors. See `handleWhen` and friends from Cockatiel for more.\n * @param options.maxConsecutiveFailures - The maximum number of times that the\n * service is allowed to fail before pausing further retries. Defaults to 12.\n * @param options.circuitBreakDuration - The length of time (in milliseconds) to\n * pause retries of the action after the number of failures reaches\n * `maxConsecutiveFailures`.\n * @param options.degradedThreshold - The length of time (in milliseconds) that\n * governs when the service is regarded as degraded (affecting when `onDegraded`\n * is called). Defaults to 5 seconds.\n * @param options.onBreak - A function which is called when the service fails\n * too many times in a row (specifically, more than `maxConsecutiveFailures`).\n * @param options.onDegraded - A function which is called when the service\n * succeeds before `maxConsecutiveFailures` is reached, but takes more time than\n * the `degradedThreshold` to run.\n * @param options.onRetry - A function which will be called the moment the\n * policy kicks off a timer to re-run the function passed to the policy. This is\n * primarily useful in tests where we are mocking timers.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy({\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n onBreak = () => {\n // do nothing\n },\n onDegraded = () => {\n // do nothing\n },\n onRetry = () => {\n // do nothing\n },\n}: {\n maxRetries?: number;\n retryFilterPolicy?: Policy;\n maxConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n degradedThreshold?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n onRetry?: () => void;\n} = {}): IPolicy {\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff: new ExponentialBackoff(),\n });\n\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maxConsecutiveFailures),\n });\n\n // The `onBreak` callback will be called if the service consistently throws\n // for as many times as exceeds the maximum consecutive number of failures.\n // Combined with the retry policy, this can happen if:\n // - `maxConsecutiveFailures` < the default max retries (3) and the policy is\n // executed once\n // - `maxConsecutiveFailures` >= the default max retries (3) but the policy is\n // executed multiple times, enough for the total number of retries to exceed\n // `maxConsecutiveFailures`\n circuitBreakerPolicy.onBreak(onBreak);\n\n // The `onRetryPolicy` callback will be called each time the service is\n // invoked (including retries).\n retryPolicy.onRetry(onRetry);\n\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n // The `onDegraded` callback will be called if the number of retries is\n // exceeded and the maximum number of consecutive failures has not been\n // reached yet (whether the policy is called once or multiple times).\n onDegraded();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n // The `onDegraded` callback will also be called if the service does not\n // throw, but the time it takes for the service to run exceeds the\n // `degradedThreshold`.\n onDegraded();\n }\n });\n\n // The retry policy really retries the circuit breaker policy, which invokes\n // the service.\n return wrap(retryPolicy, circuitBreakerPolicy);\n}\n"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { IPolicy } from "cockatiel";
|
1
|
+
import type { IPolicy, Policy } from "cockatiel";
|
2
2
|
export type { IPolicy as IServicePolicy };
|
3
3
|
/**
|
4
4
|
* The maximum number of times that a failing service should be re-run before
|
@@ -36,6 +36,12 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
36
36
|
* there for more.
|
37
37
|
*
|
38
38
|
* @param options - The options to this function.
|
39
|
+
* @param options.maxRetries - The maximum number of times that a failing
|
40
|
+
* service should be re-invoked before giving up. Defaults to 3.
|
41
|
+
* @param options.retryFilterPolicy - The policy used to control when the
|
42
|
+
* service should be retried based on either the result of the servce or an
|
43
|
+
* error that it throws. For instance, you could use this to retry only certain
|
44
|
+
* errors. See `handleWhen` and friends from Cockatiel for more.
|
39
45
|
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
40
46
|
* service is allowed to fail before pausing further retries. Defaults to 12.
|
41
47
|
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
@@ -60,6 +66,10 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
60
66
|
* class Service {
|
61
67
|
* constructor() {
|
62
68
|
* this.#policy = createServicePolicy({
|
69
|
+
* maxRetries: 3,
|
70
|
+
* retryFilterPolicy: handleWhen((error) => {
|
71
|
+
* return error.message.includes('oops');
|
72
|
+
* }),
|
63
73
|
* maxConsecutiveFailures: 3,
|
64
74
|
* circuitBreakDuration: 5000,
|
65
75
|
* degradedThreshold: 2000,
|
@@ -81,7 +91,9 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
81
91
|
* }
|
82
92
|
* ```
|
83
93
|
*/
|
84
|
-
export declare function createServicePolicy({ maxConsecutiveFailures, circuitBreakDuration, degradedThreshold, onBreak, onDegraded, onRetry, }?: {
|
94
|
+
export declare function createServicePolicy({ maxRetries, retryFilterPolicy, maxConsecutiveFailures, circuitBreakDuration, degradedThreshold, onBreak, onDegraded, onRetry, }?: {
|
95
|
+
maxRetries?: number;
|
96
|
+
retryFilterPolicy?: Policy;
|
85
97
|
maxConsecutiveFailures?: number;
|
86
98
|
circuitBreakDuration?: number;
|
87
99
|
degradedThreshold?: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-service-policy.d.cts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB;
|
1
|
+
{"version":3,"file":"create-service-policy.d.cts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB;AAEjD,YAAY,EAAE,OAAO,IAAI,cAAc,EAAE,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,gCAAgC,QAAgC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QAAiB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,UAAgC,EAChC,iBAA6B,EAC7B,sBAAyD,EACzD,oBAAqD,EACrD,iBAA8C,EAC9C,OAEC,EACD,UAEC,EACD,OAEC,GACF,GAAE;IACD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACjB,GAAG,OAAO,CA0Df"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { IPolicy } from "cockatiel";
|
1
|
+
import type { IPolicy, Policy } from "cockatiel";
|
2
2
|
export type { IPolicy as IServicePolicy };
|
3
3
|
/**
|
4
4
|
* The maximum number of times that a failing service should be re-run before
|
@@ -36,6 +36,12 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
36
36
|
* there for more.
|
37
37
|
*
|
38
38
|
* @param options - The options to this function.
|
39
|
+
* @param options.maxRetries - The maximum number of times that a failing
|
40
|
+
* service should be re-invoked before giving up. Defaults to 3.
|
41
|
+
* @param options.retryFilterPolicy - The policy used to control when the
|
42
|
+
* service should be retried based on either the result of the servce or an
|
43
|
+
* error that it throws. For instance, you could use this to retry only certain
|
44
|
+
* errors. See `handleWhen` and friends from Cockatiel for more.
|
39
45
|
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
40
46
|
* service is allowed to fail before pausing further retries. Defaults to 12.
|
41
47
|
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
@@ -60,6 +66,10 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
60
66
|
* class Service {
|
61
67
|
* constructor() {
|
62
68
|
* this.#policy = createServicePolicy({
|
69
|
+
* maxRetries: 3,
|
70
|
+
* retryFilterPolicy: handleWhen((error) => {
|
71
|
+
* return error.message.includes('oops');
|
72
|
+
* }),
|
63
73
|
* maxConsecutiveFailures: 3,
|
64
74
|
* circuitBreakDuration: 5000,
|
65
75
|
* degradedThreshold: 2000,
|
@@ -81,7 +91,9 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
81
91
|
* }
|
82
92
|
* ```
|
83
93
|
*/
|
84
|
-
export declare function createServicePolicy({ maxConsecutiveFailures, circuitBreakDuration, degradedThreshold, onBreak, onDegraded, onRetry, }?: {
|
94
|
+
export declare function createServicePolicy({ maxRetries, retryFilterPolicy, maxConsecutiveFailures, circuitBreakDuration, degradedThreshold, onBreak, onDegraded, onRetry, }?: {
|
95
|
+
maxRetries?: number;
|
96
|
+
retryFilterPolicy?: Policy;
|
85
97
|
maxConsecutiveFailures?: number;
|
86
98
|
circuitBreakDuration?: number;
|
87
99
|
degradedThreshold?: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-service-policy.d.mts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB;
|
1
|
+
{"version":3,"file":"create-service-policy.d.mts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB;AAEjD,YAAY,EAAE,OAAO,IAAI,cAAc,EAAE,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,gCAAgC,QAAgC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QAAiB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,UAAgC,EAChC,iBAA6B,EAC7B,sBAAyD,EACzD,oBAAqD,EACrD,iBAA8C,EAC9C,OAEC,EACD,UAEC,EACD,OAEC,GACF,GAAE;IACD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACjB,GAAG,OAAO,CA0Df"}
|
@@ -35,6 +35,12 @@ export const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
35
35
|
* there for more.
|
36
36
|
*
|
37
37
|
* @param options - The options to this function.
|
38
|
+
* @param options.maxRetries - The maximum number of times that a failing
|
39
|
+
* service should be re-invoked before giving up. Defaults to 3.
|
40
|
+
* @param options.retryFilterPolicy - The policy used to control when the
|
41
|
+
* service should be retried based on either the result of the servce or an
|
42
|
+
* error that it throws. For instance, you could use this to retry only certain
|
43
|
+
* errors. See `handleWhen` and friends from Cockatiel for more.
|
38
44
|
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
39
45
|
* service is allowed to fail before pausing further retries. Defaults to 12.
|
40
46
|
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
@@ -59,6 +65,10 @@ export const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
59
65
|
* class Service {
|
60
66
|
* constructor() {
|
61
67
|
* this.#policy = createServicePolicy({
|
68
|
+
* maxRetries: 3,
|
69
|
+
* retryFilterPolicy: handleWhen((error) => {
|
70
|
+
* return error.message.includes('oops');
|
71
|
+
* }),
|
62
72
|
* maxConsecutiveFailures: 3,
|
63
73
|
* circuitBreakDuration: 5000,
|
64
74
|
* degradedThreshold: 2000,
|
@@ -80,17 +90,17 @@ export const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
80
90
|
* }
|
81
91
|
* ```
|
82
92
|
*/
|
83
|
-
export function createServicePolicy({ maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, onBreak = () => {
|
93
|
+
export function createServicePolicy({ maxRetries = DEFAULT_MAX_RETRIES, retryFilterPolicy = handleAll, maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, onBreak = () => {
|
84
94
|
// do nothing
|
85
95
|
}, onDegraded = () => {
|
86
96
|
// do nothing
|
87
97
|
}, onRetry = () => {
|
88
98
|
// do nothing
|
89
99
|
}, } = {}) {
|
90
|
-
const retryPolicy = retry(
|
100
|
+
const retryPolicy = retry(retryFilterPolicy, {
|
91
101
|
// Note that although the option here is called "max attempts", it's really
|
92
102
|
// maximum number of *retries* (attempts past the initial attempt).
|
93
|
-
maxAttempts:
|
103
|
+
maxAttempts: maxRetries,
|
94
104
|
// Retries of the service will be executed following ever increasing delays,
|
95
105
|
// determined by a backoff formula.
|
96
106
|
backoff: new ExponentialBackoff(),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-service-policy.mjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,IAAI,EACJ,YAAY,EACb,kBAAkB;AAKnB;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAK,CAAC;AAEhD
|
1
|
+
{"version":3,"file":"create-service-policy.mjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,IAAI,EACJ,YAAY,EACb,kBAAkB;AAKnB;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAK,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,UAAU,GAAG,mBAAmB,EAChC,iBAAiB,GAAG,SAAS,EAC7B,sBAAsB,GAAG,gCAAgC,EACzD,oBAAoB,GAAG,8BAA8B,EACrD,iBAAiB,GAAG,0BAA0B,EAC9C,OAAO,GAAG,GAAG,EAAE;IACb,aAAa;AACf,CAAC,EACD,UAAU,GAAG,GAAG,EAAE;IAChB,aAAa;AACf,CAAC,EACD,OAAO,GAAG,GAAG,EAAE;IACb,aAAa;AACf,CAAC,MAUC,EAAE;IACJ,MAAM,WAAW,GAAG,KAAK,CAAC,iBAAiB,EAAE;QAC3C,2EAA2E;QAC3E,mEAAmE;QACnE,WAAW,EAAE,UAAU;QACvB,4EAA4E;QAC5E,mCAAmC;QACnC,OAAO,EAAE,IAAI,kBAAkB,EAAE;KAClC,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,cAAc,CAAC,SAAS,EAAE;QACrD,uEAAuE;QACvE,oEAAoE;QACpE,wEAAwE;QACxE,4EAA4E;QAC5E,qEAAqE;QACrE,qDAAqD;QACrD,aAAa,EAAE,oBAAoB;QACnC,OAAO,EAAE,IAAI,kBAAkB,CAAC,sBAAsB,CAAC;KACxD,CAAC,CAAC;IAEH,2EAA2E;IAC3E,2EAA2E;IAC3E,sDAAsD;IACtD,6EAA6E;IAC7E,gBAAgB;IAChB,8EAA8E;IAC9E,8EAA8E;IAC9E,6BAA6B;IAC7B,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtC,uEAAuE;IACvE,+BAA+B;IAC/B,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7B,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE;QACxB,IAAI,oBAAoB,CAAC,KAAK,KAAK,YAAY,CAAC,MAAM,EAAE;YACtD,uEAAuE;YACvE,uEAAuE;YACvE,qEAAqE;YACrE,UAAU,EAAE,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IACH,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;QACrC,IACE,oBAAoB,CAAC,KAAK,KAAK,YAAY,CAAC,MAAM;YAClD,QAAQ,GAAG,iBAAiB,EAC5B;YACA,wEAAwE;YACxE,kEAAkE;YAClE,uBAAuB;YACvB,UAAU,EAAE,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IAEH,4EAA4E;IAC5E,eAAe;IACf,OAAO,IAAI,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import {\n circuitBreaker,\n ConsecutiveBreaker,\n ExponentialBackoff,\n handleAll,\n retry,\n wrap,\n CircuitState,\n} from 'cockatiel';\nimport type { IPolicy, Policy } from 'cockatiel';\n\nexport type { IPolicy as IServicePolicy };\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function.\n * @param options.maxRetries - The maximum number of times that a failing\n * service should be re-invoked before giving up. Defaults to 3.\n * @param options.retryFilterPolicy - The policy used to control when the\n * service should be retried based on either the result of the servce or an\n * error that it throws. For instance, you could use this to retry only certain\n * errors. See `handleWhen` and friends from Cockatiel for more.\n * @param options.maxConsecutiveFailures - The maximum number of times that the\n * service is allowed to fail before pausing further retries. Defaults to 12.\n * @param options.circuitBreakDuration - The length of time (in milliseconds) to\n * pause retries of the action after the number of failures reaches\n * `maxConsecutiveFailures`.\n * @param options.degradedThreshold - The length of time (in milliseconds) that\n * governs when the service is regarded as degraded (affecting when `onDegraded`\n * is called). Defaults to 5 seconds.\n * @param options.onBreak - A function which is called when the service fails\n * too many times in a row (specifically, more than `maxConsecutiveFailures`).\n * @param options.onDegraded - A function which is called when the service\n * succeeds before `maxConsecutiveFailures` is reached, but takes more time than\n * the `degradedThreshold` to run.\n * @param options.onRetry - A function which will be called the moment the\n * policy kicks off a timer to re-run the function passed to the policy. This is\n * primarily useful in tests where we are mocking timers.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy({\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n onBreak = () => {\n // do nothing\n },\n onDegraded = () => {\n // do nothing\n },\n onRetry = () => {\n // do nothing\n },\n}: {\n maxRetries?: number;\n retryFilterPolicy?: Policy;\n maxConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n degradedThreshold?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n onRetry?: () => void;\n} = {}): IPolicy {\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff: new ExponentialBackoff(),\n });\n\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maxConsecutiveFailures),\n });\n\n // The `onBreak` callback will be called if the service consistently throws\n // for as many times as exceeds the maximum consecutive number of failures.\n // Combined with the retry policy, this can happen if:\n // - `maxConsecutiveFailures` < the default max retries (3) and the policy is\n // executed once\n // - `maxConsecutiveFailures` >= the default max retries (3) but the policy is\n // executed multiple times, enough for the total number of retries to exceed\n // `maxConsecutiveFailures`\n circuitBreakerPolicy.onBreak(onBreak);\n\n // The `onRetryPolicy` callback will be called each time the service is\n // invoked (including retries).\n retryPolicy.onRetry(onRetry);\n\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n // The `onDegraded` callback will be called if the number of retries is\n // exceeded and the maximum number of consecutive failures has not been\n // reached yet (whether the policy is called once or multiple times).\n onDegraded();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n // The `onDegraded` callback will also be called if the service does not\n // throw, but the time it takes for the service to run exceeds the\n // `degradedThreshold`.\n onDegraded();\n }\n });\n\n // The retry policy really retries the circuit breaker policy, which invokes\n // the service.\n return wrap(retryPolicy, circuitBreakerPolicy);\n}\n"]}
|
package/dist/index.cjs
CHANGED
@@ -14,8 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.isEqualCaseInsensitive = exports.weiHexToGweiDec = exports.toHex = exports.toChecksumHexAddress = exports.timeoutFetch = exports.successfulFetch = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.query = exports.normalizeEnsName = exports.isValidHexAddress = exports.isValidJson = exports.isSmartContractCode = exports.isSafeDynamicKey = exports.isSafeChainId = exports.isPlainObject = exports.isNonEmptyArray = exports.hexToText = exports.hexToBN = exports.handleFetch = exports.gweiDecToWEIBN = exports.getBuyURL = exports.fromHex = exports.fractionBN = exports.fetchWithErrorHandling = exports.convertHexToDecimal = exports.BNToHex = exports.createServicePolicy = void 0;
|
17
|
+
exports.isEqualCaseInsensitive = exports.weiHexToGweiDec = exports.toHex = exports.toChecksumHexAddress = exports.timeoutFetch = exports.successfulFetch = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.query = exports.normalizeEnsName = exports.isValidHexAddress = exports.isValidJson = exports.isSmartContractCode = exports.isSafeDynamicKey = exports.isSafeChainId = exports.isPlainObject = exports.isNonEmptyArray = exports.hexToText = exports.hexToBN = exports.handleFetch = exports.gweiDecToWEIBN = exports.getBuyURL = exports.fromHex = exports.fractionBN = exports.fetchWithErrorHandling = exports.convertHexToDecimal = exports.BNToHex = exports.createServicePolicy = exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = void 0;
|
18
18
|
var create_service_policy_1 = require("./create-service-policy.cjs");
|
19
|
+
Object.defineProperty(exports, "DEFAULT_CIRCUIT_BREAK_DURATION", { enumerable: true, get: function () { return create_service_policy_1.DEFAULT_CIRCUIT_BREAK_DURATION; } });
|
20
|
+
Object.defineProperty(exports, "DEFAULT_DEGRADED_THRESHOLD", { enumerable: true, get: function () { return create_service_policy_1.DEFAULT_DEGRADED_THRESHOLD; } });
|
21
|
+
Object.defineProperty(exports, "DEFAULT_MAX_CONSECUTIVE_FAILURES", { enumerable: true, get: function () { return create_service_policy_1.DEFAULT_MAX_CONSECUTIVE_FAILURES; } });
|
22
|
+
Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", { enumerable: true, get: function () { return create_service_policy_1.DEFAULT_MAX_RETRIES; } });
|
19
23
|
Object.defineProperty(exports, "createServicePolicy", { enumerable: true, get: function () { return create_service_policy_1.createServicePolicy; } });
|
20
24
|
__exportStar(require("./constants.cjs"), exports);
|
21
25
|
var util_1 = require("./util.cjs");
|
package/dist/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qEAMiC;AAL/B,uIAAA,8BAA8B,OAAA;AAC9B,mIAAA,0BAA0B,OAAA;AAC1B,yIAAA,gCAAgC,OAAA;AAChC,4HAAA,mBAAmB,OAAA;AACnB,4HAAA,mBAAmB,OAAA;AAGrB,kDAA4B;AAE5B,mCA4BgB;AA3Bd,+FAAA,OAAO,OAAA;AACP,2GAAA,mBAAmB,OAAA;AACnB,8GAAA,sBAAsB,OAAA;AACtB,kGAAA,UAAU,OAAA;AACV,+FAAA,OAAO,OAAA;AACP,iGAAA,SAAS,OAAA;AACT,sGAAA,cAAc,OAAA;AACd,mGAAA,WAAW,OAAA;AACX,+FAAA,OAAO,OAAA;AACP,iGAAA,SAAS,OAAA;AACT,uGAAA,eAAe,OAAA;AACf,qGAAA,aAAa,OAAA;AACb,qGAAA,aAAa,OAAA;AACb,wGAAA,gBAAgB,OAAA;AAChB,2GAAA,mBAAmB,OAAA;AACnB,mGAAA,WAAW,OAAA;AACX,yGAAA,iBAAiB,OAAA;AACjB,wGAAA,gBAAgB,OAAA;AAChB,6FAAA,KAAK,OAAA;AACL,qGAAA,aAAa,OAAA;AACb,gHAAA,wBAAwB,OAAA;AACxB,uGAAA,eAAe,OAAA;AACf,oGAAA,YAAY,OAAA;AACZ,4GAAA,oBAAoB,OAAA;AACpB,6FAAA,KAAK,OAAA;AACL,uGAAA,eAAe,OAAA;AACf,8GAAA,sBAAsB,OAAA;AAExB,8CAAwB;AACxB,6CAAuB","sourcesContent":["export {\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n createServicePolicy,\n} from './create-service-policy';\nexport type { IServicePolicy } from './create-service-policy';\nexport * from './constants';\nexport type { NonEmptyArray } from './util';\nexport {\n BNToHex,\n convertHexToDecimal,\n fetchWithErrorHandling,\n fractionBN,\n fromHex,\n getBuyURL,\n gweiDecToWEIBN,\n handleFetch,\n hexToBN,\n hexToText,\n isNonEmptyArray,\n isPlainObject,\n isSafeChainId,\n isSafeDynamicKey,\n isSmartContractCode,\n isValidJson,\n isValidHexAddress,\n normalizeEnsName,\n query,\n safelyExecute,\n safelyExecuteWithTimeout,\n successfulFetch,\n timeoutFetch,\n toChecksumHexAddress,\n toHex,\n weiHexToGweiDec,\n isEqualCaseInsensitive,\n} from './util';\nexport * from './types';\nexport * from './siwe';\n"]}
|
package/dist/index.d.cts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
export { createServicePolicy } from "./create-service-policy.cjs";
|
1
|
+
export { DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, createServicePolicy, } from "./create-service-policy.cjs";
|
2
|
+
export type { IServicePolicy } from "./create-service-policy.cjs";
|
2
3
|
export * from "./constants.cjs";
|
3
4
|
export type { NonEmptyArray } from "./util.cjs";
|
4
5
|
export { BNToHex, convertHexToDecimal, fetchWithErrorHandling, fractionBN, fromHex, getBuyURL, gweiDecToWEIBN, handleFetch, hexToBN, hexToText, isNonEmptyArray, isPlainObject, isSafeChainId, isSafeDynamicKey, isSmartContractCode, isValidJson, isValidHexAddress, normalizeEnsName, query, safelyExecute, safelyExecuteWithTimeout, successfulFetch, timeoutFetch, toChecksumHexAddress, toHex, weiHexToGweiDec, isEqualCaseInsensitive, } from "./util.cjs";
|
package/dist/index.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,mBAAmB,GACpB,oCAAgC;AACjC,YAAY,EAAE,cAAc,EAAE,oCAAgC;AAC9D,gCAA4B;AAC5B,YAAY,EAAE,aAAa,EAAE,mBAAe;AAC5C,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,sBAAsB,GACvB,mBAAe;AAChB,4BAAwB;AACxB,2BAAuB"}
|
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
export { createServicePolicy } from "./create-service-policy.mjs";
|
1
|
+
export { DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, createServicePolicy, } from "./create-service-policy.mjs";
|
2
|
+
export type { IServicePolicy } from "./create-service-policy.mjs";
|
2
3
|
export * from "./constants.mjs";
|
3
4
|
export type { NonEmptyArray } from "./util.mjs";
|
4
5
|
export { BNToHex, convertHexToDecimal, fetchWithErrorHandling, fractionBN, fromHex, getBuyURL, gweiDecToWEIBN, handleFetch, hexToBN, hexToText, isNonEmptyArray, isPlainObject, isSafeChainId, isSafeDynamicKey, isSmartContractCode, isValidJson, isValidHexAddress, normalizeEnsName, query, safelyExecute, safelyExecuteWithTimeout, successfulFetch, timeoutFetch, toChecksumHexAddress, toHex, weiHexToGweiDec, isEqualCaseInsensitive, } from "./util.mjs";
|
package/dist/index.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,mBAAmB,GACpB,oCAAgC;AACjC,YAAY,EAAE,cAAc,EAAE,oCAAgC;AAC9D,gCAA4B;AAC5B,YAAY,EAAE,aAAa,EAAE,mBAAe;AAC5C,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,sBAAsB,GACvB,mBAAe;AAChB,4BAAwB;AACxB,2BAAuB"}
|
package/dist/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { createServicePolicy } from "./create-service-policy.mjs";
|
1
|
+
export { DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, createServicePolicy } from "./create-service-policy.mjs";
|
2
2
|
export * from "./constants.mjs";
|
3
3
|
export { BNToHex, convertHexToDecimal, fetchWithErrorHandling, fractionBN, fromHex, getBuyURL, gweiDecToWEIBN, handleFetch, hexToBN, hexToText, isNonEmptyArray, isPlainObject, isSafeChainId, isSafeDynamicKey, isSmartContractCode, isValidJson, isValidHexAddress, normalizeEnsName, query, safelyExecute, safelyExecuteWithTimeout, successfulFetch, timeoutFetch, toChecksumHexAddress, toHex, weiHexToGweiDec, isEqualCaseInsensitive } from "./util.mjs";
|
4
4
|
export * from "./types.mjs";
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,mBAAmB,EACpB,oCAAgC;AAEjC,gCAA4B;AAE5B,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,sBAAsB,EACvB,mBAAe;AAChB,4BAAwB;AACxB,2BAAuB","sourcesContent":["export {\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n createServicePolicy,\n} from './create-service-policy';\nexport type { IServicePolicy } from './create-service-policy';\nexport * from './constants';\nexport type { NonEmptyArray } from './util';\nexport {\n BNToHex,\n convertHexToDecimal,\n fetchWithErrorHandling,\n fractionBN,\n fromHex,\n getBuyURL,\n gweiDecToWEIBN,\n handleFetch,\n hexToBN,\n hexToText,\n isNonEmptyArray,\n isPlainObject,\n isSafeChainId,\n isSafeDynamicKey,\n isSmartContractCode,\n isValidJson,\n isValidHexAddress,\n normalizeEnsName,\n query,\n safelyExecute,\n safelyExecuteWithTimeout,\n successfulFetch,\n timeoutFetch,\n toChecksumHexAddress,\n toHex,\n weiHexToGweiDec,\n isEqualCaseInsensitive,\n} from './util';\nexport * from './types';\nexport * from './siwe';\n"]}
|