Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/quiet-links-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@codama/spec': patch
Comment thread
lorisleiva marked this conversation as resolved.
Resolved
---

Declare the identifier of link nodes before their optional parent link, and the label of `valueLabelDisplayNode` before its value, so the attributes that describe a node come first. Clarify that this order is a convention for spec authors, whilst generators must emit attributes in declaration order, followed by base attributes, without regrouping them into data and child attributes.

```jsonc
// Before
{ "kind": "accountLinkNode", "program": { "kind": "programLinkNode", "identifier": "token" }, "identifier": "mint" }

// After
{ "kind": "accountLinkNode", "identifier": "mint", "program": { "kind": "programLinkNode", "identifier": "token" } }
```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ The `attribute` vs `optionalAttribute` distinction therefore has **no effect on

### Attributes serialise in declaration order

Each node declares its attributes as an ordered array in `defineNode(...)`, and that order is authored deliberately: **static data first, child nodes and arrays last**. For example, `kind`, `identifier`, `docs` and other scalars precede large child collections such as `accounts`, `instructions` or `fields`.
Each node declares its attributes as an ordered array in `defineNode(...)`, and that order is authored deliberately. By convention, **the attributes that describe a node come first and its child nodes and arrays last**. Human text such as `docs` or a display `label` counts as describing the node, even though it may hold a `textNode`. For example, `identifier`, `docs` and other scalars precede large child collections such as `accounts`, `instructions` or `fields`. This is a convention for spec authors rather than a rule, so a node may declare a child earlier when it reads better.

- **On write**, generators MUST emit a node's attributes in this declaration order (with the implicit `kind` discriminator first). They MUST NOT re-serialise through a key-sorting structure — notably `serde_json::Value`, whose object type is a `BTreeMap` and therefore sorts keys alphabetically, pushing scalars like `identifier` after the child arrays.
- **On write**, generators MUST emit a node's attributes in this declaration order (with the implicit `kind` discriminator first), without regrouping them, e.g. into data and child attributes. They MUST NOT re-serialise through a key-sorting structure — notably `serde_json::Value`, whose object type is a `BTreeMap` and therefore sorts keys alphabetically, pushing scalars like `identifier` after the child arrays.
- **On read**, attribute order carries no semantics; consumers MUST NOT depend on it.

Preserving declaration order keeps encoded IDLs readable: the identifying scalars of a node (`kind`, `identifier`, …) appear before its potentially large children, so a node's identity is legible at a glance even in a deeply nested IDL.
Expand Down
12 changes: 6 additions & 6 deletions docs/AccountNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ An on-chain account: its identifier, data type, optional fixed size, optional PD

### Data

| Attribute | Type | Description |
| ------------ | ------------------ | ---------------------------------------------------------------- |
| `kind` | `"accountNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the account. |
| `size` | `u64` _(optional)_ | The size of the account in bytes, when the data length is fixed. |
| Attribute | Type | Description |
| ------------ | ---------------------------------------------------- | ---------------------------------------------------------------- |
| `kind` | `"accountNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the account. |
| `size` | `u64` _(optional)_ | The size of the account in bytes, when the data length is fixed. |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the account. |

### Children

| Attribute | Type | Description |
| ---------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the account. |
| `data` | [`TypeNode`](./typeNodes/TypeNode.md) | The type describing the account data — any type node, including a `definedTypeLinkNode` to share or reuse a defined type. Nodes that reference account fields by name — e.g. `accountDataValueNode` or `fieldDiscriminatorNode` — are only valid when this type resolves to a struct (following links). |
| `pda` | [`PdaLinkNode`](./linkNodes/PdaLinkNode.md) _(optional)_ | A link to the PDA the account is derived from, if applicable. |
| `discriminators` | [`DiscriminatorNode`](./discriminatorNodes/DiscriminatorNode.md)[] _(optional)_ | Discriminators that distinguish this account from others in the program. When multiple are listed, they are combined with a logical AND. |
Expand Down
20 changes: 10 additions & 10 deletions docs/ConstantNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ A named constant exposed by the program: a typed value associated with a name.

### Data

| Attribute | Type | Description |
| ------------ | ------------------ | ------------------------------- |
| `kind` | `"constantNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the constant. |
| Attribute | Type | Description |
| ------------ | ---------------------------------------------------- | ---------------------------------------- |
| `kind` | `"constantNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the constant. |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the constant. |

### Children

| Attribute | Type | Description |
| --------- | ---------------------------------------------------- | ----------------------------------------------- |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the constant. |
| `type` | [`TypeNode`](./typeNodes/TypeNode.md) | The type of the constant. |
| `value` | [`ValueNode`](./valueNodes/ValueNode.md) | The concrete value of the constant. |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |
| Attribute | Type | Description |
| --------- | ---------------------------------------------- | ----------------------------------------------- |
| `type` | [`TypeNode`](./typeNodes/TypeNode.md) | The type of the constant. |
| `value` | [`ValueNode`](./valueNodes/ValueNode.md) | The concrete value of the constant. |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |

## Examples

Expand Down
18 changes: 9 additions & 9 deletions docs/DefinedTypeNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ A reusable named type that can be referenced by `definedTypeLinkNode` from elsew

### Data

| Attribute | Type | Description |
| ------------ | ------------------- | ----------------------------------- |
| `kind` | `"definedTypeNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the defined type. |
| Attribute | Type | Description |
| ------------ | ---------------------------------------------------- | ------------------------------------ |
| `kind` | `"definedTypeNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the defined type. |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the type. |

### Children

| Attribute | Type | Description |
| --------- | ---------------------------------------------------- | ----------------------------------------------- |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the type. |
| `type` | [`TypeNode`](./typeNodes/TypeNode.md) | The type definition. |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |
| Attribute | Type | Description |
| --------- | ---------------------------------------------- | ----------------------------------------------- |
| `type` | [`TypeNode`](./typeNodes/TypeNode.md) | The type definition. |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |

## Examples

Expand Down
20 changes: 10 additions & 10 deletions docs/ErrorNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ A program error — a numeric code paired with an identifier and human-readable

### Data

| Attribute | Type | Description |
| ------------ | ------------------ | ----------------------------------------------- |
| `kind` | `"errorNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the error. |
| `code` | `u32` | The numeric error code returned by the program. |
| Attribute | Type | Description |
| ------------ | ---------------------------------------------------- | ----------------------------------------------- |
| `kind` | `"errorNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the error. |
| `code` | `u32` | The numeric error code returned by the program. |
| `message` | `string` \| [`TextNode`](./TextNode.md) | A human-readable description of the error. |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the error. |

### Children

| Attribute | Type | Description |
| --------- | ---------------------------------------------------- | ----------------------------------------------- |
| `message` | `string` \| [`TextNode`](./TextNode.md) | A human-readable description of the error. |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the error. |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |
| Attribute | Type | Description |
| --------- | ---------------------------------------------- | ----------------------------------------------- |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |

## Examples

Expand Down
10 changes: 5 additions & 5 deletions docs/EventNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ A program event: its data shape and optional discriminators used to identify it

### Data

| Attribute | Type | Description |
| ------------ | ------------------ | ---------------------------- |
| `kind` | `"eventNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the event. |
| Attribute | Type | Description |
| ------------ | ---------------------------------------------------- | ------------------------------------- |
| `kind` | `"eventNode"` | The node discriminator. |
| `identifier` | `IdentifierString` | The identifier of the event. |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the event. |

### Children

| Attribute | Type | Description |
| ---------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `docs` | `string` \| [`TextNode`](./TextNode.md) _(optional)_ | Markdown documentation for the event. |
| `data` | [`TypeNode`](./typeNodes/TypeNode.md) | The type describing the event payload. |
| `discriminators` | [`DiscriminatorNode`](./discriminatorNodes/DiscriminatorNode.md)[] _(optional)_ | Discriminators that distinguish this event from others. When multiple are listed, they are combined with a logical AND. |
| `plugins` | [`PluginNode`](./PluginNode.md)[] _(optional)_ | Namespaced plugins with custom structured data. |
Expand Down
Loading
Loading