Skip to content

Commit

Permalink
fix(ario): add cache config in ario constructor (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 28, 2024
2 parents c46cd39 + 1f3c0ba commit ecb279d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ yarn add @ar-io/sdk
```typescript
import { ArIO } from '@ar-io/sdk';

const arIO = new ArIO({});
const arIO = new ArIO();
const gateways = arIO.testnet.getGateways();
```

Expand All @@ -52,7 +52,7 @@ The SDK is provided in both CommonJS and ESM formats, and it's compatible with b
```javascript
import { ArIO } from '@ar-io/sdk';

const arIO = new ArIO({});
const arIO = new ArIO();
const gateways = arIO.mainnet.getGateways();
```

Expand All @@ -63,7 +63,7 @@ const gateways = arIO.mainnet.getGateways();
import { ArIO } from 'https://unpkg.com/@ar-io/sdk';
// set up our client
const arIO = new ArIO({});
const arIO = new ArIO();
// fetch mainnet gateways
const gateways = await arIO.mainnet.getGateways();
</script>
Expand All @@ -74,7 +74,7 @@ const gateways = arIO.mainnet.getGateways();
```javascript
const { ArIO } = require('@ar-io/sdk');

const arIO = new ArIO({});
const arIO = new ArIO();
const gateways = await arIO.mainnet.getGateways();
```

Expand All @@ -93,7 +93,7 @@ The contract that the following methods retrieve data from are determined by the
Retrieves the balance of the specified address.

```typescript
const balance = new ArIO({}).testnet.getBalance({
const balance = new ArIO().testnet.getBalance({
address: 'INSERT_WALLET_ADDRESS',
});
```
Expand All @@ -103,15 +103,15 @@ const balance = new ArIO({}).testnet.getBalance({
Retrieves the balances of the ArIO contract.

```typescript
const balances = new ArIO({}).testnet.getBalances();
const balances = new ArIO().testnet.getBalances();
```

#### `getGateway({ address })`

Retrieves the gateway info of the specified address.

```typescript
const gateway = new ArIO({}).testnet.getGateway({
const gateway = new ArIO().testnet.getGateway({
address: 'INSERT_GATEWAY_ADDRESS',
});
```
Expand All @@ -121,23 +121,23 @@ const gateway = new ArIO({}).testnet.getGateway({
Retrieves the registered gateways of the ArIO contract.

```typescript
const gateways = new ArIO({}).testnet.getGateways();
const gateways = new ArIO().testnet.getGateways();
```

#### `getRecord({ domain })`

Retrieves the domain info of the specified ArNS record.

```typescript
const record = new ArIO({}).testnet.getRecord({ domain: 'INSERT_ARNS_NAME' });
const record = new ArIO().testnet.getRecord({ domain: 'INSERT_ARNS_NAME' });
```

#### `getRecords()`

Retrieves the registered ArNS domains of the ArIO contract.

```typescript
const records = new ArIO({}).testnet.getRecords();
const records = new ArIO().testnet.getRecords();
```

## Developers
Expand Down
2 changes: 1 addition & 1 deletion examples/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
} = require('../../lib/cjs/node/index.js');

(async () => {
const arIO = new ArIO({});
const arIO = new ArIO();
// testnet gateways
const testnetGateways = await arIO.testnet.getGateways();
const protocolBalance = await arIO.testnet.getBalance({
Expand Down
2 changes: 1 addition & 1 deletion examples/node/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ARNS_TESTNET_REGISTRY_TX, ArIO } from '../../lib/esm/node/index.js';

(async () => {
const arIO = new ArIO({});
const arIO = new ArIO();
// testnet gateways
const testnetGateways = await arIO.testnet.getGateways();
const protocolBalance = await arIO.testnet.getBalance({
Expand Down
2 changes: 1 addition & 1 deletion examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h1 class="text-textPrimary w-full font-bold">Browse Records</h1>
import { ArIO } from './web.bundle.min.js';

// set up our client
const arIO = new ArIO({}).testnet;
const arIO = new ArIO().testnet;

// fetch data on page load
async function init() {
Expand Down
13 changes: 10 additions & 3 deletions src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ import {
import { ArIOContract } from '../types/index.js';
import { ArNSRemoteCache } from './index.js';

export type CacheConfiguration = {
remoteCacheUrl?: string;
};
export type ArIOConfiguration = {
cacheConfig?: CacheConfiguration;
};

export class ArIO {
public testnet: ArIOContract;
public devnet: ArIOContract;

constructor({ remoteCacheUrl }: { remoteCacheUrl?: string }) {
constructor({ cacheConfig }: ArIOConfiguration = {}) {
this.testnet = new ArNSRemoteCache({
contractTxId: ARNS_TESTNET_REGISTRY_TX,
url: remoteCacheUrl,
url: cacheConfig?.remoteCacheUrl,
});
this.devnet = new ArNSRemoteCache({
contractTxId: ARNS_DEVNET_REGISTRY_TX,
url: remoteCacheUrl,
url: cacheConfig?.remoteCacheUrl,
});
}
}
2 changes: 1 addition & 1 deletion tests/ar-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ArIO } from '../src/common/ar-io.js';

describe('ArIO Client', () => {
it('should create a custom ArIO client', () => {
const arioClient = new ArIO({});
const arioClient = new ArIO();

expect(arioClient).toBeInstanceOf(ArIO);
expect(arioClient.testnet).toBeDefined();
Expand Down

0 comments on commit ecb279d

Please sign in to comment.