Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ts] ♻️ Replace quicktype by ts-codegen #39

Merged
merged 10 commits into from
Jul 1, 2024
Merged

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented Jun 26, 2024

Due to issues encountered with the quicktype library, specifically in relation to the generated cognitarium schema type (refer to issue #9), we have decided to switch to the ts-codegen library. ts-codegen has been specifically designed for smart-contract schemas, making it a more suitable choice for our project.
This PR removes the usage of quicktype for TypeScript (the removal for Go will be addressed in the upcoming PR #38) and generates new schema types using ts-codegen.

In addition to the switch in libraries, this PR also includes modifications to the package.json file and introduces a cleaning step to generated typescript files.

Summary by CodeRabbit

  • New Features

    • Introduced JSON schema for axone-law-stone and axone-dataverse contracts.
  • Enhancements

    • Updated TypeScript type generation to use ts-codegen for improved performance.
    • Clean scripts for various packages now also remove dist directories for more thorough cleaning.
  • Bug Fixes

    • Excluded .json files from specific workflow processes to prevent unnecessary operations.
  • Chores

    • Added exclusion for JSON files in the schema directory from the review process.

Copy link

coderabbitai bot commented Jun 26, 2024

Walkthrough

In this update, key improvements include refined workflows excluding JSON files from the schema directory, transitioning to ts-codegen for TypeScript type generation, adding new schemas and functionalities, and enhancing cleaning scripts. These changes streamline the build and publish processes, ensure accurate type generation, and maintain a tidy code base.

Changes

File Path Change Summary
.github/workflows/build.yml Updated the set-matrix job's run step to exclude .json files from the schema directory.
.github/workflows/publish.yml Enhanced command to filter out .json files in the set-matrix job.
.github/workflows/update-schema.yml Modified the set-matrix job to exclude .json files from the schema directory.
magefiles/build.go Transitioned Build.Ts to use ts-codegen and added a Clean.Ts method for cleaning TypeScript files.
magefiles/magefile.go Added TS_CODEGEN_VERSION constant.
magefiles/schema.go Added --include='*/schema/*.json' to rsync command in the Schema.Generate method.
magefiles/utils.go Introduced ensureTsCodegen to handle ts-codegen installation.
schema/axone-dataverse.json Defined schema for axone-dataverse version 5.0.0, introducing properties for messages and conversions.
schema/axone-law-stone.json Introduced schema for axone-law-stone version 5.0.0, detailing initialization and querying structures.
ts/.../package.json (several files) Updated clean script to remove both gen-ts and dist directories.
.coderabbit.yaml Added exclusion for JSON files from the schema directory in the review process.

Poem

In code's bright fields, changes burst forth bold,
🎩 TypeScript's new name, ts-codegen we hold. 🌟
Clean scripts now swift, sweep 'gen' and 'dist', ✨
JSONs excluded, workflows enhanced, nothing missed! 🐇
Axone schemas bloom, with structure so fine,
Progress and order, in each coding line. 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@bdeneux bdeneux changed the title ♻️ Replace quicktype by ts-codegen [Ts] ♻️ Replace quicktype by ts-codegen Jun 26, 2024
@bdeneux bdeneux force-pushed the refactor/ts-codegen branch from 2f47067 to e01e9e8 Compare June 26, 2024 09:26
@bdeneux bdeneux marked this pull request as ready for review June 26, 2024 09:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7fc308 and e01e9e8.

Files selected for processing (15)
  • .github/workflows/build.yml (1 hunks)
  • .github/workflows/publish.yml (1 hunks)
  • .github/workflows/update-schema.yml (1 hunks)
  • magefiles/build.go (3 hunks)
  • magefiles/magefile.go (1 hunks)
  • magefiles/schema.go (1 hunks)
  • magefiles/utils.go (1 hunks)
  • schema/axone-cognitarium.json (1 hunks)
  • schema/axone-dataverse.json (1 hunks)
  • schema/axone-law-stone.json (1 hunks)
  • schema/axone-objectarium.json (1 hunks)
  • ts/cognitarium-schema/package.json (1 hunks)
  • ts/dataverse-schema/package.json (1 hunks)
  • ts/law-stone-schema/package.json (1 hunks)
  • ts/objectarium-schema/package.json (1 hunks)
Files not summarized due to errors (2)
  • schema/axone-cognitarium.json: Error: Message exceeds token limit
  • schema/axone-objectarium.json: Error: Message exceeds token limit
Files skipped from review due to trivial changes (1)
  • magefiles/magefile.go
Additional comments not posted (29)
ts/law-stone-schema/package.json (1)

28-28: Enhanced cleaning process in build scripts.

The update to the clean script in package.json ensures a more thorough cleanup by removing both the gen-ts and dist directories before rebuilding, which is a good practice to prevent potential issues from stale files.

ts/dataverse-schema/package.json (1)

28-28: Enhanced cleaning process in build scripts.

Just like in the other schema configurations, updating the clean script to remove both gen-ts and dist directories before rebuilding is a good practice to ensure a clean state for builds.

ts/cognitarium-schema/package.json (1)

28-28: Enhanced cleaning process in build scripts.

Consistent with other schema configurations, the update to the clean script to include both gen-ts and dist directories ensures a clean environment for each build, which is crucial for reliable outputs.
[APROVED]

ts/objectarium-schema/package.json (1)

28-28: Enhanced cleaning process in build scripts.

This update to the clean script aligns with the changes made across other schema configurations. Removing both gen-ts and dist directories before rebuilding is an effective way to maintain a clean build environment.

.github/workflows/build.yml (1)

24-24: Optimized file selection in GitHub workflow.

The modification to the run command in the set-matrix job to exclude .json files from the schema output is a thoughtful change. It likely optimizes the workflow process by focusing on relevant files, especially in the context of transitioning from quicktype to ts-codegen.

magefiles/build.go (5)

20-20: Ensure proper dependency management for TypeScript cleaning.

The addition of a dependency on the Clean.Ts function is appropriate to ensure that TypeScript files are cleaned before rebuilding. This is a good practice to prevent potential issues from stale files.


24-24: Proper toolchain setup is crucial.

It's important to ensure that ts-codegen is available before attempting to generate TypeScript types. This change correctly introduces a dependency check which is crucial for build stability.


53-56: Ensure quicktype is available for Go type generation.

Continuing to use quicktype for Go while transitioning TypeScript to ts-codegen is noted. It's critical to ensure that quicktype is properly checked before use, as done here.


73-81: Introduction of TypeScript cleaning logic.

Adding a dedicated cleaning function for TypeScript aligns with the overall goal of maintaining clean build environments. This method should effectively handle the removal of old TypeScript builds, ensuring that only fresh builds are processed.


26-34: Check the implementation of schemaDestination for robustness.

The use of schemaDestination to determine the output directory and schema name is crucial. Ensure that this function handles different schema formats and names correctly to avoid path issues.

.github/workflows/publish.yml (1)

26-26: Ensure correct filtering of schemas in GitHub Actions.

The modification to the set-matrix step to exclude .json files using jq is crucial for correctly setting up the environment for subsequent steps. This change should help in accurately configuring the build matrix by excluding unnecessary files.

magefiles/schema.go (1)

64-64: Optimize rsync command for selective schema synchronization.

The addition of specific --include and --exclude flags in the rsync command is a good practice to ensure that only relevant schema files are moved. This should prevent unnecessary file transfers and optimize the build process.

magefiles/utils.go (1)

112-126: Ensure robust installation logic for ts-codegen.

The addition of ensureTsCodegen function is crucial for the new TypeScript generation toolchain. The function checks if ts-codegen is installed and installs it if not found. This is essential for build stability and should be carefully monitored for any issues during execution.

.github/workflows/update-schema.yml (1)

91-91: Ensure correct filtering of schemas in GitHub Actions.

The modification to the set-matrix step to exclude .json files using jq is crucial for correctly setting up the environment for subsequent steps. This change should help in accurately configuring the build matrix by excluding unnecessary files.

schema/axone-law-stone.json (4)

5-34: Review of "InstantiateMsg" section:

The instantiation message schema is well-defined, with clear descriptions and appropriate data types. The use of $ref to reference the "Binary" definition ensures consistency and reusability.


36-57: Review of "ExecuteMsg" section:

The "BreakStone" operation is well-documented, with a clear description of its purpose and the conditions under which it can be executed. The schema correctly enforces the structure of the message with additionalProperties: false, ensuring no unintended properties are included.


120-218: Review of "Responses" section:

The responses for different queries are well-structured and include all necessary information. The definitions for "Answer" and "Result" are particularly detailed, providing a comprehensive understanding of what to expect from the contract's responses.


248-250: Review of contract description and metadata:

The overall description provides a thorough overview of the contract's purpose and its operational context. It effectively communicates the contract's functionality and its integration within the broader ecosystem.

schema/axone-dataverse.json (4)

5-57: Review of "InstantiateMsg" section:

The instantiation message schema for the dataverse is comprehensive, with detailed descriptions and appropriate data types. The use of $ref to reference definitions like "TripleStoreConfig" ensures consistency and reusability.


149-216: Review of "ExecuteMsg" section:

The execution message types, "SubmitClaims" and "RevokeClaims", are well-documented with clear descriptions of their purposes and the conditions under which they can be executed. The schema correctly enforces the structure of the messages with additionalProperties: false, ensuring no unintended properties are included.


263-294: Review of "Responses" section:

The "DataverseResponse" is well-structured and includes all necessary information. The definition for "Addr" is particularly detailed, providing a comprehensive understanding of what to expect from the contract's responses.


296-298: Review of contract description and metadata:

The overall description provides a thorough overview of the contract's purpose and its operational context. It effectively communicates the contract's functionality and its integration within the broader ecosystem.

schema/axone-objectarium.json (3)

399-545: Ensure comprehensive query capabilities.

The query section should provide complete and clear information on what can be queried and any limitations or requirements. The current descriptions are good, but ensuring they are exhaustive helps prevent runtime errors and improves usability.


20-27: Review default configuration for clarity and effectiveness.

The default configuration for the bucket includes multiple compression algorithms and a hash algorithm. It's important to verify that these defaults align with the expected use cases and performance requirements of the contract.


64-90: Validate immutability claim in property description.

The description of BucketConfig claims that the configuration is immutable once set. This should be enforced in the contract logic, not just stated in the schema.

schema/axone-cognitarium.json (4)

6-6: Ensure consistent use of JSON Schema declaration.

The $schema declaration is consistently used across different sections (instantiate, execute, query). This is good practice as it ensures that the schema adheres to a specific version of JSON Schema, in this case, Draft 07.

Also applies to: 104-104, 686-686


1878-1880: Review documentation and descriptions.

The description at the end of the file provides a comprehensive overview of the smart contract's capabilities. Ensure that this description is kept up-to-date with the actual functionality of the contract as it evolves.


1-1: Check the JSON format.

Ensure that the JSON file is well-formed and valid. This is crucial for parsing and utilizing the schema correctly.

Verification successful

The JSON format is valid.

The jq command executed without any errors, confirming that the JSON structure is well-formed and valid.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check JSON format validity.

# Test: Validate JSON structure. Expect: No errors.
jq empty schema/axone-cognitarium.json

Length of output: 40


108-191: Validate conditional structures and references.

The oneOf structure used in the execute section is correctly implemented, allowing different types of execution messages. However, ensure that all referenced definitions (like Binary and DataFormat) are consistent and correctly defined elsewhere in the document.

Verification successful

Referenced definitions are correctly implemented.

The Binary and DataFormat definitions are accurately defined and consistent with their usage in the execute section of the schema.

  • Binary is defined as a string with a detailed description.
  • DataFormat includes multiple formats like RDF XML and Turtle.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify referenced definitions in schema.

# Test: Search for definitions of Binary and DataFormat. Expect: Definitions should exist and be consistent.
grep -A 20 '"Binary":' schema/axone-cognitarium.json
grep -A 20 '"DataFormat":' schema/axone-cognitarium.json

Length of output: 6252

schema/axone-cognitarium.json Show resolved Hide resolved
schema/axone-objectarium.json Show resolved Hide resolved
schema/axone-objectarium.json Show resolved Hide resolved
schema/axone-objectarium.json Show resolved Hide resolved
schema/axone-objectarium.json Show resolved Hide resolved
schema/axone-objectarium.json Show resolved Hide resolved
magefiles/build.go Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e01e9e8 and 35049e8.

Files selected for processing (1)
  • .coderabbit.yaml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .coderabbit.yaml

@bdeneux bdeneux requested review from ccamel and amimart June 26, 2024 12:05
@bdeneux bdeneux self-assigned this Jun 26, 2024
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks ! 👌

Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

Perfect 👍

@bdeneux bdeneux merged commit 9fef050 into main Jul 1, 2024
16 checks passed
@bdeneux bdeneux deleted the refactor/ts-codegen branch July 1, 2024 07:55
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