@arkiv-network/sdk 0.8.1-dev.1 → 0.9.0-next.2

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 (184) hide show
  1. package/README.md +180 -61
  2. package/dist/chains/index.d.ts +17 -17
  3. package/dist/changeOwnership-Cy9gfyjN.d.cts +1160 -0
  4. package/dist/changeOwnership-Cy9gfyjN.d.cts.map +1 -0
  5. package/dist/changeOwnership-gXf-lBqI.d.ts +1160 -0
  6. package/dist/changeOwnership-gXf-lBqI.d.ts.map +1 -0
  7. package/dist/entity/index.cjs +4 -10
  8. package/dist/entity/index.d.cts +3 -3
  9. package/dist/entity/index.d.ts +3 -3
  10. package/dist/entity/index.js +3 -4
  11. package/dist/entity-BM1unrQf.cjs +41 -0
  12. package/dist/{entity-DJ0Gml9c.cjs → entity-BgaFJSaV.cjs} +4 -4
  13. package/dist/entity-CFAI1KyG.js +36 -0
  14. package/dist/entity-CFAI1KyG.js.map +1 -0
  15. package/dist/{entity-CniBgBSd.js → entity-CGqx_AU0.js} +4 -4
  16. package/dist/entity-CGqx_AU0.js.map +1 -0
  17. package/dist/{payload-AfUfSctb.d.ts → expirationTime-C7PZK49K.d.ts} +8 -37
  18. package/dist/expirationTime-C7PZK49K.d.ts.map +1 -0
  19. package/dist/expirationTime-CkIGNAg8.cjs +140 -0
  20. package/dist/{payload-D167BlJR.d.cts → expirationTime-DOB8V4B8.d.cts} +8 -37
  21. package/dist/expirationTime-DOB8V4B8.d.cts.map +1 -0
  22. package/dist/{expiry-Cgdb_dbq.js → expirationTime-UKPuA-LM.js} +62 -27
  23. package/dist/expirationTime-UKPuA-LM.js.map +1 -0
  24. package/dist/expiry-B48I-yTA.d.cts +40 -0
  25. package/dist/expiry-B48I-yTA.d.cts.map +1 -0
  26. package/dist/expiry-S2PUL8Hg.d.ts +40 -0
  27. package/dist/expiry-S2PUL8Hg.d.ts.map +1 -0
  28. package/dist/index-C-mMF5WZ.d.cts +735 -0
  29. package/dist/index-C-mMF5WZ.d.cts.map +1 -0
  30. package/dist/{index-BkqSnGJH.d.ts → index-C4zZqJ9S.d.ts} +5 -27
  31. package/dist/index-C4zZqJ9S.d.ts.map +1 -0
  32. package/dist/{index-CLhsFyVH.d.cts → index-CcVWYB6v.d.cts} +5 -27
  33. package/dist/index-CcVWYB6v.d.cts.map +1 -0
  34. package/dist/index-DCx2XC6S.d.ts +489 -0
  35. package/dist/index-DCx2XC6S.d.ts.map +1 -0
  36. package/dist/index-DLb7BfIw.d.ts +735 -0
  37. package/dist/index-DLb7BfIw.d.ts.map +1 -0
  38. package/dist/index-DzriOUm8.d.cts +489 -0
  39. package/dist/index-DzriOUm8.d.cts.map +1 -0
  40. package/dist/index.cjs +162 -146
  41. package/dist/index.d.cts +180 -133
  42. package/dist/index.d.cts.map +1 -1
  43. package/dist/index.d.ts +180 -133
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +93 -83
  46. package/dist/index.js.map +1 -1
  47. package/dist/params-BuIrJA9a.cjs +45 -0
  48. package/dist/params-DDJOnsNi.js +22 -0
  49. package/dist/params-DDJOnsNi.js.map +1 -0
  50. package/dist/query/index.cjs +9 -4
  51. package/dist/query/index.d.cts +6 -6
  52. package/dist/query/index.d.ts +6 -6
  53. package/dist/query/index.js +4 -5
  54. package/dist/query-D0KtuFh2.cjs +1625 -0
  55. package/dist/query-DpRDozmj.js +1417 -0
  56. package/dist/query-DpRDozmj.js.map +1 -0
  57. package/dist/schema/index.cjs +46 -0
  58. package/dist/schema/index.d.cts +2 -0
  59. package/dist/schema/index.d.ts +2 -0
  60. package/dist/schema/index.js +3 -0
  61. package/dist/{attr-BXTkpnoc.cjs → schema-B9AyXcgU.cjs} +513 -246
  62. package/dist/{attr-tmyREHtw.js → schema-DY4sqehl.js} +427 -244
  63. package/dist/schema-DY4sqehl.js.map +1 -0
  64. package/dist/types/index.cjs +1 -1
  65. package/dist/types/index.d.cts +5 -5
  66. package/dist/types/index.d.ts +5 -5
  67. package/dist/types/index.js +1 -1
  68. package/dist/utils/index.cjs +3 -5
  69. package/dist/utils/index.d.cts +3 -3
  70. package/dist/utils/index.d.ts +3 -3
  71. package/dist/utils/index.js +3 -3
  72. package/package.json +9 -12
  73. package/src/actions/public/getEntity.test.ts +69 -0
  74. package/src/actions/public/getEntity.ts +34 -20
  75. package/src/actions/public/predictEntityKeys.ts +8 -7
  76. package/src/actions/public/query.test.ts +58 -0
  77. package/src/actions/public/query.ts +41 -13
  78. package/src/actions/wallet/createEntity.ts +34 -63
  79. package/src/actions/wallet/executeBatch.test.ts +38 -0
  80. package/src/actions/wallet/executeBatch.ts +26 -9
  81. package/src/actions/wallet/extendEntity.ts +9 -8
  82. package/src/actions/wallet/patchEntity.ts +43 -52
  83. package/src/clients/createPublicClient.test.ts +10 -2
  84. package/src/clients/createWalletClient.ts +4 -1
  85. package/src/clients/decorators/arkivPublic.ts +123 -80
  86. package/src/clients/decorators/arkivWallet.ts +113 -65
  87. package/src/entity/create.test.ts +25 -21
  88. package/src/entity/expiry.ts +8 -6
  89. package/src/entity/flags.ts +1 -1
  90. package/src/entity/index.ts +2 -4
  91. package/src/entity/key.ts +3 -3
  92. package/src/entity/operations.ts +1 -1
  93. package/src/errors.ts +2 -11
  94. package/src/index.ts +18 -6
  95. package/src/query/builderBase.ts +166 -0
  96. package/src/query/countBuilder.test.ts +91 -0
  97. package/src/query/countBuilder.ts +67 -0
  98. package/src/query/engine.ts +9 -3
  99. package/src/query/errors.ts +24 -14
  100. package/src/query/expression.test.ts +129 -21
  101. package/src/query/expression.ts +323 -94
  102. package/src/query/index.ts +26 -4
  103. package/src/query/injection.test.ts +5 -11
  104. package/src/query/queryBuilder.test.ts +467 -58
  105. package/src/query/queryBuilder.ts +191 -98
  106. package/src/query/queryResult.ts +35 -9
  107. package/src/query/selection.test.ts +278 -24
  108. package/src/query/selection.ts +427 -86
  109. package/src/schema/attributes.test.ts +266 -0
  110. package/src/schema/attributes.ts +212 -0
  111. package/src/{attr → schema}/codec.test.ts +37 -5
  112. package/src/{attr → schema}/codec.ts +40 -11
  113. package/src/schema/column.ts +193 -0
  114. package/src/{attr → schema}/errors.ts +67 -10
  115. package/src/schema/index.ts +76 -0
  116. package/src/{attr → schema}/names.ts +4 -2
  117. package/src/schema/schema.test.ts +171 -0
  118. package/src/schema/schema.ts +250 -0
  119. package/src/{attr → schema}/types.ts +36 -30
  120. package/src/{attr → schema}/values.test.ts +62 -3
  121. package/src/{attr → schema}/values.ts +246 -65
  122. package/src/types/entity.test.ts +1 -44
  123. package/src/types/entity.ts +9 -55
  124. package/src/types/events.ts +1 -1
  125. package/src/types/index.ts +11 -4
  126. package/src/types/rpcSchema.ts +22 -16
  127. package/src/utils/arkivTransactions.test.ts +356 -116
  128. package/src/utils/arkivTransactions.ts +30 -38
  129. package/src/utils/entities.ts +10 -9
  130. package/src/utils/expirationTime.ts +5 -5
  131. package/src/utils/index.ts +0 -1
  132. package/src/utils/logger.test.ts +45 -0
  133. package/src/utils/logger.ts +5 -39
  134. package/src/utils/revert.test.ts +25 -0
  135. package/src/utils/revert.ts +28 -3
  136. package/dist/attr/index.cjs +0 -34
  137. package/dist/attr/index.d.cts +0 -2
  138. package/dist/attr/index.d.ts +0 -2
  139. package/dist/attr/index.js +0 -3
  140. package/dist/attr-tmyREHtw.js.map +0 -1
  141. package/dist/entity-B0t6sN7F.cjs +0 -71
  142. package/dist/entity-BIp_df9u.js +0 -67
  143. package/dist/entity-BIp_df9u.js.map +0 -1
  144. package/dist/entity-CniBgBSd.js.map +0 -1
  145. package/dist/expiry-BxOlvVWC.d.ts +0 -79
  146. package/dist/expiry-BxOlvVWC.d.ts.map +0 -1
  147. package/dist/expiry-CG9GhVXv.cjs +0 -135
  148. package/dist/expiry-Cgdb_dbq.js.map +0 -1
  149. package/dist/expiry-DRV29F1r.d.cts +0 -79
  150. package/dist/expiry-DRV29F1r.d.cts.map +0 -1
  151. package/dist/flags-DCD26uhe.cjs +0 -43
  152. package/dist/flags-DUT2gHEU.js +0 -33
  153. package/dist/flags-DUT2gHEU.js.map +0 -1
  154. package/dist/index-BkqSnGJH.d.ts.map +0 -1
  155. package/dist/index-C7fbakoI.d.cts +0 -278
  156. package/dist/index-C7fbakoI.d.cts.map +0 -1
  157. package/dist/index-CIcHPx2j.d.cts +0 -424
  158. package/dist/index-CIcHPx2j.d.cts.map +0 -1
  159. package/dist/index-CLhsFyVH.d.cts.map +0 -1
  160. package/dist/index-Cd2aaWme.d.ts +0 -424
  161. package/dist/index-Cd2aaWme.d.ts.map +0 -1
  162. package/dist/index-Cq6fa8AI.d.ts +0 -278
  163. package/dist/index-Cq6fa8AI.d.ts.map +0 -1
  164. package/dist/index-DaNeJUw8.d.ts +0 -955
  165. package/dist/index-DaNeJUw8.d.ts.map +0 -1
  166. package/dist/index-Dv16LO2s.d.cts +0 -955
  167. package/dist/index-Dv16LO2s.d.cts.map +0 -1
  168. package/dist/payload-AfUfSctb.d.ts.map +0 -1
  169. package/dist/payload-D167BlJR.d.cts.map +0 -1
  170. package/dist/payload-DE7wMztL.js +0 -92
  171. package/dist/payload-DE7wMztL.js.map +0 -1
  172. package/dist/payload-DqFweqiO.cjs +0 -108
  173. package/dist/query-9oojUdM7.cjs +0 -1128
  174. package/dist/query-Ber-lOJQ.js +0 -968
  175. package/dist/query-Ber-lOJQ.js.map +0 -1
  176. package/src/actions/public/getEntityCount.ts +0 -10
  177. package/src/attr/attributes.test.ts +0 -120
  178. package/src/attr/attributes.ts +0 -196
  179. package/src/attr/index.ts +0 -50
  180. package/src/types/mimeTypes.ts +0 -27
  181. package/src/utils/compression.test.ts +0 -32
  182. package/src/utils/compression.ts +0 -102
  183. package/src/utils/payload.ts +0 -36
  184. /package/src/{attr → schema}/decimal.ts +0 -0
@@ -1,79 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"expiry-DRV29F1r.d.cts","names":[],"sources":["../src/entity/expiry.ts"],"sourcesContent":[],"mappings":";;;AAuBA;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"}
@@ -1,43 +0,0 @@
1
- const require_errors = require('./errors-DhV00966.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
- });
@@ -1,33 +0,0 @@
1
- import { t as InvalidCreationFlagsError } from "./errors-D2E1GRjw.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-DUT2gHEU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flags-DUT2gHEU.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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-BkqSnGJH.d.ts","names":[],"sources":["../src/entity/errors.ts","../src/entity/events.ts","../src/entity/flags.ts","../src/entity/key.ts","../src/entity/params.ts"],"sourcesContent":[],"mappings":";;;;cACa,kBAAA,S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kCA;;;AAGE,iBD7Bc,mBAAA,CC6Bd,KAAA,CAAA,ED7ByC,aC6BzC,CAAA,EAAA,MAAA;;;;;;;iBDXc,mBAAA,eAAkC;;;;cCjDrC;AHLb;AAQA;AAQA;AAYA;;cGhBa;;AFPb;AASA;KEGY,SAAA,mBAA4B;;;ADNxC;AAcA;AAWA;AAkBA;;;;ACjDa,iBAuBG,UAAA,CAAA,CAvBuB,EAAA,MAAA;;;;;;;;;iBAyDvB,gBAAA;;;;;;EC5DH;EAGA,KAAA,EDgEJ,OChEI;EAQD;;;;;;QD+DJ;;;IAGJ;;;;;;AH/ES,cIEA,cJFmB,EAAQ,MAAK;AAQ7C;AAQa,cIXA,aJWyB,EAAA;EAYzB,SAAA,MAAA,EAAA,CAAA;;;;ECvBA,SAAA,MAAA,EAAA,CAAA;AASb,CAAA;KGDY,aAAA,WAAwB,4BAA4B"}
@@ -1,278 +0,0 @@
1
- import { K as TypeTag } from "./index-CIcHPx2j.cjs";
2
- import { L as Expression, O as SelectArg, at as ArkivClient, ft as RpcSelect, j as Entity } from "./index-Dv16LO2s.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` `u64` `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 { tiramisu } 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: tiramisu, 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-C7fbakoI.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-C7fbakoI.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,M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