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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/chains/index.cjs +1 -1
  2. package/dist/{chains-XCO31x6G.cjs → chains-DVQiGmF6.cjs} +13 -2
  3. package/dist/index-B801JxcV.d.ts +1003 -0
  4. package/dist/index-B801JxcV.d.ts.map +1 -0
  5. package/dist/index-DQGx5KZ6.d.cts +1003 -0
  6. package/dist/index-DQGx5KZ6.d.cts.map +1 -0
  7. package/dist/index.cjs +32 -11
  8. package/dist/index.d.cts +3 -392
  9. package/dist/index.d.ts +3 -392
  10. package/dist/index.js +30 -8
  11. package/dist/index.js.map +1 -1
  12. package/dist/{payload-Da9gJMG5.d.ts → payload-BI2NXPDf.d.ts} +1 -1
  13. package/dist/{payload-Da9gJMG5.d.ts.map → payload-BI2NXPDf.d.ts.map} +1 -1
  14. package/dist/{payload-CJN8fTvX.d.cts → payload-D3fyOBWn.d.cts} +1 -1
  15. package/dist/{payload-CJN8fTvX.d.cts.map → payload-D3fyOBWn.d.cts.map} +1 -1
  16. package/dist/{payload-eB1a8vZH.cjs → payload-vwU3Rc6P.cjs} +0 -1
  17. package/dist/query/index.cjs +1 -2
  18. package/dist/query/index.d.cts +3 -6
  19. package/dist/query/index.d.cts.map +1 -1
  20. package/dist/query/index.d.ts +3 -6
  21. package/dist/query/index.d.ts.map +1 -1
  22. package/dist/query/index.js +2 -2
  23. package/dist/{queryBuilder-DS2Q9bgk.cjs → queryBuilder-B7063DYt.cjs} +111 -17
  24. package/dist/{queryBuilder-Cy7vf54g.js → queryBuilder-DMzL_J5-.js} +113 -11
  25. package/dist/queryBuilder-DMzL_J5-.js.map +1 -0
  26. package/dist/types/index.d.cts +3 -2
  27. package/dist/types/index.d.ts +3 -2
  28. package/dist/utils/index.cjs +1 -1
  29. package/dist/utils/index.d.cts +1 -1
  30. package/dist/utils/index.d.ts +1 -1
  31. package/package.json +6 -5
  32. package/src/actions/public/query.ts +49 -2
  33. package/src/actions/public/subscribeEntityEvents.ts +2 -2
  34. package/src/clients/createPublicClient.ts +1 -1
  35. package/src/clients/createWalletClient.ts +2 -2
  36. package/src/clients/decorators/arkivPublic.ts +26 -11
  37. package/src/clients/decorators/arkivWallet.ts +21 -15
  38. package/src/index.ts +6 -0
  39. package/src/query/errors.ts +0 -6
  40. package/src/query/queryBuilder.ts +7 -4
  41. package/src/types/index.ts +21 -1
  42. package/src/types/rpcSchema.ts +10 -10
  43. package/src/utils/compression.ts +1 -1
  44. package/src/utils/logger.ts +202 -5
  45. package/dist/chunk-pbleEpgJ.cjs +0 -44
  46. package/dist/entity-BNSCqNpu.d.cts +0 -254
  47. package/dist/entity-BNSCqNpu.d.cts.map +0 -1
  48. package/dist/entity-D7fzI0Hc.d.ts +0 -254
  49. package/dist/entity-D7fzI0Hc.d.ts.map +0 -1
  50. package/dist/index.d.cts.map +0 -1
  51. package/dist/index.d.ts.map +0 -1
  52. package/dist/queryBuilder-BGz98Y1C.d.ts +0 -314
  53. package/dist/queryBuilder-BGz98Y1C.d.ts.map +0 -1
  54. package/dist/queryBuilder-CvAx57pq.d.cts +0 -314
  55. package/dist/queryBuilder-CvAx57pq.d.cts.map +0 -1
  56. package/dist/queryBuilder-Cy7vf54g.js.map +0 -1
@@ -1,9 +1,116 @@
1
1
  import { bytesToString, toBytes } from "viem";
2
- import createDebug from "debug";
3
2
 
4
3
  //#region src/utils/logger.ts
5
4
  const ROOT_NAMESPACE = "arkiv";
6
- const getLogger = (scope) => createDebug(`${ROOT_NAMESPACE}:${scope}`);
5
+ function getDebugEnv() {
6
+ if (typeof process !== "undefined") {
7
+ const debugEnv = process?.env?.DEBUG;
8
+ if (debugEnv) return debugEnv;
9
+ }
10
+ if (typeof globalThis !== "undefined" && "localStorage" in globalThis) try {
11
+ return globalThis.localStorage?.getItem("DEBUG") || "";
12
+ } catch {}
13
+ return "";
14
+ }
15
+ function matchesPattern(namespace, pattern) {
16
+ if (pattern === namespace) return true;
17
+ if (pattern.endsWith("*")) {
18
+ const prefix = pattern.slice(0, -1);
19
+ return namespace.startsWith(prefix);
20
+ }
21
+ if (pattern.startsWith("-")) return !matchesPattern(namespace, pattern.slice(1));
22
+ return false;
23
+ }
24
+ function isEnabled(namespace) {
25
+ const debugEnv = getDebugEnv();
26
+ if (!debugEnv) return false;
27
+ const patterns = debugEnv.split(/[\s,]+/).filter((p) => p.length > 0);
28
+ if (patterns.length === 0) return false;
29
+ let enabled = false;
30
+ for (const pattern of patterns) if (pattern.startsWith("-")) {
31
+ if (matchesPattern(namespace, pattern)) return false;
32
+ } else if (matchesPattern(namespace, pattern)) enabled = true;
33
+ return enabled;
34
+ }
35
+ const enabledNamespaces = /* @__PURE__ */ new Set();
36
+ const disabledNamespaces = /* @__PURE__ */ new Set();
37
+ const COLOR_PALETTE = [
38
+ "#0000FF",
39
+ "#008000",
40
+ "#FF0000",
41
+ "#FF00FF",
42
+ "#FFA500",
43
+ "#800080",
44
+ "#00CED1",
45
+ "#FF1493",
46
+ "#32CD32",
47
+ "#1E90FF",
48
+ "#FF4500",
49
+ "#9370DB",
50
+ "#00FA9A",
51
+ "#FFD700",
52
+ "#DC143C",
53
+ "#00BFFF",
54
+ "#FF69B4",
55
+ "#20B2AA",
56
+ "#DA70D6",
57
+ "#4682B4"
58
+ ];
59
+ const isNode = typeof process !== "undefined" && process.versions?.node != null;
60
+ const ANSI_COLORS = [
61
+ "\x1B[94m",
62
+ "\x1B[92m",
63
+ "\x1B[91m",
64
+ "\x1B[95m",
65
+ "\x1B[93m",
66
+ "\x1B[96m",
67
+ "\x1B[35m",
68
+ "\x1B[36m",
69
+ "\x1B[32m",
70
+ "\x1B[34m",
71
+ "\x1B[33m",
72
+ "\x1B[31m",
73
+ "\x1B[90m",
74
+ "\x1B[37m",
75
+ "\x1B[1m"
76
+ ];
77
+ const ANSI_RESET = "\x1B[0m";
78
+ const ANSI_BOLD = "\x1B[1m";
79
+ const namespaceColors = /* @__PURE__ */ new Map();
80
+ function getColorForNamespace(namespace) {
81
+ const cachedColor = namespaceColors.get(namespace);
82
+ if (cachedColor) return cachedColor;
83
+ let hash = 0;
84
+ for (let i = 0; i < namespace.length; i++) {
85
+ const char = namespace.charCodeAt(i);
86
+ hash = (hash << 5) - hash + char;
87
+ hash = hash & hash;
88
+ }
89
+ const colorIndex = Math.abs(hash) % COLOR_PALETTE.length;
90
+ const color = {
91
+ css: COLOR_PALETTE[colorIndex],
92
+ ansi: ANSI_COLORS[colorIndex % ANSI_COLORS.length]
93
+ };
94
+ namespaceColors.set(namespace, color);
95
+ return color;
96
+ }
97
+ function createDebugLogger(namespace) {
98
+ const colors = getColorForNamespace(namespace);
99
+ return (...args) => {
100
+ const envEnabled = isEnabled(namespace);
101
+ const progEnabled = enabledNamespaces.has(namespace) && !disabledNamespaces.has(namespace);
102
+ if (envEnabled || progEnabled) if (isNode) {
103
+ const coloredNamespace = `${ANSI_BOLD}${colors.ansi}${namespace}${ANSI_RESET}`;
104
+ console.log(coloredNamespace, ...args);
105
+ } else {
106
+ const style1 = `color: ${colors.css}; font-weight: bold`;
107
+ console.log(`%c${namespace}%c`, style1, "color: inherit; font-weight: normal", ...args);
108
+ }
109
+ };
110
+ }
111
+ const getLogger = (scope) => {
112
+ return createDebugLogger(`${ROOT_NAMESPACE}:${scope}`);
113
+ };
7
114
 
8
115
  //#endregion
9
116
  //#region src/query/errors.ts
@@ -17,11 +124,6 @@ var NoCursorOrLimitError = class extends Error {
17
124
  super("Cursor and limit must be defined to fetch next");
18
125
  }
19
126
  };
20
- var OffsetCannotBeLessThanZeroError = class extends Error {
21
- constructor() {
22
- super("Offset cannot be less than 0");
23
- }
24
- };
25
127
  var NoEntityFoundError = class extends Error {
26
128
  constructor() {
27
129
  super("No entity found");
@@ -192,7 +294,7 @@ var QueryResult = class {
192
294
  * Helper function to create an ascending order by attribute
193
295
  * @param attributeName - The name of the attribute to order by
194
296
  * @param attributeType - The type of the attribute to order by (string or number)
195
- * @returns The OrderByAttribute instance
297
+ * @returns Input for orderBy method
196
298
  *
197
299
  * @example
198
300
  * const ascAttribute = asc("name", "string")
@@ -208,7 +310,7 @@ function asc(attributeName, attributeType) {
208
310
  * Helper function to create a descending order by attribute
209
311
  * @param attributeName - The name of the attribute to order by
210
312
  * @param attributeType - The type of the attribute to order by (string or number)
211
- * @returns The OrderByAttribute instance
313
+ * @returns Input for orderBy method
212
314
  *
213
315
  * @example
214
316
  * const descAttribute = desc("name", "string")
@@ -425,5 +527,5 @@ var QueryBuilder = class {
425
527
  };
426
528
 
427
529
  //#endregion
428
- export { entityFromRpcResult as a, NoMoreResultsError as c, QueryResult as i, OffsetCannotBeLessThanZeroError as l, asc as n, NoCursorOrLimitError as o, desc as r, NoEntityFoundError as s, QueryBuilder as t, getLogger as u };
429
- //# sourceMappingURL=queryBuilder-Cy7vf54g.js.map
530
+ export { entityFromRpcResult as a, NoMoreResultsError as c, QueryResult as i, getLogger as l, asc as n, NoCursorOrLimitError as o, desc as r, NoEntityFoundError as s, QueryBuilder as t };
531
+ //# sourceMappingURL=queryBuilder-DMzL_J5-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilder-DMzL_J5-.js","names":["enabledNamespaces: Set<string>","disabledNamespaces: Set<string>","logger","logger","predicate","queryOptions: RpcQueryOptions","order"],"sources":["../src/utils/logger.ts","../src/query/errors.ts","../src/types/entity.ts","../src/utils/entities.ts","../src/query/engine.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":["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","export class NoMoreResultsError extends Error {\n constructor() {\n super(\"No more results\")\n }\n}\n\nexport class NoCursorOrLimitError extends Error {\n constructor() {\n super(\"Cursor and limit must be defined to fetch next\")\n }\n}\n\nexport class NoEntityFoundError extends Error {\n constructor() {\n super(\"No entity found\")\n }\n}\n","import { bytesToString, type Hex } from \"viem\"\nimport type { MimeType } from \"../types\"\nimport type { Attribute } from \"./attributes\"\n\nexport class Entity {\n key: Hex\n contentType: MimeType | undefined\n owner: 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 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.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 toText(): string {\n return this.payload ? bytesToString(this.payload) : \"\"\n }\n\n toJson(): any {\n return this.payload ? JSON.parse(bytesToString(this.payload)) : {}\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.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 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 orderBy: RpcOrderByAttribute[] | undefined\n validAtBlock?: bigint | undefined\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n },\n) {\n const {\n predicates,\n limit,\n cursor,\n ownedBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n } = queryParams\n\n logger(\"Processing query with params %o\", {\n predicates,\n cursor,\n limit,\n ownedBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n })\n\n let query = processPredicates(predicates)\n if (ownedBy) {\n query += ` && $owner=${ownedBy}`\n }\n\n // remove leading and trailing spaces and leading &&\n query = query.trim()\n if (query.startsWith(\"&& \")) {\n query = query.slice(3)\n }\n\n const queryOptions: RpcQueryOptions = {\n includeData: {\n key: true,\n attributes: withAttributes ?? false,\n payload: withPayload ?? false,\n contentType: withMetadata ?? false,\n expiration: withMetadata ?? false,\n owner: withMetadata ?? false,\n 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 = Number(validAtBlock)\n }\n if (limit !== undefined) {\n queryOptions.resultsPerPage = limit\n }\n if (cursor !== undefined) {\n queryOptions.cursor = cursor\n }\n if (orderBy !== undefined) {\n queryOptions.orderBy = orderBy\n }\n\n logger(\"Built query to send %s %o\", query, {\n includeData: queryOptions.includeData,\n atBlock: queryOptions.atBlock?.toString(),\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 type { Entity } from \"../types/entity\"\nimport { getLogger } from \"../utils/logger\"\nimport { NoCursorOrLimitError, NoMoreResultsError } from \"./errors\"\nimport type { QueryBuilder } from \"./queryBuilder\"\n\nconst logger = getLogger(\"query:result\")\n\nexport class QueryResult {\n entities: Entity[]\n private _endOfIteration: boolean\n private _cursor: string | undefined\n private _limit: number | undefined\n private _validAtBlock: bigint | undefined\n private _queryBuilder: QueryBuilder\n\n // Public getters for internal state\n get queryBuilder(): QueryBuilder {\n return this._queryBuilder\n }\n\n get cursor(): string | undefined {\n return this._cursor\n }\n\n constructor(\n entities: Entity[],\n queryBuilder: QueryBuilder,\n cursor: string | undefined,\n limit: number | undefined,\n validAtBlock: bigint | undefined,\n ) {\n this.entities = entities\n this._queryBuilder = queryBuilder\n this._endOfIteration = !limit || entities.length < limit\n this._cursor = cursor\n this._limit = limit\n this._validAtBlock = validAtBlock\n }\n\n async next() {\n if (this._cursor === undefined || this._limit === undefined) {\n throw new NoCursorOrLimitError()\n }\n if (this._endOfIteration) {\n throw new NoMoreResultsError()\n }\n this._queryBuilder.cursor(this._cursor)\n const result = await this._queryBuilder.fetch()\n this.entities = result.entities\n // Update the query builder reference\n this._queryBuilder = result.queryBuilder\n // Check if we've reached the end (no more cursor or we got fewer entities than limit)\n this._endOfIteration = !result.cursor || result.entities.length < this._limit\n // Update the cursor\n this._cursor = result.cursor\n\n // TODO check current block height and if it is not too old\n 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 { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcOrderByAttribute } from \"../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../utils/entities\"\nimport { processQuery } from \"./engine\"\nimport type { Predicate } from \"./predicate\"\nimport { QueryResult } from \"./queryResult\"\n\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 * QueryBuilder is a helper class to build queries to the Arkiv DBChains.\n * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.\n * @param client - The Arkiv client\n * @returns The QueryBuilder instance {@link QueryBuilder}\n */\nexport class QueryBuilder {\n private _client: ArkivClient\n private _ownedBy: Hex | undefined\n private _orderBy: RpcOrderByAttribute[] | undefined\n private _validAtBlock: bigint | undefined\n private _withAttributes: boolean | undefined\n private _withMetadata: boolean | undefined\n private _withPayload: boolean | undefined\n private _limit: number | undefined\n private _cursor: string | undefined\n private _predicates: Predicate[]\n\n constructor(client: ArkivClient) {\n this._client = client\n this._predicates = []\n }\n\n /**\n * Sets the ownedBy filter\n * @param ownedBy - The address of the owner\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.ownedBy(\"0x1234567890123456789012345678901234567890\")\n */\n ownedBy(ownedBy: Hex) {\n this._ownedBy = ownedBy\n return this\n }\n\n /**\n * Sets the orderBy for the query.\n * It can be called multiple times to order by multiple attributes.\n * The order of the attributes is important. The first attribute is the primary order by attribute.\n * 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 QueryBuilder instance\n *\n * @example\n * const builder = client.buildQuery()\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 QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(asc(\"name\", \"string\"))\n * builder.orderBy(desc(\"name\", \"string\"))\n */\n orderBy(orderByAttribute: OrderByAttribute): this\n orderBy(\n attributeNameOrOrderByAttribute: string | OrderByAttribute,\n attributeType?: \"string\" | \"number\",\n order: \"asc\" | \"desc\" = \"asc\",\n ) {\n if (!this._orderBy) {\n this._orderBy = []\n }\n\n const pushOrderByAttribute = ({ name, type, order }: OrderByAttribute) => {\n this._orderBy?.push({\n name,\n type: type === \"number\" ? \"numeric\" : type,\n desc: order === \"desc\",\n })\n }\n\n if (typeof attributeNameOrOrderByAttribute === \"string\") {\n if (!attributeType) {\n throw new Error(\"attributeType is required when using positional orderBy arguments\")\n }\n pushOrderByAttribute({\n name: attributeNameOrOrderByAttribute,\n type: attributeType,\n order,\n })\n } else {\n pushOrderByAttribute(attributeNameOrOrderByAttribute)\n }\n\n return this\n }\n\n /**\n * Sets the withAttributes flag which will return the attributes for the entities if true\n * @param withAttributes - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withAttributes(true)\n */\n withAttributes(withAttributes: boolean = true) {\n this._withAttributes = withAttributes\n return this\n }\n\n /**\n * Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true\n * @param withMetadata - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withMetadata(true)\n */\n withMetadata(withMetadata: boolean = true) {\n this._withMetadata = withMetadata\n return this\n }\n\n /**\n * Sets the withPayload flag which will return the payload for the entities if true\n * @param withPayload - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withPayload(true)\n */\n withPayload(withPayload: boolean = true) {\n this._withPayload = withPayload\n return this\n }\n\n /**\n * Sets the limit for the query\n * @param limit - The number of entities to return\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.limit(10)\n */\n limit(limit: number) {\n this._limit = limit\n return this\n }\n\n /**\n * Sets the cursor for the query - it is advances setting which rather shouldn't be used manually but it is provided from query result if limit is used (pagination).\n * @param cursor - The cursor to set which tells to RPC Query server where to start or continue the query.\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.offset(10)\n */\n cursor(cursor: string) {\n this._cursor = cursor\n return this\n }\n\n /**\n * Sets the validAtBlock for the query which tells at which block height the state we are intested.\n * If not set, the latest block is used.\n * @param validAtBlock - The block number to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.validAtBlock(10000)\n */\n validAtBlock(validAtBlock: bigint) {\n this._validAtBlock = validAtBlock\n return this\n }\n\n /**\n * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.\n * Predicates can be nested using 'or' and 'and' predicates.\n * @param predicates - The predicates to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.where(eq(\"name\", \"John\"))\n * builder.where([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), and([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), and([eq(\"age\", 32), eq(\"age\", 33)])])])])\n */\n where(predicates: Predicate[] | Predicate) {\n if (Array.isArray(predicates)) {\n this._predicates.push(...predicates)\n } else {\n this._predicates.push(predicates)\n }\n return this\n }\n\n /**\n * Fetches the entities from the query. Re\n * It will return a QueryResult instance which can be used to fetch the next and previous pages.\n * @returns The QueryResult instance {@link QueryResult}\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).fetch()\n * // result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }\n */\n async fetch() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: this._orderBy,\n validAtBlock: this._validAtBlock,\n withAttributes: this._withAttributes,\n withMetadata: this._withMetadata,\n withPayload: this._withPayload,\n })\n\n const entities = await Promise.all(\n queryResult.data.map((entity) => entityFromRpcResult(entity)),\n )\n\n this.cursor(queryResult.cursor)\n this.validAtBlock(queryResult.blockNumber)\n\n return new QueryResult(entities, this, this._cursor, this._limit, this._validAtBlock)\n }\n\n /**\n * Counts the entities from the query.\n * @returns The number of entities\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).count()\n * // result = 10\n */\n async count() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: undefined,\n validAtBlock: this._validAtBlock,\n withAttributes: false,\n withMetadata: false,\n withPayload: false,\n })\n\n return queryResult.data.length ?? 0\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,EA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,WAAW,CAC3B,MAAK,YAAY,KAAK,GAAG,WAAW;MAEpC,MAAK,YAAY,KAAK,WAAW;AAEnC,SAAO;;;;;;;;;;;;CAaT,MAAM,QAAQ;EACZ,MAAM,cAAc,MAAM,aAAa,KAAK,SAAS;GACnD,YAAY,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,SAAS,KAAK;GACd,cAAc,KAAK;GACnB,gBAAgB,KAAK;GACrB,cAAc,KAAK;GACnB,aAAa,KAAK;GACnB,CAAC;EAEF,MAAM,WAAW,MAAM,QAAQ,IAC7B,YAAY,KAAK,KAAK,WAAW,oBAAoB,OAAO,CAAC,CAC9D;AAED,OAAK,OAAO,YAAY,OAAO;AAC/B,OAAK,aAAa,YAAY,YAAY;AAE1C,SAAO,IAAI,YAAY,UAAU,MAAM,KAAK,SAAS,KAAK,QAAQ,KAAK,cAAc;;;;;;;;;;;CAYvF,MAAM,QAAQ;AAaZ,UAZoB,MAAM,aAAa,KAAK,SAAS;GACnD,YAAY,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,SAAS;GACT,cAAc,KAAK;GACnB,gBAAgB;GAChB,cAAc;GACd,aAAa;GACd,CAAC,EAEiB,KAAK,UAAU"}
@@ -1,2 +1,3 @@
1
- import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-BNSCqNpu.cjs";
2
- export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, RpcEntity, RpcIncludeData, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
1
+ import { $ as RpcIncludeData, A as CreateEntityParameters, C as MutateEntitiesReturnType, D as ExtendEntityReturnType, E as ExtendEntityParameters, J as QueryOptionsIncludeData, M as ChangeOwnershipParameters, N as ChangeOwnershipReturnType, O as DeleteEntityParameters, P as GetBlockTimingReturnType, Q as RpcEntity, S as MutateEntitiesParameters, T as UpdateEntityReturnType, Y as QueryOptionsOrderBy, Z as ArkivRpcSchema, _ as OnEntityExpiredEvent, b as OnEntityUpdatedEvent, et as RpcOrderByAttribute, g as OnEntityDeletedEvent, h as OnEntityCreatedEvent, j as CreateEntityReturnType, k as DeleteEntityReturnType, m as TxParams, nt as MimeType, p as Entity, q as QueryOptions, tt as RpcQueryOptions, v as OnEntityExpiresInExtendedEvent, w as UpdateEntityParameters, x as Attribute, y as OnEntityOwnerChangedEvent } from "../index-DQGx5KZ6.cjs";
2
+ import "../payload-D3fyOBWn.cjs";
3
+ export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, GetBlockTimingReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, OnEntityCreatedEvent, OnEntityDeletedEvent, OnEntityExpiredEvent, OnEntityExpiresInExtendedEvent, OnEntityOwnerChangedEvent, OnEntityUpdatedEvent, QueryOptions, QueryOptionsIncludeData, QueryOptionsOrderBy, RpcEntity, RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
@@ -1,2 +1,3 @@
1
- import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-D7fzI0Hc.js";
2
- export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, RpcEntity, RpcIncludeData, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
1
+ import { $ as RpcIncludeData, A as CreateEntityParameters, C as MutateEntitiesReturnType, D as ExtendEntityReturnType, E as ExtendEntityParameters, J as QueryOptionsIncludeData, M as ChangeOwnershipParameters, N as ChangeOwnershipReturnType, O as DeleteEntityParameters, P as GetBlockTimingReturnType, Q as RpcEntity, S as MutateEntitiesParameters, T as UpdateEntityReturnType, Y as QueryOptionsOrderBy, Z as ArkivRpcSchema, _ as OnEntityExpiredEvent, b as OnEntityUpdatedEvent, et as RpcOrderByAttribute, g as OnEntityDeletedEvent, h as OnEntityCreatedEvent, j as CreateEntityReturnType, k as DeleteEntityReturnType, m as TxParams, nt as MimeType, p as Entity, q as QueryOptions, tt as RpcQueryOptions, v as OnEntityExpiresInExtendedEvent, w as UpdateEntityParameters, x as Attribute, y as OnEntityOwnerChangedEvent } from "../index-B801JxcV.js";
2
+ import "../payload-BI2NXPDf.js";
3
+ export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, GetBlockTimingReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, OnEntityCreatedEvent, OnEntityDeletedEvent, OnEntityExpiredEvent, OnEntityExpiresInExtendedEvent, OnEntityOwnerChangedEvent, OnEntityUpdatedEvent, QueryOptions, QueryOptionsIncludeData, QueryOptionsOrderBy, RpcEntity, RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
@@ -1,4 +1,4 @@
1
- const require_payload = require('../payload-eB1a8vZH.cjs');
1
+ const require_payload = require('../payload-vwU3Rc6P.cjs');
2
2
 
3
3
  //#region src/utils/expirationTime.ts
4
4
  const ExpirationTime = {
@@ -1,4 +1,4 @@
1
- import { n as stringToPayload, t as jsonToPayload } from "../payload-CJN8fTvX.cjs";
1
+ import { n as stringToPayload, t as jsonToPayload } from "../payload-D3fyOBWn.cjs";
2
2
  export * from "viem/utils";
3
3
 
4
4
  //#region src/utils/expirationTime.d.ts
@@ -1,4 +1,4 @@
1
- import { n as stringToPayload, t as jsonToPayload } from "../payload-Da9gJMG5.js";
1
+ import { n as stringToPayload, t as jsonToPayload } from "../payload-BI2NXPDf.js";
2
2
  export * from "viem/utils";
3
3
 
4
4
  //#region src/utils/expirationTime.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkiv-network/sdk",
3
- "version": "0.5.0-dev.1",
3
+ "version": "0.5.0-dev.3",
4
4
  "description": "TypeScript client library for Arkiv's blockchains interactions",
5
5
  "type": "module",
6
6
  "target": "esnext",
@@ -73,6 +73,7 @@
73
73
  "lint": "biome check src/",
74
74
  "lint:fix": "biome check --write src/",
75
75
  "test:unit": "bun test src/**/*",
76
+ "docs": "bunx typedoc --plugin typedoc-plugin-markdown",
76
77
  "package": "rimraf arkiv-network-sdk-*.tgz && bun run build && bun pm pack --no-cache",
77
78
  "package:test": "bun run package && mv arkiv-network-sdk-*.tgz arkiv-network-sdk-latest.tgz",
78
79
  "prepublishOnly": "bun run build && bun run package && mv arkiv-network-sdk-*.tgz arkiv-network-sdk-latest.tgz",
@@ -84,11 +85,11 @@
84
85
  "publish-dev:dry": "npm publish ./arkiv-network-sdk-latest.tgz --access public --tag dev --dry-run"
85
86
  },
86
87
  "devDependencies": {
87
- "@types/debug": "^4.1.12",
88
88
  "@biomejs/biome": "2.2.4",
89
89
  "@types/bun": "latest",
90
90
  "rimraf": "^6.0.1",
91
- "tsdown": "^0.16.0"
91
+ "tsdown": "^0.16.0",
92
+ "typedoc": "^0.28.14"
92
93
  },
93
94
  "peerDependencies": {
94
95
  "typescript": "^5.0.0"
@@ -117,7 +118,7 @@
117
118
  "homepage": "https://arkiv.network",
118
119
  "dependencies": {
119
120
  "brotli-wasm": "^3.0.1",
120
- "viem": "^2.38.2",
121
- "debug": "^4.3.7"
121
+ "typedoc-plugin-markdown": "^4.9.0",
122
+ "viem": "^2.38.2"
122
123
  }
123
124
  }
@@ -1,10 +1,57 @@
1
1
  import type { ArkivClient } from "../../clients/baseClient"
2
+ import type { RpcQueryOptions } from "../../types/rpcSchema"
2
3
  import { entityFromRpcResult } from "../../utils/entities"
3
4
 
4
- export async function query(client: ArkivClient, query: string) {
5
+ export type QueryOptionsIncludeData = {
6
+ attributes?: boolean
7
+ payload?: boolean
8
+ metadata?: boolean
9
+ }
10
+ export type QueryOptionsOrderBy = {
11
+ name: string
12
+ type: "string" | "numeric"
13
+ desc: "asc" | "desc"
14
+ }
15
+
16
+ export type QueryOptions = {
17
+ includeData?: QueryOptionsIncludeData
18
+ atBlock?: bigint
19
+ orderBy?: QueryOptionsOrderBy[]
20
+ resultsPerPage?: number | undefined
21
+ cursor?: string | undefined
22
+ }
23
+
24
+ export async function query(client: ArkivClient, query: string, queryOptions?: QueryOptions) {
25
+ const rpcQueryOptions: RpcQueryOptions = {
26
+ includeData: {
27
+ key: true,
28
+ payload: queryOptions?.includeData?.payload ?? true,
29
+ attributes: queryOptions?.includeData?.attributes ?? false,
30
+ contentType: queryOptions?.includeData?.metadata ?? false,
31
+ expiration: queryOptions?.includeData?.metadata ?? false,
32
+ owner: queryOptions?.includeData?.metadata ?? false,
33
+ createdAtBlock: queryOptions?.includeData?.metadata ?? false,
34
+ lastModifiedAtBlock: queryOptions?.includeData?.metadata ?? false,
35
+ transactionIndexInBlock: queryOptions?.includeData?.metadata ?? false,
36
+ operationIndexInTransaction: queryOptions?.includeData?.metadata ?? false,
37
+ },
38
+ ...(queryOptions?.atBlock !== undefined && { atBlock: Number(queryOptions.atBlock) }),
39
+ ...(queryOptions?.orderBy && {
40
+ orderBy: queryOptions?.orderBy.map((order) => ({
41
+ name: order.name,
42
+ type: order.type,
43
+ desc: order.desc === "desc",
44
+ })),
45
+ }),
46
+ ...(queryOptions?.resultsPerPage !== undefined && {
47
+ resultsPerPage: queryOptions.resultsPerPage,
48
+ }),
49
+ ...(queryOptions?.cursor !== undefined && { cursor: queryOptions?.cursor }),
50
+ }
51
+
5
52
  const result = await client.request({
6
53
  method: "arkiv_query",
7
- params: [query],
54
+ params: [query, rpcQueryOptions],
8
55
  })
9
56
 
10
57
  const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))
@@ -1,4 +1,4 @@
1
- import { decodeEventLog, parseAbi, toHex } from "viem"
1
+ import { decodeEventLog, type Hex, parseAbi, toHex } from "viem"
2
2
  import type { ArkivClient } from "../../clients/baseClient"
3
3
  import type { PublicArkivClient } from "../../clients/createPublicClient"
4
4
  import type {
@@ -53,7 +53,7 @@ export async function subscribeEntityEvents(
53
53
  for (const log of logs) {
54
54
  const event = decodeEventLog({
55
55
  abi: arkivABI,
56
- topics: log.topics as [string, string, string] | [string, string, string, string],
56
+ topics: log.topics as [Hex, ...Hex[]] | [],
57
57
  data: log.data,
58
58
  })
59
59
  logger("event from subscribeEntityEvents %o", event)
@@ -29,7 +29,7 @@ export type PublicArkivClient<
29
29
  *
30
30
  * A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.arkiv.network/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
31
31
  *
32
- * @param config - {@link PublicClientConfig}
32
+ * @param parameters - Configuration object for the public client (chain, transport, etc.)
33
33
  * @returns A Arkiv Public Client. {@link PublicArkivClient}
34
34
  *
35
35
  * @example
@@ -29,8 +29,8 @@ export type WalletArkivClient<
29
29
  *
30
30
  * A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.arkiv.network/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
31
31
  *
32
- * @param config - {@link PublicClientConfig}
33
- * @returns A Arkiv Public Client. {@link PublicArkivClient}
32
+ * @param parameters - Configuration object for the wallet client (chain, transport, account, etc.)
33
+ * @returns A Arkiv Wallet Client. {@link WalletArkivClient}
34
34
  *
35
35
  * @example
36
36
  * import { createPublicClient, http } from 'arkiv'
@@ -2,7 +2,7 @@ import type { Account, Chain, Client, Hex, PublicActions, Transport } from "viem
2
2
  import { getBlockTiming } from "../../actions/public/getBlockTiming"
3
3
  import { getEntity } from "../../actions/public/getEntity"
4
4
  import { getEntityCount } from "../../actions/public/getEntityCount"
5
- import { query } from "../../actions/public/query"
5
+ import { type QueryOptions, query } from "../../actions/public/query"
6
6
  import { subscribeEntityEvents } from "../../actions/public/subscribeEntityEvents"
7
7
  import { QueryBuilder } from "../../query/queryBuilder"
8
8
  import type { Entity } from "../../types/entity"
@@ -36,7 +36,7 @@ export type PublicArkivActions<
36
36
  *
37
37
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
38
38
  *
39
- * @param args - {entityKey}
39
+ * @param key - The entity key (hex string)
40
40
  * @returns The entity with the given key. {@link Entity}
41
41
  *
42
42
  * @example
@@ -79,7 +79,10 @@ export type PublicArkivActions<
79
79
 
80
80
  /**
81
81
  * Returns a QueryResult instance for fetching the results of a raw query.
82
- * @returns A QueryResult instance for fetching the results of a raw query. {@link QueryResult}
82
+ * If no query options are provided, all payload is included, but no metadata (like owner, expiredAt, etc.) and attributes.
83
+ * @param query - The raw query string
84
+ * @param queryOptions - The optional query options - {@link QueryOptions}
85
+ * @returns An array of entities matching the query. {@link Entity}
83
86
  *
84
87
  * @example
85
88
  * import { createPublicClient, http } from 'arkiv'
@@ -90,13 +93,25 @@ export type PublicArkivActions<
90
93
  * transport: http(),
91
94
  * })
92
95
  * const queryResult = client.query('key = value && $owner = 0x123')
93
- *
96
+ * // queryResult = [{ key: "0x123", value: "0x123" }]
97
+ * const queryResultWithOptions = client.query('key = value && $owner = 0x123', {
98
+ * includeData: {
99
+ * attributes: false,
100
+ * payload: true,
101
+ * metadata: true,
102
+ * },
103
+ * orderBy: [{ name: "key", type: "string", desc: "asc" }],
104
+ * resultsPerPage: 10,
105
+ * cursor: undefined,
106
+ * atBlock: undefined,
107
+ * })
108
+ * // queryResultWithOptions = [{ key: "0x123", value: "0x123" }]
94
109
  */
95
- query: (query: string) => Promise<Entity[]>
110
+ query: (query: string, queryOptions?: QueryOptions) => Promise<Entity[]>
96
111
 
97
112
  /**
98
113
  * Returns the number of entities in the DBChain.
99
- * @returns The number of entities in the DBChain. {@link number}
114
+ * @returns The number of entities in the DBChain
100
115
  *
101
116
  * @example
102
117
  * import { createPublicClient, http } from 'arkiv'
@@ -138,10 +153,10 @@ export type PublicArkivActions<
138
153
 
139
154
  /**
140
155
  * Subscribes to entity events.
141
- * @param events to watch - {onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended}
142
- * @param pollingInterval - The polling interval in milliseconds. {@link number}
143
- * @param fromBlock - The block number to start from. {@link bigint}
144
- * @returns A function to unsubscribe from the events. {() => void}
156
+ * Takes an object with event handlers: {onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended}
157
+ * @param pollingInterval - The polling interval in milliseconds
158
+ * @param fromBlock - The block number to start from
159
+ * @returns A function to unsubscribe from the events
145
160
  *
146
161
  * @example
147
162
  * import { createPublicClient, http } from 'arkiv'
@@ -183,7 +198,7 @@ export function publicArkivActions<
183
198
  >(client: Client<transport, chain, account>) {
184
199
  return {
185
200
  getEntity: (key: Hex) => getEntity(client, key),
186
- query: (rawQuery: string) => query(client, rawQuery),
201
+ query: (rawQuery: string, queryOptions?: QueryOptions) => query(client, rawQuery, queryOptions),
187
202
  buildQuery: () => new QueryBuilder(client),
188
203
  getBlockTiming: () => getBlockTiming(client),
189
204
  getEntityCount: () => getEntityCount(client),
@@ -29,7 +29,7 @@ import type {
29
29
  UpdateEntityReturnType,
30
30
  } from "../../actions/wallet/updateEntity"
31
31
  import { updateEntity } from "../../actions/wallet/updateEntity"
32
- import type { Entity, TxParams } from "../../types"
32
+ import type { TxParams } from "../../types"
33
33
 
34
34
  export type WalletArkivActions<
35
35
  transport extends Transport = Transport,
@@ -47,13 +47,14 @@ export type WalletArkivActions<
47
47
  | "signTransaction"
48
48
  > & {
49
49
  /**
50
- * Returns the entity with the given key.
50
+ * Creates a new entity.
51
51
  *
52
- * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
52
+ * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/createEntity
53
53
  * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
54
54
  *
55
- * @param args - {entityKey}
56
- * @returns The entity with the given key. {@link Entity}
55
+ * @param data - The entity creation parameters
56
+ * @param txParams - Optional transaction parameters
57
+ * @returns The created entity with transaction hash
57
58
  *
58
59
  * @example
59
60
  * import { createPublicClient, http } from 'arkiv'
@@ -86,8 +87,9 @@ export type WalletArkivActions<
86
87
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/updateEntity
87
88
  * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
88
89
  *
89
- * @param args - {entityKey, data}
90
- * @returns The entity with the given key. {@link Entity}
90
+ * @param data - The entity update parameters
91
+ * @param txParams - Optional transaction parameters
92
+ * @returns The updated entity with transaction hash
91
93
  *
92
94
  * @example
93
95
  * import { createWalletClient, http } from 'arkiv'
@@ -109,8 +111,9 @@ export type WalletArkivActions<
109
111
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/deleteEntity
110
112
  * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
111
113
  *
112
- * @param args - {entityKey}
113
- * @returns The entity with the given key. {@link Entity}
114
+ * @param data - The entity deletion parameters
115
+ * @param txParams - Optional transaction parameters
116
+ * @returns The deleted entity with transaction hash
114
117
  *
115
118
  * @example
116
119
  * import { createWalletClient, http } from 'arkiv'
@@ -139,8 +142,9 @@ export type WalletArkivActions<
139
142
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/extendEntity
140
143
  * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
141
144
  *
142
- * @param args - {entityKey, data}
143
- * @returns The entity with the given key. {@link Entity}
145
+ * @param data - The entity update parameters
146
+ * @param txParams - Optional transaction parameters
147
+ * @returns The updated entity with transaction hash
144
148
  *
145
149
  * @example
146
150
  * import { createWalletClient, http } from 'arkiv'
@@ -171,8 +175,9 @@ export type WalletArkivActions<
171
175
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/changeOwnership
172
176
  * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
173
177
  *
174
- * @param args - {entityKey, newOwner}
175
- * @returns The entity with the given address. {@link Entity}
178
+ * @param data - The ownership change parameters
179
+ * @param txParams - Optional transaction parameters
180
+ * @returns The entity with updated ownership and transaction hash
176
181
  */
177
182
  changeOwnership: (
178
183
  data: ChangeOwnershipParameters,
@@ -185,8 +190,9 @@ export type WalletArkivActions<
185
190
  * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/mutateEntities
186
191
  * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
187
192
  *
188
- * @param args - {data}
189
- * @returns The entity with the given key. {@link Entity}
193
+ * @param data - The mutation parameters (creates, updates, deletes, extensions)
194
+ * @param txParams - Optional transaction parameters
195
+ * @returns The mutation result with transaction hash
190
196
  *
191
197
  * @example
192
198
  * import { createWalletClient, http } from 'arkiv'
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module main
3
+ */
4
+
1
5
  // Re-export all viem stuff
2
6
  export * from "viem"
3
7
 
@@ -7,6 +11,8 @@ export type { PublicArkivClient } from "./clients/createPublicClient"
7
11
  export { createPublicClient } from "./clients/createPublicClient"
8
12
  export type { WalletArkivClient } from "./clients/createWalletClient"
9
13
  export { createWalletClient } from "./clients/createWalletClient"
14
+ export type { PublicArkivActions } from "./clients/decorators/arkivPublic"
15
+ export type { WalletArkivActions } from "./clients/decorators/arkivWallet"
10
16
 
11
17
  // re-export arkiv types in main index file
12
18
  export * from "./types"
@@ -10,12 +10,6 @@ export class NoCursorOrLimitError extends Error {
10
10
  }
11
11
  }
12
12
 
13
- export class OffsetCannotBeLessThanZeroError extends Error {
14
- constructor() {
15
- super("Offset cannot be less than 0")
16
- }
17
- }
18
-
19
13
  export class NoEntityFoundError extends Error {
20
14
  constructor() {
21
15
  super("No entity found")