@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.
- package/README.md +71 -16
- package/dist/actions/advanced/index.cjs +13 -0
- package/dist/actions/advanced/index.d.cts +8 -0
- package/dist/actions/advanced/index.d.ts +9 -0
- package/dist/actions/advanced/index.js +9 -0
- package/dist/advanced-8ZPTmmaN.js +598 -0
- package/dist/advanced-8ZPTmmaN.js.map +1 -0
- package/dist/advanced-fPImL6lW.cjs +656 -0
- package/dist/arkivTransactions-D74gERHG.d.cts +571 -0
- package/dist/arkivTransactions-D74gERHG.d.cts.map +1 -0
- package/dist/arkivTransactions-NtGD6uk5.d.ts +571 -0
- package/dist/arkivTransactions-NtGD6uk5.d.ts.map +1 -0
- package/dist/attr/index.cjs +35 -0
- package/dist/attr/index.d.cts +2 -0
- package/dist/attr/index.d.ts +3 -0
- package/dist/attr/index.js +4 -0
- package/dist/attributes-BhY5DwJp.js +809 -0
- package/dist/attributes-BhY5DwJp.js.map +1 -0
- package/dist/attributes-Df9IsCVs.cjs +1029 -0
- package/dist/chains/index.cjs +2 -3
- package/dist/chains/index.d.cts +22 -60
- package/dist/chains/index.d.cts.map +1 -1
- package/dist/chains/index.d.ts +22 -60
- package/dist/chains/index.d.ts.map +1 -1
- package/dist/chains/index.js +2 -2
- package/dist/chains-BJrZs6sG.js +57 -0
- package/dist/chains-BJrZs6sG.js.map +1 -0
- package/dist/chains-BYRTTipa.cjs +73 -0
- package/dist/codec-Car3KkFF.d.ts +102 -0
- package/dist/codec-Car3KkFF.d.ts.map +1 -0
- package/dist/entity/index.cjs +20 -0
- package/dist/entity/index.d.cts +4 -0
- package/dist/entity/index.d.ts +5 -0
- package/dist/entity/index.js +7 -0
- package/dist/entity-B00Li04j.cjs +71 -0
- package/dist/entity-B7G8q_Eo.cjs +0 -0
- package/dist/entity-BYQR1uoe.js +67 -0
- package/dist/entity-BYQR1uoe.js.map +1 -0
- package/dist/entity-CD_qFF2M.js +0 -0
- package/dist/errors-BVbjKVMN.cjs +56 -0
- package/dist/errors-LTe7bOYS.js +33 -0
- package/dist/errors-LTe7bOYS.js.map +1 -0
- package/dist/expiry-BELY2Kpw.cjs +135 -0
- package/dist/expiry-BjpxZZQU.js +95 -0
- package/dist/expiry-BjpxZZQU.js.map +1 -0
- package/dist/expiry-DRV29F1r.d.cts +79 -0
- package/dist/expiry-DRV29F1r.d.cts.map +1 -0
- package/dist/expiry-nDbCgZX4.d.ts +79 -0
- package/dist/expiry-nDbCgZX4.d.ts.map +1 -0
- package/dist/flags-5dTNRnow.d.ts +41 -0
- package/dist/flags-5dTNRnow.d.ts.map +1 -0
- package/dist/flags-CRjPpoh3.d.cts +41 -0
- package/dist/flags-CRjPpoh3.d.cts.map +1 -0
- package/dist/flags-DFBs2J94.js +33 -0
- package/dist/flags-DFBs2J94.js.map +1 -0
- package/dist/flags-kr276q6i.cjs +43 -0
- package/dist/index-B5j76711.d.ts +184 -0
- package/dist/index-B5j76711.d.ts.map +1 -0
- package/dist/index-BF7Mq9Is.d.cts +280 -0
- package/dist/index-BF7Mq9Is.d.cts.map +1 -0
- package/dist/index-CA4V7Pdh.d.cts +167 -0
- package/dist/index-CA4V7Pdh.d.cts.map +1 -0
- package/dist/index-CV5zCdpa.d.cts +417 -0
- package/dist/index-CV5zCdpa.d.cts.map +1 -0
- package/dist/index-DHDud2hC.d.ts +280 -0
- package/dist/index-DHDud2hC.d.ts.map +1 -0
- package/dist/index-DvYvrkdk.d.ts +320 -0
- package/dist/index-DvYvrkdk.d.ts.map +1 -0
- package/dist/index-EeUO0nnJ.d.cts +184 -0
- package/dist/index-EeUO0nnJ.d.cts.map +1 -0
- package/dist/index-fX_XyqLp.d.ts +167 -0
- package/dist/index-fX_XyqLp.d.ts.map +1 -0
- package/dist/index.cjs +411 -405
- package/dist/index.d.cts +360 -209
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +361 -209
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +342 -387
- package/dist/index.js.map +1 -1
- package/dist/key-D1Bh7MF0.js +70 -0
- package/dist/key-D1Bh7MF0.js.map +1 -0
- package/dist/key-WKhXnXuU.cjs +98 -0
- package/dist/logger-CVpvU8ik.js +153 -0
- package/dist/logger-CVpvU8ik.js.map +1 -0
- package/dist/logger-Cr15lPAQ.cjs +188 -0
- package/dist/payload-BNoud2KZ.d.cts +94 -0
- package/dist/payload-BNoud2KZ.d.cts.map +1 -0
- package/dist/payload-Bz6651ax.js +67 -0
- package/dist/payload-Bz6651ax.js.map +1 -0
- package/dist/payload-CcUj85ys.d.ts +94 -0
- package/dist/payload-CcUj85ys.d.ts.map +1 -0
- package/dist/payload-KC14SDlN.cjs +83 -0
- package/dist/query/index.cjs +26 -150
- package/dist/query/index.d.cts +5 -3
- package/dist/query/index.d.ts +6 -3
- package/dist/query/index.js +8 -138
- package/dist/queryBuilder-DM6AWCBa.js +820 -0
- package/dist/queryBuilder-DM6AWCBa.js.map +1 -0
- package/dist/queryBuilder-DbUMEZln.cjs +944 -0
- package/dist/selection-C4UhsMOO.d.ts +434 -0
- package/dist/selection-C4UhsMOO.d.ts.map +1 -0
- package/dist/selection-DPg0uyJf.d.cts +433 -0
- package/dist/selection-DPg0uyJf.d.cts.map +1 -0
- package/dist/types/index.cjs +3 -3
- package/dist/types/index.d.cts +7 -2
- package/dist/types/index.d.ts +8 -2
- package/dist/types/index.js +3 -3
- package/dist/types-Bu_ZwMbZ.js +0 -0
- package/dist/types-NRqymi6S.cjs +0 -0
- package/dist/utils/index.cjs +4 -17
- package/dist/utils/index.d.cts +3 -17
- package/dist/utils/index.d.ts +3 -17
- package/dist/utils/index.js +4 -18
- package/package.json +26 -5
- package/src/actions/advanced/advanced.test.ts +258 -0
- package/src/actions/advanced/buildMutation.ts +104 -0
- package/src/actions/advanced/getMutationResult.ts +112 -0
- package/src/actions/advanced/index.ts +21 -0
- package/src/actions/advanced/pingTransaction.ts +43 -0
- package/src/actions/advanced/sendMutation.ts +59 -0
- package/src/actions/public/getEntity.ts +27 -43
- package/src/actions/public/getEntityNonce.ts +30 -0
- package/src/actions/public/predictEntityKeys.test.ts +143 -0
- package/src/actions/public/predictEntityKeys.ts +138 -0
- package/src/actions/public/query.ts +35 -67
- package/src/actions/public/watchEntityEvents.test.ts +414 -0
- package/src/actions/public/watchEntityEvents.ts +225 -0
- package/src/actions/wallet/changeOwnership.ts +2 -2
- package/src/actions/wallet/createEntity.ts +99 -24
- package/src/actions/wallet/extendEntity.ts +37 -13
- package/src/actions/wallet/mutateEntities.test.ts +76 -0
- package/src/actions/wallet/mutateEntities.ts +16 -33
- package/src/actions/wallet/patchEntity.ts +90 -0
- package/src/attr/attributes.test.ts +120 -0
- package/src/attr/attributes.ts +190 -0
- package/src/attr/codec.test.ts +162 -0
- package/src/attr/codec.ts +220 -0
- package/src/attr/decimal.ts +86 -0
- package/src/attr/errors.ts +145 -0
- package/src/attr/index.ts +50 -0
- package/src/attr/names.ts +106 -0
- package/src/attr/types.ts +150 -0
- package/src/attr/values.test.ts +271 -0
- package/src/attr/values.ts +502 -0
- package/src/chains/cheesecake.ts +22 -0
- package/src/chains/index.ts +1 -2
- package/src/clients/createPublicClient.test.ts +3 -5
- package/src/clients/createPublicClient.ts +5 -4
- package/src/clients/createWalletClient.test.ts +2 -2
- package/src/clients/createWalletClient.ts +13 -7
- package/src/clients/decorators/arkivAdvanced.ts +144 -0
- package/src/clients/decorators/arkivPublic.ts +172 -139
- package/src/clients/decorators/arkivWallet.ts +101 -94
- package/src/entity/create.test.ts +184 -0
- package/src/entity/errors.ts +38 -0
- package/src/entity/events.ts +16 -0
- package/src/entity/expiry.test.ts +195 -0
- package/src/entity/expiry.ts +181 -0
- package/src/entity/flags.ts +65 -0
- package/src/entity/index.ts +15 -0
- package/src/entity/key.ts +68 -0
- package/src/entity/operations.ts +134 -0
- package/src/entity/params.ts +15 -0
- package/src/errors.ts +26 -49
- package/src/index.ts +19 -0
- package/src/query/engine.ts +68 -137
- package/src/query/errors.ts +151 -0
- package/src/query/expression.test.ts +286 -0
- package/src/query/expression.ts +493 -0
- package/src/query/index.ts +40 -4
- package/src/query/injection.test.ts +151 -0
- package/src/query/queryBuilder.test.ts +342 -637
- package/src/query/queryBuilder.ts +133 -359
- package/src/query/queryResult.ts +54 -51
- package/src/query/selection.test.ts +48 -98
- package/src/query/selection.ts +77 -65
- package/src/types/entity.test.ts +44 -155
- package/src/types/entity.ts +60 -52
- package/src/types/events.ts +59 -16
- package/src/types/index.ts +20 -17
- package/src/types/rpcSchema.ts +69 -37
- package/src/utils/arkivTransactions.test.ts +600 -155
- package/src/utils/arkivTransactions.ts +350 -219
- package/src/utils/chains.test.ts +21 -24
- package/src/utils/compression.ts +1 -1
- package/src/utils/entities.test.ts +62 -0
- package/src/utils/entities.ts +109 -37
- package/src/utils/expirationTime.ts +114 -10
- package/src/utils/logger.ts +2 -2
- package/src/utils/revert.test.ts +99 -0
- package/src/utils/revert.ts +145 -0
- package/dist/chains-BifaY04V.cjs +0 -108
- package/dist/chains-CrtkVbBh.js +0 -86
- package/dist/chains-CrtkVbBh.js.map +0 -1
- package/dist/consts-Bz0LZQZY.js +0 -7
- package/dist/consts-Bz0LZQZY.js.map +0 -1
- package/dist/consts-CxT1-RXU.cjs +0 -18
- package/dist/entity-BhSXaB23.cjs +0 -81
- package/dist/entity-CN41IOrq.d.cts +0 -401
- package/dist/entity-CN41IOrq.d.cts.map +0 -1
- package/dist/entity-DGfVyB-a.js +0 -71
- package/dist/entity-DGfVyB-a.js.map +0 -1
- package/dist/entity-NnEVlePN.d.ts +0 -401
- package/dist/entity-NnEVlePN.d.ts.map +0 -1
- package/dist/index-ClkpS6s_.d.ts +0 -481
- package/dist/index-ClkpS6s_.d.ts.map +0 -1
- package/dist/index-w4qop0Pe.d.cts +0 -481
- package/dist/index-w4qop0Pe.d.cts.map +0 -1
- package/dist/payload-BpNUPOnY.js +0 -13
- package/dist/payload-BpNUPOnY.js.map +0 -1
- package/dist/payload-C2KHOUoj.d.ts +0 -6
- package/dist/payload-C2KHOUoj.d.ts.map +0 -1
- package/dist/payload-CJN8fTvX.d.cts +0 -6
- package/dist/payload-CJN8fTvX.d.cts.map +0 -1
- package/dist/payload-D8YLKcJj.cjs +0 -23
- package/dist/query/index.js.map +0 -1
- package/dist/queryBuilder-BE_XhLLa.js +0 -735
- package/dist/queryBuilder-BE_XhLLa.js.map +0 -1
- package/dist/queryBuilder-J37buGCi.cjs +0 -865
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/src/actions/public/buildQuery.ts +0 -10
- package/src/actions/public/subscribeEntityEvents.ts +0 -93
- package/src/actions/wallet/updateEntity.ts +0 -59
- package/src/chains/braga.ts +0 -26
- package/src/chains/kaolin.ts +0 -29
- package/src/query/engine.test.ts +0 -571
- package/src/query/predicate.test.ts +0 -461
- package/src/query/predicate.ts +0 -144
- package/src/query/queryResult.test.ts +0 -270
- package/src/query/selectQueryBuilder.test.ts +0 -213
- package/src/types/attributes.ts +0 -28
- package/src/utils/validation.test.ts +0 -106
- package/src/utils/validation.ts +0 -80
- /package/dist/{types-Ci4BRClw.js → attr-DlmErkvR.cjs} +0 -0
- /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 {
|
|
7
|
-
|
|
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
|
|
45
|
+
* @returns The entity with the given key, with every field populated. {@link FullEntity}
|
|
42
46
|
*
|
|
43
47
|
* @example
|
|
44
|
-
* import { createPublicClient
|
|
45
|
-
* import {
|
|
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:
|
|
53
|
+
* chain: cheesecake,
|
|
49
54
|
* transport: http(),
|
|
50
55
|
* })
|
|
51
|
-
* const entity = await client.getEntity(
|
|
52
|
-
* // {
|
|
53
|
-
* // key: "
|
|
54
|
-
* //
|
|
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<
|
|
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
|
|
74
|
-
* import {
|
|
75
|
-
* import { eq } from
|
|
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:
|
|
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:
|
|
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`, `
|
|
99
|
-
* `
|
|
100
|
-
*
|
|
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 })
|
|
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
|
-
*
|
|
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
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
133
|
-
* import {
|
|
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:
|
|
151
|
+
* chain: cheesecake,
|
|
137
152
|
* transport: http(),
|
|
138
153
|
* })
|
|
139
|
-
* const
|
|
140
|
-
*
|
|
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
|
-
|
|
163
|
+
query: (query: Expression | string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
|
|
144
164
|
|
|
145
165
|
/**
|
|
146
|
-
* Returns
|
|
147
|
-
*
|
|
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
|
|
154
|
-
* import {
|
|
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:
|
|
175
|
+
* chain: cheesecake,
|
|
158
176
|
* transport: http(),
|
|
159
177
|
* })
|
|
160
|
-
* const
|
|
161
|
-
* //
|
|
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
|
-
|
|
181
|
+
getEntityCount: () => Promise<number>
|
|
175
182
|
|
|
176
183
|
/**
|
|
177
|
-
* Returns
|
|
178
|
-
*
|
|
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
|
|
182
|
-
* import {
|
|
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:
|
|
198
|
+
* chain: cheesecake,
|
|
186
199
|
* transport: http(),
|
|
187
200
|
* })
|
|
188
|
-
* const
|
|
189
|
-
* //
|
|
201
|
+
* const nonce = await client.getEntityNonce("0xabc…")
|
|
202
|
+
* // 7n — the next entity this account creates is its eighth
|
|
190
203
|
*/
|
|
191
|
-
|
|
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
|
|
199
|
-
* import {
|
|
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:
|
|
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
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
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
|
|
227
|
-
* import {
|
|
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:
|
|
291
|
+
* chain: cheesecake,
|
|
231
292
|
* transport: http(),
|
|
232
293
|
* })
|
|
233
|
-
* const
|
|
234
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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) =>
|
|
266
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
}
|