Skip to content

Commit

Permalink
fix(deps): remove axios-retry, will implement later
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 14, 2024
1 parent e9eaa2d commit 0218e95
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 50 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"dependencies": {
"arweave": "^1.14.4",
"axios": "1.4.0",
"axios-retry": "3.7.0",
"warp-contracts": "^1.4.34",
"winston": "^3.11.0"
}
Expand Down
10 changes: 6 additions & 4 deletions src/common/ArIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export class ArIO implements ContractStateProvider {
* Fetches the state of a contract.
* @param {string} contractTxId - The Arweave transaction id of the contract.
*/
async getContractState<ContractState>(
contractTxId: string,
): Promise<ContractState> {
return this.contractStateProvider.getContractState(contractTxId);
async getContractState<ContractState>({
contractTxId,
}: {
contractTxId: string;
}): Promise<ContractState> {
return this.contractStateProvider.getContractState({ contractTxId });
}
}
22 changes: 6 additions & 16 deletions src/common/ContractStateProviders/ArNSRemoteCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import axios, { AxiosInstance } from 'axios';
import axiosRetry from 'axios-retry';

import { RESPONSE_RETRY_CODES } from '../../constants.js';
import { ContractStateProvider } from '../../types.js';
import { validateArweaveId } from '../../utils/index.js';
import { BadRequest } from '../error.js';
Expand All @@ -41,24 +39,16 @@ export class ArNSRemoteCache implements ContractStateProvider {
version?: string;
}) {
this.logger = logger;
const arnsServiceClient = axios.create({
this.http = axios.create({
baseURL: `${protocol}://${url}/${version}`,
});
this.http = axiosRetry(arnsServiceClient, {
retries: 3,
retryDelay: axiosRetry.exponentialDelay,
retryCondition: (error) => {
this.logger.debug(`Retrying request. Error: ${error}`);
return (
!!error.response && RESPONSE_RETRY_CODES.has(error.response.status)
);
},
}) as unknown as AxiosInstance;
}

async getContractState<ContractState>(
contractTxId: string,
): Promise<ContractState> {
async getContractState<ContractState>({
contractTxId,
}: {
contractTxId: string;
}): Promise<ContractState> {
if (!validateArweaveId(contractTxId)) {
throw new BadRequest(`Invalid contract id: ${contractTxId}`);
}
Expand Down
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
*/

export const ARWEAVE_TX_REGEX = new RegExp('^[a-zA-Z0-9_-]{43}$');
export const RESPONSE_RETRY_CODES = new Set([429, 503]);
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ContractStateProvider {
/**
* The ContractStateProvider interface is used to define a contract state provider.
*/
getContractState<T>(contractId: string): Promise<T>;
getContractState<T>({ contractTxId }: { contractTxId: string }): Promise<T>;
}
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface Logger {
Expand Down
4 changes: 2 additions & 2 deletions tests/ArNSRemoteCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ describe('ArIO Client', () => {
const stubGetContractState = jest.fn();
remoteProvider.getContractState = stubGetContractState;
const contractTxId = ''.padEnd(43, 'a');
await client.getContractState(contractTxId);
await client.getContractState({ contractTxId });
expect(stubGetContractState).toHaveBeenCalledWith(contractTxId);
});

it('should call remote state provider and throw on bad contract id', async () => {
const contractTxId = ''.padEnd(42, 'a');
const result = await arioClient
.getContractState(contractTxId)
.getContractState({ contractTxId })
.catch((e) => e);

expect(result).toBeInstanceOf(BadRequest);
Expand Down
25 changes: 0 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,6 @@
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"

"@babel/runtime@^7.15.4":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.9.tgz#47791a15e4603bb5f905bc0753801cf21d6345f7"
integrity sha512-0CX6F+BI2s9dkUqr08KFrAIZgNFj75rdBU/DjCyYLIaV/quFjkk6T+EJ2LkZHyZTbEV4L5p97mNkUsHl2wLFAw==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/template@^7.22.15", "@babel/template@^7.23.9", "@babel/template@^7.3.3":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.23.9.tgz#f881d0487cba2828d3259dcb9ef5005a9731011a"
Expand Down Expand Up @@ -2239,14 +2232,6 @@ available-typed-arrays@^1.0.5, available-typed-arrays@^1.0.6:
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.6.tgz#ac812d8ce5a6b976d738e1c45f08d0b00bc7d725"
integrity sha512-j1QzY8iPNPG4o4xmO3ptzpRxTciqD3MgEHtifP/YnJpIo58Xu+ne4BejlbkuaLfXn/nz6HFiw29bLpj2PNMdGg==

axios-retry@3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.7.0.tgz#d5007755d257b97e08d846089976f838b9db9ef9"
integrity sha512-ZTnCkJbRtfScvwiRnoVskFAfvU0UG3xNcsjwTR0mawSbIJoothxn67gKsMaNAFHRXJ1RmuLhmZBzvyXi3+9WyQ==
dependencies:
"@babel/runtime" "^7.15.4"
is-retry-allowed "^2.2.0"

axios@1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f"
Expand Down Expand Up @@ -4867,11 +4852,6 @@ is-regex@^1.1.4:
call-bind "^1.0.2"
has-tostringtag "^1.0.0"

is-retry-allowed@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-2.2.0.tgz#88f34cbd236e043e71b6932d09b0c65fb7b4d71d"
integrity sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==

is-shared-array-buffer@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz#8f259c573b60b6a32d4058a1a07430c0a7344c79"
Expand Down Expand Up @@ -7341,11 +7321,6 @@ redeyed@~2.1.0:
dependencies:
esprima "~4.0.0"

regenerator-runtime@^0.14.0:
version "0.14.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f"
integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==

regexp.prototype.flags@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz#138f644a3350f981a858c44f6bb1a61ff59be334"
Expand Down

0 comments on commit 0218e95

Please sign in to comment.