@arkiv-network/sdk 0.5.0-dev.3 → 0.5.0-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/chains/index.d.cts +33 -33
  2. package/dist/index.cjs +35 -15
  3. package/dist/index.d.cts +397 -3
  4. package/dist/index.d.cts.map +1 -0
  5. package/dist/index.d.ts +397 -3
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +33 -17
  8. package/dist/index.js.map +1 -1
  9. package/dist/{payload-D3fyOBWn.d.cts → payload-CJN8fTvX.d.cts} +1 -1
  10. package/dist/{payload-D3fyOBWn.d.cts.map → payload-CJN8fTvX.d.cts.map} +1 -1
  11. package/dist/{payload-BI2NXPDf.d.ts → payload-Da9gJMG5.d.ts} +1 -1
  12. package/dist/{payload-BI2NXPDf.d.ts.map → payload-Da9gJMG5.d.ts.map} +1 -1
  13. package/dist/query/index.cjs +1 -4
  14. package/dist/query/index.d.cts +3 -16
  15. package/dist/query/index.d.ts +3 -16
  16. package/dist/query/index.js +2 -2
  17. package/dist/query-C0dwQYxT.d.cts +320 -0
  18. package/dist/query-C0dwQYxT.d.cts.map +1 -0
  19. package/dist/query-DybEplzd.d.ts +320 -0
  20. package/dist/query-DybEplzd.d.ts.map +1 -0
  21. package/dist/{queryBuilder-DMzL_J5-.js → queryBuilder-BkWFLc3Y.js} +12 -3
  22. package/dist/queryBuilder-BkWFLc3Y.js.map +1 -0
  23. package/dist/{queryBuilder-B7063DYt.cjs → queryBuilder-BozfXlzA.cjs} +16 -1
  24. package/dist/queryBuilder-DfetMC5Z.d.cts +317 -0
  25. package/dist/queryBuilder-DfetMC5Z.d.cts.map +1 -0
  26. package/dist/queryBuilder-XIln1aIM.d.ts +317 -0
  27. package/dist/queryBuilder-XIln1aIM.d.ts.map +1 -0
  28. package/dist/types/index.d.cts +2 -3
  29. package/dist/types/index.d.ts +2 -3
  30. package/dist/utils/index.d.cts +1 -1
  31. package/dist/utils/index.d.ts +1 -1
  32. package/package.json +1 -1
  33. package/src/actions/public/getEntity.ts +1 -1
  34. package/src/actions/public/query.ts +12 -1
  35. package/src/clients/decorators/arkivPublic.ts +5 -5
  36. package/src/clients/decorators/arkivWallet.ts +2 -2
  37. package/src/{query/errors.ts → errors.ts} +10 -0
  38. package/src/index.ts +2 -2
  39. package/src/query/index.ts +0 -1
  40. package/src/query/queryResult.test.ts +1 -1
  41. package/src/query/queryResult.ts +1 -1
  42. package/src/types/index.ts +1 -0
  43. package/src/types/rpcSchema.ts +1 -1
  44. package/src/utils/arkivTransactions.ts +35 -14
  45. package/dist/index-B801JxcV.d.ts +0 -1003
  46. package/dist/index-B801JxcV.d.ts.map +0 -1
  47. package/dist/index-DQGx5KZ6.d.cts +0 -1003
  48. package/dist/index-DQGx5KZ6.d.cts.map +0 -1
  49. package/dist/query/index.d.cts.map +0 -1
  50. package/dist/query/index.d.ts.map +0 -1
  51. package/dist/queryBuilder-DMzL_J5-.js.map +0 -1
@@ -0,0 +1,317 @@
1
+ import { D as ArkivClient, a as Entity } from "./query-DybEplzd.js";
2
+ import { Hex } from "viem";
3
+
4
+ //#region src/query/predicate.d.ts
5
+ type PredicateType = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "not";
6
+ type PredicateContainerType = "or" | "and";
7
+ type Predicate = {
8
+ type: PredicateType;
9
+ key: string;
10
+ value: string | number;
11
+ } | {
12
+ type: PredicateContainerType;
13
+ predicates: Predicate[];
14
+ };
15
+ /**
16
+ * Creates an OR predicate
17
+ * @param predicates - The predicates to combine
18
+ * @returns The OR predicate
19
+ *
20
+ * @example
21
+ * const predicates = [eq("name", "John"), eq("age", 30)]
22
+ * const result = or(predicates)
23
+ * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
24
+ *
25
+ */
26
+ declare function or(predicates: Predicate[]): Predicate;
27
+ /**
28
+ * Creates an AND predicate
29
+ * @param predicates - The predicates to combine
30
+ * @returns The AND predicate
31
+ *
32
+ * @example
33
+ * const predicates = [eq("name", "John"), eq("age", 30)]
34
+ * const result = and(predicates)
35
+ * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
36
+ *
37
+ */
38
+ declare function and(predicates: Predicate[]): Predicate;
39
+ /**
40
+ * Creates an equality predicate
41
+ * @param key - The key to compare
42
+ * @param value - The value to compare
43
+ * @returns The equality predicate
44
+ *
45
+ * @example
46
+ * const predicate = eq("name", "John")
47
+ * // result = { type: "eq", key: "name", value: "John" }
48
+ */
49
+ declare function eq(key: string, value: string | number): Predicate;
50
+ /**
51
+ * Creates a not equal predicate
52
+ * @param key - The key to compare
53
+ * @param value - The value to compare
54
+ * @returns The not equal predicate
55
+ *
56
+ * @example
57
+ * const predicate = neq("name", "John")
58
+ * // result = { type: "neq", key: "name", value: "John" }
59
+ */
60
+ declare function neq(key: string, value: string | number): Predicate;
61
+ /**
62
+ * Creates a greater than predicate
63
+ * @param key - The key to compare
64
+ * @param value - The value to compare
65
+ * @returns The greater than predicate
66
+ *
67
+ * @example
68
+ * const predicate = gt("name", "John")
69
+ * // result = { type: "gt", key: "name", value: "John" }
70
+ */
71
+ declare function gt(key: string, value: string | number): Predicate;
72
+ /**
73
+ * Creates a greater than or equal predicate
74
+ * @param key - The key to compare
75
+ * @param value - The value to compare
76
+ * @returns The greater than or equal predicate
77
+ *
78
+ * @example
79
+ * const predicate = gte("name", "John")
80
+ * // result = { type: "gte", key: "name", value: "John" }
81
+ */
82
+ declare function gte(key: string, value: string | number): Predicate;
83
+ /**
84
+ * Creates a less than predicate
85
+ * @param key - The key to compare
86
+ * @param value - The value to compare
87
+ * @returns The less than predicate
88
+ *
89
+ * @example
90
+ * const predicate = lt("name", "John")
91
+ * // result = { type: "lt", key: "name", value: "John" }
92
+ */
93
+ declare function lt(key: string, value: string | number): Predicate;
94
+ /**
95
+ * Creates a less than or equal predicate
96
+ * @param key - The key to compare
97
+ * @param value - The value to compare
98
+ * @returns The less than or equal predicate
99
+ *
100
+ * @example
101
+ * const predicate = lte("name", "John")
102
+ * // result = { type: "lte", key: "name", value: "John" }
103
+ */
104
+ declare function lte(key: string, value: string | number): Predicate;
105
+ /**
106
+ * Creates a not predicate
107
+ * @param key - The key to compare
108
+ * @returns The not predicate
109
+ *
110
+ * @example
111
+ * const predicate = not("name")
112
+ * // result = { type: "not", key: "name", value: "" }
113
+ */
114
+ declare function not(key: string): Predicate;
115
+ //#endregion
116
+ //#region src/query/queryResult.d.ts
117
+ declare class QueryResult {
118
+ entities: Entity[];
119
+ private _endOfIteration;
120
+ private _cursor;
121
+ private _limit;
122
+ private _validAtBlock;
123
+ private _queryBuilder;
124
+ get queryBuilder(): QueryBuilder;
125
+ get cursor(): string | undefined;
126
+ constructor(entities: Entity[], queryBuilder: QueryBuilder, cursor: string | undefined, limit: number | undefined, validAtBlock: bigint | undefined);
127
+ next(): Promise<void>;
128
+ hasNextPage(): boolean;
129
+ }
130
+ //#endregion
131
+ //#region src/query/queryBuilder.d.ts
132
+ type OrderByAttribute = {
133
+ name: string;
134
+ type: "string" | "number";
135
+ order: "asc" | "desc";
136
+ };
137
+ /**
138
+ * Helper function to create an ascending order by attribute
139
+ * @param attributeName - The name of the attribute to order by
140
+ * @param attributeType - The type of the attribute to order by (string or number)
141
+ * @returns Input for orderBy method
142
+ *
143
+ * @example
144
+ * const ascAttribute = asc("name", "string")
145
+ */
146
+ declare function asc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute;
147
+ /**
148
+ * Helper function to create a descending order by attribute
149
+ * @param attributeName - The name of the attribute to order by
150
+ * @param attributeType - The type of the attribute to order by (string or number)
151
+ * @returns Input for orderBy method
152
+ *
153
+ * @example
154
+ * const descAttribute = desc("name", "string")
155
+ */
156
+ declare function desc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute;
157
+ /**
158
+ * QueryBuilder is a helper class to build queries to the Arkiv DBChains.
159
+ * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
160
+ * @param client - The Arkiv client
161
+ * @returns The QueryBuilder instance {@link QueryBuilder}
162
+ */
163
+ declare class QueryBuilder {
164
+ private _client;
165
+ private _ownedBy;
166
+ private _orderBy;
167
+ private _validAtBlock;
168
+ private _withAttributes;
169
+ private _withMetadata;
170
+ private _withPayload;
171
+ private _limit;
172
+ private _cursor;
173
+ private _predicates;
174
+ constructor(client: ArkivClient);
175
+ /**
176
+ * Sets the ownedBy filter
177
+ * @param ownedBy - The address of the owner
178
+ * @returns The QueryBuilder instance
179
+ *
180
+ * @example
181
+ * const builder = new QueryBuilder(client)
182
+ * builder.ownedBy("0x1234567890123456789012345678901234567890")
183
+ */
184
+ ownedBy(ownedBy: Hex): this;
185
+ /**
186
+ * Sets the orderBy for the query.
187
+ * It can be called multiple times to order by multiple attributes.
188
+ * The order of the attributes is important. The first attribute is the primary order by attribute.
189
+ * You can use the helper functions asc() and desc() as input for this method.
190
+ * @param attributeName - The name of the attribute to order by
191
+ * @param attributeType - The type of the attribute to order by (string or number)
192
+ * @param order - The order to set the order by (asc or desc)
193
+ * @returns The QueryBuilder instance
194
+ *
195
+ * @example
196
+ * const builder = client.buildQuery()
197
+ * builder.orderBy("name", "string", "desc")
198
+ * builder.orderBy(asc("name", "string"))
199
+ * builder.orderBy(desc("name", "string"))
200
+ */
201
+ orderBy(attributeName: string, attributeType: "string" | "number", order?: "asc" | "desc"): this;
202
+ /**
203
+ * Sets the orderBy for the query.
204
+ * This method takes the OrderByAttribute object as an argument and is mainly
205
+ * used to use the helper functions asc() and desc() to create the OrderByAttribute instances.
206
+ * @param orderByAttribute - The OrderByAttribute instance to set
207
+ * @returns The QueryBuilder instance
208
+ *
209
+ * @example
210
+ * const builder = new QueryBuilder(client)
211
+ * builder.orderBy(asc("name", "string"))
212
+ * builder.orderBy(desc("name", "string"))
213
+ */
214
+ orderBy(orderByAttribute: OrderByAttribute): this;
215
+ /**
216
+ * Sets the withAttributes flag which will return the attributes for the entities if true
217
+ * @param withAttributes - The boolean value to set
218
+ * @returns The QueryBuilder instance
219
+ *
220
+ * @example
221
+ * const builder = new QueryBuilder(client)
222
+ * builder.withAttributes(true)
223
+ */
224
+ withAttributes(withAttributes?: boolean): this;
225
+ /**
226
+ * Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true
227
+ * @param withMetadata - The boolean value to set
228
+ * @returns The QueryBuilder instance
229
+ *
230
+ * @example
231
+ * const builder = new QueryBuilder(client)
232
+ * builder.withMetadata(true)
233
+ */
234
+ withMetadata(withMetadata?: boolean): this;
235
+ /**
236
+ * Sets the withPayload flag which will return the payload for the entities if true
237
+ * @param withPayload - The boolean value to set
238
+ * @returns The QueryBuilder instance
239
+ *
240
+ * @example
241
+ * const builder = new QueryBuilder(client)
242
+ * builder.withPayload(true)
243
+ */
244
+ withPayload(withPayload?: boolean): this;
245
+ /**
246
+ * Sets the limit for the query
247
+ * @param limit - The number of entities to return
248
+ * @returns The QueryBuilder instance
249
+ *
250
+ * @example
251
+ * const builder = new QueryBuilder(client)
252
+ * builder.limit(10)
253
+ */
254
+ limit(limit: number): this;
255
+ /**
256
+ * Sets the cursor for the query - it is advances setting which rather shouldn't be used manually but it is provided from query result if limit is used (pagination).
257
+ * @param cursor - The cursor to set which tells to RPC Query server where to start or continue the query.
258
+ * @returns The QueryBuilder instance
259
+ *
260
+ * @example
261
+ * const builder = new QueryBuilder(client)
262
+ * builder.offset(10)
263
+ */
264
+ cursor(cursor: string): this;
265
+ /**
266
+ * Sets the validAtBlock for the query which tells at which block height the state we are intested.
267
+ * If not set, the latest block is used.
268
+ * @param validAtBlock - The block number to set
269
+ * @returns The QueryBuilder instance
270
+ *
271
+ * @example
272
+ * const builder = new QueryBuilder(client)
273
+ * builder.validAtBlock(10000)
274
+ */
275
+ validAtBlock(validAtBlock: bigint): this;
276
+ /**
277
+ * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
278
+ * Predicates can be nested using 'or' and 'and' predicates.
279
+ * @param predicates - The predicates to set
280
+ * @returns The QueryBuilder instance
281
+ *
282
+ * @example
283
+ * const builder = new QueryBuilder(client)
284
+ * builder.where(eq("name", "John"))
285
+ * builder.where([eq("name", "John"), eq("age", 30)])
286
+ * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
287
+ * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
288
+ * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
289
+ * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
290
+ * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
291
+ */
292
+ where(predicates: Predicate[] | Predicate): this;
293
+ /**
294
+ * Fetches the entities from the query. Re
295
+ * It will return a QueryResult instance which can be used to fetch the next and previous pages.
296
+ * @returns The QueryResult instance {@link QueryResult}
297
+ *
298
+ * @example
299
+ * const builder = new QueryBuilder(client)
300
+ * const result = await builder.where(eq("name", "John")).fetch()
301
+ * // result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }
302
+ */
303
+ fetch(): Promise<QueryResult>;
304
+ /**
305
+ * Counts the entities from the query.
306
+ * @returns The number of entities
307
+ *
308
+ * @example
309
+ * const builder = new QueryBuilder(client)
310
+ * const result = await builder.where(eq("name", "John")).count()
311
+ * // result = 10
312
+ */
313
+ count(): Promise<number>;
314
+ }
315
+ //#endregion
316
+ export { or as _, QueryResult as a, PredicateType as c, gt as d, gte as f, not as g, neq as h, desc as i, and as l, lte as m, QueryBuilder as n, Predicate as o, lt as p, asc as r, PredicateContainerType as s, OrderByAttribute as t, eq as u };
317
+ //# sourceMappingURL=queryBuilder-XIln1aIM.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilder-XIln1aIM.d.ts","names":[],"sources":["../src/query/predicate.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":[],"mappings":";;;;KAAY,aAAA;KACA,sBAAA;KAEA,SAAA;QAEA;EALA,GAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA,GAAA,MAAA;AAEZ,CAAA,GAAY;EAEA,IAAA,EAKA,sBALA;EAKA,UAAA,EACM,SADN,EAAA;CACM;;AAclB;AAeA;AAcA;AAcA;AAcA;AAcA;AAcA;AAcA;AAaA;;iBAhHgB,EAAA,aAAe,cAAc;;AClB7C;;;;;;;;;;ACCY,iBFgCI,GAAA,CEhCY,UAAA,EFgCI,SEhCJ,EAAA,CAAA,EFgCkB,SEhClB;AAe5B;AAiBA;AAaA;;;;;;;;AAsPa,iBFrPG,EAAA,CEqPH,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EFrP4C,SEqP5C;;;;;;;;;;;iBFvOG,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;iBAa1C,GAAA,eAAkB;;;cClIrB,WAAA;YACD;EDRA,QAAA,eAAa;EACb,QAAA,OAAA;EAEA,QAAA,MAAS;EAET,QAAA,aAAA;EAKA,QAAA,aAAA;EACM,IAAA,YAAA,CAAA,CAAA,ECKI,YDLJ;EAAS,IAAA,MAAA,CAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAcX,WAAE,CAAA,QAAa,ECAjB,MDA+B,EAAA,EAAA,YAAS,ECCpC,YDDoC,EAAA,MAAA,EAAA,MAAA,GAAA,SAAA,EAAA,KAAA,EAAA,MAAA,GAAA,SAAA,EAAA,YAAA,EAAA,MAAA,GAAA,SAAA;EAetC,IAAA,CAAA,CAAG,ECDP,ODCO,CAAA,IAAa,CAAA;EAchB,WAAE,CAAA,CAAA,EAAA,OAAuC;AAczD;;;AApEY,KEQA,gBAAA,GFRa;EACb,IAAA,EAAA,MAAA;EAEA,IAAA,EAAA,QAAS,GAAA,QAAA;EAET,KAAA,EAAA,KAAA,GAAA,MAAA;CAKA;;;AAeZ;AAeA;AAcA;AAcA;AAcA;AAcA;AAcA;AAcgB,iBErGA,GAAA,CFqG0C,aAAS,EAAA,MAAA,EAAA,aAAA,EAAA,QAAA,GAAA,QAAA,CAAA,EErGa,gBFqGb;AAanE;;;;AClIA;;;;;AAgCY,iBCCI,IAAA,CDDJ,aAAA,EAAA,MAAA,EAAA,aAAA,EAAA,QAAA,GAAA,QAAA,CAAA,ECCqE,gBDDrE;;;;;AC/BZ;AAeA;AAiBgB,cAaH,YAAA,CAboE;EAapE,QAAA,OAAY;EAYH,QAAA,QAAA;EAcH,QAAA,QAAA;EAkCS,QAAA,aAAA;EAuIR,QAAA,eAAA;EAAc,QAAA,aAAA;EAmBrB,QAAA,YAAA;EAAA,QAAA,MAAA;EAgCA,QAAA,OAAA;EAAA,QAAA,WAAA;sBA1OS;;;;;;;;;;mBAcH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAkCS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAuIR,cAAc;;;;;;;;;;;WAmBrB,QAAA;;;;;;;;;;WAgCA"}
@@ -1,3 +1,2 @@
1
- import { $ as RpcIncludeData, A as CreateEntityParameters, C as MutateEntitiesReturnType, D as ExtendEntityReturnType, E as ExtendEntityParameters, J as QueryOptionsIncludeData, M as ChangeOwnershipParameters, N as ChangeOwnershipReturnType, O as DeleteEntityParameters, P as GetBlockTimingReturnType, Q as RpcEntity, S as MutateEntitiesParameters, T as UpdateEntityReturnType, Y as QueryOptionsOrderBy, Z as ArkivRpcSchema, _ as OnEntityExpiredEvent, b as OnEntityUpdatedEvent, et as RpcOrderByAttribute, g as OnEntityDeletedEvent, h as OnEntityCreatedEvent, j as CreateEntityReturnType, k as DeleteEntityReturnType, m as TxParams, nt as MimeType, p as Entity, q as QueryOptions, tt as RpcQueryOptions, v as OnEntityExpiresInExtendedEvent, w as UpdateEntityParameters, x as Attribute, y as OnEntityOwnerChangedEvent } from "../index-DQGx5KZ6.cjs";
2
- import "../payload-D3fyOBWn.cjs";
3
- export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, GetBlockTimingReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, OnEntityCreatedEvent, OnEntityDeletedEvent, OnEntityExpiredEvent, OnEntityExpiresInExtendedEvent, OnEntityOwnerChangedEvent, OnEntityUpdatedEvent, QueryOptions, QueryOptionsIncludeData, QueryOptionsOrderBy, RpcEntity, RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
1
+ import { A as RpcIncludeData, C as CreateEntityReturnType, E as GetBlockTimingReturnType, M as RpcQueryOptions, N as MimeType, O as ArkivRpcSchema, S as CreateEntityParameters, T as ChangeOwnershipReturnType, _ as UpdateEntityReturnType, a as Entity, b as DeleteEntityParameters, c as OnEntityDeletedEvent, d as OnEntityOwnerChangedEvent, f as OnEntityUpdatedEvent, g as UpdateEntityParameters, h as MutateEntitiesReturnType, i as QueryReturnType, j as RpcOrderByAttribute, k as RpcEntity, l as OnEntityExpiredEvent, m as MutateEntitiesParameters, n as QueryOptionsIncludeData, o as TxParams, p as Attribute, r as QueryOptionsOrderBy, s as OnEntityCreatedEvent, t as QueryOptions, u as OnEntityExpiresInExtendedEvent, v as ExtendEntityParameters, w as ChangeOwnershipParameters, x as DeleteEntityReturnType, y as ExtendEntityReturnType } from "../query-C0dwQYxT.cjs";
2
+ export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, GetBlockTimingReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, OnEntityCreatedEvent, OnEntityDeletedEvent, OnEntityExpiredEvent, OnEntityExpiresInExtendedEvent, OnEntityOwnerChangedEvent, OnEntityUpdatedEvent, QueryOptions, QueryOptionsIncludeData, QueryOptionsOrderBy, QueryReturnType, RpcEntity, RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
@@ -1,3 +1,2 @@
1
- import { $ as RpcIncludeData, A as CreateEntityParameters, C as MutateEntitiesReturnType, D as ExtendEntityReturnType, E as ExtendEntityParameters, J as QueryOptionsIncludeData, M as ChangeOwnershipParameters, N as ChangeOwnershipReturnType, O as DeleteEntityParameters, P as GetBlockTimingReturnType, Q as RpcEntity, S as MutateEntitiesParameters, T as UpdateEntityReturnType, Y as QueryOptionsOrderBy, Z as ArkivRpcSchema, _ as OnEntityExpiredEvent, b as OnEntityUpdatedEvent, et as RpcOrderByAttribute, g as OnEntityDeletedEvent, h as OnEntityCreatedEvent, j as CreateEntityReturnType, k as DeleteEntityReturnType, m as TxParams, nt as MimeType, p as Entity, q as QueryOptions, tt as RpcQueryOptions, v as OnEntityExpiresInExtendedEvent, w as UpdateEntityParameters, x as Attribute, y as OnEntityOwnerChangedEvent } from "../index-B801JxcV.js";
2
- import "../payload-BI2NXPDf.js";
3
- export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, GetBlockTimingReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, OnEntityCreatedEvent, OnEntityDeletedEvent, OnEntityExpiredEvent, OnEntityExpiresInExtendedEvent, OnEntityOwnerChangedEvent, OnEntityUpdatedEvent, QueryOptions, QueryOptionsIncludeData, QueryOptionsOrderBy, RpcEntity, RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
1
+ import { A as RpcIncludeData, C as CreateEntityReturnType, E as GetBlockTimingReturnType, M as RpcQueryOptions, N as MimeType, O as ArkivRpcSchema, S as CreateEntityParameters, T as ChangeOwnershipReturnType, _ as UpdateEntityReturnType, a as Entity, b as DeleteEntityParameters, c as OnEntityDeletedEvent, d as OnEntityOwnerChangedEvent, f as OnEntityUpdatedEvent, g as UpdateEntityParameters, h as MutateEntitiesReturnType, i as QueryReturnType, j as RpcOrderByAttribute, k as RpcEntity, l as OnEntityExpiredEvent, m as MutateEntitiesParameters, n as QueryOptionsIncludeData, o as TxParams, p as Attribute, r as QueryOptionsOrderBy, s as OnEntityCreatedEvent, t as QueryOptions, u as OnEntityExpiresInExtendedEvent, v as ExtendEntityParameters, w as ChangeOwnershipParameters, x as DeleteEntityReturnType, y as ExtendEntityReturnType } from "../query-DybEplzd.js";
2
+ export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, GetBlockTimingReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, OnEntityCreatedEvent, OnEntityDeletedEvent, OnEntityExpiredEvent, OnEntityExpiresInExtendedEvent, OnEntityOwnerChangedEvent, OnEntityUpdatedEvent, QueryOptions, QueryOptionsIncludeData, QueryOptionsOrderBy, QueryReturnType, RpcEntity, RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
@@ -1,4 +1,4 @@
1
- import { n as stringToPayload, t as jsonToPayload } from "../payload-D3fyOBWn.cjs";
1
+ import { n as stringToPayload, t as jsonToPayload } from "../payload-CJN8fTvX.cjs";
2
2
  export * from "viem/utils";
3
3
 
4
4
  //#region src/utils/expirationTime.d.ts
@@ -1,4 +1,4 @@
1
- import { n as stringToPayload, t as jsonToPayload } from "../payload-BI2NXPDf.js";
1
+ import { n as stringToPayload, t as jsonToPayload } from "../payload-Da9gJMG5.js";
2
2
  export * from "viem/utils";
3
3
 
4
4
  //#region src/utils/expirationTime.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkiv-network/sdk",
3
- "version": "0.5.0-dev.3",
3
+ "version": "0.5.0-dev.5",
4
4
  "description": "TypeScript client library for Arkiv's blockchains interactions",
5
5
  "type": "module",
6
6
  "target": "esnext",
@@ -1,6 +1,6 @@
1
1
  import { bytesToHex, type Hex, hexToBytes } from "viem"
2
2
  import type { ArkivClient } from "../../clients/baseClient"
3
- import { NoEntityFoundError } from "../../query/errors"
3
+ import { NoEntityFoundError } from "../../errors"
4
4
  import { entityFromRpcResult } from "../../utils/entities"
5
5
 
6
6
  export async function getEntity(client: ArkivClient, key: Hex) {
@@ -1,4 +1,5 @@
1
1
  import type { ArkivClient } from "../../clients/baseClient"
2
+ import type { Entity } from "../../types/entity"
2
3
  import type { RpcQueryOptions } from "../../types/rpcSchema"
3
4
  import { entityFromRpcResult } from "../../utils/entities"
4
5
 
@@ -21,6 +22,12 @@ export type QueryOptions = {
21
22
  cursor?: string | undefined
22
23
  }
23
24
 
25
+ export type QueryReturnType = {
26
+ entities: Entity[]
27
+ cursor: string | undefined
28
+ blockNumber: bigint | undefined
29
+ }
30
+
24
31
  export async function query(client: ArkivClient, query: string, queryOptions?: QueryOptions) {
25
32
  const rpcQueryOptions: RpcQueryOptions = {
26
33
  includeData: {
@@ -56,5 +63,9 @@ export async function query(client: ArkivClient, query: string, queryOptions?: Q
56
63
 
57
64
  const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))
58
65
 
59
- return entities
66
+ return {
67
+ entities,
68
+ cursor: result.cursor,
69
+ blockNumber: BigInt(result.blockNumber),
70
+ }
60
71
  }
@@ -2,7 +2,7 @@ import type { Account, 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 { type QueryOptions, query } from "../../actions/public/query"
5
+ import { type QueryOptions, type QueryReturnType, query } from "../../actions/public/query"
6
6
  import { subscribeEntityEvents } from "../../actions/public/subscribeEntityEvents"
7
7
  import { QueryBuilder } from "../../query/queryBuilder"
8
8
  import type { Entity } from "../../types/entity"
@@ -82,7 +82,7 @@ export type PublicArkivActions<
82
82
  * If no query options are provided, all payload is included, but no metadata (like owner, expiredAt, etc.) and attributes.
83
83
  * @param query - The raw query string
84
84
  * @param queryOptions - The optional query options - {@link QueryOptions}
85
- * @returns An array of entities matching the query. {@link Entity}
85
+ * @returns A QueryReturnType instance - {@link QueryReturnType}
86
86
  *
87
87
  * @example
88
88
  * import { createPublicClient, http } from 'arkiv'
@@ -93,7 +93,7 @@ export type PublicArkivActions<
93
93
  * transport: http(),
94
94
  * })
95
95
  * const queryResult = client.query('key = value && $owner = 0x123')
96
- * // queryResult = [{ key: "0x123", value: "0x123" }]
96
+ * // queryResult = { entities: [{ key: "0x123", value: "0x123" }], cursor: undefined, blockNumber: undefined }
97
97
  * const queryResultWithOptions = client.query('key = value && $owner = 0x123', {
98
98
  * includeData: {
99
99
  * attributes: false,
@@ -105,9 +105,9 @@ export type PublicArkivActions<
105
105
  * cursor: undefined,
106
106
  * atBlock: undefined,
107
107
  * })
108
- * // queryResultWithOptions = [{ key: "0x123", value: "0x123" }]
108
+ * // queryResultWithOptions = { entities: [{ key: "0x123", value: "0x123" }], cursor: "...", blockNumber: 32223n }
109
109
  */
110
- query: (query: string, queryOptions?: QueryOptions) => Promise<Entity[]>
110
+ query: (query: string, queryOptions?: QueryOptions) => Promise<QueryReturnType>
111
111
 
112
112
  /**
113
113
  * Returns the number of entities in the DBChain.
@@ -39,10 +39,10 @@ export type WalletArkivActions<
39
39
  Pick<
40
40
  WalletActions<chain, account>,
41
41
  | "addChain"
42
+ | "sendCalls"
43
+ | "waitForCallsStatus"
42
44
  | "sendTransaction"
43
- | "sendTransactionSync"
44
45
  | "sendRawTransaction"
45
- | "sendRawTransactionSync"
46
46
  | "signMessage"
47
47
  | "signTransaction"
48
48
  > & {
@@ -1,17 +1,27 @@
1
+ export class EntityMutationError extends Error {
2
+ constructor(message: string) {
3
+ super(message)
4
+ this.name = "EntityMutationError"
5
+ }
6
+ }
7
+
1
8
  export class NoMoreResultsError extends Error {
2
9
  constructor() {
3
10
  super("No more results")
11
+ this.name = "NoMoreResultsError"
4
12
  }
5
13
  }
6
14
 
7
15
  export class NoCursorOrLimitError extends Error {
8
16
  constructor() {
9
17
  super("Cursor and limit must be defined to fetch next")
18
+ this.name = "NoCursorOrLimitError"
10
19
  }
11
20
  }
12
21
 
13
22
  export class NoEntityFoundError extends Error {
14
23
  constructor() {
15
24
  super("No entity found")
25
+ this.name = "NoEntityFoundError"
16
26
  }
17
27
  }
package/src/index.ts CHANGED
@@ -13,10 +13,10 @@ export type { WalletArkivClient } from "./clients/createWalletClient"
13
13
  export { createWalletClient } from "./clients/createWalletClient"
14
14
  export type { PublicArkivActions } from "./clients/decorators/arkivPublic"
15
15
  export type { WalletArkivActions } from "./clients/decorators/arkivWallet"
16
-
16
+ // re-export errors
17
+ export * from "./errors"
17
18
  // re-export arkiv types in main index file
18
19
  export * from "./types"
19
-
20
20
  // re-export chosen utils
21
21
  export { chainFromName } from "./utils/chains"
22
22
  export { jsonToPayload, stringToPayload } from "./utils/payload"
@@ -1,4 +1,3 @@
1
- export * from "./errors"
2
1
  export * from "./predicate"
3
2
  export * from "./queryBuilder"
4
3
  export * from "./queryResult"
@@ -1,6 +1,6 @@
1
1
  import { beforeEach, describe, expect, jest, test } from "bun:test"
2
+ import { NoCursorOrLimitError, NoMoreResultsError } from "../errors"
2
3
  import { Entity } from "../types/entity"
3
- import { NoCursorOrLimitError, NoMoreResultsError } from "./errors"
4
4
  import type { QueryBuilder } from "./queryBuilder"
5
5
  import { QueryResult } from "./queryResult"
6
6
 
@@ -1,6 +1,6 @@
1
+ import { NoCursorOrLimitError, NoMoreResultsError } from "../errors"
1
2
  import type { Entity } from "../types/entity"
2
3
  import { getLogger } from "../utils/logger"
3
- import { NoCursorOrLimitError, NoMoreResultsError } from "./errors"
4
4
  import type { QueryBuilder } from "./queryBuilder"
5
5
 
6
6
  const logger = getLogger("query:result")
@@ -3,6 +3,7 @@ export type {
3
3
  QueryOptions,
4
4
  QueryOptionsIncludeData,
5
5
  QueryOptionsOrderBy,
6
+ QueryReturnType,
6
7
  } from "../actions/public/query"
7
8
  export type {
8
9
  ChangeOwnershipParameters,
@@ -48,7 +48,7 @@ export type ArkivRpcSchema = [
48
48
  Parameters?: [query: string, queryOptions?: RpcQueryOptions]
49
49
  ReturnType: {
50
50
  data: RpcEntity[]
51
- blockNumber: bigint
51
+ blockNumber: number
52
52
  cursor: string
53
53
  }
54
54
  },
@@ -1,4 +1,4 @@
1
- import { type Hex, toBytes, toHex, toRlp } from "viem"
1
+ import { type Hex, TransactionExecutionError, toBytes, toHex, toRlp } from "viem"
2
2
  import type { ChangeOwnershipParameters } from "../actions/wallet/changeOwnership"
3
3
  import type { CreateEntityParameters } from "../actions/wallet/createEntity"
4
4
  import type { DeleteEntityParameters } from "../actions/wallet/deleteEntity"
@@ -7,6 +7,7 @@ import type { UpdateEntityParameters } from "../actions/wallet/updateEntity"
7
7
  import type { ArkivClient } from "../clients/baseClient"
8
8
  import type { WalletArkivClient } from "../clients/createWalletClient"
9
9
  import { ARKIV_ADDRESS, BLOCK_TIME } from "../consts"
10
+ import { EntityMutationError } from "../errors"
10
11
  import type { TxParams } from "../types"
11
12
  import { compress } from "./compression"
12
13
  import { getLogger } from "./logger"
@@ -30,7 +31,10 @@ export function opsToTxData({
30
31
  key: string
31
32
  value: T
32
33
  }): [Hex, Hex] {
33
- return [toHex(attribute.key), toHex(attribute.value)]
34
+ return [
35
+ toHex(attribute.key),
36
+ toHex(typeof attribute.value === "number" && attribute.value === 0 ? "" : attribute.value),
37
+ ]
34
38
  }
35
39
 
36
40
  const payload = [
@@ -85,19 +89,36 @@ export async function sendArkivTransaction(client: ArkivClient, data: Hex, txPar
85
89
  ...txParams,
86
90
  })
87
91
 
88
- const compressed = await compress(toBytes(data))
89
- const txHash = await walletClient.sendTransaction({
90
- account: client.account,
91
- chain: client.chain,
92
- to: ARKIV_ADDRESS,
93
- value: 0n,
94
- data: toHex(compressed),
95
- ...txParams,
96
- })
92
+ try {
93
+ const compressed = await compress(toBytes(data))
94
+ const txHash = await walletClient.sendTransaction({
95
+ account: client.account,
96
+ chain: client.chain,
97
+ to: ARKIV_ADDRESS,
98
+ value: 0n,
99
+ data: toHex(compressed),
100
+ ...txParams,
101
+ })
97
102
 
98
- const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash })
103
+ const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash })
104
+ logger("Tx receipt %o", receipt)
105
+ if (receipt.status === "reverted") {
106
+ logger("Reverted transaction %o", receipt)
107
+ throw new EntityMutationError(
108
+ `Transaction ${receipt.transactionHash} reverted. Please make sure the data for entities doesn't contain invalid characters or invalid data types.`,
109
+ )
110
+ }
99
111
 
100
- logger("Tx receipt %o", receipt)
112
+ return receipt
113
+ } catch (error) {
114
+ let message = "Transaction failed"
115
+ if (error instanceof TransactionExecutionError) {
116
+ message += `: ${error.details}`
117
+ } else if (error instanceof EntityMutationError) {
118
+ throw error
119
+ }
101
120
 
102
- return receipt
121
+ logger("%s Detailed error stack: %o", message, error)
122
+ throw new EntityMutationError(message)
123
+ }
103
124
  }