Skip to content

[v2] Add spec-level base attributes and give every node a plugins list #124

Description

@lorisleiva

Today in v1

The spec defines a pluginNode — a named bag of consumer-defined data that Codama carries through the graph verbatim:

{ "kind": "pluginNode", "name": "explorerHints", "payload": { "icon": "transfer-arrow" } }

But only instructionNode has a plugins attribute to attach them to. Custom data cannot be attached to accounts, types, errors, programs, or the root. codama-idl/codama#73 asked for plugins on RootNode alone; this proposal generalises it to every node.

Proposal

Two changes, one to the meta-model and one to the v2 spec content:

1. Base attributes in the meta-model. The Spec type gains an optional base block declaring attributes that every node has. Codegen targets append them after each node's declared attributes and may emit a shared BaseNode interface. This is version-agnostic and additive: v1 declares no base attributes and is unaffected.

interface Spec {
    version: string;
    base?: { attributes: AttributeSpec[] };
    categories: CategorySpec[];
}

2. v2 declares one base attribute: plugins, an optional array of pluginNode, on every single node.

{
    "kind": "errorNode",
    "name": "invalidAmount",
    "code": 6000,
    "message": "Amount must be greater than zero.",
    "plugins": [{ "kind": "pluginNode", "name": "explorerHints", "payload": { "severity": "warning" } }]
}

Decisions

Open question

Should docs also become a base attribute, giving every node documentation? Today some nodes (most type nodes) have no docs attribute at all.

Migration

upgradeV1ToV2 copies instructionNode.plugins as-is; no other v1 node carries plugins.


Part of #102 — Tier A.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions