Skip to content

Commit 0f434f0

Browse files
committed
Add code from JS renderer
1 parent 4e8619a commit 0f434f0

File tree

329 files changed

+46806
-4719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+46806
-4719
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
33
"changelog": [
44
"@changesets/changelog-github",
5-
{ "repo": "codama-idl/renderers-demo" }
5+
{ "repo": "codama-idl/renderers-js" }
66
],
77
"commit": false,
88
"access": "public",

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103

104104
dependabot:
105105
runs-on: ubuntu-latest
106-
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'codama-idl/renderers-demo'
106+
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'codama-idl/renderers-js'
107107
needs: [lint, tests]
108108
permissions:
109109
contents: write

CHANGELOG.md

Lines changed: 529 additions & 5 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

33
Copyright (c) 2025 Codama
4+
Copyright (c) 2024 Metaplex Foundation
45

56
Permission is hereby granted, free of charge, to any person obtaining
67
a copy of this software and associated documentation files (the

README.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
1-
# Codama ➤ Renderers ➤ Demo
1+
# Codama ➤ Renderers ➤ JavaScript
22

33
[![npm][npm-image]][npm-url]
44
[![npm-downloads][npm-downloads-image]][npm-url]
55

6-
[npm-downloads-image]: https://img.shields.io/npm/dm/@codama/renderers-demo.svg?style=flat
7-
[npm-image]: https://img.shields.io/npm/v/@codama/renderers-demo.svg?style=flat&label=%40codama%2Frenderers-demo
8-
[npm-url]: https://www.npmjs.com/package/@codama/renderers-demo
6+
[npm-downloads-image]: https://img.shields.io/npm/dm/@codama/renderers-js.svg?style=flat
7+
[npm-image]: https://img.shields.io/npm/v/@codama/renderers-js.svg?style=flat&label=%40codama%2Frenderers-js
8+
[npm-url]: https://www.npmjs.com/package/@codama/renderers-js
99

10-
This package provides a demo implementation of a Codama renderer to help developers create their own.
10+
This package generates JavaScript clients from your Codama IDLs. The generated clients are compatible with [`@solana/kit`](https://github.com/anza-xyz/kit).
1111

1212
## Installation
1313

1414
```sh
15-
pnpm install @codama/renderers-demo
15+
pnpm install @codama/renderers-js
1616
```
1717

18+
> [!NOTE]
19+
> This package is **not** included in the main [`codama`](../library) package.
20+
>
21+
> However, note that the [`renderers`](../renderers) package re-exports the `renderVisitor` function of this package as `renderJavaScriptVisitor`.
22+
1823
## Usage
1924

20-
Add the following script to your Codama configuration file.
21-
22-
```json
23-
{
24-
"scripts": {
25-
"demo": {
26-
"from": "@codama/renderers-demo",
27-
"args": ["docs"]
28-
}
29-
}
30-
}
25+
Once you have a Codama IDL, you can use the `renderVisitor` of this package to generate JavaScript clients. You will need to provide the base directory where the generated files will be saved and an optional set of options to customize the output.
26+
27+
```ts
28+
// node ./codama.mjs
29+
import { renderVisitor } from '@codama/renderers-js';
30+
31+
const pathToGeneratedFolder = path.join(__dirname, 'clients', 'js', 'src', 'generated');
32+
const options = {}; // See below.
33+
codama.accept(renderVisitor(pathToGeneratedFolder, options));
3134
```
35+
36+
## Options
37+
38+
The `renderVisitor` accepts the following options.
39+
40+
| Name | Type | Default | Description |
41+
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42+
| `deleteFolderBeforeRendering` | `boolean` | `true` | Whether the base directory should be cleaned before generating new files. |
43+
| `formatCode` | `boolean` | `true` | Whether we should use Prettier to format the generated code. |
44+
| `prettierOptions` | `PrettierOptions` | `{}` | The options to use when formatting the code using Prettier. |
45+
| `asyncResolvers` | `string[]` | `[]` | The exhaustive list of `ResolverValueNode`'s names whose implementation is asynchronous in JavaScript. |
46+
| `customAccountData` | `string[]` | `[]` | The names of all `AccountNodes` whose data should be manually written in JavaScript. |
47+
| `customInstructionData` | `string[]` | `[]` | The names of all `InstructionNodes` whose data should be manually written in JavaScript. |
48+
| `linkOverrides` | `Record<'accounts' \| 'definedTypes' \| 'instructions' \| 'pdas' \| 'programs' \| 'resolvers', Record<string, string>>` | `{}` | A object that overrides the import path of link nodes. For instance, `{ definedTypes: { counter: 'hooked' } }` uses the `hooked` folder to import any link node referring to the `counter` type. |
49+
| `dependencyMap` | `Record<string, string>` | `{}` | A mapping between import aliases and their actual package name or path in JavaScript. |
50+
| `internalNodes` | `string[]` | `[]` | The names of all nodes that should be generated but not exported by the `index.ts` files. |
51+
| `nameTransformers` | `Partial<NameTransformers>` | `{}` | An object that enables us to override the names of any generated type, constant or function. |
52+
| `nonScalarEnums` | `string[]` | `[]` | The names of enum variants with no data that should be treated as a data union instead of a native `enum` type. This is only useful if you are referencing an enum value in your Codama IDL. |
53+
| `renderParentInstructions` | `boolean` | `false` | When using nested instructions, whether the parent instructions should also be rendered. When set to `false` (default), only the instruction leaves are being rendered. |
54+
| `useGranularImports` | `boolean` | `false` | Whether to import the `@solana/kit` library using sub-packages such as `@solana/addresses` or `@solana/codecs-strings`. When set to `true`, the main `@solana/kit` library is used which enables generated clients to install it as a `peerDependency`. |

package.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@codama/renderers-demo",
3-
"version": "1.0.3",
4-
"description": "Demo renderer to help creating new ones",
2+
"name": "@codama/renderers-js",
3+
"version": "1.4.0",
4+
"description": "JavaScript renderer compatible with the Solana Kit library",
55
"exports": {
66
"types": "./dist/types/index.d.ts",
77
"react-native": "./dist/index.react-native.mjs",
@@ -33,7 +33,8 @@
3333
"framework",
3434
"standard",
3535
"renderers",
36-
"demo"
36+
"js",
37+
"client"
3738
],
3839
"scripts": {
3940
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
@@ -49,14 +50,15 @@
4950
"test:unit": "vitest run"
5051
},
5152
"dependencies": {
52-
"@codama/errors": "^1.3.5",
53-
"@codama/nodes": "^1.3.5",
54-
"@codama/renderers-core": "^1.2.0",
55-
"@codama/visitors-core": "^1.3.5",
56-
"@solana/codecs": "^3.0.3"
53+
"@codama/errors": "^1.3.6",
54+
"@codama/nodes": "^1.3.6",
55+
"@codama/renderers-core": "^1.2.1",
56+
"@codama/visitors-core": "^1.3.6",
57+
"@solana/codecs-strings": "^3.0.3",
58+
"prettier": "^3.6.2"
5759
},
5860
"devDependencies": {
59-
"@codama/cli": "^1.3.3",
61+
"@codama/nodes-from-anchor": "^1.2.8",
6062
"@changesets/changelog-github": "^0.5.1",
6163
"@changesets/cli": "^2.29.7",
6264
"@solana/eslint-config-solana": "^5.0.0",
@@ -74,10 +76,10 @@
7476
"license": "MIT",
7577
"repository": {
7678
"type": "git",
77-
"url": "https://github.com/codama-idl/codama"
79+
"url": "https://github.com/codama-idl/renderers-js"
7880
},
7981
"bugs": {
80-
"url": "http://github.com/codama-idl/codama/issues"
82+
"url": "http://github.com/codama-idl/renderers-js/issues"
8183
},
8284
"browserslist": [
8385
"supports bigint and not dead",

pnpm-lock.yaml

Lines changed: 35 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)