Skip to content

Commit 0461845

Browse files
authored
Include account docs in generated code (#17)
1 parent c2e6dc3 commit 0461845

File tree

8 files changed

+28
-2
lines changed

8 files changed

+28
-2
lines changed

.changeset/funny-teeth-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-js': patch
3+
---
4+
5+
Include JSDoc comments for generated accounts

src/fragments/accountType.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ export function getAccountTypeFragment(
1616
if (customAccountData.has(accountNode.name)) return;
1717

1818
return getTypeWithCodecFragment({
19+
codecDocs: [`Gets the codec for {@link ${nameApi.dataType(accountNode.name)}} account data.`],
20+
decoderDocs: [`Gets the decoder for {@link ${nameApi.dataType(accountNode.name)}} account data.`],
21+
encoderDocs: [`Gets the encoder for {@link ${nameApi.dataArgsType(accountNode.name)}} account data.`],
1922
manifest: typeManifest,
2023
name: accountNode.name,
2124
nameApi,
2225
node: resolveNestedTypeNode(accountNode.data),
2326
size: scope.size,
27+
typeDocs: accountNode.docs,
2428
});
2529
}

test/e2e/anchor/src/generated/accounts/guardV1.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type GuardV1Args = {
9292
additionalFieldsRule: Array<MetadataAdditionalFieldRuleArgs>;
9393
};
9494

95+
/** Gets the encoder for {@link GuardV1Args} account data. */
9596
export function getGuardV1Encoder(): Encoder<GuardV1Args> {
9697
return transformEncoder(
9798
getStructEncoder([
@@ -109,6 +110,7 @@ export function getGuardV1Encoder(): Encoder<GuardV1Args> {
109110
);
110111
}
111112

113+
/** Gets the decoder for {@link GuardV1} account data. */
112114
export function getGuardV1Decoder(): Decoder<GuardV1> {
113115
return getStructDecoder([
114116
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
@@ -123,6 +125,7 @@ export function getGuardV1Decoder(): Decoder<GuardV1> {
123125
]);
124126
}
125127

128+
/** Gets the codec for {@link GuardV1} account data. */
126129
export function getGuardV1Codec(): Codec<GuardV1Args, GuardV1> {
127130
return combineCodec(getGuardV1Encoder(), getGuardV1Decoder());
128131
}

test/e2e/system/src/generated/accounts/nonce.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type NonceArgs = {
6060
lamportsPerSignature: Lamports;
6161
};
6262

63+
/** Gets the encoder for {@link NonceArgs} account data. */
6364
export function getNonceEncoder(): FixedSizeEncoder<NonceArgs> {
6465
return getStructEncoder([
6566
['version', getNonceVersionEncoder()],
@@ -70,6 +71,7 @@ export function getNonceEncoder(): FixedSizeEncoder<NonceArgs> {
7071
]);
7172
}
7273

74+
/** Gets the decoder for {@link Nonce} account data. */
7375
export function getNonceDecoder(): FixedSizeDecoder<Nonce> {
7476
return getStructDecoder([
7577
['version', getNonceVersionDecoder()],
@@ -80,6 +82,7 @@ export function getNonceDecoder(): FixedSizeDecoder<Nonce> {
8082
]);
8183
}
8284

85+
/** Gets the codec for {@link Nonce} account data. */
8386
export function getNonceCodec(): FixedSizeCodec<NonceArgs, Nonce> {
8487
return combineCodec(getNonceEncoder(), getNonceDecoder());
8588
}

test/e2e/token/idl.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
}
8888
],
8989
"name": "mint",
90-
"docs": [],
90+
"docs": ["Uniquely represents a token on the network and stores global metadata about the token."],
9191
"size": 82
9292
},
9393
{
@@ -199,7 +199,7 @@
199199
}
200200
],
201201
"name": "token",
202-
"docs": [],
202+
"docs": ["Stores information about an individual's ownership of a specific token (mint). Each token account is associated with a single mint and tracks details like the token balance and owner."],
203203
"size": 165
204204
},
205205
{

test/e2e/token/src/generated/accounts/mint.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
type OptionOrNullable,
4242
} from '@solana/kit';
4343

44+
/** Uniquely represents a token on the network and stores global metadata about the token. */
4445
export type Mint = {
4546
/**
4647
* Optional authority used to mint new tokens. The mint authority may only
@@ -75,6 +76,7 @@ export type MintArgs = {
7576
freezeAuthority: OptionOrNullable<Address>;
7677
};
7778

79+
/** Gets the encoder for {@link MintArgs} account data. */
7880
export function getMintEncoder(): FixedSizeEncoder<MintArgs> {
7981
return getStructEncoder([
8082
[
@@ -97,6 +99,7 @@ export function getMintEncoder(): FixedSizeEncoder<MintArgs> {
9799
]);
98100
}
99101

102+
/** Gets the decoder for {@link Mint} account data. */
100103
export function getMintDecoder(): FixedSizeDecoder<Mint> {
101104
return getStructDecoder([
102105
[
@@ -119,6 +122,7 @@ export function getMintDecoder(): FixedSizeDecoder<Mint> {
119122
]);
120123
}
121124

125+
/** Gets the codec for {@link Mint} account data. */
122126
export function getMintCodec(): FixedSizeCodec<MintArgs, Mint> {
123127
return combineCodec(getMintEncoder(), getMintDecoder());
124128
}

test/e2e/token/src/generated/accounts/multisig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type Multisig = {
4848

4949
export type MultisigArgs = Multisig;
5050

51+
/** Gets the encoder for {@link MultisigArgs} account data. */
5152
export function getMultisigEncoder(): FixedSizeEncoder<MultisigArgs> {
5253
return getStructEncoder([
5354
['m', getU8Encoder()],
@@ -57,6 +58,7 @@ export function getMultisigEncoder(): FixedSizeEncoder<MultisigArgs> {
5758
]);
5859
}
5960

61+
/** Gets the decoder for {@link Multisig} account data. */
6062
export function getMultisigDecoder(): FixedSizeDecoder<Multisig> {
6163
return getStructDecoder([
6264
['m', getU8Decoder()],
@@ -66,6 +68,7 @@ export function getMultisigDecoder(): FixedSizeDecoder<Multisig> {
6668
]);
6769
}
6870

71+
/** Gets the codec for {@link Multisig} account data. */
6972
export function getMultisigCodec(): FixedSizeCodec<MultisigArgs, Multisig> {
7073
return combineCodec(getMultisigEncoder(), getMultisigDecoder());
7174
}

test/e2e/token/src/generated/accounts/token.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
type AccountStateArgs,
4444
} from '../types';
4545

46+
/** Stores information about an individual's ownership of a specific token (mint). Each token account is associated with a single mint and tracks details like the token balance and owner. */
4647
export type Token = {
4748
/** The mint associated with this account. */
4849
mint: Address;
@@ -97,6 +98,7 @@ export type TokenArgs = {
9798
closeAuthority: OptionOrNullable<Address>;
9899
};
99100

101+
/** Gets the encoder for {@link TokenArgs} account data. */
100102
export function getTokenEncoder(): FixedSizeEncoder<TokenArgs> {
101103
return getStructEncoder([
102104
['mint', getAddressEncoder()],
@@ -128,6 +130,7 @@ export function getTokenEncoder(): FixedSizeEncoder<TokenArgs> {
128130
]);
129131
}
130132

133+
/** Gets the decoder for {@link Token} account data. */
131134
export function getTokenDecoder(): FixedSizeDecoder<Token> {
132135
return getStructDecoder([
133136
['mint', getAddressDecoder()],
@@ -159,6 +162,7 @@ export function getTokenDecoder(): FixedSizeDecoder<Token> {
159162
]);
160163
}
161164

165+
/** Gets the codec for {@link Token} account data. */
162166
export function getTokenCodec(): FixedSizeCodec<TokenArgs, Token> {
163167
return combineCodec(getTokenEncoder(), getTokenDecoder());
164168
}

0 commit comments

Comments
 (0)