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

@aztec/foundation

Package Overview
Dependencies
Maintainers
6
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aztec/foundation - npm Package Compare versions

Comparing version 0.1.0-alpha40 to 0.1.0-alpha41

2

dest/json-rpc/client/index.d.ts

@@ -1,2 +0,2 @@

export { createJsonRpcClient, mustSucceedFetch, defaultFetch } from './json_rpc_client.js';
export { createJsonRpcClient, mustSucceedFetch, mustSucceedFetchUnlessNoRetry, defaultFetch, makeFetch, } from './json_rpc_client.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

export { createJsonRpcClient, mustSucceedFetch, defaultFetch } from './json_rpc_client.js';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvanNvbi1ycGMvY2xpZW50L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxtQkFBbUIsRUFBRSxnQkFBZ0IsRUFBRSxZQUFZLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQyJ9
export { createJsonRpcClient, mustSucceedFetch, mustSucceedFetchUnlessNoRetry, defaultFetch, makeFetch, } from './json_rpc_client.js';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvanNvbi1ycGMvY2xpZW50L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxtQkFBbUIsRUFDbkIsZ0JBQWdCLEVBQ2hCLDZCQUE2QixFQUM3QixZQUFZLEVBQ1osU0FBUyxHQUNWLE1BQU0sc0JBQXNCLENBQUMifQ==
import { RemoteObject } from 'comlink';
import { DebugLogger } from '../../log/index.js';
import { JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';

@@ -10,5 +11,7 @@ export { JsonStringify } from '../convert.js';

* @param body - The RPC payload.
* @param noRetry - Whether to throw a `NoRetryError` in case the response is not ok and the body contains an error
* message (see `retry` function for more details).
* @returns The parsed JSON response, or throws an error.
*/
export declare function defaultFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean): Promise<any>;
export declare function defaultFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean, noRetry?: boolean): Promise<any>;
/**

@@ -19,2 +22,14 @@ * A fetch function with retries.

/**
* Makes a fetch function that retries based on the given attempts.
* @param retries - Sequence of intervals (in seconds) to retry.
* @param noRetry - Whether to stop retries on server errors.
* @param log - Optional logger for logging attempts.
* @returns A fetch function.
*/
export declare function makeFetch(retries: number[], noRetry: boolean, log?: DebugLogger): (host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) => Promise<any>;
/**
* A fetch function with retries unless the error is a NoRetryError.
*/
export declare function mustSucceedFetchUnlessNoRetry(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean): Promise<any>;
/**
* Creates a Proxy object that delegates over RPC and satisfies RemoteObject<T>.

@@ -21,0 +36,0 @@ * The server should have ran new JsonRpcServer().

import { createDebugLogger } from '../../log/index.js';
import { retry } from '../../retry/index.js';
import { NoRetryError, makeBackoff, retry } from '../../retry/index.js';
import { ClassConverter } from '../class_converter.js';

@@ -13,5 +13,7 @@ import { JsonStringify, convertFromJsonObj, convertToJsonObj } from '../convert.js';

* @param body - The RPC payload.
* @param noRetry - Whether to throw a `NoRetryError` in case the response is not ok and the body contains an error
* message (see `retry` function for more details).
* @returns The parsed JSON response, or throws an error.
*/
export async function defaultFetch(host, rpcMethod, body, useApiEndpoints) {
export async function defaultFetch(host, rpcMethod, body, useApiEndpoints, noRetry = false) {
debug(`JsonRpcClient.fetch`, host, rpcMethod, '->', body);

@@ -33,11 +35,21 @@ let resp;

}
if (!resp.ok) {
throw new Error(resp.statusText);
}
let responseJson;
try {
return await resp.json();
responseJson = await resp.json();
}
catch (err) {
if (!resp.ok) {
throw new Error(resp.statusText);
}
throw new Error(`Failed to parse body as JSON: ${resp.text()}`);
}
if (!resp.ok) {
if (noRetry) {
throw new NoRetryError(responseJson.error);
}
else {
throw new Error(responseJson.error);
}
}
return responseJson;
}

@@ -51,2 +63,21 @@ /**

/**
* Makes a fetch function that retries based on the given attempts.
* @param retries - Sequence of intervals (in seconds) to retry.
* @param noRetry - Whether to stop retries on server errors.
* @param log - Optional logger for logging attempts.
* @returns A fetch function.
*/
export function makeFetch(retries, noRetry, log) {
return async (host, rpcMethod, body, useApiEndpoints) => {
return await retry(() => defaultFetch(host, rpcMethod, body, useApiEndpoints, noRetry), 'JsonRpcClient request', makeBackoff(retries), log);
};
}
/**
* A fetch function with retries unless the error is a NoRetryError.
*/
export async function mustSucceedFetchUnlessNoRetry(host, rpcMethod, body, useApiEndpoints) {
const noRetry = true;
return await retry(() => defaultFetch(host, rpcMethod, body, useApiEndpoints, noRetry), 'JsonRpcClient request');
}
/**
* Creates a Proxy object that delegates over RPC and satisfies RemoteObject<T>.

@@ -89,2 +120,2 @@ * The server should have ran new JsonRpcServer().

}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoianNvbl9ycGNfY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2pzb24tcnBjL2NsaWVudC9qc29uX3JwY19jbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBTUEsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDdkQsT0FBTyxFQUFFLEtBQUssRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQzdDLE9BQU8sRUFBRSxjQUFjLEVBQXNELE1BQU0sdUJBQXVCLENBQU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SSxFQUFFLEdBQUcsQ0FBQyxDQUFDO1FBQ2pELElBQUksR0FBRyxDQUFDLEtBQUssRUFBRTtZQUNiLE1BQU0sR0FBRyxDQUFDLEtBQUssQ0FBQztTQUNqQjtRQUNELElBQUksQ0FBQyxJQUFJLEVBQUUsU0FBUyxFQUFFLE1BQU0sRUFBRSxXQUFXLENBQUMsQ0FBQyxRQUFRLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxFQUFFO1lBQy9ELE9BQU87U0FDUjtRQUNELE9BQU8sa0JBQWtCLENBQUMsY0FBYyxFQUFFLEdBQUcsQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUN4RCxDQUFDLENBQUM7SUFFRix5Q0FBeUM7SUFDekMseURBQXlEO0lBQ3pELE9BQU8sSUFBSSxLQUFLLENBQ2QsRUFBRSxFQUNGO1FBQ0UsR0FBRyxFQUFFLENBQUMsTUFBTSxFQUFFLFNBQWlCLEVBQUUsRUFBRTtZQUNqQyxJQUFJLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxDQUFDLFFBQVEsQ0FBQyxTQUFTLENBQUM7Z0JBQUUsT0FBTyxPQUFPLENBQUMsR0FBRyxDQUFDLE1BQU0sRUFBRSxTQUFTLENBQUMsQ0FBQztZQUNqRixPQUFPLENBQUMsR0FBRyxNQUFhLEVBQUUsRUFBRTtnQkFDMUIsS0FBSyxDQUFDLDJCQUEyQixFQUFFLE9BQU8sRUFBRSxTQUFTLEVBQUUsSUFBSSxFQUFFLE1BQU0sQ0FBQyxDQUFDO2dCQUNyRSxPQUFPLE9BQU8sQ0FBQyxTQUFTLEVBQUUsTUFBTSxDQUFDLENBQUM7WUFDcEMsQ0FBQyxDQUFDO1FBQ0osQ0FBQztLQUNGLENBQ2lCLENBQUM7QUFDdkIsQ0FBQyJ9

@@ -71,9 +71,17 @@ import cors from '@koa/cors';

const { params = [], jsonrpc, id } = ctx.request.body;
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
try {
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
}
catch (err) {
// Propagate the error message to the client. Plenty of the errors are expected to occur (e.g. adding
// a duplicate recipient) so this is necessary.
ctx.status = 400;
ctx.body = { error: err.message };
}
});

@@ -93,9 +101,19 @@ }

}
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
else {
try {
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
}
catch (err) {
// Propagate the error message to the client. Plenty of the errors are expected to occur (e.g. adding
// a duplicate recipient) so this is necessary.
ctx.status = 400;
ctx.body = { error: err.message };
}
}
});

@@ -115,2 +133,2 @@ }

}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoianNvbl9ycGNfc2VydmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2pzb24tcnBjL3NlcnZlci9qc29uX3JwY19zZXJ2ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxJQUFJLE1BQU0sV0FBVyxDQUFDO0FBQzdCLE9BQU8sSUFBSSxNQUFNLE1BQU0sQ0FBQztBQUN4QixPQUFPLEdBQUcsTUFBTSxLQUFLLENBQUM7QUFDdEIsT0FBTyxVQUFVLE1BQU0sZ0JBQWdCLENBQUM7QUFDeEMsT0FBTyxRQUFRLE1BQU0sY0FBYyxDQUFDO0FBQ3BDLE9BQU8sTUFBTSxNQUFNLFlBQVksQ0FBQztBQUVoQyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV2RCxPQUFPLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDcEQsT0FBTyxFQUF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RSxDQUFDO2lCQUN4RDtxQkFBTTtvQkFDTCxJQUFJO3dCQUNGLE1BQU0sTUFBTSxHQUFHLE1BQU0sSUFBSSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLE1BQU0sQ0FBQyxDQUFDO3dCQUVyRCxHQUFHLENBQUMsSUFBSSxHQUFHOzRCQUNULE9BQU87NEJBQ1AsRUFBRTs0QkFDRixNQUFNLEVBQUUsbUJBQW1CLENBQUMsTUFBTSxDQUFDO3lCQUNwQyxDQUFDO3dCQUNGLEdBQUcsQ0FBQyxNQUFNLEdBQUcsR0FBRyxDQUFDO3FCQUNsQjtvQkFBQyxPQUFPLEdBQVEsRUFBRTt3QkFDakIscUdBQXFHO3dCQUNyRywrQ0FBK0M7d0JBQy9DLEdBQUcsQ0FBQyxNQUFNLEdBQUcsR0FBRyxDQUFDO3dCQUNqQixHQUFHLENBQUMsSUFBSSxHQUFHLEVBQUUsS0FBSyxFQUFFLEdBQUcsQ0FBQyxPQUFPLEVBQUUsQ0FBQztxQkFDbkM7aUJBQ0Y7WUFDSCxDQUFDLENBQUMsQ0FBQztTQUNKO1FBRUQsT0FBTyxNQUFNLENBQUM7SUFDaEIsQ0FBQztJQUVEOzs7O09BSUc7SUFDSSxLQUFLLENBQUMsSUFBWSxFQUFFLE1BQU0sR0FBRyxFQUFFO1FBQ3BDLE1BQU0sVUFBVSxHQUFHLElBQUksQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFDO1FBQ3JFLFVBQVUsQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDMUIsQ0FBQztDQUNGIn0=

@@ -0,1 +1,4 @@

/** An error that indicates that the operation should not be retried. */
export declare class NoRetryError extends Error {
}
/**

@@ -11,2 +14,8 @@ * Generates a backoff sequence for retrying operations with an increasing delay.

/**
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
* @param retries - Intervals to retry (in seconds).
* @returns A generator sequence.
*/
export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
/**
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.

@@ -20,2 +29,3 @@ * It logs the error and retry interval in case an error is caught. The function can be named for better log output.

* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
*/

@@ -22,0 +32,0 @@ export declare function retry<Result>(fn: () => Promise<Result>, name?: string, backoff?: Generator<number, void, unknown>, log?: import("../log/logger.js").DebugLogger): Promise<Result>;

import { createDebugLogger } from '../log/index.js';
import { sleep } from '../sleep/index.js';
import { Timer } from '../timer/index.js';
/** An error that indicates that the operation should not be retried. */
export class NoRetryError extends Error {
}
/**

@@ -20,2 +23,12 @@ * Generates a backoff sequence for retrying operations with an increasing delay.

/**
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
* @param retries - Intervals to retry (in seconds).
* @returns A generator sequence.
*/
export function* makeBackoff(retries) {
for (const retry of retries) {
yield retry;
}
}
/**
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.

@@ -29,2 +42,3 @@ * It logs the error and retry interval in case an error is caught. The function can be named for better log output.

* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
*/

@@ -37,2 +51,6 @@ export async function retry(fn, name = 'Operation', backoff = backoffGenerator(), log = createDebugLogger('aztec:foundation:retry')) {

catch (err) {
if (err instanceof NoRetryError) {
// A special error that indicates that the operation should not be retried. Rethrow it.
throw err;
}
const s = backoff.next().value;

@@ -73,2 +91,2 @@ if (s === undefined) {

}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcmV0cnkvaW5kZX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UFDLFFBQVEsR0FBRyxJQUFJLENBQUMsQ0FBQztRQUU3QixJQUFJLE9BQU8sSUFBSSxLQUFLLENBQUMsQ0FBQyxFQUFFLEdBQUcsT0FBTyxFQUFFO1lBQ2xDLE1BQU0sSUFBSSxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxvQkFBb0IsSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFDLFNBQVMsQ0FBQyxDQUFDO1NBQ2hFO0tBQ0Y7QUFDSCxDQUFDIn0=
{
"name": "@aztec/foundation",
"version": "0.1.0-alpha40",
"version": "0.1.0-alpha41",
"exports": {

@@ -5,0 +5,0 @@ "./eslint": "./.eslintrc.cjs",

@@ -1,1 +0,7 @@

export { createJsonRpcClient, mustSucceedFetch, defaultFetch } from './json_rpc_client.js';
export {
createJsonRpcClient,
mustSucceedFetch,
mustSucceedFetchUnlessNoRetry,
defaultFetch,
makeFetch,
} from './json_rpc_client.js';

@@ -7,4 +7,4 @@ // comlink:

import { createDebugLogger } from '../../log/index.js';
import { retry } from '../../retry/index.js';
import { DebugLogger, createDebugLogger } from '../../log/index.js';
import { NoRetryError, makeBackoff, retry } from '../../retry/index.js';
import { ClassConverter, JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';

@@ -22,5 +22,13 @@ import { JsonStringify, convertFromJsonObj, convertToJsonObj } from '../convert.js';

* @param body - The RPC payload.
* @param noRetry - Whether to throw a `NoRetryError` in case the response is not ok and the body contains an error
* message (see `retry` function for more details).
* @returns The parsed JSON response, or throws an error.
*/
export async function defaultFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) {
export async function defaultFetch(
host: string,
rpcMethod: string,
body: any,
useApiEndpoints: boolean,
noRetry = false,
) {
debug(`JsonRpcClient.fetch`, host, rpcMethod, '->', body);

@@ -42,11 +50,20 @@ let resp: Response;

if (!resp.ok) {
throw new Error(resp.statusText);
}
let responseJson;
try {
return await resp.json();
responseJson = await resp.json();
} catch (err) {
if (!resp.ok) {
throw new Error(resp.statusText);
}
throw new Error(`Failed to parse body as JSON: ${resp.text()}`);
}
if (!resp.ok) {
if (noRetry) {
throw new NoRetryError(responseJson.error);
} else {
throw new Error(responseJson.error);
}
}
return responseJson;
}

@@ -62,2 +79,33 @@

/**
* Makes a fetch function that retries based on the given attempts.
* @param retries - Sequence of intervals (in seconds) to retry.
* @param noRetry - Whether to stop retries on server errors.
* @param log - Optional logger for logging attempts.
* @returns A fetch function.
*/
export function makeFetch(retries: number[], noRetry: boolean, log?: DebugLogger) {
return async (host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) => {
return await retry(
() => defaultFetch(host, rpcMethod, body, useApiEndpoints, noRetry),
'JsonRpcClient request',
makeBackoff(retries),
log,
);
};
}
/**
* A fetch function with retries unless the error is a NoRetryError.
*/
export async function mustSucceedFetchUnlessNoRetry(
host: string,
rpcMethod: string,
body: any,
useApiEndpoints: boolean,
) {
const noRetry = true;
return await retry(() => defaultFetch(host, rpcMethod, body, useApiEndpoints, noRetry), 'JsonRpcClient request');
}
/**
* Creates a Proxy object that delegates over RPC and satisfies RemoteObject<T>.

@@ -64,0 +112,0 @@ * The server should have ran new JsonRpcServer().

@@ -83,9 +83,16 @@ import cors from '@koa/cors';

const { params = [], jsonrpc, id } = ctx.request.body as any;
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
try {
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
} catch (err: any) {
// Propagate the error message to the client. Plenty of the errors are expected to occur (e.g. adding
// a duplicate recipient) so this is necessary.
ctx.status = 400;
ctx.body = { error: err.message };
}
});

@@ -105,11 +112,19 @@ }

ctx.body = { error: `Invalid method name: ${method}` };
} else {
try {
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
} catch (err: any) {
// Propagate the error message to the client. Plenty of the errors are expected to occur (e.g. adding
// a duplicate recipient) so this is necessary.
ctx.status = 400;
ctx.body = { error: err.message };
}
}
const result = await this.proxy.call(method, params);
ctx.body = {
jsonrpc,
id,
result: convertBigintsInObj(result),
};
ctx.status = 200;
});

@@ -116,0 +131,0 @@ }

@@ -5,2 +5,5 @@ import { createDebugLogger } from '../log/index.js';

/** An error that indicates that the operation should not be retried. */
export class NoRetryError extends Error {}
/**

@@ -23,2 +26,13 @@ * Generates a backoff sequence for retrying operations with an increasing delay.

/**
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
* @param retries - Intervals to retry (in seconds).
* @returns A generator sequence.
*/
export function* makeBackoff(retries: number[]) {
for (const retry of retries) {
yield retry;
}
}
/**
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.

@@ -32,2 +46,3 @@ * It logs the error and retry interval in case an error is caught. The function can be named for better log output.

* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
*/

@@ -44,2 +59,6 @@ export async function retry<Result>(

} catch (err: any) {
if (err instanceof NoRetryError) {
// A special error that indicates that the operation should not be retried. Rethrow it.
throw err;
}
const s = backoff.next().value;

@@ -46,0 +65,0 @@ if (s === undefined) {

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

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