Skip to content

Commit be4576d

Browse files
committed
Adapt structure visitors to Codama v2
1 parent f8fe739 commit be4576d

42 files changed

Lines changed: 2704 additions & 928 deletions

File tree

Some content is hidden

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

‎packages/errors/src/codes.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
export const CODAMA_ERROR__UNRECOGNIZED_NODE_KIND = 1;
2929
export const CODAMA_ERROR__UNEXPECTED_NODE_KIND = 2;
30+
/** @deprecated No longer thrown as of Codama v2, which removed nested type node wrappers. */
3031
export const CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND = 3;
3132
export const CODAMA_ERROR__LINKED_NODE_NOT_FOUND = 4;
3233
export const CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE = 5;
@@ -50,11 +51,12 @@ export const CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND = 1200005;
5051
export const CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER = 1200006;
5152
export const CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION = 1200007;
5253
export const CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE = 1200008;
53-
export const CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND = 1200009;
54+
export const CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_DATA_FIELD_NOT_FOUND = 1200009;
5455
export const CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES = 1200010;
5556
export const CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND = 1200011;
5657
export const CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK = 1200012;
5758
export const CODAMA_ERROR__VISITORS__INVALID_PROVIDED_VALUE = 1200013;
59+
export const CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_PLUGINS = 1200014;
5860

5961
// Anchor-related errors.
6062
// Reserve error codes in the range [2100000-2100999].
@@ -158,11 +160,12 @@ export type CodamaErrorCode =
158160
| typeof CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES
159161
| typeof CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION
160162
| typeof CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES
163+
| typeof CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_PLUGINS
161164
| typeof CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK
162165
| typeof CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE
163166
| typeof CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES
164167
| typeof CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE
165-
| typeof CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND
168+
| typeof CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_DATA_FIELD_NOT_FOUND
166169
| typeof CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY
167170
| typeof CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER
168171
| typeof CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES

‎packages/errors/src/context.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ import {
7070
CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES,
7171
CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION,
7272
CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES,
73+
CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_PLUGINS,
7374
CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK,
7475
CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE,
7576
CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES,
7677
CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE,
77-
CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND,
78+
CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_DATA_FIELD_NOT_FOUND,
7879
CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY,
7980
CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER,
8081
CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES,
@@ -271,6 +272,10 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
271272
[CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES]: {
272273
conflictingAttributes: IdentifierString[];
273274
};
275+
[CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_PLUGINS]: {
276+
field: StructFieldTypeNode;
277+
fieldName: IdentifierString;
278+
};
274279
[CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK]: {
275280
path: readonly Node[];
276281
};
@@ -293,8 +298,8 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
293298
formattedHistogram: string;
294299
validationItems: readonly ValidationItem[];
295300
};
296-
[CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]: {
297-
argumentName: IdentifierString;
301+
[CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_DATA_FIELD_NOT_FOUND]: {
302+
fieldName: IdentifierString;
298303
instruction: InstructionNode;
299304
instructionName: IdentifierString;
300305
};

‎packages/errors/src/messages.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ import {
5151
CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES,
5252
CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION,
5353
CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES,
54+
CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_PLUGINS,
5455
CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK,
5556
CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE,
5657
CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES,
5758
CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE,
58-
CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND,
59+
CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_DATA_FIELD_NOT_FOUND,
5960
CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY,
6061
CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER,
6162
CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES,
@@ -139,14 +140,16 @@ export const CodamaErrorMessages: Readonly<{
139140
'Cannot extend visitor with function [$visitFunction] as the base visitor does not support it.',
140141
[CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES]:
141142
'Cannot flatten struct since this would cause the following attributes to conflict [$conflictingAttributes].',
143+
[CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_PLUGINS]:
144+
'Cannot flatten the struct of field [$fieldName] since it carries plugins that would be lost.',
142145
[CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK]: 'Cannot remove the last path in the node stack.',
143146
[CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE]:
144147
'Cannot use optional account [$seedValueName] as the [$seedName] PDA seed for the [$instructionAccountName] account of the [$instructionName] instruction.',
145148
[CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES]:
146149
'Circular dependency detected when resolving the default values of the [$instructionName] instruction. Got the following dependency cycle [$formattedCycle].',
147150
[CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE]: 'Failed to validate the given node [$formattedHistogram].',
148-
[CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]:
149-
'Could not find an enum argument named [$argumentName] for instruction [$instructionName].',
151+
[CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_DATA_FIELD_NOT_FOUND]:
152+
'Could not find an enum data field named [$fieldName] for instruction [$instructionName].',
150153
[CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY]:
151154
'Dependency [$dependencyName] of kind [$dependencyKind] is not a valid dependency of [$parentName] of kind [$parentKind] in the [$instructionName] instruction.',
152155
[CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER]: 'Invalid number wrapper kind [$wrapper].',

‎packages/nodes-from-anchor/src/defaultVisitor.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { assertIsNode, Node, RootNode } from '@codama/nodes';
22
import {
33
deduplicateIdenticalDefinedTypesVisitor,
4-
flattenInstructionDataArgumentsVisitor,
4+
flattenInstructionDataVisitor,
55
getCommonInstructionAccountDefaultRules,
66
rootNodeVisitor,
77
setFixedAccountSizesVisitor,
88
setInstructionAccountDefaultValuesVisitor,
99
transformU8ArraysToBytesVisitor,
10-
unwrapInstructionArgsDefinedTypesVisitor,
10+
unwrapInstructionDataDefinedTypesVisitor,
1111
visit,
1212
Visitor,
1313
} from '@codama/visitors';
@@ -34,8 +34,8 @@ export function defaultVisitor() {
3434

3535
// Instructions.
3636
updateRoot(setInstructionAccountDefaultValuesVisitor(getCommonInstructionAccountDefaultRules()));
37-
updateRoot(unwrapInstructionArgsDefinedTypesVisitor());
38-
updateRoot(flattenInstructionDataArgumentsVisitor());
37+
updateRoot(unwrapInstructionDataDefinedTypesVisitor());
38+
updateRoot(flattenInstructionDataVisitor());
3939

4040
// Extras.
4141
updateRoot(transformU8ArraysToBytesVisitor());

0 commit comments

Comments
 (0)