Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@layerzerolabs/devtools

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@layerzerolabs/devtools - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

96

dist/index.d.ts

@@ -187,4 +187,98 @@ import { EndpointId } from '@layerzerolabs/lz-definitions';

declare const firstFactory: <TInput extends unknown[], TOutput>(...factories: Factory<TInput, TOutput>[]) => Factory<TInput, TOutput>;
/**
* RetryStrategy represents a function that, when passed to `createRetryFactory`,
* controls the execution of a retried function.
*
* It will be executed on every failed attempt and has the ability to modify the
* input originally passed to the retried function.
*
* In its simplest form, it will either return `true` (to retry again) or `false` (stop retrying).
*
* In its advanced form, it can use the parameters passed to it to create
* a new set of arguments passed to the function being retried:
*
* ```
* // As a simple example let's consider a function
* // whose argument is the amount of money we want to pay for a service
* const functionThatCanFail = (money: number): Promise<void> => { ... }
*
* // We can create a strategy that will keep adding 1 to the amount of money
* const strategy: RetryStrategy<[money: number]> = (attempt, error, [previousMoney], [originalMoney]) => [previousMoney + 1]
*
* // Or we can create a strategy that will adjust the money based on the initial value
* //
* // In this made up case it will take the original amount and will add 2 for every failed attempt
* const strategy: RetryStrategy<[money: number]> = (attempt, error, [previousMoney], [originalMoney]) => [originalMoney + attempt * 2]
*
* // Or we can go insane with our logic and can, because without objective morality
* // everything is permissible, update the amount on every other attempt
* const strategy: RetryStrategy<[money: number]> = (attempt, error, [previousMoney], [originalMoney]) => attempt % 2 ? [previousMoney + 1] : true
* ```
*
* @param {number} attempt The 0-indexed attempt that the retry function is performing
* @param {unknown} error The error thrown from the previous execution of the retried function
* @param {TInput} previousInput The input passed to the previous execution of the retried function
* @param {TInput} originalInput The input passed to the first execution of the retried function
*/
type RetryStrategy<TInput extends unknown[]> = Factory<[
attempt: number,
error: unknown,
previousInput: TInput,
originalInput: TInput
], TInput | boolean>;
/**
* Uses the retry strategy to create a function that can wrap any function with retry logic.
*
* ```
* // As a simple example let's consider a function
* // whose argument is the amount of money we want to pay for a service
* const functionThatCanFail = (money: number): Promise<void> => { ... }
*
* // By default, it will use a three-times-and-fail retry strategy
* const retry = createRetryFactory()
*
* // It can wrap any function (sync or async) that can throw or reject
* const retriedFunctionThatCanFail = retry(functionThatCanFail)
*
* // The function can then be called just like the original, wrapped function
* retriedFunctionThatCanFail(1_000_000)
*
* // For advanced cases, you can use your own strategy
* const strategy: RetryStrategy<[money: number]> = () => { ... }
* const retry = createRetryFactory(strategy)
* ```
*
* @see {@link createSimpleRetryStrategy}
* @see {@link RetryStrategy}
*
* @param {RetryStrategy<TInput>} [strategy] `RetryStrategy` to use. Defaults to a simple strategy that retries three times
* @returns {<TOutput>(task: Factory<TInput, TOutput>) => Factory<TInput, TOutput>}
*/
declare const createRetryFactory: <TInput extends unknown[]>(strategy?: RetryStrategy<TInput>) => <TOutput>(task: Factory<TInput, TOutput>) => Factory<TInput, TOutput>;
/**
* Creates a simple `RetryStrategy` that will retry N times.
*
* If you want to compose this strategy, you can pass `wrappedStrategy`:
*
* ```
* const myVeryAdvancedStrategy: RetryStrategy<[string, number]> = () => { ... }
* const myVeryAdvancedStrategyThatWillRetryThreeTimesOnly = createSimpleRetryStrategy(3, myVeryAdvancedStrategy)
* ```
*
* @param {number} numAttempts Must be larger than 0
* @param {RetryStrategy<TInput>} [wrappedStrategy] Strategy to use if the number of attempts has not been reached yet
* @returns {RetryStrategy<TInput>}
*/
declare const createSimpleRetryStrategy: <TInput extends unknown[]>(numAttempts: number, wrappedStrategy?: RetryStrategy<TInput> | undefined) => RetryStrategy<TInput>;
/**
* Splits a comma-separated string into individual values
* and discards any whitespace.
*
* @param {string} value
* @returns {string[]}
*/
declare const splitCommaSeparated: (value: string) => string[];
/**
* OmniPoint identifies a point in omniverse, an omnichain universe.

@@ -503,2 +597,2 @@ *

export { AddressSchema, type Bytes, type Bytes20, type Bytes32, EmptyOmniEdgeSchema, EmptyOmniNodeSchema, type EndpointBasedFactory, EndpointIdSchema, type Factory, type IOmniSDK, type OmniAddress, type OmniEdge, type OmniError, type OmniGraph, OmniGraphBuilder, type OmniNode, type OmniPoint, OmniPointMap, OmniPointSchema, type OmniSigner, type OmniSignerFactory, type OmniTransaction, type OmniTransactionReceipt, type OmniTransactionResponse, type OmniTransactionWithError, type OmniTransactionWithReceipt, type OmniTransactionWithResponse, type OmniVector, OmniVectorMap, OmniVectorSchema, type PossiblyBigInt, type PossiblyBytes, type SignAndSendResult, UIntBigIntSchema, UIntNumberSchema, type WithEid, type WithLooseBigInts, type WithOptionals, areBytes32Equal, arePointsEqual, areSameEndpoint, areVectorsEqual, compareBytes32Ascending, createOmniEdgeSchema, createOmniGraphSchema, createOmniNodeSchema, createSignAndSend, first, firstFactory, flattenTransactions, formatEid, formatOmniPoint, formatOmniTransaction, formatOmniVector, ignoreZero, isDeepEqual, isOmniGraphEmpty, isOmniPoint, isVectorPossible, isZero, makeBytes32, parallel, sequence, serializePoint, serializeVector, vectorFromNodes };
export { AddressSchema, type Bytes, type Bytes20, type Bytes32, EmptyOmniEdgeSchema, EmptyOmniNodeSchema, type EndpointBasedFactory, EndpointIdSchema, type Factory, type IOmniSDK, type OmniAddress, type OmniEdge, type OmniError, type OmniGraph, OmniGraphBuilder, type OmniNode, type OmniPoint, OmniPointMap, OmniPointSchema, type OmniSigner, type OmniSignerFactory, type OmniTransaction, type OmniTransactionReceipt, type OmniTransactionResponse, type OmniTransactionWithError, type OmniTransactionWithReceipt, type OmniTransactionWithResponse, type OmniVector, OmniVectorMap, OmniVectorSchema, type PossiblyBigInt, type PossiblyBytes, type SignAndSendResult, UIntBigIntSchema, UIntNumberSchema, type WithEid, type WithLooseBigInts, type WithOptionals, areBytes32Equal, arePointsEqual, areSameEndpoint, areVectorsEqual, compareBytes32Ascending, createOmniEdgeSchema, createOmniGraphSchema, createOmniNodeSchema, createRetryFactory, createSignAndSend, createSimpleRetryStrategy, first, firstFactory, flattenTransactions, formatEid, formatOmniPoint, formatOmniTransaction, formatOmniVector, ignoreZero, isDeepEqual, isOmniGraphEmpty, isOmniPoint, isVectorPossible, isZero, makeBytes32, parallel, sequence, serializePoint, serializeVector, splitCommaSeparated, vectorFromNodes };
'use strict';
var assert2 = require('assert');
var assert = require('assert');
var bytes = require('@ethersproject/bytes');
var exponentialBackoff = require('exponential-backoff');
var lzDefinitions = require('@layerzerolabs/lz-definitions');

@@ -11,3 +12,3 @@ var zod = require('zod');

var assert2__default = /*#__PURE__*/_interopDefault(assert2);
var assert__default = /*#__PURE__*/_interopDefault(assert);

@@ -39,3 +40,3 @@ var __defProp = Object.defineProperty;

try {
return assert2.deepStrictEqual(a, b), true;
return assert.deepStrictEqual(a, b), true;
} catch (e) {

@@ -59,3 +60,3 @@ return false;

var first = async (tasks) => {
assert2__default.default(tasks.length !== 0, `Must have at least one task for first()`);
assert__default.default(tasks.length !== 0, `Must have at least one task for first()`);
let lastError;

@@ -72,2 +73,37 @@ for (const task of tasks) {

var firstFactory = (...factories) => async (...input) => await first(factories.map((factory) => () => factory(...input)));
var createRetryFactory = (strategy = createSimpleRetryStrategy(3)) => (task) => async (...input) => {
let currentInput = input;
return exponentialBackoff.backOff(async () => task(...currentInput), {
// We'll effectively disable the numOfAttempts for exponential backoff
// since we want the behavior to be completely controlled by the strategy
numOfAttempts: Number.POSITIVE_INFINITY,
// The retry callback is called after an unsuccessful attemp
//
// It allows us to decide whether we want to keep trying or give up
// (we can give up by returning false)
//
// We'll use this callback to allow the strategy to effectively make changes
// to the input, thus allowing it to accommodate for things such as gas price increase
// for transactions
async retry(error, attempt) {
const strategyOutput = await strategy(attempt, error, currentInput, input);
if (typeof strategyOutput === "boolean")
return strategyOutput;
return currentInput = strategyOutput, true;
}
});
};
var createSimpleRetryStrategy = (numAttempts, wrappedStrategy) => {
assert__default.default(numAttempts > 0, `Number of attempts for a strategy must be larger than 0`);
return (attempt, error, previousInput, originalInput) => {
if (attempt > numAttempts)
return false;
if (wrappedStrategy == null)
return true;
return wrappedStrategy(attempt, error, previousInput, originalInput);
};
};
// src/common/strings.ts
var splitCommaSeparated = (value) => value.trim().split(/\s*,\s*/).filter(Boolean);
var arePointsEqual = (a, b) => a.address === b.address && a.eid === b.eid;

@@ -265,4 +301,4 @@ var areSameEndpoint = (a, b) => a.eid === b.eid;

const from = formatOmniPoint(edge.vector.from);
assert2__default.default(isVectorPossible(edge.vector), `Cannot add edge ${label}: cannot connect the two endpoints`);
assert2__default.default(this.getNodeAt(edge.vector.from), `Cannot add edge ${label}: ${from} is not in the graph`);
assert__default.default(isVectorPossible(edge.vector), `Cannot add edge ${label}: cannot connect the two endpoints`);
assert__default.default(this.getNodeAt(edge.vector.from), `Cannot add edge ${label}: ${from} is not in the graph`);
};

@@ -365,3 +401,5 @@ var OmniGraphBuilder = _OmniGraphBuilder;

exports.createOmniNodeSchema = createOmniNodeSchema;
exports.createRetryFactory = createRetryFactory;
exports.createSignAndSend = createSignAndSend;
exports.createSimpleRetryStrategy = createSimpleRetryStrategy;
exports.first = first;

@@ -385,4 +423,5 @@ exports.firstFactory = firstFactory;

exports.serializeVector = serializeVector;
exports.splitCommaSeparated = splitCommaSeparated;
exports.vectorFromNodes = vectorFromNodes;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map

9

package.json
{
"name": "@layerzerolabs/devtools",
"version": "0.1.1",
"version": "0.1.2",
"description": "Core utilities for working with LayerZero on-chain infrastructure",

@@ -24,6 +24,9 @@ "repository": {

],
"dependencies": {
"exponential-backoff": "~3.1.1"
},
"devDependencies": {
"@ethersproject/bytes": "~5.7.0",
"@ethersproject/constants": "~5.7.0",
"@layerzerolabs/io-devtools": "~0.1.0",
"@layerzerolabs/io-devtools": "~0.1.1",
"@layerzerolabs/lz-definitions": "~2.1.2",

@@ -45,3 +48,3 @@ "@layerzerolabs/test-devtools": "~0.1.1",

"@ethersproject/bytes": "~5.7.0",
"@layerzerolabs/io-devtools": "~0.1.0",
"@layerzerolabs/io-devtools": "~0.1.1",
"@layerzerolabs/lz-definitions": "~2.1.2",

@@ -48,0 +51,0 @@ "zod": "^3.22.4"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc