Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic PluginNodes to the RootNode #73

Open
lorisleiva opened this issue Jun 19, 2024 · 0 comments
Open

Add generic PluginNodes to the RootNode #73

lorisleiva opened this issue Jun 19, 2024 · 0 comments
Labels
proposal Suggesting a change / new feature

Comments

@lorisleiva
Copy link
Member

lorisleiva commented Jun 19, 2024

There is still a lot to explore here so this issue mainly offer a space to discuss this in more detail before committing to this.

The main idea here is to allow ecosystem users to extend the Codama IDL using customisable PluginNodes that can be understood by anyone that wishes to support that plugin.

For instance, here's a rough implementation proposal for illustration purposes:

type PluginNode<
  TName extends CamelCaseString = CamelCaseString,
  TData extends object = object
> = {
  kind: 'pluginNode';
  name: TName;
  data: TData;
}

Such that:

type RootNode = {
  kind: 'rootNode';
  program: ProgramNode;
  plugins: PluginNode[];
  // ...
}

Now, imagine the following two concrete plugins:

type Language = "en" | "fr" | "es"
type TranslationPluginNode = PluginNode<
  'translation',
  Record<Language, Record<CamelCaseString, { name: string, docs?: string[] }>>
>

type InstructionSummaryPluginNode = PluginNode<
  'instructionSummary',
  Record<CamelCaseString, string>
>

Which could be used in that way:

const plugins: PluginNode[] = [
  {
    kind: 'pluginNode',
    name: 'translation',
    data: {
      'fr': {
        'transferSol': { name: 'transfertDeSol', docs: [...] },
        'nonceState': { name: 'étatDuNonce' },
      },
      'es': {
        'transferSol': { name: 'transferenciaDeSol', docs: [...] },
        'nonceState': { name: 'estadoDelNonce' },
      },
    },
  },
  {
    kind: 'pluginNode',
    name: 'instructionSummary',
    data: {
      'transferSol': 'Transfer $amount SOL from $source to $destination',
      'createAccount': 'Create a new account $account with $space bytes on the $programId program',
    },
  },
];
@lorisleiva lorisleiva added the proposal Suggesting a change / new feature label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Suggesting a change / new feature
Projects
None yet
Development

No branches or pull requests

1 participant