-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.22] Add
InstructionLinkNode
, InstructionAccountLinkNode
and `I…
…nstructionArgumentLinkNode` (#183) Co-Authored-By: Danny Povolotski <[email protected]>
- Loading branch information
1 parent
279749c
commit c8c5934
Showing
42 changed files
with
1,018 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@kinobi-so/renderers-js-umi': minor | ||
'@kinobi-so/renderers-rust': minor | ||
'@kinobi-so/visitors-core': minor | ||
'@kinobi-so/renderers-js': minor | ||
'@kinobi-so/node-types': minor | ||
'@kinobi-so/errors': minor | ||
'@kinobi-so/nodes': minor | ||
--- | ||
|
||
Add `InstructionLinkNode`, `InstructionAccountLinkNode` and `InstructionArgumentLinkNode` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/node-types/src/linkNodes/InstructionAccountLinkNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { CamelCaseString } from '../shared'; | ||
import type { InstructionLinkNode } from './InstructionLinkNode'; | ||
|
||
export interface InstructionAccountLinkNode< | ||
TInstruction extends InstructionLinkNode | undefined = InstructionLinkNode | undefined, | ||
> { | ||
readonly kind: 'instructionAccountLinkNode'; | ||
|
||
// Children. | ||
readonly instruction?: TInstruction; | ||
|
||
// Data. | ||
readonly name: CamelCaseString; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/node-types/src/linkNodes/InstructionArgumentLinkNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { CamelCaseString } from '../shared'; | ||
import type { InstructionLinkNode } from './InstructionLinkNode'; | ||
|
||
export interface InstructionArgumentLinkNode< | ||
TInstruction extends InstructionLinkNode | undefined = InstructionLinkNode | undefined, | ||
> { | ||
readonly kind: 'instructionArgumentLinkNode'; | ||
|
||
// Children. | ||
readonly instruction?: TInstruction; | ||
|
||
// Data. | ||
readonly name: CamelCaseString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { CamelCaseString } from '../shared'; | ||
import type { ProgramLinkNode } from './ProgramLinkNode'; | ||
|
||
export interface InstructionLinkNode<TProgram extends ProgramLinkNode | undefined = ProgramLinkNode | undefined> { | ||
readonly kind: 'instructionLinkNode'; | ||
|
||
// Children. | ||
readonly program?: TProgram; | ||
|
||
// Data. | ||
readonly name: CamelCaseString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import type { AccountLinkNode } from './AccountLinkNode'; | ||
import type { DefinedTypeLinkNode } from './DefinedTypeLinkNode'; | ||
import type { InstructionAccountLinkNode } from './InstructionAccountLinkNode'; | ||
import type { InstructionArgumentLinkNode } from './InstructionArgumentLinkNode'; | ||
import type { InstructionLinkNode } from './InstructionLinkNode'; | ||
import type { PdaLinkNode } from './PdaLinkNode'; | ||
import type { ProgramLinkNode } from './ProgramLinkNode'; | ||
|
||
// Link Node Registration. | ||
export type RegisteredLinkNode = AccountLinkNode | DefinedTypeLinkNode | PdaLinkNode | ProgramLinkNode; | ||
export type RegisteredLinkNode = | ||
| AccountLinkNode | ||
| DefinedTypeLinkNode | ||
| InstructionAccountLinkNode | ||
| InstructionArgumentLinkNode | ||
| InstructionLinkNode | ||
| PdaLinkNode | ||
| ProgramLinkNode; | ||
|
||
// Link Node Helpers. | ||
export type LinkNode = RegisteredLinkNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export * from './AccountLinkNode'; | ||
export * from './DefinedTypeLinkNode'; | ||
export * from './InstructionAccountLinkNode'; | ||
export * from './InstructionArgumentLinkNode'; | ||
export * from './InstructionLinkNode'; | ||
export * from './LinkNode'; | ||
export * from './PdaLinkNode'; | ||
export * from './ProgramLinkNode'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/nodes/docs/linkNodes/InstructionAccountLinkNode.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# `InstructionAccountLinkNode` | ||
|
||
This node represents a reference to an existing [`InstructionAccountNode`](../InstructionAccountNode.md) in the Kinobi IDL. | ||
|
||
## Attributes | ||
|
||
### Data | ||
|
||
| Attribute | Type | Description | | ||
| --------- | ------------------------------ | --------------------------------------------------------------------------------------------- | | ||
| `kind` | `"instructionAccountLinkNode"` | The node discriminator. | | ||
| `name` | `CamelCaseString` | The name of the [`InstructionAccountNode`](../InstructionAccountNode.md) we are referring to. | | ||
|
||
### Children | ||
|
||
| Attribute | Type | Description | | ||
| ------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `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. | | ||
|
||
## Functions | ||
|
||
### `instructionAccountLinkNode(name, instruction?)` | ||
|
||
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. | ||
|
||
```ts | ||
// Links to an account in the current instruction. | ||
const node = instructionAccountLinkNode('myAccount'); | ||
|
||
// Links to an account in another instruction but within the same program. | ||
const nodeFromAnotherInstruction = instructionAccountLinkNode('myAccount', 'myOtherInstruction'); | ||
|
||
// Links to an account in another instruction from another program. | ||
const nodeFromAnotherProgram = instructionAccountLinkNode( | ||
'myAccount', | ||
instructionLinkNode('myOtherInstruction', 'myOtherProgram'), | ||
); | ||
``` |
38 changes: 38 additions & 0 deletions
38
packages/nodes/docs/linkNodes/InstructionArgumentLinkNode.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# `InstructionArgumentLinkNode` | ||
|
||
This node represents a reference to an existing [`InstructionArgumentNode`](../InstructionArgumentNode.md) in the Kinobi IDL. | ||
|
||
## Attributes | ||
|
||
### Data | ||
|
||
| Attribute | Type | Description | | ||
| --------- | ------------------------------- | ----------------------------------------------------------------------------------------------- | | ||
| `kind` | `"instructionArgumentLinkNode"` | The node discriminator. | | ||
| `name` | `CamelCaseString` | The name of the [`InstructionArgumentNode`](../InstructionArgumentNode.md) we are referring to. | | ||
|
||
### Children | ||
|
||
| Attribute | Type | Description | | ||
| ------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `instruction` | [`InstructionLinkNode`](./InstructionLinkNode.md) | (Optional) The instruction associated with the linked argument. Default to using the instruction we are currently under. Note that the instruction itself can point to a different program is needed. | | ||
|
||
## Functions | ||
|
||
### `instructionArgumentLinkNode(name, instruction?)` | ||
|
||
Helper function that creates an `InstructionArgumentLinkNode` object from the name of the `InstructionArgumentNode` we are referring to. If the argument 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. | ||
|
||
```ts | ||
// Links to an argument in the current instruction. | ||
const node = instructionArgumentLinkNode('myArgument'); | ||
|
||
// Links to an argument in another instruction but within the same program. | ||
const nodeFromAnotherInstruction = instructionArgumentLinkNode('myArgument', 'myOtherInstruction'); | ||
|
||
// Links to an argument in another instruction from another program. | ||
const nodeFromAnotherProgram = instructionArgumentLinkNode( | ||
'myArgument', | ||
instructionLinkNode('myOtherInstruction', 'myOtherProgram'), | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# `InstructionLinkNode` | ||
|
||
This node represents a reference to an existing [`InstructionNode`](../InstructionNode.md) in the Kinobi IDL. | ||
|
||
## Attributes | ||
|
||
### Data | ||
|
||
| Attribute | Type | Description | | ||
| --------- | ----------------------- | ------------------------------------------------------------------------------- | | ||
| `kind` | `"instructionLinkNode"` | The node discriminator. | | ||
| `name` | `CamelCaseString` | The name of the [`InstructionNode`](../InstructionNode.md) we are referring to. | | ||
|
||
### Children | ||
|
||
| Attribute | Type | Description | | ||
| --------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | | ||
| `program` | [`ProgramLinkNode`](./ProgramLinkNode.md) | (Optional) The program associated with the linked instruction. Default to using the program we are currently under. | | ||
|
||
## Functions | ||
|
||
### `instructionLinkNode(name, program?)` | ||
|
||
Helper function that creates an `InstructionLinkNode` object from the name of the `InstructionNode` we are referring to. If the instruction is from another program, the `program` parameter must be provided as either a `string` or a `ProgramLinkNode`. | ||
|
||
```ts | ||
const node = instructionLinkNode('myInstruction'); | ||
const nodeFromAnotherProgram = instructionLinkNode('myInstruction', 'myOtherProgram'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/nodes/src/linkNodes/InstructionAccountLinkNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { InstructionAccountLinkNode, InstructionLinkNode } from '@kinobi-so/node-types'; | ||
|
||
import { camelCase } from '../shared'; | ||
import { instructionLinkNode } from './InstructionLinkNode'; | ||
|
||
export function instructionAccountLinkNode( | ||
name: string, | ||
instruction?: InstructionLinkNode | string, | ||
): InstructionAccountLinkNode { | ||
return Object.freeze({ | ||
kind: 'instructionAccountLinkNode', | ||
|
||
// Children. | ||
...(instruction === undefined | ||
? {} | ||
: { instruction: typeof instruction === 'string' ? instructionLinkNode(instruction) : instruction }), | ||
|
||
// Data. | ||
name: camelCase(name), | ||
}); | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/nodes/src/linkNodes/InstructionArgumentLinkNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { InstructionArgumentLinkNode, InstructionLinkNode } from '@kinobi-so/node-types'; | ||
|
||
import { camelCase } from '../shared'; | ||
import { instructionLinkNode } from './InstructionLinkNode'; | ||
|
||
export function instructionArgumentLinkNode( | ||
name: string, | ||
instruction?: InstructionLinkNode | string, | ||
): InstructionArgumentLinkNode { | ||
return Object.freeze({ | ||
kind: 'instructionArgumentLinkNode', | ||
|
||
// Children. | ||
...(instruction === undefined | ||
? {} | ||
: { instruction: typeof instruction === 'string' ? instructionLinkNode(instruction) : instruction }), | ||
|
||
// Data. | ||
name: camelCase(name), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { InstructionLinkNode, ProgramLinkNode } from '@kinobi-so/node-types'; | ||
|
||
import { camelCase } from '../shared'; | ||
import { programLinkNode } from './ProgramLinkNode'; | ||
|
||
export function instructionLinkNode(name: string, program?: ProgramLinkNode | string): InstructionLinkNode { | ||
return Object.freeze({ | ||
kind: 'instructionLinkNode', | ||
|
||
// Children. | ||
...(program === undefined ? {} : { program: typeof program === 'string' ? programLinkNode(program) : program }), | ||
|
||
// Data. | ||
name: camelCase(name), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export * from './AccountLinkNode'; | ||
export * from './DefinedTypeLinkNode'; | ||
export * from './InstructionAccountLinkNode'; | ||
export * from './InstructionArgumentLinkNode'; | ||
export * from './InstructionLinkNode'; | ||
export * from './LinkNode'; | ||
export * from './PdaLinkNode'; | ||
export * from './ProgramLinkNode'; |
13 changes: 13 additions & 0 deletions
13
packages/nodes/test/linkNodes/InstructionAccountLinkNode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect, test } from 'vitest'; | ||
|
||
import { instructionAccountLinkNode } from '../../src'; | ||
|
||
test('it returns the right node kind', () => { | ||
const node = instructionAccountLinkNode('mint'); | ||
expect(node.kind).toBe('instructionAccountLinkNode'); | ||
}); | ||
|
||
test('it returns a frozen object', () => { | ||
const node = instructionAccountLinkNode('mint'); | ||
expect(Object.isFrozen(node)).toBe(true); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/nodes/test/linkNodes/InstructionArgumentLinkNode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect, test } from 'vitest'; | ||
|
||
import { instructionArgumentLinkNode } from '../../src'; | ||
|
||
test('it returns the right node kind', () => { | ||
const node = instructionArgumentLinkNode('amount'); | ||
expect(node.kind).toBe('instructionArgumentLinkNode'); | ||
}); | ||
|
||
test('it returns a frozen object', () => { | ||
const node = instructionArgumentLinkNode('amount'); | ||
expect(Object.isFrozen(node)).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect, test } from 'vitest'; | ||
|
||
import { instructionLinkNode } from '../../src'; | ||
|
||
test('it returns the right node kind', () => { | ||
const node = instructionLinkNode('transferTokens'); | ||
expect(node.kind).toBe('instructionLinkNode'); | ||
}); | ||
|
||
test('it returns a frozen object', () => { | ||
const node = instructionLinkNode('transferTokens'); | ||
expect(Object.isFrozen(node)).toBe(true); | ||
}); |
Oops, something went wrong.