Skip to content

feat(dynamic-client): types generation split#1002

Open
mikhd wants to merge 3 commits into
codama-idl:mainfrom
hoodieshq:feat/pr3-typesgen-split
Open

feat(dynamic-client): types generation split#1002
mikhd wants to merge 3 commits into
codama-idl:mainfrom
hoodieshq:feat/pr3-typesgen-split

Conversation

@mikhd

@mikhd mikhd commented May 28, 2026

Copy link
Copy Markdown
Contributor

Description

This PR [3] splits types generation between dynamic-instructions, dynamic-address-resolution, dynamic-client. Each package now owns the types for the concepts it implements, dynamic-client composes them.

Change

  • Moved type generation methods into corresponding package. Exported by separate /codegen path.
  • @codama/dynamic-address-resolution/codegen — Address input types ${Name}Args/Accounts/Resolvers (the resolution input contracts), types helpers, shared generateTypesFromFile IO helper (keep it here for now, known inconsistency).
  • @codama/dynamic-instructions/codegen${Name}Signers aliases + ${Program}InstructionBuilders map.
  • Both new packages get their own commander CLI (generate-types) plus a /codegen subpath export.
  • @codama/dynamic-client becomes a composer that reuses those primitives and emits the program-level ${Program}Methods / ${Program}Client shapes.
  • Known overhead - commander cli scaffolding duplication with few test helpers.

Commands:

dynamic-address-resolution:

npx @codama/dynamic-address-resolution generate-types <path/to/idl.json> <output-dir>

dynamic-instructions:

npx @codama/dynamic-instructions generate-types <path/to/idl.json> <output-dir>

dynamic-client:

Unchanged.

@changeset-bot

changeset-bot Bot commented May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f696e45

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

This PR includes changesets to release 3 packages
Name Type
@codama/dynamic-address-resolution Minor
@codama/dynamic-instructions Minor
@codama/dynamic-client Patch

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

});

test('should match the structural shape of the runtime ResolverFn', () => {
type EmittedResolverFn<TArgs, TAccs> = (argumentsInput: TArgs, accountsInput: TAccs) => Promise<unknown>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This tests describes this type, do I get it correct?
https://github.com/codama-idl/codama/pull/1002/changes#diff-5dfc0f859cdeec27dc82baf5989aa624af82fb012533312eaa233ab57703b45eR21-R23
If yes, i think it is worth to import it and test it directly as this might potentially degrade at some point

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, added a separate toMatchInlineSnapshot test that pins the RESOLVER_FN_DECLARATION string verbatim — so if the emitted declaration ever changes, that test fails.

378a1bb

mikhd added 3 commits June 5, 2026 10:27
* feat(dynamic-address-resolution): extract type generation

* feat(dynamic-instructions): extract type generation

* feat(dynamic-client): adjust type generation

* feat: refactor generateTypesFromFile

* chore: add tests

* fix: cleanup

* fix: improve codegen

* chore: add minimum tests

* fix: rebasing issues

* fix(dynamic-instructions): types generation in readme

* fix: remove generateInstructionBuildersMap from public api

* fix: refactor codegen helpers

  - Add getResolutionRefs (DAR) with hasRequiredArgs/hasRequiredRemainingAccounts so dynamic-client stops re-deriving args optionality.
  - Extract collectEitherSignerNames (DI) and rename DAR's instruction-types files to generate-resolution-input-types / get-resolution-refs.
  - Emit a local non-exported ResolverFn declaration inside generated files.
  - Pre-compute PDA seed entries to remove the duplicate variableSeeds filter.
  - README update

* chore: add comments

* fix: tighten accounts ref

- keep widened ref with withData suffix

* fix: redundant nullish operator

* fix: add space to unknown comments
@mikhd mikhd force-pushed the feat/pr3-typesgen-split branch from 378a1bb to f696e45 Compare June 5, 2026 07:27
@mikhd

mikhd commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main.

@lorisleiva lorisleiva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I trust you on these dynamic clients. 🫡

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