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

feat: ✨ add users/presentation lib #46

Merged
merged 5 commits into from
Nov 18, 2024

Conversation

zhumeisongsong
Copy link
Owner

@zhumeisongsong zhumeisongsong commented Nov 18, 2024

Related #47

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new README file for the users-presentation library, providing an overview and testing instructions.
    • Added Jest and ESLint configuration files for improved testing and code quality management.
    • Enhanced TypeScript configurations for stricter type-checking and better module organization.
  • Improvements

    • Updated import paths for UsersResolver and UsersService to improve module structure.
    • Exported new modules and entities to enhance visibility and usability within the application.
  • Bug Fixes

    • Adjusted return type handling in the UsersService to account for potential undefined values when a user is not found.

Copy link

coderabbitai bot commented Nov 18, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on modifying import paths for the UsersResolver and UsersService to utilize absolute paths instead of relative ones. Additionally, new TypeScript configuration files and ESLint settings have been created for the users-presentation library, along with updates to existing TypeScript configurations. The UsersService now has an updated return type for its findById method, and a new README file has been added to provide documentation for the users-presentation library.

Changes

File Change Summary
apps/users/src/users/users.module.ts Updated import paths for UsersResolver and UsersService to absolute paths.
libs/users/application/src/index.ts Added export statement for users.service.
libs/users/application/src/lib/users.service.spec.ts Updated return type of findById method from User to `User
libs/users/application/tsconfig.json Added several compiler options for TypeScript, including strict type-checking settings.
libs/users/presentation/README.md Created a new README file for the users-presentation library.
libs/users/presentation/eslint.config.js Introduced a new ESLint configuration file that extends a base configuration.
libs/users/presentation/jest.config.ts Added a new Jest configuration file for the users-presentation library.
libs/users/presentation/project.json Created a new project configuration file for the users-presentation library.
libs/users/presentation/src/index.ts Added export statement for all entities from users.resolver.
libs/users/presentation/src/lib/users.resolver.spec.ts Updated import path for UsersService to an absolute path.
libs/users/presentation/src/lib/users.resolver.ts Updated import path for UsersService to an absolute path.
libs/users/presentation/tsconfig.json Created a new TypeScript configuration file extending a base config with strict options.
libs/users/presentation/tsconfig.lib.json Created a new TypeScript configuration file for library settings.
libs/users/presentation/tsconfig.spec.json Created a new TypeScript configuration file for testing settings.
tsconfig.base.json Added path mapping for @users/presentation to point to the new library index.

Possibly related PRs

🐰 "In the land of code where bunnies play,
Paths now are clearer, come what may.
With services and resolvers in their place,
Our imports now have a friendly face.
TypeScript's strictness, a guiding light,
In our rabbit hole, everything feels right!" 🐇

Warning

Rate limit exceeded

@zhumeisongsong has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 93c8f80 and 5b6b757.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/users/src/users/users.module.ts

Oops! Something went wrong! :(

ESLint: 9.15.0

TypeError: Error while loading rule '@typescript-eslint/no-unused-expressions': Cannot read properties of undefined (reading 'allowShortCircuit')
Occurred while linting /apps/users/src/users/users.module.ts
at Object.create (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rules/no-unused-expressions.js:75:13)
at create (/node_modules/.pnpm/@typescript-eslint+eslint-plugin@8.14.0_@typescript-eslint+parser@[email protected]_typesc_u2crwq53uno6k5fweinf7nowby/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unused-expressions.js:28:32)
at Object.create (/node_modules/.pnpm/@typescript-eslint[email protected][email protected][email protected]/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:31:20)
at createRuleListeners (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:944:21)
at /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1082:84
at Array.forEach ()
at runRules (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1013:34)
at #flatVerifyWithoutProcessors (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1911:31)
at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1993:49)
at Linter._verifyWithFlatConfigArray (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:2082:21)


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • 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 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.

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

@Copilot 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.

Copilot reviewed 7 out of 16 changed files in this pull request and generated 1 suggestion.

Files not reviewed (9)
  • libs/users/application/tsconfig.json: Language not supported
  • libs/users/presentation/project.json: Language not supported
  • libs/users/presentation/tsconfig.json: Language not supported
  • libs/users/presentation/tsconfig.lib.json: Language not supported
  • libs/users/presentation/tsconfig.spec.json: Language not supported
  • tsconfig.base.json: Language not supported
  • apps/users/src/users/users.module.ts: Evaluated as low risk
  • libs/users/presentation/src/lib/users.resolver.ts: Evaluated as low risk
  • libs/users/presentation/src/lib/users.resolver.spec.ts: Evaluated as low risk

libs/users/presentation/eslint.config.js Show resolved Hide resolved
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: 0

🧹 Outside diff range and nitpick comments (6)
libs/users/application/src/index.ts (1)

3-4: Consider removing the redundant comment.

The comment "// service" is redundant since the exported file name already indicates it's a service. Consider grouping related exports together without the comment for cleaner code.

 export * from './lib/use-case/get-user.use-case';
 
-// service
 export * from './lib/users.service';
libs/users/presentation/src/lib/users.resolver.ts (1)

Line range hint 5-22: Well-structured resolver implementation!

The implementation follows clean architecture principles with proper separation of concerns. The resolver acts as a thin presentation layer, delegating business logic to the application layer (UsersService).

Some architectural points worth noting:

  1. The resolver correctly implements GraphQL federation capabilities through @ResolveReference
  2. The use of dependency injection allows for better testability
  3. The presentation layer doesn't contain business logic, maintaining clean architecture boundaries
libs/users/application/src/lib/users.service.spec.ts (2)

22-23: LGTM! Consider adding more test cases.

The explicit type annotation User | undefined improves type safety and correctly reflects the service method's return type.

Consider adding more test cases to cover different scenarios:

it('should handle various user ID formats', () => {
  expect(service.findById('user-123')).toBeDefined();
  expect(service.findById('UUID-FORMAT')).toBeDefined();
});

it('should return consistent user data', () => {
  const user = service.findById('1');
  expect(user).toMatchObject({
    id: expect.any(String),
    name: expect.any(String),
  });
});

27-28: LGTM! Consider adding error scenario tests.

The test case properly verifies the undefined return for non-existent users.

Consider adding tests for error scenarios:

it('should handle invalid user IDs gracefully', () => {
  expect(service.findById('')).toBeUndefined();
  expect(service.findById(null as unknown as string)).toBeUndefined();
});

it('should not throw errors for edge cases', () => {
  expect(() => service.findById('invalid-id')).not.toThrow();
});
apps/users/src/users/users.module.ts (1)

Line range hint 16-27: Consider documenting federation version requirement

The inline comment about federation version is helpful, but consider moving this important configuration detail to a more visible location like README.md or CONTRIBUTING.md.

Would you like me to help draft documentation for the federation version requirement?

libs/users/presentation/src/lib/users.resolver.spec.ts (1)

Line range hint 33-65: Consider adding edge case tests.

While the current test coverage is good, consider adding tests for these scenarios:

  • Invalid user ID formats
  • Empty string IDs
  • Non-string ID types (if TypeScript allows)

Example addition:

it('should handle invalid user id formats', () => {
  expect(resolver.getUser('')).toBeUndefined();
  expect(service.findById).not.toHaveBeenCalled();
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 93c8f80 and 5b6b757.

📒 Files selected for processing (15)
  • apps/users/src/users/users.module.ts (1 hunks)
  • libs/users/application/src/index.ts (1 hunks)
  • libs/users/application/src/lib/users.service.spec.ts (1 hunks)
  • libs/users/application/tsconfig.json (1 hunks)
  • libs/users/presentation/README.md (1 hunks)
  • libs/users/presentation/eslint.config.js (1 hunks)
  • libs/users/presentation/jest.config.ts (1 hunks)
  • libs/users/presentation/project.json (1 hunks)
  • libs/users/presentation/src/index.ts (1 hunks)
  • libs/users/presentation/src/lib/users.resolver.spec.ts (1 hunks)
  • libs/users/presentation/src/lib/users.resolver.ts (1 hunks)
  • libs/users/presentation/tsconfig.json (1 hunks)
  • libs/users/presentation/tsconfig.lib.json (1 hunks)
  • libs/users/presentation/tsconfig.spec.json (1 hunks)
  • tsconfig.base.json (1 hunks)
✅ Files skipped from review due to trivial changes (8)
  • libs/users/presentation/README.md
  • libs/users/presentation/eslint.config.js
  • libs/users/presentation/jest.config.ts
  • libs/users/presentation/project.json
  • libs/users/presentation/src/index.ts
  • libs/users/presentation/tsconfig.json
  • libs/users/presentation/tsconfig.lib.json
  • libs/users/presentation/tsconfig.spec.json
🔇 Additional comments (9)
libs/users/application/src/index.ts (1)

4-4: Verify the service import usage across the codebase.

The addition of this export aligns with the PR's objective of restructuring user-related modules. Let's verify that all imports are updated to use this new path.

✅ Verification successful

All imports of UsersService are correctly using the barrel file

The verification shows that all external imports of UsersService are properly using the @users/application path:

  • libs/users/presentation/src/lib/users.resolver.ts
  • libs/users/presentation/src/lib/users.resolver.spec.ts
  • apps/users/src/users/users.module.ts

The only relative import found is in the service's own test file (users.service.spec.ts), which is the correct pattern for testing the service in its own directory.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any relative imports of users.service that should be using the barrel file
# Expected: No relative imports of users.service, all imports should use @users/application

# Search for any relative imports of users.service
rg -g '*.ts' "from ['\"]\.\..*users\.service['\"]"

# Search for the correct absolute imports for comparison
rg -g '*.ts' "from ['\"]@users/application['\"].*UsersService"

Length of output: 125


Script:

#!/bin/bash
# Let's try a broader search to find any imports related to users.service
# First, let's find all TypeScript files that mention UsersService
rg -l "UsersService" --type ts

# Then, let's look for any import statements containing 'users.service'
rg "import.*users\.service" --type ts

# Also search for any exports containing UsersService
rg "export.*UsersService" --type ts

# And check for any path containing users/application
rg "from.*@users/application" --type ts

Length of output: 865

libs/users/application/tsconfig.json (2)

5-10: LGTM! Enhanced type safety configuration looks good.

The added TypeScript compiler options significantly improve type safety and code quality:

  • strict: true enables comprehensive type checking
  • noImplicitOverride prevents accidental method overrides
  • noImplicitReturns ensures all code paths return values
  • noFallthroughCasesInSwitch prevents switch case fallthrough bugs
  • noPropertyAccessFromIndexSignature enforces explicit property access

4-10: Verify consistent TypeScript configuration across related packages.

Let's ensure these compiler options are consistently applied across related packages, particularly in the users-presentation library.

✅ Verification successful

TypeScript configurations are consistent across users domain packages

The verification shows that the TypeScript compiler options are identical between the application and presentation layers in the users domain. Both configurations have the same strict type-checking flags and module settings enabled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistency in TypeScript configurations across related packages

# Find all tsconfig.json files in the users domain
echo "Checking TypeScript configurations in users domain:"
fd tsconfig.json libs/users/ --exec cat {} \; | grep -A 10 "compilerOptions"

# Specifically compare with the presentation layer
echo "\nComparing with presentation layer config:"
diff libs/users/application/tsconfig.json libs/users/presentation/tsconfig.json

Length of output: 978

libs/users/presentation/src/lib/users.resolver.ts (1)

1-3: Verify module alias consistency

There's an inconsistency in the module aliases: @users/application vs @user/domain. This could indicate a configuration issue or naming inconsistency across the monorepo.

✅ Verification successful

Let me gather more information about the module structure to understand if this is a deliberate design choice or an inconsistency.


Let me check the contents of these directories to understand the module structure better.


Module aliases are correctly structured and consistent

The apparent inconsistency in module aliases (@users vs @user) is actually a deliberate and correct design choice reflecting the module structure:

  • @user/domain: Contains the core domain entities and repository interfaces (singular, as it represents the domain model)
  • @users/application and @users/presentation: Contains the application services and presentation layer (plural, as they represent features/use-cases)

This follows a common DDD (Domain-Driven Design) pattern where the domain model is singular while its implementations and features are plural.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for module alias consistency across the workspace

# Check TypeScript paths configuration
echo "Checking tsconfig paths..."
fd tsconfig.json --exec cat {} | jq -r '.compilerOptions.paths | select(. != null)'

# Check for all imports using these aliases
echo "Checking usage of module aliases..."
rg -g '*.ts' '@users?/' --context 1

Length of output: 2358


Script:

#!/bin/bash
# Check the actual directory structure and package.json files
echo "Directory structure for user/users modules:"
fd -t d -d 1 user libs/
fd -t d -d 1 users libs/

echo -e "\nChecking package.json files in these directories:"
fd -t f package.json -p libs/user libs/users --exec cat {}

Length of output: 362


Script:

#!/bin/bash
# List contents of user and users directories
echo "Contents of libs/user directory:"
fd . libs/user/ -t f

echo -e "\nContents of libs/users directory:"
fd . libs/users/ -t f

# Check for any exports or barrel files
echo -e "\nChecking index files and exports:"
rg -g '*.ts' "export \*" libs/user libs/users

Length of output: 2083

tsconfig.base.json (2)

21-22: LGTM! Clean separation of concerns

The path mappings follow a clean architecture pattern by properly separating the presentation layer from the application layer. The consistent naming convention and structure make the codebase more maintainable.


22-22: Verify the presentation module structure

Let's ensure the new presentation module path exists and follows the expected structure.

✅ Verification successful

The users presentation module structure is properly organized and exports are correctly configured

The verification confirms that:

  • The module directory exists at the correct path
  • The module follows the standard structure with necessary configuration files
  • The index.ts file properly exports the users resolver
  • All expected files are present including tests, configs and source files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and structure of the users presentation module

# Check if the presentation module directory exists
if ! [ -d "libs/users/presentation" ]; then
  echo "Error: Presentation module directory not found"
  exit 1
fi

# Verify the index.ts file exists
if ! [ -f "libs/users/presentation/src/index.ts" ]; then
  echo "Error: index.ts not found in presentation module"
  exit 1
fi

# Check the module structure
echo "Module structure:"
fd . libs/users/presentation --type f

# Show exports from index.ts
echo -e "\nModule exports:"
cat libs/users/presentation/src/index.ts

Length of output: 715

apps/users/src/users/users.module.ts (1)

7-8: LGTM! Good architectural separation.

The change from relative to absolute imports improves the code organization by clearly separating presentation and application layers. This follows good domain-driven design principles.

Let's verify the module exports are properly configured:

✅ Verification successful

Let me gather more information about the tsconfig paths configuration since the previous command didn't show the complete picture.


Import paths and module exports are correctly configured

The verification confirms:

  • Both UsersResolver and UsersService are properly exported from their respective libraries
  • Path aliases @users/presentation and @users/application are correctly configured in tsconfig.base.json
  • Library index files export the required components:
    • presentation: exports users.resolver.ts
    • application: exports users.service.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the module exports and tsconfig paths

# Check if the modules are properly exported
echo "Checking module exports..."
rg -l "export.*UsersResolver" "libs/users/presentation"
rg -l "export.*UsersService" "libs/users/application"

# Verify tsconfig paths configuration
echo "Checking tsconfig paths..."
fd tsconfig.json -x cat {} | jq '.compilerOptions.paths | select(."@users/presentation" or ."@users/application")'

Length of output: 452


Script:

#!/bin/bash
# Check the base tsconfig and workspace tsconfig files
echo "Checking base tsconfig.json..."
cat tsconfig.base.json | jq '.compilerOptions.paths'

echo -e "\nChecking workspace tsconfig files..."
fd tsconfig.json -x sh -c 'echo "=== {} ==="; cat {} | jq ".compilerOptions.paths"'

# Also verify the exports from the library's index files
echo -e "\nChecking library exports..."
echo "=== Presentation library ==="
cat libs/users/presentation/src/index.ts || true
echo -e "\n=== Application library ==="
cat libs/users/application/src/index.ts || true

Length of output: 1474

libs/users/presentation/src/lib/users.resolver.spec.ts (2)

2-2: LGTM! Import organization looks good.

The switch to absolute imports and the logical ordering of imports (external → internal → local) improves maintainability and follows best practices.

Also applies to: 5-5


Line range hint 7-27: Well-structured test setup with comprehensive coverage.

The test organization follows best practices with:

  • Clean TestingModule setup
  • Proper dependency injection and mocking
  • Clear separation of concerns

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 16 changed files in this pull request and generated no suggestions.

Files not reviewed (10)
  • libs/users/application/tsconfig.json: Language not supported
  • libs/users/presentation/project.json: Language not supported
  • libs/users/presentation/tsconfig.json: Language not supported
  • libs/users/presentation/tsconfig.lib.json: Language not supported
  • libs/users/presentation/tsconfig.spec.json: Language not supported
  • tsconfig.base.json: Language not supported
  • apps/users/src/users/users.module.ts: Evaluated as low risk
  • libs/users/presentation/src/lib/users.resolver.ts: Evaluated as low risk
  • libs/users/application/src/lib/users.service.spec.ts: Evaluated as low risk
  • libs/users/presentation/src/lib/users.resolver.spec.ts: Evaluated as low risk
@zhumeisongsong zhumeisongsong merged commit a943204 into main Nov 18, 2024
5 checks passed
@zhumeisongsong zhumeisongsong deleted the feature/add-presentation-to-users-module branch November 18, 2024 03:24
Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on GitHub release

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