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

fix(zod): make typing of Bytes field compatible with both Buffer and Uint8Array #1279

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Apr 24, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced validation for 'Bytes' field types to better support Buffer and Uint8Array data.
    • Improved test scaffold setup with the addition of necessary type definitions.
  • Bug Fixes

    • Resolved an issue with schema loading and object validation as reported in issue 1268.
  • Refactor

    • Updated settings handling for preserving TypeScript files during schema enhancement processes.

Copy link
Contributor

coderabbitai bot commented Apr 24, 2024

Walkthrough

Walkthrough

This update enhances the handling of the 'Bytes' field type in Zod schemas, introduces conditional assignment for the preserveTsFiles setting, adds necessary types in test scaffolds, and includes a new regression test related to schema loading and object validation.

Changes

Files Change Summary
.../zod/transformer.ts, .../zod/utils/schema-gen.ts Updated 'Bytes' field type handling with a custom Zod validator for Buffer or Uint8Array.
.../testtools/src/schema.ts Updated preserveTsFiles handling based on options, and modified SchemaLoadOptions and default values.
script/test-scaffold.ts Added @types/node to npm installation in test scaffold setup script.
tests/regression/tests/issue-1268.test.ts Added a test case for issue 1268, focusing on schema loading and object validation using Zod schemas.

Possibly related issues

  • Typecasting "Bytes" Fields #1268: The changes in the handling of 'Bytes' field type with a new Zod validator might address the type-casting issues discussed in this issue, suggesting a potential link to this PR.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7c4d86c and 13061aa.
Files ignored due to path filters (2)
  • packages/schema/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml, !**/*.yaml
Files selected for processing (5)
  • packages/schema/src/plugins/zod/transformer.ts (2 hunks)
  • packages/schema/src/plugins/zod/utils/schema-gen.ts (1 hunks)
  • packages/testtools/src/schema.ts (3 hunks)
  • script/test-scaffold.ts (1 hunks)
  • tests/regression/tests/issue-1268.test.ts (1 hunks)
Additional comments not posted (4)
script/test-scaffold.ts (1)

22-22: Installation of @types/node added to npm command.

Please ensure that the installation of @types/node works as expected across different development environments.

tests/regression/tests/issue-1268.test.ts (1)

1-31: Regression test for issue 1268 looks comprehensive and well-structured.

packages/testtools/src/schema.ts (1)

104-104: Dynamic setting of preserveTsFiles implemented for enhancer and zod plugins.

Please verify that the preserveTsFiles setting correctly applies in various scenarios and correctly influences the behavior of the enhancer and zod plugins.

Also applies to: 109-109

packages/schema/src/plugins/zod/transformer.ts (1)

136-142: Custom Zod validator for Buffer or Uint8Array implemented consistently with schema-gen.ts.


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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

Copy link
Contributor

@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

Out of diff range and nitpick comments (1)
packages/schema/src/plugins/zod/utils/schema-gen.ts (1)

189-189: Custom Zod validator for Buffer or Uint8Array implemented correctly.

Consider adding a comment explaining why z.string() is included in the union with the custom validator for Buffer or Uint8Array.

@ymc9
Copy link
Member Author

ymc9 commented Apr 24, 2024

Fixes #1268

@ymc9 ymc9 merged commit 386580e into v2 Apr 24, 2024
14 checks passed
@ymc9 ymc9 deleted the fix/issue-1268 branch April 24, 2024 12:17
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.

1 participant