@arkiv-network/sdk 0.7.0 → 0.8.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -16
- package/dist/attr/index.cjs +34 -0
- package/dist/attr/index.d.cts +2 -0
- package/dist/attr/index.d.ts +2 -0
- package/dist/attr/index.js +3 -0
- package/dist/attr-BDZ-APg5.js +809 -0
- package/dist/attr-BDZ-APg5.js.map +1 -0
- package/dist/attr-BvxHN99W.cjs +1029 -0
- package/dist/chains/index.cjs +2 -3
- package/dist/chains/index.d.cts +39 -77
- package/dist/chains/index.d.cts.map +1 -1
- package/dist/chains/index.d.ts +22 -60
- package/dist/chains/index.d.ts.map +1 -1
- package/dist/chains/index.js +2 -2
- package/dist/chains-BJrZs6sG.js +57 -0
- package/dist/chains-BJrZs6sG.js.map +1 -0
- package/dist/chains-BYRTTipa.cjs +73 -0
- package/dist/changeOwnership-B7bEgla4.d.cts +509 -0
- package/dist/changeOwnership-B7bEgla4.d.cts.map +1 -0
- package/dist/changeOwnership-DwgtdSFc.d.ts +509 -0
- package/dist/changeOwnership-DwgtdSFc.d.ts.map +1 -0
- package/dist/entity/index.cjs +19 -0
- package/dist/entity/index.d.cts +4 -0
- package/dist/entity/index.d.ts +4 -0
- package/dist/entity/index.js +6 -0
- package/dist/entity-B0t6sN7F.cjs +71 -0
- package/dist/entity-BIp_df9u.js +67 -0
- package/dist/entity-BIp_df9u.js.map +1 -0
- package/dist/entity-CFhbAv0R.js +70 -0
- package/dist/entity-CFhbAv0R.js.map +1 -0
- package/dist/entity-wfBnZd91.cjs +98 -0
- package/dist/errors-D-eJkGVc.cjs +56 -0
- package/dist/errors-DGB8AgT2.js +33 -0
- package/dist/errors-DGB8AgT2.js.map +1 -0
- package/dist/expiry-BUYIXTGb.cjs +135 -0
- package/dist/expiry-BxOlvVWC.d.ts +79 -0
- package/dist/expiry-BxOlvVWC.d.ts.map +1 -0
- package/dist/expiry-DGRzrSan.js +95 -0
- package/dist/expiry-DGRzrSan.js.map +1 -0
- package/dist/expiry-DRV29F1r.d.cts +79 -0
- package/dist/expiry-DRV29F1r.d.cts.map +1 -0
- package/dist/flags-0Vl5rrHq.d.cts +41 -0
- package/dist/flags-0Vl5rrHq.d.cts.map +1 -0
- package/dist/flags-Ct8k0gpB.cjs +43 -0
- package/dist/flags-ZtlvOIIk.js +33 -0
- package/dist/flags-ZtlvOIIk.js.map +1 -0
- package/dist/flags-wmcMoAnN.d.ts +41 -0
- package/dist/flags-wmcMoAnN.d.ts.map +1 -0
- package/dist/index-Cgw1u5aY.d.cts +278 -0
- package/dist/index-Cgw1u5aY.d.cts.map +1 -0
- package/dist/index-ClgIuxJ8.d.ts +159 -0
- package/dist/index-ClgIuxJ8.d.ts.map +1 -0
- package/dist/index-D0CmtiWT.d.cts +159 -0
- package/dist/index-D0CmtiWT.d.cts.map +1 -0
- package/dist/index-D8LZt-3J.d.cts +417 -0
- package/dist/index-D8LZt-3J.d.cts.map +1 -0
- package/dist/index-DVYFaXNV.d.ts +417 -0
- package/dist/index-DVYFaXNV.d.ts.map +1 -0
- package/dist/index-VCqgn29D.d.ts +278 -0
- package/dist/index-VCqgn29D.d.ts.map +1 -0
- package/dist/index.cjs +675 -357
- package/dist/index.d.cts +251 -203
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +251 -203
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +626 -355
- package/dist/index.js.map +1 -1
- package/dist/payload-Bnw1hrvb.cjs +83 -0
- package/dist/payload-CIxSn_DW.js +67 -0
- package/dist/payload-CIxSn_DW.js.map +1 -0
- package/dist/payload-Dgx3PQeK.d.ts +94 -0
- package/dist/payload-Dgx3PQeK.d.ts.map +1 -0
- package/dist/payload-P0nWyjLg.d.cts +94 -0
- package/dist/payload-P0nWyjLg.d.cts.map +1 -0
- package/dist/query/index.cjs +24 -149
- package/dist/query/index.d.cts +5 -3
- package/dist/query/index.d.ts +5 -3
- package/dist/query/index.js +6 -137
- package/dist/queryBuilder-BXDvX1K_.cjs +1123 -0
- package/dist/queryBuilder-CbLL4pG5.js +963 -0
- package/dist/queryBuilder-CbLL4pG5.js.map +1 -0
- package/dist/selection-BvK6yX0g.d.cts +433 -0
- package/dist/selection-BvK6yX0g.d.cts.map +1 -0
- package/dist/selection-fpmI3ADQ.d.ts +433 -0
- package/dist/selection-fpmI3ADQ.d.ts.map +1 -0
- package/dist/types/index.cjs +4 -1
- package/dist/types/index.d.cts +7 -2
- package/dist/types/index.d.ts +7 -2
- package/dist/types/index.js +4 -1
- package/dist/utils/index.cjs +4 -17
- package/dist/utils/index.d.cts +3 -17
- package/dist/utils/index.d.ts +3 -17
- package/dist/utils/index.js +4 -18
- package/package.json +26 -5
- package/src/actions/public/getEntity.ts +27 -43
- package/src/actions/public/getEntityNonce.ts +30 -0
- package/src/actions/public/predictEntityKeys.test.ts +143 -0
- package/src/actions/public/predictEntityKeys.ts +138 -0
- package/src/actions/public/query.ts +33 -69
- package/src/actions/public/watchEntityEvents.test.ts +414 -0
- package/src/actions/public/watchEntityEvents.ts +225 -0
- package/src/actions/wallet/changeOwnership.ts +8 -8
- package/src/actions/wallet/createEntity.ts +104 -26
- package/src/actions/wallet/deleteEntity.ts +2 -3
- package/src/actions/wallet/extendEntity.ts +39 -16
- package/src/actions/wallet/mutateEntities.test.ts +76 -0
- package/src/actions/wallet/mutateEntities.ts +29 -74
- package/src/actions/wallet/patchEntity.ts +90 -0
- package/src/attr/attributes.test.ts +120 -0
- package/src/attr/attributes.ts +190 -0
- package/src/attr/codec.test.ts +162 -0
- package/src/attr/codec.ts +220 -0
- package/src/attr/decimal.ts +86 -0
- package/src/attr/errors.ts +145 -0
- package/src/attr/index.ts +50 -0
- package/src/attr/names.ts +106 -0
- package/src/attr/types.ts +150 -0
- package/src/attr/values.test.ts +271 -0
- package/src/attr/values.ts +502 -0
- package/src/chains/cheesecake.ts +22 -0
- package/src/chains/index.ts +1 -2
- package/src/clients/createPublicClient.test.ts +3 -5
- package/src/clients/createPublicClient.ts +5 -4
- package/src/clients/createWalletClient.test.ts +2 -2
- package/src/clients/createWalletClient.ts +13 -7
- package/src/clients/decorators/arkivPublic.ts +160 -139
- package/src/clients/decorators/arkivWallet.ts +91 -95
- package/src/consts.ts +2 -1
- package/src/entity/create.test.ts +184 -0
- package/src/entity/errors.ts +38 -0
- package/src/entity/events.ts +16 -0
- package/src/entity/expiry.test.ts +195 -0
- package/src/entity/expiry.ts +181 -0
- package/src/entity/flags.ts +65 -0
- package/src/entity/index.ts +14 -0
- package/src/entity/key.ts +68 -0
- package/src/entity/operations.ts +134 -0
- package/src/entity/params.ts +15 -0
- package/src/errors.ts +33 -28
- package/src/index.ts +6 -0
- package/src/query/engine.ts +59 -134
- package/src/query/errors.ts +151 -0
- package/src/query/expression.test.ts +286 -0
- package/src/query/expression.ts +493 -0
- package/src/query/index.ts +40 -4
- package/src/query/injection.test.ts +151 -0
- package/src/query/queryBuilder.test.ts +322 -637
- package/src/query/queryBuilder.ts +126 -359
- package/src/query/queryResult.ts +54 -51
- package/src/query/selection.test.ts +48 -98
- package/src/query/selection.ts +77 -65
- package/src/types/entity.test.ts +44 -155
- package/src/types/entity.ts +62 -44
- package/src/types/events.ts +64 -23
- package/src/types/index.ts +20 -16
- package/src/types/rpcSchema.ts +70 -33
- package/src/utils/arkivTransactions.test.ts +681 -38
- package/src/utils/arkivTransactions.ts +249 -104
- package/src/utils/chains.test.ts +21 -24
- package/src/utils/compression.ts +1 -1
- package/src/utils/entities.test.ts +62 -0
- package/src/utils/entities.ts +111 -29
- package/src/utils/expirationTime.ts +114 -10
- package/src/utils/logger.ts +2 -2
- package/src/utils/payload.ts +4 -2
- package/src/utils/revert.test.ts +99 -0
- package/src/utils/revert.ts +145 -0
- package/dist/chains-BifaY04V.cjs +0 -108
- package/dist/chains-CrtkVbBh.js +0 -86
- package/dist/chains-CrtkVbBh.js.map +0 -1
- package/dist/consts-AUoL-v42.cjs +0 -18
- package/dist/consts-BV4PR-de.js +0 -7
- package/dist/consts-BV4PR-de.js.map +0 -1
- package/dist/entity-B6g_EPm1.d.cts +0 -382
- package/dist/entity-B6g_EPm1.d.cts.map +0 -1
- package/dist/entity-qoLMAuuk.d.ts +0 -382
- package/dist/entity-qoLMAuuk.d.ts.map +0 -1
- package/dist/index-DdspxNAA.d.ts +0 -481
- package/dist/index-DdspxNAA.d.ts.map +0 -1
- package/dist/index-Ds9dwqb5.d.cts +0 -481
- package/dist/index-Ds9dwqb5.d.cts.map +0 -1
- package/dist/payload-B2kFJyah.d.ts +0 -6
- package/dist/payload-B2kFJyah.d.ts.map +0 -1
- package/dist/payload-CJN8fTvX.d.cts +0 -6
- package/dist/payload-CJN8fTvX.d.cts.map +0 -1
- package/dist/payload-Claf2jUO.js +0 -13
- package/dist/payload-Claf2jUO.js.map +0 -1
- package/dist/payload-DpA5PA-w.cjs +0 -23
- package/dist/query/index.js.map +0 -1
- package/dist/queryBuilder-D2uwP9jI.js +0 -704
- package/dist/queryBuilder-D2uwP9jI.js.map +0 -1
- package/dist/queryBuilder-UW2MCaX4.cjs +0 -792
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/src/actions/public/buildQuery.ts +0 -10
- package/src/actions/public/subscribeEntityEvents.ts +0 -119
- package/src/actions/wallet/updateEntity.ts +0 -60
- package/src/chains/braga.ts +0 -26
- package/src/chains/kaolin.ts +0 -29
- package/src/query/engine.test.ts +0 -526
- package/src/query/predicate.test.ts +0 -461
- package/src/query/predicate.ts +0 -144
- package/src/query/queryResult.test.ts +0 -270
- package/src/query/selectQueryBuilder.test.ts +0 -210
- package/src/types/attributes.ts +0 -16
- package/src/utils/validation.test.ts +0 -60
- package/src/utils/validation.ts +0 -32
- /package/dist/{types-H-TSmRpm.js → types-Bx1EKe0v.js} +0 -0
- /package/dist/{types-o3zWarRp.cjs → types-CKPddlfS.cjs} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiry-DGRzrSan.js","names":[],"sources":["../src/consts.ts","../src/entity/params.ts","../src/entity/expiry.ts"],"sourcesContent":["//export const ARKIV_ADDRESS = \"0x00000000000000000000000000000061726b6976\" as `0x${string}`\nexport const ARKIV_ADDRESS = \"0x4400000000000000000000000000000000000044\" as `0x${string}`\nexport const BLOCK_TIME = 2 // 2 seconds\n","/**\n * Max uint64 value\n */\nexport const MAX_EXPIRES_AT = 2n ** 64n - 1n\n\n/** The operation tags of the `execute` ABI's tagged union. */\nexport const OperationType = {\n Create: 1,\n Patch: 2,\n ExtendExpiry: 3,\n TransferOwnership: 4,\n Delete: 5,\n} as const\n\nexport type OperationType = (typeof OperationType)[keyof typeof OperationType]\n","import { BLOCK_TIME } from \"../consts\"\nimport { InvalidExpiryError } from \"./errors\"\nimport { MAX_EXPIRES_AT } from \"./params\"\n\n/**\n * The brand. Module-private and never exported, so the only way to obtain an {@link Expiry} is to\n * build one with {@link ExpirationTime} — a hand-written `{ minLifetime, expiresAt }` literal will\n * not typecheck, and neither will a bare number of seconds.\n */\ndeclare const validated: unique symbol\n\n/**\n * How long an entity should live.\n *\n * This is the pair the ABI carries, and the engine resolves it as\n * `max(expiresAt, currentBlock + minLifetime)` — whichever is later. Build one with\n * {@link ExpirationTime}; there is no other way to make one.\n *\n * Which slot a value lands in also decides which rules govern it. `minLifetime` is a duration, so\n * it must come to a whole number of blocks. `expiresAt` is a block height, which is a whole number\n * by construction, so a wall-clock date rounds into it rather than being rejected.\n */\nexport type Expiry = {\n /** Lifetime floor in blocks, counted from the block the transaction lands in. `0n` if unset. */\n readonly minLifetime: bigint\n /**\n * Absolute deadline: a block height, or a `Date` still to be placed against the current block.\n * `0n` if unset.\n */\n readonly expiresAt: bigint | Date\n readonly [validated]: true\n}\n\n/**\n * An expiry that is nothing but a duration — what the `ExpirationTime.from*` helpers return.\n *\n * Distinguished from a full {@link Expiry} by its `expiresAt` being the literal `0n`, which is what\n * keeps `atBlock(x, { atLeast: atBlock(y) })` from compiling: a deadline is not a floor.\n */\nexport type Lifetime = Expiry & { readonly expiresAt: 0n }\n\n/**\n * Builds a branded {@link Expiry}.\n *\n * Internal seam for {@link ExpirationTime}, which is the only thing that should call it — it is not\n * part of the package's public surface.\n */\nexport function makeExpiry(minLifetime: bigint, expiresAt: bigint | Date): Expiry {\n return { minLifetime, expiresAt } as Expiry\n}\n\n/** The two `uint256` values the ABI carries, with every `Date` already placed. */\nexport type EncodedExpiry = {\n /** Absolute target block height, or `0n` for a purely relative lifetime. */\n expiresAt: bigint\n /** Relative floor in blocks, or `0n` for a purely absolute expiry. */\n minLifetime: bigint\n}\n\n/** What an expiry resolves to, given the chain's current block. */\nexport type ResolvedExpiry = EncodedExpiry & {\n /** The block the entity will expire at — `max(expiresAt, currentBlock + minLifetime)`. */\n target: bigint\n}\n\n/** What the SDK needs to know about the chain to resolve an expiry. */\nexport type ExpiryContext = {\n currentBlock: bigint\n}\n\n/**\n * Resolves an expiry into the wire pair and the block the entity will expire at.\n *\n * Durations are converted to blocks at the nominal `BLOCK_TIME` (2 seconds), which makes them\n * **approximate**: block production is not a clock, so a lifetime asked for in days drifts if the\n * chain runs fast or slow. The block it was converted to comes back as\n * {@link ResolvedExpiry.target}, so the approximation is always observable rather than assumed.\n *\n * @throws {InvalidExpiryError} If the expiry is malformed, does not fit the `uint64` the wire\n * carries, or would leave the entity dead on arrival.\n */\nexport function resolveExpiry(expiry: Expiry, context: ExpiryContext): ResolvedExpiry {\n const { currentBlock } = context\n\n if (typeof expiry?.minLifetime !== \"bigint\" || expiry.expiresAt === undefined) {\n throw new InvalidExpiryError(\n \"expires must be built with ExpirationTime, e.g. ExpirationTime.fromDays(30) or \" +\n \"ExpirationTime.atBlock(1_200_000n)\",\n )\n }\n\n const { minLifetime } = expiry\n const absolute =\n typeof expiry.expiresAt === \"bigint\"\n ? expiry.expiresAt\n : blockAtDate(expiry.expiresAt, currentBlock)\n\n if (minLifetime === 0n && absolute === 0n) {\n throw new InvalidExpiryError(\n \"no expiry given. Pass ExpirationTime.fromDays(30) for a lifetime, \" +\n \"ExpirationTime.atBlock(n) for an absolute deadline, or a deadline with \" +\n \"{ atLeast } to take whichever is later.\",\n )\n }\n\n if (absolute > MAX_EXPIRES_AT) {\n throw new InvalidExpiryError(\n `expiresAt resolves to block ${absolute}, which does not fit the uint64 the wire carries ` +\n `(max ${MAX_EXPIRES_AT}). Use ExpirationTime.permanent() for an entity that should not ` +\n \"expire.\",\n )\n }\n if (minLifetime > MAX_EXPIRES_AT) {\n throw new InvalidExpiryError(\n `the lifetime is ${minLifetime} blocks, which does not fit the uint64 the wire carries ` +\n `(max ${MAX_EXPIRES_AT})`,\n )\n }\n\n const relative = minLifetime === 0n ? 0n : currentBlock + minLifetime\n const target = absolute > relative ? absolute : relative\n\n if (target <= currentBlock) {\n throw new InvalidExpiryError(\n `the entity would expire at block ${target}, which is not after the current block ` +\n `${currentBlock}, so it would be dead on arrival`,\n )\n }\n if (target > MAX_EXPIRES_AT) {\n throw new InvalidExpiryError(\n `a lifetime of ${minLifetime} blocks from block ${currentBlock} lands at ${target}, past ` +\n `the largest expiry the wire carries (${MAX_EXPIRES_AT})`,\n )\n }\n\n return { expiresAt: absolute, minLifetime, target }\n}\n\n/**\n * A duration in seconds as a whole number of blocks.\n *\n * Arkiv counts lifetimes in blocks, so a duration that is not a whole number of them does not\n * describe anything the chain can store. Rather than silently round a caller's `3` up to two blocks\n * — four seconds, not what they asked for — this rejects it: a duration must be a positive multiple\n * of `BLOCK_TIME` (2 seconds). The {@link ExpirationTime} helpers all produce such multiples.\n *\n * @throws {InvalidExpiryError} If the duration is not a positive whole number of blocks' seconds.\n */\nexport function toBlocks(seconds: number): bigint {\n if (!Number.isInteger(seconds) || seconds <= 0) {\n throw new InvalidExpiryError(\n `a lifetime must be a positive whole number of seconds, got ${seconds}. Use the ` +\n \"ExpirationTime helpers, e.g. ExpirationTime.fromDays(30).\",\n )\n }\n if (seconds % BLOCK_TIME !== 0) {\n throw new InvalidExpiryError(\n `a lifetime must be a multiple of the ${BLOCK_TIME}s block time, got ${seconds}, which is ` +\n `${seconds / BLOCK_TIME} blocks. Try ${seconds - (seconds % BLOCK_TIME)} or ` +\n `${seconds + BLOCK_TIME - (seconds % BLOCK_TIME)}, or ExpirationTime.fromBlocks(n).`,\n )\n }\n return BigInt(seconds / BLOCK_TIME)\n}\n\n/**\n * The block a wall-clock instant lands on.\n *\n * Rounds **up**: a date almost never falls on a block boundary, and unlike a duration — which the\n * caller states and can state exactly — there is nothing here to reject, so the entity lives until\n * at least the instant asked for.\n */\nfunction blockAtDate(date: Date, currentBlock: bigint): bigint {\n const secondsAway = (date.getTime() - Date.now()) / 1000\n if (secondsAway <= 0) {\n throw new InvalidExpiryError(\n `the deadline ${date.toISOString()} is in the past, so the entity would be dead on arrival`,\n )\n }\n return currentBlock + BigInt(Math.ceil(secondsAway / BLOCK_TIME))\n}\n"],"mappings":";;;AACA,MAAa,gBAAgB;AAC7B,MAAa,aAAa;;;;;;;ACC1B,MAAa,iBAAiB,MAAM,MAAM;;AAG1C,MAAa,gBAAgB;CAC3B,QAAQ;CACR,OAAO;CACP,cAAc;CACd,mBAAmB;CACnB,QAAQ;CACT;;;;;;;;;;ACmCD,SAAgB,WAAW,aAAqB,WAAkC;AAChF,QAAO;EAAE;EAAa;EAAW;;;;;;;;;;;;;AAiCnC,SAAgB,cAAc,QAAgB,SAAwC;CACpF,MAAM,EAAE,iBAAiB;AAEzB,KAAI,OAAO,QAAQ,gBAAgB,YAAY,OAAO,cAAc,OAClE,OAAM,IAAI,mBACR,oHAED;CAGH,MAAM,EAAE,gBAAgB;CACxB,MAAM,WACJ,OAAO,OAAO,cAAc,WACxB,OAAO,YACP,YAAY,OAAO,WAAW,aAAa;AAEjD,KAAI,gBAAgB,MAAM,aAAa,GACrC,OAAM,IAAI,mBACR,mLAGD;AAGH,KAAI,WAAW,eACb,OAAM,IAAI,mBACR,+BAA+B,SAAS,wDAC9B,eAAe,yEAE1B;AAEH,KAAI,cAAc,eAChB,OAAM,IAAI,mBACR,mBAAmB,YAAY,+DACrB,eAAe,GAC1B;CAGH,MAAM,WAAW,gBAAgB,KAAK,KAAK,eAAe;CAC1D,MAAM,SAAS,WAAW,WAAW,WAAW;AAEhD,KAAI,UAAU,aACZ,OAAM,IAAI,mBACR,oCAAoC,OAAO,yCACtC,aAAa,kCACnB;AAEH,KAAI,SAAS,eACX,OAAM,IAAI,mBACR,iBAAiB,YAAY,qBAAqB,aAAa,YAAY,OAAO,8CACxC,eAAe,GAC1D;AAGH,QAAO;EAAE,WAAW;EAAU;EAAa;EAAQ;;;;;;;;;;;;AAarD,SAAgB,SAAS,SAAyB;AAChD,KAAI,CAAC,OAAO,UAAU,QAAQ,IAAI,WAAW,EAC3C,OAAM,IAAI,mBACR,8DAA8D,QAAQ,qEAEvE;AAEH,KAAI,UAAU,eAAe,EAC3B,OAAM,IAAI,mBACR,wCAAwC,WAAW,oBAAoB,QAAQ,aAC1E,UAAU,WAAW,eAAe,UAAW,UAAU,WAAY,MACrE,UAAU,aAAc,UAAU,WAAY,oCACpD;AAEH,QAAO,OAAO,UAAU,WAAW;;;;;;;;;AAUrC,SAAS,YAAY,MAAY,cAA8B;CAC7D,MAAM,eAAe,KAAK,SAAS,GAAG,KAAK,KAAK,IAAI;AACpD,KAAI,eAAe,EACjB,OAAM,IAAI,mBACR,gBAAgB,KAAK,aAAa,CAAC,yDACpC;AAEH,QAAO,eAAe,OAAO,KAAK,KAAK,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/entity/expiry.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The brand. Module-private and never exported, so the only way to obtain an {@link Expiry} is to
|
|
4
|
+
* build one with {@link ExpirationTime} — a hand-written `{ minLifetime, expiresAt }` literal will
|
|
5
|
+
* not typecheck, and neither will a bare number of seconds.
|
|
6
|
+
*/
|
|
7
|
+
declare const validated: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* How long an entity should live.
|
|
10
|
+
*
|
|
11
|
+
* This is the pair the ABI carries, and the engine resolves it as
|
|
12
|
+
* `max(expiresAt, currentBlock + minLifetime)` — whichever is later. Build one with
|
|
13
|
+
* {@link ExpirationTime}; there is no other way to make one.
|
|
14
|
+
*
|
|
15
|
+
* Which slot a value lands in also decides which rules govern it. `minLifetime` is a duration, so
|
|
16
|
+
* it must come to a whole number of blocks. `expiresAt` is a block height, which is a whole number
|
|
17
|
+
* by construction, so a wall-clock date rounds into it rather than being rejected.
|
|
18
|
+
*/
|
|
19
|
+
type Expiry = {
|
|
20
|
+
/** Lifetime floor in blocks, counted from the block the transaction lands in. `0n` if unset. */
|
|
21
|
+
readonly minLifetime: bigint;
|
|
22
|
+
/**
|
|
23
|
+
* Absolute deadline: a block height, or a `Date` still to be placed against the current block.
|
|
24
|
+
* `0n` if unset.
|
|
25
|
+
*/
|
|
26
|
+
readonly expiresAt: bigint | Date;
|
|
27
|
+
readonly [validated]: true;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* An expiry that is nothing but a duration — what the `ExpirationTime.from*` helpers return.
|
|
31
|
+
*
|
|
32
|
+
* Distinguished from a full {@link Expiry} by its `expiresAt` being the literal `0n`, which is what
|
|
33
|
+
* keeps `atBlock(x, { atLeast: atBlock(y) })` from compiling: a deadline is not a floor.
|
|
34
|
+
*/
|
|
35
|
+
type Lifetime = Expiry & {
|
|
36
|
+
readonly expiresAt: 0n;
|
|
37
|
+
};
|
|
38
|
+
/** The two `uint256` values the ABI carries, with every `Date` already placed. */
|
|
39
|
+
type EncodedExpiry = {
|
|
40
|
+
/** Absolute target block height, or `0n` for a purely relative lifetime. */
|
|
41
|
+
expiresAt: bigint;
|
|
42
|
+
/** Relative floor in blocks, or `0n` for a purely absolute expiry. */
|
|
43
|
+
minLifetime: bigint;
|
|
44
|
+
};
|
|
45
|
+
/** What an expiry resolves to, given the chain's current block. */
|
|
46
|
+
type ResolvedExpiry = EncodedExpiry & {
|
|
47
|
+
/** The block the entity will expire at — `max(expiresAt, currentBlock + minLifetime)`. */
|
|
48
|
+
target: bigint;
|
|
49
|
+
};
|
|
50
|
+
/** What the SDK needs to know about the chain to resolve an expiry. */
|
|
51
|
+
type ExpiryContext = {
|
|
52
|
+
currentBlock: bigint;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Resolves an expiry into the wire pair and the block the entity will expire at.
|
|
56
|
+
*
|
|
57
|
+
* Durations are converted to blocks at the nominal `BLOCK_TIME` (2 seconds), which makes them
|
|
58
|
+
* **approximate**: block production is not a clock, so a lifetime asked for in days drifts if the
|
|
59
|
+
* chain runs fast or slow. The block it was converted to comes back as
|
|
60
|
+
* {@link ResolvedExpiry.target}, so the approximation is always observable rather than assumed.
|
|
61
|
+
*
|
|
62
|
+
* @throws {InvalidExpiryError} If the expiry is malformed, does not fit the `uint64` the wire
|
|
63
|
+
* carries, or would leave the entity dead on arrival.
|
|
64
|
+
*/
|
|
65
|
+
declare function resolveExpiry(expiry: Expiry, context: ExpiryContext): ResolvedExpiry;
|
|
66
|
+
/**
|
|
67
|
+
* A duration in seconds as a whole number of blocks.
|
|
68
|
+
*
|
|
69
|
+
* Arkiv counts lifetimes in blocks, so a duration that is not a whole number of them does not
|
|
70
|
+
* describe anything the chain can store. Rather than silently round a caller's `3` up to two blocks
|
|
71
|
+
* — four seconds, not what they asked for — this rejects it: a duration must be a positive multiple
|
|
72
|
+
* of `BLOCK_TIME` (2 seconds). The {@link ExpirationTime} helpers all produce such multiples.
|
|
73
|
+
*
|
|
74
|
+
* @throws {InvalidExpiryError} If the duration is not a positive whole number of blocks' seconds.
|
|
75
|
+
*/
|
|
76
|
+
declare function toBlocks(seconds: number): bigint;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { ResolvedExpiry as a, Lifetime as i, Expiry as n, resolveExpiry as o, ExpiryContext as r, toBlocks as s, EncodedExpiry as t };
|
|
79
|
+
//# sourceMappingURL=expiry-DRV29F1r.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiry-DRV29F1r.d.cts","names":[],"sources":["../src/entity/expiry.ts"],"sourcesContent":[],"mappings":";;;AAsBA;AAiBA;AAaA;AAQA,cAnDc,SAmDY,EAAA,OAAA,MAAG;AAM7B;AAeA;;;;;AAmEA;;;;;KA9HY,MAAA;;;;;;;+BAOmB;YACnB,SAAA;;;;;;;;KASA,QAAA,GAAW;;;;KAaX,aAAA;;;;;;;KAQA,cAAA,GAAiB;;;;;KAMjB,aAAA;;;;;;;;;;;;;;iBAeI,aAAA,SAAsB,iBAAiB,gBAAgB;;;;;;;;;;;iBAmEvD,QAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/entity/flags.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The immutable properties an entity is created with. Both default to `false`.
|
|
4
|
+
*
|
|
5
|
+
* Creation flags are fixed at creation: there is no operation that changes them, so an entity is
|
|
6
|
+
* whatever it was created as for its whole life.
|
|
7
|
+
*/
|
|
8
|
+
type CreationFlags = {
|
|
9
|
+
/**
|
|
10
|
+
* The entity's attributes and payload can never be changed — only its expiry extended, its
|
|
11
|
+
* ownership transferred, and the entity deleted.
|
|
12
|
+
*/
|
|
13
|
+
readonly?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Anyone, not just the owner, may extend the entity's expiry. Lets a third party keep something
|
|
16
|
+
* alive without being able to change it.
|
|
17
|
+
*/
|
|
18
|
+
permissionlessExtension?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** {@link CreationFlags} as read back, with every flag resolved and the raw byte alongside. */
|
|
21
|
+
type ResolvedCreationFlags = {
|
|
22
|
+
readonly: boolean;
|
|
23
|
+
permissionlessExtension: boolean;
|
|
24
|
+
raw: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Packs creation flags into the `creationFlags` byte.
|
|
28
|
+
*
|
|
29
|
+
* @throws {InvalidCreationFlagsError} If a value is not a boolean.
|
|
30
|
+
*/
|
|
31
|
+
declare function encodeCreationFlags(flags?: CreationFlags): number;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the `creationFlags` byte back.
|
|
34
|
+
*
|
|
35
|
+
* @param raw - The `creationFlags` byte.
|
|
36
|
+
* @throws {InvalidCreationFlagsError} Malformed input
|
|
37
|
+
*/
|
|
38
|
+
declare function decodeCreationFlags(raw: number): ResolvedCreationFlags;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { encodeCreationFlags as i, ResolvedCreationFlags as n, decodeCreationFlags as r, CreationFlags as t };
|
|
41
|
+
//# sourceMappingURL=flags-0Vl5rrHq.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags-0Vl5rrHq.d.cts","names":[],"sources":["../src/entity/flags.ts"],"sourcesContent":[],"mappings":";;AAYA;AAcA;AAWA;AAkBA;;KA3CY,aAAA;;;;;;;;;;;;;KAcA,qBAAA;;;;;;;;;;iBAWI,mBAAA,SAA2B;;;;;;;iBAkB3B,mBAAA,eAAkC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_errors = require('./errors-D-eJkGVc.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/entity/flags.ts
|
|
4
|
+
/** Bit positions in the `creationFlags` byte. Bits 2-7 are reserved and must be zero. */
|
|
5
|
+
const READONLY_BIT = 1;
|
|
6
|
+
const PERMISSIONLESS_EXTENSION_BIT = 2;
|
|
7
|
+
/**
|
|
8
|
+
* Packs creation flags into the `creationFlags` byte.
|
|
9
|
+
*
|
|
10
|
+
* @throws {InvalidCreationFlagsError} If a value is not a boolean.
|
|
11
|
+
*/
|
|
12
|
+
function encodeCreationFlags(flags = {}) {
|
|
13
|
+
for (const [name, value] of Object.entries(flags)) if (value !== void 0 && typeof value !== "boolean") throw new require_errors.InvalidCreationFlagsError(`"${name}" must be a boolean, got ${typeof value}`);
|
|
14
|
+
return (flags.readonly ? READONLY_BIT : 0) | (flags.permissionlessExtension ? PERMISSIONLESS_EXTENSION_BIT : 0);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reads the `creationFlags` byte back.
|
|
18
|
+
*
|
|
19
|
+
* @param raw - The `creationFlags` byte.
|
|
20
|
+
* @throws {InvalidCreationFlagsError} Malformed input
|
|
21
|
+
*/
|
|
22
|
+
function decodeCreationFlags(raw) {
|
|
23
|
+
if (!Number.isInteger(raw) || raw < 0 || raw > 255) throw new require_errors.InvalidCreationFlagsError(`${raw} is not a byte`);
|
|
24
|
+
return {
|
|
25
|
+
readonly: (raw & READONLY_BIT) !== 0,
|
|
26
|
+
permissionlessExtension: (raw & PERMISSIONLESS_EXTENSION_BIT) !== 0,
|
|
27
|
+
raw
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
Object.defineProperty(exports, 'decodeCreationFlags', {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return decodeCreationFlags;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(exports, 'encodeCreationFlags', {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return encodeCreationFlags;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as InvalidCreationFlagsError } from "./errors-DGB8AgT2.js";
|
|
2
|
+
|
|
3
|
+
//#region src/entity/flags.ts
|
|
4
|
+
/** Bit positions in the `creationFlags` byte. Bits 2-7 are reserved and must be zero. */
|
|
5
|
+
const READONLY_BIT = 1;
|
|
6
|
+
const PERMISSIONLESS_EXTENSION_BIT = 2;
|
|
7
|
+
/**
|
|
8
|
+
* Packs creation flags into the `creationFlags` byte.
|
|
9
|
+
*
|
|
10
|
+
* @throws {InvalidCreationFlagsError} If a value is not a boolean.
|
|
11
|
+
*/
|
|
12
|
+
function encodeCreationFlags(flags = {}) {
|
|
13
|
+
for (const [name, value] of Object.entries(flags)) if (value !== void 0 && typeof value !== "boolean") throw new InvalidCreationFlagsError(`"${name}" must be a boolean, got ${typeof value}`);
|
|
14
|
+
return (flags.readonly ? READONLY_BIT : 0) | (flags.permissionlessExtension ? PERMISSIONLESS_EXTENSION_BIT : 0);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reads the `creationFlags` byte back.
|
|
18
|
+
*
|
|
19
|
+
* @param raw - The `creationFlags` byte.
|
|
20
|
+
* @throws {InvalidCreationFlagsError} Malformed input
|
|
21
|
+
*/
|
|
22
|
+
function decodeCreationFlags(raw) {
|
|
23
|
+
if (!Number.isInteger(raw) || raw < 0 || raw > 255) throw new InvalidCreationFlagsError(`${raw} is not a byte`);
|
|
24
|
+
return {
|
|
25
|
+
readonly: (raw & READONLY_BIT) !== 0,
|
|
26
|
+
permissionlessExtension: (raw & PERMISSIONLESS_EXTENSION_BIT) !== 0,
|
|
27
|
+
raw
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { encodeCreationFlags as n, decodeCreationFlags as t };
|
|
33
|
+
//# sourceMappingURL=flags-ZtlvOIIk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags-ZtlvOIIk.js","names":[],"sources":["../src/entity/flags.ts"],"sourcesContent":["import { InvalidCreationFlagsError } from \"./errors\"\n\n/** Bit positions in the `creationFlags` byte. Bits 2-7 are reserved and must be zero. */\nconst READONLY_BIT = 0b0000_0001\nconst PERMISSIONLESS_EXTENSION_BIT = 0b0000_0010\n\n/**\n * The immutable properties an entity is created with. Both default to `false`.\n *\n * Creation flags are fixed at creation: there is no operation that changes them, so an entity is\n * whatever it was created as for its whole life.\n */\nexport type CreationFlags = {\n /**\n * The entity's attributes and payload can never be changed — only its expiry extended, its\n * ownership transferred, and the entity deleted.\n */\n readonly?: boolean\n /**\n * Anyone, not just the owner, may extend the entity's expiry. Lets a third party keep something\n * alive without being able to change it.\n */\n permissionlessExtension?: boolean\n}\n\n/** {@link CreationFlags} as read back, with every flag resolved and the raw byte alongside. */\nexport type ResolvedCreationFlags = {\n readonly: boolean\n permissionlessExtension: boolean\n raw: number\n}\n\n/**\n * Packs creation flags into the `creationFlags` byte.\n *\n * @throws {InvalidCreationFlagsError} If a value is not a boolean.\n */\nexport function encodeCreationFlags(flags: CreationFlags = {}): number {\n for (const [name, value] of Object.entries(flags)) {\n if (value !== undefined && typeof value !== \"boolean\") {\n throw new InvalidCreationFlagsError(`\"${name}\" must be a boolean, got ${typeof value}`)\n }\n }\n return (\n (flags.readonly ? READONLY_BIT : 0) |\n (flags.permissionlessExtension ? PERMISSIONLESS_EXTENSION_BIT : 0)\n )\n}\n\n/**\n * Reads the `creationFlags` byte back.\n *\n * @param raw - The `creationFlags` byte.\n * @throws {InvalidCreationFlagsError} Malformed input\n */\nexport function decodeCreationFlags(raw: number): ResolvedCreationFlags {\n if (!Number.isInteger(raw) || raw < 0 || raw > 0xff) {\n throw new InvalidCreationFlagsError(`${raw} is not a byte`)\n }\n return {\n readonly: (raw & READONLY_BIT) !== 0,\n permissionlessExtension: (raw & PERMISSIONLESS_EXTENSION_BIT) !== 0,\n raw,\n }\n}\n"],"mappings":";;;;AAGA,MAAM,eAAe;AACrB,MAAM,+BAA+B;;;;;;AAiCrC,SAAgB,oBAAoB,QAAuB,EAAE,EAAU;AACrE,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,MAAM,CAC/C,KAAI,UAAU,UAAa,OAAO,UAAU,UAC1C,OAAM,IAAI,0BAA0B,IAAI,KAAK,2BAA2B,OAAO,QAAQ;AAG3F,SACG,MAAM,WAAW,eAAe,MAChC,MAAM,0BAA0B,+BAA+B;;;;;;;;AAUpE,SAAgB,oBAAoB,KAAoC;AACtE,KAAI,CAAC,OAAO,UAAU,IAAI,IAAI,MAAM,KAAK,MAAM,IAC7C,OAAM,IAAI,0BAA0B,GAAG,IAAI,gBAAgB;AAE7D,QAAO;EACL,WAAW,MAAM,kBAAkB;EACnC,0BAA0B,MAAM,kCAAkC;EAClE;EACD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/entity/flags.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The immutable properties an entity is created with. Both default to `false`.
|
|
4
|
+
*
|
|
5
|
+
* Creation flags are fixed at creation: there is no operation that changes them, so an entity is
|
|
6
|
+
* whatever it was created as for its whole life.
|
|
7
|
+
*/
|
|
8
|
+
type CreationFlags = {
|
|
9
|
+
/**
|
|
10
|
+
* The entity's attributes and payload can never be changed — only its expiry extended, its
|
|
11
|
+
* ownership transferred, and the entity deleted.
|
|
12
|
+
*/
|
|
13
|
+
readonly?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Anyone, not just the owner, may extend the entity's expiry. Lets a third party keep something
|
|
16
|
+
* alive without being able to change it.
|
|
17
|
+
*/
|
|
18
|
+
permissionlessExtension?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** {@link CreationFlags} as read back, with every flag resolved and the raw byte alongside. */
|
|
21
|
+
type ResolvedCreationFlags = {
|
|
22
|
+
readonly: boolean;
|
|
23
|
+
permissionlessExtension: boolean;
|
|
24
|
+
raw: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Packs creation flags into the `creationFlags` byte.
|
|
28
|
+
*
|
|
29
|
+
* @throws {InvalidCreationFlagsError} If a value is not a boolean.
|
|
30
|
+
*/
|
|
31
|
+
declare function encodeCreationFlags(flags?: CreationFlags): number;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the `creationFlags` byte back.
|
|
34
|
+
*
|
|
35
|
+
* @param raw - The `creationFlags` byte.
|
|
36
|
+
* @throws {InvalidCreationFlagsError} Malformed input
|
|
37
|
+
*/
|
|
38
|
+
declare function decodeCreationFlags(raw: number): ResolvedCreationFlags;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { encodeCreationFlags as i, ResolvedCreationFlags as n, decodeCreationFlags as r, CreationFlags as t };
|
|
41
|
+
//# sourceMappingURL=flags-wmcMoAnN.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags-wmcMoAnN.d.ts","names":[],"sources":["../src/entity/flags.ts"],"sourcesContent":[],"mappings":";;AAYA;AAcA;AAWA;AAkBA;;KA3CY,aAAA;;;;;;;;;;;;;KAcA,qBAAA;;;;;;;;;;iBAWI,mBAAA,SAA2B;;;;;;;iBAkB3B,mBAAA,eAAkC"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { K as TypeTag } from "./index-D8LZt-3J.cjs";
|
|
2
|
+
import { R as RpcSelect, d as Expression, i as SelectArg, j as ArkivClient, k as Entity } from "./selection-BvK6yX0g.cjs";
|
|
3
|
+
import { Hex } from "viem";
|
|
4
|
+
|
|
5
|
+
//#region src/query/engine.d.ts
|
|
6
|
+
declare const MAX_LIMIT = 200;
|
|
7
|
+
/** One `arkiv_query` call. */
|
|
8
|
+
type QueryRequest = {
|
|
9
|
+
/** The query expression, already rendered. */
|
|
10
|
+
query: string;
|
|
11
|
+
/** What to return. */
|
|
12
|
+
select: RpcSelect;
|
|
13
|
+
/** Page size, up to {@link MAX_LIMIT}. Defaults to the node's own page size. */
|
|
14
|
+
limit?: number | undefined;
|
|
15
|
+
/** Cursor from a previous page. */
|
|
16
|
+
cursor?: string | undefined;
|
|
17
|
+
/** Block height to read at. Defaults to the head. */
|
|
18
|
+
atBlock?: bigint | undefined;
|
|
19
|
+
};
|
|
20
|
+
/** One page of results. */
|
|
21
|
+
type QueryResponse = {
|
|
22
|
+
entities: Entity[];
|
|
23
|
+
/** The block the page was read at — the same for every page of a paginated query. */
|
|
24
|
+
blockNumber: bigint;
|
|
25
|
+
/** The cursor for the next page, or `undefined` when this was the last one. */
|
|
26
|
+
cursor: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Runs one query and decodes the page it returns.
|
|
30
|
+
*
|
|
31
|
+
* @throws {QueryError} If the node rejects the query.
|
|
32
|
+
*/
|
|
33
|
+
declare function runQuery(client: ArkivClient, request: QueryRequest): Promise<QueryResponse>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/query/errors.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* A predicate asked for an operator the query language does not define for that type.
|
|
38
|
+
*
|
|
39
|
+
* The operator × type matrix is part of the language, not a policy: a range comparison on an
|
|
40
|
+
* equality-only type is a **parse error** at the node, not an empty result. Catching it here turns
|
|
41
|
+
* a round trip and an RPC error code into a stack trace pointing at the call site.
|
|
42
|
+
*
|
|
43
|
+
* | | `=` `!=` | `<` `<=` `>` `>=` | `STARTSWITH` |
|
|
44
|
+
* | --- | --- | --- | --- |
|
|
45
|
+
* | `bool` | yes | no | no |
|
|
46
|
+
* | `i32` `u256` `dec` | yes | yes | no |
|
|
47
|
+
* | `str` | yes | no | yes |
|
|
48
|
+
* | `addr` `key` `bytes32` | yes | no | no |
|
|
49
|
+
*/
|
|
50
|
+
declare class UnsupportedOperatorError extends Error {
|
|
51
|
+
/** The attribute the predicate names. */
|
|
52
|
+
readonly attributeName: string;
|
|
53
|
+
/** The operator, as it would have been written in the query. */
|
|
54
|
+
readonly operator: string;
|
|
55
|
+
/** The type of the value it was applied to. */
|
|
56
|
+
readonly tag: TypeTag;
|
|
57
|
+
constructor(attributeName: string, operator: string, tag: TypeTag, hint?: string);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A predicate could not be expressed in the query language for a reason other than its operator —
|
|
61
|
+
* a system attribute that is returned in results but cannot be filtered on, a system attribute
|
|
62
|
+
* compared against the wrong type, or a combinator with nothing to combine.
|
|
63
|
+
*/
|
|
64
|
+
declare class InvalidPredicateError extends Error {
|
|
65
|
+
/** The attribute the predicate names, where there is one. */
|
|
66
|
+
readonly attributeName: string | undefined;
|
|
67
|
+
constructor(message: string, attributeName?: string);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What a node rejected a query for. Part of the frozen RPC surface, so it is safe to branch on —
|
|
71
|
+
* a `"cursor"` failure means start the query again, a `"block"` failure means the node no longer
|
|
72
|
+
* retains that height, and the rest mean the query itself needs fixing.
|
|
73
|
+
*/
|
|
74
|
+
type QueryErrorKind = /** The query string does not parse. `data` locates it: `{ position, expected, got }`. */
|
|
75
|
+
"parse"
|
|
76
|
+
/** A predicate is well-formed but ill-typed — a range operator on an equality-only type, an unknown tag. */ | "type"
|
|
77
|
+
/** A literal failed validation — an `i32` out of range, a bad EIP-55 checksum, more than 18 decimal places. */ | "literal"
|
|
78
|
+
/** A node budget was exceeded — query length, predicate count, nesting depth, bitmap operations. */ | "limits"
|
|
79
|
+
/** The cursor expired, is malformed, or belongs to a different query, block or selection. */ | "cursor"
|
|
80
|
+
/** `atBlock` is outside the range the node retains. */ | "block";
|
|
81
|
+
/**
|
|
82
|
+
* The node rejected a query.
|
|
83
|
+
*
|
|
84
|
+
* These codes are part of the frozen `arkiv_query` surface, so {@link kind} and {@link data} are
|
|
85
|
+
* stable enough to branch on — which the underlying JSON-RPC error is not, because the codes
|
|
86
|
+
* overlap Ethereum's own EIP-1474 numbering and get wrapped accordingly on the way up.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* try {
|
|
90
|
+
* await result.next()
|
|
91
|
+
* } catch (error) {
|
|
92
|
+
* if (error instanceof QueryError && error.kind === "cursor") {
|
|
93
|
+
* // The page is gone — start the query over.
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
*/
|
|
97
|
+
declare class QueryError extends Error {
|
|
98
|
+
/** Which failure this is. */
|
|
99
|
+
readonly kind: QueryErrorKind;
|
|
100
|
+
/** The JSON-RPC error code. */
|
|
101
|
+
readonly code: number;
|
|
102
|
+
/** The machine-readable detail the node sent, if any — e.g. `{ position, expected, got }`. */
|
|
103
|
+
readonly data: unknown;
|
|
104
|
+
/** The query string that was rejected. */
|
|
105
|
+
readonly query: string;
|
|
106
|
+
constructor(kind: QueryErrorKind, code: number, query: string, data: unknown, detail?: string);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/query/queryResult.d.ts
|
|
110
|
+
/** Fetches the page a cursor points at. */
|
|
111
|
+
type FetchPage<TEntity> = (cursor: string) => Promise<QueryResult<TEntity>>;
|
|
112
|
+
/**
|
|
113
|
+
* One page of query results.
|
|
114
|
+
*
|
|
115
|
+
* A page is immutable: {@link next} returns the following page rather than mutating this one, so a
|
|
116
|
+
* page that has been read stays readable.
|
|
117
|
+
*
|
|
118
|
+
* @typeParam TEntity - The shape of each entity, inferred from the selection by `client.select()`.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* let page = await client.select({ key: true }).where(eq("category", "docs")).limit(100).fetch()
|
|
122
|
+
* while (page.hasNextPage()) {
|
|
123
|
+
* page = await page.next()
|
|
124
|
+
* }
|
|
125
|
+
*/
|
|
126
|
+
declare class QueryResult<TEntity = Entity> {
|
|
127
|
+
/** The entities on this page. */
|
|
128
|
+
readonly entities: readonly TEntity[];
|
|
129
|
+
/**
|
|
130
|
+
* The block this page was read at.
|
|
131
|
+
*
|
|
132
|
+
* Every page of one walk reads the same block — the cursor is bound to it — so results cannot
|
|
133
|
+
* shift under a paginating reader.
|
|
134
|
+
*/
|
|
135
|
+
readonly blockNumber: bigint;
|
|
136
|
+
/** The cursor for the next page, or `undefined` when this was the last one. */
|
|
137
|
+
readonly cursor: string | undefined;
|
|
138
|
+
private readonly fetchPage;
|
|
139
|
+
constructor(entities: readonly TEntity[], blockNumber: bigint, cursor: string | undefined, fetchPage: FetchPage<TEntity>);
|
|
140
|
+
/**
|
|
141
|
+
* Whether another page follows.
|
|
142
|
+
*
|
|
143
|
+
* The node omits the cursor once nothing remains, so this is an answer rather than the guess a
|
|
144
|
+
* short final page would be — a full last page is reported correctly.
|
|
145
|
+
*/
|
|
146
|
+
hasNextPage(): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Fetches the next page.
|
|
149
|
+
*
|
|
150
|
+
* @throws {NoMoreResultsError} If this was the last page — check {@link hasNextPage} first.
|
|
151
|
+
* @throws {QueryError} If the node rejects the request; `kind === "cursor"` means the cursor
|
|
152
|
+
* expired and the walk has to start again.
|
|
153
|
+
*/
|
|
154
|
+
next(): Promise<QueryResult<TEntity>>;
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/query/queryBuilder.d.ts
|
|
158
|
+
/**
|
|
159
|
+
* Builds and runs a query.
|
|
160
|
+
*
|
|
161
|
+
* The selection is fixed when the builder is created and the filter is added by chaining, so the
|
|
162
|
+
* result type is known before a single predicate is written. Create one with `client.select(...)`
|
|
163
|
+
* rather than constructing it directly — that is what infers the entity shape from the selection.
|
|
164
|
+
*
|
|
165
|
+
* Every filter added with {@link where}, {@link ownedBy} and {@link createdBy} must hold; use
|
|
166
|
+
* {@link or} for alternatives inside one call.
|
|
167
|
+
*
|
|
168
|
+
* @typeParam TEntity - The projected entity shape, inferred from the selection by `client.select()`.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
172
|
+
* import { i32 } from "@arkiv-network/sdk/attr"
|
|
173
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
174
|
+
* import { eq, gte, or } from "@arkiv-network/sdk/query"
|
|
175
|
+
* import { http } from "viem"
|
|
176
|
+
*
|
|
177
|
+
* const client = createPublicClient({ chain: cheesecake, transport: http() })
|
|
178
|
+
*
|
|
179
|
+
* const page = await client
|
|
180
|
+
* .select({ key: true, attributes: true })
|
|
181
|
+
* .where(gte("level", i32(10)), or(eq("status", "open"), eq("status", "review")))
|
|
182
|
+
* .ownedBy(owner)
|
|
183
|
+
* .limit(100)
|
|
184
|
+
* .fetch()
|
|
185
|
+
*
|
|
186
|
+
* for (const entity of page.entities) console.log(entity.key, entity.attributes)
|
|
187
|
+
*/
|
|
188
|
+
declare class SelectQueryBuilder<TEntity = Entity> {
|
|
189
|
+
private readonly _client;
|
|
190
|
+
private readonly _select;
|
|
191
|
+
private readonly _filters;
|
|
192
|
+
private _ownedBy;
|
|
193
|
+
private _createdBy;
|
|
194
|
+
private _limit;
|
|
195
|
+
private _cursor;
|
|
196
|
+
private _atBlock;
|
|
197
|
+
constructor(client: ArkivClient, selection?: SelectArg);
|
|
198
|
+
/**
|
|
199
|
+
* Adds filters. Everything passed here, and across repeated calls, must hold.
|
|
200
|
+
*
|
|
201
|
+
* @param expressions - The expressions, as separate arguments or one array.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* builder.where(eq("category", "docs"))
|
|
205
|
+
* builder.where(gte("level", i32(10)), lt("level", i32(20)))
|
|
206
|
+
* builder.where(or(eq("status", "open"), not(exists("closedAt"))))
|
|
207
|
+
*/
|
|
208
|
+
where(expressions: readonly Expression[]): this;
|
|
209
|
+
where(...expressions: Expression[]): this;
|
|
210
|
+
/**
|
|
211
|
+
* Restricts the results to entities this account owns — shorthand for
|
|
212
|
+
* `where(eq("$owner", addr(owner)))`. Calling it again replaces the filter.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* builder.ownedBy("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
|
|
216
|
+
*/
|
|
217
|
+
ownedBy(owner: Hex): this;
|
|
218
|
+
/**
|
|
219
|
+
* Restricts the results to entities this account created — shorthand for
|
|
220
|
+
* `where(eq("$creator", addr(creator)))`. Calling it again replaces the filter.
|
|
221
|
+
*
|
|
222
|
+
* The creator never changes; the owner does, so these differ after a transfer.
|
|
223
|
+
*/
|
|
224
|
+
createdBy(creator: Hex): this;
|
|
225
|
+
/**
|
|
226
|
+
* Sets the page size, up to the node maximum of 200. Without it the node picks the page size.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* builder.limit(100)
|
|
230
|
+
*/
|
|
231
|
+
limit(limit: number): this;
|
|
232
|
+
/**
|
|
233
|
+
* Starts from a cursor returned by an earlier page.
|
|
234
|
+
*
|
|
235
|
+
* Pagination normally goes through {@link QueryResult.next}, which carries the cursor for you;
|
|
236
|
+
* this is for resuming a walk in a later process. A cursor is bound to the query, block and
|
|
237
|
+
* selection it came from, so it must be used with an identically-built query.
|
|
238
|
+
*/
|
|
239
|
+
cursor(cursor: string): this;
|
|
240
|
+
/**
|
|
241
|
+
* Reads the state as of a given block rather than the head. The block must be within the range
|
|
242
|
+
* the node retains.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* builder.atBlock(1_297_000n)
|
|
246
|
+
*/
|
|
247
|
+
atBlock(block: bigint): this;
|
|
248
|
+
/**
|
|
249
|
+
* The query string this builder will send — the same text the node parses.
|
|
250
|
+
*
|
|
251
|
+
* @throws {InvalidPredicateError} If no filter has been added.
|
|
252
|
+
*/
|
|
253
|
+
toString(): string;
|
|
254
|
+
/**
|
|
255
|
+
* Runs the query and returns the first page.
|
|
256
|
+
*
|
|
257
|
+
* @throws {InvalidPredicateError} If no filter has been added.
|
|
258
|
+
* @throws {QueryError} If the node rejects the query.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* const page = await client.select({ key: true }).where(eq("category", "docs")).fetch()
|
|
262
|
+
* page.entities // this page
|
|
263
|
+
* await page.next() // the next one
|
|
264
|
+
*/
|
|
265
|
+
fetch(): Promise<QueryResult<TEntity>>;
|
|
266
|
+
/**
|
|
267
|
+
* Walks every page, yielding one entity at a time.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* for await (const entity of client.select({ key: true }).where(eq("category", "docs"))) {
|
|
271
|
+
* console.log(entity.key)
|
|
272
|
+
* }
|
|
273
|
+
*/
|
|
274
|
+
[Symbol.asyncIterator](): AsyncGenerator<TEntity>;
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
export { QueryErrorKind as a, QueryRequest as c, QueryError as i, QueryResponse as l, QueryResult as n, UnsupportedOperatorError as o, InvalidPredicateError as r, MAX_LIMIT as s, SelectQueryBuilder as t, runQuery as u };
|
|
278
|
+
//# sourceMappingURL=index-Cgw1u5aY.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Cgw1u5aY.d.cts","names":[],"sources":["../src/query/engine.ts","../src/query/errors.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":[],"mappings":";;;;;cAUa,SAAA;;AAAA,KAGD,YAAA,GAHU;EAGV;EAcA,KAAA,EAAA,MAAA;EAaU;EAAiB,MAAA,EAvB7B,SAuB6B;EAAsB;EAAuB,KAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAR;EAAO,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;ACxBnF;AAMgB,KDKJ,aAAA,GCLI;EAE4C,QAAA,EDIhD,MCJgD,EAAA;EARd;EAAK,WAAA,EAAA,MAAA;EAyBtC;EAgBD,MAAA,EAAA,MAAA,GAAc,SAAA;AAwC1B,CAAA;;;;;;iBDzDsB,QAAA,SAAiB,sBAAsB,eAAe,QAAQ;;;;;;;AA9BpF;AAGA;AAcA;AAaA;;;;;;;cCxBa,wBAAA,SAAiC,KAAA;;EAAjC,SAAA,aAAA,EAAA,MAAyB;EAMtB;EAE4C,SAAA,QAAA,EAAA,MAAA;EARd;EAAK,SAAA,GAAA,EAMnC,OANmC;EAyBtC,WAAA,CAAA,aAAsB,EAAA,MAAA,EAAA,QAAa,EAAA,MAAA,EAAA,GAAA,EAjBY,OAiBZ,EAAA,IAAA,CAAA,EAAA,MAAA;AAgBhD;AAwCA;;;;;cAxDa,qBAAA,SAA8B,KAAA;;;ECrCtC,WAAA,CAAS,OAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA;;;;;AAgBd;;AAE8B,KDmClB,cAAA;;+GCSwB;kHAApB;;;ACzBhB,0DAA0C,OAAA;;;;;;;;;;;;;;;;;cFwD7B,UAAA,SAAmB,KAAA;;iBAEf;;;;;;;oBAQG;;;;;KCvGf,yCAAyC,QAAQ,YAAY;;;AFMlE;AAGA;AAcA;AAaA;;;;;;;;;ACxBa,cCIA,WDJyB,CAAA,UCIH,MDJG,CAAA,CAAA;EAMtB;EAE4C,SAAA,QAAA,EAAA,SCF9B,ODE8B,EAAA;EARd;;AAyB9C;AAgBA;AAwCA;;EAUoB,SAAA,WAAA,EAAA,MAAA;EAVY;EAAK,SAAA,MAAA,EAAA,MAAA,GAAA,SAAA;;iCC7Dd,uEAGR,UAAU;;AAtCoB;;;;;EAmBhC,WAAA,CAAA,CAAA,EAAW,OAAA;EAAW;;;;;;;EA8CnB,IAAA,CAAA,CAAA,EAAA,OAAA,CAAQ,WAAR,CAAoB,OAApB,CAAA,CAAA;;;;AFrDhB;AAcA;AAaA;;;;;;;;;ACxBA;;;;;AAyBA;AAgBA;AAwCA;;;;;;;;AChG6C;;;;AAGQ,cCqCxC,kBDrCwC,CAAA,UCqCX,MDrCW,CAAA,CAAA;EAgBxC,iBAAW,OAAA;EAAW,iBAAA,OAAA;EAEL,iBAAA,QAAA;EAcP,QAAA,QAAA;EAGE,QAAA,UAAA;EAAV,QAAA,MAAA;EA2BqB,QAAA,OAAA;EAAZ,QAAA,QAAA;EAAR,WAAA,CAAA,MAAA,ECfM,WDeN,EAAA,SAAA,CAAA,ECf+B,SDe/B;EAAO;;;;ACzBvB;;;;;;EAuCiB,KAAA,CAAA,WAAA,EAAA,SAda,UAcb,EAAA,CAAA,EAAA,IAAA;EAWI,KAAA,CAAA,GAAA,WAAA,EAxBG,UAwBH,EAAA,CAAA,EAAA,IAAA;EAuEgB;;;;;;;iBAlFpB;;;;;;;qBAWI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAuEJ,QAAQ,YAAY;;;;;;;;;GAqB3B,MAAA,CAAO,aAAA,KAAkB,eAAe"}
|