@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.
- package/bundles/web.bundle.min.js +145 -152
- package/lib/cjs/common/contracts/ao-process.js +36 -19
- package/lib/cjs/common/io.js +1 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/contracts/ao-process.js +36 -19
- package/lib/esm/common/io.js +1 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/common/contracts/ao-process.d.ts +2 -1
- package/lib/types/common/io.d.ts +1 -0
- package/lib/types/io.d.ts +7 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -51,26 +51,43 @@ class AOProcess {
|
|
|
51
51
|
};
|
|
52
52
|
return aoSigner;
|
|
53
53
|
}
|
|
54
|
-
async read({ tags, }) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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`, {
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -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({
|
package/lib/cjs/version.js
CHANGED
|
@@ -48,26 +48,43 @@ export class AOProcess {
|
|
|
48
48
|
};
|
|
49
49
|
return aoSigner;
|
|
50
50
|
}
|
|
51
|
-
async read({ tags, }) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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`, {
|
package/lib/esm/common/io.js
CHANGED
|
@@ -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({
|
package/lib/esm/version.js
CHANGED
|
@@ -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<{
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/lib/types/version.d.ts
CHANGED