Skip to content

Commit 2a5c275

Browse files
feat: add ts utils
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent 46d8ce0 commit 2a5c275

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Utils
2+
3+
The following utilities are provided to help you work with document and asset data inside your Satellite. They simplify tasks such as decoding and encoding data, serializing custom types, and interacting with Juno’s core features in a consistent way.
4+
5+
:::note[📦 Library]
6+
7+
All utilities on this page are provided by the [@junobuild/functions](https://www.npmjs.com/package/@junobuild/functions) library.
8+
9+
To use them, add this to your project:
10+
11+
import { Bash } from "../../../components/bash.mdx";
12+
13+
<Bash
14+
npm="npm i @junobuild/functions"
15+
yarn="yarn add @junobuild/functions"
16+
pnpm="pnpm add @junobuild/functions"
17+
/>
18+
19+
:::
20+
21+
---
22+
23+
## decodeDocData
24+
25+
Decodes the raw data of a document into a typed object. Use this inside hooks or assertions to retrieve the original contents of a document.
26+
27+
```typescript
28+
function decodeDocData<T>(data: Uint8Array): T;
29+
```
30+
31+
📦 Import from `@junobuild/functions/utils`
32+
33+
Parameters:
34+
35+
- `data`: A Uint8Array containing the raw binary document data.
36+
37+
Returns:
38+
39+
- A deserialized object of type `T`.
40+
41+
---
42+
43+
## encodeDocData
44+
45+
Encodes an object into a raw binary format for storing document data. Use this when creating or modifying a document inside a hook or assertion.
46+
47+
```typescript
48+
function encodeDocData<T>(data: T): Uint8Array;
49+
```
50+
51+
📦 Import from `@junobuild/functions/utils`
52+
53+
Parameters:
54+
55+
- `data`: A JavaScript object to serialize.
56+
57+
Returns:
58+
59+
- A `Uint8Array` containing the encoded binary data.

sidebars.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,21 @@ const sidebars: SidebarsConfig = {
216216
description:
217217
"API reference for writing serverless functions in Rust."
218218
},
219-
items: [
220-
"reference/functions/rust/utils"
221-
]
219+
items: ["reference/functions/rust/utils"]
222220
},
221+
{
222+
type: "category",
223+
label: "TypeScript",
224+
link: {
225+
type: "generated-index",
226+
slug: "/reference/functions/typescript",
227+
description:
228+
"API reference for writing serverless functions with TypeScript."
229+
},
230+
items: ["reference/functions/typescript/utils"]
231+
}
223232
]
224-
},
233+
}
225234
]
226235
};
227236

0 commit comments

Comments
 (0)