@arkiv-network/sdk 0.7.0-dev.1 → 0.8.0-advanced.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 (237) hide show
  1. package/README.md +71 -16
  2. package/dist/actions/advanced/index.cjs +13 -0
  3. package/dist/actions/advanced/index.d.cts +8 -0
  4. package/dist/actions/advanced/index.d.ts +9 -0
  5. package/dist/actions/advanced/index.js +9 -0
  6. package/dist/advanced-8ZPTmmaN.js +598 -0
  7. package/dist/advanced-8ZPTmmaN.js.map +1 -0
  8. package/dist/advanced-fPImL6lW.cjs +656 -0
  9. package/dist/arkivTransactions-D74gERHG.d.cts +571 -0
  10. package/dist/arkivTransactions-D74gERHG.d.cts.map +1 -0
  11. package/dist/arkivTransactions-NtGD6uk5.d.ts +571 -0
  12. package/dist/arkivTransactions-NtGD6uk5.d.ts.map +1 -0
  13. package/dist/attr/index.cjs +35 -0
  14. package/dist/attr/index.d.cts +2 -0
  15. package/dist/attr/index.d.ts +3 -0
  16. package/dist/attr/index.js +4 -0
  17. package/dist/attributes-BhY5DwJp.js +809 -0
  18. package/dist/attributes-BhY5DwJp.js.map +1 -0
  19. package/dist/attributes-Df9IsCVs.cjs +1029 -0
  20. package/dist/chains/index.cjs +2 -3
  21. package/dist/chains/index.d.cts +22 -60
  22. package/dist/chains/index.d.cts.map +1 -1
  23. package/dist/chains/index.d.ts +22 -60
  24. package/dist/chains/index.d.ts.map +1 -1
  25. package/dist/chains/index.js +2 -2
  26. package/dist/chains-BJrZs6sG.js +57 -0
  27. package/dist/chains-BJrZs6sG.js.map +1 -0
  28. package/dist/chains-BYRTTipa.cjs +73 -0
  29. package/dist/codec-Car3KkFF.d.ts +102 -0
  30. package/dist/codec-Car3KkFF.d.ts.map +1 -0
  31. package/dist/entity/index.cjs +20 -0
  32. package/dist/entity/index.d.cts +4 -0
  33. package/dist/entity/index.d.ts +5 -0
  34. package/dist/entity/index.js +7 -0
  35. package/dist/entity-B00Li04j.cjs +71 -0
  36. package/dist/entity-B7G8q_Eo.cjs +0 -0
  37. package/dist/entity-BYQR1uoe.js +67 -0
  38. package/dist/entity-BYQR1uoe.js.map +1 -0
  39. package/dist/entity-CD_qFF2M.js +0 -0
  40. package/dist/errors-BVbjKVMN.cjs +56 -0
  41. package/dist/errors-LTe7bOYS.js +33 -0
  42. package/dist/errors-LTe7bOYS.js.map +1 -0
  43. package/dist/expiry-BELY2Kpw.cjs +135 -0
  44. package/dist/expiry-BjpxZZQU.js +95 -0
  45. package/dist/expiry-BjpxZZQU.js.map +1 -0
  46. package/dist/expiry-DRV29F1r.d.cts +79 -0
  47. package/dist/expiry-DRV29F1r.d.cts.map +1 -0
  48. package/dist/expiry-nDbCgZX4.d.ts +79 -0
  49. package/dist/expiry-nDbCgZX4.d.ts.map +1 -0
  50. package/dist/flags-5dTNRnow.d.ts +41 -0
  51. package/dist/flags-5dTNRnow.d.ts.map +1 -0
  52. package/dist/flags-CRjPpoh3.d.cts +41 -0
  53. package/dist/flags-CRjPpoh3.d.cts.map +1 -0
  54. package/dist/flags-DFBs2J94.js +33 -0
  55. package/dist/flags-DFBs2J94.js.map +1 -0
  56. package/dist/flags-kr276q6i.cjs +43 -0
  57. package/dist/index-B5j76711.d.ts +184 -0
  58. package/dist/index-B5j76711.d.ts.map +1 -0
  59. package/dist/index-BF7Mq9Is.d.cts +280 -0
  60. package/dist/index-BF7Mq9Is.d.cts.map +1 -0
  61. package/dist/index-CA4V7Pdh.d.cts +167 -0
  62. package/dist/index-CA4V7Pdh.d.cts.map +1 -0
  63. package/dist/index-CV5zCdpa.d.cts +417 -0
  64. package/dist/index-CV5zCdpa.d.cts.map +1 -0
  65. package/dist/index-DHDud2hC.d.ts +280 -0
  66. package/dist/index-DHDud2hC.d.ts.map +1 -0
  67. package/dist/index-DvYvrkdk.d.ts +320 -0
  68. package/dist/index-DvYvrkdk.d.ts.map +1 -0
  69. package/dist/index-EeUO0nnJ.d.cts +184 -0
  70. package/dist/index-EeUO0nnJ.d.cts.map +1 -0
  71. package/dist/index-fX_XyqLp.d.ts +167 -0
  72. package/dist/index-fX_XyqLp.d.ts.map +1 -0
  73. package/dist/index.cjs +411 -405
  74. package/dist/index.d.cts +360 -209
  75. package/dist/index.d.cts.map +1 -1
  76. package/dist/index.d.ts +361 -209
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +342 -387
  79. package/dist/index.js.map +1 -1
  80. package/dist/key-D1Bh7MF0.js +70 -0
  81. package/dist/key-D1Bh7MF0.js.map +1 -0
  82. package/dist/key-WKhXnXuU.cjs +98 -0
  83. package/dist/logger-CVpvU8ik.js +153 -0
  84. package/dist/logger-CVpvU8ik.js.map +1 -0
  85. package/dist/logger-Cr15lPAQ.cjs +188 -0
  86. package/dist/payload-BNoud2KZ.d.cts +94 -0
  87. package/dist/payload-BNoud2KZ.d.cts.map +1 -0
  88. package/dist/payload-Bz6651ax.js +67 -0
  89. package/dist/payload-Bz6651ax.js.map +1 -0
  90. package/dist/payload-CcUj85ys.d.ts +94 -0
  91. package/dist/payload-CcUj85ys.d.ts.map +1 -0
  92. package/dist/payload-KC14SDlN.cjs +83 -0
  93. package/dist/query/index.cjs +26 -150
  94. package/dist/query/index.d.cts +5 -3
  95. package/dist/query/index.d.ts +6 -3
  96. package/dist/query/index.js +8 -138
  97. package/dist/queryBuilder-DM6AWCBa.js +820 -0
  98. package/dist/queryBuilder-DM6AWCBa.js.map +1 -0
  99. package/dist/queryBuilder-DbUMEZln.cjs +944 -0
  100. package/dist/selection-C4UhsMOO.d.ts +434 -0
  101. package/dist/selection-C4UhsMOO.d.ts.map +1 -0
  102. package/dist/selection-DPg0uyJf.d.cts +433 -0
  103. package/dist/selection-DPg0uyJf.d.cts.map +1 -0
  104. package/dist/types/index.cjs +3 -3
  105. package/dist/types/index.d.cts +7 -2
  106. package/dist/types/index.d.ts +8 -2
  107. package/dist/types/index.js +3 -3
  108. package/dist/types-Bu_ZwMbZ.js +0 -0
  109. package/dist/types-NRqymi6S.cjs +0 -0
  110. package/dist/utils/index.cjs +4 -17
  111. package/dist/utils/index.d.cts +3 -17
  112. package/dist/utils/index.d.ts +3 -17
  113. package/dist/utils/index.js +4 -18
  114. package/package.json +26 -5
  115. package/src/actions/advanced/advanced.test.ts +258 -0
  116. package/src/actions/advanced/buildMutation.ts +104 -0
  117. package/src/actions/advanced/getMutationResult.ts +112 -0
  118. package/src/actions/advanced/index.ts +21 -0
  119. package/src/actions/advanced/pingTransaction.ts +43 -0
  120. package/src/actions/advanced/sendMutation.ts +59 -0
  121. package/src/actions/public/getEntity.ts +27 -43
  122. package/src/actions/public/getEntityNonce.ts +30 -0
  123. package/src/actions/public/predictEntityKeys.test.ts +143 -0
  124. package/src/actions/public/predictEntityKeys.ts +138 -0
  125. package/src/actions/public/query.ts +35 -67
  126. package/src/actions/public/watchEntityEvents.test.ts +414 -0
  127. package/src/actions/public/watchEntityEvents.ts +225 -0
  128. package/src/actions/wallet/changeOwnership.ts +2 -2
  129. package/src/actions/wallet/createEntity.ts +99 -24
  130. package/src/actions/wallet/extendEntity.ts +37 -13
  131. package/src/actions/wallet/mutateEntities.test.ts +76 -0
  132. package/src/actions/wallet/mutateEntities.ts +16 -33
  133. package/src/actions/wallet/patchEntity.ts +90 -0
  134. package/src/attr/attributes.test.ts +120 -0
  135. package/src/attr/attributes.ts +190 -0
  136. package/src/attr/codec.test.ts +162 -0
  137. package/src/attr/codec.ts +220 -0
  138. package/src/attr/decimal.ts +86 -0
  139. package/src/attr/errors.ts +145 -0
  140. package/src/attr/index.ts +50 -0
  141. package/src/attr/names.ts +106 -0
  142. package/src/attr/types.ts +150 -0
  143. package/src/attr/values.test.ts +271 -0
  144. package/src/attr/values.ts +502 -0
  145. package/src/chains/cheesecake.ts +22 -0
  146. package/src/chains/index.ts +1 -2
  147. package/src/clients/createPublicClient.test.ts +3 -5
  148. package/src/clients/createPublicClient.ts +5 -4
  149. package/src/clients/createWalletClient.test.ts +2 -2
  150. package/src/clients/createWalletClient.ts +13 -7
  151. package/src/clients/decorators/arkivAdvanced.ts +144 -0
  152. package/src/clients/decorators/arkivPublic.ts +172 -139
  153. package/src/clients/decorators/arkivWallet.ts +101 -94
  154. package/src/entity/create.test.ts +184 -0
  155. package/src/entity/errors.ts +38 -0
  156. package/src/entity/events.ts +16 -0
  157. package/src/entity/expiry.test.ts +195 -0
  158. package/src/entity/expiry.ts +181 -0
  159. package/src/entity/flags.ts +65 -0
  160. package/src/entity/index.ts +15 -0
  161. package/src/entity/key.ts +68 -0
  162. package/src/entity/operations.ts +134 -0
  163. package/src/entity/params.ts +15 -0
  164. package/src/errors.ts +26 -49
  165. package/src/index.ts +19 -0
  166. package/src/query/engine.ts +68 -137
  167. package/src/query/errors.ts +151 -0
  168. package/src/query/expression.test.ts +286 -0
  169. package/src/query/expression.ts +493 -0
  170. package/src/query/index.ts +40 -4
  171. package/src/query/injection.test.ts +151 -0
  172. package/src/query/queryBuilder.test.ts +342 -637
  173. package/src/query/queryBuilder.ts +133 -359
  174. package/src/query/queryResult.ts +54 -51
  175. package/src/query/selection.test.ts +48 -98
  176. package/src/query/selection.ts +77 -65
  177. package/src/types/entity.test.ts +44 -155
  178. package/src/types/entity.ts +60 -52
  179. package/src/types/events.ts +59 -16
  180. package/src/types/index.ts +20 -17
  181. package/src/types/rpcSchema.ts +69 -37
  182. package/src/utils/arkivTransactions.test.ts +600 -155
  183. package/src/utils/arkivTransactions.ts +350 -219
  184. package/src/utils/chains.test.ts +21 -24
  185. package/src/utils/compression.ts +1 -1
  186. package/src/utils/entities.test.ts +62 -0
  187. package/src/utils/entities.ts +109 -37
  188. package/src/utils/expirationTime.ts +114 -10
  189. package/src/utils/logger.ts +2 -2
  190. package/src/utils/revert.test.ts +99 -0
  191. package/src/utils/revert.ts +145 -0
  192. package/dist/chains-BifaY04V.cjs +0 -108
  193. package/dist/chains-CrtkVbBh.js +0 -86
  194. package/dist/chains-CrtkVbBh.js.map +0 -1
  195. package/dist/consts-Bz0LZQZY.js +0 -7
  196. package/dist/consts-Bz0LZQZY.js.map +0 -1
  197. package/dist/consts-CxT1-RXU.cjs +0 -18
  198. package/dist/entity-BhSXaB23.cjs +0 -81
  199. package/dist/entity-CN41IOrq.d.cts +0 -401
  200. package/dist/entity-CN41IOrq.d.cts.map +0 -1
  201. package/dist/entity-DGfVyB-a.js +0 -71
  202. package/dist/entity-DGfVyB-a.js.map +0 -1
  203. package/dist/entity-NnEVlePN.d.ts +0 -401
  204. package/dist/entity-NnEVlePN.d.ts.map +0 -1
  205. package/dist/index-ClkpS6s_.d.ts +0 -481
  206. package/dist/index-ClkpS6s_.d.ts.map +0 -1
  207. package/dist/index-w4qop0Pe.d.cts +0 -481
  208. package/dist/index-w4qop0Pe.d.cts.map +0 -1
  209. package/dist/payload-BpNUPOnY.js +0 -13
  210. package/dist/payload-BpNUPOnY.js.map +0 -1
  211. package/dist/payload-C2KHOUoj.d.ts +0 -6
  212. package/dist/payload-C2KHOUoj.d.ts.map +0 -1
  213. package/dist/payload-CJN8fTvX.d.cts +0 -6
  214. package/dist/payload-CJN8fTvX.d.cts.map +0 -1
  215. package/dist/payload-D8YLKcJj.cjs +0 -23
  216. package/dist/query/index.js.map +0 -1
  217. package/dist/queryBuilder-BE_XhLLa.js +0 -735
  218. package/dist/queryBuilder-BE_XhLLa.js.map +0 -1
  219. package/dist/queryBuilder-J37buGCi.cjs +0 -865
  220. package/dist/utils/index.d.cts.map +0 -1
  221. package/dist/utils/index.d.ts.map +0 -1
  222. package/dist/utils/index.js.map +0 -1
  223. package/src/actions/public/buildQuery.ts +0 -10
  224. package/src/actions/public/subscribeEntityEvents.ts +0 -93
  225. package/src/actions/wallet/updateEntity.ts +0 -59
  226. package/src/chains/braga.ts +0 -26
  227. package/src/chains/kaolin.ts +0 -29
  228. package/src/query/engine.test.ts +0 -571
  229. package/src/query/predicate.test.ts +0 -461
  230. package/src/query/predicate.ts +0 -144
  231. package/src/query/queryResult.test.ts +0 -270
  232. package/src/query/selectQueryBuilder.test.ts +0 -213
  233. package/src/types/attributes.ts +0 -28
  234. package/src/utils/validation.test.ts +0 -106
  235. package/src/utils/validation.ts +0 -80
  236. /package/dist/{types-Ci4BRClw.js → attr-DlmErkvR.cjs} +0 -0
  237. /package/dist/{types-a8gm_IaQ.cjs → attr-GcQKatub.js} +0 -0
@@ -0,0 +1,144 @@
1
+ import type { Account, Chain, Client, Hash, TransactionReceipt, Transport } from "viem"
2
+ import type {
3
+ BuildMutationOptions,
4
+ BuildMutationReturnType,
5
+ } from "../../actions/advanced/buildMutation"
6
+ import { buildMutation } from "../../actions/advanced/buildMutation"
7
+ import type {
8
+ GetMutationResultReturnType,
9
+ MutationResult,
10
+ } from "../../actions/advanced/getMutationResult"
11
+ import { decodeMutationResult, getMutationResult } from "../../actions/advanced/getMutationResult"
12
+ import type { PingTransactionReturnType } from "../../actions/advanced/pingTransaction"
13
+ import { pingTransaction } from "../../actions/advanced/pingTransaction"
14
+ import type {
15
+ SendMutationOptions,
16
+ SendMutationReturnType,
17
+ } from "../../actions/advanced/sendMutation"
18
+ import { sendMutation } from "../../actions/advanced/sendMutation"
19
+ import type { EntityMutationOps } from "../../utils/arkivTransactions"
20
+
21
+ /**
22
+ * The read-only half of the advanced path — checking on a transaction and decoding its result —
23
+ * which needs no account, so a Public Client carries it too.
24
+ *
25
+ * Every action here costs at most one RPC call, and says exactly which.
26
+ */
27
+ export type PublicAdvancedActions = {
28
+ /**
29
+ * Asks the chain — once — whether a transaction has landed. Exactly one
30
+ * `eth_getTransactionReceipt`, never a poll: an unmined transaction comes back as
31
+ * `{ status: "pending" }` and the schedule stays yours.
32
+ *
33
+ * @param txHash - The transaction hash returned by `sendMutation` (or any other send)
34
+ * @returns `{ status: "pending" }`, or `{ status: "success" | "reverted", blockNumber }`
35
+ *
36
+ * @example
37
+ * const { status } = await client.advanced.pingTransaction(txHash)
38
+ * if (status === "pending") scheduleAnotherPing()
39
+ */
40
+ pingTransaction: (txHash: Hash) => Promise<PingTransactionReturnType>
41
+
42
+ /**
43
+ * Fetches a transaction's receipt — once — and decodes what the mutation did: created keys and
44
+ * expiries, plus the keys of everything patched, deleted, extended or handed over. One
45
+ * `eth_getTransactionReceipt`; `{ status: "pending" }` if not mined yet. No revert diagnosis is
46
+ * run on a `reverted` result — that extra call is yours to spend or skip.
47
+ *
48
+ * @param txHash - The transaction hash
49
+ * @returns The decoded {@link MutationResult}, or `{ status: "pending" }`
50
+ *
51
+ * @example
52
+ * const result = await client.advanced.getMutationResult(txHash)
53
+ * if (result.status === "success") console.log(result.createdEntities)
54
+ */
55
+ getMutationResult: (txHash: Hash) => Promise<GetMutationResultReturnType>
56
+
57
+ /**
58
+ * Decodes a receipt you already hold into a {@link MutationResult}. **Zero RPC calls** — for
59
+ * receipts that reached you through your own `waitForTransactionReceipt`, a block watcher, or a
60
+ * webhook.
61
+ *
62
+ * @param receipt - The transaction receipt
63
+ * @returns The decoded {@link MutationResult}
64
+ */
65
+ decodeMutationResult: (receipt: TransactionReceipt) => MutationResult
66
+ }
67
+
68
+ /**
69
+ * The advanced path on a Wallet Client: build, send, ping and read results as separate steps, each
70
+ * costing the minimum number of RPC calls — down to one per transaction when you supply what the
71
+ * SDK would otherwise look up.
72
+ *
73
+ * The everyday actions (`createEntity`, `mutateEntities`, …) bundle send + wait + decode and are
74
+ * the right default. This namespace unbundles them for callers optimising their RPC budget.
75
+ *
76
+ * @example Minimal-call flow: one send, one ping, done.
77
+ * const { txHash } = await client.advanced.sendMutation(
78
+ * { creates: [{ payload, contentType: "application/json", expires }] },
79
+ * { currentBlock, txParams: { nonce, gas: 1_000_000n, maxFeePerGas, maxPriorityFeePerGas } },
80
+ * ) // exactly 1 RPC call: eth_sendRawTransaction
81
+ * // ... later, on your own schedule:
82
+ * const result = await client.advanced.getMutationResult(txHash) // 1 RPC call
83
+ * if (result.status === "success") console.log(result.createdEntities)
84
+ */
85
+ export type WalletAdvancedActions = PublicAdvancedActions & {
86
+ /**
87
+ * Encodes a mutation batch without sending anything: zero RPC calls with `currentBlock` supplied
88
+ * (or when no expiry is relative), at most one `eth_blockNumber` otherwise. Returns the
89
+ * operations for `writeContract`, and the `{ to, data }` calldata for offline signing.
90
+ *
91
+ * @param data - The batch (creates, patches, deletes, extensions, ownershipChanges)
92
+ * @param options - Optional `currentBlock` to avoid the `eth_blockNumber` lookup
93
+ */
94
+ buildMutation: (
95
+ data: EntityMutationOps,
96
+ options?: BuildMutationOptions,
97
+ ) => Promise<BuildMutationReturnType>
98
+
99
+ /**
100
+ * Signs and sends a mutation batch, returning the hash as soon as the transaction is submitted —
101
+ * no waiting, no polling, no revert diagnosis. With `currentBlock` and full `txParams` (nonce,
102
+ * gas, fees) supplied this is exactly one `eth_sendRawTransaction`; each omitted piece adds only
103
+ * the lookup viem needs to fill it.
104
+ *
105
+ * @param data - The batch (creates, patches, deletes, extensions, ownershipChanges)
106
+ * @param options - Optional `currentBlock` and `txParams`
107
+ * @returns The transaction hash and the batch's per-kind operation counts
108
+ *
109
+ * @example
110
+ * const { txHash } = await client.advanced.sendMutation({
111
+ * creates: [{ payload, contentType: "application/json", expires: ExpirationTime.atBlock(1_200_000n) }],
112
+ * })
113
+ */
114
+ sendMutation: (
115
+ data: EntityMutationOps,
116
+ options?: SendMutationOptions,
117
+ ) => Promise<SendMutationReturnType>
118
+ }
119
+
120
+ export function publicAdvancedActions<
121
+ transport extends Transport = Transport,
122
+ chain extends Chain | undefined = Chain | undefined,
123
+ account extends Account | undefined = Account | undefined,
124
+ >(client: Client<transport, chain, account>): PublicAdvancedActions {
125
+ return {
126
+ pingTransaction: (txHash: Hash) => pingTransaction(client, txHash),
127
+ getMutationResult: (txHash: Hash) => getMutationResult(client, txHash),
128
+ decodeMutationResult: (receipt: TransactionReceipt) => decodeMutationResult(receipt),
129
+ }
130
+ }
131
+
132
+ export function walletAdvancedActions<
133
+ transport extends Transport = Transport,
134
+ chain extends Chain | undefined = Chain | undefined,
135
+ account extends Account | undefined = Account | undefined,
136
+ >(client: Client<transport, chain, account>): WalletAdvancedActions {
137
+ return {
138
+ ...publicAdvancedActions(client),
139
+ buildMutation: (data: EntityMutationOps, options?: BuildMutationOptions) =>
140
+ buildMutation(client, data, options),
141
+ sendMutation: (data: EntityMutationOps, options?: SendMutationOptions) =>
142
+ sendMutation(client, data, options),
143
+ }
144
+ }
@@ -1,19 +1,23 @@
1
- import type { Account, Chain, Client, Hex, PublicActions, Transport } from "viem"
1
+ import type { Account, Address, Chain, Client, Hex, PublicActions, Transport } from "viem"
2
2
  import { getBlockTiming } from "../../actions/public/getBlockTiming"
3
3
  import { getEntity } from "../../actions/public/getEntity"
4
4
  import { getEntityCount } from "../../actions/public/getEntityCount"
5
+ import { getEntityNonce } from "../../actions/public/getEntityNonce"
6
+ import {
7
+ type PredictEntityKeysParameters,
8
+ type PredictEntityKeysReturnType,
9
+ predictEntityKeys,
10
+ } from "../../actions/public/predictEntityKeys"
5
11
  import { type QueryOptions, type QueryReturnType, query } from "../../actions/public/query"
6
- import { subscribeEntityEvents } from "../../actions/public/subscribeEntityEvents"
7
- import { QueryBuilder, SelectQueryBuilder } from "../../query/queryBuilder"
12
+ import {
13
+ type WatchEntityEventsParameters,
14
+ watchEntityEvents,
15
+ } from "../../actions/public/watchEntityEvents"
16
+ import type { Expression } from "../../query/expression"
17
+ import { SelectQueryBuilder } from "../../query/queryBuilder"
8
18
  import type { EntitySelection, FullEntity, ProjectedEntity, SelectArg } from "../../query/selection"
9
19
  import type { Entity } from "../../types/entity"
10
- import type {
11
- OnEntityCreatedEvent,
12
- OnEntityDeletedEvent,
13
- OnEntityExpiredEvent,
14
- OnEntityExpiresInExtendedEvent,
15
- OnEntityUpdatedEvent,
16
- } from "../../types/events"
20
+ import { type PublicAdvancedActions, publicAdvancedActions } from "./arkivAdvanced"
17
21
 
18
22
  export type PublicArkivActions<
19
23
  transport extends Transport = Transport,
@@ -38,23 +42,28 @@ export type PublicArkivActions<
38
42
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
39
43
  *
40
44
  * @param key - The entity key (hex string)
41
- * @returns The entity with the given key. {@link Entity}
45
+ * @returns The entity with the given key, with every field populated. {@link FullEntity}
42
46
  *
43
47
  * @example
44
- * import { createPublicClient, http } from 'arkiv'
45
- * import { braga } from 'arkiv/chains'
48
+ * import { createPublicClient } from "@arkiv-network/sdk"
49
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
50
+ * import { http } from "viem"
46
51
  *
47
52
  * const client = createPublicClient({
48
- * chain: braga,
53
+ * chain: cheesecake,
49
54
  * transport: http(),
50
55
  * })
51
- * const entity = await client.getEntity("0x123")
52
- * // {
53
- * // key: "0x123",
54
- * // value: "0x123",
56
+ * const entity = await client.getEntity(entityKey)
57
+ * // Entity {
58
+ * // key: "0x9f2c…",
59
+ * // owner: "0xabc…",
60
+ * // contentType: "application/json",
61
+ * // payload: Uint8Array, // entity.toJson() / entity.toText() decode it
62
+ * // attributes: { category: { type: "str", value: "docs" } },
63
+ * // expiresAt: 1_297_000n,
55
64
  * // }
56
65
  */
57
- getEntity: (key: Hex) => Promise<Entity>
66
+ getEntity: (key: Hex) => Promise<FullEntity>
58
67
 
59
68
  /**
60
69
  * Returns a SelectQueryBuilder for building and executing queries — the recommended way to
@@ -70,12 +79,13 @@ export type PublicArkivActions<
70
79
  * @returns A SelectQueryBuilder instance for building and executing queries. {@link SelectQueryBuilder}
71
80
  *
72
81
  * @example
73
- * import { createPublicClient, http } from 'arkiv'
74
- * import { braga } from 'arkiv/chains'
75
- * import { eq } from 'arkiv/query'
82
+ * import { createPublicClient } from "@arkiv-network/sdk"
83
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
84
+ * import { eq } from "@arkiv-network/sdk/query"
85
+ * import { http } from "viem"
76
86
  *
77
87
  * const client = createPublicClient({
78
- * chain: braga,
88
+ * chain: cheesecake,
79
89
  * transport: http(),
80
90
  * })
81
91
  * // select everything
@@ -83,7 +93,7 @@ export type PublicArkivActions<
83
93
  * await client.select("*").where(eq("category", "docs")).fetch()
84
94
  * // only the key
85
95
  * await client.select({ key: true }).where(eq("category", "docs")).fetch()
86
- * // select specific fields — result typed { owner: Hex; attributes: Attribute[] }
96
+ * // select specific fields — result typed { owner: Hex; attributes: Attributes }
87
97
  * await client.select({ owner: true, attributes: true }).fetch()
88
98
  * // a single field — result typed { owner: Hex }
89
99
  * await client.select({ owner: true }).fetch()
@@ -95,9 +105,11 @@ export type PublicArkivActions<
95
105
  * Pick the entity fields to return. Set the ones you want to `true` (at least one is required);
96
106
  * the result is typed to exactly those fields, so reading anything else is a compile error.
97
107
  *
98
- * Available fields: `key`, `owner`, `creator`, `contentType`, `payload`, `attributes`,
99
- * `expiresAtBlock`, `createdAtBlock`, `lastModifiedAtBlock`, `transactionIndexInBlock`,
100
- * `operationIndexInTransaction`.
108
+ * Available fields: `key`, `owner`, `creator`, `createdAt`, `updatedAt`, `expiresAt`,
109
+ * `creationFlags`, `contentType`, `payload`, `attributeSchema` and `attributes`.
110
+ *
111
+ * `attributes` also takes a map of names, to fetch only those:
112
+ * `select({ key: true, attributes: { projectId: true } })`.
101
113
  *
102
114
  * Pass the selection inline so its fields stay literal `true`. A selection stored in a `let`/
103
115
  * `const` variable widens to `boolean` and the result type can no longer be narrowed — annotate
@@ -105,7 +117,8 @@ export type PublicArkivActions<
105
117
  *
106
118
  * @example
107
119
  * client.select({ owner: true, attributes: true }) // entities typed { owner, attributes }
108
- * client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too
120
+ * client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too
121
+ * client.select({ key: true, attributeSchema: true }) // what shape is the data?
109
122
  */
110
123
  <const S extends EntitySelection>(selection: S): SelectQueryBuilder<ProjectedEntity<S>>
111
124
  /**
@@ -116,90 +129,133 @@ export type PublicArkivActions<
116
129
  }
117
130
 
118
131
  /**
119
- * Returns a QueryBuilder instance for building and executing queries.
120
- * The QueryBuilder object follows the Builder pattern, allowing you to chain methods to build a query and then execute it.
121
- *
122
- * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/query
132
+ * Runs one query and returns one page, with no builder in between.
123
133
  *
124
- * @deprecated Use {@link select} instead. `buildQuery()` returns only the entity `key` unless
125
- * you remember to opt in to data with `withAttributes()`/`withMetadata()`/`withPayload()`, which
126
- * is an easy mistake. `select()` makes the selection explicit. This method remains for backwards
127
- * compatibility and will be removed in a future release.
134
+ * Use {@link select} for anything typed — this returns full {@link Entity} objects whatever the
135
+ * selection, and takes a raw string as an escape hatch for a query built elsewhere. A raw string
136
+ * goes to the node exactly as written, with none of the name, type or operator checks the
137
+ * expression combinators apply.
128
138
  *
129
- * @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}
139
+ * @param query - An {@link Expression}, or the raw query string.
140
+ * @param queryOptions - Selection, page size, cursor and block. {@link QueryOptions}
141
+ * @returns One page of entities. {@link QueryReturnType}
130
142
  *
131
143
  * @example
132
- * import { createPublicClient, http } from 'arkiv'
133
- * import { braga } from 'arkiv/chains'
144
+ * import { createPublicClient } from "@arkiv-network/sdk"
145
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
146
+ * import { and, eq, gte } from "@arkiv-network/sdk/query"
147
+ * import { i32 } from "@arkiv-network/sdk/attr"
148
+ * import { http } from "viem"
134
149
  *
135
150
  * const client = createPublicClient({
136
- * chain: braga,
151
+ * chain: cheesecake,
137
152
  * transport: http(),
138
153
  * })
139
- * const query = client.buildQuery()
140
- * const entities = await query.where("key", "=", "value").ownedBy("0x123").fetch()
154
+ * const page = await client.query(and(eq("category", "docs"), gte("level", i32(10))), {
155
+ * select: { key: true, attributes: true },
156
+ * limit: 100,
157
+ * })
158
+ * // { entities: [Entity], cursor: "b64:…", blockNumber: 32223n }
141
159
  *
160
+ * // The raw form, unchecked:
161
+ * await client.query("category = str('docs') AND level >= i32(10)")
142
162
  */
143
- buildQuery: () => QueryBuilder
163
+ query: (query: Expression | string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
144
164
 
145
165
  /**
146
- * Returns a QueryResult instance for fetching the results of a raw query.
147
- * If no query options are provided, all payload is included, but no metadata (like owner, expiredAt, etc.) and attributes.
148
- * @param query - The raw query string
149
- * @param queryOptions - The optional query options - {@link QueryOptions}
150
- * @returns A QueryReturnType instance - {@link QueryReturnType}
166
+ * Returns the total number of entities on the chain.
167
+ * @returns The number of entities currently stored
151
168
  *
152
169
  * @example
153
- * import { createPublicClient, http } from 'arkiv'
154
- * import { braga } from 'arkiv/chains'
170
+ * import { createPublicClient } from "@arkiv-network/sdk"
171
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
172
+ * import { http } from "viem"
155
173
  *
156
174
  * const client = createPublicClient({
157
- * chain: braga,
175
+ * chain: cheesecake,
158
176
  * transport: http(),
159
177
  * })
160
- * const queryResult = client.query('key = value && $owner = 0x123')
161
- * // queryResult = { entities: [{ key: "0x123", value: "0x123" }], cursor: undefined, blockNumber: undefined }
162
- * const queryResultWithOptions = client.query('key = value && $owner = 0x123', {
163
- * includeData: {
164
- * attributes: false,
165
- * payload: true,
166
- * metadata: true,
167
- * },
168
- * resultsPerPage: 10,
169
- * cursor: undefined,
170
- * atBlock: undefined,
171
- * })
172
- * // queryResultWithOptions = { entities: [{ key: "0x123", value: "0x123" }], cursor: "...", blockNumber: 32223n }
178
+ * const entityCount = await client.getEntityCount()
179
+ * // entityCount = 0
173
180
  */
174
- query: (query: string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
181
+ getEntityCount: () => Promise<number>
175
182
 
176
183
  /**
177
- * Returns the number of entities in the DBChain.
178
- * @returns The number of entities in the DBChain
184
+ * Returns how many entities an account has created — its entity-minting nonce.
185
+ *
186
+ * Not the account's transaction nonce: the engine keeps its own counter per creator and mixes it
187
+ * into every key it mints, which is why two identical creates from one account never collide.
188
+ *
189
+ * @param owner - The account whose nonce to read.
190
+ * @returns The nonce the account's next create will use.
179
191
  *
180
192
  * @example
181
- * import { createPublicClient, http } from 'arkiv'
182
- * import { braga } from 'arkiv/chains'
193
+ * import { createPublicClient } from "@arkiv-network/sdk"
194
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
195
+ * import { http } from "viem"
183
196
  *
184
197
  * const client = createPublicClient({
185
- * chain: braga,
198
+ * chain: cheesecake,
186
199
  * transport: http(),
187
200
  * })
188
- * const entityCount = await client.getEntityCount()
189
- * // entityCount = 0
201
+ * const nonce = await client.getEntityNonce("0xabc…")
202
+ * // 7n — the next entity this account creates is its eighth
190
203
  */
191
- getEntityCount: () => Promise<number>
204
+ getEntityNonce: (owner: Address) => Promise<bigint>
205
+
206
+ /**
207
+ * Works out the keys an account's next creates will be given, before sending them.
208
+ *
209
+ * The engine derives a key from the chain, the registry, the owner, the owner's nonce and a
210
+ * salt — everything but the nonce is known to the caller, and the nonce is read here. This is
211
+ * what lets a batch reference an entity it is about to mint.
212
+ *
213
+ * Each key arrives paired with the salt that mints it, because a create defaults to a *random*
214
+ * salt: a predicted key only holds if the create carries the salt it was predicted with. And the
215
+ * prediction holds only while nothing else from this owner is in flight — for a key you can rely
216
+ * on unconditionally, read it back from the create instead.
217
+ *
218
+ * A literal `count` comes back as a fixed-length tuple, so the pairs destructure into names.
219
+ *
220
+ * @param parameters - Owner, and either a count or the salts. {@link PredictEntityKeysParameters}
221
+ * @returns One `{ key, salt }` pair per create, in batch order.
222
+ * {@link PredictEntityKeysReturnType}
223
+ *
224
+ * @example A batch whose second entity points at its first.
225
+ * import { key } from "@arkiv-network/sdk/attr"
226
+ *
227
+ * const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
228
+ * await wallet.mutateEntities({
229
+ * creates: [
230
+ * { payload, contentType, expires, salt: parent.salt },
231
+ * {
232
+ * payload,
233
+ * contentType,
234
+ * expires,
235
+ * salt: child.salt,
236
+ * attributes: { parent: key(parent.key) },
237
+ * },
238
+ * ],
239
+ * })
240
+ */
241
+ predictEntityKeys: <
242
+ const TCount extends number = number,
243
+ const TSalts extends readonly bigint[] | undefined = undefined,
244
+ >(
245
+ parameters: PredictEntityKeysParameters<TCount, TSalts>,
246
+ ) => Promise<PredictEntityKeysReturnType<TCount, TSalts>>
192
247
 
193
248
  /**
194
249
  * Returns the current block timing.
195
250
  * @returns The current block timing. {@link GetBlockTimingReturnType}
196
251
  *
197
252
  * @example
198
- * import { createPublicClient, http } from 'arkiv'
199
- * import { braga } from 'arkiv/chains'
253
+ * import { createPublicClient } from "@arkiv-network/sdk"
254
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
255
+ * import { http } from "viem"
200
256
  *
201
257
  * const client = createPublicClient({
202
- * chain: braga,
258
+ * chain: cheesecake,
203
259
  * transport: http(),
204
260
  * })
205
261
  * const blockTiming = await client.getBlockTiming()
@@ -216,43 +272,42 @@ export type PublicArkivActions<
216
272
  }>
217
273
 
218
274
  /**
219
- * Subscribes to entity events.
220
- * Takes an object with event handlers: {onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended}
221
- * @param pollingInterval - The polling interval in milliseconds
222
- * @param fromBlock - The block number to start from
223
- * @returns A function to unsubscribe from the events
275
+ * Watches entity events, calling the handlers you pass as they arrive.
276
+ *
277
+ * All five are decoded from logs — `onEntityCreated`, `onEntityPatched`, `onExpiryExtended`,
278
+ * `onOwnershipTransferred`, `onEntityDeleted` — and each carries the block, transaction and log
279
+ * index it came from, which is the order the operations were applied in. `onEvent` receives all
280
+ * of them, whatever their type.
281
+ *
282
+ * @param parameters - Handlers and options, all optional. {@link WatchEntityEventsParameters}
283
+ * @returns A function that stops the watcher.
224
284
  *
225
285
  * @example
226
- * import { createPublicClient, http } from 'arkiv'
227
- * import { braga } from 'arkiv/chains'
286
+ * import { createPublicClient } from "@arkiv-network/sdk"
287
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
288
+ * import { http } from "viem"
228
289
  *
229
290
  * const client = createPublicClient({
230
- * chain: braga,
291
+ * chain: cheesecake,
231
292
  * transport: http(),
232
293
  * })
233
- * const unsubscribe = await client.subscribeEntityEvents({
234
- * onError: (error) => console.error("subscribeEntityEvents error", error),
294
+ * const unwatch = client.watchEntityEvents({
295
+ * onEntityCreated: ({ entityKey, expiresAt }) => console.log(entityKey, "until", expiresAt),
296
+ * onError: (error) => console.error("watchEntityEvents error", error),
235
297
  * })
236
- * unsubscribe() // unsubscribe from the events
298
+ * unwatch() // stop watching
299
+ */
300
+ watchEntityEvents: (parameters: WatchEntityEventsParameters) => () => void
301
+
302
+ /**
303
+ * The read-only half of the advanced path: check on a transaction and decode its result with at
304
+ * most one RPC call per action — so a process that holds nothing but a transaction hash can
305
+ * follow it without a wallet. {@link PublicAdvancedActions}
306
+ *
307
+ * @example
308
+ * const { status } = await client.advanced.pingTransaction(txHash) // 1 eth_getTransactionReceipt
237
309
  */
238
- subscribeEntityEvents: (
239
- {
240
- onError,
241
- onEntityCreated,
242
- onEntityUpdated,
243
- onEntityDeleted,
244
- onEntityExpiresInExtended,
245
- }: {
246
- onError?: (error: Error) => void
247
- onEntityCreated?: (event: OnEntityCreatedEvent) => void
248
- onEntityUpdated?: (event: OnEntityUpdatedEvent) => void
249
- onEntityDeleted?: (event: OnEntityDeletedEvent) => void
250
- onEntityExpired?: (event: OnEntityExpiredEvent) => void
251
- onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void
252
- },
253
- pollingInterval?: number,
254
- fromBlock?: bigint,
255
- ) => Promise<() => void>
310
+ advanced: PublicAdvancedActions
256
311
  }
257
312
 
258
313
  export function publicArkivActions<
@@ -262,42 +317,20 @@ export function publicArkivActions<
262
317
  >(client: Client<transport, chain, account>) {
263
318
  return {
264
319
  getEntity: (key: Hex) => getEntity(client, key),
265
- query: (rawQuery: string, queryOptions?: QueryOptions) => query(client, rawQuery, queryOptions),
266
- buildQuery: () => new QueryBuilder(client),
320
+ query: (rawQuery: Expression | string, queryOptions?: QueryOptions) =>
321
+ query(client, rawQuery, queryOptions),
267
322
  select: (selection?: SelectArg) => new SelectQueryBuilder(client, selection),
268
323
  getBlockTiming: () => getBlockTiming(client),
269
324
  getEntityCount: () => getEntityCount(client),
270
- subscribeEntityEvents: (
271
- {
272
- onError,
273
- onEntityCreated,
274
- onEntityUpdated,
275
- onEntityDeleted,
276
- onEntityExpired,
277
- onEntityExpiresInExtended,
278
- }: {
279
- onError?: (error: Error) => void
280
- onEntityCreated?: (event: OnEntityCreatedEvent) => void
281
- onEntityUpdated?: (event: OnEntityUpdatedEvent) => void
282
- onEntityDeleted?: (event: OnEntityDeletedEvent) => void
283
- onEntityExpired?: (event: OnEntityExpiredEvent) => void
284
- onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void
285
- },
286
- pollingInterval?: number,
287
- fromBlock?: bigint,
288
- ) =>
289
- subscribeEntityEvents(
290
- client,
291
- {
292
- onError,
293
- onEntityCreated,
294
- onEntityUpdated,
295
- onEntityDeleted,
296
- onEntityExpired,
297
- onEntityExpiresInExtended,
298
- },
299
- pollingInterval,
300
- fromBlock,
301
- ),
325
+ getEntityNonce: (owner: Address) => getEntityNonce(client, owner),
326
+ predictEntityKeys: <
327
+ const TCount extends number = number,
328
+ const TSalts extends readonly bigint[] | undefined = undefined,
329
+ >(
330
+ parameters: PredictEntityKeysParameters<TCount, TSalts>,
331
+ ) => predictEntityKeys(client, parameters),
332
+ watchEntityEvents: (parameters: WatchEntityEventsParameters) =>
333
+ watchEntityEvents(client, parameters),
334
+ advanced: publicAdvancedActions(client),
302
335
  }
303
336
  }