@arkiv-network/sdk 0.6.8 → 0.7.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 +52 -16
- package/dist/consts-Bz0LZQZY.js +7 -0
- package/dist/consts-Bz0LZQZY.js.map +1 -0
- package/dist/consts-CxT1-RXU.cjs +18 -0
- package/dist/entity-BhSXaB23.cjs +81 -0
- package/dist/{query-CO6f35AE.d.cts → entity-CN41IOrq.d.cts} +125 -59
- package/dist/entity-CN41IOrq.d.cts.map +1 -0
- package/dist/entity-DGfVyB-a.js +71 -0
- package/dist/entity-DGfVyB-a.js.map +1 -0
- package/dist/{query-BhdmAzYg.d.ts → entity-NnEVlePN.d.ts} +125 -59
- package/dist/entity-NnEVlePN.d.ts.map +1 -0
- package/dist/index-ClkpS6s_.d.ts +481 -0
- package/dist/index-ClkpS6s_.d.ts.map +1 -0
- package/dist/index-w4qop0Pe.d.cts +481 -0
- package/dist/index-w4qop0Pe.d.cts.map +1 -0
- package/dist/index.cjs +285 -233
- package/dist/index.d.cts +100 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +101 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +280 -230
- package/dist/index.js.map +1 -1
- package/dist/payload-BpNUPOnY.js +13 -0
- package/dist/payload-BpNUPOnY.js.map +1 -0
- package/dist/{payload-Da9gJMG5.d.ts → payload-C2KHOUoj.d.ts} +1 -1
- package/dist/{payload-Da9gJMG5.d.ts.map → payload-C2KHOUoj.d.ts.map} +1 -1
- package/dist/{payload-vwU3Rc6P.cjs → payload-D8YLKcJj.cjs} +1 -18
- package/dist/query/index.cjs +11 -28
- package/dist/query/index.d.cts +3 -3
- package/dist/query/index.d.ts +3 -3
- package/dist/query/index.js +8 -28
- package/dist/query/index.js.map +1 -1
- package/dist/{queryBuilder-DonAg1aq.js → queryBuilder-BE_XhLLa.js} +303 -152
- package/dist/queryBuilder-BE_XhLLa.js.map +1 -0
- package/dist/{queryBuilder-DM-YO1Y7.cjs → queryBuilder-J37buGCi.cjs} +372 -149
- package/dist/types/index.cjs +4 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +4 -1
- package/dist/utils/index.cjs +4 -10
- package/dist/utils/index.d.cts +0 -1
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -3
- package/dist/utils/index.js.map +1 -1
- package/package.json +11 -15
- package/src/actions/public/buildQuery.ts +4 -0
- package/src/actions/public/query.ts +10 -0
- package/src/actions/public/subscribeEntityEvents.ts +25 -51
- package/src/actions/wallet/changeOwnership.ts +6 -6
- package/src/actions/wallet/createEntity.ts +19 -6
- package/src/actions/wallet/deleteEntity.ts +2 -3
- package/src/actions/wallet/extendEntity.ts +9 -5
- package/src/actions/wallet/mutateEntities.ts +11 -54
- package/src/actions/wallet/updateEntity.ts +15 -6
- package/src/clients/createPublicClient.test.ts +2 -0
- package/src/clients/decorators/arkivPublic.ts +67 -2
- package/src/clients/decorators/arkivWallet.ts +23 -1
- package/src/consts.ts +2 -1
- package/src/errors.ts +46 -0
- package/src/index.ts +0 -3
- package/src/query/engine.test.ts +45 -0
- package/src/query/engine.ts +28 -14
- package/src/query/index.ts +1 -0
- package/src/query/predicate.test.ts +43 -0
- package/src/query/predicate.ts +14 -10
- package/src/query/queryBuilder.test.ts +22 -0
- package/src/query/queryBuilder.ts +221 -106
- package/src/query/queryResult.ts +13 -7
- package/src/query/selectQueryBuilder.test.ts +213 -0
- package/src/query/selection.test.ts +120 -0
- package/src/query/selection.ts +116 -0
- package/src/types/attributes.ts +25 -1
- package/src/types/entity.ts +12 -2
- package/src/types/events.ts +14 -16
- package/src/types/index.ts +1 -0
- package/src/types/rpcSchema.ts +7 -2
- package/src/utils/arkivTransactions.test.ts +260 -0
- package/src/utils/arkivTransactions.ts +255 -92
- package/src/utils/entities.ts +17 -7
- package/src/utils/index.ts +0 -1
- package/src/utils/payload.ts +4 -2
- package/src/utils/validation.test.ts +106 -0
- package/src/utils/validation.ts +80 -0
- package/dist/accounts/index.cjs +0 -9
- package/dist/accounts/index.d.cts +0 -1
- package/dist/accounts/index.d.ts +0 -1
- package/dist/accounts/index.js +0 -1
- package/dist/payload-DKBYYjeA.js +0 -18
- package/dist/payload-DKBYYjeA.js.map +0 -1
- package/dist/query-BhdmAzYg.d.ts.map +0 -1
- package/dist/query-CO6f35AE.d.cts.map +0 -1
- package/dist/queryBuilder-BvoQXa_u.d.ts +0 -328
- package/dist/queryBuilder-BvoQXa_u.d.ts.map +0 -1
- package/dist/queryBuilder-DonAg1aq.js.map +0 -1
- package/dist/queryBuilder-zTsKXctT.d.cts +0 -328
- package/dist/queryBuilder-zTsKXctT.d.cts.map +0 -1
- package/src/accounts/index.ts +0 -1
- /package/dist/{types-H-TSmRpm.js → types-Ci4BRClw.js} +0 -0
- /package/dist/{types-o3zWarRp.cjs → types-a8gm_IaQ.cjs} +0 -0
package/README.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# arkivjs
|
|
2
2
|
|
|
3
3
|
A TypeScript client library for Arkiv's blockchains interactions.
|
|
4
|
-
The Arkiv SDK
|
|
4
|
+
The Arkiv SDK builds strongly on the [Viem](https://github.com/wevm/viem) library - it extends Viem's clients with Arkiv's chain-specific features.
|
|
5
|
+
|
|
6
|
+
[`viem`](https://viem.sh) is a **peer dependency**: install it alongside the SDK.
|
|
5
7
|
|
|
6
8
|
## Installation
|
|
7
9
|
|
|
8
10
|
```bash
|
|
9
|
-
npm install @arkiv-network/sdk
|
|
11
|
+
npm install @arkiv-network/sdk viem
|
|
10
12
|
# or
|
|
11
|
-
pnpm install @arkiv-network/sdk
|
|
13
|
+
pnpm install @arkiv-network/sdk viem
|
|
12
14
|
# or
|
|
13
|
-
bun add @arkiv-network/sdk
|
|
15
|
+
bun add @arkiv-network/sdk viem
|
|
14
16
|
# or
|
|
15
|
-
yarn add @arkiv-network/sdk
|
|
17
|
+
yarn add @arkiv-network/sdk viem
|
|
16
18
|
```
|
|
17
19
|
|
|
18
20
|
## Usage
|
|
@@ -76,14 +78,15 @@ Modify the `"main"` entry to `"read_example.ts"` and set `"type"` to `"module"`
|
|
|
76
78
|
}
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
Install `@arkiv-network/sdk` using your preferred package manager:
|
|
81
|
+
Install `@arkiv-network/sdk` along with its `viem` peer dependency using your preferred package manager:
|
|
80
82
|
```bash
|
|
81
|
-
npm install @arkiv-network/sdk
|
|
83
|
+
npm install @arkiv-network/sdk viem
|
|
82
84
|
```
|
|
83
85
|
This command will update your `package.json` with a section like:
|
|
84
86
|
```json
|
|
85
87
|
"dependencies": {
|
|
86
|
-
"@arkiv-network/sdk": "^0.6.0"
|
|
88
|
+
"@arkiv-network/sdk": "^0.6.0",
|
|
89
|
+
"viem": "^2.38.2"
|
|
87
90
|
}
|
|
88
91
|
```
|
|
89
92
|
It will also create a `node_modules` directory with all dependencies installed.
|
|
@@ -93,9 +96,10 @@ It will also create a `node_modules` directory with all dependencies installed.
|
|
|
93
96
|
You can now use Arkiv's public client to query data. Paste the following in `read_example.ts`:
|
|
94
97
|
|
|
95
98
|
```typescript
|
|
96
|
-
import { createPublicClient
|
|
99
|
+
import { createPublicClient } from "@arkiv-network/sdk"
|
|
97
100
|
import { braga } from "@arkiv-network/sdk/chains"
|
|
98
101
|
import { eq } from "@arkiv-network/sdk/query"
|
|
102
|
+
import { http } from "viem"
|
|
99
103
|
|
|
100
104
|
const publicClient = createPublicClient({
|
|
101
105
|
chain: braga, // "braga" is Arkiv's testnet
|
|
@@ -110,13 +114,11 @@ console.log('Chain ID:', chainId);
|
|
|
110
114
|
const entity = await publicClient.getEntity('0xcadb830a3414251d65e5c92cd28ecb648d9e73d85f2203eff631839d5421f9d7');
|
|
111
115
|
console.log('Entity:', entity);
|
|
112
116
|
|
|
113
|
-
// Build and execute a query using
|
|
114
|
-
const
|
|
115
|
-
|
|
117
|
+
// Build and execute a query using select()
|
|
118
|
+
const result = await publicClient
|
|
119
|
+
.select({ owner: true, attributes: true, payload: true })
|
|
116
120
|
.where(eq('category', 'documentation'))
|
|
117
121
|
.ownedBy('0x6186B0DbA9652262942d5A465d49686eb560834C')
|
|
118
|
-
.withAttributes(true)
|
|
119
|
-
.withPayload(true)
|
|
120
122
|
.limit(10)
|
|
121
123
|
.fetch();
|
|
122
124
|
|
|
@@ -129,6 +131,39 @@ if (result.hasNextPage()) {
|
|
|
129
131
|
}
|
|
130
132
|
```
|
|
131
133
|
|
|
134
|
+
#### Selecting fields with `select()`
|
|
135
|
+
|
|
136
|
+
Pass nothing (or `"*"`) to fetch everything, or pass an object to fetch only specific fields:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// All fields
|
|
140
|
+
await publicClient.select().where(eq("category", "docs")).fetch();
|
|
141
|
+
|
|
142
|
+
// Only the fields you need
|
|
143
|
+
await publicClient.select({ key: true, owner: true, payload: true }).where(eq("category", "docs")).fetch();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Select only what you need.** Every selected field is fetched over the network, so requesting
|
|
147
|
+
data you won't use makes queries slower. Narrowing the selection keeps responses small and fast.
|
|
148
|
+
|
|
149
|
+
The result type is inferred from your selection: reading a field you didn't select is a compile error. The `toText()` / `toJson()` payload
|
|
150
|
+
helpers are available only when you select `payload`.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const [entity] = (await publicClient.select({ owner: true, payload: true }).fetch()).entities;
|
|
154
|
+
entity.owner; // ✅ Hex
|
|
155
|
+
entity.toJson(); // ✅ payload was selected
|
|
156
|
+
entity.creator; // ❌ compile error — not selected
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
> **Footgun:** pass the selection inline. A selection stored in a variable widens its `true` values
|
|
160
|
+
> to `boolean`, so the result type can't be narrowed (you get `{}` and a compile error on every
|
|
161
|
+
> field). If you need to reuse one, annotate it `as const`:
|
|
162
|
+
> ```typescript
|
|
163
|
+
> const fields = { owner: true, payload: true } as const;
|
|
164
|
+
> await publicClient.select(fields).where(eq("category", "docs")).fetch();
|
|
165
|
+
> ```
|
|
166
|
+
|
|
132
167
|
### Running the Example
|
|
133
168
|
|
|
134
169
|
You have several options to run your TypeScript sample:
|
|
@@ -170,10 +205,11 @@ Now let's add storage (write) functionality.
|
|
|
170
205
|
Create a file named `write_example.ts` with the following content:
|
|
171
206
|
|
|
172
207
|
```typescript
|
|
173
|
-
import { createPublicClient, createWalletClient
|
|
174
|
-
import { privateKeyToAccount } from "@arkiv-network/sdk/accounts"
|
|
208
|
+
import { createPublicClient, createWalletClient } from "@arkiv-network/sdk"
|
|
175
209
|
import { braga } from "@arkiv-network/sdk/chains"
|
|
176
210
|
import { ExpirationTime, jsonToPayload } from "@arkiv-network/sdk/utils"
|
|
211
|
+
import { http } from "viem"
|
|
212
|
+
import { privateKeyToAccount } from "viem/accounts"
|
|
177
213
|
|
|
178
214
|
// Create a public client
|
|
179
215
|
const publicClient = createPublicClient({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts-Bz0LZQZY.js","names":[],"sources":["../src/consts.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"],"mappings":";AACA,MAAa,gBAAgB;AAC7B,MAAa,aAAa"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/consts.ts
|
|
3
|
+
const ARKIV_ADDRESS = "0x4400000000000000000000000000000000000044";
|
|
4
|
+
const BLOCK_TIME = 2;
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
Object.defineProperty(exports, 'ARKIV_ADDRESS', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return ARKIV_ADDRESS;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, 'BLOCK_TIME', {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return BLOCK_TIME;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
let viem = require("viem");
|
|
2
|
+
|
|
3
|
+
//#region src/types/entity.ts
|
|
4
|
+
let EntityOperationType = /* @__PURE__ */ function(EntityOperationType$1) {
|
|
5
|
+
EntityOperationType$1[EntityOperationType$1["Create"] = 1] = "Create";
|
|
6
|
+
EntityOperationType$1[EntityOperationType$1["Update"] = 2] = "Update";
|
|
7
|
+
EntityOperationType$1[EntityOperationType$1["Extend"] = 3] = "Extend";
|
|
8
|
+
EntityOperationType$1[EntityOperationType$1["Transfer"] = 4] = "Transfer";
|
|
9
|
+
EntityOperationType$1[EntityOperationType$1["Delete"] = 5] = "Delete";
|
|
10
|
+
EntityOperationType$1[EntityOperationType$1["Expire"] = 6] = "Expire";
|
|
11
|
+
return EntityOperationType$1;
|
|
12
|
+
}({});
|
|
13
|
+
var Entity = class {
|
|
14
|
+
key;
|
|
15
|
+
contentType;
|
|
16
|
+
owner;
|
|
17
|
+
creator;
|
|
18
|
+
expiresAtBlock;
|
|
19
|
+
createdAtBlock;
|
|
20
|
+
lastModifiedAtBlock;
|
|
21
|
+
transactionIndexInBlock;
|
|
22
|
+
operationIndexInTransaction;
|
|
23
|
+
payload;
|
|
24
|
+
attributes;
|
|
25
|
+
constructor(key, contentType = void 0, owner = void 0, creator = void 0, expiresAtBlock = void 0, createdAtBlock = void 0, lastModifiedAtBlock = void 0, transactionIndexInBlock = void 0, operationIndexInTransaction = void 0, payload = void 0, attributes) {
|
|
26
|
+
this.key = key;
|
|
27
|
+
this.owner = owner;
|
|
28
|
+
this.creator = creator;
|
|
29
|
+
this.expiresAtBlock = expiresAtBlock;
|
|
30
|
+
this.createdAtBlock = createdAtBlock;
|
|
31
|
+
this.lastModifiedAtBlock = lastModifiedAtBlock;
|
|
32
|
+
this.transactionIndexInBlock = transactionIndexInBlock;
|
|
33
|
+
this.operationIndexInTransaction = operationIndexInTransaction;
|
|
34
|
+
this.payload = payload;
|
|
35
|
+
this.attributes = attributes;
|
|
36
|
+
this.contentType = contentType;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the entity payload from bytes to a string and returns it.
|
|
40
|
+
* Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.
|
|
41
|
+
* Throws an error if the conversion from bytes to string fails.
|
|
42
|
+
* @returns The entity payload as a string.
|
|
43
|
+
*/
|
|
44
|
+
toText() {
|
|
45
|
+
if (this.payload === void 0) throw new Error("Entity has no payload – it was probably queried without withPayload(true) via QueryBuilder");
|
|
46
|
+
try {
|
|
47
|
+
return (0, viem.bytesToString)(this.payload);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
throw new Error(`Failed to convert entity payload to text: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses the entity payload as JSON and returns the resulting object.
|
|
54
|
+
* Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.
|
|
55
|
+
* Throws an error if the payload is empty or cannot be parsed as JSON.
|
|
56
|
+
* @returns The parsed JSON object from the entity payload.
|
|
57
|
+
*/
|
|
58
|
+
toJson() {
|
|
59
|
+
const text = this.toText();
|
|
60
|
+
if (!text) throw new Error("Entity has empty payload, cannot parse as JSON");
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(text);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
throw new Error(`Failed to parse entity payload as JSON: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
Object.defineProperty(exports, 'Entity', {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return Entity;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, 'EntityOperationType', {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return EntityOperationType;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Account, Chain, Client, Hash, Hex, RpcSchema, Transport } from "viem";
|
|
1
|
+
import { Account, Address, Chain, Client, Hash, Hex, RpcSchema, Transport } from "viem";
|
|
2
2
|
|
|
3
3
|
//#region src/types/mimeTypes.d.ts
|
|
4
4
|
type MimeType = "text/plain" | "text/html" | "text/css" | "text/csv" | "text/xml" | "text/javascript" | "application/json" | "application/xml" | "application/pdf" | "application/zip" | "application/gzip" | "application/octet-stream" | "application/javascript" | "application/x-www-form-urlencoded" | "image/png" | "image/jpeg" | "image/webp" | "image/gif" | "image/svg+xml" | "audio/mpeg" | "audio/wav" | "audio/ogg" | "video/mp4" | "video/webm" | "video/ogg" | "multipart/form-data";
|
|
@@ -15,15 +15,17 @@ type RpcEntity = {
|
|
|
15
15
|
operationIndexInTransaction: Hex;
|
|
16
16
|
owner: Hex;
|
|
17
17
|
creator: Hex;
|
|
18
|
-
|
|
18
|
+
attributes?: {
|
|
19
19
|
key: string;
|
|
20
20
|
value: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
key: string;
|
|
24
|
-
value: Hex;
|
|
25
|
-
}];
|
|
21
|
+
valueType: RpcAttributeValueType;
|
|
22
|
+
}[];
|
|
26
23
|
};
|
|
24
|
+
declare enum RpcAttributeValueType {
|
|
25
|
+
Uint = 1,
|
|
26
|
+
String = 2,
|
|
27
|
+
EntityKey = 3,
|
|
28
|
+
}
|
|
27
29
|
type RpcOrderByAttribute = {
|
|
28
30
|
name: string;
|
|
29
31
|
type: "string" | "numeric";
|
|
@@ -81,17 +83,52 @@ type GetBlockTimingReturnType = {
|
|
|
81
83
|
blockDuration: number;
|
|
82
84
|
};
|
|
83
85
|
//#endregion
|
|
86
|
+
//#region src/actions/public/query.d.ts
|
|
87
|
+
type QueryOptionsIncludeData = {
|
|
88
|
+
attributes?: boolean;
|
|
89
|
+
payload?: boolean;
|
|
90
|
+
metadata?: boolean;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated Server-side ordering is not supported by the network. Sort the fetched
|
|
94
|
+
* entities in JavaScript instead (e.g. `entities.sort(...)`). This type will be removed
|
|
95
|
+
* in a future release.
|
|
96
|
+
*/
|
|
97
|
+
type QueryOptionsOrderBy = {
|
|
98
|
+
name: string;
|
|
99
|
+
type: "string" | "numeric";
|
|
100
|
+
desc: "asc" | "desc";
|
|
101
|
+
};
|
|
102
|
+
type QueryOptions = {
|
|
103
|
+
includeData?: QueryOptionsIncludeData;
|
|
104
|
+
atBlock?: bigint;
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Server-side ordering is not supported by the network, so this option has no
|
|
107
|
+
* effect on the returned order. Sort the fetched entities in JavaScript instead
|
|
108
|
+
* (e.g. `entities.sort(...)`). This option will be removed in a future release.
|
|
109
|
+
*/
|
|
110
|
+
orderBy?: QueryOptionsOrderBy[];
|
|
111
|
+
resultsPerPage?: number | undefined;
|
|
112
|
+
cursor?: string | undefined;
|
|
113
|
+
};
|
|
114
|
+
type QueryReturnType = {
|
|
115
|
+
entities: Entity[];
|
|
116
|
+
cursor: string | undefined;
|
|
117
|
+
blockNumber: bigint | undefined;
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
84
120
|
//#region src/actions/wallet/changeOwnership.d.ts
|
|
85
121
|
/**
|
|
86
|
-
* Parameters for the
|
|
87
|
-
* - entityKey: The key of the entity
|
|
122
|
+
* Parameters for the changeOwnership function.
|
|
123
|
+
* - entityKey: The key of the entity.
|
|
124
|
+
* - newOwner: The address of the new owner.
|
|
88
125
|
*/
|
|
89
126
|
type ChangeOwnershipParameters = {
|
|
90
127
|
entityKey: Hex;
|
|
91
128
|
newOwner: Hex;
|
|
92
129
|
};
|
|
93
130
|
/**
|
|
94
|
-
* Return type for the
|
|
131
|
+
* Return type for the changeOwnership function.
|
|
95
132
|
* - entityKey: The key of the entity.
|
|
96
133
|
* - txHash: The transaction hash.
|
|
97
134
|
*/
|
|
@@ -104,14 +141,24 @@ type ChangeOwnershipReturnType = {
|
|
|
104
141
|
/**
|
|
105
142
|
* Parameters for the createEntity function.
|
|
106
143
|
* - payload: The payload of the entity.
|
|
107
|
-
* - attributes: The attributes of the entity.
|
|
144
|
+
* - attributes: The attributes of the entity. Attribute values may be strings
|
|
145
|
+
* or numbers, but numeric values **must be integers**. To store a non-integer,
|
|
146
|
+
* scale it to an integer (e.g. `1.5` -> `1500`) to preserve numeric ordering,
|
|
147
|
+
* or pass it as a string (e.g. `"1.5"`). A non-integer numeric value throws an
|
|
148
|
+
* {@link InvalidAttributeError}.
|
|
108
149
|
* - contentType: The content type of the entity.
|
|
109
|
-
* - expiresIn:
|
|
150
|
+
* - expiresIn: How long until the entity expires, in seconds. Because Arkiv
|
|
151
|
+
* measures expiration in blocks (1 block = 2 seconds), this **must be a
|
|
152
|
+
* positive integer and a multiple of the block time (2 seconds)**
|
|
153
|
+
* Invalid values throw an {@link InvalidExpirationError}.
|
|
110
154
|
*/
|
|
111
155
|
type CreateEntityParameters = {
|
|
112
156
|
payload: Uint8Array;
|
|
157
|
+
/** Entity attributes. Numeric values must be integers (scale non-integers, e.g. `1.5` -> `1500`, or use a string). Throws {@link InvalidAttributeError} otherwise. */
|
|
113
158
|
attributes: Attribute[];
|
|
114
159
|
contentType: MimeType | string;
|
|
160
|
+
/** Seconds until expiry. Must be a positive integer and a multiple of the 2s block time.
|
|
161
|
+
* Throws {@link InvalidExpirationError} otherwise. */
|
|
115
162
|
expiresIn: number;
|
|
116
163
|
};
|
|
117
164
|
/**
|
|
@@ -146,10 +193,15 @@ type DeleteEntityReturnType = {
|
|
|
146
193
|
/**
|
|
147
194
|
* Parameters for the extendEntity function.
|
|
148
195
|
* - entityKey: The key of the entity to extend.
|
|
149
|
-
* - expiresIn:
|
|
196
|
+
* - expiresIn: How long to extend the entity by, in seconds. Because Arkiv
|
|
197
|
+
* measures expiration in blocks (1 block = 2 seconds), this **must be a
|
|
198
|
+
* positive integer and a multiple of the block time (2 seconds)**.
|
|
199
|
+
* Invalid values throw an {@link InvalidExpirationError}.
|
|
150
200
|
*/
|
|
151
201
|
type ExtendEntityParameters = {
|
|
152
202
|
entityKey: Hex;
|
|
203
|
+
/** Seconds to extend by. Must be a positive integer and a multiple of the 2s block time.
|
|
204
|
+
* Throws {@link InvalidExpirationError} otherwise. */
|
|
153
205
|
expiresIn: number;
|
|
154
206
|
};
|
|
155
207
|
/**
|
|
@@ -167,15 +219,25 @@ type ExtendEntityReturnType = {
|
|
|
167
219
|
* Parameters for the updateEntity function.
|
|
168
220
|
* - entityKey: The key of the entity to update.
|
|
169
221
|
* - payload: The payload of the entity.
|
|
170
|
-
* - attributes: The attributes of the entity.
|
|
222
|
+
* - attributes: The attributes of the entity. Attribute values may be strings
|
|
223
|
+
* or numbers, but numeric values **must be integers**. To store a non-integer,
|
|
224
|
+
* scale it to an integer (e.g. `1.5` -> `1500`) to preserve numeric ordering,
|
|
225
|
+
* or pass it as a string (e.g. `"1.5"`). A non-integer numeric value throws an
|
|
226
|
+
* {@link InvalidAttributeError}.
|
|
171
227
|
* - contentType: The content type of the entity.
|
|
172
|
-
* - expiresIn:
|
|
228
|
+
* - expiresIn: How long until the entity expires, in seconds. Because Arkiv
|
|
229
|
+
* measures expiration in blocks (1 block = 2 seconds), this **must be a
|
|
230
|
+
* positive integer and a multiple of the block time (2 seconds)**.
|
|
231
|
+
* Invalid values throw an {@link InvalidExpirationError}.
|
|
173
232
|
*/
|
|
174
233
|
type UpdateEntityParameters = {
|
|
175
234
|
entityKey: Hex;
|
|
176
235
|
payload: Uint8Array;
|
|
236
|
+
/** Entity attributes. Numeric values must be integers (scale non-integers, e.g. `1.5` -> `1500`, or use a string). Throws {@link InvalidAttributeError} otherwise. */
|
|
177
237
|
attributes: Attribute[];
|
|
178
238
|
contentType: MimeType | string;
|
|
239
|
+
/** Seconds until expiry. Must be a positive integer and a multiple of the 2s block time.
|
|
240
|
+
* Throws {@link InvalidExpirationError} otherwise. */
|
|
179
241
|
expiresIn: number;
|
|
180
242
|
};
|
|
181
243
|
/**
|
|
@@ -222,44 +284,64 @@ type MutateEntitiesReturnType = {
|
|
|
222
284
|
};
|
|
223
285
|
//#endregion
|
|
224
286
|
//#region src/types/attributes.d.ts
|
|
287
|
+
/**
|
|
288
|
+
* An entity attribute (key/value pair).
|
|
289
|
+
*
|
|
290
|
+
* Arkiv supports string, Hex and number values.
|
|
291
|
+
*
|
|
292
|
+
* Hex values are stored as the on-chain `EntityKey` type **only when they are
|
|
293
|
+
* exactly 32 bytes** (66 characters, e.g. an entity key). Hex-looking strings
|
|
294
|
+
* of any other length are stored as plain strings: they round-trip unchanged
|
|
295
|
+
* and compare lexicographically, not as hex.
|
|
296
|
+
*
|
|
297
|
+
* Numeric values **must be non-negative integers** (they are stored on-chain
|
|
298
|
+
* as unsigned 256-bit) — passing a non-integer (e.g. `1.5`) or negative number
|
|
299
|
+
* throws an {@link InvalidAttributeError} at mutation time. To store a
|
|
300
|
+
* non-integer value:
|
|
301
|
+
* - Scale it to an integer (e.g. `1.5` -> `1500`, dividing by the same factor on
|
|
302
|
+
* read) to keep numeric ordering and range queries working.
|
|
303
|
+
* - Or pass it as a string (e.g. `"1.5"`), which sorts lexicographically and so
|
|
304
|
+
* does not support numeric comparisons.
|
|
305
|
+
*
|
|
306
|
+
* To store a negative value, offset it into the non-negative range (subtracting
|
|
307
|
+
* the offset on read) or store it as a string.
|
|
308
|
+
*/
|
|
225
309
|
type Attribute = {
|
|
226
310
|
key: string;
|
|
227
|
-
value: string |
|
|
311
|
+
value: number | string | Hex;
|
|
228
312
|
};
|
|
229
313
|
//#endregion
|
|
230
314
|
//#region src/types/events.d.ts
|
|
231
315
|
type OnEntityCreatedEvent = {
|
|
232
316
|
entityKey: Hex;
|
|
233
|
-
owner:
|
|
234
|
-
|
|
235
|
-
|
|
317
|
+
owner: Address;
|
|
318
|
+
expiresAt: number;
|
|
319
|
+
entityHash: Hex;
|
|
236
320
|
};
|
|
237
321
|
type OnEntityUpdatedEvent = {
|
|
238
322
|
entityKey: Hex;
|
|
239
|
-
owner:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
cost: bigint;
|
|
323
|
+
owner: Address;
|
|
324
|
+
expiresAt: number;
|
|
325
|
+
entityHash: Hex;
|
|
243
326
|
};
|
|
244
327
|
type OnEntityDeletedEvent = {
|
|
245
328
|
entityKey: Hex;
|
|
246
|
-
owner:
|
|
329
|
+
owner: Address;
|
|
247
330
|
};
|
|
248
331
|
type OnEntityExpiredEvent = {
|
|
249
332
|
entityKey: Hex;
|
|
250
|
-
owner:
|
|
333
|
+
owner: Address;
|
|
251
334
|
};
|
|
252
335
|
type OnEntityExpiresInExtendedEvent = {
|
|
253
336
|
entityKey: Hex;
|
|
254
|
-
owner:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
cost: bigint;
|
|
337
|
+
owner: Address;
|
|
338
|
+
expiresAt: number;
|
|
339
|
+
entityHash: Hex;
|
|
258
340
|
};
|
|
259
341
|
type OnEntityOwnerChangedEvent = {
|
|
260
342
|
entityKey: Hex;
|
|
261
|
-
|
|
262
|
-
|
|
343
|
+
owner: Address;
|
|
344
|
+
entityHash: Hex;
|
|
263
345
|
};
|
|
264
346
|
//#endregion
|
|
265
347
|
//#region src/types/txParams.d.ts
|
|
@@ -278,9 +360,17 @@ type TxParams = {
|
|
|
278
360
|
};
|
|
279
361
|
//#endregion
|
|
280
362
|
//#region src/types/entity.d.ts
|
|
363
|
+
declare enum EntityOperationType {
|
|
364
|
+
Create = 1,
|
|
365
|
+
Update = 2,
|
|
366
|
+
Extend = 3,
|
|
367
|
+
Transfer = 4,
|
|
368
|
+
Delete = 5,
|
|
369
|
+
Expire = 6,
|
|
370
|
+
}
|
|
281
371
|
declare class Entity {
|
|
282
372
|
key: Hex;
|
|
283
|
-
contentType: MimeType | undefined;
|
|
373
|
+
contentType: MimeType | `${string}/${string}` | undefined;
|
|
284
374
|
owner: Hex | undefined;
|
|
285
375
|
creator: Hex | undefined;
|
|
286
376
|
expiresAtBlock: bigint | undefined;
|
|
@@ -290,7 +380,7 @@ declare class Entity {
|
|
|
290
380
|
operationIndexInTransaction: bigint | undefined;
|
|
291
381
|
payload: Uint8Array | undefined;
|
|
292
382
|
attributes: Attribute[];
|
|
293
|
-
constructor(key: Hex, contentType: MimeType | undefined, owner: Hex | undefined, creator: Hex | undefined, expiresAtBlock: bigint | undefined, createdAtBlock: bigint | undefined, lastModifiedAtBlock: bigint | undefined, transactionIndexInBlock: bigint | undefined, operationIndexInTransaction: bigint | undefined, payload: Uint8Array | undefined, attributes: Attribute[]);
|
|
383
|
+
constructor(key: Hex, contentType: MimeType | `${string}/${string}` | undefined, owner: Hex | undefined, creator: Hex | undefined, expiresAtBlock: bigint | undefined, createdAtBlock: bigint | undefined, lastModifiedAtBlock: bigint | undefined, transactionIndexInBlock: bigint | undefined, operationIndexInTransaction: bigint | undefined, payload: Uint8Array | undefined, attributes: Attribute[]);
|
|
294
384
|
/**
|
|
295
385
|
* Converts the entity payload from bytes to a string and returns it.
|
|
296
386
|
* Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.
|
|
@@ -307,29 +397,5 @@ declare class Entity {
|
|
|
307
397
|
toJson(): any;
|
|
308
398
|
}
|
|
309
399
|
//#endregion
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
attributes?: boolean;
|
|
313
|
-
payload?: boolean;
|
|
314
|
-
metadata?: boolean;
|
|
315
|
-
};
|
|
316
|
-
type QueryOptionsOrderBy = {
|
|
317
|
-
name: string;
|
|
318
|
-
type: "string" | "numeric";
|
|
319
|
-
desc: "asc" | "desc";
|
|
320
|
-
};
|
|
321
|
-
type QueryOptions = {
|
|
322
|
-
includeData?: QueryOptionsIncludeData;
|
|
323
|
-
atBlock?: bigint;
|
|
324
|
-
orderBy?: QueryOptionsOrderBy[];
|
|
325
|
-
resultsPerPage?: number | undefined;
|
|
326
|
-
cursor?: string | undefined;
|
|
327
|
-
};
|
|
328
|
-
type QueryReturnType = {
|
|
329
|
-
entities: Entity[];
|
|
330
|
-
cursor: string | undefined;
|
|
331
|
-
blockNumber: bigint | undefined;
|
|
332
|
-
};
|
|
333
|
-
//#endregion
|
|
334
|
-
export { RpcIncludeData as A, CreateEntityReturnType as C, ArkivClient as D, GetBlockTimingReturnType as E, RpcQueryOptions as M, MimeType as N, ArkivRpcSchema as O, CreateEntityParameters as S, ChangeOwnershipReturnType as T, UpdateEntityReturnType as _, Entity as a, DeleteEntityParameters as b, OnEntityDeletedEvent as c, OnEntityOwnerChangedEvent as d, OnEntityUpdatedEvent as f, UpdateEntityParameters as g, MutateEntitiesReturnType as h, QueryReturnType as i, RpcOrderByAttribute as j, RpcEntity as k, OnEntityExpiredEvent as l, MutateEntitiesParameters as m, QueryOptionsIncludeData as n, TxParams as o, Attribute as p, QueryOptionsOrderBy as r, OnEntityCreatedEvent as s, QueryOptions as t, OnEntityExpiresInExtendedEvent as u, ExtendEntityParameters as v, ChangeOwnershipParameters as w, DeleteEntityReturnType as x, ExtendEntityReturnType as y };
|
|
335
|
-
//# sourceMappingURL=query-CO6f35AE.d.cts.map
|
|
400
|
+
export { RpcEntity as A, QueryOptions as C, GetBlockTimingReturnType as D, QueryReturnType as E, RpcOrderByAttribute as M, RpcQueryOptions as N, ArkivClient as O, MimeType as P, ChangeOwnershipReturnType as S, QueryOptionsOrderBy as T, DeleteEntityParameters as _, OnEntityDeletedEvent as a, CreateEntityReturnType as b, OnEntityOwnerChangedEvent as c, MutateEntitiesParameters as d, MutateEntitiesReturnType as f, ExtendEntityReturnType as g, ExtendEntityParameters as h, OnEntityCreatedEvent as i, RpcIncludeData as j, ArkivRpcSchema as k, OnEntityUpdatedEvent as l, UpdateEntityReturnType as m, EntityOperationType as n, OnEntityExpiredEvent as o, UpdateEntityParameters as p, TxParams as r, OnEntityExpiresInExtendedEvent as s, Entity as t, Attribute as u, DeleteEntityReturnType as v, QueryOptionsIncludeData as w, ChangeOwnershipParameters as x, CreateEntityParameters as y };
|
|
401
|
+
//# sourceMappingURL=entity-CN41IOrq.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-CN41IOrq.d.cts","names":[],"sources":["../src/types/mimeTypes.ts","../src/types/rpcSchema.ts","../src/clients/baseClient.ts","../src/actions/public/getBlockTiming.ts","../src/actions/public/query.ts","../src/actions/wallet/changeOwnership.ts","../src/actions/wallet/createEntity.ts","../src/actions/wallet/deleteEntity.ts","../src/actions/wallet/extendEntity.ts","../src/actions/wallet/updateEntity.ts","../src/actions/wallet/mutateEntities.ts","../src/types/attributes.ts","../src/types/events.ts","../src/types/txParams.ts","../src/types/entity.ts"],"sourcesContent":[],"mappings":";;;KAAY,QAAA;;;KCGA,SAAA;EDHA,GAAA,ECIL,GDJK;eCKG;;aAEF;EAJD,cAAS,EAKH,GALG;EACd,mBAAA,EAKgB,GALhB;EACQ,uBAAA,EAKY,GALZ;EAEF,2BAAA,EAIkB,GAJlB;EACK,KAAA,EAIT,GAJS;EACK,OAAA,EAIZ,GAJY;EACI,UAAA,CAAA,EAAA;IACI,GAAA,EAAA,MAAA;IACtB,KAAA,EAAA,MAAA;IACE,SAAA,EAC6C,qBAD7C;EAC6C,CAAA,EAAA;CAAqB;AAGjE,aAAA,qBAAA;EAMA,IAAA,GAAA,CAAA;EAMA,MAAA,GAAA,CAAA;EACA,SAAA,GAAA,CAAA;;AAEA,KATA,mBAAA,GASA;EACO,IAAA,EAAA,MAAA;EAAG,IAAA,EAAA,QAAA,GAAA,SAAA;EAIV,IAAA,EAAA,OAAA;AAcZ,CAAA;AAGgD,KAzBpC,eAAA,GAyBoC;EAEpC,OAAA,CAAA,EA1BA,GA0B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AAA;EACO;;;;;ACtDnB;EACoB,MAAA,CAAA,CAAA,EAAA,GAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { bytesToString } from "viem";
|
|
2
|
+
|
|
3
|
+
//#region src/types/entity.ts
|
|
4
|
+
let EntityOperationType = /* @__PURE__ */ function(EntityOperationType$1) {
|
|
5
|
+
EntityOperationType$1[EntityOperationType$1["Create"] = 1] = "Create";
|
|
6
|
+
EntityOperationType$1[EntityOperationType$1["Update"] = 2] = "Update";
|
|
7
|
+
EntityOperationType$1[EntityOperationType$1["Extend"] = 3] = "Extend";
|
|
8
|
+
EntityOperationType$1[EntityOperationType$1["Transfer"] = 4] = "Transfer";
|
|
9
|
+
EntityOperationType$1[EntityOperationType$1["Delete"] = 5] = "Delete";
|
|
10
|
+
EntityOperationType$1[EntityOperationType$1["Expire"] = 6] = "Expire";
|
|
11
|
+
return EntityOperationType$1;
|
|
12
|
+
}({});
|
|
13
|
+
var Entity = class {
|
|
14
|
+
key;
|
|
15
|
+
contentType;
|
|
16
|
+
owner;
|
|
17
|
+
creator;
|
|
18
|
+
expiresAtBlock;
|
|
19
|
+
createdAtBlock;
|
|
20
|
+
lastModifiedAtBlock;
|
|
21
|
+
transactionIndexInBlock;
|
|
22
|
+
operationIndexInTransaction;
|
|
23
|
+
payload;
|
|
24
|
+
attributes;
|
|
25
|
+
constructor(key, contentType = void 0, owner = void 0, creator = void 0, expiresAtBlock = void 0, createdAtBlock = void 0, lastModifiedAtBlock = void 0, transactionIndexInBlock = void 0, operationIndexInTransaction = void 0, payload = void 0, attributes) {
|
|
26
|
+
this.key = key;
|
|
27
|
+
this.owner = owner;
|
|
28
|
+
this.creator = creator;
|
|
29
|
+
this.expiresAtBlock = expiresAtBlock;
|
|
30
|
+
this.createdAtBlock = createdAtBlock;
|
|
31
|
+
this.lastModifiedAtBlock = lastModifiedAtBlock;
|
|
32
|
+
this.transactionIndexInBlock = transactionIndexInBlock;
|
|
33
|
+
this.operationIndexInTransaction = operationIndexInTransaction;
|
|
34
|
+
this.payload = payload;
|
|
35
|
+
this.attributes = attributes;
|
|
36
|
+
this.contentType = contentType;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the entity payload from bytes to a string and returns it.
|
|
40
|
+
* Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.
|
|
41
|
+
* Throws an error if the conversion from bytes to string fails.
|
|
42
|
+
* @returns The entity payload as a string.
|
|
43
|
+
*/
|
|
44
|
+
toText() {
|
|
45
|
+
if (this.payload === void 0) throw new Error("Entity has no payload – it was probably queried without withPayload(true) via QueryBuilder");
|
|
46
|
+
try {
|
|
47
|
+
return bytesToString(this.payload);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
throw new Error(`Failed to convert entity payload to text: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses the entity payload as JSON and returns the resulting object.
|
|
54
|
+
* Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.
|
|
55
|
+
* Throws an error if the payload is empty or cannot be parsed as JSON.
|
|
56
|
+
* @returns The parsed JSON object from the entity payload.
|
|
57
|
+
*/
|
|
58
|
+
toJson() {
|
|
59
|
+
const text = this.toText();
|
|
60
|
+
if (!text) throw new Error("Entity has empty payload, cannot parse as JSON");
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(text);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
throw new Error(`Failed to parse entity payload as JSON: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { EntityOperationType as n, Entity as t };
|
|
71
|
+
//# sourceMappingURL=entity-DGfVyB-a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-DGfVyB-a.js","names":[],"sources":["../src/types/entity.ts"],"sourcesContent":["import { bytesToString, type Hex } from \"viem\"\n\nexport enum EntityOperationType {\n Create = 1,\n Update = 2,\n Extend = 3,\n Transfer = 4,\n Delete = 5,\n Expire = 6,\n}\n\nimport type { MimeType } from \"../types\"\nimport type { Attribute } from \"./attributes\"\n\nexport class Entity {\n key: Hex\n contentType: MimeType | `${string}/${string}` | undefined\n owner: Hex | undefined\n creator: Hex | undefined\n expiresAtBlock: bigint | undefined\n createdAtBlock: bigint | undefined\n lastModifiedAtBlock: bigint | undefined\n transactionIndexInBlock: bigint | undefined\n operationIndexInTransaction: bigint | undefined\n payload: Uint8Array | undefined\n attributes: Attribute[]\n\n constructor(\n key: Hex,\n contentType: MimeType | `${string}/${string}` | undefined = undefined,\n owner: Hex | undefined = undefined,\n creator: Hex | undefined = undefined,\n expiresAtBlock: bigint | undefined = undefined,\n createdAtBlock: bigint | undefined = undefined,\n lastModifiedAtBlock: bigint | undefined = undefined,\n transactionIndexInBlock: bigint | undefined = undefined,\n operationIndexInTransaction: bigint | undefined = undefined,\n payload: Uint8Array | undefined = undefined,\n attributes: Attribute[],\n ) {\n this.key = key\n this.owner = owner\n this.creator = creator\n this.expiresAtBlock = expiresAtBlock\n this.createdAtBlock = createdAtBlock\n this.lastModifiedAtBlock = lastModifiedAtBlock\n this.transactionIndexInBlock = transactionIndexInBlock\n this.operationIndexInTransaction = operationIndexInTransaction\n this.payload = payload\n this.attributes = attributes\n this.contentType = contentType\n }\n\n /**\n * Converts the entity payload from bytes to a string and returns it.\n * Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.\n * Throws an error if the conversion from bytes to string fails.\n * @returns The entity payload as a string.\n */\n toText(): string {\n if (this.payload === undefined) {\n throw new Error(\n \"Entity has no payload – it was probably queried without withPayload(true) via QueryBuilder\",\n )\n }\n try {\n return bytesToString(this.payload)\n } catch (e) {\n throw new Error(\n `Failed to convert entity payload to text: ${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n )\n }\n }\n\n /**\n * Parses the entity payload as JSON and returns the resulting object.\n * Throws an error if the payload is undefined, which may occur if the entity was not queried with the withPayload option.\n * Throws an error if the payload is empty or cannot be parsed as JSON.\n * @returns The parsed JSON object from the entity payload.\n */\n toJson(): any {\n const text = this.toText()\n if (!text) {\n throw new Error(\"Entity has empty payload, cannot parse as JSON\")\n }\n try {\n return JSON.parse(text)\n } catch (e) {\n throw new Error(\n `Failed to parse entity payload as JSON: ${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n )\n }\n }\n}\n"],"mappings":";;;AAEA,IAAY,sEAAL;AACL;AACA;AACA;AACA;AACA;AACA;;;AAMF,IAAa,SAAb,MAAoB;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACE,KACA,cAA4D,QAC5D,QAAyB,QACzB,UAA2B,QAC3B,iBAAqC,QACrC,iBAAqC,QACrC,sBAA0C,QAC1C,0BAA8C,QAC9C,8BAAkD,QAClD,UAAkC,QAClC,YACA;AACA,OAAK,MAAM;AACX,OAAK,QAAQ;AACb,OAAK,UAAU;AACf,OAAK,iBAAiB;AACtB,OAAK,iBAAiB;AACtB,OAAK,sBAAsB;AAC3B,OAAK,0BAA0B;AAC/B,OAAK,8BAA8B;AACnC,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,cAAc;;;;;;;;CASrB,SAAiB;AACf,MAAI,KAAK,YAAY,OACnB,OAAM,IAAI,MACR,6FACD;AAEH,MAAI;AACF,UAAO,cAAc,KAAK,QAAQ;WAC3B,GAAG;AACV,SAAM,IAAI,MACR,6CAA6C,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,IACvF,EAAE,OAAO,GAAG,CACb;;;;;;;;;CAUL,SAAc;EACZ,MAAM,OAAO,KAAK,QAAQ;AAC1B,MAAI,CAAC,KACH,OAAM,IAAI,MAAM,iDAAiD;AAEnE,MAAI;AACF,UAAO,KAAK,MAAM,KAAK;WAChB,GAAG;AACV,SAAM,IAAI,MACR,2CAA2C,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,IACrF,EAAE,OAAO,GAAG,CACb"}
|