Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nodes generic interfaces #195

Merged
merged 26 commits into from
Apr 9, 2024
Prev Previous commit
Next Next commit
wip
lorisleiva committed Apr 8, 2024
commit 81403f5c1ad6af0bce812a054efd733a904302dd
2 changes: 1 addition & 1 deletion src/nodes/AccountNode.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import { PdaLinkNode, pdaLinkNode } from './linkNodes';
import { StructTypeNode, structTypeNode } from './typeNodes';
import { createTypeNodeFromIdl } from './typeNodes/TypeNode';

export type AccountNode = {
export interface AccountNode {
readonly kind: 'accountNode';

// Children.
4 changes: 2 additions & 2 deletions src/nodes/DefinedTypeNode.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import type { IdlDefinedType } from '../idl';
import { InvalidKinobiTreeError, MainCaseString, mainCase } from '../shared';
import { TypeNode, createTypeNodeFromIdl } from './typeNodes/TypeNode';

export type DefinedTypeNode = {
export interface DefinedTypeNode {
readonly kind: 'definedTypeNode';

// Children.
@@ -12,7 +12,7 @@ export type DefinedTypeNode = {
readonly name: MainCaseString;
readonly idlName: string;
readonly docs: string[];
};
}

export type DefinedTypeNodeInput = {
readonly name: string;
4 changes: 2 additions & 2 deletions src/nodes/ErrorNode.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import {
mainCase,
} from '../shared';

export type ErrorNode = {
export interface ErrorNode {
readonly kind: 'errorNode';

// Data.
@@ -15,7 +15,7 @@ export type ErrorNode = {
readonly code: number;
readonly message: string;
readonly docs: string[];
};
}

export type ErrorNodeInput = Omit<
PartialExcept<ErrorNode, 'name' | 'code' | 'message'>,
4 changes: 2 additions & 2 deletions src/nodes/InstructionAccountNode.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { IdlInstructionAccount } from '../idl';
import { MainCaseString, PartialExcept, mainCase } from '../shared';
import { InstructionInputValueNode } from './contextualValueNodes';

export type InstructionAccountNode = {
export interface InstructionAccountNode {
readonly kind: 'instructionAccountNode';

// Children.
@@ -14,7 +14,7 @@ export type InstructionAccountNode = {
readonly isSigner: boolean | 'either';
readonly isOptional: boolean;
readonly docs: string[];
};
}

export type InstructionAccountNodeInput = Omit<
PartialExcept<InstructionAccountNode, 'isWritable' | 'isSigner'>,
4 changes: 2 additions & 2 deletions src/nodes/InstructionArgumentNode.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import {
} from './typeNodes';
import { VALUE_NODES } from './valueNodes';

export type InstructionArgumentNode = {
export interface InstructionArgumentNode {
readonly kind: 'instructionArgumentNode';

// Children.
@@ -21,7 +21,7 @@ export type InstructionArgumentNode = {
readonly name: MainCaseString;
readonly docs: string[];
readonly defaultValueStrategy?: 'optional' | 'omitted';
};
}

export type InstructionArgumentNodeInput = {
readonly name: string;
4 changes: 2 additions & 2 deletions src/nodes/InstructionByteDeltaNode.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { ArgumentValueNode, ResolverValueNode } from './contextualValueNodes';
import { AccountLinkNode } from './linkNodes';
import { NumberValueNode } from './valueNodes';

export type InstructionByteDeltaNode = {
export interface InstructionByteDeltaNode {
readonly kind: 'instructionByteDeltaNode';

// Children.
@@ -16,7 +16,7 @@ export type InstructionByteDeltaNode = {
// Data.
readonly withHeader: boolean;
readonly subtract?: boolean;
};
}

export function instructionByteDeltaNode(
value: InstructionByteDeltaNode['value'],
4 changes: 2 additions & 2 deletions src/nodes/InstructionNode.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import {
import { createTypeNodeFromIdl } from './typeNodes/TypeNode';
import { numberValueNode } from './valueNodes';

export type InstructionNode = {
export interface InstructionNode {
readonly kind: 'instructionNode';

// Children.
@@ -38,7 +38,7 @@ export type InstructionNode = {
readonly idlName: string;
readonly docs: string[];
readonly optionalAccountStrategy: 'omitted' | 'programId';
};
}

export type InstructionNodeInput = Omit<
Partial<InstructionNode>,
4 changes: 2 additions & 2 deletions src/nodes/InstructionRemainingAccountsNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArgumentValueNode, ResolverValueNode } from './contextualValueNodes';

export type InstructionRemainingAccountsNode = {
export interface InstructionRemainingAccountsNode {
readonly kind: 'instructionRemainingAccountsNode';

// Children.
@@ -10,7 +10,7 @@ export type InstructionRemainingAccountsNode = {
readonly isOptional?: boolean;
readonly isSigner?: boolean | 'either';
readonly isWritable?: boolean;
};
}

export type InstructionRemainingAccountsNodeInput = Omit<
InstructionRemainingAccountsNode,
4 changes: 2 additions & 2 deletions src/nodes/PdaNode.ts
Original file line number Diff line number Diff line change
@@ -17,15 +17,15 @@ import {
stringValueNode,
} from './valueNodes';

export type PdaNode = {
export interface PdaNode {
readonly kind: 'pdaNode';

// Children.
readonly seeds: PdaSeedNode[];

// Data.
readonly name: MainCaseString;
};
}

export function pdaNode(name: string, seeds: PdaSeedNode[]): PdaNode {
if (!name) {
4 changes: 2 additions & 2 deletions src/nodes/ProgramNode.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import { ErrorNode, errorNodeFromIdl } from './ErrorNode';
import { InstructionNode, instructionNodeFromIdl } from './InstructionNode';
import { PdaNode, pdaNodeFromIdl } from './PdaNode';

export type ProgramNode = {
export interface ProgramNode {
readonly kind: 'programNode';

// Children.
@@ -22,7 +22,7 @@ export type ProgramNode = {
readonly publicKey: string;
readonly version: string;
readonly origin?: 'shank' | 'anchor';
};
}

export type ProgramNodeInput = Omit<
PartialExcept<ProgramNode, 'publicKey'>,
4 changes: 2 additions & 2 deletions src/nodes/RootNode.ts
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@ import { ProgramNode, programNodeFromIdl } from './ProgramNode';

export type IdlInputs = string | Partial<Idl> | (string | Partial<Idl>)[];

export type RootNode = {
export interface RootNode {
readonly kind: 'rootNode';

// Children.
readonly programs: ProgramNode[];
};
}

export function rootNode(programs: ProgramNode[]): RootNode {
return { kind: 'rootNode', programs };
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/ArgumentValueNode.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MainCaseString, mainCase } from '../../shared';

export type ArgumentValueNode = {
export interface ArgumentValueNode {
readonly kind: 'argumentValueNode';

// Data.
readonly name: MainCaseString;
};
}

export function argumentValueNode(name: string): ArgumentValueNode {
return { kind: 'argumentValueNode', name: mainCase(name) };
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/ConditionalValueNode.ts
Original file line number Diff line number Diff line change
@@ -11,15 +11,15 @@ export type ConditionalValueBranch = InstructionInputValueNode;

export const CONDITIONAL_VALUE_BRANCH_NODES = INSTRUCTION_INPUT_VALUE_NODE;

export type ConditionalValueNode = {
export interface ConditionalValueNode {
readonly kind: 'conditionalValueNode';

// Children.
readonly condition: ResolverValueNode | AccountValueNode | ArgumentValueNode;
readonly value?: ValueNode;
readonly ifTrue?: ConditionalValueBranch;
readonly ifFalse?: ConditionalValueBranch;
};
}

export function conditionalValueNode(input: {
condition: ConditionalValueNode['condition'];
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/IdentityValueNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type IdentityValueNode = {
export interface IdentityValueNode {
readonly kind: 'identityValueNode';
};
}

export function identityValueNode(): IdentityValueNode {
return { kind: 'identityValueNode' };
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/PayerValueNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type PayerValueNode = {
export interface PayerValueNode {
readonly kind: 'payerValueNode';
};
}

export function payerValueNode(): PayerValueNode {
return { kind: 'payerValueNode' };
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/PdaSeedValueNode.ts
Original file line number Diff line number Diff line change
@@ -3,15 +3,15 @@ import { ValueNode } from '../valueNodes';
import { AccountValueNode } from './AccountValueNode';
import { ArgumentValueNode } from './ArgumentValueNode';

export type PdaSeedValueNode = {
export interface PdaSeedValueNode {
readonly kind: 'pdaSeedValueNode';

// Children.
readonly value: ValueNode | AccountValueNode | ArgumentValueNode;

// Data.
readonly name: MainCaseString;
};
}

export function pdaSeedValueNode(
name: string,
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/PdaValueNode.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PdaLinkNode, pdaLinkNode } from '../linkNodes';
import { PdaSeedValueNode } from './PdaSeedValueNode';

export type PdaValueNode = {
export interface PdaValueNode {
readonly kind: 'pdaValueNode';

// Children.
readonly pda: PdaLinkNode;
readonly seeds: PdaSeedValueNode[];
};
}

export function pdaValueNode(
pda: PdaLinkNode | string,
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/ProgramIdValueNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type ProgramIdValueNode = {
export interface ProgramIdValueNode {
readonly kind: 'programIdValueNode';
};
}

export function programIdValueNode(): ProgramIdValueNode {
return { kind: 'programIdValueNode' };
4 changes: 2 additions & 2 deletions src/nodes/contextualValueNodes/ResolverValueNode.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { ImportFrom, MainCaseString, mainCase } from '../../shared';
import { AccountValueNode } from './AccountValueNode';
import { ArgumentValueNode } from './ArgumentValueNode';

export type ResolverValueNode = {
export interface ResolverValueNode {
readonly kind: 'resolverValueNode';

// Children.
@@ -11,7 +11,7 @@ export type ResolverValueNode = {
// Data.
readonly name: MainCaseString;
readonly importFrom?: ImportFrom;
};
}

export function resolverValueNode(
name: string,
4 changes: 2 additions & 2 deletions src/nodes/countNodes/FixedCountNode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export type FixedCountNode = {
export interface FixedCountNode {
readonly kind: 'fixedCountNode';

// Data.
readonly value: number;
};
}

export function fixedCountNode(value: number): FixedCountNode {
return { kind: 'fixedCountNode', value };
4 changes: 2 additions & 2 deletions src/nodes/countNodes/RemainderCountNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type RemainderCountNode = {
export interface RemainderCountNode {
readonly kind: 'remainderCountNode';
};
}

export function remainderCountNode(): RemainderCountNode {
return { kind: 'remainderCountNode' };
4 changes: 2 additions & 2 deletions src/nodes/discriminatorNodes/ByteDiscriminatorNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getBase58Encoder } from '@solana/codecs-strings';

export type ByteDiscriminatorNode = {
export interface ByteDiscriminatorNode {
readonly kind: 'byteDiscriminatorNode';

// Data.
readonly bytes: number[];
readonly offset: number;
};
}

export function byteDiscriminatorNode(
bytes: number[],
4 changes: 2 additions & 2 deletions src/nodes/discriminatorNodes/FieldDiscriminatorNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MainCaseString, mainCase } from '../../shared';

export type FieldDiscriminatorNode = {
export interface FieldDiscriminatorNode {
readonly kind: 'fieldDiscriminatorNode';

// Data.
readonly name: MainCaseString;
readonly offset: number;
};
}

export function fieldDiscriminatorNode(
name: string,
4 changes: 2 additions & 2 deletions src/nodes/discriminatorNodes/SizeDiscriminatorNode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export type SizeDiscriminatorNode = {
export interface SizeDiscriminatorNode {
readonly kind: 'sizeDiscriminatorNode';

// Data.
readonly size: number;
};
}

export function sizeDiscriminatorNode(size: number): SizeDiscriminatorNode {
return { kind: 'sizeDiscriminatorNode', size };
4 changes: 2 additions & 2 deletions src/nodes/linkNodes/AccountLinkNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ImportFrom, MainCaseString, mainCase } from '../../shared';

export type AccountLinkNode = {
export interface AccountLinkNode {
readonly kind: 'accountLinkNode';

// Data.
readonly name: MainCaseString;
readonly importFrom?: ImportFrom;
};
}

export function accountLinkNode(
name: string,
4 changes: 2 additions & 2 deletions src/nodes/linkNodes/DefinedTypeLinkNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ImportFrom, MainCaseString, mainCase } from '../../shared';

export type DefinedTypeLinkNode = {
export interface DefinedTypeLinkNode {
readonly kind: 'definedTypeLinkNode';

// Data.
readonly name: MainCaseString;
readonly importFrom?: ImportFrom;
};
}

export function definedTypeLinkNode(
name: string,
Loading