@ar.io/sdk 3.24.0 → 4.0.0-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/README.md +682 -600
- package/lib/esm/cli/cli.js +188 -152
- package/lib/esm/cli/commands/antCommands.js +23 -58
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
- package/lib/esm/cli/commands/escrowCommands.js +221 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +142 -23
- package/lib/esm/cli/commands/pruneCommands.js +150 -0
- package/lib/esm/cli/commands/readCommands.js +22 -3
- package/lib/esm/cli/commands/transfer.js +6 -6
- package/lib/esm/cli/options.js +124 -58
- package/lib/esm/cli/utils.js +280 -174
- package/lib/esm/common/ant-registry.js +17 -143
- package/lib/esm/common/ant.js +44 -1167
- package/lib/esm/common/faucet.js +11 -6
- package/lib/esm/common/index.js +0 -4
- package/lib/esm/common/io.js +25 -1412
- package/lib/esm/constants.js +13 -19
- package/lib/esm/solana/ant-readable.js +724 -0
- package/lib/esm/solana/ant-registry-readable.js +133 -0
- package/lib/esm/solana/ant-registry-writeable.js +472 -0
- package/lib/esm/solana/ant-writeable.js +384 -0
- package/lib/esm/solana/ata.js +70 -0
- package/lib/esm/solana/canonical-message.js +128 -0
- package/lib/esm/solana/clusters.js +111 -0
- package/lib/esm/solana/constants.js +146 -0
- package/lib/esm/solana/delegation-math.js +112 -0
- package/lib/esm/solana/deserialize.js +711 -0
- package/lib/esm/solana/escrow.js +839 -0
- package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
- package/lib/esm/solana/funding-plan.js +699 -0
- package/lib/esm/solana/index.js +126 -0
- package/lib/esm/solana/instruction.js +39 -0
- package/lib/esm/solana/io-readable.js +2182 -0
- package/lib/esm/solana/io-writeable.js +3196 -0
- package/lib/esm/solana/json-rpc.js +90 -0
- package/lib/esm/solana/metadata.js +81 -0
- package/lib/esm/solana/mpl-core.js +192 -0
- package/lib/esm/solana/pda.js +332 -0
- package/lib/esm/solana/predict-prescribed-observers.js +110 -0
- package/lib/esm/solana/retry.js +117 -0
- package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
- package/lib/esm/solana/send.js +372 -0
- package/lib/esm/solana/spawn-ant.js +224 -0
- package/lib/esm/solana/types.js +1 -0
- package/lib/esm/types/ant.js +27 -15
- package/lib/esm/types/io.js +8 -11
- package/lib/esm/utils/ant.js +0 -63
- package/lib/esm/utils/index.js +0 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +5 -13
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
- package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
- package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
- package/lib/types/cli/commands/readCommands.d.ts +27 -22
- package/lib/types/cli/commands/transfer.d.ts +9 -9
- package/lib/types/cli/options.d.ts +76 -21
- package/lib/types/cli/types.d.ts +11 -13
- package/lib/types/cli/utils.d.ts +71 -31
- package/lib/types/common/ant-registry.d.ts +49 -47
- package/lib/types/common/ant.d.ts +54 -539
- package/lib/types/common/faucet.d.ts +20 -8
- package/lib/types/common/index.d.ts +0 -3
- package/lib/types/common/io.d.ts +51 -263
- package/lib/types/constants.d.ts +11 -18
- package/lib/types/solana/ant-readable.d.ts +180 -0
- package/lib/types/solana/ant-registry-readable.d.ts +105 -0
- package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
- package/lib/types/solana/ant-writeable.d.ts +177 -0
- package/lib/types/solana/ata.d.ts +44 -0
- package/lib/types/solana/canonical-message.d.ts +121 -0
- package/lib/types/solana/clusters.d.ts +109 -0
- package/lib/types/solana/constants.d.ts +119 -0
- package/lib/types/solana/delegation-math.d.ts +45 -0
- package/lib/types/solana/deserialize.d.ts +262 -0
- package/lib/types/solana/escrow.d.ts +480 -0
- package/lib/types/solana/events.d.ts +38 -0
- package/lib/types/solana/funding-plan.d.ts +225 -0
- package/lib/types/solana/index.d.ts +87 -0
- package/lib/types/solana/instruction.d.ts +39 -0
- package/lib/types/solana/io-readable.d.ts +499 -0
- package/lib/types/solana/io-writeable.d.ts +893 -0
- package/lib/types/solana/json-rpc.d.ts +47 -0
- package/lib/types/solana/metadata.d.ts +84 -0
- package/lib/types/solana/mpl-core.d.ts +120 -0
- package/lib/types/solana/pda.d.ts +95 -0
- package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
- package/lib/types/solana/retry.d.ts +62 -0
- package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
- package/lib/types/solana/send.d.ts +94 -0
- package/lib/types/solana/spawn-ant.d.ts +145 -0
- package/lib/types/solana/types.d.ts +82 -0
- package/lib/types/types/ant-registry.d.ts +43 -4
- package/lib/types/types/ant.d.ts +114 -96
- package/lib/types/types/common.d.ts +18 -74
- package/lib/types/types/faucet.d.ts +2 -2
- package/lib/types/types/io.d.ts +244 -158
- package/lib/types/types/token.d.ts +0 -12
- package/lib/types/utils/ant.d.ts +1 -12
- package/lib/types/utils/index.d.ts +0 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +36 -33
- package/lib/cjs/cli/cli.js +0 -822
- package/lib/cjs/cli/commands/antCommands.js +0 -113
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
- package/lib/cjs/cli/commands/readCommands.js +0 -215
- package/lib/cjs/cli/commands/transfer.js +0 -159
- package/lib/cjs/cli/options.js +0 -470
- package/lib/cjs/cli/types.js +0 -2
- package/lib/cjs/cli/utils.js +0 -639
- package/lib/cjs/common/ant-registry.js +0 -155
- package/lib/cjs/common/ant-versions.js +0 -93
- package/lib/cjs/common/ant.js +0 -1182
- package/lib/cjs/common/arweave.js +0 -27
- package/lib/cjs/common/contracts/ao-process.js +0 -224
- package/lib/cjs/common/error.js +0 -64
- package/lib/cjs/common/faucet.js +0 -150
- package/lib/cjs/common/hyperbeam/hb.js +0 -173
- package/lib/cjs/common/index.js +0 -42
- package/lib/cjs/common/io.js +0 -1423
- package/lib/cjs/common/logger.js +0 -83
- package/lib/cjs/common/loggers/winston.js +0 -68
- package/lib/cjs/common/marketplace.js +0 -731
- package/lib/cjs/common/turbo.js +0 -223
- package/lib/cjs/constants.js +0 -41
- package/lib/cjs/node/index.js +0 -39
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/types/ant-registry.js +0 -2
- package/lib/cjs/types/ant.js +0 -168
- package/lib/cjs/types/common.js +0 -2
- package/lib/cjs/types/faucet.js +0 -2
- package/lib/cjs/types/index.js +0 -37
- package/lib/cjs/types/io.js +0 -51
- package/lib/cjs/types/token.js +0 -116
- package/lib/cjs/utils/ant.js +0 -108
- package/lib/cjs/utils/ao.js +0 -432
- package/lib/cjs/utils/arweave.js +0 -285
- package/lib/cjs/utils/base64.js +0 -62
- package/lib/cjs/utils/hash.js +0 -56
- package/lib/cjs/utils/index.js +0 -38
- package/lib/cjs/utils/processes.js +0 -173
- package/lib/cjs/utils/random.js +0 -30
- package/lib/cjs/utils/schema.js +0 -15
- package/lib/cjs/utils/url.js +0 -37
- package/lib/cjs/version.js +0 -20
- package/lib/cjs/web/index.js +0 -41
- package/lib/esm/common/ant-versions.js +0 -87
- package/lib/esm/common/arweave.js +0 -21
- package/lib/esm/common/contracts/ao-process.js +0 -220
- package/lib/esm/common/hyperbeam/hb.js +0 -169
- package/lib/esm/common/marketplace.js +0 -724
- package/lib/esm/common/turbo.js +0 -215
- package/lib/esm/node/index.js +0 -20
- package/lib/esm/utils/ao.js +0 -420
- package/lib/esm/utils/arweave.js +0 -271
- package/lib/esm/utils/processes.js +0 -167
- package/lib/esm/web/index.js +0 -20
- package/lib/types/common/ant-versions.d.ts +0 -39
- package/lib/types/common/arweave.d.ts +0 -17
- package/lib/types/common/contracts/ao-process.d.ts +0 -47
- package/lib/types/common/hyperbeam/hb.d.ts +0 -88
- package/lib/types/common/marketplace.d.ts +0 -568
- package/lib/types/common/turbo.d.ts +0 -61
- package/lib/types/node/index.d.ts +0 -20
- package/lib/types/utils/ao.d.ts +0 -80
- package/lib/types/utils/arweave.d.ts +0 -79
- package/lib/types/utils/processes.d.ts +0 -39
- package/lib/types/web/index.d.ts +0 -20
package/lib/cjs/utils/arweave.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.epochDistributionNoticeGqlQueryFallback = exports.epochDistributionNoticeGqlQuery = exports.getEpochDataFromGqlFallback = exports.getEpochDataFromGqlWithCUFallback = exports.getEpochDataFromGql = exports.paginationParamsToTags = exports.pruneTags = exports.validateArweaveId = void 0;
|
|
4
|
-
exports.isBlockHeight = isBlockHeight;
|
|
5
|
-
exports.sortAndPaginateEpochDataIntoEligibleDistributions = sortAndPaginateEpochDataIntoEligibleDistributions;
|
|
6
|
-
exports.removeEligibleRewardsFromEpochData = removeEligibleRewardsFromEpochData;
|
|
7
|
-
const logger_js_1 = require("../common/logger.js");
|
|
8
|
-
const constants_js_1 = require("../constants.js");
|
|
9
|
-
const io_js_1 = require("../types/io.js");
|
|
10
|
-
const ao_js_1 = require("./ao.js");
|
|
11
|
-
const validateArweaveId = (id) => {
|
|
12
|
-
return constants_js_1.ARWEAVE_TX_REGEX.test(id);
|
|
13
|
-
};
|
|
14
|
-
exports.validateArweaveId = validateArweaveId;
|
|
15
|
-
function isBlockHeight(height) {
|
|
16
|
-
return height !== undefined && !isNaN(parseInt(height.toString()));
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Prune tags that are undefined or empty.
|
|
20
|
-
* @param tags - The tags to prune.
|
|
21
|
-
* @returns The pruned tags.
|
|
22
|
-
*/
|
|
23
|
-
const pruneTags = (tags) => {
|
|
24
|
-
return tags.filter((tag) => tag.value !== undefined && tag.value !== '');
|
|
25
|
-
};
|
|
26
|
-
exports.pruneTags = pruneTags;
|
|
27
|
-
const paginationParamsToTags = (params) => {
|
|
28
|
-
const tags = [
|
|
29
|
-
{ name: 'Cursor', value: params?.cursor?.toString() },
|
|
30
|
-
{ name: 'Limit', value: params?.limit?.toString() },
|
|
31
|
-
{ name: 'Sort-By', value: params?.sortBy?.toString() },
|
|
32
|
-
{ name: 'Sort-Order', value: params?.sortOrder?.toString() },
|
|
33
|
-
...(params?.filters
|
|
34
|
-
? [{ name: 'Filters', value: JSON.stringify(params.filters) }]
|
|
35
|
-
: []),
|
|
36
|
-
];
|
|
37
|
-
return (0, exports.pruneTags)(tags);
|
|
38
|
-
};
|
|
39
|
-
exports.paginationParamsToTags = paginationParamsToTags;
|
|
40
|
-
/**
|
|
41
|
-
* Get the epoch with distribution data for the current epoch
|
|
42
|
-
* @param arweave - The Arweave instance
|
|
43
|
-
* @returns The epoch with distribution data
|
|
44
|
-
*/
|
|
45
|
-
const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, retries = 3, gqlUrl = 'https://arweave-search.goldsky.com/graphql', }) => {
|
|
46
|
-
// fetch from gql
|
|
47
|
-
const query = (0, exports.epochDistributionNoticeGqlQuery)({ epochIndex, processId });
|
|
48
|
-
// add three retries with exponential backoff
|
|
49
|
-
for (let i = 0; i < retries; i++) {
|
|
50
|
-
try {
|
|
51
|
-
const response = (await fetch(gqlUrl, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
body: query,
|
|
54
|
-
headers: {
|
|
55
|
-
'Content-Type': 'application/json',
|
|
56
|
-
},
|
|
57
|
-
}).then((res) => res.json()));
|
|
58
|
-
// parse the nodes to get the id
|
|
59
|
-
if (response?.data?.transactions?.edges?.length === 0) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
const id = response.data.transactions.edges[0].node.id;
|
|
63
|
-
// fetch the transaction from arweave
|
|
64
|
-
const transaction = await arweave.api.get(id);
|
|
65
|
-
// assert it is the correct type
|
|
66
|
-
return (0, ao_js_1.parseAoEpochData)(transaction.data);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
if (i === retries - 1)
|
|
70
|
-
throw error; // Re-throw on final attempt
|
|
71
|
-
// exponential backoff
|
|
72
|
-
await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return undefined;
|
|
76
|
-
};
|
|
77
|
-
exports.getEpochDataFromGql = getEpochDataFromGql;
|
|
78
|
-
const getEpochDataFromGqlWithCUFallback = async ({ arweave, ao, epochIndex, processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, }) => {
|
|
79
|
-
const gqlResult = await (0, exports.getEpochDataFromGql)({
|
|
80
|
-
arweave,
|
|
81
|
-
epochIndex,
|
|
82
|
-
processId,
|
|
83
|
-
});
|
|
84
|
-
if (gqlResult) {
|
|
85
|
-
return gqlResult;
|
|
86
|
-
}
|
|
87
|
-
const gqlFallbackResult = await (0, exports.getEpochDataFromGqlFallback)({
|
|
88
|
-
ao,
|
|
89
|
-
epochIndex,
|
|
90
|
-
processId,
|
|
91
|
-
});
|
|
92
|
-
if (gqlFallbackResult) {
|
|
93
|
-
return gqlFallbackResult;
|
|
94
|
-
}
|
|
95
|
-
return undefined;
|
|
96
|
-
};
|
|
97
|
-
exports.getEpochDataFromGqlWithCUFallback = getEpochDataFromGqlWithCUFallback;
|
|
98
|
-
const getEpochDataFromGqlFallback = async ({ ao, epochIndex, processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, gqlUrl = 'https://arweave-search.goldsky.com/graphql', }) => {
|
|
99
|
-
const query = (0, exports.epochDistributionNoticeGqlQueryFallback)({
|
|
100
|
-
epochIndex,
|
|
101
|
-
processId,
|
|
102
|
-
});
|
|
103
|
-
const response = await fetch(gqlUrl, {
|
|
104
|
-
method: 'POST',
|
|
105
|
-
body: query,
|
|
106
|
-
headers: {
|
|
107
|
-
'Content-Type': 'application/json',
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
const responseJson = (await response.json());
|
|
111
|
-
if (responseJson.data.transactions.edges.length === 0) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
for (const edge of responseJson.data.transactions.edges) {
|
|
115
|
-
const id = edge.node.id;
|
|
116
|
-
const messageResult = await ao
|
|
117
|
-
.result({
|
|
118
|
-
message: id,
|
|
119
|
-
process: processId,
|
|
120
|
-
})
|
|
121
|
-
.catch(() => undefined);
|
|
122
|
-
if (!messageResult) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
for (const message of messageResult?.Messages ?? []) {
|
|
126
|
-
if (!message.Data) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
const tags = message.Tags;
|
|
131
|
-
// check if the message results include epoch-distribution-notice for the requested epoch index
|
|
132
|
-
if (tags.some((tag) => tag.name === 'Action' &&
|
|
133
|
-
tag.value === 'Epoch-Distribution-Notice') &&
|
|
134
|
-
tags.some((tag) => tag.name === 'Epoch-Index' && tag.value === epochIndex.toString())) {
|
|
135
|
-
const data = JSON.parse(message.Data);
|
|
136
|
-
return (0, ao_js_1.parseAoEpochData)(data);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
// report but continue to next message
|
|
141
|
-
logger_js_1.Logger.default.error('Failed to parse AO epoch distribution message:', error, '\nMessage:', message);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return undefined;
|
|
146
|
-
};
|
|
147
|
-
exports.getEpochDataFromGqlFallback = getEpochDataFromGqlFallback;
|
|
148
|
-
/**
|
|
149
|
-
* Get the epoch with distribution data for the current epoch
|
|
150
|
-
* @param arweave - The Arweave instance
|
|
151
|
-
* @param epochIndex - The index of the epoch
|
|
152
|
-
* @param processId - The process ID (optional, defaults to ARIO_MAINNET_PROCESS_ID)
|
|
153
|
-
* @returns string - The stringified GQL query
|
|
154
|
-
*/
|
|
155
|
-
const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, authorities = ['fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY'], }) => {
|
|
156
|
-
// write the query
|
|
157
|
-
const gqlQuery = JSON.stringify({
|
|
158
|
-
query: `
|
|
159
|
-
query {
|
|
160
|
-
transactions(
|
|
161
|
-
tags: [
|
|
162
|
-
{ name: "From-Process", values: ["${processId}"] }
|
|
163
|
-
{ name: "Action", values: ["Epoch-Distribution-Notice"] }
|
|
164
|
-
{ name: "Epoch-Index", values: ["${epochIndex}"] }
|
|
165
|
-
{ name: "Data-Protocol", values: ["ao"] }
|
|
166
|
-
],
|
|
167
|
-
owners: [${authorities.map((a) => `"${a}"`).join(',')}],
|
|
168
|
-
first: 1,
|
|
169
|
-
sort: HEIGHT_DESC
|
|
170
|
-
) {
|
|
171
|
-
edges {
|
|
172
|
-
node {
|
|
173
|
-
id
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
`,
|
|
179
|
-
});
|
|
180
|
-
return gqlQuery;
|
|
181
|
-
};
|
|
182
|
-
exports.epochDistributionNoticeGqlQuery = epochDistributionNoticeGqlQuery;
|
|
183
|
-
// fallback query if the distribution notice does not get cranked
|
|
184
|
-
const epochDistributionNoticeGqlQueryFallback = ({ processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, owners = ['OAb-n-ZugyN598kZNpfOy0ACelGVmwCQ0kYbgNGDUK8'], // ar.io team wallet ticks once a day
|
|
185
|
-
}) => {
|
|
186
|
-
return JSON.stringify({
|
|
187
|
-
query: `
|
|
188
|
-
query {
|
|
189
|
-
transactions(
|
|
190
|
-
tags: [
|
|
191
|
-
{ name: "Action", values: ["Tick"] }
|
|
192
|
-
],
|
|
193
|
-
first: 100,
|
|
194
|
-
owners: [${owners.map((a) => `"${a}"`).join(',')}],
|
|
195
|
-
recipients: ["${processId}"],
|
|
196
|
-
sort: HEIGHT_DESC
|
|
197
|
-
) {
|
|
198
|
-
edges {
|
|
199
|
-
node {
|
|
200
|
-
id
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
`,
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
exports.epochDistributionNoticeGqlQueryFallback = epochDistributionNoticeGqlQueryFallback;
|
|
209
|
-
function sortAndPaginateEpochDataIntoEligibleDistributions(epochData, params) {
|
|
210
|
-
const rewards = [];
|
|
211
|
-
const sortBy = params?.sortBy ?? 'eligibleReward';
|
|
212
|
-
const sortOrder = params?.sortOrder ?? 'desc';
|
|
213
|
-
const limit = params?.limit ?? 100;
|
|
214
|
-
if (!(0, io_js_1.isDistributedEpoch)(epochData)) {
|
|
215
|
-
return {
|
|
216
|
-
hasMore: false,
|
|
217
|
-
items: [],
|
|
218
|
-
totalItems: 0,
|
|
219
|
-
limit,
|
|
220
|
-
sortOrder,
|
|
221
|
-
sortBy,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
const eligibleDistributions = epochData?.distributions.rewards.eligible;
|
|
225
|
-
for (const [gatewayAddress, reward] of Object.entries(eligibleDistributions)) {
|
|
226
|
-
rewards.push({
|
|
227
|
-
type: 'operatorReward',
|
|
228
|
-
recipient: gatewayAddress,
|
|
229
|
-
eligibleReward: reward.operatorReward,
|
|
230
|
-
cursorId: gatewayAddress + '_' + gatewayAddress,
|
|
231
|
-
gatewayAddress,
|
|
232
|
-
});
|
|
233
|
-
for (const [delegateAddress, delegateRewardQty] of Object.entries(reward.delegateRewards)) {
|
|
234
|
-
rewards.push({
|
|
235
|
-
type: 'delegateReward',
|
|
236
|
-
recipient: delegateAddress,
|
|
237
|
-
eligibleReward: delegateRewardQty,
|
|
238
|
-
cursorId: gatewayAddress + '_' + delegateAddress,
|
|
239
|
-
gatewayAddress,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
// sort the rewards by the sortBy
|
|
244
|
-
rewards.sort((a, b) => {
|
|
245
|
-
const aSort = a[sortBy];
|
|
246
|
-
const bSort = b[sortBy];
|
|
247
|
-
if (aSort === bSort || aSort === undefined || bSort === undefined) {
|
|
248
|
-
return 0;
|
|
249
|
-
}
|
|
250
|
-
if (sortOrder === 'asc') {
|
|
251
|
-
return aSort > bSort ? 1 : -1;
|
|
252
|
-
}
|
|
253
|
-
return aSort < bSort ? 1 : -1;
|
|
254
|
-
});
|
|
255
|
-
// paginate the rewards
|
|
256
|
-
const start = params?.cursor !== undefined
|
|
257
|
-
? rewards.findIndex((r) => r.cursorId === params.cursor) + 1
|
|
258
|
-
: 0;
|
|
259
|
-
const end = limit ? start + limit : rewards.length;
|
|
260
|
-
return {
|
|
261
|
-
hasMore: end < rewards.length,
|
|
262
|
-
items: rewards.slice(start, end),
|
|
263
|
-
totalItems: rewards.length,
|
|
264
|
-
limit,
|
|
265
|
-
sortOrder,
|
|
266
|
-
nextCursor: rewards[end]?.cursorId,
|
|
267
|
-
sortBy,
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
function removeEligibleRewardsFromEpochData(epochData) {
|
|
271
|
-
if (!(0, io_js_1.isDistributedEpoch)(epochData)) {
|
|
272
|
-
return epochData;
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
...epochData,
|
|
276
|
-
distributions: {
|
|
277
|
-
...epochData.distributions,
|
|
278
|
-
rewards: {
|
|
279
|
-
...epochData.distributions.rewards,
|
|
280
|
-
// @ts-expect-error -- remove eligible rewards
|
|
281
|
-
eligible: undefined,
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
};
|
|
285
|
-
}
|
package/lib/cjs/utils/base64.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fromB64Url = fromB64Url;
|
|
4
|
-
exports.toB64Url = toB64Url;
|
|
5
|
-
exports.sha256B64Url = sha256B64Url;
|
|
6
|
-
exports.getRandomText = getRandomText;
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License.
|
|
12
|
-
* You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
const crypto_1 = require("crypto");
|
|
23
|
-
// safely encodes and decodes base64url strings to and from buffers
|
|
24
|
-
const BASE64_CHAR_62 = '+';
|
|
25
|
-
const BASE64_CHAR_63 = '/';
|
|
26
|
-
const BASE64URL_CHAR_62 = '-';
|
|
27
|
-
const BASE64URL_CHAR_63 = '_';
|
|
28
|
-
const BASE64_PADDING = '=';
|
|
29
|
-
function base64urlToBase64(str) {
|
|
30
|
-
const padLength = str.length % 4;
|
|
31
|
-
if (padLength) {
|
|
32
|
-
str += BASE64_PADDING.repeat(4 - padLength);
|
|
33
|
-
}
|
|
34
|
-
return str
|
|
35
|
-
.replaceAll(BASE64URL_CHAR_62, BASE64_CHAR_62)
|
|
36
|
-
.replaceAll(BASE64URL_CHAR_63, BASE64_CHAR_63);
|
|
37
|
-
}
|
|
38
|
-
function base64urlFromBase64(str) {
|
|
39
|
-
return str
|
|
40
|
-
.replaceAll(BASE64_CHAR_62, BASE64URL_CHAR_62)
|
|
41
|
-
.replaceAll(BASE64_CHAR_63, BASE64URL_CHAR_63)
|
|
42
|
-
.replaceAll(BASE64_PADDING, '');
|
|
43
|
-
}
|
|
44
|
-
function fromB64Url(str) {
|
|
45
|
-
const b64Str = base64urlToBase64(str);
|
|
46
|
-
return Buffer.from(b64Str, 'base64');
|
|
47
|
-
}
|
|
48
|
-
function toB64Url(buffer) {
|
|
49
|
-
const b64Str = buffer.toString('base64');
|
|
50
|
-
return base64urlFromBase64(b64Str);
|
|
51
|
-
}
|
|
52
|
-
function sha256B64Url(input) {
|
|
53
|
-
return toB64Url((0, crypto_1.createHash)('sha256').update(Uint8Array.from(input)).digest());
|
|
54
|
-
}
|
|
55
|
-
function getRandomText(length = 32) {
|
|
56
|
-
// Generate a buffer of random bytes
|
|
57
|
-
const buffer = (0, crypto_1.randomBytes)(length);
|
|
58
|
-
// Convert bytes to hexadecimal string
|
|
59
|
-
return Array.from(buffer, (byte) => byte.toString(16).padStart(2, '0'))
|
|
60
|
-
.join('')
|
|
61
|
-
.slice(0, length);
|
|
62
|
-
}
|
package/lib/cjs/utils/hash.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hashBufferToB64Url = exports.hashReadableStreamToB64Url = exports.hashReadableToB64Url = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
const crypto_1 = require("crypto");
|
|
20
|
-
const base64_js_1 = require("./base64.js");
|
|
21
|
-
const hashReadableToB64Url = (stream, algorithm = 'sha256') => {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const hash = (0, crypto_1.createHash)(algorithm);
|
|
24
|
-
stream.on('data', (chunk) => hash.update(chunk));
|
|
25
|
-
stream.on('end', () => resolve((0, base64_js_1.toB64Url)(hash.digest())));
|
|
26
|
-
stream.on('error', (err) => reject(err));
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.hashReadableToB64Url = hashReadableToB64Url;
|
|
30
|
-
const hashReadableStreamToB64Url = (stream, algorithm = 'sha256') => {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
const hash = (0, crypto_1.createHash)(algorithm);
|
|
33
|
-
const reader = stream.getReader();
|
|
34
|
-
const read = async () => {
|
|
35
|
-
try {
|
|
36
|
-
const { done, value } = await reader.read();
|
|
37
|
-
if (done) {
|
|
38
|
-
resolve((0, base64_js_1.toB64Url)(hash.digest()));
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
hash.update(value);
|
|
42
|
-
read();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
reject(err);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
read().catch(reject);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
exports.hashReadableStreamToB64Url = hashReadableStreamToB64Url;
|
|
53
|
-
const hashBufferToB64Url = (buffer, algorithm = 'sha256') => {
|
|
54
|
-
return (0, base64_js_1.toB64Url)((0, crypto_1.createHash)(algorithm).update(buffer).digest());
|
|
55
|
-
};
|
|
56
|
-
exports.hashBufferToB64Url = hashBufferToB64Url;
|
package/lib/cjs/utils/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/**
|
|
18
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
19
|
-
*
|
|
20
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
-
* you may not use this file except in compliance with the License.
|
|
22
|
-
* You may obtain a copy of the License at
|
|
23
|
-
*
|
|
24
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
-
*
|
|
26
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
-
* See the License for the specific language governing permissions and
|
|
30
|
-
* limitations under the License.
|
|
31
|
-
*/
|
|
32
|
-
__exportStar(require("./ao.js"), exports);
|
|
33
|
-
__exportStar(require("./arweave.js"), exports);
|
|
34
|
-
__exportStar(require("./base64.js"), exports);
|
|
35
|
-
__exportStar(require("./json.js"), exports);
|
|
36
|
-
__exportStar(require("./processes.js"), exports);
|
|
37
|
-
__exportStar(require("./schema.js"), exports);
|
|
38
|
-
__exportStar(require("./ant.js"), exports);
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
20
|
-
const eventemitter3_1 = require("eventemitter3");
|
|
21
|
-
const ant_registry_js_1 = require("../common/ant-registry.js");
|
|
22
|
-
const ant_js_1 = require("../common/ant.js");
|
|
23
|
-
const index_js_1 = require("../common/index.js");
|
|
24
|
-
const io_js_1 = require("../common/io.js");
|
|
25
|
-
const logger_js_1 = require("../common/logger.js");
|
|
26
|
-
const constants_js_1 = require("../constants.js");
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use getArNSRecordsForAddress instead
|
|
29
|
-
*/
|
|
30
|
-
const getANTProcessesOwnedByWallet = async ({ address, registry = ant_registry_js_1.ANTRegistry.init(), }) => {
|
|
31
|
-
const res = await registry.accessControlList({ address });
|
|
32
|
-
return [...new Set([...res.Owned, ...res.Controlled])];
|
|
33
|
-
};
|
|
34
|
-
exports.getANTProcessesOwnedByWallet = getANTProcessesOwnedByWallet;
|
|
35
|
-
function timeout(ms, promise) {
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
const timer = setTimeout(() => {
|
|
38
|
-
reject(new Error('Timeout'));
|
|
39
|
-
}, ms);
|
|
40
|
-
promise
|
|
41
|
-
.then((value) => {
|
|
42
|
-
clearTimeout(timer);
|
|
43
|
-
resolve(value);
|
|
44
|
-
})
|
|
45
|
-
.catch((err) => {
|
|
46
|
-
clearTimeout(timer);
|
|
47
|
-
reject(err);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
53
|
-
*/
|
|
54
|
-
class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
55
|
-
contract;
|
|
56
|
-
timeoutMs;
|
|
57
|
-
logger;
|
|
58
|
-
strict;
|
|
59
|
-
antAoClient;
|
|
60
|
-
constructor({ contract = io_js_1.ARIO.init({
|
|
61
|
-
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
62
|
-
}), timeoutMs = 60_000, logger = logger_js_1.Logger.default, strict = false, antAoClient = (0, aoconnect_1.connect)({
|
|
63
|
-
MODE: 'legacy',
|
|
64
|
-
}), } = {}) {
|
|
65
|
-
super();
|
|
66
|
-
this.contract = contract;
|
|
67
|
-
this.timeoutMs = timeoutMs;
|
|
68
|
-
this.logger = logger;
|
|
69
|
-
this.strict = strict;
|
|
70
|
-
this.antAoClient = antAoClient;
|
|
71
|
-
}
|
|
72
|
-
async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ant_registry_js_1.ANTRegistry.init(), }) {
|
|
73
|
-
const uniqueContractProcessIds = {};
|
|
74
|
-
const antIdRes = await antRegistry.accessControlList({ address });
|
|
75
|
-
const antIds = new Set([...antIdRes.Owned, ...antIdRes.Controlled]);
|
|
76
|
-
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract, emitter: this, pageSize }))
|
|
77
|
-
.catch((e) => {
|
|
78
|
-
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
79
|
-
this.logger.error(`Error getting ArNS records`, {
|
|
80
|
-
message: e?.message,
|
|
81
|
-
stack: e?.stack,
|
|
82
|
-
});
|
|
83
|
-
return {};
|
|
84
|
-
})
|
|
85
|
-
.then((records) => {
|
|
86
|
-
Object.entries(records).forEach(([name, arnsRecord]) => {
|
|
87
|
-
if (antIds.has(arnsRecord.processId)) {
|
|
88
|
-
if (uniqueContractProcessIds[arnsRecord.processId] === undefined) {
|
|
89
|
-
uniqueContractProcessIds[arnsRecord.processId] = {
|
|
90
|
-
state: undefined,
|
|
91
|
-
names: {},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
uniqueContractProcessIds[arnsRecord.processId].names[name] =
|
|
95
|
-
arnsRecord;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
100
|
-
this.emit('progress', 0, idCount);
|
|
101
|
-
// check the contract owner and controllers
|
|
102
|
-
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => {
|
|
103
|
-
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
104
|
-
this.emit('progress', i + 1, idCount);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const ant = ant_js_1.ANT.init({
|
|
108
|
-
process: new index_js_1.AOProcess({
|
|
109
|
-
processId,
|
|
110
|
-
ao: this.antAoClient,
|
|
111
|
-
}),
|
|
112
|
-
strict: this.strict,
|
|
113
|
-
});
|
|
114
|
-
const state = (await timeout(this.timeoutMs, ant.getState()).catch((e) => {
|
|
115
|
-
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
116
|
-
return undefined;
|
|
117
|
-
}));
|
|
118
|
-
if (state?.Owner === address || state?.Controllers.includes(address)) {
|
|
119
|
-
uniqueContractProcessIds[processId].state = state;
|
|
120
|
-
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
121
|
-
}
|
|
122
|
-
this.emit('progress', i + 1, idCount);
|
|
123
|
-
}));
|
|
124
|
-
this.emit('end', uniqueContractProcessIds);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.ArNSEventEmitter = ArNSEventEmitter;
|
|
128
|
-
const fetchAllArNSRecords = async ({ contract = io_js_1.ARIO.init({
|
|
129
|
-
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
130
|
-
}), emitter, logger = logger_js_1.Logger.default, pageSize = 1000, }) => {
|
|
131
|
-
let cursor;
|
|
132
|
-
const startTimestamp = Date.now();
|
|
133
|
-
const records = {};
|
|
134
|
-
do {
|
|
135
|
-
const pageResult = await contract
|
|
136
|
-
.getArNSRecords({ cursor, limit: pageSize })
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
|
-
.catch((e) => {
|
|
139
|
-
logger?.error(`Error getting ArNS records`, {
|
|
140
|
-
message: e?.message,
|
|
141
|
-
stack: e?.stack,
|
|
142
|
-
});
|
|
143
|
-
emitter?.emit('arns:error', `Error getting ArNS records: ${e}`);
|
|
144
|
-
return undefined;
|
|
145
|
-
});
|
|
146
|
-
if (!pageResult) {
|
|
147
|
-
return {};
|
|
148
|
-
}
|
|
149
|
-
pageResult.items.forEach((record) => {
|
|
150
|
-
const { name, ...recordDetails } = record;
|
|
151
|
-
records[name] = recordDetails;
|
|
152
|
-
});
|
|
153
|
-
logger.debug('Fetched page of ArNS records', {
|
|
154
|
-
totalRecordCount: pageResult.totalItems,
|
|
155
|
-
fetchedRecordCount: Object.keys(records).length,
|
|
156
|
-
cursor: pageResult.nextCursor,
|
|
157
|
-
});
|
|
158
|
-
emitter?.emit('arns:pageLoaded', {
|
|
159
|
-
totalRecordCount: pageResult.totalItems,
|
|
160
|
-
fetchedRecordCount: Object.keys(records).length,
|
|
161
|
-
records: pageResult.items,
|
|
162
|
-
cursor: pageResult.nextCursor,
|
|
163
|
-
});
|
|
164
|
-
cursor = pageResult.nextCursor;
|
|
165
|
-
} while (cursor !== undefined);
|
|
166
|
-
emitter?.emit('arns:end', records);
|
|
167
|
-
logger.debug('Fetched all ArNS records', {
|
|
168
|
-
totalRecordCount: Object.keys(records).length,
|
|
169
|
-
durationMs: Date.now() - startTimestamp,
|
|
170
|
-
});
|
|
171
|
-
return records;
|
|
172
|
-
};
|
|
173
|
-
exports.fetchAllArNSRecords = fetchAllArNSRecords;
|
package/lib/cjs/utils/random.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomInt = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
const crypto_1 = require("crypto");
|
|
20
|
-
/**
|
|
21
|
-
* Cryptographically secure helper for randomness, does not support seeding
|
|
22
|
-
* @param min - the minimum value
|
|
23
|
-
* @param max - the maximum value
|
|
24
|
-
* @returns a random integer between min and max
|
|
25
|
-
*/
|
|
26
|
-
const randomInt = (min, max) => {
|
|
27
|
-
const [rand] = crypto_1.webcrypto.getRandomValues(new Uint32Array(1));
|
|
28
|
-
return min + (rand % (max - min));
|
|
29
|
-
};
|
|
30
|
-
exports.randomInt = randomInt;
|
package/lib/cjs/utils/schema.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseSchemaResult = parseSchemaResult;
|
|
4
|
-
/**
|
|
5
|
-
* @param schema - zod schema
|
|
6
|
-
* @param v - value to parse
|
|
7
|
-
* @throws {z.SafeParseError<any>} - if the value fails to parse
|
|
8
|
-
*/
|
|
9
|
-
function parseSchemaResult(schema, v) {
|
|
10
|
-
const schemaResult = schema.safeParse(v);
|
|
11
|
-
if (!schemaResult.success) {
|
|
12
|
-
throw new Error(JSON.stringify(schemaResult.error.format(), null, 2));
|
|
13
|
-
}
|
|
14
|
-
return schemaResult;
|
|
15
|
-
}
|