Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-plants-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codama/visitors-core': minor
---

Record and resolve `NodePaths` instead of `Nodes` in `LinkableDictionary`
4 changes: 2 additions & 2 deletions packages/errors/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
kind: LinkNode['kind'];
linkNode: LinkNode;
name: CamelCaseString;
stack: Node[];
path: readonly Node[];
};
[CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: {
fsFunction: string;
Expand Down Expand Up @@ -169,7 +169,7 @@ type ValidationItem = {
level: 'debug' | 'error' | 'info' | 'trace' | 'warn';
message: string;
node: Node;
stack: Node[];
path: Node[];
};

export function decodeEncodedContext(encodedContext: string): object {
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers-js-umi/src/getRenderMapVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}): Visitor<
}

// Seeds.
const pda = node.pda ? linkables.get(node.pda, stack) : undefined;
const pda = node.pda ? linkables.get([...stack.getPath(), node.pda]) : undefined;
const pdaSeeds = pda?.seeds ?? [];
const seeds = pdaSeeds.map(seed => {
if (isNode(seed, 'variablePdaSeedNode')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers-js-umi/src/getTypeManifestVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export function getTypeManifestVisitor(input: {
const importFrom = getImportFrom(node.enum);

// FIXME(loris): No program node can ever be in this stack.
const enumNode = linkables.get(node.enum, stack)?.type;
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
const isScalar =
enumNode && isNode(enumNode, 'enumTypeNode')
? isScalarEnum(enumNode)
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers-js/src/fragments/accountPdaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getAccountPdaHelpersFragment(
},
): Fragment {
const { accountNode, accountStack, nameApi, linkables, customAccountData, typeManifest } = scope;
const pdaNode = accountNode.pda ? linkables.get(accountNode.pda, accountStack) : undefined;
const pdaNode = accountNode.pda ? linkables.get([...accountStack.getPath(), accountNode.pda]) : undefined;
if (!pdaNode) {
return fragment('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ function getDefaultAddress(
case 'publicKeyValueNode':
return `"${defaultValue.publicKey}"`;
case 'programLinkNode':
// FIXME(loris): No need for a stack here.
// eslint-disable-next-line no-case-declarations
const programNode = linkables.get(defaultValue, new NodeStack());
const programNode = linkables.get([defaultValue]);
return programNode ? `"${programNode.publicKey}"` : 'string';
case 'programIdValueNode':
return `"${programId}"`;
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers-js/src/getTypeManifestVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export function getTypeManifestVisitor(input: {
const importFrom = getImportFrom(node.enum);

// FIXME(loris): No program node can ever be in this stack.
const enumNode = linkables.get(node.enum, stack)?.type;
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
const isScalar =
enumNode && isNode(enumNode, 'enumTypeNode')
? isScalarEnum(enumNode)
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers-rust/src/getRenderMapVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {

// Seeds.
const seedsImports = new ImportMap();
const pda = node.pda ? linkables.get(node.pda, stack) : undefined;
const pda = node.pda ? linkables.get([...stack.getPath(), node.pda]) : undefined;
const pdaSeeds = pda?.seeds ?? [];
const seeds = pdaSeeds.map(seed => {
if (isNode(seed, 'variablePdaSeedNode')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/validators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type ValidationItem = {
message: string;
// The node that the validation item is related to.
node: Node;
// The stack of nodes that led to the node above.
stack: readonly Node[];
// The path of nodes that led to the node above (including the node itself).
path: readonly Node[];
};
```

Expand Down
4 changes: 2 additions & 2 deletions packages/validators/src/ValidationItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ValidationItem = {
level: LogLevel;
message: string;
node: Node;
stack: readonly Node[];
path: readonly Node[];
};

export function validationItem(
Expand All @@ -21,7 +21,7 @@ export function validationItem(
level,
message,
node,
stack: Array.isArray(stack) ? [...stack] : stack.all(),
path: Array.isArray(stack) ? [...stack] : stack.all(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/validators/src/getValidationItemsVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function getValidationItemsVisitor(): Visitor<readonly ValidationItem[]>
const items = [] as ValidationItem[];
if (!node.name) {
items.push(validationItem('error', 'Pointing to a defined type with no name.', node, stack));
} else if (!linkables.has(node, stack)) {
} else if (!linkables.has(stack.getPath())) {
items.push(
validationItem(
'error',
Expand Down
7 changes: 2 additions & 5 deletions packages/visitors-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,8 @@ It offers the following API:
```ts
const linkables = new LinkableDictionary();

// Record program nodes.
linkables.record(programNode, stack);

// Record other linkable nodes with their associated program node.
linkables.record(accountNode, stack);
// Record linkable nodes via their full path.
linkables.recordPath([rootNode, programNode, accountNode]);

// Get a linkable node using a link node, or throw an error if it is not found.
const programNode = linkables.getOrThrow(programLinkNode, stack);
Expand Down
Loading