codama-idl / codama

Generate clients, CLIs, documentation and more from your Solana programs
MIT License
73 stars 16 forks source link

Add visitors that add more components inside a `ProgramNode` #83

Open lorisleiva opened 3 months ago

lorisleiva commented 3 months ago

It would be useful to have visitors such as addAccountsVisitor, addInstructionsVisitor, addDefinedTypesVisitor, addErrorsVisitor, etc.

By default these visitors would add the provided nodes to the main program of the RootNode.

// Example.
codama.update(
  addDefinedTypesVisitor([
    definedTypeNode({ name: 'slot', type: numberTypeNode('u64') }),
    definedTypeNode({ name: 'hash', type: publicKeyTypeNode() })
  ])
);

However, we could also support an additional signature that would look for the correct ProgramNode using the provided program name.

// Example.
codama.update(
  addDefinedTypesVisitor('someAdditionalProgram', [
    definedTypeNode({ name: 'slot', type: numberTypeNode('u64') }),
    definedTypeNode({ name: 'hash', type: publicKeyTypeNode() })
  ])
);