@ar.io/sdk 1.2.0-alpha.2 → 1.2.0-alpha.4

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.
@@ -51,26 +51,43 @@ class AOProcess {
51
51
  };
52
52
  return aoSigner;
53
53
  }
54
- async read({ tags, }) {
55
- this.logger.debug(`Evaluating read interaction on contract`, {
56
- tags,
57
- });
58
- // map tags to inputs
59
- const result = await this.ao.dryrun({
60
- process: this.processId,
61
- tags,
62
- });
63
- if (result.Error !== undefined) {
64
- throw new Error(result.Error);
65
- }
66
- if (result.Messages.length === 0) {
67
- throw new Error('Process does not support provided action.');
54
+ async read({ tags, retries = 3, }) {
55
+ let attempts = 0;
56
+ let lastError;
57
+ while (attempts < retries) {
58
+ try {
59
+ this.logger.debug(`Evaluating read interaction on contract`, {
60
+ tags,
61
+ });
62
+ // map tags to inputs
63
+ const result = await this.ao.dryrun({
64
+ process: this.processId,
65
+ tags,
66
+ });
67
+ if (result.Error !== undefined) {
68
+ throw new Error(result.Error);
69
+ }
70
+ if (result.Messages.length === 0) {
71
+ throw new Error('Process does not support provided action.');
72
+ }
73
+ this.logger.debug(`Read interaction result`, {
74
+ result: result.Messages[0].Data,
75
+ });
76
+ const data = JSON.parse(result.Messages[0].Data);
77
+ return data;
78
+ }
79
+ catch (e) {
80
+ attempts++;
81
+ this.logger.debug(`Read attempt ${attempts} failed`, {
82
+ error: e,
83
+ tags,
84
+ });
85
+ lastError = e;
86
+ // exponential backoff
87
+ await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
88
+ }
68
89
  }
69
- this.logger.debug(`Read interaction result`, {
70
- result: result.Messages[0].Data,
71
- });
72
- const data = JSON.parse(result.Messages[0].Data);
73
- return data;
90
+ throw lastError;
74
91
  }
75
92
  async send({ tags, data, signer, }) {
76
93
  this.logger.debug(`Evaluating send interaction on contract`, {
@@ -480,6 +480,7 @@ class IOWriteable extends IOReadable {
480
480
  { name: 'Name', value: params.name },
481
481
  { name: 'Type', value: params.type },
482
482
  { name: 'Years', value: params.years?.toString() },
483
+ { name: 'ProcessId', value: params.processId },
483
484
  ];
484
485
  const prunedTags = allTags.filter((tag) => tag.value !== undefined);
485
486
  return this.process.send({
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.version = void 0;
20
20
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
21
- exports.version = '1.2.0-alpha.2';
21
+ exports.version = '1.2.0-alpha.4';
@@ -48,26 +48,43 @@ export class AOProcess {
48
48
  };
49
49
  return aoSigner;
50
50
  }
51
- async read({ tags, }) {
52
- this.logger.debug(`Evaluating read interaction on contract`, {
53
- tags,
54
- });
55
- // map tags to inputs
56
- const result = await this.ao.dryrun({
57
- process: this.processId,
58
- tags,
59
- });
60
- if (result.Error !== undefined) {
61
- throw new Error(result.Error);
62
- }
63
- if (result.Messages.length === 0) {
64
- throw new Error('Process does not support provided action.');
51
+ async read({ tags, retries = 3, }) {
52
+ let attempts = 0;
53
+ let lastError;
54
+ while (attempts < retries) {
55
+ try {
56
+ this.logger.debug(`Evaluating read interaction on contract`, {
57
+ tags,
58
+ });
59
+ // map tags to inputs
60
+ const result = await this.ao.dryrun({
61
+ process: this.processId,
62
+ tags,
63
+ });
64
+ if (result.Error !== undefined) {
65
+ throw new Error(result.Error);
66
+ }
67
+ if (result.Messages.length === 0) {
68
+ throw new Error('Process does not support provided action.');
69
+ }
70
+ this.logger.debug(`Read interaction result`, {
71
+ result: result.Messages[0].Data,
72
+ });
73
+ const data = JSON.parse(result.Messages[0].Data);
74
+ return data;
75
+ }
76
+ catch (e) {
77
+ attempts++;
78
+ this.logger.debug(`Read attempt ${attempts} failed`, {
79
+ error: e,
80
+ tags,
81
+ });
82
+ lastError = e;
83
+ // exponential backoff
84
+ await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
85
+ }
65
86
  }
66
- this.logger.debug(`Read interaction result`, {
67
- result: result.Messages[0].Data,
68
- });
69
- const data = JSON.parse(result.Messages[0].Data);
70
- return data;
87
+ throw lastError;
71
88
  }
72
89
  async send({ tags, data, signer, }) {
73
90
  this.logger.debug(`Evaluating send interaction on contract`, {
@@ -472,6 +472,7 @@ export class IOWriteable extends IOReadable {
472
472
  { name: 'Name', value: params.name },
473
473
  { name: 'Type', value: params.type },
474
474
  { name: 'Years', value: params.years?.toString() },
475
+ { name: 'ProcessId', value: params.processId },
475
476
  ];
476
477
  const prunedTags = allTags.filter((tag) => tag.value !== undefined);
477
478
  return this.process.send({
@@ -15,4 +15,4 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
18
- export const version = '1.2.0-alpha.2';
18
+ export const version = '1.2.0-alpha.4';
@@ -28,11 +28,12 @@ export declare class AOProcess implements AOContract {
28
28
  id: string;
29
29
  raw: ArrayBuffer;
30
30
  }>>;
31
- read<K>({ tags, }: {
31
+ read<K>({ tags, retries, }: {
32
32
  tags?: Array<{
33
33
  name: string;
34
34
  value: string;
35
35
  }>;
36
+ retries?: number;
36
37
  }): Promise<K>;
37
38
  send<I, K>({ tags, data, signer, }: {
38
39
  tags: Array<{
@@ -107,6 +107,7 @@ export declare class IOWriteable extends IOReadable implements AoIOWrite {
107
107
  name: string;
108
108
  years?: number;
109
109
  type: 'lease' | 'permabuy';
110
+ processId: string;
110
111
  }, options?: WriteOptions): Promise<AoMessageResult>;
111
112
  extendLease(params: {
112
113
  name: string;
package/lib/types/io.d.ts CHANGED
@@ -37,8 +37,12 @@ export type EpochInput = {
37
37
  timestamp: Timestamp;
38
38
  } | undefined;
39
39
  export interface AOContract {
40
- read<K>({ tags }: {
41
- tags: any;
40
+ read<K>({ tags, retries, }: {
41
+ tags?: {
42
+ name: string;
43
+ value: string;
44
+ }[];
45
+ retries?: number;
42
46
  }): Promise<K>;
43
47
  send<I, K>({ tags, data, signer, }: {
44
48
  tags: {
@@ -110,6 +114,7 @@ export interface AoIOWrite extends AoIORead {
110
114
  name: string;
111
115
  years?: number;
112
116
  type: 'lease' | 'permabuy';
117
+ processId: string;
113
118
  }, options?: WriteOptions): Promise<AoMessageResult>;
114
119
  extendLease(params: {
115
120
  name: string;
@@ -14,4 +14,4 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- export declare const version = "1.2.0-alpha.1";
17
+ export declare const version = "1.2.0-alpha.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0-alpha.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"