Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagaprasadvr committed Dec 20, 2024
1 parent 0572cc9 commit 9416dd3
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions packages/renderers-vixen-parser/src/getRenderMapVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { getAllAccounts, getAllInstructionsWithSubs, getAllPrograms, isNode, VALUE_NODES } from '@codama/nodes';
import {
getAllAccounts,
getAllInstructionsWithSubs,
getAllPrograms,
isNode,
VALUE_NODES,
pascalCase,
snakeCase,
} from '@codama/nodes';
import { RenderMap } from '@codama/renderers-core';
import {
extendVisitor,
Expand Down Expand Up @@ -114,13 +122,13 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {

// TODO: assuming name of codama generated sdk to be {program_name}_program_sdk for now need to change it
const codamaSdkName = options.sdkName
? toSnakeCase(options.sdkName)
: `${toSnakeCase(programName)}_program_sdk`;
? snakeCase(options.sdkName)
: `${snakeCase(programName)}_program_sdk`;

const accountParserImports = new ImportMap();

accounts.forEach(acc => {
accountParserImports.add(`${codamaSdkName}::accounts::${fromCamelToPascalCase(acc.name)}`);
accountParserImports.add(`${codamaSdkName}::accounts::${pascalCase(acc.name)}`);
});

const instructionParserImports = new ImportMap();
Expand All @@ -135,7 +143,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
let ixImports = '';

instructions.forEach(ix => {
const ixPascalName = fromCamelToPascalCase(ix.name);
const ixPascalName = pascalCase(ix.name);
const ixAccounts = `${ixPascalName} as ${ixPascalName}IxAccounts`;
if (ix.hasArgs) {
// Adding alias for IxData
Expand Down Expand Up @@ -191,23 +199,3 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
v => recordLinkablesOnFirstVisitVisitor(v, linkables),
);
}

export const fromCamelToPascalCase = (str: string) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};

export const toPascalCase = (str: string) => {
return str
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
return index === 0 ? word.toUpperCase() : word.toLowerCase();
})
.replace(/\s+/g, '');
};

export const toSnakeCase = (str: string) => {
return str
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
return index === 0 ? word.toLowerCase() : `_${word.toLowerCase()}`;
})
.replace(/\s+/g, '');
};

0 comments on commit 9416dd3

Please sign in to comment.