@ar.io/sdk 2.2.0-alpha.2 → 2.2.0-alpha.3
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 +48 -48
- package/lib/cjs/utils/ao.js +34 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/utils/ao.js +33 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/utils/ao.d.ts +58 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
3
|
+
exports.isAoANTState = exports.AntStateSchema = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -152,3 +152,36 @@ function createAoSigner(signer) {
|
|
|
152
152
|
return aoSigner;
|
|
153
153
|
}
|
|
154
154
|
exports.createAoSigner = createAoSigner;
|
|
155
|
+
// using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc)
|
|
156
|
+
exports.AntStateSchema = zod_1.z
|
|
157
|
+
.object({
|
|
158
|
+
Name: zod_1.z.string(),
|
|
159
|
+
Ticker: zod_1.z.string(),
|
|
160
|
+
Owner: zod_1.z.string(),
|
|
161
|
+
Controllers: zod_1.z.array(zod_1.z.string()),
|
|
162
|
+
Records: zod_1.z.record(zod_1.z.string(), zod_1.z
|
|
163
|
+
.object({
|
|
164
|
+
transactionId: zod_1.z.string(),
|
|
165
|
+
ttlSeconds: zod_1.z.number(),
|
|
166
|
+
})
|
|
167
|
+
.passthrough()),
|
|
168
|
+
Balances: zod_1.z.record(zod_1.z.string(), zod_1.z.number()),
|
|
169
|
+
})
|
|
170
|
+
.passthrough();
|
|
171
|
+
/**
|
|
172
|
+
* @param state
|
|
173
|
+
* @returns {boolean}
|
|
174
|
+
* @throws {z.ZodError} if the state object does not match the expected schema
|
|
175
|
+
*/
|
|
176
|
+
function isAoANTState(state, logger = index_js_1.Logger.default) {
|
|
177
|
+
try {
|
|
178
|
+
exports.AntStateSchema.parse(state);
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// this allows us to see the path of the error in the object as well as the expected schema on invalid fields
|
|
183
|
+
logger.error(error.issues);
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.isAoANTState = isAoANTState;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/utils/ao.js
CHANGED
|
@@ -18,7 +18,7 @@ import { connect, createDataItemSigner } from '@permaweb/aoconnect';
|
|
|
18
18
|
import { createData } from 'arbundles';
|
|
19
19
|
import { z } from 'zod';
|
|
20
20
|
import { defaultArweave } from '../common/arweave.js';
|
|
21
|
-
import { AOProcess } from '../common/index.js';
|
|
21
|
+
import { AOProcess, Logger } from '../common/index.js';
|
|
22
22
|
import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
|
|
23
23
|
export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, }) {
|
|
24
24
|
// AoSigner is not a Contract Signer - should probably add that to the contract signer type
|
|
@@ -145,3 +145,35 @@ export function createAoSigner(signer) {
|
|
|
145
145
|
};
|
|
146
146
|
return aoSigner;
|
|
147
147
|
}
|
|
148
|
+
// using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc)
|
|
149
|
+
export const AntStateSchema = z
|
|
150
|
+
.object({
|
|
151
|
+
Name: z.string(),
|
|
152
|
+
Ticker: z.string(),
|
|
153
|
+
Owner: z.string(),
|
|
154
|
+
Controllers: z.array(z.string()),
|
|
155
|
+
Records: z.record(z.string(), z
|
|
156
|
+
.object({
|
|
157
|
+
transactionId: z.string(),
|
|
158
|
+
ttlSeconds: z.number(),
|
|
159
|
+
})
|
|
160
|
+
.passthrough()),
|
|
161
|
+
Balances: z.record(z.string(), z.number()),
|
|
162
|
+
})
|
|
163
|
+
.passthrough();
|
|
164
|
+
/**
|
|
165
|
+
* @param state
|
|
166
|
+
* @returns {boolean}
|
|
167
|
+
* @throws {z.ZodError} if the state object does not match the expected schema
|
|
168
|
+
*/
|
|
169
|
+
export function isAoANTState(state, logger = Logger.default) {
|
|
170
|
+
try {
|
|
171
|
+
AntStateSchema.parse(state);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
// this allows us to see the path of the error in the object as well as the expected schema on invalid fields
|
|
176
|
+
logger.error(error.issues);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
package/lib/esm/version.js
CHANGED
package/lib/types/utils/ao.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Logger } from '../common/index.js';
|
|
3
|
+
import { AoANTRecord, AoANTState, AoClient, AoSigner, ContractSigner, WalletAddress } from '../types.js';
|
|
2
4
|
export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, state, stateContractTxId, antRegistryId, }: {
|
|
3
5
|
signer: AoSigner;
|
|
4
6
|
module?: string;
|
|
@@ -24,3 +26,58 @@ export declare function evolveANT({ signer, processId, luaCodeTxId, ao, }: {
|
|
|
24
26
|
}): Promise<string>;
|
|
25
27
|
export declare function isAoSigner(value: unknown): value is AoSigner;
|
|
26
28
|
export declare function createAoSigner(signer: ContractSigner): AoSigner;
|
|
29
|
+
export declare const AntStateSchema: z.ZodObject<{
|
|
30
|
+
Name: z.ZodString;
|
|
31
|
+
Ticker: z.ZodString;
|
|
32
|
+
Owner: z.ZodString;
|
|
33
|
+
Controllers: z.ZodArray<z.ZodString, "many">;
|
|
34
|
+
Records: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
35
|
+
transactionId: z.ZodString;
|
|
36
|
+
ttlSeconds: z.ZodNumber;
|
|
37
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
38
|
+
transactionId: z.ZodString;
|
|
39
|
+
ttlSeconds: z.ZodNumber;
|
|
40
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
41
|
+
transactionId: z.ZodString;
|
|
42
|
+
ttlSeconds: z.ZodNumber;
|
|
43
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
44
|
+
Balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
45
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
46
|
+
Name: z.ZodString;
|
|
47
|
+
Ticker: z.ZodString;
|
|
48
|
+
Owner: z.ZodString;
|
|
49
|
+
Controllers: z.ZodArray<z.ZodString, "many">;
|
|
50
|
+
Records: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
51
|
+
transactionId: z.ZodString;
|
|
52
|
+
ttlSeconds: z.ZodNumber;
|
|
53
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
54
|
+
transactionId: z.ZodString;
|
|
55
|
+
ttlSeconds: z.ZodNumber;
|
|
56
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
57
|
+
transactionId: z.ZodString;
|
|
58
|
+
ttlSeconds: z.ZodNumber;
|
|
59
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
60
|
+
Balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
61
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
62
|
+
Name: z.ZodString;
|
|
63
|
+
Ticker: z.ZodString;
|
|
64
|
+
Owner: z.ZodString;
|
|
65
|
+
Controllers: z.ZodArray<z.ZodString, "many">;
|
|
66
|
+
Records: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
67
|
+
transactionId: z.ZodString;
|
|
68
|
+
ttlSeconds: z.ZodNumber;
|
|
69
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
70
|
+
transactionId: z.ZodString;
|
|
71
|
+
ttlSeconds: z.ZodNumber;
|
|
72
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
73
|
+
transactionId: z.ZodString;
|
|
74
|
+
ttlSeconds: z.ZodNumber;
|
|
75
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
76
|
+
Balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
77
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
78
|
+
/**
|
|
79
|
+
* @param state
|
|
80
|
+
* @returns {boolean}
|
|
81
|
+
* @throws {z.ZodError} if the state object does not match the expected schema
|
|
82
|
+
*/
|
|
83
|
+
export declare function isAoANTState(state: object, logger?: Logger): state is AoANTState;
|
package/lib/types/version.d.ts
CHANGED