Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 30, 2025

Summary by CodeRabbit

  • New Features

    • Added comprehensive support for recursive model imports, merging imported declarations, and validating merged models.
    • Introduced automated Discord notifications for new GitHub releases.
  • Bug Fixes

    • Improved schema validation to ensure a datasource is defined and to restrict to one datasource and one model with certain attributes after import merging.
  • Tests

    • Added extensive tests for import functionality, including cyclic imports and relational operations across imported models.
  • Chores

    • Updated package versions to 3.0.0-alpha.15.
    • Adjusted dependency management and workspace configuration for consistency.

ymc9 added 2 commits July 30, 2025 16:45
* feat: implement zmodel import

* addressing PR comments

* update
Copilot AI review requested due to automatic review settings July 30, 2025 08:53
@coderabbitai
Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

This update introduces comprehensive support for recursive import resolution and merging in the model language loader, adds new and enhanced tests for import scenarios, and enforces stricter schema validation. Several package versions are incremented, and dependency management is refined. A GitHub Actions workflow for Discord release notifications is also added.

Changes

Cohort / File(s) Change Summary
Language Import System Overhaul
packages/language/src/index.ts, packages/language/src/utils.ts, packages/language/src/validators/schema-validator.ts, packages/language/test/import.test.ts
Adds recursive import resolution, merging of imported declarations, container reference fixing, post-merge validation, and new utilities for document context. Introduces tests for import scenarios and minor validator refactoring.
CLI and Schema Utilities
packages/cli/src/actions/action-utils.ts, packages/cli/package.json, packages/cli/test/ts-schema-gen.test.ts
Enhances schema loading with warnings and datasource validation, updates devDependencies, and adds a test for merged imports in schema generation.
Test Tools and Runtime
packages/testtools/src/schema.ts, packages/testtools/package.json, packages/runtime/test/client-api/import.test.ts, packages/runtime/test/utils.ts
Refactors schema generation and loading to support in-place compilation, updates dependencies, adds runtime import tests, and improves test client directory handling.
Version Bumps (Multiple Packages)
package.json, packages/common-helpers/package.json, packages/create-zenstack/package.json, packages/eslint-config/package.json, packages/ide/vscode/package.json, packages/language/package.json, packages/runtime/package.json, packages/sdk/package.json, packages/tanstack-query/package.json, packages/typescript-config/package.json, packages/zod/package.json, samples/blog/package.json, tests/e2e/package.json
Increments package versions from 3.0.0-alpha.14 to 3.0.0-alpha.15 across core, plugin, and sample packages. No other changes.
Dependency Management
pnpm-workspace.yaml
Adds tmp and @types/tmp to the catalog for dependency management.
GitHub Actions Workflow
.github/workflows/github-releases-to-discord.yml
Introduces a workflow to notify Discord channels on GitHub release publication using a webhook.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Poem

A rabbit hopped through fields of code,
Importing models down the road.
Schemas merged and tests anew,
With Discord pings to tell the crew!
Version numbers leap and bound—
In every burrow, progress found.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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 generate unit tests to generate unit tests for 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.

@claude
Copy link

claude bot commented Jul 30, 2025

Claude finished @ymc9's task —— View job


PR Review Analysis

I've reviewed this pull request that merges dev to main with significant changes including zmodel import functionality and GitHub-Discord integration.

Review Tasks:

  • Analyze GitHub workflow for security and best practices
  • Review zmodel import implementation in language package
  • Check test coverage for new import functionality
  • Validate package.json changes and dependencies
  • Review CLI changes and action utilities
  • Assess overall code quality and performance implications
  • Provide comprehensive feedback and recommendations

✅ Positive Aspects

  1. Comprehensive Test Coverage: The import functionality has excellent test coverage across multiple packages:

    • Language package tests (packages/language/test/import.test.ts) cover basic merging, symbol resolution, and cyclic imports
    • Runtime tests (packages/runtime/test/client-api/import.test.ts) verify end-to-end functionality with actual database operations
    • CLI tests validate schema generation with imports
  2. Robust Import Resolution: The implementation in packages/language/src/index.ts handles complex scenarios well:

    • Transitive import resolution with cycle detection
    • Proper AST node linking after import merging
    • Validation after import merge (multiple datasources, multiple @@auth models)
  3. Clean API Design: The loadDocument function provides a clear success/failure interface with detailed error reporting

⚠️ Areas for Improvement

Security Concerns

  1. GitHub Workflow (.github/workflows/github-releases-to-discord.yml:13):
    webhook_url: ${{ secrets.RELEASE_TO_DISCORD_WEBHOOK_URL }}
    Good: Uses secrets for webhook URL
    ⚠️ Consider: Add input validation or rate limiting for webhook calls

Potential Bugs

  1. File System Race Conditions (packages/language/src/utils.ts):

    const content = fs.readFileSync(resolvedUri.fsPath, 'utf-8');

    The resolveImport function uses synchronous file operations which could cause issues in concurrent scenarios. Consider async file operations for consistency.

  2. Path Resolution Edge Cases (packages/language/src/utils.ts:695-701):

    let importPath = imp.path;
    if (!importPath.endsWith('.zmodel')) {
        importPath += '.zmodel';
    }

    This auto-extension logic might cause issues with relative paths containing dots or unusual file structures.

Performance Considerations

  1. Document Cleanup (packages/language/src/index.ts:112-115):

    imported.forEach((model) => {
        langiumDocuments.deleteDocument(model.$document!.uri);
        services.shared.workspace.IndexManager.remove(model.$document!.uri);
    });

    Good: Properly cleans up imported documents to prevent memory leaks

  2. Recursive Import Loading (packages/language/src/index.ts:134-150):
    The recursive import resolution could be optimized with memoization for large import trees.

Code Quality Issues

  1. Error Handling (packages/language/src/utils.ts:691):

    } catch {
        // NOOP
    }

    Silent error swallowing in resolveImport makes debugging difficult. Consider logging or returning specific error types.

  2. Type Safety (packages/language/src/index.ts:167-184):
    The linkContentToContainer function uses type assertions that could be strengthened:

    (item as Mutable<AstNode>).$container = node;

🚀 Recommendations

  1. Add Import Path Validation: Validate import paths against directory traversal attacks
  2. Improve Error Messages: Make import resolution errors more specific about which file/path failed
  3. Consider Caching: Add optional caching for frequently imported schemas in development workflows
  4. Documentation: Add JSDoc comments for the new import resolution functions

📊 Test Coverage Assessment

  • Excellent: Core functionality well tested
  • Good: Edge cases like cyclic imports covered
  • Missing: Error scenarios (invalid paths, malformed imports) could use more coverage

🔧 Minor Issues

  • Version bumps in package.json files are consistent (3.0.0-alpha.14)
  • New generateTsSchemaInPlace utility function is well-designed for the import testing use case
  • Workspace configuration properly includes new test directories

Overall Assessment: This is a well-implemented feature with solid architecture and comprehensive testing. The import functionality adds significant value to the ZModel language while maintaining code quality standards. The identified issues are minor and don't block the merge.

Recommendation: ✅ Approve with minor suggestions


@ymc9 ymc9 changed the title merge dev to main merge dev to main (v3.0.0-alpha.15) Jul 30, 2025
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 merges the dev branch to main, introducing import functionality for ZModel schema files. The key changes enable models to be split across multiple files and imported into each other, supporting better code organization and reusability.

  • Adds import resolution and merging functionality to handle schema files that reference other schema files
  • Implements support for cyclic imports and proper symbol resolution across imported modules
  • Centralizes dependency management by moving package versions to the workspace catalog

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pnpm-workspace.yaml Adds tmp and @types/tmp packages to the workspace catalog
packages/testtools/src/schema.ts Extracts compilation logic and adds new function for in-place schema generation
packages/testtools/package.json Updates tmp dependencies to use catalog versions
packages/runtime/test/utils.ts Adds workDir option and improves null handling in test client creation
packages/runtime/test/client-api/import.test.ts Adds comprehensive test for import functionality with cross-file model references
packages/language/test/import.test.ts Adds unit tests for import merging, symbol resolution, and cyclic imports
packages/language/src/validators/schema-validator.ts Improves import path handling by moving variable declaration closer to usage
packages/language/src/utils.ts Simplifies import resolution by removing node_modules support and adds AST utility functions
packages/language/src/index.ts Implements core import loading, merging, and validation functionality
packages/language/package.json Adds tmp dependencies for testing
packages/cli/test/ts-schema-gen.test.ts Adds test to verify import declaration merging in TypeScript schema generation
packages/cli/src/actions/action-utils.ts Adds datasource validation and warning display for schema loading
packages/cli/package.json Updates tmp dependencies to use catalog versions
.github/workflows/github-releases-to-discord.yml Adds GitHub Actions workflow for Discord release notifications
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@claude
Copy link

claude bot commented Jul 30, 2025

Claude finished @ymc9's task —— View job


PR Review Analysis

I've reviewed this pull request that merges dev to main with significant changes including zmodel import functionality and GitHub-Discord integration.

Review Tasks:

  • Analyze GitHub workflow for security and best practices
  • Review zmodel import implementation in language package
  • Check test coverage for new import functionality
  • Validate package.json changes and dependencies
  • Review CLI changes and action utilities
  • Assess overall code quality and performance implications
  • Provide comprehensive feedback and recommendations

✅ Positive Aspects

  1. Comprehensive Test Coverage: The import functionality has excellent test coverage across multiple packages:

    • Language package tests (packages/language/test/import.test.ts) cover basic merging, symbol resolution, and cyclic imports
    • Runtime tests (packages/runtime/test/client-api/import.test.ts) verify end-to-end functionality with actual database operations
    • CLI tests validate schema generation with imports
  2. Robust Import Resolution: The implementation in packages/language/src/index.ts handles complex scenarios well:

    • Transitive import resolution with cycle detection
    • Proper AST node linking after import merging
    • Validation after import merge (multiple datasources, multiple @@auth models)
  3. Clean API Design: The loadDocument function provides a clear success/failure interface with detailed error reporting

⚠️ Areas for Improvement

Security Concerns

  1. GitHub Workflow (.github/workflows/github-releases-to-discord.yml:13):
    webhook_url: ${{ secrets.RELEASE_TO_DISCORD_WEBHOOK_URL }}
    Good: Uses secrets for webhook URL
    ⚠️ Consider: Add input validation or rate limiting for webhook calls

Potential Bugs

  1. File System Race Conditions (packages/language/src/utils.ts):

    const content = fs.readFileSync(resolvedUri.fsPath, 'utf-8');

    The resolveImport function uses synchronous file operations which could cause issues in concurrent scenarios. Consider async file operations for consistency.

  2. Path Resolution Edge Cases (packages/language/src/utils.ts:695-701):

    let importPath = imp.path;
    if (!importPath.endsWith('.zmodel')) {
        importPath += '.zmodel';
    }

    This auto-extension logic might cause issues with relative paths containing dots or unusual file structures.

Performance Considerations

  1. Document Cleanup (packages/language/src/index.ts:112-115):

    imported.forEach((model) => {
        langiumDocuments.deleteDocument(model.$document!.uri);
        services.shared.workspace.IndexManager.remove(model.$document!.uri);
    });

    Good: Properly cleans up imported documents to prevent memory leaks

  2. Recursive Import Loading (packages/language/src/index.ts:134-150):
    The recursive import resolution could be optimized with memoization for large import trees.

Code Quality Issues

  1. Error Handling (packages/language/src/utils.ts:691):

    } catch {
        // NOOP
    }

    Silent error swallowing in resolveImport makes debugging difficult. Consider logging or returning specific error types.

  2. Type Safety (packages/language/src/index.ts:167-184):
    The linkContentToContainer function uses type assertions that could be strengthened:

    (item as Mutable<AstNode>).$container = node;

🚀 Recommendations

  1. Add Import Path Validation: Validate import paths against directory traversal attacks
  2. Improve Error Messages: Make import resolution errors more specific about which file/path failed
  3. Consider Caching: Add optional caching for frequently imported schemas in development workflows
  4. Documentation: Add JSDoc comments for the new import resolution functions

📊 Test Coverage Assessment

  • Excellent: Core functionality well tested
  • Good: Edge cases like cyclic imports covered
  • Missing: Error scenarios (invalid paths, malformed imports) could use more coverage

🔧 Minor Issues

  • Version bumps in package.json files are consistent (3.0.0-alpha.14)
  • New generateTsSchemaInPlace utility function is well-designed for the import testing use case
  • Workspace configuration properly includes new test directories

Overall Assessment: This is a well-implemented feature with solid architecture and comprehensive testing. The import functionality adds significant value to the ZModel language while maintaining code quality standards. The identified issues are minor and don't block the merge.

Recommendation: ✅ Approve with minor suggestions


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

♻️ Duplicate comments (5)
.github/workflows/github-releases-to-discord.yml (1)

4-14: Add a minimal permissions block to harden the workflow
GitHub recommends explicitly scoping the default GITHUB_TOKEN. Example:

 jobs:
     github-releases-to-discord:
         runs-on: ubuntu-latest
+        permissions:
+            contents: read
packages/runtime/test/utils.ts (1)

118-118: Nullish coalescing usage is correct here.

The past review comment expressed concern about using ??= with a potentially async function, but createTestProject() returns a string synchronously, so this usage is appropriate.

packages/language/src/utils.ts (1)

571-579: Missing JSDoc documentation.

The findRootNode function needs JSDoc documentation to match the pattern established by other utility functions.

packages/language/src/index.ts (2)

148-148: Use strict inequality operator.


167-167: Add JSDoc documentation for linkContentToContainer.

🧹 Nitpick comments (2)
.github/workflows/github-releases-to-discord.yml (1)

8-10: Consider upgrading to actions/checkout@v4
v4 brings performance and security improvements and is now the recommended major version.

-            - name: Checkout
-              uses: actions/checkout@v3
+            - name: Checkout
+              uses: actions/checkout@v4
packages/language/src/index.ts (1)

106-116: Consider safer null handling for document access.

The non-null assertion on line 113 could potentially throw if $document is undefined. Consider adding a null check.

-        langiumDocuments.deleteDocument(model.$document!.uri);
-        services.shared.workspace.IndexManager.remove(model.$document!.uri);
+        if (model.$document) {
+            langiumDocuments.deleteDocument(model.$document.uri);
+            services.shared.workspace.IndexManager.remove(model.$document.uri);
+        }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9d5e1d and 043161b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (26)
  • .github/workflows/github-releases-to-discord.yml (1 hunks)
  • package.json (1 hunks)
  • packages/cli/package.json (2 hunks)
  • packages/cli/src/actions/action-utils.ts (3 hunks)
  • packages/cli/test/ts-schema-gen.test.ts (2 hunks)
  • packages/common-helpers/package.json (1 hunks)
  • packages/create-zenstack/package.json (1 hunks)
  • packages/eslint-config/package.json (1 hunks)
  • packages/ide/vscode/package.json (1 hunks)
  • packages/language/package.json (2 hunks)
  • packages/language/src/index.ts (3 hunks)
  • packages/language/src/utils.ts (3 hunks)
  • packages/language/src/validators/schema-validator.ts (1 hunks)
  • packages/language/test/import.test.ts (1 hunks)
  • packages/runtime/package.json (1 hunks)
  • packages/runtime/test/client-api/import.test.ts (1 hunks)
  • packages/runtime/test/utils.ts (5 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/tanstack-query/package.json (1 hunks)
  • packages/testtools/package.json (3 hunks)
  • packages/testtools/src/schema.ts (2 hunks)
  • packages/typescript-config/package.json (1 hunks)
  • packages/zod/package.json (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
  • samples/blog/package.json (1 hunks)
  • tests/e2e/package.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
packages/cli/src/actions/action-utils.ts (2)
packages/language/src/generated/ast.ts (1)
  • isDataSource (417-419)
packages/cli/src/cli-error.ts (1)
  • CliError (4-4)
packages/cli/test/ts-schema-gen.test.ts (2)
packages/testtools/src/project.ts (1)
  • createTestProject (5-67)
packages/testtools/src/schema.ts (1)
  • generateTsSchemaInPlace (76-83)
packages/language/src/utils.ts (1)
packages/language/src/ast.ts (2)
  • AstNode (4-4)
  • AstNode (66-71)
packages/testtools/src/schema.ts (1)
packages/sdk/src/ts-schema-generator.ts (1)
  • TsSchemaGenerator (55-1414)
packages/language/src/index.ts (4)
packages/language/src/utils.ts (5)
  • resolveImport (395-413)
  • getDocument (562-569)
  • resolveTransitiveImports (364-366)
  • getDataModelAndTypeDefs (428-435)
  • hasAttribute (52-54)
packages/language/src/ast.ts (2)
  • AstNode (4-4)
  • AstNode (66-71)
packages/language/src/generated/ast.ts (1)
  • isDataSource (417-419)
packages/sdk/src/model-utils.ts (1)
  • hasAttribute (58-63)
🪛 actionlint (1.7.7)
.github/workflows/github-releases-to-discord.yml

9-9: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 GitHub Check: CodeQL
.github/workflows/github-releases-to-discord.yml

[warning] 6-14: Workflow does not contain permissions
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {{contents: read}}

⏰ 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 (42)
samples/blog/package.json (1)

3-3: Version bump looks consistent

The update to 3.0.0-alpha.15 matches the monorepo release train. No further action needed.

packages/zod/package.json (1)

3-3: Aligned with workspace version

@zenstackhq/zod now advertises 3.0.0-alpha.15, keeping peer packages in sync.

packages/sdk/package.json (1)

3-3: SDK version bumped correctly

Change is purely declarative; build/publish scripts will pick up the new tag.

packages/common-helpers/package.json (1)

3-3: Helper package version updated

Nothing else changed—good for release consistency.

package.json (1)

3-3: Root version updated

Top-level package.json now matches all workspace packages. Ensure lock-file regeneration before publishing.

Please run pnpm install to refresh the lockfile and confirm no mismatched versions remain.

packages/create-zenstack/package.json (1)

3-3: Version bump to 3.0.0-alpha.15 looks good

No issues spotted; this keeps the package in sync with the coordinated release across the monorepo.

packages/typescript-config/package.json (1)

3-3: Version updated correctly

The new version matches the rest of the workspace packages; nothing else to address.

packages/eslint-config/package.json (1)

3-3: ESLint config version aligned

Change is minimal and consistent with the release tag.

packages/runtime/package.json (1)

3-3: Runtime package version increment verified

Bump is coherent with other workspace packages; no additional adjustments required.

tests/e2e/package.json (1)

3-3: E2E tests package version updated appropriately

Version aligns with the monorepo release set. Good to go.

packages/ide/vscode/package.json (1)

4-4: Version bump aligns with the coordinated release – LGTM
No functional or metadata issues observed.

packages/tanstack-query/package.json (1)

3-3: Package version updated consistently – LGTM
Nothing else changed; looks good.

pnpm-workspace.yaml (1)

14-15: tmp usage confined to tests and CLI only
I ran the suggested grep and found import tmp from 'tmp' only in:

  • packages/testtools/src/project.ts
  • packages/cli/test/init.test.ts
  • packages/language/test/import.test.ts

Since tmp@^0.2.3 is only pulled in by non-production code (tests/CLI), it’s safe to include as a dev/test dependency. Ensure your CVE-monitoring process covers this package, and this is good to merge.

packages/cli/package.json (1)

46-54: Ensure tmp is not required at runtime
tmp and its types were moved to "catalog:" under devDependencies. If any CLI code (outside test files) invokes tmp, the package will be missing when users install the CLI globally. Double-check that all imports live strictly in test helpers.

packages/language/package.json (2)

4-4: Version update looks good.

The version bump to 3.0.0-alpha.15 aligns with the PR objectives for this release.


66-67: New dependencies appropriately added.

The addition of tmp and @types/tmp dependencies using the catalog pattern supports the new import testing functionality and aligns with similar additions across other packages.

packages/language/src/validators/schema-validator.ts (1)

51-51: Good refactoring: defer variable initialization.

Moving the importPath variable declaration inside the conditional block is a good practice that defers computation until needed and keeps the variable scope tighter.

packages/testtools/package.json (2)

3-3: Version update is consistent.

The version bump to 3.0.0-alpha.15 is consistent with the coordinated release across packages.


34-34: Dependency management improvements.

Switching from fixed versions to the catalog pattern for tmp and @types/tmp improves dependency management consistency across the monorepo.

Also applies to: 44-44

packages/cli/test/ts-schema-gen.test.ts (2)

2-4: New imports support enhanced testing capabilities.

The additional imports for createTestProject, generateTsSchemaInPlace, fs, and path properly support the new test case for import merging functionality.


331-362: Excellent test coverage for import merging.

This test case thoroughly validates the import merging functionality by:

  • Creating isolated test environment with temporary project
  • Testing cross-file import resolution (enum from a.zmodel used in b.zmodel)
  • Verifying that both imported and local declarations are properly merged in the generated schema

The test structure follows good practices and provides valuable coverage for the new import handling capabilities.

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

2-2: Appropriate import for enhanced validation.

The import of isDataSource from the language package supports the new datasource validation logic.


45-47: Improved warning visibility.

Adding yellow color to warning messages improves user experience by making warnings more distinguishable from errors.


61-63: Enhanced schema validation with datasource requirement.

The new validation ensuring at least one datasource is present strengthens schema correctness, as Prisma schemas require a datasource to be functional. This aligns with the broader validation improvements in this PR.

packages/language/test/import.test.ts (4)

9-34: Well-structured test for declaration merging.

The test correctly verifies that importing declarations from another file merges them into the main model and removes the import statements from the final AST structure.


36-60: Excellent test for symbol resolution across imports.

This test validates that imported symbols (Role enum) are properly resolved and referenced in the importing model, which is crucial for type checking and validation.


62-90: Great coverage for cyclic import scenarios.

Testing bidirectional imports between models A and B ensures the import resolution handles circular dependencies correctly, which is a common real-world scenario.


92-100: Clean helper function with proper error handling.

The expectLoaded helper provides good error reporting and validation, making test failures easier to debug.

packages/runtime/test/client-api/import.test.ts (2)

7-46: Excellent integration test setup.

The test creates a realistic scenario with mutual imports between User and Post models, properly demonstrating relational modeling across imported files. The setup with separate schema files and a main schema is a common real-world pattern.


48-70: Comprehensive end-to-end validation.

The test validates the entire pipeline from import resolution through schema generation to actual database operations. The nested create operation with inclusion properly tests that relations work correctly across imported models.

packages/runtime/test/utils.ts (2)

65-65: Good addition of workDir option.

Adding the workDir option to CreateTestClientOptions provides flexibility for tests to specify their own working directory, which is essential for the new import testing scenarios.


135-137: Conditional logging improves debugging experience.

Only logging the work directory when it's available prevents confusing output and helps with debugging test scenarios.

packages/language/src/utils.ts (3)

2-2: Good addition of required Langium types.

Adding AstNode, LangiumDocument, etc. to the imports supports the new utility functions for document and AST node manipulation.


416-423: Simplified import resolution is more maintainable.

The simplified resolveImportUri function removes complex node_modules resolution logic in favor of straightforward relative path resolution, which is more predictable and easier to maintain.


556-569: Useful document retrieval utility.

The getDocument function provides a clean way to retrieve the LangiumDocument from any AST node with proper error handling when the document is not found.

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

57-58: Good refactoring to extract common logic.

Moving the compilation and loading logic to a separate compileAndLoad function improves code organization and reusability.


60-69: Clean helper function for compilation and loading.

The compileAndLoad function centralizes the TypeScript compilation and module loading logic, making it reusable across different schema generation scenarios.


76-83: Useful addition for in-place schema generation.

The generateTsSchemaInPlace function enables schema generation directly in an existing directory, which is essential for testing import scenarios where multiple schema files need to coexist.

packages/language/src/index.ts (4)

1-1: Import statements look good.

The added imports are appropriate for the new import resolution and merging functionality.

Also applies to: 6-6, 9-9


64-69: Import loading implementation looks good.

The recursive loading of imported documents is correctly implemented.


152-165: Import merging logic is well implemented.

The function correctly handles transitive import resolution, declaration merging, and container relationship fixing.


186-200: Validation logic looks good.

The function correctly enforces the constraints for datasource and @@auth declarations after import merging.

@ymc9 ymc9 added this pull request to the merge queue Jul 30, 2025
Merged via the queue into main with commit 99eb798 Jul 30, 2025
9 checks passed
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