Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# deps
/node_modules

# generated content
.contentlayer
.content-collections
.source

# test & build
/coverage
/.next/
/out/
/build
*.tsbuildinfo

# misc
.DS_Store
*.pem
/.pnp
.pnp.js
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# others
.env*.local
.vercel
next-env.d.ts
45 changes: 45 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# docs

This is a Next.js application generated with
[Create Fumadocs](https://github.com/fuma-nama/fumadocs).

Run development server:

```bash
npm run dev
# or
pnpm dev
# or
yarn dev
```

Open http://localhost:3000 with your browser to see the result.

## Explore

In the project, you can see:

- `lib/source.ts`: Code for content source adapter, [`loader()`](https://fumadocs.dev/docs/headless/source-api) provides the interface to access your content.
- `lib/layout.shared.tsx`: Shared options for layouts, optional but preferred to keep.

| Route | Description |
| ------------------------- | ------------------------------------------------------ |
| `app/(home)` | The route group for your landing page and other pages. |
| `app/docs` | The documentation layout and pages. |
| `app/api/search/route.ts` | The Route Handler for search. |

### Fumadocs MDX

A `source.config.ts` config file has been included, you can customise different options like frontmatter schema.

Read the [Introduction](https://fumadocs.dev/docs/mdx) for further details.

## Learn More

To learn more about Next.js and Fumadocs, take a look at the following
resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- [Fumadocs](https://fumadocs.vercel.app) - learn about Fumadocs
6 changes: 6 additions & 0 deletions docs/app/(home)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { HomeLayout } from "fumadocs-ui/layouts/home"
import { baseOptions } from "@/lib/layout.shared"

export default function Layout({ children }: LayoutProps<"/">) {
return <HomeLayout {...baseOptions()}>{children}</HomeLayout>
}
6 changes: 6 additions & 0 deletions docs/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { redirect } from "next/navigation"

export default function HomePage() {
// Permanently redirect root to /docs
redirect("/docs")
}
13 changes: 13 additions & 0 deletions docs/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// import { source } from '@/lib/source';
// import { createFromSource } from 'fumadocs-core/search/server';

// export const { GET } = createFromSource(source, {
// // https://docs.orama.com/docs/orama-js/supported-languages
// language: 'english',
// });

import { source } from "@/lib/source"
import { createFromSource } from "fumadocs-core/search/server"
// it should be cached forever
export const revalidate = false
export const { staticGET: GET } = createFromSource(source)
44 changes: 44 additions & 0 deletions docs/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { source } from "@/lib/source"
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from "fumadocs-ui/page"
import type { Metadata } from "next"
import { notFound } from "next/navigation"
import { createRelativeLink } from "fumadocs-ui/mdx"
import { getMDXComponents } from "@/mdx-components"

export default async function Page(props: PageProps<"/docs/[[...slug]]">) {
const params = await props.params
const page = source.getPage(params.slug)
if (!page) notFound()

const MDXContent = page.data.body

return (
<DocsPage toc={page.data.toc} full={page.data.full}>
<DocsTitle>{page.data.title}</DocsTitle>
<DocsDescription>{page.data.description}</DocsDescription>
<DocsBody>
<MDXContent
components={getMDXComponents({
// this allows you to link to other pages with relative file paths
a: createRelativeLink(source, page)
})}
/>
</DocsBody>
</DocsPage>
)
}

export async function generateStaticParams() {
return source.generateParams()
}

export async function generateMetadata(props: PageProps<"/docs/[[...slug]]">): Promise<Metadata> {
const params = await props.params
const page = source.getPage(params.slug)
if (!page) notFound()

return {
title: page.data.title,
description: page.data.description
}
}
11 changes: 11 additions & 0 deletions docs/app/docs/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DocsLayout } from "fumadocs-ui/layouts/docs"
import { baseOptions } from "@/lib/layout.shared"
import { source } from "@/lib/source"

export default function Layout({ children }: LayoutProps<"/docs">) {
return (
<DocsLayout tree={source.pageTree} {...baseOptions()}>
{children}
</DocsLayout>
)
}
3 changes: 3 additions & 0 deletions docs/app/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
17 changes: 17 additions & 0 deletions docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "@/app/global.css"
import { RootProvider } from "fumadocs-ui/provider"
import { Inter } from "next/font/google"

const inter = Inter({
subsets: ["latin"]
})

export default function Layout({ children }: LayoutProps<"/">) {
return (
<html lang="en" className={inter.className} suppressHydrationWarning>
<body className="flex flex-col min-h-screen">
<RootProvider>{children}</RootProvider>
</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Address

Address module provides functionality for working with address types in Cardano.

## Address Example

{/* BEGIN:snippet file=address.ts region=address-example lang=typescript */}
---
title: "Address Format"
---

```typescript
// Examples for Address getting-started page
// Run with: pnpm -w -C docs ts-node examples/address.ts (or a small runner)

// #region address-example
import assert from "node:assert/strict"
import { Address } from "@evolution-sdk/evolution"
Expand All @@ -22,10 +21,9 @@ const actualBech32 = Address.toBech32(address)

// Verify the conversion is correct
assert.strictEqual(actualBech32, expectedBech32)
```

{/* END:snippet */}
// #endregion address-example

## API Reference

For detailed API documentation, see the generated TypeDoc documentation.
if (import.meta.url === `file://${process.argv[1]}`) {
console.log("Address example OK")
}
```
7 changes: 7 additions & 0 deletions docs/content/docs/getting-started/address/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "Address"
---

# Address

- [Address Format](/../content/docs/getting-started/address/address-format)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Basic Data Construction

Learn how to create fundamental Data types using constructors.
---
title: "Basic Data Construction"
description: "Learn how to create fundamental Data types using constructors."
---

```typescript
import assert from "node:assert/strict"
Expand Down
16 changes: 16 additions & 0 deletions docs/content/docs/getting-started/data/bytes-validate.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "Validate bytes"
description: "Quick check for hex-like bytes strings using Data.isBytes."
---

```typescript
import assert from "node:assert/strict"
import { Data } from "@evolution-sdk/evolution"

const hex = "deadbeef"
assert.equal(Data.isBytes(hex), true)

const invalid = "not-hex"
assert.equal(Data.isBytes(invalid), false)

```
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# CBOR Encoding Options

Compare different CBOR encoding strategies for the same data.
---
title: "CBOR Encoding Options"
description: "Compare different CBOR encoding strategies for the same data."
---

```typescript
// #region main
import assert from "node:assert/strict"
import { CBOR, Data } from "@evolution-sdk/evolution"

// Create complex data with unsorted elements (Maps should be standalone, not in constructor fields)
const unsortedMap = new Map<Data.Data, Data.Data>([
["7a65627261", 1n], // 'zebra' in hex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Complex Nested Structures

Build sophisticated nested data structures with multiple levels and types.
---
title: "Complex Nested Structures"
description: "Build sophisticated nested data structures with multiple levels and types."
---

```typescript
// #region main
import assert from "node:assert/strict"
import { Data } from "@evolution-sdk/evolution"

// Create a complex user profile with nested data using only valid Data types
const userProfile = new Data.Constr({
index: 0n, // User constructor
Expand Down
57 changes: 57 additions & 0 deletions docs/content/docs/getting-started/data/data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "Data"
---

```typescript
// Examples for Data getting-started page

// #region data-nested-canonical
import assert from "node:assert/strict"
import { CBOR, Data } from "@evolution-sdk/evolution"
// Create a complex nested data structure with:
// - Constructor with index 1 containing multiple fields
// - Nested constructors with different indices
// - A Map with mixed key-value pairs
// - An array of numbers
const nestedUnsortedData = new Data.Constr({
index: 1n,
fields: [
// Nested constructor: 121_0([123_0([])])
new Data.Constr({
index: 0n,
fields: [
new Data.Constr({
index: 2n,
fields: []
})
]
}),
// Map with unsorted keys (will be sorted in canonical mode)
new Map<Data.Data, Data.Data>([
["deadbeef01", new Data.Constr({ index: 0n, fields: [] })],
["beef", 19n],
["deadbeef03", new Data.Constr({ index: 1n, fields: [] })]
]),
// Array of numbers
[10n, 5n, 2n, 3n, 1n, 4n]
]
})

// Encode using default options (indefinite-length encoding for Data)
const cborHex = Data.toCBORHex(nestedUnsortedData)

const decodedData = Data.fromCBORHex(cborHex)

// Create a canonical codec for deterministic encoding
// This ensures consistent output and sorted map keys
// Encode using canonical mode (definite-length, sorted keys)
const canonicalCborHex = Data.toCBORHex(nestedUnsortedData, CBOR.CANONICAL_OPTIONS)

// Verify that decoding works correctly
assert.deepStrictEqual(decodedData, nestedUnsortedData)
// #endregion data-nested-canonical

if (import.meta.url === `file://${process.argv[1]}`) {
console.log("Data example OK")
}
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Error Handling Patterns

Use Either patterns for safe data operations with proper error handling.
---
title: "Error Handling Patterns"
description: "Use Either patterns for safe data operations with proper error handling."
---

```typescript
// #region main
import assert from "node:assert/strict"
import { Data, Either, pipe } from "@evolution-sdk/evolution"

// Use built-in Either-based functions for safe operations
const safeData = new Data.Constr({ index: 0n, fields: ["74657374", 42n] }) // 'test' as hex

Expand Down
15 changes: 15 additions & 0 deletions docs/content/docs/getting-started/data/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "Data"
---

# Data

- [Basic Data Construction](/../content/docs/getting-started/data/basic-construction)
- [Validate bytes](/../content/docs/getting-started/data/bytes-validate)
- [CBOR Encoding Options](/../content/docs/getting-started/data/cbor-encoding-options)
- [Complex Nested Structures](/../content/docs/getting-started/data/complex-nested-structures)
- [Data](/../content/docs/getting-started/data/data)
- [Error Handling Patterns](/../content/docs/getting-started/data/error-handling-patterns)
- [Canonical nested structure](/../content/docs/getting-started/data/nested-canonical)
- [Roundtrip encode/decode](/../content/docs/getting-started/data/roundtrip)
- [Working with Maps](/../content/docs/getting-started/data/working-with-maps)
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Canonical nested structure

Complex nested Data encoding with canonical CBOR options.
---
title: "Canonical nested structure"
description: "Complex nested Data encoding with canonical CBOR options."
---

```typescript
// #region main
import assert from "node:assert/strict"
import { CBOR, Data } from "@evolution-sdk/evolution"

const nestedUnsortedData = new Data.Constr({
index: 1n,
fields: [
Expand Down
Loading