@arkiv-network/sdk 0.1.1-dev.0 → 0.1.3-dev.0
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 +22 -10
- package/dist/chains/index.d.ts +25 -25
- package/dist/chains/index.d.ts.map +1 -1
- package/dist/index.cjs +30 -9
- package/dist/index.js +30 -16
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +22 -8
- package/src/accounts/index.ts +1 -0
- package/src/actions/public/buildQuery.ts +6 -0
- package/src/actions/public/getBlockTiming.ts +20 -0
- package/src/actions/public/getEntity.ts +18 -0
- package/src/actions/public/getEntityCount.ts +10 -0
- package/src/actions/public/query.ts +13 -0
- package/src/actions/public/subscribeEntityEvents.ts +105 -0
- package/src/actions/wallet/changeOwnership.ts +40 -0
- package/src/actions/wallet/createEntity.ts +45 -0
- package/src/actions/wallet/deleteEntity.ts +39 -0
- package/src/actions/wallet/extendEntity.ts +41 -0
- package/src/actions/wallet/mutateEntities.ts +100 -0
- package/src/actions/wallet/updateEntity.ts +47 -0
- package/src/chains/index.ts +3 -0
- package/src/chains/kaolin.ts +26 -0
- package/src/chains/localhost.ts +14 -0
- package/src/chains/marketplace.ts +26 -0
- package/src/clients/baseClient.ts +9 -0
- package/src/clients/createPublicClient.test.ts +22 -0
- package/src/clients/createPublicClient.ts +65 -0
- package/src/clients/createWalletClient.test.ts +23 -0
- package/src/clients/createWalletClient.ts +70 -0
- package/src/clients/decorators/arkivPublic.ts +203 -0
- package/src/clients/decorators/arkivWallet.ts +250 -0
- package/src/consts.ts +2 -0
- package/src/index.ts +21 -0
- package/src/query/engine.test.ts +288 -0
- package/src/query/engine.ts +112 -0
- package/src/query/errors.ts +23 -0
- package/src/query/index.ts +4 -0
- package/src/query/predicate.test.ts +418 -0
- package/src/query/predicate.ts +140 -0
- package/src/query/queryBuilder.test.ts +537 -0
- package/src/query/queryBuilder.ts +209 -0
- package/src/query/queryResult.test.ts +270 -0
- package/src/query/queryResult.ts +61 -0
- package/src/types/attributes.ts +4 -0
- package/src/types/entity.ts +36 -0
- package/src/types/events.ts +34 -0
- package/src/types/index.ts +4 -0
- package/src/types/mimeTypes.ts +27 -0
- package/src/types/rpcSchema.ts +61 -0
- package/src/types/txParams.ts +15 -0
- package/src/utils/arkivTransactions.ts +100 -0
- package/src/utils/compression.test.ts +32 -0
- package/src/utils/compression.ts +99 -0
- package/src/utils/entities.ts +23 -0
- package/src/utils/expirationTime.ts +13 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/payload.ts +9 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Address,
|
|
4
|
+
Chain,
|
|
5
|
+
Client,
|
|
6
|
+
ParseAccount,
|
|
7
|
+
Prettify,
|
|
8
|
+
PublicClientConfig,
|
|
9
|
+
RpcSchema,
|
|
10
|
+
Transport,
|
|
11
|
+
} from "viem"
|
|
12
|
+
import { createClient, publicActions } from "viem"
|
|
13
|
+
import type { ArkivRpcSchema } from "../types/rpcSchema"
|
|
14
|
+
import { type PublicArkivActions, publicArkivActions } from "./decorators/arkivPublic"
|
|
15
|
+
|
|
16
|
+
export type PublicArkivClient<
|
|
17
|
+
transport extends Transport = Transport,
|
|
18
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
19
|
+
accountOrAddress extends Account | undefined = undefined,
|
|
20
|
+
rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,
|
|
21
|
+
> = Prettify<
|
|
22
|
+
Client<transport, chain, accountOrAddress, rpcSchema, PublicArkivActions<transport, chain>>
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
|
27
|
+
*
|
|
28
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/clients/public
|
|
29
|
+
*
|
|
30
|
+
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.golemdb.io/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.golemdb.io/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
|
|
31
|
+
*
|
|
32
|
+
* @param config - {@link PublicClientConfig}
|
|
33
|
+
* @returns A Arkiv Public Client. {@link PublicArkivClient}
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
37
|
+
* import { kaolin } from 'arkiv/chains'
|
|
38
|
+
*
|
|
39
|
+
* const client = createPublicClient({
|
|
40
|
+
* chain: kaolin,
|
|
41
|
+
* transport: http(),
|
|
42
|
+
* })
|
|
43
|
+
*/
|
|
44
|
+
export function createPublicClient<
|
|
45
|
+
transport extends Transport,
|
|
46
|
+
chain extends Chain | undefined = undefined,
|
|
47
|
+
accountOrAddress extends Account | Address | undefined = undefined,
|
|
48
|
+
rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,
|
|
49
|
+
>(
|
|
50
|
+
parameters: PublicClientConfig<transport, chain, accountOrAddress, rpcSchema>,
|
|
51
|
+
): PublicArkivClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema> {
|
|
52
|
+
const { key = "public", name = "Public Client" } = parameters
|
|
53
|
+
const client = createClient({
|
|
54
|
+
...parameters,
|
|
55
|
+
key,
|
|
56
|
+
name,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return client.extend(publicArkivActions).extend(publicActions) as unknown as PublicArkivClient<
|
|
60
|
+
transport,
|
|
61
|
+
chain,
|
|
62
|
+
ParseAccount<accountOrAddress>,
|
|
63
|
+
rpcSchema
|
|
64
|
+
>
|
|
65
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expect, test, vi } from "bun:test"
|
|
2
|
+
import { createTransport, type EIP1193RequestFn } from "viem"
|
|
3
|
+
import { createWalletClient } from "./createWalletClient"
|
|
4
|
+
|
|
5
|
+
const mockTransport = () =>
|
|
6
|
+
createTransport({
|
|
7
|
+
key: "mock",
|
|
8
|
+
name: "Mock Transport",
|
|
9
|
+
request: vi.fn(() => null) as unknown as EIP1193RequestFn,
|
|
10
|
+
type: "mock",
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test("creates", () => {
|
|
14
|
+
const { uid, ...client } = createWalletClient({
|
|
15
|
+
transport: mockTransport,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
expect(uid).toBeDefined()
|
|
19
|
+
expect(client.getEntity).toBeDefined()
|
|
20
|
+
expect(typeof client.getEntity).toBe("function")
|
|
21
|
+
expect(client.createEntity).toBeDefined()
|
|
22
|
+
expect(typeof client.createEntity).toBe("function")
|
|
23
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Address,
|
|
4
|
+
Chain,
|
|
5
|
+
Client,
|
|
6
|
+
ParseAccount,
|
|
7
|
+
Prettify,
|
|
8
|
+
RpcSchema,
|
|
9
|
+
Transport,
|
|
10
|
+
WalletClientConfig,
|
|
11
|
+
} from "viem"
|
|
12
|
+
import { createClient, publicActions, walletActions } from "viem"
|
|
13
|
+
import type { ArkivRpcSchema } from "../types/rpcSchema"
|
|
14
|
+
import { publicArkivActions } from "./decorators/arkivPublic"
|
|
15
|
+
import { type WalletArkivActions, walletArkivActions } from "./decorators/arkivWallet"
|
|
16
|
+
|
|
17
|
+
export type WalletArkivClient<
|
|
18
|
+
transport extends Transport = Transport,
|
|
19
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
20
|
+
account extends Account | undefined = Account | undefined,
|
|
21
|
+
rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,
|
|
22
|
+
> = Prettify<
|
|
23
|
+
Client<transport, chain, account, rpcSchema, WalletArkivActions<transport, chain, account>>
|
|
24
|
+
>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
|
28
|
+
*
|
|
29
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/clients/public
|
|
30
|
+
*
|
|
31
|
+
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.golemdb.io/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.golemdb.io/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
|
|
32
|
+
*
|
|
33
|
+
* @param config - {@link PublicClientConfig}
|
|
34
|
+
* @returns A Arkiv Public Client. {@link PublicArkivClient}
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
38
|
+
* import { kaolin } from 'arkiv/chains'
|
|
39
|
+
*
|
|
40
|
+
* const client = createPublicClient({
|
|
41
|
+
* chain: kaolin,
|
|
42
|
+
* transport: http(),
|
|
43
|
+
* })
|
|
44
|
+
*/
|
|
45
|
+
export function createWalletClient<
|
|
46
|
+
transport extends Transport,
|
|
47
|
+
chain extends Chain | undefined = undefined,
|
|
48
|
+
accountOrAddress extends Account | Address | undefined = undefined,
|
|
49
|
+
rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,
|
|
50
|
+
>(
|
|
51
|
+
parameters: WalletClientConfig<transport, chain, accountOrAddress, rpcSchema>,
|
|
52
|
+
): WalletArkivClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema> {
|
|
53
|
+
const { key = "wallet", name = "Wallet Client" } = parameters
|
|
54
|
+
const client = createClient({
|
|
55
|
+
...parameters,
|
|
56
|
+
key,
|
|
57
|
+
name,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
return client
|
|
61
|
+
.extend(walletActions)
|
|
62
|
+
.extend(publicActions)
|
|
63
|
+
.extend(walletArkivActions)
|
|
64
|
+
.extend(publicArkivActions) as unknown as WalletArkivClient<
|
|
65
|
+
transport,
|
|
66
|
+
chain,
|
|
67
|
+
ParseAccount<accountOrAddress>,
|
|
68
|
+
rpcSchema
|
|
69
|
+
>
|
|
70
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Hex, PublicActions, Transport } from "viem"
|
|
2
|
+
import { getBlockTiming } from "../../actions/public/getBlockTiming"
|
|
3
|
+
import { getEntity } from "../../actions/public/getEntity"
|
|
4
|
+
import { getEntityCount } from "../../actions/public/getEntityCount"
|
|
5
|
+
import { query } from "../../actions/public/query"
|
|
6
|
+
import { subscribeEntityEvents } from "../../actions/public/subscribeEntityEvents"
|
|
7
|
+
import { QueryBuilder } from "../../query/queryBuilder"
|
|
8
|
+
import type { Entity } from "../../types/entity"
|
|
9
|
+
import type {
|
|
10
|
+
OnEntityCreatedEvent,
|
|
11
|
+
OnEntityDeletedEvent,
|
|
12
|
+
OnEntityExpiredEvent,
|
|
13
|
+
OnEntityExpiresInExtendedEvent,
|
|
14
|
+
OnEntityUpdatedEvent,
|
|
15
|
+
} from "../../types/events"
|
|
16
|
+
|
|
17
|
+
export type PublicArkivActions<
|
|
18
|
+
transport extends Transport = Transport,
|
|
19
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
20
|
+
account extends Account | undefined = Account | undefined,
|
|
21
|
+
> = Pick<
|
|
22
|
+
PublicActions<transport, chain, account>,
|
|
23
|
+
| "getBalance"
|
|
24
|
+
| "getBlock"
|
|
25
|
+
| "getBlockNumber"
|
|
26
|
+
| "getChainId"
|
|
27
|
+
| "getLogs"
|
|
28
|
+
| "getTransaction"
|
|
29
|
+
| "getTransactionCount"
|
|
30
|
+
| "getTransactionReceipt"
|
|
31
|
+
| "waitForTransactionReceipt"
|
|
32
|
+
| "watchEvent"
|
|
33
|
+
> & {
|
|
34
|
+
/**
|
|
35
|
+
* Returns the entity with the given key.
|
|
36
|
+
*
|
|
37
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/public/getEntity
|
|
38
|
+
*
|
|
39
|
+
* @param args - {entityKey}
|
|
40
|
+
* @returns The entity with the given key. {@link Entity}
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
44
|
+
* import { kaolin } from 'arkiv/chains'
|
|
45
|
+
*
|
|
46
|
+
* const client = createPublicClient({
|
|
47
|
+
* chain: kaolin,
|
|
48
|
+
* transport: http(),
|
|
49
|
+
* })
|
|
50
|
+
* const entity = await client.getEntity("0x123")
|
|
51
|
+
* // {
|
|
52
|
+
* // key: "0x123",
|
|
53
|
+
* // value: "0x123",
|
|
54
|
+
* // }
|
|
55
|
+
*/
|
|
56
|
+
getEntity: (key: Hex) => Promise<Entity>
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns a QueryBuilder instance for building and executing queries.
|
|
60
|
+
* The QueryBuilder object follows the Builder pattern, allowing you to chain methods to build a query and then execute it.
|
|
61
|
+
*
|
|
62
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/public/query
|
|
63
|
+
*
|
|
64
|
+
* @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
68
|
+
* import { kaolin } from 'arkiv/chains'
|
|
69
|
+
*
|
|
70
|
+
* const client = createPublicClient({
|
|
71
|
+
* chain: kaolin,
|
|
72
|
+
* transport: http(),
|
|
73
|
+
* })
|
|
74
|
+
* const query = client.buildQuery()
|
|
75
|
+
* const entities = await query.where("key", "=", "value").ownedBy("0x123").fetch()
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
buildQuery: () => QueryBuilder
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns a QueryResult instance for fetching the results of a raw query.
|
|
82
|
+
* @returns A QueryResult instance for fetching the results of a raw query. {@link QueryResult}
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
86
|
+
* import { kaolin } from 'arkiv/chains'
|
|
87
|
+
*
|
|
88
|
+
* const client = createPublicClient({
|
|
89
|
+
* chain: kaolin,
|
|
90
|
+
* transport: http(),
|
|
91
|
+
* })
|
|
92
|
+
* const queryResult = client.query('key = value && $owner = 0x123')
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
query: (query: string) => Promise<Entity[]>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Returns the number of entities in the DBChain.
|
|
99
|
+
* @returns The number of entities in the DBChain. {@link number}
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
103
|
+
* import { kaolin } from 'arkiv/chains'
|
|
104
|
+
*
|
|
105
|
+
* const client = createPublicClient({
|
|
106
|
+
* chain: kaolin,
|
|
107
|
+
* transport: http(),
|
|
108
|
+
* })
|
|
109
|
+
* const entityCount = await client.getEntityCount()
|
|
110
|
+
* // entityCount = 0
|
|
111
|
+
*/
|
|
112
|
+
getEntityCount: () => Promise<number>
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns the current block timing.
|
|
116
|
+
* @returns The current block timing. {@link GetBlockTimingReturnType}
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
120
|
+
* import { kaolin } from 'arkiv/chains'
|
|
121
|
+
*
|
|
122
|
+
* const client = createPublicClient({
|
|
123
|
+
* chain: kaolin,
|
|
124
|
+
* transport: http(),
|
|
125
|
+
* })
|
|
126
|
+
* const blockTiming = await client.getBlockTiming()
|
|
127
|
+
* // {
|
|
128
|
+
* // currentBlock: 10n, // block number
|
|
129
|
+
* // currentBlockTime: 1234567890, // block timestamp
|
|
130
|
+
* // blockDuration: 2, // in seconds
|
|
131
|
+
* // }
|
|
132
|
+
*/
|
|
133
|
+
getBlockTiming: () => Promise<{
|
|
134
|
+
currentBlock: bigint
|
|
135
|
+
currentBlockTime: number
|
|
136
|
+
blockDuration: number
|
|
137
|
+
}>
|
|
138
|
+
|
|
139
|
+
subscribeEntityEvents: (
|
|
140
|
+
{
|
|
141
|
+
onError,
|
|
142
|
+
onEntityCreated,
|
|
143
|
+
onEntityUpdated,
|
|
144
|
+
onEntityDeleted,
|
|
145
|
+
onEntityExpiresInExtended,
|
|
146
|
+
}: {
|
|
147
|
+
onError?: (error: Error) => void
|
|
148
|
+
onEntityCreated?: (event: OnEntityCreatedEvent) => void
|
|
149
|
+
onEntityUpdated?: (event: OnEntityUpdatedEvent) => void
|
|
150
|
+
onEntityDeleted?: (event: OnEntityDeletedEvent) => void
|
|
151
|
+
onEntityExpired?: (event: OnEntityExpiredEvent) => void
|
|
152
|
+
onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void
|
|
153
|
+
},
|
|
154
|
+
pollingInterval?: number,
|
|
155
|
+
fromBlock?: bigint,
|
|
156
|
+
) => Promise<() => void>
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function publicArkivActions<
|
|
160
|
+
transport extends Transport = Transport,
|
|
161
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
162
|
+
account extends Account | undefined = Account | undefined,
|
|
163
|
+
>(client: Client<transport, chain, account>) {
|
|
164
|
+
return {
|
|
165
|
+
getEntity: (key: Hex) => getEntity(client, key),
|
|
166
|
+
query: (rawQuery: string) => query(client, rawQuery),
|
|
167
|
+
buildQuery: () => new QueryBuilder(client),
|
|
168
|
+
getBlockTiming: () => getBlockTiming(client),
|
|
169
|
+
getEntityCount: () => getEntityCount(client),
|
|
170
|
+
subscribeEntityEvents: (
|
|
171
|
+
{
|
|
172
|
+
onError,
|
|
173
|
+
onEntityCreated,
|
|
174
|
+
onEntityUpdated,
|
|
175
|
+
onEntityDeleted,
|
|
176
|
+
onEntityExpired,
|
|
177
|
+
onEntityExpiresInExtended,
|
|
178
|
+
}: {
|
|
179
|
+
onError?: (error: Error) => void
|
|
180
|
+
onEntityCreated?: (event: OnEntityCreatedEvent) => void
|
|
181
|
+
onEntityUpdated?: (event: OnEntityUpdatedEvent) => void
|
|
182
|
+
onEntityDeleted?: (event: OnEntityDeletedEvent) => void
|
|
183
|
+
onEntityExpired?: (event: OnEntityExpiredEvent) => void
|
|
184
|
+
onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void
|
|
185
|
+
},
|
|
186
|
+
pollingInterval?: number,
|
|
187
|
+
fromBlock?: bigint,
|
|
188
|
+
) =>
|
|
189
|
+
subscribeEntityEvents(
|
|
190
|
+
client,
|
|
191
|
+
{
|
|
192
|
+
onError,
|
|
193
|
+
onEntityCreated,
|
|
194
|
+
onEntityUpdated,
|
|
195
|
+
onEntityDeleted,
|
|
196
|
+
onEntityExpired,
|
|
197
|
+
onEntityExpiresInExtended,
|
|
198
|
+
},
|
|
199
|
+
pollingInterval,
|
|
200
|
+
fromBlock,
|
|
201
|
+
),
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport, WalletActions } from "viem"
|
|
2
|
+
import type {
|
|
3
|
+
ChangeOwnershipParameters,
|
|
4
|
+
ChangeOwnershipReturnType,
|
|
5
|
+
} from "../../actions/wallet/changeOwnership"
|
|
6
|
+
import { changeOwnership } from "../../actions/wallet/changeOwnership"
|
|
7
|
+
import {
|
|
8
|
+
type CreateEntityParameters,
|
|
9
|
+
type CreateEntityReturnType,
|
|
10
|
+
createEntity,
|
|
11
|
+
} from "../../actions/wallet/createEntity"
|
|
12
|
+
import type {
|
|
13
|
+
DeleteEntityParameters,
|
|
14
|
+
DeleteEntityReturnType,
|
|
15
|
+
} from "../../actions/wallet/deleteEntity"
|
|
16
|
+
import { deleteEntity } from "../../actions/wallet/deleteEntity"
|
|
17
|
+
import type {
|
|
18
|
+
ExtendEntityParameters,
|
|
19
|
+
ExtendEntityReturnType,
|
|
20
|
+
} from "../../actions/wallet/extendEntity"
|
|
21
|
+
import { extendEntity } from "../../actions/wallet/extendEntity"
|
|
22
|
+
import type {
|
|
23
|
+
MutateEntitiesParameters,
|
|
24
|
+
MutateEntitiesReturnType,
|
|
25
|
+
} from "../../actions/wallet/mutateEntities"
|
|
26
|
+
import { mutateEntities } from "../../actions/wallet/mutateEntities"
|
|
27
|
+
import type {
|
|
28
|
+
UpdateEntityParameters,
|
|
29
|
+
UpdateEntityReturnType,
|
|
30
|
+
} from "../../actions/wallet/updateEntity"
|
|
31
|
+
import { updateEntity } from "../../actions/wallet/updateEntity"
|
|
32
|
+
import type { Entity, TxParams } from "../../types"
|
|
33
|
+
import type { PublicArkivActions } from "./arkivPublic"
|
|
34
|
+
|
|
35
|
+
export type WalletArkivActions<
|
|
36
|
+
transport extends Transport = Transport,
|
|
37
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
38
|
+
account extends Account | undefined = Account | undefined,
|
|
39
|
+
> = PublicArkivActions<transport, chain, account> &
|
|
40
|
+
Pick<
|
|
41
|
+
WalletActions<chain, account>,
|
|
42
|
+
| "sendTransaction"
|
|
43
|
+
| "sendTransactionSync"
|
|
44
|
+
| "sendRawTransaction"
|
|
45
|
+
| "sendRawTransactionSync"
|
|
46
|
+
| "signMessage"
|
|
47
|
+
| "signTransaction"
|
|
48
|
+
> & {
|
|
49
|
+
/**
|
|
50
|
+
* Returns the entity with the given key.
|
|
51
|
+
*
|
|
52
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/public/getEntity
|
|
53
|
+
*
|
|
54
|
+
* @param args - {entityKey}
|
|
55
|
+
* @returns The entity with the given key. {@link Entity}
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* import { createPublicClient, http } from 'arkiv'
|
|
59
|
+
* import { kaolin } from 'arkiv/chains'
|
|
60
|
+
*
|
|
61
|
+
* const client = createPublicClient({
|
|
62
|
+
* chain: kaolin,
|
|
63
|
+
* transport: http(),
|
|
64
|
+
* })
|
|
65
|
+
* const { entityKey, txHash } = await client.createEntity({
|
|
66
|
+
* payload: toBytes(JSON.stringify({ entity: { entityType: "testType", entityId: "testId" } })),
|
|
67
|
+
* attributes: [{ key: "testKey", value: "testValue" }],
|
|
68
|
+
* expiresIn: 1000,
|
|
69
|
+
* })
|
|
70
|
+
* console.log("entityKey", entityKey)
|
|
71
|
+
* console.log("txHash", txHash)
|
|
72
|
+
* // {
|
|
73
|
+
* // entityKey: "0x123",
|
|
74
|
+
* // txHash: "0x123",
|
|
75
|
+
* // }
|
|
76
|
+
*/
|
|
77
|
+
createEntity: (
|
|
78
|
+
data: CreateEntityParameters,
|
|
79
|
+
txParams?: TxParams,
|
|
80
|
+
) => Promise<CreateEntityReturnType>
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Updates the entity with the given key.
|
|
84
|
+
*
|
|
85
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/updateEntity
|
|
86
|
+
* - JSON-RPC Methods: [`golembase_updateEntity`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_updateEntity)
|
|
87
|
+
*
|
|
88
|
+
* @param args - {entityKey, data}
|
|
89
|
+
* @returns The entity with the given key. {@link Entity}
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* import { createWalletClient, http } from 'arkiv'
|
|
93
|
+
* import { kaolin } from 'arkiv/chains'
|
|
94
|
+
*
|
|
95
|
+
* const client = createWalletClient({
|
|
96
|
+
* chain: kaolin,
|
|
97
|
+
* transport: http(),
|
|
98
|
+
* })
|
|
99
|
+
*/
|
|
100
|
+
updateEntity: (
|
|
101
|
+
data: UpdateEntityParameters,
|
|
102
|
+
txParams?: TxParams,
|
|
103
|
+
) => Promise<UpdateEntityReturnType>
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Deletes the entity with the given key.
|
|
107
|
+
*
|
|
108
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/deleteEntity
|
|
109
|
+
* - JSON-RPC Methods: [`golembase_deleteEntity`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_deleteEntity)
|
|
110
|
+
*
|
|
111
|
+
* @param args - {entityKey}
|
|
112
|
+
* @returns The entity with the given key. {@link Entity}
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* import { createWalletClient, http } from 'arkiv'
|
|
116
|
+
* import { kaolin } from 'arkiv/chains'
|
|
117
|
+
*
|
|
118
|
+
* const client = createWalletClient({
|
|
119
|
+
* chain: kaolin,
|
|
120
|
+
* transport: http(),
|
|
121
|
+
* })
|
|
122
|
+
* const { entityKey, txHash } = await client.deleteEntity({ entityKey: "0x123" })
|
|
123
|
+
* console.log("entityKey", entityKey)
|
|
124
|
+
* console.log("txHash", txHash)
|
|
125
|
+
* // {
|
|
126
|
+
* // entityKey: "0x123",
|
|
127
|
+
* // txHash: "0x123",
|
|
128
|
+
* // }
|
|
129
|
+
*/
|
|
130
|
+
deleteEntity: (
|
|
131
|
+
data: DeleteEntityParameters,
|
|
132
|
+
txParams?: TxParams,
|
|
133
|
+
) => Promise<DeleteEntityReturnType>
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Extends the entity with the given key.
|
|
137
|
+
*
|
|
138
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/extendEntity
|
|
139
|
+
* - JSON-RPC Methods: [`golembase_extendEntity`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_extendEntity)
|
|
140
|
+
*
|
|
141
|
+
* @param args - {entityKey, data}
|
|
142
|
+
* @returns The entity with the given key. {@link Entity}
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* import { createWalletClient, http } from 'arkiv'
|
|
146
|
+
* import { kaolin } from 'arkiv/chains'
|
|
147
|
+
*
|
|
148
|
+
* const client = createWalletClient({
|
|
149
|
+
* chain: kaolin,
|
|
150
|
+
* transport: http(),
|
|
151
|
+
* })
|
|
152
|
+
* const { entityKey, txHash } = await client.extendEntity("0x123", {
|
|
153
|
+
* expiresIn: 1000,
|
|
154
|
+
* })
|
|
155
|
+
* console.log("entityKey", entityKey)
|
|
156
|
+
* console.log("txHash", txHash)
|
|
157
|
+
* // {
|
|
158
|
+
* // entityKey: "0x123",
|
|
159
|
+
* // txHash: "0x123",
|
|
160
|
+
* // }
|
|
161
|
+
*/
|
|
162
|
+
extendEntity: (
|
|
163
|
+
data: ExtendEntityParameters,
|
|
164
|
+
txParams?: TxParams,
|
|
165
|
+
) => Promise<ExtendEntityReturnType>
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Changes the ownership of the entity with the given address.
|
|
169
|
+
*
|
|
170
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/changeOwnership
|
|
171
|
+
* - JSON-RPC Methods: [`golembase_ownershipChange`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_ownershipChange)
|
|
172
|
+
*
|
|
173
|
+
* @param args - {entityKey, newOwner}
|
|
174
|
+
* @returns The entity with the given address. {@link Entity}
|
|
175
|
+
*/
|
|
176
|
+
changeOwnership: (
|
|
177
|
+
data: ChangeOwnershipParameters,
|
|
178
|
+
txParams?: TxParams,
|
|
179
|
+
) => Promise<ChangeOwnershipReturnType>
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Mutates the entities with the given keys.
|
|
183
|
+
*
|
|
184
|
+
* - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/mutateEntities
|
|
185
|
+
* - JSON-RPC Methods: [`golembase_mutateEntities`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_mutateEntities)
|
|
186
|
+
*
|
|
187
|
+
* @param args - {data}
|
|
188
|
+
* @returns The entity with the given key. {@link Entity}
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* import { createWalletClient, http } from 'arkiv'
|
|
192
|
+
* import { kaolin } from 'arkiv/chains'
|
|
193
|
+
*
|
|
194
|
+
* const client = createWalletClient({
|
|
195
|
+
* chain: kaolin,
|
|
196
|
+
* transport: http(),
|
|
197
|
+
* })
|
|
198
|
+
* const { entityKey, txHash } = await client.mutateEntities({
|
|
199
|
+
* creates: [{
|
|
200
|
+
* payload: toBytes(JSON.stringify({ entity: { entityType: "testType", entityId: "testId" } })),
|
|
201
|
+
* attriubutes: [{ key: "testKey", value: "testValue" }],
|
|
202
|
+
* expiresIn: 1000,
|
|
203
|
+
* }],
|
|
204
|
+
* updates: [{
|
|
205
|
+
* entityKey: "0x123",
|
|
206
|
+
* payload: toBytes(JSON.stringify({ entity: { entityType: "testType", entityId: "testId" } })),
|
|
207
|
+
* attributes: [{ key: "testKey", value: "testValue" }],
|
|
208
|
+
* expiresIn: 1000,
|
|
209
|
+
* }],
|
|
210
|
+
* deletes: [{
|
|
211
|
+
* entityKey: "0x321",
|
|
212
|
+
* }],
|
|
213
|
+
* extensions: [{
|
|
214
|
+
* entityKey: "0x1234",
|
|
215
|
+
* expiresIn: 1000,
|
|
216
|
+
* }],
|
|
217
|
+
* })
|
|
218
|
+
* console.log("entityKey", entityKey)
|
|
219
|
+
* console.log("txHash", txHash)
|
|
220
|
+
* // {
|
|
221
|
+
* // entityKey: "0x123",
|
|
222
|
+
* // txHash: "0x123",
|
|
223
|
+
* // }
|
|
224
|
+
*/
|
|
225
|
+
mutateEntities: (
|
|
226
|
+
data: MutateEntitiesParameters,
|
|
227
|
+
txParams?: TxParams,
|
|
228
|
+
) => Promise<MutateEntitiesReturnType>
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function walletArkivActions<
|
|
232
|
+
transport extends Transport = Transport,
|
|
233
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
234
|
+
account extends Account | undefined = Account | undefined,
|
|
235
|
+
>(client: Client<transport, chain, account>) {
|
|
236
|
+
return {
|
|
237
|
+
createEntity: (data: CreateEntityParameters, txParams?: TxParams) =>
|
|
238
|
+
createEntity(client, data, txParams),
|
|
239
|
+
updateEntity: (data: UpdateEntityParameters, txParams?: TxParams) =>
|
|
240
|
+
updateEntity(client, data, txParams),
|
|
241
|
+
deleteEntity: (data: DeleteEntityParameters, txParams?: TxParams) =>
|
|
242
|
+
deleteEntity(client, data, txParams),
|
|
243
|
+
extendEntity: (data: ExtendEntityParameters, txParams?: TxParams) =>
|
|
244
|
+
extendEntity(client, data, txParams),
|
|
245
|
+
changeOwnership: (data: ChangeOwnershipParameters, txParams?: TxParams) =>
|
|
246
|
+
changeOwnership(client, data, txParams),
|
|
247
|
+
mutateEntities: (data: MutateEntitiesParameters, txParams?: TxParams) =>
|
|
248
|
+
mutateEntities(client, data, txParams),
|
|
249
|
+
}
|
|
250
|
+
}
|
package/src/consts.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Export all public APIs
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
Account,
|
|
5
|
+
Address,
|
|
6
|
+
Chain,
|
|
7
|
+
Hex,
|
|
8
|
+
PublicClientConfig,
|
|
9
|
+
RpcSchema,
|
|
10
|
+
Transport,
|
|
11
|
+
} from "viem"
|
|
12
|
+
// Re-export commonly used viem types for convenience
|
|
13
|
+
export { http, toBytes, toHex, toRlp, webSocket } from "viem"
|
|
14
|
+
export type { ArkivClient } from "./clients/baseClient"
|
|
15
|
+
export type { PublicArkivClient } from "./clients/createPublicClient"
|
|
16
|
+
export { createPublicClient } from "./clients/createPublicClient"
|
|
17
|
+
export type { WalletArkivClient } from "./clients/createWalletClient"
|
|
18
|
+
export { createWalletClient } from "./clients/createWalletClient"
|
|
19
|
+
export type { Attribute } from "./types/attributes"
|
|
20
|
+
export type { Entity } from "./types/entity"
|
|
21
|
+
export type { ArkivRpcSchema } from "./types/rpcSchema"
|