Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 11, 2025

Summary by CodeRabbit

  • New Features

    • Added support for configuring schema and output paths via the project’s package.json file, enabling more flexible CLI usage.
    • Introduced a new utility for searching files upward through parent directories.
  • Bug Fixes

    • Improved CLI generate command to respect schema and output paths defined in package.json.
  • Tests

    • Added tests to verify package.json-based configuration for schema and output paths.
  • Chores

    • Upgraded zod dependency to version 4 across the project.
    • Updated package exports and dependencies to reflect changes in zod usage.
    • Added new exports for helpers and SQL utilities.

Copilot AI review requested due to automatic review settings July 11, 2025 03:24
@coderabbitai
Copy link

coderabbitai bot commented Jul 11, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces new configuration resolution logic for CLI schema and output paths using package.json, adds a generic upward file search utility, and exposes new helper exports in the runtime package. It also updates Zod dependencies to version 4 and adjusts import paths across affected packages. Additional tests and type exports are included.

Changes

Files/Groups Change Summary
packages/cli/src/actions/action-utils.ts Added getPkgJsonConfig for resolving schema/output from package.json; updated schema resolution.
packages/cli/src/actions/generate.ts Refactored output path logic into getOutputPath, using getPkgJsonConfig if needed.
packages/cli/test/generate.test.ts Added test for CLI respecting package.json config for schema/output paths.
packages/common-helpers/src/find-up.ts, .../src/index.ts Introduced and exported findUp utility for upward file search.
packages/runtime/package.json Added ./helpers export; moved zod to dependencies; updated peerDependencies.
packages/runtime/src/client/contract.ts Added exported type alias TransactionClientContract.
packages/runtime/src/client/crud/validator.ts, .../zod/src/index.ts, .../types.ts Changed Zod import paths from 'zod/v4' to 'zod'.
packages/runtime/src/helpers.ts Re-exported sql from kysely.
packages/runtime/tsup.config.ts Added helpers as an entry point for build output.
pnpm-workspace.yaml Updated zod version constraint to ^4.0.0 in catalog.

Poem

🐇
Upward I hop, through folders I go,
Seeking configs where schema paths show.
Helpers and Zod now fresh and new,
Type-safe carrots for the CLI crew!
With every test and export in place,
This rabbit’s code runs a faster race.
Hooray for configs found in every space!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades Zod to v4, adds helper exports, and extends the CLI to load schema/output configuration from package.json.

  • Bump Zod dependency and update related imports
  • Introduce shared findUp helper and re-export SQL helper
  • Enhance CLI generate action with getPkgJsonConfig and getOutputPath

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pnpm-workspace.yaml Updated Zod version constraint to ^4.0.0
packages/zod/src/types.ts Switched import from 'zod/v4' to 'zod'
packages/zod/src/index.ts Switched import from 'zod/v4' to 'zod'
packages/runtime/tsup.config.ts Added helpers entry for bundling runtime helpers
packages/runtime/src/helpers.ts Exported sql helper from Kysely
packages/runtime/src/client/crud/validator.ts Switched import from 'zod/v4' to 'zod'
packages/runtime/src/client/contract.ts Added TransactionClientContract type
packages/runtime/package.json Exposed ./helpers entrypoint and moved Zod to dependencies
packages/common-helpers/src/index.ts Re-exported new find-up utility
packages/common-helpers/src/find-up.ts Implemented findUp file resolution helper
packages/cli/src/actions/generate.ts Added getOutputPath leveraging package.json config
packages/cli/src/actions/action-utils.ts Added schema/output config loader getPkgJsonConfig
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (3)

packages/common-helpers/src/find-up.ts:18

  • The @param tag is missing the parameter name. Change to @param result An array of strings representing the accumulated results used in multiple results for proper JSDoc.
 * @param An array of strings representing the accumulated results used in multiple results

packages/cli/src/actions/action-utils.ts:64

  • New logic for loading package.json config is added but there are no corresponding tests. Consider adding unit tests for getPkgJsonConfig to cover scenarios with and without a zenstack section.
export function getPkgJsonConfig(startPath: string) {

packages/cli/src/actions/action-utils.ts:1

  • The file uses fs, path, and CliError but none are imported. Add import fs from 'node:fs';, import path from 'node:path';, and import or define CliError to avoid reference errors.
import { findUp } from '@zenstackhq/common-helpers';

@ymc9
Copy link
Member Author

ymc9 commented Jul 11, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jul 11, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 2

🧹 Nitpick comments (2)
packages/common-helpers/src/find-up.ts (1)

9-20: Clarify JSDoc documentation for the multiple parameter.

The JSDoc comment on line 17 is misleading about the multiple parameter's purpose.

- * @param multiple A boolean flag indicating whether to search for multiple levels. Useful for finding node_modules directories...
+ * @param multiple A boolean flag indicating whether to return all found paths or just the first one

The parameter controls whether to return single or multiple results, not whether to search multiple levels (the function always searches up to the root).

packages/runtime/package.json (1)

76-82: Re-classifying zod from peer → runtime dep can cause duplication in consumer apps

By shipping zod as a hard dependency:

  • Projects that already depend on a different zod@4 patch level will get two copies unless their package-manager hoists/dedupes.
  • Tree-shaking doesn’t help because Zod is side-effect free but fully included.

Consider the hybrid approach adopted by many libraries:

"dependencies": {
   ...
-  "zod": "catalog:"
+  // keep no direct dependency on zod
},
"peerDependencies": {
   ...
+  "zod": "^4.0.0",
},
"peerDependenciesMeta": {
+  "zod": { "optional": false },
   ...
}

This preserves a single Zod instance and lets the host control the version, while still signalling a strict requirement.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd8878 and 95baf0e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • packages/cli/src/actions/action-utils.ts (3 hunks)
  • packages/cli/src/actions/generate.ts (3 hunks)
  • packages/cli/test/generate.test.ts (1 hunks)
  • packages/common-helpers/src/find-up.ts (1 hunks)
  • packages/common-helpers/src/index.ts (1 hunks)
  • packages/runtime/package.json (2 hunks)
  • packages/runtime/src/client/contract.ts (1 hunks)
  • packages/runtime/src/client/crud/validator.ts (1 hunks)
  • packages/runtime/src/helpers.ts (1 hunks)
  • packages/runtime/tsup.config.ts (1 hunks)
  • packages/zod/src/index.ts (1 hunks)
  • packages/zod/src/types.ts (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/cli/src/actions/action-utils.ts (2)
packages/cli/src/cli-error.ts (1)
  • CliError (4-4)
packages/common-helpers/src/find-up.ts (1)
  • findUp (21-34)
packages/runtime/src/client/contract.ts (1)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-17)
packages/cli/test/generate.test.ts (1)
packages/cli/test/utils.ts (2)
  • createProject (12-18)
  • runCli (20-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-test (20.x)
🔇 Additional comments (16)
packages/common-helpers/src/index.ts (1)

1-1: LGTM: Clean export addition following established pattern.

The new export for the find-up utility follows the consistent pattern used throughout the index file and makes the utility available through the package's public API.

packages/cli/src/actions/generate.ts (3)

7-7: LGTM: Clean import addition for new configuration functionality.

The import properly includes the new getPkgJsonConfig function needed for package.json configuration support.


23-23: LGTM: Good refactoring to extract output path logic.

The refactoring improves code organization by extracting the output path determination logic into a dedicated helper function.


58-68: LGTM: Well-structured priority hierarchy for output path determination.

The function correctly implements a three-tier priority system:

  1. Explicit --output option (highest priority)
  2. Package.json configuration (fallback)
  3. Schema file directory (default)

This provides a logical and user-friendly configuration hierarchy.

packages/cli/test/generate.test.ts (1)

45-58: LGTM: Comprehensive test coverage for package.json configuration.

The test case properly validates the end-to-end functionality of the new configuration resolution mechanism by:

  • Setting up a custom directory structure
  • Configuring package.json with zenstack settings
  • Verifying the CLI respects the configuration without explicit arguments

This ensures the feature works correctly and provides good regression protection.

packages/cli/src/actions/action-utils.ts (2)

1-1: LGTM: Proper import for the new findUp utility.

The import correctly includes the findUp function needed for upward directory traversal.


17-23: LGTM: Good integration of package.json configuration into schema resolution.

The modification properly integrates the new configuration mechanism as a fallback option between explicit file specification and default locations. The error handling is consistent with the existing pattern.

packages/common-helpers/src/find-up.ts (1)

1-7: LGTM: Clean imports and well-designed conditional type.

The imports are appropriate and the FindUpResult conditional type properly handles the different return types based on the multiple flag.

packages/zod/src/types.ts (1)

2-2: Ensure main zod export provides all v4 types
This update replaces imports from 'zod/v4' with the package root. Please confirm that the primary zod entrypoint still exports all of the following v4 types:

  • ZodBoolean
  • ZodNumber
  • ZodObject
  • ZodString
  • ZodUnknown

Location:

  • packages/zod/src/types.ts:2
packages/zod/src/index.ts (1)

3-3: Verify Zod main export compatibility

Please confirm that replacing

import { z, ZodType } from 'zod/v4';

with

import { z, ZodType } from 'zod';

provides identical z and ZodType APIs. You may want to:

  • Check your package.json to ensure zod is at v4.x
  • Inspect the published zod package exports (e.g., via a quick Node REPL or build)
  • Run the existing schema-related tests or a minimal import test to validate there are no missing or changed types
packages/runtime/src/client/crud/validator.ts (1)

5-5: Ensure Zod is pinned to v4 and main export supports z/ZodType

Please confirm that your central version-catalog (where "zod": "catalog:" is defined) points to Zod v4, and that the unscoped zod package indeed exports both z and ZodType. All TS imports now use:

  • packages/zod/src/types.ts
  • packages/zod/src/index.ts
  • packages/runtime/src/client/crud/validator.ts
packages/runtime/src/helpers.ts (1)

1-1: Build Configuration Verified for helpers Entry

The tsup.config.ts file includes the following entry, confirming that src/helpers.ts will be bundled as expected:

• helpers: 'src/helpers.ts'

No further changes needed—approving the re-export as-is.

packages/runtime/src/client/contract.ts (1)

161-167: Excellent type safety improvement!

The new TransactionClientContract type provides a restricted interface for transaction contexts by omitting methods that aren't supported during transactions. This prevents developers from accidentally calling unsupported methods and improves the developer experience with better compile-time checks.

pnpm-workspace.yaml (1)

8-8: No remaining zod/v4 imports detected

A repository-wide search for any zod/v4 references—both ES module imports and CommonJS requires—returned no results. It’s safe to proceed with merging the upgrade to zod@^4.

packages/runtime/tsup.config.ts (1)

7-9: New helpers bundle entry looks correct

Entry is wired into tsup and placed adjacent to index/schema.
No issues spotted. 👍

packages/runtime/package.json (1)

42-51: Export map for ./helpers matches tsup output – LGTM

The map exposes both ESM/CJS and declaration files consistently with the other sub-paths.

@ymc9 ymc9 merged commit 7304cd2 into dev Jul 11, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 13, 2025
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.

2 participants