@codama/renderers-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +54 -0
- package/dist/index.node.cjs +2733 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +2700 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/templates/fragments/accountFetchHelpers.njk +43 -0
- package/dist/templates/fragments/accountPdaHelpers.njk +25 -0
- package/dist/templates/fragments/accountSizeHelpers.njk +3 -0
- package/dist/templates/fragments/instructionExtraArgs.njk +4 -0
- package/dist/templates/fragments/instructionFunction.njk +62 -0
- package/dist/templates/fragments/instructionInputType.njk +16 -0
- package/dist/templates/fragments/instructionParseFunction.njk +81 -0
- package/dist/templates/fragments/instructionType.njk +18 -0
- package/dist/templates/fragments/pdaFunction.njk +32 -0
- package/dist/templates/fragments/program.njk +3 -0
- package/dist/templates/fragments/programErrors.njk +36 -0
- package/dist/templates/fragments/type.njk +12 -0
- package/dist/templates/fragments/typeCodec.njk +6 -0
- package/dist/templates/fragments/typeDecoder.njk +6 -0
- package/dist/templates/fragments/typeDiscriminatedUnionHelpers.njk +23 -0
- package/dist/templates/fragments/typeEncoder.njk +6 -0
- package/dist/templates/layout.njk +9 -0
- package/dist/templates/macros.njk +12 -0
- package/dist/templates/pages/accountsIndex.njk +9 -0
- package/dist/templates/pages/accountsPage.njk +12 -0
- package/dist/templates/pages/definedTypesIndex.njk +9 -0
- package/dist/templates/pages/definedTypesPage.njk +9 -0
- package/dist/templates/pages/errorsIndex.njk +9 -0
- package/dist/templates/pages/errorsPage.njk +8 -0
- package/dist/templates/pages/instructionsIndex.njk +9 -0
- package/dist/templates/pages/instructionsPage.njk +14 -0
- package/dist/templates/pages/pdasIndex.njk +9 -0
- package/dist/templates/pages/pdasPage.njk +8 -0
- package/dist/templates/pages/programsIndex.njk +9 -0
- package/dist/templates/pages/programsPage.njk +10 -0
- package/dist/templates/pages/rootIndex.njk +26 -0
- package/dist/templates/pages/sharedPage.njk +106 -0
- package/dist/types/ImportMap.d.ts +15 -0
- package/dist/types/ImportMap.d.ts.map +1 -0
- package/dist/types/TypeManifest.d.ts +16 -0
- package/dist/types/TypeManifest.d.ts.map +1 -0
- package/dist/types/fragments/accountFetchHelpers.d.ts +9 -0
- package/dist/types/fragments/accountFetchHelpers.d.ts.map +1 -0
- package/dist/types/fragments/accountPdaHelpers.d.ts +10 -0
- package/dist/types/fragments/accountPdaHelpers.d.ts.map +1 -0
- package/dist/types/fragments/accountSizeHelpers.d.ts +7 -0
- package/dist/types/fragments/accountSizeHelpers.d.ts.map +1 -0
- package/dist/types/fragments/accountType.d.ts +9 -0
- package/dist/types/fragments/accountType.d.ts.map +1 -0
- package/dist/types/fragments/common.d.ts +25 -0
- package/dist/types/fragments/common.d.ts.map +1 -0
- package/dist/types/fragments/discriminatorCondition.d.ts +26 -0
- package/dist/types/fragments/discriminatorCondition.d.ts.map +1 -0
- package/dist/types/fragments/discriminatorConstants.d.ts +22 -0
- package/dist/types/fragments/discriminatorConstants.d.ts.map +1 -0
- package/dist/types/fragments/index.d.ts +31 -0
- package/dist/types/fragments/index.d.ts.map +1 -0
- package/dist/types/fragments/instructionAccountMeta.d.ts +4 -0
- package/dist/types/fragments/instructionAccountMeta.d.ts.map +1 -0
- package/dist/types/fragments/instructionAccountTypeParam.d.ts +10 -0
- package/dist/types/fragments/instructionAccountTypeParam.d.ts.map +1 -0
- package/dist/types/fragments/instructionByteDelta.d.ts +8 -0
- package/dist/types/fragments/instructionByteDelta.d.ts.map +1 -0
- package/dist/types/fragments/instructionData.d.ts +9 -0
- package/dist/types/fragments/instructionData.d.ts.map +1 -0
- package/dist/types/fragments/instructionExtraArgs.d.ts +9 -0
- package/dist/types/fragments/instructionExtraArgs.d.ts.map +1 -0
- package/dist/types/fragments/instructionFunction.d.ts +15 -0
- package/dist/types/fragments/instructionFunction.d.ts.map +1 -0
- package/dist/types/fragments/instructionInputDefault.d.ts +9 -0
- package/dist/types/fragments/instructionInputDefault.d.ts.map +1 -0
- package/dist/types/fragments/instructionInputResolved.d.ts +10 -0
- package/dist/types/fragments/instructionInputResolved.d.ts.map +1 -0
- package/dist/types/fragments/instructionInputType.d.ts +13 -0
- package/dist/types/fragments/instructionInputType.d.ts.map +1 -0
- package/dist/types/fragments/instructionParseFunction.d.ts +10 -0
- package/dist/types/fragments/instructionParseFunction.d.ts.map +1 -0
- package/dist/types/fragments/instructionRemainingAccounts.d.ts +8 -0
- package/dist/types/fragments/instructionRemainingAccounts.d.ts.map +1 -0
- package/dist/types/fragments/instructionType.d.ts +8 -0
- package/dist/types/fragments/instructionType.d.ts.map +1 -0
- package/dist/types/fragments/pdaFunction.d.ts +8 -0
- package/dist/types/fragments/pdaFunction.d.ts.map +1 -0
- package/dist/types/fragments/program.d.ts +7 -0
- package/dist/types/fragments/program.d.ts.map +1 -0
- package/dist/types/fragments/programAccounts.d.ts +7 -0
- package/dist/types/fragments/programAccounts.d.ts.map +1 -0
- package/dist/types/fragments/programErrors.d.ts +7 -0
- package/dist/types/fragments/programErrors.d.ts.map +1 -0
- package/dist/types/fragments/programInstructions.d.ts +7 -0
- package/dist/types/fragments/programInstructions.d.ts.map +1 -0
- package/dist/types/fragments/type.d.ts +9 -0
- package/dist/types/fragments/type.d.ts.map +1 -0
- package/dist/types/fragments/typeCodec.d.ts +11 -0
- package/dist/types/fragments/typeCodec.d.ts.map +1 -0
- package/dist/types/fragments/typeDecoder.d.ts +9 -0
- package/dist/types/fragments/typeDecoder.d.ts.map +1 -0
- package/dist/types/fragments/typeDiscriminatedUnionHelpers.d.ts +8 -0
- package/dist/types/fragments/typeDiscriminatedUnionHelpers.d.ts.map +1 -0
- package/dist/types/fragments/typeEncoder.d.ts +9 -0
- package/dist/types/fragments/typeEncoder.d.ts.map +1 -0
- package/dist/types/fragments/typeWithCodec.d.ts +12 -0
- package/dist/types/fragments/typeWithCodec.d.ts.map +1 -0
- package/dist/types/getRenderMapVisitor.d.ts +31 -0
- package/dist/types/getRenderMapVisitor.d.ts.map +1 -0
- package/dist/types/getTypeManifestVisitor.d.ts +19 -0
- package/dist/types/getTypeManifestVisitor.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/nameTransformers.d.ts +15 -0
- package/dist/types/nameTransformers.d.ts.map +1 -0
- package/dist/types/renderVisitor.d.ts +11 -0
- package/dist/types/renderVisitor.d.ts.map +1 -0
- package/dist/types/utils/async.d.ts +7 -0
- package/dist/types/utils/async.d.ts.map +1 -0
- package/dist/types/utils/codecs.d.ts +3 -0
- package/dist/types/utils/codecs.d.ts.map +1 -0
- package/dist/types/utils/customData.d.ts +18 -0
- package/dist/types/utils/customData.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/linkOverrides.d.ts +15 -0
- package/dist/types/utils/linkOverrides.d.ts.map +1 -0
- package/dist/types/utils/render.d.ts +4 -0
- package/dist/types/utils/render.d.ts.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Codama
|
|
4
|
+
Copyright (c) 2024 Metaplex Foundation
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Codama ➤ Renderers ➤ JavaScript
|
|
2
|
+
|
|
3
|
+
[![npm][npm-image]][npm-url]
|
|
4
|
+
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
5
|
+
|
|
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
|
|
9
|
+
|
|
10
|
+
This package generates JavaScript clients from your Codama IDLs. The generated clients are compatible with the soon-to-be-released 2.0 line of [`@solana/web3.js`](https://github.com/solana-labs/solana-web3.js).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm install @codama/renderers-js
|
|
16
|
+
```
|
|
17
|
+
|
|
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
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
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));
|
|
34
|
+
```
|
|
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/web3.js` library using sub-packages such as `@solana/addresses` or `@solana/codecs-strings`. When set to `true`, the main `@solana/web3.js` library is used which enables generated clients to install it as a `peerDependency`. |
|