@arkiv-network/sdk 0.6.8-dev.3 → 0.6.8-dev.4

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.
@@ -1,4 +1,4 @@
1
- import * as viem17 from "viem";
1
+ import * as viem8 from "viem";
2
2
 
3
3
  //#region src/chains/braga.d.ts
4
4
  declare const braga: {
@@ -11,13 +11,13 @@ declare const braga: {
11
11
  };
12
12
  blockTime?: number | undefined | undefined;
13
13
  contracts?: {
14
- [x: string]: viem17.ChainContract | {
15
- [sourceId: number]: viem17.ChainContract | undefined;
14
+ [x: string]: viem8.ChainContract | {
15
+ [sourceId: number]: viem8.ChainContract | undefined;
16
16
  } | undefined;
17
- ensRegistry?: viem17.ChainContract | undefined;
18
- ensUniversalResolver?: viem17.ChainContract | undefined;
19
- multicall3?: viem17.ChainContract | undefined;
20
- erc6492Verifier?: viem17.ChainContract | undefined;
17
+ ensRegistry?: viem8.ChainContract | undefined;
18
+ ensUniversalResolver?: viem8.ChainContract | undefined;
19
+ multicall3?: viem8.ChainContract | undefined;
20
+ erc6492Verifier?: viem8.ChainContract | undefined;
21
21
  } | undefined;
22
22
  ensTlds?: readonly string[] | undefined;
23
23
  id: 60138453102;
@@ -37,9 +37,9 @@ declare const braga: {
37
37
  sourceId?: number | undefined | undefined;
38
38
  testnet: true;
39
39
  custom?: Record<string, unknown> | undefined;
40
- fees?: viem17.ChainFees<undefined> | undefined;
40
+ fees?: viem8.ChainFees<undefined> | undefined;
41
41
  formatters?: undefined;
42
- serializers?: viem17.ChainSerializers<undefined, viem17.TransactionSerializable> | undefined;
42
+ serializers?: viem8.ChainSerializers<undefined, viem8.TransactionSerializable> | undefined;
43
43
  readonly network: "braga";
44
44
  };
45
45
  //#endregion
@@ -57,13 +57,13 @@ declare const kaolin: {
57
57
  };
58
58
  blockTime?: number | undefined | undefined;
59
59
  contracts?: {
60
- [x: string]: viem17.ChainContract | {
61
- [sourceId: number]: viem17.ChainContract | undefined;
60
+ [x: string]: viem8.ChainContract | {
61
+ [sourceId: number]: viem8.ChainContract | undefined;
62
62
  } | undefined;
63
- ensRegistry?: viem17.ChainContract | undefined;
64
- ensUniversalResolver?: viem17.ChainContract | undefined;
65
- multicall3?: viem17.ChainContract | undefined;
66
- erc6492Verifier?: viem17.ChainContract | undefined;
63
+ ensRegistry?: viem8.ChainContract | undefined;
64
+ ensUniversalResolver?: viem8.ChainContract | undefined;
65
+ multicall3?: viem8.ChainContract | undefined;
66
+ erc6492Verifier?: viem8.ChainContract | undefined;
67
67
  } | undefined;
68
68
  ensTlds?: readonly string[] | undefined;
69
69
  id: 60138453025;
@@ -83,9 +83,9 @@ declare const kaolin: {
83
83
  sourceId?: number | undefined | undefined;
84
84
  testnet: true;
85
85
  custom?: Record<string, unknown> | undefined;
86
- fees?: viem17.ChainFees<undefined> | undefined;
86
+ fees?: viem8.ChainFees<undefined> | undefined;
87
87
  formatters?: undefined;
88
- serializers?: viem17.ChainSerializers<undefined, viem17.TransactionSerializable> | undefined;
88
+ serializers?: viem8.ChainSerializers<undefined, viem8.TransactionSerializable> | undefined;
89
89
  readonly network: "kaolin";
90
90
  };
91
91
  //#endregion
@@ -105,13 +105,13 @@ declare const localhost: {
105
105
  } | undefined | undefined;
106
106
  blockTime?: number | undefined | undefined;
107
107
  contracts?: {
108
- [x: string]: viem17.ChainContract | {
109
- [sourceId: number]: viem17.ChainContract | undefined;
108
+ [x: string]: viem8.ChainContract | {
109
+ [sourceId: number]: viem8.ChainContract | undefined;
110
110
  } | undefined;
111
- ensRegistry?: viem17.ChainContract | undefined;
112
- ensUniversalResolver?: viem17.ChainContract | undefined;
113
- multicall3?: viem17.ChainContract | undefined;
114
- erc6492Verifier?: viem17.ChainContract | undefined;
111
+ ensRegistry?: viem8.ChainContract | undefined;
112
+ ensUniversalResolver?: viem8.ChainContract | undefined;
113
+ multicall3?: viem8.ChainContract | undefined;
114
+ erc6492Verifier?: viem8.ChainContract | undefined;
115
115
  } | undefined;
116
116
  ensTlds?: readonly string[] | undefined;
117
117
  id: 1337;
@@ -130,9 +130,9 @@ declare const localhost: {
130
130
  sourceId?: number | undefined | undefined;
131
131
  testnet?: boolean | undefined | undefined;
132
132
  custom?: Record<string, unknown> | undefined;
133
- fees?: viem17.ChainFees<undefined> | undefined;
133
+ fees?: viem8.ChainFees<undefined> | undefined;
134
134
  formatters?: undefined;
135
- serializers?: viem17.ChainSerializers<undefined, viem17.TransactionSerializable> | undefined;
135
+ serializers?: viem8.ChainSerializers<undefined, viem8.TransactionSerializable> | undefined;
136
136
  };
137
137
  //#endregion
138
138
  export { braga, kaolin, localhost };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/chains/braga.ts","../../src/chains/kaolin.ts","../../src/chains/localhost.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;MAuBX,SAAA,IAAA,EAAA,sBAAA;MAAA,SAAA,GAAA,EAAA,4CAAA;;;;;;iBAAA,MAAA,CAAA,aAAA;;;;;;;;ECpBW,OAAA,CAAA,EAuBX,SAAA,MAAA,EAAA,GAAA,SAAA;EAAA,EAAA,EAAA,WAAA;;;;;;;;;;;;;;EC1BW,QAAA,CAAA,EAAA,MAWX,GAAA,SAAA,GAAA,SAAA;EAAA,OAAA,EAAA,IAAA;;;;;;;;;;;;AFXW,cCGA,MDoBX,EAAA;EAAA,cAAA,EAAA;;;;;;;;;iBCGA,MAAA,CAAA,aAAA;;;;;IAvBW,UAuBX,CAAA,yBAAA,SAAA;IAAA,eAAA,CAAA,yBAAA,SAAA;;;;;;;;;;;;;;MC1BW,SAWX,SAAA,EAAA,SAAA,CAAA,yCAAA,CAAA;IAAA,CAAA;;;;;;;;;;;;cAXW;;;MFuBX,IAAA,EAAA,MAAA;MAAA,GAAA,EAAA,MAAA;;;;;;;;;;;iBEZA,MAAA,CAAA,aAAA;;;IDRW,WAuBX,CAAA,yBAAA,SAAA;IAAA,oBAAA,CAAA,yBAAA,SAAA;;;;;;;;;;;;;;IC1BW,SAWX,OAAA,EAAA;MAAA,SAAA,IAAA,EAAA,SAAA,CAAA,uBAAA,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/chains/braga.ts","../../src/chains/kaolin.ts","../../src/chains/localhost.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;MAuBX,SAAA,IAAA,EAAA,sBAAA;MAAA,SAAA,GAAA,EAAA,4CAAA;;;;;;iBAAA,KAAA,CAAA,aAAA;;;;;;;;ECpBW,OAAA,CAAA,EAuBX,SAAA,MAAA,EAAA,GAAA,SAAA;EAAA,EAAA,EAAA,WAAA;;;;;;;;;;;;;;EC1BW,QAAA,CAAA,EAAA,MAWX,GAAA,SAAA,GAAA,SAAA;EAAA,OAAA,EAAA,IAAA;;;;;;;;;;;;AFXW,cCGA,MDoBX,EAAA;EAAA,cAAA,EAAA;;;;;;;;;iBCGA,KAAA,CAAA,aAAA;;;;;IAvBW,UAuBX,CAAA,wBAAA,SAAA;IAAA,eAAA,CAAA,wBAAA,SAAA;;;;;;;;;;;;;;MC1BW,SAWX,SAAA,EAAA,SAAA,CAAA,yCAAA,CAAA;IAAA,CAAA;;;;;;;;;;;;cAXW;;;MFuBX,IAAA,EAAA,MAAA;MAAA,GAAA,EAAA,MAAA;;;;;;;;;;;iBEZA,KAAA,CAAA,aAAA;;;IDRW,WAuBX,CAAA,wBAAA,SAAA;IAAA,oBAAA,CAAA,wBAAA,SAAA;;;;;;;;;;;;;;IC1BW,SAWX,OAAA,EAAA;MAAA,SAAA,IAAA,EAAA,SAAA,CAAA,uBAAA,CAAA"}
@@ -1,4 +1,4 @@
1
- import * as viem0 from "viem";
1
+ import * as viem8 from "viem";
2
2
 
3
3
  //#region src/chains/braga.d.ts
4
4
  declare const braga: {
@@ -11,13 +11,13 @@ declare const braga: {
11
11
  };
12
12
  blockTime?: number | undefined | undefined;
13
13
  contracts?: {
14
- [x: string]: viem0.ChainContract | {
15
- [sourceId: number]: viem0.ChainContract | undefined;
14
+ [x: string]: viem8.ChainContract | {
15
+ [sourceId: number]: viem8.ChainContract | undefined;
16
16
  } | undefined;
17
- ensRegistry?: viem0.ChainContract | undefined;
18
- ensUniversalResolver?: viem0.ChainContract | undefined;
19
- multicall3?: viem0.ChainContract | undefined;
20
- erc6492Verifier?: viem0.ChainContract | undefined;
17
+ ensRegistry?: viem8.ChainContract | undefined;
18
+ ensUniversalResolver?: viem8.ChainContract | undefined;
19
+ multicall3?: viem8.ChainContract | undefined;
20
+ erc6492Verifier?: viem8.ChainContract | undefined;
21
21
  } | undefined;
22
22
  ensTlds?: readonly string[] | undefined;
23
23
  id: 60138453102;
@@ -37,9 +37,9 @@ declare const braga: {
37
37
  sourceId?: number | undefined | undefined;
38
38
  testnet: true;
39
39
  custom?: Record<string, unknown> | undefined;
40
- fees?: viem0.ChainFees<undefined> | undefined;
40
+ fees?: viem8.ChainFees<undefined> | undefined;
41
41
  formatters?: undefined;
42
- serializers?: viem0.ChainSerializers<undefined, viem0.TransactionSerializable> | undefined;
42
+ serializers?: viem8.ChainSerializers<undefined, viem8.TransactionSerializable> | undefined;
43
43
  readonly network: "braga";
44
44
  };
45
45
  //#endregion
@@ -57,13 +57,13 @@ declare const kaolin: {
57
57
  };
58
58
  blockTime?: number | undefined | undefined;
59
59
  contracts?: {
60
- [x: string]: viem0.ChainContract | {
61
- [sourceId: number]: viem0.ChainContract | undefined;
60
+ [x: string]: viem8.ChainContract | {
61
+ [sourceId: number]: viem8.ChainContract | undefined;
62
62
  } | undefined;
63
- ensRegistry?: viem0.ChainContract | undefined;
64
- ensUniversalResolver?: viem0.ChainContract | undefined;
65
- multicall3?: viem0.ChainContract | undefined;
66
- erc6492Verifier?: viem0.ChainContract | undefined;
63
+ ensRegistry?: viem8.ChainContract | undefined;
64
+ ensUniversalResolver?: viem8.ChainContract | undefined;
65
+ multicall3?: viem8.ChainContract | undefined;
66
+ erc6492Verifier?: viem8.ChainContract | undefined;
67
67
  } | undefined;
68
68
  ensTlds?: readonly string[] | undefined;
69
69
  id: 60138453025;
@@ -83,9 +83,9 @@ declare const kaolin: {
83
83
  sourceId?: number | undefined | undefined;
84
84
  testnet: true;
85
85
  custom?: Record<string, unknown> | undefined;
86
- fees?: viem0.ChainFees<undefined> | undefined;
86
+ fees?: viem8.ChainFees<undefined> | undefined;
87
87
  formatters?: undefined;
88
- serializers?: viem0.ChainSerializers<undefined, viem0.TransactionSerializable> | undefined;
88
+ serializers?: viem8.ChainSerializers<undefined, viem8.TransactionSerializable> | undefined;
89
89
  readonly network: "kaolin";
90
90
  };
91
91
  //#endregion
@@ -105,13 +105,13 @@ declare const localhost: {
105
105
  } | undefined | undefined;
106
106
  blockTime?: number | undefined | undefined;
107
107
  contracts?: {
108
- [x: string]: viem0.ChainContract | {
109
- [sourceId: number]: viem0.ChainContract | undefined;
108
+ [x: string]: viem8.ChainContract | {
109
+ [sourceId: number]: viem8.ChainContract | undefined;
110
110
  } | undefined;
111
- ensRegistry?: viem0.ChainContract | undefined;
112
- ensUniversalResolver?: viem0.ChainContract | undefined;
113
- multicall3?: viem0.ChainContract | undefined;
114
- erc6492Verifier?: viem0.ChainContract | undefined;
111
+ ensRegistry?: viem8.ChainContract | undefined;
112
+ ensUniversalResolver?: viem8.ChainContract | undefined;
113
+ multicall3?: viem8.ChainContract | undefined;
114
+ erc6492Verifier?: viem8.ChainContract | undefined;
115
115
  } | undefined;
116
116
  ensTlds?: readonly string[] | undefined;
117
117
  id: 1337;
@@ -130,9 +130,9 @@ declare const localhost: {
130
130
  sourceId?: number | undefined | undefined;
131
131
  testnet?: boolean | undefined | undefined;
132
132
  custom?: Record<string, unknown> | undefined;
133
- fees?: viem0.ChainFees<undefined> | undefined;
133
+ fees?: viem8.ChainFees<undefined> | undefined;
134
134
  formatters?: undefined;
135
- serializers?: viem0.ChainSerializers<undefined, viem0.TransactionSerializable> | undefined;
135
+ serializers?: viem8.ChainSerializers<undefined, viem8.TransactionSerializable> | undefined;
136
136
  };
137
137
  //#endregion
138
138
  export { braga, kaolin, localhost };
@@ -14,28 +14,30 @@ type Predicate = {
14
14
  };
15
15
  /**
16
16
  * Creates an OR predicate
17
- * @param predicates - The predicates to combine
17
+ * @param predicates - The predicates to combine, either as a single array or as separate arguments
18
18
  * @returns The OR predicate
19
19
  *
20
20
  * @example
21
- * const predicates = [eq("name", "John"), eq("age", 30)]
22
- * const result = or(predicates)
21
+ * const result = or(eq("name", "John"), eq("age", 30))
22
+ * // or equivalently: or([eq("name", "John"), eq("age", 30)])
23
23
  * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
24
24
  *
25
25
  */
26
26
  declare function or(predicates: Predicate[]): Predicate;
27
+ declare function or(...predicates: Predicate[]): Predicate;
27
28
  /**
28
29
  * Creates an AND predicate
29
- * @param predicates - The predicates to combine
30
+ * @param predicates - The predicates to combine, either as a single array or as separate arguments
30
31
  * @returns The AND predicate
31
32
  *
32
33
  * @example
33
- * const predicates = [eq("name", "John"), eq("age", 30)]
34
- * const result = and(predicates)
34
+ * const result = and(eq("name", "John"), eq("age", 30))
35
+ * // or equivalently: and([eq("name", "John"), eq("age", 30)])
35
36
  * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
36
37
  *
37
38
  */
38
39
  declare function and(predicates: Predicate[]): Predicate;
40
+ declare function and(...predicates: Predicate[]): Predicate;
39
41
  /**
40
42
  * Creates an equality predicate
41
43
  * @param key - The key to compare
@@ -325,22 +327,24 @@ declare abstract class BaseQueryBuilder<TEntity> {
325
327
  */
326
328
  validAtBlock(validAtBlock: bigint): this;
327
329
  /**
328
- * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
330
+ * Sets the predicates for the query limiting the results. It can be a single predicate,
331
+ * multiple predicates passed as separate arguments, or an array of predicates - all combined with 'and'.
329
332
  * Predicates can be nested using 'or' and 'and' predicates.
330
- * @param predicates - The predicates to set
333
+ * @param predicates - The predicates to set, either as a single array or as separate arguments
331
334
  * @returns The query builder instance
332
335
  *
333
336
  * @example
334
337
  * const builder = client.select()
335
338
  * builder.where(eq("name", "John"))
339
+ * builder.where(eq("name", "John"), eq("age", 30))
336
340
  * builder.where([eq("name", "John"), eq("age", 30)])
337
- * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
338
- * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
339
- * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
340
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
341
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
341
+ * builder.where(eq("name", "John"), or(eq("age", 30), eq("age", 31)))
342
+ * builder.where(eq("name", "John"), and(eq("age", 30), eq("age", 31)))
343
+ * builder.where(eq("name", "John"), or(eq("age", 30), and(eq("age", 31), eq("age", 32))))
344
+ * builder.where(eq("name", "John"), and(eq("age", 30), or(eq("age", 31), eq("age", 32))))
342
345
  */
343
- where(predicates: Predicate[] | Predicate): this;
346
+ where(predicates: Predicate[]): this;
347
+ where(...predicates: Predicate[]): this;
344
348
  /**
345
349
  * Returns the data-selection parameters forwarded to the query engine.
346
350
  * Subclasses decide which parts of an entity are fetched.
@@ -453,4 +457,4 @@ declare class SelectQueryBuilder<TEntity> extends BaseQueryBuilder<TEntity> {
453
457
  }
454
458
  //#endregion
455
459
  export { neq as C, lte as S, or as T, and as _, asc as a, gte as b, FullEntity as c, SelectionFields as d, selectionToIncludeData as f, PredicateType as g, PredicateContainerType as h, SelectQueryBuilder as i, ProjectedEntity as l, Predicate as m, OrderByAttribute as n, desc as o, QueryResult as p, QueryBuilder as r, EntitySelection as s, BaseQueryBuilder as t, SelectArg as u, eq as v, not as w, lt as x, gt as y };
456
- //# sourceMappingURL=index-CzqHiUAo.d.ts.map
460
+ //# sourceMappingURL=index-ByaanQGD.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-ByaanQGD.d.ts","names":[],"sources":["../src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an OR predicate
17
- * @param predicates - The predicates to combine
17
+ * @param predicates - The predicates to combine, either as a single array or as separate arguments
18
18
  * @returns The OR predicate
19
19
  *
20
20
  * @example
21
- * const predicates = [eq("name", "John"), eq("age", 30)]
22
- * const result = or(predicates)
21
+ * const result = or(eq("name", "John"), eq("age", 30))
22
+ * // or equivalently: or([eq("name", "John"), eq("age", 30)])
23
23
  * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
24
24
  *
25
25
  */
26
26
  declare function or(predicates: Predicate[]): Predicate;
27
+ declare function or(...predicates: Predicate[]): Predicate;
27
28
  /**
28
29
  * Creates an AND predicate
29
- * @param predicates - The predicates to combine
30
+ * @param predicates - The predicates to combine, either as a single array or as separate arguments
30
31
  * @returns The AND predicate
31
32
  *
32
33
  * @example
33
- * const predicates = [eq("name", "John"), eq("age", 30)]
34
- * const result = and(predicates)
34
+ * const result = and(eq("name", "John"), eq("age", 30))
35
+ * // or equivalently: and([eq("name", "John"), eq("age", 30)])
35
36
  * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
36
37
  *
37
38
  */
38
39
  declare function and(predicates: Predicate[]): Predicate;
40
+ declare function and(...predicates: Predicate[]): Predicate;
39
41
  /**
40
42
  * Creates an equality predicate
41
43
  * @param key - The key to compare
@@ -325,22 +327,24 @@ declare abstract class BaseQueryBuilder<TEntity> {
325
327
  */
326
328
  validAtBlock(validAtBlock: bigint): this;
327
329
  /**
328
- * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
330
+ * Sets the predicates for the query limiting the results. It can be a single predicate,
331
+ * multiple predicates passed as separate arguments, or an array of predicates - all combined with 'and'.
329
332
  * Predicates can be nested using 'or' and 'and' predicates.
330
- * @param predicates - The predicates to set
333
+ * @param predicates - The predicates to set, either as a single array or as separate arguments
331
334
  * @returns The query builder instance
332
335
  *
333
336
  * @example
334
337
  * const builder = client.select()
335
338
  * builder.where(eq("name", "John"))
339
+ * builder.where(eq("name", "John"), eq("age", 30))
336
340
  * builder.where([eq("name", "John"), eq("age", 30)])
337
- * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
338
- * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
339
- * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
340
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
341
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
341
+ * builder.where(eq("name", "John"), or(eq("age", 30), eq("age", 31)))
342
+ * builder.where(eq("name", "John"), and(eq("age", 30), eq("age", 31)))
343
+ * builder.where(eq("name", "John"), or(eq("age", 30), and(eq("age", 31), eq("age", 32))))
344
+ * builder.where(eq("name", "John"), and(eq("age", 30), or(eq("age", 31), eq("age", 32))))
342
345
  */
343
- where(predicates: Predicate[] | Predicate): this;
346
+ where(predicates: Predicate[]): this;
347
+ where(...predicates: Predicate[]): this;
344
348
  /**
345
349
  * Returns the data-selection parameters forwarded to the query engine.
346
350
  * Subclasses decide which parts of an entity are fetched.
@@ -453,4 +457,4 @@ declare class SelectQueryBuilder<TEntity> extends BaseQueryBuilder<TEntity> {
453
457
  }
454
458
  //#endregion
455
459
  export { neq as C, lte as S, or as T, and as _, asc as a, gte as b, FullEntity as c, SelectionFields as d, selectionToIncludeData as f, PredicateType as g, PredicateContainerType as h, SelectQueryBuilder as i, ProjectedEntity as l, Predicate as m, OrderByAttribute as n, desc as o, QueryResult as p, QueryBuilder as r, EntitySelection as s, BaseQueryBuilder as t, SelectArg as u, eq as v, not as w, lt as x, gt as y };
456
- //# sourceMappingURL=index-gj33r3rd.d.cts.map
460
+ //# sourceMappingURL=index-CS6sxVJC.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CS6sxVJC.d.cts","names":[],"sources":["../src/query/predicate.ts","../src/query/queryResult.ts","../src/query/selection.ts","../src/query/queryBuilder.ts"],"sour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const require_queryBuilder = require('./queryBuilder-K0ZkQGnx.cjs');
3
3
  const require_consts = require('./consts-AUoL-v42.cjs');
4
4
  require('./types-o3zWarRp.cjs');
5
5
  const require_payload = require('./payload-DpA5PA-w.cjs');
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as RpcIncludeData, C as QueryOptionsIncludeData, D as ArkivClient, E as GetBlockTimingReturnType, M as RpcQueryOptions, N as MimeType, O as ArkivRpcSchema, S as QueryOptions, T as QueryReturnType, _ as DeleteEntityReturnType, a as OnEntityExpiredEvent, b as ChangeOwnershipParameters, c as OnEntityUpdatedEvent, d as MutateEntitiesReturnType, f as UpdateEntityParameters, g as DeleteEntityParameters, h as ExtendEntityReturnType, i as OnEntityDeletedEvent, j as RpcOrderByAttribute, k as RpcEntity, l as Attribute, m as ExtendEntityParameters, n as TxParams, o as OnEntityExpiresInExtendedEvent, p as UpdateEntityReturnType, r as OnEntityCreatedEvent, s as OnEntityOwnerChangedEvent, t as Entity, u as MutateEntitiesParameters, v as CreateEntityParameters, w as QueryOptionsOrderBy, x as ChangeOwnershipReturnType, y as CreateEntityReturnType } from "./entity-BSU5-vyY.cjs";
2
- import { c as FullEntity, i as SelectQueryBuilder, l as ProjectedEntity, r as QueryBuilder, s as EntitySelection, u as SelectArg } from "./index-gj33r3rd.cjs";
2
+ import { c as FullEntity, i as SelectQueryBuilder, l as ProjectedEntity, r as QueryBuilder, s as EntitySelection, u as SelectArg } from "./index-CS6sxVJC.cjs";
3
3
  import { n as stringToPayload, t as jsonToPayload } from "./payload-CJN8fTvX.cjs";
4
4
  import { Account, Address, Chain, Client, Hex, ParseAccount, Prettify, PublicActions, PublicClientConfig, RpcSchema, Transport, WalletActions, WalletClientConfig } from "viem";
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as RpcIncludeData, C as QueryOptionsIncludeData, D as ArkivClient, E as GetBlockTimingReturnType, M as RpcQueryOptions, N as MimeType, O as ArkivRpcSchema, S as QueryOptions, T as QueryReturnType, _ as DeleteEntityReturnType, a as OnEntityExpiredEvent, b as ChangeOwnershipParameters, c as OnEntityUpdatedEvent, d as MutateEntitiesReturnType, f as UpdateEntityParameters, g as DeleteEntityParameters, h as ExtendEntityReturnType, i as OnEntityDeletedEvent, j as RpcOrderByAttribute, k as RpcEntity, l as Attribute, m as ExtendEntityParameters, n as TxParams, o as OnEntityExpiresInExtendedEvent, p as UpdateEntityReturnType, r as OnEntityCreatedEvent, s as OnEntityOwnerChangedEvent, t as Entity, u as MutateEntitiesParameters, v as CreateEntityParameters, w as QueryOptionsOrderBy, x as ChangeOwnershipReturnType, y as CreateEntityReturnType } from "./entity-CHiZ2Qu1.js";
2
- import { c as FullEntity, i as SelectQueryBuilder, l as ProjectedEntity, r as QueryBuilder, s as EntitySelection, u as SelectArg } from "./index-CzqHiUAo.js";
2
+ import { c as FullEntity, i as SelectQueryBuilder, l as ProjectedEntity, r as QueryBuilder, s as EntitySelection, u as SelectArg } from "./index-ByaanQGD.js";
3
3
  import { n as stringToPayload, t as jsonToPayload } from "./payload-B2kFJyah.js";
4
4
  import { Account, Address, Chain, Client, Hex, ParseAccount, Prettify, PublicActions, PublicClientConfig, RpcSchema, Transport, WalletActions, WalletClientConfig } from "viem";
5
5
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as chains_exports } from "./chains-CrtkVbBh.js";
2
- import { c as entityFromRpcResult, d as InvalidExpirationError, f as NoCursorOrLimitError, h as getLogger, l as EntityMutationError, m as NoMoreResultsError, n as QueryBuilder, p as NoEntityFoundError, r as SelectQueryBuilder, u as InvalidAttributeError } from "./queryBuilder-D-ACo-g_.js";
2
+ import { c as entityFromRpcResult, d as InvalidExpirationError, f as NoCursorOrLimitError, h as getLogger, l as EntityMutationError, m as NoMoreResultsError, n as QueryBuilder, p as NoEntityFoundError, r as SelectQueryBuilder, u as InvalidAttributeError } from "./queryBuilder-C3XSUYpn.js";
3
3
  import { n as BLOCK_TIME, t as ARKIV_ADDRESS } from "./consts-BV4PR-de.js";
4
4
  import "./types-H-TSmRpm.js";
5
5
  import { n as stringToPayload, t as jsonToPayload } from "./payload-Claf2jUO.js";
@@ -1,39 +1,17 @@
1
- const require_queryBuilder = require('../queryBuilder-CTPwve9u.cjs');
1
+ const require_queryBuilder = require('../queryBuilder-K0ZkQGnx.cjs');
2
2
  require('../consts-AUoL-v42.cjs');
3
3
 
4
4
  //#region src/query/predicate.ts
5
- /**
6
- * Creates an OR predicate
7
- * @param predicates - The predicates to combine
8
- * @returns The OR predicate
9
- *
10
- * @example
11
- * const predicates = [eq("name", "John"), eq("age", 30)]
12
- * const result = or(predicates)
13
- * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
14
- *
15
- */
16
- function or(predicates) {
5
+ function or(...predicates) {
17
6
  return {
18
7
  type: "or",
19
- predicates
8
+ predicates: predicates.flat()
20
9
  };
21
10
  }
22
- /**
23
- * Creates an AND predicate
24
- * @param predicates - The predicates to combine
25
- * @returns The AND predicate
26
- *
27
- * @example
28
- * const predicates = [eq("name", "John"), eq("age", 30)]
29
- * const result = and(predicates)
30
- * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
31
- *
32
- */
33
- function and(predicates) {
11
+ function and(...predicates) {
34
12
  return {
35
13
  type: "and",
36
- predicates
14
+ predicates: predicates.flat()
37
15
  };
38
16
  }
39
17
  /**
@@ -1,3 +1,3 @@
1
1
  import "../entity-BSU5-vyY.cjs";
2
- import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-gj33r3rd.cjs";
2
+ import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-CS6sxVJC.cjs";
3
3
  export { BaseQueryBuilder, EntitySelection, FullEntity, OrderByAttribute, Predicate, PredicateContainerType, PredicateType, ProjectedEntity, QueryBuilder, QueryResult, SelectArg, SelectQueryBuilder, SelectionFields, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or, selectionToIncludeData };
@@ -1,3 +1,3 @@
1
1
  import "../entity-CHiZ2Qu1.js";
2
- import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-CzqHiUAo.js";
2
+ import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-ByaanQGD.js";
3
3
  export { BaseQueryBuilder, EntitySelection, FullEntity, OrderByAttribute, Predicate, PredicateContainerType, PredicateType, ProjectedEntity, QueryBuilder, QueryResult, SelectArg, SelectQueryBuilder, SelectionFields, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or, selectionToIncludeData };
@@ -1,39 +1,17 @@
1
- import { a as desc, i as asc, n as QueryBuilder, o as selectionToIncludeData, r as SelectQueryBuilder, s as QueryResult, t as BaseQueryBuilder } from "../queryBuilder-D-ACo-g_.js";
1
+ import { a as desc, i as asc, n as QueryBuilder, o as selectionToIncludeData, r as SelectQueryBuilder, s as QueryResult, t as BaseQueryBuilder } from "../queryBuilder-C3XSUYpn.js";
2
2
  import "../consts-BV4PR-de.js";
3
3
 
4
4
  //#region src/query/predicate.ts
5
- /**
6
- * Creates an OR predicate
7
- * @param predicates - The predicates to combine
8
- * @returns The OR predicate
9
- *
10
- * @example
11
- * const predicates = [eq("name", "John"), eq("age", 30)]
12
- * const result = or(predicates)
13
- * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
14
- *
15
- */
16
- function or(predicates) {
5
+ function or(...predicates) {
17
6
  return {
18
7
  type: "or",
19
- predicates
8
+ predicates: predicates.flat()
20
9
  };
21
10
  }
22
- /**
23
- * Creates an AND predicate
24
- * @param predicates - The predicates to combine
25
- * @returns The AND predicate
26
- *
27
- * @example
28
- * const predicates = [eq("name", "John"), eq("age", 30)]
29
- * const result = and(predicates)
30
- * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
31
- *
32
- */
33
- function and(predicates) {
11
+ function and(...predicates) {
34
12
  return {
35
13
  type: "and",
36
- predicates
14
+ predicates: predicates.flat()
37
15
  };
38
16
  }
39
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/query/predicate.ts"],"sourcesContent":["export type PredicateType = \"eq\" | \"neq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"not\"\nexport type PredicateContainerType = \"or\" | \"and\"\n\nexport type Predicate =\n | {\n type: PredicateType\n key: string\n value: string | number\n }\n | {\n type: PredicateContainerType\n predicates: Predicate[]\n }\n\n/**\n * Creates an OR predicate\n * @param predicates - The predicates to combine\n * @returns The OR predicate\n *\n * @example\n * const predicates = [eq(\"name\", \"John\"), eq(\"age\", 30)]\n * const result = or(predicates)\n * // result = { type: \"or\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function or(predicates: Predicate[]): Predicate {\n return { type: \"or\", predicates }\n}\n\n/**\n * Creates an AND predicate\n * @param predicates - The predicates to combine\n * @returns The AND predicate\n *\n * @example\n * const predicates = [eq(\"name\", \"John\"), eq(\"age\", 30)]\n * const result = and(predicates)\n * // result = { type: \"and\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function and(predicates: Predicate[]): Predicate {\n return { type: \"and\", predicates }\n}\n\n/**\n * Creates an equality predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The equality predicate\n *\n * @example\n * const predicate = eq(\"name\", \"John\")\n * // result = { type: \"eq\", key: \"name\", value: \"John\" }\n */\nexport function eq(key: string, value: string | number): Predicate {\n return { type: \"eq\", key, value }\n}\n\n/**\n * Creates a not equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The not equal predicate\n *\n * @example\n * const predicate = neq(\"name\", \"John\")\n * // result = { type: \"neq\", key: \"name\", value: \"John\" }\n */\nexport function neq(key: string, value: string | number): Predicate {\n return { type: \"neq\", key, value }\n}\n\n/**\n * Creates a greater than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than predicate\n *\n * @example\n * const predicate = gt(\"name\", \"John\")\n * // result = { type: \"gt\", key: \"name\", value: \"John\" }\n */\nexport function gt(key: string, value: string | number): Predicate {\n return { type: \"gt\", key, value }\n}\n\n/**\n * Creates a greater than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than or equal predicate\n *\n * @example\n * const predicate = gte(\"name\", \"John\")\n * // result = { type: \"gte\", key: \"name\", value: \"John\" }\n */\nexport function gte(key: string, value: string | number): Predicate {\n return { type: \"gte\", key, value }\n}\n\n/**\n * Creates a less than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than predicate\n *\n * @example\n * const predicate = lt(\"name\", \"John\")\n * // result = { type: \"lt\", key: \"name\", value: \"John\" }\n */\nexport function lt(key: string, value: string | number): Predicate {\n return { type: \"lt\", key, value }\n}\n\n/**\n * Creates a less than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than or equal predicate\n *\n * @example\n * const predicate = lte(\"name\", \"John\")\n * // result = { type: \"lte\", key: \"name\", value: \"John\" }\n */\nexport function lte(key: string, value: string | number): Predicate {\n return { type: \"lte\", key, value }\n}\n\n/**\n * Creates a not predicate\n * @param key - The key to compare\n * @returns The not predicate\n *\n * @example\n * const predicate = not(\"name\")\n * // result = { type: \"not\", key: \"name\", value: \"\" }\n */\nexport function not(key: string): Predicate {\n return { type: \"not\", key, value: \"\" }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,GAAG,YAAoC;AACrD,QAAO;EAAE,MAAM;EAAM;EAAY;;;;;;;;;;;;;AAcnC,SAAgB,IAAI,YAAoC;AACtD,QAAO;EAAE,MAAM;EAAO;EAAY;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;AAYpC,SAAgB,IAAI,KAAwB;AAC1C,QAAO;EAAE,MAAM;EAAO;EAAK,OAAO;EAAI"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/query/predicate.ts"],"sourcesContent":["export type PredicateType = \"eq\" | \"neq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"not\"\nexport type PredicateContainerType = \"or\" | \"and\"\n\nexport type Predicate =\n | {\n type: PredicateType\n key: string\n value: string | number\n }\n | {\n type: PredicateContainerType\n predicates: Predicate[]\n }\n\n/**\n * Creates an OR predicate\n * @param predicates - The predicates to combine, either as a single array or as separate arguments\n * @returns The OR predicate\n *\n * @example\n * const result = or(eq(\"name\", \"John\"), eq(\"age\", 30))\n * // or equivalently: or([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * // result = { type: \"or\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function or(predicates: Predicate[]): Predicate\nexport function or(...predicates: Predicate[]): Predicate\nexport function or(...predicates: (Predicate | Predicate[])[]): Predicate {\n return { type: \"or\", predicates: predicates.flat() }\n}\n\n/**\n * Creates an AND predicate\n * @param predicates - The predicates to combine, either as a single array or as separate arguments\n * @returns The AND predicate\n *\n * @example\n * const result = and(eq(\"name\", \"John\"), eq(\"age\", 30))\n * // or equivalently: and([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * // result = { type: \"and\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function and(predicates: Predicate[]): Predicate\nexport function and(...predicates: Predicate[]): Predicate\nexport function and(...predicates: (Predicate | Predicate[])[]): Predicate {\n return { type: \"and\", predicates: predicates.flat() }\n}\n\n/**\n * Creates an equality predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The equality predicate\n *\n * @example\n * const predicate = eq(\"name\", \"John\")\n * // result = { type: \"eq\", key: \"name\", value: \"John\" }\n */\nexport function eq(key: string, value: string | number): Predicate {\n return { type: \"eq\", key, value }\n}\n\n/**\n * Creates a not equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The not equal predicate\n *\n * @example\n * const predicate = neq(\"name\", \"John\")\n * // result = { type: \"neq\", key: \"name\", value: \"John\" }\n */\nexport function neq(key: string, value: string | number): Predicate {\n return { type: \"neq\", key, value }\n}\n\n/**\n * Creates a greater than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than predicate\n *\n * @example\n * const predicate = gt(\"name\", \"John\")\n * // result = { type: \"gt\", key: \"name\", value: \"John\" }\n */\nexport function gt(key: string, value: string | number): Predicate {\n return { type: \"gt\", key, value }\n}\n\n/**\n * Creates a greater than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than or equal predicate\n *\n * @example\n * const predicate = gte(\"name\", \"John\")\n * // result = { type: \"gte\", key: \"name\", value: \"John\" }\n */\nexport function gte(key: string, value: string | number): Predicate {\n return { type: \"gte\", key, value }\n}\n\n/**\n * Creates a less than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than predicate\n *\n * @example\n * const predicate = lt(\"name\", \"John\")\n * // result = { type: \"lt\", key: \"name\", value: \"John\" }\n */\nexport function lt(key: string, value: string | number): Predicate {\n return { type: \"lt\", key, value }\n}\n\n/**\n * Creates a less than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than or equal predicate\n *\n * @example\n * const predicate = lte(\"name\", \"John\")\n * // result = { type: \"lte\", key: \"name\", value: \"John\" }\n */\nexport function lte(key: string, value: string | number): Predicate {\n return { type: \"lte\", key, value }\n}\n\n/**\n * Creates a not predicate\n * @param key - The key to compare\n * @returns The not predicate\n *\n * @example\n * const predicate = not(\"name\")\n * // result = { type: \"not\", key: \"name\", value: \"\" }\n */\nexport function not(key: string): Predicate {\n return { type: \"not\", key, value: \"\" }\n}\n"],"mappings":";;;;AA2BA,SAAgB,GAAG,GAAG,YAAoD;AACxE,QAAO;EAAE,MAAM;EAAM,YAAY,WAAW,MAAM;EAAE;;AAgBtD,SAAgB,IAAI,GAAG,YAAoD;AACzE,QAAO;EAAE,MAAM;EAAO,YAAY,WAAW,MAAM;EAAE;;;;;;;;;;;;AAavD,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;AAYpC,SAAgB,IAAI,KAAwB;AAC1C,QAAO;EAAE,MAAM;EAAO;EAAK,OAAO;EAAI"}
@@ -534,25 +534,8 @@ var BaseQueryBuilder = class {
534
534
  this._validAtBlock = validAtBlock;
535
535
  return this;
536
536
  }
537
- /**
538
- * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
539
- * Predicates can be nested using 'or' and 'and' predicates.
540
- * @param predicates - The predicates to set
541
- * @returns The query builder instance
542
- *
543
- * @example
544
- * const builder = client.select()
545
- * builder.where(eq("name", "John"))
546
- * builder.where([eq("name", "John"), eq("age", 30)])
547
- * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
548
- * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
549
- * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
550
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
551
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
552
- */
553
- where(predicates) {
554
- if (Array.isArray(predicates)) this._predicates.push(...predicates);
555
- else this._predicates.push(predicates);
537
+ where(...predicates) {
538
+ this._predicates.push(...predicates.flat());
556
539
  return this;
557
540
  }
558
541
  /**
@@ -710,4 +693,4 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
710
693
 
711
694
  //#endregion
712
695
  export { desc as a, entityFromRpcResult as c, InvalidExpirationError as d, NoCursorOrLimitError as f, getLogger as h, asc as i, EntityMutationError as l, NoMoreResultsError as m, QueryBuilder as n, selectionToIncludeData as o, NoEntityFoundError as p, SelectQueryBuilder as r, QueryResult as s, BaseQueryBuilder as t, InvalidAttributeError as u };
713
- //# sourceMappingURL=queryBuilder-D-ACo-g_.js.map
696
+ //# sourceMappingURL=queryBuilder-C3XSUYpn.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryBuilder-D-ACo-g_.js","names":["enabledNamespaces: Set<string>","disabledNamespaces: Set<string>","logger","logger","predicate","queryOptions: RpcQueryOptions","order"],"sources":["../src/utils/logger.ts","../src/errors.ts","../src/types/entity.ts","../src/utils/entities.ts","../src/query/engine.ts","../src/query/queryResult.ts","../src/query/selection.ts","../src/query/queryBuilder.ts"],"sourcesContent":["const ROOT_NAMESPACE = \"arkiv\"\n\n// Debug logger type - returns a function that can be called to log messages\ntype DebugLogger = (...args: unknown[]) => void\n\n// Get DEBUG environment variable (works in both Node.js and browser)\nfunction getDebugEnv(): string {\n if (typeof process !== \"undefined\") {\n const debugEnv = process?.env?.DEBUG\n if (debugEnv) {\n return debugEnv\n }\n }\n // Browser: check localStorage\n if (typeof globalThis !== \"undefined\" && \"localStorage\" in globalThis) {\n try {\n const storage = (globalThis as { localStorage?: Storage }).localStorage\n return storage?.getItem(\"DEBUG\") || \"\"\n } catch {\n // localStorage might not be available\n }\n }\n return \"\"\n}\n\n// Parse debug patterns and check if a namespace matches\nfunction matchesPattern(namespace: string, pattern: string): boolean {\n // Exact match\n if (pattern === namespace) return true\n\n // Wildcard match: \"arkiv:*\" matches \"arkiv:query\", \"arkiv:rpc\", etc.\n if (pattern.endsWith(\"*\")) {\n const prefix = pattern.slice(0, -1)\n return namespace.startsWith(prefix)\n }\n\n // Negative match: \"-arkiv:query\" excludes \"arkiv:query\"\n if (pattern.startsWith(\"-\")) {\n const excludePattern = pattern.slice(1)\n return !matchesPattern(namespace, excludePattern)\n }\n\n return false\n}\n\n// Check if a namespace is enabled for debugging\nfunction isEnabled(namespace: string): boolean {\n const debugEnv = getDebugEnv()\n if (!debugEnv) return false\n\n // Split by comma/space and check each pattern\n const patterns = debugEnv.split(/[\\s,]+/).filter((p) => p.length > 0)\n\n // If no patterns, nothing is enabled\n if (patterns.length === 0) return false\n\n // Check if any pattern matches (or if explicitly excluded)\n let enabled = false\n for (const pattern of patterns) {\n if (pattern.startsWith(\"-\")) {\n // Exclude pattern - if it matches, disable\n if (matchesPattern(namespace, pattern)) {\n return false\n }\n } else if (matchesPattern(namespace, pattern)) {\n enabled = true\n }\n }\n\n return enabled\n}\n\n// Store enabled namespaces (for programmatic enable/disable)\nconst enabledNamespaces: Set<string> = new Set()\nconst disabledNamespaces: Set<string> = new Set()\n\n// Color palette for namespace coloring (distinct, readable colors)\nconst COLOR_PALETTE = [\n \"#0000FF\", // blue\n \"#008000\", // green\n \"#FF0000\", // red\n \"#FF00FF\", // magenta\n \"#FFA500\", // orange\n \"#800080\", // purple\n \"#00CED1\", // dark turquoise\n \"#FF1493\", // deep pink\n \"#32CD32\", // lime green\n \"#1E90FF\", // dodger blue\n \"#FF4500\", // orange red\n \"#9370DB\", // medium purple\n \"#00FA9A\", // medium spring green\n \"#FFD700\", // gold\n \"#DC143C\", // crimson\n \"#00BFFF\", // deep sky blue\n \"#FF69B4\", // hot pink\n \"#20B2AA\", // light sea green\n \"#DA70D6\", // orchid\n \"#4682B4\", // steel blue\n]\n\n// Detect if we're in Node.js (for ANSI colors) or browser (for CSS colors)\nconst isNode = typeof process !== \"undefined\" && process.versions?.node != null\n\n// ANSI color codes for Node.js (bright, distinct colors)\nconst ANSI_COLORS = [\n \"\\x1b[94m\", // bright blue\n \"\\x1b[92m\", // bright green\n \"\\x1b[91m\", // bright red\n \"\\x1b[95m\", // bright magenta\n \"\\x1b[93m\", // bright yellow\n \"\\x1b[96m\", // bright cyan\n \"\\x1b[35m\", // magenta\n \"\\x1b[36m\", // cyan\n \"\\x1b[32m\", // green\n \"\\x1b[34m\", // blue\n \"\\x1b[33m\", // yellow\n \"\\x1b[31m\", // red\n \"\\x1b[90m\", // bright black (gray)\n \"\\x1b[37m\", // white\n \"\\x1b[1m\", // bold (as a color option)\n]\n\nconst ANSI_RESET = \"\\x1b[0m\"\nconst ANSI_BOLD = \"\\x1b[1m\"\n\n// Cache colors for namespaces (same namespace = same color)\nconst namespaceColors = new Map<string, { css: string; ansi: string }>()\n\n// Generate a consistent color for a namespace based on its hash\nfunction getColorForNamespace(namespace: string): { css: string; ansi: string } {\n // Check cache first\n const cachedColor = namespaceColors.get(namespace)\n if (cachedColor) {\n return cachedColor\n }\n\n // Simple hash function to convert string to number\n let hash = 0\n for (let i = 0; i < namespace.length; i++) {\n const char = namespace.charCodeAt(i)\n hash = (hash << 5) - hash + char\n hash = hash & hash // Convert to 32-bit integer\n }\n\n // Use absolute value and modulo to get index\n const colorIndex = Math.abs(hash) % COLOR_PALETTE.length\n const cssColor = COLOR_PALETTE[colorIndex]\n const ansiColor = ANSI_COLORS[colorIndex % ANSI_COLORS.length]\n\n const color = { css: cssColor, ansi: ansiColor }\n\n // Cache the color\n namespaceColors.set(namespace, color)\n\n return color\n}\n\n// Create a debug logger function\nfunction createDebugLogger(namespace: string): DebugLogger {\n // Get the color for this namespace (consistent across calls)\n const colors = getColorForNamespace(namespace)\n\n return (...args: unknown[]) => {\n // Check if enabled via environment variable or programmatically\n const envEnabled = isEnabled(namespace)\n const progEnabled = enabledNamespaces.has(namespace) && !disabledNamespaces.has(namespace)\n\n if (envEnabled || progEnabled) {\n if (isNode) {\n // Node.js: use ANSI color codes\n const coloredNamespace = `${ANSI_BOLD}${colors.ansi}${namespace}${ANSI_RESET}`\n console.log(coloredNamespace, ...args)\n } else {\n // Browser: use CSS styling with %c\n // The format is: console.log(\"%cstyled%cnormal\", style1, style2, ...args)\n // This colors the namespace, then resets for the rest\n const style1 = `color: ${colors.css}; font-weight: bold`\n const style2 = \"color: inherit; font-weight: normal\"\n // Combine namespace with a space, then log with styles\n console.log(`%c${namespace}%c`, style1, style2, ...args)\n }\n }\n }\n}\n\nexport const getLogger = (scope: string): DebugLogger => {\n const namespace = `${ROOT_NAMESPACE}:${scope}`\n return createDebugLogger(namespace)\n}\n\nexport const enableDebug = (namespaces: string): void => {\n // Parse and add namespaces to enabled set\n const patterns = namespaces.split(/[\\s,]+/).filter((p) => p.length > 0)\n for (const pattern of patterns) {\n if (pattern.startsWith(\"-\")) {\n // Remove from enabled, add to disabled\n const namespace = pattern.slice(1)\n enabledNamespaces.delete(namespace)\n disabledNamespaces.add(namespace)\n } else {\n enabledNamespaces.add(pattern)\n disabledNamespaces.delete(pattern)\n }\n }\n}\n\nexport const disableDebug = (): void => {\n enabledNamespaces.clear()\n disabledNamespaces.clear()\n}\n","import { BLOCK_TIME } from \"./consts\"\n\nexport class EntityMutationError extends Error {\n constructor(message: string) {\n super(message)\n this.name = \"EntityMutationError\"\n }\n}\nexport class InvalidExpirationError extends Error {\n constructor(expiresIn: unknown) {\n super(\n `Invalid expiresIn: ${String(expiresIn)}. expiresIn must be a positive integer and a multiple of the Arkiv block time (${BLOCK_TIME} seconds), because expiration is measured in whole blocks (1 block = ${BLOCK_TIME} seconds).`,\n )\n this.name = \"InvalidExpirationError\"\n }\n}\nexport class InvalidAttributeError extends Error {\n constructor(key: string, value: number) {\n super(\n `Invalid numeric value for attribute \"${key}\": ${String(value)}. Numeric attribute values must be integers. To keep numeric ordering/range queries, scale it to an integer (e.g. Math.round(${String(value)} * 1000), dividing by 1000 on read); otherwise store it as a string (e.g. \"${String(value)}\").`,\n )\n this.name = \"InvalidAttributeError\"\n }\n}\n\nexport class NoMoreResultsError extends Error {\n constructor() {\n super(\"No more results\")\n this.name = \"NoMoreResultsError\"\n }\n}\n\nexport class NoCursorOrLimitError extends Error {\n constructor() {\n super(\"Cursor and limit must be defined to fetch next\")\n this.name = \"NoCursorOrLimitError\"\n }\n}\n\nexport class NoEntityFoundError extends Error {\n constructor() {\n super(\"No entity found\")\n this.name = \"NoEntityFoundError\"\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 contentType: MimeType | undefined\n owner: Hex | undefined\n creator: Hex | undefined\n expiresAtBlock: bigint | undefined\n createdAtBlock: bigint | undefined\n lastModifiedAtBlock: bigint | undefined\n transactionIndexInBlock: bigint | undefined\n operationIndexInTransaction: bigint | undefined\n payload: Uint8Array | undefined\n attributes: Attribute[]\n\n constructor(\n key: Hex,\n contentType: MimeType | undefined = undefined,\n owner: Hex | undefined = undefined,\n creator: Hex | undefined = undefined,\n expiresAtBlock: bigint | undefined = undefined,\n createdAtBlock: bigint | undefined = undefined,\n lastModifiedAtBlock: bigint | undefined = undefined,\n transactionIndexInBlock: bigint | undefined = undefined,\n operationIndexInTransaction: bigint | undefined = undefined,\n payload: Uint8Array | undefined = undefined,\n attributes: Attribute[],\n ) {\n this.key = key\n this.owner = owner\n this.creator = creator\n this.expiresAtBlock = expiresAtBlock\n this.createdAtBlock = createdAtBlock\n this.lastModifiedAtBlock = lastModifiedAtBlock\n this.transactionIndexInBlock = transactionIndexInBlock\n this.operationIndexInTransaction = operationIndexInTransaction\n this.payload = payload\n this.attributes = attributes\n this.contentType = contentType\n }\n\n /**\n * Converts the entity payload from bytes to a string and returns it.\n * Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.\n * Throws an error if the conversion from bytes to string fails.\n * @returns The entity payload as a string.\n */\n toText(): string {\n if (this.payload === undefined) {\n throw new Error(\n \"Entity has no payload – it was probably queried without withPayload(true) via QueryBuilder\",\n )\n }\n try {\n return bytesToString(this.payload)\n } catch (e) {\n throw new Error(\n `Failed to convert entity payload to text: ${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n )\n }\n }\n\n /**\n * Parses the entity payload as JSON and returns the resulting object.\n * Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.\n * Throws an error if the payload is empty or cannot be parsed as JSON.\n * @returns The parsed JSON object from the entity payload.\n */\n toJson(): any {\n const text = this.toText()\n if (!text) {\n throw new Error(\"Entity has empty payload, cannot parse as JSON\")\n }\n try {\n return JSON.parse(text)\n } catch (e) {\n throw new Error(\n `Failed to parse entity payload as JSON: ${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n )\n }\n }\n}\n","import { toBytes } from \"viem\"\nimport { Entity } from \"../types/entity\"\nimport type { RpcEntity } from \"../types/rpcSchema\"\nimport { getLogger } from \"./logger\"\n\nconst logger = getLogger(\"utils:entities\")\n\nexport async function entityFromRpcResult(rpcEntity: RpcEntity) {\n logger(\"entityFromRpcResult %o\", rpcEntity)\n\n return new Entity(\n rpcEntity.key,\n rpcEntity.contentType,\n rpcEntity.owner,\n rpcEntity.creator,\n rpcEntity.expiresAt !== undefined ? BigInt(rpcEntity.expiresAt) : undefined,\n rpcEntity.createdAtBlock !== undefined ? BigInt(rpcEntity.createdAtBlock) : undefined,\n rpcEntity.lastModifiedAtBlock !== undefined ? BigInt(rpcEntity.lastModifiedAtBlock) : undefined,\n rpcEntity.transactionIndexInBlock !== undefined\n ? BigInt(rpcEntity.transactionIndexInBlock)\n : undefined,\n rpcEntity.operationIndexInTransaction !== undefined\n ? BigInt(rpcEntity.operationIndexInTransaction)\n : undefined,\n rpcEntity.value !== undefined ? toBytes(rpcEntity.value) : undefined,\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 { hexToNumber, numberToHex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions } from \"../types/rpcSchema\"\nimport { getLogger } from \"../utils/logger\"\nimport type { Predicate } from \"./predicate\"\n\nconst logger = getLogger(\"query:engine\")\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 createdBy: Hex | undefined\n orderBy: RpcOrderByAttribute[] | undefined\n validAtBlock?: bigint | undefined\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n /**\n * Fully-resolved include-data for fine-grained selection. When provided it takes\n * precedence over the `withAttributes`/`withMetadata`/`withPayload` booleans.\n */\n includeData?: RpcIncludeData | undefined\n },\n) {\n const {\n predicates,\n limit,\n cursor,\n ownedBy,\n createdBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n includeData,\n } = queryParams\n\n logger(\"Processing query with params %o\", {\n predicates,\n cursor,\n limit,\n ownedBy,\n createdBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n includeData,\n })\n\n let query = processPredicates(predicates)\n if (ownedBy) {\n query += ` && $owner=${ownedBy}`\n }\n if (createdBy) {\n query += ` && $creator=${createdBy}`\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 includeData ??\n ({\n key: true,\n attributes: withAttributes ?? false,\n payload: withPayload ?? false,\n contentType: withMetadata ?? false,\n expiration: withMetadata ?? false,\n owner: withMetadata ?? false,\n creator: withMetadata ?? false,\n createdAtBlock: withMetadata ?? false,\n lastModifiedAtBlock: withMetadata ?? false,\n transactionIndexInBlock: withMetadata ?? false,\n operationIndexInTransaction: withMetadata ?? false,\n } as RpcIncludeData),\n }\n\n if (validAtBlock !== undefined) {\n queryOptions.atBlock = numberToHex(validAtBlock)\n }\n if (limit !== undefined) {\n queryOptions.resultsPerPage = numberToHex(limit)\n }\n if (cursor !== undefined) {\n queryOptions.cursor = cursor\n }\n if (orderBy !== undefined) {\n queryOptions.orderBy = orderBy\n }\n\n logger(\"Built query to send %s %o\", query, {\n includeData: queryOptions.includeData,\n atBlock: queryOptions.atBlock ? hexToNumber(queryOptions.atBlock) : undefined,\n orderBy: queryOptions.orderBy,\n resultsPerPage: queryOptions.resultsPerPage,\n cursor: queryOptions.cursor,\n })\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, queryOptions],\n })\n logger(\"Raw result from query %o\", result)\n\n return result\n}\n","import { NoCursorOrLimitError, NoMoreResultsError } from \"../errors\"\nimport type { Entity } from \"../types/entity\"\nimport { getLogger } from \"../utils/logger\"\nimport type { BaseQueryBuilder } from \"./queryBuilder\"\n\nconst logger = getLogger(\"query:result\")\n\n/**\n * The result of a query. Holds the fetched entities and supports cursor-based pagination.\n *\n * @typeParam TEntity - The shape of each entity, inferred from the query builder\n * (a full {@link Entity}, or a projected object inferred from a `select()` selection).\n */\nexport class QueryResult<TEntity = Entity> {\n entities: TEntity[]\n private _endOfIteration: boolean\n private _cursor: string | undefined\n private _limit: number | undefined\n private _validAtBlock: bigint | undefined\n private _queryBuilder: BaseQueryBuilder<TEntity>\n\n // Public getters for internal state\n get queryBuilder(): BaseQueryBuilder<TEntity> {\n return this._queryBuilder\n }\n\n get cursor(): string | undefined {\n return this._cursor\n }\n\n constructor(\n entities: TEntity[],\n queryBuilder: BaseQueryBuilder<TEntity>,\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 logger(\"Current block height for next page %s\", this._validAtBlock?.toString() ?? \"unknown\")\n }\n\n hasNextPage() {\n return !this._endOfIteration\n }\n}\n","import type { Entity } from \"../types/entity\"\nimport type { RpcIncludeData } from \"../types/rpcSchema\"\n\n/** The entity fields that can be selected. These match the fields of {@link Entity} one-to-one. */\ntype DataKey =\n | \"key\"\n | \"contentType\"\n | \"owner\"\n | \"creator\"\n | \"expiresAtBlock\"\n | \"createdAtBlock\"\n | \"lastModifiedAtBlock\"\n | \"transactionIndexInBlock\"\n | \"operationIndexInTransaction\"\n | \"attributes\"\n | \"payload\"\n\n/**\n * The parts of an entity that can be selected. Every field is opt-in (including the `key`) and maps\n * directly to a field of the returned {@link Entity} — the selection is flat.\n */\nexport type SelectionFields = { [K in DataKey]?: boolean }\n\n/**\n * Requires at least one property of `T` to be present.\n * `{}` is not assignable, which is how `select({})` is rejected at compile time.\n */\ntype AtLeastOne<T, K extends keyof T = keyof T> = {\n [P in K]: Required<Pick<T, P>> & Partial<Omit<T, P>>\n}[K]\n\n/**\n * A non-empty entity selection — the object form accepted by `select()`. At least one field must be\n * selected.\n */\nexport type EntitySelection = AtLeastOne<SelectionFields>\n\n/** Argument accepted by `select()` — a non-empty {@link EntitySelection}, or `\"*\"` for everything. */\nexport type SelectArg = EntitySelection | \"*\"\n\n/**\n * The result of a selection `S`: an {@link Entity} narrowed to exactly the selected fields (each\n * non-`undefined`). The shape is flat and backwards compatible — e.g. `select({ owner: true })`\n * yields `{ owner: Hex }` accessed as `entity.owner`. Accessing an unselected field is a compile\n * error.\n *\n * The `toText()` / `toJson()` helpers operate on the payload, so they are only present when\n * `payload` was selected — calling them otherwise would always throw.\n */\nexport type ProjectedEntity<S> = {\n readonly [K in keyof S as S[K] extends true ? K : never]: K extends keyof Entity\n ? NonNullable<Entity[K]>\n : never\n} & (S extends { payload: true } ? Pick<Entity, \"toText\" | \"toJson\"> : unknown)\n\n/** A selection of every field, used to type the result of `select()` / `select(\"*\")`. */\ntype AllSelected = { [K in DataKey]: true }\n\n/** The projected entity type when everything is selected — every field, plus the methods. */\nexport type FullEntity = ProjectedEntity<AllSelected>\n\n/**\n * Converts a {@link SelectArg} into the {@link RpcIncludeData} understood by the query engine.\n * Every field is opt-in — anything not explicitly selected defaults to `false`, including the key.\n * `undefined` or `\"*\"` selects everything.\n *\n * @param selection - The selection to convert\n * @returns The fully-resolved include-data object for the RPC query\n * @throws If an empty selection object is provided\n *\n * @example\n * selectionToIncludeData() // everything\n * selectionToIncludeData(\"*\") // everything\n * selectionToIncludeData({ key: true }) // only the key\n * selectionToIncludeData({ owner: true }) // only the owner\n */\nexport function selectionToIncludeData(selection?: SelectArg): RpcIncludeData {\n if (selection === undefined || selection === \"*\") {\n return {\n key: true,\n attributes: true,\n payload: true,\n contentType: true,\n expiration: true,\n owner: true,\n creator: true,\n createdAtBlock: true,\n lastModifiedAtBlock: true,\n transactionIndexInBlock: true,\n operationIndexInTransaction: true,\n }\n }\n\n // At least one field must be opted in. This rejects both `{}` and selections whose fields are\n // all explicitly `false` (e.g. `select({ key: false })`), which the type system permits.\n if (!Object.values(selection).some((selected) => selected === true)) {\n throw new Error(\n 'select() requires at least one field to be selected. Pass select() or select(\"*\") to select everything.',\n )\n }\n\n return {\n key: selection.key ?? false,\n attributes: selection.attributes ?? false,\n payload: selection.payload ?? false,\n contentType: selection.contentType ?? false,\n // The selection uses the entity field name `expiresAtBlock`; the RPC calls it `expiration`.\n expiration: selection.expiresAtBlock ?? false,\n owner: selection.owner ?? false,\n creator: selection.creator ?? false,\n createdAtBlock: selection.createdAtBlock ?? false,\n lastModifiedAtBlock: selection.lastModifiedAtBlock ?? false,\n transactionIndexInBlock: selection.transactionIndexInBlock ?? false,\n operationIndexInTransaction: selection.operationIndexInTransaction ?? false,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { Entity } from \"../types/entity\"\nimport type { RpcEntity, RpcIncludeData, RpcOrderByAttribute } from \"../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../utils/entities\"\nimport { processQuery } from \"./engine\"\nimport type { Predicate } from \"./predicate\"\nimport { QueryResult } from \"./queryResult\"\nimport { type SelectArg, selectionToIncludeData } from \"./selection\"\n\nexport type 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 Input for orderBy method\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 Input for orderBy method\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/**\n * Data-selection parameters forwarded to the query engine on each fetch.\n * Subclasses of {@link BaseQueryBuilder} decide which parts of an entity are fetched.\n */\ntype SelectionParams = {\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n includeData?: RpcIncludeData | undefined\n}\n\n/**\n * BaseQueryBuilder holds the query-building logic shared by every query builder\n * (filtering, ordering, pagination, execution). It follows the Builder pattern,\n * allowing methods to be chained. Subclasses decide how data selection is expressed\n * by implementing the protected `selectionParams` method.\n *\n * Use {@link SelectQueryBuilder} via `client.select()` to build and execute queries.\n *\n * @typeParam TEntity - The shape of each entity produced by {@link BaseQueryBuilder.fetch}.\n */\nexport abstract class BaseQueryBuilder<TEntity> {\n protected _client: ArkivClient\n protected _ownedBy: Hex | undefined\n protected _createdBy: Hex | undefined\n protected _orderBy: RpcOrderByAttribute[] | undefined\n protected _validAtBlock: bigint | undefined\n protected _limit: number | undefined\n protected _cursor: string | undefined\n protected _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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.ownedBy(\"0x1234567890123456789012345678901234567890\")\n */\n ownedBy(ownedBy: Hex): this {\n this._ownedBy = ownedBy\n return this\n }\n\n /**\n * Sets the createdBy filter\n * @param createdBy - The address of the creator\n * @returns The query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.createdBy(\"0x1234567890123456789012345678901234567890\")\n */\n createdBy(createdBy: Hex): this {\n this._createdBy = createdBy\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 * You can use the helper functions asc() and desc() as input for this method.\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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.orderBy(\"name\", \"string\", \"desc\")\n * builder.orderBy(asc(\"name\", \"string\"))\n * builder.orderBy(desc(\"name\", \"string\"))\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 query builder instance\n *\n * @example\n * const builder = client.select()\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 ): this {\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 limit for the query\n * @param limit - The number of entities to return\n * @returns The query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.limit(10)\n */\n limit(limit: number): this {\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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.cursor(\"0xABC123\")\n */\n cursor(cursor: string): this {\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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.validAtBlock(10000)\n */\n validAtBlock(validAtBlock: bigint): this {\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 query builder instance\n *\n * @example\n * const builder = client.select()\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): this {\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 * Returns the data-selection parameters forwarded to the query engine.\n * Subclasses decide which parts of an entity are fetched.\n */\n protected abstract selectionParams(): SelectionParams\n\n /**\n * Builds a single result entity from a raw RPC entity. Subclasses decide the produced shape\n * (a full {@link Entity}, or a projected object inferred from the selection).\n */\n protected abstract projectEntity(rpcEntity: RpcEntity): TEntity | Promise<TEntity>\n\n /**\n * Fetches the entities from the query.\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 = client.select()\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(): Promise<QueryResult<TEntity>> {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n createdBy: this._createdBy,\n orderBy: this._orderBy,\n validAtBlock: this._validAtBlock,\n ...this.selectionParams(),\n })\n\n const entities = await Promise.all(queryResult.data.map((entity) => this.projectEntity(entity)))\n\n this.cursor(queryResult.cursor)\n this.validAtBlock(BigInt(queryResult.blockNumber ?? 0))\n\n return new QueryResult<TEntity>(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 = client.select()\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 createdBy: this._createdBy,\n orderBy: undefined,\n validAtBlock: this._validAtBlock,\n withAttributes: false,\n withMetadata: false,\n withPayload: false,\n })\n\n return queryResult.data.length ?? 0\n }\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 *\n * By default the result includes only the entity `key`. Additional data is opt-in through\n * `withAttributes()`, `withMetadata()` and `withPayload()`.\n *\n * @deprecated Use {@link SelectQueryBuilder} via `client.select()` instead. Declaring the\n * selection up front avoids the common mistake of forgetting to opt in to data and getting back\n * entities with only their `key` populated. This class remains for backwards compatibility and\n * will be removed in a future release.\n *\n * @param client - The Arkiv client\n * @returns The QueryBuilder instance {@link QueryBuilder}\n */\nexport class QueryBuilder extends BaseQueryBuilder<Entity> {\n private _withAttributes: boolean | undefined\n private _withMetadata: boolean | undefined\n private _withPayload: boolean | undefined\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 = client.buildQuery()\n * builder.withAttributes(true)\n */\n withAttributes(withAttributes: boolean = true): this {\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 = client.buildQuery()\n * builder.withMetadata(true)\n */\n withMetadata(withMetadata: boolean = true): this {\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 = client.buildQuery()\n * builder.withPayload(true)\n */\n withPayload(withPayload: boolean = true): this {\n this._withPayload = withPayload\n return this\n }\n\n protected selectionParams(): SelectionParams {\n return {\n withAttributes: this._withAttributes,\n withMetadata: this._withMetadata,\n withPayload: this._withPayload,\n }\n }\n\n protected projectEntity(rpcEntity: RpcEntity): Promise<Entity> {\n return entityFromRpcResult(rpcEntity)\n }\n}\n\n/**\n * SelectQueryBuilder is the recommended query builder. It requires the selection to be declared\n * up front, so results always contain exactly the data you asked for — and the type of each\n * returned entity is narrowed to exactly the selected fields.\n *\n * The selection is fixed at construction time and is flat — each field maps to an entity field.\n * Create one via `client.select(...)` rather than constructing it directly, so the result type is\n * inferred from the selection.\n *\n * @typeParam TEntity - The projected entity shape, inferred from the selection by `client.select()`.\n *\n * @example\n * // everything\n * await client.select().where(eq(\"name\", \"John\")).fetch()\n * await client.select(\"*\").where(eq(\"name\", \"John\")).fetch()\n * // specific fields\n * await client.select({ owner: true, attributes: true }).fetch()\n * // a single field — result is typed (flat) { owner: Hex }\n * await client.select({ owner: true }).fetch()\n */\nexport class SelectQueryBuilder<TEntity> extends BaseQueryBuilder<TEntity> {\n private _includeData: RpcIncludeData\n\n constructor(client: ArkivClient, selection?: SelectArg) {\n super(client)\n this._includeData = selectionToIncludeData(selection)\n }\n\n protected selectionParams(): SelectionParams {\n return { includeData: this._includeData }\n }\n\n protected async projectEntity(rpcEntity: RpcEntity): Promise<TEntity> {\n // The runtime value is a full Entity (with methods); the static type is narrowed to the\n // selected fields via `client.select()`'s inference.\n return (await entityFromRpcResult(rpcEntity)) as unknown as TEntity\n }\n}\n"],"mappings":";;;;AAAA,MAAM,iBAAiB;AAMvB,SAAS,cAAsB;AAC7B,KAAI,OAAO,YAAY,aAAa;EAClC,MAAM,WAAW,SAAS,KAAK;AAC/B,MAAI,SACF,QAAO;;AAIX,KAAI,OAAO,eAAe,eAAe,kBAAkB,WACzD,KAAI;AAEF,SADiB,WAA0C,cAC3C,QAAQ,QAAQ,IAAI;SAC9B;AAIV,QAAO;;AAIT,SAAS,eAAe,WAAmB,SAA0B;AAEnE,KAAI,YAAY,UAAW,QAAO;AAGlC,KAAI,QAAQ,SAAS,IAAI,EAAE;EACzB,MAAM,SAAS,QAAQ,MAAM,GAAG,GAAG;AACnC,SAAO,UAAU,WAAW,OAAO;;AAIrC,KAAI,QAAQ,WAAW,IAAI,CAEzB,QAAO,CAAC,eAAe,WADA,QAAQ,MAAM,EAAE,CACU;AAGnD,QAAO;;AAIT,SAAS,UAAU,WAA4B;CAC7C,MAAM,WAAW,aAAa;AAC9B,KAAI,CAAC,SAAU,QAAO;CAGtB,MAAM,WAAW,SAAS,MAAM,SAAS,CAAC,QAAQ,MAAM,EAAE,SAAS,EAAE;AAGrE,KAAI,SAAS,WAAW,EAAG,QAAO;CAGlC,IAAI,UAAU;AACd,MAAK,MAAM,WAAW,SACpB,KAAI,QAAQ,WAAW,IAAI,EAEzB;MAAI,eAAe,WAAW,QAAQ,CACpC,QAAO;YAEA,eAAe,WAAW,QAAQ,CAC3C,WAAU;AAId,QAAO;;AAIT,MAAMA,oCAAiC,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file":"queryBuilder-C3XSUYpn.js","names":["enabledNamespaces: Set<string>","disabledNamespaces: Set<string>","logger","logger","predicate","queryOptions: RpcQueryOptions","order"],"sources":["../src/utils/logger.ts","../src/errors.ts","../src/types/entity.ts","../src/utils/entities.ts","../src/query/engine.ts","../src/query/queryResult.ts","../src/query/selection.ts","../src/query/queryBuilder.ts"],"sourcesContent":["const ROOT_NAMESPACE = \"arkiv\"\n\n// Debug logger type - returns a function that can be called to log messages\ntype DebugLogger = (...args: unknown[]) => void\n\n// Get DEBUG environment variable (works in both Node.js and browser)\nfunction getDebugEnv(): string {\n if (typeof process !== \"undefined\") {\n const debugEnv = process?.env?.DEBUG\n if (debugEnv) {\n return debugEnv\n }\n }\n // Browser: check localStorage\n if (typeof globalThis !== \"undefined\" && \"localStorage\" in globalThis) {\n try {\n const storage = (globalThis as { localStorage?: Storage }).localStorage\n return storage?.getItem(\"DEBUG\") || \"\"\n } catch {\n // localStorage might not be available\n }\n }\n return \"\"\n}\n\n// Parse debug patterns and check if a namespace matches\nfunction matchesPattern(namespace: string, pattern: string): boolean {\n // Exact match\n if (pattern === namespace) return true\n\n // Wildcard match: \"arkiv:*\" matches \"arkiv:query\", \"arkiv:rpc\", etc.\n if (pattern.endsWith(\"*\")) {\n const prefix = pattern.slice(0, -1)\n return namespace.startsWith(prefix)\n }\n\n // Negative match: \"-arkiv:query\" excludes \"arkiv:query\"\n if (pattern.startsWith(\"-\")) {\n const excludePattern = pattern.slice(1)\n return !matchesPattern(namespace, excludePattern)\n }\n\n return false\n}\n\n// Check if a namespace is enabled for debugging\nfunction isEnabled(namespace: string): boolean {\n const debugEnv = getDebugEnv()\n if (!debugEnv) return false\n\n // Split by comma/space and check each pattern\n const patterns = debugEnv.split(/[\\s,]+/).filter((p) => p.length > 0)\n\n // If no patterns, nothing is enabled\n if (patterns.length === 0) return false\n\n // Check if any pattern matches (or if explicitly excluded)\n let enabled = false\n for (const pattern of patterns) {\n if (pattern.startsWith(\"-\")) {\n // Exclude pattern - if it matches, disable\n if (matchesPattern(namespace, pattern)) {\n return false\n }\n } else if (matchesPattern(namespace, pattern)) {\n enabled = true\n }\n }\n\n return enabled\n}\n\n// Store enabled namespaces (for programmatic enable/disable)\nconst enabledNamespaces: Set<string> = new Set()\nconst disabledNamespaces: Set<string> = new Set()\n\n// Color palette for namespace coloring (distinct, readable colors)\nconst COLOR_PALETTE = [\n \"#0000FF\", // blue\n \"#008000\", // green\n \"#FF0000\", // red\n \"#FF00FF\", // magenta\n \"#FFA500\", // orange\n \"#800080\", // purple\n \"#00CED1\", // dark turquoise\n \"#FF1493\", // deep pink\n \"#32CD32\", // lime green\n \"#1E90FF\", // dodger blue\n \"#FF4500\", // orange red\n \"#9370DB\", // medium purple\n \"#00FA9A\", // medium spring green\n \"#FFD700\", // gold\n \"#DC143C\", // crimson\n \"#00BFFF\", // deep sky blue\n \"#FF69B4\", // hot pink\n \"#20B2AA\", // light sea green\n \"#DA70D6\", // orchid\n \"#4682B4\", // steel blue\n]\n\n// Detect if we're in Node.js (for ANSI colors) or browser (for CSS colors)\nconst isNode = typeof process !== \"undefined\" && process.versions?.node != null\n\n// ANSI color codes for Node.js (bright, distinct colors)\nconst ANSI_COLORS = [\n \"\\x1b[94m\", // bright blue\n \"\\x1b[92m\", // bright green\n \"\\x1b[91m\", // bright red\n \"\\x1b[95m\", // bright magenta\n \"\\x1b[93m\", // bright yellow\n \"\\x1b[96m\", // bright cyan\n \"\\x1b[35m\", // magenta\n \"\\x1b[36m\", // cyan\n \"\\x1b[32m\", // green\n \"\\x1b[34m\", // blue\n \"\\x1b[33m\", // yellow\n \"\\x1b[31m\", // red\n \"\\x1b[90m\", // bright black (gray)\n \"\\x1b[37m\", // white\n \"\\x1b[1m\", // bold (as a color option)\n]\n\nconst ANSI_RESET = \"\\x1b[0m\"\nconst ANSI_BOLD = \"\\x1b[1m\"\n\n// Cache colors for namespaces (same namespace = same color)\nconst namespaceColors = new Map<string, { css: string; ansi: string }>()\n\n// Generate a consistent color for a namespace based on its hash\nfunction getColorForNamespace(namespace: string): { css: string; ansi: string } {\n // Check cache first\n const cachedColor = namespaceColors.get(namespace)\n if (cachedColor) {\n return cachedColor\n }\n\n // Simple hash function to convert string to number\n let hash = 0\n for (let i = 0; i < namespace.length; i++) {\n const char = namespace.charCodeAt(i)\n hash = (hash << 5) - hash + char\n hash = hash & hash // Convert to 32-bit integer\n }\n\n // Use absolute value and modulo to get index\n const colorIndex = Math.abs(hash) % COLOR_PALETTE.length\n const cssColor = COLOR_PALETTE[colorIndex]\n const ansiColor = ANSI_COLORS[colorIndex % ANSI_COLORS.length]\n\n const color = { css: cssColor, ansi: ansiColor }\n\n // Cache the color\n namespaceColors.set(namespace, color)\n\n return color\n}\n\n// Create a debug logger function\nfunction createDebugLogger(namespace: string): DebugLogger {\n // Get the color for this namespace (consistent across calls)\n const colors = getColorForNamespace(namespace)\n\n return (...args: unknown[]) => {\n // Check if enabled via environment variable or programmatically\n const envEnabled = isEnabled(namespace)\n const progEnabled = enabledNamespaces.has(namespace) && !disabledNamespaces.has(namespace)\n\n if (envEnabled || progEnabled) {\n if (isNode) {\n // Node.js: use ANSI color codes\n const coloredNamespace = `${ANSI_BOLD}${colors.ansi}${namespace}${ANSI_RESET}`\n console.log(coloredNamespace, ...args)\n } else {\n // Browser: use CSS styling with %c\n // The format is: console.log(\"%cstyled%cnormal\", style1, style2, ...args)\n // This colors the namespace, then resets for the rest\n const style1 = `color: ${colors.css}; font-weight: bold`\n const style2 = \"color: inherit; font-weight: normal\"\n // Combine namespace with a space, then log with styles\n console.log(`%c${namespace}%c`, style1, style2, ...args)\n }\n }\n }\n}\n\nexport const getLogger = (scope: string): DebugLogger => {\n const namespace = `${ROOT_NAMESPACE}:${scope}`\n return createDebugLogger(namespace)\n}\n\nexport const enableDebug = (namespaces: string): void => {\n // Parse and add namespaces to enabled set\n const patterns = namespaces.split(/[\\s,]+/).filter((p) => p.length > 0)\n for (const pattern of patterns) {\n if (pattern.startsWith(\"-\")) {\n // Remove from enabled, add to disabled\n const namespace = pattern.slice(1)\n enabledNamespaces.delete(namespace)\n disabledNamespaces.add(namespace)\n } else {\n enabledNamespaces.add(pattern)\n disabledNamespaces.delete(pattern)\n }\n }\n}\n\nexport const disableDebug = (): void => {\n enabledNamespaces.clear()\n disabledNamespaces.clear()\n}\n","import { BLOCK_TIME } from \"./consts\"\n\nexport class EntityMutationError extends Error {\n constructor(message: string) {\n super(message)\n this.name = \"EntityMutationError\"\n }\n}\nexport class InvalidExpirationError extends Error {\n constructor(expiresIn: unknown) {\n super(\n `Invalid expiresIn: ${String(expiresIn)}. expiresIn must be a positive integer and a multiple of the Arkiv block time (${BLOCK_TIME} seconds), because expiration is measured in whole blocks (1 block = ${BLOCK_TIME} seconds).`,\n )\n this.name = \"InvalidExpirationError\"\n }\n}\nexport class InvalidAttributeError extends Error {\n constructor(key: string, value: number) {\n super(\n `Invalid numeric value for attribute \"${key}\": ${String(value)}. Numeric attribute values must be integers. To keep numeric ordering/range queries, scale it to an integer (e.g. Math.round(${String(value)} * 1000), dividing by 1000 on read); otherwise store it as a string (e.g. \"${String(value)}\").`,\n )\n this.name = \"InvalidAttributeError\"\n }\n}\n\nexport class NoMoreResultsError extends Error {\n constructor() {\n super(\"No more results\")\n this.name = \"NoMoreResultsError\"\n }\n}\n\nexport class NoCursorOrLimitError extends Error {\n constructor() {\n super(\"Cursor and limit must be defined to fetch next\")\n this.name = \"NoCursorOrLimitError\"\n }\n}\n\nexport class NoEntityFoundError extends Error {\n constructor() {\n super(\"No entity found\")\n this.name = \"NoEntityFoundError\"\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 contentType: MimeType | undefined\n owner: Hex | undefined\n creator: Hex | undefined\n expiresAtBlock: bigint | undefined\n createdAtBlock: bigint | undefined\n lastModifiedAtBlock: bigint | undefined\n transactionIndexInBlock: bigint | undefined\n operationIndexInTransaction: bigint | undefined\n payload: Uint8Array | undefined\n attributes: Attribute[]\n\n constructor(\n key: Hex,\n contentType: MimeType | undefined = undefined,\n owner: Hex | undefined = undefined,\n creator: Hex | undefined = undefined,\n expiresAtBlock: bigint | undefined = undefined,\n createdAtBlock: bigint | undefined = undefined,\n lastModifiedAtBlock: bigint | undefined = undefined,\n transactionIndexInBlock: bigint | undefined = undefined,\n operationIndexInTransaction: bigint | undefined = undefined,\n payload: Uint8Array | undefined = undefined,\n attributes: Attribute[],\n ) {\n this.key = key\n this.owner = owner\n this.creator = creator\n this.expiresAtBlock = expiresAtBlock\n this.createdAtBlock = createdAtBlock\n this.lastModifiedAtBlock = lastModifiedAtBlock\n this.transactionIndexInBlock = transactionIndexInBlock\n this.operationIndexInTransaction = operationIndexInTransaction\n this.payload = payload\n this.attributes = attributes\n this.contentType = contentType\n }\n\n /**\n * Converts the entity payload from bytes to a string and returns it.\n * Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.\n * Throws an error if the conversion from bytes to string fails.\n * @returns The entity payload as a string.\n */\n toText(): string {\n if (this.payload === undefined) {\n throw new Error(\n \"Entity has no payload – it was probably queried without withPayload(true) via QueryBuilder\",\n )\n }\n try {\n return bytesToString(this.payload)\n } catch (e) {\n throw new Error(\n `Failed to convert entity payload to text: ${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n )\n }\n }\n\n /**\n * Parses the entity payload as JSON and returns the resulting object.\n * Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.\n * Throws an error if the payload is empty or cannot be parsed as JSON.\n * @returns The parsed JSON object from the entity payload.\n */\n toJson(): any {\n const text = this.toText()\n if (!text) {\n throw new Error(\"Entity has empty payload, cannot parse as JSON\")\n }\n try {\n return JSON.parse(text)\n } catch (e) {\n throw new Error(\n `Failed to parse entity payload as JSON: ${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n )\n }\n }\n}\n","import { toBytes } from \"viem\"\nimport { Entity } from \"../types/entity\"\nimport type { RpcEntity } from \"../types/rpcSchema\"\nimport { getLogger } from \"./logger\"\n\nconst logger = getLogger(\"utils:entities\")\n\nexport async function entityFromRpcResult(rpcEntity: RpcEntity) {\n logger(\"entityFromRpcResult %o\", rpcEntity)\n\n return new Entity(\n rpcEntity.key,\n rpcEntity.contentType,\n rpcEntity.owner,\n rpcEntity.creator,\n rpcEntity.expiresAt !== undefined ? BigInt(rpcEntity.expiresAt) : undefined,\n rpcEntity.createdAtBlock !== undefined ? BigInt(rpcEntity.createdAtBlock) : undefined,\n rpcEntity.lastModifiedAtBlock !== undefined ? BigInt(rpcEntity.lastModifiedAtBlock) : undefined,\n rpcEntity.transactionIndexInBlock !== undefined\n ? BigInt(rpcEntity.transactionIndexInBlock)\n : undefined,\n rpcEntity.operationIndexInTransaction !== undefined\n ? BigInt(rpcEntity.operationIndexInTransaction)\n : undefined,\n rpcEntity.value !== undefined ? toBytes(rpcEntity.value) : undefined,\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 { hexToNumber, numberToHex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions } from \"../types/rpcSchema\"\nimport { getLogger } from \"../utils/logger\"\nimport type { Predicate } from \"./predicate\"\n\nconst logger = getLogger(\"query:engine\")\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 createdBy: Hex | undefined\n orderBy: RpcOrderByAttribute[] | undefined\n validAtBlock?: bigint | undefined\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n /**\n * Fully-resolved include-data for fine-grained selection. When provided it takes\n * precedence over the `withAttributes`/`withMetadata`/`withPayload` booleans.\n */\n includeData?: RpcIncludeData | undefined\n },\n) {\n const {\n predicates,\n limit,\n cursor,\n ownedBy,\n createdBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n includeData,\n } = queryParams\n\n logger(\"Processing query with params %o\", {\n predicates,\n cursor,\n limit,\n ownedBy,\n createdBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n includeData,\n })\n\n let query = processPredicates(predicates)\n if (ownedBy) {\n query += ` && $owner=${ownedBy}`\n }\n if (createdBy) {\n query += ` && $creator=${createdBy}`\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 includeData ??\n ({\n key: true,\n attributes: withAttributes ?? false,\n payload: withPayload ?? false,\n contentType: withMetadata ?? false,\n expiration: withMetadata ?? false,\n owner: withMetadata ?? false,\n creator: withMetadata ?? false,\n createdAtBlock: withMetadata ?? false,\n lastModifiedAtBlock: withMetadata ?? false,\n transactionIndexInBlock: withMetadata ?? false,\n operationIndexInTransaction: withMetadata ?? false,\n } as RpcIncludeData),\n }\n\n if (validAtBlock !== undefined) {\n queryOptions.atBlock = numberToHex(validAtBlock)\n }\n if (limit !== undefined) {\n queryOptions.resultsPerPage = numberToHex(limit)\n }\n if (cursor !== undefined) {\n queryOptions.cursor = cursor\n }\n if (orderBy !== undefined) {\n queryOptions.orderBy = orderBy\n }\n\n logger(\"Built query to send %s %o\", query, {\n includeData: queryOptions.includeData,\n atBlock: queryOptions.atBlock ? hexToNumber(queryOptions.atBlock) : undefined,\n orderBy: queryOptions.orderBy,\n resultsPerPage: queryOptions.resultsPerPage,\n cursor: queryOptions.cursor,\n })\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, queryOptions],\n })\n logger(\"Raw result from query %o\", result)\n\n return result\n}\n","import { NoCursorOrLimitError, NoMoreResultsError } from \"../errors\"\nimport type { Entity } from \"../types/entity\"\nimport { getLogger } from \"../utils/logger\"\nimport type { BaseQueryBuilder } from \"./queryBuilder\"\n\nconst logger = getLogger(\"query:result\")\n\n/**\n * The result of a query. Holds the fetched entities and supports cursor-based pagination.\n *\n * @typeParam TEntity - The shape of each entity, inferred from the query builder\n * (a full {@link Entity}, or a projected object inferred from a `select()` selection).\n */\nexport class QueryResult<TEntity = Entity> {\n entities: TEntity[]\n private _endOfIteration: boolean\n private _cursor: string | undefined\n private _limit: number | undefined\n private _validAtBlock: bigint | undefined\n private _queryBuilder: BaseQueryBuilder<TEntity>\n\n // Public getters for internal state\n get queryBuilder(): BaseQueryBuilder<TEntity> {\n return this._queryBuilder\n }\n\n get cursor(): string | undefined {\n return this._cursor\n }\n\n constructor(\n entities: TEntity[],\n queryBuilder: BaseQueryBuilder<TEntity>,\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 logger(\"Current block height for next page %s\", this._validAtBlock?.toString() ?? \"unknown\")\n }\n\n hasNextPage() {\n return !this._endOfIteration\n }\n}\n","import type { Entity } from \"../types/entity\"\nimport type { RpcIncludeData } from \"../types/rpcSchema\"\n\n/** The entity fields that can be selected. These match the fields of {@link Entity} one-to-one. */\ntype DataKey =\n | \"key\"\n | \"contentType\"\n | \"owner\"\n | \"creator\"\n | \"expiresAtBlock\"\n | \"createdAtBlock\"\n | \"lastModifiedAtBlock\"\n | \"transactionIndexInBlock\"\n | \"operationIndexInTransaction\"\n | \"attributes\"\n | \"payload\"\n\n/**\n * The parts of an entity that can be selected. Every field is opt-in (including the `key`) and maps\n * directly to a field of the returned {@link Entity} — the selection is flat.\n */\nexport type SelectionFields = { [K in DataKey]?: boolean }\n\n/**\n * Requires at least one property of `T` to be present.\n * `{}` is not assignable, which is how `select({})` is rejected at compile time.\n */\ntype AtLeastOne<T, K extends keyof T = keyof T> = {\n [P in K]: Required<Pick<T, P>> & Partial<Omit<T, P>>\n}[K]\n\n/**\n * A non-empty entity selection — the object form accepted by `select()`. At least one field must be\n * selected.\n */\nexport type EntitySelection = AtLeastOne<SelectionFields>\n\n/** Argument accepted by `select()` — a non-empty {@link EntitySelection}, or `\"*\"` for everything. */\nexport type SelectArg = EntitySelection | \"*\"\n\n/**\n * The result of a selection `S`: an {@link Entity} narrowed to exactly the selected fields (each\n * non-`undefined`). The shape is flat and backwards compatible — e.g. `select({ owner: true })`\n * yields `{ owner: Hex }` accessed as `entity.owner`. Accessing an unselected field is a compile\n * error.\n *\n * The `toText()` / `toJson()` helpers operate on the payload, so they are only present when\n * `payload` was selected — calling them otherwise would always throw.\n */\nexport type ProjectedEntity<S> = {\n readonly [K in keyof S as S[K] extends true ? K : never]: K extends keyof Entity\n ? NonNullable<Entity[K]>\n : never\n} & (S extends { payload: true } ? Pick<Entity, \"toText\" | \"toJson\"> : unknown)\n\n/** A selection of every field, used to type the result of `select()` / `select(\"*\")`. */\ntype AllSelected = { [K in DataKey]: true }\n\n/** The projected entity type when everything is selected — every field, plus the methods. */\nexport type FullEntity = ProjectedEntity<AllSelected>\n\n/**\n * Converts a {@link SelectArg} into the {@link RpcIncludeData} understood by the query engine.\n * Every field is opt-in — anything not explicitly selected defaults to `false`, including the key.\n * `undefined` or `\"*\"` selects everything.\n *\n * @param selection - The selection to convert\n * @returns The fully-resolved include-data object for the RPC query\n * @throws If an empty selection object is provided\n *\n * @example\n * selectionToIncludeData() // everything\n * selectionToIncludeData(\"*\") // everything\n * selectionToIncludeData({ key: true }) // only the key\n * selectionToIncludeData({ owner: true }) // only the owner\n */\nexport function selectionToIncludeData(selection?: SelectArg): RpcIncludeData {\n if (selection === undefined || selection === \"*\") {\n return {\n key: true,\n attributes: true,\n payload: true,\n contentType: true,\n expiration: true,\n owner: true,\n creator: true,\n createdAtBlock: true,\n lastModifiedAtBlock: true,\n transactionIndexInBlock: true,\n operationIndexInTransaction: true,\n }\n }\n\n // At least one field must be opted in. This rejects both `{}` and selections whose fields are\n // all explicitly `false` (e.g. `select({ key: false })`), which the type system permits.\n if (!Object.values(selection).some((selected) => selected === true)) {\n throw new Error(\n 'select() requires at least one field to be selected. Pass select() or select(\"*\") to select everything.',\n )\n }\n\n return {\n key: selection.key ?? false,\n attributes: selection.attributes ?? false,\n payload: selection.payload ?? false,\n contentType: selection.contentType ?? false,\n // The selection uses the entity field name `expiresAtBlock`; the RPC calls it `expiration`.\n expiration: selection.expiresAtBlock ?? false,\n owner: selection.owner ?? false,\n creator: selection.creator ?? false,\n createdAtBlock: selection.createdAtBlock ?? false,\n lastModifiedAtBlock: selection.lastModifiedAtBlock ?? false,\n transactionIndexInBlock: selection.transactionIndexInBlock ?? false,\n operationIndexInTransaction: selection.operationIndexInTransaction ?? false,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { Entity } from \"../types/entity\"\nimport type { RpcEntity, RpcIncludeData, RpcOrderByAttribute } from \"../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../utils/entities\"\nimport { processQuery } from \"./engine\"\nimport type { Predicate } from \"./predicate\"\nimport { QueryResult } from \"./queryResult\"\nimport { type SelectArg, selectionToIncludeData } from \"./selection\"\n\nexport type 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 Input for orderBy method\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 Input for orderBy method\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/**\n * Data-selection parameters forwarded to the query engine on each fetch.\n * Subclasses of {@link BaseQueryBuilder} decide which parts of an entity are fetched.\n */\ntype SelectionParams = {\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n includeData?: RpcIncludeData | undefined\n}\n\n/**\n * BaseQueryBuilder holds the query-building logic shared by every query builder\n * (filtering, ordering, pagination, execution). It follows the Builder pattern,\n * allowing methods to be chained. Subclasses decide how data selection is expressed\n * by implementing the protected `selectionParams` method.\n *\n * Use {@link SelectQueryBuilder} via `client.select()` to build and execute queries.\n *\n * @typeParam TEntity - The shape of each entity produced by {@link BaseQueryBuilder.fetch}.\n */\nexport abstract class BaseQueryBuilder<TEntity> {\n protected _client: ArkivClient\n protected _ownedBy: Hex | undefined\n protected _createdBy: Hex | undefined\n protected _orderBy: RpcOrderByAttribute[] | undefined\n protected _validAtBlock: bigint | undefined\n protected _limit: number | undefined\n protected _cursor: string | undefined\n protected _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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.ownedBy(\"0x1234567890123456789012345678901234567890\")\n */\n ownedBy(ownedBy: Hex): this {\n this._ownedBy = ownedBy\n return this\n }\n\n /**\n * Sets the createdBy filter\n * @param createdBy - The address of the creator\n * @returns The query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.createdBy(\"0x1234567890123456789012345678901234567890\")\n */\n createdBy(createdBy: Hex): this {\n this._createdBy = createdBy\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 * You can use the helper functions asc() and desc() as input for this method.\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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.orderBy(\"name\", \"string\", \"desc\")\n * builder.orderBy(asc(\"name\", \"string\"))\n * builder.orderBy(desc(\"name\", \"string\"))\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 query builder instance\n *\n * @example\n * const builder = client.select()\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 ): this {\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 limit for the query\n * @param limit - The number of entities to return\n * @returns The query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.limit(10)\n */\n limit(limit: number): this {\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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.cursor(\"0xABC123\")\n */\n cursor(cursor: string): this {\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 query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.validAtBlock(10000)\n */\n validAtBlock(validAtBlock: bigint): this {\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,\n * multiple predicates passed as separate arguments, or an array of predicates - all combined with 'and'.\n * Predicates can be nested using 'or' and 'and' predicates.\n * @param predicates - The predicates to set, either as a single array or as separate arguments\n * @returns The query builder instance\n *\n * @example\n * const builder = client.select()\n * builder.where(eq(\"name\", \"John\"))\n * builder.where(eq(\"name\", \"John\"), eq(\"age\", 30))\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 */\n where(predicates: Predicate[]): this\n where(...predicates: Predicate[]): this\n where(...predicates: (Predicate | Predicate[])[]) {\n this._predicates.push(...predicates.flat())\n return this\n }\n\n /**\n * Returns the data-selection parameters forwarded to the query engine.\n * Subclasses decide which parts of an entity are fetched.\n */\n protected abstract selectionParams(): SelectionParams\n\n /**\n * Builds a single result entity from a raw RPC entity. Subclasses decide the produced shape\n * (a full {@link Entity}, or a projected object inferred from the selection).\n */\n protected abstract projectEntity(rpcEntity: RpcEntity): TEntity | Promise<TEntity>\n\n /**\n * Fetches the entities from the query.\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 = client.select()\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(): Promise<QueryResult<TEntity>> {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n createdBy: this._createdBy,\n orderBy: this._orderBy,\n validAtBlock: this._validAtBlock,\n ...this.selectionParams(),\n })\n\n const entities = await Promise.all(queryResult.data.map((entity) => this.projectEntity(entity)))\n\n this.cursor(queryResult.cursor)\n this.validAtBlock(BigInt(queryResult.blockNumber ?? 0))\n\n return new QueryResult<TEntity>(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 = client.select()\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 createdBy: this._createdBy,\n orderBy: undefined,\n validAtBlock: this._validAtBlock,\n withAttributes: false,\n withMetadata: false,\n withPayload: false,\n })\n\n return queryResult.data.length ?? 0\n }\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 *\n * By default the result includes only the entity `key`. Additional data is opt-in through\n * `withAttributes()`, `withMetadata()` and `withPayload()`.\n *\n * @deprecated Use {@link SelectQueryBuilder} via `client.select()` instead. Declaring the\n * selection up front avoids the common mistake of forgetting to opt in to data and getting back\n * entities with only their `key` populated. This class remains for backwards compatibility and\n * will be removed in a future release.\n *\n * @param client - The Arkiv client\n * @returns The QueryBuilder instance {@link QueryBuilder}\n */\nexport class QueryBuilder extends BaseQueryBuilder<Entity> {\n private _withAttributes: boolean | undefined\n private _withMetadata: boolean | undefined\n private _withPayload: boolean | undefined\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 = client.buildQuery()\n * builder.withAttributes(true)\n */\n withAttributes(withAttributes: boolean = true): this {\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 = client.buildQuery()\n * builder.withMetadata(true)\n */\n withMetadata(withMetadata: boolean = true): this {\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 = client.buildQuery()\n * builder.withPayload(true)\n */\n withPayload(withPayload: boolean = true): this {\n this._withPayload = withPayload\n return this\n }\n\n protected selectionParams(): SelectionParams {\n return {\n withAttributes: this._withAttributes,\n withMetadata: this._withMetadata,\n withPayload: this._withPayload,\n }\n }\n\n protected projectEntity(rpcEntity: RpcEntity): Promise<Entity> {\n return entityFromRpcResult(rpcEntity)\n }\n}\n\n/**\n * SelectQueryBuilder is the recommended query builder. It requires the selection to be declared\n * up front, so results always contain exactly the data you asked for — and the type of each\n * returned entity is narrowed to exactly the selected fields.\n *\n * The selection is fixed at construction time and is flat — each field maps to an entity field.\n * Create one via `client.select(...)` rather than constructing it directly, so the result type is\n * inferred from the selection.\n *\n * @typeParam TEntity - The projected entity shape, inferred from the selection by `client.select()`.\n *\n * @example\n * // everything\n * await client.select().where(eq(\"name\", \"John\")).fetch()\n * await client.select(\"*\").where(eq(\"name\", \"John\")).fetch()\n * // specific fields\n * await client.select({ owner: true, attributes: true }).fetch()\n * // a single field — result is typed (flat) { owner: Hex }\n * await client.select({ owner: true }).fetch()\n */\nexport class SelectQueryBuilder<TEntity> extends BaseQueryBuilder<TEntity> {\n private _includeData: RpcIncludeData\n\n constructor(client: ArkivClient, selection?: SelectArg) {\n super(client)\n this._includeData = selectionToIncludeData(selection)\n }\n\n protected selectionParams(): SelectionParams {\n return { includeData: this._includeData }\n }\n\n protected async projectEntity(rpcEntity: RpcEntity): Promise<TEntity> {\n // The runtime value is a full Entity (with methods); the static type is narrowed to the\n // selected fields via `client.select()`'s inference.\n return (await entityFromRpcResult(rpcEntity)) as unknown as TEntity\n }\n}\n"],"mappings":";;;;AAAA,MAAM,iBAAiB;AAMvB,SAAS,cAAsB;AAC7B,KAAI,OAAO,YAAY,aAAa;EAClC,MAAM,WAAW,SAAS,K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;;;;;;;;;;;;;;;;AAmBtC,IAAa,eAAb,cAAkC,iBAAyB;CACzD,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,eAAe,iBAA0B,MAAY;AACnD,OAAK,kBAAkB;AACvB,SAAO;;;;;;;;;;;CAYT,aAAa,eAAwB,MAAY;AAC/C,OAAK,gBAAgB;AACrB,SAAO;;;;;;;;;;;CAYT,YAAY,cAAuB,MAAY;AAC7C,OAAK,eAAe;AACpB,SAAO;;CAGT,AAAU,kBAAmC;AAC3C,SAAO;GACL,gBAAgB,KAAK;GACrB,cAAc,KAAK;GACnB,aAAa,KAAK;GACnB;;CAGH,AAAU,cAAc,WAAuC;AAC7D,SAAO,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;;;AAwBzC,IAAa,qBAAb,cAAiD,iBAA0B;CACzE,AAAQ;CAER,YAAY,QAAqB,WAAuB;AACtD,QAAM,OAAO;AACb,OAAK,eAAe,uBAAuB,UAAU;;CAGvD,AAAU,kBAAmC;AAC3C,SAAO,EAAE,aAAa,KAAK,cAAc;;CAG3C,MAAgB,cAAc,WAAwC;AAGpE,SAAQ,MAAM,oBAAoB,UAAU"}
@@ -534,25 +534,8 @@ var BaseQueryBuilder = class {
534
534
  this._validAtBlock = validAtBlock;
535
535
  return this;
536
536
  }
537
- /**
538
- * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
539
- * Predicates can be nested using 'or' and 'and' predicates.
540
- * @param predicates - The predicates to set
541
- * @returns The query builder instance
542
- *
543
- * @example
544
- * const builder = client.select()
545
- * builder.where(eq("name", "John"))
546
- * builder.where([eq("name", "John"), eq("age", 30)])
547
- * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
548
- * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
549
- * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
550
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
551
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
552
- */
553
- where(predicates) {
554
- if (Array.isArray(predicates)) this._predicates.push(...predicates);
555
- else this._predicates.push(predicates);
537
+ where(...predicates) {
538
+ this._predicates.push(...predicates.flat());
556
539
  return this;
557
540
  }
558
541
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkiv-network/sdk",
3
- "version": "0.6.8-dev.3",
3
+ "version": "0.6.8-dev.4",
4
4
  "description": "TypeScript client library for Arkiv's blockchains interactions",
5
5
  "type": "module",
6
6
  "target": "esnext",
@@ -244,6 +244,27 @@ describe("Predicate Factory Functions", () => {
244
244
  })
245
245
  })
246
246
 
247
+ test("creates or predicate from varargs", () => {
248
+ const result = or(eq("type", "admin"), eq("type", "moderator"))
249
+
250
+ expect(result).toEqual({
251
+ type: "or",
252
+ predicates: [
253
+ { type: "eq", key: "type", value: "admin" },
254
+ { type: "eq", key: "type", value: "moderator" },
255
+ ],
256
+ })
257
+ })
258
+
259
+ test("creates or predicate with no arguments", () => {
260
+ const result = or()
261
+
262
+ expect(result).toEqual({
263
+ type: "or",
264
+ predicates: [],
265
+ })
266
+ })
267
+
247
268
  test("creates or predicate with nested and", () => {
248
269
  const nestedAnd = and([eq("verified", 1), gte("age", 18)])
249
270
  const predicates = [eq("status", "premium"), nestedAnd]
@@ -314,6 +335,28 @@ describe("Predicate Factory Functions", () => {
314
335
  })
315
336
  })
316
337
 
338
+ test("creates and predicate from varargs", () => {
339
+ const result = and(eq("status", "active"), gte("age", 18), not("deleted"))
340
+
341
+ expect(result).toEqual({
342
+ type: "and",
343
+ predicates: [
344
+ { type: "eq", key: "status", value: "active" },
345
+ { type: "gte", key: "age", value: 18 },
346
+ { type: "not", key: "deleted", value: "" },
347
+ ],
348
+ })
349
+ })
350
+
351
+ test("creates and predicate with no arguments", () => {
352
+ const result = and()
353
+
354
+ expect(result).toEqual({
355
+ type: "and",
356
+ predicates: [],
357
+ })
358
+ })
359
+
317
360
  test("creates and predicate with nested or", () => {
318
361
  const nestedOr = or([eq("type", "admin"), eq("type", "moderator")])
319
362
  const predicates = [eq("active", 1), nestedOr]
@@ -14,32 +14,36 @@ export type Predicate =
14
14
 
15
15
  /**
16
16
  * Creates an OR predicate
17
- * @param predicates - The predicates to combine
17
+ * @param predicates - The predicates to combine, either as a single array or as separate arguments
18
18
  * @returns The OR predicate
19
19
  *
20
20
  * @example
21
- * const predicates = [eq("name", "John"), eq("age", 30)]
22
- * const result = or(predicates)
21
+ * const result = or(eq("name", "John"), eq("age", 30))
22
+ * // or equivalently: or([eq("name", "John"), eq("age", 30)])
23
23
  * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
24
24
  *
25
25
  */
26
- export function or(predicates: Predicate[]): Predicate {
27
- return { type: "or", predicates }
26
+ export function or(predicates: Predicate[]): Predicate
27
+ export function or(...predicates: Predicate[]): Predicate
28
+ export function or(...predicates: (Predicate | Predicate[])[]): Predicate {
29
+ return { type: "or", predicates: predicates.flat() }
28
30
  }
29
31
 
30
32
  /**
31
33
  * Creates an AND predicate
32
- * @param predicates - The predicates to combine
34
+ * @param predicates - The predicates to combine, either as a single array or as separate arguments
33
35
  * @returns The AND predicate
34
36
  *
35
37
  * @example
36
- * const predicates = [eq("name", "John"), eq("age", 30)]
37
- * const result = and(predicates)
38
+ * const result = and(eq("name", "John"), eq("age", 30))
39
+ * // or equivalently: and([eq("name", "John"), eq("age", 30)])
38
40
  * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
39
41
  *
40
42
  */
41
- export function and(predicates: Predicate[]): Predicate {
42
- return { type: "and", predicates }
43
+ export function and(predicates: Predicate[]): Predicate
44
+ export function and(...predicates: Predicate[]): Predicate
45
+ export function and(...predicates: (Predicate | Predicate[])[]): Predicate {
46
+ return { type: "and", predicates: predicates.flat() }
43
47
  }
44
48
 
45
49
  /**
@@ -78,6 +78,28 @@ describe("QueryBuilder", () => {
78
78
  })
79
79
  })
80
80
 
81
+ test("adds multiple predicates as varargs", async () => {
82
+ mockProcessQuery.mockResolvedValue({
83
+ data: [],
84
+ })
85
+
86
+ const builder = new QueryBuilder(mockClient)
87
+ await builder.where(eq("name", "test"), gt("age", 18), neq("status", "inactive")).fetch()
88
+
89
+ expect(mockProcessQuery).toHaveBeenCalledWith(mockClient, {
90
+ predicates: [eq("name", "test"), gt("age", 18), neq("status", "inactive")],
91
+ limit: undefined,
92
+ offset: undefined,
93
+ ownedBy: undefined,
94
+ createdBy: undefined,
95
+ orderBy: undefined,
96
+ validBeforeBlock: undefined,
97
+ withAttributes: undefined,
98
+ withMetadata: undefined,
99
+ withPayload: undefined,
100
+ })
101
+ })
102
+
81
103
  test("chains multiple where() calls", async () => {
82
104
  mockProcessQuery.mockResolvedValue({
83
105
  data: [],
@@ -219,27 +219,26 @@ export abstract class BaseQueryBuilder<TEntity> {
219
219
  }
220
220
 
221
221
  /**
222
- * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
222
+ * Sets the predicates for the query limiting the results. It can be a single predicate,
223
+ * multiple predicates passed as separate arguments, or an array of predicates - all combined with 'and'.
223
224
  * Predicates can be nested using 'or' and 'and' predicates.
224
- * @param predicates - The predicates to set
225
+ * @param predicates - The predicates to set, either as a single array or as separate arguments
225
226
  * @returns The query builder instance
226
227
  *
227
228
  * @example
228
229
  * const builder = client.select()
229
230
  * builder.where(eq("name", "John"))
231
+ * builder.where(eq("name", "John"), eq("age", 30))
230
232
  * builder.where([eq("name", "John"), eq("age", 30)])
231
- * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
232
- * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
233
- * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
234
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
235
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
233
+ * builder.where(eq("name", "John"), or(eq("age", 30), eq("age", 31)))
234
+ * builder.where(eq("name", "John"), and(eq("age", 30), eq("age", 31)))
235
+ * builder.where(eq("name", "John"), or(eq("age", 30), and(eq("age", 31), eq("age", 32))))
236
+ * builder.where(eq("name", "John"), and(eq("age", 30), or(eq("age", 31), eq("age", 32))))
236
237
  */
237
- where(predicates: Predicate[] | Predicate): this {
238
- if (Array.isArray(predicates)) {
239
- this._predicates.push(...predicates)
240
- } else {
241
- this._predicates.push(predicates)
242
- }
238
+ where(predicates: Predicate[]): this
239
+ where(...predicates: Predicate[]): this
240
+ where(...predicates: (Predicate | Predicate[])[]) {
241
+ this._predicates.push(...predicates.flat())
243
242
  return this
244
243
  }
245
244
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-CzqHiUAo.d.ts","names":[],"sources":["../src/query/predicate.ts","../src/query/queryResult.ts","../src/query/selection.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;;ACZ7C;;;;;;;;;;iBD2BgB,GAAA,aAAgB,cAAc;;;AEvCU;AAoBxD;AAA0D;;;;;;AAOrC,iBF0BL,EAAA,CE1BK,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EF0BoC,SE1BpC;;;;;;;;AAOrB;AAGA;AAWA;AACuB,iBFkBP,GAAA,CElBO,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EFkBmC,SElBnC;;;;;;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CAMM,YAAY,UAAU,QAAQ;;;;;;;;;;;WAY3D,QAAQ,YAAY;;;;;;;;;;WA6BxB;;;;;;;;;;;;;;;;;cAiCA,YAAA,SAAqB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BA+CpB;qCAQM,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;cAyB5C,oCAAoC,iBAAiB;;sBAG5C,yBAAyB;+BAKhB;qCAIY,YAAY,QAAQ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-gj33r3rd.d.cts","names":[],"sources":["../src/query/predicate.ts","../src/query/queryResult.ts","../src/query/selection.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;;ACZ7C;;;;;;;;;;iBD2BgB,GAAA,aAAgB,cAAc;;;AEvCU;AAoBxD;AAA0D;;;;;;AAOrC,iBF0BL,EAAA,CE1BK,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EF0BoC,SE1BpC;;;;;;;;AAOrB;AAGA;AAWA;AACuB,iBFkBP,GAAA,CElBO,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EFkBmC,SElBnC;;;;;;;;;;;AAGY,iBF6BnB,EAAA,CE7BmB,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EF6BsB,SE7BtB;;AAA4C;AAM/E;AAiBA;;;;AClEA;AAeA;AAiBA;AAYK,iBH0CW,GAAA,CG1CI,GAAA,EAAA,MAIJ,EA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