@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,6 +1,6 @@
1
- import { bytesToString, type Hex } from "viem"
2
- import type { AttributeSchema, Attributes } from "../attr"
1
+ import type { Hex } from "viem"
3
2
  import type { ResolvedCreationFlags } from "../entity/flags"
3
+ import type { AttributeSchema, Attributes } from "../schema"
4
4
 
5
5
  /**
6
6
  * The fields an {@link Entity} can carry. Every one is optional: a query returns exactly the parts
@@ -18,20 +18,20 @@ export type EntityFields = {
18
18
  expiresAt?: bigint | undefined
19
19
  /** The immutable properties the entity was created with. */
20
20
  creationFlags?: ResolvedCreationFlags | undefined
21
- contentType?: string | undefined
22
- payload?: Uint8Array | undefined
23
- /** Attribute names and types, with no values. */
21
+ /** Attribute names, types and indexing, with no values. */
24
22
  attributeSchema?: AttributeSchema | undefined
25
23
  /** Attribute names, types and values. */
26
24
  attributes?: Attributes | undefined
27
25
  }
28
26
 
29
27
  /**
30
- * An entity as it comes back from a query.
28
+ * An entity as the node returns it, decoded: the fields a query selected, with its attributes as a
29
+ * map keyed by name. Which fields are populated is decided by the selection, so each may be
30
+ * `undefined`.
31
31
  *
32
- * Which fields are populated is decided by the query's selection — `select({ key: true })` gives
33
- * back an entity carrying only its key. The static type of a `select()` result is narrowed to
34
- * exactly the selected fields, so in typed code the `undefined`s here are not reachable.
32
+ * Queries do not return these: `select()`, `query()` and `getEntity()` lay each one out as a flat
33
+ * row — the selected entity fields and attributes side by side, typed by the selection and, through
34
+ * a schema, by its columns.
35
35
  */
36
36
  export class Entity implements EntityFields {
37
37
  key: Hex | undefined
@@ -41,8 +41,6 @@ export class Entity implements EntityFields {
41
41
  updatedAt: bigint | undefined
42
42
  expiresAt: bigint | undefined
43
43
  creationFlags: ResolvedCreationFlags | undefined
44
- contentType: string | undefined
45
- payload: Uint8Array | undefined
46
44
  attributeSchema: AttributeSchema | undefined
47
45
  attributes: Attributes | undefined
48
46
 
@@ -54,51 +52,7 @@ export class Entity implements EntityFields {
54
52
  this.updatedAt = fields.updatedAt
55
53
  this.expiresAt = fields.expiresAt
56
54
  this.creationFlags = fields.creationFlags
57
- this.contentType = fields.contentType
58
- this.payload = fields.payload
59
55
  this.attributeSchema = fields.attributeSchema
60
56
  this.attributes = fields.attributes
61
57
  }
62
-
63
- /**
64
- * The payload decoded as UTF-8 text.
65
- *
66
- * @throws If the payload was not selected, or is not valid UTF-8.
67
- */
68
- toText(): string {
69
- if (this.payload === undefined) {
70
- throw new Error(
71
- "Entity has no payload — the query did not select it. Use select({ payload: true }).",
72
- )
73
- }
74
- try {
75
- return bytesToString(this.payload)
76
- } catch (e) {
77
- throw new Error(
78
- `Failed to convert entity payload to text: ${e instanceof Error ? e.message : String(e)}`,
79
- { cause: e },
80
- )
81
- }
82
- }
83
-
84
- /**
85
- * The payload parsed as JSON.
86
- *
87
- * @throws If the payload was not selected, is empty, or is not valid JSON.
88
- */
89
- // biome-ignore lint/suspicious/noExplicitAny: JSON.parse returns whatever the payload holds.
90
- toJson(): any {
91
- const text = this.toText()
92
- if (!text) {
93
- throw new Error("Entity has empty payload, cannot parse as JSON")
94
- }
95
- try {
96
- return JSON.parse(text)
97
- } catch (e) {
98
- throw new Error(
99
- `Failed to parse entity payload as JSON: ${e instanceof Error ? e.message : String(e)}`,
100
- { cause: e },
101
- )
102
- }
103
- }
104
58
  }
@@ -31,7 +31,7 @@ export type EntityCreatedEvent = EntityEventContext & {
31
31
  }
32
32
 
33
33
  /**
34
- * An entity's attributes or payload changed.
34
+ * An entity's attributes changed.
35
35
  *
36
36
  * The event says *that* it changed, not what to — read the entity to see the new state.
37
37
  */
@@ -4,20 +4,28 @@ export type {
4
4
  PredictEntityKeysReturnType,
5
5
  PredictedEntityKey,
6
6
  } from "../actions/public/predictEntityKeys"
7
- export type { QueryOptions, QueryReturnType } from "../actions/public/query"
7
+ export type { QueryOptions, QueryReturnType, QueryRow } from "../actions/public/query"
8
8
  export type { WatchEntityEventsParameters } from "../actions/public/watchEntityEvents"
9
9
  export type {
10
10
  ChangeOwnershipParameters,
11
11
  ChangeOwnershipReturnType,
12
12
  } from "../actions/wallet/changeOwnership"
13
- export type { CreateEntityParameters, CreateEntityReturnType } from "../actions/wallet/createEntity"
13
+ export type {
14
+ CreateEntityOptions,
15
+ CreateEntityParameters,
16
+ CreateEntityReturnType,
17
+ } from "../actions/wallet/createEntity"
14
18
  export type { DeleteEntityParameters, DeleteEntityReturnType } from "../actions/wallet/deleteEntity"
15
19
  export type {
16
20
  ExecuteBatchParameters,
17
21
  ExecuteBatchReturnType,
18
22
  } from "../actions/wallet/executeBatch"
19
23
  export type { ExtendEntityParameters, ExtendEntityReturnType } from "../actions/wallet/extendEntity"
20
- export type { PatchEntityParameters, PatchEntityReturnType } from "../actions/wallet/patchEntity"
24
+ export type {
25
+ PatchEntityChanges,
26
+ PatchEntityParameters,
27
+ PatchEntityReturnType,
28
+ } from "../actions/wallet/patchEntity"
21
29
  export type { EntityFields } from "./entity"
22
30
  export { Entity } from "./entity"
23
31
  export type {
@@ -29,7 +37,6 @@ export type {
29
37
  ExpiryExtendedEvent,
30
38
  OwnershipTransferredEvent,
31
39
  } from "./events"
32
- export type { MimeType } from "./mimeTypes"
33
40
  export type {
34
41
  ArkivRpcSchema,
35
42
  RpcAttribute,
@@ -1,10 +1,10 @@
1
- import type { Hex, PublicRpcSchema } from "viem"
1
+ import type { Hex } from "viem"
2
2
 
3
3
  /**
4
4
  * An attribute as the node renders it: the name, the type **tag** (not the wire typeId), and the
5
5
  * value in the JSON encoding that type prescribes — a JSON number for `i32`, a `0x` QUANTITY for
6
- * `u64` and `u256`, a decimal string for `dec`, `0x` DATA for the byte-shaped types, and a string for
7
- * `str`.
6
+ * `u64` and `u256`, a decimal string for `dec`, `0x` DATA for the byte-shaped types (`bytes`
7
+ * included), and a string for `str`.
8
8
  *
9
9
  * The encoding follows the *declared type*, never the magnitude, so a decoder dispatches on `type`
10
10
  * and never has to guess from the shape of the value.
@@ -15,10 +15,14 @@ export type RpcAttribute = {
15
15
  value: unknown
16
16
  }
17
17
 
18
- /** An entry of the `attributeSchema` projection — a name and its type, with no value. */
18
+ /**
19
+ * An entry of the `attributeSchema` projection — a name, its type, and whether the node indexes
20
+ * it, with no value.
21
+ */
19
22
  export type RpcAttributeSchemaEntry = {
20
23
  name: string
21
24
  type: string
25
+ indexed?: boolean
22
26
  }
23
27
 
24
28
  /**
@@ -42,8 +46,6 @@ export type RpcEntity = {
42
46
  updatedAt?: Hex
43
47
  expiresAt?: Hex
44
48
  creationFlags?: RpcCreationFlags | number
45
- contentType?: string
46
- payload?: Hex
47
49
  attributeSchema?: RpcAttributeSchemaEntry[]
48
50
  attributes?: RpcAttribute[]
49
51
  }
@@ -63,10 +65,13 @@ export type RpcSelect = {
63
65
  updatedAt?: boolean
64
66
  expiresAt?: boolean
65
67
  creationFlags?: boolean
66
- contentType?: boolean
67
- payload?: boolean
68
68
  attributeSchema?: boolean
69
69
  attributes?: boolean | Record<string, boolean>
70
+ /**
71
+ * Not a field of each entity but of the page: the number of entities the query matches at the
72
+ * block, regardless of `limit` and `cursor`, returned as the response's `count`.
73
+ */
74
+ count?: boolean
70
75
  }
71
76
 
72
77
  /** The second parameter of `arkiv_query` — what to return, and where in the results to start. */
@@ -75,7 +80,7 @@ export type RpcQueryOptions = {
75
80
  atBlock?: Hex
76
81
  /** What to return. Defaults to `{ key: true }`. */
77
82
  select?: RpcSelect
78
- /** Page size, as a hex quantity. Node maximum is 200. */
83
+ /** Page size, as a hex quantity. Node maximum is 100. */
79
84
  limit?: Hex
80
85
  /** Opaque cursor from a previous response; bound to that query, block and selection. */
81
86
  cursor?: string
@@ -90,8 +95,16 @@ export type ArkivRpcSchema = [
90
95
  blockNumber: Hex
91
96
  /** Omitted when no pages remain. */
92
97
  cursor?: string
98
+ /** How many entities the query matches, as a hex quantity. Present only when selected. */
99
+ count?: Hex
93
100
  }
94
101
  },
102
+ {
103
+ Method: "arkiv_getEntity"
104
+ Parameters: [entityKey: Hex]
105
+ /** Every field except `attributeSchema`, or `null` if no live entity has the key. */
106
+ ReturnType: RpcEntity | null
107
+ },
95
108
  {
96
109
  Method: "arkiv_getBlockTiming"
97
110
  Parameters?: []
@@ -101,11 +114,4 @@ export type ArkivRpcSchema = [
101
114
  duration: number
102
115
  }
103
116
  },
104
- {
105
- Method: "arkiv_getEntityCount"
106
- Parameters?: []
107
- ReturnType: number
108
- },
109
117
  ]
110
-
111
- export type PublicArkivRpcSchema = [...PublicRpcSchema, ...ArkivRpcSchema]