@ar.io/sdk 2.0.2 → 2.0.3-alpha.1
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 +50 -50
- package/lib/cjs/utils/processes.js +29 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/utils/processes.js +29 -4
- package/lib/esm/version.js +1 -1
- package/lib/types/utils/processes.d.ts +5 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ const eventemitter3_1 = require("eventemitter3");
|
|
|
21
21
|
const plimit_lit_1 = require("plimit-lit");
|
|
22
22
|
const ant_js_1 = require("../common/ant.js");
|
|
23
23
|
const io_js_1 = require("../common/io.js");
|
|
24
|
+
const logger_js_1 = require("../common/logger.js");
|
|
24
25
|
const constants_js_1 = require("../constants.js");
|
|
25
26
|
const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
|
|
26
27
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
@@ -71,19 +72,25 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
71
72
|
contract;
|
|
72
73
|
timeoutMs; // timeout for each request to 3 seconds
|
|
73
74
|
throttle;
|
|
75
|
+
logger;
|
|
74
76
|
constructor({ contract = io_js_1.IO.init({
|
|
75
77
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
76
|
-
}), timeoutMs = 60_000, concurrency = 30, }) {
|
|
78
|
+
}), timeoutMs = 60_000, concurrency = 30, logger = logger_js_1.Logger.default, } = {}) {
|
|
77
79
|
super();
|
|
78
80
|
this.contract = contract;
|
|
79
81
|
this.timeoutMs = timeoutMs;
|
|
80
82
|
this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
|
|
83
|
+
this.logger = logger;
|
|
81
84
|
}
|
|
82
85
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
83
86
|
const uniqueContractProcessIds = {};
|
|
84
|
-
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract }))
|
|
87
|
+
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract, emitter: this }))
|
|
85
88
|
.catch((e) => {
|
|
86
89
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
90
|
+
this.logger.error(`Error getting ArNS records`, {
|
|
91
|
+
message: e?.message,
|
|
92
|
+
stack: e?.stack,
|
|
93
|
+
});
|
|
87
94
|
return {};
|
|
88
95
|
})
|
|
89
96
|
.then((records) => {
|
|
@@ -103,8 +110,8 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
103
110
|
});
|
|
104
111
|
});
|
|
105
112
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
106
|
-
// check the contract owner and controllers
|
|
107
113
|
this.emit('progress', 0, idCount);
|
|
114
|
+
// check the contract owner and controllers
|
|
108
115
|
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => this.throttle(async () => {
|
|
109
116
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
110
117
|
this.emit('progress', i + 1, idCount);
|
|
@@ -130,8 +137,9 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
130
137
|
exports.ArNSEventEmitter = ArNSEventEmitter;
|
|
131
138
|
const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
132
139
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
133
|
-
}), logger, }) => {
|
|
140
|
+
}), emitter, logger = logger_js_1.Logger.default, }) => {
|
|
134
141
|
let cursor;
|
|
142
|
+
const startTimestamp = Date.now();
|
|
135
143
|
const records = {};
|
|
136
144
|
do {
|
|
137
145
|
const pageResult = await contract
|
|
@@ -141,6 +149,7 @@ const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
|
141
149
|
message: e?.message,
|
|
142
150
|
stack: e?.stack,
|
|
143
151
|
});
|
|
152
|
+
emitter?.emit('arns:error', `Error getting ArNS records: ${e}`);
|
|
144
153
|
return undefined;
|
|
145
154
|
});
|
|
146
155
|
if (!pageResult) {
|
|
@@ -150,8 +159,24 @@ const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
|
150
159
|
const { name, ...recordDetails } = record;
|
|
151
160
|
records[name] = recordDetails;
|
|
152
161
|
});
|
|
162
|
+
logger.debug('Fetched page of ArNS records', {
|
|
163
|
+
totalRecordCount: pageResult.totalItems,
|
|
164
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
165
|
+
cursor: pageResult.nextCursor,
|
|
166
|
+
});
|
|
167
|
+
emitter?.emit('arns:pageLoaded', {
|
|
168
|
+
totalRecordCount: pageResult.totalItems,
|
|
169
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
170
|
+
records: pageResult.items,
|
|
171
|
+
cursor: pageResult.nextCursor,
|
|
172
|
+
});
|
|
153
173
|
cursor = pageResult.nextCursor;
|
|
154
174
|
} while (cursor !== undefined);
|
|
175
|
+
emitter?.emit('arns:end', records);
|
|
176
|
+
logger.debug('Fetched all ArNS records', {
|
|
177
|
+
totalRecordCount: Object.keys(records).length,
|
|
178
|
+
durationMs: Date.now() - startTimestamp,
|
|
179
|
+
});
|
|
155
180
|
return records;
|
|
156
181
|
};
|
|
157
182
|
exports.fetchAllArNSRecords = fetchAllArNSRecords;
|
package/lib/cjs/version.js
CHANGED
|
@@ -18,6 +18,7 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
18
18
|
import { pLimit } from 'plimit-lit';
|
|
19
19
|
import { ANT } from '../common/ant.js';
|
|
20
20
|
import { IO } from '../common/io.js';
|
|
21
|
+
import { Logger } from '../common/logger.js';
|
|
21
22
|
import { IO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
22
23
|
export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
|
|
23
24
|
processId: IO_TESTNET_PROCESS_ID,
|
|
@@ -67,19 +68,25 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
67
68
|
contract;
|
|
68
69
|
timeoutMs; // timeout for each request to 3 seconds
|
|
69
70
|
throttle;
|
|
71
|
+
logger;
|
|
70
72
|
constructor({ contract = IO.init({
|
|
71
73
|
processId: IO_TESTNET_PROCESS_ID,
|
|
72
|
-
}), timeoutMs = 60_000, concurrency = 30, }) {
|
|
74
|
+
}), timeoutMs = 60_000, concurrency = 30, logger = Logger.default, } = {}) {
|
|
73
75
|
super();
|
|
74
76
|
this.contract = contract;
|
|
75
77
|
this.timeoutMs = timeoutMs;
|
|
76
78
|
this.throttle = pLimit(concurrency);
|
|
79
|
+
this.logger = logger;
|
|
77
80
|
}
|
|
78
81
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
79
82
|
const uniqueContractProcessIds = {};
|
|
80
|
-
await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract }))
|
|
83
|
+
await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract, emitter: this }))
|
|
81
84
|
.catch((e) => {
|
|
82
85
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
86
|
+
this.logger.error(`Error getting ArNS records`, {
|
|
87
|
+
message: e?.message,
|
|
88
|
+
stack: e?.stack,
|
|
89
|
+
});
|
|
83
90
|
return {};
|
|
84
91
|
})
|
|
85
92
|
.then((records) => {
|
|
@@ -99,8 +106,8 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
99
106
|
});
|
|
100
107
|
});
|
|
101
108
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
102
|
-
// check the contract owner and controllers
|
|
103
109
|
this.emit('progress', 0, idCount);
|
|
110
|
+
// check the contract owner and controllers
|
|
104
111
|
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => this.throttle(async () => {
|
|
105
112
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
106
113
|
this.emit('progress', i + 1, idCount);
|
|
@@ -125,8 +132,9 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
125
132
|
}
|
|
126
133
|
export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
127
134
|
processId: IO_TESTNET_PROCESS_ID,
|
|
128
|
-
}), logger, }) => {
|
|
135
|
+
}), emitter, logger = Logger.default, }) => {
|
|
129
136
|
let cursor;
|
|
137
|
+
const startTimestamp = Date.now();
|
|
130
138
|
const records = {};
|
|
131
139
|
do {
|
|
132
140
|
const pageResult = await contract
|
|
@@ -136,6 +144,7 @@ export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
|
136
144
|
message: e?.message,
|
|
137
145
|
stack: e?.stack,
|
|
138
146
|
});
|
|
147
|
+
emitter?.emit('arns:error', `Error getting ArNS records: ${e}`);
|
|
139
148
|
return undefined;
|
|
140
149
|
});
|
|
141
150
|
if (!pageResult) {
|
|
@@ -145,7 +154,23 @@ export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
|
145
154
|
const { name, ...recordDetails } = record;
|
|
146
155
|
records[name] = recordDetails;
|
|
147
156
|
});
|
|
157
|
+
logger.debug('Fetched page of ArNS records', {
|
|
158
|
+
totalRecordCount: pageResult.totalItems,
|
|
159
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
160
|
+
cursor: pageResult.nextCursor,
|
|
161
|
+
});
|
|
162
|
+
emitter?.emit('arns:pageLoaded', {
|
|
163
|
+
totalRecordCount: pageResult.totalItems,
|
|
164
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
165
|
+
records: pageResult.items,
|
|
166
|
+
cursor: pageResult.nextCursor,
|
|
167
|
+
});
|
|
148
168
|
cursor = pageResult.nextCursor;
|
|
149
169
|
} while (cursor !== undefined);
|
|
170
|
+
emitter?.emit('arns:end', records);
|
|
171
|
+
logger.debug('Fetched all ArNS records', {
|
|
172
|
+
totalRecordCount: Object.keys(records).length,
|
|
173
|
+
durationMs: Date.now() - startTimestamp,
|
|
174
|
+
});
|
|
150
175
|
return records;
|
|
151
176
|
};
|
package/lib/esm/version.js
CHANGED
|
@@ -25,16 +25,19 @@ export declare class ArNSEventEmitter extends EventEmitter {
|
|
|
25
25
|
protected contract: AoIORead;
|
|
26
26
|
private timeoutMs;
|
|
27
27
|
private throttle;
|
|
28
|
-
|
|
28
|
+
private logger;
|
|
29
|
+
constructor({ contract, timeoutMs, concurrency, logger, }?: {
|
|
29
30
|
contract?: AoIORead;
|
|
30
31
|
timeoutMs?: number;
|
|
31
32
|
concurrency?: number;
|
|
33
|
+
logger?: ILogger;
|
|
32
34
|
});
|
|
33
35
|
fetchProcessesOwnedByWallet({ address }: {
|
|
34
36
|
address: WalletAddress;
|
|
35
37
|
}): Promise<void>;
|
|
36
38
|
}
|
|
37
|
-
export declare const fetchAllArNSRecords: ({ contract, logger, }: {
|
|
39
|
+
export declare const fetchAllArNSRecords: ({ contract, emitter, logger, }: {
|
|
38
40
|
contract?: AoIORead;
|
|
41
|
+
emitter?: EventEmitter;
|
|
39
42
|
logger?: ILogger;
|
|
40
43
|
}) => Promise<Record<string, AoArNSNameData>>;
|
package/lib/types/version.d.ts
CHANGED