Skip to content

Commit 3ac2a18

Browse files
committed
Rename node name attribute to identifier
1 parent e9dfcfa commit 3ac2a18

87 files changed

Lines changed: 376 additions & 346 deletions

File tree

Some content is hidden

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

‎packages/dynamic-address-resolution/src/codegen/codama-type-to-ts.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,29 @@ export function codamaTypeToTS(type: TypeNode | undefined, definedTypes: Defined
3737
if (!type.fields || type.fields.length === 0) return '{}';
3838
const fields = type.fields
3939
.filter(f => f.defaultValueStrategy !== 'omitted')
40-
.map(f => `${f.name}: ${codamaTypeToTS(f.type, definedTypes)}`);
40+
.map(f => `${f.identifier}: ${codamaTypeToTS(f.type, definedTypes)}`);
4141
if (fields.length === 0) return '{}';
4242
return `{ ${fields.join('; ')} }`;
4343
}
4444
case 'enumTypeNode': {
4545
if (!type.variants || type.variants.length === 0) return 'unknown /** empty variants in enumTypeNode */';
4646
const allEmpty = type.variants.every(v => v.kind === 'enumEmptyVariantTypeNode');
4747
if (allEmpty) {
48-
return type.variants.map(v => `'${v.name}'`).join(' | ');
48+
return type.variants.map(v => `'${v.identifier}'`).join(' | ');
4949
}
5050
const variantTypes = type.variants.map(v => {
5151
if (v.kind === 'enumEmptyVariantTypeNode') {
52-
return `{ __kind: '${v.name}' }`;
52+
return `{ __kind: '${v.identifier}' }`;
5353
}
5454
if (v.kind === 'enumStructVariantTypeNode' && v.struct) {
5555
const inner = codamaTypeToTS(v.struct, definedTypes);
56-
return `{ __kind: '${v.name}' } & ${inner}`;
56+
return `{ __kind: '${v.identifier}' } & ${inner}`;
5757
}
5858
if (v.kind === 'enumTupleVariantTypeNode' && v.tuple) {
5959
const inner = codamaTypeToTS(v.tuple, definedTypes);
60-
return `{ __kind: '${v.name}'; fields: ${inner} }`;
60+
return `{ __kind: '${v.identifier}'; fields: ${inner} }`;
6161
}
62-
return `{ __kind: '${v.name}' }`;
62+
return `{ __kind: '${v.identifier}' }`;
6363
});
6464
return variantTypes.join(' | ');
6565
}
@@ -79,8 +79,8 @@ export function codamaTypeToTS(type: TypeNode | undefined, definedTypes: Defined
7979
return `Record<string, ${v}>`;
8080
}
8181
case 'definedTypeLinkNode': {
82-
if (!type.name) return 'unknown /** name missing in definedTypeLinkNode */';
83-
const def = definedTypes.find(d => d.name === type.name);
82+
if (!type.identifier) return 'unknown /** name missing in definedTypeLinkNode */';
83+
const def = definedTypes.find(d => d.identifier === type.identifier);
8484
if (!def) return 'unknown /** DefinedTypeNode not found for definedTypeLinkNode */';
8585
return codamaTypeToTS(def.type, definedTypes);
8686
}

‎packages/dynamic-address-resolution/src/codegen/collect-pda-nodes.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export function collectPdaNodesFromIdl(idl: RootNode): Map<string, PdaNode> {
77
const pdas = new Map<string, PdaNode>();
88

99
for (const pda of idl.program.pdas ?? []) {
10-
pdas.set(pda.name, pda);
10+
pdas.set(pda.identifier, pda);
1111
}
1212

1313
for (const ix of idl.program.instructions ?? []) {
1414
for (const acc of ix.accounts ?? []) {
1515
if (!acc.defaultValue || acc.defaultValue.kind !== 'pdaValueNode') continue;
1616
const pdaDef = acc.defaultValue.pda;
1717
if (!pdaDef || pdaDef.kind !== 'pdaNode') continue;
18-
if (!pdas.has(pdaDef.name)) {
19-
pdas.set(pdaDef.name, pdaDef);
18+
if (!pdas.has(pdaDef.identifier)) {
19+
pdas.set(pdaDef.identifier, pdaDef);
2020
}
2121
}
2222
}

‎packages/dynamic-address-resolution/src/codegen/generate-pda-types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { collectPdaNodesFromIdl } from './collect-pda-nodes';
99
* Returns the type block with the aggregate map type name. `mapTypeName` is `null` when the program has no PDAs.
1010
*/
1111
export function generatePdaTypes(idl: RootNode): { mapTypeName: string | null; typeBlock: string } {
12-
const programName = pascalCase(idl.program.name);
12+
const programName = pascalCase(idl.program.identifier);
1313
const definedTypes = idl.program.definedTypes ?? [];
1414
const pdaMap = collectPdaNodesFromIdl(idl);
1515

@@ -28,7 +28,7 @@ export function generatePdaTypes(idl: RootNode): { mapTypeName: string | null; t
2828
const tsType = seed.type
2929
? codamaTypeToTS(seed.type, definedTypes)
3030
: 'unknown/** missing type in variablePdaSeedNode */';
31-
output += ` ${seed.name}: ${tsType};\n`;
31+
output += ` ${seed.identifier}: ${tsType};\n`;
3232
}
3333
output += '};\n\n';
3434
}

‎packages/dynamic-address-resolution/src/codegen/generate-resolution-input-types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function generateTypeBlockForInstruction(ix: InstructionNode, definedTypes: Defi
5050
const tsType = codamaTypeToTS(arg.type, definedTypes);
5151
const isOptional = OPTIONAL_NODE_KINDS.includes(arg.type.kind);
5252
const sep = isOptional ? '?:' : ':';
53-
output += ` ${arg.name}${sep} ${tsType};\n`;
53+
output += ` ${arg.identifier}${sep} ${tsType};\n`;
5454
}
5555
for (const ra of remainingAccountArgs) {
5656
const sep = ra.isOptional ? '?:' : ':';
@@ -64,7 +64,7 @@ function generateTypeBlockForInstruction(ix: InstructionNode, definedTypes: Defi
6464
for (const acc of ix.accounts ?? []) {
6565
const omittable = isAccountAutoResolvable(acc) ? '?' : '';
6666
const type = acc.isOptional ? 'Address | null' : 'Address';
67-
output += ` ${acc.name}${omittable}: ${type};\n`;
67+
output += ` ${acc.identifier}${omittable}: ${type};\n`;
6868
}
6969
output += '};\n\n';
7070
output += `export type ${refs.accountsWithDataRef} = ${refs.accountsRef} & Record<string, Address | null | undefined>;\n\n`;

‎packages/dynamic-address-resolution/src/codegen/generate-types-from-file.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function generateTypesFromFile(opts: GenerateTypesFromFileOptions): void
5050

5151
let types: string;
5252
try {
53-
console.log(`Generating types for program: ${idl.program.name}`);
53+
console.log(`Generating types for program: ${idl.program.identifier}`);
5454
types = generate(idl);
5555
} catch (err) {
5656
throw new Error(`Cannot generate types for IDL: ${idlPath}`, {

‎packages/dynamic-address-resolution/src/codegen/get-resolution-refs.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type ResolutionRefs = {
3636
};
3737

3838
export function getResolutionRefs(ix: InstructionNode): ResolutionRefs {
39-
const typeName = pascalCase(ix.name);
39+
const typeName = pascalCase(ix.identifier);
4040

4141
const args = (ix.arguments ?? []).filter(arg => arg.defaultValueStrategy !== 'omitted');
4242
const remainingAccountArgs = (ix.remainingAccounts ?? []).filter(ra => ra.value.kind === 'argumentValueNode');

‎packages/dynamic-address-resolution/src/resolvers/resolve-account-address.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function resolveAccountAddress<
4242
resolutionPath,
4343
resolversInput,
4444
}: ResolveAccountAddressContext<TAccounts, TArgs, TResolvers>): Promise<Address | null> {
45-
const accountAddressInput = accountsInput?.[ixAccountNode.name];
45+
const accountAddressInput = accountsInput?.[ixAccountNode.identifier];
4646
// Optional accounts explicitly provided as null should be resolved based on optionalAccountStrategy
4747
if (accountAddressInput === null && ixAccountNode.isOptional) {
4848
return resolveOptionalAccountWithStrategy(root, ixNode, ixAccountNode);
@@ -77,8 +77,8 @@ export async function resolveAccountAddress<
7777
}
7878

7979
throw new CodamaError(CODAMA_ERROR__DYNAMIC_CLIENT__ACCOUNT_MISSING, {
80-
accountName: ixAccountNode.name,
81-
instructionName: ixNode.name,
80+
accountName: ixAccountNode.identifier,
81+
instructionName: ixNode.identifier,
8282
});
8383
}
8484

@@ -94,7 +94,7 @@ function resolveOptionalAccountWithStrategy(
9494
) {
9595
if (!ixAccountNode.isOptional) {
9696
throw new CodamaError(CODAMA_ERROR__DYNAMIC_CLIENT__INVARIANT_VIOLATION, {
97-
message: `resolveOptionalAccountWithStrategy called for non-optional account: ${ixAccountNode.name}`,
97+
message: `resolveOptionalAccountWithStrategy called for non-optional account: ${ixAccountNode.identifier}`,
9898
});
9999
}
100100
switch (ixNode.optionalAccountStrategy) {
@@ -104,8 +104,8 @@ function resolveOptionalAccountWithStrategy(
104104
return toAddress(root.program.publicKey);
105105
default:
106106
throw new CodamaError(CODAMA_ERROR__DYNAMIC_CLIENT__UNSUPPORTED_OPTIONAL_ACCOUNT_STRATEGY, {
107-
accountName: ixAccountNode.name,
108-
instructionName: ixNode.name,
107+
accountName: ixAccountNode.identifier,
108+
instructionName: ixNode.identifier,
109109
strategy: safeStringify(ixNode.optionalAccountStrategy),
110110
});
111111
}

‎packages/dynamic-address-resolution/src/resolvers/resolve-account-value-node-address.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@ export async function resolveAccountValueNodeAddress<
2727
const { accountsInput, ixNode, resolutionPath } = ctx;
2828

2929
// Check if user provided the account address.
30-
const providedAddress = accountsInput?.[node.name];
30+
const providedAddress = accountsInput?.[node.identifier];
3131
if (providedAddress !== undefined && providedAddress !== null) {
3232
return toAddress(providedAddress);
3333
}
3434

3535
// Find the referenced account in the instruction.
36-
const referencedIxAccountNode = (ixNode.accounts ?? []).find(acc => acc.name === node.name);
36+
const referencedIxAccountNode = (ixNode.accounts ?? []).find(acc => acc.identifier === node.identifier);
3737
if (!referencedIxAccountNode) {
3838
throw new CodamaError(CODAMA_ERROR__DYNAMIC_CLIENT__NODE_REFERENCE_NOT_FOUND, {
39-
instructionName: ixNode.name,
40-
referencedName: node.name,
39+
instructionName: ixNode.identifier,
40+
referencedName: node.identifier,
4141
});
4242
}
4343

4444
// Detect circular dependencies before recursing.
45-
detectCircularDependency(node.name, resolutionPath);
45+
detectCircularDependency(node.identifier, resolutionPath);
4646

4747
return await resolveAccountAddress({
4848
accountsInput: ctx.accountsInput,
4949
argumentsInput: ctx.argumentsInput,
5050
ixAccountNode: referencedIxAccountNode,
5151
ixNode,
52-
resolutionPath: [...resolutionPath, node.name],
52+
resolutionPath: [...resolutionPath, node.identifier],
5353
resolversInput: ctx.resolversInput,
5454
root: ctx.root,
5555
});

‎packages/dynamic-address-resolution/src/resolvers/resolve-conditional.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function resolveConditionalValueNodeCondition<
5050

5151
if (!expectedValueNode && !ifTrue && !ifFalse) {
5252
throw new CodamaError(CODAMA_ERROR__DYNAMIC_CLIENT__INVARIANT_VIOLATION, {
53-
message: `Invalid conditionalValueNode: missing value and branches for account ${ixAccountNode.name} in ${ixNode.name}`,
53+
message: `Invalid conditionalValueNode: missing value and branches for account ${ixAccountNode.identifier} in ${ixNode.identifier}`,
5454
});
5555
}
5656

‎packages/dynamic-address-resolution/src/resolvers/resolve-instruction-account-address.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function resolveInstructionAccountAddress<
3131
resolversInput,
3232
root,
3333
}: ResolveInstructionAccountAddressInput<TAccounts, TArgs, TResolvers>): Promise<Address | null> {
34-
const accountAddressInput = accountsInput?.[ixAccountNode.name];
34+
const accountAddressInput = accountsInput?.[ixAccountNode.identifier];
3535
const isAccountProvided = accountAddressInput !== undefined && accountAddressInput !== null;
3636

3737
// Accounts values (with default or with optionalAccountStrategy) can be omitted, as they are auto-resolved.
@@ -48,8 +48,8 @@ export async function resolveInstructionAccountAddress<
4848

4949
if (!isAccountProvided && !canAutoResolve) {
5050
throw new CodamaError(CODAMA_ERROR__DYNAMIC_CLIENT__ACCOUNT_MISSING, {
51-
accountName: ixAccountNode.name,
52-
instructionName: ixNode.name,
51+
accountName: ixAccountNode.identifier,
52+
instructionName: ixNode.identifier,
5353
});
5454
}
5555

0 commit comments

Comments
 (0)