@metamask-previews/controller-utils 11.20.0-preview-d6324f95d → 11.20.0-preview-938a7fe
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 +3 -1
- package/dist/create-service-policy.cjs +1 -1
- package/dist/create-service-policy.cjs.map +1 -1
- package/dist/create-service-policy.d.cts +3 -1
- package/dist/create-service-policy.d.cts.map +1 -1
- package/dist/create-service-policy.d.mts +3 -1
- package/dist/create-service-policy.d.mts.map +1 -1
- package/dist/create-service-policy.mjs +1 -1
- package/dist/create-service-policy.mjs.map +1 -1
- package/dist/types.cjs +0 -25
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -27
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -27
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -25
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** The `ServicePolicy` type's `onDegraded` event now emits `{ duration: number }` instead of `void` when the service succeeds but takes longer than the `degradedThreshold` ([#8455](https://github.com/MetaMask/core/pull/8455))
|
|
13
|
+
- `void` has been removed from the event's type union. Listeners that checked for `undefined` data should now check for the `duration` property instead.
|
|
14
|
+
- The event still emits a `FailureReason` when retries are exhausted.
|
|
12
15
|
- Update `normalizeEnsName` regex to allow ENS names with 3 or more characters (previously required 7 or more) ([#8510](https://github.com/MetaMask/core/pull/8510))
|
|
13
16
|
- Update default Sei Mainnet block explorer URL from `seitrace.com` to `seiscan.io` ([#8545](https://github.com/MetaMask/core/pull/8545))
|
|
14
|
-
- Update `InfuraNetworkType`, `ChainId`, `NetworksTicker`, `BlockExplorerUrl`, and `NetworkNickname` to include missing Infura networks ([#8680](https://github.com/MetaMask/core/pull/8680))
|
|
15
17
|
|
|
16
18
|
## [11.20.0]
|
|
17
19
|
|
|
@@ -166,7 +166,7 @@ function createServicePolicy(options = {}) {
|
|
|
166
166
|
if (circuitBreakerPolicy.state === cockatiel_1.CircuitState.Closed) {
|
|
167
167
|
if (duration > degradedThreshold) {
|
|
168
168
|
availabilityStatus = AVAILABILITY_STATUSES.Degraded;
|
|
169
|
-
onDegradedEventEmitter.emit();
|
|
169
|
+
onDegradedEventEmitter.emit({ duration });
|
|
170
170
|
}
|
|
171
171
|
else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {
|
|
172
172
|
availabilityStatus = AVAILABILITY_STATUSES.Available;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAYmB;AAYjB,mGAvBA,8BAAkB,OAuBA;AAElB,6FAxBA,wBAAY,OAwBA;AADZ,sGAtBgB,wBAAqB,OAsBhB;AAGrB,mGAvBA,8BAAkB,OAuBA;AADlB,gGArBA,2BAAe,OAqBA;AAEf,0FArBA,qBAAS,OAqBA;AACT,2FArBA,sBAAU,OAqBA;AAmHZ;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;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,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAW,EAAE;IACnD,IACE,O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,CAAC,OAAO,EAAE,CAAC;QAE7B,2EAA2E;QAC3E,2DAA2D;QAC3D,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC;IACrD,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC;AAtID,kDAsIC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | void>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\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. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\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\nconst isServiceFailure = (error: unknown): boolean => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\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. See\n * {@link CreateServicePolicyOptions}.\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 options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\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 backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\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,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\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: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter =\n new CockatielEventEmitter<FailureReason<unknown> | void>();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit();\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = (): number | null => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = (): CircuitState => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = (): void => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAYmB;AAYjB,mGAvBA,8BAAkB,OAuBA;AAElB,6FAxBA,wBAAY,OAwBA;AADZ,sGAtBgB,wBAAqB,OAsBhB;AAGrB,mGAvBA,8BAAkB,OAuBA;AADlB,gGArBA,2BAAe,OAqBA;AAEf,0FArBA,qBAAS,OAqBA;AACT,2FArBA,sBAAU,OAqBA;AAmHZ;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACU,QAAA,mBAAmB,GAAG,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ACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,GAAiB,EAAE;QACzC,OAAO,oBAAoB,CAAC,KAAK,CAAC;IACpC,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,4EAA4E;QAC5E,MAAM,EAAE,OAAO,EAAE,GAAG,oBAAoB,CAAC,OAAO,EAAE,CAAC;QACnD,8BAA8B;QAC9B,OAAO,EAAE,CAAC;QAEV,2CAA2C;QAC3C,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAE7B,2EAA2E;QAC3E,2DAA2D;QAC3D,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC;IACrD,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC;AAvID,kDAuIC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | { duration: number }>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\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. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\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\nconst isServiceFailure = (error: unknown): boolean => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\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. See\n * {@link CreateServicePolicyOptions}.\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 options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\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 backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\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,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\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: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter = new CockatielEventEmitter<\n FailureReason<unknown> | { duration: number }\n >();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit({ duration });\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = (): number | null => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = (): CircuitState => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = (): void => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
|
@@ -85,7 +85,9 @@ export type ServicePolicy = IPolicy & {
|
|
|
85
85
|
* never succeeds before the retry policy gives up and before the maximum
|
|
86
86
|
* number of consecutive failures has been reached.
|
|
87
87
|
*/
|
|
88
|
-
onDegraded: CockatielEvent<FailureReason<unknown> |
|
|
88
|
+
onDegraded: CockatielEvent<FailureReason<unknown> | {
|
|
89
|
+
duration: number;
|
|
90
|
+
}>;
|
|
89
91
|
/**
|
|
90
92
|
* A function which is called when the service succeeds for the first time,
|
|
91
93
|
* or when the service fails enough times to cause the circuit to break and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-policy.d.cts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EAErC,kBAAkB,EAClB,eAAe,EAEf,SAAS,EACT,UAAU,EAGX,kBAAkB;AACnB,OAAO,KAAK,EACV,oBAAoB,EACpB,KAAK,IAAI,cAAc,EACvB,aAAa,EACb,eAAe,EACf,OAAO,EACP,MAAM,EACN,WAAW,EACZ,kBAAkB;AAEnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,GACX,CAAC;AAEF,YAAY,EAAE,cAAc,EAAE,aAAa,IAAI,sBAAsB,EAAE,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC;;;OAGG;IACH,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,eAAe,EAAE,MAAM,YAAY,CAAC;IACpC;;;;OAIG;IACH,+BAA+B,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACrD;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACzC;;;;;;OAMG;IACH,UAAU,EAAE,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"create-service-policy.d.cts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EAErC,kBAAkB,EAClB,eAAe,EAEf,SAAS,EACT,UAAU,EAGX,kBAAkB;AACnB,OAAO,KAAK,EACV,oBAAoB,EACpB,KAAK,IAAI,cAAc,EACvB,aAAa,EACb,eAAe,EACf,OAAO,EACP,MAAM,EACN,WAAW,EACZ,kBAAkB;AAEnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,GACX,CAAC;AAEF,YAAY,EAAE,cAAc,EAAE,aAAa,IAAI,sBAAsB,EAAE,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC;;;OAGG;IACH,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,eAAe,EAAE,MAAM,YAAY,CAAC;IACpC;;;;OAIG;IACH,+BAA+B,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACrD;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACzC;;;;;;OAMG;IACH,UAAU,EAAE,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E;;;;OAIG;IACH,WAAW,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC;;;;OAIG;IACH,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CACjC,CAAC;AAiCF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,QAAgC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QAAiB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAoChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,aAAa,CAqIf"}
|
|
@@ -85,7 +85,9 @@ export type ServicePolicy = IPolicy & {
|
|
|
85
85
|
* never succeeds before the retry policy gives up and before the maximum
|
|
86
86
|
* number of consecutive failures has been reached.
|
|
87
87
|
*/
|
|
88
|
-
onDegraded: CockatielEvent<FailureReason<unknown> |
|
|
88
|
+
onDegraded: CockatielEvent<FailureReason<unknown> | {
|
|
89
|
+
duration: number;
|
|
90
|
+
}>;
|
|
89
91
|
/**
|
|
90
92
|
* A function which is called when the service succeeds for the first time,
|
|
91
93
|
* or when the service fails enough times to cause the circuit to break and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-policy.d.mts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EAErC,kBAAkB,EAClB,eAAe,EAEf,SAAS,EACT,UAAU,EAGX,kBAAkB;AACnB,OAAO,KAAK,EACV,oBAAoB,EACpB,KAAK,IAAI,cAAc,EACvB,aAAa,EACb,eAAe,EACf,OAAO,EACP,MAAM,EACN,WAAW,EACZ,kBAAkB;AAEnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,GACX,CAAC;AAEF,YAAY,EAAE,cAAc,EAAE,aAAa,IAAI,sBAAsB,EAAE,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC;;;OAGG;IACH,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,eAAe,EAAE,MAAM,YAAY,CAAC;IACpC;;;;OAIG;IACH,+BAA+B,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACrD;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACzC;;;;;;OAMG;IACH,UAAU,EAAE,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"create-service-policy.d.mts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EAErC,kBAAkB,EAClB,eAAe,EAEf,SAAS,EACT,UAAU,EAGX,kBAAkB;AACnB,OAAO,KAAK,EACV,oBAAoB,EACpB,KAAK,IAAI,cAAc,EACvB,aAAa,EACb,eAAe,EACf,OAAO,EACP,MAAM,EACN,WAAW,EACZ,kBAAkB;AAEnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,GACX,CAAC;AAEF,YAAY,EAAE,cAAc,EAAE,aAAa,IAAI,sBAAsB,EAAE,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC;;;OAGG;IACH,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,eAAe,EAAE,MAAM,YAAY,CAAC;IACpC;;;;OAIG;IACH,+BAA+B,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACrD;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACzC;;;;;;OAMG;IACH,UAAU,EAAE,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E;;;;OAIG;IACH,WAAW,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC;;;;OAIG;IACH,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CACjC,CAAC;AAiCF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,QAAgC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QAAiB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAoChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,aAAa,CAqIf"}
|
|
@@ -157,7 +157,7 @@ export function createServicePolicy(options = {}) {
|
|
|
157
157
|
if (circuitBreakerPolicy.state === CircuitState.Closed) {
|
|
158
158
|
if (duration > degradedThreshold) {
|
|
159
159
|
availabilityStatus = AVAILABILITY_STATUSES.Degraded;
|
|
160
|
-
onDegradedEventEmitter.emit();
|
|
160
|
+
onDegradedEventEmitter.emit({ duration });
|
|
161
161
|
}
|
|
162
162
|
else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {
|
|
163
163
|
availabilityStatus = AVAILABILITY_STATUSES.Available;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-policy.mjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EACrC,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,SAAS,EACT,UAAU,EACV,KAAK,EACL,IAAI,EACL,kBAAkB;AAWnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,EACX,CAAC;AAkHF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;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,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAW,EAAE;IACnD,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,OAAO,KAAK,CAAC,UAAU,KAA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QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | void>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\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. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\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\nconst isServiceFailure = (error: unknown): boolean => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\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. See\n * {@link CreateServicePolicyOptions}.\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 options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\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 backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\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,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\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: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter =\n new CockatielEventEmitter<FailureReason<unknown> | void>();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit();\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = (): number | null => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = (): CircuitState => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = (): void => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-service-policy.mjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EACrC,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,SAAS,EACT,UAAU,EACV,KAAK,EACL,IAAI,EACL,kBAAkB;AAWnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,EACX,CAAC;AAkHF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC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AAE;QACzC,OAAO,oBAAoB,CAAC,KAAK,CAAC;IACpC,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,4EAA4E;QAC5E,MAAM,EAAE,OAAO,EAAE,GAAG,oBAAoB,CAAC,OAAO,EAAE,CAAC;QACnD,8BAA8B;QAC9B,OAAO,EAAE,CAAC;QAEV,2CAA2C;QAC3C,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAE7B,2EAA2E;QAC3E,2DAA2D;QAC3D,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC;IACrD,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | { duration: number }>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\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. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\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\nconst isServiceFailure = (error: unknown): boolean => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\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. See\n * {@link CreateServicePolicyOptions}.\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 options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\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 backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\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,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\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: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter = new CockatielEventEmitter<\n FailureReason<unknown> | { duration: number }\n >();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit({ duration });\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = (): number | null => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = (): CircuitState => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = (): void => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
package/dist/types.cjs
CHANGED
|
@@ -17,10 +17,6 @@ exports.InfuraNetworkType = {
|
|
|
17
17
|
'optimism-mainnet': 'optimism-mainnet',
|
|
18
18
|
'polygon-mainnet': 'polygon-mainnet',
|
|
19
19
|
'sei-mainnet': 'sei-mainnet',
|
|
20
|
-
'monad-mainnet': 'monad-mainnet',
|
|
21
|
-
'megaeth-mainnet': 'megaeth-mainnet',
|
|
22
|
-
'avalanche-mainnet': 'avalanche-mainnet',
|
|
23
|
-
'zksync-mainnet': 'zksync-mainnet',
|
|
24
20
|
};
|
|
25
21
|
/**
|
|
26
22
|
* Custom network types that are not part of Infura.
|
|
@@ -90,9 +86,6 @@ var BuiltInNetworkName;
|
|
|
90
86
|
BuiltInNetworkName["PolygonMainnet"] = "polygon-mainnet";
|
|
91
87
|
BuiltInNetworkName["SeiMainnet"] = "sei-mainnet";
|
|
92
88
|
BuiltInNetworkName["MegaETHMainnet"] = "megaeth-mainnet";
|
|
93
|
-
BuiltInNetworkName["MonadMainnet"] = "monad-mainnet";
|
|
94
|
-
BuiltInNetworkName["AvalancheMainnet"] = "avalanche-mainnet";
|
|
95
|
-
BuiltInNetworkName["ZksyncMainnet"] = "zksync-mainnet";
|
|
96
89
|
})(BuiltInNetworkName || (exports.BuiltInNetworkName = BuiltInNetworkName = {}));
|
|
97
90
|
/**
|
|
98
91
|
* Decimal string chain IDs of built-in networks, by name.
|
|
@@ -120,9 +113,6 @@ exports.ChainId = {
|
|
|
120
113
|
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
|
|
121
114
|
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)
|
|
122
115
|
[BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)
|
|
123
|
-
[BuiltInNetworkName.MonadMainnet]: '0x8f', // toHex(143)
|
|
124
|
-
[BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)
|
|
125
|
-
[BuiltInNetworkName.ZksyncMainnet]: '0x144', // toHex(324)
|
|
126
116
|
};
|
|
127
117
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
128
118
|
var NetworksTicker;
|
|
@@ -151,13 +141,6 @@ var NetworksTicker;
|
|
|
151
141
|
NetworksTicker["optimism-mainnet"] = "ETH";
|
|
152
142
|
NetworksTicker["polygon-mainnet"] = "POL";
|
|
153
143
|
NetworksTicker["sei-mainnet"] = "SEI";
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
155
|
-
NetworksTicker["megaeth-mainnet"] = "ETH";
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
157
|
-
NetworksTicker["monad-mainnet"] = "MON";
|
|
158
|
-
NetworksTicker["avalanche-mainnet"] = "AVAX";
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
160
|
-
NetworksTicker["zksync-mainnet"] = "ETH";
|
|
161
144
|
NetworksTicker["rpc"] = "";
|
|
162
145
|
})(NetworksTicker || (exports.NetworksTicker = NetworksTicker = {}));
|
|
163
146
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
@@ -180,10 +163,6 @@ exports.BlockExplorerUrl = {
|
|
|
180
163
|
[BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',
|
|
181
164
|
[BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',
|
|
182
165
|
[BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',
|
|
183
|
-
[BuiltInNetworkName.MegaETHMainnet]: 'https://megaeth.blockscout.com',
|
|
184
|
-
[BuiltInNetworkName.MonadMainnet]: 'https://monadscan.com',
|
|
185
|
-
[BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',
|
|
186
|
-
[BuiltInNetworkName.ZksyncMainnet]: 'https://explorer.zksync.io',
|
|
187
166
|
};
|
|
188
167
|
exports.NetworkNickname = {
|
|
189
168
|
[BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',
|
|
@@ -204,9 +183,5 @@ exports.NetworkNickname = {
|
|
|
204
183
|
[BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',
|
|
205
184
|
[BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',
|
|
206
185
|
[BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',
|
|
207
|
-
[BuiltInNetworkName.MegaETHMainnet]: 'MegaETH Mainnet',
|
|
208
|
-
[BuiltInNetworkName.MonadMainnet]: 'Monad Mainnet',
|
|
209
|
-
[BuiltInNetworkName.AvalancheMainnet]: 'Avalanche Mainnet',
|
|
210
|
-
[BuiltInNetworkName.ZksyncMainnet]: 'ZKsync Era',
|
|
211
186
|
};
|
|
212
187
|
//# sourceMappingURL=types.cjs.map
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,aAAa;IAC5B,eAAe,EAAE,eAAe;IAChC,iBAAiB,EAAE,iBAAiB;IACpC,mBAAmB,EAAE,mBAAmB;IACxC,gBAAgB,EAAE,gBAAgB;CAC1B,CAAC;AAKX;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB;IACpC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;CACxB,CAAC;AASX;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,GAAG,yBAAiB;IACpB,GAAG,yBAAiB;IACpB,GAAG,EAAE,KAAK;CACF,CAAC;AAIX;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAW,CAAC,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;AACjE,CAAC;AAFD,sCAEC;AA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mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n 'monad-mainnet': 'monad-mainnet',\n 'megaeth-mainnet': 'megaeth-mainnet',\n 'avalanche-mainnet': 'avalanche-mainnet',\n 'zksync-mainnet': 'zksync-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n MegaETHMainnet = 'megaeth-mainnet',\n MonadMainnet = 'monad-mainnet',\n AvalancheMainnet = 'avalanche-mainnet',\n ZksyncMainnet = 'zksync-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n [BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)\n [BuiltInNetworkName.MonadMainnet]: '0x8f', // toHex(143)\n [BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)\n [BuiltInNetworkName.ZksyncMainnet]: '0x144', // toHex(324)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'monad-mainnet' = 'MON',\n 'avalanche-mainnet' = 'AVAX',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'zksync-mainnet' = 'ETH',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',\n [BuiltInNetworkName.MegaETHMainnet]: 'https://megaeth.blockscout.com',\n [BuiltInNetworkName.MonadMainnet]: 'https://monadscan.com',\n [BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',\n [BuiltInNetworkName.ZksyncMainnet]: 'https://explorer.zksync.io',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n [BuiltInNetworkName.MegaETHMainnet]: 'MegaETH Mainnet',\n [BuiltInNetworkName.MonadMainnet]: 'Monad Mainnet',\n [BuiltInNetworkName.AvalancheMainnet]: 'Avalanche Mainnet',\n [BuiltInNetworkName.ZksyncMainnet]: 'ZKsync Era',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,aAAa;CACpB,CAAC;AAKX;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB;IACpC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;CACxB,CAAC;AASX;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,GAAG,yBAAiB;IACpB,GAAG,yBAAiB;IACpB,GAAG,EAAE,KAAK;CACF,CAAC;AAIX;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW;IACvC,OAAO,MAAM,CAA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,cAAc,CAAC,EAAE,cAAc;IACnD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,iBAAiB;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,kBAAkB;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;CACO,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n MegaETHMainnet = 'megaeth-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n [BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -14,10 +14,6 @@ export declare const InfuraNetworkType: {
|
|
|
14
14
|
readonly 'optimism-mainnet': "optimism-mainnet";
|
|
15
15
|
readonly 'polygon-mainnet': "polygon-mainnet";
|
|
16
16
|
readonly 'sei-mainnet': "sei-mainnet";
|
|
17
|
-
readonly 'monad-mainnet': "monad-mainnet";
|
|
18
|
-
readonly 'megaeth-mainnet': "megaeth-mainnet";
|
|
19
|
-
readonly 'avalanche-mainnet': "avalanche-mainnet";
|
|
20
|
-
readonly 'zksync-mainnet': "zksync-mainnet";
|
|
21
17
|
};
|
|
22
18
|
export type InfuraNetworkType = (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];
|
|
23
19
|
/**
|
|
@@ -59,10 +55,6 @@ export declare const NetworkType: {
|
|
|
59
55
|
readonly 'optimism-mainnet': "optimism-mainnet";
|
|
60
56
|
readonly 'polygon-mainnet': "polygon-mainnet";
|
|
61
57
|
readonly 'sei-mainnet': "sei-mainnet";
|
|
62
|
-
readonly 'monad-mainnet': "monad-mainnet";
|
|
63
|
-
readonly 'megaeth-mainnet': "megaeth-mainnet";
|
|
64
|
-
readonly 'avalanche-mainnet': "avalanche-mainnet";
|
|
65
|
-
readonly 'zksync-mainnet': "zksync-mainnet";
|
|
66
58
|
};
|
|
67
59
|
export type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];
|
|
68
60
|
/**
|
|
@@ -105,10 +97,7 @@ export declare enum BuiltInNetworkName {
|
|
|
105
97
|
OptimismMainnet = "optimism-mainnet",
|
|
106
98
|
PolygonMainnet = "polygon-mainnet",
|
|
107
99
|
SeiMainnet = "sei-mainnet",
|
|
108
|
-
MegaETHMainnet = "megaeth-mainnet"
|
|
109
|
-
MonadMainnet = "monad-mainnet",
|
|
110
|
-
AvalancheMainnet = "avalanche-mainnet",
|
|
111
|
-
ZksyncMainnet = "zksync-mainnet"
|
|
100
|
+
MegaETHMainnet = "megaeth-mainnet"
|
|
112
101
|
}
|
|
113
102
|
/**
|
|
114
103
|
* Decimal string chain IDs of built-in networks, by name.
|
|
@@ -136,9 +125,6 @@ export declare const ChainId: {
|
|
|
136
125
|
readonly "polygon-mainnet": "0x89";
|
|
137
126
|
readonly "sei-mainnet": "0x531";
|
|
138
127
|
readonly "megaeth-mainnet": "0x10e6";
|
|
139
|
-
readonly "monad-mainnet": "0x8f";
|
|
140
|
-
readonly "avalanche-mainnet": "0xa86a";
|
|
141
|
-
readonly "zksync-mainnet": "0x144";
|
|
142
128
|
};
|
|
143
129
|
export type ChainId = (typeof ChainId)[keyof typeof ChainId];
|
|
144
130
|
export declare enum NetworksTicker {
|
|
@@ -160,10 +146,6 @@ export declare enum NetworksTicker {
|
|
|
160
146
|
'optimism-mainnet' = "ETH",
|
|
161
147
|
'polygon-mainnet' = "POL",
|
|
162
148
|
'sei-mainnet' = "SEI",
|
|
163
|
-
'megaeth-mainnet' = "ETH",
|
|
164
|
-
'monad-mainnet' = "MON",
|
|
165
|
-
'avalanche-mainnet' = "AVAX",
|
|
166
|
-
'zksync-mainnet' = "ETH",
|
|
167
149
|
rpc = ""
|
|
168
150
|
}
|
|
169
151
|
export declare const BlockExplorerUrl: {
|
|
@@ -185,10 +167,6 @@ export declare const BlockExplorerUrl: {
|
|
|
185
167
|
readonly "optimism-mainnet": "https://optimistic.etherscan.io";
|
|
186
168
|
readonly "polygon-mainnet": "https://polygonscan.com";
|
|
187
169
|
readonly "sei-mainnet": "https://seiscan.io";
|
|
188
|
-
readonly "megaeth-mainnet": "https://megaeth.blockscout.com";
|
|
189
|
-
readonly "monad-mainnet": "https://monadscan.com";
|
|
190
|
-
readonly "avalanche-mainnet": "https://snowtrace.io";
|
|
191
|
-
readonly "zksync-mainnet": "https://explorer.zksync.io";
|
|
192
170
|
};
|
|
193
171
|
export type BlockExplorerUrl = (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];
|
|
194
172
|
export declare const NetworkNickname: {
|
|
@@ -210,10 +188,6 @@ export declare const NetworkNickname: {
|
|
|
210
188
|
readonly "optimism-mainnet": "Optimism Mainnet";
|
|
211
189
|
readonly "polygon-mainnet": "Polygon Mainnet";
|
|
212
190
|
readonly "sei-mainnet": "Sei Mainnet";
|
|
213
|
-
readonly "megaeth-mainnet": "MegaETH Mainnet";
|
|
214
|
-
readonly "monad-mainnet": "Monad Mainnet";
|
|
215
|
-
readonly "avalanche-mainnet": "Avalanche Mainnet";
|
|
216
|
-
readonly "zksync-mainnet": "ZKsync Era";
|
|
217
191
|
};
|
|
218
192
|
export type NetworkNickname = (typeof NetworkNickname)[keyof typeof NetworkNickname];
|
|
219
193
|
/**
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAapB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;;;;CAIK,CAAC;AACX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,WAAW;;IAlBtB;;OAEG;;;;;;;;;;;;;;;;CAoBK,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW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'optimism-mainnet': "optimism-mainnet";
|
|
15
15
|
readonly 'polygon-mainnet': "polygon-mainnet";
|
|
16
16
|
readonly 'sei-mainnet': "sei-mainnet";
|
|
17
|
-
readonly 'monad-mainnet': "monad-mainnet";
|
|
18
|
-
readonly 'megaeth-mainnet': "megaeth-mainnet";
|
|
19
|
-
readonly 'avalanche-mainnet': "avalanche-mainnet";
|
|
20
|
-
readonly 'zksync-mainnet': "zksync-mainnet";
|
|
21
17
|
};
|
|
22
18
|
export type InfuraNetworkType = (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];
|
|
23
19
|
/**
|
|
@@ -59,10 +55,6 @@ export declare const NetworkType: {
|
|
|
59
55
|
readonly 'optimism-mainnet': "optimism-mainnet";
|
|
60
56
|
readonly 'polygon-mainnet': "polygon-mainnet";
|
|
61
57
|
readonly 'sei-mainnet': "sei-mainnet";
|
|
62
|
-
readonly 'monad-mainnet': "monad-mainnet";
|
|
63
|
-
readonly 'megaeth-mainnet': "megaeth-mainnet";
|
|
64
|
-
readonly 'avalanche-mainnet': "avalanche-mainnet";
|
|
65
|
-
readonly 'zksync-mainnet': "zksync-mainnet";
|
|
66
58
|
};
|
|
67
59
|
export type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];
|
|
68
60
|
/**
|
|
@@ -105,10 +97,7 @@ export declare enum BuiltInNetworkName {
|
|
|
105
97
|
OptimismMainnet = "optimism-mainnet",
|
|
106
98
|
PolygonMainnet = "polygon-mainnet",
|
|
107
99
|
SeiMainnet = "sei-mainnet",
|
|
108
|
-
MegaETHMainnet = "megaeth-mainnet"
|
|
109
|
-
MonadMainnet = "monad-mainnet",
|
|
110
|
-
AvalancheMainnet = "avalanche-mainnet",
|
|
111
|
-
ZksyncMainnet = "zksync-mainnet"
|
|
100
|
+
MegaETHMainnet = "megaeth-mainnet"
|
|
112
101
|
}
|
|
113
102
|
/**
|
|
114
103
|
* Decimal string chain IDs of built-in networks, by name.
|
|
@@ -136,9 +125,6 @@ export declare const ChainId: {
|
|
|
136
125
|
readonly "polygon-mainnet": "0x89";
|
|
137
126
|
readonly "sei-mainnet": "0x531";
|
|
138
127
|
readonly "megaeth-mainnet": "0x10e6";
|
|
139
|
-
readonly "monad-mainnet": "0x8f";
|
|
140
|
-
readonly "avalanche-mainnet": "0xa86a";
|
|
141
|
-
readonly "zksync-mainnet": "0x144";
|
|
142
128
|
};
|
|
143
129
|
export type ChainId = (typeof ChainId)[keyof typeof ChainId];
|
|
144
130
|
export declare enum NetworksTicker {
|
|
@@ -160,10 +146,6 @@ export declare enum NetworksTicker {
|
|
|
160
146
|
'optimism-mainnet' = "ETH",
|
|
161
147
|
'polygon-mainnet' = "POL",
|
|
162
148
|
'sei-mainnet' = "SEI",
|
|
163
|
-
'megaeth-mainnet' = "ETH",
|
|
164
|
-
'monad-mainnet' = "MON",
|
|
165
|
-
'avalanche-mainnet' = "AVAX",
|
|
166
|
-
'zksync-mainnet' = "ETH",
|
|
167
149
|
rpc = ""
|
|
168
150
|
}
|
|
169
151
|
export declare const BlockExplorerUrl: {
|
|
@@ -185,10 +167,6 @@ export declare const BlockExplorerUrl: {
|
|
|
185
167
|
readonly "optimism-mainnet": "https://optimistic.etherscan.io";
|
|
186
168
|
readonly "polygon-mainnet": "https://polygonscan.com";
|
|
187
169
|
readonly "sei-mainnet": "https://seiscan.io";
|
|
188
|
-
readonly "megaeth-mainnet": "https://megaeth.blockscout.com";
|
|
189
|
-
readonly "monad-mainnet": "https://monadscan.com";
|
|
190
|
-
readonly "avalanche-mainnet": "https://snowtrace.io";
|
|
191
|
-
readonly "zksync-mainnet": "https://explorer.zksync.io";
|
|
192
170
|
};
|
|
193
171
|
export type BlockExplorerUrl = (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];
|
|
194
172
|
export declare const NetworkNickname: {
|
|
@@ -210,10 +188,6 @@ export declare const NetworkNickname: {
|
|
|
210
188
|
readonly "optimism-mainnet": "Optimism Mainnet";
|
|
211
189
|
readonly "polygon-mainnet": "Polygon Mainnet";
|
|
212
190
|
readonly "sei-mainnet": "Sei Mainnet";
|
|
213
|
-
readonly "megaeth-mainnet": "MegaETH Mainnet";
|
|
214
|
-
readonly "monad-mainnet": "Monad Mainnet";
|
|
215
|
-
readonly "avalanche-mainnet": "Avalanche Mainnet";
|
|
216
|
-
readonly "zksync-mainnet": "ZKsync Era";
|
|
217
191
|
};
|
|
218
192
|
export type NetworkNickname = (typeof NetworkNickname)[keyof typeof NetworkNickname];
|
|
219
193
|
/**
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAapB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;;;;CAIK,CAAC;AACX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,WAAW;;IAlBtB;;OAEG;;;;;;;;;;;;;;;;CAoBK,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,WAAW,CAE7D;AAED;;;;;;GAMG;AACH,wBAAg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kD,CAAC;AACxD,MAAM,MAAM,eAAe,GACzB,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAEzD;;;;;GAKG;AAEH,MAAM,MAAM,UAAU,CAAC,IAAI,EAAE,GAAG,SAAS,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GACpE,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AAE3B,kFAAkF;AAClF,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AAEnC,qCAAqC;AACrC,MAAM,MAAM,YAAY,GAAG;IACzB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IAEjD,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,uDAAuD;IACvD,aAAa,CAAC,EAAE,YAAY,CAAC;IAE7B,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAClD,CAAC;AAEF,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,CAAC,UAAU;AACrC,wDAAwD;AACxD,OAAO,EAAE,YAAY;AAErB;;;;;GAKG;AACH,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,UAAU,KACxC,OAAO,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/types.mjs
CHANGED
|
@@ -14,10 +14,6 @@ export const InfuraNetworkType = {
|
|
|
14
14
|
'optimism-mainnet': 'optimism-mainnet',
|
|
15
15
|
'polygon-mainnet': 'polygon-mainnet',
|
|
16
16
|
'sei-mainnet': 'sei-mainnet',
|
|
17
|
-
'monad-mainnet': 'monad-mainnet',
|
|
18
|
-
'megaeth-mainnet': 'megaeth-mainnet',
|
|
19
|
-
'avalanche-mainnet': 'avalanche-mainnet',
|
|
20
|
-
'zksync-mainnet': 'zksync-mainnet',
|
|
21
17
|
};
|
|
22
18
|
/**
|
|
23
19
|
* Custom network types that are not part of Infura.
|
|
@@ -85,9 +81,6 @@ export var BuiltInNetworkName;
|
|
|
85
81
|
BuiltInNetworkName["PolygonMainnet"] = "polygon-mainnet";
|
|
86
82
|
BuiltInNetworkName["SeiMainnet"] = "sei-mainnet";
|
|
87
83
|
BuiltInNetworkName["MegaETHMainnet"] = "megaeth-mainnet";
|
|
88
|
-
BuiltInNetworkName["MonadMainnet"] = "monad-mainnet";
|
|
89
|
-
BuiltInNetworkName["AvalancheMainnet"] = "avalanche-mainnet";
|
|
90
|
-
BuiltInNetworkName["ZksyncMainnet"] = "zksync-mainnet";
|
|
91
84
|
})(BuiltInNetworkName || (BuiltInNetworkName = {}));
|
|
92
85
|
/**
|
|
93
86
|
* Decimal string chain IDs of built-in networks, by name.
|
|
@@ -115,9 +108,6 @@ export const ChainId = {
|
|
|
115
108
|
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
|
|
116
109
|
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)
|
|
117
110
|
[BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)
|
|
118
|
-
[BuiltInNetworkName.MonadMainnet]: '0x8f', // toHex(143)
|
|
119
|
-
[BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)
|
|
120
|
-
[BuiltInNetworkName.ZksyncMainnet]: '0x144', // toHex(324)
|
|
121
111
|
};
|
|
122
112
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
123
113
|
export var NetworksTicker;
|
|
@@ -146,13 +136,6 @@ export var NetworksTicker;
|
|
|
146
136
|
NetworksTicker["optimism-mainnet"] = "ETH";
|
|
147
137
|
NetworksTicker["polygon-mainnet"] = "POL";
|
|
148
138
|
NetworksTicker["sei-mainnet"] = "SEI";
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
150
|
-
NetworksTicker["megaeth-mainnet"] = "ETH";
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
152
|
-
NetworksTicker["monad-mainnet"] = "MON";
|
|
153
|
-
NetworksTicker["avalanche-mainnet"] = "AVAX";
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
155
|
-
NetworksTicker["zksync-mainnet"] = "ETH";
|
|
156
139
|
NetworksTicker["rpc"] = "";
|
|
157
140
|
})(NetworksTicker || (NetworksTicker = {}));
|
|
158
141
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
@@ -175,10 +158,6 @@ export const BlockExplorerUrl = {
|
|
|
175
158
|
[BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',
|
|
176
159
|
[BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',
|
|
177
160
|
[BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',
|
|
178
|
-
[BuiltInNetworkName.MegaETHMainnet]: 'https://megaeth.blockscout.com',
|
|
179
|
-
[BuiltInNetworkName.MonadMainnet]: 'https://monadscan.com',
|
|
180
|
-
[BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',
|
|
181
|
-
[BuiltInNetworkName.ZksyncMainnet]: 'https://explorer.zksync.io',
|
|
182
161
|
};
|
|
183
162
|
export const NetworkNickname = {
|
|
184
163
|
[BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',
|
|
@@ -199,9 +178,5 @@ export const NetworkNickname = {
|
|
|
199
178
|
[BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',
|
|
200
179
|
[BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',
|
|
201
180
|
[BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',
|
|
202
|
-
[BuiltInNetworkName.MegaETHMainnet]: 'MegaETH Mainnet',
|
|
203
|
-
[BuiltInNetworkName.MonadMainnet]: 'Monad Mainnet',
|
|
204
|
-
[BuiltInNetworkName.AvalancheMainnet]: 'Avalanche Mainnet',
|
|
205
|
-
[BuiltInNetworkName.ZksyncMainnet]: 'ZKsync Era',
|
|
206
181
|
};
|
|
207
182
|
//# sourceMappingURL=types.mjs.map
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,aAAa;IAC5B,eAAe,EAAE,eAAe;IAChC,iBAAiB,EAAE,iBAAiB;IACpC,mBAAmB,EAAE,mBAAmB;IACxC,gBAAgB,EAAE,gBAAgB;CAC1B,CAAC;AAKX;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB;IACpC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;CACxB,CAAC;AASX;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,iBAAiB;IACpB,GAAG,iBAAiB;IACpB,GAAG,EAAE,KAAK;CACF,CAAC;AAIX;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;GAM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ura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n 'monad-mainnet': 'monad-mainnet',\n 'megaeth-mainnet': 'megaeth-mainnet',\n 'avalanche-mainnet': 'avalanche-mainnet',\n 'zksync-mainnet': 'zksync-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n MegaETHMainnet = 'megaeth-mainnet',\n MonadMainnet = 'monad-mainnet',\n AvalancheMainnet = 'avalanche-mainnet',\n ZksyncMainnet = 'zksync-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n [BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)\n [BuiltInNetworkName.MonadMainnet]: '0x8f', // toHex(143)\n [BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)\n [BuiltInNetworkName.ZksyncMainnet]: '0x144', // toHex(324)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'monad-mainnet' = 'MON',\n 'avalanche-mainnet' = 'AVAX',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'zksync-mainnet' = 'ETH',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',\n [BuiltInNetworkName.MegaETHMainnet]: 'https://megaeth.blockscout.com',\n [BuiltInNetworkName.MonadMainnet]: 'https://monadscan.com',\n [BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',\n [BuiltInNetworkName.ZksyncMainnet]: 'https://explorer.zksync.io',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n [BuiltInNetworkName.MegaETHMainnet]: 'MegaETH Mainnet',\n [BuiltInNetworkName.MonadMainnet]: 'Monad Mainnet',\n [BuiltInNetworkName.AvalancheMainnet]: 'Avalanche Mainnet',\n [BuiltInNetworkName.ZksyncMainnet]: 'ZKsync Era',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,aAAa;CACpB,CAAC;AAKX;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB;IACpC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;CACxB,CAAC;AASX;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,iBAAiB;IACpB,GAAG,iBAAiB;IACpB,GAAG,EAAE,KAAK;CACF,CAA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AY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,OAAO;IAC1C;;OAEG;IACH,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,cAAc;IACnD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,iBAAiB;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,kBAAkB;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;CACO,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n MegaETHMainnet = 'megaeth-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n [BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
package/package.json
CHANGED