Skip to content

Commit c8c5934

Browse files
lorisleivaetodanik
andauthored
[0.22] Add InstructionLinkNode, InstructionAccountLinkNode and InstructionArgumentLinkNode (#183)
Co-Authored-By: Danny Povolotski <[email protected]>
1 parent 279749c commit c8c5934

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1018
-163
lines changed

.changeset/hungry-hairs-shave.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@kinobi-so/renderers-js-umi': minor
3+
'@kinobi-so/renderers-rust': minor
4+
'@kinobi-so/visitors-core': minor
5+
'@kinobi-so/renderers-js': minor
6+
'@kinobi-so/node-types': minor
7+
'@kinobi-so/errors': minor
8+
'@kinobi-so/nodes': minor
9+
---
10+
11+
Add `InstructionLinkNode`, `InstructionAccountLinkNode` and `InstructionArgumentLinkNode`

packages/errors/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type KinobiErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
7575
kind: LinkNode['kind'];
7676
linkNode: LinkNode;
7777
name: CamelCaseString;
78-
program?: CamelCaseString;
78+
stack: Node[];
7979
};
8080
[KINOBI_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: {
8181
fsFunction: string;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { CamelCaseString } from '../shared';
2+
import type { InstructionLinkNode } from './InstructionLinkNode';
3+
4+
export interface InstructionAccountLinkNode<
5+
TInstruction extends InstructionLinkNode | undefined = InstructionLinkNode | undefined,
6+
> {
7+
readonly kind: 'instructionAccountLinkNode';
8+
9+
// Children.
10+
readonly instruction?: TInstruction;
11+
12+
// Data.
13+
readonly name: CamelCaseString;
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { CamelCaseString } from '../shared';
2+
import type { InstructionLinkNode } from './InstructionLinkNode';
3+
4+
export interface InstructionArgumentLinkNode<
5+
TInstruction extends InstructionLinkNode | undefined = InstructionLinkNode | undefined,
6+
> {
7+
readonly kind: 'instructionArgumentLinkNode';
8+
9+
// Children.
10+
readonly instruction?: TInstruction;
11+
12+
// Data.
13+
readonly name: CamelCaseString;
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { CamelCaseString } from '../shared';
2+
import type { ProgramLinkNode } from './ProgramLinkNode';
3+
4+
export interface InstructionLinkNode<TProgram extends ProgramLinkNode | undefined = ProgramLinkNode | undefined> {
5+
readonly kind: 'instructionLinkNode';
6+
7+
// Children.
8+
readonly program?: TProgram;
9+
10+
// Data.
11+
readonly name: CamelCaseString;
12+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import type { AccountLinkNode } from './AccountLinkNode';
22
import type { DefinedTypeLinkNode } from './DefinedTypeLinkNode';
3+
import type { InstructionAccountLinkNode } from './InstructionAccountLinkNode';
4+
import type { InstructionArgumentLinkNode } from './InstructionArgumentLinkNode';
5+
import type { InstructionLinkNode } from './InstructionLinkNode';
36
import type { PdaLinkNode } from './PdaLinkNode';
47
import type { ProgramLinkNode } from './ProgramLinkNode';
58

69
// Link Node Registration.
7-
export type RegisteredLinkNode = AccountLinkNode | DefinedTypeLinkNode | PdaLinkNode | ProgramLinkNode;
10+
export type RegisteredLinkNode =
11+
| AccountLinkNode
12+
| DefinedTypeLinkNode
13+
| InstructionAccountLinkNode
14+
| InstructionArgumentLinkNode
15+
| InstructionLinkNode
16+
| PdaLinkNode
17+
| ProgramLinkNode;
818

919
// Link Node Helpers.
1020
export type LinkNode = RegisteredLinkNode;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export * from './AccountLinkNode';
22
export * from './DefinedTypeLinkNode';
3+
export * from './InstructionAccountLinkNode';
4+
export * from './InstructionArgumentLinkNode';
5+
export * from './InstructionLinkNode';
36
export * from './LinkNode';
47
export * from './PdaLinkNode';
58
export * from './ProgramLinkNode';

packages/nodes/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Below are all of the available nodes and their documentation. Also note that you
6161
- [`LinkNode`](./docs/linkNodes/README.md) (abstract)
6262
- [`AccountLinkNode`](./docs/linkNodes/AccountLinkNode.md)
6363
- [`DefinedTypeLinkNode`](./docs/linkNodes/DefinedTypeLinkNode.md)
64+
- [`InstructionAccountLinkNode`](./docs/linkNodes/InstructionAccountLinkNode.md)
65+
- [`InstructionArgumentLinkNode`](./docs/linkNodes/InstructionArgumentLinkNode.md)
66+
- [`InstructionLinkNode`](./docs/linkNodes/InstructionLinkNode.md)
6467
- [`PdaLinkNode`](./docs/linkNodes/PdaLinkNode.md)
6568
- [`ProgramLinkNode`](./docs/linkNodes/ProgramLinkNode.md)
6669
- [`PdaSeedNode`](./docs/pdaSeedNodes/README.md) (abstract)

packages/nodes/docs/linkNodes/AccountLinkNode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This node represents a reference to an existing [`AccountNode`](../AccountNode.m
2121

2222
### `accountLinkNode(name, program?)`
2323

24-
Helper function that creates a `AccountLinkNode` object from the name of the `AccountNode` we are referring to. If the account is from another program, the `program` parameter must be provided as either a `string` or a `ProgramLinkNode`.
24+
Helper function that creates an `AccountLinkNode` object from the name of the `AccountNode` we are referring to. If the account is from another program, the `program` parameter must be provided as either a `string` or a `ProgramLinkNode`.
2525

2626
```ts
2727
const node = accountLinkNode('myAccount');
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# `InstructionAccountLinkNode`
2+
3+
This node represents a reference to an existing [`InstructionAccountNode`](../InstructionAccountNode.md) in the Kinobi IDL.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| --------- | ------------------------------ | --------------------------------------------------------------------------------------------- |
11+
| `kind` | `"instructionAccountLinkNode"` | The node discriminator. |
12+
| `name` | `CamelCaseString` | The name of the [`InstructionAccountNode`](../InstructionAccountNode.md) we are referring to. |
13+
14+
### Children
15+
16+
| Attribute | Type | Description |
17+
| ------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| `instruction` | [`InstructionLinkNode`](./InstructionLinkNode.md) | (Optional) The instruction associated with the linked account. Default to using the instruction we are currently under. Note that the instruction itself can point to a different program is needed. |
19+
20+
## Functions
21+
22+
### `instructionAccountLinkNode(name, instruction?)`
23+
24+
Helper function that creates an `InstructionAccountLinkNode` object from the name of the `InstructionAccountNode` we are referring to. If the account is from another instruction, the `instruction` parameter must be provided as either a `string` or a `InstructionLinkNode`. When providing an `InstructionLinkNode`, we can also provide a `ProgramLinkNode` to point to a different program.
25+
26+
```ts
27+
// Links to an account in the current instruction.
28+
const node = instructionAccountLinkNode('myAccount');
29+
30+
// Links to an account in another instruction but within the same program.
31+
const nodeFromAnotherInstruction = instructionAccountLinkNode('myAccount', 'myOtherInstruction');
32+
33+
// Links to an account in another instruction from another program.
34+
const nodeFromAnotherProgram = instructionAccountLinkNode(
35+
'myAccount',
36+
instructionLinkNode('myOtherInstruction', 'myOtherProgram'),
37+
);
38+
```

0 commit comments

Comments
 (0)