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

fix: published types from package #144

Closed
wants to merge 1 commit into from

Conversation

drohan2536
Copy link

@drohan2536 drohan2536 commented Jul 1, 2024

Checklist

Make sure you have

  • Added relevant @nestjs/swagger decorators wherever required
  • Added test cases (unit and integration) wherever required

Description

  • Added TypeScript type declarations for all packages within Stencil.
  • Updated tsconfig.json to generate .d.ts files and included them in the build process.
  • Modified package.json to reference the generated type definitions.

Demo

https://drive.google.com/uc?id=1so9yliRJ_74WfFNqSrhaWhK3rWWta6CP&export=download

Summary by CodeRabbit

  • New Features

    • Enhanced type safety with stricter type checking enabled in the project.
  • Chores

    • Added a "clean" script to the package configuration.
    • Updated dependencies with type definitions for external packages.
  • Refactor

    • Improved type declarations and imports for better maintainability and consistency.
    • Updated environment variable usage for more explicit type casting.
  • Documentation

    • Adjusted tsconfig.json settings to improve code quality and consistency.

Copy link

coderabbitai bot commented Jul 1, 2024

Walkthrough

The recent changes in the common package involve improving TypeScript typing, adding scripts for cleanup, and specifying strict type checks. Interfaces for handling multipart data and file uploads were updated, along with casting environmental variables to strings in the FileUploadService. Finally, the tsconfig.json was enhanced with stricter type-checking settings to improve code reliability.

Changes

File Path Change Summary
packages/common/package.json Added "types" entry, updated "typings", "files", added "clean" script, and added two type dependencies.
packages/common/src/interfaces/fastify-multipart.d.ts Introduced ParsedPart and MultipartFields interfaces for multipart form data.
packages/common/src/interfaces/file-upload.interface.ts Switched to direct import of MultipartFields and updated its usage in MultipartFile interface.
packages/common/src/services/file-upload.service.ts Cast environment variables to strings and specified err parameter type as `Error
packages/common/tsconfig.json Added declarationDir, enabled stricter type-checking settings, and adjusted include/exclude paths.

Poem

In a file of codes, neat and bright,
Types and scripts dance in the light,
Stricter checks, now in sight,
Bugs and errors take their flight.
Common's better, swift as breeze,
Coding now is such a tease! 🐇✨


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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 (1)
packages/common/src/services/file-upload.service.ts (1)

Line range hint 119-123: Remove the redundant else clause.

The else clause is redundant and can be omitted to simplify the code.

-        else{
-            this.logger.error(`Error downloading file: File does not exist`);
-            return null;
-        }
+        this.logger.error(`Error downloading file: File does not exist`);
+        return null;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f8221bb and 3087352.

Files selected for processing (5)
  • packages/common/package.json (3 hunks)
  • packages/common/src/interfaces/fastify-multipart.d.ts (1 hunks)
  • packages/common/src/interfaces/file-upload.interface.ts (2 hunks)
  • packages/common/src/services/file-upload.service.ts (2 hunks)
  • packages/common/tsconfig.json (2 hunks)
Additional context used
Biome
packages/common/src/services/file-upload.service.ts

[error] 113-123: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 119-122: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (12)
packages/common/src/interfaces/file-upload.interface.ts (1)

1-1: Importing the MultipartFields type is correct.

The import statement correctly brings in the MultipartFields type from fastify-multipart.

packages/common/src/interfaces/fastify-multipart.d.ts (3)

1-1: Declare module 'fastify-multipart' correctly.

Declaring a module augmentation for 'fastify-multipart' is correct and ensures the new interfaces are available globally.


2-11: Define ParsedPart interface correctly.

The ParsedPart interface is well-defined and covers all necessary fields for handling multipart data.


13-15: Define MultipartFields interface correctly.

The MultipartFields interface is well-defined and supports both single and multiple ParsedPart entries.

packages/common/tsconfig.json (2)

5-5: Specify declarationDir correctly.

The declarationDir option ensures that type declarations are generated in the ./dist/types directory, which is a good practice.


16-20: Enable strict type checking options.

Enabling strict type checking options like strictNullChecks, noImplicitAny, strictBindCallApply, forceConsistentCasingInFileNames, and noFallthroughCasesInSwitch improves code quality and type safety.

packages/common/package.json (4)

18-18: Add types field correctly.

The types field ensures that the type declarations are correctly referenced in the package.


20-21: Include types directory in files field.

Including the types directory in the files field ensures that the type declarations are included in the published package.


27-27: Add clean script correctly.

The clean script uses rimraf to remove the dist and types directories, which is useful for cleaning up the build artifacts.


64-66: Add necessary type dependencies.

Adding @types/cache-manager-redis-store and @types/fastify-multipart ensures that type definitions are available for these packages.

packages/common/src/services/file-upload.service.ts (2)

26-30: LGTM! But verify environment variables.

The changes improve type safety by casting environment variables to specific types.

However, ensure that all environment variables (STORAGE_ENDPOINT, STORAGE_PORT, STORAGE_ACCESS_KEY, STORAGE_SECRET_KEY) are always set correctly.


48-48: LGTM! But verify error handling.

The change improves type safety by specifying the type of the err parameter in the callback function.

However, ensure that the callback function handles errors correctly and consistently.

Verification successful

Error handling in the callback function is correctly implemented.

The callback function logs the error and rejects the promise if an error occurs, which is a proper error handling mechanism.

  • The error is logged using console.log('err: ', err);
  • The promise is rejected with reject(err);
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in the callback function.

# Test: Search for the callback function usage. Expect: Proper error handling.
rg --type typescript $'function (err: Error | null)'

Length of output: 88



Script:

#!/bin/bash
# Description: Verify error handling in the callback function.

# Test: Search for the callback function usage. Expect: Proper error handling.
rg --type ts $'function (err: Error | null)'

Length of output: 45



Script:

#!/bin/bash
# Description: Verify error handling in the `uploadToMinio` function.

# Find the definition of the `uploadToMinio` function.
rg 'function uploadToMinio'

# Find the usage of the `uploadToMinio` function.
rg 'uploadToMinio('

Length of output: 130



Script:

#!/bin/bash
# Description: Verify error handling in the `uploadToMinio` function.

# Find the definition of the `uploadToMinio` function.
rg 'function uploadToMinio'

# Find the usage of the `uploadToMinio` function.
rg 'uploadToMinio\('

Length of output: 285



Script:

#!/bin/bash
# Description: Extract the implementation of the `uploadToMinio` function.

# Extract the implementation of the `uploadToMinio` function from the specified file.
ast-grep --lang typescript --pattern 'async uploadToMinio($_, $_): Promise<string> { $$$ }' packages/common/src/services/file-upload.service.ts

Length of output: 620



Script:

#!/bin/bash
# Description: Extract the implementation of the `uploadToMinio` function using a simplified pattern.

# Extract the implementation of the `uploadToMinio` function definition.
ast-grep --lang typescript --pattern 'async uploadToMinio($_, $_): Promise<string> { $$$ }' packages/common/src/services/file-upload.service.ts

# Extract the body of the `uploadToMinio` function.
rg -A 20 'async uploadToMinio' packages/common/src/services/file-upload.service.ts

Length of output: 1373

@techsavvyash techsavvyash linked an issue Jul 1, 2024 that may be closed by this pull request
Copy link
Member

@techsavvyash techsavvyash left a comment

Choose a reason for hiding this comment

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

closing this because #147 has the improvements

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.

[stencil] publish types from package
2 participants