Skip to content

Commit dc41bc7

Browse files
authored
Upgrade JS client to Kit v3 (#62)
1 parent 94bff9e commit dc41bc7

File tree

7 files changed

+535
-574
lines changed

7 files changed

+535
-574
lines changed

clients/js/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
"homepage": "https://github.com/solana-program/config#readme",
4343
"license": "MIT",
4444
"peerDependencies": {
45-
"@solana/kit": "^2.1.0"
45+
"@solana/kit": "^3.0"
4646
},
4747
"devDependencies": {
4848
"@ava/typescript": "^4.1.0",
4949
"@solana/eslint-config-solana": "^3.0.3",
50-
"@solana/kit": "^2.1.0",
51-
"@types/node": "^20",
50+
"@solana/kit": "^3.0",
51+
"@types/node": "^24",
5252
"@typescript-eslint/eslint-plugin": "^7.16.1",
5353
"@typescript-eslint/parser": "^7.16.1",
5454
"ava": "^6.1.3",

clients/js/pnpm-lock.yaml

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

clients/js/src/generated/instructions/store.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import {
1313
getBytesEncoder,
1414
getStructDecoder,
1515
getStructEncoder,
16+
type AccountMeta,
17+
type AccountSignerMeta,
1618
type Address,
1719
type Codec,
1820
type Decoder,
1921
type Encoder,
20-
type IAccountMeta,
21-
type IAccountSignerMeta,
22-
type IInstruction,
23-
type IInstructionWithAccounts,
24-
type IInstructionWithData,
22+
type Instruction,
23+
type InstructionWithAccounts,
24+
type InstructionWithData,
2525
type ReadonlyUint8Array,
2626
type TransactionSigner,
2727
type WritableAccount,
@@ -38,11 +38,11 @@ import {
3838

3939
export type StoreInstruction<
4040
TProgram extends string = typeof SOLANA_CONFIG_PROGRAM_ADDRESS,
41-
TAccountConfigAccount extends string | IAccountMeta<string> = string,
42-
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
43-
> = IInstruction<TProgram> &
44-
IInstructionWithData<Uint8Array> &
45-
IInstructionWithAccounts<
41+
TAccountConfigAccount extends string | AccountMeta<string> = string,
42+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
43+
> = Instruction<TProgram> &
44+
InstructionWithData<ReadonlyUint8Array> &
45+
InstructionWithAccounts<
4646
[
4747
TAccountConfigAccount extends string
4848
? WritableAccount<TAccountConfigAccount>
@@ -121,7 +121,7 @@ export function getStoreInstruction<
121121
TProgramAddress,
122122
(typeof input)['configAccount'] extends TransactionSigner<TAccountConfigAccount>
123123
? WritableSignerAccount<TAccountConfigAccount> &
124-
IAccountSignerMeta<TAccountConfigAccount>
124+
AccountSignerMeta<TAccountConfigAccount>
125125
: TAccountConfigAccount
126126
> {
127127
// Program address.
@@ -141,7 +141,7 @@ export function getStoreInstruction<
141141
const args = { ...input };
142142

143143
// Remaining accounts.
144-
const remainingAccounts: IAccountMeta[] = (args.signers ?? []).map(
144+
const remainingAccounts: AccountMeta[] = (args.signers ?? []).map(
145145
(signer) => ({
146146
address: signer.address,
147147
role: AccountRole.READONLY_SIGNER,
@@ -160,7 +160,7 @@ export function getStoreInstruction<
160160
TProgramAddress,
161161
(typeof input)['configAccount'] extends TransactionSigner<TAccountConfigAccount>
162162
? WritableSignerAccount<TAccountConfigAccount> &
163-
IAccountSignerMeta<TAccountConfigAccount>
163+
AccountSignerMeta<TAccountConfigAccount>
164164
: TAccountConfigAccount
165165
>;
166166

@@ -169,7 +169,7 @@ export function getStoreInstruction<
169169

170170
export type ParsedStoreInstruction<
171171
TProgram extends string = typeof SOLANA_CONFIG_PROGRAM_ADDRESS,
172-
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
172+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
173173
> = {
174174
programAddress: Address<TProgram>;
175175
accounts: {
@@ -186,19 +186,19 @@ export type ParsedStoreInstruction<
186186

187187
export function parseStoreInstruction<
188188
TProgram extends string,
189-
TAccountMetas extends readonly IAccountMeta[],
189+
TAccountMetas extends readonly AccountMeta[],
190190
>(
191-
instruction: IInstruction<TProgram> &
192-
IInstructionWithAccounts<TAccountMetas> &
193-
IInstructionWithData<Uint8Array>
191+
instruction: Instruction<TProgram> &
192+
InstructionWithAccounts<TAccountMetas> &
193+
InstructionWithData<ReadonlyUint8Array>
194194
): ParsedStoreInstruction<TProgram, TAccountMetas> {
195195
if (instruction.accounts.length < 1) {
196196
// TODO: Coded error.
197197
throw new Error('Not enough accounts');
198198
}
199199
let accountIndex = 0;
200200
const getNextAccount = () => {
201-
const accountMeta = instruction.accounts![accountIndex]!;
201+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
202202
accountIndex += 1;
203203
return accountMeta;
204204
};

clients/js/src/generated/shared/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
AccountRole,
1111
isProgramDerivedAddress,
1212
isTransactionSigner as kitIsTransactionSigner,
13+
type AccountMeta,
14+
type AccountSignerMeta,
1315
type Address,
14-
type IAccountMeta,
15-
type IAccountSignerMeta,
1616
type ProgramDerivedAddress,
1717
type TransactionSigner,
1818
upgradeRoleToSigner,
@@ -23,7 +23,7 @@ import {
2323
* @internal
2424
*/
2525
export function expectSome<T>(value: T | null | undefined): T {
26-
if (value == null) {
26+
if (value === null || value === undefined) {
2727
throw new Error('Expected a value but received null or undefined.');
2828
}
2929
return value;
@@ -48,7 +48,7 @@ export function expectAddress<T extends string = string>(
4848
return value.address;
4949
}
5050
if (Array.isArray(value)) {
51-
return value[0];
51+
return value[0] as Address<T>;
5252
}
5353
return value as Address<T>;
5454
}
@@ -113,7 +113,7 @@ export type ResolvedAccount<
113113
* Defines an instruction that stores additional bytes on-chain.
114114
* @internal
115115
*/
116-
export type IInstructionWithByteDelta = {
116+
export type InstructionWithByteDelta = {
117117
byteDelta: number;
118118
};
119119

@@ -127,7 +127,7 @@ export function getAccountMetaFactory(
127127
) {
128128
return (
129129
account: ResolvedAccount
130-
): IAccountMeta | IAccountSignerMeta | undefined => {
130+
): AccountMeta | AccountSignerMeta | undefined => {
131131
if (!account.value) {
132132
if (optionalAccountStrategy === 'omitted') return;
133133
return Object.freeze({

codama.mjs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,32 @@ const { default: prettierOptions } = await import(
1010

1111
export default {
1212
idl: 'program/idl.json',
13-
before: [
14-
{
13+
before: [],
14+
scripts: {
15+
js: {
1516
from: '@codama/renderers-js',
1617
args: ['clients/js/src/generated', { prettierOptions }],
1718
},
18-
{
19-
from: '@codama/visitors-core#deleteNodesVisitor',
20-
args: [['[definedTypeNode]configKeys']],
21-
},
22-
],
23-
scripts: {
24-
rust: {
25-
from: '@codama/renderers-rust',
26-
args: [
27-
'clients/rust/src/generated',
28-
{
29-
anchorTraits: false,
30-
crateFolder: 'clients/rust',
31-
formatCode: true,
32-
linkOverrides: {
33-
definedTypes: {
34-
configKeys: 'hooked',
19+
rust: [
20+
{
21+
from: '@codama/visitors-core#deleteNodesVisitor',
22+
args: [['[definedTypeNode]configKeys']],
23+
},
24+
{
25+
from: '@codama/renderers-rust',
26+
args: [
27+
'clients/rust/src/generated',
28+
{
29+
anchorTraits: false,
30+
crateFolder: 'clients/rust',
31+
formatCode: true,
32+
linkOverrides: {
33+
definedTypes: { configKeys: 'hooked' },
3534
},
35+
toolchain: `+${process.env.RUST_TOOLCHAIN_NIGHTLY}`,
3636
},
37-
toolchain: `+${process.env.RUST_TOOLCHAIN_NIGHTLY}`,
38-
},
39-
],
40-
},
37+
],
38+
},
39+
],
4140
},
42-
};
41+
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"generate:clients": "codama run --all"
66
},
77
"devDependencies": {
8-
"@codama/renderers-js": "^1.2.8",
9-
"@codama/renderers-rust": "^1.0.17",
8+
"@codama/renderers-js": "^1.3",
9+
"@codama/renderers-rust": "~1.0",
1010
"@codama/visitors-core": "^1.2.13",
11-
"codama": "^1.2.9",
11+
"codama": "^1.3",
1212
"dotenv": "^16.5.0"
1313
},
1414
"engines": {

0 commit comments

Comments
 (0)