Skip to content

Commit 608059e

Browse files
authored
Merge pull request #11 from macalinao/igm/docs-fixes
Update documentation more
2 parents 3a70e6e + a576929 commit 608059e

File tree

23 files changed

+625
-935
lines changed

23 files changed

+625
-935
lines changed

.changeset/late-socks-accept.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@macalinao/codama-instruction-accounts-dedupe-visitor": patch
3+
"@macalinao/codama-nodes-from-anchor-x": patch
4+
"@macalinao/codama-renderers-markdown": patch
5+
"@macalinao/codama-renderers-js-esm": patch
6+
"@macalinao/codama-rename-visitor": patch
7+
"@macalinao/clients-kamino-lending": patch
8+
"coda-docs": patch
9+
---
10+
11+
Update readmes

.changeset/slow-tables-dance.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@macalinao/codama-instruction-accounts-dedupe-visitor": patch
3+
"@macalinao/codama-nodes-from-anchor-x": patch
4+
"@macalinao/codama-renderers-markdown": patch
5+
"@macalinao/codama-renderers-js-esm": patch
6+
"@macalinao/codama-rename-visitor": patch
7+
"@macalinao/clients-kamino-lending": patch
8+
"coda-docs": patch
9+
---
10+
11+
Update docs and readmes

.changeset/tasty-states-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@macalinao/clients-kamino-lending": minor
3+
---
4+
5+
Add an index.ts

.changeset/tasty-taxes-fly.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@macalinao/codama-instruction-accounts-dedupe-visitor": patch
3+
"@macalinao/codama-nodes-from-anchor-x": patch
4+
"@macalinao/codama-renderers-markdown": patch
5+
"@macalinao/codama-renderers-js-esm": patch
6+
"@macalinao/codama-rename-visitor": patch
7+
"@macalinao/clients-kamino-lending": patch
8+
"@macalinao/coda": patch
9+
"coda-docs": patch
10+
---
11+
12+
docs

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Coda is an automated client generation tool for Solana programs. Built on top of [Codama](https://github.com/codama-idl/codama), Coda provides a zero-config CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
7+
Coda is an automated client generation tool for Solana programs. Built on top of [Codama](https://github.com/codama-idl/codama), Coda provides a CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
88

99
The monorepo contains:
1010
- **Coda CLI** - The main tool for generating TypeScript clients from Anchor IDLs
@@ -71,7 +71,7 @@ coda/
7171
## Core Packages
7272

7373
### 1. **@macalinao/coda** - CLI for client generation
74-
- Zero-config by default (looks for `./idls/*.json`)
74+
- Works out of the box (looks for `./idls/*.json` by default)
7575
- Configurable via `coda.config.mjs`
7676
- Generates TypeScript clients with full type safety
7777
- Built on Codama for extensibility

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Automated client generation for Solana programs.
1111
<a href="https://www.npmjs.com/package/@macalinao/coda"><img src="https://img.shields.io/npm/dm/@macalinao/coda?color=377CC0" /></a>
1212
</p>
1313

14-
Coda automatically generates type-safe TypeScript clients from your Anchor IDLs. Built on [Codama](https://github.com/codama-idl/codama), it provides a zero-config CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
14+
Coda automatically generates type-safe TypeScript clients from your Anchor IDLs. Built on [Codama](https://github.com/codama-idl/codama), it provides a CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
1515

1616
## Documentation
1717

apps/docs/content/docs/configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Configuration
33
description: Customize Coda generation with coda.config.mjs
44
---
55

6-
Coda works zero-config out of the box, but you can customize its behavior with a `coda.config.mjs` file.
6+
Coda works out of the box with sensible defaults, but you can customize its behavior with a `coda.config.mjs` file.
77

88
## Initialize Configuration
99

apps/docs/content/docs/meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
"generating-clients",
1212
"generating-docs",
1313
"examples",
14-
"---Packages---",
15-
"packages",
1614
"---Reference---",
15+
"packages",
1716
"api"
1817
]
1918
}

apps/docs/content/docs/packages/coda.mdx

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "@macalinao/coda"
33
description: The main CLI tool for automated client generation from Solana IDLs
44
---
55

6-
The core Coda package provides a zero-config CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
6+
The core Coda package provides a CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
77

88
## Installation
99

@@ -18,7 +18,7 @@ npm install -D @macalinao/coda
1818

1919
## Features
2020

21-
- 🚀 **Zero configuration** - Works out of the box with sensible defaults
21+
- 🚀 **Minimal configuration** - Works out of the box with sensible defaults
2222
- 🔧 **Fully customizable** - Extend and transform generated code with visitors
2323
- 📦 **ES modules native** - Modern JavaScript with proper `.js` extensions
2424
- 🎯 **Type-safe** - Full TypeScript support with precise types
@@ -54,7 +54,7 @@ Options:
5454

5555
## Configuration
5656

57-
### Zero-Config (Default)
57+
### Default Configuration
5858

5959
Coda works without any configuration by looking for IDLs in `./idls/*.json`:
6060

@@ -309,25 +309,123 @@ Use the dedupe visitor to flatten nested account structures:
309309
```javascript
310310
import { instructionAccountsDedupeVisitor } from "@macalinao/codama-instruction-accounts-dedupe-visitor";
311311

312+
export default defineConfig({
313+
visitors: ({ idl }) => [
314+
instructionAccountsDedupeVisitor(idl)
315+
]
316+
});
317+
```
318+
319+
### Renaming Conflicts
320+
321+
Resolve naming conflicts between multiple programs:
322+
323+
```javascript
324+
import { renameVisitor } from "@macalinao/codama-rename-visitor";
325+
312326
export default defineConfig({
313327
visitors: [
314-
instructionAccountsDedupeVisitor()
328+
renameVisitor({
329+
programA: {
330+
instructions: {
331+
transfer: "transferProgramA"
332+
}
333+
},
334+
programB: {
335+
instructions: {
336+
transfer: "transferProgramB"
337+
}
338+
}
339+
})
315340
]
316341
});
317342
```
318343

319-
### Custom Renderers
344+
## Documentation Generation
345+
346+
Generate markdown documentation alongside your TypeScript clients:
347+
348+
```bash
349+
coda docs [options]
350+
351+
Options:
352+
-i, --idl <path> Path to Anchor IDL file (default: "./idls/*.json")
353+
-o, --output <path> Output directory (default: "./docs")
354+
-c, --config <path> Path to config file (default: "./coda.config.mjs")
355+
```
356+
357+
### Basic Usage
358+
359+
```bash
360+
# Generate documentation
361+
coda docs
362+
363+
# Custom output directory
364+
coda docs -o ./api-docs
365+
```
366+
367+
### With Configuration
320368

321-
Use alternative renderers for different output formats:
369+
Add documentation generation to your config:
322370

323371
```javascript
324-
import { renderJavaScriptEsmVisitor } from "@macalinao/codama-renderers-js-esm";
372+
import { renderMarkdownVisitor } from "@macalinao/codama-renderers-markdown";
325373

326374
export default defineConfig({
327-
visitors: ({ idl }) => {
328-
const codama = createFromIdls([idl]);
329-
codama.accept(renderJavaScriptEsmVisitor("./src/generated"));
330-
return [];
331-
}
375+
visitors: [
376+
renderMarkdownVisitor("./docs")
377+
]
332378
});
333-
```
379+
```
380+
381+
## Best Practices
382+
383+
1. **Keep IDLs up-to-date**: Run `anchor build` before generating clients
384+
2. **Use TypeScript**: The generated code provides full type safety
385+
3. **Add custom PDAs**: Define program-derived addresses in your config
386+
4. **Document your programs**: Add descriptions in your Anchor programs
387+
5. **Version your clients**: Generate clients for each program version
388+
389+
## Troubleshooting
390+
391+
### IDL Not Found
392+
393+
If Coda can't find your IDL:
394+
395+
1. Check the default location: `./idls/*.json`
396+
2. Specify explicit path: `coda generate -i path/to/idl.json`
397+
3. Ensure Anchor program is built: `anchor build`
398+
399+
### Import Errors
400+
401+
If you see module resolution errors:
402+
403+
1. Ensure `"type": "module"` is in your package.json
404+
2. Check that tsconfig.json uses `"moduleResolution": "NodeNext"`
405+
3. Verify all local imports use `.js` extensions
406+
407+
### Type Errors
408+
409+
If TypeScript shows errors:
410+
411+
1. Run `bun install` to ensure dependencies are installed
412+
2. Check that `@solana/web3.js` is installed
413+
3. Verify tsconfig includes the generated directory
414+
415+
## Examples
416+
417+
### Single Program
418+
419+
See the [token-metadata client](https://github.com/macalinao/coda/tree/master/clients/token-metadata) for a complete example of a single program setup.
420+
421+
### Multiple Programs
422+
423+
See the [Quarry client](https://github.com/macalinao/coda/tree/master/clients/quarry) for an example with multiple programs and custom visitors.
424+
425+
## Related Packages
426+
427+
- [@macalinao/codama-renderers-js-esm](/docs/packages/codama-renderers-js-esm) - ESM-native TypeScript renderer
428+
- [@macalinao/codama-instruction-accounts-dedupe-visitor](/docs/packages/codama-instruction-accounts-dedupe-visitor) - Flatten nested accounts
429+
- [@macalinao/codama-rename-visitor](/docs/packages/codama-rename-visitor) - Rename instructions and accounts
430+
- [@macalinao/codama-renderers-markdown](/docs/packages/codama-renderers-markdown) - Generate documentation
431+
- [@macalinao/codama-nodes-from-anchor-x](/docs/packages/codama-nodes-from-anchor-x) - Parse multiple IDLs

apps/docs/content/docs/packages/codama-instruction-accounts-dedupe-visitor.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ Use it in your `coda.config.mjs`:
5454
```javascript
5555
import { defineConfig } from "@macalinao/coda";
5656
import { instructionAccountsDedupeVisitor } from "@macalinao/codama-instruction-accounts-dedupe-visitor";
57+
import fs from "fs";
5758

5859
export default defineConfig({
5960
idlPath: "./idls/my_program.json",
6061
outputDir: "./src/generated",
61-
visitors: [
62-
instructionAccountsDedupeVisitor()
62+
visitors: (idl) => [
63+
// Pass the IDL to the visitor
64+
instructionAccountsDedupeVisitor(idl)
6365
]
6466
});
6567
```
@@ -147,11 +149,11 @@ When flattening accounts, PDA seeds are also updated to reflect the new structur
147149
Creates a visitor that flattens nested instruction accounts:
148150

149151
```typescript
150-
function instructionAccountsDedupeVisitor(idl?: Idl): Visitor;
152+
function instructionAccountsDedupeVisitor(idl: AnchorIdl): Visitor;
151153
```
152154

153155
**Parameters:**
154-
- `idl` (optional): The Anchor IDL to use for context during transformation
156+
- `idl`: The Anchor IDL containing the instruction definitions with potentially nested accounts
155157

156158
**Returns:**
157159
- A Codama visitor that can be applied to transform the AST

0 commit comments

Comments
 (0)