@arkiv-network/sdk 0.3.1 → 0.3.2-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.
Files changed (40) hide show
  1. package/dist/entity-DvQtQL8v.d.ts +246 -0
  2. package/dist/entity-DvQtQL8v.d.ts.map +1 -0
  3. package/dist/entity-jTQZmEAd.d.cts +246 -0
  4. package/dist/entity-jTQZmEAd.d.cts.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.cts +3 -143
  7. package/dist/index.d.cts.map +1 -1
  8. package/dist/index.d.ts +3 -143
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/query/index.cjs +1 -1
  12. package/dist/query/index.d.cts +2 -2
  13. package/dist/query/index.d.ts +2 -2
  14. package/dist/query/index.js +1 -1
  15. package/dist/{queryBuilder-D38MYG7o.d.ts → queryBuilder-BBtwhH0G.d.ts} +19 -63
  16. package/dist/queryBuilder-BBtwhH0G.d.ts.map +1 -0
  17. package/dist/{queryBuilder-n9ocnT4P.cjs → queryBuilder-D-bqHg3w.cjs} +29 -2
  18. package/dist/{queryBuilder-BueP5de6.js → queryBuilder-D22Tamry.js} +30 -3
  19. package/dist/queryBuilder-D22Tamry.js.map +1 -0
  20. package/dist/{queryBuilder-DU4RQa7H.d.cts → queryBuilder-DkhyyeFr.d.cts} +19 -63
  21. package/dist/queryBuilder-DkhyyeFr.d.cts.map +1 -0
  22. package/dist/types/index.d.cts +2 -2
  23. package/dist/types/index.d.ts +2 -2
  24. package/dist/utils/index.d.cts.map +1 -1
  25. package/dist/utils/index.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/index.ts +28 -6
  28. package/src/query/engine.test.ts +69 -0
  29. package/src/query/engine.ts +8 -3
  30. package/src/query/queryBuilder.test.ts +34 -0
  31. package/src/query/queryBuilder.ts +33 -0
  32. package/src/types/index.ts +13 -0
  33. package/src/types/rpcSchema.ts +7 -0
  34. package/dist/entity-CMRcjXBK.d.ts +0 -41
  35. package/dist/entity-CMRcjXBK.d.ts.map +0 -1
  36. package/dist/entity-Dgf1SSpi.d.cts +0 -41
  37. package/dist/entity-Dgf1SSpi.d.cts.map +0 -1
  38. package/dist/queryBuilder-BueP5de6.js.map +0 -1
  39. package/dist/queryBuilder-D38MYG7o.d.ts.map +0 -1
  40. package/dist/queryBuilder-DU4RQa7H.d.cts.map +0 -1
@@ -1,65 +1,6 @@
1
- import { i as MimeType, t as Entity } from "./entity-Dgf1SSpi.cjs";
2
- import { Account, Chain, Client, Hex, RpcSchema, Transport } from "viem";
1
+ import { g as ArkivClient, t as Entity } from "./entity-jTQZmEAd.cjs";
2
+ import { Hex } from "viem";
3
3
 
4
- //#region src/types/rpcSchema.d.ts
5
- type RpcEntity = {
6
- key: Hex;
7
- contentType: MimeType;
8
- value: string;
9
- expiresAt: bigint;
10
- owner: Hex;
11
- stringAttributes?: [{
12
- key: string;
13
- value: string;
14
- }];
15
- numericAttributes?: [{
16
- key: string;
17
- value: number;
18
- }];
19
- };
20
- type RpcQueryOptions = {
21
- atBlock?: number;
22
- includeData?: RpcIncludeData;
23
- resultsPerPage?: number;
24
- cursor?: string;
25
- };
26
- type RpcIncludeData = {
27
- key: boolean;
28
- attributes: boolean;
29
- payload: boolean;
30
- contentType: boolean;
31
- expiration: boolean;
32
- owner: boolean;
33
- };
34
- type ArkivRpcSchema = [{
35
- Method: "golembase_getStorageValue";
36
- Parameters?: [entityId: Hex];
37
- ReturnType: string;
38
- }, {
39
- Method: "arkiv_query";
40
- Parameters?: [query: string, queryOptions?: RpcQueryOptions];
41
- ReturnType: {
42
- data: [RpcEntity];
43
- blockNumber: bigint;
44
- cursor: string;
45
- };
46
- }, {
47
- Method: "arkiv_getBlockTiming";
48
- Parameters?: [];
49
- ReturnType: {
50
- current_block: bigint;
51
- current_block_time: number;
52
- duration: number;
53
- };
54
- }, {
55
- Method: "arkiv_getEntityCount";
56
- Parameters?: [];
57
- ReturnType: number;
58
- }];
59
- //#endregion
60
- //#region src/clients/baseClient.d.ts
61
- type ArkivClient<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, accountOrAddress extends Account | undefined = Account | undefined, rpcSchema extends RpcSchema | undefined = ArkivRpcSchema> = Client<transport, chain, accountOrAddress, rpcSchema>;
62
- //#endregion
63
4
  //#region src/query/predicate.d.ts
64
5
  type PredicateType = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "not";
65
6
  type PredicateContainerType = "or" | "and";
@@ -197,6 +138,7 @@ declare class QueryResult {
197
138
  declare class QueryBuilder {
198
139
  private _client;
199
140
  private _ownedBy;
141
+ private _orderBy;
200
142
  private _validAtBlock;
201
143
  private _withAttributes;
202
144
  private _withMetadata;
@@ -215,6 +157,20 @@ declare class QueryBuilder {
215
157
  * builder.ownedBy("0x1234567890123456789012345678901234567890")
216
158
  */
217
159
  ownedBy(ownedBy: Hex): this;
160
+ /**
161
+ * Sets the orderBy for the query.
162
+ * It can be called multiple times to order by multiple attributes.
163
+ * The order of the attributes is important. The first attribute is the primary order by attribute.
164
+ * @param attributeName - The name of the attribute to order by
165
+ * @param attributeType - The type of the attribute to order by (string or number)
166
+ * @param descending - The boolean value to set the order by descending
167
+ * @returns The QueryBuilder instance
168
+ *
169
+ * @example
170
+ * const builder = new QueryBuilder(client)
171
+ * builder.orderBy("name", "string", true)
172
+ */
173
+ orderBy(attributeName: string, attributeType: "string" | "number", descending?: boolean | undefined): this;
218
174
  /**
219
175
  * Sets the withAttributes flag which will return the attributes for the entities if true
220
176
  * @param withAttributes - The boolean value to set
@@ -316,5 +272,5 @@ declare class QueryBuilder {
316
272
  count(): Promise<1>;
317
273
  }
318
274
  //#endregion
319
- export { PredicateType as a, gt as c, lte as d, neq as f, ArkivRpcSchema as g, ArkivClient as h, PredicateContainerType as i, gte as l, or as m, QueryResult as n, and as o, not as p, Predicate as r, eq as s, QueryBuilder as t, lt as u };
320
- //# sourceMappingURL=queryBuilder-DU4RQa7H.d.cts.map
275
+ export { PredicateType as a, gt as c, lte as d, neq as f, PredicateContainerType as i, gte as l, or as m, QueryResult as n, and as o, not as p, Predicate as r, eq as s, QueryBuilder as t, lt as u };
276
+ //# sourceMappingURL=queryBuilder-DkhyyeFr.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilder-DkhyyeFr.d.cts","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;;ACrB7C;;;;;;;;;;ACUa,iBF0BG,GAAA,CE1BS,UAAA,EF0BO,SE1BP,EAAA,CAAA,EF0BqB,SE1BrB;;;;;;;;;;;iBFwCT,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;iBAa1C,GAAA,eAAkB;;;cCrIrB,WAAA;YACD;EDLA,QAAA,eAAa;EACb,QAAA,OAAA;EAEA,QAAA,MAAS;EAET,QAAA,aAAA;EAKA,QAAA,aAAA;EACM,IAAA,YAAA,CAAA,CAAA,ECEI,YDFJ;EAAS,IAAA,MAAA,CAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAcX,WAAE,CAAA,QAAa,ECHjB,MDG+B,EAAA,EAAA,YAAS,ECFpC,YDEoC,EAAA,MAAA,EAAA,MAAA,GAAA,SAAA,EAAA,KAAA,EAAA,MAAA,GAAA,SAAA,EAAA,YAAA,EAAA,MAAA,GAAA,SAAA;EAetC,IAAA,CAAA,CAAG,ECJP,ODIO,CAAA,IAAa,CAAA;EAchB,WAAE,CAAA,CAAA,EAAA,OAAuC;AAczD;;;AApEA;AACA;AAEA;;;;AAQ2B,cEGd,YAAA,CFHc;EAcX,QAAE,OAAA;EAeF,QAAG,QAAA;EAcH,QAAE,QAAA;EAcF,QAAG,aAAuC;EAc1C,QAAE,eAAuC;EAczC,QAAG,aAAuC;EAc1C,QAAE,YAAuC;EAczC,QAAG,MAAA;EAaH,QAAG,OAAA;;sBE/GG;;ADtBtB;;;;;;;;mBCoCmB;;AA1BnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAiKoB,cAAc;;;;;;;;;;;WAmBrB,QAAA;;;;;;;;;;WAgCA"}
@@ -1,2 +1,2 @@
1
- import { i as MimeType, n as TxParams, r as Attribute, t as Entity } from "../entity-Dgf1SSpi.cjs";
2
- export { Attribute, Entity, MimeType, TxParams };
1
+ import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-jTQZmEAd.cjs";
2
+ export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, RpcEntity, RpcIncludeData, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
@@ -1,2 +1,2 @@
1
- import { i as MimeType, n as TxParams, r as Attribute, t as Entity } from "../entity-CMRcjXBK.js";
2
- export { Attribute, Entity, MimeType, TxParams };
1
+ import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-DvQtQL8v.js";
2
+ export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, RpcEntity, RpcIncludeData, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/expirationTime.ts","../../src/utils/payload.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;EAAA,SAAA,EAAA,CAAA,KAUZ,EAAA,MAAA,EAAA,GADkB,MAAI;;;;ECTP,SAAA,EAAA,CAAA,KAAa,EAAA,MAAA,EAAgB,GAAA,MAAA;EAI7B,UAAA,EAAA,CAAA,MAAe,EAAA,MAAA,EAAgB,GAAA,MAAA;mBDK5B;;;;iBCTH,aAAA,gBAA6B;iBAI7B,eAAA,gBAA+B"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/expirationTime.ts","../../src/utils/payload.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;EAAA,SAAA,EAAA,CAAA,KAUZ,EAAA,MAAA,EAAA,GADkB,MAAI;;;;ECTP,SAAA,EAAA,CAAA,KAAa,EAAA,MAAA,EAAA,GAAgB,MAAA;EAI7B,UAAA,EAAA,CAAA,MAAe,EAAA,MAAA,EAAA,GAAgB,MAAA;mBDK5B;;;;iBCTH,aAAA,gBAA6B;iBAI7B,eAAA,gBAA+B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/utils/expirationTime.ts","../../src/utils/payload.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;EAAA,SAAA,EAAA,CAAA,KAUZ,EAAA,MAAA,EAAA,GADkB,MAAI;;;;ECTP,SAAA,EAAA,CAAA,KAAa,EAAA,MAAA,EAAA,GAAgB,MAAA;EAI7B,UAAA,EAAA,CAAA,MAAe,EAAA,MAAA,EAAA,GAAgB,MAAA;mBDK5B;;;;iBCTH,aAAA,gBAA6B;iBAI7B,eAAA,gBAA+B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/utils/expirationTime.ts","../../src/utils/payload.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;EAAA,SAAA,EAAA,CAAA,KAUZ,EAAA,MAAA,EAAA,GADkB,MAAI;;;;ECTP,SAAA,EAAA,CAAA,KAAa,EAAA,MAAA,EAAgB,GAAA,MAAA;EAI7B,UAAA,EAAA,CAAA,MAAe,EAAA,MAAA,EAAgB,GAAA,MAAA;mBDK5B;;;;iBCTH,aAAA,gBAA6B;iBAI7B,eAAA,gBAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkiv-network/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2-dev.1",
4
4
  "description": "TypeScript client library for Arkiv's blockchains interactions",
5
5
  "type": "module",
6
6
  "target": "esnext",
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
- // Export all public APIs
2
-
1
+ // Re-export commonly used viem types for convenience
3
2
  export type {
4
3
  Account,
5
4
  Address,
@@ -9,13 +8,36 @@ export type {
9
8
  RpcSchema,
10
9
  Transport,
11
10
  } from "viem"
12
- // Re-export commonly used viem types for convenience
11
+
13
12
  export { http, toBytes, toHex, toRlp, webSocket } from "viem"
13
+
14
+ // export main arkiv stuff
14
15
  export type { ArkivClient } from "./clients/baseClient"
15
16
  export type { PublicArkivClient } from "./clients/createPublicClient"
16
17
  export { createPublicClient } from "./clients/createPublicClient"
17
18
  export type { WalletArkivClient } from "./clients/createWalletClient"
18
19
  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"
20
+
21
+ // re-export arkiv types in main index file
22
+ export type {
23
+ ArkivRpcSchema,
24
+ Attribute,
25
+ ChangeOwnershipParameters,
26
+ ChangeOwnershipReturnType,
27
+ CreateEntityParameters,
28
+ CreateEntityReturnType,
29
+ DeleteEntityParameters,
30
+ DeleteEntityReturnType,
31
+ Entity,
32
+ ExtendEntityParameters,
33
+ ExtendEntityReturnType,
34
+ MimeType,
35
+ MutateEntitiesParameters,
36
+ MutateEntitiesReturnType,
37
+ RpcEntity,
38
+ RpcIncludeData,
39
+ RpcQueryOptions,
40
+ TxParams,
41
+ UpdateEntityParameters,
42
+ UpdateEntityReturnType,
43
+ } from "./types"
@@ -15,6 +15,7 @@ describe("processQuery tests", () => {
15
15
  limit: undefined,
16
16
  cursor: undefined,
17
17
  ownedBy: undefined,
18
+ orderBy: undefined,
18
19
  validAtBlock: undefined,
19
20
  withAttributes: undefined,
20
21
  withMetadata: undefined,
@@ -53,6 +54,7 @@ describe("processQuery tests", () => {
53
54
  limit: undefined,
54
55
  cursor: undefined,
55
56
  ownedBy: undefined,
57
+ orderBy: undefined,
56
58
  validAtBlock: undefined,
57
59
  withAttributes: undefined,
58
60
  withMetadata: undefined,
@@ -92,6 +94,7 @@ describe("processQuery tests", () => {
92
94
  limit: undefined,
93
95
  cursor: undefined,
94
96
  ownedBy: undefined,
97
+ orderBy: undefined,
95
98
  validAtBlock: undefined,
96
99
  withAttributes: undefined,
97
100
  withMetadata: undefined,
@@ -131,6 +134,7 @@ describe("processQuery tests", () => {
131
134
  limit: undefined,
132
135
  cursor: undefined,
133
136
  ownedBy: undefined,
137
+ orderBy: undefined,
134
138
  validAtBlock: undefined,
135
139
  withAttributes: undefined,
136
140
  withMetadata: undefined,
@@ -176,6 +180,7 @@ describe("processQuery tests", () => {
176
180
  limit: undefined,
177
181
  cursor: undefined,
178
182
  ownedBy: undefined,
183
+ orderBy: undefined,
179
184
  validAtBlock: undefined,
180
185
  withAttributes: undefined,
181
186
  withMetadata: undefined,
@@ -203,6 +208,7 @@ describe("processQuery tests", () => {
203
208
  const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
204
209
  await processQuery(client, {
205
210
  predicates,
211
+ orderBy: undefined,
206
212
  limit: undefined,
207
213
  cursor: undefined,
208
214
  ownedBy: "0x123",
@@ -232,6 +238,7 @@ describe("processQuery tests", () => {
232
238
  predicates,
233
239
  limit: undefined,
234
240
  cursor: undefined,
241
+ orderBy: undefined,
235
242
  validAtBlock: undefined,
236
243
  withAttributes: undefined,
237
244
  withMetadata: undefined,
@@ -256,12 +263,74 @@ describe("processQuery tests", () => {
256
263
  })
257
264
  })
258
265
 
266
+ it("should process simple predicates with orderBy", async () => {
267
+ const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
268
+ await processQuery(client, {
269
+ predicates,
270
+ orderBy: [{ name: "key", type: "string", descending: true }],
271
+ limit: undefined,
272
+ cursor: undefined,
273
+ ownedBy: undefined,
274
+ })
275
+
276
+ expect(client.request).lastCalledWith({
277
+ method: "arkiv_query",
278
+ params: [
279
+ `key = "value"`,
280
+ {
281
+ orderBy: [{ name: "key", type: "string", descending: true }],
282
+ includeData: {
283
+ key: true,
284
+ attributes: false,
285
+ contentType: false,
286
+ payload: false,
287
+ expiration: false,
288
+ owner: false,
289
+ },
290
+ },
291
+ ],
292
+ })
293
+ })
294
+
295
+ it("should process only orderBy", async () => {
296
+ const predicates = [] as Predicate[]
297
+ await processQuery(client, {
298
+ predicates,
299
+ limit: undefined,
300
+ cursor: undefined,
301
+ ownedBy: undefined,
302
+ orderBy: [{ name: "key", type: "string", descending: true }],
303
+ validAtBlock: undefined,
304
+ withAttributes: undefined,
305
+ withMetadata: undefined,
306
+ })
307
+
308
+ expect(client.request).lastCalledWith({
309
+ method: "arkiv_query",
310
+ params: [
311
+ "",
312
+ {
313
+ orderBy: [{ name: "key", type: "string", descending: true }],
314
+ includeData: {
315
+ key: true,
316
+ attributes: false,
317
+ contentType: false,
318
+ payload: false,
319
+ expiration: false,
320
+ owner: false,
321
+ },
322
+ },
323
+ ],
324
+ })
325
+ })
326
+
259
327
  it("should process simple predicate with validAtBlock and paging", async () => {
260
328
  const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
261
329
  await processQuery(client, {
262
330
  predicates,
263
331
  limit: 10,
264
332
  cursor: undefined,
333
+ orderBy: undefined,
265
334
  validAtBlock: 123n,
266
335
  ownedBy: "0x123",
267
336
  })
@@ -1,6 +1,6 @@
1
1
  import type { Hex } from "viem"
2
2
  import type { ArkivClient } from "../clients/baseClient"
3
- import type { RpcQueryOptions } from "../types/rpcSchema"
3
+ import type { RpcOrderByAttribute, RpcQueryOptions } from "../types/rpcSchema"
4
4
  import type { Predicate } from "./predicate"
5
5
 
6
6
  function processPredicates(predicates: Predicate[]): string {
@@ -45,6 +45,7 @@ export async function processQuery(
45
45
  limit: number | undefined
46
46
  cursor: string | undefined
47
47
  ownedBy: Hex | undefined
48
+ orderBy: RpcOrderByAttribute[] | undefined
48
49
  validAtBlock?: bigint | undefined
49
50
  withAttributes?: boolean | undefined
50
51
  withMetadata?: boolean | undefined
@@ -56,6 +57,7 @@ export async function processQuery(
56
57
  limit,
57
58
  cursor,
58
59
  ownedBy,
60
+ orderBy,
59
61
  validAtBlock,
60
62
  withAttributes,
61
63
  withMetadata,
@@ -63,7 +65,7 @@ export async function processQuery(
63
65
  } = queryParams
64
66
 
65
67
  console.debug(
66
- `Processing query with params: predicates: ${predicates}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`,
68
+ `Processing query with params: predicates: ${JSON.stringify(predicates)}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, orderBy: ${JSON.stringify(orderBy)}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`,
67
69
  )
68
70
 
69
71
  let query = processPredicates(predicates)
@@ -97,9 +99,12 @@ export async function processQuery(
97
99
  if (cursor !== undefined) {
98
100
  queryOptions.cursor = cursor
99
101
  }
102
+ if (orderBy !== undefined) {
103
+ queryOptions.orderBy = orderBy
104
+ }
100
105
 
101
106
  console.debug(
102
- `Built query to send: ${query}, queryOptions: ${JSON.stringify({ includeData: queryOptions.includeData, atBlock: queryOptions.atBlock?.toString(), resultsPerPage: queryOptions.resultsPerPage, cursor: queryOptions.cursor })}`,
107
+ `Built query to send: ${query}, queryOptions: ${JSON.stringify({ includeData: queryOptions.includeData, atBlock: queryOptions.atBlock?.toString(), orderBy: queryOptions.orderBy, resultsPerPage: queryOptions.resultsPerPage, cursor: queryOptions.cursor })}`,
103
108
  )
104
109
 
105
110
  const result = await client.request({
@@ -46,6 +46,7 @@ describe("QueryBuilder", () => {
46
46
  limit: undefined,
47
47
  offset: undefined,
48
48
  ownedBy: undefined,
49
+ orderBy: undefined,
49
50
  validBeforeBlock: undefined,
50
51
  withAttributes: undefined,
51
52
  withMetadata: undefined,
@@ -67,6 +68,7 @@ describe("QueryBuilder", () => {
67
68
  limit: undefined,
68
69
  offset: undefined,
69
70
  ownedBy: undefined,
71
+ orderBy: undefined,
70
72
  validBeforeBlock: undefined,
71
73
  withAttributes: undefined,
72
74
  withMetadata: undefined,
@@ -96,6 +98,7 @@ describe("QueryBuilder", () => {
96
98
  limit: undefined,
97
99
  offset: undefined,
98
100
  ownedBy: undefined,
101
+ orderBy: undefined,
99
102
  validBeforeBlock: undefined,
100
103
  withAttributes: undefined,
101
104
  withMetadata: undefined,
@@ -117,6 +120,7 @@ describe("QueryBuilder", () => {
117
120
  limit: undefined,
118
121
  offset: undefined,
119
122
  ownedBy: undefined,
123
+ orderBy: undefined,
120
124
  validBeforeBlock: undefined,
121
125
  withAttributes: undefined,
122
126
  withMetadata: undefined,
@@ -141,6 +145,7 @@ describe("QueryBuilder", () => {
141
145
  limit: undefined,
142
146
  offset: undefined,
143
147
  ownedBy: undefined,
148
+ orderBy: undefined,
144
149
  validBeforeBlock: undefined,
145
150
  withAttributes: undefined,
146
151
  withMetadata: undefined,
@@ -164,6 +169,7 @@ describe("QueryBuilder", () => {
164
169
  limit: undefined,
165
170
  offset: undefined,
166
171
  ownedBy: owner,
172
+ orderBy: undefined,
167
173
  validBeforeBlock: undefined,
168
174
  withAttributes: undefined,
169
175
  withMetadata: undefined,
@@ -171,6 +177,27 @@ describe("QueryBuilder", () => {
171
177
  })
172
178
  })
173
179
 
180
+ test("orderBy() sets orderBy", async () => {
181
+ mockProcessQuery.mockResolvedValue({
182
+ data: [],
183
+ })
184
+
185
+ const builder = new QueryBuilder(mockClient)
186
+ await builder.orderBy("name", "string", true).fetch()
187
+
188
+ expect(mockProcessQuery).toHaveBeenCalledWith(mockClient, {
189
+ predicates: [],
190
+ limit: undefined,
191
+ offset: undefined,
192
+ ownedBy: undefined,
193
+ orderBy: [{ name: "name", type: "string", desc: true }],
194
+ validAtBlock: undefined,
195
+ withAttributes: undefined,
196
+ withMetadata: undefined,
197
+ withPayload: undefined,
198
+ })
199
+ })
200
+
174
201
  test("limit() sets limit", async () => {
175
202
  mockProcessQuery.mockResolvedValue({
176
203
  data: [],
@@ -184,6 +211,7 @@ describe("QueryBuilder", () => {
184
211
  limit: 10,
185
212
  offset: undefined,
186
213
  ownedBy: undefined,
214
+ orderBy: undefined,
187
215
  validBeforeBlock: undefined,
188
216
  withAttributes: undefined,
189
217
  withMetadata: undefined,
@@ -204,6 +232,7 @@ describe("QueryBuilder", () => {
204
232
  limit: undefined,
205
233
  cursor: "0xABC123",
206
234
  ownedBy: undefined,
235
+ orderBy: undefined,
207
236
  validAtBlock: undefined,
208
237
  withAttributes: undefined,
209
238
  withMetadata: undefined,
@@ -224,6 +253,7 @@ describe("QueryBuilder", () => {
224
253
  limit: undefined,
225
254
  offset: undefined,
226
255
  ownedBy: undefined,
256
+ orderBy: undefined,
227
257
  validBeforeBlock: undefined,
228
258
  withAttributes: true,
229
259
  withMetadata: undefined,
@@ -244,6 +274,7 @@ describe("QueryBuilder", () => {
244
274
  limit: undefined,
245
275
  cursor: undefined,
246
276
  ownedBy: undefined,
277
+ orderBy: undefined,
247
278
  validBeforeBlock: undefined,
248
279
  withAttributes: false,
249
280
  withMetadata: undefined,
@@ -264,6 +295,7 @@ describe("QueryBuilder", () => {
264
295
  limit: undefined,
265
296
  cursor: undefined,
266
297
  ownedBy: undefined,
298
+ orderBy: undefined,
267
299
  validAtBlock: undefined,
268
300
  withAttributes: undefined,
269
301
  withMetadata: true,
@@ -284,6 +316,7 @@ describe("QueryBuilder", () => {
284
316
  limit: undefined,
285
317
  cursor: undefined,
286
318
  ownedBy: undefined,
319
+ orderBy: undefined,
287
320
  validAtBlock: undefined,
288
321
  withAttributes: undefined,
289
322
  withMetadata: false,
@@ -304,6 +337,7 @@ describe("QueryBuilder", () => {
304
337
  limit: undefined,
305
338
  cursor: undefined,
306
339
  ownedBy: undefined,
340
+ orderBy: undefined,
307
341
  validAtBlock: undefined,
308
342
  withAttributes: undefined,
309
343
  withMetadata: undefined,
@@ -1,5 +1,6 @@
1
1
  import type { Hex } from "viem"
2
2
  import type { ArkivClient } from "../clients/baseClient"
3
+ import type { RpcOrderByAttribute } from "../types/rpcSchema"
3
4
  import { entityFromRpcResult } from "../utils/entities"
4
5
  import { processQuery } from "./engine"
5
6
  import type { Predicate } from "./predicate"
@@ -14,6 +15,7 @@ import { QueryResult } from "./queryResult"
14
15
  export class QueryBuilder {
15
16
  private _client: ArkivClient
16
17
  private _ownedBy: Hex | undefined
18
+ private _orderBy: RpcOrderByAttribute[] | undefined
17
19
  private _validAtBlock: bigint | undefined
18
20
  private _withAttributes: boolean | undefined
19
21
  private _withMetadata: boolean | undefined
@@ -41,6 +43,35 @@ export class QueryBuilder {
41
43
  return this
42
44
  }
43
45
 
46
+ /**
47
+ * Sets the orderBy for the query.
48
+ * It can be called multiple times to order by multiple attributes.
49
+ * The order of the attributes is important. The first attribute is the primary order by attribute.
50
+ * @param attributeName - The name of the attribute to order by
51
+ * @param attributeType - The type of the attribute to order by (string or number)
52
+ * @param descending - The boolean value to set the order by descending
53
+ * @returns The QueryBuilder instance
54
+ *
55
+ * @example
56
+ * const builder = new QueryBuilder(client)
57
+ * builder.orderBy("name", "string", true)
58
+ */
59
+ orderBy(
60
+ attributeName: string,
61
+ attributeType: "string" | "number",
62
+ descending: boolean | undefined = undefined,
63
+ ) {
64
+ if (!this._orderBy) {
65
+ this._orderBy = []
66
+ }
67
+ this._orderBy.push({
68
+ name: attributeName,
69
+ type: attributeType === "number" ? "numeric" : attributeType,
70
+ desc: !!descending,
71
+ } as RpcOrderByAttribute)
72
+ return this
73
+ }
74
+
44
75
  /**
45
76
  * Sets the withAttributes flag which will return the attributes for the entities if true
46
77
  * @param withAttributes - The boolean value to set
@@ -167,6 +198,7 @@ export class QueryBuilder {
167
198
  limit: this._limit,
168
199
  cursor: this._cursor,
169
200
  ownedBy: this._ownedBy,
201
+ orderBy: this._orderBy,
170
202
  validAtBlock: this._validAtBlock,
171
203
  withAttributes: this._withAttributes,
172
204
  withMetadata: this._withMetadata,
@@ -198,6 +230,7 @@ export class QueryBuilder {
198
230
  limit: this._limit,
199
231
  cursor: this._cursor,
200
232
  ownedBy: this._ownedBy,
233
+ orderBy: undefined,
201
234
  validAtBlock: this._validAtBlock,
202
235
  withAttributes: false,
203
236
  withMetadata: false,
@@ -1,4 +1,17 @@
1
+ export type {
2
+ ChangeOwnershipParameters,
3
+ ChangeOwnershipReturnType,
4
+ } from "../actions/wallet/changeOwnership"
5
+ export type { CreateEntityParameters, CreateEntityReturnType } from "../actions/wallet/createEntity"
6
+ export type { DeleteEntityParameters, DeleteEntityReturnType } from "../actions/wallet/deleteEntity"
7
+ export type { ExtendEntityParameters, ExtendEntityReturnType } from "../actions/wallet/extendEntity"
8
+ export type {
9
+ MutateEntitiesParameters,
10
+ MutateEntitiesReturnType,
11
+ } from "../actions/wallet/mutateEntities"
12
+ export type { UpdateEntityParameters, UpdateEntityReturnType } from "../actions/wallet/updateEntity"
1
13
  export type { Attribute } from "./attributes"
2
14
  export type { Entity } from "./entity"
3
15
  export type { MimeType } from "./mimeTypes"
16
+ export type { ArkivRpcSchema, RpcEntity, RpcIncludeData, RpcQueryOptions } from "./rpcSchema"
4
17
  export type { TxParams } from "./txParams"
@@ -11,9 +11,16 @@ export type RpcEntity = {
11
11
  numericAttributes?: [{ key: string; value: number }]
12
12
  }
13
13
 
14
+ export type RpcOrderByAttribute = {
15
+ name: string
16
+ type: "string" | "numeric"
17
+ desc: boolean
18
+ }
19
+
14
20
  export type RpcQueryOptions = {
15
21
  atBlock?: number
16
22
  includeData?: RpcIncludeData
23
+ orderBy?: RpcOrderByAttribute[]
17
24
  resultsPerPage?: number
18
25
  cursor?: string
19
26
  }
@@ -1,41 +0,0 @@
1
- import { Hex } from "viem";
2
-
3
- //#region src/types/mimeTypes.d.ts
4
- type MimeType = "text/plain" | "text/html" | "text/css" | "text/csv" | "text/xml" | "text/javascript" | "application/json" | "application/xml" | "application/pdf" | "application/zip" | "application/gzip" | "application/octet-stream" | "application/javascript" | "application/x-www-form-urlencoded" | "image/png" | "image/jpeg" | "image/webp" | "image/gif" | "image/svg+xml" | "audio/mpeg" | "audio/wav" | "audio/ogg" | "video/mp4" | "video/webm" | "video/ogg" | "multipart/form-data";
5
- //#endregion
6
- //#region src/types/attributes.d.ts
7
- type Attribute = {
8
- key: string;
9
- value: string | number;
10
- };
11
- //#endregion
12
- //#region src/types/txParams.d.ts
13
- type TxParams = {
14
- gas?: bigint;
15
- nonce?: number;
16
- gasPrice?: bigint;
17
- maxFeePerGas?: never;
18
- maxPriorityFeePerGas?: never;
19
- } | {
20
- gas?: bigint;
21
- nonce?: number;
22
- maxFeePerGas?: bigint;
23
- maxPriorityFeePerGas?: bigint;
24
- gasPrice?: never;
25
- };
26
- //#endregion
27
- //#region src/types/entity.d.ts
28
- declare class Entity {
29
- key: Hex;
30
- owner: Hex;
31
- expiresAtBlock: bigint;
32
- payload: Uint8Array;
33
- attributes: Attribute[];
34
- contentType: MimeType;
35
- constructor(key: Hex, contentType: MimeType, owner: Hex, expiresAtBlock: bigint, payload: Uint8Array, attributes: Attribute[]);
36
- toText(): string;
37
- toJson(): any;
38
- }
39
- //#endregion
40
- export { MimeType as i, TxParams as n, Attribute as r, Entity as t };
41
- //# sourceMappingURL=entity-CMRcjXBK.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-CMRcjXBK.d.ts","names":[],"sources":["../src/types/mimeTypes.ts","../src/types/attributes.ts","../src/types/txParams.ts","../src/types/entity.ts"],"sourcesContent":[],"mappings":";;;KAAY,QAAA;;;KCAA,SAAA;;;ADAZ,CAAA;;;KEAY,QAAA;;;EFAA,QAAA,CAAA,EAAQ,MAAA;;;;ECAR,GAAA,CAAA,EAAA,MAAS;;;;ECAT,QAAA,CAAA,EAAQ,KAAA;;;;AFAR,cGIC,MAAA,CHJO;OGKb;SACE;;EFNG,OAAA,EEQD,UFRU;cESP;eACC;mBAGN,kBACQ,iBACN,sCAEE,wBACG;EDlBJ,MAAA,CAAA,CAAA,EAAA,MAAQ"}