@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.
Files changed (184) hide show
  1. package/README.md +180 -61
  2. package/dist/chains/index.d.ts +17 -17
  3. package/dist/changeOwnership-Cy9gfyjN.d.cts +1160 -0
  4. package/dist/changeOwnership-Cy9gfyjN.d.cts.map +1 -0
  5. package/dist/changeOwnership-gXf-lBqI.d.ts +1160 -0
  6. package/dist/changeOwnership-gXf-lBqI.d.ts.map +1 -0
  7. package/dist/entity/index.cjs +4 -10
  8. package/dist/entity/index.d.cts +3 -3
  9. package/dist/entity/index.d.ts +3 -3
  10. package/dist/entity/index.js +3 -4
  11. package/dist/entity-BM1unrQf.cjs +41 -0
  12. package/dist/{entity-DJ0Gml9c.cjs → entity-BgaFJSaV.cjs} +4 -4
  13. package/dist/entity-CFAI1KyG.js +36 -0
  14. package/dist/entity-CFAI1KyG.js.map +1 -0
  15. package/dist/{entity-CniBgBSd.js → entity-CGqx_AU0.js} +4 -4
  16. package/dist/entity-CGqx_AU0.js.map +1 -0
  17. package/dist/{payload-AfUfSctb.d.ts → expirationTime-C7PZK49K.d.ts} +8 -37
  18. package/dist/expirationTime-C7PZK49K.d.ts.map +1 -0
  19. package/dist/expirationTime-CkIGNAg8.cjs +140 -0
  20. package/dist/{payload-D167BlJR.d.cts → expirationTime-DOB8V4B8.d.cts} +8 -37
  21. package/dist/expirationTime-DOB8V4B8.d.cts.map +1 -0
  22. package/dist/{expiry-Cgdb_dbq.js → expirationTime-UKPuA-LM.js} +62 -27
  23. package/dist/expirationTime-UKPuA-LM.js.map +1 -0
  24. package/dist/expiry-B48I-yTA.d.cts +40 -0
  25. package/dist/expiry-B48I-yTA.d.cts.map +1 -0
  26. package/dist/expiry-S2PUL8Hg.d.ts +40 -0
  27. package/dist/expiry-S2PUL8Hg.d.ts.map +1 -0
  28. package/dist/index-C-mMF5WZ.d.cts +735 -0
  29. package/dist/index-C-mMF5WZ.d.cts.map +1 -0
  30. package/dist/{index-BkqSnGJH.d.ts → index-C4zZqJ9S.d.ts} +5 -27
  31. package/dist/index-C4zZqJ9S.d.ts.map +1 -0
  32. package/dist/{index-CLhsFyVH.d.cts → index-CcVWYB6v.d.cts} +5 -27
  33. package/dist/index-CcVWYB6v.d.cts.map +1 -0
  34. package/dist/index-DCx2XC6S.d.ts +489 -0
  35. package/dist/index-DCx2XC6S.d.ts.map +1 -0
  36. package/dist/index-DLb7BfIw.d.ts +735 -0
  37. package/dist/index-DLb7BfIw.d.ts.map +1 -0
  38. package/dist/index-DzriOUm8.d.cts +489 -0
  39. package/dist/index-DzriOUm8.d.cts.map +1 -0
  40. package/dist/index.cjs +162 -146
  41. package/dist/index.d.cts +180 -133
  42. package/dist/index.d.cts.map +1 -1
  43. package/dist/index.d.ts +180 -133
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +93 -83
  46. package/dist/index.js.map +1 -1
  47. package/dist/params-BuIrJA9a.cjs +45 -0
  48. package/dist/params-DDJOnsNi.js +22 -0
  49. package/dist/params-DDJOnsNi.js.map +1 -0
  50. package/dist/query/index.cjs +9 -4
  51. package/dist/query/index.d.cts +6 -6
  52. package/dist/query/index.d.ts +6 -6
  53. package/dist/query/index.js +4 -5
  54. package/dist/query-D0KtuFh2.cjs +1625 -0
  55. package/dist/query-DpRDozmj.js +1417 -0
  56. package/dist/query-DpRDozmj.js.map +1 -0
  57. package/dist/schema/index.cjs +46 -0
  58. package/dist/schema/index.d.cts +2 -0
  59. package/dist/schema/index.d.ts +2 -0
  60. package/dist/schema/index.js +3 -0
  61. package/dist/{attr-BXTkpnoc.cjs → schema-B9AyXcgU.cjs} +513 -246
  62. package/dist/{attr-tmyREHtw.js → schema-DY4sqehl.js} +427 -244
  63. package/dist/schema-DY4sqehl.js.map +1 -0
  64. package/dist/types/index.cjs +1 -1
  65. package/dist/types/index.d.cts +5 -5
  66. package/dist/types/index.d.ts +5 -5
  67. package/dist/types/index.js +1 -1
  68. package/dist/utils/index.cjs +3 -5
  69. package/dist/utils/index.d.cts +3 -3
  70. package/dist/utils/index.d.ts +3 -3
  71. package/dist/utils/index.js +3 -3
  72. package/package.json +9 -12
  73. package/src/actions/public/getEntity.test.ts +69 -0
  74. package/src/actions/public/getEntity.ts +34 -20
  75. package/src/actions/public/predictEntityKeys.ts +8 -7
  76. package/src/actions/public/query.test.ts +58 -0
  77. package/src/actions/public/query.ts +41 -13
  78. package/src/actions/wallet/createEntity.ts +34 -63
  79. package/src/actions/wallet/executeBatch.test.ts +38 -0
  80. package/src/actions/wallet/executeBatch.ts +26 -9
  81. package/src/actions/wallet/extendEntity.ts +9 -8
  82. package/src/actions/wallet/patchEntity.ts +43 -52
  83. package/src/clients/createPublicClient.test.ts +10 -2
  84. package/src/clients/createWalletClient.ts +4 -1
  85. package/src/clients/decorators/arkivPublic.ts +123 -80
  86. package/src/clients/decorators/arkivWallet.ts +113 -65
  87. package/src/entity/create.test.ts +25 -21
  88. package/src/entity/expiry.ts +8 -6
  89. package/src/entity/flags.ts +1 -1
  90. package/src/entity/index.ts +2 -4
  91. package/src/entity/key.ts +3 -3
  92. package/src/entity/operations.ts +1 -1
  93. package/src/errors.ts +2 -11
  94. package/src/index.ts +18 -6
  95. package/src/query/builderBase.ts +166 -0
  96. package/src/query/countBuilder.test.ts +91 -0
  97. package/src/query/countBuilder.ts +67 -0
  98. package/src/query/engine.ts +9 -3
  99. package/src/query/errors.ts +24 -14
  100. package/src/query/expression.test.ts +129 -21
  101. package/src/query/expression.ts +323 -94
  102. package/src/query/index.ts +26 -4
  103. package/src/query/injection.test.ts +5 -11
  104. package/src/query/queryBuilder.test.ts +467 -58
  105. package/src/query/queryBuilder.ts +191 -98
  106. package/src/query/queryResult.ts +35 -9
  107. package/src/query/selection.test.ts +278 -24
  108. package/src/query/selection.ts +427 -86
  109. package/src/schema/attributes.test.ts +266 -0
  110. package/src/schema/attributes.ts +212 -0
  111. package/src/{attr → schema}/codec.test.ts +37 -5
  112. package/src/{attr → schema}/codec.ts +40 -11
  113. package/src/schema/column.ts +193 -0
  114. package/src/{attr → schema}/errors.ts +67 -10
  115. package/src/schema/index.ts +76 -0
  116. package/src/{attr → schema}/names.ts +4 -2
  117. package/src/schema/schema.test.ts +171 -0
  118. package/src/schema/schema.ts +250 -0
  119. package/src/{attr → schema}/types.ts +36 -30
  120. package/src/{attr → schema}/values.test.ts +62 -3
  121. package/src/{attr → schema}/values.ts +246 -65
  122. package/src/types/entity.test.ts +1 -44
  123. package/src/types/entity.ts +9 -55
  124. package/src/types/events.ts +1 -1
  125. package/src/types/index.ts +11 -4
  126. package/src/types/rpcSchema.ts +22 -16
  127. package/src/utils/arkivTransactions.test.ts +356 -116
  128. package/src/utils/arkivTransactions.ts +30 -38
  129. package/src/utils/entities.ts +10 -9
  130. package/src/utils/expirationTime.ts +5 -5
  131. package/src/utils/index.ts +0 -1
  132. package/src/utils/logger.test.ts +45 -0
  133. package/src/utils/logger.ts +5 -39
  134. package/src/utils/revert.test.ts +25 -0
  135. package/src/utils/revert.ts +28 -3
  136. package/dist/attr/index.cjs +0 -34
  137. package/dist/attr/index.d.cts +0 -2
  138. package/dist/attr/index.d.ts +0 -2
  139. package/dist/attr/index.js +0 -3
  140. package/dist/attr-tmyREHtw.js.map +0 -1
  141. package/dist/entity-B0t6sN7F.cjs +0 -71
  142. package/dist/entity-BIp_df9u.js +0 -67
  143. package/dist/entity-BIp_df9u.js.map +0 -1
  144. package/dist/entity-CniBgBSd.js.map +0 -1
  145. package/dist/expiry-BxOlvVWC.d.ts +0 -79
  146. package/dist/expiry-BxOlvVWC.d.ts.map +0 -1
  147. package/dist/expiry-CG9GhVXv.cjs +0 -135
  148. package/dist/expiry-Cgdb_dbq.js.map +0 -1
  149. package/dist/expiry-DRV29F1r.d.cts +0 -79
  150. package/dist/expiry-DRV29F1r.d.cts.map +0 -1
  151. package/dist/flags-DCD26uhe.cjs +0 -43
  152. package/dist/flags-DUT2gHEU.js +0 -33
  153. package/dist/flags-DUT2gHEU.js.map +0 -1
  154. package/dist/index-BkqSnGJH.d.ts.map +0 -1
  155. package/dist/index-C7fbakoI.d.cts +0 -278
  156. package/dist/index-C7fbakoI.d.cts.map +0 -1
  157. package/dist/index-CIcHPx2j.d.cts +0 -424
  158. package/dist/index-CIcHPx2j.d.cts.map +0 -1
  159. package/dist/index-CLhsFyVH.d.cts.map +0 -1
  160. package/dist/index-Cd2aaWme.d.ts +0 -424
  161. package/dist/index-Cd2aaWme.d.ts.map +0 -1
  162. package/dist/index-Cq6fa8AI.d.ts +0 -278
  163. package/dist/index-Cq6fa8AI.d.ts.map +0 -1
  164. package/dist/index-DaNeJUw8.d.ts +0 -955
  165. package/dist/index-DaNeJUw8.d.ts.map +0 -1
  166. package/dist/index-Dv16LO2s.d.cts +0 -955
  167. package/dist/index-Dv16LO2s.d.cts.map +0 -1
  168. package/dist/payload-AfUfSctb.d.ts.map +0 -1
  169. package/dist/payload-D167BlJR.d.cts.map +0 -1
  170. package/dist/payload-DE7wMztL.js +0 -92
  171. package/dist/payload-DE7wMztL.js.map +0 -1
  172. package/dist/payload-DqFweqiO.cjs +0 -108
  173. package/dist/query-9oojUdM7.cjs +0 -1128
  174. package/dist/query-Ber-lOJQ.js +0 -968
  175. package/dist/query-Ber-lOJQ.js.map +0 -1
  176. package/src/actions/public/getEntityCount.ts +0 -10
  177. package/src/attr/attributes.test.ts +0 -120
  178. package/src/attr/attributes.ts +0 -196
  179. package/src/attr/index.ts +0 -50
  180. package/src/types/mimeTypes.ts +0 -27
  181. package/src/utils/compression.test.ts +0 -32
  182. package/src/utils/compression.ts +0 -102
  183. package/src/utils/payload.ts +0 -36
  184. /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 { A as DECIMAL_UNIT, C as str, E as u64, F as TooManyAttributesError, I as UnknownAttributeTypeError, L as UntypedValueError, M as InvalidAttributeNameError, N as InvalidValueError, O as isArkivValue, P as MissingValueError, S as key, T as u256, _ as bytes32, a as MAX_NAME_BYTES, b as decUnits, d as I32_MIN, f as MAX_STRING_BYTES, g as bool, h as addr, i as encodeMutations, j as ConflictingMutationError, k as DECIMAL_SCALE, m as U64_MAX, n as MAX_PAYLOAD_BYTES, o as isValidAttributeName, p as U256_MAX, r as encodeAttributes, s as validateAttributeName, t as MAX_ATTRIBUTES, u as I32_MAX, v as dec, w as toValue, x as i32, y as decFromUnits } from "./attr-tmyREHtw.js";
3
- import { C as EntityMutationError, D as getLogger, E as NoMoreResultsError, S as EmptyPatchError, T as NoEntityFoundError, a as eq, r as toRpcSelect, t as SelectQueryBuilder, v as runQuery, w as InvalidContentTypeError } from "./query-Ber-lOJQ.js";
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 { n as encodeCreationFlags, t as decodeCreationFlags } from "./flags-DUT2gHEU.js";
6
- import { t as Entity } from "./entity-BIp_df9u.js";
7
- import { a as OperationType, i as MAX_EXPIRES_AT, n as resolveExpiry, o as ARKIV_ADDRESS, r as toBlocks, s as BLOCK_TIME } from "./expiry-Cgdb_dbq.js";
8
- 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-CniBgBSd.js";
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
- * Reads one entity by key, with every field selected.
33
- *
34
- * Returns a {@link FullEntity} rather than an {@link Entity}: the selection is fixed at `"*"`, so
35
- * every field is populated and none of them needs a `?` at the call site. The bare `Entity` type
36
- * has every field optional because a `select()` result carries only what it asked for.
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/attr"
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 client.executeBatch({
176
+ * await wallet.executeBatch({
196
177
  * creates: [
197
- * { payload, contentType, expires, salt: parent.salt },
178
+ * { schema: Nodes, values: { name: "root" }, expiration, salt: parent.salt },
198
179
  * {
199
- * payload,
200
- * contentType,
201
- * expires,
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
- return runQuery(client, {
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: toRpcSelect(options.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. Only $payload and \$contentType are yours to set`;
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 `"${identName(args[0])}" names type id ${String(args[1])}, which is not a known type`;
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 expiryContext = { currentBlock: creates?.length || extensions?.length ? await walletClient.getBlockNumber() : 0n };
562
- const createOps = (creates ?? []).map((item) => {
563
- validateContentType(item.contentType);
564
- return createOperation({
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
- if (item.contentType !== void 0) validateContentType(item.contentType);
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.expires, expiryContext);
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, data, txParams) {
720
- logger$4("createEntity %o", data);
721
- const { receipt, createdEntityKeys, createdExpiries } = await sendArkivTransaction(client, { creates: [data] }, txParams);
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, data, txParams) {
782
- logger("patchEntity %o", data);
783
- const { receipt } = await sendArkivTransaction(client, { patches: [data] }, txParams);
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: data.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: (data, txParams) => createEntity(client, data, txParams),
796
- patchEntity: (data, txParams) => patchEntity(client, data, txParams),
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` — on top of the read actions a Public Client has.
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, InvalidAttributeNameError, InvalidContentTypeError, InvalidCreationFlagsError, InvalidExpiryError, InvalidSaltError, InvalidValueError, MAX_ATTRIBUTES, MAX_EXPIRES_AT, MAX_NAME_BYTES, MAX_PAYLOAD_BYTES, MAX_SALT, MAX_STRING_BYTES, MissingValueError, NO_SALT, NoEntityFoundError, NoMoreResultsError, NoRandomSourceError, OperationType, SelectQueryBuilder, TooManyAttributesError, U256_MAX, U64_MAX, UnknownAttributeTypeError, UntypedValueError, addr, bool, bytes32, chainFromName, createPublicClient, createWalletClient, dec, decFromUnits, decUnits, decodeCreationFlags, encodeCreationFlags, i32, isArkivValue, isValidAttributeName, jsonToPayload, key, predictEntityKey, randomSalt, resolveExpiry, str, stringToPayload, toBlocks, toValue, u256, u64, validateAttributeName };
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