codama-idl / codama

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

[renderers-js] Improve data enum helper when using a tuple variant with a single item #75

Open lorisleiva opened 3 months ago

lorisleiva commented 3 months ago

When a EnumTupleVariantTypeNode contains a single item in the enum, we should transform the data enum helper such that it requires that item's value directly instead of having to wrap it in an array.

For instance, consider the following enum:

definedTypeNode({
  name: 'message',
  type: enumTypeNode([
    enumTupleVariantTypeNode(
      'write',
      tupleTypeNode([numberTypeNode('u16')])
    )
  ]),
})

Then instead of generating the following helper:

const myMessage = message('write', [42]);

We could simplify it to:

const myMessage = message('write', 42);