@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.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { t as chains_exports } from "./chains-DmrgfF3p.js";
|
|
2
|
-
import {
|
|
3
|
-
import { C as
|
|
2
|
+
import { D as SYSTEM_FIELDS, E as encodeCreationFlags, F as getLogger, M as EntityMutationError, N as NoEntityFoundError, O as projectSelection, P as NoMoreResultsError, T as decodeCreationFlags, b as runQuery, j as EmptyPatchError, k as toRow, r as CountQueryBuilder, t as SelectQueryBuilder, w as entityFromRpcResult } from "./query-DpRDozmj.js";
|
|
3
|
+
import { A as key, B as DECIMAL_SCALE, C as bool, D as decFromUnits, E as dec, F as isColumn, G as InvalidValueError, H as ConflictingMutationError, I as INDEXED_FLAG, J as SchemaMismatchError, K as MissingValueError, M as toValue, N as u256, O as decUnits, P as u64, R as isArkivValue, S as addr, T as bytes32, U as EntityTooLargeError, V as DECIMAL_UNIT, W as InvalidAttributeNameError, X as UnknownAttributeTypeError, Y as TooManyAttributesError, Z as UntypedValueError, _ as I32_MIN, a as SCHEMA_ATTRIBUTE, b as U256_MAX, c as isSchema, d as isValidAttributeName, f as validateAttributeName, g as I32_MAX, h as decodeTypeId, i as MAX_ATTRIBUTES, j as str, k as i32, l as lookupColumn, n as encodeCreate, o as defineSchema, q as SchemaDefinitionError, r as encodePatch, s as describeColumns, t as MAX_ENTITY_BYTES, u as MAX_NAME_BYTES, v as MAX_BYTES_LENGTH, w as bytes, x as U64_MAX, y as MAX_STRING_BYTES } from "./schema-DY4sqehl.js";
|
|
4
4
|
import { i as NoRandomSourceError, n as InvalidExpiryError, r as InvalidSaltError, t as InvalidCreationFlagsError } from "./errors-D2E1GRjw.js";
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import { a as
|
|
8
|
-
import {
|
|
5
|
+
import { t as Entity } from "./entity-CFAI1KyG.js";
|
|
6
|
+
import { i as BLOCK_TIME, n as OperationType, r as ARKIV_ADDRESS, t as MAX_EXPIRES_AT } from "./params-DDJOnsNi.js";
|
|
7
|
+
import { a as randomSalt, i as predictEntityKey, n as MAX_SALT, o as resolveSalt, r as NO_SALT, t as ENTITY_EVENTS_ABI } from "./entity-CGqx_AU0.js";
|
|
8
|
+
import { n as resolveExpiry, t as ExpirationTime } from "./expirationTime-UKPuA-LM.js";
|
|
9
9
|
import "./types-Bx1EKe0v.js";
|
|
10
|
-
import { n as stringToPayload, r as ExpirationTime, t as jsonToPayload } from "./payload-DE7wMztL.js";
|
|
11
10
|
import { BaseError, ContractFunctionExecutionError, ContractFunctionRevertedError, TransactionExecutionError, createClient, decodeEventLog, encodeAbiParameters, hexToString, parseAbi, parseAbiParameters, publicActions, walletActions } from "viem";
|
|
12
11
|
import { getChainId, readContract } from "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 runQuery(client, {
|
|
44
|
-
query: eq("$key", key(entityKey)).toString(),
|
|
45
|
-
select: toRpcSelect("*"),
|
|
46
|
-
limit: 1
|
|
47
|
-
});
|
|
48
|
-
const entity = entities[0];
|
|
49
|
-
if (entity === void 0) throw new 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 && !isSchema(schema)) throw new SchemaDefinitionError("getEntity() takes a schema built with defineSchema(...)");
|
|
32
|
+
const projection = projectSelection("*", schema);
|
|
33
|
+
const rpcEntity = await client.request({
|
|
34
|
+
method: "arkiv_getEntity",
|
|
35
|
+
params: [key(entityKey).value]
|
|
59
36
|
});
|
|
37
|
+
if (rpcEntity === null) throw new NoEntityFoundError(entityKey);
|
|
38
|
+
return toRow(entityFromRpcResult(rpcEntity), projection);
|
|
60
39
|
}
|
|
61
40
|
|
|
62
41
|
//#endregion
|
|
@@ -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 = projectSelection(options.select);
|
|
231
|
+
const page = await 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) => toRow(entity, projection))
|
|
242
|
+
};
|
|
252
243
|
}
|
|
253
244
|
|
|
254
245
|
//#endregion
|
|
@@ -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 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 SelectQueryBuilder(client, selection)),
|
|
403
|
+
count: () => new 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 } = 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 = 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 InvalidContentTypeError(contentType);
|
|
531
|
-
}
|
|
532
532
|
const ENTITY_ERRORS_ABI = 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 ? randomSalt() : resolveSalt(item.salt),
|
|
566
|
-
expiry: resolveExpiry(item.expires, expiryContext),
|
|
567
|
-
creationFlags: encodeCreationFlags(item.flags),
|
|
568
|
-
attributes: encodeAttributes(item.attributes, {
|
|
569
|
-
payload: item.payload,
|
|
570
|
-
contentType: item.contentType
|
|
571
|
-
})
|
|
572
|
-
});
|
|
573
|
-
});
|
|
561
|
+
const encodedCreates = (creates ?? []).map((item) => ({
|
|
562
|
+
item,
|
|
563
|
+
attributes: encodeCreate(item.schema, item.values)
|
|
564
|
+
}));
|
|
574
565
|
const patchOps = (patches ?? []).map((item) => {
|
|
575
|
-
|
|
576
|
-
const mutations = encodeMutations(item);
|
|
566
|
+
const mutations = encodePatch(item.schema, item);
|
|
577
567
|
if (mutations.length === 0) throw new 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 ? randomSalt() : resolveSalt(item.salt),
|
|
577
|
+
expiry: resolveExpiry(item.expiration, expiryContext),
|
|
578
|
+
creationFlags: encodeCreationFlags(item.flags),
|
|
579
|
+
attributes
|
|
580
|
+
});
|
|
581
|
+
});
|
|
583
582
|
const extendOps = (extensions ?? []).map((item) => {
|
|
584
|
-
const expiry = resolveExpiry(item.
|
|
583
|
+
const expiry = resolveExpiry(item.expiration, expiryContext);
|
|
585
584
|
return extendExpiryOperation({
|
|
586
585
|
entityKey: item.entityKey,
|
|
587
586
|
expiry
|
|
@@ -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 = 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 = 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,5 +861,5 @@ function chainFromName(name) {
|
|
|
851
861
|
}
|
|
852
862
|
|
|
853
863
|
//#endregion
|
|
854
|
-
export { ConflictingMutationError, DECIMAL_SCALE, DECIMAL_UNIT, ENTITY_EVENTS_ABI, EmptyPatchError, Entity, EntityMutationError, ExpirationTime, I32_MAX, I32_MIN,
|
|
864
|
+
export { ConflictingMutationError, CountQueryBuilder, DECIMAL_SCALE, DECIMAL_UNIT, ENTITY_EVENTS_ABI, EmptyPatchError, Entity, EntityMutationError, EntityTooLargeError, ExpirationTime, I32_MAX, I32_MIN, INDEXED_FLAG, InvalidAttributeNameError, InvalidCreationFlagsError, InvalidExpiryError, InvalidSaltError, InvalidValueError, MAX_ATTRIBUTES, MAX_BYTES_LENGTH, MAX_ENTITY_BYTES, MAX_EXPIRES_AT, MAX_NAME_BYTES, MAX_SALT, MAX_STRING_BYTES, MissingValueError, NO_SALT, NoEntityFoundError, NoMoreResultsError, NoRandomSourceError, SCHEMA_ATTRIBUTE, SYSTEM_FIELDS, SchemaDefinitionError, SchemaMismatchError, SelectQueryBuilder, TooManyAttributesError, U256_MAX, U64_MAX, UnknownAttributeTypeError, UntypedValueError, addr, bool, bytes, bytes32, chainFromName, createPublicClient, createWalletClient, dec, decFromUnits, decUnits, defineSchema, describeColumns, i32, isArkivValue, isColumn, isSchema, isValidAttributeName, key, lookupColumn, predictEntityKey, randomSalt, str, toValue, u256, u64, validateAttributeName };
|
|
855
865
|
//# sourceMappingURL=index.js.map
|