@codama/renderers-js 1.2.4 → 1.2.6
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/README.md +16 -16
- package/dist/index.node.cjs +19 -20
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +21 -22
- package/dist/index.node.mjs.map +1 -1
- package/dist/templates/pages/sharedPage.njk +1 -1
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[npm-image]: https://img.shields.io/npm/v/@codama/renderers-js.svg?style=flat&label=%40codama%2Frenderers-js
|
|
8
8
|
[npm-url]: https://www.npmjs.com/package/@codama/renderers-js
|
|
9
9
|
|
|
10
|
-
This package generates JavaScript clients from your Codama IDLs. The generated clients are compatible with
|
|
10
|
+
This package generates JavaScript clients from your Codama IDLs. The generated clients are compatible with [`@solana/kit`](https://github.com/anza-xyz/kit).
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -37,18 +37,18 @@ codama.accept(renderVisitor(pathToGeneratedFolder, options));
|
|
|
37
37
|
|
|
38
38
|
The `renderVisitor` accepts the following options.
|
|
39
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/
|
|
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/dist/index.node.cjs
CHANGED
|
@@ -40,18 +40,18 @@ var typeScriptPlugin__namespace = /*#__PURE__*/_interopNamespace(typeScriptPlugi
|
|
|
40
40
|
|
|
41
41
|
// src/ImportMap.ts
|
|
42
42
|
var DEFAULT_EXTERNAL_MODULE_MAP = {
|
|
43
|
-
solanaAccounts: "@solana/
|
|
44
|
-
solanaAddresses: "@solana/
|
|
45
|
-
solanaCodecsCore: "@solana/
|
|
46
|
-
solanaCodecsDataStructures: "@solana/
|
|
47
|
-
solanaCodecsNumbers: "@solana/
|
|
48
|
-
solanaCodecsStrings: "@solana/
|
|
49
|
-
solanaErrors: "@solana/
|
|
50
|
-
solanaInstructions: "@solana/
|
|
51
|
-
solanaOptions: "@solana/
|
|
52
|
-
solanaPrograms: "@solana/
|
|
53
|
-
solanaRpcTypes: "@solana/
|
|
54
|
-
solanaSigners: "@solana/
|
|
43
|
+
solanaAccounts: "@solana/kit",
|
|
44
|
+
solanaAddresses: "@solana/kit",
|
|
45
|
+
solanaCodecsCore: "@solana/kit",
|
|
46
|
+
solanaCodecsDataStructures: "@solana/kit",
|
|
47
|
+
solanaCodecsNumbers: "@solana/kit",
|
|
48
|
+
solanaCodecsStrings: "@solana/kit",
|
|
49
|
+
solanaErrors: "@solana/kit",
|
|
50
|
+
solanaInstructions: "@solana/kit",
|
|
51
|
+
solanaOptions: "@solana/kit",
|
|
52
|
+
solanaPrograms: "@solana/kit",
|
|
53
|
+
solanaRpcTypes: "@solana/kit",
|
|
54
|
+
solanaSigners: "@solana/kit"
|
|
55
55
|
};
|
|
56
56
|
var DEFAULT_GRANULAR_EXTERNAL_MODULE_MAP = {
|
|
57
57
|
solanaAccounts: "@solana/accounts",
|
|
@@ -457,7 +457,7 @@ function getAccountPdaHelpersFragment(scope) {
|
|
|
457
457
|
const { accountPath, nameApi, linkables, customAccountData, typeManifest: typeManifest2 } = scope;
|
|
458
458
|
const accountNode = visitorsCore.getLastNodeFromPath(accountPath);
|
|
459
459
|
const programNode = visitorsCore.findProgramNodeFromPath(accountPath);
|
|
460
|
-
const pdaNode = accountNode.pda ? linkables.get([...accountPath, accountNode.pda]) :
|
|
460
|
+
const pdaNode = accountNode.pda ? linkables.get([...accountPath, accountNode.pda]) : void 0;
|
|
461
461
|
if (!pdaNode) {
|
|
462
462
|
return fragment("");
|
|
463
463
|
}
|
|
@@ -637,14 +637,14 @@ function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
|
637
637
|
return fragment(`ReadonlyAccount<${typeParam}>`).addImports("solanaInstructions", "type ReadonlyAccount");
|
|
638
638
|
}
|
|
639
639
|
function getInstructionAccountTypeParamFragment(scope) {
|
|
640
|
-
const { instructionAccountPath,
|
|
640
|
+
const { instructionAccountPath, linkables } = scope;
|
|
641
641
|
const instructionAccountNode = visitorsCore.getLastNodeFromPath(instructionAccountPath);
|
|
642
642
|
const instructionNode = visitorsCore.findInstructionNodeFromPath(instructionAccountPath);
|
|
643
643
|
const programNode = visitorsCore.findProgramNodeFromPath(instructionAccountPath);
|
|
644
644
|
const typeParam = `TAccount${nodes.pascalCase(instructionAccountNode.name)}`;
|
|
645
|
-
const accountMeta =
|
|
645
|
+
const accountMeta = " | IAccountMeta<string>" ;
|
|
646
646
|
const imports = new ImportMap();
|
|
647
|
-
|
|
647
|
+
{
|
|
648
648
|
imports.add("solanaInstructions", "type IAccountMeta");
|
|
649
649
|
}
|
|
650
650
|
if (instructionNode.optionalAccountStrategy === "omitted" && instructionAccountNode.isOptional) {
|
|
@@ -809,7 +809,7 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
809
809
|
if (input.kind === "instructionAccountNode" && nodes.isNode(defaultValue, "resolverValueNode")) {
|
|
810
810
|
return fragment(`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`);
|
|
811
811
|
}
|
|
812
|
-
if (input.kind === "instructionAccountNode" && isWritable ===
|
|
812
|
+
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
813
813
|
return fragment(`accounts.${inputName}.value = ${renderedValue};`);
|
|
814
814
|
}
|
|
815
815
|
if (input.kind === "instructionAccountNode") {
|
|
@@ -995,7 +995,7 @@ ${ifTrueRenderer ? ifTrueRenderer.render : ifFalseRenderer?.render}
|
|
|
995
995
|
}
|
|
996
996
|
function renderNestedInstructionDefault(scope) {
|
|
997
997
|
const { input, defaultValue } = scope;
|
|
998
|
-
if (!defaultValue) return
|
|
998
|
+
if (!defaultValue) return void 0;
|
|
999
999
|
return getInstructionInputDefaultFragment({
|
|
1000
1000
|
...scope,
|
|
1001
1001
|
input: { ...input, defaultValue }
|
|
@@ -1398,7 +1398,6 @@ function getInstructionTypeFragment(scope) {
|
|
|
1398
1398
|
instructionNode.accounts.map(
|
|
1399
1399
|
(account) => getInstructionAccountTypeParamFragment({
|
|
1400
1400
|
...scope,
|
|
1401
|
-
allowAccountMeta: true,
|
|
1402
1401
|
instructionAccountPath: [...instructionPath, account]
|
|
1403
1402
|
})
|
|
1404
1403
|
),
|
|
@@ -2663,7 +2662,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2663
2662
|
"type IAccountSignerMeta",
|
|
2664
2663
|
"isTransactionSigner",
|
|
2665
2664
|
"type TransactionSigner"
|
|
2666
|
-
]).addAlias("solanaSigners", "isTransactionSigner", "
|
|
2665
|
+
]).addAlias("solanaSigners", "isTransactionSigner", "kitIsTransactionSigner").toString(dependencyMap, useGranularImports)
|
|
2667
2666
|
})
|
|
2668
2667
|
);
|
|
2669
2668
|
}
|