Skip to content

feat(nodes): add ConstantNode support with Anchor parsing#958

Open
tanmay4l wants to merge 5 commits intocodama-idl:mainfrom
tanmay4l:t1
Open

feat(nodes): add ConstantNode support with Anchor parsing#958
tanmay4l wants to merge 5 commits intocodama-idl:mainfrom
tanmay4l:t1

Conversation

@tanmay4l
Copy link
Copy Markdown
Contributor

@tanmay4l tanmay4l commented Dec 12, 2025

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 6ea901a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@codama/visitors-core Minor
@codama/nodes-from-anchor Minor
@codama/node-types Minor
@codama/nodes Minor
@codama/cli Patch
@codama/dynamic-codecs Patch
@codama/dynamic-parsers Patch
@codama/renderers-core Patch
@codama/validators Minor
@codama/visitors Minor
@codama/dynamic-client Patch
@codama/errors Minor
codama Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tanmay4l tanmay4l marked this pull request as ready for review December 12, 2025 13:40
@lorisleiva
Copy link
Copy Markdown
Member

Hi, thanks for the PR!

This is looking pretty good. The only thing I'm unsure of is whether on not the ConstantNode should wrap the existing ConstantValueNode which is the existing way for us to describe a type + value combo.

On one hand, this would make the ConstantValueNode the single source of truth for handling constants (visitors just need to add an implementation for this Node and it'll work everywhere in the tree).

On the other hand, this make the ConstantNode a bit awkward because it'll access data by doing something like program.constants[0].constant.value. Maybe something that can be fixed with a better naming convention?

What do you think?

@tanmay4l
Copy link
Copy Markdown
Contributor Author

tanmay4l commented Jan 5, 2026

Hi, thanks for the PR!

This is looking pretty good. The only thing I'm unsure of is whether on not the ConstantNode should wrap the existing ConstantValueNode which is the existing way for us to describe a type + value combo.

On one hand, this would make the ConstantValueNode the single source of truth for handling constants (visitors just need to add an implementation for this Node and it'll work everywhere in the tree).

On the other hand, this make the ConstantNode a bit awkward because it'll access data by doing something like program.constants[0].constant.value. Maybe something that can be fixed with a better naming convention?

What do you think?

hmm interesting point about ConstantValueNode. I kept them separate because program constants need name field, which ConstantValueNode doesn't have. also constants[0].constant.value feels awkward. But I see your point about reuse.
would you prefer I refactor it to wrap ConstantValueNode? happy to change if that's the direction you want

@tanmay4l tanmay4l closed this Mar 30, 2026
@lorisleiva
Copy link
Copy Markdown
Member

Hey sorry for the late reply, I was actually gonna review this properly this week. Are you still okay keeping this PR open? ☺️

@tanmay4l
Copy link
Copy Markdown
Contributor Author

tanmay4l commented Mar 30, 2026

Hey sorry for the late reply, I was actually gonna review this properly this week. Are you still okay keeping this PR open? ☺️

sure haha ( ill resolve conflict )

@tanmay4l tanmay4l reopened this Mar 30, 2026
Copy link
Copy Markdown
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR and again sorry for the super later review.

I've made a few comments, lmk what you think.

I also think you're missing an important test file in the packages/visitors-core/test/nodes folder (e.g. look at the packages/visitors-core/test/nodes/DefinedTypeNode.test.ts file for reference).

P.S.: Don't forget to rebase. ☺️

Comment thread packages/node-types/src/ConstantNode.ts
Comment thread packages/nodes-from-anchor/src/v00/ConstantNode.ts Outdated
Comment thread packages/nodes-from-anchor/src/v01/ConstantNode.ts Outdated
Comment thread packages/nodes-from-anchor/test/v00/ConstantNode.test.ts Outdated
Comment thread packages/nodes-from-anchor/test/v00/ConstantNode.test.ts Outdated
Comment thread packages/nodes/docs/ConstantNode.md Outdated
Comment thread packages/nodes/docs/ConstantNode.md Outdated
Comment thread packages/nodes/docs/ConstantNode.md Outdated
Comment thread tsup.config.base.ts Outdated
Comment thread packages/visitors-core/test/identityVisitor.test.ts Outdated
@alexanderguy
Copy link
Copy Markdown

Bump for this feature getting in. We'd like to use it in https://github.com/faremeter/flex . We can help with review/getting it landed, if anyone needs anything.

@tanmay4l
Copy link
Copy Markdown
Contributor Author

Bump for this feature getting in. We'd like to use it in https://github.com/faremeter/flex . We can help with review/getting it landed, if anyone needs anything.

I apologize for the delay. I’m back now and will push the updated code soon.

@tanmay4l tanmay4l requested a review from lorisleiva April 28, 2026 19:30
Copy link
Copy Markdown
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for the changes! I've just got a few minor comments left but after that we should be good to merge.

Comment thread packages/nodes-from-anchor/src/v01/ConstantNode.ts Outdated
Comment thread packages/nodes-from-anchor/src/v01/ProgramNode.ts Outdated
Comment thread packages/nodes-from-anchor/src/utils.ts Outdated
Comment thread packages/nodes-from-anchor/test/v00/ConstantNode.test.ts
Comment thread packages/nodes-from-anchor/test/v00/ConstantNode.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants