@arkiv-network/sdk 0.3.2-dev.1 → 0.3.2-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 (47) hide show
  1. package/README.md +1 -0
  2. package/dist/chains/index.d.ts +25 -25
  3. package/dist/{entity-DvQtQL8v.d.ts → entity-0JJeFAgO.d.cts} +1 -5
  4. package/dist/entity-0JJeFAgO.d.cts.map +1 -0
  5. package/dist/{entity-jTQZmEAd.d.cts → entity-BG8YycYJ.d.ts} +1 -5
  6. package/dist/entity-BG8YycYJ.d.ts.map +1 -0
  7. package/dist/index.cjs +20 -36
  8. package/dist/index.d.cts +40 -38
  9. package/dist/index.d.cts.map +1 -1
  10. package/dist/index.d.ts +40 -38
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +36 -26
  13. package/dist/index.js.map +1 -1
  14. package/dist/query/index.cjs +3 -1
  15. package/dist/query/index.d.cts +3 -3
  16. package/dist/query/index.d.ts +3 -3
  17. package/dist/query/index.js +2 -2
  18. package/dist/{queryBuilder-BBtwhH0G.d.ts → queryBuilder-BNhnpewa.d.ts} +44 -6
  19. package/dist/queryBuilder-BNhnpewa.d.ts.map +1 -0
  20. package/dist/{queryBuilder-D22Tamry.js → queryBuilder-CAQ7TDMZ.js} +50 -21
  21. package/dist/queryBuilder-CAQ7TDMZ.js.map +1 -0
  22. package/dist/{queryBuilder-D-bqHg3w.cjs → queryBuilder-DEkfSiCF.cjs} +60 -19
  23. package/dist/{queryBuilder-DkhyyeFr.d.cts → queryBuilder-Dc_ii8LH.d.cts} +44 -6
  24. package/dist/queryBuilder-Dc_ii8LH.d.cts.map +1 -0
  25. package/dist/types/index.cjs +1 -0
  26. package/dist/types/index.d.cts +1 -1
  27. package/dist/types/index.d.ts +1 -1
  28. package/dist/types/index.js +1 -0
  29. package/dist/types-CBTc19th.cjs +0 -0
  30. package/dist/types-Cv8NMtbo.js +0 -0
  31. package/dist/utils/index.d.cts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/actions/public/getEntity.ts +18 -3
  34. package/src/clients/createPublicClient.ts +2 -2
  35. package/src/clients/createWalletClient.ts +2 -2
  36. package/src/clients/decorators/arkivPublic.ts +2 -2
  37. package/src/clients/decorators/arkivWallet.ts +12 -11
  38. package/src/index.ts +3 -34
  39. package/src/query/engine.test.ts +4 -4
  40. package/src/query/queryBuilder.test.ts +44 -3
  41. package/src/query/queryBuilder.ts +80 -10
  42. package/src/types/rpcSchema.ts +0 -5
  43. package/dist/entity-DvQtQL8v.d.ts.map +0 -1
  44. package/dist/entity-jTQZmEAd.d.cts.map +0 -1
  45. package/dist/queryBuilder-BBtwhH0G.d.ts.map +0 -1
  46. package/dist/queryBuilder-D22Tamry.js.map +0 -1
  47. package/dist/queryBuilder-DkhyyeFr.d.cts.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["query","toHex","zlib: typeof import(\"zlib\") | null","brotli: BrotliWasmType | null","toHex","toRlp","toBytes","createdEntities: Hex[]","updatedEntities: Hex[]","deletedEntities: Hex[]","extendedEntities: Hex[]","ownershipChanges: Hex[]"],"sources":["../src/actions/public/getBlockTiming.ts","../src/actions/public/getEntity.ts","../src/actions/public/getEntityCount.ts","../src/actions/public/query.ts","../src/actions/public/subscribeEntityEvents.ts","../src/clients/decorators/arkivPublic.ts","../src/clients/createPublicClient.ts","../src/utils/compression.ts","../src/utils/arkivTransactions.ts","../src/actions/wallet/changeOwnership.ts","../src/actions/wallet/createEntity.ts","../src/actions/wallet/deleteEntity.ts","../src/actions/wallet/extendEntity.ts","../src/actions/wallet/mutateEntities.ts","../src/actions/wallet/updateEntity.ts","../src/clients/decorators/arkivWallet.ts","../src/clients/createWalletClient.ts"],"sourcesContent":["import type { ArkivClient } from \"../../clients/baseClient\"\n\nexport type GetBlockTimingReturnType = {\n currentBlock: bigint\n currentBlockTime: number\n blockDuration: number\n}\n\nexport async function getBlockTiming(client: ArkivClient) {\n const blockTiming = await client.request({\n method: \"arkiv_getBlockTiming\",\n params: [],\n })\n console.debug(\"Block timing\", blockTiming)\n return {\n currentBlock: blockTiming.current_block,\n currentBlockTime: blockTiming.current_block_time,\n blockDuration: blockTiming.duration,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport { NoEntityFoundError } from \"../../query/errors\"\nimport { entityFromRpcResult } from \"../../utils/entities\"\n\nexport async function getEntity(client: ArkivClient, key: Hex) {\n const result = await client.request({\n method: \"arkiv_query\",\n params: [`$key = ${key}`],\n })\n console.debug(\"GetEntity result\", result)\n\n if (!result.data) {\n throw new NoEntityFoundError()\n }\n\n return entityFromRpcResult(result.data[0])\n}\n","import type { ArkivClient } from \"../../clients/baseClient\"\n\nexport async function getEntityCount(client: ArkivClient) {\n const count = await client.request({\n method: \"arkiv_getEntityCount\",\n params: [],\n })\n\n return count\n}\n","import type { ArkivClient } from \"../../clients/baseClient\"\nimport { entityFromRpcResult } from \"../../utils/entities\"\n\nexport async function query(client: ArkivClient, query: string) {\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query],\n })\n\n const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))\n\n return entities\n}\n","import { decodeEventLog, parseAbi, toHex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { PublicArkivClient } from \"../../clients/createPublicClient\"\nimport type {\n OnEntityCreatedEvent,\n OnEntityDeletedEvent,\n OnEntityExpiredEvent,\n OnEntityExpiresInExtendedEvent,\n OnEntityOwnerChangedEvent,\n OnEntityUpdatedEvent,\n} from \"../../types/events\"\n\nexport const arkivABI = parseAbi([\n \"event ArkivEntityCreated(uint256 indexed entityKey, address indexed ownerAddress, uint256 expirationBlock, uint256 cost)\",\n \"event ArkivEntityUpdated(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)\",\n \"event ArkivEntityExpired(uint256 indexed entityKey, address indexed ownerAddress)\",\n \"event ArkivEntityDeleted(uint256 indexed entityKey, address indexed ownerAddress)\",\n \"event ArkivEntityBTLExtended(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)\",\n \"event ArkivEntityOwnerChanged(uint256 indexed entityKey, address indexed oldOwnerAddress, address indexed newOwnerAddress)\",\n])\n\nexport async function subscribeEntityEvents(\n client: ArkivClient,\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpired,\n onEntityExpiresInExtended,\n onEntityOwnerChanged,\n }: {\n onError: ((error: Error) => void) | undefined\n onEntityCreated?: ((event: OnEntityCreatedEvent) => void) | undefined\n onEntityUpdated?: ((event: OnEntityUpdatedEvent) => void) | undefined\n onEntityDeleted?: ((event: OnEntityDeletedEvent) => void) | undefined\n onEntityExpired?: ((event: OnEntityExpiredEvent) => void) | undefined\n onEntityExpiresInExtended?: ((event: OnEntityExpiresInExtendedEvent) => void) | undefined\n onEntityOwnerChanged?: ((event: OnEntityOwnerChangedEvent) => void) | undefined\n },\n pollingInterval?: number,\n fromBlock?: bigint,\n): Promise<() => void> {\n const unsubscribe = (client as PublicArkivClient).watchEvent({\n pollingInterval: pollingInterval ?? 1000,\n fromBlock: fromBlock ?? 0n,\n events: arkivABI,\n onLogs: (logs) => {\n console.debug(\"logs from subscribeEntityEvents\", logs)\n for (const log of logs) {\n const event = decodeEventLog({\n abi: arkivABI,\n topics: log.topics,\n data: log.data,\n })\n console.debug(\"event from subscribeEntityEvents\", event)\n switch (event.eventName) {\n case \"ArkivEntityCreated\":\n onEntityCreated?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n expirationBlock: Number(event.args.expirationBlock),\n cost: event.args.cost,\n })\n break\n case \"ArkivEntityUpdated\":\n onEntityUpdated?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n oldExpirationBlock: Number(event.args.oldExpirationBlock),\n newExpirationBlock: Number(event.args.newExpirationBlock),\n cost: event.args.cost,\n })\n break\n case \"ArkivEntityDeleted\":\n onEntityDeleted?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n })\n break\n case \"ArkivEntityBTLExtended\":\n onEntityExpiresInExtended?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n oldExpirationBlock: Number(event.args.oldExpirationBlock),\n newExpirationBlock: Number(event.args.newExpirationBlock),\n cost: event.args.cost,\n })\n break\n case \"ArkivEntityExpired\":\n onEntityExpired?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n })\n break\n case \"ArkivEntityOwnerChanged\":\n onEntityOwnerChanged?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n oldOwner: event.args.oldOwnerAddress,\n newOwner: event.args.newOwnerAddress,\n })\n break\n default:\n console.warn(\"unknown event from subscribeEntityEvents\", event)\n break\n }\n }\n },\n onError: (error) => {\n console.error(\"error from subscribeEntityEvents\", error)\n onError?.(error)\n },\n })\n\n return unsubscribe\n}\n","import type { Account, Chain, Client, Hex, PublicActions, Transport } from \"viem\"\nimport { getBlockTiming } from \"../../actions/public/getBlockTiming\"\nimport { getEntity } from \"../../actions/public/getEntity\"\nimport { getEntityCount } from \"../../actions/public/getEntityCount\"\nimport { query } from \"../../actions/public/query\"\nimport { subscribeEntityEvents } from \"../../actions/public/subscribeEntityEvents\"\nimport { QueryBuilder } from \"../../query/queryBuilder\"\nimport type { Entity } from \"../../types/entity\"\nimport type {\n OnEntityCreatedEvent,\n OnEntityDeletedEvent,\n OnEntityExpiredEvent,\n OnEntityExpiresInExtendedEvent,\n OnEntityUpdatedEvent,\n} from \"../../types/events\"\n\nexport type PublicArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n> = Pick<\n PublicActions<transport, chain, account>,\n | \"getBalance\"\n | \"getBlock\"\n | \"getBlockNumber\"\n | \"getChainId\"\n | \"getLogs\"\n | \"getTransaction\"\n | \"getTransactionCount\"\n | \"getTransactionReceipt\"\n | \"waitForTransactionReceipt\"\n | \"watchEvent\"\n> & {\n /**\n * Returns the entity with the given key.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/public/getEntity\n *\n * @param args - {entityKey}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const entity = await client.getEntity(\"0x123\")\n * // {\n * // key: \"0x123\",\n * // value: \"0x123\",\n * // }\n */\n getEntity: (key: Hex) => Promise<Entity>\n\n /**\n * Returns a QueryBuilder instance for building and executing queries.\n * The QueryBuilder object follows the Builder pattern, allowing you to chain methods to build a query and then execute it.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/public/query\n *\n * @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const query = client.buildQuery()\n * const entities = await query.where(\"key\", \"=\", \"value\").ownedBy(\"0x123\").fetch()\n *\n */\n buildQuery: () => QueryBuilder\n\n /**\n * Returns a QueryResult instance for fetching the results of a raw query.\n * @returns A QueryResult instance for fetching the results of a raw query. {@link QueryResult}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const queryResult = client.query('key = value && $owner = 0x123')\n *\n */\n query: (query: string) => Promise<Entity[]>\n\n /**\n * Returns the number of entities in the DBChain.\n * @returns The number of entities in the DBChain. {@link number}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const entityCount = await client.getEntityCount()\n * // entityCount = 0\n */\n getEntityCount: () => Promise<number>\n\n /**\n * Returns the current block timing.\n * @returns The current block timing. {@link GetBlockTimingReturnType}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const blockTiming = await client.getBlockTiming()\n * // {\n * // currentBlock: 10n, // block number\n * // currentBlockTime: 1234567890, // block timestamp\n * // blockDuration: 2, // in seconds\n * // }\n */\n getBlockTiming: () => Promise<{\n currentBlock: bigint\n currentBlockTime: number\n blockDuration: number\n }>\n\n subscribeEntityEvents: (\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpiresInExtended,\n }: {\n onError?: (error: Error) => void\n onEntityCreated?: (event: OnEntityCreatedEvent) => void\n onEntityUpdated?: (event: OnEntityUpdatedEvent) => void\n onEntityDeleted?: (event: OnEntityDeletedEvent) => void\n onEntityExpired?: (event: OnEntityExpiredEvent) => void\n onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void\n },\n pollingInterval?: number,\n fromBlock?: bigint,\n ) => Promise<() => void>\n}\n\nexport function publicArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n>(client: Client<transport, chain, account>) {\n return {\n getEntity: (key: Hex) => getEntity(client, key),\n query: (rawQuery: string) => query(client, rawQuery),\n buildQuery: () => new QueryBuilder(client),\n getBlockTiming: () => getBlockTiming(client),\n getEntityCount: () => getEntityCount(client),\n subscribeEntityEvents: (\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpired,\n onEntityExpiresInExtended,\n }: {\n onError?: (error: Error) => void\n onEntityCreated?: (event: OnEntityCreatedEvent) => void\n onEntityUpdated?: (event: OnEntityUpdatedEvent) => void\n onEntityDeleted?: (event: OnEntityDeletedEvent) => void\n onEntityExpired?: (event: OnEntityExpiredEvent) => void\n onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void\n },\n pollingInterval?: number,\n fromBlock?: bigint,\n ) =>\n subscribeEntityEvents(\n client,\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpired,\n onEntityExpiresInExtended,\n },\n pollingInterval,\n fromBlock,\n ),\n }\n}\n","import type {\n Account,\n Address,\n Chain,\n Client,\n ParseAccount,\n Prettify,\n PublicClientConfig,\n RpcSchema,\n Transport,\n} from \"viem\"\nimport { createClient, publicActions } from \"viem\"\nimport type { ArkivRpcSchema } from \"../types/rpcSchema\"\nimport { type PublicArkivActions, publicArkivActions } from \"./decorators/arkivPublic\"\n\nexport type PublicArkivClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n accountOrAddress extends Account | undefined = undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n> = Prettify<\n Client<transport, chain, accountOrAddress, rpcSchema, PublicArkivActions<transport, chain>>\n>\n\n/**\n * Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/clients/public\n *\n * 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.golemdb.io/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.golemdb.io/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).\n *\n * @param config - {@link PublicClientConfig}\n * @returns A Arkiv Public Client. {@link PublicArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n */\nexport function createPublicClient<\n transport extends Transport,\n chain extends Chain | undefined = undefined,\n accountOrAddress extends Account | Address | undefined = undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n>(\n parameters: PublicClientConfig<transport, chain, accountOrAddress, rpcSchema>,\n): PublicArkivClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema> {\n const { key = \"public\", name = \"Public Client\" } = parameters\n const client = createClient({\n ...parameters,\n key,\n name,\n })\n\n return client.extend(publicActions).extend(publicArkivActions) as unknown as PublicArkivClient<\n transport,\n chain,\n ParseAccount<accountOrAddress>,\n rpcSchema\n >\n}\n","// src/utils/compression.ts\n\nimport type { BrotliWasmType } from \"brotli-wasm\"\n\n// Detect if we're in Node.js environment\nconst isNode = typeof process !== \"undefined\" && process.versions?.node != null\n\nlet zlib: typeof import(\"zlib\") | null = null\nlet brotli: BrotliWasmType | null = null\n\n// Lazy load zlib (Node.js only)\nasync function getZlib(): Promise<typeof import(\"zlib\") | null> {\n if (!isNode) return null\n\n if (!zlib) {\n try {\n zlib = await import(\"zlib\")\n } catch (error) {\n console.error(\"Error importing zlib\", error)\n return null\n }\n }\n return zlib\n}\n\n// Lazy load brotli-wasm (browser/fallback)\nasync function getBrotli(): Promise<BrotliWasmType | null> {\n if (brotli) return brotli\n\n try {\n const brotliModule = await import(\"brotli-wasm\")\n brotli = brotliModule.default || brotliModule\n } catch (error) {\n console.error(\"Error importing brotli-wasm\", error)\n return null\n }\n\n return brotli\n}\n\nexport async function compress(data: Uint8Array): Promise<Uint8Array> {\n console.debug(`Compressing data (size: ${data.length})`)\n\n // Try Node.js zlib first (if available)\n if (isNode) {\n const zlibModule = await getZlib()\n if (zlibModule) {\n try {\n // zlib.brotliCompress expects Buffer, returns Buffer\n const buffer = Buffer.from(data)\n const compressed = zlibModule.brotliCompressSync(buffer)\n const result = new Uint8Array(compressed)\n console.debug(`Brotli compressed with zlib (size: ${result.length})`)\n return result\n } catch (error) {\n console.warn(\"zlib compression failed, falling back to brotli-wasm\", error)\n }\n }\n }\n\n // Fallback to brotli-wasm (browser or if zlib fails)\n const brotliInstance = await getBrotli()\n if (!brotliInstance) {\n console.warn(\"Brotli instance not found, not compressing data\")\n return data\n }\n\n const brotliCompressed = brotliInstance.compress(data)\n console.debug(`Brotli compressed with wasm (size: ${brotliCompressed.length})`)\n return brotliCompressed\n}\n\nexport async function decompress(data: Uint8Array): Promise<Uint8Array> {\n // Try Node.js zlib first (if available)\n if (isNode) {\n const zlibModule = await getZlib()\n if (zlibModule) {\n try {\n // zlib.brotliDecompress expects Buffer, returns Buffer\n const buffer = Buffer.from(data)\n const decompressed = zlibModule.brotliDecompressSync(buffer)\n const result = new Uint8Array(decompressed)\n console.debug(`Brotli decompressed with zlib (size: ${result.length})`)\n return result\n } catch (error) {\n console.warn(\"zlib decompression failed, falling back to brotli-wasm\", error)\n }\n }\n }\n\n // Fallback to brotli-wasm (browser or if zlib fails)\n const brotliInstance = await getBrotli()\n if (!brotliInstance) {\n console.warn(\"Brotli instance not found, not decompressing data\")\n return data\n }\n\n return brotliInstance.decompress(data)\n}\n","import { type Hex, toBytes, toHex, toRlp } from \"viem\"\nimport type { ChangeOwnershipParameters } from \"../actions/wallet/changeOwnership\"\nimport type { CreateEntityParameters } from \"../actions/wallet/createEntity\"\nimport type { DeleteEntityParameters } from \"../actions/wallet/deleteEntity\"\nimport type { ExtendEntityParameters } from \"../actions/wallet/extendEntity\"\nimport type { UpdateEntityParameters } from \"../actions/wallet/updateEntity\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { WalletArkivClient } from \"../clients/createWalletClient\"\nimport { ARKIV_ADDRESS, BLOCK_TIME } from \"../consts\"\nimport type { TxParams } from \"../types\"\nimport { compress } from \"./compression\"\n\nexport function opsToTxData({\n creates,\n updates,\n deletes,\n extensions,\n ownershipChanges,\n}: {\n creates?: CreateEntityParameters[]\n updates?: UpdateEntityParameters[]\n deletes?: DeleteEntityParameters[]\n extensions?: ExtendEntityParameters[]\n ownershipChanges?: ChangeOwnershipParameters[]\n}) {\n function formatAttributes<T extends string | number | bigint | boolean>(attribute: {\n key: string\n value: T\n }): [Hex, Hex] {\n return [toHex(attribute.key), toHex(attribute.value)]\n }\n\n const payload = [\n //creates\n (creates ?? []).map((item) => [\n toHex(item.expiresIn / BLOCK_TIME),\n toHex(item.contentType),\n toHex(item.payload),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"string\")\n .map(formatAttributes),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"number\")\n .map(formatAttributes),\n ]),\n //updates\n (updates ?? []).map((item) => [\n item.entityKey,\n toHex(item.contentType),\n toHex(item.expiresIn / BLOCK_TIME),\n toHex(item.payload),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"string\")\n .map(formatAttributes),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"number\")\n .map(formatAttributes),\n ]),\n //deletes\n (deletes ?? []).map((item) => item.entityKey),\n //extends\n (extensions ?? []).map((item) => [item.entityKey, toHex(item.expiresIn / BLOCK_TIME)]),\n //ownershipChanges TODO\n (ownershipChanges ?? []).map((item) => [item.entityKey, item.newOwner]),\n ]\n\n console.debug(\"txData to send as RLP\", payload, payload.length)\n\n return toRlp(payload)\n}\n\nexport async function sendArkivTransaction(client: ArkivClient, data: Hex, txParams?: TxParams) {\n if (!client.account) throw new Error(\"Account required\")\n const walletClient = client as WalletArkivClient\n\n console.debug(\"Sending transaction\", {\n account: client.account,\n chain: client.chain,\n to: ARKIV_ADDRESS,\n value: 0n,\n data,\n ...txParams,\n })\n\n const compressed = await compress(toBytes(data))\n const txHash = await walletClient.sendTransaction({\n account: client.account,\n chain: client.chain,\n to: ARKIV_ADDRESS,\n value: 0n,\n data: toHex(compressed),\n ...txParams,\n })\n\n const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash })\n\n console.debug(\"Tx receipt\", receipt)\n\n return receipt\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the deleteEntity function.\n * - entityKey: The key of the entity to delete.\n */\nexport type ChangeOwnershipParameters = {\n entityKey: Hex\n newOwner: Hex\n}\n\n/**\n * Return type for the deleteEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type ChangeOwnershipReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function changeOwnership(\n client: ArkivClient,\n data: ChangeOwnershipParameters,\n txParams?: TxParams,\n): Promise<ChangeOwnershipReturnType> {\n console.debug(\"changeOwnership\", data)\n const txData = opsToTxData({ ownershipChanges: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from changeOwnership\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the createEntity function.\n * - payload: The payload of the entity.\n * - attributes: The attributes of the entity.\n * - contentType: The content type of the entity.\n * - expiresIn: The expires in of the entity in seconds.\n */\nexport type CreateEntityParameters = {\n payload: Uint8Array\n attributes: Attribute[]\n contentType: MimeType\n expiresIn: number\n}\n\n/**\n * Return type for the createEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type CreateEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function createEntity(\n client: ArkivClient,\n data: CreateEntityParameters,\n txParams?: TxParams,\n): Promise<CreateEntityReturnType> {\n console.debug(\"createEntity\", data)\n const txData = opsToTxData({ creates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from createEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the deleteEntity function.\n * - entityKey: The key of the entity to delete.\n */\nexport type DeleteEntityParameters = {\n entityKey: Hex\n}\n\n/**\n * Return type for the deleteEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type DeleteEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function deleteEntity(\n client: ArkivClient,\n data: DeleteEntityParameters,\n txParams?: TxParams,\n): Promise<DeleteEntityReturnType> {\n console.debug(\"deleteEntity\", data)\n const txData = opsToTxData({ deletes: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from deleteEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the extendEntity function.\n * - entityKey: The key of the entity to extend.\n * - expiresIn: The expires in of the entity in seconds.\n */\nexport type ExtendEntityParameters = {\n entityKey: Hex\n expiresIn: number\n}\n\n/**\n * Return type for the extendEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type ExtendEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function extendEntity(\n client: ArkivClient,\n data: ExtendEntityParameters,\n txParams?: TxParams,\n): Promise<ExtendEntityReturnType> {\n console.debug(\"extendEntity\", data)\n const txData = opsToTxData({ extensions: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from extendEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hex, TransactionReceipt } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport type { ChangeOwnershipParameters } from \"./changeOwnership\"\nimport type { CreateEntityParameters } from \"./createEntity\"\nimport type { DeleteEntityParameters } from \"./deleteEntity\"\nimport type { ExtendEntityParameters } from \"./extendEntity\"\nimport type { UpdateEntityParameters } from \"./updateEntity\"\n\n/**\n * Parameters for the mutateEntities function.\n * - creates: The creates to perform.\n * - updates: The updates to perform.\n * - deletes: The deletes to perform.\n * - extensions: The extensions to perform.\n */\nexport type MutateEntitiesParameters = {\n creates?: CreateEntityParameters[]\n updates?: UpdateEntityParameters[]\n deletes?: DeleteEntityParameters[]\n extensions?: ExtendEntityParameters[]\n ownershipChanges?: ChangeOwnershipParameters[]\n}\n\nfunction parseReceipt(receipt: TransactionReceipt, params: MutateEntitiesParameters) {\n const createdEntities: Hex[] = []\n const updatedEntities: Hex[] = []\n const deletedEntities: Hex[] = []\n const extendedEntities: Hex[] = []\n const ownershipChanges: Hex[] = []\n\n const totalCreates = params.creates?.length ?? 0\n const totalUpdates = params.updates?.length ?? 0\n const totalDeletes = params.deletes?.length ?? 0\n const totalExtensions = params.extensions?.length ?? 0\n\n // iterate over all logs and parse the event\n // each odd log is the interested ones, logs goes in order like: creates, deleted, updates, extends\n for (let i = 0; i < receipt.logs.length; i++) {\n const log = receipt.logs[i]\n if (i % 2 === 1) continue\n\n const index = i / 2\n if (index < totalCreates) {\n createdEntities.push(log.topics[1] as Hex)\n } else if (index < totalCreates + totalDeletes) {\n deletedEntities.push(log.topics[1] as Hex)\n } else if (index < totalCreates + totalUpdates + totalDeletes) {\n updatedEntities.push(log.topics[1] as Hex)\n } else if (index < totalCreates + totalUpdates + totalDeletes + totalExtensions) {\n extendedEntities.push(log.topics[1] as Hex)\n } else {\n ownershipChanges.push(log.topics[1] as Hex)\n }\n }\n\n return { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges }\n}\n\n/**\n * Return type for the mutateEntities function.\n * - txHash: The transaction hash.\n * - createdEntities: The keys of the created entities.\n * - updatedEntities: The keys of the updated entities.\n * - deletedEntities: The keys of the deleted entities.\n * - extendedEntities: The keys of the extended entities.\n * - ownershipChanges: The keys of the ownership changes.\n */\nexport type MutateEntitiesReturnType = {\n txHash: string\n createdEntities: Hex[]\n updatedEntities: Hex[]\n deletedEntities: Hex[]\n extendedEntities: Hex[]\n ownershipChanges: Hex[]\n}\nexport async function mutateEntities(\n client: ArkivClient,\n data: MutateEntitiesParameters,\n txParams?: TxParams,\n): Promise<MutateEntitiesReturnType> {\n if (!data.creates && !data.updates && !data.deletes && !data.extensions) {\n throw new Error(\"No operations to perform\")\n }\n\n const txData = opsToTxData({\n creates: data.creates ?? [],\n updates: data.updates ?? [],\n deletes: data.deletes ?? [],\n extensions: data.extensions ?? [],\n ownershipChanges: data.ownershipChanges ?? [],\n })\n\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from mutateEntities\", receipt)\n\n const { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges } =\n parseReceipt(receipt, data)\n return {\n txHash: receipt.transactionHash,\n createdEntities,\n updatedEntities,\n deletedEntities,\n extendedEntities,\n ownershipChanges,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the updateEntity function.\n * - entityKey: The key of the entity to update.\n * - payload: The payload of the entity.\n * - attributes: The attributes of the entity.\n * - contentType: The content type of the entity.\n * - expiresIn: The expires in of the entity in seconds.\n */\nexport type UpdateEntityParameters = {\n entityKey: Hex\n payload: Uint8Array\n attributes: Attribute[]\n contentType: MimeType\n expiresIn: number\n}\n\n/**\n * Return type for the updateEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type UpdateEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function updateEntity(\n client: ArkivClient,\n data: UpdateEntityParameters,\n txParams?: TxParams,\n): Promise<UpdateEntityReturnType> {\n console.debug(\"updateEntity\", data)\n const txData = opsToTxData({ updates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from updateEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Account, Chain, Client, PublicActions, Transport, WalletActions } from \"viem\"\nimport type {\n ChangeOwnershipParameters,\n ChangeOwnershipReturnType,\n} from \"../../actions/wallet/changeOwnership\"\nimport { changeOwnership } from \"../../actions/wallet/changeOwnership\"\nimport {\n type CreateEntityParameters,\n type CreateEntityReturnType,\n createEntity,\n} from \"../../actions/wallet/createEntity\"\nimport type {\n DeleteEntityParameters,\n DeleteEntityReturnType,\n} from \"../../actions/wallet/deleteEntity\"\nimport { deleteEntity } from \"../../actions/wallet/deleteEntity\"\nimport type {\n ExtendEntityParameters,\n ExtendEntityReturnType,\n} from \"../../actions/wallet/extendEntity\"\nimport { extendEntity } from \"../../actions/wallet/extendEntity\"\nimport type {\n MutateEntitiesParameters,\n MutateEntitiesReturnType,\n} from \"../../actions/wallet/mutateEntities\"\nimport { mutateEntities } from \"../../actions/wallet/mutateEntities\"\nimport type {\n UpdateEntityParameters,\n UpdateEntityReturnType,\n} from \"../../actions/wallet/updateEntity\"\nimport { updateEntity } from \"../../actions/wallet/updateEntity\"\nimport type { Entity, TxParams } from \"../../types\"\n\nexport type WalletArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n> = Pick<PublicActions<transport, chain, account>, \"waitForTransactionReceipt\"> &\n Pick<\n WalletActions<chain, account>,\n | \"addChain\"\n | \"sendTransaction\"\n | \"sendTransactionSync\"\n | \"sendRawTransaction\"\n | \"sendRawTransactionSync\"\n | \"signMessage\"\n | \"signTransaction\"\n > & {\n /**\n * Returns the entity with the given key.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/public/getEntity\n *\n * @param args - {entityKey}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.createEntity({\n * payload: toBytes(JSON.stringify({ entity: { entityType: \"testType\", entityId: \"testId\" } })),\n * attributes: [{ key: \"testKey\", value: \"testValue\" }],\n * expiresIn: 1000,\n * })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n createEntity: (\n data: CreateEntityParameters,\n txParams?: TxParams,\n ) => Promise<CreateEntityReturnType>\n\n /**\n * Updates the entity with the given key.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/updateEntity\n * - JSON-RPC Methods: [`golembase_updateEntity`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_updateEntity)\n *\n * @param args - {entityKey, data}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n */\n updateEntity: (\n data: UpdateEntityParameters,\n txParams?: TxParams,\n ) => Promise<UpdateEntityReturnType>\n\n /**\n * Deletes the entity with the given key.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/deleteEntity\n * - JSON-RPC Methods: [`golembase_deleteEntity`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_deleteEntity)\n *\n * @param args - {entityKey}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.deleteEntity({ entityKey: \"0x123\" })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n deleteEntity: (\n data: DeleteEntityParameters,\n txParams?: TxParams,\n ) => Promise<DeleteEntityReturnType>\n\n /**\n * Extends the entity with the given key.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/extendEntity\n * - JSON-RPC Methods: [`golembase_extendEntity`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_extendEntity)\n *\n * @param args - {entityKey, data}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.extendEntity(\"0x123\", {\n * expiresIn: 1000,\n * })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n extendEntity: (\n data: ExtendEntityParameters,\n txParams?: TxParams,\n ) => Promise<ExtendEntityReturnType>\n\n /**\n * Changes the ownership of the entity with the given address.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/changeOwnership\n * - JSON-RPC Methods: [`golembase_ownershipChange`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_ownershipChange)\n *\n * @param args - {entityKey, newOwner}\n * @returns The entity with the given address. {@link Entity}\n */\n changeOwnership: (\n data: ChangeOwnershipParameters,\n txParams?: TxParams,\n ) => Promise<ChangeOwnershipReturnType>\n\n /**\n * Mutates the entities with the given keys.\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/actions/wallet/mutateEntities\n * - JSON-RPC Methods: [`golembase_mutateEntities`](https://docs.golemdb.io/dev/json-rpc-api/#golembase_mutateEntities)\n *\n * @param args - {data}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.mutateEntities({\n * creates: [{\n * payload: toBytes(JSON.stringify({ entity: { entityType: \"testType\", entityId: \"testId\" } })),\n * attriubutes: [{ key: \"testKey\", value: \"testValue\" }],\n * expiresIn: 1000,\n * }],\n * updates: [{\n * entityKey: \"0x123\",\n * payload: toBytes(JSON.stringify({ entity: { entityType: \"testType\", entityId: \"testId\" } })),\n * attributes: [{ key: \"testKey\", value: \"testValue\" }],\n * expiresIn: 1000,\n * }],\n * deletes: [{\n * entityKey: \"0x321\",\n * }],\n * extensions: [{\n * entityKey: \"0x1234\",\n * expiresIn: 1000,\n * }],\n * })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n mutateEntities: (\n data: MutateEntitiesParameters,\n txParams?: TxParams,\n ) => Promise<MutateEntitiesReturnType>\n }\n\nexport function walletArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n>(client: Client<transport, chain, account>) {\n return {\n createEntity: (data: CreateEntityParameters, txParams?: TxParams) =>\n createEntity(client, data, txParams),\n updateEntity: (data: UpdateEntityParameters, txParams?: TxParams) =>\n updateEntity(client, data, txParams),\n deleteEntity: (data: DeleteEntityParameters, txParams?: TxParams) =>\n deleteEntity(client, data, txParams),\n extendEntity: (data: ExtendEntityParameters, txParams?: TxParams) =>\n extendEntity(client, data, txParams),\n changeOwnership: (data: ChangeOwnershipParameters, txParams?: TxParams) =>\n changeOwnership(client, data, txParams),\n mutateEntities: (data: MutateEntitiesParameters, txParams?: TxParams) =>\n mutateEntities(client, data, txParams),\n }\n}\n","import type {\n Account,\n Address,\n Chain,\n Client,\n ParseAccount,\n Prettify,\n RpcSchema,\n Transport,\n WalletClientConfig,\n} from \"viem\"\nimport { createClient, publicActions, walletActions } from \"viem\"\nimport type { ArkivRpcSchema } from \"../types/rpcSchema\"\nimport { type WalletArkivActions, walletArkivActions } from \"./decorators/arkivWallet\"\n\nexport type WalletArkivClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n> = Prettify<\n Client<transport, chain, account, rpcSchema, WalletArkivActions<transport, chain, account>>\n>\n\n/**\n * Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).\n *\n * - Docs: https://docs.golemdb.io/ts-sdk/clients/public\n *\n * 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.golemdb.io/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.golemdb.io/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).\n *\n * @param config - {@link PublicClientConfig}\n * @returns A Arkiv Public Client. {@link PublicArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n */\nexport function createWalletClient<\n transport extends Transport,\n chain extends Chain | undefined = undefined,\n accountOrAddress extends Account | Address | undefined = undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n>(\n parameters: WalletClientConfig<transport, chain, accountOrAddress, rpcSchema>,\n): WalletArkivClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema> {\n const { key = \"wallet\", name = \"Wallet Client\" } = parameters\n const client = createClient({\n ...parameters,\n key,\n name,\n })\n\n return client\n .extend(publicActions)\n .extend(walletActions)\n .extend(walletArkivActions) as unknown as WalletArkivClient<\n transport,\n chain,\n ParseAccount<accountOrAddress>,\n rpcSchema\n >\n}\n"],"mappings":";;;;;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QAAQ,MAAM,SAAS;EACzC,iBAAiB,MAAgC,aAC/C,eAAe,QAAQ,MAAM,SAAS;EACzC;;;;;;;;;;;;;;;;;;;;;;;;AC7MH,SAAgB,mBAMd,YACgF;CAChF,MAAM,EAAE,MAAM,UAAU,OAAO,oBAAoB;AAOnD,QANe,aAAa;EAC1B,GAAG;EACH;EACA;EACD,CAAC,CAGC,OAAO,cAAc,CACrB,OAAO,cAAc,CACrB,OAAO,mBAAmB"}
1
+ {"version":3,"file":"index.js","names":["bytes: Uint8Array","query","zlib: typeof import(\"zlib\") | null","brotli: BrotliWasmType | null","createdEntities: Hex[]","updatedEntities: Hex[]","deletedEntities: Hex[]","extendedEntities: Hex[]","ownershipChanges: Hex[]"],"sources":["../src/actions/public/getBlockTiming.ts","../src/actions/public/getEntity.ts","../src/actions/public/getEntityCount.ts","../src/actions/public/query.ts","../src/actions/public/subscribeEntityEvents.ts","../src/clients/decorators/arkivPublic.ts","../src/clients/createPublicClient.ts","../src/utils/compression.ts","../src/utils/arkivTransactions.ts","../src/actions/wallet/changeOwnership.ts","../src/actions/wallet/createEntity.ts","../src/actions/wallet/deleteEntity.ts","../src/actions/wallet/extendEntity.ts","../src/actions/wallet/mutateEntities.ts","../src/actions/wallet/updateEntity.ts","../src/clients/decorators/arkivWallet.ts","../src/clients/createWalletClient.ts"],"sourcesContent":["import type { ArkivClient } from \"../../clients/baseClient\"\n\nexport type GetBlockTimingReturnType = {\n currentBlock: bigint\n currentBlockTime: number\n blockDuration: number\n}\n\nexport async function getBlockTiming(client: ArkivClient) {\n const blockTiming = await client.request({\n method: \"arkiv_getBlockTiming\",\n params: [],\n })\n console.debug(\"Block timing\", blockTiming)\n return {\n currentBlock: blockTiming.current_block,\n currentBlockTime: blockTiming.current_block_time,\n blockDuration: blockTiming.duration,\n }\n}\n","import { bytesToHex, type Hex, hexToBytes } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport { NoEntityFoundError } from \"../../query/errors\"\nimport { entityFromRpcResult } from \"../../utils/entities\"\n\nexport async function getEntity(client: ArkivClient, key: Hex) {\n // Normalize the key into bytes\n let bytes: Uint8Array\n try {\n bytes = hexToBytes(key)\n } catch {\n throw new Error(`Invalid key format: ${key}. Key must be a valid hex string.`)\n }\n\n if (bytes.length !== 32) {\n throw new Error(\n `Invalid key length: ${bytes.length} bytes. Key must be 32 bytes (64 hex characters) long.`,\n )\n }\n\n const hexKey = bytesToHex(bytes)\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [`$key = ${hexKey}`],\n })\n\n if (!result.data) {\n throw new NoEntityFoundError()\n }\n\n return entityFromRpcResult(result.data[0])\n}\n","import type { ArkivClient } from \"../../clients/baseClient\"\n\nexport async function getEntityCount(client: ArkivClient) {\n const count = await client.request({\n method: \"arkiv_getEntityCount\",\n params: [],\n })\n\n return count\n}\n","import type { ArkivClient } from \"../../clients/baseClient\"\nimport { entityFromRpcResult } from \"../../utils/entities\"\n\nexport async function query(client: ArkivClient, query: string) {\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query],\n })\n\n const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))\n\n return entities\n}\n","import { decodeEventLog, parseAbi, toHex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { PublicArkivClient } from \"../../clients/createPublicClient\"\nimport type {\n OnEntityCreatedEvent,\n OnEntityDeletedEvent,\n OnEntityExpiredEvent,\n OnEntityExpiresInExtendedEvent,\n OnEntityOwnerChangedEvent,\n OnEntityUpdatedEvent,\n} from \"../../types/events\"\n\nexport const arkivABI = parseAbi([\n \"event ArkivEntityCreated(uint256 indexed entityKey, address indexed ownerAddress, uint256 expirationBlock, uint256 cost)\",\n \"event ArkivEntityUpdated(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)\",\n \"event ArkivEntityExpired(uint256 indexed entityKey, address indexed ownerAddress)\",\n \"event ArkivEntityDeleted(uint256 indexed entityKey, address indexed ownerAddress)\",\n \"event ArkivEntityBTLExtended(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)\",\n \"event ArkivEntityOwnerChanged(uint256 indexed entityKey, address indexed oldOwnerAddress, address indexed newOwnerAddress)\",\n])\n\nexport async function subscribeEntityEvents(\n client: ArkivClient,\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpired,\n onEntityExpiresInExtended,\n onEntityOwnerChanged,\n }: {\n onError: ((error: Error) => void) | undefined\n onEntityCreated?: ((event: OnEntityCreatedEvent) => void) | undefined\n onEntityUpdated?: ((event: OnEntityUpdatedEvent) => void) | undefined\n onEntityDeleted?: ((event: OnEntityDeletedEvent) => void) | undefined\n onEntityExpired?: ((event: OnEntityExpiredEvent) => void) | undefined\n onEntityExpiresInExtended?: ((event: OnEntityExpiresInExtendedEvent) => void) | undefined\n onEntityOwnerChanged?: ((event: OnEntityOwnerChangedEvent) => void) | undefined\n },\n pollingInterval?: number,\n fromBlock?: bigint,\n): Promise<() => void> {\n const unsubscribe = (client as PublicArkivClient).watchEvent({\n pollingInterval: pollingInterval ?? 1000,\n fromBlock: fromBlock ?? 0n,\n events: arkivABI,\n onLogs: (logs) => {\n console.debug(\"logs from subscribeEntityEvents\", logs)\n for (const log of logs) {\n const event = decodeEventLog({\n abi: arkivABI,\n topics: log.topics,\n data: log.data,\n })\n console.debug(\"event from subscribeEntityEvents\", event)\n switch (event.eventName) {\n case \"ArkivEntityCreated\":\n onEntityCreated?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n expirationBlock: Number(event.args.expirationBlock),\n cost: event.args.cost,\n })\n break\n case \"ArkivEntityUpdated\":\n onEntityUpdated?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n oldExpirationBlock: Number(event.args.oldExpirationBlock),\n newExpirationBlock: Number(event.args.newExpirationBlock),\n cost: event.args.cost,\n })\n break\n case \"ArkivEntityDeleted\":\n onEntityDeleted?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n })\n break\n case \"ArkivEntityBTLExtended\":\n onEntityExpiresInExtended?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n oldExpirationBlock: Number(event.args.oldExpirationBlock),\n newExpirationBlock: Number(event.args.newExpirationBlock),\n cost: event.args.cost,\n })\n break\n case \"ArkivEntityExpired\":\n onEntityExpired?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n owner: event.args.ownerAddress,\n })\n break\n case \"ArkivEntityOwnerChanged\":\n onEntityOwnerChanged?.({\n entityKey: toHex(event.args.entityKey, { size: 32 }),\n oldOwner: event.args.oldOwnerAddress,\n newOwner: event.args.newOwnerAddress,\n })\n break\n default:\n console.warn(\"unknown event from subscribeEntityEvents\", event)\n break\n }\n }\n },\n onError: (error) => {\n console.error(\"error from subscribeEntityEvents\", error)\n onError?.(error)\n },\n })\n\n return unsubscribe\n}\n","import type { Account, Chain, Client, Hex, PublicActions, Transport } from \"viem\"\nimport { getBlockTiming } from \"../../actions/public/getBlockTiming\"\nimport { getEntity } from \"../../actions/public/getEntity\"\nimport { getEntityCount } from \"../../actions/public/getEntityCount\"\nimport { query } from \"../../actions/public/query\"\nimport { subscribeEntityEvents } from \"../../actions/public/subscribeEntityEvents\"\nimport { QueryBuilder } from \"../../query/queryBuilder\"\nimport type { Entity } from \"../../types/entity\"\nimport type {\n OnEntityCreatedEvent,\n OnEntityDeletedEvent,\n OnEntityExpiredEvent,\n OnEntityExpiresInExtendedEvent,\n OnEntityUpdatedEvent,\n} from \"../../types/events\"\n\nexport type PublicArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n> = Pick<\n PublicActions<transport, chain, account>,\n | \"getBalance\"\n | \"getBlock\"\n | \"getBlockNumber\"\n | \"getChainId\"\n | \"getLogs\"\n | \"getTransaction\"\n | \"getTransactionCount\"\n | \"getTransactionReceipt\"\n | \"waitForTransactionReceipt\"\n | \"watchEvent\"\n> & {\n /**\n * Returns the entity with the given key.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity\n *\n * @param args - {entityKey}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const entity = await client.getEntity(\"0x123\")\n * // {\n * // key: \"0x123\",\n * // value: \"0x123\",\n * // }\n */\n getEntity: (key: Hex) => Promise<Entity>\n\n /**\n * Returns a QueryBuilder instance for building and executing queries.\n * The QueryBuilder object follows the Builder pattern, allowing you to chain methods to build a query and then execute it.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/query\n *\n * @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const query = client.buildQuery()\n * const entities = await query.where(\"key\", \"=\", \"value\").ownedBy(\"0x123\").fetch()\n *\n */\n buildQuery: () => QueryBuilder\n\n /**\n * Returns a QueryResult instance for fetching the results of a raw query.\n * @returns A QueryResult instance for fetching the results of a raw query. {@link QueryResult}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const queryResult = client.query('key = value && $owner = 0x123')\n *\n */\n query: (query: string) => Promise<Entity[]>\n\n /**\n * Returns the number of entities in the DBChain.\n * @returns The number of entities in the DBChain. {@link number}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const entityCount = await client.getEntityCount()\n * // entityCount = 0\n */\n getEntityCount: () => Promise<number>\n\n /**\n * Returns the current block timing.\n * @returns The current block timing. {@link GetBlockTimingReturnType}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const blockTiming = await client.getBlockTiming()\n * // {\n * // currentBlock: 10n, // block number\n * // currentBlockTime: 1234567890, // block timestamp\n * // blockDuration: 2, // in seconds\n * // }\n */\n getBlockTiming: () => Promise<{\n currentBlock: bigint\n currentBlockTime: number\n blockDuration: number\n }>\n\n subscribeEntityEvents: (\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpiresInExtended,\n }: {\n onError?: (error: Error) => void\n onEntityCreated?: (event: OnEntityCreatedEvent) => void\n onEntityUpdated?: (event: OnEntityUpdatedEvent) => void\n onEntityDeleted?: (event: OnEntityDeletedEvent) => void\n onEntityExpired?: (event: OnEntityExpiredEvent) => void\n onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void\n },\n pollingInterval?: number,\n fromBlock?: bigint,\n ) => Promise<() => void>\n}\n\nexport function publicArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n>(client: Client<transport, chain, account>) {\n return {\n getEntity: (key: Hex) => getEntity(client, key),\n query: (rawQuery: string) => query(client, rawQuery),\n buildQuery: () => new QueryBuilder(client),\n getBlockTiming: () => getBlockTiming(client),\n getEntityCount: () => getEntityCount(client),\n subscribeEntityEvents: (\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpired,\n onEntityExpiresInExtended,\n }: {\n onError?: (error: Error) => void\n onEntityCreated?: (event: OnEntityCreatedEvent) => void\n onEntityUpdated?: (event: OnEntityUpdatedEvent) => void\n onEntityDeleted?: (event: OnEntityDeletedEvent) => void\n onEntityExpired?: (event: OnEntityExpiredEvent) => void\n onEntityExpiresInExtended?: (event: OnEntityExpiresInExtendedEvent) => void\n },\n pollingInterval?: number,\n fromBlock?: bigint,\n ) =>\n subscribeEntityEvents(\n client,\n {\n onError,\n onEntityCreated,\n onEntityUpdated,\n onEntityDeleted,\n onEntityExpired,\n onEntityExpiresInExtended,\n },\n pollingInterval,\n fromBlock,\n ),\n }\n}\n","import type {\n Account,\n Address,\n Chain,\n Client,\n ParseAccount,\n Prettify,\n PublicClientConfig,\n RpcSchema,\n Transport,\n} from \"viem\"\nimport { createClient, publicActions } from \"viem\"\nimport type { ArkivRpcSchema } from \"../types/rpcSchema\"\nimport { type PublicArkivActions, publicArkivActions } from \"./decorators/arkivPublic\"\n\nexport type PublicArkivClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n accountOrAddress extends Account | undefined = undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n> = Prettify<\n Client<transport, chain, accountOrAddress, rpcSchema, PublicArkivActions<transport, chain>>\n>\n\n/**\n * Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/clients/public\n *\n * 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).\n *\n * @param config - {@link PublicClientConfig}\n * @returns A Arkiv Public Client. {@link PublicArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n */\nexport function createPublicClient<\n transport extends Transport,\n chain extends Chain | undefined = undefined,\n accountOrAddress extends Account | Address | undefined = undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n>(\n parameters: PublicClientConfig<transport, chain, accountOrAddress, rpcSchema>,\n): PublicArkivClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema> {\n const { key = \"public\", name = \"Public Client\" } = parameters\n const client = createClient({\n ...parameters,\n key,\n name,\n })\n\n return client.extend(publicActions).extend(publicArkivActions) as unknown as PublicArkivClient<\n transport,\n chain,\n ParseAccount<accountOrAddress>,\n rpcSchema\n >\n}\n","// src/utils/compression.ts\n\nimport type { BrotliWasmType } from \"brotli-wasm\"\n\n// Detect if we're in Node.js environment\nconst isNode = typeof process !== \"undefined\" && process.versions?.node != null\n\nlet zlib: typeof import(\"zlib\") | null = null\nlet brotli: BrotliWasmType | null = null\n\n// Lazy load zlib (Node.js only)\nasync function getZlib(): Promise<typeof import(\"zlib\") | null> {\n if (!isNode) return null\n\n if (!zlib) {\n try {\n zlib = await import(\"zlib\")\n } catch (error) {\n console.error(\"Error importing zlib\", error)\n return null\n }\n }\n return zlib\n}\n\n// Lazy load brotli-wasm (browser/fallback)\nasync function getBrotli(): Promise<BrotliWasmType | null> {\n if (brotli) return brotli\n\n try {\n const brotliModule = await import(\"brotli-wasm\")\n brotli = brotliModule.default || brotliModule\n } catch (error) {\n console.error(\"Error importing brotli-wasm\", error)\n return null\n }\n\n return brotli\n}\n\nexport async function compress(data: Uint8Array): Promise<Uint8Array> {\n console.debug(`Compressing data (size: ${data.length})`)\n\n // Try Node.js zlib first (if available)\n if (isNode) {\n const zlibModule = await getZlib()\n if (zlibModule) {\n try {\n // zlib.brotliCompress expects Buffer, returns Buffer\n const buffer = Buffer.from(data)\n const compressed = zlibModule.brotliCompressSync(buffer)\n const result = new Uint8Array(compressed)\n console.debug(`Brotli compressed with zlib (size: ${result.length})`)\n return result\n } catch (error) {\n console.warn(\"zlib compression failed, falling back to brotli-wasm\", error)\n }\n }\n }\n\n // Fallback to brotli-wasm (browser or if zlib fails)\n const brotliInstance = await getBrotli()\n if (!brotliInstance) {\n console.warn(\"Brotli instance not found, not compressing data\")\n return data\n }\n\n const brotliCompressed = brotliInstance.compress(data)\n console.debug(`Brotli compressed with wasm (size: ${brotliCompressed.length})`)\n return brotliCompressed\n}\n\nexport async function decompress(data: Uint8Array): Promise<Uint8Array> {\n // Try Node.js zlib first (if available)\n if (isNode) {\n const zlibModule = await getZlib()\n if (zlibModule) {\n try {\n // zlib.brotliDecompress expects Buffer, returns Buffer\n const buffer = Buffer.from(data)\n const decompressed = zlibModule.brotliDecompressSync(buffer)\n const result = new Uint8Array(decompressed)\n console.debug(`Brotli decompressed with zlib (size: ${result.length})`)\n return result\n } catch (error) {\n console.warn(\"zlib decompression failed, falling back to brotli-wasm\", error)\n }\n }\n }\n\n // Fallback to brotli-wasm (browser or if zlib fails)\n const brotliInstance = await getBrotli()\n if (!brotliInstance) {\n console.warn(\"Brotli instance not found, not decompressing data\")\n return data\n }\n\n return brotliInstance.decompress(data)\n}\n","import { type Hex, toBytes, toHex, toRlp } from \"viem\"\nimport type { ChangeOwnershipParameters } from \"../actions/wallet/changeOwnership\"\nimport type { CreateEntityParameters } from \"../actions/wallet/createEntity\"\nimport type { DeleteEntityParameters } from \"../actions/wallet/deleteEntity\"\nimport type { ExtendEntityParameters } from \"../actions/wallet/extendEntity\"\nimport type { UpdateEntityParameters } from \"../actions/wallet/updateEntity\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { WalletArkivClient } from \"../clients/createWalletClient\"\nimport { ARKIV_ADDRESS, BLOCK_TIME } from \"../consts\"\nimport type { TxParams } from \"../types\"\nimport { compress } from \"./compression\"\n\nexport function opsToTxData({\n creates,\n updates,\n deletes,\n extensions,\n ownershipChanges,\n}: {\n creates?: CreateEntityParameters[]\n updates?: UpdateEntityParameters[]\n deletes?: DeleteEntityParameters[]\n extensions?: ExtendEntityParameters[]\n ownershipChanges?: ChangeOwnershipParameters[]\n}) {\n function formatAttributes<T extends string | number | bigint | boolean>(attribute: {\n key: string\n value: T\n }): [Hex, Hex] {\n return [toHex(attribute.key), toHex(attribute.value)]\n }\n\n const payload = [\n //creates\n (creates ?? []).map((item) => [\n toHex(item.expiresIn / BLOCK_TIME),\n toHex(item.contentType),\n toHex(item.payload),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"string\")\n .map(formatAttributes),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"number\")\n .map(formatAttributes),\n ]),\n //updates\n (updates ?? []).map((item) => [\n item.entityKey,\n toHex(item.contentType),\n toHex(item.expiresIn / BLOCK_TIME),\n toHex(item.payload),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"string\")\n .map(formatAttributes),\n item.attributes\n .filter((attribute) => typeof attribute.value === \"number\")\n .map(formatAttributes),\n ]),\n //deletes\n (deletes ?? []).map((item) => item.entityKey),\n //extends\n (extensions ?? []).map((item) => [item.entityKey, toHex(item.expiresIn / BLOCK_TIME)]),\n //ownershipChanges TODO\n (ownershipChanges ?? []).map((item) => [item.entityKey, item.newOwner]),\n ]\n\n console.debug(\"txData to send as RLP\", payload, payload.length)\n\n return toRlp(payload)\n}\n\nexport async function sendArkivTransaction(client: ArkivClient, data: Hex, txParams?: TxParams) {\n if (!client.account) throw new Error(\"Account required\")\n const walletClient = client as WalletArkivClient\n\n console.debug(\"Sending transaction\", {\n account: client.account,\n chain: client.chain,\n to: ARKIV_ADDRESS,\n value: 0n,\n data,\n ...txParams,\n })\n\n const compressed = await compress(toBytes(data))\n const txHash = await walletClient.sendTransaction({\n account: client.account,\n chain: client.chain,\n to: ARKIV_ADDRESS,\n value: 0n,\n data: toHex(compressed),\n ...txParams,\n })\n\n const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash })\n\n console.debug(\"Tx receipt\", receipt)\n\n return receipt\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the deleteEntity function.\n * - entityKey: The key of the entity to delete.\n */\nexport type ChangeOwnershipParameters = {\n entityKey: Hex\n newOwner: Hex\n}\n\n/**\n * Return type for the deleteEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type ChangeOwnershipReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function changeOwnership(\n client: ArkivClient,\n data: ChangeOwnershipParameters,\n txParams?: TxParams,\n): Promise<ChangeOwnershipReturnType> {\n console.debug(\"changeOwnership\", data)\n const txData = opsToTxData({ ownershipChanges: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from changeOwnership\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the createEntity function.\n * - payload: The payload of the entity.\n * - attributes: The attributes of the entity.\n * - contentType: The content type of the entity.\n * - expiresIn: The expires in of the entity in seconds.\n */\nexport type CreateEntityParameters = {\n payload: Uint8Array\n attributes: Attribute[]\n contentType: MimeType\n expiresIn: number\n}\n\n/**\n * Return type for the createEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type CreateEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function createEntity(\n client: ArkivClient,\n data: CreateEntityParameters,\n txParams?: TxParams,\n): Promise<CreateEntityReturnType> {\n console.debug(\"createEntity\", data)\n const txData = opsToTxData({ creates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from createEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the deleteEntity function.\n * - entityKey: The key of the entity to delete.\n */\nexport type DeleteEntityParameters = {\n entityKey: Hex\n}\n\n/**\n * Return type for the deleteEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type DeleteEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function deleteEntity(\n client: ArkivClient,\n data: DeleteEntityParameters,\n txParams?: TxParams,\n): Promise<DeleteEntityReturnType> {\n console.debug(\"deleteEntity\", data)\n const txData = opsToTxData({ deletes: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from deleteEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the extendEntity function.\n * - entityKey: The key of the entity to extend.\n * - expiresIn: The expires in of the entity in seconds.\n */\nexport type ExtendEntityParameters = {\n entityKey: Hex\n expiresIn: number\n}\n\n/**\n * Return type for the extendEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type ExtendEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function extendEntity(\n client: ArkivClient,\n data: ExtendEntityParameters,\n txParams?: TxParams,\n): Promise<ExtendEntityReturnType> {\n console.debug(\"extendEntity\", data)\n const txData = opsToTxData({ extensions: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from extendEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hex, TransactionReceipt } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport type { ChangeOwnershipParameters } from \"./changeOwnership\"\nimport type { CreateEntityParameters } from \"./createEntity\"\nimport type { DeleteEntityParameters } from \"./deleteEntity\"\nimport type { ExtendEntityParameters } from \"./extendEntity\"\nimport type { UpdateEntityParameters } from \"./updateEntity\"\n\n/**\n * Parameters for the mutateEntities function.\n * - creates: The creates to perform.\n * - updates: The updates to perform.\n * - deletes: The deletes to perform.\n * - extensions: The extensions to perform.\n */\nexport type MutateEntitiesParameters = {\n creates?: CreateEntityParameters[]\n updates?: UpdateEntityParameters[]\n deletes?: DeleteEntityParameters[]\n extensions?: ExtendEntityParameters[]\n ownershipChanges?: ChangeOwnershipParameters[]\n}\n\nfunction parseReceipt(receipt: TransactionReceipt, params: MutateEntitiesParameters) {\n const createdEntities: Hex[] = []\n const updatedEntities: Hex[] = []\n const deletedEntities: Hex[] = []\n const extendedEntities: Hex[] = []\n const ownershipChanges: Hex[] = []\n\n const totalCreates = params.creates?.length ?? 0\n const totalUpdates = params.updates?.length ?? 0\n const totalDeletes = params.deletes?.length ?? 0\n const totalExtensions = params.extensions?.length ?? 0\n\n // iterate over all logs and parse the event\n // each odd log is the interested ones, logs goes in order like: creates, deleted, updates, extends\n for (let i = 0; i < receipt.logs.length; i++) {\n const log = receipt.logs[i]\n if (i % 2 === 1) continue\n\n const index = i / 2\n if (index < totalCreates) {\n createdEntities.push(log.topics[1] as Hex)\n } else if (index < totalCreates + totalDeletes) {\n deletedEntities.push(log.topics[1] as Hex)\n } else if (index < totalCreates + totalUpdates + totalDeletes) {\n updatedEntities.push(log.topics[1] as Hex)\n } else if (index < totalCreates + totalUpdates + totalDeletes + totalExtensions) {\n extendedEntities.push(log.topics[1] as Hex)\n } else {\n ownershipChanges.push(log.topics[1] as Hex)\n }\n }\n\n return { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges }\n}\n\n/**\n * Return type for the mutateEntities function.\n * - txHash: The transaction hash.\n * - createdEntities: The keys of the created entities.\n * - updatedEntities: The keys of the updated entities.\n * - deletedEntities: The keys of the deleted entities.\n * - extendedEntities: The keys of the extended entities.\n * - ownershipChanges: The keys of the ownership changes.\n */\nexport type MutateEntitiesReturnType = {\n txHash: string\n createdEntities: Hex[]\n updatedEntities: Hex[]\n deletedEntities: Hex[]\n extendedEntities: Hex[]\n ownershipChanges: Hex[]\n}\nexport async function mutateEntities(\n client: ArkivClient,\n data: MutateEntitiesParameters,\n txParams?: TxParams,\n): Promise<MutateEntitiesReturnType> {\n if (!data.creates && !data.updates && !data.deletes && !data.extensions) {\n throw new Error(\"No operations to perform\")\n }\n\n const txData = opsToTxData({\n creates: data.creates ?? [],\n updates: data.updates ?? [],\n deletes: data.deletes ?? [],\n extensions: data.extensions ?? [],\n ownershipChanges: data.ownershipChanges ?? [],\n })\n\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from mutateEntities\", receipt)\n\n const { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges } =\n parseReceipt(receipt, data)\n return {\n txHash: receipt.transactionHash,\n createdEntities,\n updatedEntities,\n deletedEntities,\n extendedEntities,\n ownershipChanges,\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\n\n/**\n * Parameters for the updateEntity function.\n * - entityKey: The key of the entity to update.\n * - payload: The payload of the entity.\n * - attributes: The attributes of the entity.\n * - contentType: The content type of the entity.\n * - expiresIn: The expires in of the entity in seconds.\n */\nexport type UpdateEntityParameters = {\n entityKey: Hex\n payload: Uint8Array\n attributes: Attribute[]\n contentType: MimeType\n expiresIn: number\n}\n\n/**\n * Return type for the updateEntity function.\n * - entityKey: The key of the entity.\n * - txHash: The transaction hash.\n */\nexport type UpdateEntityReturnType = {\n entityKey: Hex\n txHash: string\n}\n\nexport async function updateEntity(\n client: ArkivClient,\n data: UpdateEntityParameters,\n txParams?: TxParams,\n): Promise<UpdateEntityReturnType> {\n console.debug(\"updateEntity\", data)\n const txData = opsToTxData({ updates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n console.debug(\"Receipt from updateEntity\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Account, Chain, Client, PublicActions, Transport, WalletActions } from \"viem\"\nimport type {\n ChangeOwnershipParameters,\n ChangeOwnershipReturnType,\n} from \"../../actions/wallet/changeOwnership\"\nimport { changeOwnership } from \"../../actions/wallet/changeOwnership\"\nimport {\n type CreateEntityParameters,\n type CreateEntityReturnType,\n createEntity,\n} from \"../../actions/wallet/createEntity\"\nimport type {\n DeleteEntityParameters,\n DeleteEntityReturnType,\n} from \"../../actions/wallet/deleteEntity\"\nimport { deleteEntity } from \"../../actions/wallet/deleteEntity\"\nimport type {\n ExtendEntityParameters,\n ExtendEntityReturnType,\n} from \"../../actions/wallet/extendEntity\"\nimport { extendEntity } from \"../../actions/wallet/extendEntity\"\nimport type {\n MutateEntitiesParameters,\n MutateEntitiesReturnType,\n} from \"../../actions/wallet/mutateEntities\"\nimport { mutateEntities } from \"../../actions/wallet/mutateEntities\"\nimport type {\n UpdateEntityParameters,\n UpdateEntityReturnType,\n} from \"../../actions/wallet/updateEntity\"\nimport { updateEntity } from \"../../actions/wallet/updateEntity\"\nimport type { Entity, TxParams } from \"../../types\"\n\nexport type WalletArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n> = Pick<PublicActions<transport, chain, account>, \"waitForTransactionReceipt\"> &\n Pick<\n WalletActions<chain, account>,\n | \"addChain\"\n | \"sendTransaction\"\n | \"sendTransactionSync\"\n | \"sendRawTransaction\"\n | \"sendRawTransactionSync\"\n | \"signMessage\"\n | \"signTransaction\"\n > & {\n /**\n * Returns the entity with the given key.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param args - {entityKey}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.createEntity({\n * payload: toBytes(JSON.stringify({ entity: { entityType: \"testType\", entityId: \"testId\" } })),\n * attributes: [{ key: \"testKey\", value: \"testValue\" }],\n * expiresIn: 1000,\n * })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n createEntity: (\n data: CreateEntityParameters,\n txParams?: TxParams,\n ) => Promise<CreateEntityReturnType>\n\n /**\n * Updates the entity with the given key.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/updateEntity\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param args - {entityKey, data}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n */\n updateEntity: (\n data: UpdateEntityParameters,\n txParams?: TxParams,\n ) => Promise<UpdateEntityReturnType>\n\n /**\n * Deletes the entity with the given key.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/deleteEntity\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param args - {entityKey}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.deleteEntity({ entityKey: \"0x123\" })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n deleteEntity: (\n data: DeleteEntityParameters,\n txParams?: TxParams,\n ) => Promise<DeleteEntityReturnType>\n\n /**\n * Extends the entity with the given key.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/extendEntity\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param args - {entityKey, data}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.extendEntity(\"0x123\", {\n * expiresIn: 1000,\n * })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n extendEntity: (\n data: ExtendEntityParameters,\n txParams?: TxParams,\n ) => Promise<ExtendEntityReturnType>\n\n /**\n * Changes the ownership of the entity with the given address.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/changeOwnership\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param args - {entityKey, newOwner}\n * @returns The entity with the given address. {@link Entity}\n */\n changeOwnership: (\n data: ChangeOwnershipParameters,\n txParams?: TxParams,\n ) => Promise<ChangeOwnershipReturnType>\n\n /**\n * Mutates the entities with the given keys.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/mutateEntities\n * - JSON-RPC Methods: [`golembase_mutateEntities`](https://docs.arkiv.network/dev/json-rpc-api/#golembase_mutateEntities)\n *\n * @param args - {data}\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: kaolin,\n * transport: http(),\n * })\n * const { entityKey, txHash } = await client.mutateEntities({\n * creates: [{\n * payload: toBytes(JSON.stringify({ entity: { entityType: \"testType\", entityId: \"testId\" } })),\n * attriubutes: [{ key: \"testKey\", value: \"testValue\" }],\n * expiresIn: 1000,\n * }],\n * updates: [{\n * entityKey: \"0x123\",\n * payload: toBytes(JSON.stringify({ entity: { entityType: \"testType\", entityId: \"testId\" } })),\n * attributes: [{ key: \"testKey\", value: \"testValue\" }],\n * expiresIn: 1000,\n * }],\n * deletes: [{\n * entityKey: \"0x321\",\n * }],\n * extensions: [{\n * entityKey: \"0x1234\",\n * expiresIn: 1000,\n * }],\n * })\n * console.log(\"entityKey\", entityKey)\n * console.log(\"txHash\", txHash)\n * // {\n * // entityKey: \"0x123\",\n * // txHash: \"0x123\",\n * // }\n */\n mutateEntities: (\n data: MutateEntitiesParameters,\n txParams?: TxParams,\n ) => Promise<MutateEntitiesReturnType>\n }\n\nexport function walletArkivActions<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n>(client: Client<transport, chain, account>) {\n return {\n createEntity: (data: CreateEntityParameters, txParams?: TxParams) =>\n createEntity(client, data, txParams),\n updateEntity: (data: UpdateEntityParameters, txParams?: TxParams) =>\n updateEntity(client, data, txParams),\n deleteEntity: (data: DeleteEntityParameters, txParams?: TxParams) =>\n deleteEntity(client, data, txParams),\n extendEntity: (data: ExtendEntityParameters, txParams?: TxParams) =>\n extendEntity(client, data, txParams),\n changeOwnership: (data: ChangeOwnershipParameters, txParams?: TxParams) =>\n changeOwnership(client, data, txParams),\n mutateEntities: (data: MutateEntitiesParameters, txParams?: TxParams) =>\n mutateEntities(client, data, txParams),\n }\n}\n","import type {\n Account,\n Address,\n Chain,\n Client,\n ParseAccount,\n Prettify,\n RpcSchema,\n Transport,\n WalletClientConfig,\n} from \"viem\"\nimport { createClient, publicActions, walletActions } from \"viem\"\nimport type { ArkivRpcSchema } from \"../types/rpcSchema\"\nimport { type WalletArkivActions, walletArkivActions } from \"./decorators/arkivWallet\"\n\nexport type WalletArkivClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends Account | undefined = Account | undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n> = Prettify<\n Client<transport, chain, account, rpcSchema, WalletArkivActions<transport, chain, account>>\n>\n\n/**\n * Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/clients/public\n *\n * 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).\n *\n * @param config - {@link PublicClientConfig}\n * @returns A Arkiv Public Client. {@link PublicArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { kaolin } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: kaolin,\n * transport: http(),\n * })\n */\nexport function createWalletClient<\n transport extends Transport,\n chain extends Chain | undefined = undefined,\n accountOrAddress extends Account | Address | undefined = undefined,\n rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,\n>(\n parameters: WalletClientConfig<transport, chain, accountOrAddress, rpcSchema>,\n): WalletArkivClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema> {\n const { key = \"wallet\", name = \"Wallet Client\" } = parameters\n const client = createClient({\n ...parameters,\n key,\n name,\n })\n\n return client\n .extend(publicActions)\n .extend(walletActions)\n .extend(walletArkivActions) as unknown as WalletArkivClient<\n transport,\n chain,\n ParseAccount<accountOrAddress>,\n rpcSchema\n >\n}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AA8B,aAC3C,aAAa,QAAQ,MAAM,SAAS;EACtC,eAAe,MAA8B,aAC3C,aAAa,QAAQ,MAAM,SAAS;EACtC,eAAe,MAA8B,aAC3C,aAAa,QAAQ,MAAM,SAAS;EACtC,kBAAkB,MAAiC,aACjD,gBAAgB,QAAQ,MAAM,SAAS;EACzC,iBAAiB,MAAgC,aAC/C,eAAe,QAAQ,MAAM,SAAS;EACzC;;;;;;;;;;;;;;;;;;;;;;;;AC9MH,SAAgB,mBAMd,YACgF;CAChF,MAAM,EAAE,MAAM,UAAU,OAAO,oBAAoB;AAOnD,QANe,aAAa;EAC1B,GAAG;EACH;EACA;EACD,CAAC,CAGC,OAAO,cAAc,CACrB,OAAO,cAAc,CACrB,OAAO,mBAAmB"}
@@ -1,4 +1,4 @@
1
- const require_queryBuilder = require('../queryBuilder-D-bqHg3w.cjs');
1
+ const require_queryBuilder = require('../queryBuilder-DEkfSiCF.cjs');
2
2
 
3
3
  //#region src/query/predicate.ts
4
4
  /**
@@ -162,6 +162,8 @@ exports.OffsetCannotBeLessThanZeroError = require_queryBuilder.OffsetCannotBeLes
162
162
  exports.QueryBuilder = require_queryBuilder.QueryBuilder;
163
163
  exports.QueryResult = require_queryBuilder.QueryResult;
164
164
  exports.and = and;
165
+ exports.asc = require_queryBuilder.asc;
166
+ exports.desc = require_queryBuilder.desc;
165
167
  exports.eq = eq;
166
168
  exports.gt = gt;
167
169
  exports.gte = gte;
@@ -1,5 +1,5 @@
1
- import "../entity-jTQZmEAd.cjs";
2
- import { a as PredicateType, c as gt, d as lte, f as neq, i as PredicateContainerType, l as gte, m as or, n as QueryResult, o as and, p as not, r as Predicate, s as eq, t as QueryBuilder, u as lt } from "../queryBuilder-DkhyyeFr.cjs";
1
+ import "../entity-0JJeFAgO.cjs";
2
+ import { a as Predicate, c as and, d as gte, f as lt, g as or, h as not, i as QueryResult, l as eq, m as neq, n as asc, o as PredicateContainerType, p as lte, r as desc, s as PredicateType, t as QueryBuilder, u as gt } from "../queryBuilder-Dc_ii8LH.cjs";
3
3
 
4
4
  //#region src/query/errors.d.ts
5
5
  declare class NoMoreResultsError extends Error {
@@ -15,5 +15,5 @@ declare class NoEntityFoundError extends Error {
15
15
  constructor();
16
16
  }
17
17
  //#endregion
18
- export { NoCursorOrLimitError, NoEntityFoundError, NoMoreResultsError, OffsetCannotBeLessThanZeroError, Predicate, PredicateContainerType, PredicateType, QueryBuilder, QueryResult, and, eq, gt, gte, lt, lte, neq, not, or };
18
+ export { NoCursorOrLimitError, NoEntityFoundError, NoMoreResultsError, OffsetCannotBeLessThanZeroError, Predicate, PredicateContainerType, PredicateType, QueryBuilder, QueryResult, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or };
19
19
  //# sourceMappingURL=index.d.cts.map
@@ -1,5 +1,5 @@
1
- import "../entity-DvQtQL8v.js";
2
- import { a as PredicateType, c as gt, d as lte, f as neq, i as PredicateContainerType, l as gte, m as or, n as QueryResult, o as and, p as not, r as Predicate, s as eq, t as QueryBuilder, u as lt } from "../queryBuilder-BBtwhH0G.js";
1
+ import "../entity-BG8YycYJ.js";
2
+ import { a as Predicate, c as and, d as gte, f as lt, g as or, h as not, i as QueryResult, l as eq, m as neq, n as asc, o as PredicateContainerType, p as lte, r as desc, s as PredicateType, t as QueryBuilder, u as gt } from "../queryBuilder-BNhnpewa.js";
3
3
 
4
4
  //#region src/query/errors.d.ts
5
5
  declare class NoMoreResultsError extends Error {
@@ -15,5 +15,5 @@ declare class NoEntityFoundError extends Error {
15
15
  constructor();
16
16
  }
17
17
  //#endregion
18
- export { NoCursorOrLimitError, NoEntityFoundError, NoMoreResultsError, OffsetCannotBeLessThanZeroError, Predicate, PredicateContainerType, PredicateType, QueryBuilder, QueryResult, and, eq, gt, gte, lt, lte, neq, not, or };
18
+ export { NoCursorOrLimitError, NoEntityFoundError, NoMoreResultsError, OffsetCannotBeLessThanZeroError, Predicate, PredicateContainerType, PredicateType, QueryBuilder, QueryResult, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or };
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { a as NoEntityFoundError, i as NoCursorOrLimitError, n as QueryResult, o as NoMoreResultsError, s as OffsetCannotBeLessThanZeroError, t as QueryBuilder } from "../queryBuilder-D22Tamry.js";
1
+ import { c as NoMoreResultsError, i as QueryResult, l as OffsetCannotBeLessThanZeroError, n as asc, o as NoCursorOrLimitError, r as desc, s as NoEntityFoundError, t as QueryBuilder } from "../queryBuilder-CAQ7TDMZ.js";
2
2
 
3
3
  //#region src/query/predicate.ts
4
4
  /**
@@ -155,5 +155,5 @@ function not(key) {
155
155
  }
156
156
 
157
157
  //#endregion
158
- export { NoCursorOrLimitError, NoEntityFoundError, NoMoreResultsError, OffsetCannotBeLessThanZeroError, QueryBuilder, QueryResult, and, eq, gt, gte, lt, lte, neq, not, or };
158
+ export { NoCursorOrLimitError, NoEntityFoundError, NoMoreResultsError, OffsetCannotBeLessThanZeroError, QueryBuilder, QueryResult, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or };
159
159
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { g as ArkivClient, t as Entity } from "./entity-DvQtQL8v.js";
1
+ import { g as ArkivClient, t as Entity } from "./entity-BG8YycYJ.js";
2
2
  import { Hex } from "viem";
3
3
 
4
4
  //#region src/query/predicate.d.ts
@@ -129,6 +129,31 @@ declare class QueryResult {
129
129
  }
130
130
  //#endregion
131
131
  //#region src/query/queryBuilder.d.ts
132
+ type OrderByAttribute = {
133
+ name: string;
134
+ type: "string" | "number";
135
+ order: "asc" | "desc";
136
+ };
137
+ /**
138
+ * Helper function to create an ascending order by attribute
139
+ * @param attributeName - The name of the attribute to order by
140
+ * @param attributeType - The type of the attribute to order by (string or number)
141
+ * @returns The OrderByAttribute instance
142
+ *
143
+ * @example
144
+ * const ascAttribute = asc("name", "string")
145
+ */
146
+ declare function asc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute;
147
+ /**
148
+ * Helper function to create a descending order by attribute
149
+ * @param attributeName - The name of the attribute to order by
150
+ * @param attributeType - The type of the attribute to order by (string or number)
151
+ * @returns The OrderByAttribute instance
152
+ *
153
+ * @example
154
+ * const descAttribute = desc("name", "string")
155
+ */
156
+ declare function desc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute;
132
157
  /**
133
158
  * QueryBuilder is a helper class to build queries to the Arkiv DBChains.
134
159
  * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
@@ -163,14 +188,27 @@ declare class QueryBuilder {
163
188
  * The order of the attributes is important. The first attribute is the primary order by attribute.
164
189
  * @param attributeName - The name of the attribute to order by
165
190
  * @param attributeType - The type of the attribute to order by (string or number)
166
- * @param descending - The boolean value to set the order by descending
191
+ * @param order - The order to set the order by (asc or desc)
192
+ * @returns The QueryBuilder instance
193
+ *
194
+ * @example
195
+ * const builder = new QueryBuilder(client)
196
+ * builder.orderBy("name", "string", "desc")
197
+ */
198
+ orderBy(attributeName: string, attributeType: "string" | "number", order?: "asc" | "desc"): this;
199
+ /**
200
+ * Sets the orderBy for the query.
201
+ * This method takes the OrderByAttribute object as an argument and is mainly
202
+ * used to use the helper functions asc() and desc() to create the OrderByAttribute instances.
203
+ * @param orderByAttribute - The OrderByAttribute instance to set
167
204
  * @returns The QueryBuilder instance
168
205
  *
169
206
  * @example
170
207
  * const builder = new QueryBuilder(client)
171
- * builder.orderBy("name", "string", true)
208
+ * builder.orderBy(asc("name", "string"))
209
+ * builder.orderBy(desc("name", "string"))
172
210
  */
173
- orderBy(attributeName: string, attributeType: "string" | "number", descending?: boolean | undefined): this;
211
+ orderBy(orderByAttribute: OrderByAttribute): this;
174
212
  /**
175
213
  * Sets the withAttributes flag which will return the attributes for the entities if true
176
214
  * @param withAttributes - The boolean value to set
@@ -272,5 +310,5 @@ declare class QueryBuilder {
272
310
  count(): Promise<1>;
273
311
  }
274
312
  //#endregion
275
- export { PredicateType as a, gt as c, lte as d, neq as f, PredicateContainerType as i, gte as l, or as m, QueryResult as n, and as o, not as p, Predicate as r, eq as s, QueryBuilder as t, lt as u };
276
- //# sourceMappingURL=queryBuilder-BBtwhH0G.d.ts.map
313
+ export { Predicate as a, and as c, gte as d, lt as f, or as g, not as h, QueryResult as i, eq as l, neq as m, asc as n, PredicateContainerType as o, lte as p, desc as r, PredicateType as s, QueryBuilder as t, gt as u };
314
+ //# sourceMappingURL=queryBuilder-BNhnpewa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilder-BNhnpewa.d.ts","names":[],"sources":["../src/query/predicate.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":[],"mappings":";;;;KAAY,aAAA;KACA,sBAAA;KAEA,SAAA;QAEA;EALA,GAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA,GAAA,MAAA;AAEZ,CAAA,GAAY;EAEA,IAAA,EAKA,sBALA;EAKA,UAAA,EACM,SADN,EAAA;CACM;;AAclB;AAeA;AAcA;AAcA;AAcA;AAcA;AAcA;AAcA;AAaA;;iBAhHgB,EAAA,aAAe,cAAc;;ACrB7C;;;;;;;;;;ACIK,iBFgCW,GAAA,CEhCK,UAAA,EFgCW,SEhCX,EAAA,CAAA,EFgCyB,SEhCzB;AAerB;AAiBA;AAaA;;;;;;;;AAmPa,iBFlPG,EAAA,CEkPH,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EFlP4C,SEkP5C;;;;;;;;;;;iBFpOG,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;iBAa1C,GAAA,eAAkB;;;cCrIrB,WAAA;YACD;EDLA,QAAA,eAAa;EACb,QAAA,OAAA;EAEA,QAAA,MAAS;EAET,QAAA,aAAA;EAKA,QAAA,aAAA;EACM,IAA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157,38 @@ var QueryResult = class {
157
157
  //#endregion
158
158
  //#region src/query/queryBuilder.ts
159
159
  /**
160
+ * Helper function to create an ascending order by attribute
161
+ * @param attributeName - The name of the attribute to order by
162
+ * @param attributeType - The type of the attribute to order by (string or number)
163
+ * @returns The OrderByAttribute instance
164
+ *
165
+ * @example
166
+ * const ascAttribute = asc("name", "string")
167
+ */
168
+ function asc(attributeName, attributeType) {
169
+ return {
170
+ name: attributeName,
171
+ type: attributeType,
172
+ order: "asc"
173
+ };
174
+ }
175
+ /**
176
+ * Helper function to create a descending order by attribute
177
+ * @param attributeName - The name of the attribute to order by
178
+ * @param attributeType - The type of the attribute to order by (string or number)
179
+ * @returns The OrderByAttribute instance
180
+ *
181
+ * @example
182
+ * const descAttribute = desc("name", "string")
183
+ */
184
+ function desc(attributeName, attributeType) {
185
+ return {
186
+ name: attributeName,
187
+ type: attributeType,
188
+ order: "desc"
189
+ };
190
+ }
191
+ /**
160
192
  * QueryBuilder is a helper class to build queries to the Arkiv DBChains.
161
193
  * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
162
194
  * @param client - The Arkiv client
@@ -190,26 +222,23 @@ var QueryBuilder = class {
190
222
  this._ownedBy = ownedBy;
191
223
  return this;
192
224
  }
193
- /**
194
- * Sets the orderBy for the query.
195
- * It can be called multiple times to order by multiple attributes.
196
- * The order of the attributes is important. The first attribute is the primary order by attribute.
197
- * @param attributeName - The name of the attribute to order by
198
- * @param attributeType - The type of the attribute to order by (string or number)
199
- * @param descending - The boolean value to set the order by descending
200
- * @returns The QueryBuilder instance
201
- *
202
- * @example
203
- * const builder = new QueryBuilder(client)
204
- * builder.orderBy("name", "string", true)
205
- */
206
- orderBy(attributeName, attributeType, descending = void 0) {
225
+ orderBy(attributeNameOrOrderByAttribute, attributeType, order = "asc") {
207
226
  if (!this._orderBy) this._orderBy = [];
208
- this._orderBy.push({
209
- name: attributeName,
210
- type: attributeType === "number" ? "numeric" : attributeType,
211
- desc: !!descending
212
- });
227
+ const pushOrderByAttribute = ({ name, type, order: order$1 }) => {
228
+ this._orderBy?.push({
229
+ name,
230
+ type: type === "number" ? "numeric" : type,
231
+ desc: order$1 === "desc"
232
+ });
233
+ };
234
+ if (typeof attributeNameOrOrderByAttribute === "string") {
235
+ if (!attributeType) throw new Error("attributeType is required when using positional orderBy arguments");
236
+ pushOrderByAttribute({
237
+ name: attributeNameOrOrderByAttribute,
238
+ type: attributeType,
239
+ order
240
+ });
241
+ } else pushOrderByAttribute(attributeNameOrOrderByAttribute);
213
242
  return this;
214
243
  }
215
244
  /**
@@ -364,5 +393,5 @@ var QueryBuilder = class {
364
393
  };
365
394
 
366
395
  //#endregion
367
- export { NoEntityFoundError as a, NoCursorOrLimitError as i, QueryResult as n, NoMoreResultsError as o, entityFromRpcResult as r, OffsetCannotBeLessThanZeroError as s, QueryBuilder as t };
368
- //# sourceMappingURL=queryBuilder-D22Tamry.js.map
396
+ 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 };
397
+ //# sourceMappingURL=queryBuilder-CAQ7TDMZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilder-CAQ7TDMZ.js","names":["predicate","queryOptions: RpcQueryOptions","order"],"sources":["../src/query/errors.ts","../src/types/entity.ts","../src/utils/entities.ts","../src/query/engine.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":["export class NoMoreResultsError extends Error {\n constructor() {\n super(\"No more results\")\n }\n}\n\nexport class NoCursorOrLimitError extends Error {\n constructor() {\n super(\"Cursor and limit must be defined to fetch next\")\n }\n}\n\nexport class OffsetCannotBeLessThanZeroError extends Error {\n constructor() {\n super(\"Offset cannot be less than 0\")\n }\n}\n\nexport class NoEntityFoundError extends Error {\n constructor() {\n super(\"No entity found\")\n }\n}\n","import { bytesToString, type Hex } from \"viem\"\nimport type { MimeType } from \"../types\"\nimport type { Attribute } from \"./attributes\"\n\nexport class Entity {\n key: Hex\n owner: Hex\n expiresAtBlock: bigint\n payload: Uint8Array\n attributes: Attribute[]\n contentType: MimeType\n\n constructor(\n key: Hex,\n contentType: MimeType,\n owner: Hex,\n expiresAtBlock: bigint,\n payload: Uint8Array,\n attributes: Attribute[],\n ) {\n this.key = key\n this.owner = owner\n this.expiresAtBlock = expiresAtBlock\n this.payload = payload\n this.attributes = attributes\n this.contentType = contentType\n }\n\n toText(): string {\n return bytesToString(this.payload)\n }\n\n toJson(): any {\n return JSON.parse(bytesToString(this.payload))\n }\n}\n","import { toBytes } from \"viem\"\nimport { Entity } from \"../types/entity\"\nimport type { RpcEntity } from \"../types/rpcSchema\"\n\nexport async function entityFromRpcResult(rpcEntity: RpcEntity) {\n return new Entity(\n rpcEntity.key,\n rpcEntity.contentType,\n rpcEntity.owner,\n rpcEntity.expiresAt,\n toBytes(rpcEntity.value),\n [\n ...(rpcEntity.stringAttributes ?? []).map(({ key, value }) => ({\n key,\n value,\n })),\n ...(rpcEntity.numericAttributes ?? []).map(({ key, value }) => ({\n key,\n value: Number(value),\n })),\n ],\n )\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcOrderByAttribute, RpcQueryOptions } from \"../types/rpcSchema\"\nimport type { Predicate } from \"./predicate\"\n\nfunction processPredicates(predicates: Predicate[]): string {\n const processValue = (value: string | number) => {\n if (typeof value === \"string\") {\n return `\"${value}\"`\n }\n return value\n }\n return predicates\n .map((predicate) => {\n switch (predicate.type) {\n case \"eq\":\n return `${predicate.key} = ${processValue(predicate.value)}`\n case \"neq\":\n return `${predicate.key} != ${processValue(predicate.value)}`\n case \"gt\":\n return `${predicate.key} > ${processValue(predicate.value)}`\n case \"gte\":\n return `${predicate.key} >= ${processValue(predicate.value)}`\n case \"lt\":\n return `${predicate.key} < ${processValue(predicate.value)}`\n case \"lte\":\n return `${predicate.key} <= ${processValue(predicate.value)}`\n case \"not\":\n return `!${predicate.key}`\n case \"or\":\n return `(${predicate.predicates.map((predicate) => processPredicates([predicate])).join(\" || \")})`\n case \"and\":\n return `(${predicate.predicates.map((predicate) => processPredicates([predicate])).join(\" && \")})`\n default:\n return \"\"\n }\n })\n .join(\" && \")\n}\n\nexport async function processQuery(\n client: ArkivClient,\n queryParams: {\n predicates: Predicate[]\n limit: number | undefined\n cursor: string | undefined\n ownedBy: Hex | undefined\n orderBy: RpcOrderByAttribute[] | undefined\n validAtBlock?: bigint | undefined\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n },\n) {\n const {\n predicates,\n limit,\n cursor,\n ownedBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n } = queryParams\n\n console.debug(\n `Processing query with params: predicates: ${JSON.stringify(predicates)}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, orderBy: ${JSON.stringify(orderBy)}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`,\n )\n\n let query = processPredicates(predicates)\n if (ownedBy) {\n query += ` && $owner=${ownedBy}`\n }\n\n // remove leading and trailing spaces and leading &&\n query = query.trim()\n if (query.startsWith(\"&& \")) {\n query = query.slice(3)\n }\n\n const queryOptions: RpcQueryOptions = {\n includeData: {\n key: true,\n attributes: withAttributes ?? false,\n payload: withPayload ?? false,\n contentType: withMetadata ?? false,\n expiration: withMetadata ?? false,\n owner: withMetadata ?? false,\n },\n }\n\n if (validAtBlock !== undefined) {\n queryOptions.atBlock = Number(validAtBlock)\n }\n if (limit !== undefined) {\n queryOptions.resultsPerPage = limit\n }\n if (cursor !== undefined) {\n queryOptions.cursor = cursor\n }\n if (orderBy !== undefined) {\n queryOptions.orderBy = orderBy\n }\n\n console.debug(\n `Built query to send: ${query}, queryOptions: ${JSON.stringify({ includeData: queryOptions.includeData, atBlock: queryOptions.atBlock?.toString(), orderBy: queryOptions.orderBy, resultsPerPage: queryOptions.resultsPerPage, cursor: queryOptions.cursor })}`,\n )\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, queryOptions],\n })\n console.debug(\"Raw result from query: \", result)\n\n return result\n}\n","import type { Entity } from \"../types/entity\"\nimport { NoCursorOrLimitError, NoMoreResultsError } from \"./errors\"\nimport type { QueryBuilder } from \"./queryBuilder\"\n\nexport class QueryResult {\n entities: Entity[]\n private _endOfIteration: boolean\n private _cursor: string | undefined\n private _limit: number | undefined\n private _validAtBlock: bigint | undefined\n private _queryBuilder: QueryBuilder\n\n // Public getters for internal state\n get queryBuilder(): QueryBuilder {\n return this._queryBuilder\n }\n\n get cursor(): string | undefined {\n return this._cursor\n }\n\n constructor(\n entities: Entity[],\n queryBuilder: QueryBuilder,\n cursor: string | undefined,\n limit: number | undefined,\n validAtBlock: bigint | undefined,\n ) {\n this.entities = entities\n this._queryBuilder = queryBuilder\n this._endOfIteration = !limit || entities.length < limit\n this._cursor = cursor\n this._limit = limit\n this._validAtBlock = validAtBlock\n }\n\n async next() {\n if (this._cursor === undefined || this._limit === undefined) {\n throw new NoCursorOrLimitError()\n }\n if (this._endOfIteration) {\n throw new NoMoreResultsError()\n }\n this._queryBuilder.cursor(this._cursor)\n const result = await this._queryBuilder.fetch()\n this.entities = result.entities\n // Update the query builder reference\n this._queryBuilder = result.queryBuilder\n // Check if we've reached the end (no more cursor or we got fewer entities than limit)\n this._endOfIteration = !result.cursor || result.entities.length < this._limit\n // Update the cursor\n this._cursor = result.cursor\n\n // TODO check current block height and if it is not too old\n console.debug(\"Current block height for next page: \", this._validAtBlock)\n }\n\n hasNextPage() {\n return !this._endOfIteration\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcOrderByAttribute } from \"../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../utils/entities\"\nimport { processQuery } from \"./engine\"\nimport type { Predicate } from \"./predicate\"\nimport { QueryResult } from \"./queryResult\"\n\ntype OrderByAttribute = {\n name: string\n type: \"string\" | \"number\"\n order: \"asc\" | \"desc\"\n}\n\n/**\n * Helper function to create an ascending order by attribute\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @returns The OrderByAttribute instance\n *\n * @example\n * const ascAttribute = asc(\"name\", \"string\")\n */\nexport function asc(attributeName: string, attributeType: \"string\" | \"number\"): OrderByAttribute {\n return {\n name: attributeName,\n type: attributeType,\n order: \"asc\",\n }\n}\n\n/**\n * Helper function to create a descending order by attribute\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @returns The OrderByAttribute instance\n *\n * @example\n * const descAttribute = desc(\"name\", \"string\")\n */\nexport function desc(attributeName: string, attributeType: \"string\" | \"number\"): OrderByAttribute {\n return {\n name: attributeName,\n type: attributeType,\n order: \"desc\",\n }\n}\n/**\n * QueryBuilder is a helper class to build queries to the Arkiv DBChains.\n * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.\n * @param client - The Arkiv client\n * @returns The QueryBuilder instance {@link QueryBuilder}\n */\nexport class QueryBuilder {\n private _client: ArkivClient\n private _ownedBy: Hex | undefined\n private _orderBy: RpcOrderByAttribute[] | undefined\n private _validAtBlock: bigint | undefined\n private _withAttributes: boolean | undefined\n private _withMetadata: boolean | undefined\n private _withPayload: boolean | undefined\n private _limit: number | undefined\n private _cursor: string | undefined\n private _predicates: Predicate[]\n\n constructor(client: ArkivClient) {\n this._client = client\n this._predicates = []\n }\n\n /**\n * Sets the ownedBy filter\n * @param ownedBy - The address of the owner\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.ownedBy(\"0x1234567890123456789012345678901234567890\")\n */\n ownedBy(ownedBy: Hex) {\n this._ownedBy = ownedBy\n return this\n }\n\n /**\n * Sets the orderBy for the query.\n * It can be called multiple times to order by multiple attributes.\n * The order of the attributes is important. The first attribute is the primary order by attribute.\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @param order - The order to set the order by (asc or desc)\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(\"name\", \"string\", \"desc\")\n */\n orderBy(attributeName: string, attributeType: \"string\" | \"number\", order?: \"asc\" | \"desc\"): this\n /**\n * Sets the orderBy for the query.\n * This method takes the OrderByAttribute object as an argument and is mainly\n * used to use the helper functions asc() and desc() to create the OrderByAttribute instances.\n * @param orderByAttribute - The OrderByAttribute instance to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(asc(\"name\", \"string\"))\n * builder.orderBy(desc(\"name\", \"string\"))\n */\n orderBy(orderByAttribute: OrderByAttribute): this\n orderBy(\n attributeNameOrOrderByAttribute: string | OrderByAttribute,\n attributeType?: \"string\" | \"number\",\n order: \"asc\" | \"desc\" = \"asc\",\n ) {\n if (!this._orderBy) {\n this._orderBy = []\n }\n\n const pushOrderByAttribute = ({ name, type, order }: OrderByAttribute) => {\n this._orderBy?.push({\n name,\n type: type === \"number\" ? \"numeric\" : type,\n desc: order === \"desc\",\n })\n }\n\n if (typeof attributeNameOrOrderByAttribute === \"string\") {\n if (!attributeType) {\n throw new Error(\"attributeType is required when using positional orderBy arguments\")\n }\n pushOrderByAttribute({\n name: attributeNameOrOrderByAttribute,\n type: attributeType,\n order,\n })\n } else {\n pushOrderByAttribute(attributeNameOrOrderByAttribute)\n }\n\n return this\n }\n\n /**\n * Sets the withAttributes flag which will return the attributes for the entities if true\n * @param withAttributes - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withAttributes(true)\n */\n withAttributes(withAttributes: boolean = true) {\n this._withAttributes = withAttributes\n return this\n }\n\n /**\n * Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true\n * @param withMetadata - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withMetadata(true)\n */\n withMetadata(withMetadata: boolean = true) {\n this._withMetadata = withMetadata\n return this\n }\n\n /**\n * Sets the withPayload flag which will return the payload for the entities if true\n * @param withPayload - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withPayload(true)\n */\n withPayload(withPayload: boolean = true) {\n this._withPayload = withPayload\n return this\n }\n\n /**\n * Sets the limit for the query\n * @param limit - The number of entities to return\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.limit(10)\n */\n limit(limit: number) {\n this._limit = limit\n return this\n }\n\n /**\n * Sets the cursor for the query - it is advances setting which rather shouldn't be used manually but it is provided from query result if limit is used (pagination).\n * @param cursor - The cursor to set which tells to RPC Query server where to start or continue the query.\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.offset(10)\n */\n cursor(cursor: string) {\n this._cursor = cursor\n return this\n }\n\n /**\n * Sets the validAtBlock for the query which tells at which block height the state we are intested.\n * If not set, the latest block is used.\n * @param validAtBlock - The block number to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.validAtBlock(10000)\n */\n validAtBlock(validAtBlock: bigint) {\n this._validAtBlock = validAtBlock\n return this\n }\n\n /**\n * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.\n * Predicates can be nested using 'or' and 'and' predicates.\n * @param predicates - The predicates to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.where(eq(\"name\", \"John\"))\n * builder.where([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), and([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), and([eq(\"age\", 32), eq(\"age\", 33)])])])])\n */\n where(predicates: Predicate[] | Predicate) {\n if (Array.isArray(predicates)) {\n this._predicates.push(...predicates)\n } else {\n this._predicates.push(predicates)\n }\n return this\n }\n\n /**\n * Fetches the entities from the query. Re\n * It will return a QueryResult instance which can be used to fetch the next and previous pages.\n * @returns The QueryResult instance {@link QueryResult}\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).fetch()\n * // result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }\n */\n async fetch() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: this._orderBy,\n validAtBlock: this._validAtBlock,\n withAttributes: this._withAttributes,\n withMetadata: this._withMetadata,\n withPayload: this._withPayload,\n })\n\n const entities = await Promise.all(\n queryResult.data.map((entity) => entityFromRpcResult(entity)),\n )\n\n this.cursor(queryResult.cursor)\n this.validAtBlock(queryResult.blockNumber)\n\n return new QueryResult(entities, this, this._cursor, this._limit, this._validAtBlock)\n }\n\n /**\n * Counts the entities from the query.\n * @returns The number of entities\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).count()\n * // result = 10\n */\n async count() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: undefined,\n validAtBlock: this._validAtBlock,\n withAttributes: false,\n withMetadata: false,\n withPayload: false,\n })\n\n return queryResult.data.length ?? 0\n }\n}\n"],"mappings":";;;AAAA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;AACZ,QAAM,kBAAkB;;;AAI5B,IAA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