@arkiv-network/sdk 0.7.0 → 0.8.0-advanced.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) 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-Ds2XRflQ.cjs +656 -0
  7. package/dist/advanced-FZy7WoYR.js +598 -0
  8. package/dist/advanced-FZy7WoYR.js.map +1 -0
  9. package/dist/arkivTransactions-BpARZOsH.d.cts +584 -0
  10. package/dist/arkivTransactions-BpARZOsH.d.cts.map +1 -0
  11. package/dist/arkivTransactions-DfZ_yVDD.d.ts +584 -0
  12. package/dist/arkivTransactions-DfZ_yVDD.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-BJGuhsqp.js +819 -0
  18. package/dist/attributes-BJGuhsqp.js.map +1 -0
  19. package/dist/attributes-CMJlp1wn.cjs +1039 -0
  20. package/dist/chains/index.cjs +2 -3
  21. package/dist/chains/index.d.cts +41 -76
  22. package/dist/chains/index.d.cts.map +1 -1
  23. package/dist/chains/index.d.ts +24 -59
  24. package/dist/chains/index.d.ts.map +1 -1
  25. package/dist/chains/index.js +2 -2
  26. package/dist/chains-BfNQliHU.cjs +76 -0
  27. package/dist/chains-Du8tql7I.js +60 -0
  28. package/dist/chains-Du8tql7I.js.map +1 -0
  29. package/dist/codec-M74UR1_0.d.ts +101 -0
  30. package/dist/codec-M74UR1_0.d.ts.map +1 -0
  31. package/dist/entity/index.cjs +21 -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-51znTSB1.cjs +56 -0
  41. package/dist/errors-CwPJ16bn.js +33 -0
  42. package/dist/errors-CwPJ16bn.js.map +1 -0
  43. package/dist/expiry-CZErShX6.js +95 -0
  44. package/dist/expiry-CZErShX6.js.map +1 -0
  45. package/dist/expiry-DRV29F1r.d.cts +79 -0
  46. package/dist/expiry-DRV29F1r.d.cts.map +1 -0
  47. package/dist/expiry-nDbCgZX4.d.ts +79 -0
  48. package/dist/expiry-nDbCgZX4.d.ts.map +1 -0
  49. package/dist/expiry-xr6mx4f7.cjs +135 -0
  50. package/dist/flags-5dTNRnow.d.ts +41 -0
  51. package/dist/flags-5dTNRnow.d.ts.map +1 -0
  52. package/dist/flags-Bh0HJldY.cjs +43 -0
  53. package/dist/flags-CRjPpoh3.d.cts +41 -0
  54. package/dist/flags-CRjPpoh3.d.cts.map +1 -0
  55. package/dist/flags-Cr76ldwF.js +33 -0
  56. package/dist/flags-Cr76ldwF.js.map +1 -0
  57. package/dist/index-CMeD8uEq.d.cts +280 -0
  58. package/dist/index-CMeD8uEq.d.cts.map +1 -0
  59. package/dist/index-CTDI5pXZ.d.ts +184 -0
  60. package/dist/index-CTDI5pXZ.d.ts.map +1 -0
  61. package/dist/index-CekGjkRx.d.cts +184 -0
  62. package/dist/index-CekGjkRx.d.cts.map +1 -0
  63. package/dist/index-D0IzFwMX.d.ts +328 -0
  64. package/dist/index-D0IzFwMX.d.ts.map +1 -0
  65. package/dist/index-DZxwz2Ky.d.cts +177 -0
  66. package/dist/index-DZxwz2Ky.d.cts.map +1 -0
  67. package/dist/index-Dz4SkQWg.d.ts +280 -0
  68. package/dist/index-Dz4SkQWg.d.ts.map +1 -0
  69. package/dist/index-JP31fjyM.d.ts +177 -0
  70. package/dist/index-JP31fjyM.d.ts.map +1 -0
  71. package/dist/index-NbfnXxgr.d.cts +424 -0
  72. package/dist/index-NbfnXxgr.d.cts.map +1 -0
  73. package/dist/index.cjs +434 -412
  74. package/dist/index.d.cts +401 -235
  75. package/dist/index.d.cts.map +1 -1
  76. package/dist/index.d.ts +402 -235
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +370 -404
  79. package/dist/index.js.map +1 -1
  80. package/dist/key-E7mv0BYf.cjs +116 -0
  81. package/dist/key-XQkpw2xh.js +82 -0
  82. package/dist/key-XQkpw2xh.js.map +1 -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-Cvrir3Q-.cjs +108 -0
  87. package/dist/payload-D53ms-Mg.d.ts +153 -0
  88. package/dist/payload-D53ms-Mg.d.ts.map +1 -0
  89. package/dist/payload-DaPzUvEh.js +92 -0
  90. package/dist/payload-DaPzUvEh.js.map +1 -0
  91. package/dist/payload-hluX1rc0.d.cts +153 -0
  92. package/dist/payload-hluX1rc0.d.cts.map +1 -0
  93. package/dist/query/index.cjs +26 -149
  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 -137
  97. package/dist/queryBuilder-BXR-HxD9.cjs +947 -0
  98. package/dist/queryBuilder-BwauPaGO.js +823 -0
  99. package/dist/queryBuilder-BwauPaGO.js.map +1 -0
  100. package/dist/selection-C6KeWJ7g.d.cts +441 -0
  101. package/dist/selection-C6KeWJ7g.d.cts.map +1 -0
  102. package/dist/selection-mjiiAGDO.d.ts +442 -0
  103. package/dist/selection-mjiiAGDO.d.ts.map +1 -0
  104. package/dist/types/index.cjs +4 -1
  105. package/dist/types/index.d.cts +7 -2
  106. package/dist/types/index.d.ts +8 -2
  107. package/dist/types/index.js +4 -1
  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 -9
  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 +28 -43
  122. package/src/actions/public/getEntityNonce.ts +30 -0
  123. package/src/actions/public/predictEntityKeys.test.ts +159 -0
  124. package/src/actions/public/predictEntityKeys.ts +152 -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 +8 -8
  129. package/src/actions/wallet/createEntity.ts +105 -26
  130. package/src/actions/wallet/deleteEntity.ts +2 -3
  131. package/src/actions/wallet/executeBatch.test.ts +76 -0
  132. package/src/actions/wallet/executeBatch.ts +51 -0
  133. package/src/actions/wallet/extendEntity.ts +40 -16
  134. package/src/actions/wallet/patchEntity.ts +90 -0
  135. package/src/attr/attributes.test.ts +120 -0
  136. package/src/attr/attributes.ts +196 -0
  137. package/src/attr/codec.test.ts +162 -0
  138. package/src/attr/codec.ts +220 -0
  139. package/src/attr/decimal.ts +86 -0
  140. package/src/attr/errors.ts +145 -0
  141. package/src/attr/index.ts +50 -0
  142. package/src/attr/names.ts +106 -0
  143. package/src/attr/types.ts +150 -0
  144. package/src/attr/values.test.ts +271 -0
  145. package/src/attr/values.ts +506 -0
  146. package/src/chains/cheesecake.ts +22 -0
  147. package/src/chains/index.ts +1 -2
  148. package/src/chains/localhost.ts +3 -0
  149. package/src/clients/createPublicClient.test.ts +4 -6
  150. package/src/clients/createPublicClient.ts +9 -8
  151. package/src/clients/createWalletClient.test.ts +4 -4
  152. package/src/clients/createWalletClient.ts +13 -9
  153. package/src/clients/decorators/arkivAdvanced.ts +144 -0
  154. package/src/clients/decorators/arkivPublic.ts +181 -147
  155. package/src/clients/decorators/arkivWallet.ts +141 -122
  156. package/src/consts.ts +2 -1
  157. package/src/entity/create.test.ts +203 -0
  158. package/src/entity/errors.ts +39 -0
  159. package/src/entity/events.ts +16 -0
  160. package/src/entity/expiry.test.ts +195 -0
  161. package/src/entity/expiry.ts +182 -0
  162. package/src/entity/flags.ts +65 -0
  163. package/src/entity/index.ts +16 -0
  164. package/src/entity/key.ts +88 -0
  165. package/src/entity/operations.ts +135 -0
  166. package/src/entity/params.ts +15 -0
  167. package/src/errors.ts +33 -28
  168. package/src/index.ts +19 -0
  169. package/src/query/engine.ts +68 -132
  170. package/src/query/errors.ts +151 -0
  171. package/src/query/expression.test.ts +286 -0
  172. package/src/query/expression.ts +500 -0
  173. package/src/query/index.ts +40 -4
  174. package/src/query/injection.test.ts +151 -0
  175. package/src/query/queryBuilder.test.ts +342 -637
  176. package/src/query/queryBuilder.ts +133 -359
  177. package/src/query/queryResult.ts +54 -51
  178. package/src/query/selection.test.ts +48 -98
  179. package/src/query/selection.ts +77 -65
  180. package/src/types/entity.test.ts +44 -155
  181. package/src/types/entity.ts +62 -44
  182. package/src/types/events.ts +64 -23
  183. package/src/types/index.ts +24 -20
  184. package/src/types/rpcSchema.ts +71 -33
  185. package/src/types/txParams.ts +8 -0
  186. package/src/utils/arkivTransactions.test.ts +687 -38
  187. package/src/utils/arkivTransactions.ts +400 -115
  188. package/src/utils/chains.test.ts +21 -24
  189. package/src/utils/compression.ts +1 -1
  190. package/src/utils/entities.test.ts +62 -0
  191. package/src/utils/entities.ts +111 -29
  192. package/src/utils/expirationTime.ts +153 -10
  193. package/src/utils/logger.ts +2 -2
  194. package/src/utils/payload.ts +29 -2
  195. package/src/utils/revert.test.ts +99 -0
  196. package/src/utils/revert.ts +145 -0
  197. package/dist/chains-BifaY04V.cjs +0 -108
  198. package/dist/chains-CrtkVbBh.js +0 -86
  199. package/dist/chains-CrtkVbBh.js.map +0 -1
  200. package/dist/consts-AUoL-v42.cjs +0 -18
  201. package/dist/consts-BV4PR-de.js +0 -7
  202. package/dist/consts-BV4PR-de.js.map +0 -1
  203. package/dist/entity-B6g_EPm1.d.cts +0 -382
  204. package/dist/entity-B6g_EPm1.d.cts.map +0 -1
  205. package/dist/entity-qoLMAuuk.d.ts +0 -382
  206. package/dist/entity-qoLMAuuk.d.ts.map +0 -1
  207. package/dist/index-DdspxNAA.d.ts +0 -481
  208. package/dist/index-DdspxNAA.d.ts.map +0 -1
  209. package/dist/index-Ds9dwqb5.d.cts +0 -481
  210. package/dist/index-Ds9dwqb5.d.cts.map +0 -1
  211. package/dist/payload-B2kFJyah.d.ts +0 -6
  212. package/dist/payload-B2kFJyah.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-Claf2jUO.js +0 -13
  216. package/dist/payload-Claf2jUO.js.map +0 -1
  217. package/dist/payload-DpA5PA-w.cjs +0 -23
  218. package/dist/query/index.js.map +0 -1
  219. package/dist/queryBuilder-D2uwP9jI.js +0 -704
  220. package/dist/queryBuilder-D2uwP9jI.js.map +0 -1
  221. package/dist/queryBuilder-UW2MCaX4.cjs +0 -792
  222. package/dist/utils/index.d.cts.map +0 -1
  223. package/dist/utils/index.d.ts.map +0 -1
  224. package/dist/utils/index.js.map +0 -1
  225. package/src/actions/public/buildQuery.ts +0 -10
  226. package/src/actions/public/subscribeEntityEvents.ts +0 -119
  227. package/src/actions/wallet/mutateEntities.ts +0 -111
  228. package/src/actions/wallet/updateEntity.ts +0 -60
  229. package/src/chains/braga.ts +0 -26
  230. package/src/chains/kaolin.ts +0 -29
  231. package/src/query/engine.test.ts +0 -526
  232. package/src/query/predicate.test.ts +0 -461
  233. package/src/query/predicate.ts +0 -144
  234. package/src/query/queryResult.test.ts +0 -270
  235. package/src/query/selectQueryBuilder.test.ts +0 -210
  236. package/src/types/attributes.ts +0 -16
  237. package/src/utils/validation.test.ts +0 -60
  238. package/src/utils/validation.ts +0 -32
  239. /package/dist/{types-H-TSmRpm.js → attr-DlmErkvR.cjs} +0 -0
  240. /package/dist/{types-o3zWarRp.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`, `executeBatch`, …) 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,24 @@
1
- import type { Account, Chain, Client, Hex, PublicActions, Transport } from "viem"
2
- import { getBlockTiming } from "../../actions/public/getBlockTiming"
1
+ import type { Account, Address, Chain, Client, Hex, PublicActions, Transport } from "viem"
2
+ import { type GetBlockTimingReturnType, 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 { SaltInput } from "../../entity/key"
17
+ import type { Expression } from "../../query/expression"
18
+ import { SelectQueryBuilder } from "../../query/queryBuilder"
8
19
  import type { EntitySelection, FullEntity, ProjectedEntity, SelectArg } from "../../query/selection"
9
20
  import type { Entity } from "../../types/entity"
10
- import type {
11
- OnEntityCreatedEvent,
12
- OnEntityDeletedEvent,
13
- OnEntityExpiredEvent,
14
- OnEntityExpiresInExtendedEvent,
15
- OnEntityUpdatedEvent,
16
- } from "../../types/events"
21
+ import { type PublicAdvancedActions, publicAdvancedActions } from "./arkivAdvanced"
17
22
 
18
23
  export type PublicArkivActions<
19
24
  transport extends Transport = Transport,
@@ -35,33 +40,42 @@ export type PublicArkivActions<
35
40
  /**
36
41
  * Returns the entity with the given key.
37
42
  *
38
- * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
43
+ * - JSON-RPC Methods: `arkiv_query`
39
44
  *
40
45
  * @param key - The entity key (hex string)
41
- * @returns The entity with the given key. {@link Entity}
46
+ * @returns The entity with the given key, with every field populated. {@link FullEntity}
47
+ *
48
+ * @throws {InvalidValueError} If the key is not 32 bytes.
49
+ * @throws {NoEntityFoundError} If no live entity has that key — it never existed, or it was
50
+ * deleted or has expired.
42
51
  *
43
52
  * @example
44
- * import { createPublicClient, http } from 'arkiv'
45
- * import { braga } from 'arkiv/chains'
53
+ * import { createPublicClient } from "@arkiv-network/sdk"
54
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
55
+ * import { http } from "viem"
46
56
  *
47
57
  * const client = createPublicClient({
48
- * chain: braga,
58
+ * chain: cheesecake,
49
59
  * transport: http(),
50
60
  * })
51
- * const entity = await client.getEntity("0x123")
52
- * // {
53
- * // key: "0x123",
54
- * // value: "0x123",
61
+ * const entity = await client.getEntity(entityKey)
62
+ * // Entity {
63
+ * // key: "0x9f2c…",
64
+ * // owner: "0xabc…",
65
+ * // contentType: "application/json",
66
+ * // payload: Uint8Array, // entity.toJson() / entity.toText() decode it
67
+ * // attributes: { category: { type: "str", value: "docs" } },
68
+ * // expiresAt: 1_297_000n,
55
69
  * // }
56
70
  */
57
- getEntity: (key: Hex) => Promise<Entity>
71
+ getEntity: (key: Hex) => Promise<FullEntity>
58
72
 
59
73
  /**
60
74
  * Returns a SelectQueryBuilder for building and executing queries — the recommended way to
61
75
  * read entities. You declare up front which parts of an entity you want returned, so results
62
76
  * always contain exactly the data you asked for.
63
77
  *
64
- * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/query
78
+ * - JSON-RPC Methods: `arkiv_query`
65
79
  *
66
80
  * @param selection - What to include in the results. Omit it (or pass `"*"`) to select everything,
67
81
  * or pass an object to select specific parts (at least one field is required). Every part is
@@ -70,12 +84,13 @@ export type PublicArkivActions<
70
84
  * @returns A SelectQueryBuilder instance for building and executing queries. {@link SelectQueryBuilder}
71
85
  *
72
86
  * @example
73
- * import { createPublicClient, http } from 'arkiv'
74
- * import { braga } from 'arkiv/chains'
75
- * import { eq } from 'arkiv/query'
87
+ * import { createPublicClient } from "@arkiv-network/sdk"
88
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
89
+ * import { eq } from "@arkiv-network/sdk/query"
90
+ * import { http } from "viem"
76
91
  *
77
92
  * const client = createPublicClient({
78
- * chain: braga,
93
+ * chain: cheesecake,
79
94
  * transport: http(),
80
95
  * })
81
96
  * // select everything
@@ -83,7 +98,7 @@ export type PublicArkivActions<
83
98
  * await client.select("*").where(eq("category", "docs")).fetch()
84
99
  * // only the key
85
100
  * await client.select({ key: true }).where(eq("category", "docs")).fetch()
86
- * // select specific fields — result typed { owner: Hex; attributes: Attribute[] }
101
+ * // select specific fields — result typed { owner: Hex; attributes: Attributes }
87
102
  * await client.select({ owner: true, attributes: true }).fetch()
88
103
  * // a single field — result typed { owner: Hex }
89
104
  * await client.select({ owner: true }).fetch()
@@ -95,9 +110,11 @@ export type PublicArkivActions<
95
110
  * Pick the entity fields to return. Set the ones you want to `true` (at least one is required);
96
111
  * the result is typed to exactly those fields, so reading anything else is a compile error.
97
112
  *
98
- * Available fields: `key`, `owner`, `creator`, `contentType`, `payload`, `attributes`,
99
- * `expiresAtBlock`, `createdAtBlock`, `lastModifiedAtBlock`, `transactionIndexInBlock`,
100
- * `operationIndexInTransaction`.
113
+ * Available fields: `key`, `owner`, `creator`, `createdAt`, `updatedAt`, `expiresAt`,
114
+ * `creationFlags`, `contentType`, `payload`, `attributeSchema` and `attributes`.
115
+ *
116
+ * `attributes` also takes a map of names, to fetch only those:
117
+ * `select({ key: true, attributes: { projectId: true } })`.
101
118
  *
102
119
  * Pass the selection inline so its fields stay literal `true`. A selection stored in a `let`/
103
120
  * `const` variable widens to `boolean` and the result type can no longer be narrowed — annotate
@@ -105,7 +122,8 @@ export type PublicArkivActions<
105
122
  *
106
123
  * @example
107
124
  * client.select({ owner: true, attributes: true }) // entities typed { owner, attributes }
108
- * client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too
125
+ * client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too
126
+ * client.select({ key: true, attributeSchema: true }) // what shape is the data?
109
127
  */
110
128
  <const S extends EntitySelection>(selection: S): SelectQueryBuilder<ProjectedEntity<S>>
111
129
  /**
@@ -116,90 +134,133 @@ export type PublicArkivActions<
116
134
  }
117
135
 
118
136
  /**
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
137
+ * Runs one query and returns one page, with no builder in between.
123
138
  *
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.
139
+ * Use {@link PublicArkivActions.select} for anything typed — this returns full {@link Entity} objects whatever the
140
+ * selection, and takes a raw string as an escape hatch for a query built elsewhere. A raw string
141
+ * goes to the node exactly as written, with none of the name, type or operator checks the
142
+ * expression combinators apply.
128
143
  *
129
- * @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}
144
+ * @param query - An {@link Expression}, or the raw query string.
145
+ * @param queryOptions - Selection, page size, cursor and block. {@link QueryOptions}
146
+ * @returns One page of entities. {@link QueryReturnType}
130
147
  *
131
148
  * @example
132
- * import { createPublicClient, http } from 'arkiv'
133
- * import { braga } from 'arkiv/chains'
149
+ * import { createPublicClient } from "@arkiv-network/sdk"
150
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
151
+ * import { and, eq, gte } from "@arkiv-network/sdk/query"
152
+ * import { i32 } from "@arkiv-network/sdk/attr"
153
+ * import { http } from "viem"
134
154
  *
135
155
  * const client = createPublicClient({
136
- * chain: braga,
156
+ * chain: cheesecake,
137
157
  * transport: http(),
138
158
  * })
139
- * const query = client.buildQuery()
140
- * const entities = await query.where("key", "=", "value").ownedBy("0x123").fetch()
159
+ * const page = await client.query(and(eq("category", "docs"), gte("level", i32(10))), {
160
+ * select: { key: true, attributes: true },
161
+ * limit: 100,
162
+ * })
163
+ * // { entities: [Entity], cursor: "b64:…", blockNumber: 32223n }
141
164
  *
165
+ * // The raw form, unchecked:
166
+ * await client.query("category = str('docs') AND level >= i32(10)")
142
167
  */
143
- buildQuery: () => QueryBuilder
168
+ query: (query: Expression | string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
144
169
 
145
170
  /**
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}
171
+ * Returns the total number of entities on the chain.
172
+ * @returns The number of entities currently stored
151
173
  *
152
174
  * @example
153
- * import { createPublicClient, http } from 'arkiv'
154
- * import { braga } from 'arkiv/chains'
175
+ * import { createPublicClient } from "@arkiv-network/sdk"
176
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
177
+ * import { http } from "viem"
155
178
  *
156
179
  * const client = createPublicClient({
157
- * chain: braga,
180
+ * chain: cheesecake,
158
181
  * transport: http(),
159
182
  * })
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 }
183
+ * const entityCount = await client.getEntityCount()
184
+ * // entityCount = 0
173
185
  */
174
- query: (query: string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
186
+ getEntityCount: () => Promise<number>
175
187
 
176
188
  /**
177
- * Returns the number of entities in the DBChain.
178
- * @returns The number of entities in the DBChain
189
+ * Returns how many entities an account has created — its entity-minting nonce.
190
+ *
191
+ * Not the account's transaction nonce: the engine keeps its own counter per creator and mixes it
192
+ * into every key it mints, which is why two identical creates from one account never collide.
193
+ *
194
+ * @param owner - The account whose nonce to read.
195
+ * @returns The nonce the account's next create will use.
179
196
  *
180
197
  * @example
181
- * import { createPublicClient, http } from 'arkiv'
182
- * import { braga } from 'arkiv/chains'
198
+ * import { createPublicClient } from "@arkiv-network/sdk"
199
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
200
+ * import { http } from "viem"
183
201
  *
184
202
  * const client = createPublicClient({
185
- * chain: braga,
203
+ * chain: cheesecake,
186
204
  * transport: http(),
187
205
  * })
188
- * const entityCount = await client.getEntityCount()
189
- * // entityCount = 0
206
+ * const nonce = await client.getEntityNonce("0xabc…")
207
+ * // 7n — the next entity this account creates is its eighth
190
208
  */
191
- getEntityCount: () => Promise<number>
209
+ getEntityNonce: (owner: Address) => Promise<bigint>
210
+
211
+ /**
212
+ * Works out the keys an account's next creates will be given, before sending them.
213
+ *
214
+ * The engine derives a key from the chain, the registry, the owner, the owner's nonce and a
215
+ * salt — everything but the nonce is known to the caller, and the nonce is read here. This is
216
+ * what lets a batch reference an entity it is about to mint.
217
+ *
218
+ * Each key arrives paired with the salt that mints it, because a create defaults to a *random*
219
+ * salt: a predicted key only holds if the create carries the salt it was predicted with. And the
220
+ * prediction holds only while nothing else from this owner is in flight — for a key you can rely
221
+ * on unconditionally, read it back from the create instead.
222
+ *
223
+ * A literal `count` comes back as a fixed-length tuple, so the pairs destructure into names.
224
+ *
225
+ * @param parameters - Owner, and either a count or the salts. {@link PredictEntityKeysParameters}
226
+ * @returns One `{ key, salt }` pair per create, in batch order.
227
+ * {@link PredictEntityKeysReturnType}
228
+ *
229
+ * @example A batch whose second entity points at its first.
230
+ * import { key } from "@arkiv-network/sdk/attr"
231
+ *
232
+ * const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
233
+ * await wallet.executeBatch({
234
+ * creates: [
235
+ * { payload, contentType, expires, salt: parent.salt },
236
+ * {
237
+ * payload,
238
+ * contentType,
239
+ * expires,
240
+ * salt: child.salt,
241
+ * attributes: { parent: key(parent.key) },
242
+ * },
243
+ * ],
244
+ * })
245
+ */
246
+ predictEntityKeys: <
247
+ const TCount extends number = number,
248
+ const TSalts extends readonly SaltInput[] | undefined = undefined,
249
+ >(
250
+ parameters: PredictEntityKeysParameters<TCount, TSalts>,
251
+ ) => Promise<PredictEntityKeysReturnType<TCount, TSalts>>
192
252
 
193
253
  /**
194
254
  * Returns the current block timing.
195
255
  * @returns The current block timing. {@link GetBlockTimingReturnType}
196
256
  *
197
257
  * @example
198
- * import { createPublicClient, http } from 'arkiv'
199
- * import { braga } from 'arkiv/chains'
258
+ * import { createPublicClient } from "@arkiv-network/sdk"
259
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
260
+ * import { http } from "viem"
200
261
  *
201
262
  * const client = createPublicClient({
202
- * chain: braga,
263
+ * chain: cheesecake,
203
264
  * transport: http(),
204
265
  * })
205
266
  * const blockTiming = await client.getBlockTiming()
@@ -209,50 +270,45 @@ export type PublicArkivActions<
209
270
  * // blockDuration: 2, // in seconds
210
271
  * // }
211
272
  */
212
- getBlockTiming: () => Promise<{
213
- currentBlock: bigint
214
- currentBlockTime: number
215
- blockDuration: number
216
- }>
273
+ getBlockTiming: () => Promise<GetBlockTimingReturnType>
217
274
 
218
275
  /**
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
276
+ * Watches entity events, calling the handlers you pass as they arrive.
277
+ *
278
+ * All five are decoded from logs — `onEntityCreated`, `onEntityPatched`, `onExpiryExtended`,
279
+ * `onOwnershipTransferred`, `onEntityDeleted` — and each carries the block, transaction and log
280
+ * index it came from, which is the order the operations were applied in. `onEvent` receives all
281
+ * of them, whatever their type.
282
+ *
283
+ * @param parameters - Handlers and options, all optional. {@link WatchEntityEventsParameters}
284
+ * @returns A function that stops the watcher.
224
285
  *
225
286
  * @example
226
- * import { createPublicClient, http } from 'arkiv'
227
- * import { braga } from 'arkiv/chains'
287
+ * import { createPublicClient } from "@arkiv-network/sdk"
288
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
289
+ * import { http } from "viem"
228
290
  *
229
291
  * const client = createPublicClient({
230
- * chain: braga,
292
+ * chain: cheesecake,
231
293
  * transport: http(),
232
294
  * })
233
- * const unsubscribe = await client.subscribeEntityEvents({
234
- * onError: (error) => console.error("subscribeEntityEvents error", error),
295
+ * const unwatch = client.watchEntityEvents({
296
+ * onEntityCreated: ({ entityKey, expiresAt }) => console.log(entityKey, "until", expiresAt),
297
+ * onError: (error) => console.error("watchEntityEvents error", error),
235
298
  * })
236
- * unsubscribe() // unsubscribe from the events
299
+ * unwatch() // stop watching
300
+ */
301
+ watchEntityEvents: (parameters: WatchEntityEventsParameters) => () => void
302
+
303
+ /**
304
+ * The read-only half of the advanced path: check on a transaction and decode its result with at
305
+ * most one RPC call per action — so a process that holds nothing but a transaction hash can
306
+ * follow it without a wallet. {@link PublicAdvancedActions}
307
+ *
308
+ * @example
309
+ * const { status } = await client.advanced.pingTransaction(txHash) // 1 eth_getTransactionReceipt
237
310
  */
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>
311
+ advanced: PublicAdvancedActions
256
312
  }
257
313
 
258
314
  export function publicArkivActions<
@@ -262,42 +318,20 @@ export function publicArkivActions<
262
318
  >(client: Client<transport, chain, account>) {
263
319
  return {
264
320
  getEntity: (key: Hex) => getEntity(client, key),
265
- query: (rawQuery: string, queryOptions?: QueryOptions) => query(client, rawQuery, queryOptions),
266
- buildQuery: () => new QueryBuilder(client),
321
+ query: (rawQuery: Expression | string, queryOptions?: QueryOptions) =>
322
+ query(client, rawQuery, queryOptions),
267
323
  select: (selection?: SelectArg) => new SelectQueryBuilder(client, selection),
268
324
  getBlockTiming: () => getBlockTiming(client),
269
325
  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
- ),
326
+ getEntityNonce: (owner: Address) => getEntityNonce(client, owner),
327
+ predictEntityKeys: <
328
+ const TCount extends number = number,
329
+ const TSalts extends readonly SaltInput[] | undefined = undefined,
330
+ >(
331
+ parameters: PredictEntityKeysParameters<TCount, TSalts>,
332
+ ) => predictEntityKeys(client, parameters),
333
+ watchEntityEvents: (parameters: WatchEntityEventsParameters) =>
334
+ watchEntityEvents(client, parameters),
335
+ advanced: publicAdvancedActions(client),
302
336
  }
303
337
  }