Skip to content

Update#56

Merged
joshunrau merged 38 commits intomainfrom
dev
Jun 11, 2025
Merged

Update#56
joshunrau merged 38 commits intomainfrom
dev

Conversation

@joshunrau
Copy link
Collaborator

@joshunrau joshunrau commented Jun 11, 2025

Includes features of previous PR as well as:

  • Fixes to swagger implementation (to explain in meeting)
  • Adjustments to custom user types

Summary by CodeRabbit

  • New Features

    • Introduced a Prisma client extension that adds an exists method to all models and exposes model name metadata.
    • Enhanced support for generating and applying Swagger API documentation metadata from Zod validation schemas.
  • Bug Fixes

    • Improved type consistency and simplified type imports across authentication and Prisma modules.
  • Refactor

    • Refactored Prisma integration to use explicit client constructors and extension-based enhancements.
    • Simplified and unified type definitions for authentication payloads, permissions, and environment configuration.
    • Updated global typings to require user ability and improve type safety.
  • Tests

    • Added and updated tests for new Prisma extension functionality and Swagger metadata utilities.
    • Removed obsolete tests for deprecated Prisma factory logic.
  • Chores

    • Upgraded Prisma-related dependencies to newer versions.
    • Cleaned up and consolidated type exports for easier maintenance.

joshunrau added 30 commits June 9, 2025 11:57
BREAKING CHANGE: Prisma options in app config have changed. See example for more details.
BREAKING CHANGE: use UserTypes.Locales
BREAKING CHANGE: Use UserTypes to declare JwtPayload and UserQueryMetadata
@joshunrau joshunrau merged commit bd9c9f5 into main Jun 11, 2025
1 of 3 checks passed
@coderabbitai
Copy link

coderabbitai bot commented Jun 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update refactors Prisma client integration by replacing the global omit config with explicit client options and extended client types, removes the PrismaFactory, and introduces a new Prisma extension for model utilities. It also unifies user and environment types, enhances Zod-Swagger integration, and updates authentication, middleware, and test setups accordingly.

Changes

File(s) Change Summary
.bruno/collection.bru Authentication endpoint updated: /v1/auth/login/auth/login.
example/app.ts, example/cats/cats.service.ts, src/modules/auth/__tests__/auth.module.spec.ts Updated Prisma client configuration, type annotations, and removed token payload schema.
package.json Prisma-related dependencies updated from 6.5.0 to 6.9.0.
src/app/__tests__/app.factory.test.ts Refactored to mock Prisma client constructor directly; removed unused imports.
src/app/app.container.ts, src/app/app.factory.ts Changed Prisma-related generics from global omit config to client options and extended client types.
src/decorators/__tests__/current-user.decorator.test.ts, src/modules/auth/guards/__tests__/jwt-auth.guard.spec.ts Adjusted type assertions for user objects in tests.
src/decorators/validation-schema.decorator.ts, src/mixins/data-transfer-object.mixin.ts Added Swagger metadata application when using Zod schemas.
src/index.ts Consolidated Prisma type exports; removed export from prisma.factory.js.
src/middleware/accept-language.middleware.ts, src/typings/globals.ts Simplified and unified Locale type import and definition.
src/mixins/__tests__/data-transfer-object.mixin.test.ts Added test for empty object DTO class name.
src/modules/auth/auth.config.ts, src/modules/auth/auth.module.ts, src/modules/auth/auth.service.ts, src/modules/auth/strategies/jwt.strategy.ts Unified user types, simplified generics, and updated payload typings.
src/modules/config/__tests__/config.service.test.ts, src/modules/config/config.module.ts, src/modules/config/config.service.ts Changed RuntimeEnv import to new user types module.
src/modules/prisma/__tests__/prisma.extensions.test.ts, src/modules/prisma/__tests__/prisma.types.test.ts Added new tests for Prisma extension and typings.
src/modules/prisma/__tests__/prisma.module.test.ts, src/testing/helpers/integration.ts Explicitly provided Prisma client constructor in test/module setups.
src/modules/prisma/prisma.config.ts, src/modules/prisma/prisma.extensions.ts, src/modules/prisma/prisma.types.ts Refactored Prisma module config, added new extension for model utilities, and updated type inference utilities.
src/modules/prisma/prisma.factory.ts, src/modules/prisma/__tests__/prisma.factory.test.ts Deleted PrismaFactory and related tests, shifting to direct client instantiation and extension.
src/modules/prisma/prisma.module.ts, src/modules/prisma/prisma.service.ts, src/testing/mocks/prisma.module.mock.ts Updated to use new Prisma client extension and types; adjusted mocks and constructor types.
src/schemas/env.schema.ts Removed RuntimeEnv type alias.
src/testing/helpers/e2e.ts Updated AppContainer generic arity in function signature.
src/user-config.ts, src/user-types.ts Unified user types, removed CustomTypeOptions, added UserTypes namespace and utility types for locale/env/prisma options.
src/utils/__tests__/validation.utils.test.ts, src/utils/validation.utils.ts Added comprehensive Zod-to-Swagger metadata integration and tests.

Sequence Diagram(s)

sequenceDiagram
    participant AppModule
    participant PrismaModule
    participant MongoConnection
    participant PrismaClient
    participant LibnestPrismaExtension

    AppModule->>PrismaModule: forRoot({ client: { constructor: PrismaClient, ... }, ... })
    PrismaModule->>MongoConnection: Get MongoDB URL
    PrismaModule->>PrismaClient: Instantiate with options + datasourceUrl
    PrismaClient->>LibnestPrismaExtension: $extends(LibnestPrismaExtension)
    LibnestPrismaExtension-->>PrismaClient: Adds exists() and __modelName utilities
    PrismaModule-->>AppModule: Extended PrismaClient instance
Loading

Possibly related PRs

Poem

Prisma’s cloak gets a brand new thread,
Extensions bloom where factories fled.
Zod and Swagger now entwined,
User types and locales aligned.
Tests and mocks in tidy rows—
Where refactors go, the garden grows!
🌱🛠️


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 49f3ce7 and c5f8a0e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (41)
  • .bruno/collection.bru (1 hunks)
  • example/app.ts (3 hunks)
  • example/cats/cats.service.ts (1 hunks)
  • package.json (3 hunks)
  • src/app/__tests__/app.factory.test.ts (2 hunks)
  • src/app/app.container.ts (1 hunks)
  • src/app/app.factory.ts (1 hunks)
  • src/decorators/__tests__/current-user.decorator.test.ts (1 hunks)
  • src/decorators/validation-schema.decorator.ts (2 hunks)
  • src/index.ts (1 hunks)
  • src/middleware/accept-language.middleware.ts (1 hunks)
  • src/mixins/__tests__/data-transfer-object.mixin.test.ts (1 hunks)
  • src/mixins/data-transfer-object.mixin.ts (2 hunks)
  • src/modules/auth/__tests__/auth.module.spec.ts (1 hunks)
  • src/modules/auth/auth.config.ts (2 hunks)
  • src/modules/auth/auth.module.ts (1 hunks)
  • src/modules/auth/auth.service.ts (2 hunks)
  • src/modules/auth/guards/__tests__/jwt-auth.guard.spec.ts (3 hunks)
  • src/modules/auth/strategies/jwt.strategy.ts (2 hunks)
  • src/modules/config/__tests__/config.service.test.ts (1 hunks)
  • src/modules/config/config.module.ts (1 hunks)
  • src/modules/config/config.service.ts (1 hunks)
  • src/modules/prisma/__tests__/prisma.extensions.test.ts (1 hunks)
  • src/modules/prisma/__tests__/prisma.factory.test.ts (0 hunks)
  • src/modules/prisma/__tests__/prisma.module.test.ts (2 hunks)
  • src/modules/prisma/__tests__/prisma.types.test.ts (1 hunks)
  • src/modules/prisma/prisma.config.ts (1 hunks)
  • src/modules/prisma/prisma.extensions.ts (1 hunks)
  • src/modules/prisma/prisma.factory.ts (0 hunks)
  • src/modules/prisma/prisma.module.ts (2 hunks)
  • src/modules/prisma/prisma.service.ts (1 hunks)
  • src/modules/prisma/prisma.types.ts (2 hunks)
  • src/schemas/env.schema.ts (0 hunks)
  • src/testing/helpers/e2e.ts (1 hunks)
  • src/testing/helpers/integration.ts (2 hunks)
  • src/testing/mocks/prisma.module.mock.ts (1 hunks)
  • src/typings/globals.ts (1 hunks)
  • src/user-config.ts (2 hunks)
  • src/user-types.ts (1 hunks)
  • src/utils/__tests__/validation.utils.test.ts (1 hunks)
  • src/utils/validation.utils.ts (2 hunks)
✨ 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:

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

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.

@codecov
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7993134) to head (c5f8a0e).
Report is 680 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main       #56     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           39        83     +44     
  Lines          878      2297   +1419     
  Branches       176       424    +248     
===========================================
+ Hits           878      2297   +1419     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link

🎉 This PR is included in version 7.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant