Skip to content

merge dev to main (v2.14.2) #2113

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

Merged
merged 2 commits into from
May 8, 2025
Merged

merge dev to main (v2.14.2) #2113

merged 2 commits into from
May 8, 2025

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented May 8, 2025

No description provided.

Copy link
Contributor

coderabbitai bot commented May 8, 2025

📝 Walkthrough

Walkthrough

This change introduces a new ApiHandlerService for handling API requests in a NestJS environment, adds supporting interfaces and constants, and refactors module exports for better modularity. It also updates the JetBrains IDE package version and expands test coverage for the new service and related API handler options.

Changes

File(s) Change Summary
packages/ide/jetbrains/build.gradle.kts Bumped JetBrains IDE package version from 2.14.1 to 2.14.2.
packages/server/src/nestjs/api-handler.service.ts Introduced ApiHandlerService, a request-scoped NestJS service for handling API requests, encapsulating logic for request parsing, handler invocation, and error propagation.
packages/server/src/nestjs/interfaces/api-handler-options.interface.ts Added new interface ApiHandlerOptions extending AdapterBaseOptions, with an optional baseUrl property and detailed documentation on its usage for route prefixing.
packages/server/src/nestjs/interfaces/zenstack-module-options.interface.ts Added new interfaces: ZenStackModuleOptions (with getEnhancedPrisma method) and ZenStackModuleAsyncOptions (for async module registration, with options for global scope, export token, extra providers, and factory function).
packages/server/src/nestjs/interfaces/index.ts New barrel file re-exporting interfaces from zenstack-module-options.interface and api-handler-options.interface for consolidated imports.
packages/server/src/nestjs/zenstack.constants.ts Added and exported the constant ENHANCED_PRISMA as the default export token for the enhanced Prisma service.
packages/server/src/nestjs/zenstack.module.ts Refactored to remove local declarations of ENHANCED_PRISMA, ZenStackModuleOptions, and ZenStackModuleAsyncOptions, importing them from their respective modules instead. Unused NestJS type imports were removed.
packages/server/src/nestjs/index.ts Updated to export api-handler.service and zenstack.constants in addition to zenstack.module, broadening the module's public API.
packages/server/tests/adapter/nestjs.test.ts Added a new test suite for ApiHandlerService with tests for default options, REST API handler usage, and baseUrl option. Mocks and providers were set up for HTTP context, and initial data creation was included. Existing tests remain unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant NestJS Controller
    participant ApiHandlerService
    participant PrismaClient
    participant RequestHandler

    Client->>NestJS Controller: Sends HTTP request
    NestJS Controller->>ApiHandlerService: Calls handleRequest(options?)
    ApiHandlerService->>PrismaClient: Get enhanced Prisma instance
    ApiHandlerService->>ApiHandlerService: Load model metadata & schemas
    ApiHandlerService->>RequestHandler: Invoke with request details, Prisma, metadata, schemas, logger
    RequestHandler-->>ApiHandlerService: Returns response (body, status)
    alt status >= 400
        ApiHandlerService->>NestJS Controller: Throw HttpException with body and status
    else status < 400
        ApiHandlerService->>NestJS Controller: Return response body
    end
    NestJS Controller-->>Client: Sends HTTP response
Loading

Possibly related PRs

  • zenstackhq/zenstack#2099: Introduces the same ApiHandlerService class and related exports, indicating direct overlap or duplication with this change.
  • zenstackhq/zenstack#2109: Updates the JetBrains IDE package version in the same file, representing a sequential version bump closely related to the current version update.
  • zenstackhq/zenstack#2112: Contains an identical version bump for the JetBrains IDE package, suggesting direct or parallel work on version management.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. 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 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 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.

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.

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

🧹 Nitpick comments (4)
packages/server/src/nestjs/api-handler.service.ts (2)

22-34: Consider improving type safety for request body extraction

The service correctly loads assets, determines the request handler, and extracts request details. However, the request body extraction could be improved for better type safety.

- const requestBody = (this.request as { body: unknown }).body;
+ const requestBody = this.request && typeof this.request === 'object' && 'body' in this.request 
+   ? (this.request as { body: unknown }).body 
+   : undefined;

46-54: Exception handling follows NestJS patterns

The error handling approach correctly integrates with NestJS's exception handling system by throwing an HttpException for status codes >= 400. This allows NestJS to generate appropriate error responses while also allowing callers to handle errors manually if needed.

Consider using a more type-safe approach when casting the response body.

- throw new HttpException(response.body as Record<string, any>, response.status)
+ throw new HttpException(
+   typeof response.body === 'object' ? response.body : { message: String(response.body) },
+   response.status
+ )
packages/server/src/nestjs/interfaces/zenstack-module-options.interface.ts (2)

6-11: Refine the return type of getEnhancedPrisma

The getEnhancedPrisma callback currently returns unknown, which weakens type safety for consumers. Consider specifying a more precise return type or making the interface generic, e.g.:

getEnhancedPrisma<TClient = EnhancedPrismaClient>(model?: string | symbol): TClient;

This ensures users benefit from proper IntelliSense and compile-time checks.


13-16: Consider supporting additional module metadata

ZenStackModuleAsyncOptions extends only the imports property from ModuleMetadata. If future use cases require customizing exports, providers, or other metadata, you could replace Pick with a Partial<ModuleMetadata> or selectively include more properties to enhance flexibility.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3895746 and 922e3c4.

⛔ Files ignored due to path filters (14)
  • package.json is excluded by !**/*.json
  • packages/ide/jetbrains/package.json is excluded by !**/*.json
  • packages/language/package.json is excluded by !**/*.json
  • packages/misc/redwood/package.json is excluded by !**/*.json
  • packages/plugins/openapi/package.json is excluded by !**/*.json
  • packages/plugins/swr/package.json is excluded by !**/*.json
  • packages/plugins/tanstack-query/package.json is excluded by !**/*.json
  • packages/plugins/trpc/package.json is excluded by !**/*.json
  • packages/runtime/package.json is excluded by !**/*.json
  • packages/schema/package.json is excluded by !**/*.json
  • packages/sdk/package.json is excluded by !**/*.json
  • packages/server/package.json is excluded by !**/*.json
  • packages/server/tsconfig.json is excluded by !**/*.json
  • packages/testtools/package.json is excluded by !**/*.json
📒 Files selected for processing (9)
  • packages/ide/jetbrains/build.gradle.kts (1 hunks)
  • packages/server/src/nestjs/api-handler.service.ts (1 hunks)
  • packages/server/src/nestjs/index.ts (1 hunks)
  • packages/server/src/nestjs/interfaces/api-handler-options.interface.ts (1 hunks)
  • packages/server/src/nestjs/interfaces/index.ts (1 hunks)
  • packages/server/src/nestjs/interfaces/zenstack-module-options.interface.ts (1 hunks)
  • packages/server/src/nestjs/zenstack.constants.ts (1 hunks)
  • packages/server/src/nestjs/zenstack.module.ts (1 hunks)
  • packages/server/tests/adapter/nestjs.test.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/server/src/nestjs/interfaces/api-handler-options.interface.ts (1)
packages/server/src/types.ts (1)
  • AdapterBaseOptions (32-56)
packages/server/src/nestjs/api-handler.service.ts (4)
packages/server/src/nestjs/zenstack.constants.ts (1)
  • ENHANCED_PRISMA (4-4)
packages/runtime/src/types.ts (1)
  • DbClientContract (91-93)
packages/server/src/nestjs/interfaces/api-handler-options.interface.ts (1)
  • ApiHandlerOptions (3-18)
packages/server/src/shared.ts (1)
  • loadAssets (5-21)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: dependency-review
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (15)
packages/server/src/nestjs/zenstack.constants.ts (1)

1-4: Well-structured constant definition with proper documentation

The ENHANCED_PRISMA constant is well-defined with clear JSDoc documentation explaining its purpose as the default token for exporting the enhanced Prisma service. This centralization of constants improves code organization by moving it from local usage in zenstack.module.ts to a dedicated constants file.

packages/ide/jetbrains/build.gradle.kts (1)

12-12: Version bump looks good

This minor version bump (2.14.1 → 2.14.2) aligns with the introduction of new NestJS API handling features in the server package. The change follows proper versioning practices for maintaining backward compatibility.

packages/server/src/nestjs/index.ts (1)

1-3: Clean module exports following good patterns

The additional exports provide a cleaner API surface by exposing the newly introduced ApiHandlerService and ENHANCED_PRISMA constant. This follows the principle of maintaining a well-organized public API through proper module exports.

packages/server/src/nestjs/interfaces/index.ts (1)

1-2: Good use of barrel file pattern for interface exports

This barrel file effectively consolidates exports from multiple interface files, simplifying imports for consumers of the library. It's a clean approach to maintaining modular code organization while providing a convenient import experience.

packages/server/src/nestjs/interfaces/api-handler-options.interface.ts (1)

3-18: Well-documented interface with clear examples

The ApiHandlerOptions interface extending AdapterBaseOptions is well-designed with comprehensive documentation that clearly explains the purpose and usage of the baseUrl property. The examples for both RPC and RESTful API handlers make it easy to understand how this property affects the routing paths.

packages/server/src/nestjs/zenstack.module.ts (1)

1-3: Clean refactoring to improve modularity

The changes to import constants and interfaces from dedicated modules rather than defining them inline improves code organization and maintainability. This refactoring aligns with the module's broader enhancements without changing its functionality.

packages/server/tests/adapter/nestjs.test.ts (2)

3-5: Updated imports for the new service and dependencies

The import statements have been properly updated to include the new ApiHandlerService, HttpAdapterHost, REQUEST, and RESTApiHandler that are used in the new test suite.


215-424: Comprehensive test suite for the new ApiHandlerService

The test suite for ApiHandlerService is thorough, covering three important scenarios:

  1. Default options behavior
  2. Custom REST API handler integration
  3. baseUrl option functionality

Each test properly sets up the NestJS testing environment, includes necessary mocks for HTTP context, and verifies the expected responses. This ensures the service functions correctly under different configurations.

packages/server/src/nestjs/api-handler.service.ts (2)

14-20: Appropriately scoped injectable service with proper dependency injection

The service is correctly decorated with @Injectable and scoped to REQUEST, which is appropriate for a service that handles HTTP requests. The dependencies are properly injected through the constructor.


30-30: Well-implemented path handling with baseUrl support

The logic to handle the baseUrl option is correctly implemented, slicing the path when necessary to ensure that API requests work properly when mounted under a specific URL prefix.

packages/server/src/nestjs/interfaces/zenstack-module-options.interface.ts (5)

1-2: Keep imports minimal and accurate

The imports from @nestjs/common correctly include only the necessary types (FactoryProvider, ModuleMetadata, Provider). No issues detected.


17-20: Global-scoped flag is correctly defined

The optional global boolean follows NestJS conventions for dynamic modules. No changes needed here.


27-31: Factory signature aligns with NestJS patterns

The useFactory method correctly supports both synchronous and asynchronous factories, with optional injected dependencies. This aligns with NestJS dynamic module guidelines.


32-36: Injection tokens type is correctly referenced

Using FactoryProvider['inject'] ensures the inject array matches NestJS standards for factory providers. No changes needed.


37-41: Extra providers extension is appropriate

The extraProviders field allows additional DI providers to be merged into the module, following NestJS dynamic module patterns. Looks good.

@ymc9 ymc9 merged commit b79a749 into main May 8, 2025
13 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