diff --git a/docs/codeblocks/pages.examples.Address.ts b/docs/codeblocks/pages.examples.Address.ts new file mode 100644 index 00000000..6d6f2d16 --- /dev/null +++ b/docs/codeblocks/pages.examples.Address.ts @@ -0,0 +1,14 @@ +import assert from "assert" +import { Address } from "@evolution-sdk/evolution" + +const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530" +const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m" + +// Decode from hex +const address = Address.Codec.Decode.hex(hexAddress) + +// Encode to bech32 +const actualBech32 = Address.Codec.Encode.bech32(address) + +// Verify the conversion is correct +assert(actualBech32 === expectedBech32) diff --git a/docs/codeblocks/pages.examples.Data.ts b/docs/codeblocks/pages.examples.Data.ts new file mode 100644 index 00000000..d53a87af --- /dev/null +++ b/docs/codeblocks/pages.examples.Data.ts @@ -0,0 +1,75 @@ +import assert from "assert" +import { 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([ + ["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 codec (indefinite-length encoding) +const cborHex = Data.Codec().Encode.cborHex(nestedUnsortedData) +// Output: d87a9fd8799fd87b80ffbf45deadbeef01d8798042beef1345deadbeef03d87a80ff9f0a0502030104ffff + +// CBOR diagnostic notation (indefinite-length): +// 122_0([_ +// 121_0([_ 123_0([])]), +// {_ +// h'deadbeef01': 121_0([]), +// h'beef': 19, +// h'deadbeef03': 122_0([]), +// }, +// [_ 10, 5, 2, 3, 1, 4], +// ]) +// Visualize at: https://cbor.nemo157.com/ + +const decodedData = Data.Codec().Decode.cborHex(cborHex) + +// Create a canonical codec for deterministic encoding +// This ensures consistent output and sorted map keys +const canonicalCodec = Data.Codec({ + options: { + mode: "canonical" + } +}) + +// Encode using canonical mode (definite-length, sorted keys) +const canonicalCborHex = canonicalCodec.Encode.cborHex(nestedUnsortedData) +// Output: d87a83d87981d87b80a342beef1345deadbeef01d8798045deadbeef03d87a80860a0502030104 + +// CBOR diagnostic notation (canonical/definite-length): +// 122_0([ +// 121_0([123_0([])]), +// { +// h'beef': 19, ← Keys are now sorted +// h'deadbeef01': 121_0([]), +// h'deadbeef03': 122_0([]), +// }, +// [10, 5, 2, 3, 1, 4], ← Definite-length array +// ]) + +// Verify that decoding works correctly +assert.deepStrictEqual(decodedData, nestedUnsortedData, "Decoded data should match original") diff --git a/docs/codeblocks/pages.index.quickstart.ts b/docs/codeblocks/pages.index.quickstart.ts new file mode 100644 index 00000000..85eba929 --- /dev/null +++ b/docs/codeblocks/pages.index.quickstart.ts @@ -0,0 +1,30 @@ +import assert from "assert" +import { Data } from "@evolution-sdk/evolution" + +// Create a sample data structure with constructor index 0 +// and a Map containing key-value pairs +const sampleData = new Data.Constr({ + index: 0n, + fields: [ + new Map([ + ["deadbeef", 42n], + ["cafe", 100n], + ["beef", 20n] + ]) + ] +}) + +// Encode the data to CBOR hex format +const cborHex = Data.Codec().Encode.cborHex(sampleData) +console.log("CBOR Hex:", cborHex) +// Output: d8799fbf44deadbeef182a42cafe186442beef14ffff + +// CBOR diagnostic notation: 121_0([_ {_ h'deadbeef': 42_0, h'cafe': 100_0, h'beef': 20}]) +// Visualize at: https://cbor.nemo157.com/ + +// Decode the CBOR hex back to data structure +const decodedData = Data.Codec().Decode.cborHex(cborHex) + +// Verify round-trip encoding/decoding works correctly +assert.deepEqual(sampleData, decodedData) +console.log("✅ Round-trip encoding/decoding successful!") diff --git a/docs/next.config.js b/docs/next.config.js index 8b2d1e9e..5af6cd79 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -11,5 +11,5 @@ module.exports = withNextra({ images: { unoptimized: true }, - basePath: "/evolution-sdk", + basePath: process.env.NODE_ENV === 'production' ? "/evolution-sdk" : "", }) diff --git a/docs/package.json b/docs/package.json index 6009766c..93bf76e9 100644 --- a/docs/package.json +++ b/docs/package.json @@ -9,7 +9,8 @@ "start": "next start", "export": "next build", "copy-evolution-docs": "node scripts/copy-evolution-docs.mjs", - "prebuild": "pnpm run copy-evolution-docs" + "validate-codeblocks": "node scripts/validate-and-update-codeblocks.mjs", + "prebuild": "pnpm run copy-evolution-docs && pnpm run validate-codeblocks" }, "dependencies": { "next": "^14.0.0", diff --git a/docs/pages/_meta.json b/docs/pages/_meta.json index b68244b3..29333aef 100644 --- a/docs/pages/_meta.json +++ b/docs/pages/_meta.json @@ -1,6 +1,6 @@ { "index": "Introduction", "getting-started": "Getting Started", - "api": "API Reference", - "guides": "Guides" + "examples": "Examples", + "reference": "API Reference" } diff --git a/docs/pages/examples/Address.mdx b/docs/pages/examples/Address.mdx new file mode 100644 index 00000000..f62c33c6 --- /dev/null +++ b/docs/pages/examples/Address.mdx @@ -0,0 +1,26 @@ +# Address + +Address module provides functionality for working with address types in Cardano. + +## Address Example + +```typescript +import { Address } from "@evolution-sdk/evolution" + +const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530" +const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m" + +// Decode from hex +const address = Address.Codec.Decode.hex(hexAddress) + +// Encode to bech32 +const actualBech32 = Address.Codec.Encode.bech32(address) + +// Verify the conversion is correct +assert(actualBech32 === expectedBech32) + +``` + +## API Reference + +For detailed API documentation, see the generated TypeDoc documentation. diff --git a/docs/pages/examples/Data.mdx b/docs/pages/examples/Data.mdx new file mode 100644 index 00000000..9865909f --- /dev/null +++ b/docs/pages/examples/Data.mdx @@ -0,0 +1,87 @@ +# Data + +Data module provides functionality for working with data types in Cardano. + +## Data Example + +```typescript +import { 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([ + ["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 codec (indefinite-length encoding) +const cborHex = Data.Codec().Encode.cborHex(nestedUnsortedData) +// Output: d87a9fd8799fd87b80ffbf45deadbeef01d8798042beef1345deadbeef03d87a80ff9f0a0502030104ffff + +// CBOR diagnostic notation (indefinite-length): +// 122_0([_ +// 121_0([_ 123_0([])]), +// {_ +// h'deadbeef01': 121_0([]), +// h'beef': 19, +// h'deadbeef03': 122_0([]), +// }, +// [_ 10, 5, 2, 3, 1, 4], +// ]) +// Visualize at: https://cbor.nemo157.com/ + +const decodedData = Data.Codec().Decode.cborHex(cborHex) + +// Create a canonical codec for deterministic encoding +// This ensures consistent output and sorted map keys +const canonicalCodec = Data.Codec({ + options: { + mode: "canonical" + } +}) + +// Encode using canonical mode (definite-length, sorted keys) +const canonicalCborHex = canonicalCodec.Encode.cborHex(nestedUnsortedData) +// Output: d87a83d87981d87b80a342beef1345deadbeef01d8798045deadbeef03d87a80860a0502030104 + +// CBOR diagnostic notation (canonical/definite-length): +// 122_0([ +// 121_0([123_0([])]), +// { +// h'beef': 19, ← Keys are now sorted +// h'deadbeef01': 121_0([]), +// h'deadbeef03': 122_0([]), +// }, +// [10, 5, 2, 3, 1, 4], ← Definite-length array +// ]) + +// Verify that decoding works correctly +assert.deepStrictEqual(decodedData, nestedUnsortedData, "Decoded data should match original") + +``` + +## API Reference + +For detailed API documentation, see the generated TypeDoc documentation. diff --git a/docs/pages/getting-started/examples.mdx b/docs/pages/getting-started/examples.mdx deleted file mode 100644 index c71444f4..00000000 --- a/docs/pages/getting-started/examples.mdx +++ /dev/null @@ -1,245 +0,0 @@ -# Examples - -Comprehensive examples showing how to use Evolution SDK for common Cardano development tasks. - -## Address Validation and Analysis - -### Validating Different Address Types - -```typescript -import * as PaymentAddress from "@evolution-sdk/evolution/PaymentAddress" -import * as RewardAddress from "@evolution-sdk/evolution/RewardAddress" - -// Collection of different address types from mainnet and testnet -const addresses = { - // Mainnet addresses - mainnet: { - base: "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x", - enterprise: "addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer66hrl8", - pointer: "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrzqf96k", - reward: "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw" - }, - // Testnet addresses - testnet: { - base: "addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs68faae", - enterprise: "addr_test1vz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspjrlsz", - pointer: "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrdw5vky", - reward: "stake_test1uqehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gssrtvn" - } -} - -// Validate payment addresses (base, enterprise, pointer) -function validatePaymentAddresses() { - const paymentAddresses = [ - addresses.mainnet.base, - addresses.mainnet.enterprise, - addresses.mainnet.pointer, - addresses.testnet.base, - addresses.testnet.enterprise, - addresses.testnet.pointer - ] - - paymentAddresses.forEach((address) => { - const isValid = PaymentAddress.isPaymentAddress(address) - console.log(`${address.substring(0, 20)}... is payment address: ${isValid}`) - }) -} - -// Validate reward addresses -function validateRewardAddresses() { - const rewardAddresses = [addresses.mainnet.reward, addresses.testnet.reward] - - rewardAddresses.forEach((address) => { - const isValid = RewardAddress.isRewardAddress(address) - console.log(`${address.substring(0, 20)}... is reward address: ${isValid}`) - }) -} - -validatePaymentAddresses() -validateRewardAddresses() -``` - -## Address Format Conversion - -### Working with Hex and Bech32 Formats - -```typescript -import * as Address from "@evolution-sdk/evolution/Address" - -// Sample hex addresses from the Cardano blockchain -const validHexAddresses = [ - "019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e337b62cfff6403a06a3acbc34f8c46003c69fe79a3628cefa9c47251", - "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530" -] - -function demonstrateConversion() { - validHexAddresses.forEach((hex) => { - try { - // Decode from hex - const address = Address.Codec.Decode.hex(hex) - console.log(`Decoded address from hex: ${hex.substring(0, 20)}...`) - - // Encode to bech32 - const bech32 = Address.Codec.Encode.bech32(address) - console.log(`Bech32 format: ${bech32}`) - - // Round-trip back to hex - const backToHex = Address.Codec.Encode.hex(address) - console.log(`Round-trip successful: ${backToHex === hex}`) - console.log("---") - } catch (error) { - console.error(`Failed to process hex: ${hex}`, error) - } - }) -} - -demonstrateConversion() -``` - -### Specific Hex to Bech32 Example - -```typescript -import * as Address from "@evolution-sdk/evolution/Address" - -// Real example from Cardano testnet -const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530" -const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m" - -const address = Address.Codec.Decode.hex(hexAddress) -const actualBech32 = Address.Codec.Encode.bech32(address) - -console.log(`Input hex: ${hexAddress}`) -console.log(`Expected: ${expectedBech32}`) -console.log(`Actual: ${actualBech32}`) -console.log(`Match: ${actualBech32 === expectedBech32}`) -``` - -## Data Type Validation - -### Working with PlutusData Types - -```typescript -import * as Data from "@evolution-sdk/evolution/Data" - -// Create a codec for data operations -const codec = Data.Codec() - -// Valid hex examples (even-length hex strings) -const validHexCases = ["deadbeef", "cafe0123", "abcdef0123456789", "00", "ff"] - -// Invalid hex examples -const invalidHexCases = [ - "not-hex", - "xyz", - "123g", - "deadbeef ", // trailing space - " deadbeef", // leading space - "0x123456" // hex prefix not allowed -] - -function validateHexData() { - console.log("Valid hex data:") - validHexCases.forEach((hex) => { - const isValid = Data.isBytes(hex) - console.log(`"${hex}" -> ${isValid}`) - }) - - console.log("\nInvalid hex data:") - invalidHexCases.forEach((hex) => { - const isValid = Data.isBytes(hex) - console.log(`"${hex}" -> ${isValid}`) - }) -} - -validateHexData() -``` - -## Error Handling Patterns - -### Safe Address Operations with Effect - -```typescript -import { Effect } from "effect" -import * as Address from "@evolution-sdk/evolution/Address" - -// Safe address decoding with error handling -function safeAddressOperations() { - const addresses = [ - "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530", // valid - "invalid-hex-address", // invalid - "019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e337b62cfff6403a06a3acbc34f8c46003c69fe79a3628cefa9c47251" // valid - ] - - addresses.forEach((hex) => { - const program = Effect.gen(function* () { - // Try to decode the address - const address = yield* Effect.try(() => Address.Codec.Decode.hex(hex)) - - // If successful, convert to bech32 - const bech32 = Address.Codec.Encode.bech32(address) - - return { - success: true, - input: hex, - output: bech32 - } - }) - - // Handle the result - Effect.runPromise(program) - .then((result) => { - console.log(`✅ Success: ${result.input.substring(0, 20)}... -> ${result.output}`) - }) - .catch((error) => { - console.log(`❌ Failed: ${hex.substring(0, 20)}... -> ${error.message || "Invalid address"}`) - }) - }) -} - -safeAddressOperations() -``` - -### Batch Address Validation - -```typescript -import * as PaymentAddress from "@evolution-sdk/evolution/PaymentAddress" -import * as RewardAddress from "@evolution-sdk/evolution/RewardAddress" - -// Mixed collection of valid and invalid addresses -const testAddresses = [ - "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x", - "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw", - "not-an-address", - "addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs68faae", - "stake_test1uqehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gssrtvn" -] - -function batchValidation() { - const results = testAddresses.map((address) => { - const isPayment = PaymentAddress.isPaymentAddress(address) - const isReward = RewardAddress.isRewardAddress(address) - - let type = "invalid" - if (isPayment) type = "payment" - else if (isReward) type = "reward" - - return { - address: address.substring(0, 30) + "...", - type, - valid: isPayment || isReward - } - }) - - console.log("Batch validation results:") - console.table(results) -} - -batchValidation() -``` - -## Next Steps - -- Check out the [API Reference](/api) for complete documentation -- Learn about [Address Types](/getting-started/address-types) in detail -- Explore [Advanced Usage](/guides/advanced) patterns -- View the [Test Suite](https://github.com/your-repo/tests) for more examples diff --git a/docs/pages/getting-started/installation.mdx b/docs/pages/getting-started/installation.mdx deleted file mode 100644 index 812b7daa..00000000 --- a/docs/pages/getting-started/installation.mdx +++ /dev/null @@ -1,73 +0,0 @@ -# Installation - -## Prerequisites - -- Node.js 18+ -- TypeScript 5+ -- A package manager (npm, yarn, or pnpm) - -## Package Manager Installation - -### npm - -```bash -npm install @evolution-sdk/evolution -``` - -### yarn - -```bash -yarn add @evolution-sdk/evolution -``` - -### pnpm - -```bash -pnpm add @evolution-sdk/evolution -``` - -## Development Dependencies - -If you're contributing to the SDK or need development dependencies: - -```bash -# Clone the repository -git clone https://github.com/no-witness-labs/evolution-sdk.git -cd evolution-sdk - -# Install dependencies -pnpm install - -# Build the project -pnpm build - -# Run tests -pnpm test -``` - -## TypeScript Configuration - -Evolution SDK requires TypeScript 5+ with strict mode enabled. Add to your `tsconfig.json`: - -```json -{ - "compilerOptions": { - "strict": true, - "target": "ES2022", - "moduleResolution": "node", - "allowSyntheticDefaultImports": true, - "esModuleInterop": true - } -} -``` - -## Verify Installation - -Create a simple test file to verify the installation: - -```typescript -import { Network, Address } from "@evolution-sdk/evolution" - -console.log("Evolution SDK installed successfully!") -console.log("Mainnet ID:", Network.toId("Mainnet")) -``` diff --git a/docs/pages/getting-started/quick-start.mdx b/docs/pages/getting-started/quick-start.mdx deleted file mode 100644 index 540f3446..00000000 --- a/docs/pages/getting-started/quick-start.mdx +++ /dev/null @@ -1,135 +0,0 @@ -# Quick Start - -Get up and running with Evolution SDK in minutes. - -## Installation - -First, install the Evolution SDK in your project: - -```bash -npm install @evolution-sdk/evolution -# or -yarn add @evolution-sdk/evolution -# or -pnpm add @evolution-sdk/evolution -``` - -## Basic Usage - -### Working with Cardano Addresses - -```typescript -import * as Address from "@evolution-sdk/evolution/Address" -import * as PaymentAddress from "@evolution-sdk/evolution/PaymentAddress" -import * as RewardAddress from "@evolution-sdk/evolution/RewardAddress" - -// Sample mainnet addresses from the Cardano blockchain -const mainnetBaseAddress = - "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x" -const mainnetRewardAddress = "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw" - -// Sample testnet addresses -const testnetBaseAddress = - "addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs68faae" -const testnetRewardAddress = "stake_test1uqehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gssrtvn" - -// Validate payment addresses -console.log(PaymentAddress.isPaymentAddress(mainnetBaseAddress)) // true -console.log(PaymentAddress.isPaymentAddress(mainnetRewardAddress)) // false - -// Validate reward addresses -console.log(RewardAddress.isRewardAddress(mainnetRewardAddress)) // true -console.log(RewardAddress.isRewardAddress(mainnetBaseAddress)) // false -``` - -### Address Format Conversion - -```typescript -import * as Address from "@evolution-sdk/evolution/Address" - -// Convert between hex and bech32 formats -const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530" -const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m" - -// Decode from hex -const address = Address.Codec.Decode.hex(hexAddress) - -// Encode to bech32 -const actualBech32 = Address.Codec.Encode.bech32(address) -console.log(actualBech32 === expectedBech32) // true - -// Round-trip conversion -const backToHex = Address.Codec.Encode.hex(address) -console.log(backToHex === hexAddress) // true -``` - -### Working with Different Address Types - -```typescript -// Base address (payment key hash + stake key hash) -const baseAddress = - "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x" - -// Enterprise address (payment key hash only) -const enterpriseAddress = "addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8" - -// Pointer address (payment key hash + pointer) -const pointerAddress = "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrzqf96k" - -// Reward address (stake key hash) -const rewardAddress = "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw" - -// Each address type serves different purposes in the Cardano ecosystem -console.log("All addresses are valid Cardano addresses") -``` - -### Working with Data Types - -```typescript -import * as Data from "@evolution-sdk/evolution/Data" - -// Create a codec for encoding/decoding data -const codec = Data.Codec() - -// Working with hex data -const validHex = "deadbeef" -const isValidBytes = Data.isBytes(validHex) // true - -// Invalid hex examples -const invalidHex = "not-hex" -const isInvalidBytes = Data.isBytes(invalidHex) // false -``` - -## Error Handling - -Evolution SDK uses Effect-TS for robust error handling. Most operations return an `Effect` that can either succeed or fail: - -```typescript -import { Effect } from "effect" -import * as Address from "@evolution-sdk/evolution/Address" - -// Operations that might fail are wrapped in Effect -const program = Effect.gen(function* () { - // This will succeed with a valid address - const validAddress = yield* Effect.try(() => - Address.Codec.Decode.hex("60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530") - ) - - // Convert to bech32 format - const bech32 = Address.Codec.Encode.bech32(validAddress) - - return bech32 -}) - -// Run the program -Effect.runPromise(program) - .then((result) => console.log("Address:", result)) - .catch((error) => console.error("Error:", error)) -``` - -## Next Steps - -- Explore the [API Reference](/api) for detailed documentation -- Learn about [Address Types](/getting-started/address-types) for more details -- Check out more [Examples](/getting-started/examples) for complex use cases -- Read the [Guides](/guides) for specific development scenarios diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index fcd5ab86..f73239d0 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -1,49 +1,42 @@ -# Evolution SDK +# Quickstart -A comprehensive TypeScript SDK for Cardano blockchain development, built with Effect-TS. +Quickstart module provides functionality for working with quickstart types in Cardano. -## Overview +## Quickstart Example -Evolution SDK provides a type-safe, functional programming approach to Cardano blockchain development. Built on top of Effect-TS, it offers: +```typescript +import { Data } from "@evolution-sdk/evolution" + +// Create a sample data structure with constructor index 0 +// and a Map containing key-value pairs +const sampleData = new Data.Constr({ + index: 0n, + fields: [ + new Map([ + ["deadbeef", 42n], + ["cafe", 100n], + ["beef", 20n] + ]) + ] +}) -- **Type Safety**: Full TypeScript support with comprehensive type definitions -- **CBOR Support**: Native CBOR encoding/decoding for Cardano data structures -- **Effect Integration**: Leverages Effect-TS for error handling and composability -- **Address Management**: Support for all Cardano address types -- **Transaction Building**: Tools for constructing and signing transactions -- **Plutus Data**: Native support for Plutus data structures +// Encode the data to CBOR hex format +const cborHex = Data.Codec().Encode.cborHex(sampleData) +console.log("CBOR Hex:", cborHex) +// Output: d8799fbf44deadbeef182a42cafe186442beef14ffff -## Quick Start +// CBOR diagnostic notation: 121_0([_ {_ h'deadbeef': 42_0, h'cafe': 100_0, h'beef': 20}]) +// Visualize at: https://cbor.nemo157.com/ -```bash -npm install @evolution-sdk/evolution -``` +// Decode the CBOR hex back to data structure +const decodedData = Data.Codec().Decode.cborHex(cborHex) -```typescript -import { Address, Network } from "@evolution-sdk/evolution" +// Verify round-trip encoding/decoding works correctly +assert.deepEqual(sampleData, decodedData) +console.log("✅ Round-trip encoding/decoding successful!") -// Create a base address -const baseAddr = Address.Base.make({ - network: Network.Mainnet, - paymentCredential: paymentCred, - stakeCredential: stakeCred -}) ``` -## Features - -- 🏗️ **Address Utilities** - Create and validate all Cardano address types -- 🔐 **Cryptographic Primitives** - Ed25519 signatures, VRF, KES -- 📦 **CBOR Encoding** - RFC 8949 compliant CBOR implementation -- 🏛️ **Governance** - DRep, committee, and voting procedure support -- 🌐 **Network Configuration** - Support for all Cardano networks -- 🪙 **Native Tokens** - Multi-asset and minting utilities - -## Architecture - -Evolution SDK is designed around functional programming principles: +## API Reference -- **Immutable Data Structures** - All data types are immutable by default -- **Composable Operations** - Functions can be easily composed and chained -- **Error Handling** - Leverages Effect-TS for robust error management -- **Type Safety** - Comprehensive TypeScript definitions prevent runtime errors +For detailed API documentation, see the generated TypeDoc documentation. diff --git a/docs/pages/reference/_meta.json b/docs/pages/reference/_meta.json index 70e7367d..6b5a32a9 100644 --- a/docs/pages/reference/_meta.json +++ b/docs/pages/reference/_meta.json @@ -1,4 +1,4 @@ { - "index": "Overview", + "index": "Introduction", "modules": "Modules" } \ No newline at end of file diff --git a/docs/pages/reference/index.mdx b/docs/pages/reference/index.mdx index d77a4411..f07580dd 100644 --- a/docs/pages/reference/index.mdx +++ b/docs/pages/reference/index.mdx @@ -1,4 +1,7 @@ ---- -title: Home -nav_order: 1 ---- +# API Reference + +Complete API reference for the Evolution SDK. + +## Modules + +Browse the complete API documentation for all Evolution SDK modules. diff --git a/docs/pages/reference/modules/modules/Address.mdx b/docs/pages/reference/modules/Address.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Address.mdx rename to docs/pages/reference/modules/Address.mdx diff --git a/docs/pages/reference/modules/modules/AddressDetails.mdx b/docs/pages/reference/modules/AddressDetails.mdx similarity index 100% rename from docs/pages/reference/modules/modules/AddressDetails.mdx rename to docs/pages/reference/modules/AddressDetails.mdx diff --git a/docs/pages/reference/modules/modules/AddressTag.mdx b/docs/pages/reference/modules/AddressTag.mdx similarity index 100% rename from docs/pages/reference/modules/modules/AddressTag.mdx rename to docs/pages/reference/modules/AddressTag.mdx diff --git a/docs/pages/reference/modules/modules/Anchor.mdx b/docs/pages/reference/modules/Anchor.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Anchor.mdx rename to docs/pages/reference/modules/Anchor.mdx diff --git a/docs/pages/reference/modules/modules/AssetName.mdx b/docs/pages/reference/modules/AssetName.mdx similarity index 100% rename from docs/pages/reference/modules/modules/AssetName.mdx rename to docs/pages/reference/modules/AssetName.mdx diff --git a/docs/pages/reference/modules/modules/AuxiliaryDataHash.mdx b/docs/pages/reference/modules/AuxiliaryDataHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/AuxiliaryDataHash.mdx rename to docs/pages/reference/modules/AuxiliaryDataHash.mdx diff --git a/docs/pages/reference/modules/modules/BaseAddress.mdx b/docs/pages/reference/modules/BaseAddress.mdx similarity index 100% rename from docs/pages/reference/modules/modules/BaseAddress.mdx rename to docs/pages/reference/modules/BaseAddress.mdx diff --git a/docs/pages/reference/modules/modules/Bech32.mdx b/docs/pages/reference/modules/Bech32.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bech32.mdx rename to docs/pages/reference/modules/Bech32.mdx diff --git a/docs/pages/reference/modules/modules/BigInt.mdx b/docs/pages/reference/modules/BigInt.mdx similarity index 100% rename from docs/pages/reference/modules/modules/BigInt.mdx rename to docs/pages/reference/modules/BigInt.mdx diff --git a/docs/pages/reference/modules/modules/Block.mdx b/docs/pages/reference/modules/Block.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Block.mdx rename to docs/pages/reference/modules/Block.mdx diff --git a/docs/pages/reference/modules/modules/BlockBodyHash.mdx b/docs/pages/reference/modules/BlockBodyHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/BlockBodyHash.mdx rename to docs/pages/reference/modules/BlockBodyHash.mdx diff --git a/docs/pages/reference/modules/modules/BlockHeaderHash.mdx b/docs/pages/reference/modules/BlockHeaderHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/BlockHeaderHash.mdx rename to docs/pages/reference/modules/BlockHeaderHash.mdx diff --git a/docs/pages/reference/modules/modules/BoundedBytes.mdx b/docs/pages/reference/modules/BoundedBytes.mdx similarity index 100% rename from docs/pages/reference/modules/modules/BoundedBytes.mdx rename to docs/pages/reference/modules/BoundedBytes.mdx diff --git a/docs/pages/reference/modules/modules/ByronAddress.mdx b/docs/pages/reference/modules/ByronAddress.mdx similarity index 100% rename from docs/pages/reference/modules/modules/ByronAddress.mdx rename to docs/pages/reference/modules/ByronAddress.mdx diff --git a/docs/pages/reference/modules/modules/Bytes.mdx b/docs/pages/reference/modules/Bytes.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes.mdx rename to docs/pages/reference/modules/Bytes.mdx diff --git a/docs/pages/reference/modules/modules/Bytes16.mdx b/docs/pages/reference/modules/Bytes16.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes16.mdx rename to docs/pages/reference/modules/Bytes16.mdx diff --git a/docs/pages/reference/modules/modules/Bytes29.mdx b/docs/pages/reference/modules/Bytes29.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes29.mdx rename to docs/pages/reference/modules/Bytes29.mdx diff --git a/docs/pages/reference/modules/modules/Bytes32.mdx b/docs/pages/reference/modules/Bytes32.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes32.mdx rename to docs/pages/reference/modules/Bytes32.mdx diff --git a/docs/pages/reference/modules/modules/Bytes4.mdx b/docs/pages/reference/modules/Bytes4.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes4.mdx rename to docs/pages/reference/modules/Bytes4.mdx diff --git a/docs/pages/reference/modules/modules/Bytes448.mdx b/docs/pages/reference/modules/Bytes448.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes448.mdx rename to docs/pages/reference/modules/Bytes448.mdx diff --git a/docs/pages/reference/modules/modules/Bytes57.mdx b/docs/pages/reference/modules/Bytes57.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes57.mdx rename to docs/pages/reference/modules/Bytes57.mdx diff --git a/docs/pages/reference/modules/modules/Bytes64.mdx b/docs/pages/reference/modules/Bytes64.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes64.mdx rename to docs/pages/reference/modules/Bytes64.mdx diff --git a/docs/pages/reference/modules/modules/Bytes80.mdx b/docs/pages/reference/modules/Bytes80.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Bytes80.mdx rename to docs/pages/reference/modules/Bytes80.mdx diff --git a/docs/pages/reference/modules/modules/CBOR.mdx b/docs/pages/reference/modules/CBOR.mdx similarity index 100% rename from docs/pages/reference/modules/modules/CBOR.mdx rename to docs/pages/reference/modules/CBOR.mdx diff --git a/docs/pages/reference/modules/modules/Certificate.mdx b/docs/pages/reference/modules/Certificate.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Certificate.mdx rename to docs/pages/reference/modules/Certificate.mdx diff --git a/docs/pages/reference/modules/modules/Codec.mdx b/docs/pages/reference/modules/Codec.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Codec.mdx rename to docs/pages/reference/modules/Codec.mdx diff --git a/docs/pages/reference/modules/modules/Coin.mdx b/docs/pages/reference/modules/Coin.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Coin.mdx rename to docs/pages/reference/modules/Coin.mdx diff --git a/docs/pages/reference/modules/modules/Combinator.mdx b/docs/pages/reference/modules/Combinator.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Combinator.mdx rename to docs/pages/reference/modules/Combinator.mdx diff --git a/docs/pages/reference/modules/modules/CommitteeColdCredential.mdx b/docs/pages/reference/modules/CommitteeColdCredential.mdx similarity index 100% rename from docs/pages/reference/modules/modules/CommitteeColdCredential.mdx rename to docs/pages/reference/modules/CommitteeColdCredential.mdx diff --git a/docs/pages/reference/modules/modules/CommitteeHotCredential.mdx b/docs/pages/reference/modules/CommitteeHotCredential.mdx similarity index 100% rename from docs/pages/reference/modules/modules/CommitteeHotCredential.mdx rename to docs/pages/reference/modules/CommitteeHotCredential.mdx diff --git a/docs/pages/reference/modules/modules/Credential.mdx b/docs/pages/reference/modules/Credential.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Credential.mdx rename to docs/pages/reference/modules/Credential.mdx diff --git a/docs/pages/reference/modules/modules/DRep.mdx b/docs/pages/reference/modules/DRep.mdx similarity index 100% rename from docs/pages/reference/modules/modules/DRep.mdx rename to docs/pages/reference/modules/DRep.mdx diff --git a/docs/pages/reference/modules/modules/DRepCredential.mdx b/docs/pages/reference/modules/DRepCredential.mdx similarity index 100% rename from docs/pages/reference/modules/modules/DRepCredential.mdx rename to docs/pages/reference/modules/DRepCredential.mdx diff --git a/docs/pages/reference/modules/modules/Data.mdx b/docs/pages/reference/modules/Data.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Data.mdx rename to docs/pages/reference/modules/Data.mdx diff --git a/docs/pages/reference/modules/modules/DataJson.mdx b/docs/pages/reference/modules/DataJson.mdx similarity index 100% rename from docs/pages/reference/modules/modules/DataJson.mdx rename to docs/pages/reference/modules/DataJson.mdx diff --git a/docs/pages/reference/modules/modules/DatumOption.mdx b/docs/pages/reference/modules/DatumOption.mdx similarity index 100% rename from docs/pages/reference/modules/modules/DatumOption.mdx rename to docs/pages/reference/modules/DatumOption.mdx diff --git a/docs/pages/reference/modules/modules/Devnet/Devnet.mdx b/docs/pages/reference/modules/Devnet/Devnet.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Devnet/Devnet.mdx rename to docs/pages/reference/modules/Devnet/Devnet.mdx diff --git a/docs/pages/reference/modules/modules/Devnet/DevnetDefault.mdx b/docs/pages/reference/modules/Devnet/DevnetDefault.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Devnet/DevnetDefault.mdx rename to docs/pages/reference/modules/Devnet/DevnetDefault.mdx diff --git a/docs/pages/reference/modules/modules/DnsName.mdx b/docs/pages/reference/modules/DnsName.mdx similarity index 100% rename from docs/pages/reference/modules/modules/DnsName.mdx rename to docs/pages/reference/modules/DnsName.mdx diff --git a/docs/pages/reference/modules/modules/Ed25519Signature.mdx b/docs/pages/reference/modules/Ed25519Signature.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Ed25519Signature.mdx rename to docs/pages/reference/modules/Ed25519Signature.mdx diff --git a/docs/pages/reference/modules/modules/EnterpriseAddress.mdx b/docs/pages/reference/modules/EnterpriseAddress.mdx similarity index 100% rename from docs/pages/reference/modules/modules/EnterpriseAddress.mdx rename to docs/pages/reference/modules/EnterpriseAddress.mdx diff --git a/docs/pages/reference/modules/modules/EpochNo.mdx b/docs/pages/reference/modules/EpochNo.mdx similarity index 100% rename from docs/pages/reference/modules/modules/EpochNo.mdx rename to docs/pages/reference/modules/EpochNo.mdx diff --git a/docs/pages/reference/modules/modules/FormatError.mdx b/docs/pages/reference/modules/FormatError.mdx similarity index 100% rename from docs/pages/reference/modules/modules/FormatError.mdx rename to docs/pages/reference/modules/FormatError.mdx diff --git a/docs/pages/reference/modules/modules/Hash28.mdx b/docs/pages/reference/modules/Hash28.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Hash28.mdx rename to docs/pages/reference/modules/Hash28.mdx diff --git a/docs/pages/reference/modules/modules/Header.mdx b/docs/pages/reference/modules/Header.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Header.mdx rename to docs/pages/reference/modules/Header.mdx diff --git a/docs/pages/reference/modules/modules/HeaderBody.mdx b/docs/pages/reference/modules/HeaderBody.mdx similarity index 100% rename from docs/pages/reference/modules/modules/HeaderBody.mdx rename to docs/pages/reference/modules/HeaderBody.mdx diff --git a/docs/pages/reference/modules/modules/IPv4.mdx b/docs/pages/reference/modules/IPv4.mdx similarity index 100% rename from docs/pages/reference/modules/modules/IPv4.mdx rename to docs/pages/reference/modules/IPv4.mdx diff --git a/docs/pages/reference/modules/modules/IPv6.mdx b/docs/pages/reference/modules/IPv6.mdx similarity index 100% rename from docs/pages/reference/modules/modules/IPv6.mdx rename to docs/pages/reference/modules/IPv6.mdx diff --git a/docs/pages/reference/modules/modules/KESVkey.mdx b/docs/pages/reference/modules/KESVkey.mdx similarity index 100% rename from docs/pages/reference/modules/modules/KESVkey.mdx rename to docs/pages/reference/modules/KESVkey.mdx diff --git a/docs/pages/reference/modules/modules/KesSignature.mdx b/docs/pages/reference/modules/KesSignature.mdx similarity index 100% rename from docs/pages/reference/modules/modules/KesSignature.mdx rename to docs/pages/reference/modules/KesSignature.mdx diff --git a/docs/pages/reference/modules/modules/KeyHash.mdx b/docs/pages/reference/modules/KeyHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/KeyHash.mdx rename to docs/pages/reference/modules/KeyHash.mdx diff --git a/docs/pages/reference/modules/modules/Mint.mdx b/docs/pages/reference/modules/Mint.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Mint.mdx rename to docs/pages/reference/modules/Mint.mdx diff --git a/docs/pages/reference/modules/modules/MultiAsset.mdx b/docs/pages/reference/modules/MultiAsset.mdx similarity index 100% rename from docs/pages/reference/modules/modules/MultiAsset.mdx rename to docs/pages/reference/modules/MultiAsset.mdx diff --git a/docs/pages/reference/modules/modules/MultiHostName.mdx b/docs/pages/reference/modules/MultiHostName.mdx similarity index 100% rename from docs/pages/reference/modules/modules/MultiHostName.mdx rename to docs/pages/reference/modules/MultiHostName.mdx diff --git a/docs/pages/reference/modules/modules/NativeScriptJSON.mdx b/docs/pages/reference/modules/NativeScriptJSON.mdx similarity index 100% rename from docs/pages/reference/modules/modules/NativeScriptJSON.mdx rename to docs/pages/reference/modules/NativeScriptJSON.mdx diff --git a/docs/pages/reference/modules/modules/NativeScripts.mdx b/docs/pages/reference/modules/NativeScripts.mdx similarity index 100% rename from docs/pages/reference/modules/modules/NativeScripts.mdx rename to docs/pages/reference/modules/NativeScripts.mdx diff --git a/docs/pages/reference/modules/modules/Natural.mdx b/docs/pages/reference/modules/Natural.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Natural.mdx rename to docs/pages/reference/modules/Natural.mdx diff --git a/docs/pages/reference/modules/modules/Network.mdx b/docs/pages/reference/modules/Network.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Network.mdx rename to docs/pages/reference/modules/Network.mdx diff --git a/docs/pages/reference/modules/modules/NetworkId.mdx b/docs/pages/reference/modules/NetworkId.mdx similarity index 100% rename from docs/pages/reference/modules/modules/NetworkId.mdx rename to docs/pages/reference/modules/NetworkId.mdx diff --git a/docs/pages/reference/modules/modules/NonZeroInt64.mdx b/docs/pages/reference/modules/NonZeroInt64.mdx similarity index 100% rename from docs/pages/reference/modules/modules/NonZeroInt64.mdx rename to docs/pages/reference/modules/NonZeroInt64.mdx diff --git a/docs/pages/reference/modules/modules/Numeric.mdx b/docs/pages/reference/modules/Numeric.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Numeric.mdx rename to docs/pages/reference/modules/Numeric.mdx diff --git a/docs/pages/reference/modules/modules/OperationalCert.mdx b/docs/pages/reference/modules/OperationalCert.mdx similarity index 100% rename from docs/pages/reference/modules/modules/OperationalCert.mdx rename to docs/pages/reference/modules/OperationalCert.mdx diff --git a/docs/pages/reference/modules/modules/PaymentAddress.mdx b/docs/pages/reference/modules/PaymentAddress.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PaymentAddress.mdx rename to docs/pages/reference/modules/PaymentAddress.mdx diff --git a/docs/pages/reference/modules/modules/Pointer.mdx b/docs/pages/reference/modules/Pointer.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Pointer.mdx rename to docs/pages/reference/modules/Pointer.mdx diff --git a/docs/pages/reference/modules/modules/PointerAddress.mdx b/docs/pages/reference/modules/PointerAddress.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PointerAddress.mdx rename to docs/pages/reference/modules/PointerAddress.mdx diff --git a/docs/pages/reference/modules/modules/PolicyId.mdx b/docs/pages/reference/modules/PolicyId.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PolicyId.mdx rename to docs/pages/reference/modules/PolicyId.mdx diff --git a/docs/pages/reference/modules/modules/PoolKeyHash.mdx b/docs/pages/reference/modules/PoolKeyHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PoolKeyHash.mdx rename to docs/pages/reference/modules/PoolKeyHash.mdx diff --git a/docs/pages/reference/modules/modules/PoolMetadata.mdx b/docs/pages/reference/modules/PoolMetadata.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PoolMetadata.mdx rename to docs/pages/reference/modules/PoolMetadata.mdx diff --git a/docs/pages/reference/modules/modules/PoolParams.mdx b/docs/pages/reference/modules/PoolParams.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PoolParams.mdx rename to docs/pages/reference/modules/PoolParams.mdx diff --git a/docs/pages/reference/modules/modules/Port.mdx b/docs/pages/reference/modules/Port.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Port.mdx rename to docs/pages/reference/modules/Port.mdx diff --git a/docs/pages/reference/modules/modules/PositiveCoin.mdx b/docs/pages/reference/modules/PositiveCoin.mdx similarity index 100% rename from docs/pages/reference/modules/modules/PositiveCoin.mdx rename to docs/pages/reference/modules/PositiveCoin.mdx diff --git a/docs/pages/reference/modules/modules/ProposalProcedures.mdx b/docs/pages/reference/modules/ProposalProcedures.mdx similarity index 100% rename from docs/pages/reference/modules/modules/ProposalProcedures.mdx rename to docs/pages/reference/modules/ProposalProcedures.mdx diff --git a/docs/pages/reference/modules/modules/ProtocolVersion.mdx b/docs/pages/reference/modules/ProtocolVersion.mdx similarity index 100% rename from docs/pages/reference/modules/modules/ProtocolVersion.mdx rename to docs/pages/reference/modules/ProtocolVersion.mdx diff --git a/docs/pages/reference/modules/modules/Relay.mdx b/docs/pages/reference/modules/Relay.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Relay.mdx rename to docs/pages/reference/modules/Relay.mdx diff --git a/docs/pages/reference/modules/modules/RewardAccount.mdx b/docs/pages/reference/modules/RewardAccount.mdx similarity index 100% rename from docs/pages/reference/modules/modules/RewardAccount.mdx rename to docs/pages/reference/modules/RewardAccount.mdx diff --git a/docs/pages/reference/modules/modules/RewardAddress.mdx b/docs/pages/reference/modules/RewardAddress.mdx similarity index 100% rename from docs/pages/reference/modules/modules/RewardAddress.mdx rename to docs/pages/reference/modules/RewardAddress.mdx diff --git a/docs/pages/reference/modules/modules/ScriptDataHash.mdx b/docs/pages/reference/modules/ScriptDataHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/ScriptDataHash.mdx rename to docs/pages/reference/modules/ScriptDataHash.mdx diff --git a/docs/pages/reference/modules/modules/ScriptHash.mdx b/docs/pages/reference/modules/ScriptHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/ScriptHash.mdx rename to docs/pages/reference/modules/ScriptHash.mdx diff --git a/docs/pages/reference/modules/modules/ScriptRef.mdx b/docs/pages/reference/modules/ScriptRef.mdx similarity index 100% rename from docs/pages/reference/modules/modules/ScriptRef.mdx rename to docs/pages/reference/modules/ScriptRef.mdx diff --git a/docs/pages/reference/modules/modules/SingleHostAddr.mdx b/docs/pages/reference/modules/SingleHostAddr.mdx similarity index 100% rename from docs/pages/reference/modules/modules/SingleHostAddr.mdx rename to docs/pages/reference/modules/SingleHostAddr.mdx diff --git a/docs/pages/reference/modules/modules/SingleHostName.mdx b/docs/pages/reference/modules/SingleHostName.mdx similarity index 100% rename from docs/pages/reference/modules/modules/SingleHostName.mdx rename to docs/pages/reference/modules/SingleHostName.mdx diff --git a/docs/pages/reference/modules/modules/StakeReference.mdx b/docs/pages/reference/modules/StakeReference.mdx similarity index 100% rename from docs/pages/reference/modules/modules/StakeReference.mdx rename to docs/pages/reference/modules/StakeReference.mdx diff --git a/docs/pages/reference/modules/modules/TSchema.mdx b/docs/pages/reference/modules/TSchema.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TSchema.mdx rename to docs/pages/reference/modules/TSchema.mdx diff --git a/docs/pages/reference/modules/modules/Text.mdx b/docs/pages/reference/modules/Text.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Text.mdx rename to docs/pages/reference/modules/Text.mdx diff --git a/docs/pages/reference/modules/modules/Text128.mdx b/docs/pages/reference/modules/Text128.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Text128.mdx rename to docs/pages/reference/modules/Text128.mdx diff --git a/docs/pages/reference/modules/modules/Transaction.mdx b/docs/pages/reference/modules/Transaction.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Transaction.mdx rename to docs/pages/reference/modules/Transaction.mdx diff --git a/docs/pages/reference/modules/modules/TransactionBody.mdx b/docs/pages/reference/modules/TransactionBody.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TransactionBody.mdx rename to docs/pages/reference/modules/TransactionBody.mdx diff --git a/docs/pages/reference/modules/modules/TransactionHash.mdx b/docs/pages/reference/modules/TransactionHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TransactionHash.mdx rename to docs/pages/reference/modules/TransactionHash.mdx diff --git a/docs/pages/reference/modules/modules/TransactionIndex.mdx b/docs/pages/reference/modules/TransactionIndex.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TransactionIndex.mdx rename to docs/pages/reference/modules/TransactionIndex.mdx diff --git a/docs/pages/reference/modules/modules/TransactionInput.mdx b/docs/pages/reference/modules/TransactionInput.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TransactionInput.mdx rename to docs/pages/reference/modules/TransactionInput.mdx diff --git a/docs/pages/reference/modules/modules/TransactionMetadatumLabels.mdx b/docs/pages/reference/modules/TransactionMetadatumLabels.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TransactionMetadatumLabels.mdx rename to docs/pages/reference/modules/TransactionMetadatumLabels.mdx diff --git a/docs/pages/reference/modules/modules/TransactionOutput.mdx b/docs/pages/reference/modules/TransactionOutput.mdx similarity index 100% rename from docs/pages/reference/modules/modules/TransactionOutput.mdx rename to docs/pages/reference/modules/TransactionOutput.mdx diff --git a/docs/pages/reference/modules/modules/UnitInterval.mdx b/docs/pages/reference/modules/UnitInterval.mdx similarity index 100% rename from docs/pages/reference/modules/modules/UnitInterval.mdx rename to docs/pages/reference/modules/UnitInterval.mdx diff --git a/docs/pages/reference/modules/modules/Url.mdx b/docs/pages/reference/modules/Url.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Url.mdx rename to docs/pages/reference/modules/Url.mdx diff --git a/docs/pages/reference/modules/modules/VKey.mdx b/docs/pages/reference/modules/VKey.mdx similarity index 100% rename from docs/pages/reference/modules/modules/VKey.mdx rename to docs/pages/reference/modules/VKey.mdx diff --git a/docs/pages/reference/modules/modules/Value.mdx b/docs/pages/reference/modules/Value.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Value.mdx rename to docs/pages/reference/modules/Value.mdx diff --git a/docs/pages/reference/modules/modules/VotingProcedures.mdx b/docs/pages/reference/modules/VotingProcedures.mdx similarity index 100% rename from docs/pages/reference/modules/modules/VotingProcedures.mdx rename to docs/pages/reference/modules/VotingProcedures.mdx diff --git a/docs/pages/reference/modules/modules/VrfCert.mdx b/docs/pages/reference/modules/VrfCert.mdx similarity index 100% rename from docs/pages/reference/modules/modules/VrfCert.mdx rename to docs/pages/reference/modules/VrfCert.mdx diff --git a/docs/pages/reference/modules/modules/VrfKeyHash.mdx b/docs/pages/reference/modules/VrfKeyHash.mdx similarity index 100% rename from docs/pages/reference/modules/modules/VrfKeyHash.mdx rename to docs/pages/reference/modules/VrfKeyHash.mdx diff --git a/docs/pages/reference/modules/modules/VrfVkey.mdx b/docs/pages/reference/modules/VrfVkey.mdx similarity index 100% rename from docs/pages/reference/modules/modules/VrfVkey.mdx rename to docs/pages/reference/modules/VrfVkey.mdx diff --git a/docs/pages/reference/modules/modules/Withdrawals.mdx b/docs/pages/reference/modules/Withdrawals.mdx similarity index 100% rename from docs/pages/reference/modules/modules/Withdrawals.mdx rename to docs/pages/reference/modules/Withdrawals.mdx diff --git a/docs/pages/reference/modules/_config.yml b/docs/pages/reference/modules/_config.yml deleted file mode 100644 index f3cae7a8..00000000 --- a/docs/pages/reference/modules/_config.yml +++ /dev/null @@ -1,9 +0,0 @@ -remote_theme: mikearnaldi/docgen-template - -# Enable or disable the site search -search_enabled: true - -# Aux links for the upper right navigation -aux_links: -"@evolution-sdk/evolution on GitHub": - - "https://github.com/no-witness-labs/evolution-sdk" diff --git a/docs/pages/reference/modules/_meta.json b/docs/pages/reference/modules/_meta.json index 9e26dfee..7c37e93a 100644 --- a/docs/pages/reference/modules/_meta.json +++ b/docs/pages/reference/modules/_meta.json @@ -1 +1,101 @@ -{} \ No newline at end of file +{ + "Address": "Address", + "AddressDetails": "AddressDetails", + "AddressTag": "AddressTag", + "Anchor": "Anchor", + "AssetName": "AssetName", + "AuxiliaryDataHash": "AuxiliaryDataHash", + "BaseAddress": "BaseAddress", + "Bech32": "Bech32", + "BigInt": "BigInt", + "Block": "Block", + "BlockBodyHash": "BlockBodyHash", + "BlockHeaderHash": "BlockHeaderHash", + "BoundedBytes": "BoundedBytes", + "ByronAddress": "ByronAddress", + "Bytes": "Bytes", + "Bytes16": "Bytes16", + "Bytes29": "Bytes29", + "Bytes32": "Bytes32", + "Bytes4": "Bytes4", + "Bytes448": "Bytes448", + "Bytes57": "Bytes57", + "Bytes64": "Bytes64", + "Bytes80": "Bytes80", + "CBOR": "CBOR", + "Certificate": "Certificate", + "Codec": "Codec", + "Coin": "Coin", + "Combinator": "Combinator", + "CommitteeColdCredential": "CommitteeColdCredential", + "CommitteeHotCredential": "CommitteeHotCredential", + "Credential": "Credential", + "DRep": "DRep", + "DRepCredential": "DRepCredential", + "Data": "Data", + "DataJson": "DataJson", + "DatumOption": "DatumOption", + "DnsName": "DnsName", + "Ed25519Signature": "Ed25519Signature", + "EnterpriseAddress": "EnterpriseAddress", + "EpochNo": "EpochNo", + "FormatError": "FormatError", + "Hash28": "Hash28", + "Header": "Header", + "HeaderBody": "HeaderBody", + "IPv4": "IPv4", + "IPv6": "IPv6", + "KESVkey": "KESVkey", + "KesSignature": "KesSignature", + "KeyHash": "KeyHash", + "Mint": "Mint", + "MultiAsset": "MultiAsset", + "MultiHostName": "MultiHostName", + "NativeScriptJSON": "NativeScriptJSON", + "NativeScripts": "NativeScripts", + "Natural": "Natural", + "Network": "Network", + "NetworkId": "NetworkId", + "NonZeroInt64": "NonZeroInt64", + "Numeric": "Numeric", + "OperationalCert": "OperationalCert", + "PaymentAddress": "PaymentAddress", + "Pointer": "Pointer", + "PointerAddress": "PointerAddress", + "PolicyId": "PolicyId", + "PoolKeyHash": "PoolKeyHash", + "PoolMetadata": "PoolMetadata", + "PoolParams": "PoolParams", + "Port": "Port", + "PositiveCoin": "PositiveCoin", + "ProposalProcedures": "ProposalProcedures", + "ProtocolVersion": "ProtocolVersion", + "Relay": "Relay", + "RewardAccount": "RewardAccount", + "RewardAddress": "RewardAddress", + "ScriptDataHash": "ScriptDataHash", + "ScriptHash": "ScriptHash", + "ScriptRef": "ScriptRef", + "SingleHostAddr": "SingleHostAddr", + "SingleHostName": "SingleHostName", + "StakeReference": "StakeReference", + "TSchema": "TSchema", + "Text": "Text", + "Text128": "Text128", + "Transaction": "Transaction", + "TransactionBody": "TransactionBody", + "TransactionHash": "TransactionHash", + "TransactionIndex": "TransactionIndex", + "TransactionInput": "TransactionInput", + "TransactionMetadatumLabels": "TransactionMetadatumLabels", + "TransactionOutput": "TransactionOutput", + "UnitInterval": "UnitInterval", + "Url": "Url", + "VKey": "VKey", + "Value": "Value", + "VotingProcedures": "VotingProcedures", + "VrfCert": "VrfCert", + "VrfKeyHash": "VrfKeyHash", + "VrfVkey": "VrfVkey", + "Withdrawals": "Withdrawals" +} \ No newline at end of file diff --git a/docs/pages/reference/modules/index.mdx b/docs/pages/reference/modules/index.mdx index d77a4411..d20a6b7c 100644 --- a/docs/pages/reference/modules/index.mdx +++ b/docs/pages/reference/modules/index.mdx @@ -1,4 +1,6 @@ --- -title: Home -nav_order: 1 +title: Modules +has_children: true +permalink: /docs/modules +nav_order: 2 --- diff --git a/docs/pages/reference/modules/modules/index.mdx b/docs/pages/reference/modules/modules/index.mdx deleted file mode 100644 index d20a6b7c..00000000 --- a/docs/pages/reference/modules/modules/index.mdx +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: Modules -has_children: true -permalink: /docs/modules -nav_order: 2 ---- diff --git a/docs/pages/reference/test.mdx b/docs/pages/reference/test.mdx deleted file mode 100644 index 30f50e67..00000000 --- a/docs/pages/reference/test.mdx +++ /dev/null @@ -1,11 +0,0 @@ -# Test API Module - -This is a test to see if the API navigation is working. - -## Test Function - -```typescript -function test() { - return "Hello from the API docs!"; -} -``` diff --git a/docs/scripts/copy-evolution-docs.mjs b/docs/scripts/copy-evolution-docs.mjs index 1fdd6a87..3cf20769 100644 --- a/docs/scripts/copy-evolution-docs.mjs +++ b/docs/scripts/copy-evolution-docs.mjs @@ -3,8 +3,9 @@ import * as fs from 'fs/promises'; import * as path from 'path'; -const sourceDir = path.resolve(process.cwd(), '../packages/evolution/docs'); +const sourceDir = path.resolve(process.cwd(), '../packages/evolution/docs/modules'); const targetDir = path.resolve(process.cwd(), './pages/reference/modules'); +const referenceDir = path.resolve(process.cwd(), './pages/reference'); async function ensureDirectoryExists(dir) { try { @@ -94,24 +95,64 @@ async function createMetaJson(directory) { } } +async function createReferenceIndex() { + try { + // Create reference index.mdx + const indexContent = `# API Reference + +Complete API reference for the Evolution SDK. + +## Modules + +Browse the complete API documentation for all Evolution SDK modules. +`; + + await fs.writeFile( + path.join(referenceDir, 'index.mdx'), + indexContent + ); + + // Create reference _meta.json + const metaContent = { + "index": "Introduction", + "modules": "Modules" + }; + + await fs.writeFile( + path.join(referenceDir, '_meta.json'), + JSON.stringify(metaContent, null, 2) + ); + + console.log(`Created reference index and meta files`); + } catch (error) { + console.error(`Error creating reference index: ${error.message}`); + } +} + async function main() { try { console.log('Starting copy of evolution documentation...'); - // Remove existing target directory + // Remove existing reference directory to clean up any nested structure try { - await fs.rm(targetDir, { recursive: true, force: true }); - console.log(`Removing existing directory: ${targetDir}`); + await fs.rm(referenceDir, { recursive: true, force: true }); + console.log(`Cleaning up existing reference directory: ${referenceDir}`); } catch (error) { // Directory might not exist, that's ok } + // Ensure the reference directory structure exists + await ensureDirectoryExists(path.dirname(targetDir)); + // Copy source to target await copyDirectory(sourceDir, targetDir); // Create _meta.json for navigation await createMetaJson(targetDir); + // Create reference index and meta files + await createReferenceIndex(); + console.log('Documentation copy completed successfully!'); } catch (error) { console.error('Error copying documentation:', error.message); diff --git a/docs/scripts/validate-and-update-codeblocks.mjs b/docs/scripts/validate-and-update-codeblocks.mjs new file mode 100644 index 00000000..dd8b0119 --- /dev/null +++ b/docs/scripts/validate-and-update-codeblocks.mjs @@ -0,0 +1,339 @@ +#!/usr/bin/env node + +import { execSync } from 'child_process' +import { readFileSync, writeFileSync, readdirSync, unlinkSync } from 'fs' +import { join, dirname, relative } from 'path' +import { fileURLToPath } from 'url' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) + +const DOCS_DIR = join(__dirname, '..') +const CODEBLOCKS_DIR = join(DOCS_DIR, 'codeblocks') + +/** + * Derive the target documentation file path from codeblock filename + * Examples: + * - pages.index.quickstart.ts -> pages/index.mdx + * - pages.reference.modules.Address.ts -> pages/reference/modules/Address.mdx + * - pages.getting-started.installation.ts -> pages/getting-started/installation.mdx + * - pages.api.playground.example.ts -> pages/api/playground/example.mdx + */ +function getTargetFileFromCodeblock(codeblockFilename) { + const nameWithoutExt = codeblockFilename.replace('.ts', '') + const parts = nameWithoutExt.split('.') + + if (parts.length < 2) { + throw new Error(`Invalid codeblock filename format: ${codeblockFilename}. Expected format: pages.section.subsection.title.ts`) + } + + // First part should always be 'pages' + if (parts[0] !== 'pages') { + throw new Error(`Codeblock filename must start with 'pages.': ${codeblockFilename}`) + } + + // Remove 'pages' prefix and build path + const pathParts = parts.slice(1) + + // Special case: if it's pages.index.something, target pages/index.mdx + if (pathParts[0] === 'index') { + return 'pages/index.mdx' + } + + // Last part is the title/filename, everything else is directory structure + const directories = pathParts.slice(0, -1) + const filename = pathParts[pathParts.length - 1] + + // Build the path: pages/dir1/dir2/filename.mdx + let targetPath = 'pages' + if (directories.length > 0) { + targetPath += '/' + directories.join('/') + } + targetPath += `/${filename}.mdx` + + return targetPath +} + +/** + * Extract the main function name from codeblock file + */ +function extractMainFunctionName(codeblockPath) { + const content = readFileSync(codeblockPath, 'utf-8') + + // Look for exported functions + const exportMatch = content.match(/export\s*{\s*([^}]+)\s*}/) + if (exportMatch) { + const exports = exportMatch[1].split(',').map(e => e.trim()) + // Return the first exported function + return exports[0] + } + + // Fallback: look for any function declaration + const functionMatch = content.match(/function\s+(\w+)/) + if (functionMatch) { + return functionMatch[1] + } + + return 'example' +} + +/** + * Generate section title from codeblock filename + */ +function getSectionTitle(codeblockFilename) { + const nameWithoutExt = codeblockFilename.replace('.ts', '') + const parts = nameWithoutExt.split('.') + + if (parts.length >= 2) { + // Use the last part (filename) as the section title + const title = parts[parts.length - 1] + // Convert camelCase to Title Case + return title.charAt(0).toUpperCase() + title.slice(1).replace(/([A-Z])/g, ' $1').trim() + ' Example' + } + + return 'Usage Examples' +} + +/** + * Run a codeblock and return whether it passed + */ +function runCodeblock(codeblockPath) { + try { + console.log(`🧪 Testing ${codeblockPath}...`) + execSync(`npx tsx ${codeblockPath}`, { + cwd: join(__dirname, '../..'), // Root of monorepo + stdio: 'pipe', + timeout: 30000 // 30 second timeout + }) + console.log(`✅ ${codeblockPath} passed`) + return true + } catch (error) { + console.error(`❌ ${codeblockPath} failed:`) + console.error(error.stdout?.toString() || error.message) + return false + } +} + +/** + * Extract the TypeScript code from a codeblock file + */ +function extractCodeFromCodeblock(codeblockPath) { + const content = readFileSync(codeblockPath, 'utf-8') + + // Remove the comment header and imports, keep only the implementation + const lines = content.split('\n') + const importEndIndex = lines.findIndex(line => line.trim() === '' && lines[lines.indexOf(line) - 1].startsWith('import')) + + if (importEndIndex === -1) { + // Fallback: find the first function + const functionStartIndex = lines.findIndex(line => line.includes('function ')) + if (functionStartIndex === -1) return content + + // Get everything from the first function to the export + const exportIndex = lines.findIndex(line => line.startsWith('export ')) + return lines.slice(functionStartIndex, exportIndex).join('\n').trim() + } + + // Get everything after imports, before exports + const exportIndex = lines.findIndex(line => line.startsWith('export ')) + return lines.slice(importEndIndex + 1, exportIndex).join('\n').trim() +} + +/** + * Get the imports from a codeblock file + */ +function extractImportsFromCodeblock(codeblockPath) { + const content = readFileSync(codeblockPath, 'utf-8') + const lines = content.split('\n') + + const imports = lines + .filter(line => line.startsWith('import ')) + .filter(line => !line.includes('import assert')) // Remove assert import for docs + .join('\n') + + return imports +} + +/** + * Clean and rebuild a documentation file with fresh content + */ +function cleanAndUpdateDocumentationFile(codeblockFilename, codeblockPath) { + const targetFile = getTargetFileFromCodeblock(codeblockFilename) + const sectionTitle = getSectionTitle(codeblockFilename) + const functionName = extractMainFunctionName(codeblockPath) + const targetPath = join(DOCS_DIR, targetFile) + + try { + // Extract imports and code from codeblock + const imports = extractImportsFromCodeblock(codeblockPath) + const codeExample = extractCodeFromCodeblock(codeblockPath) + + // Determine the module name from the filename for the title + const nameWithoutExt = codeblockFilename.replace('.ts', '') + const parts = nameWithoutExt.split('.') + const moduleName = parts[parts.length - 1] + const moduleTitle = moduleName.charAt(0).toUpperCase() + moduleName.slice(1) + + // Create clean MDX content + const mdxContent = `# ${moduleTitle} + +${moduleTitle} module provides functionality for working with ${moduleName.toLowerCase()} types in Cardano. + +## ${sectionTitle} + +\`\`\`typescript +${imports} + +${codeExample} + +\`\`\` + +## API Reference + +For detailed API documentation, see the generated TypeDoc documentation. +` + + writeFileSync(targetPath, mdxContent) + console.log(`🧹 Cleaned and updated ${targetFile}`) + return true + } catch (error) { + console.error(`❌ Failed to clean and update ${targetFile}:`, error.message) + return false + } +} + +/** + * Insert or update a code example in a documentation file (legacy function) + */ +function updateDocumentationFile(codeblockFilename, codeblockPath) { + // For now, just call the clean function - we can keep both approaches if needed + return cleanAndUpdateDocumentationFile(codeblockFilename, codeblockPath) +} + +/** + * Main function to validate codeblocks and update documentation + */ +async function main() { + console.log('🚀 Starting codeblock validation and documentation update...\n') + + // Discover all codeblock files + const codeblockFiles = readdirSync(CODEBLOCKS_DIR) + .filter(file => file.endsWith('.ts') && file.startsWith('pages.')) + .sort() + + if (codeblockFiles.length === 0) { + console.log('❌ No codeblock files found in', CODEBLOCKS_DIR) + console.log('Expected files matching pattern: pages.section.subsection.title.ts') + process.exit(1) + } + + console.log(`📁 Found ${codeblockFiles.length} codeblock files:`) + codeblockFiles.forEach(file => { + try { + const targetFile = getTargetFileFromCodeblock(file) + console.log(` ${file} → ${targetFile}`) + } catch (error) { + console.log(` ${file} → ❌ ${error.message}`) + } + }) + console.log() + + const results = [] + let allPassed = true + + // Test all codeblocks first + for (const codeblockFile of codeblockFiles) { + const codeblockPath = join(CODEBLOCKS_DIR, codeblockFile) + + try { + getTargetFileFromCodeblock(codeblockFile) // Validate filename format + const passed = runCodeblock(codeblockPath) + + results.push({ + codeblockFile, + codeblockPath, + passed + }) + + if (!passed) { + allPassed = false + } + } catch (error) { + console.error(`❌ Invalid filename format: ${codeblockFile} - ${error.message}`) + allPassed = false + results.push({ + codeblockFile, + codeblockPath, + passed: false + }) + } + } + + console.log('\n📊 Validation Results:') + console.log('=' .repeat(50)) + + results.forEach(({ codeblockFile, passed }) => { + const status = passed ? '✅ PASS' : '❌ FAIL' + console.log(`${status} ${codeblockFile}`) + }) + + if (!allPassed) { + console.log('\n❌ Some codeblocks failed validation. Documentation will not be updated.') + console.log('Please fix the failing codeblocks and run this script again.') + process.exit(1) + } + + console.log('\n✅ All codeblocks passed validation!') + console.log('\n🧹 Cleaning and updating documentation files...') + console.log('Note: This will completely rebuild the MDX files with fresh content.') + + // Group codeblocks by their target directories for cleanup + const directoriesByCodeblock = new Map() + const cleanedDirectories = new Set() + + for (const { codeblockFile, codeblockPath, passed } of results) { + if (passed) { + const targetFile = getTargetFileFromCodeblock(codeblockFile) + const targetDir = dirname(join(DOCS_DIR, targetFile)) + directoriesByCodeblock.set(codeblockFile, { codeblockPath, targetDir, targetFile }) + } + } + + // Clean directories only once before processing their files + let updateCount = 0 + for (const [codeblockFile, { codeblockPath, targetDir, targetFile }] of directoriesByCodeblock) { + // Clean the directory only once + if (!cleanedDirectories.has(targetDir)) { + try { + // Delete all existing MDX files in this directory + const existingFiles = readdirSync(targetDir).filter(file => file.endsWith('.mdx')) + for (const file of existingFiles) { + const filePath = join(targetDir, file) + const relativeFilePath = relative(DOCS_DIR, filePath) + console.log(`🗑️ Deleting ${relativeFilePath}`) + unlinkSync(filePath) + } + cleanedDirectories.add(targetDir) + console.log(`🧹 Cleaned directory ${relative(DOCS_DIR, targetDir)} (removed ${existingFiles.length} files)`) + } catch (error) { + // Directory might not exist, that's fine + console.log(`📁 Directory ${relative(DOCS_DIR, targetDir)} doesn't exist, will be created`) + } + } + + // Now update the specific file + const updated = updateDocumentationFile(codeblockFile, codeblockPath) + if (updated) { + updateCount++ + } + } + + console.log(`\n🎉 Successfully cleaned and updated ${updateCount} documentation files!`) + console.log('\nNext steps:') + console.log('- Review the cleaned documentation files') + console.log('- Commit the changes to your repository') + console.log('- The MDX files now contain fresh, up-to-date content with working code examples') +} + +// Run the script +main().catch(console.error) diff --git a/package.json b/package.json index 6be2cf0d..2c901001 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "madge": "^8.0.0", "prettier": "^3.5.0", "rimraf": "^6.0.0", + "tsx": "^4.20.3", "turbo": "^2.0.0", "typescript": "^5.8.0", "vitest": "^3.2.4" diff --git a/packages/evolution/src/Data.ts b/packages/evolution/src/Data.ts index 0613c3b6..652503f9 100644 --- a/packages/evolution/src/Data.ts +++ b/packages/evolution/src/Data.ts @@ -47,7 +47,7 @@ export class DataError extends EffectData.TaggedError("DataError")<{ * @since 2.0.0 * @category model */ -export type Data = Constr | MapList | List | Int | ByteArray +export type Data = Constr | Map| List | Int | ByteArray /** * Constr type for constructor alternatives based on Conway CDDL specification @@ -77,7 +77,7 @@ export type Data = Constr | MapList | List | Int | ByteArray // readonly fields: readonly Data[]; // } -export type MapList = Map +export type Map = globalThis.Map /** * PlutusList type for plutus data lists @@ -247,7 +247,7 @@ export const constr = (index: bigint, data: Array): Constr => * @since 2.0.0 * @category constructors */ -export const map = (entries: Array<{ key: Data; value: Data }>): MapList => +export const map = (entries: Array<{ key: Data; value: Data }>): Map => new Map(entries.map(({ key, value }) => [key, value])) /** @@ -416,7 +416,7 @@ export const genConstr = (depth: number): FastCheck.Arbitrary => * * @since 2.0.0 */ -export const genPlutusMap = (depth: number): FastCheck.Arbitrary => { +export const genPlutusMap = (depth: number): FastCheck.Arbitrary => { // Helper to create key-value pairs with unique keys const uniqueKeyValuePairs = (keyGen: FastCheck.Arbitrary, maxSize: number) => FastCheck.uniqueArray(FastCheck.tuple(keyGen, genPlutusData(depth > 0 ? depth - 1 : 0)), { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d3fab15e..a750ce95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -80,6 +80,9 @@ importers: rimraf: specifier: ^6.0.0 version: 6.0.1 + tsx: + specifier: ^4.20.3 + version: 4.20.3 turbo: specifier: ^2.0.0 version: 2.5.5