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

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 (38) hide show
  1. package/dist/chains/index.d.cts +25 -25
  2. package/dist/chains/index.d.cts.map +1 -1
  3. package/dist/{entity-CHiZ2Qu1.d.ts → entity-B6g_EPm1.d.cts} +11 -1
  4. package/dist/entity-B6g_EPm1.d.cts.map +1 -0
  5. package/dist/{entity-BSU5-vyY.d.cts → entity-qoLMAuuk.d.ts} +11 -1
  6. package/dist/entity-qoLMAuuk.d.ts.map +1 -0
  7. package/dist/{index-CzqHiUAo.d.ts → index-DdspxNAA.d.ts} +41 -16
  8. package/dist/index-DdspxNAA.d.ts.map +1 -0
  9. package/dist/{index-gj33r3rd.d.cts → index-Ds9dwqb5.d.cts} +41 -16
  10. package/dist/index-Ds9dwqb5.d.cts.map +1 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.d.cts +2 -3
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.ts +2 -3
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/query/index.cjs +5 -27
  19. package/dist/query/index.d.cts +2 -2
  20. package/dist/query/index.d.ts +2 -2
  21. package/dist/query/index.js +5 -27
  22. package/dist/query/index.js.map +1 -1
  23. package/dist/{queryBuilder-D-ACo-g_.js → queryBuilder-D2uwP9jI.js} +11 -20
  24. package/dist/{queryBuilder-D-ACo-g_.js.map → queryBuilder-D2uwP9jI.js.map} +1 -1
  25. package/dist/{queryBuilder-CTPwve9u.cjs → queryBuilder-UW2MCaX4.cjs} +10 -19
  26. package/dist/types/index.d.cts +1 -1
  27. package/dist/types/index.d.ts +1 -1
  28. package/package.json +1 -1
  29. package/src/actions/public/query.ts +10 -0
  30. package/src/clients/decorators/arkivPublic.ts +0 -1
  31. package/src/query/predicate.test.ts +43 -0
  32. package/src/query/predicate.ts +14 -10
  33. package/src/query/queryBuilder.test.ts +22 -0
  34. package/src/query/queryBuilder.ts +33 -13
  35. package/dist/entity-BSU5-vyY.d.cts.map +0 -1
  36. package/dist/entity-CHiZ2Qu1.d.ts.map +0 -1
  37. package/dist/index-CzqHiUAo.d.ts.map +0 -1
  38. package/dist/index-gj33r3rd.d.cts.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["logger","bytes: Uint8Array","rpcQueryOptions: RpcQueryOptions","query","logger","logger","zlib: typeof import(\"zlib\") | null","brotli: BrotliWasmType | null","logger","logger","logger","logger","logger","logger","createdEntities: Hex[]","updatedEntities: Hex[]","deletedEntities: Hex[]","extendedEntities: Hex[]","ownershipChanges: Hex[]","chains"],"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/validation.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","../src/utils/chains.ts"],"sourcesContent":["import type { ArkivClient } from \"../../clients/baseClient\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:public:get-block-timing\")\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 logger(\"Block timing %o\", blockTiming)\n return {\n currentBlock: BigInt(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 \"../../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: [\n `$key = ${hexKey}`,\n {\n includeData: {\n key: true,\n attributes: true,\n payload: true,\n contentType: true,\n expiration: true,\n owner: true,\n creator: true,\n createdAtBlock: true,\n lastModifiedAtBlock: true,\n transactionIndexInBlock: true,\n operationIndexInTransaction: true,\n },\n },\n ],\n })\n\n if (!result.data.length) {\n throw new NoEntityFoundError()\n }\n\n return await 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 { numberToHex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Entity } from \"../../types/entity\"\nimport type { RpcQueryOptions } from \"../../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../../utils/entities\"\n\nexport type QueryOptionsIncludeData = {\n attributes?: boolean\n payload?: boolean\n metadata?: boolean\n}\nexport type QueryOptionsOrderBy = {\n name: string\n type: \"string\" | \"numeric\"\n desc: \"asc\" | \"desc\"\n}\n\nexport type QueryOptions = {\n includeData?: QueryOptionsIncludeData\n atBlock?: bigint\n orderBy?: QueryOptionsOrderBy[]\n resultsPerPage?: number | undefined\n cursor?: string | undefined\n}\n\nexport type QueryReturnType = {\n entities: Entity[]\n cursor: string | undefined\n blockNumber: bigint | undefined\n}\n\nexport async function query(client: ArkivClient, query: string, queryOptions?: QueryOptions) {\n const rpcQueryOptions: RpcQueryOptions = {\n includeData: {\n key: true,\n payload: queryOptions?.includeData?.payload ?? true,\n attributes: queryOptions?.includeData?.attributes ?? false,\n contentType: queryOptions?.includeData?.metadata ?? false,\n expiration: queryOptions?.includeData?.metadata ?? false,\n owner: queryOptions?.includeData?.metadata ?? false,\n creator: queryOptions?.includeData?.metadata ?? false,\n createdAtBlock: queryOptions?.includeData?.metadata ?? false,\n lastModifiedAtBlock: queryOptions?.includeData?.metadata ?? false,\n transactionIndexInBlock: queryOptions?.includeData?.metadata ?? false,\n operationIndexInTransaction: queryOptions?.includeData?.metadata ?? false,\n },\n ...(queryOptions?.atBlock !== undefined && { atBlock: numberToHex(queryOptions.atBlock) }),\n ...(queryOptions?.orderBy && {\n orderBy: queryOptions?.orderBy.map((order) => ({\n name: order.name,\n type: order.type,\n desc: order.desc === \"desc\",\n })),\n }),\n ...(queryOptions?.resultsPerPage !== undefined && {\n resultsPerPage: numberToHex(queryOptions.resultsPerPage),\n }),\n ...(queryOptions?.cursor !== undefined && { cursor: queryOptions?.cursor }),\n }\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, rpcQueryOptions],\n })\n\n const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))\n\n return {\n entities,\n cursor: result.cursor,\n blockNumber: BigInt(result.blockNumber),\n }\n}\n","import { decodeEventLog, type Hex, 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\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:public:subscribe-entity-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,\n events: arkivABI,\n onLogs: (logs) => {\n logger(\"logs from subscribeEntityEvents %o\", logs)\n for (const log of logs) {\n const event = decodeEventLog({\n abi: arkivABI,\n topics: log.topics as [Hex, ...Hex[]] | [],\n data: log.data,\n })\n logger(\"event from subscribeEntityEvents %o\", 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 { type QueryOptions, type QueryReturnType, query } from \"../../actions/public/query\"\nimport { subscribeEntityEvents } from \"../../actions/public/subscribeEntityEvents\"\nimport { QueryBuilder, SelectQueryBuilder } from \"../../query/queryBuilder\"\nimport type { EntitySelection, FullEntity, ProjectedEntity, SelectArg } from \"../../query/selection\"\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 key - The entity key (hex string)\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 SelectQueryBuilder for building and executing queries — the recommended way to\n * read entities. You declare up front which parts of an entity you want returned, so results\n * always contain exactly the data you asked for.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/query\n *\n * @param selection - What to include in the results. Omit it (or pass `\"*\"`) to select everything,\n * or pass an object to select specific parts (at least one field is required). Every part is\n * opt-in, including the `key`. The selection is flat — each field maps to an entity field.\n * {@link SelectArg}\n * @returns A SelectQueryBuilder instance for building and executing queries. {@link SelectQueryBuilder}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n * import { eq } from 'arkiv/query'\n *\n * const client = createPublicClient({\n * chain: braga,\n * transport: http(),\n * })\n * // select everything\n * await client.select().where(eq(\"category\", \"docs\")).fetch()\n * await client.select(\"*\").where(eq(\"category\", \"docs\")).fetch()\n * // only the key\n * await client.select({ key: true }).where(eq(\"category\", \"docs\")).fetch()\n * // select specific fields — result typed { owner: Hex; attributes: Attribute[] }\n * await client.select({ owner: true, attributes: true }).fetch()\n * // a single field — result typed { owner: Hex }\n * await client.select({ owner: true }).fetch()\n */\n select: {\n /** Select every field. Pass nothing or `\"*\"`; the returned entities contain all fields. */\n (selection?: \"*\"): SelectQueryBuilder<FullEntity>\n /**\n * Pick the entity fields to return. Set the ones you want to `true` (at least one is required);\n * the result is typed to exactly those fields, so reading anything else is a compile error.\n *\n * Available fields: `key`, `owner`, `creator`, `contentType`, `payload`, `attributes`,\n * `expiresAtBlock`, `createdAtBlock`, `lastModifiedAtBlock`, `transactionIndexInBlock`,\n * `operationIndexInTransaction`.\n *\n * Pass the selection inline so its fields stay literal `true`. A selection stored in a `let`/\n * `const` variable widens to `boolean` and the result type can no longer be narrowed — annotate\n * it `as const` (e.g. `const sel = { owner: true } as const`) in that case.\n *\n * @example\n * client.select({ owner: true, attributes: true }) // entities typed { owner, attributes }\n * client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too\n */\n <const S extends EntitySelection>(selection: S): SelectQueryBuilder<ProjectedEntity<S>>\n /**\n * Dynamic selection: accepts a value typed {@link SelectArg} (e.g. built at runtime). The\n * result cannot be narrowed in this case, so the entities are typed as the full entity.\n */\n (selection: SelectArg): SelectQueryBuilder<FullEntity>\n }\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 * @deprecated Use {@link select} instead. `buildQuery()` returns only the entity `key` unless\n * you remember to opt in to data with `withAttributes()`/`withMetadata()`/`withPayload()`, which\n * is an easy mistake. `select()` makes the selection explicit. This method remains for backwards\n * compatibility and will be removed in a future release.\n *\n * @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 * If no query options are provided, all payload is included, but no metadata (like owner, expiredAt, etc.) and attributes.\n * @param query - The raw query string\n * @param queryOptions - The optional query options - {@link QueryOptions}\n * @returns A QueryReturnType instance - {@link QueryReturnType}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\n * transport: http(),\n * })\n * const queryResult = client.query('key = value && $owner = 0x123')\n * // queryResult = { entities: [{ key: \"0x123\", value: \"0x123\" }], cursor: undefined, blockNumber: undefined }\n * const queryResultWithOptions = client.query('key = value && $owner = 0x123', {\n * includeData: {\n * attributes: false,\n * payload: true,\n * metadata: true,\n * },\n * orderBy: [{ name: \"key\", type: \"string\", desc: \"asc\" }],\n * resultsPerPage: 10,\n * cursor: undefined,\n * atBlock: undefined,\n * })\n * // queryResultWithOptions = { entities: [{ key: \"0x123\", value: \"0x123\" }], cursor: \"...\", blockNumber: 32223n }\n */\n query: (query: string, queryOptions?: QueryOptions) => Promise<QueryReturnType>\n\n /**\n * Returns the number of entities in the DBChain.\n * @returns The number of entities in the DBChain\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 /**\n * Subscribes to entity events.\n * Takes an object with event handlers: {onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended}\n * @param pollingInterval - The polling interval in milliseconds\n * @param fromBlock - The block number to start from\n * @returns A function to unsubscribe from the events\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\n * transport: http(),\n * })\n * const unsubscribe = await client.subscribeEntityEvents({\n * onError: (error) => console.error(\"subscribeEntityEvents error\", error),\n * })\n * unsubscribe() // unsubscribe from the events\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, queryOptions?: QueryOptions) => query(client, rawQuery, queryOptions),\n buildQuery: () => new QueryBuilder(client),\n select: (selection?: SelectArg) => new SelectQueryBuilder(client, selection),\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 [Braga JSON-RPC API](https://braga.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 parameters - Configuration object for the public client (chain, transport, etc.)\n * @returns A Arkiv Public Client. {@link PublicArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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\"\nimport { getLogger } from \"./logger\"\n\nconst logger = getLogger(\"utils:compression\")\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 ? await brotliModule.default : brotliModule) as BrotliWasmType\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 logger(\"Compressing data size %d\", 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 logger(\"Brotli compressed with zlib size %d\", 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 logger(\"Brotli compressed with wasm size %d\", 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 logger(\"Brotli decompressed with zlib size %d\", 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 { BLOCK_TIME } from \"../consts\"\nimport { InvalidAttributeError, InvalidExpirationError } from \"../errors\"\nimport type { Attribute } from \"../types\"\n\n/**\n * Expiration on Arkiv is measured in blocks (1 block =\n * 2 seconds), so the value must be a positive integer that is\n * a multiple of the block time.\n *\n * @param expiresIn - The expiration in seconds.\n * @throws {InvalidExpirationError} If the value is not a positive integer that\n * is a multiple of the block time.\n */\nexport function validateExpiresIn(expiresIn: number): void {\n if (!Number.isInteger(expiresIn) || expiresIn <= 0 || expiresIn % BLOCK_TIME !== 0) {\n throw new InvalidExpirationError(expiresIn)\n }\n}\n\n/**\n * Validates a single attribute. Arkiv supports string and number attribute\n * values, but numeric values must be integers.\n *\n * @param attribute - The attribute to validate.\n * @throws {InvalidAttributeError} If the attribute has a non-integer numeric\n * value.\n */\nexport function validateAttribute(attribute: Attribute): void {\n if (typeof attribute.value === \"number\" && !Number.isInteger(attribute.value)) {\n throw new InvalidAttributeError(attribute.key, attribute.value)\n }\n}\n","import { type Hex, hexToString, TransactionExecutionError, 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 { EntityMutationError } from \"../errors\"\nimport type { TxParams } from \"../types\"\nimport { compress } from \"./compression\"\nimport { getLogger } from \"./logger\"\nimport { validateAttribute, validateExpiresIn } from \"./validation\"\n\nconst logger = getLogger(\"utils:arkiv-transactions\")\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 [\n toHex(attribute.key),\n toHex(typeof attribute.value === \"number\" && attribute.value === 0 ? \"\" : attribute.value),\n ]\n }\n\n const payload = [\n //creates\n (creates ?? []).map((item) => {\n validateExpiresIn(item.expiresIn)\n item.attributes.forEach(validateAttribute)\n return [\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 }),\n //updates\n (updates ?? []).map((item) => {\n validateExpiresIn(item.expiresIn)\n item.attributes.forEach(validateAttribute)\n return [\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 }),\n //deletes\n (deletes ?? []).map((item) => item.entityKey),\n //extends\n (extensions ?? []).map((item) => {\n validateExpiresIn(item.expiresIn)\n return [item.entityKey, toHex(item.expiresIn / BLOCK_TIME)]\n }),\n //ownershipChanges TODO\n (ownershipChanges ?? []).map((item) => [item.entityKey, item.newOwner]),\n ]\n\n logger(\"txData to send as RLP %o length %d\", 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 logger(\"Sending transaction %o\", {\n account: client.account,\n chain: client.chain,\n to: ARKIV_ADDRESS,\n value: 0n,\n data,\n ...txParams,\n })\n\n try {\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 logger(\"Tx receipt %o\", receipt)\n if (receipt.status === \"reverted\") {\n try {\n const callResult = await walletClient.call({\n account: client.account,\n to: ARKIV_ADDRESS,\n value: 0n,\n data: toHex(compressed),\n ...txParams,\n })\n throw new EntityMutationError(\n `Transaction ${receipt.transactionHash} reverted. Please make sure the data for entities doesn't contain invalid characters or invalid data types.\n Reason: ${callResult.data ? hexToString(callResult.data) : \"No reason provided by backend.\"}`,\n )\n } catch (err) {\n const error = err as { cause?: { details?: string } }\n const reason = error.cause?.details ?? \"No reason provided by backend.\"\n logger(\n \"Error while calling to get more details about reverted transaction. Reason: %s\",\n reason,\n )\n throw new EntityMutationError(\n `Transaction ${receipt.transactionHash} reverted. Reason: ${reason}`,\n )\n }\n }\n\n return receipt\n } catch (error) {\n let message = \"Transaction failed\"\n if (error instanceof TransactionExecutionError) {\n message += `: ${error.details}`\n } else if (error instanceof EntityMutationError) {\n throw error\n }\n\n logger(\"%s Detailed error stack: %o\", message, error)\n throw new EntityMutationError(message)\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\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:change-ownership\")\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 logger(\"changeOwnership %o\", data)\n const txData = opsToTxData({ ownershipChanges: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from changeOwnership %o\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:create-entity\")\n\n/**\n * Parameters for the createEntity function.\n * - payload: The payload of the entity.\n * - attributes: The attributes of the entity. Attribute values may be strings\n * or numbers, but numeric values **must be integers**. To store a non-integer,\n * scale it to an integer (e.g. `1.5` -> `1500`) to preserve numeric ordering,\n * or pass it as a string (e.g. `\"1.5\"`). A non-integer numeric value throws an\n * {@link InvalidAttributeError}.\n * - contentType: The content type of the entity.\n * - expiresIn: How long until the entity expires, in seconds. Because Arkiv\n * measures expiration in blocks (1 block = 2 seconds), this **must be a\n * positive integer and a multiple of the block time (2 seconds)**\n * Invalid values throw an {@link InvalidExpirationError}.\n */\nexport type CreateEntityParameters = {\n payload: Uint8Array\n /** Entity attributes. Numeric values must be integers (scale non-integers, e.g. `1.5` -> `1500`, or use a string). Throws {@link InvalidAttributeError} otherwise. */\n attributes: Attribute[]\n contentType: MimeType | string\n /** Seconds until expiry. Must be a positive integer and a multiple of the 2s block time.\n * Throws {@link InvalidExpirationError} otherwise. */\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: Hash\n}\n\nexport async function createEntity(\n client: ArkivClient,\n data: CreateEntityParameters,\n txParams?: TxParams,\n): Promise<CreateEntityReturnType> {\n logger(\"createEntity %o\", data)\n const txData = opsToTxData({ creates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from createEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:delete-entity\")\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: Hash\n}\n\nexport async function deleteEntity(\n client: ArkivClient,\n data: DeleteEntityParameters,\n txParams?: TxParams,\n): Promise<DeleteEntityReturnType> {\n logger(\"deleteEntity %o\", data)\n const txData = opsToTxData({ deletes: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from deleteEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:extend-entity\")\n\n/**\n * Parameters for the extendEntity function.\n * - entityKey: The key of the entity to extend.\n * - expiresIn: How long to extend the entity by, in seconds. Because Arkiv\n * measures expiration in blocks (1 block = 2 seconds), this **must be a\n * positive integer and a multiple of the block time (2 seconds)**.\n * Invalid values throw an {@link InvalidExpirationError}.\n */\nexport type ExtendEntityParameters = {\n entityKey: Hex\n /** Seconds to extend by. Must be a positive integer and a multiple of the 2s block time.\n * Throws {@link InvalidExpirationError} otherwise. */\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: Hash\n}\n\nexport async function extendEntity(\n client: ArkivClient,\n data: ExtendEntityParameters,\n txParams?: TxParams,\n): Promise<ExtendEntityReturnType> {\n logger(\"extendEntity %o\", data)\n const txData = opsToTxData({ extensions: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from extendEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hash, Hex, TransactionReceipt } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\nimport type { ChangeOwnershipParameters } from \"./changeOwnership\"\n\nconst logger = getLogger(\"actions:wallet:mutate-entities\")\n\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 // logs go in the following order: creates, deleted, updates, extends, ownership changes\n for (let index = 0; index < receipt.logs.length; index++) {\n const log = receipt.logs[index]\n\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: Hash\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 logger(\"Receipt from mutateEntities %o\", receipt)\n\n const { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges } =\n parseReceipt(receipt, data)\n return {\n txHash: receipt.transactionHash as Hash,\n createdEntities,\n updatedEntities,\n deletedEntities,\n extendedEntities,\n ownershipChanges,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:update-entity\")\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. Attribute values may be strings\n * or numbers, but numeric values **must be integers**. To store a non-integer,\n * scale it to an integer (e.g. `1.5` -> `1500`) to preserve numeric ordering,\n * or pass it as a string (e.g. `\"1.5\"`). A non-integer numeric value throws an\n * {@link InvalidAttributeError}.\n * - contentType: The content type of the entity.\n * - expiresIn: How long until the entity expires, in seconds. Because Arkiv\n * measures expiration in blocks (1 block = 2 seconds), this **must be a\n * positive integer and a multiple of the block time (2 seconds)**.\n * Invalid values throw an {@link InvalidExpirationError}.\n */\nexport type UpdateEntityParameters = {\n entityKey: Hex\n payload: Uint8Array\n /** Entity attributes. Numeric values must be integers (scale non-integers, e.g. `1.5` -> `1500`, or use a string). Throws {@link InvalidAttributeError} otherwise. */\n attributes: Attribute[]\n contentType: MimeType | string\n /** Seconds until expiry. Must be a positive integer and a multiple of the 2s block time.\n * Throws {@link InvalidExpirationError} otherwise. */\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: Hash\n}\n\nexport async function updateEntity(\n client: ArkivClient,\n data: UpdateEntityParameters,\n txParams?: TxParams,\n): Promise<UpdateEntityReturnType> {\n logger(\"updateEntity %o\", data)\n const txData = opsToTxData({ updates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from updateEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\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 { 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\" | \"call\"> &\n Pick<\n WalletActions<chain, account>,\n | \"addChain\"\n | \"sendCalls\"\n | \"waitForCallsStatus\"\n | \"sendTransaction\"\n | \"sendRawTransaction\"\n | \"signMessage\"\n | \"signTransaction\"\n > & {\n /**\n * Creates a new entity.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/createEntity\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param data - The entity creation parameters\n * @param txParams - Optional transaction parameters\n * @returns The created entity with transaction hash\n *\n * @throws {InvalidExpirationError} If `expiresIn` is not a positive integer\n * that is a multiple of the block time (2 seconds).\n * @throws {InvalidAttributeError} If a numeric attribute value is not an\n * integer.\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 data - The entity update parameters\n * @param txParams - Optional transaction parameters\n * @returns The updated entity with transaction hash\n *\n * @throws {InvalidExpirationError} If `expiresIn` is not a positive integer\n * that is a multiple of the block time (2 seconds).\n * @throws {InvalidAttributeError} If a numeric attribute value is not an\n * integer.\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 data - The entity deletion parameters\n * @param txParams - Optional transaction parameters\n * @returns The deleted entity with transaction hash\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 data - The entity update parameters\n * @param txParams - Optional transaction parameters\n * @returns The updated entity with transaction hash\n *\n * @throws {InvalidExpirationError} If `expiresIn` is not a positive integer\n * that is a multiple of the block time (2 seconds).\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 data - The ownership change parameters\n * @param txParams - Optional transaction parameters\n * @returns The entity with updated ownership and transaction hash\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: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param data - The mutation parameters (creates, updates, deletes, extensions)\n * @param txParams - Optional transaction parameters\n * @returns The mutation result with transaction hash\n *\n * @throws {InvalidExpirationError} If any create/update/extension `expiresIn`\n * is not a positive integer that is a multiple of the block time (2 seconds).\n * @throws {InvalidAttributeError} If a numeric attribute value is not an\n * integer.\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 [Braga JSON-RPC API](https://braga.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 parameters - Configuration object for the wallet client (chain, transport, account, etc.)\n * @returns A Arkiv Wallet Client. {@link WalletArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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","import type { Chain } from \"viem\"\nimport * as chains from \"../chains\"\n\n// Create a lookup map from all exported chains\nconst chainMap = new Map(Object.entries(chains).map(([key, value]) => [key.toLowerCase(), value]))\n\n/**\n * Get a chain from its name\n * @param name - The name of the chain, case insensitive\n * @returns The chain\n * @throws An error if the chain is not found\n */\nexport function chainFromName(name: string): Chain {\n const chain = chainMap.get(name.toLowerCase())\n if (!chain) {\n throw new Error(`Unknown chain: ${name}`)\n }\n return chain as Chain\n}\n"],"mappings":";;;;;;;;AAGA,MAAMA,WAAS,UAAU,kCAAkC;AAQ3D,eAAsB,eAAe,QAAqB;CACxD,MAAM,cAAc,MAAM,OAAO,QAAQ;EACvC,QAAQ;EACR,QAAQ,EAAE;EACX,CAAC;AACF,UAAO,mBAAmB,YAAY;AACtC,QAAO;EACL,cAAc,OAAO,YAAY,cAAc;EAC/C,kBAAkB,YAAY;EAC9B,eAAe,YAAY;EAC5B;;;;;AChBH,eAAsB,UAAU,QAAqB,KAAU;CAE7D,IAAIC;AACJ,KAAI;AACF,UAAQ,WAAW,IAAI;SACjB;AACN,QAAM,IAAI,MAAM,uBAAuB,IAAI,mCAAmC;;AAGhF,KAAI,MAAM,WAAW,GACnB,OAAM,IAAI,MACR,uBAAuB,MAAM,OAAO,wDACrC;CAGH,MAAM,SAAS,WAAW,MAAM;CAEhC,MAAM,SAAS,MAAM,OAAO,QAAQ;EAClC,QAAQ;EACR,QAAQ,CACN,UAAU,UACV,EACE,aAAa;GACX,KAAK;GACL,YAAY;GACZ,SAAS;GACT,aAAa;GACb,YAAY;GACZ,OAAO;GACP,SAAS;GACT,gBAAgB;GAChB,qBAAqB;GACrB,yBAAyB;GACzB,6BAA6B;GAC9B,EACF,CACF;EACF,CAAC;AAEF,KAAI,CAAC,OAAO,KAAK,OACf,OAAM,IAAI,oBAAoB;AAGhC,QAAO,MAAM,oBAA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;AAE/C,QAAO;EACL,QAAQ,QAAQ;EAChB,WAAW,QAAQ,KAAK,GAAG,OAAO;EACnC;;;;;ACqMH,SAAgB,mBAId,QAA2C;AAC3C,QAAO;EACL,eAAe,MAA8B,aAC3C,aAAa,QAAQ,MAAM,SAAS;EACtC,eAAe,MAA8B,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;;;;;;;;;;;;;;;;;;;;;;;;ACtOH,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;;;;;ACzD/B,MAAM,WAAW,IAAI,IAAI,OAAO,QAAQC,eAAO,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,IAAI,aAAa,EAAE,MAAM,CAAC,CAAC;;;;;;;AAQlG,SAAgB,cAAc,MAAqB;CACjD,MAAM,QAAQ,SAAS,IAAI,KAAK,aAAa,CAAC;AAC9C,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,kBAAkB,OAAO;AAE3C,QAAO"}
1
+ {"version":3,"file":"index.js","names":["logger","bytes: Uint8Array","rpcQueryOptions: RpcQueryOptions","query","logger","logger","zlib: typeof import(\"zlib\") | null","brotli: BrotliWasmType | null","logger","logger","logger","logger","logger","logger","createdEntities: Hex[]","updatedEntities: Hex[]","deletedEntities: Hex[]","extendedEntities: Hex[]","ownershipChanges: Hex[]","chains"],"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/validation.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","../src/utils/chains.ts"],"sourcesContent":["import type { ArkivClient } from \"../../clients/baseClient\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:public:get-block-timing\")\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 logger(\"Block timing %o\", blockTiming)\n return {\n currentBlock: BigInt(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 \"../../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: [\n `$key = ${hexKey}`,\n {\n includeData: {\n key: true,\n attributes: true,\n payload: true,\n contentType: true,\n expiration: true,\n owner: true,\n creator: true,\n createdAtBlock: true,\n lastModifiedAtBlock: true,\n transactionIndexInBlock: true,\n operationIndexInTransaction: true,\n },\n },\n ],\n })\n\n if (!result.data.length) {\n throw new NoEntityFoundError()\n }\n\n return await 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 { numberToHex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Entity } from \"../../types/entity\"\nimport type { RpcQueryOptions } from \"../../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../../utils/entities\"\n\nexport type QueryOptionsIncludeData = {\n attributes?: boolean\n payload?: boolean\n metadata?: boolean\n}\n/**\n * @deprecated Server-side ordering is not supported by the network. Sort the fetched\n * entities in JavaScript instead (e.g. `entities.sort(...)`). This type will be removed\n * in a future release.\n */\nexport type QueryOptionsOrderBy = {\n name: string\n type: \"string\" | \"numeric\"\n desc: \"asc\" | \"desc\"\n}\n\nexport type QueryOptions = {\n includeData?: QueryOptionsIncludeData\n atBlock?: bigint\n /**\n * @deprecated Server-side ordering is not supported by the network, so this option has no\n * effect on the returned order. Sort the fetched entities in JavaScript instead\n * (e.g. `entities.sort(...)`). This option will be removed in a future release.\n */\n orderBy?: QueryOptionsOrderBy[]\n resultsPerPage?: number | undefined\n cursor?: string | undefined\n}\n\nexport type QueryReturnType = {\n entities: Entity[]\n cursor: string | undefined\n blockNumber: bigint | undefined\n}\n\nexport async function query(client: ArkivClient, query: string, queryOptions?: QueryOptions) {\n const rpcQueryOptions: RpcQueryOptions = {\n includeData: {\n key: true,\n payload: queryOptions?.includeData?.payload ?? true,\n attributes: queryOptions?.includeData?.attributes ?? false,\n contentType: queryOptions?.includeData?.metadata ?? false,\n expiration: queryOptions?.includeData?.metadata ?? false,\n owner: queryOptions?.includeData?.metadata ?? false,\n creator: queryOptions?.includeData?.metadata ?? false,\n createdAtBlock: queryOptions?.includeData?.metadata ?? false,\n lastModifiedAtBlock: queryOptions?.includeData?.metadata ?? false,\n transactionIndexInBlock: queryOptions?.includeData?.metadata ?? false,\n operationIndexInTransaction: queryOptions?.includeData?.metadata ?? false,\n },\n ...(queryOptions?.atBlock !== undefined && { atBlock: numberToHex(queryOptions.atBlock) }),\n ...(queryOptions?.orderBy && {\n orderBy: queryOptions?.orderBy.map((order) => ({\n name: order.name,\n type: order.type,\n desc: order.desc === \"desc\",\n })),\n }),\n ...(queryOptions?.resultsPerPage !== undefined && {\n resultsPerPage: numberToHex(queryOptions.resultsPerPage),\n }),\n ...(queryOptions?.cursor !== undefined && { cursor: queryOptions?.cursor }),\n }\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, rpcQueryOptions],\n })\n\n const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))\n\n return {\n entities,\n cursor: result.cursor,\n blockNumber: BigInt(result.blockNumber),\n }\n}\n","import { decodeEventLog, type Hex, 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\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:public:subscribe-entity-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,\n events: arkivABI,\n onLogs: (logs) => {\n logger(\"logs from subscribeEntityEvents %o\", logs)\n for (const log of logs) {\n const event = decodeEventLog({\n abi: arkivABI,\n topics: log.topics as [Hex, ...Hex[]] | [],\n data: log.data,\n })\n logger(\"event from subscribeEntityEvents %o\", 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 { type QueryOptions, type QueryReturnType, query } from \"../../actions/public/query\"\nimport { subscribeEntityEvents } from \"../../actions/public/subscribeEntityEvents\"\nimport { QueryBuilder, SelectQueryBuilder } from \"../../query/queryBuilder\"\nimport type { EntitySelection, FullEntity, ProjectedEntity, SelectArg } from \"../../query/selection\"\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 key - The entity key (hex string)\n * @returns The entity with the given key. {@link Entity}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 SelectQueryBuilder for building and executing queries — the recommended way to\n * read entities. You declare up front which parts of an entity you want returned, so results\n * always contain exactly the data you asked for.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/public/query\n *\n * @param selection - What to include in the results. Omit it (or pass `\"*\"`) to select everything,\n * or pass an object to select specific parts (at least one field is required). Every part is\n * opt-in, including the `key`. The selection is flat — each field maps to an entity field.\n * {@link SelectArg}\n * @returns A SelectQueryBuilder instance for building and executing queries. {@link SelectQueryBuilder}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n * import { eq } from 'arkiv/query'\n *\n * const client = createPublicClient({\n * chain: braga,\n * transport: http(),\n * })\n * // select everything\n * await client.select().where(eq(\"category\", \"docs\")).fetch()\n * await client.select(\"*\").where(eq(\"category\", \"docs\")).fetch()\n * // only the key\n * await client.select({ key: true }).where(eq(\"category\", \"docs\")).fetch()\n * // select specific fields — result typed { owner: Hex; attributes: Attribute[] }\n * await client.select({ owner: true, attributes: true }).fetch()\n * // a single field — result typed { owner: Hex }\n * await client.select({ owner: true }).fetch()\n */\n select: {\n /** Select every field. Pass nothing or `\"*\"`; the returned entities contain all fields. */\n (selection?: \"*\"): SelectQueryBuilder<FullEntity>\n /**\n * Pick the entity fields to return. Set the ones you want to `true` (at least one is required);\n * the result is typed to exactly those fields, so reading anything else is a compile error.\n *\n * Available fields: `key`, `owner`, `creator`, `contentType`, `payload`, `attributes`,\n * `expiresAtBlock`, `createdAtBlock`, `lastModifiedAtBlock`, `transactionIndexInBlock`,\n * `operationIndexInTransaction`.\n *\n * Pass the selection inline so its fields stay literal `true`. A selection stored in a `let`/\n * `const` variable widens to `boolean` and the result type can no longer be narrowed — annotate\n * it `as const` (e.g. `const sel = { owner: true } as const`) in that case.\n *\n * @example\n * client.select({ owner: true, attributes: true }) // entities typed { owner, attributes }\n * client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too\n */\n <const S extends EntitySelection>(selection: S): SelectQueryBuilder<ProjectedEntity<S>>\n /**\n * Dynamic selection: accepts a value typed {@link SelectArg} (e.g. built at runtime). The\n * result cannot be narrowed in this case, so the entities are typed as the full entity.\n */\n (selection: SelectArg): SelectQueryBuilder<FullEntity>\n }\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 * @deprecated Use {@link select} instead. `buildQuery()` returns only the entity `key` unless\n * you remember to opt in to data with `withAttributes()`/`withMetadata()`/`withPayload()`, which\n * is an easy mistake. `select()` makes the selection explicit. This method remains for backwards\n * compatibility and will be removed in a future release.\n *\n * @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 * If no query options are provided, all payload is included, but no metadata (like owner, expiredAt, etc.) and attributes.\n * @param query - The raw query string\n * @param queryOptions - The optional query options - {@link QueryOptions}\n * @returns A QueryReturnType instance - {@link QueryReturnType}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\n * transport: http(),\n * })\n * const queryResult = client.query('key = value && $owner = 0x123')\n * // queryResult = { entities: [{ key: \"0x123\", value: \"0x123\" }], cursor: undefined, blockNumber: undefined }\n * const queryResultWithOptions = client.query('key = value && $owner = 0x123', {\n * includeData: {\n * attributes: false,\n * payload: true,\n * metadata: true,\n * },\n * resultsPerPage: 10,\n * cursor: undefined,\n * atBlock: undefined,\n * })\n * // queryResultWithOptions = { entities: [{ key: \"0x123\", value: \"0x123\" }], cursor: \"...\", blockNumber: 32223n }\n */\n query: (query: string, queryOptions?: QueryOptions) => Promise<QueryReturnType>\n\n /**\n * Returns the number of entities in the DBChain.\n * @returns The number of entities in the DBChain\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 /**\n * Subscribes to entity events.\n * Takes an object with event handlers: {onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended}\n * @param pollingInterval - The polling interval in milliseconds\n * @param fromBlock - The block number to start from\n * @returns A function to unsubscribe from the events\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\n * transport: http(),\n * })\n * const unsubscribe = await client.subscribeEntityEvents({\n * onError: (error) => console.error(\"subscribeEntityEvents error\", error),\n * })\n * unsubscribe() // unsubscribe from the events\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, queryOptions?: QueryOptions) => query(client, rawQuery, queryOptions),\n buildQuery: () => new QueryBuilder(client),\n select: (selection?: SelectArg) => new SelectQueryBuilder(client, selection),\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 [Braga JSON-RPC API](https://braga.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 parameters - Configuration object for the public client (chain, transport, etc.)\n * @returns A Arkiv Public Client. {@link PublicArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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\"\nimport { getLogger } from \"./logger\"\n\nconst logger = getLogger(\"utils:compression\")\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 ? await brotliModule.default : brotliModule) as BrotliWasmType\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 logger(\"Compressing data size %d\", 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 logger(\"Brotli compressed with zlib size %d\", 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 logger(\"Brotli compressed with wasm size %d\", 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 logger(\"Brotli decompressed with zlib size %d\", 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 { BLOCK_TIME } from \"../consts\"\nimport { InvalidAttributeError, InvalidExpirationError } from \"../errors\"\nimport type { Attribute } from \"../types\"\n\n/**\n * Expiration on Arkiv is measured in blocks (1 block =\n * 2 seconds), so the value must be a positive integer that is\n * a multiple of the block time.\n *\n * @param expiresIn - The expiration in seconds.\n * @throws {InvalidExpirationError} If the value is not a positive integer that\n * is a multiple of the block time.\n */\nexport function validateExpiresIn(expiresIn: number): void {\n if (!Number.isInteger(expiresIn) || expiresIn <= 0 || expiresIn % BLOCK_TIME !== 0) {\n throw new InvalidExpirationError(expiresIn)\n }\n}\n\n/**\n * Validates a single attribute. Arkiv supports string and number attribute\n * values, but numeric values must be integers.\n *\n * @param attribute - The attribute to validate.\n * @throws {InvalidAttributeError} If the attribute has a non-integer numeric\n * value.\n */\nexport function validateAttribute(attribute: Attribute): void {\n if (typeof attribute.value === \"number\" && !Number.isInteger(attribute.value)) {\n throw new InvalidAttributeError(attribute.key, attribute.value)\n }\n}\n","import { type Hex, hexToString, TransactionExecutionError, 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 { EntityMutationError } from \"../errors\"\nimport type { TxParams } from \"../types\"\nimport { compress } from \"./compression\"\nimport { getLogger } from \"./logger\"\nimport { validateAttribute, validateExpiresIn } from \"./validation\"\n\nconst logger = getLogger(\"utils:arkiv-transactions\")\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 [\n toHex(attribute.key),\n toHex(typeof attribute.value === \"number\" && attribute.value === 0 ? \"\" : attribute.value),\n ]\n }\n\n const payload = [\n //creates\n (creates ?? []).map((item) => {\n validateExpiresIn(item.expiresIn)\n item.attributes.forEach(validateAttribute)\n return [\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 }),\n //updates\n (updates ?? []).map((item) => {\n validateExpiresIn(item.expiresIn)\n item.attributes.forEach(validateAttribute)\n return [\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 }),\n //deletes\n (deletes ?? []).map((item) => item.entityKey),\n //extends\n (extensions ?? []).map((item) => {\n validateExpiresIn(item.expiresIn)\n return [item.entityKey, toHex(item.expiresIn / BLOCK_TIME)]\n }),\n //ownershipChanges TODO\n (ownershipChanges ?? []).map((item) => [item.entityKey, item.newOwner]),\n ]\n\n logger(\"txData to send as RLP %o length %d\", 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 logger(\"Sending transaction %o\", {\n account: client.account,\n chain: client.chain,\n to: ARKIV_ADDRESS,\n value: 0n,\n data,\n ...txParams,\n })\n\n try {\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 logger(\"Tx receipt %o\", receipt)\n if (receipt.status === \"reverted\") {\n try {\n const callResult = await walletClient.call({\n account: client.account,\n to: ARKIV_ADDRESS,\n value: 0n,\n data: toHex(compressed),\n ...txParams,\n })\n throw new EntityMutationError(\n `Transaction ${receipt.transactionHash} reverted. Please make sure the data for entities doesn't contain invalid characters or invalid data types.\n Reason: ${callResult.data ? hexToString(callResult.data) : \"No reason provided by backend.\"}`,\n )\n } catch (err) {\n const error = err as { cause?: { details?: string } }\n const reason = error.cause?.details ?? \"No reason provided by backend.\"\n logger(\n \"Error while calling to get more details about reverted transaction. Reason: %s\",\n reason,\n )\n throw new EntityMutationError(\n `Transaction ${receipt.transactionHash} reverted. Reason: ${reason}`,\n )\n }\n }\n\n return receipt\n } catch (error) {\n let message = \"Transaction failed\"\n if (error instanceof TransactionExecutionError) {\n message += `: ${error.details}`\n } else if (error instanceof EntityMutationError) {\n throw error\n }\n\n logger(\"%s Detailed error stack: %o\", message, error)\n throw new EntityMutationError(message)\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\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:change-ownership\")\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 logger(\"changeOwnership %o\", data)\n const txData = opsToTxData({ ownershipChanges: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from changeOwnership %o\", receipt)\n\n return {\n txHash: receipt.transactionHash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:create-entity\")\n\n/**\n * Parameters for the createEntity function.\n * - payload: The payload of the entity.\n * - attributes: The attributes of the entity. Attribute values may be strings\n * or numbers, but numeric values **must be integers**. To store a non-integer,\n * scale it to an integer (e.g. `1.5` -> `1500`) to preserve numeric ordering,\n * or pass it as a string (e.g. `\"1.5\"`). A non-integer numeric value throws an\n * {@link InvalidAttributeError}.\n * - contentType: The content type of the entity.\n * - expiresIn: How long until the entity expires, in seconds. Because Arkiv\n * measures expiration in blocks (1 block = 2 seconds), this **must be a\n * positive integer and a multiple of the block time (2 seconds)**\n * Invalid values throw an {@link InvalidExpirationError}.\n */\nexport type CreateEntityParameters = {\n payload: Uint8Array\n /** Entity attributes. Numeric values must be integers (scale non-integers, e.g. `1.5` -> `1500`, or use a string). Throws {@link InvalidAttributeError} otherwise. */\n attributes: Attribute[]\n contentType: MimeType | string\n /** Seconds until expiry. Must be a positive integer and a multiple of the 2s block time.\n * Throws {@link InvalidExpirationError} otherwise. */\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: Hash\n}\n\nexport async function createEntity(\n client: ArkivClient,\n data: CreateEntityParameters,\n txParams?: TxParams,\n): Promise<CreateEntityReturnType> {\n logger(\"createEntity %o\", data)\n const txData = opsToTxData({ creates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from createEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:delete-entity\")\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: Hash\n}\n\nexport async function deleteEntity(\n client: ArkivClient,\n data: DeleteEntityParameters,\n txParams?: TxParams,\n): Promise<DeleteEntityReturnType> {\n logger(\"deleteEntity %o\", data)\n const txData = opsToTxData({ deletes: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from deleteEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\n entityKey: data.entityKey,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:extend-entity\")\n\n/**\n * Parameters for the extendEntity function.\n * - entityKey: The key of the entity to extend.\n * - expiresIn: How long to extend the entity by, in seconds. Because Arkiv\n * measures expiration in blocks (1 block = 2 seconds), this **must be a\n * positive integer and a multiple of the block time (2 seconds)**.\n * Invalid values throw an {@link InvalidExpirationError}.\n */\nexport type ExtendEntityParameters = {\n entityKey: Hex\n /** Seconds to extend by. Must be a positive integer and a multiple of the 2s block time.\n * Throws {@link InvalidExpirationError} otherwise. */\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: Hash\n}\n\nexport async function extendEntity(\n client: ArkivClient,\n data: ExtendEntityParameters,\n txParams?: TxParams,\n): Promise<ExtendEntityReturnType> {\n logger(\"extendEntity %o\", data)\n const txData = opsToTxData({ extensions: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from extendEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\n entityKey: receipt.logs[0].topics[1] as Hex,\n }\n}\n","import type { Hash, Hex, TransactionReceipt } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\nimport type { ChangeOwnershipParameters } from \"./changeOwnership\"\n\nconst logger = getLogger(\"actions:wallet:mutate-entities\")\n\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 // logs go in the following order: creates, deleted, updates, extends, ownership changes\n for (let index = 0; index < receipt.logs.length; index++) {\n const log = receipt.logs[index]\n\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: Hash\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 logger(\"Receipt from mutateEntities %o\", receipt)\n\n const { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges } =\n parseReceipt(receipt, data)\n return {\n txHash: receipt.transactionHash as Hash,\n createdEntities,\n updatedEntities,\n deletedEntities,\n extendedEntities,\n ownershipChanges,\n }\n}\n","import type { Hash, Hex } from \"viem\"\nimport type { ArkivClient } from \"../../clients/baseClient\"\nimport type { Attribute, MimeType, TxParams } from \"../../types\"\nimport { opsToTxData, sendArkivTransaction } from \"../../utils/arkivTransactions\"\nimport { getLogger } from \"../../utils/logger\"\n\nconst logger = getLogger(\"actions:wallet:update-entity\")\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. Attribute values may be strings\n * or numbers, but numeric values **must be integers**. To store a non-integer,\n * scale it to an integer (e.g. `1.5` -> `1500`) to preserve numeric ordering,\n * or pass it as a string (e.g. `\"1.5\"`). A non-integer numeric value throws an\n * {@link InvalidAttributeError}.\n * - contentType: The content type of the entity.\n * - expiresIn: How long until the entity expires, in seconds. Because Arkiv\n * measures expiration in blocks (1 block = 2 seconds), this **must be a\n * positive integer and a multiple of the block time (2 seconds)**.\n * Invalid values throw an {@link InvalidExpirationError}.\n */\nexport type UpdateEntityParameters = {\n entityKey: Hex\n payload: Uint8Array\n /** Entity attributes. Numeric values must be integers (scale non-integers, e.g. `1.5` -> `1500`, or use a string). Throws {@link InvalidAttributeError} otherwise. */\n attributes: Attribute[]\n contentType: MimeType | string\n /** Seconds until expiry. Must be a positive integer and a multiple of the 2s block time.\n * Throws {@link InvalidExpirationError} otherwise. */\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: Hash\n}\n\nexport async function updateEntity(\n client: ArkivClient,\n data: UpdateEntityParameters,\n txParams?: TxParams,\n): Promise<UpdateEntityReturnType> {\n logger(\"updateEntity %o\", data)\n const txData = opsToTxData({ updates: [data] })\n const receipt = await sendArkivTransaction(client, txData, txParams)\n\n logger(\"Receipt from updateEntity %o\", receipt)\n\n return {\n txHash: receipt.transactionHash as Hash,\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 { 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\" | \"call\"> &\n Pick<\n WalletActions<chain, account>,\n | \"addChain\"\n | \"sendCalls\"\n | \"waitForCallsStatus\"\n | \"sendTransaction\"\n | \"sendRawTransaction\"\n | \"signMessage\"\n | \"signTransaction\"\n > & {\n /**\n * Creates a new entity.\n *\n * - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/createEntity\n * - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param data - The entity creation parameters\n * @param txParams - Optional transaction parameters\n * @returns The created entity with transaction hash\n *\n * @throws {InvalidExpirationError} If `expiresIn` is not a positive integer\n * that is a multiple of the block time (2 seconds).\n * @throws {InvalidAttributeError} If a numeric attribute value is not an\n * integer.\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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 data - The entity update parameters\n * @param txParams - Optional transaction parameters\n * @returns The updated entity with transaction hash\n *\n * @throws {InvalidExpirationError} If `expiresIn` is not a positive integer\n * that is a multiple of the block time (2 seconds).\n * @throws {InvalidAttributeError} If a numeric attribute value is not an\n * integer.\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 data - The entity deletion parameters\n * @param txParams - Optional transaction parameters\n * @returns The deleted entity with transaction hash\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 data - The entity update parameters\n * @param txParams - Optional transaction parameters\n * @returns The updated entity with transaction hash\n *\n * @throws {InvalidExpirationError} If `expiresIn` is not a positive integer\n * that is a multiple of the block time (2 seconds).\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 data - The ownership change parameters\n * @param txParams - Optional transaction parameters\n * @returns The entity with updated ownership and transaction hash\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: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)\n *\n * @param data - The mutation parameters (creates, updates, deletes, extensions)\n * @param txParams - Optional transaction parameters\n * @returns The mutation result with transaction hash\n *\n * @throws {InvalidExpirationError} If any create/update/extension `expiresIn`\n * is not a positive integer that is a multiple of the block time (2 seconds).\n * @throws {InvalidAttributeError} If a numeric attribute value is not an\n * integer.\n *\n * @example\n * import { createWalletClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createWalletClient({\n * chain: braga,\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 [Braga JSON-RPC API](https://braga.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 parameters - Configuration object for the wallet client (chain, transport, account, etc.)\n * @returns A Arkiv Wallet Client. {@link WalletArkivClient}\n *\n * @example\n * import { createPublicClient, http } from 'arkiv'\n * import { braga } from 'arkiv/chains'\n *\n * const client = createPublicClient({\n * chain: braga,\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","import type { Chain } from \"viem\"\nimport * as chains from \"../chains\"\n\n// Create a lookup map from all exported chains\nconst chainMap = new Map(Object.entries(chains).map(([key, value]) => [key.toLowerCase(), value]))\n\n/**\n * Get a chain from its name\n * @param name - The name of the chain, case insensitive\n * @returns The chain\n * @throws An error if the chain is not found\n */\nexport function chainFromName(name: string): Chain {\n const chain = chainMap.get(name.toLowerCase())\n if (!chain) {\n throw new Error(`Unknown chain: ${name}`)\n }\n return chain as Chain\n}\n"],"mappings":";;;;;;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B,MAAgC,aAC/C,eAAe,QAAQ,MAAM,SAAS;EACzC;;;;;;;;;;;;;;;;;;;;;;;;ACtOH,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;;;;;ACzD/B,MAAM,WAAW,IAAI,IAAI,OAAO,QAAQC,eAAO,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,IAAI,aAAa,EAAE,MAAM,CAAC,CAAC;;;;;;;AAQlG,SAAgB,cAAc,MAAqB;CACjD,MAAM,QAAQ,SAAS,IAAI,KAAK,aAAa,CAAC;AAC9C,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,kBAAkB,OAAO;AAE3C,QAAO"}
@@ -1,39 +1,17 @@
1
- const require_queryBuilder = require('../queryBuilder-CTPwve9u.cjs');
1
+ const require_queryBuilder = require('../queryBuilder-UW2MCaX4.cjs');
2
2
  require('../consts-AUoL-v42.cjs');
3
3
 
4
4
  //#region src/query/predicate.ts
5
- /**
6
- * Creates an OR predicate
7
- * @param predicates - The predicates to combine
8
- * @returns The OR predicate
9
- *
10
- * @example
11
- * const predicates = [eq("name", "John"), eq("age", 30)]
12
- * const result = or(predicates)
13
- * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
14
- *
15
- */
16
- function or(predicates) {
5
+ function or(...predicates) {
17
6
  return {
18
7
  type: "or",
19
- predicates
8
+ predicates: predicates.flat()
20
9
  };
21
10
  }
22
- /**
23
- * Creates an AND predicate
24
- * @param predicates - The predicates to combine
25
- * @returns The AND predicate
26
- *
27
- * @example
28
- * const predicates = [eq("name", "John"), eq("age", 30)]
29
- * const result = and(predicates)
30
- * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
31
- *
32
- */
33
- function and(predicates) {
11
+ function and(...predicates) {
34
12
  return {
35
13
  type: "and",
36
- predicates
14
+ predicates: predicates.flat()
37
15
  };
38
16
  }
39
17
  /**
@@ -1,3 +1,3 @@
1
- import "../entity-BSU5-vyY.cjs";
2
- import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-gj33r3rd.cjs";
1
+ import "../entity-B6g_EPm1.cjs";
2
+ import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-Ds9dwqb5.cjs";
3
3
  export { BaseQueryBuilder, EntitySelection, FullEntity, OrderByAttribute, Predicate, PredicateContainerType, PredicateType, ProjectedEntity, QueryBuilder, QueryResult, SelectArg, SelectQueryBuilder, SelectionFields, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or, selectionToIncludeData };
@@ -1,3 +1,3 @@
1
- import "../entity-CHiZ2Qu1.js";
2
- import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-CzqHiUAo.js";
1
+ import "../entity-qoLMAuuk.js";
2
+ import { C as neq, S as lte, T as or, _ as and, a as asc, b as gte, c as FullEntity, d as SelectionFields, f as selectionToIncludeData, g as PredicateType, h as PredicateContainerType, i as SelectQueryBuilder, l as ProjectedEntity, m as Predicate, n as OrderByAttribute, o as desc, p as QueryResult, r as QueryBuilder, s as EntitySelection, t as BaseQueryBuilder, u as SelectArg, v as eq, w as not, x as lt, y as gt } from "../index-DdspxNAA.js";
3
3
  export { BaseQueryBuilder, EntitySelection, FullEntity, OrderByAttribute, Predicate, PredicateContainerType, PredicateType, ProjectedEntity, QueryBuilder, QueryResult, SelectArg, SelectQueryBuilder, SelectionFields, and, asc, desc, eq, gt, gte, lt, lte, neq, not, or, selectionToIncludeData };
@@ -1,39 +1,17 @@
1
- import { a as desc, i as asc, n as QueryBuilder, o as selectionToIncludeData, r as SelectQueryBuilder, s as QueryResult, t as BaseQueryBuilder } from "../queryBuilder-D-ACo-g_.js";
1
+ import { a as desc, i as asc, n as QueryBuilder, o as selectionToIncludeData, r as SelectQueryBuilder, s as QueryResult, t as BaseQueryBuilder } from "../queryBuilder-D2uwP9jI.js";
2
2
  import "../consts-BV4PR-de.js";
3
3
 
4
4
  //#region src/query/predicate.ts
5
- /**
6
- * Creates an OR predicate
7
- * @param predicates - The predicates to combine
8
- * @returns The OR predicate
9
- *
10
- * @example
11
- * const predicates = [eq("name", "John"), eq("age", 30)]
12
- * const result = or(predicates)
13
- * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
14
- *
15
- */
16
- function or(predicates) {
5
+ function or(...predicates) {
17
6
  return {
18
7
  type: "or",
19
- predicates
8
+ predicates: predicates.flat()
20
9
  };
21
10
  }
22
- /**
23
- * Creates an AND predicate
24
- * @param predicates - The predicates to combine
25
- * @returns The AND predicate
26
- *
27
- * @example
28
- * const predicates = [eq("name", "John"), eq("age", 30)]
29
- * const result = and(predicates)
30
- * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
31
- *
32
- */
33
- function and(predicates) {
11
+ function and(...predicates) {
34
12
  return {
35
13
  type: "and",
36
- predicates
14
+ predicates: predicates.flat()
37
15
  };
38
16
  }
39
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/query/predicate.ts"],"sourcesContent":["export type PredicateType = \"eq\" | \"neq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"not\"\nexport type PredicateContainerType = \"or\" | \"and\"\n\nexport type Predicate =\n | {\n type: PredicateType\n key: string\n value: string | number\n }\n | {\n type: PredicateContainerType\n predicates: Predicate[]\n }\n\n/**\n * Creates an OR predicate\n * @param predicates - The predicates to combine\n * @returns The OR predicate\n *\n * @example\n * const predicates = [eq(\"name\", \"John\"), eq(\"age\", 30)]\n * const result = or(predicates)\n * // result = { type: \"or\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function or(predicates: Predicate[]): Predicate {\n return { type: \"or\", predicates }\n}\n\n/**\n * Creates an AND predicate\n * @param predicates - The predicates to combine\n * @returns The AND predicate\n *\n * @example\n * const predicates = [eq(\"name\", \"John\"), eq(\"age\", 30)]\n * const result = and(predicates)\n * // result = { type: \"and\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function and(predicates: Predicate[]): Predicate {\n return { type: \"and\", predicates }\n}\n\n/**\n * Creates an equality predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The equality predicate\n *\n * @example\n * const predicate = eq(\"name\", \"John\")\n * // result = { type: \"eq\", key: \"name\", value: \"John\" }\n */\nexport function eq(key: string, value: string | number): Predicate {\n return { type: \"eq\", key, value }\n}\n\n/**\n * Creates a not equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The not equal predicate\n *\n * @example\n * const predicate = neq(\"name\", \"John\")\n * // result = { type: \"neq\", key: \"name\", value: \"John\" }\n */\nexport function neq(key: string, value: string | number): Predicate {\n return { type: \"neq\", key, value }\n}\n\n/**\n * Creates a greater than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than predicate\n *\n * @example\n * const predicate = gt(\"name\", \"John\")\n * // result = { type: \"gt\", key: \"name\", value: \"John\" }\n */\nexport function gt(key: string, value: string | number): Predicate {\n return { type: \"gt\", key, value }\n}\n\n/**\n * Creates a greater than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than or equal predicate\n *\n * @example\n * const predicate = gte(\"name\", \"John\")\n * // result = { type: \"gte\", key: \"name\", value: \"John\" }\n */\nexport function gte(key: string, value: string | number): Predicate {\n return { type: \"gte\", key, value }\n}\n\n/**\n * Creates a less than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than predicate\n *\n * @example\n * const predicate = lt(\"name\", \"John\")\n * // result = { type: \"lt\", key: \"name\", value: \"John\" }\n */\nexport function lt(key: string, value: string | number): Predicate {\n return { type: \"lt\", key, value }\n}\n\n/**\n * Creates a less than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than or equal predicate\n *\n * @example\n * const predicate = lte(\"name\", \"John\")\n * // result = { type: \"lte\", key: \"name\", value: \"John\" }\n */\nexport function lte(key: string, value: string | number): Predicate {\n return { type: \"lte\", key, value }\n}\n\n/**\n * Creates a not predicate\n * @param key - The key to compare\n * @returns The not predicate\n *\n * @example\n * const predicate = not(\"name\")\n * // result = { type: \"not\", key: \"name\", value: \"\" }\n */\nexport function not(key: string): Predicate {\n return { type: \"not\", key, value: \"\" }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,GAAG,YAAoC;AACrD,QAAO;EAAE,MAAM;EAAM;EAAY;;;;;;;;;;;;;AAcnC,SAAgB,IAAI,YAAoC;AACtD,QAAO;EAAE,MAAM;EAAO;EAAY;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;AAYpC,SAAgB,IAAI,KAAwB;AAC1C,QAAO;EAAE,MAAM;EAAO;EAAK,OAAO;EAAI"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/query/predicate.ts"],"sourcesContent":["export type PredicateType = \"eq\" | \"neq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"not\"\nexport type PredicateContainerType = \"or\" | \"and\"\n\nexport type Predicate =\n | {\n type: PredicateType\n key: string\n value: string | number\n }\n | {\n type: PredicateContainerType\n predicates: Predicate[]\n }\n\n/**\n * Creates an OR predicate\n * @param predicates - The predicates to combine, either as a single array or as separate arguments\n * @returns The OR predicate\n *\n * @example\n * const result = or(eq(\"name\", \"John\"), eq(\"age\", 30))\n * // or equivalently: or([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * // result = { type: \"or\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function or(predicates: Predicate[]): Predicate\nexport function or(...predicates: Predicate[]): Predicate\nexport function or(...predicates: (Predicate | Predicate[])[]): Predicate {\n return { type: \"or\", predicates: predicates.flat() }\n}\n\n/**\n * Creates an AND predicate\n * @param predicates - The predicates to combine, either as a single array or as separate arguments\n * @returns The AND predicate\n *\n * @example\n * const result = and(eq(\"name\", \"John\"), eq(\"age\", 30))\n * // or equivalently: and([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * // result = { type: \"and\", predicates: [eq(\"name\", \"John\"), eq(\"age\", 30)] }\n *\n */\nexport function and(predicates: Predicate[]): Predicate\nexport function and(...predicates: Predicate[]): Predicate\nexport function and(...predicates: (Predicate | Predicate[])[]): Predicate {\n return { type: \"and\", predicates: predicates.flat() }\n}\n\n/**\n * Creates an equality predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The equality predicate\n *\n * @example\n * const predicate = eq(\"name\", \"John\")\n * // result = { type: \"eq\", key: \"name\", value: \"John\" }\n */\nexport function eq(key: string, value: string | number): Predicate {\n return { type: \"eq\", key, value }\n}\n\n/**\n * Creates a not equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The not equal predicate\n *\n * @example\n * const predicate = neq(\"name\", \"John\")\n * // result = { type: \"neq\", key: \"name\", value: \"John\" }\n */\nexport function neq(key: string, value: string | number): Predicate {\n return { type: \"neq\", key, value }\n}\n\n/**\n * Creates a greater than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than predicate\n *\n * @example\n * const predicate = gt(\"name\", \"John\")\n * // result = { type: \"gt\", key: \"name\", value: \"John\" }\n */\nexport function gt(key: string, value: string | number): Predicate {\n return { type: \"gt\", key, value }\n}\n\n/**\n * Creates a greater than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The greater than or equal predicate\n *\n * @example\n * const predicate = gte(\"name\", \"John\")\n * // result = { type: \"gte\", key: \"name\", value: \"John\" }\n */\nexport function gte(key: string, value: string | number): Predicate {\n return { type: \"gte\", key, value }\n}\n\n/**\n * Creates a less than predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than predicate\n *\n * @example\n * const predicate = lt(\"name\", \"John\")\n * // result = { type: \"lt\", key: \"name\", value: \"John\" }\n */\nexport function lt(key: string, value: string | number): Predicate {\n return { type: \"lt\", key, value }\n}\n\n/**\n * Creates a less than or equal predicate\n * @param key - The key to compare\n * @param value - The value to compare\n * @returns The less than or equal predicate\n *\n * @example\n * const predicate = lte(\"name\", \"John\")\n * // result = { type: \"lte\", key: \"name\", value: \"John\" }\n */\nexport function lte(key: string, value: string | number): Predicate {\n return { type: \"lte\", key, value }\n}\n\n/**\n * Creates a not predicate\n * @param key - The key to compare\n * @returns The not predicate\n *\n * @example\n * const predicate = not(\"name\")\n * // result = { type: \"not\", key: \"name\", value: \"\" }\n */\nexport function not(key: string): Predicate {\n return { type: \"not\", key, value: \"\" }\n}\n"],"mappings":";;;;AA2BA,SAAgB,GAAG,GAAG,YAAoD;AACxE,QAAO;EAAE,MAAM;EAAM,YAAY,WAAW,MAAM;EAAE;;AAgBtD,SAAgB,IAAI,GAAG,YAAoD;AACzE,QAAO;EAAE,MAAM;EAAO,YAAY,WAAW,MAAM;EAAE;;;;;;;;;;;;AAavD,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;;AAapC,SAAgB,GAAG,KAAa,OAAmC;AACjE,QAAO;EAAE,MAAM;EAAM;EAAK;EAAO;;;;;;;;;;;;AAanC,SAAgB,IAAI,KAAa,OAAmC;AAClE,QAAO;EAAE,MAAM;EAAO;EAAK;EAAO;;;;;;;;;;;AAYpC,SAAgB,IAAI,KAAwB;AAC1C,QAAO;EAAE,MAAM;EAAO;EAAK,OAAO;EAAI"}
@@ -400,6 +400,10 @@ function selectionToIncludeData(selection) {
400
400
  * @param attributeType - The type of the attribute to order by (string or number)
401
401
  * @returns Input for orderBy method
402
402
  *
403
+ * @deprecated Server-side ordering is not supported by the network, so `orderBy` (and this
404
+ * helper) have no effect on the returned order. Sort the fetched entities in JavaScript
405
+ * instead (e.g. `entities.sort(...)`). This function will be removed in a future release.
406
+ *
403
407
  * @example
404
408
  * const ascAttribute = asc("name", "string")
405
409
  */
@@ -416,6 +420,10 @@ function asc(attributeName, attributeType) {
416
420
  * @param attributeType - The type of the attribute to order by (string or number)
417
421
  * @returns Input for orderBy method
418
422
  *
423
+ * @deprecated Server-side ordering is not supported by the network, so `orderBy` (and this
424
+ * helper) have no effect on the returned order. Sort the fetched entities in JavaScript
425
+ * instead (e.g. `entities.sort(...)`). This function will be removed in a future release.
426
+ *
419
427
  * @example
420
428
  * const descAttribute = desc("name", "string")
421
429
  */
@@ -534,25 +542,8 @@ var BaseQueryBuilder = class {
534
542
  this._validAtBlock = validAtBlock;
535
543
  return this;
536
544
  }
537
- /**
538
- * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
539
- * Predicates can be nested using 'or' and 'and' predicates.
540
- * @param predicates - The predicates to set
541
- * @returns The query builder instance
542
- *
543
- * @example
544
- * const builder = client.select()
545
- * builder.where(eq("name", "John"))
546
- * builder.where([eq("name", "John"), eq("age", 30)])
547
- * builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
548
- * builder.where([eq("name", "John"), and([eq("age", 30), eq("age", 31)])])
549
- * builder.where([eq("name", "John"), or([eq("age", 30), and([eq("age", 31), eq("age", 32)])])])
550
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), eq("age", 32)])])])
551
- * builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])
552
- */
553
- where(predicates) {
554
- if (Array.isArray(predicates)) this._predicates.push(...predicates);
555
- else this._predicates.push(predicates);
545
+ where(...predicates) {
546
+ this._predicates.push(...predicates.flat());
556
547
  return this;
557
548
  }
558
549
  /**
@@ -710,4 +701,4 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
710
701
 
711
702
  //#endregion
712
703
  export { desc as a, entityFromRpcResult as c, InvalidExpirationError as d, NoCursorOrLimitError as f, getLogger as h, asc as i, EntityMutationError as l, NoMoreResultsError as m, QueryBuilder as n, selectionToIncludeData as o, NoEntityFoundError as p, SelectQueryBuilder as r, QueryResult as s, BaseQueryBuilder as t, InvalidAttributeError as u };
713
- //# sourceMappingURL=queryBuilder-D-ACo-g_.js.map
704
+ //# sourceMappingURL=queryBuilder-D2uwP9jI.js.map