@arkiv-network/sdk 0.7.0-dev.1 → 0.8.0-dev.1
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 +29 -16
- package/dist/attr/index.cjs +34 -0
- package/dist/attr/index.d.cts +2 -0
- package/dist/attr/index.d.ts +2 -0
- package/dist/attr/index.js +3 -0
- package/dist/attr-BDZ-APg5.js +809 -0
- package/dist/attr-BDZ-APg5.js.map +1 -0
- package/dist/attr-BvxHN99W.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/changeOwnership-B7bEgla4.d.cts +509 -0
- package/dist/changeOwnership-B7bEgla4.d.cts.map +1 -0
- package/dist/changeOwnership-DwgtdSFc.d.ts +509 -0
- package/dist/changeOwnership-DwgtdSFc.d.ts.map +1 -0
- package/dist/entity/index.cjs +19 -0
- package/dist/entity/index.d.cts +4 -0
- package/dist/entity/index.d.ts +4 -0
- package/dist/entity/index.js +6 -0
- package/dist/entity-B0t6sN7F.cjs +71 -0
- package/dist/entity-BIp_df9u.js +67 -0
- package/dist/entity-BIp_df9u.js.map +1 -0
- package/dist/entity-CFhbAv0R.js +70 -0
- package/dist/entity-CFhbAv0R.js.map +1 -0
- package/dist/entity-wfBnZd91.cjs +98 -0
- package/dist/errors-D-eJkGVc.cjs +56 -0
- package/dist/errors-DGB8AgT2.js +33 -0
- package/dist/errors-DGB8AgT2.js.map +1 -0
- package/dist/expiry-BUYIXTGb.cjs +135 -0
- package/dist/expiry-BxOlvVWC.d.ts +79 -0
- package/dist/expiry-BxOlvVWC.d.ts.map +1 -0
- package/dist/expiry-DGRzrSan.js +95 -0
- package/dist/expiry-DGRzrSan.js.map +1 -0
- package/dist/expiry-DRV29F1r.d.cts +79 -0
- package/dist/expiry-DRV29F1r.d.cts.map +1 -0
- package/dist/flags-0Vl5rrHq.d.cts +41 -0
- package/dist/flags-0Vl5rrHq.d.cts.map +1 -0
- package/dist/flags-Ct8k0gpB.cjs +43 -0
- package/dist/flags-ZtlvOIIk.js +33 -0
- package/dist/flags-ZtlvOIIk.js.map +1 -0
- package/dist/flags-wmcMoAnN.d.ts +41 -0
- package/dist/flags-wmcMoAnN.d.ts.map +1 -0
- package/dist/index-Cgw1u5aY.d.cts +278 -0
- package/dist/index-Cgw1u5aY.d.cts.map +1 -0
- package/dist/index-ClgIuxJ8.d.ts +159 -0
- package/dist/index-ClgIuxJ8.d.ts.map +1 -0
- package/dist/index-D0CmtiWT.d.cts +159 -0
- package/dist/index-D0CmtiWT.d.cts.map +1 -0
- package/dist/index-D8LZt-3J.d.cts +417 -0
- package/dist/index-D8LZt-3J.d.cts.map +1 -0
- package/dist/index-DVYFaXNV.d.ts +417 -0
- package/dist/index-DVYFaXNV.d.ts.map +1 -0
- package/dist/index-VCqgn29D.d.ts +278 -0
- package/dist/index-VCqgn29D.d.ts.map +1 -0
- package/dist/index.cjs +676 -375
- package/dist/index.d.cts +247 -208
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +247 -208
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +626 -368
- package/dist/index.js.map +1 -1
- package/dist/payload-Bnw1hrvb.cjs +83 -0
- package/dist/payload-CIxSn_DW.js +67 -0
- package/dist/payload-CIxSn_DW.js.map +1 -0
- package/dist/payload-Dgx3PQeK.d.ts +94 -0
- package/dist/payload-Dgx3PQeK.d.ts.map +1 -0
- package/dist/payload-P0nWyjLg.d.cts +94 -0
- package/dist/payload-P0nWyjLg.d.cts.map +1 -0
- package/dist/query/index.cjs +24 -150
- package/dist/query/index.d.cts +5 -3
- package/dist/query/index.d.ts +5 -3
- package/dist/query/index.js +6 -138
- package/dist/queryBuilder-BXDvX1K_.cjs +1123 -0
- package/dist/queryBuilder-CbLL4pG5.js +963 -0
- package/dist/queryBuilder-CbLL4pG5.js.map +1 -0
- package/dist/selection-BvK6yX0g.d.cts +433 -0
- package/dist/selection-BvK6yX0g.d.cts.map +1 -0
- package/dist/selection-fpmI3ADQ.d.ts +433 -0
- package/dist/selection-fpmI3ADQ.d.ts.map +1 -0
- package/dist/types/index.cjs +3 -3
- package/dist/types/index.d.cts +7 -2
- package/dist/types/index.d.ts +7 -2
- package/dist/types/index.js +3 -3
- 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/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 +33 -69
- 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 +19 -21
- 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/arkivPublic.ts +160 -139
- package/src/clients/decorators/arkivWallet.ts +86 -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 +14 -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 +6 -0
- package/src/query/engine.ts +59 -139
- 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 +322 -637
- package/src/query/queryBuilder.ts +126 -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 +181 -190
- 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 → types-Bx1EKe0v.js} +0 -0
- /package/dist/{types-a8gm_IaQ.cjs → types-CKPddlfS.cjs} +0 -0
|
@@ -1,19 +1,22 @@
|
|
|
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"
|
|
17
20
|
|
|
18
21
|
export type PublicArkivActions<
|
|
19
22
|
transport extends Transport = Transport,
|
|
@@ -38,23 +41,28 @@ export type PublicArkivActions<
|
|
|
38
41
|
* - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
|
|
39
42
|
*
|
|
40
43
|
* @param key - The entity key (hex string)
|
|
41
|
-
* @returns The entity with the given key. {@link
|
|
44
|
+
* @returns The entity with the given key, with every field populated. {@link FullEntity}
|
|
42
45
|
*
|
|
43
46
|
* @example
|
|
44
|
-
* import { createPublicClient
|
|
45
|
-
* import {
|
|
47
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
48
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
49
|
+
* import { http } from "viem"
|
|
46
50
|
*
|
|
47
51
|
* const client = createPublicClient({
|
|
48
|
-
* chain:
|
|
52
|
+
* chain: cheesecake,
|
|
49
53
|
* transport: http(),
|
|
50
54
|
* })
|
|
51
|
-
* const entity = await client.getEntity(
|
|
52
|
-
* // {
|
|
53
|
-
* // key: "
|
|
54
|
-
* //
|
|
55
|
+
* const entity = await client.getEntity(entityKey)
|
|
56
|
+
* // Entity {
|
|
57
|
+
* // key: "0x9f2c…",
|
|
58
|
+
* // owner: "0xabc…",
|
|
59
|
+
* // contentType: "application/json",
|
|
60
|
+
* // payload: Uint8Array, // entity.toJson() / entity.toText() decode it
|
|
61
|
+
* // attributes: { category: { type: "str", value: "docs" } },
|
|
62
|
+
* // expiresAt: 1_297_000n,
|
|
55
63
|
* // }
|
|
56
64
|
*/
|
|
57
|
-
getEntity: (key: Hex) => Promise<
|
|
65
|
+
getEntity: (key: Hex) => Promise<FullEntity>
|
|
58
66
|
|
|
59
67
|
/**
|
|
60
68
|
* Returns a SelectQueryBuilder for building and executing queries — the recommended way to
|
|
@@ -70,12 +78,13 @@ export type PublicArkivActions<
|
|
|
70
78
|
* @returns A SelectQueryBuilder instance for building and executing queries. {@link SelectQueryBuilder}
|
|
71
79
|
*
|
|
72
80
|
* @example
|
|
73
|
-
* import { createPublicClient
|
|
74
|
-
* import {
|
|
75
|
-
* import { eq } from
|
|
81
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
82
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
83
|
+
* import { eq } from "@arkiv-network/sdk/query"
|
|
84
|
+
* import { http } from "viem"
|
|
76
85
|
*
|
|
77
86
|
* const client = createPublicClient({
|
|
78
|
-
* chain:
|
|
87
|
+
* chain: cheesecake,
|
|
79
88
|
* transport: http(),
|
|
80
89
|
* })
|
|
81
90
|
* // select everything
|
|
@@ -83,7 +92,7 @@ export type PublicArkivActions<
|
|
|
83
92
|
* await client.select("*").where(eq("category", "docs")).fetch()
|
|
84
93
|
* // only the key
|
|
85
94
|
* await client.select({ key: true }).where(eq("category", "docs")).fetch()
|
|
86
|
-
* // select specific fields — result typed { owner: Hex; attributes:
|
|
95
|
+
* // select specific fields — result typed { owner: Hex; attributes: Attributes }
|
|
87
96
|
* await client.select({ owner: true, attributes: true }).fetch()
|
|
88
97
|
* // a single field — result typed { owner: Hex }
|
|
89
98
|
* await client.select({ owner: true }).fetch()
|
|
@@ -95,9 +104,11 @@ export type PublicArkivActions<
|
|
|
95
104
|
* Pick the entity fields to return. Set the ones you want to `true` (at least one is required);
|
|
96
105
|
* the result is typed to exactly those fields, so reading anything else is a compile error.
|
|
97
106
|
*
|
|
98
|
-
* Available fields: `key`, `owner`, `creator`, `
|
|
99
|
-
* `
|
|
100
|
-
*
|
|
107
|
+
* Available fields: `key`, `owner`, `creator`, `createdAt`, `updatedAt`, `expiresAt`,
|
|
108
|
+
* `creationFlags`, `contentType`, `payload`, `attributeSchema` and `attributes`.
|
|
109
|
+
*
|
|
110
|
+
* `attributes` also takes a map of names, to fetch only those:
|
|
111
|
+
* `select({ key: true, attributes: { projectId: true } })`.
|
|
101
112
|
*
|
|
102
113
|
* Pass the selection inline so its fields stay literal `true`. A selection stored in a `let`/
|
|
103
114
|
* `const` variable widens to `boolean` and the result type can no longer be narrowed — annotate
|
|
@@ -105,7 +116,8 @@ export type PublicArkivActions<
|
|
|
105
116
|
*
|
|
106
117
|
* @example
|
|
107
118
|
* client.select({ owner: true, attributes: true }) // entities typed { owner, attributes }
|
|
108
|
-
* client.select({ key: true, payload: true })
|
|
119
|
+
* client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too
|
|
120
|
+
* client.select({ key: true, attributeSchema: true }) // what shape is the data?
|
|
109
121
|
*/
|
|
110
122
|
<const S extends EntitySelection>(selection: S): SelectQueryBuilder<ProjectedEntity<S>>
|
|
111
123
|
/**
|
|
@@ -116,90 +128,133 @@ export type PublicArkivActions<
|
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
/**
|
|
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
|
|
131
|
+
* Runs one query and returns one page, with no builder in between.
|
|
123
132
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
133
|
+
* Use {@link select} for anything typed — this returns full {@link Entity} objects whatever the
|
|
134
|
+
* selection, and takes a raw string as an escape hatch for a query built elsewhere. A raw string
|
|
135
|
+
* goes to the node exactly as written, with none of the name, type or operator checks the
|
|
136
|
+
* expression combinators apply.
|
|
128
137
|
*
|
|
129
|
-
* @
|
|
138
|
+
* @param query - An {@link Expression}, or the raw query string.
|
|
139
|
+
* @param queryOptions - Selection, page size, cursor and block. {@link QueryOptions}
|
|
140
|
+
* @returns One page of entities. {@link QueryReturnType}
|
|
130
141
|
*
|
|
131
142
|
* @example
|
|
132
|
-
* import { createPublicClient
|
|
133
|
-
* import {
|
|
143
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
144
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
145
|
+
* import { and, eq, gte } from "@arkiv-network/sdk/query"
|
|
146
|
+
* import { i32 } from "@arkiv-network/sdk/attr"
|
|
147
|
+
* import { http } from "viem"
|
|
134
148
|
*
|
|
135
149
|
* const client = createPublicClient({
|
|
136
|
-
* chain:
|
|
150
|
+
* chain: cheesecake,
|
|
137
151
|
* transport: http(),
|
|
138
152
|
* })
|
|
139
|
-
* const
|
|
140
|
-
*
|
|
153
|
+
* const page = await client.query(and(eq("category", "docs"), gte("level", i32(10))), {
|
|
154
|
+
* select: { key: true, attributes: true },
|
|
155
|
+
* limit: 100,
|
|
156
|
+
* })
|
|
157
|
+
* // { entities: [Entity], cursor: "b64:…", blockNumber: 32223n }
|
|
141
158
|
*
|
|
159
|
+
* // The raw form, unchecked:
|
|
160
|
+
* await client.query("category = str('docs') AND level >= i32(10)")
|
|
142
161
|
*/
|
|
143
|
-
|
|
162
|
+
query: (query: Expression | string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
|
|
144
163
|
|
|
145
164
|
/**
|
|
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}
|
|
165
|
+
* Returns the total number of entities on the chain.
|
|
166
|
+
* @returns The number of entities currently stored
|
|
151
167
|
*
|
|
152
168
|
* @example
|
|
153
|
-
* import { createPublicClient
|
|
154
|
-
* import {
|
|
169
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
170
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
171
|
+
* import { http } from "viem"
|
|
155
172
|
*
|
|
156
173
|
* const client = createPublicClient({
|
|
157
|
-
* chain:
|
|
174
|
+
* chain: cheesecake,
|
|
158
175
|
* transport: http(),
|
|
159
176
|
* })
|
|
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 }
|
|
177
|
+
* const entityCount = await client.getEntityCount()
|
|
178
|
+
* // entityCount = 0
|
|
173
179
|
*/
|
|
174
|
-
|
|
180
|
+
getEntityCount: () => Promise<number>
|
|
175
181
|
|
|
176
182
|
/**
|
|
177
|
-
* Returns
|
|
178
|
-
*
|
|
183
|
+
* Returns how many entities an account has created — its entity-minting nonce.
|
|
184
|
+
*
|
|
185
|
+
* Not the account's transaction nonce: the engine keeps its own counter per creator and mixes it
|
|
186
|
+
* into every key it mints, which is why two identical creates from one account never collide.
|
|
187
|
+
*
|
|
188
|
+
* @param owner - The account whose nonce to read.
|
|
189
|
+
* @returns The nonce the account's next create will use.
|
|
179
190
|
*
|
|
180
191
|
* @example
|
|
181
|
-
* import { createPublicClient
|
|
182
|
-
* import {
|
|
192
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
193
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
194
|
+
* import { http } from "viem"
|
|
183
195
|
*
|
|
184
196
|
* const client = createPublicClient({
|
|
185
|
-
* chain:
|
|
197
|
+
* chain: cheesecake,
|
|
186
198
|
* transport: http(),
|
|
187
199
|
* })
|
|
188
|
-
* const
|
|
189
|
-
* //
|
|
200
|
+
* const nonce = await client.getEntityNonce("0xabc…")
|
|
201
|
+
* // 7n — the next entity this account creates is its eighth
|
|
190
202
|
*/
|
|
191
|
-
|
|
203
|
+
getEntityNonce: (owner: Address) => Promise<bigint>
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Works out the keys an account's next creates will be given, before sending them.
|
|
207
|
+
*
|
|
208
|
+
* The engine derives a key from the chain, the registry, the owner, the owner's nonce and a
|
|
209
|
+
* salt — everything but the nonce is known to the caller, and the nonce is read here. This is
|
|
210
|
+
* what lets a batch reference an entity it is about to mint.
|
|
211
|
+
*
|
|
212
|
+
* Each key arrives paired with the salt that mints it, because a create defaults to a *random*
|
|
213
|
+
* salt: a predicted key only holds if the create carries the salt it was predicted with. And the
|
|
214
|
+
* prediction holds only while nothing else from this owner is in flight — for a key you can rely
|
|
215
|
+
* on unconditionally, read it back from the create instead.
|
|
216
|
+
*
|
|
217
|
+
* A literal `count` comes back as a fixed-length tuple, so the pairs destructure into names.
|
|
218
|
+
*
|
|
219
|
+
* @param parameters - Owner, and either a count or the salts. {@link PredictEntityKeysParameters}
|
|
220
|
+
* @returns One `{ key, salt }` pair per create, in batch order.
|
|
221
|
+
* {@link PredictEntityKeysReturnType}
|
|
222
|
+
*
|
|
223
|
+
* @example A batch whose second entity points at its first.
|
|
224
|
+
* import { key } from "@arkiv-network/sdk/attr"
|
|
225
|
+
*
|
|
226
|
+
* const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
|
|
227
|
+
* await wallet.mutateEntities({
|
|
228
|
+
* creates: [
|
|
229
|
+
* { payload, contentType, expires, salt: parent.salt },
|
|
230
|
+
* {
|
|
231
|
+
* payload,
|
|
232
|
+
* contentType,
|
|
233
|
+
* expires,
|
|
234
|
+
* salt: child.salt,
|
|
235
|
+
* attributes: { parent: key(parent.key) },
|
|
236
|
+
* },
|
|
237
|
+
* ],
|
|
238
|
+
* })
|
|
239
|
+
*/
|
|
240
|
+
predictEntityKeys: <
|
|
241
|
+
const TCount extends number = number,
|
|
242
|
+
const TSalts extends readonly bigint[] | undefined = undefined,
|
|
243
|
+
>(
|
|
244
|
+
parameters: PredictEntityKeysParameters<TCount, TSalts>,
|
|
245
|
+
) => Promise<PredictEntityKeysReturnType<TCount, TSalts>>
|
|
192
246
|
|
|
193
247
|
/**
|
|
194
248
|
* Returns the current block timing.
|
|
195
249
|
* @returns The current block timing. {@link GetBlockTimingReturnType}
|
|
196
250
|
*
|
|
197
251
|
* @example
|
|
198
|
-
* import { createPublicClient
|
|
199
|
-
* import {
|
|
252
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
253
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
254
|
+
* import { http } from "viem"
|
|
200
255
|
*
|
|
201
256
|
* const client = createPublicClient({
|
|
202
|
-
* chain:
|
|
257
|
+
* chain: cheesecake,
|
|
203
258
|
* transport: http(),
|
|
204
259
|
* })
|
|
205
260
|
* const blockTiming = await client.getBlockTiming()
|
|
@@ -216,43 +271,32 @@ export type PublicArkivActions<
|
|
|
216
271
|
}>
|
|
217
272
|
|
|
218
273
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
274
|
+
* Watches entity events, calling the handlers you pass as they arrive.
|
|
275
|
+
*
|
|
276
|
+
* All five are decoded from logs — `onEntityCreated`, `onEntityPatched`, `onExpiryExtended`,
|
|
277
|
+
* `onOwnershipTransferred`, `onEntityDeleted` — and each carries the block, transaction and log
|
|
278
|
+
* index it came from, which is the order the operations were applied in. `onEvent` receives all
|
|
279
|
+
* of them, whatever their type.
|
|
280
|
+
*
|
|
281
|
+
* @param parameters - Handlers and options, all optional. {@link WatchEntityEventsParameters}
|
|
282
|
+
* @returns A function that stops the watcher.
|
|
224
283
|
*
|
|
225
284
|
* @example
|
|
226
|
-
* import { createPublicClient
|
|
227
|
-
* import {
|
|
285
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
286
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
287
|
+
* import { http } from "viem"
|
|
228
288
|
*
|
|
229
289
|
* const client = createPublicClient({
|
|
230
|
-
* chain:
|
|
290
|
+
* chain: cheesecake,
|
|
231
291
|
* transport: http(),
|
|
232
292
|
* })
|
|
233
|
-
* const
|
|
234
|
-
*
|
|
293
|
+
* const unwatch = client.watchEntityEvents({
|
|
294
|
+
* onEntityCreated: ({ entityKey, expiresAt }) => console.log(entityKey, "until", expiresAt),
|
|
295
|
+
* onError: (error) => console.error("watchEntityEvents error", error),
|
|
235
296
|
* })
|
|
236
|
-
*
|
|
297
|
+
* unwatch() // stop watching
|
|
237
298
|
*/
|
|
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>
|
|
299
|
+
watchEntityEvents: (parameters: WatchEntityEventsParameters) => () => void
|
|
256
300
|
}
|
|
257
301
|
|
|
258
302
|
export function publicArkivActions<
|
|
@@ -262,42 +306,19 @@ export function publicArkivActions<
|
|
|
262
306
|
>(client: Client<transport, chain, account>) {
|
|
263
307
|
return {
|
|
264
308
|
getEntity: (key: Hex) => getEntity(client, key),
|
|
265
|
-
query: (rawQuery: string, queryOptions?: QueryOptions) =>
|
|
266
|
-
|
|
309
|
+
query: (rawQuery: Expression | string, queryOptions?: QueryOptions) =>
|
|
310
|
+
query(client, rawQuery, queryOptions),
|
|
267
311
|
select: (selection?: SelectArg) => new SelectQueryBuilder(client, selection),
|
|
268
312
|
getBlockTiming: () => getBlockTiming(client),
|
|
269
313
|
getEntityCount: () => getEntityCount(client),
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
),
|
|
314
|
+
getEntityNonce: (owner: Address) => getEntityNonce(client, owner),
|
|
315
|
+
predictEntityKeys: <
|
|
316
|
+
const TCount extends number = number,
|
|
317
|
+
const TSalts extends readonly bigint[] | undefined = undefined,
|
|
318
|
+
>(
|
|
319
|
+
parameters: PredictEntityKeysParameters<TCount, TSalts>,
|
|
320
|
+
) => predictEntityKeys(client, parameters),
|
|
321
|
+
watchEntityEvents: (parameters: WatchEntityEventsParameters) =>
|
|
322
|
+
watchEntityEvents(client, parameters),
|
|
302
323
|
}
|
|
303
324
|
}
|