@arkiv-network/sdk 0.8.1-dev.1 → 0.9.0-next.2
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 +180 -61
- package/dist/chains/index.d.ts +17 -17
- package/dist/changeOwnership-Cy9gfyjN.d.cts +1160 -0
- package/dist/changeOwnership-Cy9gfyjN.d.cts.map +1 -0
- package/dist/changeOwnership-gXf-lBqI.d.ts +1160 -0
- package/dist/changeOwnership-gXf-lBqI.d.ts.map +1 -0
- package/dist/entity/index.cjs +4 -10
- package/dist/entity/index.d.cts +3 -3
- package/dist/entity/index.d.ts +3 -3
- package/dist/entity/index.js +3 -4
- package/dist/entity-BM1unrQf.cjs +41 -0
- package/dist/{entity-DJ0Gml9c.cjs → entity-BgaFJSaV.cjs} +4 -4
- package/dist/entity-CFAI1KyG.js +36 -0
- package/dist/entity-CFAI1KyG.js.map +1 -0
- package/dist/{entity-CniBgBSd.js → entity-CGqx_AU0.js} +4 -4
- package/dist/entity-CGqx_AU0.js.map +1 -0
- package/dist/{payload-AfUfSctb.d.ts → expirationTime-C7PZK49K.d.ts} +8 -37
- package/dist/expirationTime-C7PZK49K.d.ts.map +1 -0
- package/dist/expirationTime-CkIGNAg8.cjs +140 -0
- package/dist/{payload-D167BlJR.d.cts → expirationTime-DOB8V4B8.d.cts} +8 -37
- package/dist/expirationTime-DOB8V4B8.d.cts.map +1 -0
- package/dist/{expiry-Cgdb_dbq.js → expirationTime-UKPuA-LM.js} +62 -27
- package/dist/expirationTime-UKPuA-LM.js.map +1 -0
- package/dist/expiry-B48I-yTA.d.cts +40 -0
- package/dist/expiry-B48I-yTA.d.cts.map +1 -0
- package/dist/expiry-S2PUL8Hg.d.ts +40 -0
- package/dist/expiry-S2PUL8Hg.d.ts.map +1 -0
- package/dist/index-C-mMF5WZ.d.cts +735 -0
- package/dist/index-C-mMF5WZ.d.cts.map +1 -0
- package/dist/{index-BkqSnGJH.d.ts → index-C4zZqJ9S.d.ts} +5 -27
- package/dist/index-C4zZqJ9S.d.ts.map +1 -0
- package/dist/{index-CLhsFyVH.d.cts → index-CcVWYB6v.d.cts} +5 -27
- package/dist/index-CcVWYB6v.d.cts.map +1 -0
- package/dist/index-DCx2XC6S.d.ts +489 -0
- package/dist/index-DCx2XC6S.d.ts.map +1 -0
- package/dist/index-DLb7BfIw.d.ts +735 -0
- package/dist/index-DLb7BfIw.d.ts.map +1 -0
- package/dist/index-DzriOUm8.d.cts +489 -0
- package/dist/index-DzriOUm8.d.cts.map +1 -0
- package/dist/index.cjs +162 -146
- package/dist/index.d.cts +180 -133
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +180 -133
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -83
- package/dist/index.js.map +1 -1
- package/dist/params-BuIrJA9a.cjs +45 -0
- package/dist/params-DDJOnsNi.js +22 -0
- package/dist/params-DDJOnsNi.js.map +1 -0
- package/dist/query/index.cjs +9 -4
- package/dist/query/index.d.cts +6 -6
- package/dist/query/index.d.ts +6 -6
- package/dist/query/index.js +4 -5
- package/dist/query-D0KtuFh2.cjs +1625 -0
- package/dist/query-DpRDozmj.js +1417 -0
- package/dist/query-DpRDozmj.js.map +1 -0
- package/dist/schema/index.cjs +46 -0
- package/dist/schema/index.d.cts +2 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +3 -0
- package/dist/{attr-BXTkpnoc.cjs → schema-B9AyXcgU.cjs} +513 -246
- package/dist/{attr-tmyREHtw.js → schema-DY4sqehl.js} +427 -244
- package/dist/schema-DY4sqehl.js.map +1 -0
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.d.cts +5 -5
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.js +1 -1
- package/dist/utils/index.cjs +3 -5
- package/dist/utils/index.d.cts +3 -3
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/package.json +9 -12
- package/src/actions/public/getEntity.test.ts +69 -0
- package/src/actions/public/getEntity.ts +34 -20
- package/src/actions/public/predictEntityKeys.ts +8 -7
- package/src/actions/public/query.test.ts +58 -0
- package/src/actions/public/query.ts +41 -13
- package/src/actions/wallet/createEntity.ts +34 -63
- package/src/actions/wallet/executeBatch.test.ts +38 -0
- package/src/actions/wallet/executeBatch.ts +26 -9
- package/src/actions/wallet/extendEntity.ts +9 -8
- package/src/actions/wallet/patchEntity.ts +43 -52
- package/src/clients/createPublicClient.test.ts +10 -2
- package/src/clients/createWalletClient.ts +4 -1
- package/src/clients/decorators/arkivPublic.ts +123 -80
- package/src/clients/decorators/arkivWallet.ts +113 -65
- package/src/entity/create.test.ts +25 -21
- package/src/entity/expiry.ts +8 -6
- package/src/entity/flags.ts +1 -1
- package/src/entity/index.ts +2 -4
- package/src/entity/key.ts +3 -3
- package/src/entity/operations.ts +1 -1
- package/src/errors.ts +2 -11
- package/src/index.ts +18 -6
- package/src/query/builderBase.ts +166 -0
- package/src/query/countBuilder.test.ts +91 -0
- package/src/query/countBuilder.ts +67 -0
- package/src/query/engine.ts +9 -3
- package/src/query/errors.ts +24 -14
- package/src/query/expression.test.ts +129 -21
- package/src/query/expression.ts +323 -94
- package/src/query/index.ts +26 -4
- package/src/query/injection.test.ts +5 -11
- package/src/query/queryBuilder.test.ts +467 -58
- package/src/query/queryBuilder.ts +191 -98
- package/src/query/queryResult.ts +35 -9
- package/src/query/selection.test.ts +278 -24
- package/src/query/selection.ts +427 -86
- package/src/schema/attributes.test.ts +266 -0
- package/src/schema/attributes.ts +212 -0
- package/src/{attr → schema}/codec.test.ts +37 -5
- package/src/{attr → schema}/codec.ts +40 -11
- package/src/schema/column.ts +193 -0
- package/src/{attr → schema}/errors.ts +67 -10
- package/src/schema/index.ts +76 -0
- package/src/{attr → schema}/names.ts +4 -2
- package/src/schema/schema.test.ts +171 -0
- package/src/schema/schema.ts +250 -0
- package/src/{attr → schema}/types.ts +36 -30
- package/src/{attr → schema}/values.test.ts +62 -3
- package/src/{attr → schema}/values.ts +246 -65
- package/src/types/entity.test.ts +1 -44
- package/src/types/entity.ts +9 -55
- package/src/types/events.ts +1 -1
- package/src/types/index.ts +11 -4
- package/src/types/rpcSchema.ts +22 -16
- package/src/utils/arkivTransactions.test.ts +356 -116
- package/src/utils/arkivTransactions.ts +30 -38
- package/src/utils/entities.ts +10 -9
- package/src/utils/expirationTime.ts +5 -5
- package/src/utils/index.ts +0 -1
- package/src/utils/logger.test.ts +45 -0
- package/src/utils/logger.ts +5 -39
- package/src/utils/revert.test.ts +25 -0
- package/src/utils/revert.ts +28 -3
- package/dist/attr/index.cjs +0 -34
- package/dist/attr/index.d.cts +0 -2
- package/dist/attr/index.d.ts +0 -2
- package/dist/attr/index.js +0 -3
- package/dist/attr-tmyREHtw.js.map +0 -1
- package/dist/entity-B0t6sN7F.cjs +0 -71
- package/dist/entity-BIp_df9u.js +0 -67
- package/dist/entity-BIp_df9u.js.map +0 -1
- package/dist/entity-CniBgBSd.js.map +0 -1
- package/dist/expiry-BxOlvVWC.d.ts +0 -79
- package/dist/expiry-BxOlvVWC.d.ts.map +0 -1
- package/dist/expiry-CG9GhVXv.cjs +0 -135
- package/dist/expiry-Cgdb_dbq.js.map +0 -1
- package/dist/expiry-DRV29F1r.d.cts +0 -79
- package/dist/expiry-DRV29F1r.d.cts.map +0 -1
- package/dist/flags-DCD26uhe.cjs +0 -43
- package/dist/flags-DUT2gHEU.js +0 -33
- package/dist/flags-DUT2gHEU.js.map +0 -1
- package/dist/index-BkqSnGJH.d.ts.map +0 -1
- package/dist/index-C7fbakoI.d.cts +0 -278
- package/dist/index-C7fbakoI.d.cts.map +0 -1
- package/dist/index-CIcHPx2j.d.cts +0 -424
- package/dist/index-CIcHPx2j.d.cts.map +0 -1
- package/dist/index-CLhsFyVH.d.cts.map +0 -1
- package/dist/index-Cd2aaWme.d.ts +0 -424
- package/dist/index-Cd2aaWme.d.ts.map +0 -1
- package/dist/index-Cq6fa8AI.d.ts +0 -278
- package/dist/index-Cq6fa8AI.d.ts.map +0 -1
- package/dist/index-DaNeJUw8.d.ts +0 -955
- package/dist/index-DaNeJUw8.d.ts.map +0 -1
- package/dist/index-Dv16LO2s.d.cts +0 -955
- package/dist/index-Dv16LO2s.d.cts.map +0 -1
- package/dist/payload-AfUfSctb.d.ts.map +0 -1
- package/dist/payload-D167BlJR.d.cts.map +0 -1
- package/dist/payload-DE7wMztL.js +0 -92
- package/dist/payload-DE7wMztL.js.map +0 -1
- package/dist/payload-DqFweqiO.cjs +0 -108
- package/dist/query-9oojUdM7.cjs +0 -1128
- package/dist/query-Ber-lOJQ.js +0 -968
- package/dist/query-Ber-lOJQ.js.map +0 -1
- package/src/actions/public/getEntityCount.ts +0 -10
- package/src/attr/attributes.test.ts +0 -120
- package/src/attr/attributes.ts +0 -196
- package/src/attr/index.ts +0 -50
- package/src/types/mimeTypes.ts +0 -27
- package/src/utils/compression.test.ts +0 -32
- package/src/utils/compression.ts +0 -102
- package/src/utils/payload.ts +0 -36
- /package/src/{attr → schema}/decimal.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
const require_chains = require('./chains-Etgm64UM.cjs');
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_query = require('./query-D0KtuFh2.cjs');
|
|
3
|
+
const require_schema = require('./schema-B9AyXcgU.cjs');
|
|
4
4
|
const require_errors = require('./errors-DhV00966.cjs');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const require_entity = require('./entity-BM1unrQf.cjs');
|
|
6
|
+
const require_params = require('./params-BuIrJA9a.cjs');
|
|
7
|
+
const require_entity$1 = require('./entity-BgaFJSaV.cjs');
|
|
8
|
+
const require_expirationTime = require('./expirationTime-CkIGNAg8.cjs');
|
|
9
9
|
require('./types-CKPddlfS.cjs');
|
|
10
|
-
const require_payload = require('./payload-DqFweqiO.cjs');
|
|
11
10
|
let viem = require("viem");
|
|
12
11
|
let viem_actions = require("viem/actions");
|
|
13
12
|
|
|
@@ -28,35 +27,15 @@ async function getBlockTiming(client) {
|
|
|
28
27
|
|
|
29
28
|
//#endregion
|
|
30
29
|
//#region src/actions/public/getEntity.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
* @throws {InvalidValueError} If the key is not 32 bytes.
|
|
39
|
-
* @throws {NoEntityFoundError} If no live entity has that key — it never existed, or it was
|
|
40
|
-
* deleted or has expired.
|
|
41
|
-
*/
|
|
42
|
-
async function getEntity(client, entityKey) {
|
|
43
|
-
const { entities } = await require_query.runQuery(client, {
|
|
44
|
-
query: require_query.eq("$key", require_attr.key(entityKey)).toString(),
|
|
45
|
-
select: require_query.toRpcSelect("*"),
|
|
46
|
-
limit: 1
|
|
47
|
-
});
|
|
48
|
-
const entity = entities[0];
|
|
49
|
-
if (entity === void 0) throw new require_query.NoEntityFoundError(entityKey);
|
|
50
|
-
return entity;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/actions/public/getEntityCount.ts
|
|
55
|
-
async function getEntityCount(client) {
|
|
56
|
-
return await client.request({
|
|
57
|
-
method: "arkiv_getEntityCount",
|
|
58
|
-
params: []
|
|
30
|
+
async function getEntity(client, entityKey, schema) {
|
|
31
|
+
if (schema !== void 0 && !require_schema.isSchema(schema)) throw new require_schema.SchemaDefinitionError("getEntity() takes a schema built with defineSchema(...)");
|
|
32
|
+
const projection = require_query.projectSelection("*", schema);
|
|
33
|
+
const rpcEntity = await client.request({
|
|
34
|
+
method: "arkiv_getEntity",
|
|
35
|
+
params: [require_schema.key(entityKey).value]
|
|
59
36
|
});
|
|
37
|
+
if (rpcEntity === null) throw new require_query.NoEntityFoundError(entityKey);
|
|
38
|
+
return require_query.toRow(require_query.entityFromRpcResult(rpcEntity), projection);
|
|
60
39
|
}
|
|
61
40
|
|
|
62
41
|
//#endregion
|
|
@@ -85,17 +64,17 @@ const ATTRIBUTE_TUPLE = "(bytes32 name, uint8 typeId, bytes value)[]";
|
|
|
85
64
|
* selects — a tagged union, so a new operation is additive rather than a change to `execute`.
|
|
86
65
|
*/
|
|
87
66
|
const PAYLOAD_PARAMS = {
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
67
|
+
[require_params.OperationType.Create]: (0, viem.parseAbiParameters)(`(uint128 salt, uint64 expiresAt, uint64 minLifetime, uint8 creationFlags, ${ATTRIBUTE_TUPLE} attributes)`),
|
|
68
|
+
[require_params.OperationType.Patch]: (0, viem.parseAbiParameters)(`(bytes32 entityKey, ${ATTRIBUTE_TUPLE} mutations)`),
|
|
69
|
+
[require_params.OperationType.ExtendExpiry]: (0, viem.parseAbiParameters)("(bytes32 entityKey, uint64 expiresAt, uint64 minLifetime)"),
|
|
70
|
+
[require_params.OperationType.TransferOwnership]: (0, viem.parseAbiParameters)("(bytes32 entityKey, address newOwner)"),
|
|
71
|
+
[require_params.OperationType.Delete]: (0, viem.parseAbiParameters)("(bytes32 entityKey)")
|
|
93
72
|
};
|
|
94
73
|
/** Creates an entity. The key is derived by the engine; predict it with `predictEntityKey`. */
|
|
95
74
|
function createOperation({ salt, expiry, creationFlags, attributes }) {
|
|
96
75
|
return {
|
|
97
|
-
operation:
|
|
98
|
-
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[
|
|
76
|
+
operation: require_params.OperationType.Create,
|
|
77
|
+
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[require_params.OperationType.Create], [{
|
|
99
78
|
salt,
|
|
100
79
|
expiresAt: expiry.expiresAt,
|
|
101
80
|
minLifetime: expiry.minLifetime,
|
|
@@ -107,8 +86,8 @@ function createOperation({ salt, expiry, creationFlags, attributes }) {
|
|
|
107
86
|
/** Applies a set of mutations to an existing entity. Tombstones unset attributes. */
|
|
108
87
|
function patchOperation({ entityKey, mutations }) {
|
|
109
88
|
return {
|
|
110
|
-
operation:
|
|
111
|
-
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[
|
|
89
|
+
operation: require_params.OperationType.Patch,
|
|
90
|
+
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[require_params.OperationType.Patch], [{
|
|
112
91
|
entityKey,
|
|
113
92
|
mutations
|
|
114
93
|
}])
|
|
@@ -117,8 +96,8 @@ function patchOperation({ entityKey, mutations }) {
|
|
|
117
96
|
/** Pushes an entity's expiry further out. Extending is allowed; shortening reverts. */
|
|
118
97
|
function extendExpiryOperation({ entityKey, expiry }) {
|
|
119
98
|
return {
|
|
120
|
-
operation:
|
|
121
|
-
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[
|
|
99
|
+
operation: require_params.OperationType.ExtendExpiry,
|
|
100
|
+
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[require_params.OperationType.ExtendExpiry], [{
|
|
122
101
|
entityKey,
|
|
123
102
|
expiresAt: expiry.expiresAt,
|
|
124
103
|
minLifetime: expiry.minLifetime
|
|
@@ -128,8 +107,8 @@ function extendExpiryOperation({ entityKey, expiry }) {
|
|
|
128
107
|
/** Hands an entity to a new owner. */
|
|
129
108
|
function transferOwnershipOperation({ entityKey, newOwner }) {
|
|
130
109
|
return {
|
|
131
|
-
operation:
|
|
132
|
-
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[
|
|
110
|
+
operation: require_params.OperationType.TransferOwnership,
|
|
111
|
+
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[require_params.OperationType.TransferOwnership], [{
|
|
133
112
|
entityKey,
|
|
134
113
|
newOwner
|
|
135
114
|
}])
|
|
@@ -138,8 +117,8 @@ function transferOwnershipOperation({ entityKey, newOwner }) {
|
|
|
138
117
|
/** Deletes an entity before its expiry. */
|
|
139
118
|
function deleteOperation({ entityKey }) {
|
|
140
119
|
return {
|
|
141
|
-
operation:
|
|
142
|
-
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[
|
|
120
|
+
operation: require_params.OperationType.Delete,
|
|
121
|
+
operationData: (0, viem.encodeAbiParameters)(PAYLOAD_PARAMS[require_params.OperationType.Delete], [{ entityKey }])
|
|
143
122
|
};
|
|
144
123
|
}
|
|
145
124
|
|
|
@@ -159,7 +138,7 @@ const logger$8 = require_query.getLogger("actions:public:get-entity-nonce");
|
|
|
159
138
|
*/
|
|
160
139
|
async function getEntityNonce(client, owner) {
|
|
161
140
|
const nonce = await (0, viem_actions.readContract)(client, {
|
|
162
|
-
address:
|
|
141
|
+
address: require_params.ARKIV_ADDRESS,
|
|
163
142
|
abi: ENTITY_NONCE_ABI,
|
|
164
143
|
functionName: "entityNonce",
|
|
165
144
|
args: [owner]
|
|
@@ -189,18 +168,19 @@ async function getEntityNonce(client, owner) {
|
|
|
189
168
|
* @returns One `{ key, salt }` pair per create, in batch order. {@link PredictEntityKeysReturnType}
|
|
190
169
|
*
|
|
191
170
|
* @example A batch whose second entity points at its first.
|
|
192
|
-
* import { key } from "@arkiv-network/sdk/
|
|
171
|
+
* import { defineSchema, key, str } from "@arkiv-network/sdk/schema"
|
|
172
|
+
*
|
|
173
|
+
* const Nodes = defineSchema("nodes", { name: str(), parent: key().indexed().optional() })
|
|
193
174
|
*
|
|
194
175
|
* const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
|
|
195
|
-
* await
|
|
176
|
+
* await wallet.executeBatch({
|
|
196
177
|
* creates: [
|
|
197
|
-
* {
|
|
178
|
+
* { schema: Nodes, values: { name: "root" }, expiration, salt: parent.salt },
|
|
198
179
|
* {
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
180
|
+
* schema: Nodes,
|
|
181
|
+
* values: { name: "leaf", parent: key(parent.key) },
|
|
182
|
+
* expiration,
|
|
202
183
|
* salt: child.salt,
|
|
203
|
-
* attributes: { parent: key(parent.key) },
|
|
204
184
|
* },
|
|
205
185
|
* ],
|
|
206
186
|
* })
|
|
@@ -235,20 +215,31 @@ function resolveSalts(count, salts) {
|
|
|
235
215
|
/**
|
|
236
216
|
* Runs a single query and returns one page, with no builder in between.
|
|
237
217
|
*
|
|
218
|
+
* The selection means what it does in `select()`, and each result is the same flat row a query
|
|
219
|
+
* without a schema returns — typed from the selection, with every attribute an `ArkivValue` or
|
|
220
|
+
* `undefined`.
|
|
221
|
+
*
|
|
238
222
|
* Takes either an {@link Expression} or a raw query string. The string form is an escape hatch for
|
|
239
223
|
* a query built elsewhere — it goes to the node exactly as written, with none of the name, type or
|
|
240
224
|
* operator checks the expression combinators apply.
|
|
241
225
|
*
|
|
226
|
+
* @throws If the selection asks for nothing, or names an attribute outside the name grammar.
|
|
242
227
|
* @throws {QueryError} If the node rejects the query.
|
|
243
228
|
*/
|
|
244
|
-
function query(client, query$1, options = {}) {
|
|
245
|
-
|
|
229
|
+
async function query(client, query$1, options = {}) {
|
|
230
|
+
const projection = require_query.projectSelection(options.select);
|
|
231
|
+
const page = await require_query.runQuery(client, {
|
|
246
232
|
query: query$1.toString(),
|
|
247
|
-
select:
|
|
233
|
+
select: projection.select,
|
|
248
234
|
limit: options.limit,
|
|
249
235
|
cursor: options.cursor,
|
|
250
|
-
atBlock: options.atBlock
|
|
236
|
+
atBlock: options.atBlock,
|
|
237
|
+
count: options.count
|
|
251
238
|
});
|
|
239
|
+
return {
|
|
240
|
+
...page,
|
|
241
|
+
entities: page.entities.map((entity) => require_query.toRow(entity, projection))
|
|
242
|
+
};
|
|
252
243
|
}
|
|
253
244
|
|
|
254
245
|
//#endregion
|
|
@@ -260,7 +251,7 @@ const logger$7 = require_query.getLogger("actions:public:watch-entity-events");
|
|
|
260
251
|
* Half a block: fast enough that an event is never a whole block stale, slow enough not to hammer
|
|
261
252
|
* the node. viem's own default is derived from a 12-second Ethereum block and is far too slow here.
|
|
262
253
|
*/
|
|
263
|
-
const DEFAULT_POLLING_INTERVAL =
|
|
254
|
+
const DEFAULT_POLLING_INTERVAL = require_params.BLOCK_TIME * 1e3 / 2;
|
|
264
255
|
/**
|
|
265
256
|
* Watches entity events, calling the handlers you pass as they arrive.
|
|
266
257
|
*
|
|
@@ -327,7 +318,7 @@ function watchEntityEvents(client, parameters) {
|
|
|
327
318
|
}
|
|
328
319
|
}
|
|
329
320
|
return publicClient.watchEvent({
|
|
330
|
-
address:
|
|
321
|
+
address: require_params.ARKIV_ADDRESS,
|
|
331
322
|
events: require_entity$1.ENTITY_EVENTS_ABI,
|
|
332
323
|
pollingInterval,
|
|
333
324
|
...fromBlock !== void 0 && { fromBlock },
|
|
@@ -377,7 +368,7 @@ function toEntityEvent(topics, data, context) {
|
|
|
377
368
|
type: "EntityCreated",
|
|
378
369
|
...context,
|
|
379
370
|
...decoded.args,
|
|
380
|
-
creationFlags:
|
|
371
|
+
creationFlags: require_query.decodeCreationFlags(decoded.args.creationFlags)
|
|
381
372
|
};
|
|
382
373
|
case "EntityPatched": return {
|
|
383
374
|
type: "EntityPatched",
|
|
@@ -406,11 +397,11 @@ function toEntityEvent(topics, data, context) {
|
|
|
406
397
|
//#region src/clients/decorators/arkivPublic.ts
|
|
407
398
|
function publicArkivActions(client) {
|
|
408
399
|
return {
|
|
409
|
-
getEntity: (key$1) => getEntity(client, key$1),
|
|
410
|
-
query: (rawQuery, queryOptions) => query(client, rawQuery, queryOptions),
|
|
411
|
-
select: (selection) => new require_query.SelectQueryBuilder(client, selection),
|
|
400
|
+
getEntity: ((key$1, schema) => getEntity(client, key$1, schema)),
|
|
401
|
+
query: ((rawQuery, queryOptions) => query(client, rawQuery, queryOptions)),
|
|
402
|
+
select: ((selection) => new require_query.SelectQueryBuilder(client, selection)),
|
|
403
|
+
count: () => new require_query.CountQueryBuilder(client),
|
|
412
404
|
getBlockTiming: () => getBlockTiming(client),
|
|
413
|
-
getEntityCount: () => getEntityCount(client),
|
|
414
405
|
getEntityNonce: (owner) => getEntityNonce(client, owner),
|
|
415
406
|
predictEntityKeys: (parameters) => predictEntityKeys(client, parameters),
|
|
416
407
|
watchEntityEvents: (parameters) => watchEntityEvents(client, parameters)
|
|
@@ -479,10 +470,10 @@ function explain(name, args) {
|
|
|
479
470
|
return `an attribute name holds ${printable(String(args[1] ?? "0x00"))} at byte ${position}, which is outside the name charset (${CHARSET})`;
|
|
480
471
|
}
|
|
481
472
|
case "Ident32Empty": return "an attribute name is empty";
|
|
482
|
-
case "SystemAttributeNotWritable": return `"${identName(args[0])}" is owned by the engine and cannot be written.
|
|
473
|
+
case "SystemAttributeNotWritable": return `"${identName(args[0])}" is owned by the engine and cannot be written. Names starting with "\$" are reserved for system attributes`;
|
|
483
474
|
case "TombstoneInCreate": return `a create cannot unset "${identName(args[0])}" — nothing exists yet, so leave the name out instead`;
|
|
484
475
|
case "TombstoneValueNotEmpty": return `the tombstone for "${identName(args[0])}" carries a value; unsetting takes no value`;
|
|
485
|
-
case "InvalidValueType": return
|
|
476
|
+
case "InvalidValueType": return describeInvalidType(identName(args[0]), Number(args[1]));
|
|
486
477
|
case "AttributesNotSorted": return "attributes must be strictly ascending by name, which also makes each name unique";
|
|
487
478
|
case "TooManyAttributes": return `${String(args[0])} attributes exceeds the limit of ${String(args[1])}`;
|
|
488
479
|
case "EmptyMutations": return `the patch of ${short(args[0])} has no mutations, so it would do nothing`;
|
|
@@ -501,6 +492,19 @@ function explain(name, args) {
|
|
|
501
492
|
default: return;
|
|
502
493
|
}
|
|
503
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Why the engine refused a `typeId` — an indexed `bytes`, a known type it would not take (most
|
|
497
|
+
* likely the indexed flag, on a node that predates it), or a type it does not know.
|
|
498
|
+
*/
|
|
499
|
+
function describeInvalidType(name, typeId) {
|
|
500
|
+
try {
|
|
501
|
+
const { tag, indexed } = require_schema.decodeTypeId(typeId);
|
|
502
|
+
if (tag === "bytes" && indexed) return `"${name}" is a bytes attribute flagged as indexed, and bytes are stored but never indexed`;
|
|
503
|
+
if (indexed) return `"${name}" has type ${tag} and is flagged as indexed (type id ${typeId}), which the node does not accept. The node may not support the indexed flag yet`;
|
|
504
|
+
return `"${name}" has type ${tag} (type id ${typeId}), which the node does not accept`;
|
|
505
|
+
} catch {}
|
|
506
|
+
return `"${name}" names type id ${typeId}, which is not a known type`;
|
|
507
|
+
}
|
|
504
508
|
/** A `bytes32` Ident32 cell as the name it holds — left-aligned, null-padded. */
|
|
505
509
|
function identName(raw) {
|
|
506
510
|
if (typeof raw !== "string") return String(raw);
|
|
@@ -525,10 +529,6 @@ function printable(byte) {
|
|
|
525
529
|
//#endregion
|
|
526
530
|
//#region src/utils/arkivTransactions.ts
|
|
527
531
|
const logger$6 = require_query.getLogger("utils:arkiv-transactions");
|
|
528
|
-
const MIME_REGEX = /^[a-z][a-z0-9!#$&\-^_]*\/[a-z0-9][a-z0-9!#$&\-^_.+]*$/;
|
|
529
|
-
function validateContentType(contentType) {
|
|
530
|
-
if (!MIME_REGEX.test(contentType)) throw new require_query.InvalidContentTypeError(contentType);
|
|
531
|
-
}
|
|
532
532
|
const ENTITY_ERRORS_ABI = (0, viem.parseAbi)([
|
|
533
533
|
"error EmptyBatch()",
|
|
534
534
|
"error InvalidOpType(uint8 operation)",
|
|
@@ -558,30 +558,29 @@ async function sendArkivTransaction(client, ops, txParams) {
|
|
|
558
558
|
if (!client.chain) throw new Error("Chain required");
|
|
559
559
|
const walletClient = client;
|
|
560
560
|
const { creates, patches, deletes, extensions, ownershipChanges } = ops;
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
salt: item.salt === void 0 ? require_entity$1.randomSalt() : require_entity$1.resolveSalt(item.salt),
|
|
566
|
-
expiry: require_expiry.resolveExpiry(item.expires, expiryContext),
|
|
567
|
-
creationFlags: require_flags.encodeCreationFlags(item.flags),
|
|
568
|
-
attributes: require_attr.encodeAttributes(item.attributes, {
|
|
569
|
-
payload: item.payload,
|
|
570
|
-
contentType: item.contentType
|
|
571
|
-
})
|
|
572
|
-
});
|
|
573
|
-
});
|
|
561
|
+
const encodedCreates = (creates ?? []).map((item) => ({
|
|
562
|
+
item,
|
|
563
|
+
attributes: require_schema.encodeCreate(item.schema, item.values)
|
|
564
|
+
}));
|
|
574
565
|
const patchOps = (patches ?? []).map((item) => {
|
|
575
|
-
|
|
576
|
-
const mutations = require_attr.encodeMutations(item);
|
|
566
|
+
const mutations = require_schema.encodePatch(item.schema, item);
|
|
577
567
|
if (mutations.length === 0) throw new require_query.EmptyPatchError(item.entityKey);
|
|
578
568
|
return patchOperation({
|
|
579
569
|
entityKey: item.entityKey,
|
|
580
570
|
mutations
|
|
581
571
|
});
|
|
582
572
|
});
|
|
573
|
+
const expiryContext = { currentBlock: creates?.length || extensions?.length ? await walletClient.getBlockNumber() : 0n };
|
|
574
|
+
const createOps = encodedCreates.map(({ item, attributes }) => {
|
|
575
|
+
return createOperation({
|
|
576
|
+
salt: item.salt === void 0 ? require_entity$1.randomSalt() : require_entity$1.resolveSalt(item.salt),
|
|
577
|
+
expiry: require_expirationTime.resolveExpiry(item.expiration, expiryContext),
|
|
578
|
+
creationFlags: require_query.encodeCreationFlags(item.flags),
|
|
579
|
+
attributes
|
|
580
|
+
});
|
|
581
|
+
});
|
|
583
582
|
const extendOps = (extensions ?? []).map((item) => {
|
|
584
|
-
const expiry =
|
|
583
|
+
const expiry = require_expirationTime.resolveExpiry(item.expiration, expiryContext);
|
|
585
584
|
return extendExpiryOperation({
|
|
586
585
|
entityKey: item.entityKey,
|
|
587
586
|
expiry
|
|
@@ -602,7 +601,7 @@ async function sendArkivTransaction(client, ops, txParams) {
|
|
|
602
601
|
let txHash;
|
|
603
602
|
try {
|
|
604
603
|
txHash = await walletClient.writeContract({
|
|
605
|
-
address:
|
|
604
|
+
address: require_params.ARKIV_ADDRESS,
|
|
606
605
|
abi: EXECUTE_ABI$1,
|
|
607
606
|
functionName: "execute",
|
|
608
607
|
args: [operations],
|
|
@@ -615,7 +614,7 @@ async function sendArkivTransaction(client, ops, txParams) {
|
|
|
615
614
|
if (receipt.status === "reverted") {
|
|
616
615
|
try {
|
|
617
616
|
await walletClient.simulateContract({
|
|
618
|
-
address:
|
|
617
|
+
address: require_params.ARKIV_ADDRESS,
|
|
619
618
|
abi: EXECUTE_ABI$1,
|
|
620
619
|
functionName: "execute",
|
|
621
620
|
args: [operations],
|
|
@@ -667,7 +666,7 @@ function readAppliedOperations(receipt, expected) {
|
|
|
667
666
|
const createdExpiries = [];
|
|
668
667
|
const extendedExpiries = [];
|
|
669
668
|
for (const log of receipt.logs ?? []) {
|
|
670
|
-
if (log.address.toLowerCase() !==
|
|
669
|
+
if (log.address.toLowerCase() !== require_params.ARKIV_ADDRESS.toLowerCase()) continue;
|
|
671
670
|
const decoded = decodeEntityLog(log);
|
|
672
671
|
if (decoded === void 0) continue;
|
|
673
672
|
if (decoded.eventName === "EntityCreated") {
|
|
@@ -716,9 +715,13 @@ async function changeOwnership(client, data, txParams) {
|
|
|
716
715
|
//#endregion
|
|
717
716
|
//#region src/actions/wallet/createEntity.ts
|
|
718
717
|
const logger$4 = require_query.getLogger("actions:wallet:create-entity");
|
|
719
|
-
async function createEntity(client,
|
|
720
|
-
logger$4("createEntity %o",
|
|
721
|
-
const { receipt, createdEntityKeys, createdExpiries } = await sendArkivTransaction(client, { creates: [
|
|
718
|
+
async function createEntity(client, schema, values, options, txParams) {
|
|
719
|
+
logger$4("createEntity %o", values);
|
|
720
|
+
const { receipt, createdEntityKeys, createdExpiries } = await sendArkivTransaction(client, { creates: [{
|
|
721
|
+
...options,
|
|
722
|
+
schema,
|
|
723
|
+
values
|
|
724
|
+
}] }, txParams);
|
|
722
725
|
logger$4("Receipt from createEntity %o", receipt);
|
|
723
726
|
const [entityKey] = createdEntityKeys;
|
|
724
727
|
const [expiresAt] = createdExpiries;
|
|
@@ -778,13 +781,17 @@ async function extendEntity(client, data, txParams) {
|
|
|
778
781
|
//#endregion
|
|
779
782
|
//#region src/actions/wallet/patchEntity.ts
|
|
780
783
|
const logger = require_query.getLogger("actions:wallet:patch-entity");
|
|
781
|
-
async function patchEntity(client,
|
|
782
|
-
logger("patchEntity %o",
|
|
783
|
-
const { receipt } = await sendArkivTransaction(client, { patches: [
|
|
784
|
+
async function patchEntity(client, schema, entityKey, changes, txParams) {
|
|
785
|
+
logger("patchEntity %s %o", entityKey, changes);
|
|
786
|
+
const { receipt } = await sendArkivTransaction(client, { patches: [{
|
|
787
|
+
...changes,
|
|
788
|
+
schema,
|
|
789
|
+
entityKey
|
|
790
|
+
}] }, txParams);
|
|
784
791
|
logger("Receipt from patchEntity %o", receipt);
|
|
785
792
|
return {
|
|
786
793
|
txHash: receipt.transactionHash,
|
|
787
|
-
entityKey
|
|
794
|
+
entityKey
|
|
788
795
|
};
|
|
789
796
|
}
|
|
790
797
|
|
|
@@ -792,8 +799,8 @@ async function patchEntity(client, data, txParams) {
|
|
|
792
799
|
//#region src/clients/decorators/arkivWallet.ts
|
|
793
800
|
function walletArkivActions(client) {
|
|
794
801
|
return {
|
|
795
|
-
createEntity: (
|
|
796
|
-
patchEntity: (
|
|
802
|
+
createEntity: (schema, values, options, txParams) => createEntity(client, schema, values, options, txParams),
|
|
803
|
+
patchEntity: (schema, entityKey, changes, txParams) => patchEntity(client, schema, entityKey, changes, txParams),
|
|
797
804
|
deleteEntity: (data, txParams) => deleteEntity(client, data, txParams),
|
|
798
805
|
extendEntity: (data, txParams) => extendEntity(client, data, txParams),
|
|
799
806
|
changeOwnership: (data, txParams) => changeOwnership(client, data, txParams),
|
|
@@ -809,7 +816,10 @@ function walletArkivActions(client) {
|
|
|
809
816
|
*
|
|
810
817
|
* A Wallet Client signs and sends transactions, so it carries an `account` and exposes everything
|
|
811
818
|
* that mutates state — `createEntity`, `patchEntity`, `deleteEntity`, `extendEntity`,
|
|
812
|
-
* `changeOwnership` and `executeBatch` —
|
|
819
|
+
* `changeOwnership` and `executeBatch` — alongside the viem actions those need, such as
|
|
820
|
+
* `getBlockNumber`, `readContract` and `waitForTransactionReceipt`. It does not have the Arkiv
|
|
821
|
+
* read actions (`getEntity`, `query`, `select`, `watchEntityEvents`, `predictEntityKeys`); read
|
|
822
|
+
* through a Public Client from `createPublicClient` for those.
|
|
813
823
|
*
|
|
814
824
|
* @param parameters - Configuration object for the wallet client (chain, transport, account, etc.)
|
|
815
825
|
* @returns An Arkiv Wallet Client. {@link WalletArkivClient}
|
|
@@ -851,63 +861,69 @@ function chainFromName(name) {
|
|
|
851
861
|
}
|
|
852
862
|
|
|
853
863
|
//#endregion
|
|
854
|
-
exports.ConflictingMutationError =
|
|
855
|
-
exports.
|
|
856
|
-
exports.
|
|
864
|
+
exports.ConflictingMutationError = require_schema.ConflictingMutationError;
|
|
865
|
+
exports.CountQueryBuilder = require_query.CountQueryBuilder;
|
|
866
|
+
exports.DECIMAL_SCALE = require_schema.DECIMAL_SCALE;
|
|
867
|
+
exports.DECIMAL_UNIT = require_schema.DECIMAL_UNIT;
|
|
857
868
|
exports.ENTITY_EVENTS_ABI = require_entity$1.ENTITY_EVENTS_ABI;
|
|
858
869
|
exports.EmptyPatchError = require_query.EmptyPatchError;
|
|
859
870
|
exports.Entity = require_entity.Entity;
|
|
860
871
|
exports.EntityMutationError = require_query.EntityMutationError;
|
|
861
|
-
exports.
|
|
862
|
-
exports.
|
|
863
|
-
exports.
|
|
864
|
-
exports.
|
|
865
|
-
exports.
|
|
872
|
+
exports.EntityTooLargeError = require_schema.EntityTooLargeError;
|
|
873
|
+
exports.ExpirationTime = require_expirationTime.ExpirationTime;
|
|
874
|
+
exports.I32_MAX = require_schema.I32_MAX;
|
|
875
|
+
exports.I32_MIN = require_schema.I32_MIN;
|
|
876
|
+
exports.INDEXED_FLAG = require_schema.INDEXED_FLAG;
|
|
877
|
+
exports.InvalidAttributeNameError = require_schema.InvalidAttributeNameError;
|
|
866
878
|
exports.InvalidCreationFlagsError = require_errors.InvalidCreationFlagsError;
|
|
867
879
|
exports.InvalidExpiryError = require_errors.InvalidExpiryError;
|
|
868
880
|
exports.InvalidSaltError = require_errors.InvalidSaltError;
|
|
869
|
-
exports.InvalidValueError =
|
|
870
|
-
exports.MAX_ATTRIBUTES =
|
|
871
|
-
exports.
|
|
872
|
-
exports.
|
|
873
|
-
exports.
|
|
881
|
+
exports.InvalidValueError = require_schema.InvalidValueError;
|
|
882
|
+
exports.MAX_ATTRIBUTES = require_schema.MAX_ATTRIBUTES;
|
|
883
|
+
exports.MAX_BYTES_LENGTH = require_schema.MAX_BYTES_LENGTH;
|
|
884
|
+
exports.MAX_ENTITY_BYTES = require_schema.MAX_ENTITY_BYTES;
|
|
885
|
+
exports.MAX_EXPIRES_AT = require_params.MAX_EXPIRES_AT;
|
|
886
|
+
exports.MAX_NAME_BYTES = require_schema.MAX_NAME_BYTES;
|
|
874
887
|
exports.MAX_SALT = require_entity$1.MAX_SALT;
|
|
875
|
-
exports.MAX_STRING_BYTES =
|
|
876
|
-
exports.MissingValueError =
|
|
888
|
+
exports.MAX_STRING_BYTES = require_schema.MAX_STRING_BYTES;
|
|
889
|
+
exports.MissingValueError = require_schema.MissingValueError;
|
|
877
890
|
exports.NO_SALT = require_entity$1.NO_SALT;
|
|
878
891
|
exports.NoEntityFoundError = require_query.NoEntityFoundError;
|
|
879
892
|
exports.NoMoreResultsError = require_query.NoMoreResultsError;
|
|
880
893
|
exports.NoRandomSourceError = require_errors.NoRandomSourceError;
|
|
881
|
-
exports.
|
|
894
|
+
exports.SCHEMA_ATTRIBUTE = require_schema.SCHEMA_ATTRIBUTE;
|
|
895
|
+
exports.SYSTEM_FIELDS = require_query.SYSTEM_FIELDS;
|
|
896
|
+
exports.SchemaDefinitionError = require_schema.SchemaDefinitionError;
|
|
897
|
+
exports.SchemaMismatchError = require_schema.SchemaMismatchError;
|
|
882
898
|
exports.SelectQueryBuilder = require_query.SelectQueryBuilder;
|
|
883
|
-
exports.TooManyAttributesError =
|
|
884
|
-
exports.U256_MAX =
|
|
885
|
-
exports.U64_MAX =
|
|
886
|
-
exports.UnknownAttributeTypeError =
|
|
887
|
-
exports.UntypedValueError =
|
|
888
|
-
exports.addr =
|
|
889
|
-
exports.bool =
|
|
890
|
-
exports.
|
|
899
|
+
exports.TooManyAttributesError = require_schema.TooManyAttributesError;
|
|
900
|
+
exports.U256_MAX = require_schema.U256_MAX;
|
|
901
|
+
exports.U64_MAX = require_schema.U64_MAX;
|
|
902
|
+
exports.UnknownAttributeTypeError = require_schema.UnknownAttributeTypeError;
|
|
903
|
+
exports.UntypedValueError = require_schema.UntypedValueError;
|
|
904
|
+
exports.addr = require_schema.addr;
|
|
905
|
+
exports.bool = require_schema.bool;
|
|
906
|
+
exports.bytes = require_schema.bytes;
|
|
907
|
+
exports.bytes32 = require_schema.bytes32;
|
|
891
908
|
exports.chainFromName = chainFromName;
|
|
892
909
|
exports.createPublicClient = createPublicClient;
|
|
893
910
|
exports.createWalletClient = createWalletClient;
|
|
894
|
-
exports.dec =
|
|
895
|
-
exports.decFromUnits =
|
|
896
|
-
exports.decUnits =
|
|
897
|
-
exports.
|
|
898
|
-
exports.
|
|
899
|
-
exports.i32 =
|
|
900
|
-
exports.isArkivValue =
|
|
901
|
-
exports.
|
|
902
|
-
exports.
|
|
903
|
-
exports.
|
|
911
|
+
exports.dec = require_schema.dec;
|
|
912
|
+
exports.decFromUnits = require_schema.decFromUnits;
|
|
913
|
+
exports.decUnits = require_schema.decUnits;
|
|
914
|
+
exports.defineSchema = require_schema.defineSchema;
|
|
915
|
+
exports.describeColumns = require_schema.describeColumns;
|
|
916
|
+
exports.i32 = require_schema.i32;
|
|
917
|
+
exports.isArkivValue = require_schema.isArkivValue;
|
|
918
|
+
exports.isColumn = require_schema.isColumn;
|
|
919
|
+
exports.isSchema = require_schema.isSchema;
|
|
920
|
+
exports.isValidAttributeName = require_schema.isValidAttributeName;
|
|
921
|
+
exports.key = require_schema.key;
|
|
922
|
+
exports.lookupColumn = require_schema.lookupColumn;
|
|
904
923
|
exports.predictEntityKey = require_entity$1.predictEntityKey;
|
|
905
924
|
exports.randomSalt = require_entity$1.randomSalt;
|
|
906
|
-
exports.
|
|
907
|
-
exports.
|
|
908
|
-
exports.
|
|
909
|
-
exports.
|
|
910
|
-
exports.
|
|
911
|
-
exports.u256 = require_attr.u256;
|
|
912
|
-
exports.u64 = require_attr.u64;
|
|
913
|
-
exports.validateAttributeName = require_attr.validateAttributeName;
|
|
925
|
+
exports.str = require_schema.str;
|
|
926
|
+
exports.toValue = require_schema.toValue;
|
|
927
|
+
exports.u256 = require_schema.u256;
|
|
928
|
+
exports.u64 = require_schema.u64;
|
|
929
|
+
exports.validateAttributeName = require_schema.validateAttributeName;
|