Skip to content

Commit 93a318a

Browse files
authored
Add program to link nodes and update LinkableDictionary (#180)
1 parent 00e7e26 commit 93a318a

22 files changed

+293
-101
lines changed

.changeset/tough-grapes-give.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@kinobi-so/visitors-core': minor
3+
'@kinobi-so/node-types': minor
4+
'@kinobi-so/nodes': minor
5+
'@kinobi-so/visitors': patch
6+
'@kinobi-so/errors': patch
7+
---
8+
9+
Add optional `program` attribute to link nodes and namespace linkable nodes under their associated program.

packages/errors/src/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export type KinobiErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
7575
kind: LinkNode['kind'];
7676
linkNode: LinkNode;
7777
name: CamelCaseString;
78+
program?: CamelCaseString;
7879
};
7980
[KINOBI_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: {
8081
fsFunction: string;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type { CamelCaseString } from '../shared';
2+
import type { ProgramLinkNode } from './ProgramLinkNode';
23

3-
export interface AccountLinkNode {
4+
export interface AccountLinkNode<TProgram extends ProgramLinkNode | undefined = ProgramLinkNode | undefined> {
45
readonly kind: 'accountLinkNode';
56

7+
// Children.
8+
readonly program?: TProgram;
9+
610
// Data.
711
readonly name: CamelCaseString;
812
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type { CamelCaseString } from '../shared';
2+
import type { ProgramLinkNode } from './ProgramLinkNode';
23

3-
export interface DefinedTypeLinkNode {
4+
export interface DefinedTypeLinkNode<TProgram extends ProgramLinkNode | undefined = ProgramLinkNode | undefined> {
45
readonly kind: 'definedTypeLinkNode';
56

7+
// Children.
8+
readonly program?: TProgram;
9+
610
// Data.
711
readonly name: CamelCaseString;
812
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type { CamelCaseString } from '../shared';
2+
import type { ProgramLinkNode } from './ProgramLinkNode';
23

3-
export interface PdaLinkNode {
4+
export interface PdaLinkNode<TProgram extends ProgramLinkNode | undefined = ProgramLinkNode | undefined> {
45
readonly kind: 'pdaLinkNode';
56

7+
// Children.
8+
readonly program?: TProgram;
9+
610
// Data.
711
readonly name: CamelCaseString;
812
}

packages/nodes/docs/linkNodes/AccountLinkNode.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ This node represents a reference to an existing [`AccountNode`](../AccountNode.m
1313

1414
### Children
1515

16-
_This node has no children._
16+
| Attribute | Type | Description |
17+
| --------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
18+
| `program` | [`ProgramLinkNode`](./ProgramLinkNode.md) | (Optional) The program associated with the linked account. Default to using the program we are currently under. |
1719

1820
## Functions
1921

20-
### `accountLinkNode(name)`
22+
### `accountLinkNode(name, program?)`
2123

22-
Helper function that creates a `AccountLinkNode` object from the name of the `AccountNode` we are referring to.
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`.
2325

2426
```ts
2527
const node = accountLinkNode('myAccount');
28+
const nodeFromAnotherProgram = accountLinkNode('myAccount', 'myOtherProgram');
2629
```

packages/nodes/docs/linkNodes/DefinedTypeLinkNode.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ This node represents a reference to an existing [`DefinedTypeNode`](../DefinedTy
1313

1414
### Children
1515

16-
_This node has no children._
16+
| Attribute | Type | Description |
17+
| --------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
18+
| `program` | [`ProgramLinkNode`](./ProgramLinkNode.md) | (Optional) The program associated with the linked type. Default to using the program we are currently under. |
1719

1820
## Functions
1921

20-
### `definedTypeLinkNode(name)`
22+
### `definedTypeLinkNode(name, program?)`
2123

22-
Helper function that creates a `DefinedTypeLinkNode` object from the name of the `DefinedTypeNode` we are referring to.
24+
Helper function that creates a `DefinedTypeLinkNode` object from the name of the `DefinedTypeNode` we are referring to. If the defined type is from another program, the `program` parameter must be provided as either a `string` or a `ProgramLinkNode`.
2325

2426
```ts
2527
const node = definedTypeLinkNode('myDefinedType');
28+
const nodeFromAnotherProgram = definedTypeLinkNode('myDefinedType', 'myOtherProgram');
2629
```

packages/nodes/docs/linkNodes/PdaLinkNode.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ This node represents a reference to an existing [`PdaNode`](../PdaNode.md) in th
1313

1414
### Children
1515

16-
_This node has no children._
16+
| Attribute | Type | Description |
17+
| --------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
18+
| `program` | [`ProgramLinkNode`](./ProgramLinkNode.md) | (Optional) The program associated with the linked PDA. Default to using the program we are currently under. |
1719

1820
## Functions
1921

20-
### `pdaLinkNode(name)`
22+
### `pdaLinkNode(name, program?)`
2123

22-
Helper function that creates a `PdaLinkNode` object from the name of the `PdaNode` we are referring to.
24+
Helper function that creates a `PdaLinkNode` object from the name of the `PdaNode` we are referring to. If the PDA is from another program, the `program` parameter must be provided as either a `string` or a `ProgramLinkNode`.
2325

2426
```ts
2527
const node = pdaLinkNode('myPda');
28+
const nodeFromAnotherProgram = pdaLinkNode('myPda', 'myOtherProgram');
2629
```

packages/nodes/src/linkNodes/AccountLinkNode.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import type { AccountLinkNode } from '@kinobi-so/node-types';
1+
import type { AccountLinkNode, ProgramLinkNode } from '@kinobi-so/node-types';
22

33
import { camelCase } from '../shared';
4+
import { programLinkNode } from './ProgramLinkNode';
45

5-
export function accountLinkNode(name: string): AccountLinkNode {
6+
export function accountLinkNode(name: string, program?: ProgramLinkNode | string): AccountLinkNode {
67
return Object.freeze({
78
kind: 'accountLinkNode',
89

10+
// Children.
11+
...(program === undefined ? {} : { program: typeof program === 'string' ? programLinkNode(program) : program }),
12+
913
// Data.
1014
name: camelCase(name),
1115
});

packages/nodes/src/linkNodes/DefinedTypeLinkNode.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import type { DefinedTypeLinkNode } from '@kinobi-so/node-types';
1+
import type { DefinedTypeLinkNode, ProgramLinkNode } from '@kinobi-so/node-types';
22

33
import { camelCase } from '../shared';
4+
import { programLinkNode } from './ProgramLinkNode';
45

5-
export function definedTypeLinkNode(name: string): DefinedTypeLinkNode {
6+
export function definedTypeLinkNode(name: string, program?: ProgramLinkNode | string): DefinedTypeLinkNode {
67
return Object.freeze({
78
kind: 'definedTypeLinkNode',
89

10+
// Children.
11+
...(program === undefined ? {} : { program: typeof program === 'string' ? programLinkNode(program) : program }),
12+
913
// Data.
1014
name: camelCase(name),
1115
});

0 commit comments

Comments
 (0)