@arkiv-network/sdk 0.3.2-dev.3 → 0.4.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +27 -13
  2. package/dist/chains/index.cjs +26 -1
  3. package/dist/chains/index.d.cts +44 -1
  4. package/dist/chains/index.d.cts.map +1 -1
  5. package/dist/chains/index.d.ts +69 -26
  6. package/dist/chains/index.d.ts.map +1 -1
  7. package/dist/chains/index.js +24 -1
  8. package/dist/chains/index.js.map +1 -1
  9. package/dist/{entity-BG8YycYJ.d.ts → entity-Bsvmepwv.d.cts} +25 -13
  10. package/dist/entity-Bsvmepwv.d.cts.map +1 -0
  11. package/dist/{entity-0JJeFAgO.d.cts → entity-ChTOBhd6.d.ts} +25 -13
  12. package/dist/entity-ChTOBhd6.d.ts.map +1 -0
  13. package/dist/index.cjs +31 -21
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +31 -21
  17. package/dist/index.js.map +1 -1
  18. package/dist/query/index.cjs +1 -1
  19. package/dist/query/index.d.cts +2 -2
  20. package/dist/query/index.d.ts +2 -2
  21. package/dist/query/index.js +1 -1
  22. package/dist/{queryBuilder-Dc_ii8LH.d.cts → queryBuilder-CNRqyot6.d.cts} +2 -2
  23. package/dist/{queryBuilder-Dc_ii8LH.d.cts.map → queryBuilder-CNRqyot6.d.cts.map} +1 -1
  24. package/dist/{queryBuilder-DEkfSiCF.cjs → queryBuilder-Cn5JJRMM.cjs} +79 -11
  25. package/dist/{queryBuilder-BNhnpewa.d.ts → queryBuilder-DI251Jjp.d.ts} +2 -2
  26. package/dist/{queryBuilder-BNhnpewa.d.ts.map → queryBuilder-DI251Jjp.d.ts.map} +1 -1
  27. package/dist/{queryBuilder-CAQ7TDMZ.js → queryBuilder-DVs4ZIyZ.js} +45 -13
  28. package/dist/queryBuilder-DVs4ZIyZ.js.map +1 -0
  29. package/dist/types/index.d.cts +1 -1
  30. package/dist/types/index.d.ts +1 -1
  31. package/dist/utils/index.cjs +1 -0
  32. package/dist/utils/index.d.cts.map +1 -1
  33. package/package.json +4 -2
  34. package/src/actions/public/getBlockTiming.ts +4 -1
  35. package/src/actions/public/subscribeEntityEvents.ts +6 -3
  36. package/src/actions/wallet/changeOwnership.ts +5 -2
  37. package/src/actions/wallet/createEntity.ts +8 -5
  38. package/src/actions/wallet/deleteEntity.ts +8 -5
  39. package/src/actions/wallet/extendEntity.ts +8 -5
  40. package/src/actions/wallet/mutateEntities.ts +8 -4
  41. package/src/actions/wallet/updateEntity.ts +8 -5
  42. package/src/chains/index.ts +1 -0
  43. package/src/chains/mendoza.ts +26 -0
  44. package/src/clients/decorators/arkivWallet.ts +1 -1
  45. package/src/query/engine.test.ts +75 -0
  46. package/src/query/engine.ts +28 -9
  47. package/src/query/queryBuilder.test.ts +8 -0
  48. package/src/query/queryResult.ts +4 -1
  49. package/src/types/entity.ts +22 -10
  50. package/src/types/rpcSchema.ts +9 -1
  51. package/src/utils/arkivTransactions.ts +6 -3
  52. package/src/utils/compression.ts +7 -4
  53. package/src/utils/entities.ts +15 -2
  54. package/src/utils/logger.ts +13 -0
  55. package/dist/entity-0JJeFAgO.d.cts.map +0 -1
  56. package/dist/entity-BG8YycYJ.d.ts.map +0 -1
  57. package/dist/queryBuilder-CAQ7TDMZ.js.map +0 -1
@@ -34,6 +34,10 @@ describe("processQuery tests", () => {
34
34
  payload: false,
35
35
  expiration: false,
36
36
  owner: false,
37
+ createdAtBlock: false,
38
+ lastModifiedAtBlock: false,
39
+ transactionIndexInBlock: false,
40
+ operationIndexInTransaction: false,
37
41
  },
38
42
  },
39
43
  ],
@@ -72,6 +76,10 @@ describe("processQuery tests", () => {
72
76
  payload: false,
73
77
  expiration: false,
74
78
  owner: false,
79
+ createdAtBlock: false,
80
+ lastModifiedAtBlock: false,
81
+ transactionIndexInBlock: false,
82
+ operationIndexInTransaction: false,
75
83
  },
76
84
  },
77
85
  ],
@@ -112,6 +120,10 @@ describe("processQuery tests", () => {
112
120
  payload: false,
113
121
  expiration: false,
114
122
  owner: false,
123
+ createdAtBlock: false,
124
+ lastModifiedAtBlock: false,
125
+ transactionIndexInBlock: false,
126
+ operationIndexInTransaction: false,
115
127
  },
116
128
  },
117
129
  ],
@@ -152,6 +164,10 @@ describe("processQuery tests", () => {
152
164
  payload: false,
153
165
  expiration: false,
154
166
  owner: false,
167
+ createdAtBlock: false,
168
+ lastModifiedAtBlock: false,
169
+ transactionIndexInBlock: false,
170
+ operationIndexInTransaction: false,
155
171
  },
156
172
  },
157
173
  ],
@@ -198,6 +214,10 @@ describe("processQuery tests", () => {
198
214
  payload: false,
199
215
  expiration: false,
200
216
  owner: false,
217
+ createdAtBlock: false,
218
+ lastModifiedAtBlock: false,
219
+ transactionIndexInBlock: false,
220
+ operationIndexInTransaction: false,
201
221
  },
202
222
  },
203
223
  ],
@@ -226,6 +246,10 @@ describe("processQuery tests", () => {
226
246
  payload: false,
227
247
  expiration: false,
228
248
  owner: false,
249
+ createdAtBlock: false,
250
+ lastModifiedAtBlock: false,
251
+ transactionIndexInBlock: false,
252
+ operationIndexInTransaction: false,
229
253
  },
230
254
  },
231
255
  ],
@@ -257,6 +281,10 @@ describe("processQuery tests", () => {
257
281
  payload: false,
258
282
  expiration: false,
259
283
  owner: false,
284
+ createdAtBlock: false,
285
+ lastModifiedAtBlock: false,
286
+ transactionIndexInBlock: false,
287
+ operationIndexInTransaction: false,
260
288
  },
261
289
  },
262
290
  ],
@@ -286,6 +314,10 @@ describe("processQuery tests", () => {
286
314
  payload: false,
287
315
  expiration: false,
288
316
  owner: false,
317
+ createdAtBlock: false,
318
+ lastModifiedAtBlock: false,
319
+ transactionIndexInBlock: false,
320
+ operationIndexInTransaction: false,
289
321
  },
290
322
  },
291
323
  ],
@@ -318,6 +350,10 @@ describe("processQuery tests", () => {
318
350
  payload: false,
319
351
  expiration: false,
320
352
  owner: false,
353
+ createdAtBlock: false,
354
+ lastModifiedAtBlock: false,
355
+ transactionIndexInBlock: false,
356
+ operationIndexInTransaction: false,
321
357
  },
322
358
  },
323
359
  ],
@@ -349,6 +385,45 @@ describe("processQuery tests", () => {
349
385
  payload: false,
350
386
  expiration: false,
351
387
  owner: false,
388
+ createdAtBlock: false,
389
+ lastModifiedAtBlock: false,
390
+ transactionIndexInBlock: false,
391
+ operationIndexInTransaction: false,
392
+ },
393
+ },
394
+ ],
395
+ })
396
+ })
397
+
398
+ it("should includeData all metadata if withMetadata is true", async () => {
399
+ const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
400
+ await processQuery(client, {
401
+ predicates,
402
+ limit: 10,
403
+ cursor: undefined,
404
+ orderBy: undefined,
405
+ validAtBlock: undefined,
406
+ ownedBy: "0x123",
407
+ withMetadata: true,
408
+ })
409
+
410
+ expect(client.request).lastCalledWith({
411
+ method: "arkiv_query",
412
+ params: [
413
+ `key = "value" && $owner=0x123`,
414
+ {
415
+ resultsPerPage: 10,
416
+ includeData: {
417
+ key: true,
418
+ attributes: false,
419
+ contentType: true,
420
+ payload: false,
421
+ expiration: true,
422
+ owner: true,
423
+ createdAtBlock: true,
424
+ lastModifiedAtBlock: true,
425
+ transactionIndexInBlock: true,
426
+ operationIndexInTransaction: true,
352
427
  },
353
428
  },
354
429
  ],
@@ -1,8 +1,11 @@
1
1
  import type { Hex } from "viem"
2
2
  import type { ArkivClient } from "../clients/baseClient"
3
- import type { RpcOrderByAttribute, RpcQueryOptions } from "../types/rpcSchema"
3
+ import type { RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions } from "../types/rpcSchema"
4
+ import { getLogger } from "../utils/logger"
4
5
  import type { Predicate } from "./predicate"
5
6
 
7
+ const logger = getLogger("query:engine")
8
+
6
9
  function processPredicates(predicates: Predicate[]): string {
7
10
  const processValue = (value: string | number) => {
8
11
  if (typeof value === "string") {
@@ -64,9 +67,17 @@ export async function processQuery(
64
67
  withPayload,
65
68
  } = queryParams
66
69
 
67
- console.debug(
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}`,
69
- )
70
+ logger("Processing query with params %o", {
71
+ predicates,
72
+ cursor,
73
+ limit,
74
+ ownedBy,
75
+ orderBy,
76
+ validAtBlock,
77
+ withAttributes,
78
+ withMetadata,
79
+ withPayload,
80
+ })
70
81
 
71
82
  let query = processPredicates(predicates)
72
83
  if (ownedBy) {
@@ -87,7 +98,11 @@ export async function processQuery(
87
98
  contentType: withMetadata ?? false,
88
99
  expiration: withMetadata ?? false,
89
100
  owner: withMetadata ?? false,
90
- },
101
+ createdAtBlock: withMetadata ?? false,
102
+ lastModifiedAtBlock: withMetadata ?? false,
103
+ transactionIndexInBlock: withMetadata ?? false,
104
+ operationIndexInTransaction: withMetadata ?? false,
105
+ } as RpcIncludeData,
91
106
  }
92
107
 
93
108
  if (validAtBlock !== undefined) {
@@ -103,15 +118,19 @@ export async function processQuery(
103
118
  queryOptions.orderBy = orderBy
104
119
  }
105
120
 
106
- console.debug(
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 })}`,
108
- )
121
+ logger("Built query to send %s %o", query, {
122
+ includeData: queryOptions.includeData,
123
+ atBlock: queryOptions.atBlock?.toString(),
124
+ orderBy: queryOptions.orderBy,
125
+ resultsPerPage: queryOptions.resultsPerPage,
126
+ cursor: queryOptions.cursor,
127
+ })
109
128
 
110
129
  const result = await client.request({
111
130
  method: "arkiv_query",
112
131
  params: [query, queryOptions],
113
132
  })
114
- console.debug("Raw result from query: ", result)
133
+ logger("Raw result from query %o", result)
115
134
 
116
135
  return result
117
136
  }
@@ -450,6 +450,10 @@ describe("QueryBuilder", () => {
450
450
  "application/json" as const,
451
451
  "0x123" as const,
452
452
  1000n,
453
+ 1000n,
454
+ 1000n,
455
+ 1000n,
456
+ 1000n,
453
457
  new Uint8Array(),
454
458
  [],
455
459
  )
@@ -458,6 +462,10 @@ describe("QueryBuilder", () => {
458
462
  "application/json" as const,
459
463
  "0x456" as const,
460
464
  2000n,
465
+ 2000n,
466
+ 2000n,
467
+ 2000n,
468
+ 2000n,
461
469
  new Uint8Array(),
462
470
  [],
463
471
  )
@@ -1,7 +1,10 @@
1
1
  import type { Entity } from "../types/entity"
2
+ import { getLogger } from "../utils/logger"
2
3
  import { NoCursorOrLimitError, NoMoreResultsError } from "./errors"
3
4
  import type { QueryBuilder } from "./queryBuilder"
4
5
 
6
+ const logger = getLogger("query:result")
7
+
5
8
  export class QueryResult {
6
9
  entities: Entity[]
7
10
  private _endOfIteration: boolean
@@ -52,7 +55,7 @@ export class QueryResult {
52
55
  this._cursor = result.cursor
53
56
 
54
57
  // TODO check current block height and if it is not too old
55
- console.debug("Current block height for next page: ", this._validAtBlock)
58
+ logger("Current block height for next page %s", this._validAtBlock?.toString() ?? "unknown")
56
59
  }
57
60
 
58
61
  hasNextPage() {
@@ -4,33 +4,45 @@ import type { Attribute } from "./attributes"
4
4
 
5
5
  export class Entity {
6
6
  key: Hex
7
- owner: Hex
8
- expiresAtBlock: bigint
9
- payload: Uint8Array
7
+ contentType: MimeType | undefined
8
+ owner: Hex | undefined
9
+ expiresAtBlock: bigint | undefined
10
+ createdAtBlock: bigint | undefined
11
+ lastModifiedAtBlock: bigint | undefined
12
+ transactionIndexInBlock: bigint | undefined
13
+ operationIndexInTransaction: bigint | undefined
14
+ payload: Uint8Array | undefined
10
15
  attributes: Attribute[]
11
- contentType: MimeType
12
16
 
13
17
  constructor(
14
18
  key: Hex,
15
- contentType: MimeType,
16
- owner: Hex,
17
- expiresAtBlock: bigint,
18
- payload: Uint8Array,
19
+ contentType: MimeType | undefined = undefined,
20
+ owner: Hex | undefined = undefined,
21
+ expiresAtBlock: bigint | undefined = undefined,
22
+ createdAtBlock: bigint | undefined = undefined,
23
+ lastModifiedAtBlock: bigint | undefined = undefined,
24
+ transactionIndexInBlock: bigint | undefined = undefined,
25
+ operationIndexInTransaction: bigint | undefined = undefined,
26
+ payload: Uint8Array | undefined = undefined,
19
27
  attributes: Attribute[],
20
28
  ) {
21
29
  this.key = key
22
30
  this.owner = owner
23
31
  this.expiresAtBlock = expiresAtBlock
32
+ this.createdAtBlock = createdAtBlock
33
+ this.lastModifiedAtBlock = lastModifiedAtBlock
34
+ this.transactionIndexInBlock = transactionIndexInBlock
35
+ this.operationIndexInTransaction = operationIndexInTransaction
24
36
  this.payload = payload
25
37
  this.attributes = attributes
26
38
  this.contentType = contentType
27
39
  }
28
40
 
29
41
  toText(): string {
30
- return bytesToString(this.payload)
42
+ return this.payload ? bytesToString(this.payload) : ""
31
43
  }
32
44
 
33
45
  toJson(): any {
34
- return JSON.parse(bytesToString(this.payload))
46
+ return this.payload ? JSON.parse(bytesToString(this.payload)) : {}
35
47
  }
36
48
  }
@@ -5,7 +5,11 @@ export type RpcEntity = {
5
5
  key: Hex
6
6
  contentType: MimeType
7
7
  value: string
8
- expiresAt: bigint
8
+ expiresAt: string
9
+ createdAtBlock: string
10
+ lastModifiedAtBlock: string
11
+ transactionIndexInBlock: string
12
+ operationIndexInTransaction: string
9
13
  owner: Hex
10
14
  stringAttributes?: [{ key: string; value: string }]
11
15
  numericAttributes?: [{ key: string; value: number }]
@@ -32,6 +36,10 @@ export type RpcIncludeData = {
32
36
  contentType: boolean
33
37
  expiration: boolean
34
38
  owner: boolean
39
+ createdAtBlock: boolean
40
+ lastModifiedAtBlock: boolean
41
+ transactionIndexInBlock: boolean
42
+ operationIndexInTransaction: boolean
35
43
  }
36
44
 
37
45
  export type ArkivRpcSchema = [
@@ -9,6 +9,9 @@ import type { WalletArkivClient } from "../clients/createWalletClient"
9
9
  import { ARKIV_ADDRESS, BLOCK_TIME } from "../consts"
10
10
  import type { TxParams } from "../types"
11
11
  import { compress } from "./compression"
12
+ import { getLogger } from "./logger"
13
+
14
+ const logger = getLogger("utils:arkiv-transactions")
12
15
 
13
16
  export function opsToTxData({
14
17
  creates,
@@ -64,7 +67,7 @@ export function opsToTxData({
64
67
  (ownershipChanges ?? []).map((item) => [item.entityKey, item.newOwner]),
65
68
  ]
66
69
 
67
- console.debug("txData to send as RLP", payload, payload.length)
70
+ logger("txData to send as RLP %o length %d", payload, payload.length)
68
71
 
69
72
  return toRlp(payload)
70
73
  }
@@ -73,7 +76,7 @@ export async function sendArkivTransaction(client: ArkivClient, data: Hex, txPar
73
76
  if (!client.account) throw new Error("Account required")
74
77
  const walletClient = client as WalletArkivClient
75
78
 
76
- console.debug("Sending transaction", {
79
+ logger("Sending transaction %o", {
77
80
  account: client.account,
78
81
  chain: client.chain,
79
82
  to: ARKIV_ADDRESS,
@@ -94,7 +97,7 @@ export async function sendArkivTransaction(client: ArkivClient, data: Hex, txPar
94
97
 
95
98
  const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash })
96
99
 
97
- console.debug("Tx receipt", receipt)
100
+ logger("Tx receipt %o", receipt)
98
101
 
99
102
  return receipt
100
103
  }
@@ -1,6 +1,9 @@
1
1
  // src/utils/compression.ts
2
2
 
3
3
  import type { BrotliWasmType } from "brotli-wasm"
4
+ import { getLogger } from "./logger"
5
+
6
+ const logger = getLogger("utils:compression")
4
7
 
5
8
  // Detect if we're in Node.js environment
6
9
  const isNode = typeof process !== "undefined" && process.versions?.node != null
@@ -39,7 +42,7 @@ async function getBrotli(): Promise<BrotliWasmType | null> {
39
42
  }
40
43
 
41
44
  export async function compress(data: Uint8Array): Promise<Uint8Array> {
42
- console.debug(`Compressing data (size: ${data.length})`)
45
+ logger("Compressing data size %d", data.length)
43
46
 
44
47
  // Try Node.js zlib first (if available)
45
48
  if (isNode) {
@@ -50,7 +53,7 @@ export async function compress(data: Uint8Array): Promise<Uint8Array> {
50
53
  const buffer = Buffer.from(data)
51
54
  const compressed = zlibModule.brotliCompressSync(buffer)
52
55
  const result = new Uint8Array(compressed)
53
- console.debug(`Brotli compressed with zlib (size: ${result.length})`)
56
+ logger("Brotli compressed with zlib size %d", result.length)
54
57
  return result
55
58
  } catch (error) {
56
59
  console.warn("zlib compression failed, falling back to brotli-wasm", error)
@@ -66,7 +69,7 @@ export async function compress(data: Uint8Array): Promise<Uint8Array> {
66
69
  }
67
70
 
68
71
  const brotliCompressed = brotliInstance.compress(data)
69
- console.debug(`Brotli compressed with wasm (size: ${brotliCompressed.length})`)
72
+ logger("Brotli compressed with wasm size %d", brotliCompressed.length)
70
73
  return brotliCompressed
71
74
  }
72
75
 
@@ -80,7 +83,7 @@ export async function decompress(data: Uint8Array): Promise<Uint8Array> {
80
83
  const buffer = Buffer.from(data)
81
84
  const decompressed = zlibModule.brotliDecompressSync(buffer)
82
85
  const result = new Uint8Array(decompressed)
83
- console.debug(`Brotli decompressed with zlib (size: ${result.length})`)
86
+ logger("Brotli decompressed with zlib size %d", result.length)
84
87
  return result
85
88
  } catch (error) {
86
89
  console.warn("zlib decompression failed, falling back to brotli-wasm", error)
@@ -1,14 +1,27 @@
1
1
  import { toBytes } from "viem"
2
2
  import { Entity } from "../types/entity"
3
3
  import type { RpcEntity } from "../types/rpcSchema"
4
+ import { getLogger } from "./logger"
5
+
6
+ const logger = getLogger("utils:entities")
4
7
 
5
8
  export async function entityFromRpcResult(rpcEntity: RpcEntity) {
9
+ logger("entityFromRpcResult %o", rpcEntity)
10
+
6
11
  return new Entity(
7
12
  rpcEntity.key,
8
13
  rpcEntity.contentType,
9
14
  rpcEntity.owner,
10
- rpcEntity.expiresAt,
11
- toBytes(rpcEntity.value),
15
+ rpcEntity.expiresAt !== undefined ? BigInt(rpcEntity.expiresAt) : undefined,
16
+ rpcEntity.createdAtBlock !== undefined ? BigInt(rpcEntity.createdAtBlock) : undefined,
17
+ rpcEntity.lastModifiedAtBlock !== undefined ? BigInt(rpcEntity.lastModifiedAtBlock) : undefined,
18
+ rpcEntity.transactionIndexInBlock !== undefined
19
+ ? BigInt(rpcEntity.transactionIndexInBlock)
20
+ : undefined,
21
+ rpcEntity.operationIndexInTransaction !== undefined
22
+ ? BigInt(rpcEntity.operationIndexInTransaction)
23
+ : undefined,
24
+ rpcEntity.value !== undefined ? toBytes(rpcEntity.value) : undefined,
12
25
  [
13
26
  ...(rpcEntity.stringAttributes ?? []).map(({ key, value }) => ({
14
27
  key,
@@ -0,0 +1,13 @@
1
+ import createDebug from "debug"
2
+
3
+ const ROOT_NAMESPACE = "arkiv"
4
+
5
+ export const getLogger = (scope: string) => createDebug(`${ROOT_NAMESPACE}:${scope}`)
6
+
7
+ export const enableDebug = (namespaces: string): void => {
8
+ createDebug.enable(namespaces)
9
+ }
10
+
11
+ export const disableDebug = (): void => {
12
+ createDebug.disable()
13
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-0JJeFAgO.d.cts","names":[],"sources":["../src/types/mimeTypes.ts","../src/types/rpcSchema.ts","../src/clients/baseClient.ts","../src/actions/wallet/changeOwnership.ts","../src/actions/wallet/createEntity.ts","../src/actions/wallet/deleteEntity.ts","../src/actions/wallet/extendEntity.ts","../src/actions/wallet/updateEntity.ts","../src/actions/wallet/mutateEntities.ts","../src/types/attributes.ts","../src/types/txParams.ts","../src/types/entity.ts"],"sourcesContent":[],"mappings":";;;KAAY,QAAA;;;KCGA,SAAA;EDHA,GAAA,ECIL,GDJK;eCKG;;;EAFH,KAAA,EAKH,GALG;EACL,gBAAA,CAAA,EAAA,CAAA;IACQ,GAAA,EAAA,MAAA;IAGN,KAAA,EAAA,MAAA;EAAG,CAAA,CAAA;EAKA,iBAAA,CAAA,EAAA,CAAA;IAMA,GAAA,EAAA,MAAA;IAQA,KAAA,EAAA,MAAc;EASd,CAAA,CAAA;;KAvBA,mBAAA;;ECVA,IAAA,EAAA,QAAW,GAAA,SAAA;EACH,IAAA,EAAA,OAAA;CAAY;AAChB,KDcJ,eAAA,GCdI;EAAoB,OAAA,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,EAAA;EAAG,MAAA,CAAA,CAAA,EAAA,MAAA;EAKA,MAAA,CAAA,CAAA,EAAA,GAAA;AAMZ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-BG8YycYJ.d.ts","names":[],"sources":["../src/types/mimeTypes.ts","../src/types/rpcSchema.ts","../src/clients/baseClient.ts","../src/actions/wallet/changeOwnership.ts","../src/actions/wallet/createEntity.ts","../src/actions/wallet/deleteEntity.ts","../src/actions/wallet/extendEntity.ts","../src/actions/wallet/updateEntity.ts","../src/actions/wallet/mutateEntities.ts","../src/types/attributes.ts","../src/types/txParams.ts","../src/types/entity.ts"],"sourcesContent":[],"mappings":";;;KAAY,QAAA;;;KCGA,SAAA;EDHA,GAAA,ECIL,GDJK;eCKG;;;EAFH,KAAA,EAKH,GALG;EACL,gBAAA,CAAA,EAAA,CAAA;IACQ,GAAA,EAAA,MAAA;IAGN,KAAA,EAAA,MAAA;EAAG,CAAA,CAAA;EAKA,iBAAA,CAAA,EAAA,CAAA;IAMA,GAAA,EAAA,MAAA;IAQA,KAAA,EAAA,MAAc;EASd,CAAA,CAAA;;KAvBA,mBAAA;;ECVA,IAAA,EAAA,QAAW,GAAA,SAAA;EACH,IAAA,EAAA,OAAA;CAAY;AAChB,KDcJ,eAAA,GCdI;EAAoB,OAAA,CAAA,EAAA,MAAA;EACT,WAAA,CAAA,EDeX,cCfW;EAAsB,OAAA,CAAA,EDgBrC,mBChBqC,EAAA;EAC7B,cAAA,CAAA,EAAA,MAAA;EAAwB,MAAA,CAAA,EAAA,MAAA;CACjC;AAAW,KDmBV,cAAA,GCnBU;EAAO,GAAA,EAAA,OAAA;EAAkB,UAAA,EAAA,OAAA;EAA3C,OAAA,EAAA,OAAA;EAAM,WAAA,EAAA,OAAA;;;;ACCE,KF2BA,cAAA,GE3BA,CAUA;;8CFoBoC;;IG3BpC,IAAA,EAAA,CH6BC,SG7BD,CAAsB;IACvB,WAAA,EAAA,MAAA;IACG,MAAA,EAAA,MAAA;EACC,CA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BAAA,GPsBoC;YOrBpC;YACA;YACA;ENjBA,UAAA,CAAA,EMkBG,sBNlBQ,EAAA;EACH,gBAAA,CAAA,EMkBC,yBNlBD,EAAA;CAAY;;;;;;;;;;AAIe,KM6DnC,wBAAA,GN7DmC;EAA3C,MAAA,EAAA,MAAA;EAAM,eAAA,EM+DS,GN/DT,EAAA;mBMgES;mBACA;oBACC;ELjER,gBAAA,EKkEQ,GLlER,EAAA;AAUZ,CAAA;;;KMnBY,SAAA;;;ATAZ,CAAA;;;KUAY,QAAA;;;EVAA,QAAA,CAAA,EAAQ,MAAA;;;;ECGR,GAAA,CAAA,EAAA,MAAS;EACd,KAAA,CAAA,EAAA,MAAA;EACQ,YAAA,CAAA,EAAA,MAAA;EAGN,oBAAA,CAAA,EAAA,MAAA;EAAG,QAAA,CAAA,EAAA,KAAA;AAKZ,CAAA;;;ADbY,cWIC,MAAA,CXJO;OWKb;SACE;;EVHG,OAAA,EUKD,UVLU;EACd,UAAA,EUKO,SVLP,EAAA;EACQ,WAAA,EUKA,QVLA;EAGN,WAAA,CAAA,GAAA,EUKA,GVLA,EAAA,WAAA,EUMQ,QVNR,EAAA,KAAA,EUOE,GVPF,EAAA,cAAA,EAAA,MAAA,EAAA,OAAA,EUSI,UVTJ,EAAA,UAAA,EUUO,SVVP,EAAA;EAAG,MAAA,CAAA,CAAA,EAAA,MAAA;EAKA,MAAA,CAAA,CAAA,EAAA,GAAA;AAMZ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"queryBuilder-CAQ7TDMZ.js","names":["predicate","queryOptions: RpcQueryOptions","order"],"sources":["../src/query/errors.ts","../src/types/entity.ts","../src/utils/entities.ts","../src/query/engine.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":["export class NoMoreResultsError extends Error {\n constructor() {\n super(\"No more results\")\n }\n}\n\nexport class NoCursorOrLimitError extends Error {\n constructor() {\n super(\"Cursor and limit must be defined to fetch next\")\n }\n}\n\nexport class OffsetCannotBeLessThanZeroError extends Error {\n constructor() {\n super(\"Offset cannot be less than 0\")\n }\n}\n\nexport class NoEntityFoundError extends Error {\n constructor() {\n super(\"No entity found\")\n }\n}\n","import { bytesToString, type Hex } from \"viem\"\nimport type { MimeType } from \"../types\"\nimport type { Attribute } from \"./attributes\"\n\nexport class Entity {\n key: Hex\n owner: Hex\n expiresAtBlock: bigint\n payload: Uint8Array\n attributes: Attribute[]\n contentType: MimeType\n\n constructor(\n key: Hex,\n contentType: MimeType,\n owner: Hex,\n expiresAtBlock: bigint,\n payload: Uint8Array,\n attributes: Attribute[],\n ) {\n this.key = key\n this.owner = owner\n this.expiresAtBlock = expiresAtBlock\n this.payload = payload\n this.attributes = attributes\n this.contentType = contentType\n }\n\n toText(): string {\n return bytesToString(this.payload)\n }\n\n toJson(): any {\n return JSON.parse(bytesToString(this.payload))\n }\n}\n","import { toBytes } from \"viem\"\nimport { Entity } from \"../types/entity\"\nimport type { RpcEntity } from \"../types/rpcSchema\"\n\nexport async function entityFromRpcResult(rpcEntity: RpcEntity) {\n return new Entity(\n rpcEntity.key,\n rpcEntity.contentType,\n rpcEntity.owner,\n rpcEntity.expiresAt,\n toBytes(rpcEntity.value),\n [\n ...(rpcEntity.stringAttributes ?? []).map(({ key, value }) => ({\n key,\n value,\n })),\n ...(rpcEntity.numericAttributes ?? []).map(({ key, value }) => ({\n key,\n value: Number(value),\n })),\n ],\n )\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcOrderByAttribute, RpcQueryOptions } from \"../types/rpcSchema\"\nimport type { Predicate } from \"./predicate\"\n\nfunction processPredicates(predicates: Predicate[]): string {\n const processValue = (value: string | number) => {\n if (typeof value === \"string\") {\n return `\"${value}\"`\n }\n return value\n }\n return predicates\n .map((predicate) => {\n switch (predicate.type) {\n case \"eq\":\n return `${predicate.key} = ${processValue(predicate.value)}`\n case \"neq\":\n return `${predicate.key} != ${processValue(predicate.value)}`\n case \"gt\":\n return `${predicate.key} > ${processValue(predicate.value)}`\n case \"gte\":\n return `${predicate.key} >= ${processValue(predicate.value)}`\n case \"lt\":\n return `${predicate.key} < ${processValue(predicate.value)}`\n case \"lte\":\n return `${predicate.key} <= ${processValue(predicate.value)}`\n case \"not\":\n return `!${predicate.key}`\n case \"or\":\n return `(${predicate.predicates.map((predicate) => processPredicates([predicate])).join(\" || \")})`\n case \"and\":\n return `(${predicate.predicates.map((predicate) => processPredicates([predicate])).join(\" && \")})`\n default:\n return \"\"\n }\n })\n .join(\" && \")\n}\n\nexport async function processQuery(\n client: ArkivClient,\n queryParams: {\n predicates: Predicate[]\n limit: number | undefined\n cursor: string | undefined\n ownedBy: Hex | undefined\n orderBy: RpcOrderByAttribute[] | undefined\n validAtBlock?: bigint | undefined\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n },\n) {\n const {\n predicates,\n limit,\n cursor,\n ownedBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n } = queryParams\n\n console.debug(\n `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}`,\n )\n\n let query = processPredicates(predicates)\n if (ownedBy) {\n query += ` && $owner=${ownedBy}`\n }\n\n // remove leading and trailing spaces and leading &&\n query = query.trim()\n if (query.startsWith(\"&& \")) {\n query = query.slice(3)\n }\n\n const queryOptions: RpcQueryOptions = {\n includeData: {\n key: true,\n attributes: withAttributes ?? false,\n payload: withPayload ?? false,\n contentType: withMetadata ?? false,\n expiration: withMetadata ?? false,\n owner: withMetadata ?? false,\n },\n }\n\n if (validAtBlock !== undefined) {\n queryOptions.atBlock = Number(validAtBlock)\n }\n if (limit !== undefined) {\n queryOptions.resultsPerPage = limit\n }\n if (cursor !== undefined) {\n queryOptions.cursor = cursor\n }\n if (orderBy !== undefined) {\n queryOptions.orderBy = orderBy\n }\n\n console.debug(\n `Built query to send: ${query}, queryOptions: ${JSON.stringify({ includeData: queryOptions.includeData, atBlock: queryOptions.atBlock?.toString(), orderBy: queryOptions.orderBy, resultsPerPage: queryOptions.resultsPerPage, cursor: queryOptions.cursor })}`,\n )\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, queryOptions],\n })\n console.debug(\"Raw result from query: \", result)\n\n return result\n}\n","import type { Entity } from \"../types/entity\"\nimport { NoCursorOrLimitError, NoMoreResultsError } from \"./errors\"\nimport type { QueryBuilder } from \"./queryBuilder\"\n\nexport class QueryResult {\n entities: Entity[]\n private _endOfIteration: boolean\n private _cursor: string | undefined\n private _limit: number | undefined\n private _validAtBlock: bigint | undefined\n private _queryBuilder: QueryBuilder\n\n // Public getters for internal state\n get queryBuilder(): QueryBuilder {\n return this._queryBuilder\n }\n\n get cursor(): string | undefined {\n return this._cursor\n }\n\n constructor(\n entities: Entity[],\n queryBuilder: QueryBuilder,\n cursor: string | undefined,\n limit: number | undefined,\n validAtBlock: bigint | undefined,\n ) {\n this.entities = entities\n this._queryBuilder = queryBuilder\n this._endOfIteration = !limit || entities.length < limit\n this._cursor = cursor\n this._limit = limit\n this._validAtBlock = validAtBlock\n }\n\n async next() {\n if (this._cursor === undefined || this._limit === undefined) {\n throw new NoCursorOrLimitError()\n }\n if (this._endOfIteration) {\n throw new NoMoreResultsError()\n }\n this._queryBuilder.cursor(this._cursor)\n const result = await this._queryBuilder.fetch()\n this.entities = result.entities\n // Update the query builder reference\n this._queryBuilder = result.queryBuilder\n // Check if we've reached the end (no more cursor or we got fewer entities than limit)\n this._endOfIteration = !result.cursor || result.entities.length < this._limit\n // Update the cursor\n this._cursor = result.cursor\n\n // TODO check current block height and if it is not too old\n console.debug(\"Current block height for next page: \", this._validAtBlock)\n }\n\n hasNextPage() {\n return !this._endOfIteration\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcOrderByAttribute } from \"../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../utils/entities\"\nimport { processQuery } from \"./engine\"\nimport type { Predicate } from \"./predicate\"\nimport { QueryResult } from \"./queryResult\"\n\ntype OrderByAttribute = {\n name: string\n type: \"string\" | \"number\"\n order: \"asc\" | \"desc\"\n}\n\n/**\n * Helper function to create an ascending order by attribute\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @returns The OrderByAttribute instance\n *\n * @example\n * const ascAttribute = asc(\"name\", \"string\")\n */\nexport function asc(attributeName: string, attributeType: \"string\" | \"number\"): OrderByAttribute {\n return {\n name: attributeName,\n type: attributeType,\n order: \"asc\",\n }\n}\n\n/**\n * Helper function to create a descending order by attribute\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @returns The OrderByAttribute instance\n *\n * @example\n * const descAttribute = desc(\"name\", \"string\")\n */\nexport function desc(attributeName: string, attributeType: \"string\" | \"number\"): OrderByAttribute {\n return {\n name: attributeName,\n type: attributeType,\n order: \"desc\",\n }\n}\n/**\n * QueryBuilder is a helper class to build queries to the Arkiv DBChains.\n * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.\n * @param client - The Arkiv client\n * @returns The QueryBuilder instance {@link QueryBuilder}\n */\nexport class QueryBuilder {\n private _client: ArkivClient\n private _ownedBy: Hex | undefined\n private _orderBy: RpcOrderByAttribute[] | undefined\n private _validAtBlock: bigint | undefined\n private _withAttributes: boolean | undefined\n private _withMetadata: boolean | undefined\n private _withPayload: boolean | undefined\n private _limit: number | undefined\n private _cursor: string | undefined\n private _predicates: Predicate[]\n\n constructor(client: ArkivClient) {\n this._client = client\n this._predicates = []\n }\n\n /**\n * Sets the ownedBy filter\n * @param ownedBy - The address of the owner\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.ownedBy(\"0x1234567890123456789012345678901234567890\")\n */\n ownedBy(ownedBy: Hex) {\n this._ownedBy = ownedBy\n return this\n }\n\n /**\n * Sets the orderBy for the query.\n * It can be called multiple times to order by multiple attributes.\n * The order of the attributes is important. The first attribute is the primary order by attribute.\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @param order - The order to set the order by (asc or desc)\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(\"name\", \"string\", \"desc\")\n */\n orderBy(attributeName: string, attributeType: \"string\" | \"number\", order?: \"asc\" | \"desc\"): this\n /**\n * Sets the orderBy for the query.\n * This method takes the OrderByAttribute object as an argument and is mainly\n * used to use the helper functions asc() and desc() to create the OrderByAttribute instances.\n * @param orderByAttribute - The OrderByAttribute instance to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(asc(\"name\", \"string\"))\n * builder.orderBy(desc(\"name\", \"string\"))\n */\n orderBy(orderByAttribute: OrderByAttribute): this\n orderBy(\n attributeNameOrOrderByAttribute: string | OrderByAttribute,\n attributeType?: \"string\" | \"number\",\n order: \"asc\" | \"desc\" = \"asc\",\n ) {\n if (!this._orderBy) {\n this._orderBy = []\n }\n\n const pushOrderByAttribute = ({ name, type, order }: OrderByAttribute) => {\n this._orderBy?.push({\n name,\n type: type === \"number\" ? \"numeric\" : type,\n desc: order === \"desc\",\n })\n }\n\n if (typeof attributeNameOrOrderByAttribute === \"string\") {\n if (!attributeType) {\n throw new Error(\"attributeType is required when using positional orderBy arguments\")\n }\n pushOrderByAttribute({\n name: attributeNameOrOrderByAttribute,\n type: attributeType,\n order,\n })\n } else {\n pushOrderByAttribute(attributeNameOrOrderByAttribute)\n }\n\n return this\n }\n\n /**\n * Sets the withAttributes flag which will return the attributes for the entities if true\n * @param withAttributes - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withAttributes(true)\n */\n withAttributes(withAttributes: boolean = true) {\n this._withAttributes = withAttributes\n return this\n }\n\n /**\n * Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true\n * @param withMetadata - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withMetadata(true)\n */\n withMetadata(withMetadata: boolean = true) {\n this._withMetadata = withMetadata\n return this\n }\n\n /**\n * Sets the withPayload flag which will return the payload for the entities if true\n * @param withPayload - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withPayload(true)\n */\n withPayload(withPayload: boolean = true) {\n this._withPayload = withPayload\n return this\n }\n\n /**\n * Sets the limit for the query\n * @param limit - The number of entities to return\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.limit(10)\n */\n limit(limit: number) {\n this._limit = limit\n return this\n }\n\n /**\n * 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).\n * @param cursor - The cursor to set which tells to RPC Query server where to start or continue the query.\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.offset(10)\n */\n cursor(cursor: string) {\n this._cursor = cursor\n return this\n }\n\n /**\n * Sets the validAtBlock for the query which tells at which block height the state we are intested.\n * If not set, the latest block is used.\n * @param validAtBlock - The block number to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.validAtBlock(10000)\n */\n validAtBlock(validAtBlock: bigint) {\n this._validAtBlock = validAtBlock\n return this\n }\n\n /**\n * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.\n * Predicates can be nested using 'or' and 'and' predicates.\n * @param predicates - The predicates to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.where(eq(\"name\", \"John\"))\n * builder.where([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), and([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), and([eq(\"age\", 32), eq(\"age\", 33)])])])])\n */\n where(predicates: Predicate[] | Predicate) {\n if (Array.isArray(predicates)) {\n this._predicates.push(...predicates)\n } else {\n this._predicates.push(predicates)\n }\n return this\n }\n\n /**\n * Fetches the entities from the query. Re\n * It will return a QueryResult instance which can be used to fetch the next and previous pages.\n * @returns The QueryResult instance {@link QueryResult}\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).fetch()\n * // result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }\n */\n async fetch() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: this._orderBy,\n validAtBlock: this._validAtBlock,\n withAttributes: this._withAttributes,\n withMetadata: this._withMetadata,\n withPayload: this._withPayload,\n })\n\n const entities = await Promise.all(\n queryResult.data.map((entity) => entityFromRpcResult(entity)),\n )\n\n this.cursor(queryResult.cursor)\n this.validAtBlock(queryResult.blockNumber)\n\n return new QueryResult(entities, this, this._cursor, this._limit, this._validAtBlock)\n }\n\n /**\n * Counts the entities from the query.\n * @returns The number of entities\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).count()\n * // result = 10\n */\n async count() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: undefined,\n validAtBlock: this._validAtBlock,\n withAttributes: false,\n withM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