Skip to content

[codegen] move codegen for view function#12

Merged
0o-de-lally merged 15 commits intomainfrom
move-codegen
May 22, 2025
Merged

[codegen] move codegen for view function#12
0o-de-lally merged 15 commits intomainfrom
move-codegen

Conversation

@0o-de-lally
Copy link
Copy Markdown
Collaborator

TypeScript Codegen for Move #[view] Functions:

  • Added a robust code generation tool that parses Move source files for #[view] functions and generates TypeScript sugar functions for each view.

  • Sugar functions are named in the format moduleName_functionName (camelCase for both), e.g. olAccount_balance(address: string).

  • All generated sugar functions are exported from src/views/viewFunctionsSugar.ts.

  • Added a LibraViews namespace/object export, so users can import and use view helpers as:

    import { LibraViews } from "open-libra-sdk";
    LibraViews.olAccount_balance("0x...");
  • Codegen supports deduplication, correct Move-to-TypeScript type mapping, and flexible import paths for dev/prod.

  • Testing:

    • Comprehensive tests for extraction, type mapping, sugar function output, and TypeScript compilation of generated files.
    • E2E test for querying validators using the new sugar functions.
  • Documentation:

    • Updated README with codegen and release instructions for maintainers.
    • Added usage examples for the new LibraViews API.

Changed

  • Project Structure:
    • Moved all generated view helpers to src/views/viewFunctionsSugar.ts.
    • Updated CLI and test scripts to use the new codegen and import paths.

Deprecated

  • Deprecation of payloads:
    • The old payloads constants (e.g., currentValidatorsPayload) are now deprecated.
    • Use the new LibraViews sugar functions instead:
      // Deprecated:
      import { currentValidatorsPayload } from "open-libra-sdk/payloads";
      // New:
      import { LibraViews } from "open-libra-sdk";
      LibraViews.validatorUniverse_getEligibleValidators();
    • The payloads module will be removed in a future release.

Copy link
Copy Markdown

@dboreham dboreham left a comment

Choose a reason for hiding this comment

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

A masterpiece.

Comment thread tests/codegen/generateViewFunctionsSugar.test.ts
Comment thread tests/codegen/parseViewFunctions.test.ts
@0o-de-lally 0o-de-lally changed the title [codegen] Move codegen for view function [codegen] move codegen for view function May 22, 2025
Copy link
Copy Markdown

@sirouk sirouk left a comment

Choose a reason for hiding this comment

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

🔥

@0o-de-lally 0o-de-lally merged commit 696b826 into main May 22, 2025
8 checks passed
@0o-de-lally 0o-de-lally deleted the move-codegen branch June 24, 2025 21:03
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